Old 02-07-2020, 07:35 AM   #1
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 136
Default connect 2 actions in one script

Hello
How can I connect this two actions?

action(41305)Item edit: Trim left edge of item to edit cursor
only left of the middle of the selected item

action(41311)Item edit: Trim right edge of item to edit cursor
only right of the middle of the selected item

Code:
--     curpos = reaper.GetCursorPosition()
--  start_pos = reaper.GetMediaItemInfo_Value(it, 'D_POSITION')
--        len = reaper.GetMediaItemInfo_Value(it, 'D_LENGTH')
--     curmid = start_pos + len/2
       
if curpos<curmid then
    --Item edit: Trim left edge of item to edit cursor
      reaper.Main_OnCommand(41305,1)
else
    --Item edit: Trim right edge of item to edit cursor  
      reaper.Main_OnCommand(41311,1)
Thank you very much

Last edited by Dragonetti; 02-07-2020 at 07:40 AM.
Dragonetti is online now   Reply With Quote
Old 02-07-2020, 09:17 AM   #2
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,370
Default

Like this?

Code:
it =  reaper.GetSelectedMediaItem(0, 0) -- get first sel. item
if it == nil then return end
curpos = reaper.GetCursorPosition()
start_pos = reaper.GetMediaItemInfo_Value(it, 'D_POSITION')
len = start_pos + reaper.GetMediaItemInfo_Value(it, 'D_LENGTH')
curmid = start_pos + len/2
       
if curpos<curmid then
    --Item edit: Trim left edge of item to edit cursor
      reaper.Main_OnCommand(41305,1)
else
    --Item edit: Trim right edge of item to edit cursor  
      reaper.Main_OnCommand(41311,1)
end
nofish is offline   Reply With Quote
Old 02-07-2020, 11:18 AM   #3
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 136
Default

very fast
thank you
but len = only length
Code:
it =  reaper.GetSelectedMediaItem(0, 0) -- get first sel. item
if it == nil then return end
curpos = reaper.GetCursorPosition()
start_pos = reaper.GetMediaItemInfo_Value(it, 'D_POSITION')
len = reaper.GetMediaItemInfo_Value(it, 'D_LENGTH')
curmid = start_pos + len/2
       
if curpos<curmid then
    --Item edit: Trim left edge of item to edit cursor
      reaper.Main_OnCommand(41305,1)
else
    --Item edit: Trim right edge of item to edit cursor  
      reaper.Main_OnCommand(41311,1)
end
Dragonetti is online now   Reply With Quote
Old 02-07-2020, 11:52 AM   #4
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,370
Default

Ah right, sorry.
Donation received, thanks a lot.
nofish is offline   Reply With Quote
Old 02-08-2020, 03:57 AM   #5
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 136
Default

Is there a way to get this script toggle state (on/off)?
Dragonetti is online now   Reply With Quote
Old 02-08-2020, 01:22 PM   #6
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,885
Default

Get the toggle-state:
https://mespotin.uber.space/Ultrasch...leCommandState

Set the toggle-state:
https://mespotin.uber.space/Ultrasch...leCommandState
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 02-09-2020, 09:34 AM   #7
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 136
Default

I can't do it alone. Can someone help me there?(get this script toggle state)
Thank you
Code:
--integer = reaper.GetToggleCommandState(integer command_id)
--boolean = reaper.SetToggleCommandState(integer section_id, integer command_id, integer state)


it =  reaper.GetSelectedMediaItem(0, 0) -- get first sel. item
if it == nil then return end
curpos = reaper.GetCursorPosition()
start_pos = reaper.GetMediaItemInfo_Value(it, 'D_POSITION')
len =  reaper.GetMediaItemInfo_Value(it, 'D_LENGTH')
curmid = start_pos + len/2
       
if curpos<curmid then
    --Item edit: Trim left edge of item to edit cursor
      reaper.Main_OnCommand(41305,1)
else
    --Item edit: Trim right edge of item to edit cursor  
      reaper.Main_OnCommand(41311,1)
end
Dragonetti is online now   Reply With Quote
Old 02-10-2020, 09:23 AM   #8
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,370
Default

Quote:
Originally Posted by Dragonetti View Post
Is there a way to get this script toggle state (on/off)?
As this script is not one which continously runs in the background (so it can be toggled on/off), I don't understand what you mean by on/off, could you elaborate?
nofish is offline   Reply With Quote
Old 02-11-2020, 04:43 AM   #9
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 136
Default

With a button in a toolbar I want to start the script(it should run continuously in the background) and the same button end it after editing.
Just like you can turn the metronome on and off.

Last edited by Dragonetti; 02-11-2020 at 04:55 AM.
Dragonetti is online now   Reply With Quote
Old 02-11-2020, 08:20 AM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,370
Default

You could assign the script to a toolbar button, rightclick the button to arm it (button lights up), now the script executes whenever you click on an item, leftclick button or press Esc to unarm it again. Would that do?

Last edited by nofish; 02-11-2020 at 08:59 AM.
nofish is offline   Reply With Quote
Old 02-12-2020, 06:01 AM   #11
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 136
Default

I didn't know this function at all.
This could be very practical in this case.
Thanks
Dragonetti is online now   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 09:39 AM.


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