Ok, so this is probably the most wasteful usage of an Axoloti, but I wanted to see how it would be to do some MIDI processing, as well as get some exercise in patches and object writing.
What I wanted is a MIDI transpose function that I can connect to any MIDI keyboard which will simply shift the MIDI notes up or down by octaves. As an added complexity, I want it to work even if the transpose button is pressed while notes are held down, so simply shifting the note number won't work. And I want it to work polyphonically too.
So to this avail I created a MIDI transpose object, which takes MIDI in data on any channel, transposes it by an amount governed by its input, and outputs it on the same channel.
In the patch, the transposition is controlled by using MIDI program change: MIDI program numbers 0,1,2,3,4,5,6,7 set the transposition to -4,-3-,2-,1,0,1,2 or 3 octaves, respectively. Actually, any group of divisible-by-8 program numbers achieve the same thing.
I noticed by the way, that the MIDI input objects such as midi/in/pgm have an internal channel attribute that is undefined, so they only react to channel 1 (I suppose undefined attributes default to 0), and the channel cannot be set. So currently, the patch only responds to program changes on channel 0 even though the actual transposition can take place on any channel.
A limitation currently with the transpose object is that it only functions correctly one a single channel at a time. It has an internal vector storing the transpositions at the time of the note on in order to retain that transposition for the subsequent note off, and all note on events regardless of channel are stored in the vector. To do this properly would require a multi-dimensional vector, but that would head up 16 times more memory too (ok, so it only ends up being about 2 kbytes in the end, but still...). Room for future improvement.
The sample-and-hold is there so that a new transposition is only performed when a program change is actually received; since the output from the midi/in/pgm object defaults to 0, that would give a start-up transposition of -4 octaves otherwise.
There's also the added bonus of the red led on the Axoloti board lighting up every time a note on is received. It's not part of the transpose function.
I wasn't sure where to put the transpose object definition (I'm using version 1.0.6). It is currently in axoloti/objects/midi .
miditranspose.axp (4.7 KB)
transpose.axo (2.4 KB)