Skip to content

Commit

Permalink
apply clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
corrados committed Jun 15, 2024
1 parent 159ffb7 commit 35d6a12
Show file tree
Hide file tree
Showing 7 changed files with 1,744 additions and 1,724 deletions.
1,085 changes: 524 additions & 561 deletions edrumulus.cpp

Large diffs are not rendered by default.

971 changes: 519 additions & 452 deletions edrumulus.h

Large diffs are not rendered by default.

550 changes: 272 additions & 278 deletions edrumulus.ino

Large diffs are not rendered by default.

593 changes: 294 additions & 299 deletions hardware.cpp

Large diffs are not rendered by default.

232 changes: 116 additions & 116 deletions hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,171 +28,171 @@ enum Espikestate
ST_OTHER
};

#define MAX_NUM_PADS 12 // a maximum of 12 pads are supported
#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)
#define MAX_EEPROM_SIZE 512 // bytes (Teensy 4.0: max 1024 bytes)
#define MAX_NUM_SET_PER_PAD 30 // maximum number of settings which can be stored per pad

#define MAX_NUM_PADS 12 // a maximum of 12 pads are supported
#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)
#define MAX_EEPROM_SIZE 512 // bytes (Teensy 4.0: max 1024 bytes)
#define MAX_NUM_SET_PER_PAD 30 // maximum number of settings which can be stored per pad

// -----------------------------------------------------------------------------
// Teensy 4.0/4.1 --------------------------------------------------------------
// -----------------------------------------------------------------------------
#ifdef TEENSYDUINO

#include "EEPROM.h"
#include <ADC.h>
# include <ADC.h>

# include "EEPROM.h"

#define BOARD_LED_PIN 13 // pin number of the LED on the Teensy 4.0 board
#define ADC_MAX_RANGE 4096 // Teensy 4.0/4.1 ADC has 12 bits -> 0..4095
#define ADC_MAX_NOISE_AMPL 8 // highest assumed ADC noise amplitude in the ADC input range unit (measured)
# define BOARD_LED_PIN 13 // pin number of the LED on the Teensy 4.0 board
# define ADC_MAX_RANGE 4096 // Teensy 4.0/4.1 ADC has 12 bits -> 0..4095
# define ADC_MAX_NOISE_AMPL 8 // highest assumed ADC noise amplitude in the ADC input range unit (measured)

class Edrumulus_hardware
{
public:
public:
Edrumulus_hardware();

static int get_prototype_pins ( int** analog_pins,
int** analog_pins_rimshot,
int* number_pins,
int* status_LED_pin );
static int get_prototype_pins(int** analog_pins,
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] );
void setup(const int conf_Fs,
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] );
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]);

void cancel_ADC_spikes ( float& signal,
int& overload_detected,
const int pad_index,
const int input_channel_index,
const int level );
void cancel_ADC_spikes(float& signal,
int& overload_detected,
const int pad_index,
const int input_channel_index,
const int level);

void write_setting ( const int pad_index, const int address, const byte value );
byte read_setting ( const int pad_index, const int address );
void write_setting(const int pad_index, const int address, const byte value);
byte read_setting(const int pad_index, const int address);

protected:
int Fs;
protected:
int Fs;
IntervalTimer myTimer;
static void on_timer();
static void on_timer();
volatile bool timer_ready;
ADC adc_obj;
ADC adc_obj;

int total_number_inputs;
int input_pin[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
int total_number_inputs;
int input_pin[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint16_t input_sample[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];

Espikestate prev1_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
Espikestate prev2_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
Espikestate prev3_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
Espikestate prev4_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
Espikestate prev5_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input1[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input2[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input3[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input4[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload1[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload2[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload3[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload4[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input1[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input2[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input3[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input4[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload1[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload2[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload3[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload4[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
};

#endif


// -----------------------------------------------------------------------------
// ESP32 Dual Core -------------------------------------------------------------
// -----------------------------------------------------------------------------
#ifdef ESP_PLATFORM

#include <Preferences.h>
#include "soc/sens_reg.h"
#include "driver/adc.h"
#ifdef CONFIG_IDF_TARGET_ESP32
# include "driver/dac.h"
#else // CONFIG_IDF_TARGET_ESP32S3
# include "hal/adc_hal.h"
#endif
# include <Preferences.h>

#define BOARD_LED_PIN 2 // pin number of the LED on the ESP32 board
#define ADC_MAX_RANGE 4096 // ESP32 ADC has 12 bits -> 0..4095
#define ADC_MAX_NOISE_AMPL 8 // highest assumed ADC noise amplitude in the ADC input range unit (measured)
# include "driver/adc.h"
# include "soc/sens_reg.h"
# ifdef CONFIG_IDF_TARGET_ESP32
# include "driver/dac.h"
# else // CONFIG_IDF_TARGET_ESP32S3
# include "hal/adc_hal.h"
# endif

# define BOARD_LED_PIN 2 // pin number of the LED on the ESP32 board
# define ADC_MAX_RANGE 4096 // ESP32 ADC has 12 bits -> 0..4095
# define ADC_MAX_NOISE_AMPL 8 // highest assumed ADC noise amplitude in the ADC input range unit (measured)

class Edrumulus_hardware
{
public:
public:
Edrumulus_hardware();

static int get_prototype_pins ( int** analog_pins,
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] );

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] );

void cancel_ADC_spikes ( float& signal,
int& overload_detected,
const int pad_index,
const int input_channel_index,
const int level );

void write_setting ( const int pad_index, const int address, const byte value );
byte read_setting ( const int pad_index, const int address );

protected:
int Fs;
Preferences settings;
static int get_prototype_pins(int** analog_pins,
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]);

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]);

void cancel_ADC_spikes(float& signal,
int& overload_detected,
const int pad_index,
const int input_channel_index,
const int level);

void write_setting(const int pad_index, const int address, const byte value);
byte read_setting(const int pad_index, const int address);

protected:
int Fs;
Preferences settings;
volatile SemaphoreHandle_t timer_semaphore;
hw_timer_t* timer = nullptr;
static void IRAM_ATTR on_timer();
static void start_timer_core0_task ( void* param );

void setup_timer();
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 );

int total_number_inputs;
int input_pin[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint16_t input_sample[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];

int num_pin_pairs;
int adc1_index[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
int adc2_index[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint32_t channel_adc1_bitval[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint32_t channel_adc2_bitval[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];

int num_pin_single;
int single_index[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
hw_timer_t* timer = nullptr;
static void IRAM_ATTR on_timer();
static void start_timer_core0_task(void* param);

void setup_timer();
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);

int total_number_inputs;
int input_pin[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint16_t input_sample[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];

int num_pin_pairs;
int adc1_index[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
int adc2_index[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint32_t channel_adc1_bitval[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint32_t channel_adc2_bitval[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];

int num_pin_single;
int single_index[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];

Espikestate prev1_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
Espikestate prev2_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
Espikestate prev3_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
Espikestate prev4_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
Espikestate prev5_input_state[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input1[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input2[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input3[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input4[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload1[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload2[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload3[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload4[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input1[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input2[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input3[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
float prev_input4[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload1[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload2[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload3[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
int prev_overload4[MAX_NUM_PADS][MAX_NUM_PAD_INPUTS];
};

#endif
9 changes: 2 additions & 7 deletions parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "edrumulus.h"


void Edrumulus::Pad::apply_preset_pad_settings()
{
// apply PRESET settings (might be overwritten by pad-specific properties)
Expand Down Expand Up @@ -57,7 +56,7 @@ void Edrumulus::Pad::apply_preset_pad_settings()
pad_settings.rim_shot_window_len_ms = 3.5f; // pad specific parameter: window length for rim shot detection
pad_settings.clip_comp_ampmap_step = 0.08f; // pad specific parameter: clipping compensation amplitude mapping step, conservative value from PD80R as default

switch ( pad_settings.pad_type )
switch (pad_settings.pad_type)
{
// Mesh pads ---------------------------------------------------------------
case PD120: // dual trigger
Expand Down Expand Up @@ -167,7 +166,6 @@ void Edrumulus::Pad::apply_preset_pad_settings()
pad_settings.velocity_sensitivity = 3;
break;


// Rubber pads -------------------------------------------------------------
case PD5: // single trigger
pad_settings.scan_time_ms = 4.0f;
Expand Down Expand Up @@ -223,7 +221,6 @@ void Edrumulus::Pad::apply_preset_pad_settings()
pad_settings.pos_low_pass_cutoff = 300.0f;
break;


// Kick drum pads ----------------------------------------------------------
case KD7: // single trigger
pad_settings.velocity_threshold = 11;
Expand Down Expand Up @@ -280,7 +277,6 @@ void Edrumulus::Pad::apply_preset_pad_settings()
pad_settings.curve_type = LOG2;
break;


// Cymbal pads -------------------------------------------------------------
case CY5: // dual trigger
pad_settings.is_rim_switch = true;
Expand Down Expand Up @@ -325,7 +321,7 @@ void Edrumulus::Pad::apply_preset_pad_settings()
break;

case VH12: // dual trigger
// TODO if the Hi-Hat is open just a little bit, we get double triggers
// TODO if the Hi-Hat is open just a little bit, we get double triggers
pad_settings.is_rim_switch = true;
pad_settings.velocity_sensitivity = 5;
pad_settings.rim_shot_threshold = 23;
Expand Down Expand Up @@ -380,7 +376,6 @@ void Edrumulus::Pad::apply_preset_pad_settings()
pad_settings.velocity_sensitivity = 6;
break;


// Hi-hat controllers ------------------------------------------------------
case FD8:
pad_settings.is_control = true;
Expand Down
28 changes: 17 additions & 11 deletions teensy_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@

#ifdef TEENSYDUINO

#include <usb_names.h>
# include <usb_names.h>

// 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

0 comments on commit 35d6a12

Please sign in to comment.