File: VolcaBeatsControl.cpp

package info (click to toggle)
bespokesynth 1.3.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,716 kB
  • sloc: cpp: 117,136; ansic: 18,752; python: 593; xml: 74; makefile: 4
file content (225 lines) | stat: -rw-r--r-- 6,889 bytes parent folder | download | duplicates (2)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**
    bespoke synth, a software modular synthesizer
    Copyright (C) 2021 Ryan Challinor (contact: awwbees@gmail.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/
/*
  ==============================================================================

    VolcaBeatsControl.cpp
    Created: 28 Jan 2017 10:48:14pm
    Author:  Ryan Challinor

  ==============================================================================
*/

#include "VolcaBeatsControl.h"
#include "OpenFrameworksPort.h"
#include "Scale.h"
#include "ModularSynth.h"

VolcaBeatsControl::VolcaBeatsControl()
{
   for (int i = 0; i < 10; ++i)
   {
      mLevels[i] = 1;
      mLevelSliders[i] = nullptr;
   }
}

VolcaBeatsControl::~VolcaBeatsControl()
{
}

void VolcaBeatsControl::CreateUIControls()
{
   IDrawableModule::CreateUIControls();

   mClapSpeedSlider = new FloatSlider(this, "clap speed", 5, 5, 140, 15, &mClapSpeed, 0, 1);
   mClaveSpeedSlider = new FloatSlider(this, "clave speed", mClapSpeedSlider, kAnchor_Below, 140, 15, &mClaveSpeed, 0, 1);
   mAgogoSpeedSlider = new FloatSlider(this, "agogo speed", mClaveSpeedSlider, kAnchor_Below, 140, 15, &mAgogoSpeed, 0, 1);
   mCrashSpeedSlider = new FloatSlider(this, "crash speed", mAgogoSpeedSlider, kAnchor_Below, 140, 15, &mCrashSpeed, 0, 1);
   mStutterTimeSlider = new FloatSlider(this, "stutter time", mCrashSpeedSlider, kAnchor_Below, 140, 15, &mStutterTime, 0, 1);
   mStutterDepthSlider = new FloatSlider(this, "stutter depth", mStutterTimeSlider, kAnchor_Below, 140, 15, &mStutterDepth, 0, 1);
   mTomDecaySlider = new FloatSlider(this, "tom decay", mStutterDepthSlider, kAnchor_Below, 140, 15, &mTomDecay, 0, 1);
   mClosedHatDecaySlider = new FloatSlider(this, "closed hat decay", mTomDecaySlider, kAnchor_Below, 140, 15, &mClosedHatDecay, 0, 1);
   mOpenHatDecaySlider = new FloatSlider(this, "open hat decay", mClosedHatDecaySlider, kAnchor_Below, 140, 15, &mOpenHatDecay, 0, 1);
   mHatGrainSlider = new FloatSlider(this, "hat grain", mOpenHatDecaySlider, kAnchor_Below, 140, 15, &mHatGrain, 0, 1);

   for (int i = 0; i < 10; ++i)
   {
      mLevelSliders[i] = new FloatSlider(this, ("level " + ofToString(i)).c_str(), 155, 5, 100, 15, &mLevels[i], 0, 1);
      if (i > 0)
         mLevelSliders[i]->PositionTo(mLevelSliders[i - 1], kAnchor_Below);
   }
}

void VolcaBeatsControl::DrawModule()
{
   if (Minimized() || IsVisible() == false)
      return;

   mClapSpeedSlider->Draw();
   mClaveSpeedSlider->Draw();
   mAgogoSpeedSlider->Draw();
   mCrashSpeedSlider->Draw();
   mStutterTimeSlider->Draw();
   mStutterDepthSlider->Draw();
   mTomDecaySlider->Draw();
   mClosedHatDecaySlider->Draw();
   mOpenHatDecaySlider->Draw();
   mHatGrainSlider->Draw();
   for (int i = 0; i < 10; ++i)
      mLevelSliders[i]->Draw();
}

void VolcaBeatsControl::PlayNote(double time, int pitch, int velocity, int voiceIdx, ModulationParameters modulation)
{
   if (!mEnabled)
   {
      PlayNoteOutput(time, pitch, velocity, voiceIdx, modulation);
      return;
   }

   if (pitch < 10)
   {
      mLevelSliders[pitch]->Compute();
      velocity *= mLevels[pitch];
   }

   switch (pitch)
   {
      case 0: //kick
         pitch = 36;
         if (velocity > 0)
            SendCC(40, velocity);
         break;
      case 1: //snare
         pitch = 38;
         if (velocity > 0)
            SendCC(41, velocity);
         break;
      case 2: //closed
         pitch = 42;
         if (velocity > 0)
         {
            SendCC(44, velocity);
            mClosedHatDecaySlider->Compute();
            mHatGrainSlider->Compute();
         }
         break;
      case 3: //ride
         pitch = 67;
         if (velocity > 0)
         {
            SendCC(48, velocity);
            mAgogoSpeedSlider->Compute();
         }
         break;
      case 4: //clap
         pitch = 39;
         if (velocity > 0)
         {
            SendCC(46, velocity);
            mClapSpeedSlider->Compute();
         }
         break;
      case 5: //crash
         pitch = 49;
         if (velocity > 0)
         {
            SendCC(49, velocity);
            mCrashSpeedSlider->Compute();
         }
         break;
      case 6: //open
         pitch = 46;
         if (velocity > 0)
         {
            SendCC(45, velocity);
            mOpenHatDecaySlider->Compute();
            mHatGrainSlider->Compute();
         }
         break;
      case 7: //stick
         pitch = 75;
         if (velocity > 0)
         {
            SendCC(47, velocity);
            mClaveSpeedSlider->Compute();
         }
         break;
      case 8: //floor
         pitch = 43;
         if (velocity > 0)
         {
            SendCC(42, velocity);
            mTomDecaySlider->Compute();
         }
         break;
      case 9: //low
         pitch = 50;
         if (velocity > 0)
         {
            SendCC(43, velocity);
            mTomDecaySlider->Compute();
         }
         break;
      default:
         pitch = -1;
   }

   mStutterTimeSlider->Compute();
   mStutterDepthSlider->Compute();

   if (pitch != -1)
      PlayNoteOutput(time, pitch, velocity, voiceIdx, modulation);
}

void VolcaBeatsControl::FloatSliderUpdated(FloatSlider* slider, float oldVal, double time)
{
   if (slider == mClapSpeedSlider)
      SendCC(50, (int)(mClapSpeed * 127));
   if (slider == mClaveSpeedSlider)
      SendCC(51, (int)(mClaveSpeed * 127));
   if (slider == mAgogoSpeedSlider)
      SendCC(52, (int)(mAgogoSpeed * 127));
   if (slider == mCrashSpeedSlider)
      SendCC(53, (int)(mCrashSpeed * 127));
   if (slider == mStutterTimeSlider)
      SendCC(54, (int)(mStutterTime * 127));
   if (slider == mStutterDepthSlider)
      SendCC(55, (int)(mStutterDepth * 127));
   if (slider == mTomDecaySlider)
      SendCC(56, (int)(mTomDecay * 127));
   if (slider == mClosedHatDecaySlider)
      SendCC(57, (int)(mClosedHatDecay * 127));
   if (slider == mOpenHatDecaySlider)
      SendCC(58, (int)(mOpenHatDecay * 127));
   if (slider == mHatGrainSlider)
      SendCC(59, (int)(mHatGrain * 127));
}

void VolcaBeatsControl::LoadLayout(const ofxJSONElement& moduleInfo)
{
   mModuleSaveData.LoadString("target", moduleInfo);

   SetUpFromSaveData();
}

void VolcaBeatsControl::SetUpFromSaveData()
{
   SetUpPatchCables(mModuleSaveData.GetString("target"));
}