74 lines
2.3 KiB
C
74 lines
2.3 KiB
C
// cppcheck-suppress missingIncludeSystem
|
|
#include "channel.h"
|
|
#include <jack/jack.h>
|
|
#include <stdatomic.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
void channel_add(jack_client_t *client, int idx) {
|
|
struct channel_t *cur = get_channels_array();
|
|
|
|
char in_name[64], out_name[64];
|
|
snprintf(in_name, sizeof(in_name), "channel%d_input", next_channel_id);
|
|
snprintf(out_name, sizeof(out_name), "channel%d_output", next_channel_id);
|
|
|
|
cur[idx].audio_in = jack_port_register(
|
|
client, in_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
|
|
cur[idx].audio_out = jack_port_register(
|
|
client, out_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
|
|
if (!cur[idx].audio_in || !cur[idx].audio_out) {
|
|
fprintf(stderr, "Failed to register ports for channel %d\n",
|
|
next_channel_id);
|
|
atomic_store(&cur[idx].active, 0);
|
|
return;
|
|
}
|
|
|
|
atomic_store(&cur[idx].active, 1);
|
|
atomic_store(&cur[idx].state, STATE_IDLE);
|
|
cur[idx].prev_state = -1;
|
|
cur[idx].loop_count = 0;
|
|
cur[idx].record_pos = 0;
|
|
cur[idx].playback_pos = 0;
|
|
cur[idx].type = CHANNEL_AUDIO;
|
|
|
|
next_channel_id++;
|
|
atomic_fetch_add(&channel_count, 1);
|
|
}
|
|
|
|
void channel_add_midi(jack_client_t *client, int idx) {
|
|
struct channel_t *cur = get_channels_array();
|
|
|
|
char in_name[64], out_name[64];
|
|
snprintf(in_name, sizeof(in_name), "channel%d_midi_in", next_channel_id);
|
|
snprintf(out_name, sizeof(out_name), "channel%d_midi_out", next_channel_id);
|
|
|
|
cur[idx].midi_in = jack_port_register(client, in_name, JACK_DEFAULT_MIDI_TYPE,
|
|
JackPortIsInput, 0);
|
|
cur[idx].midi_out = jack_port_register(
|
|
client, out_name, JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
|
|
if (!cur[idx].midi_in || !cur[idx].midi_out) {
|
|
fprintf(stderr, "Failed to register MIDI ports for channel %d\n",
|
|
next_channel_id);
|
|
atomic_store(&cur[idx].active, 0);
|
|
return;
|
|
}
|
|
|
|
atomic_store(&cur[idx].active, 1);
|
|
atomic_store(&cur[idx].state, STATE_IDLE);
|
|
cur[idx].prev_state = -1;
|
|
cur[idx].loop_count = 0;
|
|
cur[idx].record_pos = 0;
|
|
cur[idx].playback_pos = 0;
|
|
cur[idx].type = CHANNEL_MIDI;
|
|
|
|
next_channel_id++;
|
|
atomic_fetch_add(&channel_count, 1);
|
|
}
|
|
|
|
void channel_remove(jack_client_t *client, int idx) {
|
|
(void)client;
|
|
struct channel_t *cur = get_channels_array();
|
|
atomic_store(&cur[idx].active, 0);
|
|
atomic_fetch_sub(&channel_count, 1);
|
|
}
|