Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER General Discussion Forum

Reply
 
Thread Tools Display Modes
Old 08-11-2022, 09:01 AM   #1
138BPM
Human being with feelings
 
Join Date: Dec 2019
Posts: 67
Default Is there an automated way to rename 128 samplers + note numbers?

To setup 128 samplers (one for every MIDI note) I can add them in the FX by just copying and pasting after the first one, using ReaSamplOmatic5000.

Now the time consuming part... every sampler is called "ReaSamplOmatic5000" and they need to be numbered from 000 to 128. Every instance has the note set at #48 and needs to be unique, running from 0 to 128.

The way I did automate that was to make an AutoIt2 script that tabs around and enters it all on each one, but it's a really crude way of doing it.

Is there some text based file where I can edit it to add the samplers to the track FX? Is that part of the main project ".RPP" file and it's just not possible to do it?

What about an SWS extension? It would take the first FX item and rename it 0 then +1 for every other FX item until it runs out of items to rename. Same with notes, it would have to start at 0 and rename them all until it runs out. It sounds complicated but maybe it's been automated somehow by now?

SWS only mentions renaming tracks, takes, project markers... not FX:




Renaming the sampler notes in (specifically) ReaSamplOmatic5000 so each FX item runs from 000 to 128 (with the note number there twice because it's a note range) is an even taller order than renaming the FX! It seems like there isn't an easy way.

If I can do this then I will be able to create an absolute monster of a Trance drumkit! This would have 1 instrument on 1 track like a kick drum, but it could have a selection of 128 different kick drums. Track 2 with 128 different snare drums and so on. If you don't have 128 samples to fill it, nevermind, the blank samplers are all there if needed.

One good thing is once 1 track has been setup that way, it could be muted and used as a template track, where you can just copy that track and you basically have your next drum hit/instrument. I intend to save just one blank track as a project file if I get the 128 samplers setup on 1 track.

This would be insane if it could be done quickly and easily. Clicking manually to create just one set of 128 samplers named with the notes changed would take ages. Doing it with AutoIt is alright but if it makes 1 mistake it throws out the order of things from then on, etc.

I tried highlighting all the FX instances and renaming, but that only renames the first instance. Imagine if Reaper popped up a box because it knows you highlighted multiple FX and it just let you put "000 to X" in a box, where it just renames them all in order until it runs out of FX to rename... hint hint!

Last edited by 138BPM; 08-11-2022 at 09:22 AM.
138BPM is offline   Reply With Quote
Old 08-11-2022, 07:53 PM   #2
138BPM
Human being with feelings
 
Join Date: Dec 2019
Posts: 67
Default

I made an AutoIt2 script, you'd need AutoIt2 installing to use it, it's messy, it's 4,000+ lines long, you shouldn't touch the keyboard or mouse while it's running, any other windows popping up at the time will throw it out of whack, it takes about 10 minutes to complete and it won't work if your page down key doesn't page down exactly 30 items in the FX list... but it works for me personally.

It's actually not likely this would work for anyone else, but here it is anyway:

Code:
https://www.dropbox.com/s/owrw51tkyg3xel2/Sampler%20-%20Create%20128%20Samplers%2C%20Rename%2C%20Change%20Notes.7z?dl=1
Once that was created, I called the track "BLANK SAMPLERS" and muted it. Then to make the first track (Kick drums) I copied that track, renamed the copy "Kick" and dragged 128 kick drum samples into the samplers. I did the same with snare, clap, closed hi-hat, open hi-hat and so on.

Then I saved it as a project and now, it's a nice Trance drumkit template file I can just start off with, without spending ages messing about dragging samples into a project, they are all there. It ended up totaling about 570 samples by the end of it, with only about 8 tracks there (1 instrument type on each track).

How it looks:
https://i.imgur.com/7x5SWxq.png

Last edited by 138BPM; 08-11-2022 at 08:03 PM.
138BPM is offline   Reply With Quote
Old 08-12-2022, 10:41 AM   #3
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Probably too late, but this took ~5-6 seconds on i7-3770 to rename 128 instances of ReaSamplOmatic5000 and set their note start and note end values (0 to 127).

Code:
function TrackFx_Rename(Track, idx_fx, newName);
-- Special Thanks to Archie for this function, https://raw.githubusercontent.com/ArchieScript/Archie_ReaScripts/06d2c5c3dee5aba65080d82e05e0534de9899e64/Functions/Arc_Function_lua.lua
    local strT, found, slot = {};
    local Pcall,FXGUID = pcall(reaper.TrackFX_GetFXGUID,Track,idx_fx);
    if not Pcall or not FXGUID then return false end;
    local retval,str = reaper.GetTrackStateChunk(Track,"",false);
    for l in (str.."\n"):gmatch(".-\n")do table.insert(strT,l)end;
    for i = #strT,1,-1 do;
        if strT[i]:match(FXGUID:gsub("%p","%%%0"))then found = true end;
        if strT[i]:match("^<")and found and not strT[i]:match("JS_SER")then;
            found = nil;
            local nStr = {};
            for S in strT[i]:gmatch("%S+")do;
                if not X then nStr[#nStr+1] = S else nStr[#nStr] = nStr[#nStr].." "..S end;
                if S:match('"') and not S:match('""')and not S:match('".-"') then;
                    if not X then;X = true;else;X = nil;end;
                end;
            end;
            if strT[i]:match("^<%s-JS")then;
                slot = 3;
            elseif strT[i]:match("^<%s-AU")then;
                slot = 4;
            elseif strT[i]:match("^<%s-VST")then;
                slot = 5;
            end;
            if not slot then error("Failed to rename",2)end;
             nStr[slot] = newName:gsub(newName:gsub("%p","%%%0"),'"%0"');
            nStr[#nStr+1]="\n";
            strT[i] = table.concat(nStr," ");
            break;
        end;
    end;
    return reaper.SetTrackStateChunk(Track,table.concat(strT),false);
end;

function Main()
  local track = reaper.GetSelectedTrack(0,0) -- first selected track
  if not track then return end
  
  local fx_count = reaper.TrackFX_GetCount(track)
  local SamplOmatic_Count = 0
  local param_value = 0
  
  for fx = 0, fx_count-1 do
    local retval, fx_name = reaper.TrackFX_GetFXName(track, fx, "")
    if fx_name:match("ReaSamplOmatic5000") then
      -- rename ReaSamplOmatic5000 to "RS5K_000" ... "RS5K_127" 
      TrackFx_Rename(track, fx, "RS5K_".. string.format("%03d", SamplOmatic_Count))
      -- set starting/ending note same as instance # (0 to 127) 
      reaper.TrackFX_SetParam(track, fx, 3, param_value) -- Note range start, index = 3
      reaper.TrackFX_SetParam(track, fx, 4, param_value) -- Note range end, index = 4
      SamplOmatic_Count = SamplOmatic_Count + 1
      if SamplOmatic_Count > 127 then return end
      param_value = (SamplOmatic_Count / 127)
    end
  end
 
end

Main()
Edgemeal is offline   Reply With Quote
Old 08-12-2022, 01:06 PM   #4
138BPM
Human being with feelings
 
Join Date: Dec 2019
Posts: 67
Default

It's never too late because I'd always avoid the way I did it if possible. I have no idea how to use the code you posted or what language it is, but thanks anyway.
138BPM is offline   Reply With Quote
Old 08-12-2022, 02:06 PM   #5
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Oh OK, I thought since you wrote that, you'd know some rea-scripting also, at least be able to read the function Main() part Its a Lua script. To save the code and run, open Actions window > set to MAIN section > click New Action button > New ReaScript > Enter name for script file & click Save button (the IDE window opens) , Paste code in IDE window, close IDE window & select YES when asked to save. You'll now have a new action to run/edit.
Edgemeal is offline   Reply With Quote
Old 08-12-2022, 06:06 PM   #6
138BPM
Human being with feelings
 
Join Date: Dec 2019
Posts: 67
Default

Edgemeal thanks that's a massive help. If I know it's a LUA file I know what to do from there but... what code would need adding to the start of it to create the 128 instances of ReaSamplOmatic5000?

That script would do everything if it's possible to have the code before what it's already doing.
138BPM is offline   Reply With Quote
Old 08-12-2022, 07:15 PM   #7
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

After you get the selected track, try the TrackFX_AddByName function...
Code:
  local track = reaper.GetSelectedTrack(0,0) -- first selected track
  if not track then return end
  
  for i = 1, 128 do 
    reaper.TrackFX_AddByName(track, "ReaSamplOmatic5000", false, -1)
  end
With FX chain not visible it took just under 2 secs to add 128 instances, with fx chain visible it took 9 sec!

EDIT: I ran full script from actions list on new/empty track with fx chain NOT visible.
4.4208230999939 seconds.

benchmark code,
Code:
init_time = reaper.time_precise()
Main()
reaper.ShowConsoleMsg(tostring(reaper.time_precise() - init_time) .. "\n")

Last edited by Edgemeal; 08-12-2022 at 07:40 PM.
Edgemeal is offline   Reply With Quote
Old 08-12-2022, 07:44 PM   #8
138BPM
Human being with feelings
 
Join Date: Dec 2019
Posts: 67
Default

Cheers Edgemeal that is ruthless lol.

I tried to combine the scripts into one so it creates the 128 samplers, renames them and changes the notes, but it didn't work (although they work when run separately).

I'm just no good at coding. I put a semi-colon after the last "end" trying to figure it out from the way the longer script looks, but it didn't run and do the three things. errrr...

EDIT: Oh wait it does work, by simply pasting the 2 scripts as they are into one file I thought end ended the script and a semi-colon was needed to make it continue but it works just using the code as it is when they are put together.

Create, Rename, Change Notes on 128 Samplers.lua

Code:
  local track = reaper.GetSelectedTrack(0,0) -- first selected track
  if not track then return end
  
  for i = 1, 128 do 
    reaper.TrackFX_AddByName(track, "ReaSamplOmatic5000", false, -1)
  end

function TrackFx_Rename(Track, idx_fx, newName);
-- Special Thanks to Archie for this function, https://raw.githubusercontent.com/ArchieScript/Archie_ReaScripts/06d2c5c3dee5aba65080d82e05e0534de9899e64/Functions/Arc_Function_lua.lua
    local strT, found, slot = {};
    local Pcall,FXGUID = pcall(reaper.TrackFX_GetFXGUID,Track,idx_fx);
    if not Pcall or not FXGUID then return false end;
    local retval,str = reaper.GetTrackStateChunk(Track,"",false);
    for l in (str.."\n"):gmatch(".-\n")do table.insert(strT,l)end;
    for i = #strT,1,-1 do;
        if strT[i]:match(FXGUID:gsub("%p","%%%0"))then found = true end;
        if strT[i]:match("^<")and found and not strT[i]:match("JS_SER")then;
            found = nil;
            local nStr = {};
            for S in strT[i]:gmatch("%S+")do;
                if not X then nStr[#nStr+1] = S else nStr[#nStr] = nStr[#nStr].." "..S end;
                if S:match('"') and not S:match('""')and not S:match('".-"') then;
                    if not X then;X = true;else;X = nil;end;
                end;
            end;
            if strT[i]:match("^<%s-JS")then;
                slot = 3;
            elseif strT[i]:match("^<%s-AU")then;
                slot = 4;
            elseif strT[i]:match("^<%s-VST")then;
                slot = 5;
            end;
            if not slot then error("Failed to rename",2)end;
             nStr[slot] = newName:gsub(newName:gsub("%p","%%%0"),'"%0"');
            nStr[#nStr+1]="\n";
            strT[i] = table.concat(nStr," ");
            break;
        end;
    end;
    return reaper.SetTrackStateChunk(Track,table.concat(strT),false);
end;

function Main()
  local track = reaper.GetSelectedTrack(0,0) -- first selected track
  if not track then return end
  
  local fx_count = reaper.TrackFX_GetCount(track)
  local SamplOmatic_Count = 0
  local param_value = 0
  
  for fx = 0, fx_count-1 do
    local retval, fx_name = reaper.TrackFX_GetFXName(track, fx, "")
    if fx_name:match("ReaSamplOmatic5000") then
      -- rename ReaSamplOmatic5000 to "RS5K_000" ... "RS5K_127" 
      TrackFx_Rename(track, fx, "RS5K_".. string.format("%03d", SamplOmatic_Count))
      -- set starting/ending note same as instance # (0 to 127) 
      reaper.TrackFX_SetParam(track, fx, 3, param_value) -- Note range start, index = 3
      reaper.TrackFX_SetParam(track, fx, 4, param_value) -- Note range end, index = 4
      SamplOmatic_Count = SamplOmatic_Count + 1
      if SamplOmatic_Count > 127 then return end
      param_value = (SamplOmatic_Count / 127)
    end
  end
 
end

Main()
Crazy stuff this!

Now I need to add a bit of code before that to create a new track (I'm lazy!)

Or it might be better not to lol. I set it up on Ctrl+Alt+A - will have to hope I don't accidentally run it because that's a lot of undoing haha.

Last edited by 138BPM; 08-12-2022 at 07:57 PM.
138BPM is offline   Reply With Quote
Old 08-13-2022, 05:38 AM   #9
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default UPDATED

Quote:
Originally Posted by 138BPM View Post
Now I need to add a bit of code before that to create a new track (I'm lazy!)
Exactly my thought, and code is even faster since it doesn't need to check the name of the FX, since we know what it is.

Quote:
Or it might be better not to lol. I set it up on Ctrl+Alt+A - will have to hope I don't accidentally run it because that's a lot of undoing haha.
Added an Undo Block so it shows up as only one entry in UnDo History now, forgot about that!

Code:
function TrackFx_Rename(Track, idx_fx, newName);
-- Special Thanks to Archie for this function, https://raw.githubusercontent.com/ArchieScript/Archie_ReaScripts/06d2c5c3dee5aba65080d82e05e0534de9899e64/Functions/Arc_Function_lua.lua
    local strT, found, slot = {};
    local Pcall,FXGUID = pcall(reaper.TrackFX_GetFXGUID,Track,idx_fx);
    if not Pcall or not FXGUID then return false end;
    local retval,str = reaper.GetTrackStateChunk(Track,"",false);
    for l in (str.."\n"):gmatch(".-\n")do table.insert(strT,l)end;
    for i = #strT,1,-1 do;
        if strT[i]:match(FXGUID:gsub("%p","%%%0"))then found = true end;
        if strT[i]:match("^<")and found and not strT[i]:match("JS_SER")then;
            found = nil;
            local nStr = {};
            for S in strT[i]:gmatch("%S+")do;
                if not X then nStr[#nStr+1] = S else nStr[#nStr] = nStr[#nStr].." "..S end;
                if S:match('"') and not S:match('""')and not S:match('".-"') then;
                    if not X then;X = true;else;X = nil;end;
                end;
            end;
            if strT[i]:match("^<%s-JS")then;
                slot = 3;
            elseif strT[i]:match("^<%s-AU")then;
                slot = 4;
            elseif strT[i]:match("^<%s-VST")then;
                slot = 5;
            end;
            if not slot then error("Failed to rename",2)end;
             nStr[slot] = newName:gsub(newName:gsub("%p","%%%0"),'"%0"');
            nStr[#nStr+1]="\n";
            strT[i] = table.concat(nStr," ");
            break;
        end;
    end;
    return reaper.SetTrackStateChunk(Track,table.concat(strT),false);
end;

function Main()
  reaper.Main_OnCommand(40001, 0) -- Track: Insert new track
  local track = reaper.GetSelectedTrack(0,0) -- get new track
  reaper.GetSetMediaTrackInfo_String(track, "P_NAME", "128 Samplers", true) -- name the new track
  local fx_count = 128 -- # of FX to add (* 128 Max! *) 
  for fx = 0, fx_count-1 do
    -- Add FX
    reaper.TrackFX_AddByName(track, "ReaSamplOmatic5000", false, -1)
    -- rename FX ReaSamplOmatic5000 to "RS5K_000" ... "RS5K_127"
    TrackFx_Rename(track, fx, "RS5K_".. string.format("%03d", fx))
    -- set starting/ending note same as instance # (0 to 127)
    reaper.TrackFX_SetParam(track, fx, 3, (fx / 127)) -- Note range start, index = 3
    reaper.TrackFX_SetParam(track, fx, 4, (fx / 127)) -- Note range end, index = 4 
  end 
end

reaper.Undo_BeginBlock()
Main()
reaper.Undo_EndBlock('Add track with 128 Samplers', -1)
Edgemeal is offline   Reply With Quote
Old 08-13-2022, 06:20 AM   #10
138BPM
Human being with feelings
 
Join Date: Dec 2019
Posts: 67
Default

Got so many versions I don't know what to do with them all now.

Wizardry, cheers Edgemeal.
138BPM 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 04:54 AM.


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