// Zoom R16 LED driver // by Robin Peters 2023 // modified from, MIDIOX Toggle script // by Royce Craven 2022 // Based on Jamie's js example // in order for this to work you need to set the midi filter in MIDI-OX to filter out note-off events and set it to filter out the data as well as the printout. // This code is meant to run as 'end of chain' the midi data it outputs is not really useable except for running the LEDS. var mox; // This is the MidiOx object var n; // Numbers var Buttons = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; var RecButton = 0; var StopStart = 0; // Create a MidiOx object and assign it to mox mox = WScript.CreateObject("Midiox.MoxScript.1", "On_"); n = mox.InstanceCount; // Ask the MidiOx object if this in the only MidiOx currently running mox.DivertMidiInput = 1; // = 1 = yes - means that all Midi coming in will not be routed by the MidiOx Port Routing window // If you need the above start MidiOx before you run this script to create a separate scripted MidiOx mox.FireMidiInput = 1; // =1 = start processing incoming Midi. "Sometimes I get an error relating to this line, I usually just need to cycle the device connection" -Robin. if (n == 1) // If this is the only MidiOx currently running on this computer { mox.ShutdownAtEnd = 0} // then don't close it when we stop this script else { mox.ShutdownAtEnd = 1}; // else close this MidiOx WScript.Echo ( "R16 LED Driver - Press OK to end MidiOx Instance: " + n); // This is the window with a button to kill off the script // Loop Killed so finishing up - clean up and don't leave anything behind mox.FireMidiInput = 0; // Stop processing incoming Midi mox.DivertMidiInput = 0; // Process the Port routing window as normal mox = null; // Exit NOW Point ********************************************************** // Loop Routines //------------------------------------------ // This is where the loop will look for how to process the incoming Midi //------------------------------------------ //ts = time stamp //port = the Midi port it is sent to // -1 is every post the Midi-Ox Event Port is routed to // To find the port number start with -1 and run your script // Options / Midi Devices - look at the bottom left window to see the numbers // and the Port identifier in the Output window is 'COM' instead of 'MOX' //stat = Status, dat1 and dat2 are the data bytes //------------------------------------------ function On_MidiInput( ts, port, stat, dat1, dat2) { //var statraw; //Raw Status - without the channel message //var newCC; //CC message with the same channel as the NoteOn // Filter out unwanted Midi messages like Midi clock or Active message etc if (stat > 0xF0) {return}; statraw = stat & 0xF0; //Get rid of the Channel part as we what all channels newCC = 0xB0 + (stat & 0x0F); // extract the channel from stat and added to CC status if (statraw == 0x90 && dat1 >= 0x00 && dat1 < 0x18 && dat2 > 0) { if(Buttons[dat1] == 0) { //NOTE normally you would use -1 for all connected devices mox.OutputMidiMsg(-1, 0x90, dat1, 0x7F); // Turn the LED on. // drop the original message and put this out instead Buttons[dat1] = 1; //Sets the button state } else { mox.OutputMidiMsg( -1, 0x90, dat1, 0x00 ); // Turn the LED off // drop the original message and put this out instead Buttons[dat1] = 0 ; } } else if (statraw == 0x90 && dat1 == 0x5f && dat2 == 0x7f) { if (RecButton == 0) { mox.OutputMidiMsg(-1, 0x90, 0x5f, 0x7f); RecButton = 1; } else { mox.OutputMidiMsg(-1, 0x90, 0x5f, 0x00); RecButton = 0; } } else if (statraw == 0x90 && dat1 == 0x5d && dat2 == 0x7f) { mox.OutputMidiMsg(-1, 0x90, 0x5d, 0x7f); mox.OutputMidiMsg(-1, 0x90, 0x5e, 0x00); } else if (statraw == 0x90 && dat1 == 0x5e && dat2 == 0x7f) { mox.OutputMidiMsg(-1,0x90, 0x5d, 0x00); mox.OutputMidiMsg(-1, 0x90, 0x5e, 0x7f); } else // you might want to route other Midi messages through the COM (Midi-Ox Event Port) { mox.OutputMidiMsg( -1, stat, dat1, dat2 ); //echo the ones we are not interested in changing. } } //End of Midi In loop processing