Old 08-29-2019, 06:25 AM   #1
Distressor
Human being with feelings
 
Distressor's Avatar
 
Join Date: Mar 2017
Location: Berlin
Posts: 103
Default Use CC action inside script

Is it possible to use a Midi CC dependant action inside a script?

Like "View: Move edit cursor (MIDI CC/OSC only - relative recommended)"

Basically take the value of this:
is_new_value, filename, sectionID, cmdID, mode, resolution, val = reaper.get_action_context()
and pass it on to this:
reaper.Main_OnCommandEx(996, 0, 0)
Distressor is offline   Reply With Quote
Old 08-29-2019, 06:42 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,783
Default

Why not move the edit cursor using the API?
cfillion is online now   Reply With Quote
Old 08-29-2019, 07:18 AM   #3
Distressor
Human being with feelings
 
Distressor's Avatar
 
Join Date: Mar 2017
Location: Berlin
Posts: 103
Default

Because this function is already done so why spend time writing it again?
I actually tried it but the results were not as smooth as the action.

If you have some lua code that does exactly the same as the action i'd love to get my hands on it .

Also this idea is not limited to the cursor movement action. There's quite a few actions that react to midi values.

Last edited by Distressor; 08-29-2019 at 07:23 AM.
Distressor is offline   Reply With Quote
Old 08-29-2019, 07:31 AM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,783
Default

To move the edit cursor a set amount of time relative to its current position:

Code:
reaper.MoveEditCursor(2, false) -- two seconds ahead
To move it to an absolute time position instead:

Code:
reaper.SetEditCurPos(2, true, false) -- move the edit cursor to 00:02.000
cfillion is online now   Reply With Quote
Old 08-29-2019, 07:44 AM   #5
Distressor
Human being with feelings
 
Distressor's Avatar
 
Join Date: Mar 2017
Location: Berlin
Posts: 103
Default

I wrote this to emulate the action (plus keeping the cursor centred):

function main()
local z = reaper.GetHZoomLevel()
local is_new_value, filename, sectionID, cmdID, mode, resolution, val = reaper.get_action_context()
local cursor = reaper.GetCursorPosition()
reaper.MoveEditCursor(val/z,0)
local arr_start, arr_end = reaper.GetSet_ArrangeView2(0, false, 0,0)
reaper.GetSet_ArrangeView2(0, true, 0,0, cursor-((arr_end-arr_start)/2), cursor+((arr_end-arr_start)/2))
end

It works and is not terribly slow but the action is still smoother.

So Midi CC dependant actions can't be used in scripts?


By the way.. how do i insert that code box in the forum post?
Distressor is offline   Reply With Quote
Old 08-29-2019, 07:56 AM   #6
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,059
Default

Quote:
Originally Posted by Distressor View Post
By the way.. how do i insert that code box in the forum post?
By using [_code] [_/code] tags (without the underscores).
https://forum.cockos.com/misc.php?do=bbcode#code
nofish is offline   Reply With Quote
Old 08-29-2019, 08:00 AM   #7
Distressor
Human being with feelings
 
Distressor's Avatar
 
Join Date: Mar 2017
Location: Berlin
Posts: 103
Default

Nice. Many thanks for the info.
Distressor 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 04:39 PM.


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