MIDI Tutorial 4: MIDI Basic Sequencing
This tutorial covers sequencing topics using the Max seq object. We will cover basic sequence setup, and the ability to start and stop playback. We will also examine a few ways to control the playback speed of a loaded sequence.
MIDI event recording and playback (generally called sequencing) is an important task for many MIDI-based Max programs. There are several objects within Max that can accomplish MIDI sequencing tasks, but the seq object provides the easiest interface while still allowing for the recording and playback of notes, controllers and all other MIDI messages.
One of the things that makes MIDI sequencing so useful is that you can change playback speed with little effect on the output sound; the MIDI recipient is responsible for sound creation, and merely responds to the data stream provided by the sequencer. Thus, playback rate change is an important part of MIDI sequencing, and is covered in depth with this tutorial.
To open the tutorial patch, click on the Open Tutorial button in the upper right-hand corner of the documentation window.
Basic sequencing using seq
Our tutorial patcher contains three regions containing patcher logic routed through a single seq object. The leftmost area (labeled 1) shows the most basic of MIDI sequencing setups. The seq object is initialized with a MIDI sequence name as its argument. This sequence is loaded when the patch is opened, and is available for playback. The left output of the seq object is the playback output – it sends raw MIDI data into a midiflush object, then to a midiout object.
The midiflush object is used to maintain the note-on/note-off pairings of a raw MIDI stream, and will send note-off messages when it receives a . Using midiflush, we can stop all sounding notes even if the sequence is only half-way through its playback. Clicking on the message at the top of the patch will not only stop the sequence, but will send a to midiflush to stop all sounding notes on your synthesizer.
Double-click on the midiout object and select a valid MIDI output device for your system. Then click on either the button or the message to begin sequence playback from the start of the sequence; the MIDI sequence loaded into the seq object will play back at its natural speed. When the sequence is done playing, a will be sent out the right outlet of the seq object. We have this connected to a button object, giving us a visual indication of sequence completion.
Try each of the messages attached to the seq object, and it during playback to hear the results of the midiflush object. Also notice that playback always starts at the beginning of the sequence.
Changing playback speed
The next area (labeled 2) contains a bit of programming that changes the playback speed of the sequence. It is based on the argument to themessage: an integer appended to the start message will change the playback rate. A playback rate of represents normal speed; hence, is half-speed, and is double-speed. While this may seem convoluted (in comparison to using a floating-point "rate" from the start), it is easy to calculate the proper value for playback.
In this case, we use a floating-point number box for playback speed, and multiply it by to get the number expected by seq object. The number is stored in an int object; then, hitting the message box, we trigger a button that sends the number through a message, with the properly formatted message sent to seq. Remember, since the button object converts any message into a , the text in the message is arbitrary.
To test this, change the floating-point number box to and hit . Change it to and hit again. You will hear the sequence play at the suggested speed. Using an argument to the message is an easy way to control playback, but this method can only be used to change playback speed at the start of playback. To change the rate during playback, you need to work with the message.
Using tick messages for playback
The rightmost area (labeled 3) shows how to change the speed of the sequence during playback. Two messages are responsible for this: a variation on the seq object has an internal timer that is used by default for playback. However, when the message has the argument, the transport of the seq object is disengaged from an internal clock and depends on incoming messages to advance the sequence.message (with the argument of ) and the message. The
In our example, we are using a tempo object to transform a bpm (beats per minute) value into the appropriate ticks. The arguments to tempo set a default (in this case, bpm), a default beat ( ) and the number of pulses for each whole note ( , the equivalent of pulses per quarter note). If you click on the message and then turn on the tempo object with the toggle box, you will hear the sequence play back at bpm. Next, change the tempo to something faster (say bpm) with the number box connected to its second inlet; if you restart the sequence you will hear it play much more quickly. Turn the tempo object's speed down to bpm and you will hear very slow playback. You can also change the tempo object while the sequence is playing, and the playback will change to match your selected speed.
There are many creative options when using the line object to alter the tempo object would allow you to ramp up playback speed for the duration of the sequence; alternatively, you could create a curve that would cause the playback speed to wobble while it plays. You can also the tempo object using the toggle to temporarily pause playback. When you start it again, playback continues from the point at which you stopped. Using your own clocking provides much more flexibility than simply changing the arguments to the message.message for playback clocking. Using a
The seq object is a robust sequencing tool, allowing you to play back MIDI sequences at a variety of speeds. This is especially true when you override the internal clock and use the message to alter playback in real time. The output of the seq object should be routed through the midiflush object, so that stopping playback will also stop any currently sounding notes. The seq object is perfect for playback of short loops, note/controller phrases or even complete sequences.
|seq||Sequencer for recording and playing MIDI data|
|midiflush||Send MIDI note-offs for hanging note-ons|
|tempo||Output numbers at a metronomic tempo|