How to use the music21.pitch.Pitch 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 / tablature.py View on Github external
def __init__(self, fretNotes=None, displayFrets=4):
        numStrings=4
        super(MandolinFretBoard, self).__init__(numStrings, fretNotes, displayFrets)
        
        self.tuning= [pitch.Pitch('G3'), pitch.Pitch('D4'), pitch.Pitch('A4'), pitch.Pitch('E5')]
#-------------------------------------------------------------------------------
github cuthbertLab / music21 / music21 / graph / plots_old.py View on Github external
def ticksPitchSpaceOctave(self, pitchMin=36, pitchMax=100):
        '''
        Utility method to get ticks in pitch space only for every octave.

        >>> s = stream.Stream()
        >>> a = graph.plots.PlotStream(s)
        >>> a.ticksPitchSpaceOctave()
        [[36, 'C2'], [48, 'C3'], [60, 'C4'], [72, 'C5'], [84, 'C6'], [96, 'C7']]
        '''
        ticks = []
        cVals = range(pitchMin, pitchMax, 12)
        for i in cVals:
            p = pitch.Pitch(ps=i)
            ticks.append([i, '%s' % (p.nameWithOctave)])
        ticks = self.makePitchLabelsUnicode(ticks)
        return ticks
github cuthbertLab / music21 / music21 / noteworthy / translate.py View on Github external
54.0
        '''
        accidental = ""
        if pos[0] in ['n', 'b', '#', 'x', 'v']:
            accidental = pos[0]
            pos = pos[1:]
            if accidental == 'b':
                accidental  = '-'
            elif accidental  == 'x':
                accidental = '##'
            elif accidental  == 'v':
                accidental = "--"
        positionNote = int(pos)
        (noteStep, octave) = self.getStepAndOctaveFromPosition(positionNote)

        p = pitch.Pitch()
        p.step = noteStep
        p.octave = octave
        pname = p.nameWithOctave

        if accidental != "":
            p.accidental = pitch.Accidental(accidental)
            self.activeAccidentals[pname] = accidental
        ## previous accidental in same bar that is still active
        elif pname in self.activeAccidentals:
            p.accidental = pitch.Accidental(self.activeAccidentals[pname])
        else:
            stepAccidental = self.currentKey.accidentalByStep(noteStep)
            if stepAccidental is not None:
                p.accidental = stepAccidental
        return p
github cuthbertLab / music21 / music21 / intervalNetwork.py View on Github external
>>> nodeKeys        
        ['terminusLow', 0, 1, 2, 3, 4, 5]
        '''

        # get first node if no node is provided
        if isinstance(nodeId, Node):
            nodeObj = nodeId
        elif nodeId is None: # assume low terminus by default
            # this is useful for appending a descending segment with an 
            # ascending segment
            nodeObj = self._getTerminusLowNodes()[0]
        else:
            nodeObj = self._nodeNameToNodes(nodeId)[0]
            
        if common.isStr(pitchReference):
            pitchReference = pitch.Pitch(pitchReference)
        else:
            pitchReference = copy.deepcopy(pitchReference)

        # must set an octave for pitch reference, even if not given
        if pitchReference.octave is None:
            pitchReference.octave = 4

        if common.isStr(minPitch):
            minPitch = pitch.Pitch(minPitch)
        if common.isStr(maxPitch):
            maxPitch = pitch.Pitch(maxPitch)
        if fillMinMaxIfNone and minPitch is None and maxPitch is None:
            #environLocal.printDebug(['_realizeDescending()', 'fillMinMaxIfNone'])
            minPitch, maxPitch = self.realizeMinMax(pitchReference, nodeObj, 
                                 alteredDegrees=alteredDegrees)
github cuthbertLab / music21 / music21 / figuredBassScale.py View on Github external
def __convertToPitch(self, pitchValue):
        '''
        Converts a pitch string to a music21 pitch, only if necessary.
        '''
        if type(pitchValue) == str:
            pitchValue = pitch.Pitch(pitchValue)
        return pitchValue
github cuthbertLab / music21 / music21 / analysis / transposition.py View on Github external
def testNormalOrderChords(self):
        pList = [pitch.Pitch('C4'), pitch.Pitch('E4'), pitch.Pitch('G#4')]
        tc = TranspositionChecker(pList)

        allNormalOrderChords = tc.getChordsOfDistinctTranspositions()

        self.assertEqual(len(allNormalOrderChords), 4)
        # self.assertEqual(lengthDistinctNormalOrders, 4)
        self.assertIsInstance(allNormalOrderChords[0], chord.Chord)
        self.assertIsInstance(allNormalOrderChords[0].pitches[0], pitch.Pitch)
        # self.assertEqual(allDistinctNormalOrders[0], [0,4,8])
github cuthbertLab / music21 / music21 / intervalNetwork.py View on Github external
else:
            nodeObj = self._nodeNameToNodes(nodeId)[0]
            
        if common.isStr(pitchReference):
            pitchReference = pitch.Pitch(pitchReference)
        else:
            pitchReference = copy.deepcopy(pitchReference)

        # must set an octave for pitch reference, even if not given
        if pitchReference.octave is None:
            pitchReference.octave = 4

        if common.isStr(minPitch):
            minPitch = pitch.Pitch(minPitch)
        if common.isStr(maxPitch):
            maxPitch = pitch.Pitch(maxPitch)
        if fillMinMaxIfNone and minPitch is None and maxPitch is None:
            #environLocal.printDebug(['_realizeDescending()', 'fillMinMaxIfNone'])
            minPitch, maxPitch = self.realizeMinMax(pitchReference, nodeObj, 
                                 alteredDegrees=alteredDegrees)

        # when the pitch reference is altered, we need to get the
        # unaltered version of this pitch. 
        pUnaltered = self._getUnalteredPitch(pitchReference, nodeObj,
                     direction=DIRECTION_DESCENDING, alteredDegrees=alteredDegrees)
        if pUnaltered is not None:
            pitchReference = pUnaltered

        # see if we can get from cache
        if self.deterministic:
            ck = self._getCacheKey(nodeObj, pitchReference, minPitch, maxPitch, 
                                   includeFirst)
github cuthbertLab / music21 / music21 / pitch.py View on Github external
('natural', True), ('sharp', False), ('sharp', True)]
        ks = key.KeySignature(3) 
        proc(pList, [], ks.alteredPitches)        
        compare(pList, result)

        # non initial scale tones with chromatic alteration
        pList = [Pitch('a3'), Pitch('c#3'), Pitch('g#3'), 
        Pitch('g3'), Pitch('c#4'), Pitch('g#4')]
        result = [(None, None), ('sharp', False), ('sharp', False), 
            ('natural', True), ('sharp', False), ('sharp', True)]
        ks = key.KeySignature(3) 
        proc(pList, [], ks.alteredPitches)        
        compare(pList, result)

        # initial scale tones with chromatic alteration, repeated tones
        pList = [Pitch('f#3'), Pitch('f3'), Pitch('f#3'), 
        Pitch('g3'), Pitch('f#4'), Pitch('f#4')]
        result = [('sharp', False), ('natural', True), ('sharp', True), 
            (None, None), ('sharp', False), ('sharp', False)]
        ks = key.KeySignature(1) 
        proc(pList, [], ks.alteredPitches)        
        compare(pList, result)

        # initial scale tones with chromatic alteration, repeated tones
        pList = [Pitch('d3'), Pitch('e3'), Pitch('f#3'), 
        Pitch('g3'), Pitch('f4'), Pitch('g#4'),
        Pitch('c#3'), Pitch('f#4'), Pitch('c#4')]
        result = [(None, None), (None, None), ('sharp', False), 
            (None, None), ('natural', True), ('sharp', True),
            ('sharp', False), ('sharp', True), ('sharp', False)]
        ks = key.KeySignature(2) 
        proc(pList, [], ks.alteredPitches)
github cuthbertLab / music21 / music21 / analysis / keyDetectSketch.py View on Github external
def getLikelyKeys(keyResults):
    ''' Takes in a list of probably key results in points and returns a
        list of keys in letters, sorted from most likely to least likely
    '''
    likelyKeys = [0]*12
    #keySorted = [0]*12
    a = sorted(keyResults)
    a.reverse()
    
    for i in range(len(a)):
        likelyKeys[i] = Pitch(keyResults.index(a[i]))
    
    return likelyKeys