Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 09-15-2019, 04:15 PM   #1
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
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: 115
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: 115
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: 14,687
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 online now   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: 115
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: 14,687
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 online now   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: 115
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: 115
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
Old 11-06-2022, 11:14 PM   #9
Michelob
Human being with feelings
 
Michelob's Avatar
 
Join Date: Sep 2010
Location: Mons, Belgium
Posts: 3,053
Default

Hi !

I'm a bit late here, but would you mind to post this very interesting jsfx code ?

Thanks,

Michel
Michelob is offline   Reply With Quote
Old 11-06-2022, 11:29 PM   #10
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

new additions to API related to retroactive record can read last triggered event so an action can theoretically knows by which midi event it was triggered (after some kind of fiktering messages).
mpl is offline   Reply With Quote
Old 11-07-2022, 01:19 AM   #11
Michelob
Human being with feelings
 
Michelob's Avatar
 
Join Date: Sep 2010
Location: Mons, Belgium
Posts: 3,053
Default

Hello MPL,

Thanks.

In fact, I'd need to trigger an action with Note On (kinda simple) and a different one with Note off (absolutely no idea how to do that).

Michel
Michelob is offline   Reply With Quote
Old 11-07-2022, 12:49 PM   #12
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

i don't think you can directly link action to noteoff, but there can be some tricky ways to do it. What action do yoh wabt to perform for noteon/off? Maybe there is an easier way to do what you want.
mpl is offline   Reply With Quote
Old 11-07-2022, 01:43 PM   #13
Michelob
Human being with feelings
 
Michelob's Avatar
 
Join Date: Sep 2010
Location: Mons, Belgium
Posts: 3,053
Default

Quote:
Originally Posted by mpl View Post
i don't think you can directly link action to noteoff, but there can be some tricky ways to do it. What action do yoh wabt to perform for noteon/off? Maybe there is an easier way to do what you want.
Yes I think so.

I'm using automation envelopes to record MIDI CCs. I know that's quite unusual, but I do this for year now and I love it.

Yesterday I bought an Icon Platform X+, which is great, and I'm trying a lot of things, taking my time to find the best way to use it.

For now, I have good results, and every fader moves the CC lanes.

As the faders are touch sensitive and you can program the note, I was thinking of some kind of automatic "select/deselect" when simply touching the faders, but for that, I needed to affect those 2 different actions to the note on and the note off that are triggered.

Today I changed my mind and I'm currently using SEL/MUTE/ARM buttons to interact with the CCs envelopes.

But now my problem is different as the workflow I built needs to always have the 8 envelopes visible to work.

But well, I think I'm kinda off topic here now

Thanks anyway,

Michel
Michelob 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 12:27 PM.


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