
Load Theremino_HAL.exe
Load Theremino_SlotViewer.exe
Load Theremino_SlotViewer2.exe
Load Theremino_SlotsToMidi\Theremino_SlotsToMidi.exe

EnableAll
Goto Loop

Stop

Variable Numeric FirstMidiSlot = 500
Variable Numeric NumMidiSlots = 72 ' = 6 ottave

Variable Numeric FirstStepperSlot = 101
Variable Numeric FirstEnableSlot = 106

Label Loop
	v1 = 0
	For v2 = 0 To 4
		ScanSlots
	Next
Goto Loop

Label ScanSlots
	Frequency = 1e7
	For v1 = v1 + 1 To NumMidiSlots
		If Slot(FirstMidiSlot + v1) > 0
			NoteToFrequency(v1)
			Exit
		EndIf
	Next
	Slot(FirstStepperSlot + v2) = Frequency
Return

Label NoteToFrequency
	Variable Numeric Note
	Variable Numeric Octave
	Variable Numeric Frequency
	Octave = Int((Note - 1) / 12)
	Note = Mod(Note - 1, 12) + 1
	Select Note
		Case 1   ' DO
			Frequency = 261.63
		Case 2   ' DO #
			Frequency = 277.18
		Case 3   ' RE
			Frequency = 293.66
		Case 4   ' RE #
			Frequency = 311.13
		Case 5   ' MI
			Frequency = 329.63
		Case 6   ' FA
			Frequency = 349.23
		Case 7   ' FA #
			Frequency = 369.99
		Case 8   ' SOL
			Frequency = 392.00
		Case 9   ' SOL #
			Frequency = 415.30
		Case 10  ' LA
			Frequency = 440
		Case 11  ' LA #
			Frequency = 466.16
		Case 12  ' SI
			Frequency = 493.88
	EndSelect
	Frequency = Frequency * Pow(2, Octave)
Return

Label EventStop
	DisableAll
End

Label EnableAll
	For v1 = FirstEnableSlot To FirstEnableSlot + 4
		Slot(v1) = 1000
	Next
Return

Label DisableAll
	For v1 = FirstEnableSlot To FirstEnableSlot + 4
		Slot(v1) = 0
	Next
Return


