3

I'm processing a bulk of midi files that are made for existing pop songs using music21.

While channel 10 is reserved for percussions, melodic tracks are all over different channels, so I was wondering if there is an efficient way to pick out the main melody (vocal) track.

I'm guessing one way to do it is to pick a track that consists of single notes rather than overlapping harmonics (chords), and the one that plays throughout the song, but is there any other efficient way?

ytrewq
  • 3,670
  • 9
  • 42
  • 71

3 Answers3

1

Depending on how your particular files are encoded, you could try filtering based on each part's name. That would look something like this:

import music21
from music21 import *

piece = converter.parse("full_path_to_piece.midi")
for part in piece.parts:
  print(part[0].bestName()) # replace this print statement with a relevant if statement
Alex
  • 2,154
  • 3
  • 26
  • 49
  • Thanx! Does bestName refer to track names set by the user, or does it automatically match the name of the sound patch? Also, what is the case when bestName returns None? – ytrewq Dec 09 '16 at 06:40
  • According to the docs on bestName(), it says it does this "Find a viable name, looking first at instrument, then part, then abbreviations." I assume it would return None if none of those things were given a name in the original file. Here's the documentation: http://web.mit.edu/music21/doc/moduleReference/moduleInstrument.html?highlight=bestname#music21.instrument.Instrument.bestName – Alex Dec 09 '16 at 09:33
0

The SMF format has no restrictions on how events are organized into tracks. It is common to have one track per channel, but it's also possible to have multiple channels in one track, or multiple tracks with events for the same channel.

The organization of the tracks is entirely determined by humans. It is unlikely that you can write code that can correctly determine how some random brain works.

All you have to go on are conventions (e.g., melody is likely to be in the first track(s), or has a certain structure), but you have to know if these conventions are actually used in the files you're handling.

CL.
  • 173,858
  • 17
  • 217
  • 259
0

Instead of using .bestName(), I found .partName very useful for finding the correct melody. The documentation can be found here: http://web.mit.edu/music21/doc/moduleReference/moduleStream.html#part

And here is how I used it:

midi_data = converter.parse(data_fn) #data_fn is the path to the .mid file I use
for part in midi_data.parts:
    print(part.partName)
Eric
  • 6,563
  • 5
  • 42
  • 66
Brian Sunbury
  • 45
  • 2
  • 9