My questions, though: How might one record rhythms in a similar manner?
The easiest way is to use
MIDIRecSocket from my ddwMIDI quark.
I haven’t used this in ages, but it should work something like this:
// midiChannel also includes device info:
// chan_num (simple integer): this number is the channel number; the port will be assumed 0
// \omni: respond to any channel on port 0
// nil: assume port 0, channel 0
// [port_num, chan_num]: specify a port as well as channel. port_num can be the uid belonging to the port (see MIDIClient and MIDIEndPoint), or an integer index to the sources initialized by MIDIClient.
// [port_num, \omni]: respond to any channel on this port
k = MIDIRecSocket(midiChannel);
... play notes...
b = k.stopRecord;
Now ‘b’ is a
MIDIRecBuf containing an array of
SequenceNote objects, each of which has a note number, time, duration and velocity. If you need to convert them into some other format, that’s up to you, but…
Also, is it possible to record incoming MIDI as chords?
If you keep your MIDIRecBuf data in the original format, you can do:
c = b.parse(deltaThresh, overlapThresh, allowShortNotes);
If you set the thresholds to a reasonable value (default = 0.1 s), then it should clump chord notes together into a single object, e.g.
// make two triads and a couple melody notes
b = MIDIRecBuf(\demo, [
[48, 55, 60, 64, 67, 64, 50, 60, 62, 65, 69],
[0.03, 0.02, 0.02, 1, 1, 0.93, 0.03, 0.02, 0.02, 1, 2], // deltas
[3, 3, 3, 1, 1, 1, 3, 3, 3, 1, 2], // lengths
0.5 ! 11
b.notes; // 11 sequence notes
c = b.parse;
c.notes; // 5 items, including 2 SeqChordNotes
All of the note data are still there, and
Pseq(c.notes, 1) will actually spit out all the 11 original notes (should be with the original timing, but I wrote this a long time ago and I wasn’t as solid a programmer then, so there might be some bugs). But you can manipulate the chords as atomic entities.
I would suggest very strongly against trying to record the incoming notes as chords. Recording is complex enough by itself, and interpreting the notes into chords is also complex enough by itself. Trying to do them both at the same time is a really nice way to get confused and make a lot of mistakes.