Skip to content

Commit

Permalink
Daisy: suppport more midi (#137)
Browse files Browse the repository at this point in the history
* suppport midierealtimein

* add polytouchin/out to daisy

* update docs

* daisy midiin; dpf fix midiout
  • Loading branch information
dromer authored Nov 21, 2023
1 parent d9f9648 commit 7952a53
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 43 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Next Release
* Objects: `[bang~]`
* Documentation fixes/additions
* Daisy: ability to set samplerate and blocksize
* 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
Expand Down
2 changes: 1 addition & 1 deletion docs/03.gen.daisy.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Additionally `usb_midi`, running on the onboard micro-usb, can be enabled separa

At the moment all midi messages will be merged between USB and UART MIDI interfaces. In the future it will likely be possible to assign additional UART pins and group them under a specific PD midi "port".

Currently supported MIDI messages are: Note On/Off, Control Change, Program Change, Channel Pressure, and Pitch Bend.
Currently supported MIDI messages are: Note On/Off, Poly Aftertouch, Control Change, Program Change, Channel Pressure, Pitch Bend, and Midi Realtime messages.

## [print] object

Expand Down
4 changes: 3 additions & 1 deletion hvcc/generators/c2daisy/c2daisy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
hv_midi_messages = {
"__hv_noteout",
"__hv_ctlout",
"__hv_polytouchout",
"__hv_pgmout",
"__hv_touchout",
"__hv_bendout",
"__hv_midiout"
"__hv_midiout",
"__hv_midioutport"
}


Expand Down
101 changes: 81 additions & 20 deletions hvcc/generators/c2daisy/templates/HeavyDaisy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{% if has_midi or usb_midi %}
#define HV_HASH_NOTEIN 0x67E37CA3
#define HV_HASH_CTLIN 0x41BE0f9C
#define HV_HASH_POLYTOUCHIN 0xBC530F59
#define HV_HASH_PGMIN 0x2E1EA03D
#define HV_HASH_TOUCHIN 0x553925BD
#define HV_HASH_BENDIN 0x3083F0F7
Expand All @@ -17,6 +18,7 @@

#define HV_HASH_NOTEOUT 0xD1D4AC2
#define HV_HASH_CTLOUT 0xE5e2A040
#define HV_HASH_POLYTOUCHOUT 0xD5ACA9D1
#define HV_HASH_PGMOUT 0x8753E39E
#define HV_HASH_TOUCHOUT 0x476D4387
#define HV_HASH_BENDOUT 0xE8458013
Expand Down Expand Up @@ -46,6 +48,8 @@ FIFO<FixedCapStr<64>, 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();
Expand Down Expand Up @@ -95,8 +99,43 @@ 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: {
float srtType;

switch(m.srt_type)
{
case TimingClock:
srtType = MIDI_RT_CLOCK;
break;
case Start:
srtType = MIDI_RT_START;
break;
case Continue:
srtType = MIDI_RT_CONTINUE;
break;
case Stop:
srtType = MIDI_RT_STOP;
break;
case ActiveSensing:
srtType = MIDI_RT_ACTIVESENSE;
break;
case Reset:
srtType = MIDI_RT_RESET;
break;
}

hv.sendMessageToReceiverV(HV_HASH_MIDIREALTIMEIN, 0, "ff",
(float) srtType);
break;
}
case NoteOff: {
NoteOnEvent p = m.AsNoteOn();
hv.sendMessageToReceiverV(HV_HASH_NOTEIN, 0, "fff",
Expand All @@ -113,6 +152,14 @@ void HandleMidiMessage(MidiEvent m)
(float) p.channel);
break;
}
case PolyphonicKeyPressure: { // polyphonic aftertouch
PolyphonicKeyPressureEvent p = m.AsPolyphonicKeyPressure();
hv.sendMessageToReceiverV(HV_HASH_POLYTOUCHIN, 0, "fff",
(float) p.pressure, // pressure
(float) p.note, // note
(float) p.channel);
break;
}
case ControlChange: {
ControlChangeEvent p = m.AsControlChange();
hv.sendMessageToReceiverV(HV_HASH_CTLIN, 0, "fff",
Expand Down Expand Up @@ -283,6 +330,22 @@ void HandleMidiSend(uint32_t sendHash, const HvMessage *m)
HandleMidiOut(midiData, numElements);
break;
}
case HV_HASH_POLYTOUCHOUT:
{
uint8_t value = hv_msg_getFloat(m, 0);
uint8_t note = hv_msg_getFloat(m, 1);
uint8_t ch = hv_msg_getFloat(m, 2);
ch %= 16; // drop any pd "ports"

const uint8_t numElements = 3;
uint8_t midiData[numElements];
midiData[0] = 0xA0 | ch; // send Poly Aftertouch
midiData[1] = note;
midiData[2] = value;

HandleMidiOut(midiData, numElements);
break;
}
case HV_HASH_CTLOUT:
{
uint8_t value = hv_msg_getFloat(m, 0);
Expand Down Expand Up @@ -344,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;
}
Expand Down
4 changes: 4 additions & 0 deletions hvcc/generators/c2dpf/templates/HeavyDPF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ class {{class_name}} : public Plugin
double nextClockTick;
double sampleAtCycleStart;

// midi out buffer
int midiOutCount;
MidiEvent midiOutEvent;

// heavy context
HeavyContextInterface *_context;

Expand Down
32 changes: 12 additions & 20 deletions hvcc/generators/c2dpf/templates/HeavyDPF_MIDI_Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7952a53

Please sign in to comment.