Coding the basics of the MIDI protocole was not very complicated, except concerning the fact that some 32 bits data are encoded using the Variable-Length Quantity code to use only the minimum number of bytes. It’s because MIDI (Musical Instrument Digital Interface) was launched in 1983 and its speed is only 31250 baud!
Two interesting articles about an early experiment: “Push Button Bertha” (1956). In the second link, there is some newspapers articles published in 1956-57:
Probably not yet in Fortran, our baby was just being born…
src/music.f90: a module containing some music theory elements (scales, circle of fifths, chords), and the subroutine write_chord() and the function get_note_name().
src/MIDI_control_changes.f90: a module with all the MIDI Control Changes parameters.
src/GM_instruments.f90: contains the list of 128 General MIDI instruments and 47 percussive instruments (channel 9).
src/demos.f90: a new demo4 plays a random walk on the circle of fifths. You can listen to it here . It’s a pleasant music, although just a random walk: the probabilities are 1/3 to move one chord clockwise on the circle of fifths, 1/3 to move one chord counterclockwise, 1/3 to switch between the major and minor circles. The Pythagoreans already knew the fifth was very important in music, with its simple 2/3 string length ratio!
The music theory elements are stored in arrays, for example chords can be defined like this and passed to the write_chord() subroutine:
Another long term hobby project, ForMIDI 0.3 “Forbidden Planet” was just released. It was heavily refactored with a MIDI_file class and the API was considerably simplified (see the CHANGELOG.md).
A new example la_folia.f90 was added. On a first track, strings are playing the chords of that classical theme. On the second track, the same chords are arpeggiated in several ways. Listen to the OGG file.
But for your first encounter with ForMIDI, start by the simplest example third_kind.f90, which is just playing five notes on a single track:
$ fpm run --example third_kind
More comments were added in the examples, as a documentation for beginners.
A time_signature optional argument in the new() method (4/4 is the default).
The MIDI event pitch_bend() (corresponding to the left wheel on synthesizers).
Most useful notes values, alongside quarter_note, are now defined as Fortran parameters: whole_note, half_note, eighth_note, sixteenth_note and thirty_second_note, expressed in MIDI ticks. There is also a new dotted() function returning the value of a dotted note.
Common note levels are defined as Fortran parameters from pppp_level to ffff_level.
The method play_broken_chord() can now either accept a value argument with the whole duration or a values array argument containing the values for each note.
A new example/motifs.f90 was added: the original idea was to play with Dmitri Shostakovich’s DSCH motif and BACH motif (in German notation). As there are four musical tracks, it was also used to explore ways of coding synchronized tracks. Indeed, all MIDI tracks are played simultaneously but are coded sequentially in the Fortran code, unlike a musical score. Listen to the Ogg file.