]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
added LEFTRIGHT keyword to midi.inp
authorc vw <dl1ycf@darc.de>
Thu, 24 Oct 2019 08:12:35 +0000 (10:12 +0200)
committerc vw <dl1ycf@darc.de>
Thu, 24 Oct 2019 08:12:35 +0000 (10:12 +0200)
midi.h
midi2.c

diff --git a/midi.h b/midi.h
index 3c9e8b0d8befce989ea87f3a0338703be7a30607..28156d6871ae3098fe56d6474d464f942ec4bbb9 100644 (file)
--- a/midi.h
+++ b/midi.h
@@ -166,6 +166,7 @@ struct desc {
    int               up_thr1;     // Wheel only: If controller value is <= this value, generate "          up  "
    int               up_thr2;     // Wheel only: If controller value is <= this value, generate "     fast up  "
    int               up_thr3;     // Wheel only: If controller value is <= this value, generate "very fast up  "
+   int               leftright;   // Wheel: if set, swap left/right or up/down; Knob: map 0-127 onto 127-0
    int              delay;       // Wheel only: delay (msec) before next message is given upstream
    enum MIDIaction   action;     // SDR "action" to generate
    struct desc       *next;       // Next defined action for a controller/key with that note value (NULL for end of list)
diff --git a/midi2.c b/midi2.c
index 3ac2eceb14fd779b4c330faa879c80dd95078a7b..e41484e7c83de03b57fc03a80a1029f8513e853a 100644 (file)
--- a/midi2.c
+++ b/midi2.c
@@ -39,6 +39,8 @@ void NewMidiEvent(enum MIDIevent event, int channel, int note, int val) {
                    if (desc->type == MIDI_KNOB) {
                        // normalize value to range 0 - 100
                        new = (val*100)/127;
+                       // LEFTRIGHT: swap min/max value
+                       if (desc->leftright) new=100-new;
                        DoTheMidi(desc->action, desc->type, new);
                    } else if (desc->type == MIDI_WHEEL) {
                        if (desc->delay > 0) {
@@ -55,6 +57,8 @@ void NewMidiEvent(enum MIDIevent event, int channel, int note, int val) {
                        if (val >= desc->up_thr1 ) new=1;
                        if (val >= desc->up_thr2 ) new=10;
                        if (val >= desc->up_thr3 ) new=100;
+                       // LEFTRIGHT: swap up/down
+                       if (desc->leftright) new=-new;
                        DoTheMidi(desc->action, desc->type, new);
                        last_wheel_action=desc->action;
                    }
@@ -63,6 +67,8 @@ void NewMidiEvent(enum MIDIevent event, int channel, int note, int val) {
                    if (desc->type == MIDI_KNOB) {
                        // normalize value to 0 - 100
                        new = (val*100)/16383;
+                       // possibly reverse scale
+                       if (desc->leftright) new=100-new;
                        DoTheMidi(desc->action, desc->type, new);
                    }
                    break;
@@ -157,7 +163,7 @@ void MIDIstartup() {
     int key;
     enum MIDIaction action;
     int chan;
-    int is_wheel;
+    int swap_lr;
     int lt3,lt2,lt1,ut1,ut2,ut3;
     int onoff, delay;
     struct desc *desc,*dp;
@@ -193,6 +199,7 @@ void MIDIstartup() {
       lt3=lt2=lt1=-1;
       ut3=ut2=ut1=128;
       onoff=0;
+      swap_lr=0;
       event=EVENT_NONE;
       type=TYPE_NONE;
       key=0;
@@ -221,6 +228,9 @@ void MIDIstartup() {
        // change type from MIDI_KNOB to MIDI_WHEEL
         type=MIDI_WHEEL;
       }
+      if ((cp = strstr(zeile, "LEFTRIGHT"))) {
+       swap_lr=1;
+      }
       if ((cp = strstr(zeile, "ONOFF"))) {
         onoff=1;
       }
@@ -229,7 +239,6 @@ void MIDIstartup() {
       }
       if ((cp = strstr(zeile, "THR="))) {
         sscanf(cp+4, "%d %d %d %d %d %d", &lt3, &lt2, &lt1, &ut1, &ut2, &ut3);
-        is_wheel=1;
       }
       if ((cp = strstr(zeile, "ACTION="))) {
         // cut zeile at the first blank character following
@@ -240,7 +249,8 @@ void MIDIstartup() {
       }
       if (event == EVENT_NONE || type == TYPE_NONE || key < 0 || key > 127) continue;
       // Now all entries of the line have been read. Construct descriptor
-//fprintf(stderr,"K=%d C=%d T=%d E=%d A=%d OnOff=%d THRs=%d %d %d %d %d %d\n", key,chan,type, event, action, onoff, lt3,lt2,lt1,ut1,ut2,ut3);
+//fprintf(stderr,"K=%d C=%d T=%d E=%d A=%d OnOff=%d LeftRight=%d THRs=%d %d %d %d %d %d\n",
+//               key,chan,type, event, action, onoff, swap_lr, lt3,lt2,lt1,ut1,ut2,ut3);
       desc = (struct desc *) malloc(sizeof(struct desc));
       desc->next = NULL;
       desc->action = action;
@@ -254,6 +264,7 @@ void MIDIstartup() {
       desc->up_thr1  = ut1;
       desc->up_thr2  = ut2;
       desc->up_thr3  = ut3;
+      desc->leftright= swap_lr;
       desc->channel  = chan;
       // insert descriptor
       if (event == MIDI_PITCH) {