From 66b872db9638a946e47479e3387a38d4d49c2406 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 16 Jul 2021 10:08:46 +0200 Subject: [PATCH] Fixes for synced delay calculation. --- MicroDexed.ino | 25 +++++++++++++----------- UI.hpp | 4 ++-- third-party/Synth_Dexed/tools/sysex2c.py | 5 ++++- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 99fe769..13c5852 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -45,7 +45,7 @@ // Audio engines AudioSynthDexed* MicroDexed[NUM_DEXED]; -AudioEffectDynamics* dynamics[NUM_DEXED]; +AudioEffectDynamics* dynamics[NUM_DEXED]; #if defined(USE_FX) AudioSynthWaveform* chorus_modulator[NUM_DEXED]; @@ -222,11 +222,12 @@ void create_audio_engine_chain(uint8_t instance_id) uint8_t sd_card = 0; Sd2Card card; SdVolume volume; -float midi_ticks_factor[10] = {0.0, 0.0625, 0.09375, 0.125, 0.1875, 0.25, 0.375, 0.5, 0.75 , 1.0}; +//float midi_ticks_factor[10] = {0.0, 0.0625, 0.09375, 0.125, 0.1875, 0.25, 0.375, 0.5, 0.75 , 1.0}; +float midi_ticks_factor[10] = {0.0, 0.25, 0.375, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0 , 4.0}; uint8_t midi_bpm_counter = 0; uint8_t midi_bpm = 0; int16_t _midi_bpm = -1; -bool midi_clock_running = false; +//midi_bpmbool midi_clock_running = false; elapsedMillis midi_bpm_timer; elapsedMillis long_button_pressed; elapsedMillis control_rate; @@ -282,7 +283,7 @@ extern void getNoteName(char* noteName, uint8_t noteNumber); SETUP ***********************************************************************/ void setup() -{ +{ #ifdef DISPLAY_LCD_SPI pinMode(SDCARD_CS_PIN, OUTPUT); pinMode(U8X8_CS_PIN, OUTPUT); @@ -1370,8 +1371,8 @@ void handleTuneRequest(void) void handleClock(void) { - if (midi_clock_running != true) - return; + //if (midi_clock_running != true) + // return; if (midi_bpm_counter % 24 == 0) { @@ -1403,10 +1404,12 @@ void handleClock(void) { if (configuration.fx.delay_sync[instance_id] > 0) { - uint16_t midi_sync_delay_time = uint16_t(60.0 / float(midi_bpm) * 1000.0 * midi_ticks_factor[configuration.fx.delay_sync[instance_id]] + 0.5); + uint16_t midi_sync_delay_time = uint16_t(60000.0 * midi_ticks_factor[configuration.fx.delay_sync[instance_id]] / float(midi_bpm) + 0.5); delay_fx[instance_id]->delay(0, constrain(midi_sync_delay_time, DELAY_TIME_MIN * 10, DELAY_TIME_MAX * 10)); #ifdef DEBUG - Serial.print(F("Setting Delay-Sync to ")); + Serial.print(F("Setting Delay-Sync of instance ")); + Serial.print(instance_id); + Serial.print(F(" to ")); Serial.print(constrain(midi_sync_delay_time, DELAY_TIME_MIN * 10, DELAY_TIME_MAX * 10), DEC); Serial.println(F(" ms")); #endif @@ -1425,7 +1428,7 @@ void handleClock(void) void handleStart(void) { - midi_clock_running = true; + //midi_clock_running = true; midi_bpm_timer = 0; midi_bpm_counter = 0; _midi_bpm = -1; @@ -1433,12 +1436,12 @@ void handleStart(void) void handleContinue(void) { - midi_clock_running = true; + //midi_clock_running = true; } void handleStop(void) { - midi_clock_running = false; + //midi_clock_running = false; } void handleActiveSensing(void) diff --git a/UI.hpp b/UI.hpp index f4b87a1..d6e366c 100644 --- a/UI.hpp +++ b/UI.hpp @@ -6068,12 +6068,12 @@ void lcd_display_delay_sync(uint8_t sync) break; } - uint16_t midi_sync_delay_time = uint16_t(1000.0 * midi_bpm * midi_ticks_factor[sync] / 60.0 + 0.5); + uint16_t midi_sync_delay_time = uint16_t(60000.0 * midi_ticks_factor[sync] / midi_bpm + 0.5); if (midi_sync_delay_time > DELAY_MAX_TIME) { #ifdef DEBUG Serial.println(F("Calculated MIDI-Sync delay: ")); - Serial.print(round(1000.0 * midi_bpm * midi_ticks_factor[sync] / 60.0), DEC); + Serial.print(round(60000.0 * midi_ticks_factor[sync] / midi_bpm), DEC); Serial.println(F("ms")); Serial.println(F("MIDI-Sync delay: midi_sync_delay_time")); Serial.print(midi_sync_delay_time, DEC); diff --git a/third-party/Synth_Dexed/tools/sysex2c.py b/third-party/Synth_Dexed/tools/sysex2c.py index 9a8bba0..d033f84 100755 --- a/third-party/Synth_Dexed/tools/sysex2c.py +++ b/third-party/Synth_Dexed/tools/sysex2c.py @@ -93,6 +93,8 @@ print(""" // // File generated with sysex2c.py // + +#pragma once """) if(decode==True): print("uint8_t progmem_bank[%d][32][156] PROGMEM =\n{" % int(len(sys.argv))) @@ -132,7 +134,8 @@ for sysex in sys.argv: for v in range(1,33): data=f.read(128) - print("\t\t{\t// %d: %s" % (v, data[118:128].decode('ascii'))) + patchname=str(data[118:128].decode('ascii')).upper().replace('\\','') + print("\t\t{\t// %d: %s" % (v, patchname)) if(decode==True): print_header_data(unpack_packed_patch(data)) else: