Drawing with MIDI notes.
Key number data (pitch information) from a MIDI keyboard can be used to trigger and/or control events in Max, such as drawing a colored shape. First the data is mapped into the appropriate range to describe a horizontal pixel coordinate in a drawing space( e.g., pixel 0 to pixel 240). Then it is used as the left corner coordinate (and a number 16 greater than that is used as the right corner coordinate) for a ‘paintrect’ message to a lcd object.
Note the use of the stripnote object to suppress note-off messages (note-on message with a velocity of 0) so that a rectangle is drawn only when a key is pressed, and not when it is released. The split object is used to limit the range of notes that it will try to draw (only the most commonly-used notes, those of a standard 61-key MIDI keyboard). The valid key numbers are first used to trigger a ‘clear’ message to erase the previous contents of the drawing space, then to a + object to get 16 added to them, then to a pack object. The pack object is used to combine two numbers together into a single message known as a ‘list’ (a message that starts with a number and has other space-separated items after that). The ‘list’ goes to a message box that contains a properly formed ‘paintrect’ message with fixed top and bottom coordinates (120 and 136) and that uses the two items of the ‘list’ from the pack object as its left and right coordinates. The lcd object then paints a rectangle using the desired color (black by default). The ‘color’ message uses colors from a palette of 256 preset indexed colors, with 0=white and 255=black.