CS 198: Project #2

### Project 2: State Machines

Due midnight, Monday 22 February, 2010

The purpose of this assignment is to get you thinking about playing sequences of notes using a combination of Max and Python. By the end of the assignment, you should have two note sequences, defined in a Python file, that you can play individually or together from within Max.

For this assignment, continue to use the same patcher and python file from lab.

1. MIDI lets you control the instrument as well as pitch, duration, and velocity. The noteout object's rightmost input is the instrument channel. 10, for example, is percussion.

Edit the ScriptEngine object so that it has three outputs instead of two by changing the 2 to 3. Connect the third output to the rightmost input of the noteout object.

Edit your playRandomNote function so that it also picks a random instrument channel. Pick random numbers between 0 and 15 (experiment). When you go back to Max, reload the script and then see what happens.

When you are debugging, it can be handy to put number displays in various locations in your patcher so you can see the values.

2. In Max, create a metronome object metro 500. Put a checkbox on its leftmost input to enable turning it on or off. Connect its output to the playNext message. Test this out. It should play your sequence at a regular pace.

Next, connect the second output from the ScriptEngine (duration) to the metronome's rightmost input. Test this out. It should play your sequence with random intervals.

3. Create a new gobal variable called duration in the python file. Put it next to your sequence. Use it to specify the duration (in ms) of each note in your sequence. There should be the same number of elements in both your sequence and duration list.
4. In your playNext function, instead of generating a random duration, use the duration from your new list. You'll need to put a global duration line in the function. You want to use the same counter for the sequence variable. Does it play your theme appropriately?
5. In Max, create a second metronome and on/off box. Create a new message called playSecond and connect the metronome's output to the playSecond input. Connect playSecond to the ScriptEngine's input. Your Max file should now have two separate metronome systems that call different python functions.

In your Python file, create a function playSecond. It should play a different theme from playNext. It will look just like your playNext function, but you will need to use two different new lists and a different new counter.

Try playing the themes individually. Then try to play them together.

### Extensions

Each assignment will have a set of suggested extensions. The required tasks constitute about 85% of the assignment, and if you do only the required tasks and do them well you will earn a B+. To earn a higher grade, you need to undertake at least one extension. The difficulty and quality of the extension or extensions will determine your final grade for the assignment. One significant extension or 2-3 smaller extensions, done well, are typical. Doing one or more extensions does not guarantee a higher grade, as your overall grade depends upon every part of the assignment, but it is part of earning it.

Here are some suggested extensions for this assignment.

• Create additional python functions that do other things. For example, figure out how to set the base pitch for your themes using a python function.
• Add interface elements to your patcher that send information to a python function. We'll go over the prepend object and sending function arguments to Python in lab.

Once you are finished with your work, put the python and Max files, and anything else you want to hand in, into your handin folder on the Academic server.

### Writeup

Each of you should create your own wiki page for your writeup.

Please put the label cs198s10proj2 on your writeup page (down below the editing window on the edit tab).

• How does information move from Max into a Python function?
• How does information move from a Python function back to Max?
• If you create a new function in Python, how do you call it in Max?
• Do you have to synchronize the duration and pitch lists within the playNext function? How could you make the duration list be a different size than the pitch list? What would be the result?
• Could a single Python function switch beween several different themes? How could you have Max tell the function which theme to play?