cuthbertLab / music21

music21 is a Toolkit for Computational Musicology
https://www.music21.org/
Other
2.12k stars 402 forks source link

Get chordify() to do something with Unpitched #1182

Open jacobtylerwalls opened 2 years ago

jacobtylerwalls commented 2 years ago

Motivation chordify() silently drops Unpitched objects in a stream, including Notes mixed in with PercussionChords.

Feature summary Need to create PercussionChord instances when Unpitched instances are in the mix instead of just dropping them.

Example

>>> s = stream.Stream()
>>> pc = percussion.PercussionChord([note.Unpitched(), note.Note()])
>>> s.append(pc)
>>> c = s.chordify()
>>> c.show()
Screen Shot 2021-12-04 at 8 15 39 PM

Intent

[?] I plan on implementing this myself. [ ] I am willing to pay to have this feature added. [x] I am starting a discussion with the hope that community members will volunteer their time to create this. I understand that individuals work on features of interest to them and that this feature may never be implemented.

adhason commented 2 years ago

I was looking at this, and I was wondering why there is a quarter rest and then a dotted half rest. May I know why that occurs?

jacobtylerwalls commented 2 years ago

Why a rest at all or why not quarter + half? The former: musicxml export attempts to produce complete measures. This can be avoided with setting paddingRight to specify incomplete measures or exporting with makeNotation=False etc

jacobtylerwalls commented 2 years ago

Didn't mean to be short; was on mobile. Regarding why not quarter + half, there is a feature request #992 for splitting larger values according to the meter. Wasn't sure if that's what you meant. Any help or testcases for the original issue, getting chordify() to be compatible with the percussion classes, is of course welcome.

adhason commented 2 years ago

Oh, no worries. I was evaluating if I had the knowledge to actually implement this. I don't think I can really help at this time, but I appreciate your explanations!

adityac95 commented 2 years ago

Hi, I've been trying to use chordify() on a passage that has Unpitched and PercussionChord objects. I want chordify to ignore them, but every time I run it, it throws an error:

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/music21/tree/verticality.py:809, in Verticality.makeElement.<locals>.conditionalAdd(ts, n)
    802 '''
    803 Add an element only if it is not already in the chord.
    804 
    805 If it has more tie information than the previously
    806 added note, then remove the previously added note and add it
    807 '''
    808 nonlocal pitchBust  # love Py3!!!
--> 809 p = n.pitch
    810 pitchKey = p.nameWithOctave
    812 pitchGroup = None

AttributeError: 'Unpitched' object has no attribute 'pitch'

How can I ignore them without changing the original music I want to chordify?