Untitled

mail@pastecode.io avatar
unknown
lua
2 years ago
2.3 kB
1
Indexable
Never
function check()
  if slot_to_move ~= nil then
    local choose_slot = string.match(reaper.Undo_CanUndo2(0), "Add FX: [%w:]+ %w+")
    if choose_slot then
      local choose_slot2 = math.tointeger(string.match(choose_slot, "%d+"))
      local undo_fx_name = string.match(reaper.Undo_CanUndo2(0), "Track [%w:]+.+")
      local undo_fx_name = string.sub(string.match(undo_fx_name, ":.+"), 3)
      if not choose_slot2 then
        local choose_slot2 = string.match(choose_slot, "Master")
        if choose_slot2 == "Master" then
          undo_fx_name = string.match(reaper.Undo_CanUndo2(0), "Master[%w:]+.+")
          undo_fx_name = string.sub(string.match(undo_fx_name, ":.+"), 3)
          local choose_slot2 = -1
        end
      end
      local sel_tr_n = math.tointeger(reaper.GetMediaTrackInfo_Value(sel_track, 'IP_TRACKNUMBER'))
      fx_name_ok, fx_name = reaper.TrackFX_GetFXName(sel_track, fx_n_sel_tr)
      if sel_tr_n == choose_slot2 and string.match(fx_name, undo_fx_name) then
        reaper.PreventUIRefresh(1)
        reaper.Undo_BeginBlock2(0)
        reaper.TrackFX_CopyToTrack(sel_track, fx_n_sel_tr, sel_track, slot_to_move-1, true)
        reaper.Undo_EndBlock2(0, 'Move '..undo_fx_name..' to '..slot_to_move..'th slot', 2)
        reaper.PreventUIRefresh(-1)
        return 0
      end
    end
  end
  reaper.defer(check)
end
 
sel_track = reaper.GetSelectedTrack2(0, 0, true)
if not sel_track then reaper.ShowMessageBox('Select a track','vitalker move FX to slot x',0) return 0 end
fx_n_sel_tr = reaper.TrackFX_GetCount(sel_track)
slot_to_move = 1 --REPLACE BY ANY NUMBER IF YOU NEED TO
if tonumber(slot_to_move) > fx_n_sel_tr+1 then
  reaper.ShowMessageBox('Enter slot number from 1 to '..fx_n_sel_tr+1,'vitalker move FX to slot x',0)
  return 0
end
if sel_track then
  reaper.PreventUIRefresh(1)
  reaper.SetMediaTrackInfo_Value(sel_track, 'I_SELECTED', 0)
  reaper.SetMediaTrackInfo_Value(sel_track, 'I_SELECTED', 1)
  if reaper.GetToggleCommandStateEx(0,40271) == 1 then
    reaper.Main_OnCommand(40271, 0)
    reaper.Main_OnCommand(40271, 0)
  elseif reaper.GetToggleCommandStateEx(0,40271) == 0 then
    reaper.Main_OnCommand(40271, 0)
  end
  reaper.PreventUIRefresh(-1)
  slot_to_move = tonumber(slot_to_move)
  check()
end