HID to Program Change, there is more than one way to do it

Post your groups/layouts here

Moderators: davidv, seb@plogue

JensJohansson
Posts: 42
Joined: Sun Nov 04, 2012 10:48 am
Contact:

HID to Program Change, there is more than one way to do it

Postby JensJohansson » Thu Jun 15, 2017 3:22 am

Especially when i have these kind of problems that have very convoluted solutions in pure Bidule, I reach for Jesusonic.

I use the win32 version (ReaJS) that's included in ReaPlugs. It's unfortunately Yet Another Language with some strange quirks, but once you learn it etc. I don't think there is a Mac version that works as a plug, unfortunately.

Anyway the upshot is that you have to install ReaJS and for pure MIDI plugins I recommend setting up a separate MIDI processing DLL per the ReaJS documentation. Note that Bidule has to be started as Administrator to be able to write the source files (they are just .txt files) to ReaJS's directory (in my case "C:\Program Files (x86)\steinberg\VSTPlugins\ReaPlugs\JS\Effects")

I figured I would share the idea of using Jesusonic, here is a JS script that converts the MIDI output from Bidule's HID to MIDI module, to Program Change events. I had to finally write this because British Airways lost my normal controller, so i had to use one which doesn't send PC events.

This is a typical example of something that quickly becomes a violently bad nightmare to try to implement natively.

It traps the keys 0-9, enter and "," from the num keypad. One or two digits plus enter sends the corresponding program change. The "," key clears the input. Implementing full 3 digit PC sending is left as an exercise for the reader.

Code: Select all

desc:HID to MIDI in, PC out
@init

//
// JJ 20170614
//

prevprevkey = -2;
prevkey = -2;

@block
while ( // while
   midirecv(ts,msg1,msg23);
   msg1 > 0 ? status = msg1 & 0xF0;
   
   msg1 ? ( // ?1 is there a message

      msg1 > 0 ? (
         status = msg1&0xF0; chan = msg1&0x0F;
         msg2 = msg23&0xFF; msg3 = (msg23/256) & 0xFF;
      );

// note, these status vars just catch the relevant messages by being 1.

      is_noteon = is_noteoff = is_pc = 0;
      msg_passthru = 1;

      is_noteon =  (status == 0x90) && (msg3 > 0) ;
      is_noteoff =  (status == 0x80) || ( (status == 0x90) && (msg3 == 0) ) ;
      is_pc = ((status == 0xC0));
      is_cc = ((status == 0xB0));


// if it was a 'relevant message': flag that we don't pass it on,
// cause we process it instead.
//      (noteon||noteoff||pc) ? msg_passthru = 0;

// actually, we don't pass anything thru here.
      msg_passthru = 0;

      is_noteon ? (
        key = -2;
        msg2 == 81 ? key = 0;

        msg2 == 78 ? key = 1; msg2 == 79 ? key = 2; msg2 == 80 ? key = 3;
        msg2 == 74 ? key = 4; msg2 == 75 ? key = 5; msg2 == 76 ? key = 6;
        msg2 == 70 ? key = 7; msg2 == 71 ? key = 8; msg2 == 72 ? key = 9;

        msg2 == 89 ? key = -1; // -1 signifies "enter" -- meaning "execute PC"
 
        msg2 == 82 ? key = 10; // 10 signifies ","  -- meaning "clear"
     
        key == 10 ? prevprevkey = prevkey = key = -2;

      ) : (key = -2) ; // is_noteon


      // key now may have -2 or a value

      key != -2 ? (  // key != -2, a relevant key was pressed

        pc = -1;


        key == -1 ? (  // "enter" was hit
          prevprevkey < 0 ? prevprevkey = 0;  // single digit + enter is possible
          prevkey >= 0 ? (
            pc = prevprevkey * 10 + prevkey;
            pc = pc - 1;
            pc < 0 ? pc = 0;
          );
          prevprevkey = prevkey = key = -2;
        ); // end key -1


        pc != -1 ? (
          midisend(ts, 0xC0, pc);
          prevprevkey = prevkey = key = -2;
        ); // end ?pc -1

        prevprevkey = prevkey;
        prevkey = key;
       
      ); // end relevant key was pressed

// if there was a message, and it should be passed on-- then pass it on
      (msg1 && msg_passthru) ? midisend(ts,msg1,msg23);

 // if there was a message keep looping to get next one
      msg1;

  ); // end ?1 is there a message

); // while


@sample


reezekeys
Posts: 411
Joined: Wed Mar 08, 2006 11:06 pm
Location: New York

Re: HID to Program Change, there is more than one way to do it

Postby reezekeys » Thu Jun 22, 2017 7:12 am

For those without Jesusonic, I did a similar Bidule group about seven years ago. It doesn't output program changes, just values from 0 to 99 and a trigger when the value changes.

viewtopic.php?f=8&t=4970&p=26838


Return to “Bidule Layouts”

Who is online

Users browsing this forum: No registered users and 2 guests