From: c vw <dl1ycf@darc.de>
Date: Tue, 29 Oct 2019 18:15:59 +0000 (+0100)
Subject: Streamlining code, added SWAPRX
X-Git-Url: https://git.rkrishnan.org/pf/content/en/cyclelanguage?a=commitdiff_plain;h=50d85383072695edcca26208bfc50a916bca61e4;p=pihpsdr.git

Streamlining code, added SWAPRX
---

diff --git a/midi.h b/midi.h
index a72803e..654cea0 100644
--- a/midi.h
+++ b/midi.h
@@ -74,6 +74,7 @@ enum MIDIaction {
   RIT_VAL,		// change RIT value
   MIDI_SPLIT,		// Split on/off
   SWAP_VFO,		// swap VFO A/B frequency
+  SWAP_RX, 		// swap active receiver (if there are two receivers)
   MIDI_TUNE,		// toggle "tune" state
   TX_DRIVE,		// RF output power
   VFO,			// change VFO frequency
diff --git a/midi.inp b/midi.inp
index fb1e922..e3f9d51 100644
--- a/midi.inp
+++ b/midi.inp
@@ -63,7 +63,7 @@ KEY=7 ACTION=NONE
 #
 KEY=16 ACTION=NONE
 KEY=17 ACTION=ATT
-KEY=18 ACTION=RITCLEAR
+KEY=18 ACTION=RIT
 KEY=19 ACTION=CTUN
 KEY=20 ACTION=NOISEBLANKER
 KEY=21 ACTION=NOISEREDUCTION
@@ -76,7 +76,7 @@ KEY=23 ACTION=AGCATTACK
 KEY=24 ACTION=TUNE                # LOAD    button: TUNE on/off
 KEY=25 ACTION=LOCK                # LOCK    button: Lock VFO(s)
 KEY=26 ACTION=PURESIGNAL          # DECK    button: toggle PURESIGNAL
-KEY=27 ACTION=SWAPVFO             # SCRATCH button: Swap VFOs A and B
+KEY=27 ACTION=SWAPRX              # SCRATCH button: Swap VFOs A and B
 KEY=32 ACTION=VFOA2B              # SYNC    button: Frequency VFO A -> VFO B
 KEY=33 ACTION=VFOB2A              # TAP     button: Frequency VFO B -> VFO A
 KEY=34 ACTION=MOX                 # CUE     button: MOX on/off
diff --git a/midi2.c b/midi2.c
index e12f254..18e5737 100644
--- a/midi2.c
+++ b/midi2.c
@@ -116,10 +116,11 @@ static struct {
         { PAN_LOW,      	"PANLOW"},
         { PRE,          	"PREAMP"},
 	{ MIDI_PS,    		"PURESIGNAL"},
-        { RIT_TOGGLE,   	"RITONOFF"},
+        { RIT_TOGGLE,   	"RIT"},
 	{ RIT_STEP, 		"RITSTEP"},
         { RIT_VAL,      	"RITVAL"},
 	{ MIDI_SPLIT,  		"SPLIT"},
+	{ SWAP_RX,		"SWAPRX"},
 	{ SWAP_VFO,		"SWAPVFO"},
         { MIDI_TUNE,    	"TUNE"},
         { TX_DRIVE,     	"RFPOWER"},
diff --git a/midi3.c b/midi3.c
index 899eead..790ce82 100644
--- a/midi3.c
+++ b/midi3.c
@@ -30,38 +30,10 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
     double *dp;
     int    *ip;
 
+    //
+    // Handle cases in alphabetical order of the key words in midi.inp
+    //
     switch (action) {
-	case SWAP_VFO:	// only key supported
-	    if (type == MIDI_KEY) {
-		g_idle_add(ext_vfo_a_swap_b,NULL);
-	    }
-	    break;    
-	case VFO: // only wheel supported
-	    if (type == MIDI_WHEEL && !locked) {
-		g_idle_add(ext_vfo_step, GINT_TO_POINTER(val));
-	    }
-	    break;
-	case VFOA: // only wheel supported
-	case VFOB: // only wheel supported
-	    if (type == MIDI_WHEEL && !locked) {
-	        ip=malloc(2*sizeof(int));
-		*ip = (action == VFOA) ? 0 : 1;   // could use (action - VFOA) to support even more VFOs
-		*(ip+1)=val;
-		g_idle_add(ext_vfo_id_step, ip);
-	    }
-	    break;
-	case MIDI_TUNE: // only key supported
-	    if (type == MIDI_KEY) {
-	        new = !tune;
-		g_idle_add(ext_tune_update, GINT_TO_POINTER(new));
-	    }
-	    break;    
-	case MIDI_MOX: // only key supported
-	    if (type == MIDI_KEY) {
-	        new = !mox;
-		g_idle_add(ext_mox_update, GINT_TO_POINTER(new));
-	    }
-	    break;    
 	case AF_GAIN: // knob or wheel supported
             switch (type) {
 	      case MIDI_KNOB:
@@ -79,25 +51,6 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
 	    }
 	    g_idle_add(ext_update_af_gain, NULL);
 	    break;
-	case MIC_VOLUME: // knob or wheel supported
-	    switch (type) {
-	      case MIDI_KNOB:
-		dnew=-10.0 + 0.6*val;
-		break;
-	      case MIDI_WHEEL:
-		dnew = mic_gain + val;
-		if (dnew < -10.0) dnew=-10.0; if (dnew > 50.0) dnew=50.0;
-		break;
-	      default:
-		// do not change mic gain
-		// we should not come here anyway
-		dnew = mic_gain;
-		break;
-	    }
-	    dp=malloc(sizeof(double));
-	    *dp=dnew;
-	    g_idle_add(ext_set_mic_gain, (gpointer) dp);
-	    break;
 	case MIDI_AGC: // knob or wheel supported
 	    switch (type) {
 	      case MIDI_KNOB:
@@ -117,27 +70,47 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
 	    *dp=dnew;
 	    g_idle_add(ext_set_agc_gain, (gpointer) dp);
 	    break;
-	case TX_DRIVE: // knob or wheel supported
-	    switch (type) {
-	      case MIDI_KNOB:
-		dnew = val;
+	case AGCATTACK: // only key supported
+	    // cycle through fast/med/slow AGC attack
+	    if (type == MIDI_KEY) {
+	      new=active_receiver->agc + 1;
+	      if (new > AGC_FAST) new=0;
+	      active_receiver->agc=new;
+	      g_idle_add(ext_vfo_update, NULL);
+	    }
+	    break;
+	case ATT:	// Key for ALEX attenuator, wheel or knob for slider
+	    switch(type) {
+	      case MIDI_KEY:
+		if (filter_board == ALEX && active_receiver->adc == 0) {
+		  new=active_receiver->alex_attenuation + 1;
+		  if (new > 3) new=0;
+		  g_idle_add(ext_set_alex_attenuation, GINT_TO_POINTER(new));
+		  g_idle_add(ext_update_att_preamp, NULL);
+		}
 		break;
 	      case MIDI_WHEEL:
-		dnew=transmitter->drive + val;
-		if (dnew < 0.0) dnew=0.0; if (dnew > 100.0) dnew=100.0;
+		  new=adc_attenuation[active_receiver->adc] + val;
+		  if (new > 31) new=31;
+		  if (new < 0 ) new=0;
+		  dp=malloc(sizeof(double));
+		  *dp=new;
+		  g_idle_add(ext_set_attenuation_value,(gpointer) dp);
+		  break;
+	      case MIDI_KNOB:
+		new=(31*val)/100;
+		dp=malloc(sizeof(double));
+		*dp=new;
+		g_idle_add(ext_set_attenuation_value,(gpointer) dp);
 		break;
 	      default:
-		// do not change value
+		// do nothing
 		// we should not come here anyway
-		dnew=transmitter->drive;
 		break;
 	    }
-	    dp=malloc(sizeof(double));
-	    *dp=dnew;
-	    g_idle_add(ext_set_drive, (gpointer) dp);
 	    break;
-	case BAND_UP:
 	case BAND_DOWN:
+	case BAND_UP:
 	    switch (type) {
 	      case MIDI_KEY:
 		new=(action == BAND_UP) ? 1 : -1;
@@ -166,140 +139,157 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
 	      g_idle_add(ext_vfo_band_changed, GINT_TO_POINTER(new));
 	    }
 	    break;
-	case FILTER_UP:
-	case FILTER_DOWN:
+	case COMPRESS: // wheel or knob
 	    switch (type) {
-	      case MIDI_KEY:
-		new=(action == FILTER_UP) ? 1 : -1;
-		new+=vfo[active_receiver->id].filter;
-		if (new >= FILTERS) new=0;
-		if (new <0) new=FILTERS-1;
-		break;
 	      case MIDI_WHEEL:
-		new=val > 0 ? 1 : -1;
-		new+=vfo[active_receiver->id].filter;
-		if (new >= FILTERS) new=0;
-		if (new <0) new=FILTERS-1;
+		dnew=transmitter->compressor_level + val;
+		if (dnew > 20.0) dnew=20.0;
+		if (dnew < 0 ) dnew=0;
 		break;
 	      case MIDI_KNOB:
-		// cycle through all the filters
-		new = ((FILTERS-1) * val) / 100;
+		dnew=(20.0*val)/100.0;
 		break;
 	      default:
-		// do not change filter setting
+		// do not change
 		// we should not come here anyway
-		new=vfo[active_receiver->id].filter;
+		dnew=transmitter->compressor_level;
 		break;
 	    }
-	    g_idle_add(ext_vfo_filter_changed, GINT_TO_POINTER(new));
+	    transmitter->compressor_level=dnew;
+	    // automatically engange compressor if level > 0.5
+	    if (dnew < 0.5) transmitter->compressor=0;
+	    if (dnew > 0.5) transmitter->compressor=1;
+	    g_idle_add(ext_set_compression, NULL);
 	    break;
-	case MODE_UP:
-	case MODE_DOWN:
+	case MIDI_CTUN: // only key supported
+	    // toggle CTUN
+	    if (type == MIDI_KEY) {
+	      new=active_receiver->id;
+	      if(!vfo[new].ctun) {
+		vfo[new].ctun=1;
+		vfo[new].offset=0;
+	      } else {
+		vfo[new].ctun=0;
+	      }
+	      vfo[new].ctun_frequency=vfo[new].frequency;
+	      set_offset(active_receiver,vfo[new].offset);
+	      g_idle_add(ext_vfo_update, NULL);
+	    }
+	    break;
+	case FILTER_DOWN:
+	case FILTER_UP:
 	    switch (type) {
 	      case MIDI_KEY:
-		new=(action == MODE_UP) ? 1 : -1;
-		new+=vfo[active_receiver->id].mode;
-		if (new >= MODES) new=0;
-		if (new <0) new=MODES-1;
+		new=(action == FILTER_UP) ? 1 : -1;
 		break;
 	      case MIDI_WHEEL:
 		new=val > 0 ? 1 : -1;
-		new+=vfo[active_receiver->id].mode;
-		if (new >= MODES) new=0;
-		if (new <0) new=MODES-1;
 		break;
 	      case MIDI_KNOB:
-		// cycle through all the modes
-		new = ((MODES-1) * val) / 100;
+		// cycle through all the filters
+		new = ((FILTERS-1) * val) / 100 - vfo[active_receiver->id].filter;
 		break;
 	      default:
-		// do not change
+		// do not change filter setting
 		// we should not come here anyway
-		new=vfo[active_receiver->id].mode;
+		new=0;
 		break;
 	    }
-	    g_idle_add(ext_vfo_mode_changed, GINT_TO_POINTER(new));
+	    if (new != 0) {
+	      new+=vfo[active_receiver->id].filter;
+	      if (new >= FILTERS) new=0;
+	      if (new <0) new=FILTERS-1;
+	      g_idle_add(ext_vfo_filter_changed, GINT_TO_POINTER(new));
+	    }
 	    break;
-	case PAN_LOW:  // wheel and knob
+	case MIDI_LOCK: // only key supported
+	    if (type == MIDI_KEY) {
+	      locked=!locked;
+	      g_idle_add(ext_vfo_update, NULL);
+	    }
+	    break;
+	case MIC_VOLUME: // knob or wheel supported
 	    switch (type) {
-	      case MIDI_WHEEL:
-		if (isTransmitting()) {
-		    // TX panadapter affected
-		    transmitter->panadapter_low += val;
-		} else {
-		    active_receiver->panadapter_low += val;
-		}
-		break;
 	      case MIDI_KNOB:
-		if (isTransmitting()) {
-		    // TX panadapter: use values -100 through -50
-		    new = -100 + val/2;
-		    transmitter->panadapter_low =new;
-		} else {
-		    // RX panadapter: use values -140 through -90
-		    new = -140 + val/2;
-		    active_receiver->panadapter_low = new;
-		}
+		dnew=-10.0 + 0.6*val;
+		break;
+	      case MIDI_WHEEL:
+		dnew = mic_gain + val;
+		if (dnew < -10.0) dnew=-10.0; if (dnew > 50.0) dnew=50.0;
 		break;
 	      default:
-		// do nothing
+		// do not change mic gain
 		// we should not come here anyway
+		dnew = mic_gain;
 		break;
 	    }
-	    g_idle_add(ext_vfo_update, NULL);
+	    dp=malloc(sizeof(double));
+	    *dp=dnew;
+	    g_idle_add(ext_set_mic_gain, (gpointer) dp);
 	    break;
-	case RIT_STEP: // key or wheel supported
-	    // This cycles between RIT increments 1, 10, 100, 1, 10, 100, ...
+	case MODE_DOWN:
+	case MODE_UP:
 	    switch (type) {
 	      case MIDI_KEY:
-		// key cycles through in upward direction
-		val=1;
-		/* FALLTHROUGH */
+		new=(action == MODE_UP) ? 1 : -1;
+		break;
 	      case MIDI_WHEEL:
-		// wheel cycles upward or downward
-		if (val > 0) {
-		  rit_increment=10*rit_increment;
-		} else {
-		  rit_increment=rit_increment/10;
-		}
-		if (rit_increment < 1) rit_increment=100;
-		if (rit_increment > 100) rit_increment=1;
+		new=val > 0 ? 1 : -1;
+		break;
+	      case MIDI_KNOB:
+		// cycle through all the modes
+		new = ((MODES-1) * val) / 100 - vfo[active_receiver->id].mode;
 		break;
 	      default:
-		// do nothing
+		// do not change
+		// we should not come here anyway
+		new=0;
 		break;
 	    }
-	    g_idle_add(ext_vfo_update, NULL);
+	    if (new != 0) {
+	      new+=vfo[active_receiver->id].mode;
+	      if (new >= MODES) new=0;
+	      if (new <0) new=MODES-1;
+	      g_idle_add(ext_vfo_mode_changed, GINT_TO_POINTER(new));
+	    }
 	    break;
-	case RIT_TOGGLE:  // only key supported
+	case MIDI_MOX: // only key supported
 	    if (type == MIDI_KEY) {
-		// enable/disable RIT
-		new=vfo[active_receiver->id].rit_enabled;
-		vfo[active_receiver->id].rit_enabled = new ? 0 : 1;
-	        g_idle_add(ext_vfo_update, NULL);
+	        new = !mox;
+		g_idle_add(ext_mox_update, GINT_TO_POINTER(new));
+	    }
+	    break;    
+	case MIDI_NB: // only key supported
+	    // cycle through NoiseBlanker settings: OFF, NB, NB2
+            if (type == MIDI_KEY) {
+	      if (active_receiver->nb) {
+		active_receiver->nb = 0;
+		active_receiver->nb2= 1;
+	      } else if (active_receiver->nb2) {
+		active_receiver->nb = 0;
+		active_receiver->nb2= 0;
+	      } else {
+		active_receiver->nb = 1;
+		active_receiver->nb2= 0;
+	      }
+	      g_idle_add(ext_vfo_update, NULL);
 	    }
 	    break;
-	case RIT_VAL:	// wheel or knob
-	    switch (type) {
-	      case MIDI_WHEEL:
-		// This changes the RIT value incrementally,
-	  	// but we restrict the change to +/ 9.999 kHz
-		new = vfo[active_receiver->id].rit + val*rit_increment;
-		if (new >  9999) new= 9999;
-		if (new < -9999) new=-9999;
-		vfo[active_receiver->id].rit = new;
-		break;
-	      case MIDI_KNOB:
-	 	// knob: adjust in the range +/ 50*rit_increment
-		new = (val-50) * rit_increment;
-		vfo[active_receiver->id].rit = new;
-		break;
-	      default:
-		// do nothing
-		// we should not come here anyway
-		break;
+	case MIDI_NR: // only key supported
+	    // cycle through NoiseReduction settings: OFF, NR1, NR2
+	    if (type == MIDI_KEY) {
+	      if (active_receiver->nr) {
+		active_receiver->nr = 0;
+		active_receiver->nr2= 1;
+	      } else if (active_receiver->nr2) {
+		active_receiver->nr = 0;
+		active_receiver->nr2= 0;
+	      } else {
+		active_receiver->nr = 1;
+		active_receiver->nr2= 0;
+	      }
+	      g_idle_add(ext_vfo_update, NULL);
 	    }
-	    g_idle_add(ext_vfo_update, NULL);
 	    break;
 	case PAN_HIGH:  // wheel or knob
 	    switch (type) {
@@ -327,6 +317,34 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
 	    }
 	    g_idle_add(ext_vfo_update, NULL);
 	    break;
+	case PAN_LOW:  // wheel and knob
+	    switch (type) {
+	      case MIDI_WHEEL:
+		if (isTransmitting()) {
+		    // TX panadapter affected
+		    transmitter->panadapter_low += val;
+		} else {
+		    active_receiver->panadapter_low += val;
+		}
+		break;
+	      case MIDI_KNOB:
+		if (isTransmitting()) {
+		    // TX panadapter: use values -100 through -50
+		    new = -100 + val/2;
+		    transmitter->panadapter_low =new;
+		} else {
+		    // RX panadapter: use values -140 through -90
+		    new = -140 + val/2;
+		    active_receiver->panadapter_low = new;
+		}
+		break;
+	      default:
+		// do nothing
+		// we should not come here anyway
+		break;
+	    }
+	    g_idle_add(ext_vfo_update, NULL);
+	    break;
 	case PRE:	// only key supported, and only CHARLY25
 	    if (filter_board == CHARLY25 && type == MIDI_KEY) {
 		//
@@ -353,120 +371,86 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
 		g_idle_add(ext_update_att_preamp, NULL);
 	    }
 	    break;
-	case ATT:	// Key for ALEX attenuator, wheel or knob for slider
-	    switch(type) {
-	      case MIDI_KEY:
-		if (filter_board == ALEX && active_receiver->adc == 0) {
-		  new=active_receiver->alex_attenuation + 1;
-		  if (new > 3) new=0;
-		  g_idle_add(ext_set_alex_attenuation, GINT_TO_POINTER(new));
-		  g_idle_add(ext_update_att_preamp, NULL);
-		}
+	case MIDI_PS: // only key supported
+#ifdef PURESIGNAL
+	    // toggle PURESIGNAL
+	    if (type == MIDI_KEY) {
+	      new=!(transmitter->puresignal);
+	      g_idle_add(ext_tx_set_ps,GINT_TO_POINTER(new));
+	    }
+#endif
+	    break;
+	case TX_DRIVE: // knob or wheel supported
+	    switch (type) {
+	      case MIDI_KNOB:
+		dnew = val;
 		break;
 	      case MIDI_WHEEL:
-		  new=adc_attenuation[active_receiver->adc] + val;
-		  if (new > 31) new=31;
-		  if (new < 0 ) new=0;
-		  dp=malloc(sizeof(double));
-		  *dp=new;
-		  g_idle_add(ext_set_attenuation_value,(gpointer) dp);
-		  break;
-	      case MIDI_KNOB:
-		new=(31*val)/100;
-		dp=malloc(sizeof(double));
-		*dp=new;
-		g_idle_add(ext_set_attenuation_value,(gpointer) dp);
+		dnew=transmitter->drive + val;
+		if (dnew < 0.0) dnew=0.0; if (dnew > 100.0) dnew=100.0;
 		break;
 	      default:
-		// do nothing
+		// do not change value
 		// we should not come here anyway
+		dnew=transmitter->drive;
 		break;
 	    }
+	    dp=malloc(sizeof(double));
+	    *dp=dnew;
+	    g_idle_add(ext_set_drive, (gpointer) dp);
 	    break;
-	case COMPRESS:
+	case RIT_TOGGLE:  // only key supported
+	    if (type == MIDI_KEY) {
+		// enable/disable RIT
+		new=vfo[active_receiver->id].rit_enabled;
+		vfo[active_receiver->id].rit_enabled = new ? 0 : 1;
+	        g_idle_add(ext_vfo_update, NULL);
+	    }
+	    break;
+	case RIT_STEP: // key or wheel supported
+	    // This cycles between RIT increments 1, 10, 100, 1, 10, 100, ...
 	    switch (type) {
+	      case MIDI_KEY:
+		// key cycles through in upward direction
+		val=1;
+		/* FALLTHROUGH */
 	      case MIDI_WHEEL:
-		dnew=transmitter->compressor_level + val;
-		if (dnew > 20.0) dnew=20.0;
-		if (dnew < 0 ) dnew=0;
+		// wheel cycles upward or downward
+		if (val > 0) {
+		  rit_increment=10*rit_increment;
+		} else {
+		  rit_increment=rit_increment/10;
+		}
+		if (rit_increment < 1) rit_increment=100;
+		if (rit_increment > 100) rit_increment=1;
+		break;
+	      default:
+		// do nothing
+		break;
+	    }
+	    g_idle_add(ext_vfo_update, NULL);
+	    break;
+	case RIT_VAL:	// wheel or knob
+	    switch (type) {
+	      case MIDI_WHEEL:
+		// This changes the RIT value incrementally,
+	  	// but we restrict the change to +/ 9.999 kHz
+		new = vfo[active_receiver->id].rit + val*rit_increment;
+		if (new >  9999) new= 9999;
+		if (new < -9999) new=-9999;
+		vfo[active_receiver->id].rit = new;
 		break;
 	      case MIDI_KNOB:
-		dnew=(20.0*val)/100.0;
+	 	// knob: adjust in the range +/ 50*rit_increment
+		new = (val-50) * rit_increment;
+		vfo[active_receiver->id].rit = new;
 		break;
 	      default:
-		// do not change
+		// do nothing
 		// we should not come here anyway
-		dnew=transmitter->compressor_level;
 		break;
 	    }
-	    transmitter->compressor_level=dnew;
-	    // automatically engange compressor if level > 0.5
-	    if (dnew < 0.5) transmitter->compressor=0;
-	    if (dnew > 0.5) transmitter->compressor=1;
-	    g_idle_add(ext_set_compression, NULL);
-	    break;
-	case MIDI_NB: // only key supported
-	    // cycle through NoiseBlanker settings: OFF, NB, NB2
-            if (type == MIDI_KEY) {
-	      if (active_receiver->nb) {
-		active_receiver->nb = 0;
-		active_receiver->nb2= 1;
-	      } else if (active_receiver->nb2) {
-		active_receiver->nb = 0;
-		active_receiver->nb2= 0;
-	      } else {
-		active_receiver->nb = 1;
-		active_receiver->nb2= 0;
-	      }
-	      g_idle_add(ext_vfo_update, NULL);
-	    }
-	    break;
-	case MIDI_NR: // only key supported
-	    // cycle through NoiseReduction settings: OFF, NR1, NR2
-	    if (type == MIDI_KEY) {
-	      if (active_receiver->nr) {
-		active_receiver->nr = 0;
-		active_receiver->nr2= 1;
-	      } else if (active_receiver->nr2) {
-		active_receiver->nr = 0;
-		active_receiver->nr2= 0;
-	      } else {
-		active_receiver->nr = 1;
-		active_receiver->nr2= 0;
-	      }
-	      g_idle_add(ext_vfo_update, NULL);
-	    }
-	    break;
-	case VOX: // only key supported
-	    // toggle VOX
-	    if (type == MIDI_KEY) {
-	      vox_enabled = !vox_enabled;
-	      g_idle_add(ext_vfo_update, NULL);
-	    }
-	    break;
-	case MIDI_CTUN: // only key supported
-	    // toggle CTUN
-	    if (type == MIDI_KEY) {
-	      new=active_receiver->id;
-	      if(!vfo[new].ctun) {
-		vfo[new].ctun=1;
-		vfo[new].offset=0;
-	      } else {
-		vfo[new].ctun=0;
-	      }
-	      vfo[new].ctun_frequency=vfo[new].frequency;
-	      set_offset(active_receiver,vfo[new].offset);
-	      g_idle_add(ext_vfo_update, NULL);
-	    }
-	    break;
-	case MIDI_PS: // only key supported
-#ifdef PURESIGNAL
-	    // toggle PURESIGNAL
-	    if (type == MIDI_KEY) {
-	      new=!(transmitter->puresignal);
-	      g_idle_add(ext_tx_set_ps,GINT_TO_POINTER(new));
-	    }
-#endif
+	    g_idle_add(ext_vfo_update, NULL);
 	    break;
 	case MIDI_SPLIT: // only key supported
 	    // toggle split mode
@@ -481,33 +465,53 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
 	      g_idle_add(ext_vfo_update, NULL);
 	    }
 	    break;
-	case VFO_A2B: // only key supported
+	case SWAP_RX:	// only key supported
+	    if (type == MIDI_KEY && receivers == 2) {
+		new=active_receiver->id;	// 0 or 1
+		new= (new == 1) ? 0 : 1;	// id of currently inactive receiver
+		active_receiver=receiver[new];
+		g_idle_add(menu_active_receiver_changed,NULL);
+		g_idle_add(ext_vfo_update,NULL);
+		g_idle_add(sliders_active_receiver_changed,NULL);
+	    }
+	    break;    
+	case SWAP_VFO:	// only key supported
 	    if (type == MIDI_KEY) {
-	      g_idle_add(ext_vfo_a_to_b, NULL);
+		g_idle_add(ext_vfo_a_swap_b,NULL);
 	    }
-	    break;
-	case VFO_B2A: // only key supported
+	    break;    
+	case MIDI_TUNE: // only key supported
 	    if (type == MIDI_KEY) {
-	      g_idle_add(ext_vfo_b_to_a, NULL);
+	        new = !tune;
+		g_idle_add(ext_tune_update, GINT_TO_POINTER(new));
+	    }
+	    break;    
+	case VFO: // only wheel supported
+	    if (type == MIDI_WHEEL && !locked) {
+		g_idle_add(ext_vfo_step, GINT_TO_POINTER(val));
 	    }
 	    break;
-	case MIDI_LOCK: // only key supported
+	case VFOA: // only wheel supported
+	case VFOB: // only wheel supported
+	    if (type == MIDI_WHEEL && !locked) {
+	        ip=malloc(2*sizeof(int));
+		*ip = (action == VFOA) ? 0 : 1;   // could use (action - VFOA) to support even more VFOs
+		*(ip+1)=val;
+		g_idle_add(ext_vfo_id_step, ip);
+	    }
+	    break;
+	case VFO_A2B: // only key supported
 	    if (type == MIDI_KEY) {
-	      locked=!locked;
-	      g_idle_add(ext_vfo_update, NULL);
+	      g_idle_add(ext_vfo_a_to_b, NULL);
 	    }
 	    break;
-	case AGCATTACK: // only key supported
-	    // cycle through fast/med/slow AGC attack
+	case VFO_B2A: // only key supported
 	    if (type == MIDI_KEY) {
-	      new=active_receiver->agc + 1;
-	      if (new > AGC_FAST) new=0;
-	      active_receiver->agc=new;
-	      g_idle_add(ext_vfo_update, NULL);
+	      g_idle_add(ext_vfo_b_to_a, NULL);
 	    }
 	    break;
-        case VFO_STEP_UP: // key or wheel supported
-        case VFO_STEP_DOWN:
+        case VFO_STEP_DOWN: // key or wheel supported
+        case VFO_STEP_UP:
 	    switch (type) {
 	      case MIDI_KEY:
 		new =  (action == VFO_STEP_UP) ? 1 : -1;
@@ -523,6 +527,13 @@ void DoTheMidi(enum MIDIaction action, enum MIDItype type, int val) {
 		break;
 	    }
             break;
+	case VOX: // only key supported
+	    // toggle VOX
+	    if (type == MIDI_KEY) {
+	      vox_enabled = !vox_enabled;
+	      g_idle_add(ext_vfo_update, NULL);
+	    }
+	    break;
 	case ACTION_NONE:
 	    // No error message, this is the "official" action for un-used controller buttons.
 	    break;
diff --git a/release/documentation/MIDI-manual.odt b/release/documentation/MIDI-manual.odt
index afc8c89..fae1bb9 100644
Binary files a/release/documentation/MIDI-manual.odt and b/release/documentation/MIDI-manual.odt differ
diff --git a/release/documentation/MIDI-manual.pdf b/release/documentation/MIDI-manual.pdf
index 8bebd77..b54a264 100644
Binary files a/release/documentation/MIDI-manual.pdf and b/release/documentation/MIDI-manual.pdf differ