A MIDI code typically consists of 4 different values each having a length of 1 byte (0-255):
The Message value (msg), basically the nature of the MIDI message. See midi-implementation.
The Data1 value : It depends of the message value (for instance for a NOTE ON message, data1 contains the pitch value (0-127, note C3=60).
The Data2 value: It also depends on the msg value (for instance for a NOTE ON message, data1 contains the velocity value (0-127, 0=silence, 127= loudest).
To deal with the multiple-value MIDI message, Usine Script has a built-in type defined as follows:
type TMIDI = Record
Msg : Byte;
Data1 : Byte;
Data2 : Byte;
Channel : byte;
end;
''TMIDI'' is a data structure used in Pascal called record.
A record is a variable containing several 'sub-variables'.
Or you can see it as several variables all grouped under a common name.
Let's declare a MIDI variable:
Var MIDI1 : TMIDI;
// MIDI1 will store a MIDI message
To access the different values of the MIDI1 message do like this:
Var m, d1, d2, c : byte;
m := MIDI1.msg;
d1 := MIDI1.data1;
d2 := MIDI1.data2;
c := MIDI1.channel;
// the different values of MIDI1 are stored to m, d1, d2, c.
// notice the dot between MIDI1 and it's values, this is how you access a record sub-variables.
Let's store in MIDI1 the message ( NOTE ON, note=C3, vel=90, channel=1):
Var MIDI1 : TMIDI;
MIDI1.msg := 144; // Note ON
MIDI1.data1 :=60; // C3
MIDI1.data2 := 90; // vel 90
MIDI1.channel :=1; // Channel 1
Let's transpose MIDI1 an octave higher:
MIDI1.data1 := MIDI1.data1 + 12;
If we have an array of MIDI codes, it's the same:
Var TabMIDI : array of TMIDI;
TabMIDI[3].msg := 148;
TabMIDI[3].data1 := 60;
version 4.0.191119
Edit All Pages