Event Scripts are feature I expect to evolve a lot in the future, but I wanted to get something
basic out there early to see how well it works for a particular use case: Sending a MIDI event
when the loop reaches the end (gustebeast).
The way it is configured is rather crude, but for now, go the Global Parameters panel
and select the Files tab. In the form is the field labeled "Event Script" which is actually
not a file at all, it is the name of a script that must be loaded into the script library.
The script must be written in MSL. The name will either be the file name without the
containing folder, for example c:\Users\Jeff\scripts\test.msl would just be "test". Or
you can use the #name directive in the script to give it a better name:
#name My Event Script
This script will be run whenever a few things happen in an AUDIO track. They do not yet
work with MIDI tracks. Internally these are called "notifications", and I may start using
that term since "event" is already being used for too many things. Information about the notification
is passed into the script using positional arguments you reference with special symbols that start
with the dollar sign: $1, $2, etc.
Here is an example script that sends a MIDI note whenever a track reaches the end and loops.
#name MidiNoteAtLoopStart
if ($1 == "LoopStart") {
MidiOut("note", 1, 42)
}
The first #name line is a "declaration" that let's you select the reference name for this
script if you want to use something other than the file name. If the file containing
this script is in c:\Users\Jeff\mobius\script\something.msl then the the default script
reference name will be "something". You might want to use #name to give it a more meaningful name.
This line decides which of the various notifications you want to pay attention to:
if ($1 == "LoopStart") {
The $1 is a reference to the first positional argument passed into the script. For event scripts
it will contain the name of the events. At the time of this writing, the possible event names are
Reset
RecordStart
RecordEnd
MuteStart
MuteEnd
ModeStart
ModeEnd
LoopStart
LoopCycle
Many other event types are planned for the future, let me know what you would find interesting.
This line sends the MIDI event
MidiOut("note", 1, 42)
The first argument is the MIDI message type, it may be one of these names
note, noteOn
noteOff
control, cc
start
stop
continue
clock
poly
touch
bend
The second argument is the MIDI channel number from 1 to 16.
The third argument is the MIDI note number.
By default the velocity of this note will be 127. If you want to specify a velocity
add a fourth argument:
MidiOut("note", 1, 42, 64)
For continuous control events, you must specify the fourth argument which becomes
the value of the CC.
MidiOut("cc", 1, 42, 127)
MidiOut("cc", 1, 42, 0)
The MIDI message will be sent to the default device. When running as a plugin this will
be the host application unless you have explicitly configured a MIDI device for the plugin
in the MIDI Devices configuration panel. When you enable MIDI output devices for the plugin,
one of them may be designated as the "Export" device. If Export is checked, this will be the default
device for the MidiOut function instead of the host.
If you need to send message to more than one MIDI device, there is an optional argument
that may be placed in front of the type name:
MidiOut(0, "cc", 1, 42, 127)
The 0 in this example is the "device id". When you configure devices in the MIDI Devices panel,
device ids are assigned starting from 0 and going up by 1 for each enabled device, in the order
they appear in the table.
If the table looks like this:
Device Enabled
Something x
Another x
Bome 1 x
Then device id 0 means the device named "Something", 1 means "Another", etc.
Using numeric device ids can be difficult in scripts because they can change whenever
you add or remove devices or change which ones are enabled. If you unhecked the Enabled
box for "Another" for example, then 0 would still mean "Something" but 1 would now mean "Bome 1".
To make scripts more tolerant of changes to the device configuration you can use
the GetMidiDeviceId function like this:
var deviceId = GetMidiDeviceId("Bome MIDI Translator 2")
What this does is define a local variable named "deviceId" and gives it the value
returned by the GetMidiDeviceId function. GetMidiDeviceId takes the device name as an argument,
determines it's location in the enabled device list and returns that id. You can then
use this variable in the MidiOut function:
MidiOut(deviceId, "cc", 1, 42, 127)
The event script always receives two positional arguments and sometimes three. The second
argument is the number of the track in which the event happened. So if you only want to send
a MIDI event when something happens in track number 1, you can adjust the "if" statement like this:
if ($1 == "LoopStart" and $2 == 1) {
The $3 argument is only available for certain event types, currently just ModeStart and ModeEnd
whhere it will contain the name of the major mode that is starting or ending. For example:
if ($1 == "ModeStart" and $2 == 1 and $3 == "Insert") {
print("Insert mode is starting in track number 1")
}