// Automatically create record and play loops for the selected track using section markers.
// Arguments:  
//		(no argument)
//
// Author: LoopToGo
//
// Description  : 	For a selected track, create a Record Loop for each Section. 
//					The name of the Loop will be the same as the Section.
//					If a Section has the same name as a previous section, a Play loop
//					will be created instead. The Play loop will be link to the corresponding
//					Record loop.


// Check if a track is selected
ifNot $selectedTrack
	endScriptDynamic  // No need to continue
endIf

print Creating loops for selectedTrack : $selectedTrack

for section 1 $nbSections

	variable sectionName sectionName & $section
	variable sectionStart sectionStart & $section
	variable sectionEnd sectionEnd & $section
	variable loopName loop_ & $$sectionName
	
	variable sectionlength $$sectionEnd - $$sectionStart
				
	if $sectionlength > 0	
		if $$loopName
			// A loop with this name exist, we add a Play loop
			addPlayLoop $selectedTrack $$sectionName $$sectionStart $$sectionEnd
		else
			variable $loopName 1
			addRecordLoop $selectedTrack $$sectionName $$sectionStart $$sectionEnd
		endIf
	endIf
	
	//print Created loop $selectedTrack $$sectionName $$sectionStart $$sectionEnd
		
endFor