From 084b409d185aa0c329ac07d26488b700e0bdc975 Mon Sep 17 00:00:00 2001
From: c vw <dl1ycf@darc.de>
Date: Fri, 31 May 2019 17:44:51 +0200
Subject: [PATCH] We needed a more permanent solution to the problem of RX
 panels that are un-used at program startup.

---
 Makefile.mac  |  4 +++-
 radio.c       | 38 +++++++++++++++++++++-----------------
 rigctl.c      |  2 --
 transmitter.h |  6 ++++++
 4 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/Makefile.mac b/Makefile.mac
index 980dca8..ec053b9 100644
--- a/Makefile.mac
+++ b/Makefile.mac
@@ -481,7 +481,9 @@ hpsdrsim:       hpsdrsim.o
 #       =========
 #       Upon starting a freshly built application in an "app" bundle,
 #       it will do the FFT calculations required for wdsp-Wisdom, since
-#       this is then stored *within* the app bundle.
+#       this is then stored *within* the app bundle. For experimentation,
+#       use "make localapp", this will copy such run-time files (WDSP wisom,
+#       ".props" files and the definition of the MIDI device) to the app bundle.
 #
 #############################################################################
 app:	$(OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) $(LIMESDR_OBJS) $(FREEDV_OBJS) \
diff --git a/radio.c b/radio.c
index b52f5f8..82c6fbf 100644
--- a/radio.c
+++ b/radio.c
@@ -564,30 +564,22 @@ void start_radio() {
     rx_height-=SLIDERS_HEIGHT;
   }
   int tx_height=rx_height;
-  rx_height=rx_height/receivers;
+  rx_height=rx_height/RECEIVERS;
 
 
-//fprintf(stderr,"Create %d receivers: height=%d\n",receivers,rx_height);
+  //
+  // To be on the safe side, we create ALL receiver panels here
+  // If upon startup, we only should display one panel, we do the switch below
+  //
   for(i=0;i<RECEIVERS;i++) {
-    // A receiver may be un-unsed upon program start, but can be activated through the radio menu later.
-    // Create it here with height 0. Make sure to call g_object_ref for this one as well,
-    // this cures the seg-faults observed when switching beteen 1 and 2 RX in the radio menu.
-    if(i<receivers) {
-      receiver[i]=create_receiver(i, buffer_size, fft_size, display_width, updates_per_second, display_width, rx_height);
-    } else {
-      receiver[i]=create_receiver(i, buffer_size, fft_size, display_width, updates_per_second, display_width, 0        );
-    }
+    receiver[i]=create_receiver(i, buffer_size, fft_size, display_width, updates_per_second, display_width, rx_height);
     setSquelch(receiver[i]);
     receiver[i]->x=0;
     receiver[i]->y=y;
     gtk_fixed_put(GTK_FIXED(fixed),receiver[i]->panel,0,y);
     g_object_ref((gpointer)receiver[i]->panel);
-    if (i<receivers) {
-      set_displaying(receiver[i],1);
-      y+=rx_height;
-    } else {
-      set_displaying(receiver[i],0);
-    }
+    set_displaying(receiver[i],1);
+    y+=rx_height;
   }
 
   if((protocol==ORIGINAL_PROTOCOL) && (RECEIVERS==2) && (receiver[0]->sample_rate!=receiver[1]->sample_rate)) {
@@ -658,6 +650,18 @@ void start_radio() {
   gtk_fixed_put(GTK_FIXED(fixed),toolbar,0,y);
   y+=TOOLBAR_HEIGHT;
 
+//
+// Now, if there should only one receiver be displayed
+// at startup, do the change. We must momentarily fake
+// the number of receivers otherwise radio_change_receivers
+// will do nothing.
+//
+  if (receivers != RECEIVERS) {
+    i=receivers,
+    receivers=RECEIVERS;
+    radio_change_receivers(i);
+  }
+
   gtk_widget_show_all (fixed);
 //#ifdef FREEDV
 //  if(!active_receiver->freedv) {
@@ -746,8 +750,8 @@ void radio_change_sample_rate(int rate) {
         old_protocol_run();
 #ifdef PURESIGNAL
         tx_set_ps_sample_rate(transmitter,rate);
-      }
 #endif
+      }
       break;
 #ifdef LIMESDR
     case LIMESDR_PROTOCOL:
diff --git a/rigctl.c b/rigctl.c
index e1dcc8d..ddb6f87 100644
--- a/rigctl.c
+++ b/rigctl.c
@@ -302,8 +302,6 @@ static long dashlen;
 static int  dotsamples;
 static int  dashsamples;
 
-extern int cw_key_up, cw_key_down, cw_not_ready;
-
 //
 // send_dash()         send a "key-down" of a dashlen, followed by a "key-up" of a dotlen
 // send_dot()          send a "key-down" of a dotlen,  followed by a "key-up" of a dotlen
diff --git a/transmitter.h b/transmitter.h
index 177075e..ed8d82f 100644
--- a/transmitter.h
+++ b/transmitter.h
@@ -121,6 +121,12 @@ extern TRANSMITTER *create_transmitter(int id, int buffer_size, int fft_size, in
 
 void reconfigure_transmitter(TRANSMITTER *tx,int height);
 
+//
+// CW pulse shaper variables, needed by rigctl (CAT CW) and iambic.c (LOCALCW)
+//
+extern int cw_key_up;
+extern int cw_key_down;
+extern int cw_not_ready;
 
 extern void tx_set_mode(TRANSMITTER* tx,int m);
 extern void tx_set_filter(TRANSMITTER *tx,int low,int high);
-- 
2.45.2