How to use the music21.stream.Score 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 / composition / aug30.py View on Github external
def test():
    from music21 import instrument as j
    sc1 = stream.Score()
#    instruments = [Piccolo(), Glockenspiel(), 72, 69, 41, 27, 47, 1, 1, 1, 1, 34]
    instrument = [j.Piccolo(), j.Xylophone(), j.Clarinet(), j.Oboe(), j.Violin(),
                  j.ElectricGuitar(), j.Harp(), j.Piano(), j.Piano(), j.Piano(), j.Piano(), j.ElectricBass()]
    instrumentOctave = [3, 2, 2, 2, 1, 1, 1, 2, 1, 0, -1, -2]

    for i in range(12):
        inst = instrument[i]
        if i < 9:
            inst.midiChannel = i
        else:
            inst.midiChannel = i + 1
        part = addPart(instrument=inst)
        if instrumentOctave[i] != 0:
            part.transpose(12 * instrumentOctave[i], inPlace=True)
        sc1.insert(0, part)
    sc1.show()
github cuthbertLab / music21 / music21 / instrument.py View on Github external
from music21 import stream, note

        s1 = stream.Stream()
        i1 = Violin()
        i1.partName = 'test'
        s1.append(i1)
        s1.repeatAppend(note.Note(), 10)
        # s.show()

        s2 = stream.Stream()
        i2 = Piano()
        i2.partName = 'test2'
        s2.append(i2)
        s2.repeatAppend(note.Note('g4'), 10)

        s3 = stream.Score()
        s3.insert(0, s1)
        s3.insert(0, s2)
github cuthbertLab / music21 / music21 / vexflow / base.py View on Github external
Checks if it has parts. If so, parses like a Score.
    Otherwise, just flattens it and parses it like a Part
    
    ::

        >>> #print vexflow.fromStream(tinyNotation.TinyNotationStream('c8 d8 e-4 dd4 cc2'), mode='txt')
        >>> #print vexflow.fromStream(tinyNotation.TinyNotationStream('C8 D8 E-4 d4 c2'), mode='txt')

    '''
    if mode not in supportedDisplayModes:
        raise Vexflow21UnsupportedException, 'Unsupported mode: ' + str(mode)

    theseParts = thisStream.getElementsByClass('Part')
    if len(theseParts) == 0:
        return VexflowPart(stream.Part(thisStream.flat).makeNotation(inPlace=False)).generateCode(mode)
    return VexflowScore(stream.Score(thisStream).makeNotation(inPlace=False)).generateCode(mode)
github cuthbertLab / music21-tools / trecento / quodJactatur.py View on Github external
def prepareSolution(triplumTup, ctTup, tenorTup):
    qjSolved = stream.Score()

    for transpose, delay, invert, retro in [triplumTup, ctTup, tenorTup]:
        idString = "%d-%d-%s-%s" % (transpose, delay, invert, retro)
        if idString in cachedParts:
            qjPart = copy.deepcopy(cachedParts[idString])
        else:
            qjPart = copy.deepcopy(cachedParts["1-0-False-False"])
            if retro is True:
                qjPart = reverse(qjPart, makeNotation = False)
            if invert is True:
                qjPart.invertDiatonic(qjPart.flat.notesAndRests[0], inPlace=True)
            if transpose != 1:
                transposeStreamDiatonic(qjPart, transpose)
            if delay > 0:
                qjPart = prependBlankMeasures(qjPart, delay)
            cachedParts[idString] = copy.deepcopy(qjPart)
github cuthbertLab / music21 / music21 / figuredBass / realizer2.py View on Github external
def generateSolutionFromChordProgression(self, chordProgression):
        '''
        Generates a solution as a stream.Score() given a chord progression
        
        bass line is taken from the figured bass object, but is checked against
        the chord progression for consistency.
        '''
        sol = stream.Score()
        rightHand = stream.Part()
        rightHand.insert(0, copy.copy(self.ts))
        rightHand.insert(0, copy.copy(self.ks))

        v0 = self.fbInfo.fbVoices[0]
        
        for j in range(len(chordProgression)):
            givenPossib = chordProgression[j]
            bassNote = self.bassNotes[j]

            if givenPossib[v0.label] != bassNote.pitch:
                raise FiguredBassException("Chord progression possibility doesn't match up with bass line.")
        
            rhPitches = []
            for k in range(1, len(self.fbInfo.fbVoices)):
                v1 = self.fbInfo.fbVoices[k]
github cuthbertLab / music21 / music21 / figuredBass / examples.py View on Github external
boogieBassLine = converter.parse("tinynotation: BB-8. D16 F8. G16 A-8. G16 F8. D16",
                                     makeNotation=False)

    newBassLine = stream.Part()
    newBassLine.append(sampleScore[1][0]) #Time signature
    newBassLine.append(sampleScore[1][1]) #Key signature

    for n in sampleScore[1].notes:
        i = interval.notesToInterval(boogieBassLine[0], n)
        tp = boogieBassLine.transpose(i)
        for lyr in n.lyrics:
            tp.notes[0].addLyric(lyr.text)
        for m in tp.notes:
            newBassLine.append(m)

    newScore = stream.Score()
    newScore.insert(0, sampleScore[0])
    newScore.insert(newBassLine)

    return newScore
github cuthbertLab / music21 / music21 / instrument.py View on Github external
def testPartitionByInstrumentA(self):
        from music21 import instrument, stream

        # basic case of instruments in Parts
        s = stream.Score()
        p1 = stream.Part()
        p1.append(instrument.Piano())

        p2 = stream.Part()
        p2.append(instrument.Piccolo())
        s.insert(0, p1)
        s.insert(0, p2)

        post = instrument.partitionByInstrument(s)
        self.assertEqual(len(post), 2)
        self.assertEqual(len(post.flat.getElementsByClass('Instrument')), 2)

        # post.show('t')

        # one Stream with multiple instruments
        s = stream.Stream()
github cuthbertLab / music21 / music21 / figuredBass / realizer2.py View on Github external
def generateAllSolutions(self):
        allSols = stream.Score()
        
        chordProgressions = self.getAllChordProgressions()
        for chordProgression in chordProgressions:
            sol = self.generateSolutionFromChordProgression(chordProgression)
            allSols.append(sol)
        
        return allSols
github cuthbertLab / music21 / music21 / demos / bhadley / hack.py View on Github external
for k in o.pitches:
                boolist.append(str(k.name))
            print foolist
            print boolist
            if foolist != boolist:
                chord2.lyric = "INVERSION"
            else:
                numCorrect = numCorrect + 1
                chord2.lyric = ":)"
        if isCorrect == False:
            chord2.lyric = "PITCHES"

    percentCorrect =  float(numCorrect)/float(totalNumChords) * 100
    s = music21piece2.getElementsByClass(music21.stream.PartStaff)[1]
    s.insert(0, music21.clef.BassClef())
    newScore = music21.stream.Score()
    newScore.append(music21piece2.getElementsByClass(music21.stream.PartStaff)[0])
    newScore.append(s)
   
    return (newScore, percentCorrect) #student's corrected score
github cuthbertLab / music21-tools / bhadley / harmonyRealizer.py View on Github external
and the current bass note, all using the previous bass note's newly defined
           octave and one of three current bass note octaves:
            1. the last bass note's octave
            2. the last bass note's octave + 1
            3. the last bass note's octave - 1
        ii. evaluates the size of each of the three intervals above
            (using interval.generic.undirected)
            and finds the smallest size
        iii. assigns the bass note octave that yields
             this smallest interval to the current bass note
             - if the newly found octave is determined to be greater than 3 or less than 1, the
               bass note octave is assigned to the last bass note's octave
        iv. updates the previous bass note, and the iteration continues
    3. returns list of chordSymbols, with computer generated octaves assigned
    '''
    s = stream.Score()
    s.append(clef.BassClef())
    harmonyObjects[0].bass().octave = 2
    lastBass = harmonyObjects[0].bass()
    s.append(note.Note(lastBass))
    for cs in harmonyObjects[1:]:
        cs.bass().octave = lastBass.octave
        sameOctave = interval.Interval(lastBass, copy.deepcopy(cs.bass()))
        cs.bass().octave += 1
        octavePlus = interval.Interval(lastBass, copy.deepcopy(cs.bass()))
        cs.bass().octave = cs.bass().octave - 2
        octaveMinus = interval.Interval(lastBass, copy.deepcopy(cs.bass()))
        l = [sameOctave, octavePlus, octaveMinus]
        minimum = sameOctave.generic.undirected
        ret = sameOctave
        for i in l:
            if i.generic.undirected < minimum: