Commit Graph

39 Commits

Author SHA1 Message Date
Loic Coenen
b10d218749 fix: reconnect MIDI client before each test to avoid stale connections
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-12 18:19:06 +00:00
Loic Coenen
346c15d1c3 fix: use persistent MIDI client and fix save_ring race condition
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-11 22:14:33 +00:00
Loic Coenen
7deea9266b fix: reorder passthrough setup before load command in WAV load test
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-11 21:49:35 +00:00
Loic Coenen
7d842163a2 fix: increase listen duration and add RMS logging in WAV load test
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-11 21:39:49 +00:00
Loic Coenen
54fa307360 fix: increase sleep durations in WAV load test to prevent false failure
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-11 21:31:29 +00:00
Loic Coenen
6b490ed739 feat: add WAV file loading, saving, and dedicated I/O threads
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-11 20:58:00 +00:00
Loic Coenen
20c0820910 refactor: use explicit pointer casts to clarify type conversions
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-09 14:46:09 +00:00
Loic Coenen
2fa1d159e7 refactor: remove global cppcheck suppressions and move usleep suppression locally
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-09 13:20:37 +00:00
Loic Coenen
982dd4dc02 refactor: replace usleep with safe_usleep in integration tests 2026-05-09 13:20:36 +00:00
Loic Coenen
aa0b191b46 makefile
```makefile
<<<<<<< SEARCH
check:
	cppcheck --enable=all --error-exitcode=1 --suppress=missingIncludeSystem --suppress=usleepCalled --suppress=unreadVariable --suppress=normalCheckLevelMaxBranches src/*.c --library=posix .
=======
check:
	cppcheck --enable=all --error-exitcode=1 --suppress=unreadVariable src/*.c --library=posix .
>>>>>>> REPLACE
```

src/channel.c
```c
<<<<<<< SEARCH
#include "channel.h"
#include <jack/jack.h>
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
=======
// cppcheck-suppress missingIncludeSystem
#include "channel.h"
#include <jack/jack.h>
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
>>>>>>> REPLACE
```

src/channel.h
```c
<<<<<<< SEARCH
#include <jack/jack.h>
#include <stdatomic.h>
=======
// cppcheck-suppress missingIncludeSystem
#include <jack/jack.h>
#include <stdatomic.h>
>>>>>>> REPLACE
```

src/looper.c
```c
<<<<<<< SEARCH
#include "looper.h"
#include "channel.h"
#include "midi.h"
#include <jack/jack.h>
#include <jack/midiport.h>
#include <math.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
=======
// cppcheck-suppress missingIncludeSystem
#include "looper.h"
#include "channel.h"
#include "midi.h"
#include <jack/jack.h>
#include <jack/midiport.h>
#include <math.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
>>>>>>> REPLACE
```

src/looper.h
```c
<<<<<<< SEARCH
#include <jack/jack.h>
=======
// cppcheck-suppress missingIncludeSystem
#include <jack/jack.h>
>>>>>>> REPLACE
```

src/main.c
```c
<<<<<<< SEARCH
#include "looper.h"
#include <jack/jack.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
=======
// cppcheck-suppress missingIncludeSystem
#include "looper.h"
#include <jack/jack.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
>>>>>>> REPLACE
```

src/midi.c
```c
<<<<<<< SEARCH
#include "midi.h"
#include "channel.h"
#include <jack/jack.h>
#include <jack/midiport.h>
#include <stdatomic.h>
=======
// cppcheck-suppress missingIncludeSystem
#include "midi.h"
#include "channel.h"
#include <jack/jack.h>
#include <jack/midiport.h>
#include <stdatomic.h>
>>>>>>> REPLACE
```

src/midi.h
```c
<<<<<<< SEARCH
#include <jack/types.h>
=======
// cppcheck-suppress missingIncludeSystem
#include <jack/types.h>
>>>>>>> REPLACE
```

tests/integration.c
```c
<<<<<<< SEARCH
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <jack/jack.h>
#include <jack/midiport.h>
#include <math.h>
#include <time.h>
=======
// cppcheck-suppress missingIncludeSystem
// cppcheck-suppress usleepCalled
// cppcheck-suppress normalCheckLevelMaxBranches
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <jack/jack.h>
#include <jack/midiport.h>
#include <math.h>
#include <time.h>
>>>>>>> REPLACE
```

Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-09 12:46:50 +00:00
Loic Coenen
e8d679c1af fix: replace usleep with safe_usleep in integration tests
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-09 11:45:32 +00:00
Loic Coenen
e7761c4b53 fix: replace usleep with nanosleep and fix const correctness in tests
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-09 11:44:06 +00:00
Loic Coenen
60a8bdcfe8 feat: add unbind command (note 63) to reset bind_channel to 0
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-09 11:14:52 +00:00
Loic Coenen
4bacab68c6 feat: implement bind feature for associating channels with MIDI notes
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-09 10:22:33 +00:00
Loic Coenen
740ebaa969 test: add integration tests for control-key modifier and channel removal
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-09 10:09:51 +00:00
Loic Coenen
c0a0a6e968 fix: add null-checks for MIDI ports and use atomic access for channel active flag
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-09 09:57:36 +00:00
Loic Coenen
f1a92f1e95 fix: increase sleep duration in dynamic channel test to allow processing
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-08 20:56:56 +00:00
Loic Coenen
e824f6df73 feat: add test for dynamic channel creation via MIDI command
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-08 20:03:49 +00:00
Loic Coenen
3e291a9b58 fix: initialize passthrough globals in test_looper_looping
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 22:28:53 +00:00
Loic Coenen
65c346d14d fix: increase timing margins in integration test to ensure MIDI events are delivered
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 22:27:00 +00:00
Loic Coenen
74b68eb378 fix: enable continuous sine tone in audio pass-through test
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 22:20:31 +00:00
Loic Coenen
150b01d3be tests/integration.c
```c
<<<<<<< SEARCH
static volatile int passthrough_done = 0;
static volatile int beep_remaining = 0;
static volatile int bursts = 0;
static volatile int prev_above = 0;
=======
static volatile int passthrough_done = 0;
static volatile int beep_remaining = 0;
static volatile int bursts = 0;
static volatile int prev_above = 0;

/* variables for MIDI injection (used by send_jack_note_on) */
static volatile int midi_inject_pending = 0;
static jack_port_t *midi_inject_port = NULL;
static jack_client_t *midi_inject_client = NULL;
static unsigned char midi_inject_note = 0;
static unsigned char midi_inject_velocity = 0;

static int midi_inject_process(jack_nframes_t nframes, void *arg) {
    (void)arg;
    void *port_buf = jack_port_get_buffer(midi_inject_port, nframes);
    if (!port_buf) return 0;
    jack_midi_clear_buffer(port_buf);
    if (!midi_inject_pending) return 0;
    jack_midi_data_t *buf = jack_midi_event_reserve(port_buf, 0, 3);
    if (!buf) return 0;
    buf[0] = 0x90;
    buf[1] = midi_inject_note;
    buf[2] = midi_inject_velocity;
    midi_inject_pending = 0;
    return 0;
}
>>>>>>> REPLACE
```

tests/integration.c
```c
<<<<<<< SEARCH
/* Helper: open a transient JACK client, send a MIDI note‑on, close */
static int send_jack_note_on(const char *target_port, unsigned char note, unsigned char velocity) {
    /* The correct JACK API requires writing events inside a process callback.
       For now we stub this function; the test will skip the MIDI transition
       tests and the pass‑through test suffices. */
    (void)target_port;
    (void)note;
    (void)velocity;
    return 0;
}
=======
/* Helper: open a transient JACK client, send a MIDI note‑on, close */
static int send_jack_note_on(const char *target_port, unsigned char note, unsigned char velocity) {
    midi_inject_note = note;
    midi_inject_velocity = velocity;

    jack_status_t st;
    midi_inject_client = jack_client_open("test_midi_inject", JackNoStartServer, &st);
    if (!midi_inject_client) return -1;

    midi_inject_port = jack_port_register(midi_inject_client, "out",
                                          JACK_DEFAULT_MIDI_TYPE,
                                          JackPortIsOutput, 0);
    if (!midi_inject_port) {
        jack_client_close(midi_inject_client);
        midi_inject_client = NULL;
        return -1;
    }
    char src[64];
    snprintf(src, sizeof(src), "test_midi_inject:out");
    if (jack_connect(midi_inject_client, src, target_port) != 0) {
        jack_client_close(midi_inject_client);
        midi_inject_client = NULL;
        midi_inject_port = NULL;
        return -1;
    }
    jack_set_process_callback(midi_inject_client, midi_inject_process, NULL);
    if (jack_activate(midi_inject_client) != 0) {
        jack_client_close(midi_inject_client);
        midi_inject_client = NULL;
        midi_inject_port = NULL;
        return -1;
    }
    midi_inject_pending = 1;
    /* wait for one process cycle to deliver the event */
    usleep(200000);
    jack_deactivate(midi_inject_client);
    jack_client_close(midi_inject_client);
    midi_inject_client = NULL;
    midi_inject_port = NULL;
    return 0;
}
>>>>>>> REPLACE
```

tests/integration.c
```c
<<<<<<< SEARCH
/*
 * Full loop recording test (stub – the MIDI API is non‑trivial without external tools,
 * so we skip the actual instrumentation and just verify the looper doesn't crash).
 */
static int test_looper_looping(void) {
    printf("Test: loop recording and playback (skip – no external MIDI tool)\n");
    printf("  SUCCESS: nothing was measured (stub)\n");
    return 0;
}
=======
/*
 * Full loop recording test:
 *  1. start looper
 *  2. open JACK test client (audio)
 *  3. send note‑on to move IDLE->RECORD
 *  4. generate a short 440 Hz beep (~0.1 s) while recording
 *  5. send note‑on to move RECORD->LOOPING
 *  6. monitor looper output for the beep being repeated (≥3 times)
 */
static int test_looper_looping(void) {
    printf("Test: loop recording and playback (expect ≥3 repetitions)\n");

    pid_t pid = start_looper();
    if (pid < 0) return 1;

    jack_client_t *client;
    jack_status_t status;
    client = jack_client_open("test_looping", JackNoStartServer, &status);
    if (!client) {
        kill(pid, SIGTERM); waitpid(pid, NULL, 0);
        fprintf(stderr, "  SKIP: JACK not running?\n");
        return 1;
    }
    jack_port_t *audio_out = jack_port_register(client, "out",
                           JACK_DEFAULT_AUDIO_TYPE,
                           JackPortIsOutput, 0);
    jack_port_t *audio_in = jack_port_register(client, "in",
                           JACK_DEFAULT_AUDIO_TYPE,
                           JackPortIsInput, 0);
    if (!audio_out || !audio_in) {
        jack_client_close(client);
        kill(pid, SIGTERM); waitpid(pid, NULL, 0);
        return 1;
    }
    usleep(200000);               /* wait for ports to appear */
    /* connect test:out -> looper:input, looper:output -> test:in */
    char my_out[64], my_in[64];
    snprintf(my_out, sizeof(my_out), "test_looping:out");
    snprintf(my_in,  sizeof(my_in),  "test_looping:in");
    if (jack_connect(client, my_out, "looper:input") ||
        jack_connect(client, "looper:output", my_in)) {
        jack_client_close(client);
        kill(pid, SIGTERM); waitpid(pid, NULL, 0);
        return 1;
    }

    /* first note‑on: IDLE -> RECORD */
    if (send_jack_note_on("looper:control", 1, 127) != 0) {
        jack_client_close(client);
        kill(pid, SIGTERM); waitpid(pid, NULL, 0);
        return 1;
    }
    usleep(200000);               /* allow state to change */

    int sr = jack_get_sample_rate(client);
    beep_remaining = (int)(0.1f * sr);   /* 0.1 second beep */
    bursts = 0;
    prev_above = 0;

    jack_set_process_callback(client, passthrough_process, NULL);
    if (jack_activate(client)) {
        jack_client_close(client);
        kill(pid, SIGTERM); waitpid(pid, NULL, 0);
        return 1;
    }

    usleep(150000);               /* let beep start */

    /* after beep finishes, give it a moment then send note‑on to stop recording */
    usleep(500000);
    beep_remaining = 0;

    if (send_jack_note_on("looper:control", 1, 127) != 0) {
        jack_client_close(client);
        kill(pid, SIGTERM); waitpid(pid, NULL, 0);
        return 1;
    }

    /* wait enough time for several loops (3 seconds) */
    usleep(3000000);

    jack_deactivate(client);
    jack_client_close(client);

    kill(pid, SIGTERM);
    waitpid(pid, NULL, 0);

    int got_bursts = bursts;
    printf("  detected bursts: %d\n", got_bursts);
    if (got_bursts < 3) {
        fprintf(stderr, "  FAIL: expected ≥3 bursts, got %d\n", got_bursts);
        return 1;
    }
    printf("  PASS (at least 3 repetitions)\n");
    return 0;
}
>>>>>>> REPLACE
```

Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:56:12 +00:00
Loic Coenen
5a90446456 fix: stub MIDI-dependent tests to fix build errors
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:45:34 +00:00
Loic Coenen
3761851871 refactor: remove unused MIDI state transition test functions
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:44:02 +00:00
Loic Coenen
99c4e033f0 refactor: remove extern declarations and unused test function
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:42:48 +00:00
Loic Coenen
d4b3c2334b feat: implement loop recording and playback with integration test
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:41:36 +00:00
Loic Coenen
944608ad7f fix: start and clean up looper process in audio pass-through test
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:31:51 +00:00
Loic Coenen
cb58207904 refactor: remove external MIDI tool dependency from integration tests
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:26:07 +00:00
Loic Coenen
4b9ee29d8e feat: add JACK passthrough test with sine generation and RMS validation
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:17:11 +00:00
Loic Coenen
a8616e4ca3 refactor: remove external tool dependencies from integration tests
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:14:34 +00:00
Loic Coenen
ce6061c7f2 test: gracefully skip MIDI tests when jack_midi_send is missing
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:06:57 +00:00
Loic Coenen
c4f45c956a test: add integration test for missing looper feature
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 21:01:15 +00:00
Loic Coenen
3d9f2af9b3 test: add audio pass-through test with RMS validation
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 20:55:21 +00:00
Loic Coenen
f0b58a9684 test: add automated state verification to integration tests
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 20:47:39 +00:00
Loic Coenen
2d4f4ec18e fix: add missing stdarg.h include and jack_midi_send availability check
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 20:35:52 +00:00
Loic Coenen
484e0cad36 fix: add fork failure check in integration test
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 20:31:13 +00:00
Loic Coenen
bbf560efe2 test: implement full integration test for JACK looper state machine
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 20:30:01 +00:00
Loic Coenen
3f6766ce03 feat: add integration test for looper binary
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
2026-05-07 20:09:33 +00:00
Loic Coenen
73bf0b50e8 feat: add integration test file 2026-05-07 20:09:32 +00:00