Exemplo n.º 1
0
    def getQuarterLength(self):
        '''determine the length in quarter notes from current information'''

        if (self.__qtrLength):
            return self.__qtrLength

        if (self.typeToDuration.has_key(self.type)):
            durationFromType = self.typeToDuration[self.type]
        else:
            raise KeyError, "No key in typeToDuration for " + self.type

        if (durationFromType == 0):
            raise ("Error: no correct Duration for " + self.type)
        qtrLength = 0.0
        qtrLength = durationFromType * common.dotMultiplier(self.dots)

        ###
        if (len(self.dotGroups) > 0):
            for thisDot in self.dotGroups:
                qtrLength *= common.dotMultiplier(thisDot)

        if (len(self.tuplets) > 0):
            for thisTuplet in self.tuplets:
                qtrLength *= thisTuplet.tupletMultiplier()

        return qtrLength
Exemplo n.º 2
0
    def getQuarterLength(self):
        '''determine the length in quarter notes from current information'''

        if (self.__qtrLength):
            return self.__qtrLength
        
        if (self.typeToDuration.has_key(self.type)):
            durationFromType = self.typeToDuration[self.type]
        else:
            raise KeyError, "No key in typeToDuration for " + self.type

        if (durationFromType == 0):
            raise ("Error: no correct Duration for " + self.type)
        qtrLength = 0.0
        qtrLength = durationFromType * common.dotMultiplier(self.dots)

        ###
        if (len(self.dotGroups) > 0):
            for thisDot in self.dotGroups:
                qtrLength *= common.dotMultiplier(thisDot)

        if (len(self.tuplets) > 0):
            for thisTuplet in self.tuplets:
                qtrLength *= thisTuplet.tupletMultiplier()

        return qtrLength
Exemplo n.º 3
0
    def setDurationFromQtrLength(self, qL):
        ### rewrite using common.decimalToTuplet

        noDotQL = qL * (2.0/3)
        # JR  -- assumes dots are of 14th-cent. nested form:
        # MSC -- Do not assume that.  Or if they are, set:
        #        note.duration.dots = 1
        #        note.duration.dotGroups = [1]
        # test double dots with qL * 
        noDotQL2 = noDotQL * (2.0/3)

        ## look for functions already defined and reuse them
        noDblDotQL = qL / common.dotMultiplier(2.0)
        noTrpDotQL = qL / common.dotMultiplier(3.0)
        # etc...

        ## clear old data
        self.type = ""
        self.dots = 0
        self.dotGroups = []
        self.tuplets = []
        
        if (common.isPowerOfTwo(qL)):
            tempType = self.getTypeFromQtrLength(qL)
            if (tempType): self.type = tempType
            else: raise DurationException("couldnt get type from Power of Two: %f" % qL)

        elif (common.isPowerOfTwo(noDotQL)):
            self.dots = 1
            tempType = self.getTypeFromQtrLength(noDotQL)
            if (tempType): self.type = tempType
            else: raise DurationException

        elif (common.isPowerOfTwo(noDblDotQL)):
            self.dots = 2
            tempType = self.getTypeFromQtrLength(noDblDotQL)
            if (tempType): self.type = tempType
            else: raise DurationException
            
        elif (common.isPowerOfTwo(noTrpDotQL)):
            self.dots = 3
            tempType = self.getTypeFromQtrLength(noTrpDotQL)
            if (tempType): self.type = tempType
            else: raise DurationException

            ## add code for 4 dots...

        elif (common.isPowerOfTwo(noDotQL2)):  # medieval dotted dotted notes
            self.dots = 1
            self.dotGroups = [1]
            tempType = self.getTypeFromQtrLength(noDotQL2)
            if (tempType): self.type = tempType
            else: raise DurationException

        #(check for simple tuplets, but don't spend too much time on it
        #python2.6 will have a Fraction class which will make finding the
        #closest tuplet representation much easier)

        else: raise DurationException("couldnt get type from Length: %f" % qL)
Exemplo n.º 4
0
    def setDurationFromQtrLength(self, qL):
        ### rewrite using common.decimalToTuplet

        noDotQL = qL * (2.0 / 3)
        # JR  -- assumes dots are of 14th-cent. nested form:
        # MSC -- Do not assume that.  Or if they are, set:
        #        note.duration.dots = 1
        #        note.duration.dotGroups = [1]
        # test double dots with qL *
        noDotQL2 = noDotQL * (2.0 / 3)

        ## look for functions already defined and reuse them
        noDblDotQL = qL / common.dotMultiplier(2.0)
        noTrpDotQL = qL / common.dotMultiplier(3.0)
        # etc...

        ## clear old data
        self.type = ""
        self.dots = 0
        self.dotGroups = []
        self.tuplets = []

        if (common.isPowerOfTwo(qL)):
            tempType = self.getTypeFromQtrLength(qL)
            if (tempType): self.type = tempType
            else:
                raise DurationException(
                    "couldnt get type from Power of Two: %f" % qL)

        elif (common.isPowerOfTwo(noDotQL)):
            self.dots = 1
            tempType = self.getTypeFromQtrLength(noDotQL)
            if (tempType): self.type = tempType
            else: raise DurationException

        elif (common.isPowerOfTwo(noDblDotQL)):
            self.dots = 2
            tempType = self.getTypeFromQtrLength(noDblDotQL)
            if (tempType): self.type = tempType
            else: raise DurationException

        elif (common.isPowerOfTwo(noTrpDotQL)):
            self.dots = 3
            tempType = self.getTypeFromQtrLength(noTrpDotQL)
            if (tempType): self.type = tempType
            else: raise DurationException

            ## add code for 4 dots...

        elif (common.isPowerOfTwo(noDotQL2)):  # medieval dotted dotted notes
            self.dots = 1
            self.dotGroups = [1]
            tempType = self.getTypeFromQtrLength(noDotQL2)
            if (tempType): self.type = tempType
            else: raise DurationException

        #(check for simple tuplets, but don't spend too much time on it
        #python2.6 will have a Fraction class which will make finding the
        #closest tuplet representation much easier)

        else:
            raise DurationException("couldnt get type from Length: %f" % qL)