12-command-art
This commit is contained in:
66
src/looper.c
66
src/looper.c
@@ -1,7 +1,9 @@
|
||||
// cppcheck-suppress missingIncludeSystem
|
||||
#include "looper.h"
|
||||
#include "channel.h"
|
||||
#include "command.h"
|
||||
#include "midi.h"
|
||||
#include "queue.h"
|
||||
#include <jack/jack.h>
|
||||
#include <jack/midiport.h>
|
||||
#include <math.h>
|
||||
@@ -9,8 +11,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "command.h"
|
||||
#include "queue.h"
|
||||
|
||||
/* Global state (shared across files) */
|
||||
struct channel_t channels[MAX_CHANNELS];
|
||||
@@ -30,38 +30,48 @@ static int pending_unregister_idx = -1;
|
||||
static int pending_unregister_cycle = 0;
|
||||
|
||||
static void apply_command(command_t cmd) {
|
||||
switch (cmd.type) {
|
||||
case CMD_CYCLE:
|
||||
if (cmd.channel >= 0 && cmd.channel < MAX_CHANNELS) {
|
||||
int cur = atomic_load(&channels[cmd.channel].state);
|
||||
int next;
|
||||
switch (cur) {
|
||||
case STATE_IDLE: next = STATE_RECORD; break;
|
||||
case STATE_RECORD: next = STATE_LOOPING; break;
|
||||
case STATE_LOOPING: next = STATE_PAUSED; break;
|
||||
case STATE_PAUSED: next = STATE_LOOPING; break;
|
||||
default: next = STATE_IDLE; break;
|
||||
}
|
||||
atomic_store(&channels[cmd.channel].state, next);
|
||||
}
|
||||
switch (cmd.type) {
|
||||
case CMD_CYCLE:
|
||||
if (cmd.channel >= 0 && cmd.channel < MAX_CHANNELS) {
|
||||
int cur = atomic_load(&channels[cmd.channel].state);
|
||||
int next;
|
||||
switch (cur) {
|
||||
case STATE_IDLE:
|
||||
next = STATE_RECORD;
|
||||
break;
|
||||
case CMD_STOP:
|
||||
if (cmd.channel >= 0 && cmd.channel < MAX_CHANNELS)
|
||||
atomic_store(&channels[cmd.channel].state, STATE_IDLE);
|
||||
else {
|
||||
for (int i = 0; i < MAX_CHANNELS; i++)
|
||||
atomic_store(&channels[i].state, STATE_IDLE);
|
||||
}
|
||||
case STATE_RECORD:
|
||||
next = STATE_LOOPING;
|
||||
break;
|
||||
case CMD_BIND_CHANNEL:
|
||||
atomic_store(&bind_channel, cmd.data);
|
||||
case STATE_LOOPING:
|
||||
next = STATE_PAUSED;
|
||||
break;
|
||||
case CMD_UNBIND:
|
||||
atomic_store(&bind_channel, 0);
|
||||
case STATE_PAUSED:
|
||||
next = STATE_LOOPING;
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
next = STATE_IDLE;
|
||||
break;
|
||||
}
|
||||
atomic_store(&channels[cmd.channel].state, next);
|
||||
}
|
||||
break;
|
||||
case CMD_STOP:
|
||||
if (cmd.channel >= 0 && cmd.channel < MAX_CHANNELS)
|
||||
atomic_store(&channels[cmd.channel].state, STATE_IDLE);
|
||||
else {
|
||||
for (int i = 0; i < MAX_CHANNELS; i++)
|
||||
atomic_store(&channels[i].state, STATE_IDLE);
|
||||
}
|
||||
break;
|
||||
case CMD_BIND_CHANNEL:
|
||||
atomic_store(&bind_channel, cmd.data);
|
||||
break;
|
||||
case CMD_UNBIND:
|
||||
atomic_store(&bind_channel, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user