fix: correct dispatcher_get_state call and fix undefined behavior in gui.c
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
43
gui.c
43
gui.c
@@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <jack/jack.h>
|
#include <jack/jack.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -94,21 +95,29 @@ static void gui_update(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mu_button(ctx, "Reset")) {
|
if (mu_button(ctx, "Reset")) {
|
||||||
|
Action action = { .type = ACTION_RESET_TRANSPORT };
|
||||||
|
g_engine->dispatch(action);
|
||||||
current_beat = 0;
|
current_beat = 0;
|
||||||
}
|
}
|
||||||
if (mu_button(ctx, "Quit")) {
|
if (mu_button(ctx, "Quit")) {
|
||||||
|
Action action = { .type = ACTION_QUIT };
|
||||||
|
g_engine->dispatch(action);
|
||||||
running = 0;
|
running = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BPM slider */
|
/* BPM slider */
|
||||||
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
||||||
mu_label(ctx, "BPM:");
|
mu_label(ctx, "BPM:");
|
||||||
mu_slider_ex(ctx, &bpm, 20.0f, 300.0f, 0, "%.0f", 0);
|
mu_slider_ex(ctx, &bpm, 20.0f, 300.0f, 0, "%.0f", MU_OPT_ALIGNCENTER);
|
||||||
|
|
||||||
/* loop length */
|
/* loop length */
|
||||||
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
||||||
mu_label(ctx, "Length:");
|
mu_label(ctx, "Length:");
|
||||||
mu_slider_ex(ctx, (float*)&loop_length, 1.0f, 64.0f, 0, "%.0f", 0);
|
{
|
||||||
|
float loop_length_f = (float)loop_length;
|
||||||
|
mu_slider_ex(ctx, &loop_length_f, 1.0f, 64.0f, 0, "%.0f", 0);
|
||||||
|
loop_length = (int)loop_length_f;
|
||||||
|
}
|
||||||
|
|
||||||
/* beat indicator */
|
/* beat indicator */
|
||||||
mu_layout_row(ctx, 1, (int[]) { -1 }, 0);
|
mu_layout_row(ctx, 1, (int[]) { -1 }, 0);
|
||||||
@@ -123,7 +132,8 @@ static void gui_update(void)
|
|||||||
{
|
{
|
||||||
float progress = (loop_length > 0) ? (float)current_beat / (float)loop_length : 0.0f;
|
float progress = (loop_length > 0) ? (float)current_beat / (float)loop_length : 0.0f;
|
||||||
mu_Rect r = mu_layout_next(ctx);
|
mu_Rect r = mu_layout_next(ctx);
|
||||||
mu_draw_control_frame(ctx, mu_get_id(ctx, &progress, sizeof(progress)), r, MU_COLOR_BASE, 0);
|
mu_Id prog_id = mu_get_id(ctx, &progress, sizeof(progress));
|
||||||
|
mu_draw_control_frame(ctx, prog_id, r, MU_COLOR_BASE, 0);
|
||||||
if (progress > 0.0f) {
|
if (progress > 0.0f) {
|
||||||
mu_Rect fill = r;
|
mu_Rect fill = r;
|
||||||
fill.w = (int)(r.w * progress);
|
fill.w = (int)(r.w * progress);
|
||||||
@@ -162,6 +172,8 @@ static void gui_update(void)
|
|||||||
mu_label(ctx, "Level:");
|
mu_label(ctx, "Level:");
|
||||||
if (mu_button(ctx, zoom_labels[zoom_level])) {
|
if (mu_button(ctx, zoom_labels[zoom_level])) {
|
||||||
zoom_level = (zoom_level + 1) % 3;
|
zoom_level = (zoom_level + 1) % 3;
|
||||||
|
zoom_focus_scene = 0;
|
||||||
|
zoom_focus_channel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
||||||
@@ -169,9 +181,7 @@ static void gui_update(void)
|
|||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
snprintf(buf, sizeof(buf), "%d", zoom_focus_scene + 1);
|
snprintf(buf, sizeof(buf), "%d", zoom_focus_scene + 1);
|
||||||
if (mu_button(ctx, buf)) {
|
mu_label(ctx, buf);
|
||||||
/* click to reset? no action needed */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
||||||
@@ -179,9 +189,7 @@ static void gui_update(void)
|
|||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
snprintf(buf, sizeof(buf), "%d", zoom_focus_channel + 1);
|
snprintf(buf, sizeof(buf), "%d", zoom_focus_channel + 1);
|
||||||
if (mu_button(ctx, buf)) {
|
mu_label(ctx, buf);
|
||||||
/* click to reset? no action needed */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Navigation hint */
|
/* Navigation hint */
|
||||||
@@ -204,7 +212,12 @@ static void gui_update(void)
|
|||||||
mu_layout_row(ctx, 1, (int[]) { -1 }, 0);
|
mu_layout_row(ctx, 1, (int[]) { -1 }, 0);
|
||||||
if (mu_button(ctx, "Add Plugin")) {
|
if (mu_button(ctx, "Add Plugin")) {
|
||||||
if (plugin_uri_input_len > 0) {
|
if (plugin_uri_input_len > 0) {
|
||||||
carla_add_plugin(&g_engine->carla_host, selected_channel, plugin_uri_input, PLUGIN_TYPE_INTERNAL);
|
Action action = { .type = ACTION_RACK_ADD_PLUGIN };
|
||||||
|
action.data.rack_add_plugin.channel = selected_channel;
|
||||||
|
strncpy(action.data.rack_add_plugin.uri, plugin_uri_input, sizeof(action.data.rack_add_plugin.uri) - 1);
|
||||||
|
action.data.rack_add_plugin.uri[sizeof(action.data.rack_add_plugin.uri) - 1] = '\0';
|
||||||
|
action.data.rack_add_plugin.type = PLUGIN_TYPE_INTERNAL;
|
||||||
|
g_engine->dispatch(action);
|
||||||
plugin_uri_input_len = 0;
|
plugin_uri_input_len = 0;
|
||||||
plugin_uri_input[0] = '\0';
|
plugin_uri_input[0] = '\0';
|
||||||
}
|
}
|
||||||
@@ -257,7 +270,12 @@ int gui_main(Engine *engine)
|
|||||||
} else if (ch == '\n' || ch == '\r') {
|
} else if (ch == '\n' || ch == '\r') {
|
||||||
/* Submit plugin URI */
|
/* Submit plugin URI */
|
||||||
if (plugin_uri_input_len > 0) {
|
if (plugin_uri_input_len > 0) {
|
||||||
carla_add_plugin(&g_engine->carla_host, selected_channel, plugin_uri_input, PLUGIN_TYPE_INTERNAL);
|
Action action = { .type = ACTION_RACK_ADD_PLUGIN };
|
||||||
|
action.data.rack_add_plugin.channel = selected_channel;
|
||||||
|
strncpy(action.data.rack_add_plugin.uri, plugin_uri_input, sizeof(action.data.rack_add_plugin.uri) - 1);
|
||||||
|
action.data.rack_add_plugin.uri[sizeof(action.data.rack_add_plugin.uri) - 1] = '\0';
|
||||||
|
action.data.rack_add_plugin.type = PLUGIN_TYPE_INTERNAL;
|
||||||
|
g_engine->dispatch(action);
|
||||||
plugin_uri_input_len = 0;
|
plugin_uri_input_len = 0;
|
||||||
plugin_uri_input[0] = '\0';
|
plugin_uri_input[0] = '\0';
|
||||||
}
|
}
|
||||||
@@ -323,7 +341,8 @@ int gui_main(Engine *engine)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* update engine state */
|
/* update engine state */
|
||||||
AppState state = dispatcher_get_state();
|
AppState state;
|
||||||
|
dispatcher_get_state(&state);
|
||||||
current_beat = state.bar_position * 4 + state.beat_position;
|
current_beat = state.bar_position * 4 + state.beat_position;
|
||||||
|
|
||||||
/* render GUI */
|
/* render GUI */
|
||||||
|
|||||||
Reference in New Issue
Block a user