|
|
|
09-13-2018, 10:09 AM
|
#1
|
Human being with feelings
Join Date: Aug 2018
Posts: 12
|
Track name verify
Hello,
I'm trying to do a script that will only perform a reaper.Main_OnCommand action if the name is the one specified. I have a cycle that runs through all the tracks, gets the name of the track and compares their names.
this is the code i have at the moment:
Code:
countTracks = reaper.CountTracks(0)
test = false
if countTracks > 0 then
for j = 0, countTracks-1 do
track = reaper.GetTrack(0, j)
if track ~= nil then
name = reaper.GetTrackName(track, "")
if name ~= nil then
line = "X"
if name == line then
test = true
reaper.Main_OnCommand(40142,0)
end
end
end
end
end
end
i have placed a test boolean inside the if to see if it can get inside the comparison and its not getting in so i assume the error is in either the compare if or getting the name of the track.
Can anyone help me please?
Thank you
|
|
|
09-13-2018, 10:45 AM
|
#2
|
Human being with feelings
Join Date: Sep 2008
Location: Sweden
Posts: 7,417
|
This is Lua, right?
In Lua the GetTrackName has this definition:
Code:
Lua: boolean retval, string buf = reaper.GetTrackName(MediaTrack track, string buf)
(from https://www.reaper.fm/sdk/reascript/...l#GetTrackName)
I think that means that you must write:
Code:
retval, name = reaper.GetTrackName(track, "")
to get the trackname into the name variable. I am not 100% sure, since I mainly use EEL, but try it, see if it works.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
|
|
|
09-14-2018, 01:39 AM
|
#3
|
Human being with feelings
Join Date: Aug 2018
Posts: 12
|
Thank you Fabian, that was it
|
|
|
09-14-2018, 10:02 AM
|
#4
|
Human being with feelings
Join Date: Aug 2018
Posts: 12
|
I am having another issue now, i want to perform the action after selecting the track. i am selecting the correct track but the script is performing the OnCommand n the previously selected track.
Code:
function main()
countTracks = reaper.CountTracks(0)
test = false
if countTracks > 0 then
for j = 0, countTracks-1 do
track = reaper.GetTrack(0, j)
if track ~= nil then
retval, name = reaper.GetTrackName(track, "")
if name ~= nil then
if name == "X" then
reaper.SetOnlyTrackSelected(track)
end
end
end
end
end
end
main()
reaper.Main_OnCommand(40142,0)
this is what i have at the moment. i took the Main_OnCommand out to try if it works like this but still doesn't. Before i had it inside the comparing if and it was still not working.
|
|
|
09-14-2018, 11:06 AM
|
#5
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
reaper.Main_OnCommand(40142,0) at the end will always run the "Insert empty item" -action.
Maybe this would work?
Code:
function main()
local countTracks = reaper.CountTracks(0)
for j = 0, countTracks-1 do
local track = reaper.GetTrack(0, j)
if track ~= nil then
local retval, name = reaper.GetTrackName(track, "")
if retval then
if name == "X" then
reaper.SetOnlyTrackSelected(track)
reaper.Main_OnCommand(40142,0)
return -- Track named "X" found -> return
end
end
end
end
end
main()
|
|
|
09-14-2018, 11:13 AM
|
#6
|
Human being with feelings
Join Date: Aug 2018
Posts: 12
|
Quote:
Originally Posted by spk77
reaper.Main_OnCommand(40142,0) at the end will always run the "Insert empty item" -action
|
it still does not work. It selects the track visually, but the pointer is still on the previous one so it pastes the item on the track selected before. I think i need to set it to point to the new selected but i can't find a way to do it unfortunately
|
|
|
09-14-2018, 11:21 AM
|
#7
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Dizzee
it still does not work. It selects the track visually, but the pointer is still on the previous one so it pastes the item on the track selected before. I think i need to set it to point to the new selected but i can't find a way to do it unfortunately
|
This is how it works for me:
|
|
|
09-14-2018, 11:32 AM
|
#8
|
Human being with feelings
Join Date: Aug 2018
Posts: 12
|
In that case all I can assume is that the script works on windows but not on macs because that is what I am using? It is not the first time that a script I have done works on a windows and not on a mac... any work around this issue?
|
|
|
09-14-2018, 11:38 AM
|
#9
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Dizzee
In that case all I can assume is that the script works on windows but not on macs because that is what I am using? It is not the first time that a script I have done works on a windows and not on a mac... any work around this issue?
|
I really don't know why it doesn't work for you...maybe someone with a mac could test the script and see if it works.
|
|
|
09-14-2018, 11:42 AM
|
#10
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
Not sure if that's the issue here (can't test atm) but some actions work on the (last) touched track, not the selected track I think. Touched and selected are sometimes different in Reaper.
Try adding action "Track: Set first selected track as last touched track" (40914) after reaper.SetOnlyTrackSelected(track) and see if it helps maybe,
|
|
|
09-14-2018, 11:53 AM
|
#11
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by nofish
Not sure if that's the issue here (can't test atm) but some actions work on the (last) touched track, not the selected track I think. Touched and selected are sometimes different in Reaper.
Try adding action "Track: Set first selected track as last touched track" (40914) after reaper.SetOnlyTrackSelected(track) and see if it helps maybe,
|
That might be the case here.
I actually managed to reproduce the problem (doesn't happen always).
Here's "Track: Set first selected track as last touched track" added
Code:
function main()
local countTracks = reaper.CountTracks(0)
for j = 0, countTracks-1 do
local track = reaper.GetTrack(0, j)
if track ~= nil then
local retval, name = reaper.GetTrackName(track, "")
if retval then
if name == "X" then
reaper.SetOnlyTrackSelected(track)
reaper.Main_OnCommand(40914,0) -- Track: Set first selected track as last touched track"
reaper.Main_OnCommand(40142,0)
return -- Track named "X" found -> return
end
end
end
end
end
main()
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 06:15 AM.
|