(maxmsp) Converting Instructions to Patcher

The first midi programming assignment always creates difficulties. The biggest problem is translating the instructions step by step into a working patcher. I’m going to explain the process using the first problem from Assignment 2.

Part of the problem is that we tend to try and start at the top of the instruction list and work our down in a linear fashion. Max/MSP works very well at providing easy output quickly, and then allowing you to add controls and functionality to some working function. To take advantage of this design, you should start with the note output portion of the patcher and work your way backwards.

Since the patcher generates notes from internal processes, you need to start with a makenote – noteout pair of objects. Add an integer number box to manually input note numbers to makenote and confirm that the MIDI synth portion of your patcher is working.

Next you need to have intervals stored and a transposition method for your gesture. Working up from the bottom add the transposition first, using an addition (+) object. Give it an initial argument of 60 so that you will get transposition even before you hook up MIDI note input.

Storing a group of intervals means using a table object to store interval sizes in half steps. Be sure to choose the table inspector (cntl-click on object and choose Inspector) and check “save table contents with patcher.” Otherwise you have to enter your intervals every time you open the patcher. Make your life easier by storing the maximum number of intervals as your patcher will eventually play (8 in this case). Connect the table to a number box, and the number box to the addition object. Next, add a random object with an argument of 8 to the table. I always use number boxes so that I can confirm the output of a given object matches my expectations. Add a bang button so that you can manually trigger the random object.

At this point, you can click on the button and randomly generate intervals that will be transposed by 60 (middle C), and have them played by the MIDI synth.

Add a note input with the common notein- stripnote pair of objects, since we only want on pitches to be used for transposition (and only on velocities to turn on the toggle when we get to that).

We have several control functions left to program. We need to have a metro that starts with note input and stops when a maximum count based on key velocity is reached. Let’s start with the counting program. In a separate area of the program (I worked to the left of the note playback part of the patcher), connect a button to a counter to a number box.

The counter max is 8, matching the maximum number of notes to play. The minimum is 1, because we always need to start counting at one, not the lowest maximum of 2.

We need to look for the counter maximum. My favorite way to do this is with a select object following the number box. (***counter does have an outlet for max value reached, but it outputs two numbers, so you still need a select object if you use it.) Add a select object with the same max argument as the counter, and add a number box that feeds into both the counter and select object for changing maximum values.

At this point it is useful to hook up the noteon velocity (from stripnote) to a toggle that turns a metro object on and off. The metro should connect to the bang button for the counter and the bang button for the random object.

The select object outputs a bang when a message matches its argument (changeable from input to right inlet). Since toggles reverse state with a bang message (easily found from the header of the toggle help patcher), you can connect that bang output to the toggle controlling the metro.

The final step is to reset the counter whenever you stop the metro, since you always want the counter to start at 1. (If you don’t reset the counter before increasing the maximum count, it will start without returning to 1.) Use a message of 1 sent to the middle counter inlet (reset to number on next clock). Don’t use the next inlet over, which will reset the counter immediately and cause the new value to be output right away. The same bang from select can be used to send this message. The counter and metro portion of the patcher is below.

Finally, you need to set the maximum count by scaling the noteon velocity to the required number of values, then offsetting that range to occupy the desired number of events: 2 to 8. (***there is an object that does this with arguments, but I’d like you to know how to do the steps at this point.) You want to find out the “segment size” by dividing 127 (max velocity) by 7 (2,3,4,5,6,7,8 = 7 events). That will return the number 18 (as a truncated int). Switch your divide object argument and input 127. The answer needs to be no more than 6 (0,1,2,3,4,5,6 = 7), but it will be 7. Max truncating floating point numbers means you need to add one more to your divide argument. That number needs to be offset (addition) by 2 to fit our event range.

The final patcher is uploaded (2-1a.maxpat) and fully commented. Also take a look at 2-1b.maxpat. This version plays back the gesture in order. It uses the count offset by (-1) to directly feed the table object. 2-1c.maxpat allows for either random or ordered playback, with a umenu controlling a switch. A switch chooses between multiple inputs and routes to a single output. 2-1b and 2-1c are minimally commented (only the changes).


Comments

Leave a Reply