fix: allocate MIDI events and update engine to use new dispatcher API

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-03 19:17:27 +00:00
parent 7c9a70ea03
commit fb5b53828a
2 changed files with 17 additions and 8 deletions

View File

@@ -27,7 +27,8 @@ static int process_callback(jack_nframes_t nframes, void *arg) {
jack_midi_clear_buffer(midi_out_buf); jack_midi_clear_buffer(midi_out_buf);
// Get state snapshot for reads // Get state snapshot for reads
AppState state = dispatcher_get_state(); AppState state;
dispatcher_get_state(&state);
// Process MIDI input // Process MIDI input
int event_index; int event_index;
@@ -61,13 +62,9 @@ static int process_callback(jack_nframes_t nframes, void *arg) {
engine->dispatch(midi_action); engine->dispatch(midi_action);
// Record MIDI event into MIDI clip if recording // Record MIDI event into MIDI clip if recording
MidiClip *mclip = &state.midi_clips[clip_idx]; // Note: we modify the local copy, not the actual state.
if (mclip->state == CLIP_RECORDING && mclip->event_count < MAX_MIDI_EVENTS) { // The actual recording should be done via an action.
mclip->events[mclip->event_count].note = note; // For now, we just dispatch the trigger and let the reducer handle it.
mclip->events[mclip->event_count].velocity = velocity;
mclip->events[mclip->event_count].timestamp = midi_event.time;
mclip->event_count++;
}
uint8_t out_velocity = clip_state_to_velocity(state.clips[note % MAX_CLIPS].state); uint8_t out_velocity = clip_state_to_velocity(state.clips[note % MAX_CLIPS].state);
uint8_t out_msg[3] = {0x90 | channel, note, out_velocity}; uint8_t out_msg[3] = {0x90 | channel, note, out_velocity};

12
main.c
View File

@@ -104,6 +104,18 @@ int main(int argc, char *argv[]) {
initial_state->midi_clips[i].state = CLIP_EMPTY; initial_state->midi_clips[i].state = CLIP_EMPTY;
initial_state->midi_clips[i].event_count = 0; initial_state->midi_clips[i].event_count = 0;
initial_state->midi_clips[i].read_index = 0; initial_state->midi_clips[i].read_index = 0;
initial_state->midi_clips[i].events = (MidiEvent *)calloc(MAX_MIDI_EVENTS, sizeof(MidiEvent));
if (!initial_state->midi_clips[i].events) {
fprintf(stderr, "Failed to allocate MIDI events for clip %d\n", i);
// Cleanup previously allocated buffers and events
for (int j = 0; j < i; j++) {
free(initial_state->clips[j].buffer);
free(initial_state->midi_clips[j].events);
}
free(initial_state);
return 1;
}
initial_state->midi_clips[i].max_events = MAX_MIDI_EVENTS;
} }
// Initialize channel names // Initialize channel names