Skip to content

Commit 7a15609

Browse files
committed
Merge branch 'master' of https://bitbucket.org/ajharker/framelib
2 parents 8b2b829 + 933180d commit 7a15609

File tree

13 files changed

+1235
-6
lines changed

13 files changed

+1235
-6
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#include "FrameLib_MultiSelect.h"
3+
#include "FrameLib_MaxClass.h"
4+
5+
extern "C" int C74_EXPORT main(void)
6+
{
7+
FrameLib_MaxClass_Expand<FrameLib_MultiSelect>::makeClass(CLASS_BOX, "fl.multiselect~");
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#include "FrameLib_TimeDelta.h"
3+
#include "FrameLib_MaxClass.h"
4+
5+
extern "C" int C74_EXPORT main(void)
6+
{
7+
FrameLib_MaxClass<FrameLib_Expand <FrameLib_TimeDelta> >::makeClass(CLASS_BOX, "fl.timedelta~");
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#include "FrameLib_Timer.h"
3+
#include "FrameLib_MaxClass.h"
4+
5+
extern "C" int C74_EXPORT main(void)
6+
{
7+
FrameLib_MaxClass<FrameLib_Expand <FrameLib_Timer> >::makeClass(CLASS_BOX, "fl.timer~");
8+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
#include "FrameLib_MultiSelect.h"
3+
4+
// Internal Valve Class
5+
6+
// Constructor
7+
8+
FrameLib_MultiSelect::Select::Select(FrameLib_Context context, FrameLib_Parameters::Serial *serialisedParameters, void *owner, long numIns, long num) : FrameLib_Processor(context, owner, NULL, 1, 1), mNumIns(numIns)
9+
{
10+
char name[32];
11+
sprintf(name, "input_%2ld", num);
12+
mParameters.addInt(kActiveIn, name, 0);
13+
14+
mParameters.set(serialisedParameters);
15+
16+
mActiveIn = floor(mParameters.getInt(kActiveIn));
17+
18+
for (unsigned long i = 0; i < mNumIns; i++)
19+
setInputMode(i, false, i == mActiveIn, true, kFrameAny);
20+
21+
setOutputMode(0, kFrameAny);
22+
addParameterInput();
23+
}
24+
25+
// Update and Process
26+
27+
void FrameLib_MultiSelect::Select::update()
28+
{
29+
if (mParameters.changed(kActiveIn))
30+
{
31+
// FIX - which way to index the inputs?
32+
33+
mActiveIn = floor(mParameters.getValue(kActiveIn));
34+
35+
for (unsigned long i = 0; i < mNumIns; i++)
36+
updateTrigger(i, i == mActiveIn);
37+
}
38+
}
39+
40+
void FrameLib_MultiSelect::Select::process()
41+
{
42+
// Copy active input to output
43+
44+
prepareCopyInputToOutput(mActiveIn, 0);
45+
allocateOutputs();
46+
copyInputToOutput(mActiveIn, 0);
47+
48+
}
49+
50+
// Main Class
51+
52+
// Constructor
53+
54+
FrameLib_MultiSelect::FrameLib_MultiSelect(FrameLib_Context context, FrameLib_Parameters::Serial *serialisedParameters, void *owner)
55+
: FrameLib_Block(kProcessor, context, owner), mParameters(&sParamInfo)
56+
{
57+
mParameters.addDouble(kNumIns, "num_ins", 2, 0);
58+
mParameters.setClip(2, 32);
59+
mParameters.setInstantiation();
60+
mParameters.addDouble(kNumOuts, "num_outs", 2, 1);
61+
mParameters.setClip(2, 32);
62+
mParameters.setInstantiation();
63+
64+
mParameters.set(serialisedParameters);
65+
66+
mNumOuts = mParameters.getInt(kNumIns);
67+
mNumOuts = mParameters.getInt(kNumOuts);
68+
69+
for (long i = 0; i < mNumOuts; i++)
70+
{
71+
char name[32];
72+
sprintf(name, "input_%2ld", i);
73+
mParameters.addInt(kActiveIn1 + i, name, 0);
74+
}
75+
76+
mParameters.set(serialisedParameters);
77+
78+
setIO(kNumIns + 1, kNumOuts);
79+
80+
for (int i = 0; i < mNumOuts; i++)
81+
{
82+
mSelects.push_back(new Select(context, serialisedParameters, owner, mNumIns, i));
83+
for (unsigned long j = 0; j < mNumIns + 1; j++)
84+
mSelects[i]->setInputAlias(Connection(this, j), j);
85+
mSelects[i]->setOutputAlias(Connection(this, i), 0);
86+
}
87+
}
88+
89+
FrameLib_MultiSelect::~FrameLib_MultiSelect()
90+
{
91+
for (std::vector<Select *>::iterator it = mSelects.begin(); it != mSelects.end(); it++)
92+
delete (*it);
93+
}
94+
95+
// Info
96+
97+
std::string FrameLib_MultiSelect::objectInfo(bool verbose)
98+
{
99+
return formatInfo("Routes input frames to one of a number of outputs: The number of outputs is variable. The selected output can be changed with a parameter.",
100+
"Routes input frames to one of a number of outputs.", verbose);
101+
}
102+
103+
std::string FrameLib_MultiSelect::inputInfo(unsigned long idx, bool verbose)
104+
{
105+
if (idx == mNumOuts)
106+
return formatInfo("Parameter Update - tagged input updates parameters", "Parameter Update", verbose);
107+
else
108+
return "Input Frames";
109+
}
110+
111+
std::string FrameLib_MultiSelect::outputInfo(unsigned long idx, bool verbose)
112+
{
113+
return formatInfo("Output #", "Output #", idx, verbose);
114+
}
115+
116+
// Parameter Info
117+
118+
FrameLib_MultiSelect::ParameterInfo FrameLib_MultiSelect::sParamInfo;
119+
120+
FrameLib_MultiSelect::ParameterInfo::ParameterInfo()
121+
{
122+
add("Sets the number of object outputs.");
123+
add("Sets the current output (or off if out of range).");
124+
}
125+
126+
// Reset
127+
128+
void FrameLib_MultiSelect::reset(double samplingRate, unsigned long maxBlockSize)
129+
{
130+
for (std::vector<Select *>::iterator it = mSelects.begin(); it != mSelects.end(); it++)
131+
(*it)->reset(samplingRate, maxBlockSize);
132+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
#ifndef FRAMELIB_MULTISELECT_H
3+
#define FRAMELIB_MULTISELECT_H
4+
5+
#include "FrameLib_DSP.h"
6+
7+
class FrameLib_MultiSelect : public FrameLib_Block
8+
{
9+
// Internal valve class
10+
11+
class Select : public FrameLib_Processor
12+
{
13+
// Parameter Enums and Info
14+
15+
enum ParameterList { kActiveIn };
16+
17+
public:
18+
19+
// Constructor
20+
21+
Select(FrameLib_Context context, FrameLib_Parameters::Serial *serialisedParameters, void *owner, long numIns, long num);
22+
23+
private:
24+
25+
// Update and Process
26+
27+
void update();
28+
void process();
29+
30+
// Data
31+
32+
long mNumIns;
33+
long mActiveIn;
34+
};
35+
36+
// Parameter Enums and Info
37+
38+
enum ParameterList { kNumIns, kNumOuts, kActiveIn1 };
39+
40+
struct ParameterInfo : public FrameLib_Parameters::Info { ParameterInfo(); };
41+
42+
public:
43+
44+
// Constructor / Destructor
45+
46+
FrameLib_MultiSelect(FrameLib_Context context, FrameLib_Parameters::Serial *serialisedParameters, void *owner);
47+
~FrameLib_MultiSelect();
48+
49+
// Object Type
50+
51+
static ObjectType getType() { return kProcessor; }
52+
53+
// Info
54+
55+
std::string objectInfo(bool verbose);
56+
std::string inputInfo(unsigned long idx, bool verbose);
57+
std::string outputInfo(unsigned long idx, bool verbose);
58+
59+
// Connection Types
60+
61+
virtual FrameType inputType(unsigned long idx) const { return kFrameAny; }
62+
virtual FrameType outputType(unsigned long idx) const { return kFrameAny; }
63+
64+
// N.B. - Nothing can be acheived by setting a fixed input, so ignore this
65+
66+
virtual void setFixedInput(unsigned long idx, double *input, unsigned long size) {}
67+
68+
// Audio Processing
69+
70+
virtual void blockUpdate(double **ins, double **outs, unsigned long blockSize) {}
71+
virtual void reset(double samplingRate, unsigned long maxBlockSize);
72+
73+
virtual const FrameLib_Parameters *getParameters() const { return &mParameters; }
74+
75+
// Ordering Connections
76+
77+
virtual void autoOrderingConnections() {};
78+
virtual void clearAutoOrderingConnections() {};
79+
80+
private:
81+
82+
// Data
83+
84+
long mNumIns;
85+
long mNumOuts;
86+
87+
std::vector<Select *> mSelects;
88+
FrameLib_Parameters mParameters;
89+
static ParameterInfo sParamInfo;
90+
};
91+
92+
#endif

FrameLib_Objects/Routing/FrameLib_Route.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
// Constructor
77

8-
FrameLib_Route::Valve::Valve(FrameLib_Context context, FrameLib_Parameters::Serial *serialisedParameters, void *owner, long num) : FrameLib_Processor(context, owner, NULL, 1, 1)
8+
FrameLib_Route::Valve::Valve(FrameLib_Context context, FrameLib_Parameters::Serial *serialisedParameters, void *owner, long num) : FrameLib_Processor(context, owner, NULL, 1, 1), mValveNumber(num)
99
{
1010
mParameters.addInt(kActiveValve, "output", 0);
1111
mParameters.set(serialisedParameters);
1212

13-
mValveNumber = num;
1413
mActiveValve = floor(mParameters.getInt(kActiveValve));
1514

1615
setInputMode(0, false, mValveNumber == mActiveValve, true, kFrameAny);

FrameLib_Objects/Timing/FrameLib_Now.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class FrameLib_Now : public FrameLib_Processor
3535

3636
void objectReset() { calculateMultiplier(); }
3737

38-
3938
// Update and Process
4039

4140
void update();
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
#include "FrameLib_TimeDelta.h"
3+
4+
FrameLib_TimeDelta::FrameLib_TimeDelta(FrameLib_Context context, FrameLib_Parameters::Serial *serialisedParameters, void *owner) : FrameLib_Processor(context, owner, &sParamInfo, 1, 1)
5+
{
6+
mParameters.addEnum(kUnits, "units", 0);
7+
mParameters.addEnumItem(kSamples, "samples");
8+
mParameters.addEnumItem(kMS, "ms");
9+
mParameters.addEnumItem(kSeconds, "seconds");
10+
mParameters.setInstantiation();
11+
12+
mParameters.set(serialisedParameters);
13+
14+
calculateMultiplier();
15+
}
16+
17+
// Info
18+
19+
std::string FrameLib_TimeDelta::objectInfo(bool verbose)
20+
{
21+
return formatInfo("Outputs the current time in the specified units: Output is a single value.",
22+
"Outputs the current time in the specified units.", verbose);
23+
}
24+
25+
std::string FrameLib_TimeDelta::inputInfo(unsigned long idx, bool verbose)
26+
{
27+
return formatInfo("Trigger Input - input frames generate output", "Trigger Input", verbose);
28+
}
29+
30+
std::string FrameLib_TimeDelta::outputInfo(unsigned long idx, bool verbose)
31+
{
32+
return "Output Values";
33+
}
34+
35+
// Parameter Info
36+
37+
FrameLib_TimeDelta::ParameterInfo FrameLib_TimeDelta::sParamInfo;
38+
39+
FrameLib_TimeDelta::ParameterInfo::ParameterInfo()
40+
{
41+
add("Sets the time units used to for output.");
42+
}
43+
44+
// Calculate Multiplier
45+
46+
void FrameLib_TimeDelta::calculateMultiplier()
47+
{
48+
switch ((Units) (mParameters.getValue(kUnits)))
49+
{
50+
case kMS: mMultiplier = 1000.0 / FrameLib_TimeFormat(mSamplingRate); break;
51+
case kSeconds: mMultiplier = 1.0 / FrameLib_TimeFormat(mSamplingRate); break;
52+
case kSamples: mMultiplier = FrameLib_TimeFormat(1); break;
53+
}
54+
}
55+
56+
// Object Reset
57+
58+
void FrameLib_TimeDelta::objectReset()
59+
{
60+
mLastTime = FrameLib_TimeFormat(1);
61+
calculateMultiplier();
62+
}
63+
64+
// Update and Process
65+
66+
void FrameLib_TimeDelta::update()
67+
{
68+
if (mParameters.changed(kUnits))
69+
calculateMultiplier();
70+
}
71+
72+
void FrameLib_TimeDelta::process()
73+
{
74+
requestOutputSize(0, 1);
75+
76+
if (allocateOutputs())
77+
{
78+
unsigned long size;
79+
double *output = getOutput(0, &size);
80+
81+
FrameLib_TimeFormat now = getCurrentTime();
82+
83+
output[0] = (now - mLastTime) * mMultiplier;
84+
mLastTime = now;
85+
}
86+
}

0 commit comments

Comments
 (0)