arpeggios Program

Uses

  • program~~arpeggios~~UsesGraph program~arpeggios arpeggios module~envelopes envelopes program~arpeggios->module~envelopes module~forsynth forsynth program~arpeggios->module~forsynth module~music music program~arpeggios->module~music module~music_common music_common program~arpeggios->module~music_common module~signals signals program~arpeggios->module~signals module~wav_file_class wav_file_class program~arpeggios->module~wav_file_class module~envelopes->module~forsynth module~tape_recorder_class tape_recorder_class module~envelopes->module~tape_recorder_class iso_fortran_env iso_fortran_env module~forsynth->iso_fortran_env module~music->module~envelopes module~music->module~forsynth module~music->module~music_common module~music->module~signals module~music->module~tape_recorder_class module~signals->module~envelopes module~signals->module~forsynth module~signals->module~tape_recorder_class module~wav_file_class->module~forsynth module~wav_file_class->iso_fortran_env module~wav_file_class->module~tape_recorder_class module~tape_recorder_class->module~forsynth

Arpeggios played in various ways using the circles of fifths https://en.wikipedia.org/wiki/Arpeggio


Calls

program~~arpeggios~~CallsGraph program~arpeggios arpeggios proc~add_broken_chord add_broken_chord program~arpeggios->proc~add_broken_chord proc~add_karplus_strong add_karplus_strong program~arpeggios->proc~add_karplus_strong proc~apply_fade_out apply_fade_out program~arpeggios->proc~apply_fade_out proc~close_wav_file WAV_file%close_WAV_file program~arpeggios->proc~close_wav_file proc~create_wav_file WAV_file%create_WAV_file program~arpeggios->proc~create_wav_file proc~fr fr program~arpeggios->proc~fr proc~get_name WAV_file%get_name program~arpeggios->proc~get_name proc~mix_tracks tape_recorder%mix_tracks program~arpeggios->proc~mix_tracks proc~add_broken_chord->proc~add_karplus_strong proc~finalize tape_recorder%finalize proc~close_wav_file->proc~finalize proc~write_normalized_data WAV_file%write_normalized_data proc~close_wav_file->proc~write_normalized_data proc~new tape_recorder%new proc~create_wav_file->proc~new proc~write_header WAV_file%write_header proc~create_wav_file->proc~write_header proc~clear_tracks tape_recorder%clear_tracks proc~new->proc~clear_tracks

Variables

Type Attributes Name Initial
type(WAV_file) :: demo
real(kind=wp) :: dur
integer :: i
character(len=3) :: name
real(kind=wp) :: t

Source Code

program arpeggios
    use forsynth, only: wp
    use wav_file_class, only: WAV_file
    use music_common, only: MINOR_CHORD, MAJOR_CHORD, &
                          & CIRCLE_OF_FIFTHS_MAJOR, CIRCLE_OF_FIFTHS_MINOR
    use music, only: add_chord, add_broken_chord, fr, SEMITONE
    use signals, only: add_karplus_strong
    use envelopes, only: apply_fade_out

    implicit none
    type(WAV_file) :: demo
    integer  :: i
    real(wp) :: t, dur
    character(3) :: name

    print *, "**** Demo arpeggios ****"
    ! We create a new WAV file, and define the number of tracks and its duration:
    call demo%create_WAV_file('arpeggios.wav', tracks=2, duration=40._wp)

    associate(tape => demo%tape_recorder)

    ! Chord duration in seconds:
    dur = 0.75_wp

    print *, "Track 1: the circle of fifths major (left channel, octave 2)"
    t = 0.0_wp
    do i = 1, size(CIRCLE_OF_FIFTHS_MAJOR)
        name = trim(CIRCLE_OF_FIFTHS_MAJOR(i)) // "2"
        print *, i, name, fr(name)
        call add_broken_chord(tape, track=1, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MAJOR_CHORD)
        t = t + dur
    end do

    print *, "The same, but the notes of each chord are played in an inverted order"
    do i = 1, size(CIRCLE_OF_FIFTHS_MAJOR)
        name = trim(CIRCLE_OF_FIFTHS_MAJOR(i)) // "2"
        print *, i, name, fr(name)
        call add_broken_chord(tape, track=1, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MAJOR_CHORD(3:1:-1))
        t = t + dur
    end do

    print *, "Counterclockwise, the circle of fourths"
    do i = size(CIRCLE_OF_FIFTHS_MAJOR), 1, -1
        name = trim(CIRCLE_OF_FIFTHS_MAJOR(i)) // "2"
        call add_broken_chord(tape, track=1, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MAJOR_CHORD)
        t = t + dur
    end do

    print *, "Once again, half the circle, slower and slower, with inverted arpeggios"
    do i = size(CIRCLE_OF_FIFTHS_MAJOR)/2, 1, -1
        name = trim(CIRCLE_OF_FIFTHS_MAJOR(i)) // "2"
        call add_broken_chord(tape, track=1, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MAJOR_CHORD(3:1:-1))
        t = t + dur
        dur = dur * 1.1_wp
    end do

    print *, "We repeat the final chord"
    call add_broken_chord(tape, track=1, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MAJOR_CHORD(3:1:-1))
    call add_karplus_strong(tape, track=1, t1=t+dur, t2=t+5*dur, f=fr(name)*SEMITONE**MAJOR_CHORD(3), Amp=1.0_wp)

    print *, "Track 2: the circle of fifths minor (right channel, octave 3)"
    dur = 0.75_wp
    t = 0.0_wp
    do i = 1, size(CIRCLE_OF_FIFTHS_MINOR)
        name = trim(CIRCLE_OF_FIFTHS_MINOR(i)) // "3"
        call add_broken_chord(tape, track=2, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MINOR_CHORD)
        t = t + dur
    end do

    print *, "The same, but the notes of each chord are played in an inverted order"
    do i = 1, size(CIRCLE_OF_FIFTHS_MINOR)
        name = trim(CIRCLE_OF_FIFTHS_MINOR(i)) // "3"
        call add_broken_chord(tape, track=2, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MINOR_CHORD(3:1:-1))
        t = t + dur
    end do

    print *, "Counterclockwise, the circle of fourths"
    do i = size(CIRCLE_OF_FIFTHS_MINOR), 1, -1
        name = trim(CIRCLE_OF_FIFTHS_MINOR(i)) // "3"
        call add_broken_chord(tape, track=2, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MINOR_CHORD)
        t = t + dur
    end do

    print *, "Once again, half the circle, slower and slower, with inverted arpeggios"
    do i = size(CIRCLE_OF_FIFTHS_MINOR)/2, 1, -1
        name = trim(CIRCLE_OF_FIFTHS_MINOR(i)) // "3"
        call add_broken_chord(tape, track=2, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MINOR_CHORD(3:1:-1))
        t = t + dur
        dur = dur * 1.1_wp
    end do

    print *, "We repeat the final chord and the final note"
    call add_broken_chord(tape, track=2, t1=t, t2=t+dur, f=fr(name), Amp=1.0_wp, chord=MINOR_CHORD(3:1:-1))
    call add_karplus_strong(tape, track=2, t1=t+dur, t2=t+5*dur, f=fr(name)*SEMITONE**MINOR_CHORD(3), Amp=1.0_wp)

    print *, "Final fade out"
    call apply_fade_out(tape, track=1, t1=t+dur,  t2=t+5*dur)
    call apply_fade_out(tape, track=2, t1=t+dur,  t2=t+5*dur)

    end associate

    print *, "Final mix..."
    ! In the mix, chords are rather on the left
    ! and plucked strings on the right (and their level is lowered):
    call demo%mix_tracks(levels=[1._wp, 1.2_wp], pan=[-0.5_wp, +0.5_wp])
    call demo%close_WAV_file()

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