You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my application I create a musicxml from another token language that only states visible accidentals. For that reason, I rely on keySignature.getAccidentalByStep() to get the accidental of the key if no accidental was stated and there is no prior accidental in the measure for that step+octave.
This works fine except that music21 seems to add redundant naturals like in this example where the D5 gets a natural (because prior measure contained D#4). Even setting the accidental to None does not help. How to stop this auto creation of redundant naturals?
from music21 import *
score = stream.Score()
part = stream.Part()
score.append(part)
measure = stream.Measure()
part.append(measure)
keyS = key.KeySignature(1)
measure.append(keyS)
n = note.Note('D#4')
measure.append(n)
n2 = note.Note()
n2.step = 'F'
n2.octave = 4
# if acc is explicitly stated: use it
# elif (n2.step, n2.octave) in measureAcc.keys(): use value of dictionary
# else:
n2.pitch.accidental = keyS.accidentalByStep(n2.step)
measure.append(n2)
measure = stream.Measure()
part.append(measure)
measure.append(keyS)
n = note.Note('D5')
n.pitch.accidental = keyS.accidentalByStep(n.step)
#n.pitch.accidental = None # no effect
measure.append(n)
score.show()
The text was updated successfully, but these errors were encountered:
Hi @Daniel63656. You'll want to get familiar with music21's displayType attribute on Accidental objects. If you don't set the displayType yourself, you're delegating to music21's makeAccidentals() method, called with default arguments, one of which (cautionaryPitchClass=True) is creating the natural you don't want.
or, call makeAccidentals() with the specific arguments you want, e.g. cautionaryPitchClass=False
or, and possibly additionally if you find it necessary, call .show(makeNotation=False) so that you opt-out of the methods that clean up notation. (This last option is for power users who aren't depending on music21 cleaning up fine details of rests/bars/tuplet brackets etc)
In my application I create a musicxml from another token language that only states visible accidentals. For that reason, I rely on keySignature.getAccidentalByStep() to get the accidental of the key if no accidental was stated and there is no prior accidental in the measure for that step+octave.
This works fine except that music21 seems to add redundant naturals like in this example where the D5 gets a natural (because prior measure contained D#4). Even setting the accidental to None does not help. How to stop this auto creation of redundant naturals?
The text was updated successfully, but these errors were encountered: