Contains the main class you need to create a MIDI file.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | OFF | = | 128 | |
integer, | public, | parameter | :: | ON | = | 144 |
Used by Note ON and Note OFF events: |
integer, | public, | parameter | :: | drums | = | 9 |
Useful MIDI parameters Percussions channel (in the 0..15 range): |
The main class you need to create a MIDI file.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=:), | private, | allocatable | :: | filename | |||
integer(kind=int32), | private | :: | size_pos | ||||
integer, | private | :: | status | ||||
integer, | private | :: | unit |
procedure, public :: Control_Change | |
procedure, public :: Note_OFF | |
procedure, public :: Note_ON | |
procedure, public :: Pitch_Bend | |
procedure, public :: Program_Change | |
procedure, public :: close | |
procedure, public :: cue_point | |
procedure, public :: delta_time | |
procedure, public :: end_of_track | |
procedure, public :: get_name | |
procedure, public :: instrument_name | |
procedure, public :: lyric | |
procedure, public :: marker | |
procedure, public :: new | |
procedure, public :: play_broken_chord | |
procedure, public :: play_chord | |
procedure, public :: play_note | |
procedure, public :: sequence_track_name | |
procedure, public :: set_tempo | |
procedure, public :: set_time_signature | |
procedure, public :: text_event | |
procedure, public :: track_header | |
procedure, private :: copyright_notice | |
procedure, private :: init_formidi | |
procedure, private :: write_string | |
procedure, private :: write_track_size | |
procedure, private :: write_variable_length_quantity |
Returns the name of the MIDI file:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(in) | :: | self |
MIDI delta times are composed of one to four bytes, depending on their values. If there is still bytes to write, the MSB (most significant bit) of the current byte is 1, else 0. This functions is automatically tested. https://en.wikipedia.org/wiki/Variable-length_quantity
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int32), | intent(in) | :: | i |
Many MIDI parameters can be set by Control Change. See the list.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | channel | |||
integer, | intent(in) | :: | type | |||
integer, | intent(in) | :: | ctl_value |
Writes a Note OFF event. MIDI notes are in the range 0..127 The release velocity is in the range 0..127.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | channel | |||
integer, | intent(in) | :: | note | |||
integer, | intent(in), | optional | :: | velocity |
Writes a Note ON event. MIDI notes are in the range 0..127 The attack velocity is in the range 1..127 and will set the volume. A Note ON event with a zero velocity is equivalent to a Note OFF.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | channel | |||
integer, | intent(in) | :: | note | |||
integer, | intent(in) | :: | velocity |
Apply a pitch bend to all notes currently sounding on the channel. No bend is 00 40 (64 in decimal), maximum downward bend is 00 00, maximum upward bend is 7F 7F. The Least Significant Byte (lsb) is optional (default value is 0), as it is useful only for fine adjustment. You can not use it with play_note, play_chord or play_broken_chord: you must manage yourself the Note ON and Note OFF events, and put the bend between.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | channel | |||
integer, | intent(in), | optional | :: | lsb | ||
integer, | intent(in) | :: | msb |
Each channel (0..15) can use one General MIDI instrument (0..127) at a time.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | channel | |||
integer, | intent(in) | :: | instrument |
Closes the MIDI file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self |
Copyright Notice event: FF 02 len text
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | text |
Cue Point event: FF 07 len text
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | text |
Each MIDI event must be preceded by a delay called "delta time", expressed in MIDI ticks.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | ticks |
A track must end with 0xFF2F00.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self |
Verifies the needed data types.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(in) | :: | self |
Instrument Name event: FF 04 len text
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | text |
Lyric event: FF 05 len text
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | text |
Marker event: FF 06 len text
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | text |
Create a new MIDI file and its metadata track. Concerning the "divisions" argument, ForMIDI uses the "metrical timing" scheme, defining the number of ticks in a quarter note. The "timecode" scheme is not implemented. SMF format: 0: only one track in the file 1: several tracks played together (generally used) 2: several tracks played sequentially
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | file_name | |||
integer, | intent(in) | :: | format | |||
integer, | intent(in) | :: | tracks | |||
integer, | intent(in) | :: | divisions | |||
integer, | intent(in) | :: | tempo | |||
integer, | intent(in), | optional | :: | time_signature(:) | ||
character(len=*), | intent(in), | optional | :: | copyright | ||
character(len=*), | intent(in), | optional | :: | text_event |
Writes a broken chord using an array containing the intervals (see the music_common module). https://en.wikipedia.org/wiki/Arpeggio You must pass either a scalar value (whole duration) or a values array (containing the values for each note).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | channel | |||
integer, | intent(in) | :: | note | |||
integer, | intent(in), | dimension(:) | :: | chord | ||
integer, | intent(in) | :: | velocity | |||
integer, | intent(in), | optional | :: | value | ||
integer, | intent(in), | optional, | dimension(:) | :: | values |
Writes a chord, waits for its duration, and writes the OFF events
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | channel | |||
integer, | intent(in) | :: | note | |||
integer, | intent(in), | dimension(:) | :: | chord | ||
integer, | intent(in) | :: | velocity | |||
integer, | intent(in) | :: | value |
Write a Note ON event, waits for its duration, and writes a Note OFF.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | channel | |||
integer, | intent(in) | :: | note | |||
integer, | intent(in) | :: | velocity | |||
integer, | intent(in) | :: | value |
Sequence or Track Name event: FF 03 len text
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | text |
Specifies a tempo change by writing the duration of a quarter note expressed in µs. It is coded on 3 bytes: from 1 µs to 256**3 µs ~ 16.7 s. A duration of 500000 µs = 0.5 s is equivalent to a 120 bpm tempo. https://en.wikipedia.org/wiki/Tempo MIDI events must always be preceded by a "delta time", even if null:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | duration |
The time signature includes the numerator, the denominator, the number of MIDI clocks between metronome ticks, (there are 24 MIDI clocks per quarter note) and the number of 32nd notes in a quarter note. The number of "MIDI clocks" between metronome clicks.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | numerator | |||
integer, | intent(in) | :: | denominator | |||
integer, | intent(in) | :: | metronome | |||
integer, | intent(in), | optional | :: | tsnotes |
Text event: FF 01 len text
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
character(len=*), | intent(in) | :: | text |
Writes a track header and stores the position where the size of the track will be written when the track will be closed.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
character(len=*), | intent(in), | optional | :: | track_name | ||
character(len=*), | intent(in), | optional | :: | text_event |
This subroutine is used my many events. The text must be coded in ASCII (7 bits).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer, | intent(in) | :: | event | |||
character(len=*), | intent(in) | :: | text |
Must be called when the track is finished. It writes its size at the memorized position in the track header.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self |
Writes the integer i in the MIDI file using the variable length quantity representation:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(MIDI_file), | intent(inout) | :: | self | |||
integer(kind=int32), | intent(in) | :: | i |