|
|
|
11-10-2018, 05:47 AM
|
#1
|
Human being with feelings
Join Date: Aug 2015
Posts: 3,672
|
my weird script works, but is repetitive due to an untamed FOR loop
hello, thanks all for getting me this far, advertently or inadvertently
here's a script i cobbled together largely using yours as inspiration, and by pestering MPL for help. description in description.
the issue can be seen by running the script while 2 or more instances of RS5K exist on a track in your project. the script's "count" for loop runs 1x time per instance, counting instances of RS5K and outputting their noterangestart params to the "inq" js.
how can i tame this count for loop so that it only performs the inquiry on a single RS5K instance at a time, rather than all of them?
any other cleanup suggestions would be welcome too
Code:
-- @version .01
-- @author mccrabney
-- @website
-- @description -- this script looks for RS5K instances,
-- determines their Note Range Start param values,
-- uses this to modulate slider1 of a JSfx called "inq"
-- which in turn sends OSC to bidule, ctrling LEDs
-- (in bidule, at 1st message received, all LEDs are blanked)
-- (so we don't need to worry about ctrling noteoffs in this script)
-- @ISSUE -- script runs 1x times per instance?
local script_title = 'show RS5K instances on Launchpad'
-------------------------------------------------------------------------------
--local track = reaper.GetSelectedTrack(0,0)
reaper.PreventUIRefresh(-1)
for i = 1, reaper.CountTracks(0) do
tr = reaper.GetTrack(0,i-1)
local _, chunk = reaper.GetTrackStateChunk( tr, '', false )
for line in chunk:gmatch('[^\r\n]+') do
if line:find('reasamplomatic.dll') then rs5ktrue = 1
local _, name = reaper.GetTrackName(tr,"")
--count = reaper.TrackFX_GetCount(tr);
for count = 0, reaper.TrackFX_GetCount(tr)-1 do
local _, param = reaper.TrackFX_GetParamName(tr, count, 3,"")
if param == "Note range start" then
--reaper.ShowConsoleMsg("[Name of track with RS5K] - ")
--reaper.ShowConsoleMsg(name)
--reaper.ShowConsoleMsg("\n")
reaper.ShowConsoleMsg("[RS5K is on FX slot] - ")
reaper.ShowConsoleMsg(count+1)
reaper.ShowConsoleMsg("\n")
val=reaper.TrackFX_GetParam(tr, count, 3)
val = math.floor(val*128) if val == 128 then val = val-1 end
reaper.ShowConsoleMsg("[value of NoteRangeStart] - ")
reaper.ShowConsoleMsg(val)
reaper.ShowConsoleMsg("\n")
for j = 1, reaper.CountTracks(0) do
track = reaper.GetTrack(0,j-1)
_, track_name = reaper.GetSetMediaTrackInfo_String( track, 'P_NAME', '', 0 )
--reaper.ShowConsoleMsg("j = ")
--reaper.ShowConsoleMsg(j)
--reaper.ShowConsoleMsg("\n")
if track_name:lower():find("inq") then
reaper.TrackFX_SetParam(track, 0, 0 , val )
reaper.ShowConsoleMsg("[noteons] - ")
reaper.ShowConsoleMsg(val)
reaper.ShowConsoleMsg("\n")
reaper.ShowConsoleMsg("\n")
end
end
end
end
end
end
end
reaper.PreventUIRefresh(1)
-------------------------------------------------------------------------------
|
|
|
11-10-2018, 06:27 AM
|
#2
|
Banned
Join Date: Sep 2015
Posts: 1,650
|
You can use the rs5ktrue flag you set to exit the chunk loop after finding the first RS5K...
Code:
-- @version .01
-- @author mccrabney
-- @website
-- @description -- this script looks for RS5K instances,
-- determines their Note Range Start param values,
-- uses this to modulate slider1 of a JSfx called "inq"
-- which in turn sends OSC to bidule, ctrling LEDs
-- (in bidule, at 1st message received, all LEDs are blanked)
-- (so we don't need to worry about ctrling noteoffs in this script)
-- @ISSUE -- script runs 1x times per instance?
local script_title = 'show RS5K instances on Launchpad'
-------------------------------------------------------------------------------
--local track = reaper.GetSelectedTrack(0,0)
reaper.PreventUIRefresh(-1)
for i = 1, reaper.CountTracks(0) do
tr = reaper.GetTrack(0,i-1)
local _, chunk = reaper.GetTrackStateChunk( tr, '', false )
for line in chunk:gmatch('[^\r\n]+') do
-- if we've already processed an instance then exit loop
if rs5ktrue then break end
if line:find('reasamplomatic.dll') then
rs5ktrue = 1
local _, name = reaper.GetTrackName(tr, "")
--count = reaper.TrackFX_GetCount(tr);
for count = 0, reaper.TrackFX_GetCount(tr)-1 do
local _, param = reaper.TrackFX_GetParamName(tr, count, 3, "")
if param == "Note range start" then
--reaper.ShowConsoleMsg("[Name of track with RS5K] - ")
--reaper.ShowConsoleMsg(name)
--reaper.ShowConsoleMsg("\n")
reaper.ShowConsoleMsg("[RS5K is on FX slot] - ")
reaper.ShowConsoleMsg(count+1)
reaper.ShowConsoleMsg("\n")
val = reaper.TrackFX_GetParam(tr, count, 3)
val = math.floor(val*128) if val == 128 then val = val-1 end
reaper.ShowConsoleMsg("[value of NoteRangeStart] - ")
reaper.ShowConsoleMsg(val)
reaper.ShowConsoleMsg("\n")
for j = 1, reaper.CountTracks(0) do
track = reaper.GetTrack(0,j-1)
_, track_name = reaper.GetSetMediaTrackInfo_String( track, 'P_NAME', '', 0 )
--reaper.ShowConsoleMsg("j = ")
--reaper.ShowConsoleMsg(j)
--reaper.ShowConsoleMsg("\n")
if track_name:lower():find("inq") then
reaper.TrackFX_SetParam(track, 0, 0 , val )
reaper.ShowConsoleMsg("[noteons] - ")
reaper.ShowConsoleMsg(val)
reaper.ShowConsoleMsg("\n")
reaper.ShowConsoleMsg("\n")
end
end
end
end
end
end
rs5ktrue = false -- reset the flag
end
reaper.PreventUIRefresh(1)
-------------------------------------------------------------------------------
The indentation was a bit off too, it's really really good to keep on top of indentation for keeping track of the logic when things go wrong (and it's also much less anxiety inducing to view).
|
|
|
11-10-2018, 09:05 AM
|
#3
|
Human being with feelings
Join Date: Aug 2015
Posts: 3,672
|
yeah, i am not used to reaper's IDE and find spacing a little clunky.
EDIT - your fix worked! thanks, i tried that but couldn't figure out where to put the rs5ktrue == false...probably due to my indentation
|
|
|
11-10-2018, 09:53 AM
|
#4
|
Banned
Join Date: Sep 2015
Posts: 1,650
|
Yeah, I do most non-tiny Lua things in ZeroBraneStudio for the more advanced editing functionality. I didn't know what was going on either until I sorted the indents.
|
|
|
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 05:13 PM.
|