Old 09-15-2019, 04:15 PM   #1
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 84
Default Get Note On or Off from within a script triggered by a MIDI Note

Does anyone know if it's possible to determine whether the MIDI message that triggered an action was an On or an Off? When setting an action trigger the MIDI trigger is "Note #" which is fine but I then need to determine from within the script whether it was an On or Off.

get_action_context() doesn't appear to have that information. At least not that I can find.

Thanks,
Ken
kenm is offline   Reply With Quote
Old 09-16-2019, 04:36 PM   #2
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 84
Default

Further testing shows that the only MIDI Note trigger is for Note On. This is confirmed by looking at the Actions keymap and seeing that the decimal value just after "KEY" is 144 which is Channel 1 Note On. (0x90)

Ken
kenm is offline   Reply With Quote
Old 09-17-2019, 10:46 AM   #3
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 84
Default Possible Workaround

This may not work for others but for my situation I'm going to create a JS FX plugin that sits on the Input of a track, receives the midi data, and calls the appropriate action based on Note On or Off.

I'll post the code once I get it working.

Ken
kenm is offline   Reply With Quote
Old 09-17-2019, 11:57 AM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 7,900
Default

Reaper Scripts are not intended to receive Midi Notes (Maybe there are certain workarounds).

One reason is that Reaper Scripts are (intended to be) "start once and stop" mode functions.

To do decent Mid work you need to do JSFX plugins.

-Michael
mschnell is offline   Reply With Quote
Old 09-17-2019, 12:20 PM   #5
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 84
Default

Thanks Michael. I came to the same conclusion as I started working on the JSFX code. At first I was going to just get the note data and then trigger a script action based on that but I've since realized that it's best just to do all of the work in the plugin. I have a little bit of Lua experience but know nothing about EEL2 so I guess it's time to dig in.

Ken
kenm is offline   Reply With Quote
Old 09-17-2019, 02:59 PM   #6
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 7,900
Default

The best/most efficient way to trigger a script from a JSFX is to have the JSFX generate a CC message and use the MidiToReaControlPath VST plugin to route that information into the guts of Reaper (i.e. from the OS thread that handles the track to Reaper's GUI thread), and then "Learn" an action to that control path message which in turn triggers the start of a script. The Script can use a Reaper API call to detect the value of the original CC message (but AFAIK, not the CC message number or the Midi channel).

You might want to take a look at some of the Midi utility JSFXes I posted in ReaPack as examples on how to handle Midi with EEL.

OTOH, MidiToReaControlPath already seems to be able to convert Note Midi messages to ControlPath messages. But I never tried this and don't know how it works.

-Michael

Last edited by mschnell; 09-17-2019 at 03:06 PM.
mschnell is offline   Reply With Quote
Old 09-17-2019, 05:33 PM   #7
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 84
Default

Thank you Michael! This is very helpful. I was stuck earlier today so I started reading forum posts on handling midi with JSFX plugins. Your DNA is all over those posts so, again, it's much appreciated.

I've started by creating a copy of MIDI logger and I'm adding my code to that. Once I get things working I'll move it to a new file but for now the MIDI logger provides a nice debug view of what's coming into my plugin.

I'm sure I'll have more questions down the road.

Ken
kenm is offline   Reply With Quote
Old 09-24-2019, 01:22 PM   #8
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 84
Default

Thanks to Robert Randolph's excellent JSFX tutorial I have a working plugin that takes note messages and converts them to CC messages with a value that can be used to indicate On or Off. It also has the option to output the CC messages on a different channel.

Here's a link to the tutorial: http://admiralbumblebee.com/music/20...m-scratch.html

I'll post the code once I get it cleaned up and properly commented.

Ken
kenm is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.