Search code examples
pythonmusic21

music21 --> stream.chordify() not working


total newbie with music21 here.

I'm trying to use chordify(): http://web.mit.edu/music21/doc/usersGuide/usersGuide_09_chordify.html

How do you obtain a stream object (on which you can call chordify()) from a midi file?

I tried two approaches:

1:

s = converter.parse(fn)
for el in s.recurse():
    print '\n'
    if 'Stream' in el.classes:
        el.chordify() # NOT WORKING! throws error.
    if 'Score' in el.classes:
        el.chordify() # NOT WORKING EITHER! also throws error.

2:

stream = c.parseFile(fn, format='.mid')
print stream # NOTHING! stream is None

Thanks in advance for telling me how I can get that stream object on which to call chordify(), from my midi file.


Solution

  • Your first answer was on the right track. After running

    s = converter.parse(fn)
    

    do

    s2 = s.chordify()
    

    Then you can call s2.show() or whatever you want.