refactor: convert MidiClip events to dynamic allocation to reduce stack size
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
23
dispatcher.c
23
dispatcher.c
@@ -495,6 +495,7 @@ AppState reducer(AppState state, Action action) {
|
||||
state.midi_clips[idx].state = CLIP_EMPTY;
|
||||
state.midi_clips[idx].event_count = 0;
|
||||
state.midi_clips[idx].read_index = 0;
|
||||
// Don't free events here - just reset count
|
||||
}
|
||||
return state;
|
||||
}
|
||||
@@ -526,6 +527,13 @@ AppState reducer(AppState state, Action action) {
|
||||
} else {
|
||||
clip->buffer = (float *)calloc(MAX_BUFFER_SIZE, sizeof(float));
|
||||
}
|
||||
|
||||
// NEW: Reset midi clips
|
||||
MidiClip *mclip = &state.midi_clips[i];
|
||||
mclip->state = CLIP_EMPTY;
|
||||
mclip->event_count = 0;
|
||||
mclip->read_index = 0;
|
||||
// events pointer should already be valid from init
|
||||
}
|
||||
|
||||
// Reset Carla host
|
||||
@@ -595,6 +603,15 @@ static void* dispatcher_thread_func(void *arg) {
|
||||
|
||||
DispatchFn dispatcher_init(AppState *initial_state) {
|
||||
memcpy(&dispatcher.state, initial_state, sizeof(AppState));
|
||||
|
||||
// NEW: Ensure midi clip events are allocated (in case initial_state has NULL pointers)
|
||||
for (int i = 0; i < MAX_CLIPS; i++) {
|
||||
if (dispatcher.state.midi_clips[i].events == NULL) {
|
||||
dispatcher.state.midi_clips[i].events = (MidiEvent *)calloc(MAX_MIDI_EVENTS, sizeof(MidiEvent));
|
||||
dispatcher.state.midi_clips[i].max_events = MAX_MIDI_EVENTS;
|
||||
}
|
||||
}
|
||||
|
||||
atomic_store(&dispatcher.running, false);
|
||||
atomic_store(&dispatcher.write_index, 0);
|
||||
atomic_store(&dispatcher.read_index, 0);
|
||||
@@ -617,6 +634,12 @@ void dispatcher_stop(void) {
|
||||
pthread_cond_signal(&dispatcher.action_cond);
|
||||
pthread_join(dispatcher.thread, NULL);
|
||||
|
||||
// NEW: Free midi clip events
|
||||
for (int i = 0; i < MAX_CLIPS; i++) {
|
||||
free(dispatcher.state.midi_clips[i].events);
|
||||
dispatcher.state.midi_clips[i].events = NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&dispatcher.subscribers_mutex);
|
||||
SubscriberNode *node = dispatcher.subscribers;
|
||||
while (node) {
|
||||
|
||||
Reference in New Issue
Block a user