After opening a port, you can call MidiIoOutShort to output one MIDI message (ie, event) of limited size to the currently open MIDI Out port. Each call to MidiIoOutShort() will output one event, so you'll typically make a series of calls, perhaps with delays inbetween each call in order to implement some sort of timed output.

You pass the type of event that you wish output. You can pass either an ID number or ID name, for example, 144 or "On Note" to sound a note. When passing a name, only the first 4 characters are significant, so "On N" is the same as "On Note".

You also pass the MIDI channel upon which you would like the event transmitted. The MIDI channels are numbered 1 to 16. If you pass an empty string, then this means that you intend to supply an Event Type number that already includes the channel (such as what MidiIoInput would return).

Finally, you must pass the data values for the event. If omitted, then the same data values as the last MidiIoOutShort() event are used. What data values you supply, and what they signify, depends upon the type of event.

MidiIoOutShort() will return an empty string if the event is output successfully, or an error message if a failure.

For example, here we sound a middle C note (with a velocity of 100) on MIDI channel 1, let it sound for 3 seconds, and turn turn it off:

/* Output a middle C Note On with velocity=100 on channel 1. */
err = MidiIoOutShort(1, "On Note", 60 100)
IF err \== "" THEN SAY err

/* Delay for a little while to give it time to sound. */
SLEEP(3)

/* Output a Note Off for that middle C -- same channel. */
err = MidiIoOutShort(, "(Off) Note")
IF err \== "" THEN SAY err
Here we output a Pitch Wheel event on channel 3 to center the wheel. Note that a pitch wheel event has only 1 data value -- a position from -8192 to 8191 where 0 is center position (ie, no pitch transposition).
/* Output a centered pitch wheel on channel 3. */
err = MidiIoOutShort(3, "Pitch", 0)
IF err \== "" THEN SAY err

Large messages, or multiple events

If your System Exclusive message has 255 data values or less, you can use MidiIoOutShort() to output it. But if there are more than 255 values, you must use MidiIoOutLong(). You must pass the message to be output. The first value must be the type ID number (not an ID name), which for System Exclusive is 240. Then, the data values follow, each separated by at least one space. The last data value should be 247 for a System Exclusive message. Data values must be expressed in decimal (base 10), not hexadecimal (base 16). Use the Windows Calculator utility while notating your script if you need to convert between bases.

For example, here we output the message "240 127 127 4 1 127 127 247". (Yes, you can use MidiIoShortMsg() for this message, since it has less than 255 values after the 240 ID number. That would be more efficient. But this is just to demonstrate how to call MidiIoOutLong):

/* Output a System Exclusive message. */
err = MidiIoOutLong("240 127 127 4 1 127 127 247")
IF err \== "" THEN SAY err
Whereas MidiIoOutShort() outputs only one event at a time, MidiIoOutLong() could be used to output several events with one call. The events get output one immediately after the other. (To the human ear, it would seem as if they were all "playing" simultaneously). You set the value of the variable to the combined string of all events. You must use type ID numbers (not names). For Voice category messages, such as On Note and (Off) Note, you need to add the desired MIDI channel number (minus 1) to the ID number. And you may not omit any data values. For Pitch Wheel and Song Position, you must specify two values exactly as they are transmitted over MIDI (rather than as one value like with MidiIoOutShort()).

For example, below we will pass a variable that contains 3 events.

The first event is an On Note for middle C with a velocity of 100. It will be on MIDI channel 1. So, we take the ID number for an On Note, which is 144 (according to our ID number chart), and add the MIDI Channel minus 1. That would be 144 + 1 - 1, or 144. Then we need two data values, the note number which will be 60 here, and the velocity which will be 100.

The second event is an (Off) Note for the D above middle C. It will be on MIDI channel 4. So, we take the ID number for an (Off) Note, which is also 144, and add the MIDI Channel minus 1. That would be 144 + 4 - 1, or 148. Then we need two data values, the note number which will be 62 here, and the velocity which is always 0 for an (Off) Note.

The third event is a Program event to select program number 5. It will be on MIDI channel 10. So, we take the ID number for Program, which is 192, and add the MIDI Channel minus 1. That would be 192 + 10 - 1, or 201. Then we need one data value, the program number which will be 5 here.

Here is how we output all three events simultaneously with MidiIoOutLong():

/* Output 3 events simultaneously. */
MyVar = "144 60 100 148 62 0 201 5"
err = MidiIoOutLong(MyVar)
IF err \== "" THEN SAY err
It is possible to omit some ID number if it is the same value as the preceding event. For example, if you have two On Note events in a row, both on the same MIDI channel, you can omit the second event's ID number. But at least the very first event should have an ID number.