Exemplo 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):
        music21.noteworthy.translate.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
Exemplo n.º 2
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