diff --git a/src/Core/MIDIToCVInterface.cpp b/src/Core/MIDIToCVInterface.cpp index 8ac7447d..534fc001 100644 --- a/src/Core/MIDIToCVInterface.cpp +++ b/src/Core/MIDIToCVInterface.cpp @@ -1,5 +1,6 @@ #include "Core.hpp" #include "midi.hpp" +#include "dsp/digital.hpp" #include "dsp/filter.hpp" #include @@ -43,6 +44,10 @@ struct MIDIToCVInterface : Module { ExponentialFilter modFilter; uint16_t pitch = 0; ExponentialFilter pitchFilter; + PulseGenerator startPulse; + PulseGenerator stopPulse; + PulseGenerator continuePulse; + PulseGenerator clockPulse; MidiNoteData noteData[128]; std::list heldNotes; @@ -102,21 +107,28 @@ struct MIDIToCVInterface : Module { while (midiInput.shift(&msg)) { processMessage(msg); } + float deltaTime = engineGetSampleTime(); outputs[CV_OUTPUT].value = (lastNote - 60) / 12.f; outputs[GATE_OUTPUT].value = gate ? 10.f : 0.f; outputs[VELOCITY_OUTPUT].value = rescale(noteData[lastNote].velocity, 0, 127, 0.f, 10.f); - modFilter.lambda = 100.f * engineGetSampleTime(); + modFilter.lambda = 100.f * deltaTime; outputs[MOD_OUTPUT].value = modFilter.process(rescale(mod, 0, 127, 0.f, 10.f)); - pitchFilter.lambda = 100.f * engineGetSampleTime(); + pitchFilter.lambda = 100.f * deltaTime; outputs[PITCH_OUTPUT].value = pitchFilter.process(rescale(pitch, 0, 16384, -5.f, 5.f)); outputs[AFTERTOUCH_OUTPUT].value = rescale(noteData[lastNote].aftertouch, 0, 127, 0.f, 10.f); + + outputs[START_OUTPUT].value = startPulse.process(deltaTime) ? 10.f : 0.f; + outputs[STOP_OUTPUT].value = stopPulse.process(deltaTime) ? 10.f : 0.f; + outputs[CONTINUE_OUTPUT].value = continuePulse.process(deltaTime) ? 10.f : 0.f; + + outputs[CLOCK_OUTPUT].value = clockPulse.process(deltaTime) ? 10.f : 0.f; } void processMessage(MidiMessage msg) { - debug("MIDI: %01x %01x %02x %02x", msg.status(), msg.channel(), msg.data1, msg.data2); + // debug("MIDI: %01x %01x %02x %02x", msg.status(), msg.channel(), msg.data1, msg.data2); switch (msg.status()) { // note off @@ -174,17 +186,21 @@ struct MIDIToCVInterface : Module { void processSystem(MidiMessage msg) { switch (msg.channel()) { + // Timing case 0x8: { - debug("timing clock"); + clockPulse.trigger(1e-3); } break; + // Start case 0xa: { - debug("start"); + startPulse.trigger(1e-3); } break; + // Continue case 0xb: { - debug("continue"); + continuePulse.trigger(1e-3); } break; + // Stop case 0xc: { - debug("stop"); + stopPulse.trigger(1e-3); } break; default: break; } diff --git a/src/midi.cpp b/src/midi.cpp index 6cb96b9f..2279bc83 100644 --- a/src/midi.cpp +++ b/src/midi.cpp @@ -129,18 +129,20 @@ static void midiInputCallback(double timeStamp, std::vector *mess MidiInput *midiInput = (MidiInput*) userData; if (!midiInput) return; - MidiMessage midiMessage; + MidiMessage msg; if (message->size() >= 1) - midiMessage.cmd = (*message)[0]; + msg.cmd = (*message)[0]; if (message->size() >= 2) - midiMessage.data1 = (*message)[1]; + msg.data1 = (*message)[1]; if (message->size() >= 3) - midiMessage.data2 = (*message)[2]; + msg.data2 = (*message)[2]; // Filter channel - if (midiInput->channel >= 0 && (midiMessage.channel() != midiInput->channel)) - return; - midiInput->onMessage(midiMessage); + if (midiInput->channel >= 0) { + if (msg.status() != 0xf && msg.channel() != midiInput->channel) + return; + } + midiInput->onMessage(msg); } MidiInput::MidiInput() { @@ -157,7 +159,7 @@ void MidiInput::setDriver(int driver) { if (driver >= 0) { rtMidiIn = new RtMidiIn((RtMidi::Api) driver); rtMidiIn->setCallback(midiInputCallback, this); - rtMidiIn->ignoreTypes(enableSysEx, enableTime, enableSense); + rtMidiIn->ignoreTypes(!enableSysEx, !enableTime, !enableSense); rtMidi = rtMidiIn; this->driver = rtMidiIn->getCurrentApi(); }