From ac6ada1302475a2a8ebb0fc3047096e78d469a00 Mon Sep 17 00:00:00 2001 From: dreamer Date: Tue, 21 Nov 2023 10:39:53 +0100 Subject: [PATCH] daisy midiin; dpf fix midiout --- CHANGELOG.md | 4 +- hvcc/generators/c2daisy/c2daisy.py | 3 +- .../c2daisy/templates/HeavyDaisy.cpp | 46 +++++++++++-------- hvcc/generators/c2dpf/templates/HeavyDPF.hpp | 4 ++ .../c2dpf/templates/HeavyDPF_MIDI_Output.cpp | 32 +++++-------- 5 files changed, 46 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f2171f9..52460762 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,9 @@ Next Release * Objects: `[bang~]` * Documentation fixes/additions * Daisy: ability to set samplerate and blocksize -* Daisy: adding midirealtimein, polytouchin/out +* Daisy: adding midirealtimein, polytouchin/out, midiin (midiout WIP) * DPF: enum for UI parameter IDs -* DPF bugfixes: correct input PortGroup names; correct UI slider updates +* DPF bugfixes: correct input PortGroup names; correct UI slider updates; midiout reimplementation * Cleanup: remove deprecated build.json 0.9.0 diff --git a/hvcc/generators/c2daisy/c2daisy.py b/hvcc/generators/c2daisy/c2daisy.py index 693d5312..00a8d41f 100644 --- a/hvcc/generators/c2daisy/c2daisy.py +++ b/hvcc/generators/c2daisy/c2daisy.py @@ -17,7 +17,8 @@ "__hv_pgmout", "__hv_touchout", "__hv_bendout", - "__hv_midiout" + "__hv_midiout", + "__hv_midioutport" } diff --git a/hvcc/generators/c2daisy/templates/HeavyDaisy.cpp b/hvcc/generators/c2daisy/templates/HeavyDaisy.cpp index 90d20d10..e957dca8 100644 --- a/hvcc/generators/c2daisy/templates/HeavyDaisy.cpp +++ b/hvcc/generators/c2daisy/templates/HeavyDaisy.cpp @@ -48,6 +48,8 @@ FIFO, 64> event_log; {% elif usb_midi %} daisy::MidiUsbHandler midiusb; {% endif %} +// int midiOutCount; +// uint8_t* midiOutData; void CallbackWriteIn(Heavy_{{patch_name}}& hv); void LoopWriteIn(Heavy_{{patch_name}}& hv); void CallbackWriteOut(); @@ -97,6 +99,12 @@ DaisyHvParamOut DaisyOutputParameters[DaisyNumOutputParameters] = { // Typical Switch case for Message Type. void HandleMidiMessage(MidiEvent m) { + for (int i = 0; i <= 2; ++i) { + hv.sendMessageToReceiverV(HV_HASH_MIDIIN, 0, "ff", + (float) m.data[i], + (float) m.channel); + } + switch(m.type) { case SystemRealTime: { @@ -399,26 +407,24 @@ void HandleMidiSend(uint32_t sendHash, const HvMessage *m) HandleMidiOut(midiData, numElements); break; } - case HV_HASH_MIDIOUT: // __hv_midiout - { - const uint8_t numElements = m->numElements; - uint8_t midiData[numElements]; - if (numElements <=4 ) - { - for (int i = 0; i < numElements; ++i) - { - midiData[i] = hv_msg_getFloat(m, i); - } - } - else - { - // we do not support sysex yet - break; - } - - HandleMidiOut(midiData, numElements); - break; - } + // not functional yet + // case HV_HASH_MIDIOUT: // __hv_midiout + // { + // if (midiOutCount == 0 ) { + // uint8_t midiOutData[3]; + // } + + // midiOutData[midiOutCount] = hv_msg_getFloat(m, 0); + + // if (midiOutCount < 2) { + // midiOutCount++; + // break; + // } + + // HandleMidiOut(midiOutData, 3); + // midiOutCount = 0; + // break; + // } default: break; } diff --git a/hvcc/generators/c2dpf/templates/HeavyDPF.hpp b/hvcc/generators/c2dpf/templates/HeavyDPF.hpp index 4bc6e079..df6480cd 100644 --- a/hvcc/generators/c2dpf/templates/HeavyDPF.hpp +++ b/hvcc/generators/c2dpf/templates/HeavyDPF.hpp @@ -146,6 +146,10 @@ class {{class_name}} : public Plugin double nextClockTick; double sampleAtCycleStart; + // midi out buffer + int midiOutCount; + MidiEvent midiOutEvent; + // heavy context HeavyContextInterface *_context; diff --git a/hvcc/generators/c2dpf/templates/HeavyDPF_MIDI_Output.cpp b/hvcc/generators/c2dpf/templates/HeavyDPF_MIDI_Output.cpp index d7593ea2..cdaaa039 100644 --- a/hvcc/generators/c2dpf/templates/HeavyDPF_MIDI_Output.cpp +++ b/hvcc/generators/c2dpf/templates/HeavyDPF_MIDI_Output.cpp @@ -100,30 +100,22 @@ void {{class_name}}::handleMidiSend(uint32_t sendHash, const HvMessage *m) } case HV_HASH_MIDIOUT: // __hv_midiout { - const uint8_t numElements = m->numElements; - if (numElements <=4 ) - { - for (int i = 0; i < numElements; ++i) - { - midiSendEvent.data[i] = hv_msg_getFloat(m, i); - } - } - else - { - printf("> we do not support sysex yet \n"); - break; + if (midiOutCount == 0) { + midiOutEvent.frame = 0; + midiOutEvent.dataExt = nullptr; + // we don't support sysex + midiOutEvent.size = 4; } - // unsigned char* rawData = new unsigned char; - // for (int i = 0; i < numElements; ++i) { - // rawData[i] = (uint8_t) hv_msg_getFloat(m, i); - // printf("> data: %d \n", rawData[i]); - // } + midiOutEvent.data[midiOutCount] = hv_msg_getFloat(m, 0); - midiSendEvent.size = numElements; - // midiSendEvent.dataExt = (const uint8_t *) rawData; + if (midiOutCount < 3) { + midiOutCount++; + break; + } - writeMidiEvent(midiSendEvent); + writeMidiEvent(midiOutEvent); + midiOutCount = 0; break; } default: