Well, I think we are about to take a little road trip. I didn’t like the sound of the chord progression files I was generating. So, in a moment of madness, I decided to check out MIDI files. And, though I don’t yet know if I can do what I want programmatically, I do like what I have managed to do manually. Though with a bit of difficulty and a fair bit of searching and reading.

I converted two of my WAV to MIDI using an on-line converter. Then installed a midi editor (I am going to use lowercase from here on). Loaded my files, selected an instrument and exported to wav. And, I do find the resulting files much more pleasant. I also removed the nosnd spaces in the midi files. I will be modifying my code to stop inserting those blanks. They just resulted in a ticking sound in my own wav files (well at least that’s what I think, haven’t yet tested that thought).

I will run you through what I have done, and provide a resulting sound file or two. Then I will go off to investigate what I can or can not do programmatically. Then get back to finishing this post or starting a new one.

Manual Conversion

Audio to Midi

The audio to midi converter I used was the Basic Pitch on-line demo.

About Basic Pitch from Spotify

Basic Pitch is a lightweight, lightning-fast audio-to-MIDI converter that features pitch bend detection and works on recordings of almost any instrument, including voice. It’s brought to you by the researchers and engineers at Spotify’s Audio Intelligence Lab.

Basic Pitch

I won’t bother with a screen shot. I converted a couple of my generated .wav files to midi and downloaded/saved the resulting midi files.

MIDI Editor

As my initial attempt at a midi editor I decided to go with MuseScore Studio. Based on a rather old article, but…

MuseScore is a music recording and editing program designed with an emphasis on working with piano parts. It supports the MusicXML format, which allows you to easily exchange notes between different programs and devices. The intuitive interface makes the process of creating and editing projects convenient, and the ability to work with several audio tracks simultaneously significantly speeds up the work.

MIDI editors

However, I did install the version without MuseHub. Didn’t think I would be needing or using that app. Again, no screen shot.

Generate Audio File from MIDI File

As soon as I loaded one of the midi files into MuseScore the whole bit of music sounded completely different. The conversion, to my eyes, generated a completely different though fundamentally similar piece of music. I am guessing the overtones I added somehow affected that process.

I may try to write my version as a music score to compare it with that generated by Basic Pitch. But I expect that would be a lot of work for someone, like me, with no experience.

For the remainder of this section, I am going to use the following chord progression. Here’s the terminal output.

(base) PS R:\learn\e_music> uv run tst_chords.py
chord progression with overtones on each chord

selected key: D# min_nat (octave: 3)
  scale notes: ['D#3', 'F3', 'F#3', 'G#3', 'A#3', 'B3', 'C#4']
  key chords: [('D#', 'minor'), ('F', 'dim'), ('F#', 'major'), ('G#', 'minor'), ('A#', 'minor'), ('B', 'major'), ('C#', 'major')]
  chord progression (roman numerals): I-vi-ii
  chord progression: [('D#', 'minor'), ('B', 'major'), ('F', 'dim')]
    [
      D# minor -> ['D#3', 'F#3', 'A#3']
      B major -> ['B3', 'D#4', 'F#4']
      F dim -> ['F3', 'G#3', 'B3']
    ]
        multipliers: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
        amplitudes: [-0.228, 0.108, -0.063, 0.0406, -0.0267, 0.0204, -0.0159, 0.0126, -0.0098, 0.0084]
        {'whl': 4.0, 'hlf': 2.0, 'qtr': 1.0, '8th': 0.5, '16th': 0.25, '32nd': 0.125}
  ['hlf', 'qtr', 'qtr']
    0: hlf -> 2.0 * 0.2870 -> 0: ('D#', 'minor')
    1: qtr -> 1.0 * 0.4773 -> 1: ('B', 'major')
    2: qtr -> 1.0 * 0.7370 -> 2: ('F', 'dim')
  ['qtr', 'qtr', 'hlf']
    0: qtr -> 1.0 * 0.2224 -> 0: ('D#', 'minor')
    1: qtr -> 1.0 * 0.5112 -> 1: ('B', 'major')
    2: hlf -> 2.0 * 0.6181 -> 2: ('F', 'dim')
  ['hlf', 'qtr', 'qtr']
    0: hlf -> 2.0 * 0.6558 -> 0: ('D#', 'minor')
    1: qtr -> 1.0 * 0.5760 -> 1: ('B', 'major')
    2: qtr -> 1.0 * 0.6073 -> 2: ('F', 'dim')
  ['hlf', 'qtr', 'qtr']
    0: hlf -> 2.0 * 0.7038 -> 0: ('D#', 'minor')
    1: qtr -> 1.0 * 0.5760 -> 1: ('B', 'major')
    2: qtr -> 1.0 * 0.2838 -> 2: ('F', 'dim')
  ['qtr', 'qtr', 'hlf']
    0: qtr -> 1.0 * 0.6455 -> 0: ('D#', 'minor')
    1: qtr -> 1.0 * 0.7554 -> 1: ('B', 'major')
    2: hlf -> 2.0 * 0.4453 -> 2: ('F', 'dim')
  ['qtr', 'qtr', 'hlf']
    0: qtr -> 1.0 * 0.2983 -> 0: ('D#', 'minor')
    1: qtr -> 1.0 * 0.3322 -> 1: ('B', 'major')
    2: hlf -> 2.0 * 0.5395 -> 2: ('F', 'dim')
         qtr -> 1.0 * 0.5395 -> 2: ('F', 'dim')
         qtr -> 1.0 * 0.5395 -> 2: ('D#', 'minor')
writing to wave file: I-vi-ii_4-4_even_tri_o3_1.wav

And here’s what I saw in the MuseScore window when I loaded that file.

Truly not what I expected. Certainly not two clefs, treble and bass. Nothing like that in the .wav file I generated. When I saw that I was hoping I could assign a different instrument to each clef. But that bracket to the left of each row of the score indicates both clefs are tied to the same instrument (at least so I believe).

Not only that, my code says it was generating a chord progression in the key of D# Natural Minor (relative key would be F# major). The key above looks to be G♭ major or E♭ minor (relative keys). Not sure why the app chose E♭ minor. That said, E♭ and D# are the same key on a piano. But the result, I believe, is that the chords do get written differently on the music score. Turns out E♭ minor is preferred over D# minor for writing music.

Anyway, I broke down and made an attempt to write the score for the program’s version of the chord progression. I duplicated it on treble and bass clefs. Here’s the PDF of that score.

Do note, the program set the ii as F dim. For the normal minor key the ii is E sharp dim. In my case, an F is subsituted for the E#. As you can see, I assigned the treble clef to an electric piano and the bass to a bass guitar. Had meant to select electric bass guitar but messed up. The bass is mixed at a lower volume than the piano. Not sure what the numbers mean but piano is at \(0\) and the bass at \(-6\). The beats per minute are \(~120\) rather than the \(60\) in the program’s version. So a quarter note below lasts \(1/2\) second.

And, here’s what my score sounds like.

And for reference here’s the MuseScore generated midi exported to a .wav. Both clefs on an electric piano. And both mixed at the same volume.

This One Done

I had planned to mess around with different instruments to play the miniature score. And when exporting to the .wav files. But, have decided this post pretty much does what I set out to cover/do. So, I am going to call it quits. And think about getting my program to generate the MIDI file instead of going to a web site and doing so manually. Hopefully, I will also find a way to take the midi file and generate a .wav file.

Until next time, may your musical ambitions be more fruitful than mine have been.

Resources