From 073b54d03941ddac392fe96c4033b2c076158b18 Mon Sep 17 00:00:00 2001 From: bsp2 Date: Sun, 10 Mar 2019 12:05:30 +0100 Subject: [PATCH] support channel aftertouch --- include/midi.hpp | 28 +++++++++++++++++----------- src/Core/MIDIToCVInterface.cpp | 11 ++++++++--- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/include/midi.hpp b/include/midi.hpp index db2974dd..4b507b25 100644 --- a/include/midi.hpp +++ b/include/midi.hpp @@ -11,21 +11,27 @@ namespace rack { struct MidiMessage { - uint8_t cmd = 0x00; - uint8_t data1 = 0x00; - uint8_t data2 = 0x00; + uint8_t cmd = 0u; + uint8_t data1 = 0u; + uint8_t data2 = 0u; - uint8_t channel() { - return cmd & 0xf; + uint8_t channel() const { + return cmd & 15u; } - uint8_t status() { - return (cmd >> 4) & 0xf; + uint8_t status() const { + return (cmd >> 4) & 15u; } - uint8_t note() { - return data1 & 0x7f; + uint8_t note() const { + return data1 & 127u; } - uint8_t value() { - return data2 & 0x7f; + uint8_t value() const { + return data2 & 127u; + } + uint8_t getData1() const { + return data1 & 127u; + } + uint8_t getData2() const { + return data2 & 127u; } }; diff --git a/src/Core/MIDIToCVInterface.cpp b/src/Core/MIDIToCVInterface.cpp index 00ba915f..57c8d074 100644 --- a/src/Core/MIDIToCVInterface.cpp +++ b/src/Core/MIDIToCVInterface.cpp @@ -280,7 +280,7 @@ struct MIDIToCVInterface : Module { // note on case 0x9: { if (msg.value() > 0) { - noteData[msg.note()].velocity = msg.value(); + noteData[msg.note()].velocity = msg.getData2(); pressNote(msg.note()); } else { @@ -288,15 +288,20 @@ struct MIDIToCVInterface : Module { releaseNote(msg.note()); } } break; - // channel aftertouch + // polyphonic aftertouch case 0xa: { uint8_t note = msg.note(); - noteData[note].aftertouch = msg.value(); + noteData[note].aftertouch = msg.getData2(); } break; // cc case 0xb: { processCC(msg); } break; + // channel aftertouch + case 0xd: { + for(uint8_t noteIdx = 0u; noteIdx < 128u; noteIdx++) + noteData[noteIdx].aftertouch = msg.getData1(); + } break; // pitch wheel case 0xe: { pitch = msg.value() * 128 + msg.note();