From 2529c181d449818469a9f3d4e43effb361f538be Mon Sep 17 00:00:00 2001 From: Nero MBP Date: Sat, 12 Sep 2020 23:21:46 -0400 Subject: [PATCH] increasing preset/library size, not yet complete --- docs/library.md | 21 ++++++++++++--------- docs/presets.md | 20 ++++++++++++++------ src/BMC-Api.h | 2 +- src/BMC.midi.cpp | 24 ++++++++++++------------ src/utility/BMC-Callbacks.h | 2 +- src/utility/BMC-Library.h | 2 +- src/utility/BMC-Presets.h | 4 ++-- src/utility/BMC-Settings.h | 16 ++-------------- 8 files changed, 45 insertions(+), 46 deletions(-) diff --git a/docs/library.md b/docs/library.md index dd21da2..ed047e0 100644 --- a/docs/library.md +++ b/docs/library.md @@ -7,6 +7,9 @@ # MIDI Events Library BMC has an events library, these are events that are stored globally and can be used across hardware, these events contain MIDI Messages and are meant to make it easier to pre define some of your most used MIDI messages, for example, if you're a guitar player you'll likely want to use your controller to Engage/Bypass an effect on your processor, we'll use a delay as an example. This is commonly done with MIDI Control Change Messages, so let's say CC#100 is used to engage/bypass your Delay and your device is on Channel 1 and connected to Serial Port A, when you send CC#100 with value 127 the Delay is turned on, CC#100 with value 0 will bypass it. +BMC has a typedef for the library `bmcLibrary_t` this type will be a `uint8_t` if the library size is equal to or less than 255 and a `uint16_t` if it's more than 255. +This is to avoid using more RAM/EEPROM whenever the library size is 255 or less. + You can then create a Library message assigned to CC#100/CH#1/Value#127 and assign it to Serial Port A, do the same for Value#0 then set 2 button events one for PRESS and one for 2nd PRESS the PRESS trigger will send the engage library event and the 2nd PRESS will send the bypass message. Even better a library message for Control Change can be set to TOGGLE which will toggle the value sent so you only need 1 event to turn the Delay On/Off. **Toggling happens because BMC remembers the last value of any CC on any Channel that was sent or received and this feature is available across BMC** Library Events also have their own PORT or PORT Preset, that means that you can assign the port that you want that preset to be sent to every time that library event is triggered. These are Global and do not change with page changes. @@ -22,32 +25,32 @@ There are many API callbacks and functions available for use, these may not refl ```c++ // retrieve a Library event name // must pass a pointer to your string with length >= BMC_NAME_LEN_LIBRARY -void getLibraryEventName(uint8_t n, char* t_string); +void getLibraryEventName(bmcLibrary_t n, char* t_string); // send/execute a library event -void sendLibraryEvent(uint8_t n); +void sendLibraryEvent(bmcLibrary_t n); // send a library even but override the port(s) // example to send library event 0 to USB and Serial A ports at the same time // sendLibraryEventToPorts(0, BMC_USB | BMC_SERIAL_A); -void sendLibraryEventToPorts(uint8_t n, uint8_t ports); +void sendLibraryEventToPorts(bmcLibrary_t n, uint8_t ports); // retrieve the a library event as a 32-bit unsigned integer -uint32_t getLibraryEvent(uint8_t n); +uint32_t getLibraryEvent(bmcLibrary_t n); // retrieve the status of a library event -uint8_t getLibraryEventStatus(uint8_t n); +uint8_t getLibraryEventStatus(bmcLibrary_t n); // retrieve the channel of a library event -uint8_t getLibraryEventChannel(uint8_t n); +uint8_t getLibraryEventChannel(bmcLibrary_t n); // retrieve the first MIDI word of a library event -uint8_t getLibraryEventData1(uint8_t n); +uint8_t getLibraryEventData1(bmcLibrary_t n); // retrieve the second MIDI word of a library event -uint8_t getLibraryEventData2(uint8_t n); +uint8_t getLibraryEventData2(bmcLibrary_t n); // retrieve the stored ports of a library event -uint8_t getLibraryEventPort(uint8_t n); +uint8_t getLibraryEventPort(bmcLibrary_t n); ``` ##### CALLBACKS diff --git a/docs/presets.md b/docs/presets.md index db4a838..f41b35a 100644 --- a/docs/presets.md +++ b/docs/presets.md @@ -7,6 +7,14 @@ # Presets BMC Presets are basically collections of Library Events, you can compile presets to have up to 16 library events, you can also enable a startup preset which obviously will be executed upon BMC starting up. These are Global and do not change with page changes. +BMC has a typedef `bmcPreset_t` this will be either a `uint8_t` if the maximum number of presets compiled is 255 or less and `uint16_t` if the maximum number of presets compiled is higher than 255. + +The same foes for the library in which case theres a typedef `bmcLibrary_t` which is a `uint8_t` if the library is equal to or less than 255 and a `uint16_t` if it's more than 255. + +In either case this is to use less RAM/EEPROM depending of the size of the library and number of presets compiled. + +BMC presets are also broken into banks, you select how many presets you want per bank in the config file maker, however, the maximum number of banks is locked at 255 and the maximum number of presets per bank is also and the output of (banks * presetsPerBank) can not exceed BMC_MAX_PRESETS. + Below is an example of how Library Events are part of Presets. ![Presets & Library](../images/presets-library.jpg) @@ -20,16 +28,16 @@ There are many API callbacks and functions available for use, these may not refl void getPresetName(char* t_string); // retrieve a preset name -void getPresetName(uint8_t n, char* t_string); +void getPresetName(bmcPreset_t n, char* t_string); // get how many library messages this preset has -uint8_t getPresetLength(uint8_t n); +uint8_t getPresetLength(bmcPreset_t n); // get a library message id -uint8_t getPresetItem(uint8_t n, uint8_t e); +bmcLibrary_t getPresetItem(bmcPreset_t n, uint8_t e); // get the current preset number -uint8_t getPreset(); +bmcPreset_t getPreset(); // get the current preset bank uint8_t getPresetBank(); @@ -38,7 +46,7 @@ uint8_t getPresetBank(); uint8_t getPresetInBank(); // change to a preset -void setPreset(uint8_t n); +void setPreset(bmcPreset_t n); // go to the next preset void presetUp(bool endless); @@ -67,7 +75,7 @@ void presetInBankDown(bool endless); ##### CALLBACKS ```c++ // triggered when a BMC Preset has changed -void onPresetChange(void (*fptr)(uint8_t n)); +void onPresetChange(void (*fptr)(bmcPreset_t n)); // triggered when a BMC Preset Bank has changed void onPresetsBankChange(void (*fptr)(uint8_t n)); diff --git a/src/BMC-Api.h b/src/BMC-Api.h index 9533b91..a4ed9d4 100644 --- a/src/BMC-Api.h +++ b/src/BMC-Api.h @@ -334,7 +334,7 @@ class BMCApi : public BMC { } #endif // triggered when a BMC Preset has changed - void onPresetChange(void (*fptr)(uint8_t n)){ + void onPresetChange(void (*fptr)(bmcPreset_t n)){ callback.presetChanged = fptr; } // triggered when a BMC Preset Bank has changed diff --git a/src/BMC.midi.cpp b/src/BMC.midi.cpp index 587497c..23e3228 100644 --- a/src/BMC.midi.cpp +++ b/src/BMC.midi.cpp @@ -89,29 +89,29 @@ void BMC::incomingMidi(BMCMidiMessage message){ case BMC_NONE: break; case 1: - #if BMC_MAX_PAGE > 127 - setPage((bank*128) + message.getData1()); - #else - setPage(message.getData1()); - #endif +#if BMC_MAX_PAGE > 127 + setPage((bank*128) + message.getData1()); +#else + setPage(message.getData1()); +#endif break; case 2: - #if BMC_MAX_PRESETS > 127 - presets.send((bank*128) + message.getData1()); - #elif BMC_MAX_PRESETS > 0 - presets.send(message.getData1()); - #endif +#if BMC_MAX_PRESETS > 127 + presets.send((bmcPreset_t) ((bank*128) + message.getData1())); +#elif BMC_MAX_PRESETS > 0 + presets.send(message.getData1()); +#endif break; } } else if(message.isControlChange()){ // if BMC is set to listen to incoming messages, MIDI CC#0 on the // specified channel is automatically the BANK control change - #if BMC_MAX_PAGE > 127 || BMC_MAX_PRESETS > 127 +#if BMC_MAX_PAGE > 127 || BMC_MAX_PRESETS > 127 if(message.getData1() == 0){ bank = message.getData2() > 0 ? 1 : 0; BMC_PRINTLN("MIDI Bank Changed", bank); } - #endif +#endif } } diff --git a/src/utility/BMC-Callbacks.h b/src/utility/BMC-Callbacks.h index d48fdf5..3be786f 100644 --- a/src/utility/BMC-Callbacks.h +++ b/src/utility/BMC-Callbacks.h @@ -174,7 +174,7 @@ class BMCCallbacks { bool (*midiPreRoute)(BMCMidiMessage& data, uint8_t destinations); void (*valueStream)(BMCValueStream item); - void (*presetChanged)(uint8_t n); + void (*presetChanged)(bmcPreset_t n); void (*presetBankChanged)(uint8_t n); void (*setListChanged)(uint8_t n); void (*setListSongChanged)(uint8_t n); diff --git a/src/utility/BMC-Library.h b/src/utility/BMC-Library.h index 2862a0f..540dda3 100644 --- a/src/utility/BMC-Library.h +++ b/src/utility/BMC-Library.h @@ -155,7 +155,7 @@ class BMCLibrary { #if BMC_MAX_CUSTOM_SYSEX > 0 BMCCustomSysEx& customSysEx; - void sendCustomSysEx(uint8_t index, uint8_t status, uint8_t ports){ + void sendCustomSysEx(bmcLibrary_t index, uint8_t status, uint8_t ports){ uint8_t mode = BMC_CUSTOM_SYSEX_SEND_A; if(status==0xF1){ mode = BMC_CUSTOM_SYSEX_SEND_B; diff --git a/src/utility/BMC-Presets.h b/src/utility/BMC-Presets.h index d032b05..e4bb5bc 100644 --- a/src/utility/BMC-Presets.h +++ b/src/utility/BMC-Presets.h @@ -100,10 +100,10 @@ class BMCPresets { void scrollInBank(uint8_t t_amount, bool t_up, bool t_endless){ scrollInBank(t_amount, t_up, t_up, 0, BMC_MAX_PRESETS_PER_BANK-1); } - void scrollInBank(uint8_t t_amount, uint8_t t_flags, uint8_t t_min, uint8_t t_max){ + void scrollInBank(uint8_t t_amount, uint8_t t_flags, bmcPreset_t t_min, bmcPreset_t t_max){ scrollInBank(t_amount, bitRead(t_flags,0), bitRead(t_flags,1), t_min, t_max); } - void scrollInBank(uint8_t t_amount, bool t_up, bool t_endless, uint8_t t_min, uint8_t t_max){ + void scrollInBank(uint8_t t_amount, bool t_up, bool t_endless, bmcPreset_t t_min, bmcPreset_t t_max){ // first preset of bank uint8_t s = bank * BMC_MAX_PRESETS_PER_BANK; t_min += s; diff --git a/src/utility/BMC-Settings.h b/src/utility/BMC-Settings.h index e2f3bf4..1925115 100644 --- a/src/utility/BMC-Settings.h +++ b/src/utility/BMC-Settings.h @@ -156,20 +156,8 @@ class BMCSettings { writeFlag(8, value); } - - - - - // DATA BYTES -/* - // moved to settins.data[2] to increase value - uint8_t getButtonHoldThreshold(){ - return settings.data[0] & 0x03; - } - void setButtonHoldThreshold(uint8_t value){ - BMC_WRITE_BITS(settings.data[0],value,0x03,0); - } -*/ + // data array + uint8_t getListenerChannel(){ return (settings.data[0]>>2) & 0x1F; }