/
SomeMoreExperiments.cpp
158 lines (123 loc) · 3.23 KB
/
SomeMoreExperiments.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "SomeMoreExperiments.h"
#include "IPlug_include_in_plug_src.h"
#include "IControl.h"
#include "resource.h"
const int kNumPrograms = 1;
enum EParams
{
kGain = 0,
kNumParams
};
enum ELayout
{
kWidth = GUI_WIDTH,
kHeight = GUI_HEIGHT,
kGainX = 100,
kGainY = 100,
kKnobFrames = 60
};
SomeMoreExperiments::SomeMoreExperiments(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), mGain(1.)
{
TRACE;
//arguments are: name, defaultVal, minVal, maxVal, step, label
GetParam(kGain)->InitDouble("Gain", 50., 0., 100.0, 0.01, "%");
GetParam(kGain)->SetShape(2.);
IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight);
pGraphics->AttachPanelBackground(&COLOR_RED);
IBitmap knob = pGraphics->LoadIBitmap(KNOB_ID, KNOB_FN, kKnobFrames);
pGraphics->AttachControl(new IKnobMultiControl(this, kGainX, kGainY, kGain, &knob));
AttachGraphics(pGraphics);
//MakePreset("preset 1", ... );
MakeDefaultPreset((char *) "-", kNumPrograms);
}
SomeMoreExperiments::~SomeMoreExperiments() {}
void SomeMoreExperiments::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
// Mutex is already locked for us.
double* in1 = inputs[0];
double* in2 = inputs[1];
double* out1 = outputs[0];
double* out2 = outputs[1];
for (int s = 0; s < nFrames; ++s, ++in1, ++in2, ++out1, ++out2)
{
*out1 = *in1 * mGain;
*out2 = *in2 * mGain;
}
ITimeInfo info;
GetTime(&info) ;
double SamplesPerBeat = GetSamplesPerBeat();
}
void SomeMoreExperiments::ProcessMidiMsg(IMidiMsg* pMsg)
{
TRACE;
IMutexLock lock(this);
ITimeInfo info;
GetTime(&info) ;
double SamplesPerBeat = GetSamplesPerBeat();
int status = pMsg->StatusMsg();
int velocity = pMsg->Velocity();
switch (status)
{
// This is a good soultion to get velocity = 0 and NoteOff as NoteOff commands
// since midi controller implments this diferently
case IMidiMsg::kNoteOn:
case IMidiMsg::kNoteOff:
// filter only note messages
if (status == IMidiMsg::kNoteOn && velocity)
{
DBGMSG("NoteOn");
int value = pMsg->NoteNumber();
char szVal[256];
sprintf(szVal,"%d",value);
DBGMSG(szVal);
}
else
{
DBGMSG("NoteOff");
}
break;
case IMidiMsg::kControlChange:
IMidiMsg::EControlChangeMsg controlmsg;
controlmsg = pMsg->ControlChangeIdx();
switch (controlmsg)
{
case IMidiMsg::kModWheel:
DBGMSG("ModWheel");
double value = pMsg->ControlChange(controlmsg);
char szVal[256];
sprintf(szVal,"%f",value);
DBGMSG(szVal);
break;
}
break;
default:
return; // if !note message, nothing gets added to the queue
}
}
void SomeMoreExperiments::Reset()
{
TRACE;
IMutexLock lock(this);
int TaktOben;
int TaktUnten;
GetTimeSig(&TaktOben, &TaktUnten);
double fs = GetSampleRate();
int SamplesSinceStart = GetSamplePos(); // Samples since start of project.
double Tempo = GetTempo();
double SamplesPerBeat = GetSamplesPerBeat();
ITimeInfo info;
GetTime(&info) ;
}
void SomeMoreExperiments::OnParamChange(int paramIdx)
{
IMutexLock lock(this);
switch (paramIdx)
{
case kGain:
mGain = GetParam(kGain)->Value() / 100.;
break;
default:
break;
}
}