diff --git a/src/core/MidiClockToCV.cpp b/src/core/MidiClockToCV.cpp index 2e0a0f7d..b19603a6 100644 --- a/src/core/MidiClockToCV.cpp +++ b/src/core/MidiClockToCV.cpp @@ -34,6 +34,20 @@ struct MIDIClockToCVInterface : MidiIO, Module { bool reset = false; int c_bar = 0; + /* Note this is in relation to the Midi clock's Tick (6x per 16th note). + * Therefore, e.g. the 2:3 is calculated: + * + * 24 (Ticks per quarter note) * 2 / 3 = 16 + * + * Implying that every 16 midi clock ticks we need to send a pulse + * */ + int ratios[] = {6, 8, 12, 16, 24, 32, 48, 96, 192}; + int numratios = sizeof(ratios) / sizeof(*ratios); + + /* + * Length of clock pulse + */ + float pulseTime = 0.05; MIDIClockToCVInterface() : MidiIO(), Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { @@ -74,19 +88,8 @@ struct MIDIClockToCVInterface : MidiIO, Module { }; void MIDIClockToCVInterface::step() { - static float trigger_length = 0.05; float sampleRate = engineGetSampleRate(); - /* Note this is in relation to the Midi clock's Tick (6x per 16th note). - * Therefore, e.g. the 2:3 is calculated: - * - * 24 (Ticks per quarter note) * 2 / 3 = 16 - * - * Implying that every 16 midi clock ticks we need to send a pulse - * */ - static int ratios[] = {6, 8, 12, 16, 24, 32, 48, 96, 192}; - static int numratios = sizeof(ratios) / sizeof(*ratios); - if (isPortOpen()) { static std::vector message; @@ -107,7 +110,7 @@ void MIDIClockToCVInterface::step() { } if (reset) { - resetPulse.trigger(trigger_length); + resetPulse.trigger(pulseTime); reset = false; c_bar = 0; clock1Pulse.time = 0.0; @@ -126,11 +129,11 @@ void MIDIClockToCVInterface::step() { */ if (running) { if (c_bar % ratios[clock1ratio] == 0) { - clock1Pulse.trigger(trigger_length); + clock1Pulse.trigger(pulseTime); } if (c_bar % ratios[clock2ratio] == 0) { - clock2Pulse.trigger(trigger_length); + clock2Pulse.trigger(pulseTime); } } diff --git a/src/core/MidiIO.cpp b/src/core/MidiIO.cpp index ab485cfa..22c6f444 100644 --- a/src/core/MidiIO.cpp +++ b/src/core/MidiIO.cpp @@ -50,7 +50,7 @@ void MidiIO::baseFromJson(json_t *rootJ) { std::vector MidiIO::getDevices() { /* Note: we could also use an existing interface if one exists */ - static RtMidiIn *m = new RtMidiIn(); + RtMidiIn *m = new RtMidiIn(); std::vector names = {}; diff --git a/src/core/MidiIO.hpp b/src/core/MidiIO.hpp index eee405f6..106f4a6e 100644 --- a/src/core/MidiIO.hpp +++ b/src/core/MidiIO.hpp @@ -48,6 +48,10 @@ struct MidiInWrapper : RtMidiIn { } }; +/** + * Note: MidiIO is not thread safe which might become + * important in the future + */ struct MidiIO { private: static std::unordered_map midiInMap; diff --git a/src/core/MidiToCV.cpp b/src/core/MidiToCV.cpp index 4e12a25a..14d8c8b0 100644 --- a/src/core/MidiToCV.cpp +++ b/src/core/MidiToCV.cpp @@ -84,7 +84,7 @@ void MIDIToCVInterface::resetMidi() { } void MIDIToCVInterface::step() { - static float sampleRate = engineGetSampleRate(); + float sampleRate = engineGetSampleRate(); if (isPortOpen()) { std::vector message; diff --git a/src/core/QuadMidiToCV.cpp b/src/core/QuadMidiToCV.cpp index 5f27f7b3..3b9b50af 100644 --- a/src/core/QuadMidiToCV.cpp +++ b/src/core/QuadMidiToCV.cpp @@ -94,11 +94,12 @@ void QuadMIDIToCVInterface::resetMidi() { } void QuadMIDIToCVInterface::step() { - static float sampleRate = engineGetSampleRate(); - static int msgsProcessed = 0; + float sampleRate = engineGetSampleRate(); + if (isPortOpen()) { std::vector message; + int msgsProcessed = 0; // midiIn->getMessage returns empty vector if there are no messages in the queue // NOTE: For the quadmidi we will process max 4 midi messages per step to avoid @@ -109,7 +110,6 @@ void QuadMIDIToCVInterface::step() { getMessage(&message); msgsProcessed++; } - msgsProcessed = 0; }