Ejemplo n.º 1
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'gaRhythm'
        self.doc = lang.docPoGr
        self.argTypes = ['list', 'num', 'num', 'num', 'str', 'num']
        self.argNames = ['pulseList', 'crossover', 'mutation', 'elitism',
                              'selectionString', 'populationSize']
        self.argDefaults = [[(3,1,1),(3,1,1),(6,1,1),(6,3,1),(3,1,0)],.70,
                                  .060, 0.01, 'oc', 20]
        self.priority = 9 # rhythm gets top priority
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error

        # args = [rObj, crossoverRate, mutationRate, percentElite]
        self.currentPulse = None # init value, used in getCurrentRhythm
        
        self.rObj = rhythm.Rhythm(self.args[0])     
        # must check rhythm before instantiating genome
        if len(self.rObj) <= 2:
            msg = 'pulse list error: supply a rhythm of 3 or more pulses'
            raise error.ParameterObjectSyntaxError(msg) # report error
            
        # exapnd rhythms without rests
        #self.rObj = self._expandRhythm(self.rObj)
        self.bpm = 120 # used for initial dur calculations
        self.crossoverRate = self.args[1]
        self.mutationRate    = self.args[2]
        self.percentElite    = self.args[3]

        # get populationi size as last arg
        self.popSize = self.args[5]
        if self.popSize < 2:
            msg = 'population size must be 2 or greater'
            raise error.ParameterObjectSyntaxError(msg) # report error

        try:
            self.genome = genetic.Genome(self.popSize, self.rObj.get('triple'),
                              rhythm.bpmToBeatTime(self.bpm), self.crossoverRate, 
                              self.mutationRate, self.percentElite)
        except ValueError:
            self.genome = None # this will return error when args checked
        if self.genome == None:
            raise error.ParameterObjectSyntaxError('genome failed to be populated.')

        self.rObjBundle = [] # stores list of rhythms, by family
        self.pulseBundle = [] # stores all pulses as one list

        self.rawRhythmBundle = self.genome.gen(40, 1) # 2nd arg makes silent
        for rawList in self.rawRhythmBundle:
            rObj = rhythm.Rhythm(rawList)
            rObj.setSus(.94) # create equal sustain
            self.rObjBundle.append(rObj) # list of rhythms
            for i in range(0, len(rObj)):
                self.pulseBundle.append(rObj[i]) # flat list of pulse objects

        # set pulseBundle as list from which selector draws
        self.control = self._selectorParser(self.args[4]) # raises exception
        self.selector = basePmtr.Selector(self.pulseBundle, self.control)
Ejemplo n.º 2
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'convertSecond'
        self.doc = lang.docPoCs
        self.argTypes = ['list',]
        self.argNames = ['parameterObject: duration values in seconds',]
        self.argDefaults = [('ru', .25, 2.5),]
        
        self.priority = 9 # rhythm gets top priority
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error

        self.currentPulse = None # init value, used in getCurrentRhythm
        # might be good to calculate a proper rhyhm object with given tempo
        self.rObj = rhythm.Rhythm((1,1)) # just a place holder
        self.pmtrObj = self._loadSub(args[0], 'genPmtrObjs')
Ejemplo n.º 3
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'convertSecondTriple'
        self.doc = lang.docPoCst
        self.argTypes = ['list', 'list', 'list']
        self.argNames = ['parameterObject: duration values in seconds',
                              'parameterObject: sustain values in seconds',
                              'parameterObject: accent values between 0 and 1',]
                              
        self.argDefaults = [('ws','e',30,0,.25,2.5), ('ws','e',60,.25,.25,2.5), 
                                  ('bg', 'rc', [0,1,1,1])]
        
        self.priority = 9 # rhythm gets top priority
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if not ok: raise error.ParameterObjectSyntaxError(msg) # report error

        self.currentPulse = None # init value, used in getCurrentRhythm
        # might be good to calculate a proper rhyhm object with given tempo
        self.rObj = rhythm.Rhythm((1,1)) # just a place holder
        self.durObj = self._loadSub(args[0], 'genPmtrObjs', 'duration')
        self.susObj = self._loadSub(args[1], 'genPmtrObjs', 'sustain')
        self.accObj = self._loadSub(args[2], 'genPmtrObjs', 'accent')
Ejemplo n.º 4
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'loop'
        self.doc = lang.docPoL
        self.argTypes = ['list', 'str']
        self.argNames = ['pulseList', 'selectionString']
        self.argDefaults = [((3,1,1),(3,1,1),(8,1,1),(8,1,1),(8,3,1),(3,2,0)),
                                  'oc']
        self.priority = 9 # rhythm gets top priority
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error

        self.currentPulse = None # init value, used in getCurrentRhythm
        try:
            self.rObj = rhythm.Rhythm(self.args[0])
        except error.PulseSyntaxError:
            raise error.ParameterObjectSyntaxError("enter a list of pulse objects.")
        for r in range(0, len(self.rObj)):
            self.rObj[r].setSus(.94) # set constant sustain, was 98, but still cut

        self.control = self._selectorParser(self.args[1]) # raises exception
        self.selector = basePmtr.Selector(self.rObj, self.control)
Ejemplo n.º 5
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'binaryAccent'
        self.doc = lang.docPoBa
        self.argTypes = ['list',]
        self.argNames = ['pulseList']
        self.argDefaults = [[(3,1,1),(3,2,1)],]

        self.priority = 9 # rhythm gets top priority
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error

        self.currentPulse = None # init value, used in getCurrentRhythm
        try:
            self.rObj = rhythm.Rhythm(self.args[0])  # first arg list of rhtyhms
        except error.PulseSyntaxError:
            raise error.ParameterObjectSyntaxError("enter a list of two pulse objects.")
        #self.rObj = self._expandRhythm(self.rObj)
        if len(self.rObj) != 2:
            raise error.ParameterObjectSyntaxError("enter a list of two pulse objects.")
        # set sustain mults for each pulse
        self.rObj[0].setSus(1.4)
        self.rObj[1].setSus(1.6)