Assigning values to variables
Use the Let instruction to assign a value to a variable. The second word of the instruction is the variable name and after that you type an "=" and specify the value. The value can be a literal as in:
Let DataByte2 = 60
It can also be another variable (user-defined or pre-defined):
Let DataByte2 = MyNewValue
The new value may also be specified in a function. The available functions are listed in the help file. You may want to increase the value of databyte2 in selected events:
Let DataByte2 = Add DataByte2 10
The function "Add DataByte12 10" will compute the total of DataByte2 and 10. Of course the value should never be higher than 127. So it should be followed by:
If DataByte2 > 127
DataByte2 = 127
EndIfYou can run the following program to experience that you can increase the tempo in a style:
Define OriginalTempo Numeric
Let OriginalTempo = Tempo
ForEachPart
PrintLine PartName
PrintLine 'Playing normal tempo'
PlayPart
Let Tempo = 250
PrintLine 'Playing fast tempo'
PlayPart
Let Tempo = OriginalTempo
NextPartAnother way to assign a value to a variable is with the Input instruction. The Input is only allowed for user defined variables. When the Input instruction is encountered you are requested to enter a value for the variable in the upper right corner of the window. Try running the following program:
Define NewTempo Numeric
Input NewTempo
Let Tempo = NewTempo
PlayPartIf constructions
If you already have been programming in other languages, then you have probably used complex If.. And..Or..Else contructions, complete with formulas. In STPL you can do all that differently in one or more of the following ways.
If there are more conditions and all of them should be true, then make nested If's:
If EventType = 1
If DataByte2 > 100
If DataByte2 <= 110
;Instructions inserted here will only be executed on note-on events with velocity 101 thru 110
EndIf
EndIf
EndIfWhen you cut and paste examples in this tutorial to the STPL editor and press the Run button, then you will notice that the lines between If..EndIf and between ForEach..Next are automatically indented. This makes it easier to see which lines are captured in these constructions. Each Next must be aligned with the matching ForEach, and each EndIf with its If. If this is not the case then these constructs are either incomplete or overlapping. For example the sequence: If-ForEachTrack-EndIf-NextTrack is not correct. It should be If-ForEachTrack-NextTrack-EndIf.
If there are more conditions and only one has to be true, then define a numeric variable that has the value 0 if false and 1 if true.
Let MainPart = 0
If PartName = 'Main A'
Let MainPart = 1
EndIf
If PartName = 'Main B'
Let MainPart = 1
EndIf
If PartName = 'Main C'
Let MainPart = 1
EndIf
If PartName = 'Main D'
Let MainPart = 1
EndIf
If MainPart = 1
;Instructions inserted here will only be executed in Main parts
EndIfIf you want to replace some notes in the drum tracks to other values, you may want to do it like this:
If DataByte1 = 32
Let DataByte1 = 34
EndIf
If DataByte1 = 33
Let DataByte1 = 40
EndIf
If DataByte1 = 34
Let DataByte1 = 37
EndIf
This is not correct! The value 32 is first changed to 34. But then further on the value 34 is changed to 37. That is not what you intended. Only the events that had originally the value 34 should be changed to 37. The events that were originally 32 should be changed to 34 and stay 34. You can accomplish this by defining a numeric variable NewDataByte1 and give that the (invalid) value -1 first .
Let NewDataByte1 = -1
If DataByte1 = 32
Let NewDataByte1 = 34
EndIf
If DataByte1 = 33
Let NewDataByte1 = 40
EndIf
If DataByte1 = 34
Let NewDataByte1 = 37
EndIf
If NewDataByte1 > -1
Let DataByte1 = NewDataByte1
EndifInstead of formulas you must use as many additional Let instructions and user defined variables as needed. So instead of:
If Variable1 = ((Variable2 + Variable3) * Variable4)
You write:Let AdditionalVariable1 = Add Variable2 Variable3
Let AdditionalVariable1 = Multiply AdditionalVariable1 Variable4
If Variable1 = AdditionalVariable1Modifying styles
When you modify styles you will change the predefined variables in each style and then save it. Actions upon predefined variables should be done in the associated ForEach loop for that variable, both assigning a value to that variable and using the value in that variable. In general a program will have this construction:
;Define user variables here
ForEachStyle
;Assign values to StyleName, FolderName, Tempo, BeatsPerMeasure and TicksPerBeat
ForEachPart
;Assign values to PartName and MeasuresInPart
ForEachTrack
;Assign values to Track, TrackName, TrackChannel, TranspositionType, DrumTrack,
;NoteLow, NoteHigh, HighKey, SourceChord, SourceChordType, ChordNote1 thru ChordNote5
ForEachEvent
;Assign values to EventType, DataByte1, DataByte2, Measure, Beat, Tick
UpdateEvent ; Must be specified or the assigned event values will not be kept OR
InsertEvent ; Alternatively you can insert a new event with the assigned values OR
DeleteEvent ; Will remove the current event
NextEvent
NextTrack
NextPart
SaveStyle
NextStyleWhile testing you better remove (or place a semicolon before) the ForEachStyle, SaveStyle and NextStyle instructions. You will be testing with just one style and don't want to save it. If you just want to work with Part variables then the ForEachTrack and ForEachEvent loop can be removed too. When a style is saved then any change you made to the predefined varables is saved too. A special rule is for the Event variables: you must specify UpdateEvent before the changes come in effect. Alternatively you can specify InsertEvent to add an event with the values that you assigned to the predefined event variables. If you did not assign a value then the value form the current event will be copied in the inserted event. DeleteEvent will remove the current event.
It is possible to make the part and track loops inside out: the ForEachPart loop is placed inside the ForEachTrack loop. An example is the sample program AvarageLoudness. This program will stay inside a track while walking tru the parts, evaluating the volume controllers in the track that may occur in different parts. Also notice that besides parts with well known names like "Main A" there is also a part named "Control changes". This contains patches and controllers to setup the synthsizer. In styles converted from non-Yamaha keyboards these patches and controllers are often also present in the other parts.
Always make copies of your styles. You might want to restore the originals.