From fa5ff1c7df169a66cc6f192c46034f1c813968e7 Mon Sep 17 00:00:00 2001 From: Nero Date: Fri, 16 Oct 2020 13:53:42 -0400 Subject: [PATCH] v0.3.2 added custom MIDI trigger --- library.properties | 2 +- src/BMC-Api.h | 5 +++++ src/BMC-Version.h | 2 +- src/BMC.cpp | 4 ++-- src/BMC.triggers.cpp | 5 +++++ src/utility/BMC-Callbacks.h | 16 ++++++++++++++++ src/utility/BMC-Library.h | 20 ++++++++++++++++---- 7 files changed, 46 insertions(+), 8 deletions(-) diff --git a/library.properties b/library.properties index 287de5a..813dc27 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=BMC -version=0.3.1 +version=0.3.2 author=Nero Rox maintainer=Nero Rox sentence=Fully featured MIDI Controller Library with a Companion Editor App. For Teensy diff --git a/src/BMC-Api.h b/src/BMC-Api.h index 3287f9c..e4f836d 100644 --- a/src/BMC-Api.h +++ b/src/BMC-Api.h @@ -181,6 +181,11 @@ class BMCApi : public BMC { void onPageChange(void (*fptr)(uint8_t page)){ callback.pageChanged = fptr; } + void onTriggerCustom(void (*fptr)(uint8_t id)){ +#if BMC_MAX_TRIGGERS > 0 + callback.triggerCustom = fptr; +#endif + } // triggered when EEPROM has been updated either by the editor or the API void onStoreUpdate(void (*fptr)()){ callback.storeUpdated = fptr; diff --git a/src/BMC-Version.h b/src/BMC-Version.h index 538ba99..548e6a6 100644 --- a/src/BMC-Version.h +++ b/src/BMC-Version.h @@ -23,7 +23,7 @@ // BMC Version stored in EEPROM (for editor usage) #define BMC_VERSION_MAJ 0 #define BMC_VERSION_MIN 3 -#define BMC_VERSION_PATCH 1 +#define BMC_VERSION_PATCH 2 //16 bits unsigned, LSB byte is minor, MSB byte is major #define BMC_VERSION ((BMC_VERSION_MAJ<<8) | BMC_VERSION_MIN) diff --git a/src/BMC.cpp b/src/BMC.cpp index 05f405d..b47c82c 100644 --- a/src/BMC.cpp +++ b/src/BMC.cpp @@ -32,9 +32,9 @@ BMC::BMC(): #endif #if BMC_MAX_LIBRARY > 0 #if BMC_MAX_CUSTOM_SYSEX > 0 - ,library(midi, store.global, customSysEx) + ,library(midi, store.global, callback, customSysEx) #else - ,library(midi, store.global) + ,library(midi, store.global, callback) #endif #if BMC_MAX_PRESETS > 0 ,presets(midi, store.global, library) diff --git a/src/BMC.triggers.cpp b/src/BMC.triggers.cpp index 0625a2f..479b595 100644 --- a/src/BMC.triggers.cpp +++ b/src/BMC.triggers.cpp @@ -32,6 +32,11 @@ uint8_t byteC = BMC_GET_BYTE(3,event); switch(parseMidiEventType(type)){ + case BMC_TRIGGER_EVENT_TYPE_CUSTOM: + if(callback.triggerCustom){ + callback.triggerCustom(byteA); + } + break; case BMC_MIDI_NOTE_OFF: case BMC_MIDI_NOTE_ON: case BMC_MIDI_CONTROL_CHANGE: diff --git a/src/utility/BMC-Callbacks.h b/src/utility/BMC-Callbacks.h index 3be786f..e9232c2 100644 --- a/src/utility/BMC-Callbacks.h +++ b/src/utility/BMC-Callbacks.h @@ -21,6 +21,14 @@ class BMCCallbacks { typerCommand = 0; typerCustomCommand = 0; +#if BMC_MAX_TRIGGERS > 0 + triggerCustom = 0; +#endif + +#if BMC_MAX_LIBRARY > 0 + libraryCustom = 0; +#endif + buttonDualPress = 0; buttonActivity = 0; encoderActivity = 0; @@ -117,6 +125,14 @@ class BMCCallbacks { void (*typerCommand)(uint16_t t_value, uint16_t t_rawValue); void (*typerCustomCommand)(uint16_t t_value, uint16_t t_rawValue); +#if BMC_MAX_TRIGGERS > 0 + void (*triggerCustom)(uint8_t id); +#endif + +#if BMC_MAX_LIBRARY > 0 + void (*libraryCustom)(uint8_t id); +#endif + void (*buttonDualPress)(uint8_t btn1, uint8_t btn2); void (*buttonActivity)(uint8_t n, uint8_t eventIndex, uint8_t trigger, diff --git a/src/utility/BMC-Library.h b/src/utility/BMC-Library.h index ff4113e..240f41e 100644 --- a/src/utility/BMC-Library.h +++ b/src/utility/BMC-Library.h @@ -47,17 +47,19 @@ class BMCLibrary { public: #if BMC_MAX_CUSTOM_SYSEX > 0 - BMCLibrary(BMCMidi& t_midi,bmcStoreGlobal& t_global, BMCCustomSysEx& t_sysex): + BMCLibrary(BMCMidi& t_midi,bmcStoreGlobal& t_global, BMCCallbacks& cb, BMCCustomSysEx& t_sysex): midi(t_midi), global(t_global), + callback(cb), customSysEx(t_sysex) { } #else - BMCLibrary(BMCMidi& t_midi,bmcStoreGlobal& t_global): + BMCLibrary(BMCMidi& t_midi,bmcStoreGlobal& t_global, BMCCallbacks& cb): midi(t_midi), - global(t_global) + global(t_global), + callback(cb) { } @@ -84,8 +86,12 @@ class BMCLibrary { pixelProgram = BMC_GET_BYTE(1, global.library[index].event); flags.on(BMC_LIBRARY_FLAG_SET_PIXEL_PROGRAM); flags.on(BMC_LIBRARY_FLAG_CHANGE_AVAILABLE); + } else if(status==BMC_EVENT_TYPE_CUSTOM){ + uint8_t value = mergeDataBytes(global.library[index].event) & 0xFF; + if(callback.libraryCustom){ + callback.libraryCustom(value); + } } - } } void sendWithDifferentPorts(bmcLibrary_t index, uint8_t ports){ @@ -109,6 +115,11 @@ class BMCLibrary { pixelProgram = BMC_GET_BYTE(1, global.library[index].event); flags.on(BMC_LIBRARY_FLAG_SET_PIXEL_PROGRAM); flags.on(BMC_LIBRARY_FLAG_CHANGE_AVAILABLE); + } else if(status==BMC_EVENT_TYPE_CUSTOM){ + uint8_t value = mergeDataBytes(global.library[index].event) & 0xFF; + if(callback.libraryCustom){ + callback.libraryCustom(value); + } } } } @@ -203,6 +214,7 @@ class BMCLibrary { // reference to midi object from BMC BMCMidi& midi; bmcStoreGlobal& global; + BMCCallbacks& callback; BMCFlags flags; uint8_t page = 0; uint8_t pixelProgram = 0;