third_kind Program

Uses

  • program~~third_kind~~UsesGraph program~third_kind third_kind module~gm_instruments GM_instruments program~third_kind->module~gm_instruments module~midi_file_class MIDI_file_class program~third_kind->module~midi_file_class module~music music program~third_kind->module~music iso_fortran_env iso_fortran_env module~midi_file_class->iso_fortran_env module~utilities utilities module~midi_file_class->module~utilities module~music->iso_fortran_env module~music_common music_common module~music->module~music_common module~music->module~utilities module~utilities->iso_fortran_env

This is your starting point in the ForMIDI world. Close Encounters of the Third Kind: https://www.youtube.com/watch?v=S4PYI6TzqYk

You will generally use the format SMF 1 which allows several tracks to be played together. We will use only one musical track but we need 2 tracks, as there is always a metadata track automatically created by the new() method. Divisions is the number of ticks ("metrical timing" MIDI scheme) in a quarter note, and can be considered as the time resolution of your file.

The MIDI velocity is the speed at which you type on the keyboard and can be considered equivalent to the volume. As many MIDI values, it is defined in the 0..127 range. There are 16 channels (0..15). The value (duration) of a note is expressed in MIDI ticks.


Calls

program~~third_kind~~CallsGraph program~third_kind third_kind proc~end_of_track MIDI_file%end_of_track program~third_kind->proc~end_of_track proc~get_name MIDI_file%get_name program~third_kind->proc~get_name proc~midi_note MIDI_Note program~third_kind->proc~midi_note proc~new MIDI_file%new program~third_kind->proc~new proc~play_note MIDI_file%play_note program~third_kind->proc~play_note proc~program_change MIDI_file%Program_Change program~third_kind->proc~program_change proc~track_header MIDI_file%track_header program~third_kind->proc~track_header proc~delta_time MIDI_file%delta_time proc~end_of_track->proc~delta_time proc~write_track_size MIDI_file%write_track_size proc~end_of_track->proc~write_track_size proc~new->proc~end_of_track proc~new->proc~track_header proc~checked_int16 checked_int16 proc~new->proc~checked_int16 proc~checked_int32 checked_int32 proc~new->proc~checked_int32 proc~checked_int8 checked_int8 proc~new->proc~checked_int8 proc~copyright_notice MIDI_file%copyright_notice proc~new->proc~copyright_notice proc~init_formidi MIDI_file%init_formidi proc~new->proc~init_formidi proc~set_tempo MIDI_file%set_tempo proc~new->proc~set_tempo proc~set_time_signature MIDI_file%set_time_signature proc~new->proc~set_time_signature proc~text_event MIDI_file%text_event proc~new->proc~text_event proc~play_note->proc~checked_int32 proc~play_note->proc~delta_time proc~note_off MIDI_file%Note_OFF proc~play_note->proc~note_off proc~note_on MIDI_file%Note_ON proc~play_note->proc~note_on proc~program_change->proc~checked_int8 proc~program_change->proc~delta_time proc~sequence_track_name MIDI_file%sequence_track_name proc~track_header->proc~sequence_track_name proc~track_header->proc~text_event proc~write_string MIDI_file%write_string proc~copyright_notice->proc~write_string proc~delta_time->proc~checked_int32 proc~write_variable_length_quantity MIDI_file%write_variable_length_quantity proc~delta_time->proc~write_variable_length_quantity proc~note_off->proc~checked_int8 proc~note_on->proc~checked_int8 proc~sequence_track_name->proc~write_string proc~set_tempo->proc~checked_int32 proc~set_tempo->proc~delta_time proc~set_time_signature->proc~checked_int8 proc~set_time_signature->proc~delta_time proc~text_event->proc~write_string proc~write_string->proc~checked_int8 proc~write_string->proc~delta_time proc~write_string->proc~write_variable_length_quantity proc~variable_length_quantity variable_length_quantity proc~write_variable_length_quantity->proc~variable_length_quantity

Variables

Type Attributes Name Initial
type(MIDI_file) :: midi

Source Code

program third_kind
    ! The main class you need to create music:
    use MIDI_file_class
    ! The function MIDI_Note() returns the MIDI number of a note from 12 (C0)
    ! to 127 (G9). The A4 (440 Hz tuning standard) is the note 69.
    use music
    ! Contains the list of General MIDI 128 instruments and 47 percussions:
    use GM_instruments

    implicit none
    type(MIDI_file) :: midi

    !> You will generally use the format SMF 1 which allows several tracks
    !> to be played together.
    !> We will use only one musical track but we need 2 tracks, as there is
    !> always a metadata track automatically created by the new() method.
    !> Divisions is the number of ticks ("metrical timing" MIDI scheme) in
    !> a quarter note, and can be considered as the time resolution of your file.
    ! We define the tempo: a quarter note will last 500000 µs = 0.5 s => tempo=120 bpm
    call midi%new("third_kind.mid", format=1, tracks=2, divisions=quarter_note, tempo=500000, &
                & text_event="This file was created with the ForMIDI Fortran project")

    ! (1) The single musical track:
    call midi%track_header()

    ! Choosing the instrument (in the 0..127 range):
    call midi%Program_Change(channel=0, instrument=Pad_6_metallic)

    ! Playing a sequence of five notes on MIDI channel 0:
    call midi%play_note(channel=0, note=MIDI_Note("G4"), velocity=mf_level, value=quarter_note)
    call midi%play_note(channel=0, note=MIDI_Note("A4"), velocity=mf_level, value=quarter_note)
    call midi%play_note(channel=0, note=MIDI_Note("F4"), velocity=mf_level, value=quarter_note)
    call midi%play_note(channel=0, note=MIDI_Note("F3"), velocity=mf_level, value=quarter_note)
    call midi%play_note(channel=0, note=MIDI_Note("C4"), velocity=mf_level, value=half_note)
    !> The MIDI velocity is the speed at which you type on the keyboard and
    !> can be considered equivalent to the volume. As many MIDI values, it is
    !> defined in the 0..127 range.
    !> There are 16 channels (0..15).
    !> The value (duration) of a note is expressed in MIDI ticks.

    call midi%end_of_track()

    call midi%close()

    print *,"You can now play the file ", midi%get_name()
end program third_kind