diff --git a/MicroDexed.ino b/MicroDexed.ino index 1a016a6..6a755f2 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -49,7 +49,8 @@ void setup() Serial.begin(115200); //while (!Serial) ; // wait for Arduino Serial Monitor delay(300); - Serial.println(F("MicroDexed")); + Serial.println(F("MicroDexed based on https://github.com/asb2m10/dexed")); + Serial.println(F("(c)2018 H. Wirtz")); Serial.println(F("setup start")); MIDI.begin(MIDI_CHANNEL_OMNI); @@ -59,7 +60,7 @@ void setup() AudioMemory(16); sgtl5000_1.enable(); - sgtl5000_1.volume(0.5); + sgtl5000_1.volume(0.4); // Initialize processor and memory measurements //AudioProcessorUsageMaxReset(); @@ -71,7 +72,7 @@ void setup() int16_t* audio_buffer = queue1.getBuffer(); if (audio_buffer != NULL) { - memset(audio_buffer, 0, AUDIO_BUFFER_SIZE); + memset(audio_buffer, 0, sizeof(int16_t)*AUDIO_BUFFER_SIZE); queue1.playBuffer(); } } @@ -86,6 +87,7 @@ void setup() midi_queue.enqueue(m); m.data1 = TEST_NOTE2; midi_queue.enqueue(m); + m.cmd = 0xb0; #endif threads.addThread(audio_thread, 1); @@ -120,11 +122,12 @@ void loop() void audio_thread(void) { - int16_t* audio_buffer; // pointer for 128 * int16_t - + int16_t* audio_buffer; // pointer to 128 * int16_t + bool break_for_calculation; + Serial.println(F("audio thread start")); - while (42 == 42) + while (42 == 42) // Don't panic! { audio_buffer = queue1.getBuffer(); if (audio_buffer == NULL) @@ -137,8 +140,10 @@ void audio_thread(void) if (midi_queue_lock.lock(MIDI_QUEUE_LOCK_TIMEOUT_MS)) { midi_queue_t m = midi_queue.dequeue(); - dexed->ProcessMidiMessage(m.cmd, m.data1, m.data2); + break_for_calculation=dexed->ProcessMidiMessage(m.cmd, m.data1, m.data2); midi_queue_lock.unlock(); + if(break_for_calculation==true) + break; } else break; diff --git a/controllers.h b/controllers.h index 1f23ab6..f41eba3 100644 --- a/controllers.h +++ b/controllers.h @@ -1,18 +1,18 @@ /* - * Copyright 2013 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + Copyright 2013 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ #ifndef __CONTROLLERS_H #define __CONTROLLERS_H @@ -34,57 +34,56 @@ const int kControllerPitchStep = 2; class FmCore; struct FmMod { - uint8_t range; - bool pitch; - bool amp; - bool eg; - - FmMod() { - range = 0; - pitch = false; - amp = false; - eg = false; - } + uint8_t range; + bool pitch; + bool amp; + bool eg; - void setRange(uint8_t r) { - range = r < 0 && r > 127 ? 0 : r; - } + FmMod() { + range = 0; + pitch = false; + amp = false; + eg = false; + } - void setTarget(uint8_t assign) { - assign=assign < 0 && assign > 7 ? 0 : assign; - pitch=assign&1; // AMP - amp=assign&2; // PITCH - eg=assign&4; // EG + void setRange(uint8_t r) { + range = r < 0 && r > 127 ? 0 : r; + } - } + void setTarget(uint8_t assign) { + assign = assign < 0 && assign > 7 ? 0 : assign; + pitch = assign & 1; // AMP + amp = assign & 2; // PITCH + eg = assign & 4; // EG + } }; class Controllers { void applyMod(int cc, FmMod &mod) { - float range = 0.01 * mod.range; - uint8_t total = (float)cc * range; - if(mod.amp) - amp_mod = max(amp_mod, total); - - if(mod.pitch) - pitch_mod = max(pitch_mod, total); - - if(mod.eg) - eg_mod = max(eg_mod, total); + float range = 0.01 * mod.range; + uint8_t total = (float)cc * range; + if (mod.amp) + amp_mod = max(amp_mod, total); + + if (mod.pitch) + pitch_mod = max(pitch_mod, total); + + if (mod.eg) + eg_mod = max(eg_mod, total); } - -public: + + public: int32_t values_[3]; - + uint8_t amp_mod; uint8_t pitch_mod; uint8_t eg_mod; - + uint8_t aftertouch_cc; uint8_t breath_cc; uint8_t foot_cc; uint8_t modwheel_cc; - + int masterTune; uint8_t opSwitch; @@ -93,25 +92,25 @@ public: FmMod foot; FmMod breath; FmMod at; - + Controllers() { - amp_mod = 0; - pitch_mod = 0; - eg_mod = 0; + amp_mod = 0; + pitch_mod = 0; + eg_mod = 0; } void refresh() { - amp_mod=pitch_mod=eg_mod=0; - - applyMod(modwheel_cc, wheel); - applyMod(breath_cc, breath); - applyMod(foot_cc, foot); - applyMod(aftertouch_cc, at); - - if ( ! ((wheel.eg || foot.eg) || (breath.eg || at.eg)) ) - eg_mod = 127; + amp_mod = pitch_mod = eg_mod = 0; + + applyMod(modwheel_cc, wheel); + applyMod(breath_cc, breath); + applyMod(foot_cc, foot); + applyMod(aftertouch_cc, at); + + if ( ! ((wheel.eg || foot.eg) || (breath.eg || at.eg)) ) + eg_mod = 127; } - + FmCore *core; }; diff --git a/dexed.cpp b/dexed.cpp index 433cc2a..7535757 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -125,6 +125,7 @@ void Dexed::activate(void) panic(); controllers.values_[kControllerPitchRange] = data[155]; controllers.values_[kControllerPitchStep] = data[156]; + controllers.refresh(); } void Dexed::deactivate(void)