Added JSON parser for drum configuration (drm/CFGDrums.json). A maximum of 24 drum-sounds can be configured. An "EMPTY" drum-sound for the step sequencer is added internally.

pull/58/head
Holger Wirtz 3 years ago
parent f55cc2b1db
commit 408d34d984
  1. 11
      MicroDexed.ino
  2. 2
      UI.hpp
  3. 10
      addon/SD/drm/CFGDrums.json
  4. 80
      drums.cpp
  5. 156
      drums.h

@ -326,9 +326,9 @@ int16_t delayline[NUM_DEXED][MOD_DELAY_SAMPLE_BUFFER];
#if NUM_DRUMS > 0
uint8_t num_drums = 0;
drum_config_t drum_config[DRUM_MAX_INSTRUMENTS];
drum_config_t drum_config[DRUM_MAX_INSTRUMENTS + 1];
uint8_t drum_counter;
uint8_t drum_type[DRUM_MAX_INSTRUMENTS];
uint8_t drum_type[DRUM_MAX_INSTRUMENTS + 1];
extern void sequencer(void);
#endif
@ -516,7 +516,7 @@ void setup()
}
else
{
read_drum_config();
num_drums = read_drum_config();
check_and_create_directories();
@ -758,7 +758,6 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity)
Serial.print(drum_counter, DEC);
Serial.print(F("]: "));
Serial.println(note_name);
Serial.println(inNumber);
#endif
for (uint8_t d = 0; d < num_drums; d++)
@ -786,9 +785,7 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity)
Serial.print(F(" P"));
Serial.print(drum_config[d].pan, 2);
Serial.print(F(" RS"));
Serial.print(drum_config[d].reverb_send, 2);
Serial.print(F(" fsin"));
Serial.println(fsin, 2);
Serial.println(drum_config[d].reverb_send, 2);
#endif
break;
}

@ -81,7 +81,7 @@ extern uint8_t seq_chain_active_chainstep; //for editor
extern uint8_t seq_chain_active_step;
#if NUM_DRUMS > 0
#include "drums.h"
extern drum_config_t drum_config[DRUM_MAX_INSTRUMENTS];
extern drum_config_t drum_config[DRUM_MAX_INSTRUMENTS + 1];
extern uint8_t num_drums;
#endif

@ -127,15 +127,5 @@
"vol_min": 0,
"reverb_send": 0
},
"EMPTY": {
"drum_class": "DRUM_NONE",
"midinote": "NONE",
"filename": "EMPTY",
"shortname": "-",
"pan": 0,
"vol_max": 0,
"vol_min": 0,
"reverb_send": 0
}
}
}

@ -31,11 +31,11 @@
#include "config.h"
#include "drums.h"
extern uint8_t num_drums;
extern drum_config_t drum_config[DRUM_MAX_INSTRUMENTS];
void read_drum_config(void)
uint8_t read_drum_config(void)
{
uint8_t config_drums = 0;
File json;
DynamicJsonDocument drums_json(4096);
@ -51,17 +51,17 @@ void read_drum_config(void)
deserializeJson(drums_json, json);
json.close();
num_drums = drums_json.size();
config_drums = drums_json["drums"].size();
#ifdef DEBUG
Serial.print(F("Drum Objects: "));
Serial.println(num_drums);
if (num_drums > DRUM_MAX_INSTRUMENTS)
Serial.println(config_drums);
if (config_drums > DRUM_MAX_INSTRUMENTS)
Serial.println(F("*** Maximum number of drum samples exceeded! ***"));
//Serial.println(F("Drum Configuration:"));
//serializeJsonPretty(drums_json, Serial);
//Serial.println();
#endif
num_drums = constrain(num_drums, 0, DRUM_MAX_INSTRUMENTS);
config_drums = constrain(config_drums, 0, DRUM_MAX_INSTRUMENTS);
}
}
AudioInterrupts();
@ -123,7 +123,7 @@ void read_drum_config(void)
switch (midi_note[0])
{
case 'A':
case 'C':
if (midi_note[1] == '#')
{
note_number = 1;
@ -135,23 +135,23 @@ void read_drum_config(void)
oct = midi_note[1] - 48;
}
break;
case 'B':
note_number = 2;
oct = midi_note[1] - 48;
break;
case 'C':
case 'D':
if (midi_note[1] == '#')
{
note_number = 4;
note_number = 3;
oct = midi_note[2] - 48;
}
else
{
note_number = 3;
note_number = 2;
oct = midi_note[1] - 48;
}
break;
case 'D':
case 'E':
note_number = 4;
oct = midi_note[1] - 48;
break;
case 'F':
if (midi_note[1] == '#')
{
note_number = 6;
@ -163,36 +163,36 @@ void read_drum_config(void)
oct = midi_note[1] - 48;
}
break;
case 'E':
note_number = 7;
oct = midi_note[1] - 48;
break;
case 'F':
case 'G':
if (midi_note[1] == '#')
{
note_number = 9;
note_number = 8;
oct = midi_note[2] - 48;
}
else
{
note_number = 8;
note_number = 7;
oct = midi_note[1] - 48;
}
break;
case 'G':
case 'A':
if (midi_note[1] == '#')
{
note_number = 11;
note_number = 10;
oct = midi_note[2] - 48;
}
else
{
note_number = 10;
note_number = 9;
oct = midi_note[1] - 48;
}
break;
case 'B':
note_number = 11;
oct = midi_note[1] - 48;
break;
}
drum_config[drum].midinote = note_number + 9 + (oct * 12);
drum_config[drum].midinote = constrain(note_number + 12 + (oct * 12), 21, 127);
}
}
else if (strcmp(drum_kv.key().c_str(), "shortname") == 0)
@ -204,30 +204,30 @@ void read_drum_config(void)
else if (strcmp(drum_kv.key().c_str(), "pan") == 0)
{
if (drum_kv.value().is<float>())
drum_config[drum].pan = drum_kv.value().as<float>();
drum_config[drum].pan = constrain(drum_kv.value().as<float>(), 0.0, 1.0);
if (drum_kv.value().is<int>())
drum_config[drum].pan = float(drum_kv.value().as<int>());
drum_config[drum].pan = constrain(float(drum_kv.value().as<int>()), 0.0, 1.0);
}
else if (strcmp(drum_kv.key().c_str(), "vol_max") == 0)
{
if (drum_kv.value().is<float>())
drum_config[drum].vol_max = drum_kv.value().as<float>();
drum_config[drum].vol_max = constrain(drum_kv.value().as<float>(), 0.0, 1.0);
if (drum_kv.value().is<int>())
drum_config[drum].vol_max = float(drum_kv.value().as<int>());
drum_config[drum].vol_max = constrain(float(drum_kv.value().as<int>()), 0.0, 1.0);
}
else if (strcmp(drum_kv.key().c_str(), "vol_min") == 0)
{
if (drum_kv.value().is<float>())
drum_config[drum].vol_min = drum_kv.value().as<float>();
drum_config[drum].vol_min = constrain(drum_kv.value().as<float>(), 0.0, 1.0);
if (drum_kv.value().is<int>())
drum_config[drum].vol_min = float(drum_kv.value().as<int>());
drum_config[drum].vol_min = constrain(float(drum_kv.value().as<int>()), 0.0, 1.0);
}
else if (strcmp(drum_kv.key().c_str(), "reverb_send") == 0)
{
if (drum_kv.value().is<float>())
drum_config[drum].reverb_send = drum_kv.value().as<float>();
drum_config[drum].reverb_send = constrain(drum_kv.value().as<float>(), 0.0, 1.0);
if (drum_kv.value().is<int>())
drum_config[drum].reverb_send = float(drum_kv.value().as<int>());
drum_config[drum].reverb_send = constrain(float(drum_kv.value().as<int>()), 0.0, 1.0);
}
}
@ -254,4 +254,16 @@ void read_drum_config(void)
#endif
drum++;
}
drum++;
drum_config[drum].drum_class = DRUM_NONE;
drum_config[drum].midinote = 0;
strcpy(drum_config[drum].filename, "EMPTY");
strcpy(drum_config[drum].shortname, "-");
drum_config[drum].pan = 0.0;
drum_config[drum].vol_max = 0.0;
drum_config[drum].vol_min = 0.0;
drum_config[drum].reverb_send = 0.0;
return (drum);
}

@ -31,7 +31,7 @@
#ifndef _DRUMS_H
#define _DRUMS_H
void read_drum_config(void);
uint8_t read_drum_config(void);
typedef struct drum_config_s {
uint8_t drum_class; // Type of drum
@ -46,158 +46,4 @@ typedef struct drum_config_s {
enum {DRUM_NONE, DRUM_BASS, DRUM_SNARE, DRUM_HIHAT, DRUM_HANDCLAP, DRUM_RIDE, DRUM_CHRASH, DRUM_LOWTOM, DRUM_MIDTOM, DRUM_HIGHTOM, DRUM_PERCUSSION};
//drum_config_t drum_config[DRUM_MAX_INSTRUMENTS];
/* = {
{
DRUM_BASS,
MIDI_C3,
"/drm/bd01.wav",
"B",
0.0,
0.8,
0.0,
0.0
},
{
DRUM_HANDCLAP,
MIDI_CIS3,
"/drm/cp02.wav",
"C",
-0.4,
0.6,
0.0,
0.4
},
{
DRUM_SNARE,
MIDI_D3,
"/drm/sd15.wav",
"S",
0.2,
0.6,
0.2,
0.0
},
{
DRUM_HIHAT,
MIDI_FIS3,
"/drm/hh01.wav",
"h",
0.8,
0.2,
0.0,
0.0
},
{
DRUM_HIHAT,
MIDI_GIS3,
"/drm/hh02.wav",
"h",
0.8,
0.2,
0.0,
0.0
},
{
DRUM_HIHAT,
MIDI_AIS3,
"/drm/oh02.wav",
"H",
0.8,
0.2,
0.0,
0.0
},
{
DRUM_LOWTOM,
MIDI_G3,
"/drm/lt01.wav",
"T",
-0.7,
0.8,
0.0,
0.0
},
{
DRUM_HIGHTOM,
MIDI_A3,
"/drm/ht01.wav",
"T",
-0.5,
0.8,
0.0,
0.0
},
{
DRUM_RIDE,
MIDI_CIS4,
"/drm/rd01.wav",
"R",
-0.6,
0.3,
0.0,
0.0
},
{
DRUM_RIDE,
MIDI_DIS4,
"/drm/rd02.wav",
"R",
-0.6,
0.3,
0.0,
0.0
},
{
DRUM_BASS,
MIDI_C5,
"/drm/PHKick1.wav",
"B",
-1.0,
0.9,
0.0,
0.0
},
{
DRUM_HANDCLAP,
MIDI_DIS5,
"/drm/808Clap1.wav",
"C",
1.0,
0.9,
0.0,
0.1
},
{
DRUM_SNARE,
MIDI_CIS5,
"/drm/808RimS1.wav",
"R",
-0.3,
0.5,
0.0,
0.0
},
{
DRUM_HIHAT,
MIDI_FIS5,
"/drm/808HHCL1.wav",
"H",
1.0,
0.6,
0.0,
0.0
},
{
DRUM_NONE,
0,
"/drm/EMPTY ",
"-",
0.0,
0.0,
0.0,
0.0
}
};
*/
#endif

Loading…
Cancel
Save