|
||
|
Title: Example of jScript: NoteOn toggle Post by Breath on Jul 10th, 2022, 11:45pm I have often been asked about how to use Midi to turn something on or off with the same message. That would mean that MidiOx would have to remember if that message had come in before. MidiOx data map can't do that, but a script can. Here is an script in jScript (Microsoft built in interpreter) example where pressing Middle C (C4) mutes the same channel as the note came in by (CC7 =0) Pressing C4 again sets CC7 to the velocity of the C4 note. ie turns the volume back on. You could add to this to set up a real time controller of several keys in one area of the keyboard to mute different channels of, say, a sequencer. https://bwalk.com.au/pub/RPC_ToggleNote2CC.js 1) Download the code and press Ctrl A to select all the text and press Ctrl C to copy 2) Paste in an editor (Notepad++ is a good free editor that will colour the code to make it more understandable). 3) Save the text file as "RPC_noteOn2Mute.js" 4) Go to where you have saved it and double click on the name to start the script 5) a new MidiOx will popup (if MidiOx is already running this script will use this) - make sure your keyboard's Midi input and output can be seen on the MIDI Port Routing window. - connect the MidiOX Event Port to your synth Midi port on the right side (Midi Out). 6) play some notes (NOT Middle C - note 60) to see the data being sent - play Middle C and MidiOx will put out CC7 value 0 and mute you synth - play other notes to check it is muted - play middle C again and CC7 will be put out again with a value of the velocity of Middle C just played 5) Click OK on the small dialog that just popped up to stop it all. Let me know if this is useful. All the best Royce |
||
|
Title: Re: Example of jScript: NoteOn toggle Post by Breath on Mar 7th, 2026, 7:37pm It seems that some folk are being blocked from downloading the script file. This is understandable as it could run something undesirable. Here is a text version "MIDIOX Toggle Script" that you can read (and see that there is nothing dangerous) and Ctrl A to select all, then Ctrl C to copy to the clipboard and then you can paste it into your favorite text editor. All the best Royce |
||
|
Title: Re: Example of jScript: NoteOn toggle Post by Breath on Mar 7th, 2026, 7:38pm // MIDIOX Toggle script // by Royce Craven 2022 // Based on Jamie's js example // This script is an example of using JScript with MIDI-OX // It converts a single NoteOn event into CC7 message, // turning the volume on or off with repeated C4 (Note 60) and // uses the velocity to set the volume level when it is turned on. var mox; // This is the MidiOx object var n; // Numbers var DoIt = 1; // Toggle state // set this so the first C4 note mutes the channel (CC7 = 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 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 ( "RPC- NoteOn Toggle Example - 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 //------------------------------------------ // We convert C4 NoteOn to a CC7 message and set the value to 0 or the NoteOn velocity //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 // what message do we ant to change ? if (statraw == 0x90 && dat1 == 60 && dat2 > 0) // NoteOn Middle C (NoteOn velocity 0 is really NoteOff) { if(DoIt == 1) //Mute { //NOTE normally you would use -1 for all connected devices mox.OutputMidiMsg( -1, newCC, 0x07, 0x00 ); // Mute the current keyboard channel // drop the original message and put this out instead DoIt = 0 ; //set it so the next middle C turns it back on } else //DoIt is 0 : turn up the volume { mox.OutputMidiMsg( -1, newCC, 0x07, dat2 ); // Turn the volume up based on the velocity // drop the original message and put this out instead DoIt = 1 ; //set it so the next middle C mutes it again } } 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 } |
||
|
MIDI-OX User Forum » Powered by YaBB 1 Gold - SP 1.3.1! YaBB © 2000-2003. All Rights Reserved. |