Skip to content

Commit d1b342f

Browse files
committed
misc
1 parent 3204c32 commit d1b342f

File tree

3 files changed

+73
-20
lines changed

3 files changed

+73
-20
lines changed

src/arpeggiator.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,15 @@ int arpeggiator_step(Arpeggiator *arp, float samplerate, struct Synth *synth) {
132132
if (!arp->enabled || arp->held_count == 0)
133133
return -1;
134134

135-
float step_time = 60.0f / arp->tempo / 4.0f;
135+
// Calculate step time based on rate
136+
float rate_divisor = 1.0f;
137+
switch (arp->rate) {
138+
case RATE_QUARTER: rate_divisor = 1.0f; break; // 1/4 notes
139+
case RATE_EIGHTH: rate_divisor = 2.0f; break; // 1/8 notes (default)
140+
case RATE_SIXTEENTH: rate_divisor = 4.0f; break; // 1/16 notes
141+
case RATE_THIRTYSECOND: rate_divisor = 8.0f; break; // 1/32 notes
142+
}
143+
float step_time = 60.0f / arp->tempo / rate_divisor;
136144

137145
// Turn off all notes from previous step before playing new ones
138146
for (int i = 0; i < 16; ++i) {

src/midi.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,34 +126,24 @@ void on_midi1_message(void* ctx, libremidi_timestamp ts, const libremidi_midi1_s
126126
unsigned char note = msg[1];
127127
unsigned char vel = msg[2];
128128

129-
// Log all MIDI events to console for debugging
130-
SDL_Log("[MIDI EVENT] ");
131-
132129
switch (status) {
133130
case 0x80: // Note Off
134-
SDL_Log("Note OFF: %d (vel=%d)\n", note, vel);
135131
if (synth->arp.enabled) {
136-
SDL_Log(" → Arpeggiator: note_off(%d)\n", note);
137132
arpeggiator_note_off(&synth->arp, note);
138133
} else {
139-
SDL_Log(" → Synthesizer: note_off(%d)\n", note);
140134
synth_note_off(synth, note);
141135
}
142136
break;
143137

144138
case 0x90: // Note On (with velocity)
145-
SDL_Log("Note ON: %d (vel=%d)\n", note, vel);
146139
if (synth->arp.enabled) {
147-
SDL_Log(" → Arpeggiator: note_on(%d, %0.3f)\n", note, vel / 127.0f);
148140
arpeggiator_note_on(&synth->arp, note);
149141
} else {
150-
SDL_Log(" → Synthesizer: note_on(%d, %0.3f)\n", note, vel / 127.0f);
151142
synth_note_on(synth, note, vel / 127.0f);
152143
}
153144
break;
154145

155146
case 0xB0: // Control Change
156-
SDL_Log("Control Change: CC=%d, value=%d\n", note, vel);
157147
// Store last CC info for GUI display
158148
synth->midi.last_cc = note;
159149
synth->midi.last_cc_value = vel;
@@ -521,19 +511,15 @@ void midi_init(Midi *midi, struct Synth *synth) {
521511
if (midi->enabled) {
522512
SDL_Log(" - Ready to receive MIDI input\n");
523513
} else {
524-
SDL_Log(" - WARNING: No MIDI devices available\n");
514+
SDL_Log(" - No MIDI devices available\n");
525515
}
526516
#endif
527517

528-
SDL_Log("=====================================\n\n");
529-
530518
midi->last_cc = -1;
531519
midi->last_cc_value = 0;
532520
}
533521

534522
void midi_shutdown(Midi *midi) {
535-
SDL_Log("Shutting down MIDI system...\n");
536-
537523
// First, set a flag to prevent any new MIDI processing
538524
midi->enabled = 0;
539525

@@ -559,8 +545,6 @@ void midi_shutdown(Midi *midi) {
559545
}
560546

561547
midi->device_count = 0;
562-
563-
SDL_Log("MIDI system shutdown complete\n");
564548
}
565549

566550
void midi_map_cc_to_param(struct Synth *synth, int cc, int value) {

src/synth.c

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)