Old 09-13-2018, 10:09 AM   #1
Dizzee
Human being with feelings
 
Join Date: Aug 2018
Posts: 12
Default 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
Dizzee is offline   Reply With Quote
Old 09-13-2018, 10:45 AM   #2
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,417
Default

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...
Fabian is offline   Reply With Quote
Old 09-14-2018, 01:39 AM   #3
Dizzee
Human being with feelings
 
Join Date: Aug 2018
Posts: 12
Default

Thank you Fabian, that was it
Dizzee is offline   Reply With Quote
Old 09-14-2018, 10:02 AM   #4
Dizzee
Human being with feelings
 
Join Date: Aug 2018
Posts: 12
Default

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.
Dizzee is offline   Reply With Quote
Old 09-14-2018, 11:06 AM   #5
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

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()
spk77 is offline   Reply With Quote
Old 09-14-2018, 11:13 AM   #6
Dizzee
Human being with feelings
 
Join Date: Aug 2018
Posts: 12
Default

Quote:
Originally Posted by spk77 View Post
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
Dizzee is offline   Reply With Quote
Old 09-14-2018, 11:21 AM   #7
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Dizzee View Post
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:
spk77 is offline   Reply With Quote
Old 09-14-2018, 11:32 AM   #8
Dizzee
Human being with feelings
 
Join Date: Aug 2018
Posts: 12
Default

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?
Dizzee is offline   Reply With Quote
Old 09-14-2018, 11:38 AM   #9
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Dizzee View Post
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.
spk77 is offline   Reply With Quote
Old 09-14-2018, 11:42 AM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

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,
nofish is offline   Reply With Quote
Old 09-14-2018, 11:53 AM   #11
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by nofish View Post
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()
spk77 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:15 AM.


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