From 0d4d070211c9067b7ffda7292c041bb43369f5aa Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 16 Jul 2024 17:16:49 +0200 Subject: [PATCH] use AlignAfterOpenBracket: Align for clang format --- .clang-format | 2 +- common.h | 6 ++-- edrumulus.cpp | 80 ++++++++++++++++++++++---------------------- edrumulus.h | 12 +++---- edrumulus.ino | 10 +++--- hardware.cpp | 48 +++++++++++++------------- hardware.h | 42 +++++++++++------------ pad.cpp | 62 +++++++++++++++++----------------- pad.h | 64 +++++++++++++++++------------------ signalprocessing.cpp | 34 +++++++++---------- 10 files changed, 180 insertions(+), 180 deletions(-) diff --git a/.clang-format b/.clang-format index 1124acf..bfdc9fe 100644 --- a/.clang-format +++ b/.clang-format @@ -13,5 +13,5 @@ SpacesBeforeTrailingComments: 1 AllowAllParametersOfDeclarationOnNextLine: true AllowShortFunctionsOnASingleLine: All IndentPPDirectives: AfterHash +AlignAfterOpenBracket: Align #AllowShortLiteralsOnASingleLine: true -#BracketAlignmentStyle: BAS_Align diff --git a/common.h b/common.h index 2b24c71..10b6d57 100644 --- a/common.h +++ b/common.h @@ -26,8 +26,8 @@ #define MAX_NUM_PAD_INPUTS 5 // a maximum of 5 sensors per pad is supported (where one is rim and one is the sum of three) inline void update_fifo(const float input, - const int fifo_length, - float* fifo_memory) + const int fifo_length, + float* fifo_memory) { // move all values in the history one step back and put new value on the top for (int i = 0; i < fifo_length - 1; i++) @@ -38,7 +38,7 @@ inline void update_fifo(const float input, } inline void allocate_initialize(float** array_memory, - const int array_length) + const int array_length) { // (delete and) allocate memory if (*array_memory != nullptr) diff --git a/edrumulus.cpp b/edrumulus.cpp index 3202822..713c355 100644 --- a/edrumulus.cpp +++ b/edrumulus.cpp @@ -55,8 +55,8 @@ Edrumulus::Edrumulus() } void Edrumulus::setup(const int conf_num_pads, - const int* conf_analog_pins, - const int* conf_analog_pins_rim_shot) + const int* conf_analog_pins, + const int* conf_analog_pins_rim_shot) { number_pads = min(conf_num_pads, MAX_NUM_PADS); @@ -74,9 +74,9 @@ void Edrumulus::setup(const int conf_num_pads, // setup the ESP32 specific object, this has to be done after assigning the analog // pin numbers and before using the analog read function (as in the DC offset estimator) edrumulus_hardware.setup(Fs, - number_pads, - number_inputs, - analog_pin); + number_pads, + number_inputs, + analog_pin); // estimate the DC offset for all inputs float dc_offset_sum[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS]; @@ -84,9 +84,9 @@ void Edrumulus::setup(const int conf_num_pads, for (int k = 0; k < dc_offset_est_len; k++) { edrumulus_hardware.capture_samples(number_pads, - number_inputs, - analog_pin, - sample_org); + number_inputs, + analog_pin, + sample_org); for (int i = 0; i < number_pads; i++) { @@ -131,9 +131,9 @@ void Edrumulus::process() // Query samples ------------------------------------------------------------- // note that this is a blocking function edrumulus_hardware.capture_samples(number_pads, - number_inputs, - analog_pin, - sample_org); + number_inputs, + analog_pin, + sample_org); /* // TEST for plotting all captures samples in the serial plotter (but with low sampling rate) @@ -207,7 +207,7 @@ void Edrumulus::process() // process sample if (any_coupling_used && // note: short-cut for speed optimization of normal non-coupling mode (((coupled_pad_idx_primary >= 0) && ((i == coupled_pad_idx_secondary) || (i == coupled_pad_idx_primary))) || - ((coupled_pad_idx_rim_primary >= 0) && ((i == coupled_pad_idx_rim_secondary) || (i == coupled_pad_idx_rim_primary))))) + ((coupled_pad_idx_rim_primary >= 0) && ((i == coupled_pad_idx_rim_secondary) || (i == coupled_pad_idx_rim_primary))))) { // special case: couple pad inputs for multiple head sensor capturing (assume that both pads have dual-inputs) if ((i == coupled_pad_idx_primary) || (i == coupled_pad_idx_secondary)) @@ -246,14 +246,14 @@ void Edrumulus::process() sample[0] = (sample[2] + sample[3] + sample[4]) / 3; // sum is on channel 0 pad[coupled_pad_idx_primary].process_sample(sample, - 5, - overload_detected, - peak_found[coupled_pad_idx_primary], - midi_velocity[coupled_pad_idx_primary], - midi_pos[coupled_pad_idx_primary], - rim_state[coupled_pad_idx_primary], - is_choke_on[coupled_pad_idx_primary], - is_choke_off[coupled_pad_idx_primary]); + 5, + overload_detected, + peak_found[coupled_pad_idx_primary], + midi_velocity[coupled_pad_idx_primary], + midi_pos[coupled_pad_idx_primary], + rim_state[coupled_pad_idx_primary], + is_choke_on[coupled_pad_idx_primary], + is_choke_off[coupled_pad_idx_primary]); } } @@ -285,14 +285,14 @@ void Edrumulus::process() } pad[coupled_pad_idx_rim_primary].process_sample(sample, - 3, - overload_detected, - peak_found[coupled_pad_idx_rim_primary], - midi_velocity[coupled_pad_idx_rim_primary], - midi_pos[coupled_pad_idx_rim_primary], - rim_state[coupled_pad_idx_rim_primary], - is_choke_on[coupled_pad_idx_rim_primary], - is_choke_off[coupled_pad_idx_rim_primary]); + 3, + overload_detected, + peak_found[coupled_pad_idx_rim_primary], + midi_velocity[coupled_pad_idx_rim_primary], + midi_pos[coupled_pad_idx_rim_primary], + rim_state[coupled_pad_idx_rim_primary], + is_choke_on[coupled_pad_idx_rim_primary], + is_choke_off[coupled_pad_idx_rim_primary]); } } } @@ -300,14 +300,14 @@ void Edrumulus::process() { // normal case: process samples directly pad[i].process_sample(sample, - number_inputs[i], - overload_detected, - peak_found[i], - midi_velocity[i], - midi_pos[i], - rim_state[i], - is_choke_on[i], - is_choke_off[i]); + number_inputs[i], + overload_detected, + peak_found[i], + midi_velocity[i], + midi_pos[i], + rim_state[i], + is_choke_on[i], + is_choke_off[i]); } } } @@ -438,10 +438,10 @@ void Edrumulus::set_coupled_pad_idx(const int pad_idx, const int new_idx) } void Edrumulus::cancel_ADC_spikes(float& signal, - int& overload_detected, - const int pad_index, - const int input_channel_index, - const int level) + int& overload_detected, + const int pad_index, + const int input_channel_index, + const int level) { // remove single/dual sample spikes by checking if right before and right after the // detected spike(s) we only have noise and no useful signal (since the ESP32 spikes diff --git a/edrumulus.h b/edrumulus.h index bbe5958..e150bf0 100644 --- a/edrumulus.h +++ b/edrumulus.h @@ -29,8 +29,8 @@ class Edrumulus // call this function during the Setup function of the main program void setup(const int conf_num_pads, - const int* conf_analog_pins, - const int* conf_analog_pins_rim_shot); + const int* conf_analog_pins, + const int* conf_analog_pins_rim_shot); // call the process function during the main loop void process(); @@ -179,10 +179,10 @@ class Edrumulus // ADC spike cancellation void cancel_ADC_spikes(float& signal, - int& overload_detected, - const int pad_index, - const int input_channel_index, - const int level); + int& overload_detected, + const int pad_index, + const int input_channel_index, + const int level); enum Espikestate { diff --git a/edrumulus.ino b/edrumulus.ino index 2315ad2..d122bf6 100644 --- a/edrumulus.ino +++ b/edrumulus.ino @@ -71,9 +71,9 @@ void setup() 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); + &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); @@ -462,8 +462,8 @@ void loop() #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) + const int value, + const bool send_all) { if (send_all) { diff --git a/hardware.cpp b/hardware.cpp index 69d49d3..230409a 100644 --- a/hardware.cpp +++ b/hardware.cpp @@ -31,9 +31,9 @@ Edrumulus_hardware::Edrumulus_hardware() #ifdef TEENSYDUINO int Edrumulus_hardware::get_prototype_pins(int** analog_pins, - int** analog_pins_rimshot, - int* number_pins, - int* status_LED_pin) + int** analog_pins_rimshot, + int* number_pins, + int* status_LED_pin) { // clang-format off // analog pins setup: snare | kick | hi-hat | hi-hat-ctrl | crash | tom1 | ride | tom2 | tom3 @@ -48,9 +48,9 @@ int Edrumulus_hardware::get_prototype_pins(int** analog_pins, } void Edrumulus_hardware::setup(const int conf_Fs, - const int number_pads, - const int number_inputs[], - int analog_pin[][MAX_NUM_PAD_INPUTS]) + const int number_pads, + const int number_inputs[], + int analog_pin[][MAX_NUM_PAD_INPUTS]) { // set essential parameters Fs = conf_Fs; @@ -97,14 +97,14 @@ void Edrumulus_hardware::setup(const int conf_Fs, } void Edrumulus_hardware::write_setting(const int pad_index, - const int address, - const byte value) + const int address, + const byte value) { EEPROM.update(pad_index * MAX_NUM_SET_PER_PAD + address, value); } byte Edrumulus_hardware::read_setting(const int pad_index, - const int address) + const int address) { return EEPROM.read(pad_index * MAX_NUM_SET_PER_PAD + address); } @@ -116,9 +116,9 @@ void Edrumulus_hardware::on_timer() } void Edrumulus_hardware::capture_samples(const int number_pads, - const int number_inputs[], - int analog_pin[][MAX_NUM_PAD_INPUTS], - int sample_org[][MAX_NUM_PAD_INPUTS]) + const int number_inputs[], + int analog_pin[][MAX_NUM_PAD_INPUTS], + int sample_org[][MAX_NUM_PAD_INPUTS]) { // wait for the timer to get the correct sampling rate when reading the analog value while (!timer_ready) delayMicroseconds(5); @@ -150,9 +150,9 @@ void Edrumulus_hardware::capture_samples(const int number_pads, #ifdef ESP_PLATFORM int Edrumulus_hardware::get_prototype_pins(int** analog_pins, - int** analog_pins_rimshot, - int* number_pins, - int* status_LED_pin) + int** analog_pins_rimshot, + int* number_pins, + int* status_LED_pin) { # ifdef CONFIG_IDF_TARGET_ESP32 // Definition: @@ -224,9 +224,9 @@ int Edrumulus_hardware::get_prototype_pins(int** analog_pins, } void Edrumulus_hardware::setup(const int conf_Fs, - const int number_pads, - const int number_inputs[], - int analog_pin[][MAX_NUM_PAD_INPUTS]) + const int number_pads, + const int number_inputs[], + int analog_pin[][MAX_NUM_PAD_INPUTS]) { // set essential parameters Fs = conf_Fs; @@ -369,9 +369,9 @@ void IRAM_ATTR Edrumulus_hardware::on_timer() } void Edrumulus_hardware::capture_samples(const int number_pads, - const int number_inputs[], - int analog_pin[][MAX_NUM_PAD_INPUTS], - int sample_org[][MAX_NUM_PAD_INPUTS]) + const int number_inputs[], + int analog_pin[][MAX_NUM_PAD_INPUTS], + int sample_org[][MAX_NUM_PAD_INPUTS]) { // wait for the timer to get the correct sampling rate when reading the analog value if (xSemaphoreTake(timer_semaphore, portMAX_DELAY) == pdTRUE) @@ -502,9 +502,9 @@ uint16_t Edrumulus_hardware::my_analogRead(const uint8_t pin) } void Edrumulus_hardware::my_analogRead_parallel(const uint32_t channel_adc1_bitval, - const uint32_t channel_adc2_bitval, - uint16_t& out_adc1, - uint16_t& out_adc2) + const uint32_t channel_adc2_bitval, + uint16_t& out_adc1, + uint16_t& out_adc2) { # ifdef CONFIG_IDF_TARGET_ESP32 // start ADC1 diff --git a/hardware.h b/hardware.h index 00a7f80..8c7fe6a 100644 --- a/hardware.h +++ b/hardware.h @@ -41,19 +41,19 @@ class Edrumulus_hardware Edrumulus_hardware(); static int get_prototype_pins(int** analog_pins, - int** analog_pins_rimshot, - int* number_pins, - int* status_LED_pin); + int** analog_pins_rimshot, + int* number_pins, + int* status_LED_pin); void setup(const int conf_Fs, - const int number_pads, - const int number_inputs[], - int analog_pin[][MAX_NUM_PAD_INPUTS]); + const int number_pads, + const int number_inputs[], + int analog_pin[][MAX_NUM_PAD_INPUTS]); void capture_samples(const int number_pads, - const int number_inputs[], - int analog_pin[][MAX_NUM_PAD_INPUTS], - int sample_org[][MAX_NUM_PAD_INPUTS]); + const int number_inputs[], + int analog_pin[][MAX_NUM_PAD_INPUTS], + int sample_org[][MAX_NUM_PAD_INPUTS]); void write_setting(const int pad_index, const int address, const byte value); byte read_setting(const int pad_index, const int address); @@ -95,19 +95,19 @@ class Edrumulus_hardware Edrumulus_hardware(); static int get_prototype_pins(int** analog_pins, - int** analog_pins_rimshot, - int* number_pins, - int* status_LED_pin); + int** analog_pins_rimshot, + int* number_pins, + int* status_LED_pin); void setup(const int conf_Fs, - const int number_pads, - const int number_inputs[], - int analog_pin[][MAX_NUM_PAD_INPUTS]); + const int number_pads, + const int number_inputs[], + int analog_pin[][MAX_NUM_PAD_INPUTS]); void capture_samples(const int number_pads, - const int number_inputs[], - int analog_pin[][MAX_NUM_PAD_INPUTS], - int sample_org[][MAX_NUM_PAD_INPUTS]); + const int number_inputs[], + int analog_pin[][MAX_NUM_PAD_INPUTS], + int sample_org[][MAX_NUM_PAD_INPUTS]); void write_setting(const int, const int, const byte){}; // not supported byte read_setting(const int, const int) { return 0; }; // not supported @@ -124,9 +124,9 @@ class Edrumulus_hardware void init_my_analogRead(); uint16_t my_analogRead(const uint8_t pin); void my_analogRead_parallel(const uint32_t channel_adc1_bitval, - const uint32_t channel_adc2_bitval, - uint16_t& out_adc1, - uint16_t& out_adc2); + const uint32_t channel_adc2_bitval, + uint16_t& out_adc1, + uint16_t& out_adc2); int total_number_inputs; int input_pin[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS]; diff --git a/pad.cpp b/pad.cpp index 540b21c..6622730 100644 --- a/pad.cpp +++ b/pad.cpp @@ -121,7 +121,7 @@ void Pad::initialize() } velocity_factor = 126.0f / ((pow(curve_param, 126.0f) - 1) * curve_param * - pow(threshold, 1270.0f / velocity_range_db * log10(curve_param))); + pow(threshold, 1270.0f / velocity_range_db * log10(curve_param))); velocity_exponent = 1270.0f / velocity_range_db * log10(curve_param); velocity_offset = 1.0f - 126.0f / (pow(curve_param, 126.0f) - 1); @@ -281,14 +281,14 @@ void Pad::initialize() } float Pad::process_sample(const float* input, - const int input_len, - const int* overload_detected, - bool& peak_found, - int& midi_velocity, - int& midi_pos, - Erimstate& rim_state, - bool& is_choke_on, - bool& is_choke_off) + const int input_len, + const int* overload_detected, + bool& peak_found, + int& midi_velocity, + int& midi_pos, + Erimstate& rim_state, + bool& is_choke_on, + bool& is_choke_off) { // initialize return parameters and configuration parameters peak_found = false; @@ -443,10 +443,10 @@ float Pad::process_sample(const float* input, if (number_head_sensors > 1) { multi_head_sensor.calculate_subsample_peak_value(s_x_sq_hist, - x_sq_hist_len, - total_scan_time, - first_peak_idx, - s.sResults.first_peak_sub_sample); + x_sq_hist_len, + total_scan_time, + first_peak_idx, + s.sResults.first_peak_sub_sample); } // get the maximum velocity in the scan time using the unfiltered signal @@ -469,11 +469,11 @@ float Pad::process_sample(const float* input, // overload correction overload_correction(s_x_sq_hist, - s.overload_hist, - first_peak_idx, - peak_velocity_idx, - s.is_overloaded_state, - s.peak_val); + s.overload_hist, + first_peak_idx, + peak_velocity_idx, + s.is_overloaded_state, + s.peak_val); } // end condition of mask time @@ -785,27 +785,27 @@ float Pad::process_sample(const float* input, if (number_head_sensors > 1) { multi_head_sensor.calculate(sSensor, - sensor0_has_results, - number_head_sensors, - pad_settings.pos_sensitivity, - pad_settings.pos_threshold, - peak_found, - midi_velocity, - midi_pos, - rim_state); + sensor0_has_results, + number_head_sensors, + pad_settings.pos_sensitivity, + pad_settings.pos_threshold, + peak_found, + midi_velocity, + midi_pos, + rim_state); } DEBUG_ADD_VALUES(input[0] * input[0], x_filt, sSensor[0].scan_time_cnt > 0 ? 0.5 : sSensor[0].mask_back_cnt > 0 ? 0.2 : cur_decay, - threshold); + threshold); return x_filt; // here, you can return debugging values for verification with Ocatve } void Pad::process_control_sample(const int* input, - bool& change_found, - int& midi_ctrl_value, - bool& peak_found, - int& midi_velocity) + bool& change_found, + int& midi_ctrl_value, + bool& peak_found, + int& midi_velocity) { manage_delayed_initialization(); diff --git a/pad.h b/pad.h index a77e38a..1e06b05 100644 --- a/pad.h +++ b/pad.h @@ -75,20 +75,20 @@ class Pad void setup(const int conf_Fs); float process_sample(const float* input, - const int input_len, - const int* overload_detected, - bool& peak_found, - int& midi_velocity, - int& midi_pos, - Erimstate& rim_state, - bool& is_choke_on, - bool& is_choke_off); + const int input_len, + const int* overload_detected, + bool& peak_found, + int& midi_velocity, + int& midi_pos, + Erimstate& rim_state, + bool& is_choke_on, + bool& is_choke_off); void process_control_sample(const int* input, - bool& change_found, - int& midi_ctrl_value, - bool& peak_found, - int& midi_velocity); + bool& change_found, + int& midi_ctrl_value, + bool& peak_found, + int& midi_velocity); void set_pad_type(const Epadtype new_pad_type); Epadtype get_pad_type() { return pad_settings.pad_type; } @@ -252,11 +252,11 @@ class Pad void sched_init() { init_delay_cnt = init_delay_value; }; // schedule initialization function (for delayed initialization) void overload_correction(FastWriteFIFO& x_sq_hist, - FastWriteFIFO& overload_hist, - const int first_peak_idx, - const int peak_velocity_idx, - bool& is_overloaded_state, - float& peak_val); + FastWriteFIFO& overload_hist, + const int first_peak_idx, + const int peak_velocity_idx, + bool& is_overloaded_state, + float& peak_val); const float init_delay_value_s = 0.2; // init delay value in seconds static const int max_length_ampmap = 20; // maxmimum number of amplification mappings for clipping compensation @@ -343,20 +343,20 @@ class Pad void initialize(); void calculate_subsample_peak_value(FastWriteFIFO& x_sq_hist, - const int x_sq_hist_len, - const int total_scan_time, - const int first_peak_idx, - float& first_peak_sub_sample); + const int x_sq_hist_len, + const int total_scan_time, + const int first_peak_idx, + float& first_peak_sub_sample); void calculate(SSensor* sSensor, - const bool sensor0_has_results, - const int number_head_sensors, - const int pos_sensitivity, - const int pos_threshold, - bool& peak_found, - int& midi_velocity, - int& midi_pos, - Erimstate& rim_state); + const bool sensor0_has_results, + const int number_head_sensors, + const int pos_sensitivity, + const int pos_threshold, + bool& peak_found, + int& midi_velocity, + int& midi_pos, + Erimstate& rim_state); protected: int multiple_sensor_cnt; @@ -446,9 +446,9 @@ class Pad float debug_buffer[number_debug_buffers][debug_buffer_size]; void DEBUG_ADD_VALUES(const float value0, - const float value1, - const float value2, - const float value3) + const float value1, + const float value2, + const float value3) { debug_buffer[0][debug_buffer_idx] = value0; debug_buffer[1][debug_buffer_idx] = value1; diff --git a/signalprocessing.cpp b/signalprocessing.cpp index 8d2a921..0d7447b 100644 --- a/signalprocessing.cpp +++ b/signalprocessing.cpp @@ -20,11 +20,11 @@ // Pad ------------------------------------------------------------------------- void Pad::overload_correction(FastWriteFIFO& x_sq_hist, - FastWriteFIFO& overload_hist, - const int first_peak_idx, - const int peak_velocity_idx, - bool& is_overloaded_state, - float& peak_val) + FastWriteFIFO& overload_hist, + const int first_peak_idx, + const int peak_velocity_idx, + bool& is_overloaded_state, + float& peak_val) { // if the first peak is overloaded, use this position as the maximum peak int peak_velocity_idx_ovhist = peak_velocity_idx; @@ -152,10 +152,10 @@ void Pad::MultiHeadSensor::initialize() } void Pad::MultiHeadSensor::calculate_subsample_peak_value(FastWriteFIFO& x_sq_hist, - const int x_sq_hist_len, - const int total_scan_time, - const int first_peak_idx, - float& first_peak_sub_sample) + const int x_sq_hist_len, + const int total_scan_time, + const int first_peak_idx, + float& first_peak_sub_sample) { // calculate sub-sample first peak value using simplified metric: // m = (x_sq[2] - x_sq[0]) / (x_sq[1] - x_sq[0]) -> sub_sample = m * m / 2 @@ -184,14 +184,14 @@ void Pad::MultiHeadSensor::calculate_subsample_peak_value(FastWriteFIFO& x_sq_hi } void Pad::MultiHeadSensor::calculate(SSensor* sSensor, - const bool sensor0_has_results, - const int number_head_sensors, - const int pos_sensitivity, - const int pos_threshold, - bool& peak_found, - int& midi_velocity, - int& midi_pos, - Erimstate& rim_state) + const bool sensor0_has_results, + const int number_head_sensors, + const int pos_sensitivity, + const int pos_threshold, + bool& peak_found, + int& midi_velocity, + int& midi_pos, + Erimstate& rim_state) { // TODO do not use hard coded "17" at the three places here but define a pad specific value and use that instead // -> use that value also for definition of max_sensor_sample_diff