Reputation: 3930
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?
Upvotes: 3
Views: 2251
Reputation: 45
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)
Upvotes: 0
Reputation: 2479
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
Upvotes: 1
Reputation: 180210
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.
Upvotes: 0