How to use the music21.pitch.Accidental function in music21

To help you get started, we’ve selected a few music21 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cuthbertLab / music21 / music21 / demos / trecento / capua.py View on Github external
or n3.pitch.accidental is not None):
            continue

        ### never seems to improve things...
        if n2.step == "A" or n2.step == "D":
            continue

        # e.g., D B A => D Bb A
        if i1.directedName  == "m-3" and i2.directedName  == "M-2":
            numChanged += 1
            if ("capua" in n2.editorial.misc):
                n2.editorial.misc['capua_rule_number'] += RULE_FOUR_A
            else:
                n2.editorial.misc['capua_rule_number'] = RULE_FOUR_A
            n2.editorial.ficta = pitch.Accidental("flat")
            n2.editorial.misc["capua-ficta"] = pitch.Accidental("flat")
            n1.style.color = "orange"
            n2.style.color = "ForestGreen"
            n3.style.color = "orange"

    return numChanged
github cuthbertLab / music21 / music21 / volpiano.py View on Github external
n.stemDirection = 'noStem'

            if token in normalPitches:
                distanceFromLowestLine = normalPitches.index(token) - 5
                n.editorial.misc['liquescence'] = False
            else:
                distanceFromLowestLine = liquscentPitches.index(token) - 5
                n.notehead = 'x'
                n.editorial.misc['liquescence'] = True

            clefLowestLine = lastClef.lowestLine
            diatonicNoteNum = clefLowestLine + distanceFromLowestLine

            n.pitch.diatonicNoteNum = diatonicNoteNum
            if n.pitch.step == 'B' and bIsFlat:
                n.pitch.accidental = pitch.Accidental('flat')
            elif n.pitch.step == 'E' and eIsFlat:
                n.pitch.accidental = pitch.Accidental('flat')

            m.append(n)

            if noteThatWouldGoInSpanner is not None:
                currentNeumeSpanner = Neume([noteThatWouldGoInSpanner, n])
                noteThatWouldGoInSpanner = None
            else:
                noteThatWouldGoInSpanner = n

        elif token in accidentalTokens:
            if token.lower() in eflatTokens and token in naturalTokens:
                eIsFlat = False
            elif token.lower() in bflatTokens and token in naturalTokens:
                bIsFlat = False
github cuthbertLab / music21 / music21 / musedata / base.py View on Github external
>>> mdr._getAccidentalObject().displayStatus == True
        True
        >>> mdr = musedata.MuseDataRecord('F#4    1        s ')
        >>> mdr._getAccidentalObject() == None
        True
        '''
        # this is not called by stage 1 
        from music21 import pitch
        if len(self.src) <= 18:
            return None

        data = self.src[18]
        acc = None
        if data == '#':
            acc = pitch.Accidental('sharp')
        elif data == 'n':
            acc = pitch.Accidental('natural')
        elif data == 'f':
            acc = pitch.Accidental('flat')
        elif data == 'x':
            acc = pitch.Accidental('double-sharp')
        elif data == 'X':
            # this is sharp sharp, cannot distinguish
            acc = pitch.Accidental('double-sharp')
        elif data == '&':
            acc = pitch.Accidental('double-flat')
        elif data == 'S':
            # natural sharp; cannot yet do
            acc = pitch.Accidental('sharp')
        elif data == 'F':
            # natural flat; cannot yet do
github cuthbertLab / music21 / music21 / roman.py View on Github external
continue
            if thisSemis == thisCorrect:
                continue

            correctedSemis = thisCorrect - thisSemis
            if correctedSemis >= 6:
                correctedSemis = -1 * (12 - correctedSemis)
            elif correctedSemis <= -6:
                correctedSemis += 12

            faultyPitch = self.getChordStep(thisChordStep)
            if faultyPitch is None:
                raise RomanException(
                    'this is very odd... should have been caught in semitonesFromChordStep')
            if faultyPitch.accidental is None:
                faultyPitch.accidental = pitch.Accidental(correctedSemis)
            else:
                acc = faultyPitch.accidental
                correctedSemis += acc.alter
                if correctedSemis >= 6:
                    correctedSemis = -1 * (12 - correctedSemis)
                elif correctedSemis <= -6:
                    correctedSemis += 12

                acc.set(correctedSemis)
github cuthbertLab / music21 / music21 / pitch.py View on Github external
octNot = []
        for char in usrStr:
            if char in [str(x) for x in range(10)]:
                octFound.append(char)
            else:
                octNot.append(char)
        usrStr = ''.join(octNot)
        octFound = ''.join(octFound)
        # we have nothing but pitch specification
        if len(usrStr) == 1 and usrStr in STEPREF.keys():
            self._step = usrStr
            self.accidental = None
        # assume everything following pitch is accidental specification
        elif len(usrStr) > 1 and usrStr[0] in STEPREF.keys():
            self._step = usrStr[0]
            self.accidental = Accidental(usrStr[1:])
        else:
            raise PitchException("Cannot make a name out of %s" % repr(usrStr))
        if octFound != '': 
            octave = int(octFound)
            self.octave = octave

        # when setting by name, we assume that the accidental intended
        self.implicitAccidental = False

        self._pitchSpaceNeedsUpdating = True
github cuthbertLab / music21-tools / trecento / capua.py View on Github external
continue

        # never seems to improve things...
        if n2.step == 'A' or n2.step == 'D':
            continue

        # e.g., E C D => E C# D
        if (i1.directedName  == 'M-3'
                and i2.directedName  == 'M2'):
            numChanged += 1
            if 'capuaRuleNumber' in n2.editorial:
                n2.editorial.capuaRuleNumber += RULE_THREE
            else:
                n2.editorial.capuaRuleNumber = RULE_THREE
            n2.editorial.ficta = pitch.Accidental('sharp')
            n2.editorial.capuaFicta = pitch.Accidental('sharp')
            n1.style.color = 'DeepPink'
            n2.style.color = 'ForestGreen'
            n3.style.color = 'DeepPink'

    return numChanged
github cuthbertLab / music21-tools / trecento / capua.py View on Github external
or n3.pitch.accidental is not None):
            continue

        # never seems to improve things...
        if n2.step == 'A' or n2.step == 'D':
            continue

        # e.g., E C D => E C# D
        if (i1.directedName  == 'M-3'
                and i2.directedName  == 'M2'):
            numChanged += 1
            if 'capuaRuleNumber' in n2.editorial:
                n2.editorial.capuaRuleNumber += RULE_THREE
            else:
                n2.editorial.capuaRuleNumber = RULE_THREE
            n2.editorial.ficta = pitch.Accidental('sharp')
            n2.editorial.capuaFicta = pitch.Accidental('sharp')
            n1.style.color = 'DeepPink'
            n2.style.color = 'ForestGreen'
            n3.style.color = 'DeepPink'

    return numChanged
github cuthbertLab / music21 / music21 / musicxml / fromMxObjects.py View on Github external
if mxAccidental is not None: # the source had wanted to show alter
            try:
                accObj = mxToAccidental(mxAccidental)
                # used to to just use acc value
                # self.accidental = Accidental(float(acc))
                # better to use accObj if possible
                p.accidental = accObj
                p.accidental.displayStatus = True
            except pitch.AccidentalException:
                # MuseScore 0.9.6 generates Accidentals with empty objects
                pass
        else:
            # here we generate an accidental object from the alter value
            # but in the source, there was not a defined accidental
            try:
                p.accidental = pitch.Accidental(float(acc))
            except pitch.AccidentalException:
                raise FromMxObjectsException('incorrect accidental %s for pitch %s' % (str(acc), p))
            p.accidental.displayStatus = False
    p.octave = int(mxPitch.get('octave'))
    return p
github cuthbertLab / music21 / music21 / demos / trecento / capua.py View on Github external
or n2.pitch.accidental is not None
                or n3.pitch.accidental is not None):
            continue

        ### never seems to improve things...
        if n2.step == "A" or n2.step == "D":
            continue

        # e.g., D B A => D Bb A
        if i1.directedName  == "m-3" and i2.directedName  == "M-2":
            numChanged += 1
            if ("capua" in n2.editorial.misc):
                n2.editorial.misc['capua_rule_number'] += RULE_FOUR_A
            else:
                n2.editorial.misc['capua_rule_number'] = RULE_FOUR_A
            n2.editorial.ficta = pitch.Accidental("flat")
            n2.editorial.misc["capua-ficta"] = pitch.Accidental("flat")
            n1.style.color = "orange"
            n2.style.color = "ForestGreen"
            n3.style.color = "orange"

    return numChanged
github cuthbertLab / music21-tools / trecento / capua.py View on Github external
# never seems to improve things...
        if n2.step == 'A' or n2.step == 'D':
            continue

        # e.g. G, F, G => G, F#, G
        if (i1.directedName == 'M-2'
                and i2.directedName == 'M2'):
            numChanged += 1
            if 'capuaRuleNumber' in n2.editorial:
                n2.editorial.capuaRuleNumber += RULE_ONE
            else:
                n2.editorial.capuaRuleNumber = RULE_ONE
            if n2.pitch.accidental is not None and n2.pitch.accidental.name == 'flat':
                n2.editorial.savedAccidental = n2.pitch.accidental
                n2.pitch.accidental = None
                n2.editorial.ficta = pitch.Accidental('natural')
                n2.editorial.capuaFicta = pitch.Accidental('natural')
                n1.style.color = 'blue'
                n2.style.color = 'forestGreen'
                n3.style.color = 'blue'
            else:
                n2.editorial.ficta = pitch.Accidental('sharp')
                n2.editorial.capuaFicta = pitch.Accidental('sharp')
                n1.style.color = 'blue'
                n2.style.color = 'ForestGreen'
                n3.style.color = 'blue'

    return numChanged