How to use the music21.note 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 / mei / test_base.py View on Github external
def testTuplets10(self):
        '''
        _postGuessTuplets(): integration test that a single-part Score with one triplet is guessed
        '''
        # setup the Voice with tuplets
        theVoice = stream.Voice()
        for _ in range(3):
            eachNote = note.Note('D-5', quarterLength=0.5)
            theVoice.append(eachNote)
        theVoice[0].m21TupletSearch = 'start'
        theVoice[0].m21TupletNum = '3'
        theVoice[0].m21TupletNumbase = '2'
        theVoice[2].m21TupletSearch = 'stop'
        theVoice[2].m21TupletNum = '3'
        theVoice[2].m21TupletNumbase = '2'
        # setup the Score->Part->Measure->Voice hierarchy
        theMeasure = stream.Measure([theVoice])
        thePart = stream.Part([theMeasure])
        theScore = stream.Score(givenElements=[thePart])
        # make the expected values
        expectedOffsets = [0.0, Fraction(1, 3), Fraction(2, 3)]

        actual = base._postGuessTuplets(theScore)
github cuthbertLab / music21 / music21 / demos / music21Theory.py View on Github external
def labelEditorialMotion(music21Stream):
    '''Generates intervalList and intervalORList.'''

    for part in music21Stream.parts:
        notes = part.flat.notes
        currentObject = notes[1]
        notes[0].editorial.misc['motion'] = None
        while currentObject != None and not isinstance(currentObject, music21.bar.Barline):
            previousObject = currentObject.previous()
            if isinstance(currentObject, music21.note.Note) and isinstance(previousObject, music21.note.Note):
                thisInterval = interval.Interval(previousObject, currentObject)
                if thisInterval.generic.isDiatonicStep:
                    currentObject.editorial.misc['motion'] = 'step'
                elif thisInterval.generic.isSkip:
                    currentObject.editorial.misc['motion'] = 'skip'
                else:
                    currentObject.editorial.misc['motion'] = 'unison'
                currentObject.lyric = currentObject.editorial.misc['motion']
            else:
                currentObject.editorial.misc['motion'] = None
            currentObject = currentObject.next()
        

    for noteObj in music21Stream.flat.getElementsByClass('Note'):
        print noteObj
        try:
github cuthbertLab / music21 / music21 / musedata / translate.py View on Github external
def _musedataRecordListToNoteOrChord(records, previousElement=None):
    '''Given a list of MuseDataRecord objects, return a configured
    :class:`~music21.note.Note` or :class:`~music21.chord.Chord`.

    Optionally pass a previous element, which may be music21 Note, Chord, or Rest;
    this is used to determine tie status
    '''
    from music21 import note
    from music21 import chord
    from music21 import tie

    if len(records) == 1:
        post = note.Note()
        # directly assign pitch object; will already have accidental
        post.pitch = records[0].getPitchObject()
    else:
        # environLocal.printDebug(['attempting chord creation: records', len(records)])
        # can supply a lost of Pitch objects at creation
        post = chord.Chord([r.getPitchObject() for r in records])

    # if a chord, we are assume that all durations are the same
    post.quarterLength = records[0].getQuarterLength()

    # see if there are nay lyrics; not sure what to do if lyrics are defined
    # for multiple chord tones
    lyricList = records[0].getLyrics()
    if lyricList is not None:
        # cyclically calling addLyric will auto increment lyric number assigned
        for lyric in lyricList:
github cuthbertLab / music21 / music21 / demos / mgtaPart1.py View on Github external
def ch1_basic_I_A(show=True, *arguments, **keywords):
    '''
    p2.
    For a given pitch name, give two possible enharmonic equivalents with
    octave designation
    '''
    pitches = ['d#3', 'g3', 'g#3', 'c#4', 'd4', 'a4', 'a#4', 'e5', 'f#5', 'a5']
    found = []
    for p in pitches:
        unused_n = note.Note(p)

        # get direction of enharmonic move?
        # a move upward goes from f to g-, then a---
        #n.pitch.getEnharmonic(1)
        found.append(None)
    if show:
        for i in range(len(pitches)):
            print(str(pitches[i]).ljust(10) + str(found[i]))
github cuthbertLab / music21 / music21 / noteworthy / translate.py View on Github external
>>> nwt.translateNote({'Dur': 'Half', 'Pos': '#-3'})
        >>> measure[0]
        

        Note that the next note in the measure with the same position should
        inherit the last position's accidental:

        >>> nwt.translateNote({'Dur': 'Half', 'Pos': '-3'})
        >>> measure[1]
        

        '''
        durationInfo = attributes['Dur']
        pitchInfo = attributes['Pos']

        n = note.Note()   # note!

        # durationInfo
        self.setDurationForObject(n, durationInfo)

        ## pitchInfo
        self.setTieFromPitchInfo(n, pitchInfo)
        n.pitch = self.getPitchFromPositionInfo(pitchInfo)

        # if Lyrics
        if self.lyrics and self.lyricPosition < len(self.lyrics):
            n.addLyric(self.lyrics[self.lyricPosition])

        self.currentMeasure.append(n)
github cuthbertLab / music21 / music21 / tempo.py View on Github external
def testSetup(self):
        mm1 = MetronomeMark(number=60, referent=note.Note(type='quarter'))
        self.assertEqual(mm1.number, 60)

        tm1 = TempoText('Lebhaft')
        self.assertEqual(tm1.text, 'Lebhaft')
github cuthbertLab / music21 / music21 / figuredBass / realizer.py View on Github external
def generateRealizationFromPossibilityProgression(self, possibilityProgression):
        '''
        Generates a realization as a :class:`~music21.stream.Score` given a possibility progression.
        '''
        sol = stream.Score()

        bassLine = stream.Part()
        bassLine.append([copy.deepcopy(self._keySig), copy.deepcopy(self._inTime)])
        r = None
        if self._paddingLeft != 0.0:
            r = note.Rest(quarterLength=self._paddingLeft)
            bassLine.append(copy.deepcopy(r))

        if self.keyboardStyleOutput:
            rightHand = stream.Part()
            sol.insert(0.0, rightHand)
            rightHand.append([copy.deepcopy(self._keySig), copy.deepcopy(self._inTime)])
            if r is not None:
                rightHand.append(copy.deepcopy(r))

            for segmentIndex in range(len(self._segmentList)):
                possibA = possibilityProgression[segmentIndex]
                bassNote = self._segmentList[segmentIndex].bassNote
                bassLine.append(copy.deepcopy(bassNote))
                rhPitches = possibA[0:-1]
                rhChord = chord.Chord(rhPitches)
                rhChord.quarterLength = self._segmentList[segmentIndex].quarterLength
github cuthbertLab / music21-tools / chant / chant.py View on Github external
def testSimpleFile(self):
        s = GregorianStream()
        s.append(clef.AltoClef())

        n = GregorianNote("C4")
        l = note.Lyric("Po")
        l.syllabic = "start"
        n.lyrics.append(l)
        n.oriscus = True
        s.append(n)
        n2 = GregorianNote("D4")
        s.append(n2)
        n3 = GregorianNote("C4")
        n3.stropha = True
        s.append(n3)
        n4 = GregorianNote("B3")
        n4.stropha = True
        s.append(n4)

        gabcText = s.toGABCText()
        bsc = BaseScoreConverter()
        bsc.score = gabcText
github cuthbertLab / music21 / music21 / variant.py View on Github external
def testDeepCopyVariantA(self):
        s = stream.Stream()
        s.repeatAppend(note.Note('G4'), 8)
        vn1 = note.Note('F#4')
        vn2 = note.Note('A-4')

        v1 = Variant([vn1, vn2])
        v1Copy = copy.deepcopy(v1)
        # copies stored objects; they point to the different Notes vn1/vn2
        self.assertIsNot(v1Copy[0], v1[0])
        self.assertIsNot(v1Copy[1], v1[1])
        self.assertIs(v1[0], vn1)
        self.assertIsNot(v1Copy[0], vn1)

        # normal in-place variant functionality
        s.insert(5, v1)
        self.assertEqual(self.pitchOut([p for p in s.pitches]),
            '[G4, G4, G4, G4, G4, G4, G4, G4]')
        sv = s.activateVariants(inPlace=False)
        self.assertEqual(self.pitchOut([p for p in sv.pitches]),
github cuthbertLab / music21 / music21 / demos / bhadley / harmonyRealizer.py View on Github external
def mergeLeadSheetAndBassLine(leadsheet, bassLine):
    '''
    method to combine the lead sheet with just the melody line
    and chord symbols with the newly realized bassLine (i.e. from fbRealizer) which
    consists of two parts, the treble line and bass line.
    '''
    s = stream.Score()

    s.insert(metadata.Metadata())
    s.metadata.title = leadsheet.metadata.title
    cs = leadsheet.flat.getElementsByClass(harmony.ChordSymbol)
    if cs[0].offset > 0:
        bassLine.parts[0].insertAndShift(0, note.Rest(quarterLength=cs[0].offset))
        bassLine.parts[1].insertAndShift(0, note.Rest(quarterLength=cs[0].offset))
    voicePart = leadsheet.parts[0]
    pianoTreble = bassLine.parts[0]
    pianoBass = bassLine.parts[1]
    s.insert(0, voicePart)
    s.insert(0, pianoTreble)
    s.insert(0, pianoBass)

    return s
#-------------------------------------------------------------------------------