]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Re-organized memory store/recall and implemented MIDI actions for this
authorc vw <dl1ycf@darc.de>
Thu, 15 Oct 2020 11:38:36 +0000 (13:38 +0200)
committerc vw <dl1ycf@darc.de>
Thu, 15 Oct 2020 11:38:36 +0000 (13:38 +0200)
(as suggested by David)

ext.c
ext.h
midi.h
midi2.c
midi3.c
store.c
store.h
store_menu.c

diff --git a/ext.c b/ext.c
index 6cdf9868bcfb19f318c72b9052fd3fddcfcb111d..f1269f8cb7cec655a9ad9774fe77a953df28d430 100644 (file)
--- 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 a64cf4ca251a1dabbd142846ad659fd2d4e80a8e..b14c14d5a872a74162de67ad996433920af282d6 100644 (file)
--- 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 e1ad0ad43cc09b23082db2f7756bd273e3ebec61..82fbeb78c152a7419102519c12efbcce79282ff2 100644 (file)
--- 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 7f9422a4c0cf29a9baa1fbcb0fe7549d53881742..f7a3c186e35bdebba90cecd55a13c7b9a1edeeb5 100644 (file)
--- 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 4ac35325480bba4c511e72a0ad8966d18630e106..3baec720cef88da3c34528fcf288e41fbde08b3c 100644 (file)
--- 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 3eb332df89549bdf253c8a6e9f31215b426c2000..8c5b971444362be0c310dcd4ef55ed05e2de7069 100644 (file)
--- a/store.c
+++ b/store.c
 #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;b<NUM_OF_MEMORYS;b++) {
-      if(strlen(mem[b].title)>0) {
-        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; b<NUM_OF_MEMORYS; b++) {
-       strcpy(mem[b].title,"10");  
        mem[b].frequency = 28010000LL;
        mem[b].mode = modeCWU;
        mem[b].filter = filterF0;
@@ -106,36 +72,74 @@ void memRestoreState() {
     fprintf(stderr,"memRestoreState: restore memory\n");
 
     for(b=0;b<NUM_OF_MEMORYS;b++) {
-        sprintf(name,"mem.%d.title",b);
-        value=getProperty(name);
-        if(value) {
-          strcpy(mem[b].title,value);
-          fprintf(stderr,"RESTORE: index=%d title=%s\n",b,value);
-       }
-
-        sprintf(name,"mem.%d.freqA",b);
-        value=getProperty(name);
-        if(value) {
-         mem[b].frequency=atoll(value);
-          fprintf(stderr,"RESTORE MEM:Mem %d=FreqA %11lld\n",b,mem[b].frequency);
-       }
-
-        sprintf(name,"mem.%d.mode",b);
-        value=getProperty(name);
-        if(value) {
-         mem[b].mode=atoi(value);
-          fprintf(stderr,"RESTORE: index=%d mode=%d\n",b,mem[b].mode);
-       }
-
-        sprintf(name,"mem.%d.filter",b);
-        value=getProperty(name);
-        if(value) {
-         mem[b].filter=atoi(value);
-          fprintf(stderr,"RESTORE: index=%d filter=%d\n",b,mem[b].filter);
-       }
+      sprintf(name,"mem.%d.freqA",b);
+      value=getProperty(name);
+      if(value) {
+         mem[b].frequency=atoll(value);
+         fprintf(stderr,"RESTORE MEM:Mem %d=FreqA %11lld\n",b,mem[b].frequency);
+      }
+
+      sprintf(name,"mem.%d.mode",b);
+      value=getProperty(name);
+      if(value) {
+        mem[b].mode=atoi(value);
+        fprintf(stderr,"RESTORE: index=%d mode=%d\n",b,mem[b].mode);
+      }
+
+      sprintf(name,"mem.%d.filter",b);
+      value=getProperty(name);
+      if(value) {
+        mem[b].filter=atoi(value);
+        fprintf(stderr,"RESTORE: index=%d filter=%d\n",b,mem[b].filter);
+      }
     }
+}
+
+void recall_memory_slot(int index) {
+    long long new_freq;
+    int id=active_receiver->id;
+
+    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 2bcb9e2257e2982496c74787dba5453a935c6972..48b35db1c0eb5f9d1d72badad772d2ab1c157a78 100644 (file)
--- 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
index 29f8808802de14322fded814435b095228fcb63b..4e127995f2622dbcaa7345698853bfc5d0ca2506 100644 (file)
 
 #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) {