@ -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 ) ;
}