If you want to synchronize realtime performed events to the Max transport, or to the Live transport in Max for Live, you need to hold onto the vital information about the performed event until the next beat (or downbeat, or whatever your unit of quantization is), then trigger it. For example, in Live, when you trigger a new audio clip, if the launch quantization is set to 1 Bar, your clip will not be launched until the next downbeat. Live holds onto your request to launch the clip, then enacts it when the downbeat of the next bar arrives.
The coll object stores an indexed collection of messages. You can trigger those messages to be sent out, just by sending coll the index of the desired message. One way that this can be useful is that you can make an entire musical score in the format of a collection of note messages, each of which contains whatever information you consider vital for describing a note. That’s similar to the way that languages like csound and cmusic read a score file to play notes.
You can change the color of text in most Max UI objects with the textcolor attribute. Note that the color must be specified in the RGBA format—red, green, blue, and alpha (opacity)—rather than simply RGB. That is, textcolor requires four arguments, and will not work with only three.
To make a random decision between two things, you can use the decide object. To make a probabilistic decision between two things, with one thing being more likely than the other, you can use the random object to choose randomly from a larger set of numbers, then assign a majority of those choices to mean one thing (and the remaining minority to mean the other thing). An easy way to do this is with the < object.
The up-down arrow keys seem like reasonable keys to use for incrementing or decrementing a number box or a slider. But rather than require a new key press for each step up or down, you can use a fast metro to trigger messages continuously as long as the key is pressed. There are several ways one could implement this in Max; here's one example.
Using both the key and keyup objects, you can tell when a key was pressed and when it was released. The split object allows you to isolate a range of numbers; it passes only the specified range of numbers out its left outlet, and passes all other numbers out its right outlet. The numbered keys 0 to 9 correspond to ASCII codes 48 to 57, so it's easy to isolate those keys, and subtracting 48 brings those numbers down into the range 0 to 9.
The line object sends out a periodic series of numbers that progress to some new value over a certain amount of time. The input to line is a destination value (where it should eventually arrive), a transition time (how long it should take to get there), and a time interval between outputs (how often it should send out intermediate values along the way). The left part of this patch shows the use of line to generate integers that are used as pitches.
This program shows the formula for linear mapping of one range to another, and implements the formula using basic Max math objects. One can use the objects zmap and scale to do this task more simply, but this example demonstrates the formula explicitly.
This patch demonstrates the two simplest objects for generating random numbers. Every time it receives a bang in its left inlet, the random object generates a random integer in the range from 0 to one less than its argument. (For example, if you tell it to generate one of 12 random numbers, it will choose a number from 0 through 11 inclusive.) Note that this includes the possibility that successive random choices may appear to generate what seem to be patterns, especially if it's choosing from among a small range of possibilities.
When we want to measure how much time something took, we use a stopwatch. We click once at the beginning of the time we want to measure, click once at the end, and get a reading of the elapsed time. When we want a notification that a particular amount of time has elapsed we use a timer. We set the amount of time in the future that we want to be notified, start the timer, and the timer notifies us when that amount of time has passed.