Subsections

- Channel
- ChannelPref
- ChShare
- ForceOut
- MIDI
- MIDIClear
- MIDIFile
- MIDIGlis
- MIDIInc
- MIDIMark
- MIDIPan
- MIDISeq
  - MIDIDef
- MIDISplit
- MIDITname
- MIDIVoice
- MIDIVolume

#
Low Level MIDI Commands

The commands discussed in this chapter directly effect your MIDI output devices.

Not all MIDI devices are equal. Many of the effects in this chapter may be ignored by your devices. Sorry, but that's just the way MIDI is.

#
Channel

As noted in Tracks and Channels MMA assigns MIDI channels dynamically as it creates tracks. In most cases this works fine; however, you can if you wish force the assignment of a specific MIDI channel to a track with the CHANNEL command.

You cannot assign a channel number to a track if it already defined (well, see the section CHSHARE, below, for the inevitable exception), nor can you change the channel assignments for any of the DRUM tracks.

Let us assume that you want the Bass track assigned to MIDI channel 8. Simply use:

Bass Channel 8

Caution: If the selected channel is already in use an error will be generated. Due to the way MMA allocates tracks, if you really need to manually assign track it is recommended that you do this in a MMARC file.

You can disable a channel at any time by using a channel number of 0:

Arpeggio-1 Channel 0

will disable the Arpeggio-1 channel, freeing it for use by other tracks. A warning message is generated. Disabling a track without a valid channel is fine. When you set a channel to 0 the track is also disabled. You can restart the track with the ON command (here).

You don't need to have a valid MIDI channel assigned to a track to do things like: MIDIPAN, MIDIGLIS, MIDIVOLUME or even the assignment of any music to a track. MIDI data is created in tracks and then sent out to the MIDI buffers. Channel assignment is checked and allocated at this point, and an error will be generated if no channels are available.

It's quite acceptable to do channel reassignments in the middle of a song. Just assign channel 0 to the unneeded track first.

MIDI channel settings are not saved in GROOVEs.

MMA inserts a MIDI ``track name'' meta event when the channel buffers are first assigned at a MIDI offset of 0. If the MIDI channel is reassigned, a new ``track name'' is inserted at the current song offset.

A more general method is to use CHANNELPREF detailed below.

You can access the currently assigned channel with the $_TRACK_CHANNEL macro.

# ChannelPref

If you prefer to have certain tracks assigned to certain channels you can use the CHANNELPREF command to create a custom set of preferences. By default, MMA assigns channels starting at 16 and working down to 1 (with the expectation of drum tracks which are all assigned channel 10). If, for example, you would like the Bass track to be on channel 9, sustained bass on channel 3, and Arpeggio on channel 5, you can have a command like:

ChannelPref Bass=9 Arpeggio=5 Bass-Sus=3

Most likely this will be in your MMARC file.

You can use multiple command lines, or have multiple assignments on a single line. Just make sure that each item consists of a trackname, an ``='' and a channel number in the range 1 to 16.

#
ChShare

MMA is fairly conservative in its use of MIDI tracks. ``Out of the box'' it demands a separate MIDI channel for each of its tracks, but only as they are actually used. In most cases, this works just fine.

However, there are times when you might need more tracks than the available MIDI channels or you may want to free up some channels for other programs.

If you have different tracks with the same voicing, it's quite simple. For example, you might have an arpeggio and scale track:

Arpeggio Sequence A16 z Arpeggio Voice Piano1 Scale Sequence z S8 Scale Voice Piano1

In this example, MMA will use different MIDI channels for the Arpeggio and the Scale. Now, if you force channel sharing:

Scale ChShare Arpeggio

both tracks will use the same MIDI channel.

This is really foolproof in the above example, especially since the same voice is being used for both. Now, what if you wanted to use a different voice for the tracks?

Arpeggio Sequence A16 z Arpeggio Voice Piano1 Strings Scale Sequence z S8 Scale ChShare Arpeggio

You might think that this would work, but it doesn't. MMA ignores voice changes for bars which don't have a sequence, so it will set ``Piano1'' for the first bar, then ``Strings'' for the second (so far, so good). But, when it does the third bar (an ARPEGGIO) it will not know that the voice has been changed to ``Strings'' by the Scale track.

So, the general rule for track channel sharing is to use only one voice.

One more example which doesn't work:

Arpeggio Sequence A8 Scale Sequence S4 Arpeggio Voice Piano1 Scale Voice Piano1 Scale ChShare Arpeggio

This example has an active scale and arpeggio sequence in each bar. Since both use the same voice, you may think that it will work just fine ...but it may not. The problem here is that MMA will generate MIDI on and off events which may overlap each other. One or the other will be truncated. If you are using a different octave, it will work much better. It may sound okay, but you should probably find a better way to do this.

When a CHSHARE directive is parsed the ``shared'' channel is first checked to ensure that it has been assigned. If not currently assigned, the assignment is first done. What this means is that you are subverting MMA 's normal dynamic channel allocation scheme. This may cause is a depletion of available channels.

Please note that that the use of the CHSHARE command is probably never really needed, so it might have more problems than outlined here. If you want to see how much a bother channel sharing becomes, have a look at the standard library file `frenchwaltz.mma`. All this so the accordion bass can use one channel instead of 6. If I were to write it again I'd just let it suck up the MIDI channels.

For another, simpler, way of reassigning MIDI tracks and letting MMA do most of the work for you, refer to the DELETE command.

# ForceOut

Under normal conditions MMA only generates the MIDI tracks it thinks are valid or relevant. So, if you create a track but insert no note data into that track it will not be generated. An easy way to verify this is by creating file and running MMA with the -c command line option. Lets start off by creating a file you might think will set the keyboard channel on your synth to a TenorSax voice:

Begin Solo-Keyboard Channel 1 Voice TenorSax MIDIVolume 100 End

If you compile this you should get:

$ mma test -c File 'test' parsed, but no MIDI file produced! Tracks allocated: SOLO-KEYBOARD Channel assignments: 1 SOLO-KEYBOARD

So, a MMA track was created, but if you compile this file and examine the resulting MIDI file you will find that the voice has not been set.

To overcome this, insert the FORCEOUT command at the end of the track setup. For example, here is a more complete file which will set the keyboard track to TenorSax with a volume of 100, play a bar of accompaniment, set a Trumpet voice with a louder volume, play another bar, and finally reset the keyboard to the default Piano voice.

Groove BossaNova Begin Solo Channel 1 Voice TenorSax MIDIVolume 100 ForceOut End 1 C Begin Solo Voice Trumpet MIDIVolume 120 ForceOut End 2 G Begin Solo Voice Piano1 MIDIVolume 127 ForceOut End

Note: The same or similar results could be accomplished with the MIDI command; however, it's a bit harder to use and the commands would be in the Meta track.

#
MIDI

The complete set of MIDI commands is not limitless--but from this end it seems that adding commands to suit every possible configuration is never-ending. So, in an attempt to satisfy everyone, a command which will place any arbitrary MIDI stream in your tracks has been implemented. In most cases this will be a MIDI ``Sysex'' or ``Meta'' event.

For example, you might want to start a song off with a MIDI reset:

MIDI 0xF0 0x05 0x7e 0x7f 0x09 0x01 0xf7

The values passed to the MIDI command are normal integers; however, they must all be in the range of 0x00 to 0xff. In most cases it is easiest to use hexadecimal numbers by using the ``0x'' prefix. But, you can use plain decimal integers if you prefer.

In the above example:

0xF0
  Designates a SYSEX message

0x05
  The length of the message

0x7e
  ...The actual message

Another example places the key signature of F major (1 flat) in the meta track:20.1

MIDI 0xff 0x59 0x02 0xff 0x00

Some cautions:

- MMA makes no attempt to verify the validity of the data!

- The ``Length'' field must be manually calculated.

- Malformed sequences can create unplayable MIDI files. In extreme situations, these might even damage your synth. You are on your own with this command ...be careful.

- The MIDI directive always places data in the Meta track at the current time offset into the file. This should not be a problem.

Cautions aside, `includes/init.mma` has been included in this distribution. I use this without apparent problems; to use it add the command line:

MMAstart init

in your MMARC file. The file is pretty well commented and it sets a synth up to something reasonably sane.

If you need a brief delay after a raw MIDI command, it is possible to insert a silent beat with the BEATADJUST command. See the file `includes/reset.mma` for an example.

#
MIDIClear

As noted earlier in this manual you should be very careful in programming MIDI sequences into your song and/or library files. Doing damage to a synthesizer is probably a remote possibility ...but leaving it in a unexpected mode is likely. For this reason the MIDICLEAR command has been added as a companion to the MIDIVOICE and MIDISEQ commands.

Each time a MIDI track (not necessary the same as a MMA track) is ended or a new GROOVE is started, a check is done to see if any MIDI data has been inserted in the track with a MIDIVOICE or MIDISEQ command. If it has, a further check is done to see if there is an ``undo'' sequence defined via a MIDICLEAR command. That data is then sent; or, if data has not be defined for the track, a warning message is displayed.

The MIDICLEAR command uses the same syntax as MIDIVOICE and MIDISEQ; however, you can not specify different sequence for different bars in the sequence:

Bass-Funky MIDIClear 1 Modulation 0; 1 ReleaseTime 0

As in MIDIVOICE and MIDISEQ you can include sequences defined in a MIDIDEF. The <beat>offsets are required, but ignored.

#
MIDIFile

This option controls some fine points of the generated MIDI file. The command is issued with a series of parameters in the form ``MODE=VALUE''. You can have multiple settings in a single MIDIFILE command.

MMA can generate two types of SMF (Standard MIDI Files):

0.
  This file contains only one track into which the data for all the different channel tracks has been merged. A number of synths which accept SMF (Casio, Yamaha and others) only accept type 0 files.

1.
  This file has the data for each MIDI channel in its own track. This is the default file generated by MMA .

You can set the filetype in an RC file (or, for that matter, in any file processed by MMA ) with the command:

MidiFile SMF=0

or

MidiFile SMF=1

You can also set it on the command line with the -M option. Using the command line option will override the MIDISMF command if it is in a RC file.

By default MMA uses ``running status'' when generating MIDI files. This can be disabled with the command:

MidiFile Running=0

or enabled (but this is the default) with:

MidiFile Running=1

Files generated without running status will be about 20 to 30% larger than their compressed counterparts. They may be useful for use with brain-dead sequencers and in debugging generated code. There is no command line equivalent for this option.

# MIDIGlis

This sets the MIDI portamento20.2 (in case you're new to all this, portamento is like glissando between notes--wonderful, if you like trombones! To enable portamento:

Arpeggio MIDIGlis 30

The parameter can be any value between 1 and 127. To turn the sliding off:

Arpeggio MIDIGlis 0

This command will work with any track (including drum tracks). However, the results may be somewhat ``interesting'' or ``disappointing'', and many MIDI devices don't support portamento at all. So, be cautious. The data generated is not sent into the MIDI stream until musical data is created for the relevant MIDI channel.

# MIDIInc

MMA has the ability to include a user supplied MIDI file at any point of its generated files. These included files can be used to play a melodic solo over a MMA pattern or to fill a section of a song with something like a drum solo.

When the MIDIINC command is encountered the current line is parsed for options, the file is inserted into the stored MIDI stream, and processing continues. The include has no effect on any song pointers, etc.

MIDIINC has a number of options, all set in the form OPTION=VALUE. Following are the recognized options:

FILENAME
  The filename of the file to be included. This must be a complete filename. The filename will be expanded by the Python os.path.expanduser() function for tilde expansion. No prefixes or extensions are added by MMA . Examples: FILENAME=`/home/bob/midi/myfile.mid`. or FILENAME=`/sounds/myfile.mid`.

VOLUME
  An adjustment for the volume of all the note on events in the included MIDI file. The adjustment is specified as a percentage with values under 100 decreasing the volume and over 100 increasing it. If the resultant volume (velocity) is less than 1 a velocity of 1 will be used; if it is over 127, 127 will be used. Example: VOLUME=80.

OCTAVE
  Octave adjustment for all notes in the file. Values in the range -4 to 4 are permitted. Notes in drum tracks (channel 10) will not be effected. Example: OCTAVE=2.

TRANSPOSE
  Transposition adjustment settings in the range -24 to 24 are permitted. If you do not set a value for this the global transpose setting will be applied (expecting channel 10, drum, notes). Example: TRANSPOSE=-2.

LYRIC
  This option will copy any Lyric events to the MMA meta track. The valid settings are ``On'' or ``Off''. By default this is set to ``Off''. Example LYRIC=On.

TEXT
  This option will copy any Text events to the MMA meta track. The valid settings are ``On'' or ``Off''. By default this is set to ``Off''. Example TEXT=On.

START
  Specifies the start point of the file to be included in beats. For example, ``Start=22'' would start the include process 22 beats into the file. The data will be inserted at the current song position in your MMA file. The value used must greater or equal to 0 and may be a fractional beat value (18.456 if fine).

END
  Specifies the end point of the file to be included in beats. For example, ``End=100'' would discard all data after 100 beats in the file. The value used must be greater that the Start position and can be fractional.

TRACK
  A trackname must be set into which notes are inserted. You can set more than one track/channel if you wish. For example, if you had the option DRUM=10 any notes in the MIDI file with a channel 10 setting would be inserted into the MMA Drum track. Similarity, Solo-Tenor=1 will copy notes from channel 1 into the Solo-Tenor track. If the track doesn't exist, it will be created. Note: this means that the channel assignment in your included file and the new MMA generated file will most likely be different.

  At least one TRACK option is required to include a MIDI file. It is up to the user to examine exisiting MIDI files to determine the tracks being used and which to include into MMA 's output.

A complete example of usage is shown in the files in the directory `egs/frankie` in the distribution. A short example:

MIDIinc File=test.mid Solo-Piano=1 Drum=10 Volume=70

will include the MIDI file ``test.mid'' at the current position and assign all notes in channel 1 to the Solo-Piano track and the notes from channel 10 to the Drum track. The volumes for all the notes will be adjusted to 70% of that in the original.

A few notes:

- MIDI files to be included do not have to have the same tempo. MIDIINC adjusts this automatically during the importation. However, the internal setting for beat division should be the same. MMA assumes a beat division of 192 (this is set in bytes 12 and 13 of the MIDI file). If the included file differs a warning is printed and MMA will attempt to adjust the timings.

- All files are parsed to find the offset of the first note-on event; notes to be included are set with their offsets compensated by that time. This means that any silence at the start of the included file is skipped (this may surprise you if you have used the optional Start setting). If you want the included file to start somewhere besides the start of the current bar you can use a BEATADJUST before the MIDIINC--use another to move the pointer back right after the include to keep the song pointer correct.

- Not all events in the included files are transferred: notably all system and meta events (other than text and lyric, see above) are ignored.

- If you want to apply different VOLUME or other options to different tracks, just do multiple includes of the same file (with each include using a different track and options).

# MIDIMark

You can insert a MIDI Marker event into the Meta track with this command. The mark can be useful in debugging your MIDI output with a sequencer or editor which supports Mark events (most do).

MidiMark Label

will insert the text ``Label'' at the current position. You can add an optional negative or positive offset in beats:

MidiMark 2 Label4

will insert ``Label4'' 2 beats into the next bar.

# MIDIPan

In MIDI-speak ``pan'' is the same as ``balance'' on a stereo. By adjusting the MIDIPAN for a track you can direct the output to the left, right or both speakers. Example:

Bass MIDIPan 4

This command is only available in track mode. The data generated is not sent into the MIDI stream until musical data is created for the relevant MIDI channel.

The value specified must be in the range 0 to 127, and must be an integer.

A variation for this command is to have the pan value change over a range of beats:

Solo MidiPan 10 120 4

in this case you must give exactly 3 arguments:

1. The initial pan value (0 to 127),
2. The final pan value (0 to 127),
3. The number of beats to apply the pan over.

Using a beat count you can create interesting effects with different instruments moving between the left and right channels.

MIDIPAN is not saved or restored by GROOVE commands, nor is it effected by SEQCLEAR. A MIDIPAN is inserted directly into the MIDI track at the point at which it is encountered in the music file. This means that the effect of MIDIPAN will be in use until another MIDIPAN is encountered.

MIDIPAN can be used in MIDI compositions to emulate the sound of an orchestra. By assigning different values to different groups of instruments, you can get the feeling of strings, horns, etc. all placed in the ``correct'' position on the stage.

MIDIPAN can be used for much cruder purposes. When creating accompaniment tracks for a mythical jazz group, you might set all the bass tracks (Bass, Walk, Bass-1, etc) set to aMIDIPAN 0. Now, when practicing at home you have a ``full band''; and the bass player can practice without the generated bass lines simply by turning off the left speaker.

Because most MIDI keyboard do not reset between tunes, there should be a MIDIPAN to undo the effects at the end of the file. Example:20.3

Include swing Groove Swing Bass MIDIPan 0 Walk MIDIPan 0 1 C 2 C ... 123 C Bass MIDIPan 64 Walk MIDIPan 64

# MIDISeq

It is possible to associate a set of MIDI controller messages with certain beats in a sequence. For example, you might want to have the Modulation Wheel set for the first beats in a bar, but not for the third. The following example shows how:

Seqsize 4 Begin Bass-2 Voice NylonGuitar Octave 4 Sequence { 1 4 1 90; 2 4 3 90; 3 4 5 90; 4 4 1+ 90} MIDIDef WheelStuff 1 1 0x7f ; 2 1 0x50; 3 1 0 MidiSeq WheelStuff Articulate 90 End C 4

The MIDISEQ command is specific to a track and is saved as part of the GROOVE definition. This lets style file writers use enhanced MIDI features to dress up their sounds.

The command has the following syntax:

TrackName MidiSeq <Beat> <Controller> <Datum> [ ; ...]

where:

Beat
  is the Beat in the bar. This can be an integer (1,2, etc.) or a floating point value (1.2, 2.25, etc.). It must be 1 or greater and less than the end of bar (in 4/4 it must be less than 5).

Controller
  A valid MIDI controller. This can be a value in the range 0x00 to 0x7f or a symbolic name. See the appendix , here, for a list of defined names.

Datum
  All controller messages use a single byte ``parameter'' in the range 0x00 to 0x7f.

You can enter the values in either standard decimal notation or in hexadecimal with the prefixed ``0x''. In most cases, your code will be clearer if you use values like ``0x7f'' rather than the equivalent ``127''.

The MIDI sequences specified can take several forms:

1. A simple series like:

   MIDISeq 1 ReleaseTime 50; 3 ReleaseTime 0

   in this case the commands are applied to beats 1 and 3 in each bar of the sequence.

## .

As a set of names predefined in an MIDIDEF command:

MIDIdef Rel1 1 ReleaseTime 50; 3 ReleaseTime 0 MIDIdef Rel2 2 ReleaseTime 50; 4 ReleaseTime 0 MIDISeq Rel1 Rel2

Here, the commands defined in ``Rel1'' are applied to the first bar in the sequence, ``Rel2'' to the second. And, if there are more bars in the sequence than definitions in the line, the series will be repeated for each bar.

A set of series enclosed in { } braces. Each braced series is applied to a different bar in the sequence. The example above could have been does as:

MIDISeq { 1 ReleaseTime 50; 3 ReleaseTime 0 } \ { 2 ReleaseTime 50; 4 ReleaseTime 0 }

Finally, you can combine the above into different combinations. For example:

MIDIDef Rel1 1 ReleaseTime 50 MIDIDef Rel2 2 ReleaseTime 50 MIDISeq { Rel1; 3 ReleaseTime 0 } { Rel2; 4 ReleaseTime 0 }

You can have specify different messages for different beats (or different messages/controllers for the same beat) by listing them on the same MIDISEQ line separated by ``;''s.

If you need to repeat a sequence for a measure in a sequence you can use the special notation ``/'' to force the use of the previous line. The special symbol ``z'' or ''-'' can be used to disable a bar (or number of bars). For example:

Bass-Dumb MIDISeq 1 ReleaseTime 20 z / FOOBAR

would set the ``ReleaseTime'' sequence for the first bar of the sequence, no MIDISeq events for the second and third, and the contents of ``FOOBAR'' for the fourth.

To disable the sending of messages just use a single ``-'':

Bass-2 MidiSeq - // disable controllers

# MIDISplit

For certain post-processing effects it is convenient to have each different drum tone in a separate MIDI track. This makes it easier to apply an effect to, for example, the snare drum. Just to make this a bit more fun you can split any track created by MMA .

To use this feature:

MIDISplit <list of channels>

So, to split out just the drum channel20.4 you would have the command:

MIDISplit 10

somewhere in your song file.

When processing MMA creates an internal list of MIDI note-on events for each tone or pitch in the track. It then creates a separate MIDI track for each list. Any other events are written to another track.

# MIDITname

When creating a MIDI track, MMA inserts a MIDI Track Name event at the start of the track. By default, this name is the same as the associated MMA track name. You can change this by issuing the MIDITNAME command. For example, to change the CHORD track name you might do something like:

Chord MidiTname Piano

Please note that this only effects the tracks in the generated MIDI file. You still refer to the track in your file as CHORD.

# MIDIVoice

Similar to the MIDISEQ command discussed in the previous section, the MIDIVOICE command is used to insert MIDI controller messages into your files. Instead of sending the data for each bar as MIDISEQ does, this command just sends the listed control events at the start of a track and then, if needed, at the start of each bar.

Again, a short example. Let us assume that you want to use the ``Release Time'' controller to sustain notes in a bass line:

Seqsize 4 Begin Bass-2 Voice NylonGuitar MidiVoice 1 ReleaseTime 50 Octave 4 Sequence { 1 4 1 90; 2 4 3 90; 3 4 5 90; 4 4 1+ 90} Articulate 60 End C 4

should give an interesting effect.

The syntax for the command is:

Track MIDIVoice <beat> <controller> <Datum> [; ...]

This syntax is identical to that discussed in the section for MIDISEQ, above. The <beat>value is required for the command--it determines if the data is sent before or after the VOICE command is sent. Some controllers are reset by a voice, others not. My experiments show that BANK should be sent before, most others after. Using a ``beat'' of ``0'' forces the MidiVoice data to be sent before the Voice control; any other ``beat'' value causes the data to be sent after the Voice control. In this silly example:

Voice Piano1 MidiVoice {0 Bank 5; 1 ReleaseTime 100}

the MIDI data is created in an order like:

> 0 Param Ch=xx Con=00 val=05
> 0 ProgCh Ch=xx Prog=00
> 0 Param Ch=xx Con=72 val=80

All the MIDI events occur at the same offset, but the order is (may be) important.

By default MMA assumes that the MIDIVoice data is to be used only for the first bar in the sequence. But, it's possible to have a different sequence for each bar in the sequence (just like you can have a different VOICE for each bar). In this case, group the different data groups with {} brackets:

Bass-1 MIDIVoice {1 ReleaseTime 50} {1 ReleaseTime 20}

This list is stored with other GROOVE data, so is ideal for inclusion in a style file.

If you want to disable this command after it has been issued you can use the form:

Track MIDIVoice - // disable

Some technical notes:

- MMA tracks the events sent for each bar and will not duplicate sequences.

- Be cautious in using this command to switch voice banks. If you don't switch the voice bank back to a sane value you'll be playing the wrong instruments!

- Do use the MIDICLEAR command ((details)) to ``undo'' anything you've done via a MIDIVOICE command.

#
MIDIVolume

MIDI devices equipped with mixer settings can make use of the ``Channel'' or ``Master'' volume settings.20.5

MMA doesn't set any channel volumes without your knowledge. If you want to use a set of reasonable defaults, look at the file `includes/init.mma` which sets all channels other than ``1'' to ``100''. Channel ``1'' is assumed to be a solo/keyboard track and is set to the maximum volume of ``127''.

You can set selected MIDIVOLUMEs:

Chord MIDIVolume 55

will set the Chord track channel. For most users, the use of this command is not recommended since it will upset the balance of the library grooves. If you need a track softer or louder you should use the volume setting for the track.

The data generated is not sent into the MIDI stream until musical data is created for the relevant MIDI channel.

Caution: If you use the command with ALLTRACKS you should note that only existing MMA tracks will be effected.

#### Footnotes

... track:20.1
  This is much easier to do with the KeySig command, here
... portamento 20.2
  The name ``Glis'' is used because ``MIDIPortamento'' gets to be a bit long to type and ``MIDIPort'' might be interpreted as something to do with ``ports''.
... Example:20.3
  This is much easier to do with the MMAStart and MMAEnd options (details).
... channel 20.4
  In MMA this will always be channel 10.
... settings.20.5
  I discovered this on my keyboard after many frustrating hours attempting to balance the volumes in the library. Other programs would change the keyboard settings, and not being aware of the changes, I'd end up scratching my head.