incrementalism
Applied to coding, incrementalism is more a philosophy than a tangible thing. It’s the idea that you break large project into small steps, to not try to do too much at once. Incrementalism encourages you to develop a small part of the project, test it, and expand it. We’ve been using incrementalism with the development of an arpeggiator patcher. First we got a repeated note to play, then we made it so that playing a MIDI key didn’t upset the rhythm of what was playing, etc. It’s good for us to be aware of process.
starting/stopping
The first improvement to make is to be able to start and stop the repeating note with the MIDI keyboard, with a key press sending pitch to the repeater and turning the metro on, and a key release turning the metro off.
The <toggle> object has an inlet, which can be used to turn the toggle state on or off. Any non-zero number turns the <toggle> on; a zero turns the <toggle> off.
Key velocity from <notein> can be used for <toggle> control. You need to take the key velocity directly from <notein>, not <stripnote>, as no zero velocities get through <stripnote>.
other pitches
Day3-RepeatingNoteKeyRandom.maxpat
An arpeggiator that only repeats one note is really an unfulfilled arpeggiator. To play other pitches we need to think about how to generate intervals in half steps that can be added to the base pitch. The simplest way to do this is with the <random> object. <random> takes an argument for how many different numbers to choose from. If the argument is 4 then the range of possible values will be 4. The only confusion is that computers start counting at zero. So a range of 4 equals 0 – 3 (0, 1, 2, 3). The maximum number will always be the range – 1.
It can be confusing, so I’ll say it again:
computers start counting at zero
mapping values
Day3-RepeatingNoteKeyTableRandom.maxpat
Day3-RepeatingNoteKeyTableCount.maxpat
Just playing random intervals above a base pitch gets old quickly. A better way would be to play specified intervals above a base pitch. To do that, we need an <itable> (or <table>) object. An <itable> is an (x,y) graph that stores values (y) at locations (x). To retrieve a value, send a location in the form of a number to the <itable>. Taking one set of values and using it to select from another set of values is called mapping.
You can set the size (# of x values) and range (# of y values) for an <itable>. I highly recommend that you reduce both properties in the <itable> inspector so that you have a useful/visible space to edit. You can change values in the <itable> by clicking or click-dragging within the <itable> in a locked patcher. My example patchers use a pentatonic scale.
The TableRandom version of the patcher uses the <random> object to generate numbers that are read as index locations by <itable>. The TableCount version uses a <counter> that will always play the table in order. By looking for 0 velocities (noteoff messages), we can reset the <counter> so that the next time a note is played it will start at the beginning of the pattern. The <select> object looks for 0. When a 0 is found, a bang is sent out the left outlet of <select>. Routing the bang to the middle inlet of the <counter> tells counter to reset to the minimum value and output that value on the next count. You could also reset the <counter> and immediately output a value (but then you would hear a note when releasing the key), and you can reset the <counter> to any value within the counting range.