
' -----------------------------------------------------------------
'  BUTTONS
' -----------------------------------------------------------------
Button 2 Label RunSequence1
Button RunSequence1 Text "Run sequence 1"
Button RunSequence1 Color Yellow8

Button 3 Label RunSequence2
Button RunSequence2 Text "Run sequence 2"
Button RunSequence2 Color Yellow8

Button 5 Label EditSequence1
Button EditSequence1 Text "Edit sequence 1"
Button EditSequence1 Color Yellow8

Button 6 Label EditSequence2
Button EditSequence2 Text "Edit sequence 2"
Button EditSequence2 Color Yellow8

Stop												'



' =====================================================================
'  LED COLORS
' =====================================================================
Label Red
	Slot(1) = 1000
	Slot(2) = 0
	Slot(3) = 0
Return

Label Green
	Slot(1) = 0
	Slot(2) = 1000
	Slot(3) = 0
Return

Label Blu
	Slot(1) = 0
	Slot(2) = 0
	Slot(3) = 1000
Return


' =====================================================================
'  SEQUENCES
' =====================================================================
Label InitSequencePaths
	Variable String EditorFolder
	Variable String EditorApp
	Variable String Sequence1
	Variable String Sequence2
	'
	EditorFolder = ".\Apps\Theremino_Editor\"
	'
	EditorApp = EditorFolder + "Theremino_Editor.exe"
	'
	Sequence1 = EditorFolder + "Sequences\TestSequence.seq"
	'
	Sequence2 = EditorFolder + "Sequences\ChangeSpeed.seq"
Return

Label RunSequence1
	Gosub InitSequencePaths
	SequenceToExecute = Sequence1
	For v1 = 1 To 3
		Gosub ExecSequence
	Next
Return

Label RunSequence2
	Gosub InitSequencePaths
	SequenceToExecute = Sequence2
	Gosub ExecSequence
Return

Label EditSequence1
	Gosub InitSequencePaths
	Load EditorApp + " " + Sequence1
Return

Label EditSequence2
	Gosub InitSequencePaths
	Load EditorApp + " " + Sequence2
Return


' =====================================================================
'  SEQUENCE LOADING AND EXECUTION
' =====================================================================
Variable String SequenceToExecute
Variable String Sequence
Variable String SequenceCmd
Variable Numeric SequenceIndex
Variable Numeric SequenceLength
Variable Numeric SequenceValue

Label ExecSequence
	Load Sequence SequenceToExecute
	If Len(Sequence) = 0
		Controls OpenTextBox
		Print CRLF + " Sequence file not found: " + SequenceToExecute
		Beep
		Stop
	EndIf
	'
	Print CRLF + "Sequence " + GetFileNameWithoutPath(SequenceToExecute)
	Print " started at " + Format(Now, "HH:mm:ss") + CRLF + Chars("-", 50) + CRLF
	' ----------------------------------------------------------
	Variable Numeric ExecSequenceStartTime
	ExecSequenceStartTime = ElapsedTime
	' ----------------------------------------------------------
	SequenceLength = GetSeparatedStringCount(Sequence, CRLF)
	For SequenceIndex = 0 To SequenceLength - 1
		' ------------------------------------------------------
		SequenceCmd = GetSeparatedString(Sequence, SequenceIndex, CRLF)
		SequenceCmd = Replace(SequenceCmd, Chr(9), " ") 'TABS to SPACES
		' ------------------------------------------------------ Do not print lines containing ''
		If GetSeparatedStringCount(SequenceCmd, "''") < 2
			Print " Exec: " + SequenceCmd + CRLF
		EndIf
		' ------------------------------------------------------ Trim and remove comments
		SequenceCmd = Trim(RemoveComments(SequenceCmd))
		' ------------------------------------------------------
		If SequenceCmd <> ""
			Select GetSeparatedString(SequenceCmd, 0)
				' ---------------------------------------------- LED COLORS
				Case "Red"
					Gosub Red
				Case "Green"
					Gosub Green
				Case "Blu"
					Gosub Blu
				' ---------------------------------------------- End sequence
				Case "EendSeq"
					SequenceIndex = SequenceLength-1
				' ---------------------------------------------- With parameters
				Case "Pause"
					Wait Seconds GetSeparatedString(SequenceCmd, 1)
				Case "Speed"
					SequenceValue = GetSeparatedString(SequenceCmd, 1)
					Option Speed SequenceValue
				Case "Transparency"
					SequenceValue = GetSeparatedString(SequenceCmd, 1)
					Option Transparency SequenceValue
				Case "PressKeys"
					SequenceCmd = Mid(SequenceCmd, 11)
					PressKeys SequenceCmd
				Case "SendKeys"
					SequenceCmd = Mid(SequenceCmd, 10)
					SendKeys SequenceCmd
				' ---------------------------------------------- Errors
				CaseElse
					Controls OpenTextBox
					Print CRLF + " Unrecognized command: " + SequenceCmd + CRLF
					Beep
					Stop
			EndSelect
		EndIf
	Next
	Print Chars("-", 50) + CRLF + "Sequence " + GetFileNameWithoutPath(SequenceToExecute)
	Print " executed in " + Format(ElapsedTime - ExecSequenceStartTime, "0.00") + " sec" + CRLF
Return


'EXEC Load CloseApps EditorApp
