Skip to content

Commit

Permalink
Make channel Controls atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
brummer10 committed Mar 21, 2024
1 parent bab1f95 commit c0f49c8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 37 deletions.
51 changes: 17 additions & 34 deletions src/MidiKeyBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3533,7 +3533,7 @@ void XKeyBoard::show_looper_ui(int present) {
int y = main_y-71;
if (main_y < 75) y = main_y + main_h+21;
XMoveWindow(win->app->dpy,looper_control->widget, main_x+650, y);
}else {
} else {
widget_hide(looper_control);
}
}
Expand All @@ -3551,143 +3551,127 @@ static void play_channel1_callback(void *w_, void* user_data) noexcept{
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[0] = i;

xjmkb->xjack->channel_matrix[0].store(i, std::memory_order_release);
}

static void play_channel2_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[1] = i;

xjmkb->xjack->channel_matrix[1].store(i, std::memory_order_release);
}

static void play_channel3_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[2] = i;

xjmkb->xjack->channel_matrix[2].store(i, std::memory_order_release);
}

static void play_channel4_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[3] = i;

xjmkb->xjack->channel_matrix[3].store(i, std::memory_order_release);
}

static void play_channel5_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[4] = i;

xjmkb->xjack->channel_matrix[4].store(i, std::memory_order_release);
}

static void play_channel6_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[5] = i;

xjmkb->xjack->channel_matrix[5].store(i, std::memory_order_release);
}

static void play_channel7_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[6] = i;

xjmkb->xjack->channel_matrix[6].store(i, std::memory_order_release);
}

static void play_channel8_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[7] = i;

xjmkb->xjack->channel_matrix[7].store(i, std::memory_order_release);
}

static void play_channel9_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[8] = i;

xjmkb->xjack->channel_matrix[8].store(i, std::memory_order_release);
}

static void play_channel10_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[9] = i;

xjmkb->xjack->channel_matrix[9].store(i, std::memory_order_release);
}

static void play_channel11_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[10] = i;

xjmkb->xjack->channel_matrix[10].store(i, std::memory_order_release);
}

static void play_channel12_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[11] = i;

xjmkb->xjack->channel_matrix[11].store(i, std::memory_order_release);
}

static void play_channel13_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[12] = i;

xjmkb->xjack->channel_matrix[12].store(i, std::memory_order_release);
}

static void play_channel14_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[13] = i;

xjmkb->xjack->channel_matrix[13].store(i, std::memory_order_release);
}

static void play_channel15_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[14] = i;

xjmkb->xjack->channel_matrix[14].store(i, std::memory_order_release);
}

static void play_channel16_callback(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
Widget_t *win = get_toplevel_widget(w->app);
XKeyBoard *xjmkb = (XKeyBoard*) win->parent_struct;
int i = (int)adj_get_value(w->adj);
xjmkb->xjack->channel_matrix[15] = i;

xjmkb->xjack->channel_matrix[15].store(i, std::memory_order_release);
}

void XKeyBoard::init_looper_ui(Widget_t *parent) {
Expand All @@ -3696,7 +3680,6 @@ void XKeyBoard::init_looper_ui(Widget_t *parent) {
|EnterWindowMask|LeaveWindowMask|ButtonReleaseMask|KeyReleaseMask
|ButtonPressMask|Button1MotionMask|PointerMotionMask);
XSetTransientForHint(parent->app->dpy, looper_control->widget, parent->widget);
soundfontname = basename((char*)soundfont.c_str());
std::string title = _("Looper Channel Control ");
widget_set_title(looper_control, title.c_str());
looper_control->flags &= ~USE_TRANSPARENCY;
Expand Down
6 changes: 4 additions & 2 deletions src/XJack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ XJack::XJack(mamba::MidiMessenger *mmessage_,
for ( int i = 0; i < 16; i++) posPlay[i] = 0;
for ( int i = 0; i < 16; i++) startPlay[i] = 0;
for ( int i = 0; i < 16; i++) stopPlay[i] = 0;
for ( int i = 0; i < 16; i++) channel_matrix[i] = 0;
for ( int i = 0; i < 16; i++) channel_matrix[i].store(0, std::memory_order_release);
}

XJack::~XJack() {
Expand Down Expand Up @@ -271,7 +271,9 @@ inline void XJack::play_midi(void *buf, unsigned int n) {
const mamba::MidiEvent ev = rec.play[i][posPlay[i]];
if (deltaTime >= ev.deltaTime * bpm_ratio) {
playPosTime = ev.absoluteTime;
if (!channel_matrix[int(ev.buffer[0]&0x0f)] || ((ev.buffer[0] & 0xf0) == 0x80 )) {
// check if channel is muted
if (!channel_matrix[int(ev.buffer[0]&0x0f)].load(std::memory_order_acquire) ||
((ev.buffer[0] & 0xf0) == 0x80 )) {
unsigned char* midi_send = jack_midi_event_reserve(buf, n, ev.num);
if (midi_send) {
midi_send[0] = ev.buffer[0];
Expand Down
2 changes: 1 addition & 1 deletion src/XJack.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class XJack : public sigc::trackable {
std::atomic<bool> bpm_changed;
std::atomic<int> bpm_set;
std::atomic<bool> record_off;
std::atomic<int> channel_matrix[16];
jack_client_t *client;
jack_port_t *in_port;
jack_port_t *out_port;
Expand Down Expand Up @@ -150,7 +151,6 @@ class XJack : public sigc::trackable {
unsigned int bpm;
float max_loop_time;
int midi_map;
unsigned int channel_matrix[16];

float get_max_loop_time() noexcept;
sigc::signal<void > trigger_quit_by_jack;
Expand Down

0 comments on commit c0f49c8

Please sign in to comment.