Author |
Topic: Help Needed with NRPN to CC Script (Read 1873 times) |
|
abhunkin
Member
 
 MIDI-OX Rules!

Posts: 35
|
 |
Help Needed with NRPN to CC Script
« on: Oct 14th, 2005, 5:48pm » |
Quote Modify
|
I'd really appreciate some help getting started on a Jscript that does essentially the opposite of Breath2NRPN.js. I need to take a 4-message incoming set of NRPN's on channel 16, at NRPN=500, that inputs MSB values of either 0 or 16256 (the LSB is ignored); and outputs on channel 1 a controller 30 value incremented by 1 if the input (MSB) is 0, or decremented by 1 if the input (MBS) is 16256. Furthermore the output range must be constrained to 0-127, and its initial value is 0. The script should run while MIDIOx is open. Can someone help get me started? (I'm trying to get the Studiomix rotary encoders translated to CC's) TIA - Art Hunkins abhunkin@uncg.edu
|
|
IP Logged |
Art Hunkins abhunkin@uncg.edu http://www.arthunkins.com
|
|
|
Jamie OConnell
Administrator
    


Gender: 
Posts: 2027
|
 |
Re: Help Needed with NRPN to CC Script
« Reply #1 on: Oct 15th, 2005, 12:18pm » |
Quote Modify
|
Quote:I need to take a 4-message incoming set of NRPN's on channel 16, at NRPN=500, that inputs MSB values of either 0 or 16256 (the LSB is ignored); and outputs on channel 1 a controller 30 value incremented by 1 if the input (MSB) is 0, or decremented by 1 if the input (MBS) is 16256. |
| For NRPN = 500 (decimal?) you'll get MSB = 3 (CC=99), LSB = 116 (CC=98). You'll then get either a "Data Entry" (CC=6, CC=38), or "Data Increment" (CC=96) or "Data Decrement" (CC=97) to change the value of the NRPN. Each CC controller value can only be in the range of 0-127, so to get a range of 0 - 16383, you need to look at both the MSB CC (6) and the LSB CC (38) and combine them using the formula: value = MSB * 128 + LSB Further complicating NRPN's is the requirement to store and detect when you've received both the MSB AND LSB of both the NRPN and the combined CC's. Otherwise you may be acting on only partial data. Once the NRPN is set though (you've received both the MSB and LSB of the NRPN number), a device can continually change the NRPN value using Data Entry and Data Increment/Decrement. If another NRPN or RPN is received however, it invalidates everything, and you must start redetection.
|
« Last Edit: Oct 15th, 2005, 12:18pm by Jamie OConnell » |
IP Logged |
--Jamie Music is its own reward.
|
|
|
abhunkin
Member
 
 MIDI-OX Rules!

Posts: 35
|
 |
Re: Help Needed with NRPN to CC Script
« Reply #2 on: Oct 15th, 2005, 3:45pm » |
Quote Modify
|
Thanks for the reply, Jamie. Yes, the NPRN is 500 decimal, and the Studiomix rotary encoders don't use INC and DEC, but rather Data Entries of 1 (for an increment) and 16383 (for a decrement) - both decimal. It doesn't use running status either, so the four NRPN's are sent each time. I believe the fourth message can be safely ignored and the MSB simply tested against 0 (for the increment) and 127 (or is it 16256? - for the decrement). No other values than those two are sent by Studiomix. Your second paragraph nicely sums up the issue: how do you capture and save 3-4 messages before doing the conversion to CC (by incrementing/decrementing the previously saved value)? I assume I need a loop that tests for NPRN = 500dec, and if true increments or decrements CC 30's value depending on the MSB of the NPRN. Can you show me a subroutine that will do this? (I assume it can be done in Jscript.) Thanks for your suggestions. Art Hunkins
|
|
IP Logged |
Art Hunkins abhunkin@uncg.edu http://www.arthunkins.com
|
|
|
Jamie OConnell
Administrator
    


Gender: 
Posts: 2027
|
 |
Re: Help Needed with NRPN to CC Script
« Reply #3 on: Oct 15th, 2005, 4:56pm » |
Quote Modify
|
Quote:Yes, the NPRN is 500 decimal, and the Studiomix rotary encoders don't use INC and DEC, but rather Data Entries of 1 (for an increment) and 16383 (for a decrement) - both decimal. |
| Be aware that the MIDI Status window translates and combines NRPN Number and NRPN Value for you -- according to the formula I specified earlier. To see the actual messages you need to look at the Monitor Window. MIDI cannot specify a value larger than 127 in a single message except for Pitch Bend and Key Aftertouch (each of those specify 14 bit values split between 2 bytes of 0 - 127).
|
|
IP Logged |
--Jamie Music is its own reward.
|
|
|
abhunkin
Member
 
 MIDI-OX Rules!

Posts: 35
|
 |
Re: Help Needed with NRPN to CC Script
« Reply #4 on: Oct 15th, 2005, 7:07pm » |
Quote Modify
|
Yes, I've been watching (and learning from) the Monitor Window. It's a great tool to find out the MIDI messages various hardware is putting out. From my observations so far, I think it is sufficient in my processing loop to identify the NRPN (using the first two messages), then check CC6 (MSB) for 0 or 127 - forgetting about CC38 (LSB). If CC6 is 0, increment CC30 out; if 127, decrement CC30 out. Is it possible to do this entirely within a single While (mox.ShouldExitScript = 0) loop? (I'm busy struggling through Jscript.) Thanks much - Art Hunkins
|
|
IP Logged |
Art Hunkins abhunkin@uncg.edu http://www.arthunkins.com
|
|
|
abhunkin
Member
 
 MIDI-OX Rules!

Posts: 35
|
 |
Re: Help Needed with NRPN to CC Script
« Reply #5 on: Oct 20th, 2005, 2:34pm » |
Quote Modify
|
Jamie, I've managed to learn VBscript fairly well, and was able successfully to implement the above project. It took a number of steps. I first wrote an .oxm that converted 4-message NRPN's to a single (coded) CC message. MIDIOx is good at this; it just can't remember values and do the necessary arithmetic to update these values by +/- 1. So I wrote the VBscript to do this. A script, OTOH, as you pointed out, would have a very hard time converting the 4-message NRPN's to single CC's; nevertheless doing simple math and keeping running values are quite elementary. (I tried doing the conversion in a script; I'm convinced it *could* be done, but only at great length and incredible effort.) The remaining issue is operational complexity. Here's what is required to run the process: 1) Open one instance of MIDIOx, set it to no mapping, input = Junction1, output = Junction2. 2) Open a second instance of MIDIOx, set it for mapping and load in the .oxm file mentioned above, input = my sound card, output = Junction1. 3) Click/start the script (which attaches to the first instance of MIDIOx, but is actually second in the chain). Whew! So here come's a feature request - one that I think has been brought up on the forum already (though I can't locate it): Is there any chance for a MIDIOx option to run scripts *after* mapping rather than always before? That would cut out fully half the steps outlined above, including the second instance of MIDIOx - which is *only* there so that the script can run after the .oxm. I should think there would be a number of cases, like this, where users would like to access and process MIDI data *after* MIDIOx does its thing, rather than before. (I see one possible issue: should the Midi Monitor display data before or after the script? I've no opinion on this, but perhaps there could be a switch to allow either. OTOH, perhaps this would make for unnecessary complication.) I plan to write up this work and send it on to you, as well as posting it to the Csounds.com site. If you'd consider the above feature for MIDIOx, I'd certainly want to write up the materials with this in mind. TIA - Art Hunkins
|
|
IP Logged |
Art Hunkins abhunkin@uncg.edu http://www.arthunkins.com
|
|
|
Jamie OConnell
Administrator
    


Gender: 
Posts: 2027
|
 |
Re: Help Needed with NRPN to CC Script
« Reply #6 on: Oct 20th, 2005, 4:17pm » |
Quote Modify
|
Quote:I first wrote an .oxm that converted 4-message NRPN's to a single (coded) CC message. MIDIOx is good at this; it just can't remember values and do the necessary arithmetic to update these values by +/- 1. |
| That has been requested a lot, and I am currently looking into ways that that might be accomplished. It wouldn't be that hard to do for ALL inputs together -- using it in conjunction with the MIDI Status window; but I think that people would need to do it on a port by port basis ultimately. Quote:Is there any chance for a MIDIOx option to run scripts *after* mapping rather than always before? |
| Unfortunately, that isn't the way COM or WSH operates: the WSH script itself launches MIDI-OX and then attaches to it. So any RAW data is seen by the script before any mapping is performed. It might be possible to add another codepath at the very lowest level of the application to do the mapping before handing the data to the COM interface. That would require another programmable COM function 'switch' in a future version of the COM interface.
|
« Last Edit: Oct 20th, 2005, 4:19pm by Jamie OConnell » |
IP Logged |
--Jamie Music is its own reward.
|
|
|
Peter L Jones
Expert
    

Hit it
Gender: 
Posts: 978
|
 |
Re: Help Needed with NRPN to CC Script
« Reply #7 on: Oct 20th, 2005, 5:05pm » |
Quote Modify
|
In an ideal world, MIDI OX would be able to use a script as a mapping rule (i.e. calling the script from MIDI OX, rather than the other way around)...
|
|
IP Logged |
"...Playing fast around the drums is one thing. But to play with people for others, to listen to, that's something else. That's a whole other world." -- Tony Williams
|
|
|
abhunkin
Member
 
 MIDI-OX Rules!

Posts: 35
|
 |
Re: Help Needed with NRPN to CC Script
« Reply #8 on: Oct 20th, 2005, 10:59pm » |
Quote Modify
|
Jamie, Sounds like your ideas might make it possible at some point to do my project in a single instance of MIDIOx with or without a script. Mark me down as really interested in such features. I'll be checking back periodically for further developments. Meanwhile, I'll write up what I've done until now. Art Hunkins
|
|
IP Logged |
Art Hunkins abhunkin@uncg.edu http://www.arthunkins.com
|
|
|
|