Casting midi data bytes to 14 bit integers - JoueBien/rtp-midi-transport GitHub Wiki
Overview
Some times you need to encode a single unsigned number into two midi data bytes.
castUnsignedInt14ToMidiDatais used to encode an integer into two midi data bytes.castMidiDataToUnsignedInt14can take those data bytes and decode them back into an integer.
The largest number that can be encoded is 16383. The smallest number that can be encoded is 0. Numbers larger than 16383 will be wrapped around. For example encoding 16385 will result in the number 1 being decoded.
castUnsignedInt14ToMidiData
Encode an into into two midi data values. Commonly used for fader values.
import { MidiTransport } from "@joue-bien/rtp-midi-transport/utils";
const data = castUnsignedInt14ToMidiData(123);
// [0, 123]
castMidiDataToUnsignedInt14
Decode two midi data points into a single int. Commonly used for fader values.
import { MidiTransport } from "@joue-bien/rtp-midi-transport/utils";
const intValue = castMidiDataToUnsignedInt14([0, 123]);
// 123