From 371ed3ecc230952221687619e6cbf185c01ed4ed Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sun, 10 Nov 2019 17:53:55 +0100 Subject: [PATCH] Check function with constrains for parameters added. --- MicroDexed.ino | 88 +++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index e031e40..867aec6 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -1163,45 +1163,6 @@ void initial_values_from_eeprom(bool init) else { EEPROM.get(EEPROM_START_ADDRESS, configuration); - /* - configuration.instances %= INSTANCES_MAX; - configuration.instance_mode %= INSTANCE_MODE_MAX; - configuration.instance_splitpoint %= INSTANCE_SPLITPOINT_MAX; - configuration.vol %= VOLUME_MAX; - configuration.mono %= MONO_MAX; - configuration.reverb_roomsize %= REVERB_ROOMSIZE_MAX; - configuration.reverb_damping %= REVERB_DAMPING_MAX; - configuration.chorus_frequency %= CHORUS_FREQUENCY_MAX; - configuration.chorus_waveform %= CHORUS_WAVEFORM_MAX; - configuration.chorus_depth %= CHORUS_DEPTH_MAX; - configuration.delay_time %= DELAY_TIME_MAX; - configuration.delay_feedback %= DELAY_FEEDBACK_MAX; - for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) - { - configuration.dexed[instance_id].midi_channel %= MIDI_CHANNEL_MAX; - configuration.dexed[instance_id].bank %= MAX_BANKS; - configuration.dexed[instance_id].voice %= MAX_VOICES; - configuration.dexed[instance_id].pan %= PANORAMA_MAX; - configuration.dexed[instance_id].reverb_send %= REVERB_SEND_MAX; - configuration.dexed[instance_id].chorus_send %= CHORUS_SEND_MAX; - configuration.dexed[instance_id].delay_send %= DELAY_SEND_MAX; - configuration.dexed[instance_id].filter_cutoff %= FILTER_CUTOFF_MAX; - configuration.dexed[instance_id].filter_resonance %= FILTER_RESONANCE_MAX; - configuration.dexed[instance_id].loudness %= LOUDNESS_MAX; - configuration.dexed[instance_id].polyphony %= POLYPHONY_MAX; - configuration.dexed[instance_id].engine %= ENGINE_MAX; - configuration.dexed[instance_id].monopoly %= MONOPOLY_MAX; - configuration.dexed[instance_id].pb_range %= PB_RANGE_MAX; - configuration.dexed[instance_id].pb_step %= PB_STEP_MAX; - configuration.dexed[instance_id].mw_range %= MW_RANGE_MAX; - configuration.dexed[instance_id].mw_assign %= MW_ASSIGN_MAX; - configuration.dexed[instance_id].fc_range %= FC_RANGE_MAX; - configuration.dexed[instance_id].fc_assign %= FC_ASSIGN_MAX; - configuration.dexed[instance_id].bc_range %= BC_RANGE_MAX; - configuration.dexed[instance_id].bc_assign %= BC_ASSIGN_MAX; - configuration.dexed[instance_id].at_range %= AT_RANGE_MAX; - configuration.dexed[instance_id].at_assign %= AT_ASSIGN_MAX; - configuration.dexed[instance_id].op_enabled %= 0x3f; */ for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) { @@ -1213,16 +1174,61 @@ void initial_values_from_eeprom(bool init) MicroDexed[instance_id]->setOPs(configuration.dexed[instance_id].op_enabled); MicroDexed[instance_id]->doRefreshVoice(); } - Serial.println(F("OK, loaded!")); } + Serial.println(F("OK, loaded!")); } + check_configuration(); + #ifdef DEBUG show_configuration(); #endif if (configuration.vol > 100) - configuration.vol = 100; + configuration.vol = 100; // just to be sure ;-) +} + +void check_configuration(void) +{ + configuration.instances = constrain(configuration.instances, INSTANCES_MIN, INSTANCES_MAX); + configuration.instance_mode = constrain(configuration.instance_mode, INSTANCE_MODE_MIN, INSTANCE_MODE_MAX); + configuration.instance_splitpoint = constrain(configuration.instance_splitpoint, INSTANCE_SPLITPOINT_MAX, INSTANCE_SPLITPOINT_MAX); + configuration.vol = constrain(configuration.vol, VOLUME_MIN, VOLUME_MAX); + configuration.pan = constrain(configuration.pan, PANORAMA_MIN, PANORAMA_MAX); + configuration.mono = constrain(configuration.mono, MONO_MIN, MONO_MAX); + configuration.reverb_roomsize = constrain(configuration.reverb_roomsize, REVERB_ROOMSIZE_MIN, REVERB_ROOMSIZE_MAX); + configuration.reverb_damping = constrain(configuration.reverb_damping, REVERB_DAMPING_MIN, REVERB_DAMPING_MAX); + configuration.chorus_frequency = constrain(configuration.chorus_frequency, CHORUS_FREQUENCY_MIN, CHORUS_FREQUENCY_MAX); + configuration.chorus_waveform = constrain(configuration.chorus_waveform, CHORUS_WAVEFORM_MIN, CHORUS_WAVEFORM_MAX); + configuration.chorus_depth = constrain(configuration.chorus_depth, CHORUS_DEPTH_MIN, CHORUS_DEPTH_MAX); + configuration.delay_time = constrain(configuration.delay_time, DELAY_TIME_MIN, DELAY_TIME_MAX); + configuration.delay_feedback = constrain(configuration.delay_feedback, DELAY_FEEDBACK_MIN, DELAY_FEEDBACK_MAX); + for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) + { + configuration.dexed[instance_id].midi_channel = constrain(configuration.dexed[instance_id].midi_channel, MIDI_CHANNEL_MIN, MIDI_CHANNEL_MAX); + configuration.dexed[instance_id].bank = constrain(configuration.dexed[instance_id].bank, 0, MAX_BANKS); + configuration.dexed[instance_id].voice = constrain(configuration.dexed[instance_id].voice, 0, MAX_VOICES); + configuration.dexed[instance_id].reverb_send = constrain(configuration.dexed[instance_id].reverb_send, REVERB_SEND_MIN, REVERB_SEND_MAX); + configuration.dexed[instance_id].chorus_send = constrain(configuration.dexed[instance_id].chorus_send, CHORUS_SEND_MIN, CHORUS_SEND_MAX); + configuration.dexed[instance_id].delay_send = constrain(configuration.dexed[instance_id].delay_send, DELAY_SEND_MIN, DELAY_SEND_MAX); + configuration.dexed[instance_id].filter_cutoff = constrain(configuration.dexed[instance_id].filter_cutoff, FILTER_CUTOFF_MIN, FILTER_CUTOFF_MAX); + configuration.dexed[instance_id].filter_resonance = constrain(configuration.dexed[instance_id].filter_resonance, FILTER_RESONANCE_MIN, FILTER_RESONANCE_MAX); + configuration.dexed[instance_id].loudness = constrain(configuration.dexed[instance_id].loudness, LOUDNESS_MIN, LOUDNESS_MAX); + configuration.dexed[instance_id].polyphony = constrain(configuration.dexed[instance_id].polyphony, POLYPHONY_MIN, POLYPHONY_MAX); + configuration.dexed[instance_id].engine = constrain(configuration.dexed[instance_id].engine, ENGINE_MIN, ENGINE_MAX); + configuration.dexed[instance_id].monopoly = constrain(configuration.dexed[instance_id].monopoly, MONOPOLY_MIN, MONOPOLY_MAX); + configuration.dexed[instance_id].pb_range = constrain(configuration.dexed[instance_id].pb_range, PB_RANGE_MIN, PB_RANGE_MAX); + configuration.dexed[instance_id].pb_step = constrain(configuration.dexed[instance_id].pb_step, PB_STEP_MIN, PB_STEP_MAX); + configuration.dexed[instance_id].mw_range = constrain(configuration.dexed[instance_id].mw_range, MW_RANGE_MIN, MW_RANGE_MAX); + configuration.dexed[instance_id].mw_assign = constrain(configuration.dexed[instance_id].mw_assign, MW_ASSIGN_MIN, MW_ASSIGN_MAX); + configuration.dexed[instance_id].fc_range = constrain(configuration.dexed[instance_id].fc_range, FC_RANGE_MIN, FC_RANGE_MAX); + configuration.dexed[instance_id].fc_assign = constrain(configuration.dexed[instance_id].fc_assign, FC_ASSIGN_MIN, FC_ASSIGN_MAX); + configuration.dexed[instance_id].bc_range = constrain(configuration.dexed[instance_id].bc_range, BC_RANGE_MIN, BC_RANGE_MAX); + configuration.dexed[instance_id].bc_assign = constrain(configuration.dexed[instance_id].bc_assign, BC_ASSIGN_MIN, BC_ASSIGN_MAX); + configuration.dexed[instance_id].at_range = constrain(configuration.dexed[instance_id].at_range, AT_RANGE_MIN, AT_RANGE_MAX); + configuration.dexed[instance_id].at_assign = constrain(configuration.dexed[instance_id].at_assign, AT_ASSIGN_MIN, AT_ASSIGN_MAX); + configuration.dexed[instance_id].op_enabled = constrain(configuration.dexed[instance_id].op_enabled, OP_ENABLED_MIN, OP_ENABLED_MAX); + } } void init_configuration(void)