@@ -167,7 +167,7 @@ int synth_init(Synth *synth, int samplerate, int buffer_size, int voices) {
167167 arpeggiator_init (& synth -> arp );
168168
169169
170- synth -> arp .enabled = 0 ; // Will be enabled when progression starts
170+ synth -> arp .enabled = 1 ; // Will be enabled when progression starts
171171 synth -> arp .tempo = 120.0f ;
172172 synth -> arp .mode = ARP_UP ;
173173
@@ -189,7 +189,8 @@ int synth_init(Synth *synth, int samplerate, int buffer_size, int voices) {
189189 synth_set_param (synth , "lfo2.sync" , 1.0f ); // LFO_SYNC_RETRIGGER
190190 synth_set_param (synth , "lfo3.sync" , 1.0f ); // LFO_SYNC_RETRIGGER
191191
192- synth_play_startup_melody (synth ); // Start the melody at startup
192+ // synth_play_startup_melody(synth); // Start the melody at startup
193+
193194 char param_name [16 ];
194195 for (int i = 0 ; i < 6 ; ++ i ) { // Loop for all 6 oscillators
195196 osc_init (& synth -> osc [i ], samplerate );
@@ -496,6 +497,20 @@ char* synth_save_preset_json(const Synth *synth) {
496497 cJSON_AddBoolToObject (arp , "enabled" , synth -> arp .enabled );
497498 cJSON_AddNumberToObject (arp , "mode" , synth -> arp .mode );
498499 cJSON_AddNumberToObject (arp , "tempo" , synth -> arp .tempo );
500+ cJSON_AddNumberToObject (arp , "rate" , synth -> arp .rate );
501+ cJSON_AddBoolToObject (arp , "polyphonic" , synth -> arp .polyphonic );
502+ cJSON_AddBoolToObject (arp , "hold" , synth -> arp .hold );
503+ cJSON_AddNumberToObject (arp , "octave" , synth -> arp .octave );
504+ cJSON_AddNumberToObject (arp , "octaves" , synth -> arp .octaves );
505+
506+ // Chord generation parameters
507+ cJSON_AddNumberToObject (arp , "chord_type" , synth -> arp .chord_type );
508+ cJSON_AddBoolToObject (arp , "add_6" , synth -> arp .add_6 );
509+ cJSON_AddBoolToObject (arp , "add_m7" , synth -> arp .add_m7 );
510+ cJSON_AddBoolToObject (arp , "add_M7" , synth -> arp .add_M7 );
511+ cJSON_AddBoolToObject (arp , "add_9" , synth -> arp .add_9 );
512+ cJSON_AddNumberToObject (arp , "voicing" , synth -> arp .voicing );
513+
499514 cJSON_AddItemToObject (root , "arpeggiator" , arp );
500515
501516 char * json_string = cJSON_Print (root );
@@ -662,6 +677,52 @@ void synth_load_preset_json(Synth *synth, const char *json_string) {
662677 if (cJSON_IsNumber (tempo )) {
663678 synth_set_param (synth , "arp.tempo" , (float )tempo -> valuedouble );
664679 }
680+ cJSON * rate = cJSON_GetObjectItemCaseSensitive (arp , "rate" );
681+ if (cJSON_IsNumber (rate )) {
682+ synth_set_param (synth , "arp.rate" , (float )rate -> valuedouble );
683+ }
684+ cJSON * polyphonic = cJSON_GetObjectItemCaseSensitive (arp , "polyphonic" );
685+ if (cJSON_IsBool (polyphonic )) {
686+ synth_set_param (synth , "arp.polyphonic" , (float )cJSON_IsTrue (polyphonic ));
687+ }
688+ cJSON * hold = cJSON_GetObjectItemCaseSensitive (arp , "hold" );
689+ if (cJSON_IsBool (hold )) {
690+ synth_set_param (synth , "arp.hold" , (float )cJSON_IsTrue (hold ));
691+ }
692+ cJSON * octave = cJSON_GetObjectItemCaseSensitive (arp , "octave" );
693+ if (cJSON_IsNumber (octave )) {
694+ synth_set_param (synth , "arp.octave" , (float )octave -> valuedouble );
695+ }
696+ cJSON * octaves = cJSON_GetObjectItemCaseSensitive (arp , "octaves" );
697+ if (cJSON_IsNumber (octaves )) {
698+ synth_set_param (synth , "arp.octaves" , (float )octaves -> valuedouble );
699+ }
700+
701+ // Chord generation parameters
702+ cJSON * chord_type = cJSON_GetObjectItemCaseSensitive (arp , "chord_type" );
703+ if (cJSON_IsNumber (chord_type )) {
704+ synth_set_param (synth , "arp.chord_type" , (float )chord_type -> valuedouble );
705+ }
706+ cJSON * add_6 = cJSON_GetObjectItemCaseSensitive (arp , "add_6" );
707+ if (cJSON_IsBool (add_6 )) {
708+ synth_set_param (synth , "arp.add_6" , (float )cJSON_IsTrue (add_6 ));
709+ }
710+ cJSON * add_m7 = cJSON_GetObjectItemCaseSensitive (arp , "add_m7" );
711+ if (cJSON_IsBool (add_m7 )) {
712+ synth_set_param (synth , "arp.add_m7" , (float )cJSON_IsTrue (add_m7 ));
713+ }
714+ cJSON * add_M7 = cJSON_GetObjectItemCaseSensitive (arp , "add_M7" );
715+ if (cJSON_IsBool (add_M7 )) {
716+ synth_set_param (synth , "arp.add_M7" , (float )cJSON_IsTrue (add_M7 ));
717+ }
718+ cJSON * add_9 = cJSON_GetObjectItemCaseSensitive (arp , "add_9" );
719+ if (cJSON_IsBool (add_9 )) {
720+ synth_set_param (synth , "arp.add_9" , (float )cJSON_IsTrue (add_9 ));
721+ }
722+ cJSON * voicing = cJSON_GetObjectItemCaseSensitive (arp , "voicing" );
723+ if (cJSON_IsNumber (voicing )) {
724+ synth_set_param (synth , "arp.voicing" , (float )voicing -> valuedouble );
725+ }
665726 }
666727
667728 cJSON_Delete (root );
0 commit comments