// Example of a one button standard looper. First loop length will be the length of all other loops // // Author: LoopToGo // // Arguments or user arguments : // 1 : (optional) gFirstTrack, track number to start the looping, default is 1 // 2 : (optional) gNbBars, number of bars for the first recording, default is 10 // // Warning when using with midi events, make sure "Use MIDI events as arg" is uncheck! loadScript Looptogo\aliases.txt // To use aliases instead of shortcut commands ///////////////////////////////////////////////////////// ///////////// For debugging // Note see LoopToGo\libs\debugUtilities.ltgl For details on how to use debugging loadScript LoopToGo\libs\debugUtilities.ltgl // To uses debugging prints // Uncomment the following line to remove all debug prints. When uncommented, there is no impact on perfromance //alias debug doNothing // Set tag Info and Info2 to 1 to print or 0 to not print debugTag Info 1 debugTag Info2 0 alias print debug Info [ $scriptLineNumber ] alias print2 debug Info2 [ $scriptLineNumber ] // Uses { and } to increment and decrement debug message alias { debugIncreaseIndentation alias } debugDecreaseIndentation ///////////// End of debugging ///////////////////////////////////////////////////////// // Do not run the script without a track if $nbTracks < 1 setUserArgs // Reset the users args just in case! endScriptDynamic endIf // Refrain from calling this script twice in a short time (see debounce of midi events below) variable deltaTime $sysTime - $gLastExecutionTime globalVariable gLastExecutionTime $sysTime ///////////////////////////////////////////////////////// ///////////// Script configuration alias aDefaultFirstTrack 1 // The first track used For looping alias aDefaultNbBars 10 // Lenght of first record loop If not specified by $arg1 or $userArg1 alias aGridLineColor #224422 // Color For the grid lines ///////////// End of configuration ///////////////////////////////////////////////////////// alias true 1 alias false 0 // Locked state value For loops alias UnLockedState 0 alias LockedState 3 alias OverdubMode 6 // Looper States alias LooperStoppedAndEmpty 0 alias LooperStopped 1 alias LooperRecord 2 alias LooperPlay 3 alias LooperOverdub 4 // Track monitoring mode alias InLoopsOrWhileTrackSelected 3 // If this script is called a second time within 200 ms, the script is not executed if $deltaTime < 200 print "Debouncing: " $deltaTime endScriptDynamic endIf // Code For pausing or resetting the looper with a double click. if $deltaTime < 500 print "Double click: " $deltaTime $gLooperState $isRecording if $gLooperState = LooperStopped loadScript LoopToGo\LooperEmulations\resetSong.ltgs // The user ask For stop twice to reset the looper endScriptDynamic endIf if $isRecording pause endScriptDynamic endIf endIf print "Start of script: " callFunction fctComputeLooperState // The looper state must be compute in case the user used Ctr-Z (undo) or Ctr-Y (Redo) // If we are not starting from scratch, just make sure we have a jam marker if $nbMarkers < 1 print2 startJamMode $gFirstRecordLoopID startJamMode $gFirstRecordLoopID endIf // Execute actions upon Looper State value if $gLooperState = LooperStoppedAndEmpty // First time globalVariable gNbBars aDefaultNbBars globalVariable gFirstTrack aDefaultFirstTrack // Let's see if users provided arguments if $nbUserArgs globalVariable gFirstTrack $userArg1 if $nbUserArgs > 1 globalVariable gNbBars $userArg2 endIf setUserArgs // Make sure user args a resetted else if $nbArgs globalVariable gFirstTrack $arg1 if $nbArgs > 1 globalVariable gNbBars $arg2 endIf endIf endIf print gFirstTrack: $gFirstTrack gNbBars: $gNbBars // Let's init global variables and start start recording callFunction fctInitAndStartRecording else // Script called but not first time setUserArgs // reset the users args just in case! print LooperState : $gLooperState // Let's do action upon looper state value if $gLooperState = LooperRecord callFunction fctStopFirstRecording endScriptDynamic endIf if $gLooperState = LooperPlay callFunction fctNewOverdub endScriptDynamic endIf if $gLooperState = LooperOverdub callFunction fctStopOverdub endScriptDynamic endIf if $gLooperState = LooperStopped callFunction fctStopOverdub setBar $gFirstRecordLoopStart shortcutByID 39 // Start recording endIf endIf // All initialization and start of recording function fctInitAndStartRecording { print "fctInitAndStartRecording: " globalVariable gFirstTime true globalVariable gInRecordLoop true globalVariable gLooperState LooperRecord globalVariable gFirstRecordLoopStart $songBar selectTrack $gFirstTrack callFunction setTracksMonitoringMode // First record loop addRecordLoop $selectedTrack FirstLoop $gFirstRecordLoopStart $gFirstRecordLoopStart + $gNbBars globalVariable gFirstRecordLoopID $lastCreatedRecordLoopID // Since we are not sync with any tempo, let's remove the grid lines and add our own grid lines setGridLinesVisibility 0 removeAllCustomGridLines // In case there are older grid lines addCustomGridLine $gFirstRecordLoopStart 3 aGridLineColor addCustomGridLine $gFirstRecordLoopStart + $gNbBars 3 aGridLineColor record // Start recording startJamMode $lastCreatedRecordLoopID } endFunction // Add a new record loop and set it in overdub mode. function fctNewOverdub { print "fctNewOverdub: " setLoopLockState $lastCreatedRecordLoopID LockedState addRecordLoop $selectedTrack "Overdub" $gFirstRecordLoopStart $gFirstRecordLoopEnd jamMode // Starts jam mode setLoopJamState $lastCreatedRecordLoopID OverdubMode } endFunction // Stop the first recordin and lock the loop function fctStopFirstRecording { print "fctStopFirstRecording: " // We must compute the next start of the record loop which must be the start of the first record loop plus a integer number of the first record loop length globalVariable gFirstRecordLoopEnd $songBar globalVariable gFirstRecordLoopLength $gFirstRecordLoopEnd - $gFirstRecordLoopStart print $lastCreatedRecordLoopID $gFirstRecordLoopStart $gFirstRecordLoopEnd setLoopStartAndEnd $lastCreatedRecordLoopID $gFirstRecordLoopStart $gFirstRecordLoopEnd setLoopLockState $lastCreatedRecordLoopID 3 // 3 = Locked jumpTo $gFirstRecordLoopStart // More accurate than setBar!!! waitDelta .01 // Wait For the jump! startJamMode $lastCreatedRecordLoopID // Make sure we stay in Jam Mode } endFunction // Lock the last overdub loop function fctStopOverdub { print "fctStopOverdub: " setLoopLockState $lastCreatedRecordLoopID LockedState } endFunction // Determine the looper state based on recording state and loops state function fctComputeLooperState { print "fctComputeLooperState: " globalVariable gLooperState LooperPlay ifNot $isRecording if $nbLoops = 0 globalVariable gLooperState LooperStoppedAndEmpty else globalVariable gLooperState LooperStopped endIf exitFunction // The state has been set, exit!!! endIf for loop 1 $nbLoops variable loopID loopID & $loop getLoopJamState loopJamMode $$loopID getLoopLockState loopLockState $$loopID if $loopLockState = UnLockedState if $loopJamMode = OverdubMode globalVariable gLooperState LooperOverdub else globalVariable gLooperState LooperRecord endIf exitFunction // The state has been set, exit!!! endIf endFor } endFunction // Set all tracks Play Record and Pause monitoring mode to "In loops or when track is selected" function setTracksMonitoringMode { print "setTracksMonitoringMode: " for track 1 $nbTracks setChainRecordPlayMonitorMode $track InLoopsOrWhileTrackSelected endFor } endFunction