From 5d123f21ddd9eccbb61dbfd53f6707ab474d2d2b Mon Sep 17 00:00:00 2001 From: DL1YCF Date: Thu, 13 May 2021 15:13:42 +0200 Subject: [PATCH] Finalized MIDI GUI --- midi2.c | 16 ++-- midi_menu.c | 232 +++++++++++++++++++++++++++------------------------- 2 files changed, 129 insertions(+), 119 deletions(-) diff --git a/midi2.c b/midi2.c index 2c09d8b..9924e2e 100644 --- a/midi2.c +++ b/midi2.c @@ -152,11 +152,11 @@ ACTION_TABLE ActionTable[] = { { MIDI_ACTION_BAND_80, "BAND80", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_BAND_902, "BAND902", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_BAND_AIR, "BANDAIR", MIDI_TYPE_KEY, 0}, - { MIDI_ACTION_BAND_DOWN, "BANDDOWN", MIDI_TYPE_KEY|MIDI_TYPE_WHEEL, 0}, + { MIDI_ACTION_BAND_DOWN, "BANDDOWN", MIDI_TYPE_KEY|MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_BAND_GEN, "BANDGEN", MIDI_TYPE_KEY, 0}, - { MIDI_ACTION_BAND_UP, "BANDUP", MIDI_TYPE_KEY|MIDI_TYPE_WHEEL, 0}, + { MIDI_ACTION_BAND_UP, "BANDUP", MIDI_TYPE_KEY|MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_BAND_WWV, "BANDWWV", MIDI_TYPE_KEY, 0}, - { MIDI_ACTION_COMPRESS, "COMPRESS", MIDI_TYPE_KEY, 0}, + { MIDI_ACTION_COMPRESS, "COMPRESS", MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_CTUN, "CTUN", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_VFO, "CURRVFO", MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_CWKEYER, "CW(Keyer)", MIDI_TYPE_KEY, 1}, @@ -171,8 +171,8 @@ ACTION_TABLE ActionTable[] = { { MIDI_ACTION_DIV_PHASE, "DIVPHASE", MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_DIV_TOGGLE, "DIVTOGGLE", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_DUP, "DUP", MIDI_TYPE_KEY, 0}, - { MIDI_ACTION_FILTER_DOWN, "FILTERDOWN", MIDI_TYPE_KEY|MIDI_TYPE_WHEEL, 0}, - { MIDI_ACTION_FILTER_UP, "FILTERUP", MIDI_TYPE_KEY|MIDI_TYPE_WHEEL, 0}, + { MIDI_ACTION_FILTER_DOWN, "FILTERDOWN", MIDI_TYPE_KEY|MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, + { MIDI_ACTION_FILTER_UP, "FILTERUP", MIDI_TYPE_KEY|MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_LOCK, "LOCK", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_MEM_RECALL_M0, "RECALLM0", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_MEM_RECALL_M1, "RECALLM1", MIDI_TYPE_KEY, 0}, @@ -182,8 +182,8 @@ ACTION_TABLE ActionTable[] = { { MIDI_ACTION_MENU_FILTER, "MENU_FILTER", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_MENU_MODE, "MENU_MODE", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_MIC_VOLUME, "MICGAIN", MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, - { MIDI_ACTION_MODE_DOWN, "MODEDOWN", MIDI_TYPE_KEY|MIDI_TYPE_WHEEL, 0}, - { MIDI_ACTION_MODE_UP, "MODEUP", MIDI_TYPE_KEY|MIDI_TYPE_WHEEL, 0}, + { MIDI_ACTION_MODE_DOWN, "MODEDOWN", MIDI_TYPE_KEY|MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, + { MIDI_ACTION_MODE_UP, "MODEUP", MIDI_TYPE_KEY|MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_MOX, "MOX", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_MUTE, "MUTE", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_NB, "NOISEBLANKER", MIDI_TYPE_KEY, 0}, @@ -209,7 +209,7 @@ ACTION_TABLE ActionTable[] = { { MIDI_ACTION_RF_GAIN, "RFGAIN", MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_TX_DRIVE, "RFPOWER", MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_RIT_CLEAR, "RITCLEAR", MIDI_TYPE_KEY, 0}, - { MIDI_ACTION_RIT_STEP, "RITSTEP", MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, + { MIDI_ACTION_RIT_STEP, "RITSTEP", MIDI_TYPE_KEY|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_RIT_TOGGLE, "RITTOGGLE", MIDI_TYPE_KEY, 0}, { MIDI_ACTION_RIT_VAL, "RITVAL", MIDI_TYPE_KNOB|MIDI_TYPE_WHEEL, 0}, { MIDI_ACTION_SAT, "SAT", MIDI_TYPE_KEY, 0}, diff --git a/midi_menu.c b/midi_menu.c index b0ad128..4cdec09 100644 --- a/midi_menu.c +++ b/midi_menu.c @@ -178,27 +178,25 @@ static void any_cb(GtkWidget *widget, gpointer data) { } static void update_wheelparams(gpointer user_data) { - char text[32]; // - // Task: insert current wheel param values into the text boxes + // Task: show or hide WheelContainer depending on whether + // thre current type is a wheel. If it is a wheel, + // set spin buttons to current values. // - // This is a no-op if the "wheel params" dialog is not open - // If the actual command does not specify a wheel, insert blanks - // if (thisType==MIDI_TYPE_WHEEL) { - sprintf(text,"%d",thisDelay); gtk_entry_set_text(GTK_ENTRY(set_delay), text); - sprintf(text,"%d",thisVfl1 ); gtk_entry_set_text(GTK_ENTRY(set_vfl1 ), text); - sprintf(text,"%d",thisVfl2 ); gtk_entry_set_text(GTK_ENTRY(set_vfl2 ), text); - sprintf(text,"%d",thisFl1 ); gtk_entry_set_text(GTK_ENTRY(set_fl1 ), text); - sprintf(text,"%d",thisFl2 ); gtk_entry_set_text(GTK_ENTRY(set_fl2 ), text); - sprintf(text,"%d",thisLft1 ); gtk_entry_set_text(GTK_ENTRY(set_lft1 ), text); - sprintf(text,"%d",thisLft2 ); gtk_entry_set_text(GTK_ENTRY(set_lft2 ), text); - sprintf(text,"%d",thisRgt1 ); gtk_entry_set_text(GTK_ENTRY(set_rgt1 ), text); - sprintf(text,"%d",thisRgt2 ); gtk_entry_set_text(GTK_ENTRY(set_rgt2 ), text); - sprintf(text,"%d",thisFr1 ); gtk_entry_set_text(GTK_ENTRY(set_fr1 ), text); - sprintf(text,"%d",thisFr2 ); gtk_entry_set_text(GTK_ENTRY(set_fr2 ), text); - sprintf(text,"%d",thisVfr1 ); gtk_entry_set_text(GTK_ENTRY(set_vfr1 ), text); - sprintf(text,"%d",thisVfr2 ); gtk_entry_set_text(GTK_ENTRY(set_vfr2 ), text); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_delay),(double) thisDelay); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_vfl1 ),(double) thisVfl1 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_vfl2 ),(double) thisVfl2 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_fl1 ),(double) thisFl1 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_fl2 ),(double) thisFl2 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_lft1 ),(double) thisLft1 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_lft2 ),(double) thisLft2 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_rgt1 ),(double) thisRgt1 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_rgt2 ),(double) thisRgt2 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_fr1 ),(double) thisFr1 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_fr2 ),(double) thisFr2 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_vfr1 ),(double) thisVfr1 ); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(set_vfr2 ),(double) thisVfr2 ); gtk_widget_show(WheelContainer); } else { gtk_widget_hide(WheelContainer); @@ -350,66 +348,72 @@ static void find_current_cmd() { static void wheelparam_cb(GtkWidget *widget, gpointer user_data) { int what = GPOINTER_TO_INT(user_data); - const gchar *text=gtk_entry_get_text(GTK_ENTRY(widget)); - char newtext[32]; - int val; + int val=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); + int newval=val; + g_print("WHEEL CB what=%d newval=%d\n", what, newval); + if (thisType != MIDI_TYPE_WHEEL) { - sprintf(newtext,"%s",""); - } else { - if (sscanf(text,"%d", &val) != 1) { - val = -1; - } - if (what == 1) { - if (val < 0) val=0; - if (val > 1000) val=1000; - } else { - if (val < -1) val=-1; - if (val > 127) val=127; - } - switch (what) { + // we should never arrive here + return; + } + switch (what) { case 1: // Delay - thisDelay=val; + thisDelay=newval; break; case 2: // Very fast Left 1 - thisVfl1=val; g_print("SET VFL1=%d\n", thisVfl1); + if (newval > thisVfl2) newval=thisVfl2; + thisVfl1=newval; break; case 3: // Very fast Left 2 - thisVfl2=val; + if (newval < thisVfl1) newval=thisVfl1; + thisVfl2=newval; break; case 4: // Fast Left 1 - thisFl1=val; + if (newval > thisFl2) newval=thisFl2; + thisFl1=newval; break; case 5: // Fast Left 2 - thisFl2=val; + if (newval < thisFl1) newval=thisFl1; + thisFl2=newval; break; case 6: // Left 1 - thisLft1=val; + if (newval > thisLft2) newval=thisLft2; + thisLft1=newval; break; case 7: // Left 2 - thisLft2=val; + if (newval < thisLft1) newval=thisLft1; + thisLft2=newval; break; case 8: // Right 1 - thisRgt1=val; + if (newval > thisRgt2) newval=thisRgt2; + thisRgt1=newval; break; case 9: // Right 2 - thisRgt2=val; + if (newval < thisRgt1) newval=thisRgt1; + thisRgt2=newval; break; case 10: // Fast Right 1 - thisFr1=val; + if (newval > thisFr2) newval=thisFr2; + thisFr1=newval; break; case 11: // Fast Right2 - thisFr2=val; + if (newval < thisFr1) newval=thisFr1; + thisFr2=newval; break; case 12: // Very fast Right 1 - thisVfr1=val; + if (newval > thisVfr2) newval=thisVfr2; + thisVfr1=newval; break; case 13: // Very fast Right 2 - thisVfr2=val; + if (newval < thisVfr1) newval=thisVfr1; + thisVfr2=newval; break; - } - sprintf(newtext,"%d",val); } - gtk_entry_set_text(GTK_ENTRY(widget), newtext); + // + // If we have changed the value because we kept thisVfl2 >= thisVfl1 etc, + // update the spin button + // + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),(double) newval); } static void clear_cb(GtkWidget *widget,gpointer user_data) { @@ -843,26 +847,26 @@ void midi_menu(GtkWidget *parent) { gtk_label_set_justify(GTK_LABEL(devices_label),GTK_JUSTIFY_LEFT); gtk_grid_attach(GTK_GRID(grid),devices_label,col,row,2,1); // - // Now put the device checkboxes in columns 3 (width: 2), 5 (width: 3), 8 (width: 2) + // Now put the device checkboxes in columns 3 (width: 1), 4 (width: 3), 7 (width: 1) // and make as many rows as necessary col=3; - int width = 2; + int width = 1; for (i=0; iConfigure special WHEEL parameters"); gtk_widget_set_halign(lbl, GTK_ALIGN_CENTER); - gtk_frame_set_label_widget(GTK_FRAME(WheelContainer), lbl); GtkWidget *WheelGrid=gtk_grid_new(); gtk_grid_set_column_spacing (GTK_GRID(WheelGrid),2); + gtk_grid_attach(GTK_GRID(WheelGrid), lbl, col, row, 3, 1); // // Finally, put wheel config elements into the wheel grid // col=0; - row=0; + row++; - lbl=gtk_label_new("Delay (msec):"); + lbl=gtk_label_new("Delay"); gtk_widget_set_halign(lbl, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(WheelGrid), lbl, col, row, 1, 1); col++; - set_delay = gtk_entry_new(); + set_delay = gtk_spin_button_new_with_range(0.0, 500.0, 10.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_delay, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_delay), 4); - g_signal_connect(set_delay, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(1)); + g_signal_connect(set_delay, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(1)); col++; row++; col=0; - lbl=gtk_label_new("Range for VeryFastLeft:"); + lbl=gtk_label_new("Left <<<:"); gtk_widget_set_halign(lbl, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(WheelGrid), lbl, col, row, 1, 1); col++; - set_vfl1 = gtk_entry_new(); + set_vfl1 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_vfl1, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_vfl1), 4); - g_signal_connect(set_vfl1, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(2)); + g_signal_connect(set_vfl1, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(2)); col++; - set_vfl2 = gtk_entry_new(); + set_vfl2 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_vfl2, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_vfl2), 4); - g_signal_connect(set_vfl2, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(3)); + g_signal_connect(set_vfl2, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(3)); + col++; row++; col=0; - lbl=gtk_label_new("Range for FastLeft:"); + + lbl=gtk_label_new("Left <<"); gtk_widget_set_halign(lbl, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(WheelGrid), lbl, col, row, 1, 1); col++; - set_fl1 = gtk_entry_new(); + set_fl1 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_fl1, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_fl1), 4); - g_signal_connect(set_fl1, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(4)); + g_signal_connect(set_fl1, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(4)); col++; - set_fl2 = gtk_entry_new(); + set_fl2 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_fl2, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_fl2), 4); - g_signal_connect(set_fl2, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(5)); + g_signal_connect(set_vfl2, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(5)); + col++; row++; col=0; - lbl=gtk_label_new("Range for NormalLeft:"); + lbl=gtk_label_new("Left <"); gtk_widget_set_halign(lbl, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(WheelGrid), lbl, col, row, 1, 1); col++; - set_lft1 = gtk_entry_new(); + set_lft1 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_lft1, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_lft1), 4); - g_signal_connect(set_lft1, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(6)); + g_signal_connect(set_lft1, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(6)); col++; - set_lft2 = gtk_entry_new(); + set_lft2 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_lft2, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_lft2), 4); - g_signal_connect(set_lft2, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(7)); + g_signal_connect(set_lft2, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(7)); + col++; row++; col=0; - lbl=gtk_label_new("Range for NormalRight:"); + lbl=gtk_label_new("Right >"); gtk_widget_set_halign(lbl, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(WheelGrid), lbl, col, row, 1, 1); col++; - set_rgt1 = gtk_entry_new(); + set_rgt1 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_rgt1, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_rgt1), 4); - g_signal_connect(set_rgt1, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(8)); + g_signal_connect(set_rgt1, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(8)); col++; - set_rgt2 = gtk_entry_new(); + set_rgt2 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_rgt2, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_rgt2), 4); - g_signal_connect(set_lft2, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(9)); + g_signal_connect(set_rgt2, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(9)); + col++; row++; col=0; - lbl=gtk_label_new("Range for FastRight:"); + lbl=gtk_label_new("Right >>"); gtk_widget_set_halign(lbl, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(WheelGrid), lbl, col, row, 1, 1); col++; - set_fr1 = gtk_entry_new(); + set_fr1 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_fr1, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_fr1), 4); - g_signal_connect(set_fr1, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(10)); + g_signal_connect(set_fr1, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(10)); col++; - set_fr2 = gtk_entry_new(); + set_fr2 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_fr2, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_fr2), 4); - g_signal_connect(set_fr2, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(11)); + g_signal_connect(set_fr2, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(11)); + col++; row++; col=0; - lbl=gtk_label_new("Range for VeryFastRight:"); + lbl=gtk_label_new("Right >>>"); gtk_widget_set_halign(lbl, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(WheelGrid), lbl, col, row, 1, 1); col++; - set_vfr1 = gtk_entry_new(); + set_vfr1 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_vfr1, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_vfr1), 4); - g_signal_connect(set_vfr1, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(12)); + g_signal_connect(set_vfr1, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(12)); col++; - set_vfr2 = gtk_entry_new(); + set_vfr2 = gtk_spin_button_new_with_range(-1.0, 127.0, 1.0); gtk_grid_attach(GTK_GRID(WheelGrid), set_vfr2, col, row, 1, 1); - gtk_entry_set_width_chars(GTK_ENTRY(set_vfr2), 4); - g_signal_connect(set_vfr2, "activate", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(13)); + g_signal_connect(set_vfr2, "value-changed", G_CALLBACK(wheelparam_cb), GINT_TO_POINTER(13)); + col++; gtk_container_add(GTK_CONTAINER(content),grid); gtk_container_add(GTK_CONTAINER(WheelContainer), WheelGrid); -- 2.45.2