// Script that has a different behavior if the song is stopped vs recording for jamming
// Arguments:  
//		(no argument)
//
// Author: LoopToGo
//
// Description  : 	Start recording if the song is stopped otherwise, starts the Jam mode if not already jamming and over a record loop
//					Stop the jam mode if already in jam mode
//					This is an example of how to setup a midi pedal with different behaviors

ifNot $isRecording
	shortcut "Ctrl+Space"  	// Start recording
	globalVariable gInJamMode 0
	endScriptDynamic 	 	// No need to do anything else
endIf

unselectAllLoops // We will use selectedLoop to confirm that the jam mode has been enabled so we need to unselectAllLoops first

ifNot $gInJamMode

	shortcut "Ctrl+Down"  // Select the loop at song bar for selected track
	
	if $selectedLoopID
	
		getLoopType selectedLoopType $selectedLoopID
		
		if $selectedLoopType = Record
			shortcut J
			globalVariable gInJamMode 1
			endScriptDynamic 	 	// No need to do anything else
		endIf

	endIf
	
	print "Make sure you are over a record loop to enable jam mode!"
			
	endScriptDynamic 	 	// No need to do anything else

endIf

shortcut O
globalVariable gInJamMode 0

