Esempio n. 1
0
    def createClef(self, attributes):
        r'''
        Add a new clef to the current measure and return the currentClef.
        
        
        Clef lines should look like: \|Clef\|Type:ClefType  or
        \|Clef\|Type:ClefType\|OctaveShift:Octave Down (or Up)
               
         
        
        >>> nwt = noteworthy.translate.NoteworthyTranslator()
        >>> nwt.currentMeasure = stream.Measure()
        >>> nwt.createClef({"Type": "Treble"})
        >>> nwt.currentMeasure.show('text')
        {0.0} <music21.clef.TrebleClef>      
        >>> nwt.currentClef
        'TREBLE'
        >>> nwt.createClef({"Type" : "Bass", "OctaveShift" : "Octave Down"})
        >>> nwt.currentMeasure.show('text')
        {0.0} <music21.clef.TrebleClef>      
        {0.0} <music21.clef.Bass8vbClef>      
        
        
        
    
        If no clef can be found then it raises a NoteworthyTranslate exception
    
    
        >>> nwt.createClef({"Type" : "OBonobo"})
        Traceback (most recent call last):
        NoteworthyTranslateException: Did not find a proper clef in type, OBonobo
    
        '''  
        currentClef = None
        if 'OctaveShift' in attributes:
            if attributes['OctaveShift'] == 'Octave Down':
                octaveShift = -1
            elif attributes['OctaveShift'] == 'Octave Up':
                octaveShift = 1
            else:
                raise NoteworthyTranslateException(
                    'Did not get a proper octave shift from %s' % attributes[3])
        else:
            octaveShift = 0
 
        cl = attributes['Type']   
        if cl == "Treble":
            if octaveShift == 0: 
                self.currentMeasure.append(clef.TrebleClef())
                currentClef = "TREBLE"
            elif octaveShift == -1:
                self.currentMeasure.append(clef.Treble8vbClef())
                currentClef = "TREBLE8dw"
            elif octaveShift == 1:
                self.currentMeasure.append(clef.Treble8vaClef())
                currentClef = "TREBLE8up"                   
                    
        elif cl == "Bass":
            if octaveShift == 0: 
                self.currentMeasure.append(clef.BassClef())
                currentClef = "BASS"
            elif octaveShift == -1:
                self.currentMeasure.append(clef.Bass8vbClef())
                currentClef = "BASS8dw"
            elif octaveShift == 1:
                self.currentMeasure.append(clef.Bass8vaClef())
                currentClef = "BASS8up"                   
    
        elif cl == "Alto":
            if octaveShift != 0: 
                raise NoteworthyTranslateException('cannot shift octaves on an alto clef')
            self.currentMeasure.append(clef.AltoClef())
            currentClef = "ALTO" 
        elif cl == "Tenor":
            if octaveShift != 0: 
                raise NoteworthyTranslateException('cannot shift octaves on a tenor clef')
            self.currentMeasure.append(clef.TenorClef())
            currentClef = "TENOR" 
        if currentClef is None:
            raise NoteworthyTranslateException('Did not find a proper clef in type, %s' % cl)
        self.currentClef = currentClef
Esempio n. 2
0
def pendulumMusic(show = True, 
                  loopLength = 160.0, 
                  totalLoops = 1, 
                  maxNotesPerLoop = 40,
                  totalParts = 16,
                  scaleStepSize = 3,
                  scaleType = scale.OctatonicScale,
                  startingPitch = 'C1'
                  ):    
    totalLoops = totalLoops * 1.01
    jMax = loopLength * totalLoops
    
    
    p = pitch.Pitch(startingPitch)
    if isinstance(scaleType, scale.Scale):
        octo = scaleType
    else:
        octo = scaleType(p)
    s = stream.Score()
    s.metadata = metadata.Metadata()
    s.metadata.title = 'Pendulum Waves'
    s.metadata.composer = 'inspired by http://www.youtube.com/watch?v=yVkdfJ9PkRQ'
    parts = [stream.Part(), stream.Part(), stream.Part(), stream.Part()]
    parts[0].insert(0, clef.Treble8vaClef())
    parts[1].insert(0, clef.TrebleClef())
    parts[2].insert(0, clef.BassClef())
    parts[3].insert(0, clef.Bass8vbClef())
    for i in range(totalParts):
        j = 1.0
        while j < (jMax+1.0):
            ps = p.ps
            if ps > 84:
                active = 0
            elif ps >= 60:
                active = 1
            elif ps >= 36:
                active = 2
            elif ps < 36:
                active = 3
            
            jQuant = round(j*8)/8.0

            establishedChords = parts[active].getElementsByOffset(jQuant)
            if len(establishedChords) == 0:
                c = chord.Chord([p])
                c.duration.type = '32nd'
                parts[active].insert(jQuant, c)
            else:
                c = establishedChords[0]
                pitches = c.pitches
                pitches.append(p)
                c.pitches = pitches
            j += loopLength/(maxNotesPerLoop - totalParts + i)
            #j += (8+(8-i))/8.0
        p = octo.next(p, stepSize = scaleStepSize)
            

    parts[0].insert(0, tempo.MetronomeMark(number = 120, referent = duration.Duration(2.0)))
    for i in range(4):
        parts[i].insert(int((jMax + 4.0)/4)*4, note.Rest(quarterLength=4.0))
        parts[i].makeRests(fillGaps=True, inPlace=True)
        parts[i] = parts[i].makeNotation()
        s.insert(0, parts[i])
    
    if show == True:
        #s.show('text')
        s.show('midi')
        s.show()
Esempio n. 3
0
 def test_clef_to_lily_2(self):
     bee_ell = clef.Treble8vaClef()
     expected = u"\\clef \"treble^8\"\n"
     self.assertEqual(functions.clef_to_lily(bee_ell), expected)
Esempio n. 4
0
    def createClef(self, attributes):
        r'''
        Add a new clef to the current measure and return the currentClef.


        Clef lines should look like: \|Clef\|Type:ClefType  or
        \|Clef\|Type:ClefType\|OctaveShift:Octave Down (or Up)



        >>> nwt = noteworthy.translate.NoteworthyTranslator()
        >>> nwt.currentMeasure = stream.Measure()
        >>> nwt.createClef({'Type': 'Treble'})
        >>> nwt.currentMeasure.show('text')
        {0.0} <music21.clef.TrebleClef>
        >>> nwt.currentClef
        'TREBLE'
        >>> nwt.createClef({'Type' : 'Bass', 'OctaveShift' : 'Octave Down'})
        >>> nwt.currentMeasure.show('text')
        {0.0} <music21.clef.TrebleClef>
        {0.0} <music21.clef.Bass8vbClef>




        If no clef can be found then it raises a NoteworthyTranslate exception


        >>> nwt.createClef({'Type' : 'OrangeClef'})
        Traceback (most recent call last):
        music21.noteworthy.translate.NoteworthyTranslateException: Did
            not find a proper clef in type, OrangeClef

        '''
        currentClef = None
        if 'OctaveShift' in attributes:
            if attributes['OctaveShift'] == 'Octave Down':
                octaveShift = -1
            elif attributes['OctaveShift'] == 'Octave Up':
                octaveShift = 1
            else:
                raise NoteworthyTranslateException(
                    f'Did not get a proper octave shift from {attributes[3]}')
        else:
            octaveShift = 0

        cl = attributes['Type']
        if cl == 'Treble':
            if octaveShift == 0:
                self.currentMeasure.append(clef.TrebleClef())
                currentClef = 'TREBLE'
            elif octaveShift == -1:
                self.currentMeasure.append(clef.Treble8vbClef())
                currentClef = 'TREBLE8dw'
            elif octaveShift == 1:
                self.currentMeasure.append(clef.Treble8vaClef())
                currentClef = 'TREBLE8up'

        elif cl == 'Bass':
            if octaveShift == 0:
                self.currentMeasure.append(clef.BassClef())
                currentClef = 'BASS'
            elif octaveShift == -1:
                self.currentMeasure.append(clef.Bass8vbClef())
                currentClef = 'BASS8dw'
            elif octaveShift == 1:
                self.currentMeasure.append(clef.Bass8vaClef())
                currentClef = 'BASS8up'

        elif cl == 'Alto':
            if octaveShift != 0:
                raise NoteworthyTranslateException(
                    'cannot shift octaves on an alto clef')
            self.currentMeasure.append(clef.AltoClef())
            currentClef = 'ALTO'
        elif cl == 'Tenor':
            if octaveShift != 0:
                raise NoteworthyTranslateException(
                    'cannot shift octaves on a tenor clef')
            self.currentMeasure.append(clef.TenorClef())
            currentClef = 'TENOR'
        if currentClef is None:
            raise NoteworthyTranslateException(
                f'Did not find a proper clef in type, {cl}')
        self.currentClef = currentClef