MIDI - Notes
Microsoft Windows bundles SMFs together with Downloadable Sounds (DLS) in a Resource Interchange File Format (RIFF) wrapper, as RMID files with a .rmi extension. RIFF-RMID has been deprecated in favor of Extensible Music Files (XMF).
Controllers include devices such as pedals and levers. Controller numbers 120-127 are reserved as "Channel Mode Messages".
Midi File Format:
Header Chunk | (Tempo) Track Chunk1 | Track Chunk 2-17
Header Chunk:
MThd - 4 bytes - Midi Track Header Signature 4 bytes. "File Type"
Length - 4 bytes -
SMF Type - 2 bytes - Type 0 means only single Track.
Total Tracks - 2 bytes -
PPQ Value - 2 bytes - PPQN (Pulses Per Quarter Note, also known as PPQ). 96 is common.
Higher PPQ is more fine control.
Meta Track Chunk 1 :
Track Number - 4 bytes
(PPQ-Offset, Time Signature Meta Event)
(PPQ-Offset, Key Signature Meta Event Changes) *
(PPQ-Offset, Additional meta events) ... e.g. "Track name", copyright, "Instrument Name",
"Lyric", "Marker", "Cue Point" (e.g. He starts dreaming).
Track 2 :
Track Number - 4 bytes
PPQ, Patch Change Message.
PPQ, Reset All Controllers Message. All values set to default values. (c = 121 command)
PPQ, PAN control
PPQ, Volume control .... (Say, start with High volume)
PPQ, First Midi Message ... Followed by N messages.
PPQ, End of Track Message.
Note: Channel Mode Messages followed by Channel Voice Messages.
Note: Use smfsh utility to examine the midi file:
$ smfsh
load file
tracks
track 1
events
tempo
help
MIDI Channels represents real/virtual instruments. MIDI standard supports only max 16 channels. To overcome this limitation (channel, bank) virtually represents large number of instruments.
MIDI Tracks are mostly logical representation in software or in MIDI file. In theory single MIDI track can represent entire composition in MIDI file. The software can split this into logical tracks. (e.g. 1 track per channel or (channel,bank) ).
Track:Channel is N:N relation:
- A track can have one or more channels. Possible only in MIDI file. Not possible in Cubase track.
A track can not change it's instrument/program selection between start to end.
In practice a track can be associated with only one Channel instance. i.e (channel, Prog, instance-no).
- A channel instance can be associated with multiple tracks:
e.g. Left Hand and Right Hand separate tracks. But both hands play the same instrument.
e.g. Drum Kits may be split into different groove beats tracks mapping into same instrument.
For complete info see, midicsv tool http://www.fourmilab.ch/webtools/midicsv/
::
0, 0, Header, 1, 2, 480 1, 0, Start_track 1, 0, Title_t, "Close
Encounters" 1, 0, Text_t, "Sample for MIDIcsv Distribution" 1, 0,
Copyright_t, "This file is in the public domain" 1, 0, Time_signature,
4, 2, 24, 8 1, 0, Tempo, 500000 1, 0, End_track 2, 0, Start_track 2, 0,
Instrument_name_t, "Church Organ" 2, 0, Program_c, 1, 19 2, 0,
Note_on_c, 1, 79, 81 2, 960, Note_off_c, 1, 79, 0 2, 960, Note_on_c, 1,
81, 81 2, 1920, Note_off_c, 1, 81, 0 ... 0, 0, End_of_file
Synopsis:
Header Records:
-----------------
0, 0, Header, format, nTracks, division # The first record of a CSV MIDI file is always the Header record.
# format: the MIDI file type (0, 1, or 2),
# division: the number of clock pulses per quarter note.
Track, 0, Start_track
Track, Time, End_track
0, 0, End_of_file
Track, Time, Tempo, Number # Tempo is Number of microseconds per beat; 500000 means .5 secs; 120 bpm.
Track, Time, Time_signature, Num, Denom, Click, NotesQ # Click: Metronome click rate; NotesQ: Number of 32nd notes per beat;
# Denom specifies the denominator as a negative power of two, for example 2 for a quarter note, 3 for an eighth note, etc.
Meta Events
------------
All meta-events which take a text argument are identified by a suffix of “_t” (e.g. Title_t, Instrument_name_t, etc).
Track, Time, Marker_t, Text # Support for time markers. e.g. "Third Movement".
Track, Time, Cue_point_t, Text # Info cue support. for example, "Door slams".
Track, Time, Lyric_t, Text # Karaoke support
Track, Time, Text_t, Text # Generic tagging at specific time. Use as you like.
Track, Time, Key_signature, Key, Major/Minor # Key is 0 for C, range 7 to -7 sharps/flats. "major" or "minor".
Rarely used / Vendor specific:
--------------------------------
Track, 0, Sequence_number, Number # This meta-event specifies a sequence Number between 0 and 65535,
# used to pack multiple tracks in type 2 MIDI; should occur at Time zero.
Track, Time, Channel_prefix, Number # Change current channel event; Future events apply to this channel.
Track, Time, Sequencer_specific, Length, Data, … # To store vendor-proprietary data in a MIDI file.
Track, Time, Unknown_meta_event, Type, Length, Data, … # midicsv uses to flag unknown meta-event code encountered.
Track, Time, System_exclusive, Length, Data, … # Vendor specific ...
Channel Events:
---------------
Track, Time, Note_on_c, Channel, Note, Velocity # Names of channel events all have a suffix of “_c”.
# Middle C is defined as Note number 60;
# Velocity (0 to 127). A Note_on_c event with Velocity zero is Note_off_c.
Track, Time, Note_off_c, Channel, Note, Velocity # Velocity must be 0.
Track, Time, Pitch_bend_c, Channel, Value # Range from 0-16383. The value 8192 is no pitch bend; Effect unspecified.
Track, Time, Control_c, Channel, Control_num, Value # Range is 0-127 for both control_num and value.
# Controllers: 1 (modulation); 7:volume, 10:pan, 11:expression, 64:sustain
Track, Time, Program_c, Channel, Program_num # Switch channel to program (patch) Program_num; Range: 0-127;
# Instruments documentation may refer to 1 to 128 patches (refers to n+1)
Track, Time, Poly_aftertouch_c, Channel, Note, Value # Polyphonic synths repeats sending the pressures until released. 0-127.
Track, Time, Channel_aftertouch_c, Channel, Value # Monophonic synths send aftertouch pressure for lastkey for entire channel.
Track, 0, SMPTE_offset, Hour, Minute, Second, Frame, FracFrame # Used for video sync start time. Fractional Frame time is 0 to 99.
Pros:
Cons:
The best compatible sound font players use the fluidsynth library: http://www.fluidsynth.org/ The vstsynth and many opensource projects use this library. Fortunately, we don't have to use any sf font player synthesizer with FL Studio.
We use Fruity LSD as an effect plugin on (first) mixer channel. It is a software synthesizer which uses your soundcard (efficient implementation) and allows you to access 16 instruments.
In step sequencer, you load MIDI out plugin.
Fruity LSD Plugin configuration:
MIDI Out Channel Plugin Configuration for each channel :
Port - Leave as 0 to accept any midi controller attached live.
When multiple instruments have set port:0, the one with the lowest channel number 'traps' midi signal and does not propagate to others. If you want to assign different ports to different devices, then filter it here accordingly.
Channel: Choose unique slot number from 1 to 16.
The patch number (aka Program number or instrument number) chooses the real instrument (like piano, recorder, etc). The midi controller does not send "patch number" over the wire. It just sends the 'channel number' as part of protocol. The midi controller hardware connection (usb slot) defines the "port number".
The channel number 10 is reserved for drumkit. So patch number is ignored when channel = 10.