Max MIDI Tutorial 4: MIDI Basic Sequencing

MIDI Tutorial 4: MIDI Basic Sequencing

Introduction

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 bang. Using midiflush, we can stop all sounding notes even if the sequence is only half-way through its playback. Clicking on the stop message at the top of the patch will not only stop the sequence, but will send a bang 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 start 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 bang 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 stop 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 the start message: an integer appended to the start message will change the playback rate. A playback rate of 1024 represents normal speed; hence, 512 is half-speed, and 2048 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 1024 to get the number expected by seq object. The number is stored in an int object; then, hitting the Go! message box, we trigger a button that sends the number through a start message, with the properly formatted message sent to seq. Remember, since the button object converts any message into a bang, the text in the Go! message is arbitrary.

To test this, change the floating-point number box to 0.5and hit Go!. Change it to 2.0 and hit Go! again. You will hear the sequence play at the suggested speed. Using an argument to the start 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 tick 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 start message (with the argument of -1) and the tick message. The seq object has an internal timer that is used by default for playback. However, when the start message has the -1 argument, the transport of the seq object is disengaged from an internal clock and depends on incoming tick messages to advance the sequence.

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 rate (in this case, 120 bpm), a default beat multiplier (1) and the number of pulses for each whole note (96, the equivalent of 24 pulses per quarter note). If you click on the start -1 message and then turn on the tempo object with the toggle box, you will hear the sequence play back at 120 bpm. Next, change the tempo to something faster (say 200 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 50 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 tick message for playback clocking. Using a 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 stop 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 start message.

Summary

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 tick 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.

See Also

Name Description
MIDI MIDI
seq Sequencer for recording and playing MIDI data
midiflush Send MIDI note-offs for hanging note-ons
tempo Output numbers at a metronomic tempo