feat: implement scene infrastructure for multi-scene looper support
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
@@ -5,6 +5,13 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Helper: zero a scene and set its state to IDLE */
|
||||
static void init_scene(scene_t *sc) {
|
||||
memset(sc, 0, sizeof(scene_t));
|
||||
atomic_store(&sc->state, STATE_IDLE);
|
||||
sc->prev_state = -1;
|
||||
}
|
||||
|
||||
void channel_add(jack_client_t *client, int idx) {
|
||||
struct channel_t *cur = get_channels_array();
|
||||
|
||||
@@ -24,12 +31,10 @@ void channel_add(jack_client_t *client, int idx) {
|
||||
}
|
||||
|
||||
atomic_store(&cur[idx].active, 1);
|
||||
atomic_store(&cur[idx].state, STATE_IDLE);
|
||||
cur[idx].prev_state = -1;
|
||||
cur[idx].loop_count = 0;
|
||||
cur[idx].record_pos = 0;
|
||||
cur[idx].playback_pos = 0;
|
||||
cur[idx].type = CHANNEL_AUDIO;
|
||||
cur[idx].scene_count = 1;
|
||||
cur[idx].current_scene = 0;
|
||||
init_scene(&cur[idx].scenes[0]);
|
||||
|
||||
next_channel_id++;
|
||||
atomic_fetch_add(&channel_count, 1);
|
||||
@@ -54,12 +59,10 @@ void channel_add_midi(jack_client_t *client, int idx) {
|
||||
}
|
||||
|
||||
atomic_store(&cur[idx].active, 1);
|
||||
atomic_store(&cur[idx].state, STATE_IDLE);
|
||||
cur[idx].prev_state = -1;
|
||||
cur[idx].loop_count = 0;
|
||||
cur[idx].record_pos = 0;
|
||||
cur[idx].playback_pos = 0;
|
||||
cur[idx].type = CHANNEL_MIDI;
|
||||
cur[idx].scene_count = 1;
|
||||
cur[idx].current_scene = 0;
|
||||
init_scene(&cur[idx].scenes[0]);
|
||||
|
||||
next_channel_id++;
|
||||
atomic_fetch_add(&channel_count, 1);
|
||||
@@ -71,3 +74,47 @@ void channel_remove(jack_client_t *client, int idx) {
|
||||
atomic_store(&cur[idx].active, 0);
|
||||
atomic_fetch_sub(&channel_count, 1);
|
||||
}
|
||||
|
||||
void channel_add_scene(jack_client_t *client, int idx) {
|
||||
(void)client;
|
||||
struct channel_t *cur = get_channels_array();
|
||||
if (cur[idx].scene_count >= MAX_SCENES)
|
||||
return;
|
||||
int ns = cur[idx].scene_count;
|
||||
init_scene(&cur[idx].scenes[ns]);
|
||||
cur[idx].scene_count++;
|
||||
}
|
||||
|
||||
void channel_remove_scene(jack_client_t *client, int idx) {
|
||||
(void)client;
|
||||
struct channel_t *cur = get_channels_array();
|
||||
if (cur[idx].scene_count <= 1)
|
||||
return;
|
||||
int cs = cur[idx].current_scene;
|
||||
/* shift remaining scenes down */
|
||||
for (int i = cs; i < cur[idx].scene_count - 1; i++) {
|
||||
cur[idx].scenes[i] = cur[idx].scenes[i + 1];
|
||||
}
|
||||
cur[idx].scene_count--;
|
||||
if (cur[idx].current_scene >= cur[idx].scene_count)
|
||||
cur[idx].current_scene = cur[idx].scene_count - 1;
|
||||
}
|
||||
|
||||
void channel_next_scene(jack_client_t *client, int idx) {
|
||||
(void)client;
|
||||
struct channel_t *cur = get_channels_array();
|
||||
if (cur[idx].scene_count > 1) {
|
||||
cur[idx].current_scene =
|
||||
(cur[idx].current_scene + 1) % cur[idx].scene_count;
|
||||
}
|
||||
}
|
||||
|
||||
void channel_prev_scene(jack_client_t *client, int idx) {
|
||||
(void)client;
|
||||
struct channel_t *cur = get_channels_array();
|
||||
if (cur[idx].scene_count > 1) {
|
||||
cur[idx].current_scene =
|
||||
(cur[idx].current_scene - 1 + cur[idx].scene_count) %
|
||||
cur[idx].scene_count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user