From 10d05fcd7c669324eb6a0bbf331c5855f8a376ac Mon Sep 17 00:00:00 2001 From: c vw Date: Thu, 15 Oct 2020 13:38:36 +0200 Subject: [PATCH] Re-organized memory store/recall and implemented MIDI actions for this (as suggested by David) --- ext.c | 11 ++++ ext.h | 2 + midi.h | 10 ++++ midi2.c | 10 ++++ midi3.c | 29 ++++++++++ store.c | 154 ++++++++++++++++++++++++++------------------------- store.h | 5 +- store_menu.c | 51 +++-------------- 8 files changed, 151 insertions(+), 121 deletions(-) diff --git a/ext.c b/ext.c index 6cdf986..f1269f8 100644 --- a/ext.c +++ b/ext.c @@ -50,6 +50,7 @@ #include "ext.h" #include "zoompan.h" #include "equalizer_menu.h" +#include "store.h" // The following calls functions can be called usig g_idle_add @@ -1153,3 +1154,13 @@ int ext_set_title(void *data) { gtk_window_set_title(GTK_WINDOW(top_window),(char *)data); return 0; } + +int ext_store_memory_slot(void *data) { + store_memory_slot(GPOINTER_TO_INT(data)); + return 0; +} + +int ext_recall_memory_slot(void *data) { + recall_memory_slot(GPOINTER_TO_INT(data)); + return 0; +} diff --git a/ext.h b/ext.h index a64cf4c..b14c14d 100644 --- a/ext.h +++ b/ext.h @@ -141,4 +141,6 @@ extern int ext_remote_set_zoom(void *data); extern int ext_remote_set_pan(void *data); extern int ext_set_title(void *data); +extern int ext_store_memory_slot(void *data); +extern int ext_recall_memory_slot(void *data); diff --git a/midi.h b/midi.h index e1ad0ad..82fbeb7 100644 --- a/midi.h +++ b/midi.h @@ -88,6 +88,11 @@ enum MIDIaction { MIDI_ACTION_PRE, // PREAMP: preamp on/off MIDI_ACTION_PTTONOFF, // PTT: set PTT state to "on" or "off" MIDI_ACTION_PS, // PURESIGNAL: toggle PURESIGNAL on/off + MIDI_ACTION_MEM_RECALL_M0, // RECALLM0: load current freq/mode/filter from memory slot #0 + MIDI_ACTION_MEM_RECALL_M1, // RECALLM1: load current freq/mode/filter from memory slot #0 + MIDI_ACTION_MEM_RECALL_M2, // RECALLM2: load current freq/mode/filter from memory slot #0 + MIDI_ACTION_MEM_RECALL_M3, // RECALLM3: load current freq/mode/filter from memory slot #0 + MIDI_ACTION_MEM_RECALL_M4, // RECALLM4: load current freq/mode/filter from memory slot #0 MIDI_ACTION_RF_GAIN, // RFGAIN: receiver RF gain MIDI_ACTION_TX_DRIVE, // RFPOWER: adjust TX RF output power MIDI_ACTION_RIT_CLEAR, // RITCLEAR: clear RIT and XIT value @@ -97,6 +102,11 @@ enum MIDIaction { MIDI_ACTION_SAT, // SAT: cycle through SAT modes off/SAT/RSAT MIDI_ACTION_SNB, // SNB: toggle SNB on/off MIDI_ACTION_SPLIT, // SPLIT: Split on/off + MIDI_ACTION_MEM_STORE_M0, // STOREM0: store current freq/mode/filter in memory slot #0 + MIDI_ACTION_MEM_STORE_M1, // STOREM1: store current freq/mode/filter in memory slot #1 + MIDI_ACTION_MEM_STORE_M2, // STOREM2: store current freq/mode/filter in memory slot #2 + MIDI_ACTION_MEM_STORE_M3, // STOREM3: store current freq/mode/filter in memory slot #3 + MIDI_ACTION_MEM_STORE_M4, // STOREM4: store current freq/mode/filter in memory slot #4 MIDI_ACTION_SWAP_RX, // SWAPRX: swap active receiver (if there are two receivers) MIDI_ACTION_SWAP_VFO, // SWAPVFO: swap VFO A/B frequency MIDI_ACTION_TUNE, // TUNE: toggle "tune" state diff --git a/midi2.c b/midi2.c index 7f9422a..f7a3c18 100644 --- a/midi2.c +++ b/midi2.c @@ -152,6 +152,11 @@ static struct { { MIDI_ACTION_PRE, "PREAMP"}, { MIDI_ACTION_PTTONOFF, "PTT"}, { MIDI_ACTION_PS, "PURESIGNAL"}, + { MIDI_ACTION_MEM_RECALL_M0, "RECALLM0"}, + { MIDI_ACTION_MEM_RECALL_M1, "RECALLM1"}, + { MIDI_ACTION_MEM_RECALL_M2, "RECALLM2"}, + { MIDI_ACTION_MEM_RECALL_M3, "RECALLM3"}, + { MIDI_ACTION_MEM_RECALL_M4, "RECALLM4"}, { MIDI_ACTION_RF_GAIN, "RFGAIN"}, { MIDI_ACTION_TX_DRIVE, "RFPOWER"}, { MIDI_ACTION_RIT_CLEAR, "RITCLEAR"}, @@ -161,6 +166,11 @@ static struct { { MIDI_ACTION_SAT, "SAT"}, { MIDI_ACTION_SNB, "SNB"}, { MIDI_ACTION_SPLIT, "SPLIT"}, + { MIDI_ACTION_MEM_STORE_M0, "STOREM0"}, + { MIDI_ACTION_MEM_STORE_M1, "STOREM1"}, + { MIDI_ACTION_MEM_STORE_M2, "STOREM2"}, + { MIDI_ACTION_MEM_STORE_M3, "STOREM3"}, + { MIDI_ACTION_MEM_STORE_M4, "STOREM4"}, { MIDI_ACTION_SWAP_RX, "SWAPRX"}, { MIDI_ACTION_SWAP_VFO, "SWAPVFO"}, { MIDI_ACTION_TUNE, "TUNE"}, diff --git a/midi3.c b/midi3.c index 4ac3532..3baec72 100644 --- a/midi3.c +++ b/midi3.c @@ -22,6 +22,7 @@ #include "ext.h" #include "agc.h" #include "midi.h" +#include "store.h" #ifdef LOCALCW #include "iambic.h" #endif @@ -602,6 +603,20 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) { } #endif break; + /////////////////////////////////////////////////////////// "RECALLM[0-4]" + case MIDI_ACTION_MEM_RECALL_M0: + case MIDI_ACTION_MEM_RECALL_M1: + case MIDI_ACTION_MEM_RECALL_M2: + case MIDI_ACTION_MEM_RECALL_M3: + case MIDI_ACTION_MEM_RECALL_M4: + // + // only knob supported + // + if (type == MIDI_TYPE_KNOB) { + new = action - MIDI_ACTION_MEM_RECALL_M0, + g_idle_add(ext_recall_memory_slot, GINT_TO_POINTER(new)); + } + break; /////////////////////////////////////////////////////////// "RFGAIN" case MIDI_ACTION_RF_GAIN: // knob or wheel supported if (type == MIDI_TYPE_KNOB) { @@ -725,6 +740,20 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) { g_idle_add(ext_split_toggle, NULL); } break; + /////////////////////////////////////////////////////////// "STOREM[0-4]" + case MIDI_ACTION_MEM_STORE_M0: + case MIDI_ACTION_MEM_STORE_M1: + case MIDI_ACTION_MEM_STORE_M2: + case MIDI_ACTION_MEM_STORE_M3: + case MIDI_ACTION_MEM_STORE_M4: + // + // only knob supported + // + if (type == MIDI_TYPE_KNOB) { + new = action - MIDI_ACTION_MEM_STORE_M0; + g_idle_add(ext_recall_memory_slot, GINT_TO_POINTER(new)); + } + break; /////////////////////////////////////////////////////////// "SWAPRX" case MIDI_ACTION_SWAP_RX: // only key supported if (type == MIDI_TYPE_KEY && receivers == 2) { diff --git a/store.c b/store.c index 3eb332d..8c5b971 100644 --- a/store.c +++ b/store.c @@ -30,63 +30,30 @@ #include "property.h" #include "store.h" #include "store_menu.h" +#include "radio.h" +#include "ext.h" +#include "vfo.h" - -/* -struct MEM { - char title[16]; // Begin BAND Struct - BANDSTACK *bandstack; - unsigned char OCrx; - unsigned char OCtx; - int preamp; - int alexRxAntenna; - int alexTxAntenna; - int alexAttenuation; - double pa_calibration; - long long frequencyMin; - long long frequencyMax; - long long frequencyLO; - int disablePA; - long long frequency; // Begin BANDSTACK_ENTRY - int mode; - int filter; - int var1Low; - int var1High; - int var2Low; - int var2High; -}*/ MEM mem[NUM_OF_MEMORYS]; // This makes it a compile time option -/* */ -/* Memory uses the same format as Band Stack */ -/* Implement NUM_OF_MEMORYS memory locations for now... */ - void memSaveState() { char name[128]; char value[128]; int b; for(b=0;b0) { - sprintf(name,"mem.%d.title",b); - setProperty(name,mem[b].title); + sprintf(value,"%lld",mem[b].frequency); + sprintf(name,"mem.%d.freqA",b); + setProperty(name,value); - sprintf(value,"%lld",mem[b].frequency); - sprintf(name,"mem.%d.freqA",b); - setProperty(name,value); + sprintf(value,"%d",mem[b].mode); + sprintf(name,"mem.%d.mode",b); + setProperty(name,value); - sprintf(value,"%d",mem[b].mode); - sprintf(name,"mem.%d.mode",b); - setProperty(name,value); - - sprintf(value,"%d",mem[b].filter); - sprintf(name,"mem.%d.filter",b); - setProperty(name,value); - } + sprintf(value,"%d",mem[b].filter); + sprintf(name,"mem.%d.filter",b); + setProperty(name,value); } - - //sprintf(value,"%d",band); - //setProperty("band",value); } void memRestoreState() { @@ -97,7 +64,6 @@ void memRestoreState() { // Initialize the array with default values // Allows this to be a compile time option.. for(b=0; bid; + + new_freq = mem[index].frequency; + fprintf(stderr,"recall_select_cb: Index=%d\n",index); + fprintf(stderr,"recall_select_cb: freqA=%11lld\n",new_freq); + fprintf(stderr,"recall_select_cb: mode=%d\n",mem[index].mode); + fprintf(stderr,"recall_select_cb: filter=%d\n",mem[index].filter); + + // + // Recalling a memory slot is equivalent to the following actions + // + // a) set the new frequency via the "Freq" menu + // b) set the new mode via the "Mode" menu + // c) set the new filter via the "Filter" menu + // + // Step b) automatically restores the filter, noise reduction, and + // equalizer settings stored with that mode + // + // Step c) will not only change the filter but also store the new setting + // with that mode. + // + local_set_frequency(active_receiver->id, new_freq); + vfo_mode_changed(mem[index].mode); + vfo_filter_changed(mem[index].filter); + g_idle_add(ext_vfo_update,NULL); +} + +void store_memory_slot(int index) { + char workstr[40]; + int id=active_receiver->id; + + // + // Store current frequency, mode, and filter in slot #index + // + mem[index].frequency = vfo[id].frequency; + mem[index].mode = vfo[id].mode; + mem[index].filter=vfo[id].filter; + + fprintf(stderr,"store_select_cb: Index=%d\n",index); + fprintf(stderr,"store_select_cb: freqA=%11lld\n",mem[index].frequency); + fprintf(stderr,"store_select_cb: mode=%d\n",mem[index].mode); + fprintf(stderr,"store_select_cb: filter=%d\n",mem[index].filter); - //value=getProperty("band"); - //if(value) band=atoi(value); + memSaveState(); } diff --git a/store.h b/store.h index 2bcb9e2..48b35db 100644 --- a/store.h +++ b/store.h @@ -30,8 +30,7 @@ * @brief Band definition */ struct _MEM_STORE { - char title[16]; // Begin BAND Struct - long long frequency; // Begin BANDSTACK_ENTRY + long long frequency; int mode; int filter; }; @@ -41,5 +40,7 @@ typedef struct _MEM_STORE MEM; extern MEM mem[]; void memRestoreState(); void memSaveState(); +void recall_memory_slot(int index); +void store_memory_slot(int index); #endif diff --git a/store_menu.c b/store_menu.c index 29f8808..4e12799 100644 --- a/store_menu.c +++ b/store_menu.c @@ -26,17 +26,8 @@ #include "new_menu.h" #include "store_menu.h" -#include "band.h" -#include "bandstack.h" -#include "filter.h" -#include "mode.h" -#include "radio.h" -#include "rigctl.h" -#include "band.h" -#include "vfo.h" #include "button_text.h" #include "store.h" -#include "ext.h" static GtkWidget *parent_window=NULL; @@ -67,47 +58,19 @@ static gboolean store_select_cb (GtkWidget *widget, gpointer data) { fprintf(stderr,"STORE BUTTON PUSHED=%d\n",index); char workstr[40]; - /* Update mem[data] with current info */ + store_memory_slot(index); - mem[index].frequency = vfo[active_receiver->id].frequency; // Store current frequency - mem[index].mode = vfo[active_receiver->id].mode; - mem[index].filter=vfo[active_receiver->id].filter; + sprintf(workstr,"M%d=%8.6f MHz", index,((double) mem[index].frequency)/1000000.0); + gtk_button_set_label(GTK_BUTTON(store_button[index]),workstr); - fprintf(stderr,"store_select_cb: Index=%d\n",index); - fprintf(stderr,"store_select_cb: freqA=%11lld\n",mem[index].frequency); - fprintf(stderr,"store_select_cb: mode=%d\n",mem[index].mode); - fprintf(stderr,"store_select_cb: filter=%d\n",mem[index].filter); - - sprintf(workstr,"M%d=%8.6f MHz", index,((double) mem[index].frequency)/1000000.0); - gtk_button_set_label(GTK_BUTTON(store_button[index]),workstr); - - // Save in the file now.. - memSaveState(); - return FALSE; + return FALSE; } + static gboolean recall_select_cb (GtkWidget *widget, gpointer data) { int index = GPOINTER_TO_INT(data); - long long new_freq; - - //new_freq = mem[index].frequency; - strcpy(mem[index].title,"Active"); - new_freq = mem[index].frequency; - fprintf(stderr,"recall_select_cb: Index=%d\n",index); - fprintf(stderr,"recall_select_cb: freqA=%11lld\n",new_freq); - fprintf(stderr,"recall_select_cb: mode=%d\n",mem[index].mode); - fprintf(stderr,"recall_select_cb: filter=%d\n",mem[index].filter); - - vfo[active_receiver->id].frequency = new_freq; - vfo[active_receiver->id].band = get_band_from_frequency(new_freq); - vfo[active_receiver->id].mode = mem[index].mode; - vfo[active_receiver->id].filter = mem[index].filter; - //vfo_band_changed(vfo[active_receiver->id].band); - vfo_filter_changed(mem[index].filter); - vfo_mode_changed(mem[index].mode); - g_idle_add(ext_vfo_update,NULL); - - return FALSE; + recall_memory_slot(index); + return FALSE; } void store_menu(GtkWidget *parent) { -- 2.45.2