Modality-toolkit
Modality-toolkit copied to clipboard
How to use the 14bit midi?
Hello everyone I am experimenting with the 14bit midi capabilities of Modality and trying to figure it all out without documentation so just wanted to create this issue to document some of it and then maybe we can move to add help files / info at some point.
So, I have a very basic controller made using a Teensy microcontroller board. I have set up a small desc for two potentiometers that are transmitted as 14 bit midi from the controller to Modality:
~descInput = (
idInfo: "Teensy MIDI",
deviceName: "Teensy MIDI",
protocol: \midi,
elementsDesc: (
elements: (16..20).collect{|lowerMidiCC|
(
key: "kn%".format(lowerMidiCC).asSymbol,
type: 'knob',
spec: \midiCC,
midiMsgType: \cc14,
midiChan: 0,
midiNum: lowerMidiCC,
ioType: \in
)
}
)
);
m = MKtl( \testMIDI, ~descInput ).trace(true);
The raw values look fine going from 0 to 14 bits value, but the mapped value seems to rely on the normal midicc spec so it reaches 1.0 when the raw input is 127. Looking at the source code I see no midicc14 spec. Is this missing?
And so for now, if you want to get a proper spec fitting for the cc14 range you need to add it manually, eg:
(
~descInput = (
idInfo: "Teensy MIDI",
deviceName: "Teensy MIDI",
protocol: \midi,
elementsDesc: (
elements: (16..20).collect{|lowerMidiCC|
(
key: "kn%".format(lowerMidiCC).asSymbol,
type: 'knob',
spec: [0,16383,\lin,1,0], // 14 bit spec
midiMsgType: \cc14,
midiChan: 0,
midiNum: lowerMidiCC,
ioType: \in
)
}
)
);
);
Adding a section to the "how to create a description file for a midi device" help file about 14 bit midi would be cool too
And for reference, this is the teensy 3.2 code reading the values of two potentiomters and sending them as 14 bit midi:
#include "Arduino.h"
/* #include <ResponsiveAnalogRead.h> */
#define LEDPIN 13
#define POT_PIN1 14
#define POT_PIN2 15
/* Pot value storage */
const int numPots = 2;
int pots[numPots] = {0, 0};
int potsOld[numPots] = {0, 0};
void setup() {
/* pin configuration */
pinMode(POT_PIN1, INPUT);
pinMode(POT_PIN2, INPUT);
pinMode(LEDPIN, OUTPUT);
/* resolution */
analogReadResolution(13);
/* smooth input values */
analogReadAveraging(16);
digitalWrite(LEDPIN, HIGH);
}
void readPots() {
for (int potNum = 0; potNum < numPots; ++potNum) {
switch (potNum) {
case 0:
// Shift up from ADC's 13 bits to Midi 14 bit
pots[potNum] = analogRead(POT_PIN1) << 1;
if (pots[potNum] != potsOld[potNum]) {
usbMIDI.sendControlChange(48, pots[potNum] & 0x7F, 1);
usbMIDI.sendControlChange(16, (pots[potNum] >> 7) & 0x7F, 1);
}
break;
case 1:
pots[potNum] = analogRead(POT_PIN2) << 1;
if (pots[potNum] != potsOld[potNum]) {
usbMIDI.sendControlChange(49, pots[potNum] & 0x7F, 1);
usbMIDI.sendControlChange(17, (pots[potNum] >> 7) & 0x7F, 1);
}
break;
}
}
}
void loop() {
readPots();
delay(10);
}
(made for uploading with platformio)
I ended up writing a blog post about this https://madskjeldgaard.dk/posts/14bit-midi-teensy-supercollider/
See this PR https://github.com/ModalityTeam/Modality-toolkit/pull/381