Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 08-27-2018, 09:42 AM   #1
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
Default New Script: Play and store & toggle previous 3 play positions

Hi guys,

Here are 2 companion scripts to be used with each other. One for "Play" and one for "Stop". The scripts track the previous 3 play position as well as your last stopped position and will toggle through those positions when you hit the "Stop" key.

If people are interested, I'll also include a "Record" version that will also add the Record/Play positions to the history.

Here I used the space bar for Play and the comma for Stop. In the example below, I played for 3 different start positions, and with the comma key "," I toggled between the last 3 starts and most recent stop. The script is also smart in that it ignores repeated starts from the same position and doesn't add them to the history:



Here is the play code:
Code:
--[[
    Description: Thonex_Mem Play -- Play and store & toggle previous 3 play positions
    Version: 1.0.0
    Author: Thonex
    Instructions: To be used with companion script "Thonex_Mem Stop -- Stop and toggle last 3 play-start positions"
                  Bind this scfript to a "Play" shortcut.
]]--

function Msg (param)
  reaper.ShowConsoleMsg(tostring (param).."\n")
end



function Play_Start_History ()
  reaper.ClearConsole()
  
  -- initial settings (no nil) if hitting play for the first time in a project
  reaper.SetExtState("Thonex_Play_Locations", "Stop_Counter",1,false)
  
  if reaper.GetExtState("Thonex_Play_Locations", "Init_State") == "" then
    reaper.SetExtState("Thonex_Play_Locations", "Play_Pos_1", 0, false)
    reaper.SetExtState("Thonex_Play_Locations", "Play_Pos_2", 0, false)
    reaper.SetExtState("Thonex_Play_Locations", "Play_Pos_3", 0, false)
    reaper.SetExtState("Thonex_Play_Locations", "Play_Pos_4", reaper.GetCursorPosition(), false)
    reaper.SetExtState("Thonex_Play_Locations", "Init_State", 1, false)
  end
  
  --get external states
  Play_mem_1 = reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_1")
  Play_mem_2 = reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_2")
  Play_mem_3 = reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_3")
  
  reaper.SetExtState("Thonex_Play_Locations", "Play_Pos_4", reaper.GetCursorPosition(), false)
  Play_mem_4 = reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_4")

  reaper.Main_OnCommand(1007, 0 ) --Transport: Play
  
  
  -- update states if playing from a different place by
  --shifting all play memories to lower momory slots
  if Play_mem_4 ~= Play_mem_3 then
  Play_mem_1 = reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_2")
  Play_mem_2 = reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_3")
  Play_mem_3 = reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_4")
  end
  
  
  -- set updated external states
  
  reaper.SetExtState("Thonex_Play_Locations", "Play_Pos_1",  Play_mem_1, false)
  reaper.SetExtState("Thonex_Play_Locations", "Play_Pos_2",  Play_mem_2, false)
  reaper.SetExtState("Thonex_Play_Locations", "Play_Pos_3",  Play_mem_3, false)
  
  
  -- message play memories
  --[[
  Msg(reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_1"))
  Msg(reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_2"))
  Msg(reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_3"))
  Msg(reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_4"))
  ]]

end
 

Play_Start_History ()

Here is the stop code:
Code:
--[[
    Description: Thonex_Mem Stop -- Stop and toggle previous 3 play-start positions
    Version: 1.0.0
    Author: Thonex
    Instrictions: to be used with the companion sctipt "Thonex_Mem Play -- Play and store last 3 play positions"
    				Bind this script with a "stop" shortcut. Press the shortcut to toggle the last 3 play 
    				positions and then it will cycle to your last stopped position. 
]]--

function Msg (param)
  reaper.ShowConsoleMsg(tostring (param).."\n")
end



function Stop_And_Goto_Memorized_Location ()
    reaper.ClearConsole()
    Play_Loc={}
   
    if reaper.GetPlayState() == 1 then
      reaper.Main_OnCommand(40434, 0 ) -- 40434 View: Move edit cursor to play cursor
      reaper.Main_OnCommand(1016, 0 ) -- 1016 Transport: Stop
      Play_Loc[4] = reaper.GetCursorPosition()
      reaper.SetExtState("Thonex_Play_Locations", "Play_Pos_4",Play_Loc[4], false) -- Play_Pos_4 is last location where play stopped
    else
    
      --get external var states
      Play_Loc[1] = tonumber(reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_1"))
      Play_Loc[2] = tonumber(reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_2"))
      Play_Loc[3] = tonumber(reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_3"))      
      Play_Loc[4] = tonumber(reaper.GetExtState("Thonex_Play_Locations", "Play_Pos_4"))
      
      Stop_i =  tonumber(reaper.GetExtState("Thonex_Play_Locations", "Stop_Counter"))
    
      if Stop_i == nil then 
        Stop_i = 0
      end
      
      reaper.SetEditCurPos(Play_Loc[4-Stop_i],1, 0 )
      --[[
      Msg(Play_Loc[1])
      Msg(Play_Loc[2])
      Msg(Play_Loc[3])
      Msg(4-Stop_i)
      Msg(Play_Loc[4-Stop_i])
      ]]
      
      Stop_i = (Stop_i + 1) % 4
      reaper.SetExtState("Thonex_Play_Locations", "Stop_Counter", Stop_i, false) 
    end
   

end

Stop_And_Goto_Memorized_Location ()
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex 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:39 PM.


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