Old 03-04-2018, 05:39 PM   #41
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,752
Default

Here is a set of three scripts:
* Two scripts to move the edit cursor left or right to the nearest edge of an item in selected tracks. The default offset can be specified in the script text file.
* A script that opens a dialog box in which you can easily set a new offset while you are working. (This overrides the default offsets; blank input restores the default.)

Code:
-- Move edit cursor to next item edge in selected tracks

defaultOffset = 0 -- User can change this value (in seconds)

----------------------------------------------------------------------------------
offset = tonumber(reaper.GetExtState("MoveEditCursor", "offset")) or defaultOffset
reaper.Undo_BeginBlock2(0)
nearestEdge = math.huge
cursorTimePos = reaper.GetCursorPositionEx(0)
for t = 0, reaper.CountSelectedTracks(0)-1 do
    local track = reaper.GetSelectedTrack(0, t)
    for i = 0, reaper.GetTrackNumMediaItems(track)-1 do
        local item = reaper.GetTrackMediaItem(track, i)
        local itemStart = offset + reaper.GetMediaItemInfo_Value(item, "D_POSITION")
        local itemEnd = itemStart + reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
        if itemStart > cursorTimePos and itemStart < nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemStart
        elseif itemEnd > cursorTimePos and itemEnd < nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemEnd       
        end
    end
end
if mustMoveCursor then
    reaper.ApplyNudge(0, 1, 6, 1, nearestEdge, false, 0)
end
-- Whether undo point is created depends on Preferences -> Undo settings -> Include cursor position
reaper.Undo_EndBlock2(0, "Move edit cursor right to item edge", -1)
Code:
-- Move edit cursor to previous item edge in selected tracks

defaultOffset = 0 -- User can change this value (in seconds)

----------------------------------------------------------------------------------
offset = tonumber(reaper.GetExtState("MoveEditCursor", "offset")) or defaultOffset
reaper.Undo_BeginBlock2(0)
nearestEdge = -math.huge 
cursorTimePos = reaper.GetCursorPositionEx(0)
for t = 0, reaper.CountSelectedTracks(0)-1 do
    local track = reaper.GetSelectedTrack(0, t)
    for i = 0, reaper.GetTrackNumMediaItems(track)-1 do
        local item = reaper.GetTrackMediaItem(track, i)
        local itemStart = offset + reaper.GetMediaItemInfo_Value(item, "D_POSITION")
        local itemEnd = itemStart + reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
        if itemEnd < cursorTimePos and itemEnd > nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemEnd  
        elseif itemStart < cursorTimePos and itemStart > nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemStart     
        end
    end
end
if mustMoveCursor then
    reaper.ApplyNudge(0, 1, 6, 1, nearestEdge, false, 0)
end
-- Whether undo point is created depends on Preferences -> Undo settings -> Include cursor position
reaper.Undo_EndBlock2(0, "Move edit cursor left to item edge", -1)
Code:
-- Sets offset for the "Move edit cursor" scripts.
-- Blank input restores default offset (as specified in the "Move edit cursor" scripts).
currentOffset = reaper.GetExtState("MoveEditCursor", "offset")
repeat
    OK, newOffset = reaper.GetUserInputs([[Set offset for "Move cursor" script]], 1, "Offset (in seconds)", currentOffset)
    if not OK then return end
until newOffset == "" or tonumber(newOffset)
reaper.SetExtState("MoveEditCursor", "offset", newOffset, true)
juliansader is offline   Reply With Quote
Old 03-06-2018, 06:57 AM   #42
Jonas Ekstrom
Human being with feelings
 
Jonas Ekstrom's Avatar
 
Join Date: Feb 2017
Location: Stockholm
Posts: 81
Default

Quote:
Originally Posted by juliansader View Post
Here is a set of three scripts:
* Two scripts to move the edit cursor left or right to the nearest edge of an item in selected tracks. The default offset can be specified in the script text file.
* A script that opens a dialog box in which you can easily set a new offset while you are working. (This overrides the default offsets; blank input restores the default.)

Code:
-- Move edit cursor to next item edge in selected tracks

defaultOffset = 0 -- User can change this value (in seconds)

----------------------------------------------------------------------------------
offset = tonumber(reaper.GetExtState("MoveEditCursor", "offset")) or defaultOffset
reaper.Undo_BeginBlock2(0)
nearestEdge = math.huge
cursorTimePos = reaper.GetCursorPositionEx(0)
for t = 0, reaper.CountSelectedTracks(0)-1 do
    local track = reaper.GetSelectedTrack(0, t)
    for i = 0, reaper.GetTrackNumMediaItems(track)-1 do
        local item = reaper.GetTrackMediaItem(track, i)
        local itemStart = offset + reaper.GetMediaItemInfo_Value(item, "D_POSITION")
        local itemEnd = itemStart + reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
        if itemStart > cursorTimePos and itemStart < nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemStart
        elseif itemEnd > cursorTimePos and itemEnd < nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemEnd       
        end
    end
end
if mustMoveCursor then
    reaper.ApplyNudge(0, 1, 6, 1, nearestEdge, false, 0)
end
-- Whether undo point is created depends on Preferences -> Undo settings -> Include cursor position
reaper.Undo_EndBlock2(0, "Move edit cursor right to item edge", -1)
Code:
-- Move edit cursor to previous item edge in selected tracks

defaultOffset = 0 -- User can change this value (in seconds)

----------------------------------------------------------------------------------
offset = tonumber(reaper.GetExtState("MoveEditCursor", "offset")) or defaultOffset
reaper.Undo_BeginBlock2(0)
nearestEdge = -math.huge 
cursorTimePos = reaper.GetCursorPositionEx(0)
for t = 0, reaper.CountSelectedTracks(0)-1 do
    local track = reaper.GetSelectedTrack(0, t)
    for i = 0, reaper.GetTrackNumMediaItems(track)-1 do
        local item = reaper.GetTrackMediaItem(track, i)
        local itemStart = offset + reaper.GetMediaItemInfo_Value(item, "D_POSITION")
        local itemEnd = itemStart + reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
        if itemEnd < cursorTimePos and itemEnd > nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemEnd  
        elseif itemStart < cursorTimePos and itemStart > nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemStart     
        end
    end
end
if mustMoveCursor then
    reaper.ApplyNudge(0, 1, 6, 1, nearestEdge, false, 0)
end
-- Whether undo point is created depends on Preferences -> Undo settings -> Include cursor position
reaper.Undo_EndBlock2(0, "Move edit cursor left to item edge", -1)
Code:
-- Sets offset for the "Move edit cursor" scripts.
-- Blank input restores default offset (as specified in the "Move edit cursor" scripts).
currentOffset = reaper.GetExtState("MoveEditCursor", "offset")
repeat
    OK, newOffset = reaper.GetUserInputs([[Set offset for "Move cursor" script]], 1, "Offset (in seconds)", currentOffset)
    if not OK then return end
until newOffset == "" or tonumber(newOffset)
reaper.SetExtState("MoveEditCursor", "offset", newOffset, true)
Incredible! Thank you Julian, Will try this as soon as i get back into the studio tonight.
__________________
Jonas Ekstrom
www.northmastering.com
Jonas Ekstrom is offline   Reply With Quote
Old 03-07-2018, 12:04 PM   #43
tusitala
Human being with feelings
 
tusitala's Avatar
 
Join Date: Apr 2010
Location: London (UK)
Posts: 333
Default

Quote:
Originally Posted by me2beats View Post
Save selected tracks, slot 1 (persist).lua
Save selected tracks, slot 2 (persist).lua
Save selected tracks, slot 3 (persist).lua

Toggle show-hide saved tracks, slot 1 (persist).lua
Toggle show-hide saved tracks, slot 2 (persist).lua
Toggle show-hide saved tracks, slot 3 (persist).lua

Added.
They use project notes.
You can make as slots as you want
for this you need to create the same script and just replace the variable (slot number) in the first line for example
Code:
local slot = 4


Hi! I think it's possible, but I'm not good at JS


Hi! I'll see what i can do


Hi, Do you guys know how to have this script work exactly like it is working now, but leaving racks visible in the mixer?
I would like to hide them only on the arrange view but keep seeing them in the mixer.

Thanks a lot!
All the best
-t
tusitala is online now   Reply With Quote
Old 03-21-2018, 06:00 AM   #44
Jonas Ekstrom
Human being with feelings
 
Jonas Ekstrom's Avatar
 
Join Date: Feb 2017
Location: Stockholm
Posts: 81
Default

Quote:
Originally Posted by juliansader View Post
Here is a set of three scripts:
* Two scripts to move the edit cursor left or right to the nearest edge of an item in selected tracks. The default offset can be specified in the script text file.
* A script that opens a dialog box in which you can easily set a new offset while you are working. (This overrides the default offsets; blank input restores the default.)

Code:
-- Move edit cursor to next item edge in selected tracks

defaultOffset = 0 -- User can change this value (in seconds)

----------------------------------------------------------------------------------
offset = tonumber(reaper.GetExtState("MoveEditCursor", "offset")) or defaultOffset
reaper.Undo_BeginBlock2(0)
nearestEdge = math.huge
cursorTimePos = reaper.GetCursorPositionEx(0)
for t = 0, reaper.CountSelectedTracks(0)-1 do
    local track = reaper.GetSelectedTrack(0, t)
    for i = 0, reaper.GetTrackNumMediaItems(track)-1 do
        local item = reaper.GetTrackMediaItem(track, i)
        local itemStart = offset + reaper.GetMediaItemInfo_Value(item, "D_POSITION")
        local itemEnd = itemStart + reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
        if itemStart > cursorTimePos and itemStart < nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemStart
        elseif itemEnd > cursorTimePos and itemEnd < nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemEnd       
        end
    end
end
if mustMoveCursor then
    reaper.ApplyNudge(0, 1, 6, 1, nearestEdge, false, 0)
end
-- Whether undo point is created depends on Preferences -> Undo settings -> Include cursor position
reaper.Undo_EndBlock2(0, "Move edit cursor right to item edge", -1)
Code:
-- Move edit cursor to previous item edge in selected tracks

defaultOffset = 0 -- User can change this value (in seconds)

----------------------------------------------------------------------------------
offset = tonumber(reaper.GetExtState("MoveEditCursor", "offset")) or defaultOffset
reaper.Undo_BeginBlock2(0)
nearestEdge = -math.huge 
cursorTimePos = reaper.GetCursorPositionEx(0)
for t = 0, reaper.CountSelectedTracks(0)-1 do
    local track = reaper.GetSelectedTrack(0, t)
    for i = 0, reaper.GetTrackNumMediaItems(track)-1 do
        local item = reaper.GetTrackMediaItem(track, i)
        local itemStart = offset + reaper.GetMediaItemInfo_Value(item, "D_POSITION")
        local itemEnd = itemStart + reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
        if itemEnd < cursorTimePos and itemEnd > nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemEnd  
        elseif itemStart < cursorTimePos and itemStart > nearestEdge then
            mustMoveCursor = true
            nearestEdge = itemStart     
        end
    end
end
if mustMoveCursor then
    reaper.ApplyNudge(0, 1, 6, 1, nearestEdge, false, 0)
end
-- Whether undo point is created depends on Preferences -> Undo settings -> Include cursor position
reaper.Undo_EndBlock2(0, "Move edit cursor left to item edge", -1)
Code:
-- Sets offset for the "Move edit cursor" scripts.
-- Blank input restores default offset (as specified in the "Move edit cursor" scripts).
currentOffset = reaper.GetExtState("MoveEditCursor", "offset")
repeat
    OK, newOffset = reaper.GetUserInputs([[Set offset for "Move cursor" script]], 1, "Offset (in seconds)", currentOffset)
    if not OK then return end
until newOffset == "" or tonumber(newOffset)
reaper.SetExtState("MoveEditCursor", "offset", newOffset, true)
Thank you Julian, works great!
Where do i send beer-money?
__________________
Jonas Ekstrom
www.northmastering.com
Jonas Ekstrom is offline   Reply With Quote
Old 03-21-2018, 06:05 AM   #45
Jonas Ekstrom
Human being with feelings
 
Jonas Ekstrom's Avatar
 
Join Date: Feb 2017
Location: Stockholm
Posts: 81
Default

Desperatly need this: i want to press key #3 and activate smart tool split item.
Posssible scripting this?
__________________
Jonas Ekstrom
www.northmastering.com
Jonas Ekstrom is offline   Reply With Quote
Old 03-21-2018, 10:36 AM   #46
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,752
Default

Quote:
Originally Posted by Jonas Ekstrom View Post
Where do i send beer-money?
paypal.me/juliansader, thanks!


Quote:
Originally Posted by Jonas Ekstrom View Post
Desperatly need this: i want to press key #3 and activate smart tool split item.
Posssible scripting this?
It might be possible... What exactly do you mean by "key #3" and "activate smart tool split item"?

Last edited by juliansader; 03-22-2018 at 08:40 AM.
juliansader is offline   Reply With Quote
Old 03-24-2018, 09:14 AM   #47
Gianfini
Human being with feelings
 
Join Date: Jan 2015
Posts: 566
Default script not working

hi, I cannot get me2beats_remove selected regions contents (moving later items) to work

I created a region, selected it but it does nothing...

g
Gianfini is offline   Reply With Quote
Old 03-25-2018, 03:47 AM   #48
Jonas Ekstrom
Human being with feelings
 
Jonas Ekstrom's Avatar
 
Join Date: Feb 2017
Location: Stockholm
Posts: 81
Default

Quote:
Originally Posted by juliansader View Post

It might be possible... What exactly do you mean by "key #3" and "activate smart tool split item"?

Right now I right click the split item icon to make it a smart tool, split always active until I click it again, effectively making the edit cursor a scissor tool.

Now, is there a way of scripting that instead of right clicking the button? In that case I could assign a key to it.

Coming from Samplitude, one of the most things I miss is the universal mouse mode.
I've set up mouse modifiers to come close, just miss a proper scissor tool.
__________________
Jonas Ekstrom
www.northmastering.com
Jonas Ekstrom is offline   Reply With Quote
Old 03-25-2018, 04:43 AM   #49
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,752
Default

Quote:
Originally Posted by Jonas Ekstrom View Post
Now, is there a way of scripting that instead of right clicking the button? In that case I could assign a key to it.
Do you want mouse cursor to reflect the default vs "split tool" state, similar to how the cursor changes when you arm a toolbar button? If so, try this script:

Code:
--[[
Description: Toggles left-click mouse modifier between "split item" and whatever was previously the assigned action

Author: juliansader

Instructions: 
* Assign any shortcut to script.  
* Press shortcut once to start script, and once again to stop script. 
* If the "ReaScript task control" window pops up with the question 
  "Would you like to terminate all instances of this script or launch a new instance?", 
  select "Terminate instances" and check "Remember my answer for this script".
]]

originalAction = reaper.GetMouseModifier("MM_CTX_ITEM_CLK", 0, "")
is_new_value,filename,sectionID,cmdID,mode,resolution,val = reaper.get_action_context()


function exit()
    reaper.SetMouseModifier("MM_CTX_ITEM_CLK", 0, originalAction)
    reaper.TrackCtl_SetToolTip("", 0, 0, true)
    reaper.SetToggleCommandState(sectionID, cmdID, 0)
    reaper.RefreshToolbar2(sectionID, cmdID)
end
reaper.atexit(exit)

function loopDrawTooltip()
    x, y = reaper.GetMousePosition()
    reaper.TrackCtl_SetToolTip(" ][", x+8, y+9, true)
    reaper.defer(loopDrawTooltip)
end

reaper.SetMouseModifier("MM_CTX_ITEM_CLK", 0, 40746 ) -- Split item at mouse cursor
reaper.SetToggleCommandState(sectionID, cmdID, 1)
reaper.RefreshToolbar2(sectionID, cmdID)
loopDrawTooltip()
But would it not be simpler to assign the keystroke shortcut to the split action itself? Then you can just press the shortcut whenever you want to split.

EDIT: Updated to reflect state in toolbar button.

For a simpler script that doesn't change the mouse cursor, try:
Code:
currentAction = reaper.GetMouseModifier("MM_CTX_ITEM_CLK", 0, "")

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

if currentAction == "40746" then
    reaper.SetMouseModifier("MM_CTX_ITEM_CLK", 0, "1") -- Select Item
    reaper.SetToggleCommandState(sectionID, cmdID, 0) -- Toggle button OFF
else
    reaper.SetMouseModifier("MM_CTX_ITEM_CLK", 0, "40746") -- Split item under mouse cursor
    reaper.SetToggleCommandState(sectionID, cmdID, 1) -- Toggle button ON
end

reaper.RefreshToolbar2(sectionID, cmdID)

Last edited by juliansader; 03-30-2018 at 03:07 AM.
juliansader is offline   Reply With Quote
Old 04-17-2018, 02:32 AM   #50
Jonas Ekstrom
Human being with feelings
 
Jonas Ekstrom's Avatar
 
Join Date: Feb 2017
Location: Stockholm
Posts: 81
Default

Quote:
Originally Posted by juliansader View Post
Do you want mouse cursor to reflect the default vs "split tool" state, similar to how the cursor changes when you arm a toolbar button? If so, try this script:

Code:
--[[
Description: Toggles left-click mouse modifier between "split item" and whatever was previously the assigned action

Author: juliansader

Instructions: 
* Assign any shortcut to script.  
* Press shortcut once to start script, and once again to stop script. 
* If the "ReaScript task control" window pops up with the question 
  "Would you like to terminate all instances of this script or launch a new instance?", 
  select "Terminate instances" and check "Remember my answer for this script".
]]

originalAction = reaper.GetMouseModifier("MM_CTX_ITEM_CLK", 0, "")
is_new_value,filename,sectionID,cmdID,mode,resolution,val = reaper.get_action_context()


function exit()
    reaper.SetMouseModifier("MM_CTX_ITEM_CLK", 0, originalAction)
    reaper.TrackCtl_SetToolTip("", 0, 0, true)
    reaper.SetToggleCommandState(sectionID, cmdID, 0)
    reaper.RefreshToolbar2(sectionID, cmdID)
end
reaper.atexit(exit)

function loopDrawTooltip()
    x, y = reaper.GetMousePosition()
    reaper.TrackCtl_SetToolTip(" ][", x+8, y+9, true)
    reaper.defer(loopDrawTooltip)
end

reaper.SetMouseModifier("MM_CTX_ITEM_CLK", 0, 40746 ) -- Split item at mouse cursor
reaper.SetToggleCommandState(sectionID, cmdID, 1)
reaper.RefreshToolbar2(sectionID, cmdID)
loopDrawTooltip()
But would it not be simpler to assign the keystroke shortcut to the split action itself? Then you can just press the shortcut whenever you want to split.

EDIT: Updated to reflect state in toolbar button.

For a simpler script that doesn't change the mouse cursor, try:
Code:
currentAction = reaper.GetMouseModifier("MM_CTX_ITEM_CLK", 0, "")

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

if currentAction == "40746" then
    reaper.SetMouseModifier("MM_CTX_ITEM_CLK", 0, "1") -- Select Item
    reaper.SetToggleCommandState(sectionID, cmdID, 0) -- Toggle button OFF
else
    reaper.SetMouseModifier("MM_CTX_ITEM_CLK", 0, "40746") -- Split item under mouse cursor
    reaper.SetToggleCommandState(sectionID, cmdID, 1) -- Toggle button ON
end

reaper.RefreshToolbar2(sectionID, cmdID)
Thank you for this Julian!
Tested it and it seems to toogle so much it´s a bit slow.
And also, i think i was overlooking the mouse modifiers, i guess this can be done with that.

Only thing missing is a vertical ruler with the mouse-pointer, if this could be triggered with a script then my editing headache would be gone.
__________________
Jonas Ekstrom
www.northmastering.com
Jonas Ekstrom 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 06:05 PM.


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