@@ -34,6 +34,20 @@ struct MIDIClockToCVInterface : MidiIO, Module { | |||||
bool reset = false; | bool reset = false; | ||||
int c_bar = 0; | 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) { | MIDIClockToCVInterface() : MidiIO(), Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { | ||||
@@ -74,19 +88,8 @@ struct MIDIClockToCVInterface : MidiIO, Module { | |||||
}; | }; | ||||
void MIDIClockToCVInterface::step() { | void MIDIClockToCVInterface::step() { | ||||
static float trigger_length = 0.05; | |||||
float sampleRate = engineGetSampleRate(); | 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()) { | if (isPortOpen()) { | ||||
static std::vector<unsigned char> message; | static std::vector<unsigned char> message; | ||||
@@ -107,7 +110,7 @@ void MIDIClockToCVInterface::step() { | |||||
} | } | ||||
if (reset) { | if (reset) { | ||||
resetPulse.trigger(trigger_length); | |||||
resetPulse.trigger(pulseTime); | |||||
reset = false; | reset = false; | ||||
c_bar = 0; | c_bar = 0; | ||||
clock1Pulse.time = 0.0; | clock1Pulse.time = 0.0; | ||||
@@ -126,11 +129,11 @@ void MIDIClockToCVInterface::step() { | |||||
*/ | */ | ||||
if (running) { | if (running) { | ||||
if (c_bar % ratios[clock1ratio] == 0) { | if (c_bar % ratios[clock1ratio] == 0) { | ||||
clock1Pulse.trigger(trigger_length); | |||||
clock1Pulse.trigger(pulseTime); | |||||
} | } | ||||
if (c_bar % ratios[clock2ratio] == 0) { | if (c_bar % ratios[clock2ratio] == 0) { | ||||
clock2Pulse.trigger(trigger_length); | |||||
clock2Pulse.trigger(pulseTime); | |||||
} | } | ||||
} | } | ||||
@@ -50,7 +50,7 @@ void MidiIO::baseFromJson(json_t *rootJ) { | |||||
std::vector<std::string> MidiIO::getDevices() { | std::vector<std::string> MidiIO::getDevices() { | ||||
/* Note: we could also use an existing interface if one exists */ | /* Note: we could also use an existing interface if one exists */ | ||||
static RtMidiIn *m = new RtMidiIn(); | |||||
RtMidiIn *m = new RtMidiIn(); | |||||
std::vector<std::string> names = {}; | std::vector<std::string> names = {}; | ||||
@@ -48,6 +48,10 @@ struct MidiInWrapper : RtMidiIn { | |||||
} | } | ||||
}; | }; | ||||
/** | |||||
* Note: MidiIO is not thread safe which might become | |||||
* important in the future | |||||
*/ | |||||
struct MidiIO { | struct MidiIO { | ||||
private: | private: | ||||
static std::unordered_map<std::string, MidiInWrapper *> midiInMap; | static std::unordered_map<std::string, MidiInWrapper *> midiInMap; | ||||
@@ -84,7 +84,7 @@ void MIDIToCVInterface::resetMidi() { | |||||
} | } | ||||
void MIDIToCVInterface::step() { | void MIDIToCVInterface::step() { | ||||
static float sampleRate = engineGetSampleRate(); | |||||
float sampleRate = engineGetSampleRate(); | |||||
if (isPortOpen()) { | if (isPortOpen()) { | ||||
std::vector<unsigned char> message; | std::vector<unsigned char> message; | ||||
@@ -94,11 +94,12 @@ void QuadMIDIToCVInterface::resetMidi() { | |||||
} | } | ||||
void QuadMIDIToCVInterface::step() { | void QuadMIDIToCVInterface::step() { | ||||
static float sampleRate = engineGetSampleRate(); | |||||
static int msgsProcessed = 0; | |||||
float sampleRate = engineGetSampleRate(); | |||||
if (isPortOpen()) { | if (isPortOpen()) { | ||||
std::vector<unsigned char> message; | std::vector<unsigned char> message; | ||||
int msgsProcessed = 0; | |||||
// midiIn->getMessage returns empty vector if there are no messages in the queue | // 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 | // NOTE: For the quadmidi we will process max 4 midi messages per step to avoid | ||||
@@ -109,7 +110,6 @@ void QuadMIDIToCVInterface::step() { | |||||
getMessage(&message); | getMessage(&message); | ||||
msgsProcessed++; | msgsProcessed++; | ||||
} | } | ||||
msgsProcessed = 0; | |||||
} | } | ||||