|
|
@ -84,19 +84,19 @@ mdaEPiano* ep; |
|
|
|
|
|
|
|
|
|
|
|
extern void init_menus(void); |
|
|
|
extern void init_menus(void); |
|
|
|
extern int32_t encoder_value[NUM_ENCODER]; |
|
|
|
extern int32_t encoder_value[NUM_ENCODER]; |
|
|
|
|
|
|
|
extern Bounce but[NUM_ENCODER]; |
|
|
|
|
|
|
|
|
|
|
|
// more variables
|
|
|
|
// more variables
|
|
|
|
|
|
|
|
uint8_t sound = 1; |
|
|
|
uint32_t xrun = 0; |
|
|
|
uint32_t xrun = 0; |
|
|
|
uint32_t overload = 0; |
|
|
|
uint32_t overload = 0; |
|
|
|
uint32_t peak = 0; |
|
|
|
uint32_t peak = 0; |
|
|
|
uint16_t render_time_max = 0; |
|
|
|
uint16_t render_time_max = 0; |
|
|
|
elapsedMicros fill_audio_buffer; |
|
|
|
elapsedMicros fill_audio_buffer; |
|
|
|
elapsedMillis control_rate; |
|
|
|
elapsedMillis control_rate; |
|
|
|
elapsedMillis autostore; |
|
|
|
|
|
|
|
const uint16_t audio_block_time_us = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES); |
|
|
|
const uint16_t audio_block_time_us = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES); |
|
|
|
config_t configuration = { |
|
|
|
config_t configuration = { |
|
|
|
0xffff, // checksum
|
|
|
|
0xffff, // checksum
|
|
|
|
1, // sound
|
|
|
|
|
|
|
|
ENC_DECAY_DEFAULT, // decay
|
|
|
|
ENC_DECAY_DEFAULT, // decay
|
|
|
|
ENC_RELEASE_DEFAULT, // release
|
|
|
|
ENC_RELEASE_DEFAULT, // release
|
|
|
|
ENC_HARDNESS_DEFAULT, // hardness
|
|
|
|
ENC_HARDNESS_DEFAULT, // hardness
|
|
|
@ -133,13 +133,16 @@ config_t configuration = { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
float _loudness = mapfloat(float(ENC_LOUDNESS_DEFAULT), ENC_LOUDNESS_MIN, ENC_LOUDNESS_MAX, 0.0, 1.0); |
|
|
|
float _loudness = mapfloat(float(ENC_LOUDNESS_DEFAULT), ENC_LOUDNESS_MIN, ENC_LOUDNESS_MAX, 0.0, 1.0); |
|
|
|
|
|
|
|
uint8_t master_volume = ENC_MASTER_VOLUME_DEFAULT; |
|
|
|
|
|
|
|
int8_t pan = ENC_MASTER_PAN_DEFAULT; |
|
|
|
|
|
|
|
uint8_t eeprom_config_update_flag = 0; |
|
|
|
|
|
|
|
bool eeprom_master_volume_update_flag = false; |
|
|
|
|
|
|
|
elapsedMillis eeprom_master_volume_update_timer; |
|
|
|
|
|
|
|
|
|
|
|
bool eeprom_update_flag = false; |
|
|
|
|
|
|
|
#ifdef SHOW_CPU_LOAD_MSEC |
|
|
|
#ifdef SHOW_CPU_LOAD_MSEC |
|
|
|
elapsedMillis cpu_mem_millis; |
|
|
|
elapsedMillis cpu_mem_millis; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*************************************************************************************************
|
|
|
|
//*************************************************************************************************
|
|
|
|
//* SETUP FUNCTION
|
|
|
|
//* SETUP FUNCTION
|
|
|
|
//*************************************************************************************************
|
|
|
|
//*************************************************************************************************
|
|
|
@ -166,9 +169,8 @@ void setup() |
|
|
|
// create EPiano object
|
|
|
|
// create EPiano object
|
|
|
|
ep = new mdaEPiano(); |
|
|
|
ep = new mdaEPiano(); |
|
|
|
|
|
|
|
|
|
|
|
set_complete_configuration(); |
|
|
|
|
|
|
|
// read initial EEPROM variables
|
|
|
|
|
|
|
|
initial_values_from_eeprom(); |
|
|
|
initial_values_from_eeprom(); |
|
|
|
|
|
|
|
set_complete_configuration(); |
|
|
|
|
|
|
|
|
|
|
|
setup_midi_devices(); |
|
|
|
setup_midi_devices(); |
|
|
|
|
|
|
|
|
|
|
@ -211,8 +213,6 @@ void setup() |
|
|
|
Serial.print(audio_block_time_us); |
|
|
|
Serial.print(audio_block_time_us); |
|
|
|
Serial.println(F("ms)")); |
|
|
|
Serial.println(F("ms)")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AudioInterrupts(); |
|
|
|
AudioInterrupts(); |
|
|
|
|
|
|
|
|
|
|
|
Serial.println(F("<setup end>")); |
|
|
|
Serial.println(F("<setup end>")); |
|
|
@ -285,6 +285,12 @@ void loop() |
|
|
|
{ |
|
|
|
{ |
|
|
|
control_rate = 0; |
|
|
|
control_rate = 0; |
|
|
|
handle_ui(); |
|
|
|
handle_ui(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( eeprom_config_update_flag > 0 && ep->getActiveVoices() == 0) // write only to eeprom when no voice is active
|
|
|
|
|
|
|
|
eeprom_config_update(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (eeprom_master_volume_update_flag == true && eeprom_master_volume_update_timer > STORE_MASTER_VOLUME_MS) |
|
|
|
|
|
|
|
eeprom_master_volume_update(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -441,6 +447,9 @@ void set_master_volume(uint8_t value) |
|
|
|
// http://files.csound-tutorial.net/floss_manual/Release03/Cs_FM_03_ScrapBook/b-panning-and-spatialization.html
|
|
|
|
// http://files.csound-tutorial.net/floss_manual/Release03/Cs_FM_03_ScrapBook/b-panning-and-spatialization.html
|
|
|
|
mixer_r.gain(0, tmp3 * sinf(tmp2 * PI / 2)); |
|
|
|
mixer_r.gain(0, tmp3 * sinf(tmp2 * PI / 2)); |
|
|
|
mixer_l.gain(0, tmp3 * cosf(tmp2 * PI / 2)); |
|
|
|
mixer_l.gain(0, tmp3 * cosf(tmp2 * PI / 2)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eeprom_master_volume_update_flag = true; |
|
|
|
|
|
|
|
eeprom_master_volume_update_timer = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
/******************************************************************************
|
|
|
@ -452,7 +461,7 @@ void initial_values_from_eeprom(void) |
|
|
|
uint32_t checksum; |
|
|
|
uint32_t checksum; |
|
|
|
config_t tmp_conf; |
|
|
|
config_t tmp_conf; |
|
|
|
|
|
|
|
|
|
|
|
EEPROM_readAnything(EEPROM_START_ADDRESS, tmp_conf); |
|
|
|
EEPROM_readAnything(EEPROM_CONFIGURATIONS + sizeof(config_t) * (sound - 1), tmp_conf); |
|
|
|
checksum = crc32((byte*)&tmp_conf + 4, sizeof(tmp_conf) - 4); |
|
|
|
checksum = crc32((byte*)&tmp_conf + 4, sizeof(tmp_conf) - 4); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
@ -462,35 +471,52 @@ void initial_values_from_eeprom(void) |
|
|
|
Serial.print(checksum, HEX); |
|
|
|
Serial.print(checksum, HEX); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if (checksum != tmp_conf.checksum) |
|
|
|
if (checksum != tmp_conf.checksum || (but[0].read() == LOW && but[1].read() == LOW)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.print(F(" - mismatch -> initializing EEPROM!")); |
|
|
|
Serial.println(F(" - mismatch (or force) -> initializing EEPROM!")); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
eeprom_update(); |
|
|
|
eeprom_config_update_flag = sound; |
|
|
|
|
|
|
|
eeprom_config_update(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
EEPROM_readAnything(EEPROM_START_ADDRESS, configuration); |
|
|
|
EEPROM_readAnything(EEPROM_CONFIGURATIONS + sizeof(config_t) * (sound - 1), configuration); |
|
|
|
Serial.print(F(" - OK, loading!")); |
|
|
|
master_volume = EEPROM.read(EEPROM_MASTER_VOLUME); |
|
|
|
|
|
|
|
Serial.print(F(" - OK, loading")); |
|
|
|
} |
|
|
|
} |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
Serial.println(); |
|
|
|
Serial.print(F(" - Master volume: ")); |
|
|
|
|
|
|
|
Serial.println(master_volume, DEC); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void eeprom_write(void) |
|
|
|
void eeprom_config_write(uint8_t value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
autostore = 0; |
|
|
|
eeprom_config_update_flag = value; |
|
|
|
eeprom_update_flag = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void eeprom_update(void) |
|
|
|
void eeprom_config_update(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
eeprom_update_flag = false; |
|
|
|
|
|
|
|
configuration.checksum = crc32((byte*)&configuration + 4, sizeof(configuration) - 4); |
|
|
|
configuration.checksum = crc32((byte*)&configuration + 4, sizeof(configuration) - 4); |
|
|
|
EEPROM_writeAnything(EEPROM_START_ADDRESS, configuration); |
|
|
|
EEPROM_writeAnything(EEPROM_CONFIGURATIONS + sizeof(config_t) * (eeprom_config_update_flag - 1), configuration); |
|
|
|
Serial.println(F("Updating EEPROM with configuration data")); |
|
|
|
Serial.print(F("Updating EEPROM configuration for sound ")); |
|
|
|
|
|
|
|
Serial.print(eeprom_config_update_flag, DEC); |
|
|
|
|
|
|
|
Serial.print(F(" at 0x")); |
|
|
|
|
|
|
|
Serial.println(EEPROM_CONFIGURATIONS + sizeof(config_t) * (eeprom_config_update_flag - 1), HEX); |
|
|
|
|
|
|
|
eeprom_config_update_flag = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void eeprom_master_volume_write(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
eeprom_master_volume_update_flag = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void eeprom_master_volume_update(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
eeprom_master_volume_update_flag = false; |
|
|
|
|
|
|
|
EEPROM.update(EEPROM_MASTER_VOLUME, master_volume); |
|
|
|
|
|
|
|
Serial.println(F("Updating EEPROM with master_volume")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t crc32(byte * calc_start, uint16_t calc_bytes) // base code from https://www.arduino.cc/en/Tutorial/EEPROMCrc
|
|
|
|
uint32_t crc32(byte * calc_start, uint16_t calc_bytes) // base code from https://www.arduino.cc/en/Tutorial/EEPROMCrc
|
|
|
|