Esempio n. 1
0
    def __init__(self, args, refDict):
        basePmtr.FilterParameter.__init__(self, args,
                                          refDict)  # call base init
        self.type = 'pipeLine'
        self.doc = lang.docPoPl
        self.argTypes = ['list']
        self.argNames = [
            'filterParameterObjectList: a list of sequential Filter ParameterObjects'
        ]
        self.argDefaults = [[['or', 40], ['ob']]]
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg)  # report error
        # will raise exception on error
        self.outputFmt = 'num'  # declare outputFmt as num by default
        self.inputFmt = ['num', 'str']  # declare outputFmt as num by default
        from athenaCL.libATH.libPmtr import parameter

        self.objArray = []
        for argList in self.args[0]:
            try:
                pmtrObj = parameter.factory(argList, 'filterPmtrObjs')
            except error.ParameterObjectSyntaxError as msg:
                raise error.ParameterObjectSyntaxError(
                    'failed sub-parameter: %s' % msg)
            self.objArray.append(pmtrObj)
Esempio n. 2
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'markovPulse'
        self.doc = lang.docPoMp
        self.argTypes = ['str', 'list']
        self.argNames = ['transitionString', 'parameterObject: order value']
        # note: restringulator can hand commas in braces...

        # TODO: accept single value for order value!

        self.argDefaults = ['a{3,1,1}b{2,1,1}c{3,2,0}:{a=3|b=4|c=1}', 
                                 ('c', 0)]
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error
        
        self.markovObj = markov.Transition() # creat obj w/o loading
        try:
            self.markovObj.loadTransition(self.args[0])
        except error.TransitionSyntaxError as e: 
            raise error.ParameterObjectSyntaxError('Markov transition creation failed: %s' % e)
        # will raise error
        self.orderObj = self._loadSub(self.args[1], 'genPmtrObjs')
        # need to store accumulated values
        self.accum = []
        # create a dictionary to store pulse objects, w/ string
        self.pulseRef = {}
        # we only need unique signified; even if more than one symbol refers
        # to the same signified, this does not matter
        for key in self.markovObj.getSignified():
            try:
                pulseObj = rhythm.Pulse(key) # let guess pulse type
            except error.PulseSyntaxError as e:
                raise error.ParameterObjectSyntaxError('failed pulse object definition: %s' % e)
            self.pulseRef[key] = pulseObj # store objs
Esempio n. 3
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'rhythmSieve'
        self.doc = lang.docPoRs
        self.argTypes = [['str', 'num', 'list'], 'num', 'str', 'list',]
        self.argNames = ['logicalString', 'sieveLength', 'selectionString', 
                              'parameterObject: Rhythm Generator']
        self.argDefaults = ['3|4|5', 60, 'rw', ('l', ((3,1,1),(3,1,1),(3,5,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     
        self.length = abs(int(round(self.args[1])))
        self.z = list(range(0, self.length))
        try:
            self.sieveObj = sieve.Sieve(self.args[0], self.z)
        except AttributeError: 
            raise error.ParameterObjectSyntaxError("incorrect sieve syntax.")

        # NOTE: update this to use binary segment
        # gets a binary representawtion
        self.sieveSeg = self.sieveObj(0, self.z, 'bin')
        # set z as list from which selector draws
        self.control = self._selectorParser(self.args[2]) # raises exception
        # select 1/0 from ginary sieve seg
        self.selector = basePmtr.Selector(self.sieveSeg, self.control)
        # create a parameter object     
        self.rthmObj = self._loadSub(self.args[3], 'rthmPmtrObjs')
Esempio n. 4
0
    def _loadMinMax(self, min, max):
        '''
        >>> a = Parameter([])
        >>> post = a._loadMinMax(45, 34)
        >>> post[0].type, post[1].type
        ('constant', 'constant')
        >>> post = a._loadMinMax(45, ['ru', 0, 1])
        >>> post[0].type, post[1].type
        ('constant', 'randomUniform')
        >>> post = a._loadMinMax(['ru', 0, 1], ['ru', 0, 1])
        >>> post[0].type, post[1].type
        ('randomUniform', 'randomUniform')
        '''

        if drawer.isNum(min):
            minArgs = ('c', min)
        elif drawer.isList(min):
            minArgs = min
        # check max
        if drawer.isNum(max):
            maxArgs = ('c', max)
        elif drawer.isList(max):
            maxArgs = max
        # create a parameter object
        from athenaCL.libATH.libPmtr import parameter
        try:
            minObj = parameter.factory(minArgs)
        except error.ParameterObjectSyntaxError as msg:
            raise error.ParameterObjectSyntaxError('failed sub-parameter: %s' % msg)
        try:
            maxObj = parameter.factory(maxArgs)
        except error.ParameterObjectSyntaxError as msg:
            raise error.ParameterObjectSyntaxError('failed sub-parameter: %s' % msg)
        return minObj, maxObj
Esempio n. 5
0
def locator(usrStr, libName=None):
    """
    libName can be None to permit access to all 

    >>> post, name = locator('ru')
    >>> name == 'RandomUniform'
    True
    """
    # convert acronum or other into fully named parameter string
    if usrStr == None:
        raise Exception('got bad usr string')

    #print _MOD, 'locator', usrStr, libName
    objType = pmtrTypeParser(usrStr, libName)  #check type string
    # fix case, capitalize lead character:
    if objType == None:
        raise error.ParameterObjectSyntaxError(
            'name error: no parameter named %r' % usrStr)
    objType = objType[0].upper() + objType[1:]
    modFound = None
    # this actually looks through external module files
    for mod in pmtrModules:  # look through all mods for
        reload(mod)
        classList = dir(mod)
        if objType in classList:
            modFound = mod
            break
    if modFound == None:  # failure
        raise error.ParameterObjectSyntaxError(
            'name error: no parameter named %r' % usrStr)
    # return reference to object, and string name of object
    # may want to retrun objType first char to lower case?
    return modFound, objType
Esempio n. 6
0
    def __init__(self, args, refDict):
        basePmtr.FilterParameter.__init__(self, args,
                                          refDict)  # call base init
        self.type = None
        self.argTypes = ['str', 'list']
        self.argNames = [
            'anchorString', 'parameterObject: operator value generator'
        ]
        self.argDefaults = ['lower', ('wc', 'e', 30, 0, 0, 1)]
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg)  # report error
        # will raise exception on error
        self.outputFmt = 'num'  # declare outputFmt as num by default
        self.inputFmt = 'num'  # declare outputFmt as num by default

        self.anchor = self._anchorParser(self.args[0])
        #print _MOD, 'anchor set to', self.anchor
        from athenaCL.libATH.libPmtr import parameter
        try:
            self.pmtrObj = parameter.factory(self.args[1],
                                             ['genPmtrObjs', 'rthmPmtrObjs'])
        except error.ParameterObjectSyntaxError as msg:
            raise error.ParameterObjectSyntaxError('failed sub-parameter: %s' %
                                                   msg)
Esempio n. 7
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)
Esempio n. 8
0
 def _loadSub(self, arg, lib, idStr=''):
     from athenaCL.libATH.libPmtr import parameter
     try:
         obj = parameter.factory(arg, lib)
     except error.ParameterObjectSyntaxError as msg:
         if idStr == '':
             raise error.ParameterObjectSyntaxError('failed sub-parameter: %s' % msg)
         else:
             raise error.ParameterObjectSyntaxError('failed %s sub-parameter: %s' % (idStr, msg))            
     return obj
Esempio n. 9
0
def durToAdsr(tStart,
              propAbsSwitch,
              dur,
              attack,
              decay,
              sustain,
              release,
              susScalar,
              min=0,
              max=1):
    """create an adsr envelope
    sustain scalar is a value, w/n the unit interval, of the difference between
    min and max

    >>> durToAdsr(0, 'absolute', 10, 2, 1, 2, 2, .5)
    [[0, 0.0], [2, 1.0], [3, 0.5], [5, 0.5], [7, 0.0], [9.999..., 0.0]]

    """
    # will automatically sort min, max
    peak = unit.denorm(1, min, max)
    nadir = unit.denorm(0, min, max)
    susLevel = (peak - nadir) * unit.limit(susScalar)

    if propAbsSwitch not in ['absolute', 'proportional']:
        raise error.ParameterObjectSyntaxError('incorrect switch')

    if propAbsSwitch == 'absolute':
        timeUnitDenorm = [attack, decay, sustain, release]
        if sum(timeUnitDenorm) > dur:  # force proportional
            propAbsSwitch = 'proportional'

    if propAbsSwitch == 'proportional':
        timeUnit = unit.unitNormProportion([attack, decay, sustain, release])
        timeUnitDenorm = [x * dur for x in timeUnit]

    tEnd = tStart + dur
    t = tStart

    envelope = []
    envelope.append([t, nadir])

    t = t + _stepFilter(timeUnitDenorm[0])  # attack
    envelope.append([t, peak])

    t = t + _stepFilter(timeUnitDenorm[1])  # decay
    envelope.append([t, susLevel])

    t = t + _stepFilter(timeUnitDenorm[2])  # sustain
    envelope.append([t, susLevel])

    if propAbsSwitch == 'proportional':
        t = tEnd - OFFSET  # always measure to end
        envelope.append([t, nadir])
    else:  # absolute
        t = t + _stepFilter(timeUnitDenorm[3])  # sustain
        envelope.append([t, nadir])
        t = tEnd - OFFSET  # always measure to end
        envelope.append([t, nadir])

    return envelope
Esempio n. 10
0
    def __init__(self, args, refDict):
        basePmtr.Parameter.__init__(self, args, refDict)  # call base init
        self.type = 'directorySelect'
        self.doc = lang.docPoDs
        self.outputFmt = 'str'  # declare outputFmt as string
        self.argTypes = ['str', 'str', 'str']
        self.argNames = [
            'directoryFilePath', 'fileExtension', 'selectionString'
        ]
        self.argDefaults = ['.', 'aif', 'rw']
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg)  # report error

        self.dirPath = ''
        self.fileExt = ''  # can start w/ period or not
        self.filePathList = []  # updated on __call__
        self.timer = rhythm.Timer()  # sets start time

        self.dirPath = self.args[0]
        self.fileExt = self.args[1]
        self.control = self._selectorParser(self.args[2])  # raises exception
        # will update in self._updateFileList
        # can initialize selector empty, but cannot call empty
        self.selector = basePmtr.Selector([], self.control)
        self.updatePathList = 1  # force update of path list on init
Esempio n. 11
0
    def __init__(self, args, refDict):
        basePmtr.FilterParameter.__init__(self, args,
                                          refDict)  # call base init
        self.type = 'maskFilter'
        self.doc = lang.docPoMf
        self.argTypes = ['str', 'list', 'list']
        self.argNames = [
            'boundaryString: limit, wrap, reflect',
            'parameterObject: first boundary',
            'parameterObject: second boundary',
        ]
        self.argDefaults = [
            'l', ('ws', 'e', 60, 0, .5, 0), ('wc', 'e', 90, 0, .5, 1)
        ]
        self.argDemos = []
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg)  # report error
        # will raise exception on error
        self.outputFmt = 'num'  # declare outputFmt as num by default
        self.inputFmt = ['num']  # declare outputFmt as num by default

        # will raise exception on error
        self.boundaryMethod = self._boundaryParser(self.args[0])
        self.boundingPmtrObjA = self._loadSub(self.args[1], 'genPmtrObjs')
        self.boundingPmtrObjB = self._loadSub(self.args[2], 'genPmtrObjs')
Esempio n. 12
0
    def __init__(self, args, refDict):
        basePmtr.FilterParameter.__init__(self, args,
                                          refDict)  # call base init
        self.type = 'filterQuantize'
        self.doc = lang.docPoFq
        self.argTypes = ['list', 'list', 'int', 'list']
        self.argNames = [
            'parameterObject: grid reference value Generator',
            'parameterObject: step width Generator',
            'stepCount',
            'parameterObject: unit interval measure of quantize pull',
        ]
        self.argDefaults = [('c', 0), ('c', .25), 1, ('c', 1)]
        self.argDemos = [[('cg', 'up', 0, 1, .0025), ('bg', 'oc', (.4, .6)), 2,
                          ('bpp', 'e', 'l', ((0, 1), (59, 0), (119, 1)), -3)]]
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg)  # report error
        # will raise exception on error
        self.outputFmt = 'num'  # declare outputFmt as num by default
        self.inputFmt = ['num']  # declare outputFmt as num by default

        # will raise exception on error
        self.gridRefObj = self._loadSub(self.args[0], 'genPmtrObjs')
        self.stepGenObj = self._loadSub(self.args[1], 'genPmtrObjs')
        self.stepCount = self.args[2]
        self.pullObj = self._loadSub(self.args[3], 'genPmtrObjs')
        self.quantObj = quantize.Quantizer(self.LOOPLIMIT)
Esempio n. 13
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'pulseTriple'
        self.doc = lang.docPoPt
        self.argTypes = ['list', 'list', 'list', 'list']
        self.argNames = ['parameterObject: pulse divisor',
                              'parameterObject: pulse multiplier',
                              'parameterObject: accent value between 0 and 1',
                              'parameterObject: sustain scalar greater than 0',]
                              
        self.argDefaults = [('bg','rc',(6,5,4,3)), ('bg','rc',(1,2,3)), 
                                  ('bg','rc',(1,1,1,0)), ('ru', .5, 1.5)]
        self.argDemos = [[('c',4),('cl','f{s}x{81}y{120}k{2}r{1}w{6}c{-2}',109,0.01,'sr','oc'),('cv','f{s}x{81}y{120}k{2}r{1}w{3}c{8}',109,0.003,'sr',0,1,'oc'),('c',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
        # will raise error 
        self.divObj  = self._loadSub(args[0], 'genPmtrObjs', 'divisor')
        self.multObj = self._loadSub(args[1], 'genPmtrObjs', 'multiplier')
        self.accObj  = self._loadSub(args[2], 'genPmtrObjs', 'accent')
        self.susObj  = self._loadSub(args[3], 'genPmtrObjs', 'sustain')
Esempio n. 14
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'iterateRhythmWindow'
        self.doc = lang.docPoIrw
        
        self.argTypes = ['list', 'list', 'str']
        self.argNames = ['parameterObjectList: a list of Rhythm Generators', 
                              'parameterObject: generate or skip control Generator', 
                              'selectionString']

        self.argDefaults = [(
                 ('l', ((4,3,1),(4,3,1),(4,2,0),(8,1,1),(4,2,1),(4,2,1)),'oc'),
                 ('cs', ('ru', 1.5, 4)),
             ),
                 ('bg','rc',(-3,6,-1,15)), 
                 'oc']
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error

        self.valueBuffer = [] # values g selected 

        from athenaCL.libATH.libPmtr import parameter
        self.objArray = []
        for argList in self.args[0]:
            try:
                pmtrObj = parameter.factory(argList, 'rthmPmtrObjs')
            except error.ParameterObjectSyntaxError, msg:
                raise error.ParameterObjectSyntaxError, 'failed sub-parameter: %s' % msg
            self.objArray.append(pmtrObj)
Esempio n. 15
0
    def __init__(self, args, refDict):
        """searches a list of directories recursively and finds all files
            files named in args are found within these directories
            dirs are onlys serached if list of dirs has changed"""
        basePmtr.Parameter.__init__(self, args, refDict) # call base init
        self.type = None # in subclass
        self.outputFmt = 'str' # declare outputFmt as string
        self.argTypes = [['list', 'str'], 'str']
        self.argNames = ['fileNameList', 'selectionString']
        self.argDefaults = [[], 'rc']
        
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error

        self.dirList = [] # used to look for changes
        self.filePathList = [] # updated on __call__
        self.timer = rhythm.Timer() # sets start time
        self.updatePathList = 1 # forces update of paths
        # not sure this is functioning
        #self.tLastUpdate = 0.0 # time of last file dir update

        if drawer.isList(self.args[0]):
            self.nameList = self.args[0]
        elif drawer.isStr(self.args[0]):
            tempList = []
            tempList.append(self.args[0])
            self.nameList = tuple(tempList)

        self.control = self._selectorParser(self.args[1]) # raises exception
        # choose names from name list
        self.selector = basePmtr.Selector(self.nameList, self.control)
Esempio n. 16
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'markovRhythmAnalysis'
        self.doc = lang.docPoMra
        
        self.argTypes = ['list', 'int', 'int', 'list']
        self.argNames = ['parameterObject: source Rhythm Generator', 
                              'pulseCount',
                              'maxAnalysisOrder',
                              'parameterObject: output order value'
                              ]
        self.argDefaults = [('l', 
                                    ((4,3,1),(4,3,1),(4,2,0),(8,1,1),(4,2,1),(4,2,1)),
                                    'oc'), 12, 2, ('cg','u',0,2,.25)]
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error

        self.srcObj = self._loadSub(self.args[0], 'rthmPmtrObjs')
        self.pulseCount = self.args[1]
        self.maxAnalysisOrder = self.args[2]
        self.orderObj = self._loadSub(self.args[3], 'genPmtrObjs')

        # need to store accumulated values
        self.analysisSeries = []
        self.accum = []
        # create a dictionary to store pulse objects, w/ string
        self.pulseRef = {}
        # analysis is done on init
        self.markovObj = markov.Transition() # creat obj w/o loading
        # this may raise an exception
        self._updateAnalysis()
Esempio n. 17
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'iterateRhythmHold'
        self.doc = lang.docPoIrh
        self.argTypes = ['list', 'list', 'list', 'str']
        self.argNames = ['parameterObject: source Rhythm Generator', 
                              'parameterObject: size Generator', 
                              'parameterObject: refresh count Generator', 
                              'selectionString']

        self.argDefaults = [('pt',('bg', 'rc', (4,2)),('bg', 'oc', (5,4,3,2,1)),
                                  ('c', 1), ('ru', .75, 1.25)),
                                  ('bg','rc',[2,3,4]),
                                  ('bg','oc',[4,5,6]),'oc']
                             
        # check raw arguments for number, type
        ok, msg = self._checkRawArgs()
        if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error

        self.srcObj = self._loadSub(self.args[0], 'rthmPmtrObjs')   
        self.sizeObj = self._loadSub(self.args[1], 'genPmtrObjs')   
        self.refreshObj = self._loadSub(self.args[2], 'genPmtrObjs')    
        self.control = self._selectorParser(self.args[3]) # check control string
        self.valueBuffer = [] # collection values selected from
        self.eventCount = 0
        self.eventCountTotal = 0
        self.refreshValue = None
Esempio n. 18
0
    def __init__(self, args, refDict):
        basePmtr.RhythmParameter.__init__(self, args, refDict) # call base init
        self.type = 'pulseSieve'
        self.doc = lang.docPoPs
        self.argTypes = [['str', 'num','list'], 'num', 'list', 'str', 'str']
        
        self.argNames = ['logicalString', 'sieveLength', 'pulse',
                              'selectionString', 'articulationString']
        self.argDefaults = ['3|4|5@2', 60, (3,1,1), 'oc', 'a']
        self.argDemos = [['3|4|5@2', 60, (4,1,1), 'rc', 's'],
                             ]
                             
        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     
        self.length = abs(int(round(self.args[1])))
        self.z = list(range(0, self.length))
        try:
            self.sieveObj = sieve.Sieve(self.args[0], self.z)
        except AttributeError: 
            raise error.ParameterObjectSyntaxError("incorrect sieve syntax.")

        try:
            self.pulseObj = rhythm.Pulse(self.args[2])
        except error.PulseSyntaxError:
            raise error.ParameterObjectSyntaxError("incorrect sieve syntax.")
        self.pulseObj.setSus(.94) # no sustain

        self.pulseOn = self.pulseObj.copy()
        self.pulseOn.setAcc(1)  # force on
        self.pulseOff = self.pulseObj.copy()
        self.pulseOff.setAcc(0) # force off
        # gets a list if numbers, like 0,3,4,6,9,10
        # interpret as equal dur time points

        # get format based on ariticulation
        self.articulation = self._articulationParser(self.args[4])
        if self.articulation == 'sustain': fmt = 'wid'
        elif self.articulation == 'attack': fmt = 'bin'
        self.sieveObj.segFmtSet(fmt)
        self.sieveSeg = self.sieveObj(0, self.z)
        # set z as list from which selector draws
        self.control = self._selectorParser(self.args[3]) # raises exception
        self.selector = basePmtr.Selector(self.sieveSeg, self.control)
Esempio n. 19
0
def pmtrTypeParser(typeName, libName='genPmtrObjs'):
    """utility functions for parsing user paramter strings into proper
    parameter names. accepts short names and long names, regardless of case
    does not raise an error if no match: returns string unmodified
    parameters can have the same abbreviation if they are in different libraries

    >>> pmtrTypeParser('ru', 'genPmtrObjs')
    'randomUniform'

    >>> pmtrTypeParser('ru', None)
    'randomUniform'

    >>> pmtrTypeParser('gr', None)
    'gaRhythm'
    """
    if typeName == None:
        raise Exception('got a type name of none')
    #print _MOD, 'pmtrTypeParser', typeName, libName

    usrStr = drawer.strScrub(typeName, 'lower')
    # get all parameter names in a dictionary
    if libName == 'genPmtrObjs':
        pmtrNames = genPmtrNames
    elif libName == 'rthmPmtrObjs':
        pmtrNames = rthmPmtrNames
    elif libName == 'textPmtrObjs':
        pmtrNames = textPmtrNames
    elif libName == 'clonePmtrObjs':
        pmtrNames = clonePmtrNames
    elif libName == 'filterPmtrObjs':
        pmtrNames = filterPmtrNames
    elif libName == None:
        pmtrNames = allPmtrNames

    else:
        raise error.ParameterObjectSyntaxError(
            'no parameter library named: %r' % libName)

    for key in list(pmtrNames.keys()):
        className = pmtrNames[key]
        if usrStr == key:
            return className
        elif usrStr == className.lower():
            return className
    # if not mattched, raise an error
    raise error.ParameterObjectSyntaxError('no parameter named %r in %s' %
                                           (usrStr, pmtrLibTitle(libName)))
Esempio n. 20
0
 def __init__(self, args, refDict):
     basePmtr.FilterParameter.__init__(self, args,
                                       refDict)  # call base init
     self.type = None
     self.argTypes = ['list']
     self.argNames = ['parameterObject: operator value generator']
     self.argDefaults = [('ws', 'e', 30, 0, 0, 1)]
     # check raw arguments for number, type
     ok, msg = self._checkRawArgs()
     if ok == 0: raise error.ParameterObjectSyntaxError(msg)  # report error
     # will raise exception on error
     self.outputFmt = 'num'  # declare outputFmt as num by default
     self.inputFmt = 'num'  # declare outputFmt as num by default
     from athenaCL.libATH.libPmtr import parameter
     try:  # note: can be eithe gen or filter parameter object
         self.pmtrObj = parameter.factory(self.args[0],
                                          ['genPmtrObjs', 'rthmPmtrObjs'])
     except error.ParameterObjectSyntaxError as msg:
         raise error.ParameterObjectSyntaxError('failed sub-parameter: %s' %
                                                msg)
Esempio n. 21
0
 def _typeFormatParser(self, usrStr):
     "decode control choice strings"
     ref = {
         'stringQuote' : ['sq',],
         'string'          : ['str', 's'],
             }
     usrStr = drawer.selectionParse(usrStr, ref)
     if usrStr == None:
         selStr = drawer.selectionParseKeyLabel(ref)
         raise error.ParameterObjectSyntaxError('bad control value: enter %s.' % selStr)
     return usrStr
Esempio n. 22
0
 def _selectLevelMonophonicParser(self, usrStr):
     "decode control choice strings"
     ref = {
         'event' : ['e'],
         'set' : ['s'],
             }
     usrStr = drawer.selectionParse(usrStr, ref)
     if usrStr == None:
         selStr = drawer.selectionParseKeyLabel(ref)
         raise error.ParameterObjectSyntaxError('bad control value: enter %s.' % selStr)
     return usrStr
Esempio n. 23
0
 def __init__(self, args, refDict):
     basePmtr.StaticParameterTexture.__init__(self, args, refDict) 
     # arg types exclude name of parameter: just data arg
     self.argTypes = ['str',]
     self.argNames = ['level: event, frame',]
     # check raw arguments for number, type
     ok, msg = self._checkRawArgs()
     if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error
     # will raise exception on error
     self.args[0] = self._selectLevelFrameParser(self.args[0])
     # must call update switches to fill internal dictionary
     self._updateSwitches()
Esempio n. 24
0
def durToTrapezoid(tStart,
                   propAbsSwitch,
                   dur,
                   rampUp,
                   widthMax,
                   rampDown,
                   widthMin,
                   min=0,
                   max=1):
    """assume dir of peal is widthOn
    will automatically convert to proportion if abs sum extends past dur
    this is an trapezoid with only one ramp; may not have complete duration time; always leads on

    >>> durToTrapezoid(0, 'absolute', 10, 3, 3, 3, .5)
    [[0, 0.0], [3, 1.0], [6, 1.0], [9, 0.0], [9.999..., 0.0]]
    """

    # will automatically sort min, max
    peak = unit.denorm(1, min, max)
    nadir = unit.denorm(0, min, max)

    if propAbsSwitch not in ['absolute', 'proportional']:
        raise error.ParameterObjectSyntaxError('incorrect switch')

    if propAbsSwitch == 'absolute':
        timeUnitDenorm = [rampUp, widthMax, rampDown, widthMin]
        if sum(timeUnitDenorm) > dur:  # force proportional
            propAbsSwitch = 'proportional'

    if propAbsSwitch == 'proportional':
        timeUnit = unit.unitNormProportion(
            [rampUp, widthMax, rampDown, widthMin])
        timeUnitDenorm = [x * dur for x in timeUnit]

    tEnd = tStart + dur
    t = tStart

    envelope = []
    envelope.append([t, nadir])

    t = t + _stepFilter(timeUnitDenorm[0])  # ramp
    envelope.append([t, peak])

    t = t + _stepFilter(timeUnitDenorm[1])  # width
    envelope.append([t, peak])

    t = t + _stepFilter(timeUnitDenorm[2])  # ramp
    envelope.append([t, nadir])

    t = tEnd - OFFSET  # always measure to end
    envelope.append([t, nadir])

    return envelope
Esempio n. 25
0
 def _selectRetrogradeParser(self, usrStr):
     "decode control choice strings"
     ref = {
         'off' : ['off', '0'],
         'timeInverse' : ['ti', 'tinvers'],
         'eventInverse' : ['ei', 'retro'],
             }
     usrStr = drawer.selectionParse(usrStr, ref)
     if usrStr == None:
         selStr = drawer.selectionParseKeyLabel(ref)
         raise error.ParameterObjectSyntaxError('bad control value: enter %s.' % selStr)
     return usrStr
Esempio n. 26
0
 def _selectLevelEventCountParser(self, usrStr):
     "decode control choice strings"
     ref = {
         'texture': ['t', 'text', 'texture'],
         'segment': ['s', 'seg', 'segment'],
     }
     usrStr = drawer.selectionParse(usrStr, ref)
     if usrStr == None:
         selStr = drawer.selectionParseKeyLabel(ref)
         raise error.ParameterObjectSyntaxError(
             'bad control value: enter %s.' % selStr)
     return usrStr
Esempio n. 27
0
 def _selectDensityPartitionParser(self, usrStr):
     "decode control choice strings"
     ref = {
         'duration': ['d', 'dur'],
         'set': ['s'],
     }
     usrStr = drawer.selectionParse(usrStr, ref)
     if usrStr == None:
         selStr = drawer.selectionParseKeyLabel(ref)
         raise error.ParameterObjectSyntaxError(
             'bad control value: enter %s.' % selStr)
     return usrStr
Esempio n. 28
0
    def _loadAutoConstantStr(self, arg, ref, lib='genPmtrObjs'):
        """accept a number, a list parameter object, or a string from 
        within a dfeind string group"""
#         ref = {'0' : ['tn', 't', 't n' '0'],
#                 }
        if drawer.isNum(arg):
            pmtrArgs = ('c', arg)
        elif drawer.isStr(arg):
            post = drawer.selectionParse(arg, ref, 0) # autosearch off
            if post == None:
                raise error.ParameterObjectSyntaxError('no such preset name known.')
            pmtrArgs = ('c', post) # a constant pmtr obj
        else: # its a list to create a ParameterObject
            pmtrArgs = arg
        # create a ParameterObject
        from athenaCL.libATH.libPmtr import parameter
        try:
            obj = parameter.factory(pmtrArgs, lib)
        except error.ParameterObjectSyntaxError as msg:
            raise error.ParameterObjectSyntaxError('failed sub-parameter: %s' % msg)
        return obj   
Esempio n. 29
0
 def __init__(self, args, refDict):
     basePmtr.Parameter.__init__(self, args, refDict) # call base init
     self.type = 'constantFile'    
     self.doc = lang.docPoCf
     self.outputFmt = 'str' # declare outputFmt as string
     self.argTypes = ['str']
     self.argNames = ['absoluteFilePath']
     self.argDefaults = [''] # no default possible
     # check raw arguments for number, type
     ok, msg = self._checkRawArgs()
     if ok == 0: raise error.ParameterObjectSyntaxError(msg) # report error
     self.filePath = drawer.pathScrub(self.args[0])
Esempio n. 30
0
def factory(rawArgs, libName=None, refDict=None):
    """this is used only for loading and returning an object
    can return obj or parsed args
    first thing in list must be a string, type def

    libName can be a list or a string
    rawArgs is a list of python data types, starting with the po name
    exceptions that may be raised: error.ParameterObjectSyntaxError
    """
    reload(basePmtr)  # reload base class
    if not drawer.isList(rawArgs):
        rawArgs = eval(drawer.restringulator(rawArgs))
        # if only string, we have only one argument, no commas
        if drawer.isStr(rawArgs):
            rawArgs = [rawArgs]

        # old method simply put rawArgs, if a string, as a first argument
        # rawArgs = [rawArgs,] # add to a list, could be a single str

    # first arg is always a string, naming the parameter type
    # obj args could be empty if requires no arguments
    objType, objArgs = rawArgs[0], list(rawArgs[1:])

    libOpt = []  # option libs
    if not drawer.isList(libName):
        libOpt.append(libName)
    else:
        libOpt = libName

    for i in range(0, len(libOpt)):
        name = libOpt[i]
        if name != None:  # None is all
            name = pmtrLibParser(name)  # name of possible library

        try:  # will raise exception on error
            mod, modStr = locator(objType, name)  #check type string
        except error.ParameterObjectSyntaxError as e:
            modStr = None
        if modStr == None:
            if i != len(libOpt) - 1:
                continue  # if not the last one to try
            else:
                raise error.ParameterObjectSyntaxError(
                    'parameter lib error (%s: %s, %s, %s)' %
                    (name, objType, modStr, rawArgs))
        else:  # got a good object
            break
            # failure
    pmtrObjAttr = getattr(mod, modStr)
    #print _MOD, 'factory loading object', mod, objType
    pmtrObj = pmtrObjAttr(objArgs, refDict)
    return pmtrObj