Old 02-16-2020, 01:12 PM   #1
iainduncan
Human being with feelings
 
Join Date: Jul 2011
Posts: 42
Default OSC into reascript? how to hook up actions?

Hi folks, I've figured out that in order for a reascript to "listen" for input I need to have it examine it's triggering action with get_action_context, and have it poll via defer. But I'm not clear yet (and haven't found good examples) on how I hook it up to listen to a range of incoming OSC messages so that get_action_context can get what I need. I'm intending to send input from Max/MSP, so I can make the OSC messages be whatever I want. Does anyone have examples you can point me at?

thanks!
iainduncan is offline   Reply With Quote
Old 02-16-2020, 02:07 PM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

You can not listen for MIDI or OSC in ReaScript.

You can get the MIDI-parameters, but only once per script-calling via get_action_context(which is what you probably try to do with polling).
OSC is impossible yet.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-16-2020, 03:00 PM   #3
iainduncan
Human being with feelings
 
Join Date: Jul 2011
Posts: 42
Default

Thanks Mespotine. I'm a bit confused, as I seem to be finding conflicting information in various places online. Is there no way at all to map one osc message to an action and get a dynamic value from it? The reaper API docs say get_action_context works with OSC actions, so what does it return then?

thanks for the help
iainduncan is offline   Reply With Quote
Old 02-16-2020, 03:17 PM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Hmm..you can map an OSC-message to an action as "shortcut", but that's all.

According to the docs about get_action_context:
https://mespotin.uber.space/Ultrasch...action_context

the retvals mode, resolution and val can hold values put into the script by MIDI/OSC.

However, I think this will work for OSC somewhat like MIDI, so the amount of values returned here should reflect, what MIDI would send.

You can toy around with MIDI first and see, how these three values change when running the script.

If that works, you can try to find a way, how mode, resolution and val can be triggered by OSC.

I personally think, that this has similarities to StuffMIDIMessage.
https://mespotin.uber.space/Ultrasch...uffMIDIMessage


Question is now: What kind of OSC-message could you send, that Reaper would interpret as mode, resolution and val?

Outside of that, you are out of luck. AFAIK, OSC-messages are strings but get_action_context doesn't return a string for that, as the only string returned is scriptfilename_with_path.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-16-2020, 03:21 PM   #5
iainduncan
Human being with feelings
 
Join Date: Jul 2011
Posts: 42
Default

Thanks for the help. I'm sending from Max, so really, I can send anything, and encode/decode it on either end. I've got a 14 bit value going in ok from listening to the pitch wheel, which is a start, but 14 bits is not much to work with for encoding. I can prob figure something hacky out (like sending pairs of messages I guess) but was hoping there was some way for my reascript to pick up a payload originating from max with enough bit depth to encode all the possible messages I want to send. If anyone knows of a way to just have my reascript pickup anything big from osc I'm all ears!

iain
iainduncan is offline   Reply With Quote
Old 02-16-2020, 03:22 PM   #6
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

If you can figure out something, please share it with us. Maybe you can find out, what we think is impossible.
Wouldn't be the first time in this forum
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-16-2020, 04:00 PM   #7
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Have you seen this?
https://www.cockos.com/reaper/sdk/osc/osc.php

You could set up a OSC device in Preferences > Control/OSC/web and then use a pattern config file (there are some factory ones in Reaper install/OSC folder) to make Reaper do stuff (skipping the ReaScript approach).
nofish is offline   Reply With Quote
Old 02-16-2020, 04:12 PM   #8
iainduncan
Human being with feelings
 
Join Date: Jul 2011
Posts: 42
Default

Thanks, yes I've seen it. The whole objective here is to get dynamic data into a reascript from Max/MSP though. I'm wondering if I can do this by having two osc messages sent:

- msg 1 goes into a control surface, and writes a payload somewhere
- msg 2 is a trigger to the reascript, which goes and reads the payload set by msg 1.

However, I don't really understand the syntax of the osc config files. Does anyone know:
-Is there a list somewhere of all the left hand (all caps) targets that we can write to?
- Is it possible to add our own?
- does my idea trigger a thought in anyone of "oh yeah, you could write to X and read from X in reascript?

I imagine there must have been some deep underlying architectural decisions that made this hard, or you would think it would have been simplified a while ago!

thanks for the tips
iainduncan is offline   Reply With Quote
Old 09-02-2020, 02:06 AM   #9
Distressor
Human being with feelings
 
Distressor's Avatar
 
Join Date: Mar 2017
Location: Berlin
Posts: 151
Default

Quote:
Originally Posted by iainduncan View Post
-Is there a list somewhere of all the left hand (all caps) targets that we can write to?
The Default.ReaperOSC list has all the targets that are available.

Quote:
Originally Posted by iainduncan View Post
-Is it possible to add our own?
Kind of... You can assign any OSC string to any function or script via the actions menu the same way you would assign a keyboard shortcut or MIDI message. As far as i know that's all.

I just hit the same wall. I thought i could send OSC messages from Max/MSP to a script and have the OSC string as a value. That would be an awesome feature.
It should be possible to encode the OSC string you want to send into 14bit MIDI and decode it in the script. I'm not a good coder but i'll give it a shot.
Distressor is offline   Reply With Quote
Old 09-02-2020, 02:16 PM   #10
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,688
Default

I also tried to send a parameter value via OSC to s script and failed (see some other forum thread).

I also vote for implementing and documenting this feature.
-Michael

Last edited by mschnell; 09-17-2021 at 02:30 PM.
mschnell is online now   Reply With Quote
Old 09-05-2020, 08:40 AM   #11
Ben Osterhouse
Human being with feelings
 
Join Date: Jan 2019
Posts: 51
Default

I made an OSC control surface in Reaper, and in the config file made these two paths:
n/posx/@
n/posy/@

Then sent OSC messages from Unreal Engine to Reaper like this:


It was my first time trying a defer loop, and it turns out if you send a continuous stream of OSC messages to an action, it doesn't just keep running the action a bunch of times, it actually seems to keep the action running, and updates the val, which is pretty cool!

[lua]
function move_item()
--set variables
item_name = "item0"
item_pos_seconds = 6
----------------------
local is_new_value,_,_,_,_,_,val = reaper.get_action_context()
if is_new_value == true then
value = (val / 16383) * item_pos_seconds
items = {}
num_media_items = reaper.CountMediaItems()
for i = 0, num_media_items - 1 do
items[i] = reaper.GetMediaItem(0, i)
take = reaper.GetTake(items[i], 0)
if reaper.GetTakeName(take) == item_name then
reaper.SetMediaItemInfo_Value(items[i], "D_POSITION", value)
end
end
end
reaper.defer(move_item)
end
move_item()
[/lua]

Here is what it does now: https://www.youtube.com/watch?v=EFlG...ature=youtu.be


I'm not sure this speaks exactly to what you are trying to do, but as an example it might give some hints maybe.
Attached Images
File Type: png actions window.png (35.8 KB, 169 views)
Ben Osterhouse is offline   Reply With Quote
Old 09-05-2020, 05:44 PM   #12
tdc
Human being with feelings
 
Join Date: Oct 2019
Location: Sydney
Posts: 471
Default

Quote:
Originally Posted by Ben Osterhouse View Post
LOL - I have felt that way whilst writing too!

Great integration ideas Ben.
tdc is offline   Reply With Quote
Old 09-06-2020, 06:03 PM   #13
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by Ben Osterhouse View Post
I made an OSC control surface in Reaper, and in the config file made these two paths:
n/posx/@
n/posy/@

Then sent OSC messages from Unreal Engine to Reaper like this:


It was my first time trying a defer loop, and it turns out if you send a continuous stream of OSC messages to an action, it doesn't just keep running the action a bunch of times, it actually seems to keep the action running, and updates the val, which is pretty cool!

[lua]
function move_item()
--set variables
item_name = "item0"
item_pos_seconds = 6
----------------------
local is_new_value,_,_,_,_,_,val = reaper.get_action_context()
if is_new_value == true then
value = (val / 16383) * item_pos_seconds
items = {}
num_media_items = reaper.CountMediaItems()
for i = 0, num_media_items - 1 do
items[i] = reaper.GetMediaItem(0, i)
take = reaper.GetTake(items[i], 0)
if reaper.GetTakeName(take) == item_name then
reaper.SetMediaItemInfo_Value(items[i], "D_POSITION", value)
end
end
end
reaper.defer(move_item)
end
move_item()
[/lua]

Here is what it does now: https://www.youtube.com/watch?v=EFlG...ature=youtu.be


I'm not sure this speaks exactly to what you are trying to do, but as an example it might give some hints maybe.
Hmm...so you don't have tons of scripts running or the "Terminate Instance"-dialog popped up at some time?
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 09-17-2021, 12:02 AM   #14
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Hey this is a very nice idea to get MIDI and OSC into a script (putting in the shortcut and getting it via get_action_context() )!!!

To answer Mespotine above, it doesnt tons of it on the background, which is great! (I mean it will have one on background per script not like many per script)
Although I think for what you are doing there are no reason to make it defer.

A small version of his/her script
Code:
function print(val)
    reaper.ShowConsoleMsg(tostring(val)..'\n')
end

function recive_midi_osc()
    --print('running')
    local is_new_value,_,_,_,_,_,val = reaper.get_action_context()
    if is_new_value == true then
        print('is_new_value:      '..tostring(is_new_value))
        print('val:      '..tostring(val))
    end
    reaper.defer(recive_midi_osc)
end

function fim()
    print('fim')
end

print('started')
recive_midi_osc()
reaper.atexit(fim)
Putting this sctipt to a MIDI/OSC shortcut It will start just once, and keep running recive_midi_osc() in defer loop. If value changes it print some messages. It will just end running the action again on the action window and it will ask to terminate.


----

An alternative is not put in a defer (at least for this scenario) so it will execute every time it receives an osc/midi call start do it thing(print) and terminate. (As a exemple just comment the reaper.defer(receive_midi_osc) line above)

How do I set an action shortcut to OSC?

Last edited by daniellumertz; 09-17-2021 at 12:23 AM.
daniellumertz is offline   Reply With Quote
Old 10-19-2021, 03:52 AM   #15
GameAudioRvlzzr
Human being with feelings
 
GameAudioRvlzzr's Avatar
 
Join Date: Apr 2016
Location: Stuttgart, Germany
Posts: 217
Default

Quote:
Originally Posted by Ben Osterhouse View Post
I made an OSC control surface in Reaper, and in the config file made these two paths:
n/posx/@
n/posy/@

Then sent OSC messages from Unreal Engine to Reaper like this:

Hi Ben, i'm trying to replicate what you did, with little success.

In the OSC Config file i have added the path "n/posx/@" like this:



Is this correct? Feels wrong since all other lines have a word before the path.

However, i DO get a value sent into reaper.
Here's what i get in the Listen-function of the OSC Device Setup page:



In the next step, i hit a wall:
I can't assign the OSC message as a shortcut for the action. When i press the trigger,
the assign shortcut function of reaper does nothing:



Can you please point me to what i'm doing wrong?
Micha
Attached Images
File Type: png reaper osc1 path.png (14.3 KB, 878 views)
File Type: png reaper osc1 listening.png (30.5 KB, 931 views)
File Type: png reaper osc1 shortcut.png (20.3 KB, 873 views)
GameAudioRvlzzr is offline   Reply With Quote
Old 10-19-2021, 04:20 AM   #16
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,688
Default

If you want to use the "Control Surface" functionality in Reaper,
Did you take a look at the CSI Reaper extension ?


If not wanting to use the "Control Surface" functionality in Reaper,
Did you take a look at ReaPack->ReaLearn ?

AFAIK, it can receive and send OSC and bind to Actions and parameter modulation.

-Michael
mschnell is online now   Reply With Quote
Old 10-19-2021, 06:06 AM   #17
GameAudioRvlzzr
Human being with feelings
 
GameAudioRvlzzr's Avatar
 
Join Date: Apr 2016
Location: Stuttgart, Germany
Posts: 217
Default

Quote:
Originally Posted by mschnell View Post
If you want to use the "Control Surface" functionality in Reaper,
Did you take a look at the CSI Reaper extension ?


If not wanting to use the "Control Surface" functionality in Reaper,
Did you take a look at ReaPack->ReaLearn ?

AFAIK, it can receive and send OSC and bind to Actions and parameter modulation.

-Michael
Hi Michael,
no i want neither. What i want is to send values via OSC to a Lua script i'm working on.
The part about actions is only a work-around to get there, as discussed earlier in this thread.
GameAudioRvlzzr is offline   Reply With Quote
Old 10-19-2021, 08:35 AM   #18
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by GameAudioRvlzzr View Post
Hi Ben, i'm trying to replicate what you did, with little success.

In the OSC Config file i have added the path "n/posx/@" like this:



Is this correct? Feels wrong since all other lines have a word before the path.

However, i DO get a value sent into reaper.
Here's what i get in the Listen-function of the OSC Device Setup page:



In the next step, i hit a wall:
I can't assign the OSC message as a shortcut for the action. When i press the trigger,
the assign shortcut function of reaper does nothing:



Can you please point me to what i'm doing wrong?
Micha
Look at your control surface settings windows, you forgot to check allow bindings to actions
daniellumertz is offline   Reply With Quote
Old 10-19-2021, 09:27 AM   #19
GameAudioRvlzzr
Human being with feelings
 
GameAudioRvlzzr's Avatar
 
Join Date: Apr 2016
Location: Stuttgart, Germany
Posts: 217
Default

Quote:
Originally Posted by daniellumertz View Post
Look at your control surface settings windows, you forgot to check allow bindings to actions
Of course!! So obvious -.-
Thank you Daniel!

I can trigger the action now, but... the value is always 0:



this is what i'm sending in on the device side, btw:

Attached Images
File Type: png osc reaper2 listener and log.png (8.1 KB, 853 views)
File Type: png osc reaper2 companion.png (4.4 KB, 846 views)
GameAudioRvlzzr is offline   Reply With Quote
Old 10-24-2021, 05:42 AM   #20
GameAudioRvlzzr
Human being with feelings
 
GameAudioRvlzzr's Avatar
 
Join Date: Apr 2016
Location: Stuttgart, Germany
Posts: 217
Default

Ok, for anyone trying to achieve a similar thing, i'll post what i found out:

I still get values transmitted to Reascript that are different from what i've sent in via OSC. Odd.
Every string or int value just comes out as zero on the other side, as written in my previous post. So, those are useless.
Only float values do come out, but strangely, a range of float 0.0 to 1.0 comes out as a range of 0 to 16384. So you send in 0.5, you get out 8192. Just divide by 16384 and you get the original value. But then it works! :-D Hoorray:

I was wondering why Ben in his Post was dividing by 16383. Seems to me you just accepted the oddity? Or can you explain?

Anyway, here's my script working: https://www.youtube.com/watch?v=uV5czfTnvRA
GameAudioRvlzzr is offline   Reply With Quote
Old 10-24-2021, 07:57 AM   #21
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Has been some time I tested osc. I had the same results. Also you can send inter between 0 and 16383 if I remember correctly.
daniellumertz is offline   Reply With Quote
Old 05-23-2023, 09:28 PM   #22
loupis45
Human being with feelings
 
Join Date: Jul 2016
Location: Karditsa, Greece
Posts: 20
Default

Quote:
Originally Posted by GameAudioRvlzzr View Post
Ok, for anyone trying to achieve a similar thing, i'll post what i found out:

I still get values transmitted to Reascript that are different from what i've sent in via OSC. Odd.
Every string or int value just comes out as zero on the other side, as written in my previous post. So, those are useless.
Only float values do come out, but strangely, a range of float 0.0 to 1.0 comes out as a range of 0 to 16384. So you send in 0.5, you get out 8192. Just divide by 16384 and you get the original value. But then it works! :-D Hoorray:

I was wondering why Ben in his Post was dividing by 16383. Seems to me you just accepted the oddity? Or can you explain?

Anyway, here's my script working: https://www.youtube.com/watch?v=uV5czfTnvRA
Nice work! where can i found your script? i want to make something similar and i thing it's a perfect starter point. Thanks
loupis45 is offline   Reply With Quote
Old 05-24-2023, 05:55 PM   #23
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

well this thread have been brought up again, so just an update the most updated way to send/receive OSC nowadays is using

mavirq Batteries(have many lua modules including luasockets and luaseq) (Windows and MacOS only): https://forums.cockos.com/showthread.php?t=267360


or


mavriq Sockets(just the luasockets module for Windows,MacOS,Linux) https://forums.cockos.com/showthread.php?t=265912
daniellumertz is offline   Reply With Quote
Old 06-01-2023, 03:19 AM   #24
GameAudioRvlzzr
Human being with feelings
 
GameAudioRvlzzr's Avatar
 
Join Date: Apr 2016
Location: Stuttgart, Germany
Posts: 217
Default

Quote:
Originally Posted by loupis45 View Post
Nice work! where can i found your script? i want to make something similar and i thing it's a perfect starter point. Thanks
Here you go, hope it helps.
Show your work please if you do something with this, always interesting to see other people's projects.

Code:
function receive_midi_osc()

-- This function listens for OSC messages coming into reaper. 
-- The OSC message you send has to be a float value between 0.0 and 1.0.
-- For some reason, a float value of 1.0 sent as OSC will come out in Reaper not as 1.0 but as an int value of 16384.

-- I use the Streamdeck hardware controller that has buttons. I make Button 1 send an OSC value of 0.01, Button 2 sends 0.02 etc... so i could use up to 100 buttons (with the range of 0.0 to 1.0 available)
-- When i press Button 1, the code below receives a strange number but divides it by 163, resulting in the value 1 being assigned to ButtonPressed in code line 3.

-- In short: Just divide the number you want ButtonPressed to be by 100 and send that in from the Streamdeck via OSC.

    local is_new_value,_,_,_,_,_,val = reaper.get_action_context()
    if is_new_value == true then    
        ButtonPressed = math.floor(val/163)
    selectButton(GuiButtons[ButtonPressed], ButtonPressed)
    end
 
    reaper.defer(receive_midi_osc)
end

function selectButton(self, id)
  print("Button selected: ",tostring(id))
end

In the companion editor, i have these settings for Button 1:

Attached Images
File Type: png Reaper OSC.png (14.1 KB, 387 views)

Last edited by GameAudioRvlzzr; 06-01-2023 at 03:23 AM. Reason: added info
GameAudioRvlzzr is offline   Reply With Quote
Old 08-13-2023, 04:08 AM   #25
GameAudioRvlzzr
Human being with feelings
 
GameAudioRvlzzr's Avatar
 
Join Date: Apr 2016
Location: Stuttgart, Germany
Posts: 217
Default

Quote:
Originally Posted by loupis45 View Post
Nice work! where can i found your script? i want to make something similar and i thing it's a perfect starter point. Thanks
Was it of any help?
GameAudioRvlzzr is offline   Reply With Quote
Old 08-13-2023, 04:40 AM   #26
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

Since REAPER 6.71 (or better 6.77) you can map each controller to single script and the use something like:

Code:
is_new_value,filename,sectionID,cmdID,mode,resolution,val,contextstr = reaper.get_action_context()

map = {
{address='/2/fader1',func = function() reaper.ShowConsoleMsg(os.date()..' fader 1 tweaked'..'\n') end},
{address='/2/fader6',func = function() reaper.ShowConsoleMsg(os.date()..' fader 6 tweaked'..'\n') end},
}

for i = 1, #map do
  if contextstr:match('osc%:('..map[i].address..')%:') then map[i].func() end
end
mpl is offline   Reply With Quote
Old 03-22-2024, 05:45 AM   #27
Mr.X
Human being with feelings
 
Join Date: Jun 2011
Posts: 93
Default

Quote:
Originally Posted by mpl View Post
Since REAPER 6.71 (or better 6.77) you can map each controller to single script
Could you explain the process of how to map a controller to a script?
Mr.X is offline   Reply With Quote
Old 03-25-2024, 07:07 AM   #28
Mr.X
Human being with feelings
 
Join Date: Jun 2011
Posts: 93
Default

Does anyone know of a way to reach user mpl? It seems like he might actually be the only person on the planet that knows the secret of how to attach a script to incoming OSC messages!
He is not accepting private messages.
Mr.X 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:23 PM.


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