From c6f2a483a1b63819399bcb70f59006faa50f4645 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 15 Jun 2024 08:48:09 +0200 Subject: [PATCH] apply clang format --- .clang-format | 1 + edrumulus.ino | 552 +++++++++++++++++++++++++------------------------- teensy_name.c | 26 ++- 3 files changed, 290 insertions(+), 289 deletions(-) diff --git a/.clang-format b/.clang-format index f38bf49..5eeed40 100644 --- a/.clang-format +++ b/.clang-format @@ -21,4 +21,5 @@ SpacesBeforeTrailingComments: 1 AlignOperands: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortFunctionsOnASingleLine: All +#AllowShortLiteralsOnASingleLine: true #BracketAlignmentStyle: BAS_Align diff --git a/edrumulus.ino b/edrumulus.ino index 2cc61e2..04a4eb2 100644 --- a/edrumulus.ino +++ b/edrumulus.ino @@ -21,37 +21,36 @@ // For older prototypes or custom implementations, simply change the GPIO numbers in the table below // to match your hardware (note that the GPIO assignment of Prototype 2 is the same as Prototype 4). // analog pins setup: snare | kick | hi-hat | hi-hat-ctrl | crash | tom1 | ride | tom2 | tom3 -static int analog_pins4[] = { 36, 33, 32, 25, 34, 39, 27, 12, 15 }; -static int analog_pins_rimshot4[] = { 35, -1, 26, -1, 14, -1, 13, -1, -1 }; +static int analog_pins4[] = {36, 33, 32, 25, 34, 39, 27, 12, 15}; +static int analog_pins_rimshot4[] = {35, -1, 26, -1, 14, -1, 13, -1, -1}; // if you want to use less number of pads, simply adjust number_pads4 value -//const int number_pads4 = sizeof ( analog_pins4 ) / sizeof ( int ); // example: use all inputs defined in analog_pins4 +// const int number_pads4 = sizeof ( analog_pins4 ) / sizeof ( int ); // example: use all inputs defined in analog_pins4 const int number_pads4 = 8; // example: do not use tom3 and shrink number of pads from 9 to 8 -//const int number_pads4 = 1; // example: just one single pad - +// const int number_pads4 = 1; // example: just one single pad #include "edrumulus.h" #ifdef USE_MIDI -# ifdef ESP_PLATFORM -# include -# ifdef USE_TINYUSB -# include - Adafruit_USBD_MIDI usb_midi; - MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI); -# else - MIDI_CREATE_DEFAULT_INSTANCE(); -# endif -# define MYMIDI MIDI -# define MIDI_CONTROL_CHANGE_TYPE midi::ControlChange -# define MIDI_SEND_AFTER_TOUCH sendAfterTouch -# define MIDI_SERIAL 38400 -# endif -# ifdef TEENSYDUINO -# define MYMIDI usbMIDI -# define MIDI_CONTROL_CHANGE_TYPE usbMIDI.ControlChange -# define MIDI_SEND_AFTER_TOUCH sendAfterTouchPoly -# endif +#ifdef ESP_PLATFORM +#include +#ifdef USE_TINYUSB +#include +Adafruit_USBD_MIDI usb_midi; +MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI); +#else +MIDI_CREATE_DEFAULT_INSTANCE(); +#endif +#define MYMIDI MIDI +#define MIDI_CONTROL_CHANGE_TYPE midi::ControlChange +#define MIDI_SEND_AFTER_TOUCH sendAfterTouch +#define MIDI_SERIAL 38400 +#endif +#ifdef TEENSYDUINO +#define MYMIDI usbMIDI +#define MIDI_CONTROL_CHANGE_TYPE usbMIDI.ControlChange +#define MIDI_SEND_AFTER_TOUCH sendAfterTouchPoly +#endif #endif // local variables and defines @@ -59,49 +58,49 @@ Edrumulus edrumulus; const int midi_channel = 10; // default for edrums is 10 const int hihat_pad_idx = 2; // this definition should not be changed const int hihatctrl_pad_idx = 3; // this definition should not be changed -int number_pads = number_pads4; // initialization value, may be overwritten by get_prototype_pins() -int status_LED_pin = 0; // initialization value, will be set in get_prototype_pins() -bool is_status_LED_on = false; // initialization value -int selected_pad = 0; // initialization value +int number_pads = number_pads4; // initialization value, may be overwritten by get_prototype_pins() +int status_LED_pin = 0; // initialization value, will be set in get_prototype_pins() +bool is_status_LED_on = false; // initialization value +int selected_pad = 0; // initialization value void setup() { // get the pin-to-pad assignments int* analog_pins = analog_pins4; // initialize with the default setup int* analog_pins_rimshot = analog_pins_rimshot4; // initialize with the default setup - const int prototype = Edrumulus_hardware::get_prototype_pins ( &analog_pins, - &analog_pins_rimshot, - &number_pads, - &status_LED_pin ); + const int prototype = Edrumulus_hardware::get_prototype_pins(&analog_pins, + &analog_pins_rimshot, + &number_pads, + &status_LED_pin); // initialize GPIO port for status LED and set it to on during setup - pinMode ( status_LED_pin, OUTPUT ); - digitalWrite ( status_LED_pin, HIGH ); + pinMode(status_LED_pin, OUTPUT); + digitalWrite(status_LED_pin, HIGH); -#if defined ( USE_SERIAL_DEBUG_PLOTTING ) && defined ( ESP_PLATFORM ) - number_pads = min ( number_pads, 7 ); // only max. 7 pads are supported for ESP32 serial debug plotting +#if defined(USE_SERIAL_DEBUG_PLOTTING) && defined(ESP_PLATFORM) + number_pads = min(number_pads, 7); // only max. 7 pads are supported for ESP32 serial debug plotting #endif #ifdef USE_MIDI -# ifdef USE_TINYUSB - TinyUSBDevice.setProductDescriptor ( "Edrumulus" ); -# endif +#ifdef USE_TINYUSB + TinyUSBDevice.setProductDescriptor("Edrumulus"); +#endif MYMIDI.begin(); #endif #ifdef MIDI_SERIAL - if ( prototype == 5 ) + if (prototype == 5) { - Serial.begin ( 115200 ); // faster communication on prototype 5 + Serial.begin(115200); // faster communication on prototype 5 } else { - Serial.begin ( MIDI_SERIAL ); + Serial.begin(MIDI_SERIAL); } #else - Serial.begin ( 115200 ); + Serial.begin(115200); #endif - edrumulus.setup ( number_pads, analog_pins, analog_pins_rimshot ); - digitalWrite ( status_LED_pin, LOW ); // set board LED to low right after setup is done + edrumulus.setup(number_pads, analog_pins, analog_pins_rimshot); + digitalWrite(status_LED_pin, LOW); // set board LED to low right after setup is done #ifdef ESP_PLATFORM preset_settings(); // for ESP32, the load/save of settings is not supported, preset instead #else @@ -109,57 +108,55 @@ void setup() #endif } - void preset_settings() { // default MIDI note assignments - edrumulus.set_midi_notes ( 0, 38, 40 ); // snare - edrumulus.set_midi_notes ( 1, 36, 36 ); // kick - edrumulus.set_midi_notes ( hihat_pad_idx, 22 /*42*/, 22 ); - edrumulus.set_midi_notes_open ( hihat_pad_idx, 26 /*46*/, 26 ); - edrumulus.set_midi_notes ( hihatctrl_pad_idx, 44, 44 ); // Hi-Hat pedal hit - edrumulus.set_midi_notes ( 4, 49, 55 ); // crash - edrumulus.set_midi_notes ( 5, 48, 50 ); // tom 1 - edrumulus.set_midi_notes ( 6, 51, 53 /*59*/ ); // ride (edge: 59, bell: 53) - edrumulus.set_midi_notes ( 7, 45, 47 ); // tom 2 - edrumulus.set_midi_notes ( 8, 43, 58 ); // tom 3 + edrumulus.set_midi_notes(0, 38, 40); // snare + edrumulus.set_midi_notes(1, 36, 36); // kick + edrumulus.set_midi_notes(hihat_pad_idx, 22 /*42*/, 22); + edrumulus.set_midi_notes_open(hihat_pad_idx, 26 /*46*/, 26); + edrumulus.set_midi_notes(hihatctrl_pad_idx, 44, 44); // Hi-Hat pedal hit + edrumulus.set_midi_notes(4, 49, 55); // crash + edrumulus.set_midi_notes(5, 48, 50); // tom 1 + edrumulus.set_midi_notes(6, 51, 53 /*59*/); // ride (edge: 59, bell: 53) + edrumulus.set_midi_notes(7, 45, 47); // tom 2 + edrumulus.set_midi_notes(8, 43, 58); // tom 3 // default drum kit setup - edrumulus.set_pad_type ( 0, Pad::PD8 ); // snare - edrumulus.set_pad_type ( 1, Pad::KD7 ); // kick - edrumulus.set_pad_type ( 2, Pad::PD6 ); // Hi-Hat - edrumulus.set_pad_type ( 3, Pad::FD8 ); // Hi-Hat-ctrl - edrumulus.set_pad_type ( 4, Pad::CY6 ); // crash - edrumulus.set_pad_type ( 5, Pad::TP80 ); // tom 1 - edrumulus.set_pad_type ( 6, Pad::CY8 ); // ride - edrumulus.set_pad_type ( 7, Pad::TP80 ); // tom 2 - edrumulus.set_pad_type ( 8, Pad::TP80 ); // tom 3 + edrumulus.set_pad_type(0, Pad::PD8); // snare + edrumulus.set_pad_type(1, Pad::KD7); // kick + edrumulus.set_pad_type(2, Pad::PD6); // Hi-Hat + edrumulus.set_pad_type(3, Pad::FD8); // Hi-Hat-ctrl + edrumulus.set_pad_type(4, Pad::CY6); // crash + edrumulus.set_pad_type(5, Pad::TP80); // tom 1 + edrumulus.set_pad_type(6, Pad::CY8); // ride + edrumulus.set_pad_type(7, Pad::TP80); // tom 2 + edrumulus.set_pad_type(8, Pad::TP80); // tom 3 } - void loop() { // this function is blocking at the system sampling rate edrumulus.process(); // status LED handling - if ( edrumulus.get_status_is_overload() || edrumulus.get_status_is_error() ) + if (edrumulus.get_status_is_overload() || edrumulus.get_status_is_error()) { - if ( !is_status_LED_on ) + if (!is_status_LED_on) { - digitalWrite ( status_LED_pin, HIGH ); + digitalWrite(status_LED_pin, HIGH); is_status_LED_on = true; #ifdef USE_MIDI - if ( edrumulus.get_status_is_error() ) + if (edrumulus.get_status_is_error()) { const int dc_offset_error_channel = edrumulus.get_status_dc_offset_error_channel(); - if ( dc_offset_error_channel >= 0 ) + if (dc_offset_error_channel >= 0) { - MYMIDI.sendNoteOff ( 125, 64 + dc_offset_error_channel, 1 ); // > 63 means DC offset error and pad/input index is coded in one value + MYMIDI.sendNoteOff(125, 64 + dc_offset_error_channel, 1); // > 63 means DC offset error and pad/input index is coded in one value } else { - MYMIDI.sendNoteOff ( 125, 1, 1 ); // 1 means to set error state + MYMIDI.sendNoteOff(125, 1, 1); // 1 means to set error state } } #endif @@ -167,392 +164,389 @@ void loop() } else { - if ( is_status_LED_on ) + if (is_status_LED_on) { - digitalWrite ( status_LED_pin, LOW ); + digitalWrite(status_LED_pin, LOW); is_status_LED_on = false; #ifdef USE_MIDI - MYMIDI.sendNoteOff ( 125, 0, 1 ); // 0 means that all errors are cleared + MYMIDI.sendNoteOff(125, 0, 1); // 0 means that all errors are cleared #endif } } #ifdef USE_MIDI // send MIDI note to drum synthesizer - for ( int pad_idx = 0; pad_idx < number_pads; pad_idx++ ) + for (int pad_idx = 0; pad_idx < number_pads; pad_idx++) { - if ( edrumulus.get_peak_found ( pad_idx ) ) + if (edrumulus.get_peak_found(pad_idx)) { // get current MIDI note and velocity (maybe note will be overwritten later on) - const int midi_velocity = edrumulus.get_midi_velocity ( pad_idx ); - int midi_note = edrumulus.get_midi_note ( pad_idx ); + const int midi_velocity = edrumulus.get_midi_velocity(pad_idx); + int midi_note = edrumulus.get_midi_note(pad_idx); // send midi positional control message if positional sensing is enabled for the current pad - if ( edrumulus.get_pos_sense_is_used ( pad_idx ) ) + if (edrumulus.get_pos_sense_is_used(pad_idx)) { - const int midi_pos = edrumulus.get_midi_pos ( pad_idx ); - MYMIDI.sendControlChange ( 16, midi_pos, midi_channel ); // positional sensing + const int midi_pos = edrumulus.get_midi_pos(pad_idx); + MYMIDI.sendControlChange(16, midi_pos, midi_channel); // positional sensing } // send Hi-Hat control message right before each Hi-Hat pad hit - if ( pad_idx == hihat_pad_idx ) + if (pad_idx == hihat_pad_idx) { - const int midi_ctrl_ch = edrumulus.get_midi_ctrl_ch ( hihatctrl_pad_idx ); - const int midi_ctrl_value = edrumulus.get_midi_ctrl_value ( hihatctrl_pad_idx ); - const bool hi_hat_is_open = edrumulus.get_midi_ctrl_is_open ( hihatctrl_pad_idx ); - MYMIDI.sendControlChange ( midi_ctrl_ch, midi_ctrl_value, midi_channel ); + const int midi_ctrl_ch = edrumulus.get_midi_ctrl_ch(hihatctrl_pad_idx); + const int midi_ctrl_value = edrumulus.get_midi_ctrl_value(hihatctrl_pad_idx); + const bool hi_hat_is_open = edrumulus.get_midi_ctrl_is_open(hihatctrl_pad_idx); + MYMIDI.sendControlChange(midi_ctrl_ch, midi_ctrl_value, midi_channel); // if Hi-Hat is open, overwrite MIDI note - if ( hi_hat_is_open ) + if (hi_hat_is_open) { - midi_note = edrumulus.get_midi_note_open ( pad_idx ); + midi_note = edrumulus.get_midi_note_open(pad_idx); } } - MYMIDI.sendNoteOn ( midi_note, midi_velocity, midi_channel ); // (note, velocity, channel) - MYMIDI.sendNoteOff ( midi_note, 0, midi_channel ); // we need a note off + MYMIDI.sendNoteOn(midi_note, midi_velocity, midi_channel); // (note, velocity, channel) + MYMIDI.sendNoteOff(midi_note, 0, midi_channel); // we need a note off } - if ( edrumulus.get_control_found ( pad_idx ) ) + if (edrumulus.get_control_found(pad_idx)) { - const int midi_ctrl_ch = edrumulus.get_midi_ctrl_ch ( pad_idx ); - const int midi_ctrl_value = edrumulus.get_midi_ctrl_value ( pad_idx ); - MYMIDI.sendControlChange ( midi_ctrl_ch, midi_ctrl_value, midi_channel ); + const int midi_ctrl_ch = edrumulus.get_midi_ctrl_ch(pad_idx); + const int midi_ctrl_value = edrumulus.get_midi_ctrl_value(pad_idx); + MYMIDI.sendControlChange(midi_ctrl_ch, midi_ctrl_value, midi_channel); } - if ( edrumulus.get_choke_on_found ( pad_idx ) ) + if (edrumulus.get_choke_on_found(pad_idx)) { // special case: if MIDI note open rim is set to zero, we use NoteOn instead of aftertouch // for cymbal choke (#85), where the MIDI note for NoteOn is defined by MIDI note open norm - if ( edrumulus.get_midi_note_open_rim ( pad_idx ) == 0 ) + if (edrumulus.get_midi_note_open_rim(pad_idx) == 0) { // special case: if grabbed edge found, we send a MIDI NoteOn - const int midi_choke_noteon = edrumulus.get_midi_note_open_norm ( pad_idx ); - MYMIDI.sendNoteOn ( midi_choke_noteon, 127, midi_channel ); - MYMIDI.sendNoteOff ( midi_choke_noteon, 0, midi_channel ); // we need a note off + const int midi_choke_noteon = edrumulus.get_midi_note_open_norm(pad_idx); + MYMIDI.sendNoteOn(midi_choke_noteon, 127, midi_channel); + MYMIDI.sendNoteOff(midi_choke_noteon, 0, midi_channel); // we need a note off } else { // if grabbed edge found, polyphonic aftertouch at 127 is transmitted for all notes of the pad - MYMIDI.MIDI_SEND_AFTER_TOUCH ( edrumulus.get_midi_note_norm ( pad_idx ), 127, midi_channel ); - MYMIDI.MIDI_SEND_AFTER_TOUCH ( edrumulus.get_midi_note_rim ( pad_idx ), 127, midi_channel ); - MYMIDI.MIDI_SEND_AFTER_TOUCH ( edrumulus.get_midi_note_open_norm ( pad_idx ), 127, midi_channel ); - MYMIDI.MIDI_SEND_AFTER_TOUCH ( edrumulus.get_midi_note_open_rim ( pad_idx ), 127, midi_channel ); + MYMIDI.MIDI_SEND_AFTER_TOUCH(edrumulus.get_midi_note_norm(pad_idx), 127, midi_channel); + MYMIDI.MIDI_SEND_AFTER_TOUCH(edrumulus.get_midi_note_rim(pad_idx), 127, midi_channel); + MYMIDI.MIDI_SEND_AFTER_TOUCH(edrumulus.get_midi_note_open_norm(pad_idx), 127, midi_channel); + MYMIDI.MIDI_SEND_AFTER_TOUCH(edrumulus.get_midi_note_open_rim(pad_idx), 127, midi_channel); } } - else if ( edrumulus.get_choke_off_found ( pad_idx ) ) + else if (edrumulus.get_choke_off_found(pad_idx)) { // if released edge found, polyphonic aftertouch at 0 is transmitted for all notes of the pad - MYMIDI.MIDI_SEND_AFTER_TOUCH ( edrumulus.get_midi_note_norm ( pad_idx ), 0, midi_channel ); - MYMIDI.MIDI_SEND_AFTER_TOUCH ( edrumulus.get_midi_note_rim ( pad_idx ), 0, midi_channel ); - MYMIDI.MIDI_SEND_AFTER_TOUCH ( edrumulus.get_midi_note_open_norm ( pad_idx ), 0, midi_channel ); - MYMIDI.MIDI_SEND_AFTER_TOUCH ( edrumulus.get_midi_note_open_rim ( pad_idx ), 0, midi_channel ); + MYMIDI.MIDI_SEND_AFTER_TOUCH(edrumulus.get_midi_note_norm(pad_idx), 0, midi_channel); + MYMIDI.MIDI_SEND_AFTER_TOUCH(edrumulus.get_midi_note_rim(pad_idx), 0, midi_channel); + MYMIDI.MIDI_SEND_AFTER_TOUCH(edrumulus.get_midi_note_open_norm(pad_idx), 0, midi_channel); + MYMIDI.MIDI_SEND_AFTER_TOUCH(edrumulus.get_midi_note_open_rim(pad_idx), 0, midi_channel); } } // receiving MIDI messages to change the pad settings: edrumuluscontrol.m -> loopMIDI -> Hairless MIDI - if ( MYMIDI.read ( midi_channel ) ) + if (MYMIDI.read(midi_channel)) { - if ( MYMIDI.getType() == MIDI_CONTROL_CHANGE_TYPE ) + if (MYMIDI.getType() == MIDI_CONTROL_CHANGE_TYPE) { const int controller = MYMIDI.getData1(); const int value = MYMIDI.getData2(); // controller 102: pad type - if ( controller == 102 ) + if (controller == 102) { - edrumulus.set_pad_type ( selected_pad, static_cast ( value ) ); - edrumulus.write_setting ( selected_pad, 0, value ); + edrumulus.set_pad_type(selected_pad, static_cast(value)); + edrumulus.write_setting(selected_pad, 0, value); // on a pad type change, return all parameters of the selected pad - confirm_setting ( controller, value, true ); + confirm_setting(controller, value, true); } // controller 103: threshold - if ( controller == 103 ) + if (controller == 103) { - edrumulus.set_velocity_threshold ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 1, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_velocity_threshold(selected_pad, value); + edrumulus.write_setting(selected_pad, 1, value); + confirm_setting(controller, value, false); } // controller 104: sensitivity - if ( controller == 104 ) + if (controller == 104) { - edrumulus.set_velocity_sensitivity ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 2, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_velocity_sensitivity(selected_pad, value); + edrumulus.write_setting(selected_pad, 2, value); + confirm_setting(controller, value, false); } // controller 105: positional sensing threshold - if ( controller == 105 ) + if (controller == 105) { - edrumulus.set_pos_threshold ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 3, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_pos_threshold(selected_pad, value); + edrumulus.write_setting(selected_pad, 3, value); + confirm_setting(controller, value, false); } // controller 106: positional sensing sensitivity - if ( controller == 106 ) + if (controller == 106) { - edrumulus.set_pos_sensitivity ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 4, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_pos_sensitivity(selected_pad, value); + edrumulus.write_setting(selected_pad, 4, value); + confirm_setting(controller, value, false); } // controller 107: rim shot threshold - if ( controller == 107 ) + if (controller == 107) { - edrumulus.set_rim_shot_threshold ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 5, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_rim_shot_threshold(selected_pad, value); + edrumulus.write_setting(selected_pad, 5, value); + confirm_setting(controller, value, false); } // controller 108: select pad - if ( ( controller == 108 ) && ( value < MAX_NUM_PADS ) ) + if ((controller == 108) && (value < MAX_NUM_PADS)) { selected_pad = value; // on a pad selection, return all parameters of the selected pad - confirm_setting ( controller, value, true ); + confirm_setting(controller, value, true); } // controller 109: MIDI curve type - if ( controller == 109 ) + if (controller == 109) { - edrumulus.set_curve ( selected_pad, static_cast ( value ) ); - edrumulus.write_setting ( selected_pad, 6, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_curve(selected_pad, static_cast(value)); + edrumulus.write_setting(selected_pad, 6, value); + confirm_setting(controller, value, false); } // controller 110: spike cancellation level - if ( controller == 110 ) + if (controller == 110) { - edrumulus.set_spike_cancel_level ( value ); - edrumulus.write_setting ( number_pads, 0, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_spike_cancel_level(value); + edrumulus.write_setting(number_pads, 0, value); + confirm_setting(controller, value, false); } // controller 111: enable/disable rim shot and positional sensing support - if ( controller == 111 ) + if (controller == 111) { - switch ( value ) + switch (value) { case 0: - edrumulus.set_rim_shot_is_used ( selected_pad, false ); - edrumulus.write_setting ( selected_pad, 7, false ); - edrumulus.set_pos_sense_is_used ( selected_pad, false ); - edrumulus.write_setting ( selected_pad, 8, false ); + edrumulus.set_rim_shot_is_used(selected_pad, false); + edrumulus.write_setting(selected_pad, 7, false); + edrumulus.set_pos_sense_is_used(selected_pad, false); + edrumulus.write_setting(selected_pad, 8, false); break; case 1: - edrumulus.set_rim_shot_is_used ( selected_pad, true ); - edrumulus.write_setting ( selected_pad, 7, true ); - edrumulus.set_pos_sense_is_used ( selected_pad, false ); - edrumulus.write_setting ( selected_pad, 8, false ); + edrumulus.set_rim_shot_is_used(selected_pad, true); + edrumulus.write_setting(selected_pad, 7, true); + edrumulus.set_pos_sense_is_used(selected_pad, false); + edrumulus.write_setting(selected_pad, 8, false); break; case 2: - edrumulus.set_rim_shot_is_used ( selected_pad, false ); - edrumulus.write_setting ( selected_pad, 7, false ); - edrumulus.set_pos_sense_is_used ( selected_pad, true ); - edrumulus.write_setting ( selected_pad, 8, true ); + edrumulus.set_rim_shot_is_used(selected_pad, false); + edrumulus.write_setting(selected_pad, 7, false); + edrumulus.set_pos_sense_is_used(selected_pad, true); + edrumulus.write_setting(selected_pad, 8, true); break; case 3: - edrumulus.set_rim_shot_is_used ( selected_pad, true ); - edrumulus.write_setting ( selected_pad, 7, true ); - edrumulus.set_pos_sense_is_used ( selected_pad, true ); - edrumulus.write_setting ( selected_pad, 8, true ); + edrumulus.set_rim_shot_is_used(selected_pad, true); + edrumulus.write_setting(selected_pad, 7, true); + edrumulus.set_pos_sense_is_used(selected_pad, true); + edrumulus.write_setting(selected_pad, 8, true); break; } - confirm_setting ( controller, value, false ); + confirm_setting(controller, value, false); } // controller 112: normal MIDI note - if ( controller == 112 ) + if (controller == 112) { - edrumulus.set_midi_note_norm ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 9, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_midi_note_norm(selected_pad, value); + edrumulus.write_setting(selected_pad, 9, value); + confirm_setting(controller, value, false); } // controller 113: MIDI note for rim - if ( controller == 113 ) + if (controller == 113) { - edrumulus.set_midi_note_rim ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 10, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_midi_note_rim(selected_pad, value); + edrumulus.write_setting(selected_pad, 10, value); + confirm_setting(controller, value, false); } // controller 114: cross talk cancellation - if ( controller == 114 ) + if (controller == 114) { - edrumulus.set_cancellation ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 11, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_cancellation(selected_pad, value); + edrumulus.write_setting(selected_pad, 11, value); + confirm_setting(controller, value, false); } // controller 115: apply preset settings and store these to the EEPROM - if ( controller == 115 ) + if (controller == 115) { preset_settings(); write_all_settings(); - confirm_setting ( controller, value, false ); + confirm_setting(controller, value, false); } // controller 116: normal MIDI note open (Hi-Hat) - if ( controller == 116 ) + if (controller == 116) { - edrumulus.set_midi_note_open_norm ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 12, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_midi_note_open_norm(selected_pad, value); + edrumulus.write_setting(selected_pad, 12, value); + confirm_setting(controller, value, false); } // controller 117: MIDI note open (Hi-Hat) for rim - if ( controller == 117 ) + if (controller == 117) { - edrumulus.set_midi_note_open_rim ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 13, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_midi_note_open_rim(selected_pad, value); + edrumulus.write_setting(selected_pad, 13, value); + confirm_setting(controller, value, false); } // controller 118: mask time - if ( controller == 118 ) + if (controller == 118) { - edrumulus.set_mask_time ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 14, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_mask_time(selected_pad, value); + edrumulus.write_setting(selected_pad, 14, value); + confirm_setting(controller, value, false); } // controller 119: rim shot boost - if ( controller == 119 ) + if (controller == 119) { - edrumulus.set_rim_shot_boost ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 15, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_rim_shot_boost(selected_pad, value); + edrumulus.write_setting(selected_pad, 15, value); + confirm_setting(controller, value, false); } // controller 120: pad coupling - if ( controller == 120 ) + if (controller == 120) { - edrumulus.set_coupled_pad_idx ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 16, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_coupled_pad_idx(selected_pad, value); + edrumulus.write_setting(selected_pad, 16, value); + confirm_setting(controller, value, false); } // controller 121: rim positional sensing threshold - if ( controller == 121 ) + if (controller == 121) { - edrumulus.set_rim_pos_threshold ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 17, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_rim_pos_threshold(selected_pad, value); + edrumulus.write_setting(selected_pad, 17, value); + confirm_setting(controller, value, false); } // controller 122: rim positional sensing sensitivity - if ( controller == 122 ) + if (controller == 122) { - edrumulus.set_rim_pos_sensitivity ( selected_pad, value ); - edrumulus.write_setting ( selected_pad, 18, value ); - confirm_setting ( controller, value, false ); + edrumulus.set_rim_pos_sensitivity(selected_pad, value); + edrumulus.write_setting(selected_pad, 18, value); + confirm_setting(controller, value, false); } } } #endif } - #ifdef USE_MIDI // give feedback to the controller GUI via MIDI Note Off -void confirm_setting ( const int controller, - const int value, - const bool send_all ) +void confirm_setting(const int controller, + const int value, + const bool send_all) { - if ( send_all ) + if (send_all) { // return all parameters of the selected pad - MYMIDI.sendNoteOff ( 102, static_cast ( edrumulus.get_pad_type ( selected_pad ) ), 1 ); - MYMIDI.sendNoteOff ( 103, edrumulus.get_velocity_threshold ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 104, edrumulus.get_velocity_sensitivity ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 105, edrumulus.get_pos_threshold ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 106, edrumulus.get_pos_sensitivity ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 107, edrumulus.get_rim_shot_threshold ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 108, selected_pad, 1 ); - MYMIDI.sendNoteOff ( 109, static_cast ( edrumulus.get_curve ( selected_pad ) ), 1 ); - MYMIDI.sendNoteOff ( 110, edrumulus.get_spike_cancel_level(), 1 ); - MYMIDI.sendNoteOff ( 111, edrumulus.get_rim_shot_is_used ( selected_pad ) + 2 * edrumulus.get_pos_sense_is_used ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 112, edrumulus.get_midi_note_norm ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 113, edrumulus.get_midi_note_rim ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 114, edrumulus.get_cancellation ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 116, edrumulus.get_midi_note_open_norm ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 117, edrumulus.get_midi_note_open_rim ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 118, edrumulus.get_mask_time ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 119, edrumulus.get_rim_shot_boost ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 120, edrumulus.get_coupled_pad_idx ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 121, edrumulus.get_rim_pos_threshold ( selected_pad ), 1 ); - MYMIDI.sendNoteOff ( 122, edrumulus.get_rim_pos_sensitivity ( selected_pad ), 1 ); + MYMIDI.sendNoteOff(102, static_cast(edrumulus.get_pad_type(selected_pad)), 1); + MYMIDI.sendNoteOff(103, edrumulus.get_velocity_threshold(selected_pad), 1); + MYMIDI.sendNoteOff(104, edrumulus.get_velocity_sensitivity(selected_pad), 1); + MYMIDI.sendNoteOff(105, edrumulus.get_pos_threshold(selected_pad), 1); + MYMIDI.sendNoteOff(106, edrumulus.get_pos_sensitivity(selected_pad), 1); + MYMIDI.sendNoteOff(107, edrumulus.get_rim_shot_threshold(selected_pad), 1); + MYMIDI.sendNoteOff(108, selected_pad, 1); + MYMIDI.sendNoteOff(109, static_cast(edrumulus.get_curve(selected_pad)), 1); + MYMIDI.sendNoteOff(110, edrumulus.get_spike_cancel_level(), 1); + MYMIDI.sendNoteOff(111, edrumulus.get_rim_shot_is_used(selected_pad) + 2 * edrumulus.get_pos_sense_is_used(selected_pad), 1); + MYMIDI.sendNoteOff(112, edrumulus.get_midi_note_norm(selected_pad), 1); + MYMIDI.sendNoteOff(113, edrumulus.get_midi_note_rim(selected_pad), 1); + MYMIDI.sendNoteOff(114, edrumulus.get_cancellation(selected_pad), 1); + MYMIDI.sendNoteOff(116, edrumulus.get_midi_note_open_norm(selected_pad), 1); + MYMIDI.sendNoteOff(117, edrumulus.get_midi_note_open_rim(selected_pad), 1); + MYMIDI.sendNoteOff(118, edrumulus.get_mask_time(selected_pad), 1); + MYMIDI.sendNoteOff(119, edrumulus.get_rim_shot_boost(selected_pad), 1); + MYMIDI.sendNoteOff(120, edrumulus.get_coupled_pad_idx(selected_pad), 1); + MYMIDI.sendNoteOff(121, edrumulus.get_rim_pos_threshold(selected_pad), 1); + MYMIDI.sendNoteOff(122, edrumulus.get_rim_pos_sensitivity(selected_pad), 1); // NOTE: 125 reserved for error message - MYMIDI.sendNoteOff ( 126, VERSION_MINOR, 1 ); - MYMIDI.sendNoteOff ( 127, VERSION_MAJOR, 1 ); + MYMIDI.sendNoteOff(126, VERSION_MINOR, 1); + MYMIDI.sendNoteOff(127, VERSION_MAJOR, 1); } else { // return only the given parameter - MYMIDI.sendNoteOff ( controller, value, 1 ); // can be checked, e.g., in the log file + MYMIDI.sendNoteOff(controller, value, 1); // can be checked, e.g., in the log file } } #endif - void read_settings() { - for ( int i = 0; i < number_pads; i++ ) + for (int i = 0; i < number_pads; i++) { // NOTE that it is important that set_pad_type() is called first because it resets all other parameters - edrumulus.set_pad_type ( i, static_cast ( edrumulus.read_setting ( i, 0 ) ) ); - edrumulus.set_velocity_threshold ( i, edrumulus.read_setting ( i, 1 ) ); - edrumulus.set_velocity_sensitivity ( i, edrumulus.read_setting ( i, 2 ) ); - edrumulus.set_pos_threshold ( i, edrumulus.read_setting ( i, 3 ) ); - edrumulus.set_pos_sensitivity ( i, edrumulus.read_setting ( i, 4 ) ); - edrumulus.set_rim_shot_threshold ( i, edrumulus.read_setting ( i, 5 ) ); - edrumulus.set_curve ( i, static_cast ( edrumulus.read_setting ( i, 6 ) ) ); - edrumulus.set_rim_shot_is_used ( i, edrumulus.read_setting ( i, 7 ) ); - edrumulus.set_pos_sense_is_used ( i, edrumulus.read_setting ( i, 8 ) ); - edrumulus.set_midi_note_norm ( i, edrumulus.read_setting ( i, 9 ) ); - edrumulus.set_midi_note_rim ( i, edrumulus.read_setting ( i, 10 ) ); - edrumulus.set_cancellation ( i, edrumulus.read_setting ( i, 11 ) ); - edrumulus.set_midi_note_open_norm ( i, edrumulus.read_setting ( i, 12 ) ); - edrumulus.set_midi_note_open_rim ( i, edrumulus.read_setting ( i, 13 ) ); - edrumulus.set_mask_time ( i, edrumulus.read_setting ( i, 14 ) ); - edrumulus.set_rim_shot_boost ( i, edrumulus.read_setting ( i, 15 ) ); - edrumulus.set_coupled_pad_idx ( i, edrumulus.read_setting ( i, 16 ) ); - edrumulus.set_rim_pos_threshold ( i, edrumulus.read_setting ( i, 17 ) ); - edrumulus.set_rim_pos_sensitivity ( i, edrumulus.read_setting ( i, 18 ) ); + edrumulus.set_pad_type(i, static_cast(edrumulus.read_setting(i, 0))); + edrumulus.set_velocity_threshold(i, edrumulus.read_setting(i, 1)); + edrumulus.set_velocity_sensitivity(i, edrumulus.read_setting(i, 2)); + edrumulus.set_pos_threshold(i, edrumulus.read_setting(i, 3)); + edrumulus.set_pos_sensitivity(i, edrumulus.read_setting(i, 4)); + edrumulus.set_rim_shot_threshold(i, edrumulus.read_setting(i, 5)); + edrumulus.set_curve(i, static_cast(edrumulus.read_setting(i, 6))); + edrumulus.set_rim_shot_is_used(i, edrumulus.read_setting(i, 7)); + edrumulus.set_pos_sense_is_used(i, edrumulus.read_setting(i, 8)); + edrumulus.set_midi_note_norm(i, edrumulus.read_setting(i, 9)); + edrumulus.set_midi_note_rim(i, edrumulus.read_setting(i, 10)); + edrumulus.set_cancellation(i, edrumulus.read_setting(i, 11)); + edrumulus.set_midi_note_open_norm(i, edrumulus.read_setting(i, 12)); + edrumulus.set_midi_note_open_rim(i, edrumulus.read_setting(i, 13)); + edrumulus.set_mask_time(i, edrumulus.read_setting(i, 14)); + edrumulus.set_rim_shot_boost(i, edrumulus.read_setting(i, 15)); + edrumulus.set_coupled_pad_idx(i, edrumulus.read_setting(i, 16)); + edrumulus.set_rim_pos_threshold(i, edrumulus.read_setting(i, 17)); + edrumulus.set_rim_pos_sensitivity(i, edrumulus.read_setting(i, 18)); } - edrumulus.set_spike_cancel_level ( edrumulus.read_setting ( number_pads, 0 ) ); + edrumulus.set_spike_cancel_level(edrumulus.read_setting(number_pads, 0)); } - void write_all_settings() { - for ( int i = 0; i < number_pads; i++ ) + for (int i = 0; i < number_pads; i++) { - edrumulus.write_setting ( i, 0, edrumulus.get_pad_type ( i ) ); - edrumulus.write_setting ( i, 1, edrumulus.get_velocity_threshold ( i ) ); - edrumulus.write_setting ( i, 2, edrumulus.get_velocity_sensitivity ( i ) ); - edrumulus.write_setting ( i, 3, edrumulus.get_pos_threshold ( i ) ); - edrumulus.write_setting ( i, 4, edrumulus.get_pos_sensitivity ( i ) ); - edrumulus.write_setting ( i, 5, edrumulus.get_rim_shot_threshold ( i ) ); - edrumulus.write_setting ( i, 6, edrumulus.get_curve ( i ) ); - edrumulus.write_setting ( i, 7, edrumulus.get_rim_shot_is_used ( i ) ); - edrumulus.write_setting ( i, 8, edrumulus.get_pos_sense_is_used ( i ) ); - edrumulus.write_setting ( i, 9, edrumulus.get_midi_note_norm ( i ) ); - edrumulus.write_setting ( i, 10, edrumulus.get_midi_note_rim ( i ) ); - edrumulus.write_setting ( i, 11, edrumulus.get_cancellation ( i ) ); - edrumulus.write_setting ( i, 12, edrumulus.get_midi_note_open_norm ( i ) ); - edrumulus.write_setting ( i, 13, edrumulus.get_midi_note_open_rim ( i ) ); - edrumulus.write_setting ( i, 14, edrumulus.get_mask_time ( i ) ); - edrumulus.write_setting ( i, 15, edrumulus.get_rim_shot_boost ( i ) ); - edrumulus.write_setting ( i, 16, edrumulus.get_coupled_pad_idx ( i ) ); - edrumulus.write_setting ( i, 17, edrumulus.get_rim_pos_threshold ( i ) ); - edrumulus.write_setting ( i, 18, edrumulus.get_rim_pos_sensitivity ( i ) ); + edrumulus.write_setting(i, 0, edrumulus.get_pad_type(i)); + edrumulus.write_setting(i, 1, edrumulus.get_velocity_threshold(i)); + edrumulus.write_setting(i, 2, edrumulus.get_velocity_sensitivity(i)); + edrumulus.write_setting(i, 3, edrumulus.get_pos_threshold(i)); + edrumulus.write_setting(i, 4, edrumulus.get_pos_sensitivity(i)); + edrumulus.write_setting(i, 5, edrumulus.get_rim_shot_threshold(i)); + edrumulus.write_setting(i, 6, edrumulus.get_curve(i)); + edrumulus.write_setting(i, 7, edrumulus.get_rim_shot_is_used(i)); + edrumulus.write_setting(i, 8, edrumulus.get_pos_sense_is_used(i)); + edrumulus.write_setting(i, 9, edrumulus.get_midi_note_norm(i)); + edrumulus.write_setting(i, 10, edrumulus.get_midi_note_rim(i)); + edrumulus.write_setting(i, 11, edrumulus.get_cancellation(i)); + edrumulus.write_setting(i, 12, edrumulus.get_midi_note_open_norm(i)); + edrumulus.write_setting(i, 13, edrumulus.get_midi_note_open_rim(i)); + edrumulus.write_setting(i, 14, edrumulus.get_mask_time(i)); + edrumulus.write_setting(i, 15, edrumulus.get_rim_shot_boost(i)); + edrumulus.write_setting(i, 16, edrumulus.get_coupled_pad_idx(i)); + edrumulus.write_setting(i, 17, edrumulus.get_rim_pos_threshold(i)); + edrumulus.write_setting(i, 18, edrumulus.get_rim_pos_sensitivity(i)); } - edrumulus.write_setting ( number_pads, 0, edrumulus.get_spike_cancel_level() ); + edrumulus.write_setting(number_pads, 0, edrumulus.get_spike_cancel_level()); } diff --git a/teensy_name.c b/teensy_name.c index 0c4fe24..6489867 100644 --- a/teensy_name.c +++ b/teensy_name.c @@ -20,19 +20,25 @@ #include // define the name of the Teensy USB MIDI device showing up in the operating system -#define MANUFACTURER_NAME {'v', 'o', 'f', 'i', ' ', 't', 'e', 'c'} -#define MANUFACTURER_NAME_LEN 8 -#define PRODUCT_NAME {'E', 'd', 'r', 'u', 'm', 'u', 'l', 'u', 's'} -#define PRODUCT_NAME_LEN 9 +#define MANUFACTURER_NAME \ + { \ + 'v', 'o', 'f', 'i', ' ', 't', 'e', 'c' \ + } +#define MANUFACTURER_NAME_LEN 8 +#define PRODUCT_NAME \ + { \ + 'E', 'd', 'r', 'u', 'm', 'u', 'l', 'u', 's' \ + } +#define PRODUCT_NAME_LEN 9 struct usb_string_descriptor_struct usb_string_manufacturer_name = { - 2 + MANUFACTURER_NAME_LEN * 2, - 3, - MANUFACTURER_NAME }; + 2 + MANUFACTURER_NAME_LEN * 2, + 3, + MANUFACTURER_NAME}; struct usb_string_descriptor_struct usb_string_product_name = { - 2 + PRODUCT_NAME_LEN * 2, - 3, - PRODUCT_NAME }; + 2 + PRODUCT_NAME_LEN * 2, + 3, + PRODUCT_NAME}; #endif