From 3197d138ada7fcd759aeee01595886626f8acd4c Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 3 Aug 2021 08:28:20 +0200 Subject: [PATCH] Commit before merge. --- MicroDexed.ino | 38 ++--------- UI.hpp | 7 +-- .../drm/{CFG_MDDrums.json => CFGDrums.json} | 0 config.h | 2 +- dexed_sd.cpp | 12 +--- drums.cpp | 63 +++++++++++++++++++ drums.h | 18 +++--- sequencer.cpp | 2 +- 8 files changed, 85 insertions(+), 57 deletions(-) rename addon/SD/drm/{CFG_MDDrums.json => CFGDrums.json} (100%) create mode 100644 drums.cpp diff --git a/MicroDexed.ino b/MicroDexed.ino index 7a12239..e23f412 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -245,8 +245,6 @@ void create_audio_dexed_chain(uint8_t instance_id) #ifdef DEBUG Serial.print(F("Dexed-Instance: ")); Serial.println(instance_id); - Serial.print(F("Dynamic-Connection-Counter=")); - Serial.println(nDynamic); #endif } @@ -274,6 +272,7 @@ void create_audio_drum_chain(uint8_t instance_id) } #endif +StaticJsonDocument data_json; uint8_t sd_card = 0; Sd2Card card; SdVolume volume; @@ -325,10 +324,7 @@ int perform_release_mod[NUM_DEXED] = { 0 }; int16_t delayline[NUM_DEXED][MOD_DELAY_SAMPLE_BUFFER]; #endif -#if NUM_DRUMS > 1 -extern uint8_t drum_counter; -extern uint8_t drum_type[NUM_DRUMS]; -extern drum_config_t drum_config[NUM_DRUMCONFIG]; +#if NUM_DRUMS > 0 extern void sequencer(void); #endif @@ -472,32 +468,6 @@ void setup() #endif create_audio_drum_chain(instance_id); - File json; - // first check if file exists... - AudioNoInterrupts(); - if (SD.exists("/DRM/CFG_MDDrums.json")) - { - // ... and if: load -#ifdef DEBUG - Serial.println(F("Found drum configuration file.")); -#endif - json = SD.open("/DRM/CFG_MDDrums.json"); - if (json) - { - StaticJsonDocument data_json; - JsonObject object = data_json.to(); - - deserializeJson(data_json, json); - deserializeJson(data_json, Serial); - json.close(); - - Serial.print(F("objects: ")); - Serial.println(object["drums"].size()); - - } - } - AudioInterrupts(); - drum_mixer_r.gain(instance_id, 1.0); drum_mixer_l.gain(instance_id, 1.0); drum_reverb_send_mixer_r.gain(instance_id, 0.0); @@ -542,6 +512,8 @@ void setup() } else { + read_drum_config(); + check_and_create_directories(); for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) @@ -788,7 +760,7 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) { if (inNumber == drum_config[d].midinote) { - uint8_t slot = drum_get_slot(drum_config[d].type); + uint8_t slot = drum_get_slot(drum_config[d].drum_class); float fsin = mapfloat(arm_sin_f32(drum_config[d].pan * PI / 2.0), -1.0, 1.0, 0.0, 1.0); drum_mixer_r.gain(slot, (1.0 - fsin) * pseudo_log_curve(mapfloat(inVelocity, 0, 127, drum_config[d].vol_min, drum_config[d].vol_max))); diff --git a/UI.hpp b/UI.hpp index f3e43e3..d216099 100644 --- a/UI.hpp +++ b/UI.hpp @@ -37,6 +37,9 @@ #include "effect_freeverbf.h" #endif #include "synth_dexed.h" +#if NUM_DRUMS > 0 +#include "drums.h" +#endif #include #include @@ -78,9 +81,6 @@ extern bool seq_button_r; extern uint8_t seq_chain_select_menu; extern uint8_t seq_chain_active_menu; extern uint8_t seq_chain_active_chainstep; -#if NUM_DRUMS > 0 -#include "drums.h" -#endif #ifdef DISPLAY_LCD_SPI extern void change_disp_sd(bool d); @@ -123,7 +123,6 @@ extern int perform_release_mod[NUM_DEXED]; extern float midi_ticks_factor[10]; extern uint8_t midi_bpm; - /*********************************************************************** GLOBAL ************************************************************************/ diff --git a/addon/SD/drm/CFG_MDDrums.json b/addon/SD/drm/CFGDrums.json similarity index 100% rename from addon/SD/drm/CFG_MDDrums.json rename to addon/SD/drm/CFGDrums.json diff --git a/config.h b/config.h index 2d3eae3..f6e0aa2 100644 --- a/config.h +++ b/config.h @@ -611,7 +611,7 @@ #define EQ_TREBLE_DEFAULT 0 // Buffer for load/save configuration as JSON -#define JSON_BUFFER 1024 +#define JSON_BUFFER 3072 // Internal configuration structure typedef struct dexed_s { diff --git a/dexed_sd.cpp b/dexed_sd.cpp index 4b14e59..b07da7b 100644 --- a/dexed_sd.cpp +++ b/dexed_sd.cpp @@ -35,6 +35,7 @@ extern void init_MIDI_send_CC(void); extern void check_configuration_dexed(uint8_t instance_id); extern void check_configuration_performance(void); extern void check_configuration_fx(void); +extern StaticJsonDocument data_json; /****************************************************************************** SD BANK/VOICE LOADING @@ -424,8 +425,6 @@ bool load_sd_voiceconfig_json(int8_t vc, uint8_t instance_id) json = SD.open(filename); if (json) { - StaticJsonDocument data_json; - deserializeJson(data_json, json); json.close(); @@ -519,8 +518,6 @@ bool save_sd_voiceconfig_json(uint8_t vc, uint8_t instance_id) json = SD.open(filename, FILE_WRITE); if (json) { - StaticJsonDocument data_json; - data_json["lowest_note"] = configuration.dexed[instance_id].lowest_note; data_json["highest_note"] = configuration.dexed[instance_id].highest_note; data_json["transpose"] = configuration.dexed[instance_id].transpose; @@ -608,8 +605,6 @@ bool load_sd_fx_json(int8_t fx) json = SD.open(filename); if (json) { - StaticJsonDocument data_json; - deserializeJson(data_json, json); json.close(); @@ -694,8 +689,6 @@ bool save_sd_fx_json(uint8_t fx) json = SD.open(filename, FILE_WRITE); if (json) { - StaticJsonDocument data_json; - for (uint8_t i = 0; i < MAX_DEXED; i++) { data_json["filter_cutoff"][i] = configuration.fx.filter_cutoff[i]; @@ -775,7 +768,6 @@ bool load_sd_performance_json(int8_t p) json = SD.open(filename); if (json) { - StaticJsonDocument data_json; deserializeJson(data_json, json); json.close(); AudioInterrupts(); @@ -876,8 +868,6 @@ bool save_sd_performance_json(uint8_t p) json = SD.open(filename, FILE_WRITE); if (json) { - StaticJsonDocument data_json; - for (uint8_t i = 0; i < MAX_DEXED; i++) { data_json["bank"][i] = configuration.performance.bank[i]; diff --git a/drums.cpp b/drums.cpp new file mode 100644 index 0000000..1e94738 --- /dev/null +++ b/drums.cpp @@ -0,0 +1,63 @@ +/* + MicroDexed + + MicroDexed is a port of the Dexed sound engine + Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android + + (c)2018-2021 H. Wirtz + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include +#include +#include +#include "config.h" + + +void read_drum_config(void) +{ + File json; + + AudioNoInterrupts(); + if (SD.exists("/DRM/CFGDrums.json")) + { +#ifdef DEBUG + Serial.println(F("Found drum configuration file.")); +#endif + json = SD.open("/DRM/CFGDrums.json"); + if (json) + { + DynamicJsonDocument drums_json(5000); + + deserializeJson(drums_json, json); +#ifdef DEBUG + Serial.println("Drums:"); + serializeJsonPretty(drums_json, Serial); + Serial.println(); + Serial.print(F("Drum Objects: ")); + Serial.println(drums_json["drums"].size()); +#endif + json.close(); + + while (1); + } + } + AudioInterrupts(); +} diff --git a/drums.h b/drums.h index 4f9c8ea..e9ce8e9 100644 --- a/drums.h +++ b/drums.h @@ -25,18 +25,18 @@ THE SOFTWARE. */ -#pragma once +#include +#include "config.h" -#if NUM_DRUMS >1 -uint8_t drum_counter; -uint8_t drum_type[NUM_DRUMS]; +#ifndef _DRUMS_H +#define _DRUMS_H -enum {DRUM_NONE, DRUM_BASS, DRUM_SNARE, DRUM_HIHAT, DRUM_HANDCLAP, DRUM_RIDE, DRUM_CHRASH, DRUM_LOWTOM, DRUM_MIDTOM, DRUM_HIGHTOM, DRUM_PERCUSSION}; +void read_drum_config(void); typedef struct drum_config_s { - uint8_t type; // Type of drum + uint8_t drum_class; // Type of drum uint8_t midinote; // Triggered by note - char filename[18]; // 44.1kHz mono LSB raw-sample to play + char filename[18]; // 44.1kHz mono LSB wav-sample char shortname[2]; // 1 char name for sequencer float32_t pan; // Panorama (-1.0 - +1.0) float32_t vol_max; // max. Volume (0.0 - 1.0) @@ -44,6 +44,10 @@ typedef struct drum_config_s { float32_t reverb_send; // how much signal to send to the reverb (0.0 - 1.0) } drum_config_t; +enum {DRUM_NONE, DRUM_BASS, DRUM_SNARE, DRUM_HIHAT, DRUM_HANDCLAP, DRUM_RIDE, DRUM_CHRASH, DRUM_LOWTOM, DRUM_MIDTOM, DRUM_HIGHTOM, DRUM_PERCUSSION}; + +uint8_t drum_counter; +uint8_t drum_type[NUM_DRUMS]; #define NUM_DRUMCONFIG 15 drum_config_t drum_config[NUM_DRUMCONFIG] = { { diff --git a/sequencer.cpp b/sequencer.cpp index b1adb9d..8e7ff8c 100644 --- a/sequencer.cpp +++ b/sequencer.cpp @@ -12,7 +12,7 @@ extern void handleNoteOff(byte , byte , byte ); extern void UI_func_sequencer(uint8_t); extern const char* seq_find_shortname(uint8_t); -void sequencer() +void sequencer(void) { bool seq_noteoffsent = false;