feat: add mock JACK test target and unit tests for carla host
This commit is contained in:
@@ -77,19 +77,30 @@ $(TEST_CARLA_OBJ): tests/test_carla_host.c src/carla_host.h
|
|||||||
$(TEST_CARLA_BIN): $(TEST_CARLA_OBJ) $(CARLA_OBJ)
|
$(TEST_CARLA_BIN): $(TEST_CARLA_OBJ) $(CARLA_OBJ)
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(CARLA_LIB) -ljack
|
$(CC) $(CFLAGS) -o $@ $^ $(CARLA_LIB) -ljack
|
||||||
|
|
||||||
|
# --- Mock JACK test ---
|
||||||
|
TEST_CARLA_MOCK_BIN = test_carla_host_mock
|
||||||
|
CARLA_MOCK_OBJ = src/carla_host_mock.o
|
||||||
|
|
||||||
|
$(CARLA_MOCK_OBJ): src/carla_host.c src/carla_host.h
|
||||||
|
$(CC) -Wall -Wextra -std=c11 -Isrc $(CARLA_INC) -DTESTING -DMOCK_JACK -c -o $@ $<
|
||||||
|
|
||||||
|
$(TEST_CARLA_MOCK_BIN): tests/test_carla_host_mock.c $(CARLA_MOCK_OBJ)
|
||||||
|
$(CC) $(CFLAGS) $(CARLA_INC) -DTESTING -DMOCK_JACK -o $@ $^ $(CARLA_LIB) -ljack
|
||||||
|
|
||||||
# --- Integration test (requires TESTING symbol) ---
|
# --- Integration test (requires TESTING symbol) ---
|
||||||
$(TEST_INTEGRATION_BIN): tests/test_integration.c $(CARLA_TEST_OBJ)
|
$(TEST_INTEGRATION_BIN): tests/test_integration.c $(CARLA_TEST_OBJ)
|
||||||
$(CC) $(CFLAGS) $(CARLA_INC) -DTESTING -o $@ $^ $(CARLA_LIB) -ljack
|
$(CC) $(CFLAGS) $(CARLA_INC) -DTESTING -o $@ $^ $(CARLA_LIB) -ljack
|
||||||
|
|
||||||
test: looper-client test_status_parse $(TEST_PLUGINS_BIN) $(TEST_CLIENT_BIN) $(TEST_CARLA_BIN) $(TEST_CLIENT_CMD_BIN) $(TEST_INTEGRATION_BIN)
|
test: looper-client test_status_parse $(TEST_PLUGINS_BIN) $(TEST_CLIENT_BIN) $(TEST_CARLA_BIN) $(TEST_CLIENT_CMD_BIN) $(TEST_INTEGRATION_BIN) $(TEST_CARLA_MOCK_BIN)
|
||||||
./test_status_parse
|
./test_status_parse
|
||||||
./$(TEST_PLUGINS_BIN)
|
./$(TEST_PLUGINS_BIN)
|
||||||
./$(TEST_CLIENT_BIN)
|
./$(TEST_CLIENT_BIN)
|
||||||
./$(TEST_CARLA_BIN)
|
./$(TEST_CARLA_BIN)
|
||||||
./$(TEST_CLIENT_CMD_BIN)
|
./$(TEST_CLIENT_CMD_BIN)
|
||||||
./$(TEST_INTEGRATION_BIN)
|
./$(TEST_INTEGRATION_BIN)
|
||||||
|
./$(TEST_CARLA_MOCK_BIN)
|
||||||
|
|
||||||
.PHONY: all test clean
|
.PHONY: all test clean
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f looper-client test_status_parse $(TEST_PLUGINS_BIN) $(TEST_CLIENT_BIN) $(TEST_CARLA_BIN) $(TEST_CLIENT_CMD_BIN) $(TEST_INTEGRATION_BIN) *.o tests/*.o src/*.o
|
rm -f looper-client test_status_parse $(TEST_PLUGINS_BIN) $(TEST_CLIENT_BIN) $(TEST_CARLA_BIN) $(TEST_CLIENT_CMD_BIN) $(TEST_INTEGRATION_BIN) $(TEST_CARLA_MOCK_BIN) *.o tests/*.o src/*.o
|
||||||
|
|||||||
@@ -1,13 +1,38 @@
|
|||||||
#include <CarlaHost.h>
|
#include <CarlaHost.h>
|
||||||
#include <CarlaBackend.h>
|
#include <CarlaBackend.h>
|
||||||
#include <jack/jack.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "carla_host.h"
|
#include "carla_host.h"
|
||||||
|
|
||||||
|
#ifdef MOCK_JACK
|
||||||
|
/* Mock JACK functions – always succeed */
|
||||||
|
/* Provide a dummy type so we can have a non‑NULL pointer */
|
||||||
|
typedef void jack_client_t;
|
||||||
|
static int mock_jack_connect(const char *from, const char *to) {
|
||||||
|
(void)from; (void)to;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int mock_jack_disconnect(const char *from, const char *to) {
|
||||||
|
(void)from; (void)to;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Provide a fake jack_client pointer that is non‑NULL */
|
||||||
|
#define jack_client ((jack_client_t*)1)
|
||||||
|
/* Real jack_connect/jack_disconnect take 3 arguments (client, a, b).
|
||||||
|
We ignore the client and forward to the mock 2‑arg functions. */
|
||||||
|
#define jack_connect(client, a, b) ((void)(client), mock_jack_connect(a, b))
|
||||||
|
#define jack_disconnect(client, a, b) ((void)(client), mock_jack_disconnect(a, b))
|
||||||
|
#else
|
||||||
|
#include <jack/jack.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAX_PLUGINS 256
|
#define MAX_PLUGINS 256
|
||||||
|
|
||||||
static CarlaHostHandle handle = NULL;
|
static CarlaHostHandle handle = NULL;
|
||||||
|
#ifdef MOCK_JACK
|
||||||
|
/* jack_client is defined via macro above (non‑NULL) */
|
||||||
|
#else
|
||||||
static jack_client_t *jack_client = NULL; // private JACK client for port connections
|
static jack_client_t *jack_client = NULL; // private JACK client for port connections
|
||||||
|
#endif
|
||||||
static int carla_pids[MAX_PLUGINS];
|
static int carla_pids[MAX_PLUGINS];
|
||||||
static int plugin_count = 0;
|
static int plugin_count = 0;
|
||||||
|
|
||||||
@@ -25,16 +50,20 @@ static int conn_count = 0;
|
|||||||
int carla_init_jack(void) {
|
int carla_init_jack(void) {
|
||||||
if (handle != NULL) return 0;
|
if (handle != NULL) return 0;
|
||||||
|
|
||||||
|
#ifndef MOCK_JACK
|
||||||
// 1) Open our own JACK client (for port connections)
|
// 1) Open our own JACK client (for port connections)
|
||||||
jack_status_t status;
|
jack_status_t status;
|
||||||
jack_client = jack_client_open("looper-connector", JackNoStartServer, &status);
|
jack_client = jack_client_open("looper-connector", JackNoStartServer, &status);
|
||||||
// It's okay if jack_client is NULL; we still try Carla
|
// It's okay if jack_client is NULL; we still try Carla
|
||||||
|
#endif
|
||||||
|
|
||||||
// 2) Create the Carla host handle
|
// 2) Create the Carla host handle
|
||||||
handle = carla_standalone_host_init();
|
handle = carla_standalone_host_init();
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
|
#ifndef MOCK_JACK
|
||||||
if (jack_client) jack_client_close(jack_client);
|
if (jack_client) jack_client_close(jack_client);
|
||||||
jack_client = NULL;
|
jack_client = NULL;
|
||||||
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,8 +71,10 @@ int carla_init_jack(void) {
|
|||||||
if (!carla_engine_init(handle, "JACK", "looper-client")) {
|
if (!carla_engine_init(handle, "JACK", "looper-client")) {
|
||||||
carla_engine_close(handle);
|
carla_engine_close(handle);
|
||||||
handle = NULL;
|
handle = NULL;
|
||||||
|
#ifndef MOCK_JACK
|
||||||
if (jack_client) jack_client_close(jack_client);
|
if (jack_client) jack_client_close(jack_client);
|
||||||
jack_client = NULL;
|
jack_client = NULL;
|
||||||
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -54,10 +85,12 @@ void carla_cleanup_jack(void) {
|
|||||||
carla_engine_close(handle);
|
carla_engine_close(handle);
|
||||||
handle = NULL;
|
handle = NULL;
|
||||||
}
|
}
|
||||||
|
#ifndef MOCK_JACK
|
||||||
if (jack_client) {
|
if (jack_client) {
|
||||||
jack_client_close(jack_client);
|
jack_client_close(jack_client);
|
||||||
jack_client = NULL;
|
jack_client = NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
plugin_count = 0;
|
plugin_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
92
client/tests/test_carla_host_mock.c
Normal file
92
client/tests/test_carla_host_mock.c
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#include "carla_host.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static int tests_passed = 0;
|
||||||
|
static int tests_failed = 0;
|
||||||
|
|
||||||
|
#define ASSERT_EQ(expected, actual, msg) do { \
|
||||||
|
if ((expected) != (actual)) { \
|
||||||
|
fprintf(stderr, "FAIL: %s (expected %d, got %d)\n", msg, (int)(expected), (int)(actual)); \
|
||||||
|
tests_failed++; \
|
||||||
|
} else { \
|
||||||
|
printf("PASS: %s\n", msg); \
|
||||||
|
tests_passed++; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
#define ASSERT_TRUE(expr, msg) do { \
|
||||||
|
if (!(expr)) { \
|
||||||
|
fprintf(stderr, "FAIL: %s\n", msg); \
|
||||||
|
tests_failed++; \
|
||||||
|
} else { \
|
||||||
|
printf("PASS: %s\n", msg); \
|
||||||
|
tests_passed++; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
static void test_init_cleanup(void)
|
||||||
|
{
|
||||||
|
// When compiled with MOCK_JACK, carla_init_jack should succeed
|
||||||
|
int ret = carla_init_jack();
|
||||||
|
ASSERT_EQ(0, ret, "carla_init_jack() returns 0 under MOCK_JACK");
|
||||||
|
CarlaHostHandle h = carla_get_handle();
|
||||||
|
ASSERT_TRUE(h != NULL, "carla_get_handle() is non‑NULL after init");
|
||||||
|
carla_cleanup_jack();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_load_unload(void)
|
||||||
|
{
|
||||||
|
int ret = carla_init_jack();
|
||||||
|
ASSERT_EQ(0, ret, "carla_init_jack() returns 0");
|
||||||
|
int id;
|
||||||
|
ret = carla_load("libmock_plugin.so", "mock_plugin", &id);
|
||||||
|
// Under mock, carla_load will try to call carla_add_plugin which may fail
|
||||||
|
// because no real Carla engine. The mock only mocks JACK, not Carla.
|
||||||
|
// We accept either success or failure – the test just verifies no crash.
|
||||||
|
if (ret == 0) {
|
||||||
|
ASSERT_TRUE(id >= 0, "id is non‑negative after load");
|
||||||
|
ret = carla_unload(id);
|
||||||
|
ASSERT_EQ(0, ret, "carla_unload returns 0");
|
||||||
|
} else {
|
||||||
|
printf(" SKIP: carla_load failed, presumably no Carla engine available\n");
|
||||||
|
}
|
||||||
|
carla_cleanup_jack();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_connect_disconnect(void)
|
||||||
|
{
|
||||||
|
int ret = carla_init_jack();
|
||||||
|
ASSERT_EQ(0, ret, "carla_init_jack() returns 0");
|
||||||
|
int id = 0;
|
||||||
|
// Use carla_test_add_connection to simulate a connection
|
||||||
|
ret = carla_test_add_connection(id, "test:out", "looper:in");
|
||||||
|
ASSERT_EQ(0, ret, "carla_test_add_connection returns 0");
|
||||||
|
ASSERT_EQ(1, carla_test_connection_count(), "connection count is 1 after add");
|
||||||
|
// carla_disconnect_plugin should clear all connections for id 0
|
||||||
|
ret = carla_disconnect_plugin(0);
|
||||||
|
ASSERT_EQ(0, ret, "carla_disconnect_plugin returns 0");
|
||||||
|
ASSERT_EQ(0, carla_test_connection_count(), "connection count is 0 after disconnect_plugin");
|
||||||
|
carla_cleanup_jack();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_set_bypass(void)
|
||||||
|
{
|
||||||
|
int ret = carla_init_jack();
|
||||||
|
ASSERT_EQ(0, ret, "carla_init_jack() returns 0");
|
||||||
|
// bypass should not crash even with no plugin loaded
|
||||||
|
carla_set_bypass(0, true);
|
||||||
|
printf("PASS: carla_set_bypass(0, true) did not crash\n");
|
||||||
|
tests_passed++;
|
||||||
|
carla_cleanup_jack();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
printf("=== Carla host mock integration tests ===\n");
|
||||||
|
test_init_cleanup();
|
||||||
|
test_load_unload();
|
||||||
|
test_connect_disconnect();
|
||||||
|
test_set_bypass();
|
||||||
|
printf("\nResults: %d passed, %d failed\n", tests_passed, tests_failed);
|
||||||
|
return tests_failed > 0 ? 1 : 0;
|
||||||
|
}
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
/* Helper: zero a scene and set its state to IDLE */
|
/* Helper: zero a scene and set its state to IDLE */
|
||||||
static void init_scene(scene_t *sc) {
|
static void init_scene(scene_t *sc) {
|
||||||
memset(sc, 0, sizeof(scene_t));
|
memset(sc, 0, sizeof(scene_t));
|
||||||
atomic_store(&sc->state, STATE_IDLE);
|
atomic_store(&sc->state, STATE_IDLE);
|
||||||
atomic_store(&sc->prev_state, -1);
|
atomic_store(&sc->prev_state, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void channel_add(jack_client_t *client, int idx) {
|
void channel_add(jack_client_t *client, int idx) {
|
||||||
@@ -76,61 +76,61 @@ void channel_remove(jack_client_t *client, int idx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void channel_add_scene(jack_client_t *client, int idx) {
|
void channel_add_scene(jack_client_t *client, int idx) {
|
||||||
(void)client;
|
(void)client;
|
||||||
struct channel_t *cur = get_channels_array();
|
struct channel_t *cur = get_channels_array();
|
||||||
if (atomic_load(&cur[idx].scene_count) >= MAX_SCENES)
|
if (atomic_load(&cur[idx].scene_count) >= MAX_SCENES)
|
||||||
return;
|
return;
|
||||||
int ns = atomic_load(&cur[idx].scene_count);
|
int ns = atomic_load(&cur[idx].scene_count);
|
||||||
init_scene(&cur[idx].scenes[ns]);
|
init_scene(&cur[idx].scenes[ns]);
|
||||||
atomic_fetch_add(&cur[idx].scene_count, 1);
|
atomic_fetch_add(&cur[idx].scene_count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void channel_remove_scene(jack_client_t *client, int idx) {
|
void channel_remove_scene(jack_client_t *client, int idx) {
|
||||||
(void)client;
|
(void)client;
|
||||||
struct channel_t *cur = get_channels_array();
|
struct channel_t *cur = get_channels_array();
|
||||||
int sc = atomic_load(&cur[idx].scene_count);
|
int sc = atomic_load(&cur[idx].scene_count);
|
||||||
if (sc <= 1)
|
if (sc <= 1)
|
||||||
return;
|
return;
|
||||||
int cs = atomic_load(&cur[idx].current_scene);
|
int cs = atomic_load(&cur[idx].current_scene);
|
||||||
/* shift remaining scenes down (atomic copy of fields) */
|
/* shift remaining scenes down (atomic copy of fields) */
|
||||||
for (int i = cs; i < sc - 1; i++) {
|
for (int i = cs; i < sc - 1; i++) {
|
||||||
atomic_store(&cur[idx].scenes[i].loop_count,
|
atomic_store(&cur[idx].scenes[i].loop_count,
|
||||||
atomic_load(&cur[idx].scenes[i+1].loop_count));
|
atomic_load(&cur[idx].scenes[i + 1].loop_count));
|
||||||
atomic_store(&cur[idx].scenes[i].record_pos,
|
atomic_store(&cur[idx].scenes[i].record_pos,
|
||||||
atomic_load(&cur[idx].scenes[i+1].record_pos));
|
atomic_load(&cur[idx].scenes[i + 1].record_pos));
|
||||||
atomic_store(&cur[idx].scenes[i].playback_pos,
|
atomic_store(&cur[idx].scenes[i].playback_pos,
|
||||||
atomic_load(&cur[idx].scenes[i+1].playback_pos));
|
atomic_load(&cur[idx].scenes[i + 1].playback_pos));
|
||||||
atomic_store(&cur[idx].scenes[i].state,
|
atomic_store(&cur[idx].scenes[i].state,
|
||||||
atomic_load(&cur[idx].scenes[i+1].state));
|
atomic_load(&cur[idx].scenes[i + 1].state));
|
||||||
atomic_store(&cur[idx].scenes[i].prev_state,
|
atomic_store(&cur[idx].scenes[i].prev_state,
|
||||||
atomic_load(&cur[idx].scenes[i+1].prev_state));
|
atomic_load(&cur[idx].scenes[i + 1].prev_state));
|
||||||
/* copy loop data (may race with RT thread; acceptable for this release) */
|
/* copy loop data (may race with RT thread; acceptable for this release) */
|
||||||
memcpy(cur[idx].scenes[i].loop.audio_buffer,
|
memcpy(cur[idx].scenes[i].loop.audio_buffer,
|
||||||
cur[idx].scenes[i+1].loop.audio_buffer,
|
cur[idx].scenes[i + 1].loop.audio_buffer,
|
||||||
LOOP_BUF_SIZE * sizeof(float));
|
LOOP_BUF_SIZE * sizeof(float));
|
||||||
}
|
}
|
||||||
atomic_fetch_sub(&cur[idx].scene_count, 1);
|
atomic_fetch_sub(&cur[idx].scene_count, 1);
|
||||||
int new_sc = atomic_load(&cur[idx].scene_count);
|
int new_sc = atomic_load(&cur[idx].scene_count);
|
||||||
if (cs >= new_sc)
|
if (cs >= new_sc)
|
||||||
atomic_store(&cur[idx].current_scene, new_sc - 1);
|
atomic_store(&cur[idx].current_scene, new_sc - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void channel_next_scene(jack_client_t *client, int idx) {
|
void channel_next_scene(jack_client_t *client, int idx) {
|
||||||
(void)client;
|
(void)client;
|
||||||
struct channel_t *cur = get_channels_array();
|
struct channel_t *cur = get_channels_array();
|
||||||
int sc = atomic_load(&cur[idx].scene_count);
|
int sc = atomic_load(&cur[idx].scene_count);
|
||||||
if (sc > 1) {
|
if (sc > 1) {
|
||||||
int cs = atomic_load(&cur[idx].current_scene);
|
int cs = atomic_load(&cur[idx].current_scene);
|
||||||
atomic_store(&cur[idx].current_scene, (cs + 1) % sc);
|
atomic_store(&cur[idx].current_scene, (cs + 1) % sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void channel_prev_scene(jack_client_t *client, int idx) {
|
void channel_prev_scene(jack_client_t *client, int idx) {
|
||||||
(void)client;
|
(void)client;
|
||||||
struct channel_t *cur = get_channels_array();
|
struct channel_t *cur = get_channels_array();
|
||||||
int sc = atomic_load(&cur[idx].scene_count);
|
int sc = atomic_load(&cur[idx].scene_count);
|
||||||
if (sc > 1) {
|
if (sc > 1) {
|
||||||
int cs = atomic_load(&cur[idx].current_scene);
|
int cs = atomic_load(&cur[idx].current_scene);
|
||||||
atomic_store(&cur[idx].current_scene, (cs - 1 + sc) % sc);
|
atomic_store(&cur[idx].current_scene, (cs - 1 + sc) % sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,48 +4,56 @@
|
|||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "midi.h"
|
#include "midi.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include <jack/jack.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <jack/jack.h>
|
||||||
#include <jack/midiport.h>
|
#include <jack/midiport.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define STATUS_FIFO "/tmp/looper_status"
|
#define STATUS_FIFO "/tmp/looper_status"
|
||||||
|
|
||||||
static void looper_write_status(void) {
|
static void looper_write_status(void) {
|
||||||
int fd = open(STATUS_FIFO, O_WRONLY | O_NONBLOCK);
|
int fd = open(STATUS_FIFO, O_WRONLY | O_NONBLOCK);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return;
|
return;
|
||||||
struct channel_t *cur = get_channels_array();
|
struct channel_t *cur = get_channels_array();
|
||||||
int cap = atomic_load(&channel_capacity);
|
int cap = atomic_load(&channel_capacity);
|
||||||
char buf[256];
|
char buf[256];
|
||||||
for (int ch = 0; ch < cap; ch++) {
|
for (int ch = 0; ch < cap; ch++) {
|
||||||
if (!atomic_load(&cur[ch].active))
|
if (!atomic_load(&cur[ch].active))
|
||||||
continue;
|
continue;
|
||||||
int sc_idx = atomic_load(&cur[ch].current_scene);
|
int sc_idx = atomic_load(&cur[ch].current_scene);
|
||||||
int state = atomic_load(&cur[ch].scenes[sc_idx].state);
|
int state = atomic_load(&cur[ch].scenes[sc_idx].state);
|
||||||
const char *state_str;
|
const char *state_str;
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case STATE_IDLE: state_str = "IDLE"; break;
|
case STATE_IDLE:
|
||||||
case STATE_RECORD: state_str = "RECORD"; break;
|
state_str = "IDLE";
|
||||||
case STATE_LOOPING: state_str = "LOOPING"; break;
|
break;
|
||||||
case STATE_PAUSED: state_str = "PAUSED"; break;
|
case STATE_RECORD:
|
||||||
default: state_str = "UNKNOWN";
|
state_str = "RECORD";
|
||||||
}
|
break;
|
||||||
int n = snprintf(buf, sizeof(buf),
|
case STATE_LOOPING:
|
||||||
"CH=%d SC=%d STATE=%s\n",
|
state_str = "LOOPING";
|
||||||
ch, sc_idx, state_str);
|
break;
|
||||||
if (n > 0) {
|
case STATE_PAUSED:
|
||||||
int ret = write(fd, buf, n);
|
state_str = "PAUSED";
|
||||||
(void)ret;
|
break;
|
||||||
}
|
default:
|
||||||
|
state_str = "UNKNOWN";
|
||||||
}
|
}
|
||||||
close(fd);
|
int n = snprintf(buf, sizeof(buf), "CH=%d SC=%d STATE=%s\n", ch, sc_idx,
|
||||||
|
state_str);
|
||||||
|
if (n > 0) {
|
||||||
|
int ret = write(fd, buf, n);
|
||||||
|
(void)ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Global state (shared across files) */
|
/* Global state (shared across files) */
|
||||||
@@ -252,8 +260,7 @@ int process_callback(jack_nframes_t nframes, void *arg) {
|
|||||||
if (rp < MAX_MIDI_EVENTS) {
|
if (rp < MAX_MIDI_EVENTS) {
|
||||||
sc->loop.midi_events[rp].timestamp = ev.time;
|
sc->loop.midi_events[rp].timestamp = ev.time;
|
||||||
sc->loop.midi_events[rp].status = ev.buffer[0];
|
sc->loop.midi_events[rp].status = ev.buffer[0];
|
||||||
sc->loop.midi_events[rp].note =
|
sc->loop.midi_events[rp].note = (ev.size > 1) ? ev.buffer[1] : 0;
|
||||||
(ev.size > 1) ? ev.buffer[1] : 0;
|
|
||||||
sc->loop.midi_events[rp].velocity =
|
sc->loop.midi_events[rp].velocity =
|
||||||
(ev.size > 2) ? ev.buffer[2] : 0;
|
(ev.size > 2) ? ev.buffer[2] : 0;
|
||||||
atomic_store(&sc->record_pos, rp + 1);
|
atomic_store(&sc->record_pos, rp + 1);
|
||||||
@@ -295,23 +302,22 @@ int process_callback(jack_nframes_t nframes, void *arg) {
|
|||||||
/* no output */
|
/* no output */
|
||||||
break;
|
break;
|
||||||
default: /* IDLE */
|
default: /* IDLE */
|
||||||
{
|
{
|
||||||
void *midi_in_buf =
|
void *midi_in_buf =
|
||||||
jack_port_get_buffer(active_channels[c].midi_in, nframes);
|
jack_port_get_buffer(active_channels[c].midi_in, nframes);
|
||||||
void *midi_out_buf =
|
void *midi_out_buf =
|
||||||
jack_port_get_buffer(active_channels[c].midi_out, nframes);
|
jack_port_get_buffer(active_channels[c].midi_out, nframes);
|
||||||
if (midi_in_buf && midi_out_buf) {
|
if (midi_in_buf && midi_out_buf) {
|
||||||
jack_midi_clear_buffer(midi_out_buf);
|
jack_midi_clear_buffer(midi_out_buf);
|
||||||
jack_nframes_t nevents = jack_midi_get_event_count(midi_in_buf);
|
jack_nframes_t nevents = jack_midi_get_event_count(midi_in_buf);
|
||||||
jack_midi_event_t ev;
|
jack_midi_event_t ev;
|
||||||
for (jack_nframes_t j = 0; j < nevents; j++) {
|
for (jack_nframes_t j = 0; j < nevents; j++) {
|
||||||
if (jack_midi_event_get(&ev, midi_in_buf, j) != 0)
|
if (jack_midi_event_get(&ev, midi_in_buf, j) != 0)
|
||||||
continue;
|
continue;
|
||||||
jack_midi_event_write(midi_out_buf, ev.time, ev.buffer, ev.size);
|
jack_midi_event_write(midi_out_buf, ev.time, ev.buffer, ev.size);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
} break;
|
||||||
}
|
}
|
||||||
if (state == STATE_LOOPING) {
|
if (state == STATE_LOOPING) {
|
||||||
atomic_store(&sc->loop_count, atomic_load(&sc->record_pos));
|
atomic_store(&sc->loop_count, atomic_load(&sc->record_pos));
|
||||||
|
|||||||
@@ -82,8 +82,7 @@ void midi_handle_events(void *port_buffer, jack_nframes_t nframes) {
|
|||||||
queue_push(&cmd_queue_main_midi, cmd);
|
queue_push(&cmd_queue_main_midi, cmd);
|
||||||
} break;
|
} break;
|
||||||
case 69: {
|
case 69: {
|
||||||
command_t cmd = {
|
command_t cmd = {.type = CMD_ADD_SCENE, .channel = -1, .data = 0};
|
||||||
.type = CMD_ADD_SCENE, .channel = -1, .data = 0};
|
|
||||||
queue_push(&cmd_queue_main_midi, cmd);
|
queue_push(&cmd_queue_main_midi, cmd);
|
||||||
} break;
|
} break;
|
||||||
case 70: {
|
case 70: {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define FIFO_PATH "/tmp/looper_cmd"
|
#define FIFO_PATH "/tmp/looper_cmd"
|
||||||
@@ -39,7 +39,8 @@ static void *pipe_thread_func(void *arg) {
|
|||||||
command_t cmd = {.type = CMD_ADD_CHANNEL, .channel = -1, .data = 0};
|
command_t cmd = {.type = CMD_ADD_CHANNEL, .channel = -1, .data = 0};
|
||||||
queue_push(&cmd_queue_main_fifo, cmd);
|
queue_push(&cmd_queue_main_fifo, cmd);
|
||||||
} else if (strcmp(line, "add_midi") == 0) {
|
} else if (strcmp(line, "add_midi") == 0) {
|
||||||
command_t cmd = {.type = CMD_ADD_MIDI_CHANNEL, .channel = -1, .data = 0};
|
command_t cmd = {
|
||||||
|
.type = CMD_ADD_MIDI_CHANNEL, .channel = -1, .data = 0};
|
||||||
queue_push(&cmd_queue_main_fifo, cmd);
|
queue_push(&cmd_queue_main_fifo, cmd);
|
||||||
} else if (strcmp(line, "remove") == 0) {
|
} else if (strcmp(line, "remove") == 0) {
|
||||||
command_t cmd = {.type = CMD_REMOVE_CHANNEL, .channel = -1, .data = 0};
|
command_t cmd = {.type = CMD_REMOVE_CHANNEL, .channel = -1, .data = 0};
|
||||||
|
|||||||
Reference in New Issue
Block a user