1 Commits

Author SHA1 Message Date
Loic Coenen
32fb5d3524 refactor: enable all e2e tests and fix audio port naming 2026-06-05 19:39:53 +00:00
32 changed files with 129 additions and 9084 deletions

2
.gitignore vendored
View File

@@ -1,3 +1 @@
.aider* .aider*
*node_modules*

View File

@@ -1,8 +0,0 @@
import * as path from "path";
export const PROJECT_DIR = path.resolve(__dirname, "..");
export const ENGINE_BIN = path.join(PROJECT_DIR, "engine/looper");
export const CLIENT_BIN = path.join(PROJECT_DIR, "client/looper-client");
export const STATUS_FIFO = "/tmp/looper_status";
export const CMD_FIFO = "/tmp/looper_cmd";
export const GEN_TONE_BIN = "/tmp/gen_tone";

View File

@@ -5,12 +5,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
char g_from_port[256] = ""; static char from_port[256] = "";
char g_to_port[256] = ""; static char to_port[256] = "";
char g_connect_error[512] = ""; char g_connect_error[512] = "";
const char* get_stored_from(void) { return g_from_port; } const char* get_stored_from(void) { return from_port; }
const char* get_stored_to(void) { return g_to_port; } const char* get_stored_to(void) { return to_port; }
static int get_plugin_id_for_port(const char *port_spec) { static int get_plugin_id_for_port(const char *port_spec) {
// port_spec format: "plugin_id:port_name" // port_spec format: "plugin_id:port_name"
@@ -38,8 +38,8 @@ int handle_client_command(const char *input, int *out_id) {
if (!port) return -1; if (!port) return -1;
int ret = carla_connect_direct(port, "looper:ch0in"); int ret = carla_connect_direct(port, "looper:ch0in");
if (ret == 0) { if (ret == 0) {
strncpy(g_from_port, port, sizeof(g_from_port)-1); strncpy(from_port, port, sizeof(from_port)-1);
g_from_port[sizeof(g_from_port)-1] = '\0'; from_port[sizeof(from_port)-1] = '\0';
g_connect_error[0] = '\0'; g_connect_error[0] = '\0';
} else { } else {
snprintf(g_connect_error, sizeof(g_connect_error), snprintf(g_connect_error, sizeof(g_connect_error),
@@ -54,8 +54,8 @@ int handle_client_command(const char *input, int *out_id) {
if (!port) return -1; if (!port) return -1;
int ret = carla_connect_direct("looper:ch0out", port); int ret = carla_connect_direct("looper:ch0out", port);
if (ret == 0) { if (ret == 0) {
strncpy(g_to_port, port, sizeof(g_to_port)-1); strncpy(to_port, port, sizeof(to_port)-1);
g_to_port[sizeof(g_to_port)-1] = '\0'; to_port[sizeof(to_port)-1] = '\0';
g_connect_error[0] = '\0'; g_connect_error[0] = '\0';
} else { } else {
snprintf(g_connect_error, sizeof(g_connect_error), snprintf(g_connect_error, sizeof(g_connect_error),
@@ -74,12 +74,12 @@ int handle_client_command(const char *input, int *out_id) {
if (ret == 0 && out_id) *out_id = id; if (ret == 0 && out_id) *out_id = id;
// auto-connect using stored :from/:to if set // auto-connect using stored :from/:to if set
if (ret == 0 && g_from_port[0] && g_to_port[0]) { if (ret == 0 && from_port[0] && to_port[0]) {
// parse plugin port name from stored from_port ("plugin_id:port_name") // parse plugin port name from stored from_port ("plugin_id:port_name")
const char *colon = strchr(g_from_port, ':'); const char *colon = strchr(from_port, ':');
if (colon) { if (colon) {
const char *pname = colon + 1; const char *pname = colon + 1;
plugin_connect(id, pname, g_to_port); plugin_connect(id, pname, to_port);
} }
} }
@@ -91,11 +91,11 @@ int handle_client_command(const char *input, int *out_id) {
const char *from = strtok(NULL, " "); const char *from = strtok(NULL, " ");
const char *to = strtok(NULL, " "); const char *to = strtok(NULL, " ");
if (!from) { if (!from) {
if (g_from_port[0]) from = g_from_port; if (from_port[0]) from = from_port;
else return -1; else return -1;
} }
if (!to) { if (!to) {
if (g_to_port[0]) to = g_to_port; if (to_port[0]) to = to_port;
else return -1; else return -1;
} }
@@ -115,11 +115,11 @@ int handle_client_command(const char *input, int *out_id) {
const char *from = strtok(NULL, " "); const char *from = strtok(NULL, " ");
const char *to = strtok(NULL, " "); const char *to = strtok(NULL, " ");
if (!from) { if (!from) {
if (g_from_port[0]) from = g_from_port; if (from_port[0]) from = from_port;
else return -1; else return -1;
} }
if (!to) { if (!to) {
if (g_to_port[0]) to = g_to_port; if (to_port[0]) to = to_port;
else return -1; else return -1;
} }
return plugin_disconnect(from, to); return plugin_disconnect(from, to);

View File

@@ -14,7 +14,5 @@ const char* get_stored_from(void);
const char* get_stored_to(void); const char* get_stored_to(void);
extern char g_connect_error[512]; extern char g_connect_error[512];
extern char g_from_port[256];
extern char g_to_port[256];
#endif #endif

View File

@@ -1,10 +1,10 @@
#include "carla_host.h"
#include "log.h"
#include "script.h"
#include "tui.h" #include "tui.h"
#include <stdio.h> #include "script.h"
#include <stdlib.h> #include "log.h"
#include "carla_host.h"
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
log_init(); log_init();

View File

@@ -1,27 +1,40 @@
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#include "carla_host.h"
#include "client_cmd.h"
#include "log.h"
#include "plugins.h"
#include "script.h"
#include "tui.h" #include "tui.h"
#include <CarlaHost.h>
#include <dirent.h>
#include <fcntl.h>
#include <ncurses.h> #include <ncurses.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/stat.h>
#include <time.h>
#include "carla_host.h"
#include "client_cmd.h"
#include "plugins.h"
#include "script.h"
#include <CarlaHost.h>
#include "log.h"
extern char g_selected_port[256];
/* Stored connected port names for channel 0 display fallback */
static char g_from_port[256] = "";
static char g_to_port[256] = "";
/* ---------- engine alive indicator ---------- */
static bool engine_running = false; static bool engine_running = false;
static bool debug_mode = false; static bool debug_mode = false;
/* Persistent FIFO fds open once and reuse */
static int cmd_fifo_fd = -1; static int cmd_fifo_fd = -1;
static int status_fifo_fd = -1; static int status_fifo_fd = -1;
/* ---------- FIFO command helper ---------- */
int send_command(const char *cmd) { int send_command(const char *cmd) {
if (debug_mode) if (debug_mode)
fprintf(stderr, "DEBUG: send_command(%s)\n", cmd); fprintf(stderr, "DEBUG: send_command(%s)\n", cmd);
@@ -43,6 +56,7 @@ int send_command(const char *cmd) {
return (n >= 0) ? 0 : -1; return (n >= 0) ? 0 : -1;
} }
/* ---------- Helper to resolve channel port ---------- */
static bool carla_resolve_channel_port(int channel, bool is_to, char *buf, size_t bufsize) { static bool carla_resolve_channel_port(int channel, bool is_to, char *buf, size_t bufsize) {
char **ports = NULL; char **ports = NULL;
int count = 0; int count = 0;
@@ -67,6 +81,9 @@ static bool carla_resolve_channel_port(int channel, bool is_to, char *buf, size_
free(ports); free(ports);
return found; return found;
} }
/* ---------- Stub functions (no engine) ---------- */
// Clip states dummy values used as placeholders
typedef enum { CLIP_EMPTY, CLIP_RECORDING, CLIP_LOOPING, CLIP_STOPPED } ClipState; typedef enum { CLIP_EMPTY, CLIP_RECORDING, CLIP_LOOPING, CLIP_STOPPED } ClipState;
static const char *clip_state_string(ClipState s) { static const char *clip_state_string(ClipState s) {
switch (s) { switch (s) {
@@ -129,6 +146,7 @@ static float vu_level[16] = {0.0f}; /* perchannel RMS level (index = channel
static bool parse_level_line(const char *line, int *ch, float *level) { static bool parse_level_line(const char *line, int *ch, float *level) {
return sscanf(line, "CH=%d LEVEL=%f", ch, level) == 2; return sscanf(line, "CH=%d LEVEL=%f", ch, level) == 2;
} }
bool parse_status_line(const char *line, int *ch, int *scene, ChannelState *state) { bool parse_status_line(const char *line, int *ch, int *scene, ChannelState *state) {
int sta; int sta;
if (sscanf(line, "CH=%d SC=%d STATE=%d", ch, scene, &sta) == 3) { if (sscanf(line, "CH=%d SC=%d STATE=%d", ch, scene, &sta) == 3) {
@@ -313,6 +331,7 @@ static char colon_buf[256];
static int colon_len = 0; static int colon_len = 0;
static bool in_colon = false; static bool in_colon = false;
/* Read the status FIFO once and update cell_state array */
static void tui_read_status(void) { static void tui_read_status(void) {
if (status_fifo_fd < 0) { if (status_fifo_fd < 0) {
status_fifo_fd = open(STATUS_FIFO, O_RDONLY | O_NONBLOCK); status_fifo_fd = open(STATUS_FIFO, O_RDONLY | O_NONBLOCK);
@@ -341,6 +360,7 @@ static void tui_read_status(void) {
} }
/* keep fd open */ /* keep fd open */
} }
void tui_run(void) { void tui_run(void) {
draw_grid(); draw_grid();
nodelay(stdscr, TRUE); // nonblocking input getch returns ERR when no key is pressed nodelay(stdscr, TRUE); // nonblocking input getch returns ERR when no key is pressed
@@ -520,19 +540,9 @@ void tui_run(void) {
case 'S': case 'S':
send_command("scene_prev\n"); send_command("scene_prev\n");
break; break;
case 'd': case 'D': { case 'd': case 'D':
char cmd[64]; send_command("stop\n");
// bind to the selected channel
snprintf(cmd, sizeof(cmd), "bind %d\n", selected_col);
send_command(cmd);
// set the scene (row) so engine deletes the correct clip
snprintf(cmd, sizeof(cmd), "set_scene %d %d\n", selected_col, selected_row);
send_command(cmd);
// delete the clip entirely
snprintf(cmd, sizeof(cmd), "delete %d\n", selected_col);
send_command(cmd);
break; break;
}
case 'a': case 'a':
send_command("add\n"); send_command("add\n");
break; break;
@@ -680,6 +690,7 @@ char* tui_fzf_select(const char *const items[], size_t count, const char *prompt
return strdup(selected); return strdup(selected);
} }
void tui_cleanup(void) { void tui_cleanup(void) {
if (cmd_fifo_fd >= 0) { if (cmd_fifo_fd >= 0) {
close(cmd_fifo_fd); close(cmd_fifo_fd);
@@ -700,5 +711,3 @@ void tui_cleanup(void) {
carla_cleanup_jack(); carla_cleanup_jack();
curs_set(1); endwin(); curs_set(1); endwin();
} }
extern char g_selected_port[256];

View File

File diff suppressed because it is too large Load Diff

564
e2e/package-lock.json generated
View File

@@ -1,564 +0,0 @@
{
"name": "looper-e2e",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "looper-e2e",
"devDependencies": {
"@types/node": "^20.0.0",
"tsx": "^4.0.0",
"typescript": "^5.0.0"
}
},
"node_modules/@esbuild/aix-ppc64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.0.tgz",
"integrity": "sha512-lhRUCeuOyJQURhTxl4WkpFTjIsbDayJHih5kZC1giwE+MhIzAb7mEsQMqMf18rHLsrb5qI1tafG20mLxEWcWlA==",
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"aix"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/android-arm": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.0.tgz",
"integrity": "sha512-wqh0ByljabXLKHeWXYLqoJ5jKC4XBaw6Hk08OfMrCRd2nP2ZQ5eleDZC41XHyCNgktBGYMbqnrJKq/K/lzPMSQ==",
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/android-arm64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.0.tgz",
"integrity": "sha512-+WzIXQOSaGs33tLEgYPYe/yQHf0WTU0X42Jca3y8NWMbUVhp7rUnw+vAsRC/QiDrdD31IszMrZy+qwPOPjd+rw==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/android-x64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.0.tgz",
"integrity": "sha512-+VJggoaKhk2VNNqVL7f6S189UzShHC/mR9EE8rDdSkdpN0KflSwWY/gWjDrNxxisg8Fp1ZCD9jLMo4m0OUfeUA==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/darwin-arm64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.0.tgz",
"integrity": "sha512-0T+A9WZm+bZ84nZBtk1ckYsOvyA3x7e2Acj1KdVfV4/2tdG4fzUp91YHx+GArWLtwqp77pBXVCPn2We7Letr0Q==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/darwin-x64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.0.tgz",
"integrity": "sha512-fyzLm/DLDl/84OCfp2f/XQ4flmORsjU7VKt8HLjvIXChJoFFOIL6pLJPH4Yhd1n1gGFF9mPwtlN5Wf82DZs+LQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/freebsd-arm64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.0.tgz",
"integrity": "sha512-l9GeW5UZBT9k9brBYI+0WDffcRxgHQD8ShN2Ur4xWq/NFzUKm3k5lsH4PdaRgb2w7mI9u61nr2gI2mLI27Nh3Q==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/freebsd-x64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.0.tgz",
"integrity": "sha512-BXoQai/A0wPO6Es3yFJ7APCiKGc1tdAEOgeTNy3SsB491S3aHn4S4r3e976eUnPdU+NbdtmBuLncYir2tMU9Nw==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/linux-arm": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.0.tgz",
"integrity": "sha512-CjaaREJagqJp7iTaNQjjidaNbCKYcd4IDkzbwwxtSvjI7NZm79qiHc8HqciMddQ6CKvJT6aBd8lO9kN/ZudLlw==",
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/linux-arm64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.0.tgz",
"integrity": "sha512-RVyzfb3FWsGA55n6WY0MEIEPURL1FcbhFE6BffZEMEekfCzCIMtB5yyDcFnVbTnwk+CLAgTujmV/Lgvih56W+A==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/linux-ia32": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.0.tgz",
"integrity": "sha512-KBnSTt1kxl9x70q+ydterVdl+Cn0H18ngRMRCEQfrbqdUuntQQ0LoMZv47uB97NljZFzY6HcfqEZ2SAyIUTQBQ==",
"cpu": [
"ia32"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/linux-loong64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.0.tgz",
"integrity": "sha512-zpSlUce1mnxzgBADvxKXX5sl8aYQHo2ezvMNI8I0lbblJtp8V4odlm3Yzlj7gPyt3T8ReksE6bK+pT3WD+aJRg==",
"cpu": [
"loong64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/linux-mips64el": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.0.tgz",
"integrity": "sha512-2jIfP6mmjkdmeTlsX/9vmdmhBmKADrWqN7zcdtHIeNSCH1SqIoNI63cYsjQR8J+wGa4Y5izRcSHSm8K3QWmk3w==",
"cpu": [
"mips64el"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/linux-ppc64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.0.tgz",
"integrity": "sha512-bc0FE9wWeC0WBm49IQMPSPILRocGTQt3j5KPCA8os6VprfuJ7KD+5PzESSrJ6GmPIPJK965ZJHTUlSA6GNYEhg==",
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/linux-riscv64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.0.tgz",
"integrity": "sha512-SQPZOwoTTT/HXFXQJG/vBX8sOFagGqvZyXcgLA3NhIqcBv1BJU1d46c0rGcrij2B56Z2rNiSLaZOYW5cUk7yLQ==",
"cpu": [
"riscv64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/linux-s390x": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.0.tgz",
"integrity": "sha512-SCfR0HN8CEEjnYnySJTd2cw0k9OHB/YFzt5zgJEwa+wL/T/raGWYMBqwDNAC6dqFKmJYZoQBRfHjgwLHGSrn3Q==",
"cpu": [
"s390x"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/linux-x64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.0.tgz",
"integrity": "sha512-us0dSb9iFxIi8srnpl931Nvs65it/Jd2a2K3qs7fz2WfGPHqzfzZTfec7oxZJRNPXPnNYZtanmRc4AL/JwVzHQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/netbsd-arm64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.0.tgz",
"integrity": "sha512-CR/RYotgtCKwtftMwJlUU7xCVNg3lMYZ0RzTmAHSfLCXw3NtZtNpswLEj/Kkf6kEL3Gw+BpOekRX0BYCtklhUw==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"netbsd"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/netbsd-x64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.0.tgz",
"integrity": "sha512-nU1yhmYutL+fQ71Kxnhg8uEOdC0pwEW9entHykTgEbna2pw2dkbFSMeqjjyHZoCmt8SBkOSvV+yNmm94aUrrqw==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"netbsd"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/openbsd-arm64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.0.tgz",
"integrity": "sha512-cXb5vApOsRsxsEl4mcZ1XY3D4DzcoMxR/nnc4IyqYs0rTI8ZKmW6kyyg+11Z8yvgMfAEldKzP7AdP64HnSC/6g==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"openbsd"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/openbsd-x64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.0.tgz",
"integrity": "sha512-8wZM2qqtv9UP3mzy7HiGYNH/zjTA355mpeuA+859TyR+e+Tc08IHYpLJuMsfpDJwoLo1ikIJI8jC3GFjnRClzA==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"openbsd"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/openharmony-arm64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.0.tgz",
"integrity": "sha512-FLGfyizszcef5C3YtoyQDACyg95+dndv79i2EekILBofh5wpCa1KuBqOWKrEHZg3zrL3t5ouE5jgr94vA+Wb2w==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"openharmony"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/sunos-x64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.0.tgz",
"integrity": "sha512-1ZgjUoEdHZZl/YlV76TSCz9Hqj9h9YmMGAgAPYd+q4SicWNX3G5GCyx9uhQWSLcbvPW8Ni7lj4gDa1T40akdlw==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"sunos"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/win32-arm64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.0.tgz",
"integrity": "sha512-Q9StnDmQ/enxnpxCCLSg0oo4+34B9TdXpuyPeTedN/6+iXBJ4J+zwfQI28u/Jl40nOYAxGoNi7mFP40RUtkmUA==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/win32-ia32": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.0.tgz",
"integrity": "sha512-zF3ag/gfiCe6U2iczcRzSYJKH1DCI+ByzSENHlM2FcDbEeo5Zd2C86Aq0tKUYAJJ1obRP84ymxIAksZUcdztHA==",
"cpu": [
"ia32"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/win32-x64": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.0.tgz",
"integrity": "sha512-pEl1bO9mfAmIC+tW5btTmrKaujg3zGtUmWNdCw/xs70FBjwAL3o9OEKNHvNmnyylD6ubxUERiEhdsL0xBQ9efw==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=18"
}
},
"node_modules/@types/node": {
"version": "20.19.41",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.41.tgz",
"integrity": "sha512-ECymXOukMnOoVkC2bb1Vc/w/836DXncOg5m8Xj1RH7xSHZJWNYY6Zh7EH477vcnD5egKNNfy2RpNOmuChhFPgQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.21.0"
}
},
"node_modules/esbuild": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.0.tgz",
"integrity": "sha512-sNR9MHpXSUV/XB4zmsFKN+QgVG82Cc7+/aaxJ8Adi8hyOac+EXptIp45QBPaVyX3N70664wRbTcLTOemCAnyqw==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"bin": {
"esbuild": "bin/esbuild"
},
"engines": {
"node": ">=18"
},
"optionalDependencies": {
"@esbuild/aix-ppc64": "0.28.0",
"@esbuild/android-arm": "0.28.0",
"@esbuild/android-arm64": "0.28.0",
"@esbuild/android-x64": "0.28.0",
"@esbuild/darwin-arm64": "0.28.0",
"@esbuild/darwin-x64": "0.28.0",
"@esbuild/freebsd-arm64": "0.28.0",
"@esbuild/freebsd-x64": "0.28.0",
"@esbuild/linux-arm": "0.28.0",
"@esbuild/linux-arm64": "0.28.0",
"@esbuild/linux-ia32": "0.28.0",
"@esbuild/linux-loong64": "0.28.0",
"@esbuild/linux-mips64el": "0.28.0",
"@esbuild/linux-ppc64": "0.28.0",
"@esbuild/linux-riscv64": "0.28.0",
"@esbuild/linux-s390x": "0.28.0",
"@esbuild/linux-x64": "0.28.0",
"@esbuild/netbsd-arm64": "0.28.0",
"@esbuild/netbsd-x64": "0.28.0",
"@esbuild/openbsd-arm64": "0.28.0",
"@esbuild/openbsd-x64": "0.28.0",
"@esbuild/openharmony-arm64": "0.28.0",
"@esbuild/sunos-x64": "0.28.0",
"@esbuild/win32-arm64": "0.28.0",
"@esbuild/win32-ia32": "0.28.0",
"@esbuild/win32-x64": "0.28.0"
}
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/tsx": {
"version": "4.22.3",
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.22.3.tgz",
"integrity": "sha512-mdoNxBC/cSQObGGVQ5Bpn5i+yv7j68gk3Nfm3wFjcJg3Z0Mix9jzAFfP12prmm5eVGmDKtp0yyArrs0Q+8gZHg==",
"dev": true,
"license": "MIT",
"dependencies": {
"esbuild": "~0.28.0"
},
"bin": {
"tsx": "dist/cli.mjs"
},
"engines": {
"node": ">=18.0.0"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
}
},
"node_modules/typescript": {
"version": "5.9.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/undici-types": {
"version": "6.21.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
"dev": true,
"license": "MIT"
}
}
}

View File

@@ -1,7 +1,6 @@
import { execSync, exec, ChildProcess } from "child_process"; import { execSync, exec, ChildProcess } from "child_process";
import * as path from "path"; import * as path from "path";
import * as fs from "fs"; import * as fs from "fs";
import { testDeleteClip } from './test_delete_clip';
const PROJECT_DIR = path.resolve(__dirname, ".."); const PROJECT_DIR = path.resolve(__dirname, "..");
const ENGINE_BIN = path.join(PROJECT_DIR, "engine/looper"); const ENGINE_BIN = path.join(PROJECT_DIR, "engine/looper");
@@ -1185,8 +1184,7 @@ async function main(): Promise<void> {
testStressRandomUsage, testStressRandomUsage,
testKeyPressLatency, testKeyPressLatency,
testStatusFifoLevelLine, testStatusFifoLevelLine,
testVUMeter, testVUMeter
testDeleteClip
]; ];
let passCount = 0; let passCount = 0;
let failCount = 0; let failCount = 0;

View File

@@ -1,43 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, readStatusNonBlock, teardownTest } from './test_utils';
export async function testChannelAddRemove(): Promise<void> {
console.log("\nTest: CHANNEL ADD / REMOVE");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(500);
// Send "add" command via FIFO
writeFifoCommand("add");
await wait(1000);
// Read status lines and look for CH=1 (channel 1 active)
const st = readStatusNonBlock();
// Count channels by counting lines starting with "CH="
let channelCount = 0;
for (const line of st.split("\n")) {
if (line.startsWith("CH=")) channelCount++;
}
// Initially channel 0 was present; after add we expect at least 2 channels
if (channelCount >= 2) {
console.log(" PASS: Channel added (saw " + channelCount + " channels in status)");
} else {
// Wait a little more and retry
await wait(1000);
const st2 = readStatusNonBlock();
let channelCount2 = 0;
for (const line of st2.split("\n")) {
if (line.startsWith("CH=")) channelCount2++;
}
if (channelCount2 >= 2) {
console.log(" PASS: Channel added (saw " + channelCount2 + " channels in status)");
} else {
console.log(" WARN: Could not verify new channel in status (got " + channelCount2 + " channels)");
console.log(" Status data: " + st2);
}
}
engine.kill();
teardownTest();
}

View File

@@ -1,94 +0,0 @@
import {
setupTest, startEngine, startClientInTmux, openCmdFifo,
writeFifoCommand, wait, tmuxSendKeys, tmuxCapturePane,
ensureGenTone, run, teardownTest
} from './test_utils';
import * as globals from './test_globals';
export async function testDeleteClip(): Promise<void> {
console.log("\nTest: DELETE CLIP (navigate to channel 2, record, press d clip should be deleted)");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
ensureGenTone();
await wait(500);
// Add channels so column 2 exists (channels 0,1,2)
writeFifoCommand("add");
await wait(200);
writeFifoCommand("add");
await wait(500);
// Navigate to column 2 (two rights)
tmuxSendKeys("looper", "0", "l");
await wait(200);
tmuxSendKeys("looper", "0", "l");
await wait(500);
// Verify selection is at Row 0, Col 2
let pane = tmuxCapturePane("looper", "0");
if (!pane.includes("Selected: Grid 0, Row 0, Col 2")) {
console.log(" FAIL: Could not navigate to Col 2");
engine.kill(); teardownTest();
throw new Error("Navigation to column 2 failed");
}
console.log(" PASS: Navigated to Col 2");
// Start recording on this cell
tmuxSendKeys("looper", "0", "t");
await wait(1000);
// Play a tone into channel 2 (looper:ch2in)
run(`${globals.GEN_TONE_BIN} 1.5 "looper:ch2in"`, 5);
// Stop recording (toggle again) should become LOOPING
tmuxSendKeys("looper", "0", "t");
await wait(1500);
// Verify the grid shows 'L' for this cell (indicates looping)
pane = tmuxCapturePane("looper", "0");
if (!pane.includes("L")) {
console.log(" FAIL: After recording, grid does not show 'L' (clip not in loop state)");
console.log(" Pane excerpt:\n" + pane.slice(0, 1500));
engine.kill(); teardownTest();
throw new Error("Clip not in LOOPING state after record");
}
console.log(" PASS: Clip recorded and looping on channel 2");
// Press 'd' to delete the clip
tmuxSendKeys("looper", "0", "d");
// Wait longer for state to propagate through status FIFO
await wait(2000);
// Now the grid should no longer show 'L' on that cell.
pane = tmuxCapturePane("looper", "0");
// If delete works, the cell at column 2 should show '.' (IDLE), not 'L'.
// Find the line that contains " ch 2." (note the dot after space the state character)
const paneLines = pane.split("\n");
const idlePattern = " ch 2.";
const loopPattern = " ch 2L";
let cell2Idle = false;
let cell2Loop = false;
for (let i = 0; i < paneLines.length; i++) {
if (paneLines[i].includes(idlePattern)) cell2Idle = true;
if (paneLines[i].includes(loopPattern)) cell2Loop = true;
}
if (cell2Loop) {
console.log(" FAIL: After pressing d, grid still shows 'L' near cell 2 (clip not deleted)");
console.log(" Pane excerpt:\n" + pane.slice(0, 1500));
engine.kill(); teardownTest();
throw new Error("Delete key did not remove the clip");
}
if (cell2Idle) {
console.log(" PASS: After pressing d, cell shows '.' clip successfully deleted");
} else {
console.log(" WARN: Could not confirm '.' on cell 2 (may be due to layout), but delete worked");
}
engine.kill();
teardownTest();
}

View File

@@ -1,84 +0,0 @@
import { setupTest, startEngine, openCmdFifo, writeFifoCommand, wait, execSync, teardownTest } from './test_utils';
export async function testFromToAudioPass(): Promise<void> {
console.log("\nTest: FROM/TO audio pass");
setupTest();
const engine = await startEngine();
openCmdFifo();
await wait(1000);
// Send commands directly to the engine's FIFO (bypass TUI)
writeFifoCommand("from system:capture_1");
writeFifoCommand("to system:playback_1");
await wait(1000);
// Read the engine's stderr log to confirm the connection attempt
let stderrLog = "";
try {
stderrLog = execSync("cat /tmp/engine_stderr.log", { encoding: "utf-8" }).trim();
} catch {}
console.log(" Engine stderr lines:\n" + stderrLog);
// Expect either success (no error) or a "Failed to connect" message
const fromReceived = stderrLog.includes("FIFO RECEIVED from: system:capture_1");
const toReceived = stderrLog.includes("FIFO RECEIVED to: system:playback_1");
if (!fromReceived) {
console.log(" FAIL: Engine did not receive 'from' command via FIFO");
engine.kill(); teardownTest();
throw new Error("Engine did not process 'from' command");
} else {
console.log(" PASS: Engine received 'from' command via FIFO");
}
if (!toReceived) {
console.log(" FAIL: Engine did not receive 'to' command via FIFO");
engine.kill(); teardownTest();
throw new Error("Engine did not process 'to' command");
} else {
console.log(" PASS: Engine received 'to' command via FIFO");
}
// Now check the connection result look for error lines produced by the fixed pipe.c
const fromFailed = stderrLog.includes("Failed to connect system:capture_1 -> looper:ch0in");
const toFailed = stderrLog.includes("Failed to connect looper:ch0out -> system:playback_1");
const anyError = stderrLog.includes("Failed to connect") || stderrLog.includes("Retry also failed");
if (fromFailed) {
console.log(` FAIL: Engine reported failure connecting system:capture_1 -> looper:input`);
console.log(" Connection not established (expected test environment may not have JACK ports)");
console.log(" PASS: Engine correctly logged the failure");
} else if (!anyError) {
console.log(` PASS: Engine did not log any failure for input connection (may have succeeded)`);
} else {
// Some other error was logged (e.g. retry also failed for the old or new conn)
console.log(` FAIL: Unexpected connection error for input`);
console.log(" Engine stderr:\n" + stderrLog);
engine.kill(); teardownTest();
throw new Error("Unexpected connection error for from");
}
if (toFailed) {
console.log(` FAIL: Engine reported failure connecting looper:output -> system:playback_1`);
console.log(" PASS: Engine correctly logged the failure");
} else if (!anyError) {
console.log(` PASS: Engine did not log any failure for output connection (may have succeeded)`);
} else {
console.log(` FAIL: Unexpected connection error for output`);
console.log(" Engine stderr:\n" + stderrLog);
engine.kill(); teardownTest();
throw new Error("Unexpected connection error for to");
}
// If both failed as expected, the test passes
if (fromFailed && toFailed) {
console.log(" PASS: Both connections failed as expected (no real system:capture_1 / system:playback_1 ports in this test environment)");
} else if (!fromFailed && !toFailed && !anyError) {
console.log(" PASS: Both connections succeeded");
} else {
console.log(" INFO: Mixed outcome (one succeeded, one failed)");
}
engine.kill();
teardownTest();
}

View File

@@ -1,8 +0,0 @@
import * as path from "path";
export const PROJECT_DIR = path.resolve(__dirname, "..");
export const ENGINE_BIN = path.join(PROJECT_DIR, "engine/looper");
export const CLIENT_BIN = path.join(PROJECT_DIR, "client/looper-client");
export const STATUS_FIFO = "/tmp/looper_status";
export const CMD_FIFO = "/tmp/looper_cmd";
export const GEN_TONE_BIN = "/tmp/gen_tone";

View File

@@ -1,49 +0,0 @@
import { setupTest, startEngine, startClientInTmux, tmuxSendKeys, wait, tmuxCapturePane, waitForPaneText, teardownTest } from './test_utils';
export async function testGridNavigation(): Promise<void> {
console.log("\nTest: GRID NAVIGATION");
setupTest();
const engine = await startEngine();
await startClientInTmux();
// Default location should be Row 0, Col 0
let pane = await waitForPaneText("Selected: Grid 0, Row 0, Col 0", 5000);
if (pane.includes("Selected: Grid 0, Row 0, Col 0")) {
console.log(" PASS: Default selection at origin");
} else {
console.log(" FAIL: Expected 'Selected: Grid 0, Row 0, Col 0'");
console.log(" Actual pane content:\n" + pane);
engine.kill(); teardownTest();
throw new Error("Grid navigation test failed");
}
// Move right then down
tmuxSendKeys("looper", "0", "l");
tmuxSendKeys("looper", "0", "j");
await wait(200);
pane = tmuxCapturePane("looper", "0");
if (pane.includes("Selected: Grid 0, Row 1, Col 1")) {
console.log(" PASS: Moved to Row 1, Col 1");
} else {
console.log(" FAIL: Expected 'Row 1, Col 1'");
engine.kill(); teardownTest();
throw new Error("Grid navigation test failed");
}
// Cycle back to origin
tmuxSendKeys("looper", "0", "h");
await wait(400);
tmuxSendKeys("looper", "0", "k");
await wait(400);
pane = tmuxCapturePane("looper", "0");
if (pane.includes("Selected: Grid 0, Row 0, Col 0")) {
console.log(" PASS: Returned to origin");
} else {
console.log(" FAIL: Not at origin after h/k");
engine.kill(); teardownTest();
throw new Error("Grid navigation test failed");
}
engine.kill();
teardownTest();
}

View File

@@ -1,62 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, tmuxSendKeys, waitForPaneText, teardownTest } from './test_utils';
export async function testKeyPressLatency(): Promise<void> {
console.log("\nTest: KEY PRESS LATENCY (50 toggles, check for exponential slowdown)");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(500);
const ITERATIONS = 50;
const LATENCY_WARN = 500; // warn if >500ms
const LATENCY_FAIL = 5000; // fail if >5s
let latencies: number[] = [];
let prevState = "IDLE";
for (let i = 0; i < ITERATIONS; i++) {
// Determine which state we expect after toggle
const expectNext = (prevState === "IDLE") ? "R" : "L";
const startTime = Date.now();
tmuxSendKeys("looper", "0", "t");
const pane = await waitForPaneText(expectNext, 10000);
const elapsed = Date.now() - startTime;
latencies.push(elapsed);
// Log periodic summary
if (i % 10 === 9) {
const avg = latencies.slice(i-9, i+1).reduce((a,b)=>a+b,0) / 10;
console.log(` Iteration ${i+1}: avg last 10 = ${avg.toFixed(0)} ms, last = ${elapsed} ms`);
}
if (elapsed > LATENCY_FAIL) {
console.log(` FAIL: Iteration ${i+1} latency ${elapsed} ms exceeds ${LATENCY_FAIL} ms`);
engine.kill(); teardownTest();
throw new Error(`Latency exceeded fail threshold at iteration ${i+1}`);
}
if (elapsed > LATENCY_WARN) {
console.log(` WARN: Iteration ${i+1} latency ${elapsed} ms > ${LATENCY_WARN} ms (possible slowdown)`);
}
// Toggle state for next expectation
prevState = (prevState === "IDLE") ? "LOOPING" : "IDLE";
await wait(200); // brief cooldown
}
// Check for trend: if last 10 avg > 3x first 10 avg → exponential
const first10Avg = latencies.slice(0,10).reduce((a,b)=>a+b,0) / 10;
const last10Avg = latencies.slice(-10).reduce((a,b)=>a+b,0) / 10;
console.log(` First 10 avg: ${first10Avg.toFixed(0)} ms, Last 10 avg: ${last10Avg.toFixed(0)} ms`);
if (last10Avg > 3 * first10Avg && last10Avg > 500) {
console.log(` FAIL: Latency grew from ${first10Avg.toFixed(0)} ms to ${last10Avg.toFixed(0)} ms (exponential pattern)`);
engine.kill(); teardownTest();
throw new Error("Exponential latency increase");
}
console.log(" PASS: No exponential latency growth");
engine.kill();
teardownTest();
}

View File

@@ -1,64 +0,0 @@
import { testGridNavigation } from './test_grid_navigation';
import { testChannelAddRemove } from './test_channel_add_remove';
import { testToggleRecordStop } from './test_toggle_record_stop';
import { testTUIRecordAndLoop } from './test_tui_record_and_loop';
import { testRecordOnSelectedCell } from './test_record_on_selected_cell';
import { testSaveLoad } from './test_save_load';
import { testRecordOnMissingChannel } from './test_record_on_missing_channel';
import { testRapidKeyMashConsistency } from './test_rapid_key_mash';
import { testRecordOnHighRow } from './test_record_on_high_row';
import { testFromToAudioPass } from './test_from_to_audio_pass';
import { testRecordMoveRecord } from './test_record_move_record';
import { testStressRandomUsage } from './test_stress_random';
import { testKeyPressLatency } from './test_key_press_latency';
import { testStatusFifoLevelLine } from './test_status_fifo_level';
import { testVUMeter } from './test_vu_meter';
async function main(): Promise<void> {
console.log("=== Looper E2E Tests ===\n");
const tests = [
testGridNavigation,
testChannelAddRemove,
testToggleRecordStop,
testTUIRecordAndLoop,
testRecordOnSelectedCell,
testSaveLoad,
testRecordOnMissingChannel,
testRapidKeyMashConsistency,
testRecordOnHighRow,
testFromToAudioPass,
testRecordMoveRecord,
testStressRandomUsage,
testKeyPressLatency,
testStatusFifoLevelLine,
testVUMeter,
];
let passCount = 0;
let failCount = 0;
for (const testFn of tests) {
process.stdout.write("\n");
try {
await Promise.race([
testFn(),
new Promise<void>((_, reject) => setTimeout(() => reject(new Error("Test timed out")), 600000))
]);
passCount++;
} catch (e: any) {
console.log(` ERROR: ${e.message}`);
failCount++;
}
}
console.log(`\n=== Results: ${passCount} passed, ${failCount} failed ===`);
if (failCount > 0) {
process.exit(1);
}
process.exit(0);
}
main().catch((e) => {
console.error("Unhandled error:", e);
process.exit(1);
});

View File

@@ -1,71 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, tmuxSendKeys, tmuxCapturePane, teardownTest } from './test_utils';
export async function testRapidKeyMashConsistency(): Promise<void> {
console.log("\nTest: RAPID KEY MASH CONSISTENCY (burst of 10 keys, verify pane)");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(500);
// Add channels up to column 5
for (let i = 1; i <= 5; i++) {
writeFifoCommand("add");
await wait(100);
}
const ITERATIONS = 20;
for (let iter = 0; iter < ITERATIONS; iter++) {
const seed = iter * 7;
let keys = "";
for (let k = 0; k < 10; k++) {
const dir = (seed + k) % 4;
switch (dir) {
case 0: keys += "l"; break;
case 1: keys += "h"; break;
case 2: keys += "j"; break;
case 3: keys += "k"; break;
}
}
keys += "t"; // record
tmuxSendKeys("looper", "0", keys);
await wait(500);
// Capture pane
const pane = tmuxCapturePane("looper", "0");
// 1. Selected line must be present
const selMatch = pane.match(/Selected: Grid \d+, Row (\d+), Col (\d+)/);
if (!selMatch) {
console.log(` FAIL at iteration ${iter}: No selected line in pane`);
console.log(" Pane:\n" + pane.slice(0, 500));
engine.kill(); teardownTest();
throw new Error("Selected line missing after burst");
}
const row = parseInt(selMatch[1]);
const col = parseInt(selMatch[2]);
if (row < 0 || row > 7 || col < 0 || col > 7) {
console.log(` FAIL at iteration ${iter}: selected (${row},${col}) out of bounds`);
engine.kill(); teardownTest();
throw new Error("Selected cell out of bounds after burst");
}
// 2. At least one 'R' must appear in the pane
const hasR = pane.includes("R");
if (!hasR) {
console.log(` FAIL at iteration ${iter}: No 'R' found after burst`);
console.log(" Pane:\n" + pane.slice(0, 1000));
engine.kill(); teardownTest();
throw new Error("No 'R' indicator after rapid key mash");
}
// 3. Toggle back to idle for next iteration
tmuxSendKeys("looper", "0", "t");
await wait(300);
}
console.log(" PASS: Rapid key mash consistency maintained over " + ITERATIONS + " iterations");
engine.kill();
teardownTest();
}

View File

@@ -1,62 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, tmuxSendKeys, tmuxCapturePane, teardownTest } from './test_utils';
export async function testRecordMoveRecord(): Promise<void> {
console.log("\nTest: RECORD ON ROW2 COL0, THEN MOVE RIGHT AND RECORD AGAIN");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(500);
// Do NOT preadd engine must autocreate channel 1 on demand
// Navigate down twice to row2, col0
tmuxSendKeys("looper", "0", "j");
tmuxSendKeys("looper", "0", "j");
await wait(500);
// Verify selection
let pane = tmuxCapturePane("looper", "0");
if (!pane.includes("Row 2, Col 0")) {
console.log(" FAIL: Could not navigate to Row2, Col0");
engine.kill(); teardownTest();
throw new Error("Navigation failed");
}
// First trigger: record on cell (row2, col0)
tmuxSendKeys("looper", "0", "t");
await wait(1000);
pane = tmuxCapturePane("looper", "0");
const gridArea1 = pane.split("Selected:")[0] || pane;
const rCount1 = (gridArea1.match(/R/g) || []).length;
if (rCount1 !== 1) {
console.log(` FAIL: Expected 1 'R' after first trigger, got ${rCount1}`);
console.log(" Pane:\n" + pane.slice(0, 1000));
engine.kill(); teardownTest();
throw new Error("First trigger not reflected");
}
console.log(" PASS: First trigger produced exactly one 'R'");
// Move right to col1
tmuxSendKeys("looper", "0", "l");
await wait(500);
// Second trigger
tmuxSendKeys("looper", "0", "t");
await wait(1000);
pane = tmuxCapturePane("looper", "0");
const gridArea2 = pane.split("Selected:")[0] || pane;
const rCount2 = (gridArea2.match(/R/g) || []).length;
if (rCount2 !== 2) {
console.log(` FAIL: Expected 2 'R's after second trigger on col1, got ${rCount2}`);
console.log(" Pane:\n" + pane.slice(0, 1000));
engine.kill(); teardownTest();
throw new Error("Second trigger did not create another recording indicator");
}
console.log(" PASS: Second trigger produced a second 'R'");
engine.kill();
teardownTest();
}

View File

@@ -1,56 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, tmuxSendKeys, tmuxCapturePane, waitForPaneText, teardownTest } from './test_utils';
export async function testRecordOnHighRow(): Promise<void> {
console.log("\nTest: RECORD ON HIGH ROW (row 5, col 0) verifies engine & TUI");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(500);
// Add a few channels so column 0 is usable
for (let i = 1; i <= 3; i++) {
writeFifoCommand("add");
await wait(100);
}
// Navigate to row 5, col 0
tmuxSendKeys("looper", "0", "j");
tmuxSendKeys("looper", "0", "j");
tmuxSendKeys("looper", "0", "j");
tmuxSendKeys("looper", "0", "j");
tmuxSendKeys("looper", "0", "j");
await wait(500);
// Verify selection shows row 5
let pane = tmuxCapturePane("looper", "0");
if (!pane.includes("Selected: Grid 0, Row 5, Col 0")) {
console.log(" FAIL: Could not navigate to Row 5, Col 0");
engine.kill(); teardownTest();
throw new Error("Navigation to row 5 failed");
}
console.log(" PASS: Navigated to Row 5, Col 0");
// Press 't' to start recording
tmuxSendKeys("looper", "0", "t");
// Check the TUI pane wait until it shows 'R' near row 5
const paneWithR = await waitForPaneText("R", 5000);
const paneLines = paneWithR.split("\n");
let cell5Line = -1, recordLine = -1;
for (let i = 0; i < paneLines.length; i++) {
if (paneLines[i].includes(" 5")) cell5Line = i;
if (paneLines[i].includes("R")) recordLine = i;
}
if (cell5Line !== -1 && recordLine !== -1 && Math.abs(recordLine - cell5Line) <= 2) {
console.log(" PASS: TUI grid shows 'R' near row 5");
} else {
console.log(" FAIL: TUI grid does not show 'R' near row 5");
console.log(" Pane:\n" + paneWithR.slice(0, 1000));
engine.kill(); teardownTest();
throw new Error("TUI indicator missing for row 5");
}
engine.kill();
teardownTest();
}

View File

@@ -1,50 +0,0 @@
import { setupTest, startEngine, startClientInTmux, wait, tmuxSendKeys, tmuxCapturePane, teardownTest } from './test_utils';
export async function testRecordOnMissingChannel(): Promise<void> {
console.log("\nTest: RECORD ON MISSING CHANNEL (col 2, row 2)");
setupTest();
const engine = await startEngine();
await startClientInTmux();
// Do NOT add any channels only channel 0 exists
await wait(500);
// Navigate to row 2, col 2 (two rights, two downs)
tmuxSendKeys("looper", "0", "l");
tmuxSendKeys("looper", "0", "l");
await wait(200);
tmuxSendKeys("looper", "0", "j");
tmuxSendKeys("looper", "0", "j");
await wait(200);
// Verify selection line
let pane = tmuxCapturePane("looper", "0");
if (!pane.includes("Selected: Grid 0, Row 2, Col 2")) {
console.log(" FAIL: Could not navigate to Row 2, Col 2");
engine.kill(); teardownTest();
throw new Error("Navigation to (2,2) failed");
}
// Press 't' to start recording (no extra key TUI polls itself)
tmuxSendKeys("looper", "0", "t");
await wait(1500);
// Check the grid shows 'R' near cell (2,2)
pane = tmuxCapturePane("looper", "0");
const paneLines = pane.split("\n");
let cellLine = -1, recordLine = -1;
for (let i = 0; i < paneLines.length; i++) {
if (paneLines[i].includes(" 2")) cellLine = i;
if (paneLines[i].includes("R")) recordLine = i;
}
if (cellLine !== -1 && recordLine !== -1 && Math.abs(recordLine - cellLine) <= 2) {
console.log(" PASS: Grid shows 'R' indicator near cell 2");
} else {
console.log(" FAIL: Could not find 'R' near cell 2 in pane");
console.log(" Pane excerpt:\n" + pane.slice(0, 1000));
engine.kill(); teardownTest();
throw new Error("Grid indicator missing for col 2");
}
engine.kill();
teardownTest();
}

View File

@@ -1,63 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, tmuxSendKeys, tmuxCapturePane, ensureGenTone, teardownTest } from './test_utils';
export async function testRecordOnSelectedCell(): Promise<void> {
console.log("\nTest: RECORD ON SELECTED CELL (col 1, row 0)");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
ensureGenTone();
await wait(500);
// Add a new channel so column 1 (channel 1) exists
writeFifoCommand("add");
await wait(500);
// Navigation: move right once to column 1 (channel 1)
tmuxSendKeys("looper", "0", "l"); // right once → col 1
await wait(500);
// Verify selection shows column 1
let pane = tmuxCapturePane("looper", "0");
if (!pane.includes("Selected: Grid 0, Row 0, Col 1")) {
console.log(" FAIL: Could not navigate to Col 1");
engine.kill(); teardownTest();
throw new Error("Navigation to column 1 failed");
}
console.log(" PASS: Successfully navigated to Col 1");
// Press 't' to start recording no extra key, TUI should redraw on its own
tmuxSendKeys("looper", "0", "t");
await wait(1500);
// Capture the pane once this is the TUI's state
const paneAfter = tmuxCapturePane("looper", "0");
// 1. The grid should show 'R' near cell 1 (col 1, row 0)
const paneLines = paneAfter.split("\n");
let cell1Line = -1, recordLine = -1;
for (let i = 0; i < paneLines.length; i++) {
if (paneLines[i].includes(" 1")) cell1Line = i;
if (paneLines[i].includes("R")) recordLine = i;
}
if (cell1Line === -1 || recordLine === -1 || Math.abs(recordLine - cell1Line) > 2) {
console.log(" FAIL: Grid did not show 'R' near cell 1");
console.log(" Pane excerpt:\n" + paneAfter.slice(0, 1000));
engine.kill(); teardownTest();
throw new Error("Grid indicator not updated for selected cell");
}
console.log(" PASS: Grid shows 'R' indicator near cell 1 after single 't'");
// 2. Verify that cell (row 0, col 0) does NOT show 'R' via pane char position
// Cell (0,0) has its state character at line 5, column 4 (based on grid layout)
const cell00StateCh = (paneLines.length > 5 && paneLines[5].length > 4) ? paneLines[5][4] : '?';
if (cell00StateCh === 'R') {
console.log(" FAIL: Cell (0,0) shows 'R' (crosstalk)");
engine.kill(); teardownTest();
throw new Error("Crosstalk detected on cell 0");
}
console.log(" PASS: Cell (0,0) does not show 'R' (no crosstalk)");
engine.kill();
teardownTest();
}

View File

@@ -1,117 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, ensureGenTone, execSync, waitForStatusContaining, readStatusNonBlock, teardownTest } from './test_utils';
import * as path from "path";
import * as fs from "fs";
import * as globals from "./test_globals";
export async function testSaveLoad(): Promise<void> {
console.log("\nTest: SAVE / LOAD");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(1000);
ensureGenTone();
// Start recording via FIFO with retry
let recordAttempts = 0;
while (recordAttempts < 3) {
writeFifoCommand("record 0");
const st1 = await waitForStatusContaining("RECORD", 3000);
if (st1.includes("RECORD")) {
console.log(" DEBUG: RECORD confirmed after attempt " + (recordAttempts + 1));
break;
}
recordAttempts++;
console.log(" WARN: First toggle attempt " + (recordAttempts) + " did not produce RECORD, retrying...");
}
if (recordAttempts >= 3) {
console.log(" FAIL: Could not enter RECORD after 3 attempts");
const st1 = readStatusNonBlock();
console.log(" DEBUG status after first toggle:", st1.slice(0, 200));
engine.kill(); teardownTest();
throw new Error("Could not enter RECORD");
}
// Play tone into looper:input using gen_tone (synchronous, blocks until done)
execSync(`${globals.GEN_TONE_BIN} 3.0 "looper:ch0in"`, { timeout: 8000 }); // 3 seconds tone
// Stop recording (toggle again -> loop)
writeFifoCommand("record 0");
const loopState = await waitForStatusContaining("LOOPING", 8000);
if (!loopState.includes("LOOPING")) {
console.log(" WARN: Second toggle did not produce LOOPING within 8s, will attempt save anyway");
console.log(" DEBUG status after second toggle:", loopState.slice(0, 200));
} else {
console.log(" DEBUG: LOOPING confirmed");
}
// Save via FIFO
writeFifoCommand("save");
await wait(6000); // wait for synchronous save
// Print engine stderr log for save debug
try {
const stderrLog = execSync("tail -5 /tmp/engine_stderr.log", { encoding: "utf-8" });
console.log(" Engine stderr:", stderrLog.trim());
} catch {}
// Look for save file in project directory (engine writes there)
const files = fs.readdirSync(globals.PROJECT_DIR);
const saveFile = files.find(f => f === "save.wav");
if (saveFile) {
const stat = fs.statSync(path.join(globals.PROJECT_DIR, saveFile));
if (stat.size > 44) {
console.log(` PASS: save.wav created (${stat.size} bytes)`);
} else {
console.log(` FAIL: save.wav exists but header may be incomplete (size=${stat.size})`);
engine.kill(); teardownTest();
throw new Error("save.wav too short");
}
} else {
console.log(" FAIL: save.wav not found in project directory");
console.log(" Directory listing: " + fs.readdirSync(globals.PROJECT_DIR).filter(f => f.endsWith(".wav")).join(","));
engine.kill(); teardownTest();
throw new Error("save.wav not created");
}
// Load into channel 0
const testWavPath = path.join(globals.PROJECT_DIR, "loop.wav");
// generateTestWav is not imported here; we'll use execSync directly
execSync(`sox -n -r 48000 -b 16 -c 1 ${testWavPath} synth 3.0 sine 440`, { timeout: 5000 });
await wait(500);
writeFifoCommand("load loop.wav");
await wait(3000);
// Wait for LOOPING state after load
const loadState = await waitForStatusContaining("LOOPING", 5000);
if (!loadState.includes("LOOPING")) {
console.log(" WARN: Status did not show LOOPING after load command");
console.log(" Status: " + loadState.slice(0,200));
}
// Check engine stderr for load success line using grep over whole file
let loadSucceeded = false;
try {
// Look for the actual load success message (printed by exec_command->cmd_load handling)
execSync("grep -q 'LOAD:' /tmp/engine_stderr.log", { timeout: 3000 });
console.log(" PASS: Engine acknowledged load command");
loadSucceeded = true;
} catch {
const stderrLog = execSync("cat /tmp/engine_stderr.log", { encoding: "utf-8" }).trim();
// Also search for any FIFO RECEIVED load message
const hasFifo = stderrLog.includes("FIFO RECEIVED load");
console.log(" FAIL: Engine did not report LOAD: success in stderr; FIFO received = " + hasFifo);
console.log(" Full stderr (last 30 lines):\n" + stderrLog.split("\n").slice(-30).join("\n"));
}
if (!loadSucceeded) {
console.log(" FAIL: Engine load did not succeed");
engine.kill(); teardownTest();
throw new Error("Engine load reported failure");
}
engine.kill();
teardownTest();
}

View File

@@ -1,29 +0,0 @@
import { setupTest, startEngine, openCmdFifo, wait, ensureGenTone, execSync, readStatusNonBlock, teardownTest } from './test_utils';
import * as globals from "./test_globals";
export async function testStatusFifoLevelLine(): Promise<void> {
console.log("\nTest: STATUS FIFO LEVEL LINE AFTER TONE");
const engine = await startEngine();
openCmdFifo();
await wait(500);
// Play tone directly (not through TUI)
ensureGenTone();
execSync(`${globals.GEN_TONE_BIN} 1.0 "looper:ch0in"`, { timeout: 5000 });
// Wait for engine to write status
await wait(2000);
// Read status FIFO directly
const data = readStatusNonBlock();
const hasLevel = data.includes("LEVEL=");
console.log(" Status FIFO data:", data.slice(0, 500));
if (hasLevel) {
console.log(" PASS: LEVEL line found in status FIFO");
} else {
console.log(" FAIL: No LEVEL line in status FIFO. Check engine RMS computation.");
engine.kill(); teardownTest();
throw new Error("Level line missing from status FIFO");
}
engine.kill(); teardownTest();
}

View File

@@ -1,80 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, tmuxSendKeys, tmuxCapturePane, isProcessAlive, execSync, teardownTest } from './test_utils';
export async function testStressRandomUsage(): Promise<void> {
console.log("\nTest: STRESS RANDOM USAGE (10,000 keys, stability check)");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(500);
// Preadd channels for more variety
for (let i = 0; i < 7; i++) {
writeFifoCommand("add");
await wait(100);
}
const KEY_ACTIONS = ['h','j','k','l','t','d','s','S','a','A','r','b','u'];
const TOTAL = 5000;
const KEY_DELAY_MS = 20;
const CHECK_INTERVAL = 500;
console.log(` Starting stress loop: ${TOTAL} keys at ~20 keys/second...`);
let keysSent = 0;
const startTime = Date.now();
for (let i = 0; i < TOTAL; i++) {
const key = KEY_ACTIONS[Math.floor(Math.random() * KEY_ACTIONS.length)];
tmuxSendKeys("looper", "0", key);
await wait(KEY_DELAY_MS);
keysSent++;
if (keysSent % CHECK_INTERVAL === 0) {
// Wait a little for TUI to settle
await wait(500);
// Check engine alive
if (engine.pid && !isProcessAlive(engine.pid)) {
console.log(` FAIL: Engine died at key ${keysSent}`);
try {
const stderr = execSync("tail -20 /tmp/engine_stderr.log", { encoding: "utf-8" }).trim();
console.log(" Engine stderr:", stderr);
} catch {}
teardownTest();
throw new Error("Engine crash during stress test");
}
// Wait a little more for TUI to settle and pane to be captured fully
await wait(1000);
// Retry pane capture up to 5 times with small delays if it doesn't contain "Selected:"
let pane = "";
for (let retry = 0; retry < 5; retry++) {
pane = tmuxCapturePane("looper", "0");
if (pane && pane.includes("Selected:")) break;
await wait(200);
pane = tmuxCapturePane("looper", "0");
}
if (!pane || !pane.includes("Selected:")) {
console.log(` FAIL: TUI pane appears corrupted at key ${keysSent}`);
console.log(" Pane:\n" + (pane ? pane.slice(0, 1000) : "(empty)"));
teardownTest();
throw new Error("TUI corruption during stress test");
}
}
}
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
console.log(` Stress loop finished in ${elapsed}s`);
await wait(500);
if (engine.pid && !isProcessAlive(engine.pid)) {
console.log(" FAIL: Engine died after test");
teardownTest();
throw new Error("Engine crash");
}
console.log(" PASS: Stress test completed (no crash or corruption)");
engine.kill();
teardownTest();
}

View File

@@ -1,51 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, readStatusNonBlock, teardownTest } from './test_utils';
export async function testToggleRecordStop(): Promise<void> {
console.log("\nTest: TOGGLE RECORD / STOP");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(500);
// Send 'record 0' via FIFO to start recording
writeFifoCommand("record 0");
await wait(1500);
// Read status nonblocking and look for RECORD
const stAfterRecord = readStatusNonBlock();
if (stAfterRecord.includes("RECORD")) {
console.log(" PASS: Status shows RECORD");
} else {
// Wait a bit more and retry once
await wait(500);
const st2 = readStatusNonBlock();
if (st2.includes("RECORD")) {
console.log(" PASS: Status shows RECORD (after delay)");
} else {
console.log(" STATUS data: " + st2);
console.log(" WARN: Did not see RECORD in status");
}
}
// Stop
writeFifoCommand("stop");
await wait(1500);
const stAfterStop = readStatusNonBlock();
if (stAfterStop.includes("IDLE")) {
console.log(" PASS: Status shows IDLE after stop");
} else {
await wait(500);
const st3 = readStatusNonBlock();
if (st3.includes("IDLE")) {
console.log(" PASS: Status shows IDLE after stop (after delay)");
} else {
console.log(" WARN: Did not see IDLE in status");
console.log(" STATUS data: " + st3);
}
}
engine.kill();
teardownTest();
}

View File

@@ -1,86 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, tmuxSendKeys, tmuxCapturePane, ensureGenTone, execSync, waitForStatusContaining, teardownTest } from './test_utils';
import * as path from "path";
import * as fs from "fs";
import * as globals from "./test_globals";
export async function testTUIRecordAndLoop(): Promise<void> {
console.log("\nTest: TUI RECORD AND LOOP (T key)");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
ensureGenTone();
await wait(500);
// press 't' to start recording on default cell (col 0, row 0)
tmuxSendKeys("looper", "0", "t");
await wait(1000);
// 1) Check status FIFO shows RECORD
const statusRec = await waitForStatusContaining("RECORD", 5000);
if (!statusRec.includes("RECORD")) {
console.log(" FAIL: Status FIFO did not show RECORD after pressing t");
engine.kill(); teardownTest();
throw new Error("RECORD state not achieved via TUI");
}
console.log(" PASS: Status FIFO shows RECORD");
// 2) Check tmux pane for 'R' indicator (first character of cell in grid)
const paneAfterT = tmuxCapturePane("looper", "0");
const paneContainsR = paneAfterT.includes("R");
if (!paneContainsR) {
console.log(" FAIL: TUI grid does not show 'R' indicator after pressing t");
console.log(" Pane excerpt (maybe): " + paneAfterT.slice(0, 1000));
engine.kill(); teardownTest();
throw new Error("Grid indicator not updated");
}
console.log(" PASS: TUI grid shows 'R' indicator");
// Play tone into looper:ch0in (3 seconds)
execSync(`${globals.GEN_TONE_BIN} 3.0 "looper:ch0in"`, { timeout: 8000 });
// press 't' again to stop recording -> loop
tmuxSendKeys("looper", "0", "t");
const statusLoop = await waitForStatusContaining("LOOPING", 8000);
if (!statusLoop.includes("LOOPING")) {
console.log(" WARN: Did not see LOOPING in status, continuing");
} else {
console.log(" PASS: Status FIFO shows LOOPING after second t");
}
// Check pane for 'L' indicator
const paneAfterLoop = tmuxCapturePane("looper", "0");
const paneContainsL = paneAfterLoop.includes("L");
if (!paneContainsL) {
console.log(" FAIL: TUI grid does not show 'L' indicator after loop");
engine.kill(); teardownTest();
throw new Error("Grid indicator not updated for LOOPING");
}
console.log(" PASS: TUI grid shows 'L' indicator");
// Wait a couple of repetitions (3 seconds) then save via FIFO to verify audio
await wait(3000);
// Save via FIFO
writeFifoCommand("save");
await wait(3000);
// Check save.wav exists and has audio
const savePath = path.join(globals.PROJECT_DIR, "save.wav");
let saveOk = false;
if (fs.existsSync(savePath)) {
const stat = fs.statSync(savePath);
if (stat.size > 44) {
saveOk = true;
console.log(` PASS: save.wav created (${stat.size} bytes) loop has audio`);
}
}
if (!saveOk) {
console.log(" FAIL: save.wav not created or too small loop not producing audio");
engine.kill(); teardownTest();
throw new Error("Loop playback not producing audio");
}
engine.kill();
teardownTest();
}

View File

@@ -1,229 +0,0 @@
import { execSync, exec, ChildProcess } from "child_process";
import * as path from "path";
import * as fs from "fs";
import * as globals from "./test_globals";
let cmdFifoFd: number | null = null;
export function run(cmd: string, timeout_sec = 15): string {
return execSync(cmd, { encoding: "utf-8", timeout: timeout_sec * 1000 }).trim();
}
export function runNoThrow(cmd: string): void {
try { run(cmd); } catch { /* ignore */ }
}
export function tmuxSendKeys(session: string, pane: string, keys: string) {
run(`tmux send-keys -t ${session}:${pane} ${JSON.stringify(keys)}`);
}
export function tmuxCapturePane(session: string, pane: string): string {
return run(`tmux capture-pane -t ${session}:${pane} -p`);
}
export function wait(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
/** Wait for a file to exist, up to `timeoutMs` milliseconds. */
export function waitForFile(filepath: string, timeoutMs: number): Promise<void> {
const start = Date.now();
return new Promise<void>((resolve, reject) => {
const check = () => {
if (fs.existsSync(filepath)) {
resolve();
} else if (Date.now() - start > timeoutMs) {
reject(new Error(`Timeout waiting for ${filepath}`));
} else {
setTimeout(check, 200);
}
};
check();
});
}
export function waitForCommandFifo(timeoutMs = 5000): Promise<void> {
return waitForFile(globals.CMD_FIFO, timeoutMs);
}
export function openCmdFifo(): void {
// Wait for FIFO to exist (engine creates it)
let waited = 0;
while (!fs.existsSync(globals.CMD_FIFO) && waited < 5000) {
const waitUntil = Date.now() + 200;
require("child_process").execSync(`sleep 0.2`);
waited += 200;
}
cmdFifoFd = fs.openSync(globals.CMD_FIFO, 'w');
}
export function writeFifoCommand(cmd: string): void {
if (cmdFifoFd === null) {
openCmdFifo();
}
fs.writeSync(cmdFifoFd!, cmd + '\n');
}
export function setupTest() {
process.stdout.write(" Killing stale processes...\n");
runNoThrow("pkill -15 -x looper");
runNoThrow("pkill -15 -x looper-client");
runNoThrow("pkill -9 -x jack_capture");
runNoThrow("tmux kill-session -t looper 2>/dev/null || true");
process.stdout.write(" Checking JACK...\n");
try {
run("jack_wait -c -t 5", 10);
} catch {
console.warn(" JACK server is not running. Tests may fail.");
}
process.stdout.write(" Removing old temp files...\n");
run("rm -f /tmp/looper_cmd /tmp/looper_status /tmp/test.wav /tmp/captured.wav /tmp/loop.wav /tmp/save.wav /tmp/load_test.wav /tmp/loaded.wav save_ch*.wav save.wav loop.wav");
}
export function teardownTest() {
if (cmdFifoFd !== null) {
fs.closeSync(cmdFifoFd);
cmdFifoFd = null;
}
runNoThrow("pkill -15 -x looper");
runNoThrow("pkill -15 -x looper-client");
runNoThrow("pkill -9 -x jack_capture");
runNoThrow("tmux kill-session -t looper");
}
export function isProcessAlive(pid: number): boolean {
try {
process.kill(pid, 0);
return true;
} catch {
return false;
}
}
export async function startEngine(): Promise<ChildProcess> {
process.stdout.write(" Starting engine directly...\n");
const stderrFile = "/tmp/engine_stderr.log";
const proc = exec(`${globals.ENGINE_BIN} 2>${stderrFile}`, { cwd: globals.PROJECT_DIR });
// Wait for the status FIFO to appear (up to 10 seconds)
try {
await Promise.race([
waitForFile(globals.STATUS_FIFO, 10000),
wait(11000),
]);
} catch {
process.stdout.write(" Engine status FIFO did not appear within timeout\n");
if (proc.pid && !isProcessAlive(proc.pid)) {
process.stdout.write(" Engine process died prematurely. stderr log:\n");
const stderr = execSync(`cat ${stderrFile}`, { encoding: "utf-8" }).trim();
process.stdout.write(stderr + "\n");
}
}
if (proc.pid && isProcessAlive(proc.pid)) {
process.stdout.write(" Engine started (pid " + proc.pid + ")\n");
} else {
process.stdout.write(" Engine process is not alive after start attempt\n");
}
return proc;
}
export async function startClientInTmux(): Promise<void> {
// Kill any stale session (silently)
runNoThrow("tmux kill-session -t looper 2>/dev/null");
run("tmux new-session -d -s looper");
// Resize the window (width x height) so we can see the full grid and status line
run("tmux resize-window -t looper:0 -x 120 -y 50 2>/dev/null || true");
// Launch the client
run(`tmux send-keys -t looper:0 ${JSON.stringify(globals.CLIENT_BIN)} Enter`);
// Wait for the client to draw the initial frame (max 10 seconds, poll every 500 ms)
const deadline = Date.now() + 10000;
let pane = "";
while (Date.now() < deadline) {
await wait(500);
pane = tmuxCapturePane("looper", "0");
if (pane.includes("[online]") || pane.includes("Selected:")) {
break;
}
}
// Final short extra wait to ensure status lines are updated
await wait(500);
}
/* Check if the tmux pane contains a given substring */
export function tmuxContains(text: string): boolean {
const pane = tmuxCapturePane("looper", "0");
return pane.includes(text);
}
/* Read the status FIFO nonblocking. Returns the data read (may be empty) */
export function readStatusNonBlock(): string {
try {
const fd = fs.openSync(globals.STATUS_FIFO, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
const buf = Buffer.alloc(2000);
const bytesRead = fs.readSync(fd, buf, 0, 2000, null);
fs.closeSync(fd);
return buf.slice(0, bytesRead).toString('utf-8').trim();
} catch {
return "";
}
}
/* Read the status FIFO and return the first line that matches a pattern, or "" */
export function readStatusLineMatching(pattern: string): string {
const data = readStatusNonBlock();
for (const line of data.split("\n")) {
if (line.includes(pattern)) return line;
}
return "";
}
/* Wait until the tmux pane contains the given substring (optional, used by tests) */
export async function waitForPaneText(text: string, timeoutMs = 5000): Promise<string> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const pane = tmuxCapturePane("looper", "0");
if (pane.includes(text)) return pane;
await wait(300);
}
return tmuxCapturePane("looper", "0");
}
/* Generate a test WAV with a 440 Hz sine wave */
export function generateTestWav(p: string, durationSec = 1): void {
run(`sox -n -r 48000 -b 16 -c 1 ${p} synth ${durationSec} sine 440`);
}
export function ensureGenTone(): void {
if (!fs.existsSync(globals.GEN_TONE_BIN)) {
const src = path.join(__dirname, "gen_tone.c");
execSync(`gcc -o ${globals.GEN_TONE_BIN} ${src} -ljack -lm`, { timeout: 10000 });
}
}
/* Check if a WAV file contains audio (RMS > 0.001) */
export function wavHasAudio(p: string): boolean {
try {
const stat: fs.Stats = fs.statSync(p);
return stat.size > 44;
} catch {
return false;
}
}
export function runCmd(cmd: string): string {
try {
return execSync(cmd, { encoding: 'utf-8', timeout: 3000 }).trim();
} catch { return ""; }
}
/** Wait until the status FIFO contains the given substring or timeout */
export async function waitForStatusContaining(substr: string, timeoutMs = 8000): Promise<string> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const data = readStatusNonBlock();
if (data.includes(substr)) return data;
await wait(200);
}
return readStatusNonBlock();
}

View File

@@ -1,49 +0,0 @@
import { setupTest, startEngine, startClientInTmux, openCmdFifo, wait, ensureGenTone, exec, tmuxCapturePane, teardownTest } from './test_utils';
import * as globals from "./test_globals";
export async function testVUMeter(): Promise<void> {
console.log("\nTest: VU METER RESPONDS TO AUDIO");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(500);
// Capture initial VU line (should be empty/spaces)
let pane = tmuxCapturePane("looper", "0");
const paneLines = pane.split("\n");
// Look for any line containing x or # that is the VU meter line.
const vuLineBefore = paneLines.find(l => /[x#]/.test(l)) || "";
console.log(` Initial VU line: "${vuLineBefore.trim()}"`);
// Generate tone in background (does not block the test)
ensureGenTone();
const toneProc = exec(`${globals.GEN_TONE_BIN} 3.0 "looper:ch0in"`, { timeout: 8000 });
// Wait for audio to start reaching the meter
await wait(1500);
// Capture pane while tone is playing
pane = tmuxCapturePane("looper", "0");
const paneLines2 = pane.split("\n");
// Same detection as above
const vuLineDuring = paneLines2.find(l => /[x#]/.test(l)) || "";
console.log(` VU line during tone: "${vuLineDuring.trim()}"`);
// The VU meter should show non-space characters (at least one 'x' or '#')
const hasSignal = /[x#]/.test(vuLineDuring);
if (hasSignal) {
console.log(" PASS: VU meter shows signal (nonspace characters)");
} else {
console.log(" FAIL: VU meter line does not show any signal characters");
console.log(" Pane excerpt:\n" + pane.slice(0, 2000));
engine.kill(); teardownTest();
throw new Error("VU meter not responsive");
}
// Wait for tone process to finish
try { toneProc.kill(); } catch {}
engine.kill();
teardownTest();
}

View File

@@ -16,7 +16,6 @@ typedef enum {
CMD_ADD_SCENE, CMD_ADD_SCENE,
CMD_REMOVE_SCENE, CMD_REMOVE_SCENE,
CMD_SET_SCENE, CMD_SET_SCENE,
CMD_DELETE,
} cmd_type_t; } cmd_type_t;
typedef struct { typedef struct {

View File

@@ -30,70 +30,9 @@ spsc_queue_t cmd_queue_main_fifo;
/* writer status fd */ /* writer status fd */
static int status_fd = -1; static int status_fd = -1;
/* global sample rate (set during init) */
static int global_sample_rate = 0;
/* global JACK client pointer used by channel.c */
jack_client_t *global_client = NULL; jack_client_t *global_client = NULL;
/* default filename for load/save */ /* Global state (shared across files) */
/* ---------- prev_state moved before first user ---------- */
static atomic_int prev_state[MAX_CHANNELS][MAX_SCENES];
static void looper_write_status(void) {
if (status_fd < 0)
return;
char buf[4096];
int pos = 0;
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
if (!atomic_load(&channels[ch].active))
continue;
int sc_idx = atomic_load(&channels[ch].current_scene);
int state = atomic_load(&channels[ch].scenes[sc_idx].state);
const char *state_str;
switch (state) {
case STATE_IDLE:
state_str = "IDLE";
break;
case STATE_RECORD:
state_str = "RECORD";
break;
case STATE_LOOPING:
state_str = "LOOPING";
break;
case STATE_PAUSED:
state_str = "PAUSED";
break;
default:
state_str = "UNKNOWN";
}
/* Always write state line */
int n = snprintf(buf + pos, sizeof(buf) - pos, "CH=%d SC=%d STATE=%s\n", ch,
sc_idx, state_str);
if (n > 0)
pos += n;
if (pos >= (int)sizeof(buf) - 128)
break;
/* Write RMS level line every time */
{
float level = atomic_load(&channels[ch].rms_level);
int n2 =
snprintf(buf + pos, sizeof(buf) - pos, "CH=%d LEVEL=%f\n", ch, level);
if (n2 > 0)
pos += n2;
if (pos >= (int)sizeof(buf) - 128)
break;
}
}
if (pos > 0) {
int ret = write(status_fd, buf, pos);
(void)ret;
}
}
struct channel_t channels[MAX_CHANNELS]; struct channel_t channels[MAX_CHANNELS];
atomic_int channel_count = 0; atomic_int channel_count = 0;
atomic_int channel_capacity = MAX_CHANNELS; atomic_int channel_capacity = MAX_CHANNELS;
@@ -107,6 +46,10 @@ jack_port_t *midi_clock_port = NULL;
atomic_int control_key_active = 0; atomic_int control_key_active = 0;
atomic_int bind_channel = 0; atomic_int bind_channel = 0;
/* Track previous state to avoid writing unchanged status lines */
static atomic_int prev_state[MAX_CHANNELS][MAX_SCENES];
/* Unregister all ports and close the JACK client */
static void looper_cleanup(jack_client_t *client) { static void looper_cleanup(jack_client_t *client) {
for (int c = 0; c < MAX_CHANNELS; c++) { for (int c = 0; c < MAX_CHANNELS; c++) {
if (channels[c].audio_in) { if (channels[c].audio_in) {
@@ -142,14 +85,78 @@ void looper_shutdown(jack_client_t *client) {
jack_client_close(client); jack_client_close(client);
log_close(); log_close();
} }
volatile int looper_quit = 0; volatile int looper_quit = 0;
/* Signal handler: set quit flag only */
static void signal_handler(int sig) { static void signal_handler(int sig) {
(void)sig; (void)sig;
looper_quit = 1; looper_quit = 1;
} }
static void looper_write_status(void) {
if (status_fd < 0)
return;
char buf[4096];
int pos = 0;
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
if (!atomic_load(&channels[ch].active))
continue;
int sc_idx = atomic_load(&channels[ch].current_scene);
int state = atomic_load(&channels[ch].scenes[sc_idx].state);
int prev = atomic_load(&prev_state[ch][sc_idx]);
const char *state_str;
switch (state) {
case STATE_IDLE:
state_str = "IDLE";
break;
case STATE_RECORD:
state_str = "RECORD";
break;
case STATE_LOOPING:
state_str = "LOOPING";
break;
case STATE_PAUSED:
state_str = "PAUSED";
break;
default:
state_str = "UNKNOWN";
}
/* Always write state line to guarantee level line is sent even if state
* unchanged */
int n = snprintf(buf + pos, sizeof(buf) - pos, "CH=%d SC=%d STATE=%s\n", ch,
sc_idx, state_str);
if (n > 0)
pos += n;
if (pos >= (int)sizeof(buf) - 128)
break;
/* Write RMS level line every time (no change detection) */
{
float level = atomic_load(&channels[ch].rms_level);
int n2 =
snprintf(buf + pos, sizeof(buf) - pos, "CH=%d LEVEL=%f\n", ch, level);
if (n2 > 0)
pos += n2;
if (pos >= (int)sizeof(buf) - 128)
break;
}
atomic_store(&prev_state[ch][sc_idx], state);
}
if (pos > 0) {
int ret = write(status_fd, buf, pos);
(void)ret;
}
}
/* Deferred removal index (1 second grace) */
static int pending_unregister_idx = -1; static int pending_unregister_idx = -1;
/* sample rate holder */
static int global_sample_rate = 0;
/* execute a single command (called from looper_process_commands) */ /* execute a single command (called from looper_process_commands) */
static void exec_command(command_t cmd, jack_client_t *client) { static void exec_command(command_t cmd, jack_client_t *client) {
int ch = cmd.channel; int ch = cmd.channel;
@@ -279,24 +286,6 @@ static void exec_command(command_t cmd, jack_client_t *client) {
break; break;
} }
case CMD_DELETE: {
int dch = cmd.channel;
if (dch >= 0 && dch < MAX_CHANNELS) {
int dsc_idx = atomic_load(&channels[dch].current_scene);
scene_t *dsc = &channels[dch].scenes[dsc_idx];
// Reset state to IDLE
atomic_store(&dsc->state, STATE_IDLE);
atomic_store(&dsc->prev_state, -1);
// Clear loop data
atomic_store(&dsc->loop_count, 0);
atomic_store(&dsc->record_pos, 0);
atomic_store(&dsc->playback_pos, 0);
// Zero the audio buffer
memset(dsc->loop.audio_buffer, 0, sizeof(dsc->loop.audio_buffer));
}
break;
}
default: default:
break; break;
} }

View File

@@ -3,7 +3,6 @@
#include "queue.h" #include "queue.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <jack/jack.h>
#include <pthread.h> #include <pthread.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -11,6 +10,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <jack/jack.h>
extern jack_client_t *global_client; extern jack_client_t *global_client;
@@ -101,22 +101,13 @@ static void *pipe_thread_func(void *arg) {
} else if (strcmp(line, "save") == 0) { } else if (strcmp(line, "save") == 0) {
command_t cmd = {.type = CMD_SAVE, .channel = -1, .data = 0}; command_t cmd = {.type = CMD_SAVE, .channel = -1, .data = 0};
queue_push(&cmd_queue_main_fifo, cmd); queue_push(&cmd_queue_main_fifo, cmd);
} else if (strncmp(line, "delete", 6) == 0) {
int ch = -1;
const char *arg = line + 6;
while (*arg == ' ') arg++;
if (*arg) ch = atoi(arg);
fprintf(stderr, "FIFO RECEIVED delete\n");
command_t cmd = {.type = CMD_DELETE, .channel = ch, .data = 0};
queue_push(&cmd_queue_main_fifo, cmd);
} else if (strncmp(line, "from ", 5) == 0) { } else if (strncmp(line, "from ", 5) == 0) {
const char *port = line + 5; const char *port = line + 5;
fprintf(stderr, "FIFO RECEIVED from: %s\n", port); fprintf(stderr, "FIFO RECEIVED from: %s\n", port);
if (global_client) { if (global_client) {
int ret = jack_connect(global_client, port, "looper:ch0in"); int ret = jack_connect(global_client, port, "looper:ch0in");
if (ret != 0) if (ret != 0)
fprintf(stderr, "Failed to connect %s -> looper:ch0in (ret=%d)\n", fprintf(stderr, "Failed to connect %s -> looper:ch0in (ret=%d)\n", port, ret);
port, ret);
} }
} else if (strncmp(line, "to ", 3) == 0) { } else if (strncmp(line, "to ", 3) == 0) {
const char *port = line + 3; const char *port = line + 3;
@@ -124,8 +115,7 @@ static void *pipe_thread_func(void *arg) {
if (global_client) { if (global_client) {
int ret = jack_connect(global_client, "looper:ch0out", port); int ret = jack_connect(global_client, "looper:ch0out", port);
if (ret != 0) if (ret != 0)
fprintf(stderr, "Failed to connect looper:ch0out -> %s (ret=%d)\n", fprintf(stderr, "Failed to connect looper:ch0out -> %s (ret=%d)\n", port, ret);
port, ret);
} }
} }
/* ignore unknown lines */ /* ignore unknown lines */