Example #1
0
    def toBasicGABC(self, useClef=None):
        '''
        returns the character representing inNote in the given clef (default = AltoClef)

        see http://home.gna.org/gregorio/gabc/ for more details.  'd' = lowest line



        >>> n = alpha.chant.GregorianNote("C4")
        >>> c = clef.AltoClef()
        >>> n.toBasicGABC(c)
        'h'

        >>> c2 = clef.SopranoClef()
        >>> n.toBasicGABC(c2)
        'd'

        '''
        inNote = self
        usedDefaultClef = False
        if useClef is None:
            useClef = clef.AltoClef()
            usedDefaultClef = True

        asciiD = 100
        asciiA = 97
        asciiM = 109

        if not hasattr(useClef, 'lowestLine'):
            raise ChantException(
                "useClef has to define the diatonicNoteNum representing the lowest line"
            )

        stepsAboveLowestLine = inNote.pitch.diatonicNoteNum - useClef.lowestLine
        asciiNote = stepsAboveLowestLine + asciiD

        if asciiNote < asciiA:
            if usedDefaultClef is True:
                raise ChantException(
                    "note is too low for the default clef (AltoClef), choose a lower one"
                )
            else:
                raise ChantException(
                    "note is too low for the clef (%s), choose a lower one" %
                    str(useClef))
        elif asciiNote > asciiM:
            if usedDefaultClef is True:
                raise ChantException(
                    "note is too high for the default clef (AltoClef), choose a higher one"
                )
            else:
                raise ChantException(
                    "note is too high for the clef (%s), choose a higher one" %
                    str(useClef))
        else:
            return six.unichr(asciiNote)  # unichr on python2; chr python3
Example #2
0
    def toBasicGABC(self, useClef=None):
        '''
        returns the character representing inNote in the given clef (default = AltoClef)

        see http://home.gna.org/gregorio/gabc/ for more details.  'd' = lowest line



        >>> n = alpha.chant.GregorianNote("C4")
        >>> c = clef.AltoClef()
        >>> n.toBasicGABC(c)
        'h'

        >>> c2 = clef.SopranoClef()
        >>> n.toBasicGABC(c2)
        'd'

        '''
        inNote = self
        usedDefaultClef = False
        if useClef is None:
            useClef = clef.AltoClef()
            usedDefaultClef = True

        asciiD = 100
        asciiA = 97
        asciiM = 109

        if not hasattr(useClef, 'lowestLine'):
            raise ChantException(
                "useClef has to define the diatonicNoteNum representing the lowest line")

        stepsAboveLowestLine = inNote.pitch.diatonicNoteNum - useClef.lowestLine
        asciiNote = stepsAboveLowestLine + asciiD

        if asciiNote < asciiA:
            if usedDefaultClef is True:
                raise ChantException(
                    "note is too low for the default clef (AltoClef), choose a lower one")
            else:
                raise ChantException(
                    "note is too low for the clef (%s), choose a lower one" % str(useClef))
        elif asciiNote > asciiM:
            if usedDefaultClef is True:
                raise ChantException(
                    "note is too high for the default clef (AltoClef), choose a higher one")
            else:
                raise ChantException(
                    "note is too high for the clef (%s), choose a higher one" % str(useClef))
        else:
            return six.unichr(asciiNote) # unichr on python2; chr python3