def __set_scope(self, a, prop, fr, fo, to): to_str = action.abstract_string(to).lower() to_val = -1 to_match = None if to_str == 'note': to_val = const.scope_pernote elif to_str == 'global': to_val = const.scope_global else: to_match = re.match('^channel\s(\d+)$', to_str, re.IGNORECASE) if to_match: to_val = int(to_match.group(1)) if to_val < 1 or to_val > 16: return errors.invalid_thing(to_str, 'set') else: return errors.invalid_thing(to_str, 'set') try: (iparam, oparam, midi, info) = self.__map_from_for(fr, fo) if to_match: if oparam != -1: self.__delegate.map_param( iparam, info.clone_with_channelscope(to_val)) elif midi != -1: self.__delegate.map_midi( iparam, info.clone_with_channelscope(to_val)) else: if oparam != -1: self.__delegate.map_param(iparam, info.clone_with_scope(to_val)) elif midi != -1: self.__delegate.map_midi(iparam, info.clone_with_scope(to_val)) except RuntimeError, e: return e.message
def __map_channel(self, subject, cfrom, cto): cfrom = int(action.mass_quantity(cfrom)) cto = int(action.mass_quantity(cto)) if cfrom < 1 or cfrom > 16: return errors.invalid_thing(str(cfrom), 'map') if cto < 1 or cto > 16: return errors.invalid_thing(str(cto), 'map') new_mapping = [] new_mapping.append((cfrom, cto)) for m in self.__current_channel_mapping(): if m[0] != cfrom: new_mapping.append(m) self.__set_channel_mapping(new_mapping)
def __set_bank_change(self, ctx, subj, dummy, val): to = action.abstract_wordlist(val)[0] to_val = int(to) if to_val < 0 or to_val > 127: return errors.invalid_thing(to, 'set') return piw.trigger(self.host.change_bank(), piw.makelong_nb(to_val, 0)), None
def __set_midi_control(self, ctx, subj, ctl, val): c = action.mass_quantity(ctl) to = action.abstract_wordlist(val)[0] c_val = int(c) to_val = int(to) if c_val < 0 or c_val > 127: return errors.invalid_thing(c, 'set') if to_val < 0 or to_val > 127: return errors.invalid_thing(to, 'set') return piw.trigger( self.host.change_cc(), utils.makedict_nb( { 'ctl': piw.makelong_nb(c_val, 0), 'val': piw.makelong_nb(to_val, 0) }, 0)), None
def __set_program_change(self, ctx, subj, dummy, val): to = action.abstract_wordlist(val)[0] to_val = int(to) if to_val < 0 or to_val > 127: return errors.invalid_thing(to, 'set') return piw.trigger(self.__midi_from_belcanto.change_program(), piw.makelong_nb(to_val, 0)), None
def __firstv(self,subj,voice): id = self.crack_voice(voice) voice = self[5].get_voice(int(id)) if voice is None: thing='voice %s' %str(id) return async.success(errors.invalid_thing(thing,'first')) voice.first()
def __select(self,subj,voice): id = self.crack_voice(voice) if self[5].choose_voice(id): return action.nosync_return() thing='voice %s' %str(id) return async.success(errors.invalid_thing(thing,'select'))
def __uncreate_output(self,subj,mass): id = int(action.mass_quantity(mass)) channel = self[2].get_channel(id) if channel is None: thing='output %s' %str(id) return async.success(errors.invalid_thing(thing,'un create')) self[2].del_channel(id)
def __uncreate(self,subj,channel): id = int(action.abstract_string(channel)) channel = self[1].get_input(id) if channel is None: thing='channel %s' %str(id) return async.success(errors.invalid_thing(thing,'un create')) self[1].del_input(id)
def __once(self,ctx,subj,voice): id = self.crack_voice(voice) voice = self[5].get_voice(id) if voice is None: thing='voice %s' %str(id) return async.success(errors.invalid_thing(thing,'play')) return voice.loop_once,None
def __do_play_now(self,arg,mode): cookie = self.__load(arg,1) if not cookie: thing= 'take %s' %str(arg) return async.success(errors.invalid_thing(thing,'play')) f = self.player.player(cookie,mode) ff = piw.fastchange(f) ff(piw.makefloat_bounded_nb(1,0,0,1,0)) self.player.unload(cookie,False) return action.nosync_return()
def __set_high(self, a, prop, fr, fo, to): to_str = action.abstract_string(to) to_val = float(to_str) / 100.0 if to_val < 0 or to_val > 1: return errors.invalid_thing(to_str, 'set') try: (iparam, oparam, midi, info) = self.__map_from_for(fr, fo) if oparam != -1: self.__delegate.map_param(iparam, info.clone_with_hi(to_val)) elif midi != -1: self.__delegate.map_midi(iparam, info.clone_with_hi(to_val)) except RuntimeError, e: return e.message
def __remove(self,subj,voice): if voice is None: voice = self[5].current_voice() if not voice: return async.success(errors.no_current_voice('','remove')) id = voice.voice else: id = self.crack_voice(voice) if self[5].remove_voice(id): return action.nosync_return() thing='voice %s' %str(id) return async.success(errors.invalid_thing(thing,'remove'))
def __set_resolution(self, a, prop, fr, fo, to): to_str = action.abstract_string(to).lower() to_val = int(to_str) if to_val != const.resolution_bits_7 and to_val != const.resolution_bits_14: return errors.invalid_thing(to_str, 'set') try: (iparam, oparam, midi, info) = self.__map_from_for(fr, fo) if oparam != -1: self.__delegate.map_param(iparam, info.clone_with_resolution(to_val)) elif midi != -1: self.__delegate.map_midi(iparam, info.clone_with_resolution(to_val)) except RuntimeError, e: return e.message
def __repeat(self,subj,arg,mode): arg = self.__crack_arg(arg) mode = self.__crack_mode(mode) print 'repeat mode',mode if not self.__schedready: return async.success(errors.state_error1('scheduler','use')) path = self.library.cookie2file(arg) if not path or not os.path.exists(path): thing='take %s' % str(arg) return async.success(errors.invalid_thing(thing,'repeat')) recording = recorder_native.read(path) cookie = self.player.load(arg,recording,1) delta = recording.get_tag(5).as_float() start = recording.get_tag(3).as_float() duration = recording.get_tag(4).as_float() desc = "take %s every %g song beat" % (arg,duration) schema = 'schema("%s",[m(3,%f,%f)])' % (desc,duration,start%duration) r = async.Deferred() def trigger_ok(trigger): print '__repeat:trigger_ok' event,status = self.verb_defer(3,(False,trigger,4,mode),trigger,None,self.cookie_arg(arg)) self[5].update() self.player.unload(cookie,False) r.succeeded(action.nosync_return()) def trigger_failed(msg): r.failed(msg) trigger = self.__scheduler.create_trigger(schema) trigger.setCallback(trigger_ok).setErrback(trigger_failed) return r
def __play_aue(self,subj,arg,a,u,e,mode): #print 'play aue',arg arg = self.__crack_arg(arg) mode = self.__crack_mode(mode) #print '->',arg a = tsm(a) u = tsm(u) e = tsm(e) if not self.__schedready: return async.success(errors.state_error1('scheduler','use')) path = self.library.cookie2file(arg) if not path or not os.path.exists(path): thing='take %s' %str(arg) return async.success(errors.invalid_thing(thing,'play')) recording = recorder_native.read(path) cookie = self.player.load(arg,recording,1) delta = recording.get_tag(5).as_float() schema = schedproxy.make_schema(a,u,e,delta,prefix='take %s' % arg) #print 'playback',arg,'delta=',delta,'schema',schema r = async.Deferred() def trigger_ok(trigger): print '__play_aue:trigger_ok' event,status = self.verb_defer(3,(False,trigger,4,mode),trigger,None,self.cookie_arg(arg)) self.player.unload(cookie,False) r.succeeded(action.nosync_return()) def trigger_failed(msg): r.failed(msg) trigger = self.__scheduler.create_trigger(schema) trigger.setCallback(trigger_ok).setErrback(trigger_failed) return r
def __set_curve(self, a, prop, fr, fo, to): to_str = action.abstract_string(to).lower() if 'linear' == to_str: to_val = 0 elif 'cubic' == to_str: to_val = 1 elif 'quadratic' == to_str: to_val = 2 elif 'step' == to_str: to_val = 3 else: return errors.invalid_thing(to_str, 'set') try: (iparam, oparam, midi, info) = self.__map_from_for(fr, fo) if oparam != -1: self.__delegate.map_param(iparam, info.clone_with_curve(to_val)) elif midi != -1: self.__delegate.map_midi(iparam, info.clone_with_curve(to_val)) except RuntimeError, e: return e.message
def __map_from_for(self, fr, fo): from_str = action.abstract_string(fr) for_str = action.abstract_string(fo).lower() iparam_number = 0 oparam_number = -1 midi_number = -1 # determine the input parameter number from_match = re.match('^parameter\s+(\d+)$', from_str, re.IGNORECASE) if not from_match: for i in range(1, 17): param_name = self[i].get_property_string('name') param_ordinal = self[i].get_property_long('ordinal') if param_ordinal: param_name = param_name + ' ' + str(param_ordinal) if from_str.lower() == param_name.lower(): iparam_number = i break else: iparam_number = int(from_match.group(1)) if iparam_number < 1 or iparam_number > 16: raise RuntimeError(errors.invalid_thing(from_str, 'map')) # determine the output parameter or midi mapping oparam_match = re.match('^\d+$', for_str, re.IGNORECASE) midi_match = re.match('^midi\s(\d+)$', for_str, re.IGNORECASE) if oparam_match: oparam_number = int(oparam_match.group(0)) elif midi_match: midi_number = int(midi_match.group(1)) else: if for_str == "polyphonic aftertouch": midi_number = 128 elif for_str == "program change": midi_number = 129 elif for_str == "channel aftertouch": midi_number = 130 elif for_str == "pitch wheel": midi_number = 131 elif for_str == "legato trigger": midi_number = 132 # validate the results if oparam_number < 0 and (midi_number < 0 or midi_number > 131): raise RuntimeError(errors.invalid_thing(for_str, 'map')) print 'iparam:', iparam_number, 'oparam:', oparam_number, 'midi:', midi_number info = None if oparam_number != -1: if self.__delegate.is_mapped_param(iparam_number, oparam_number): info = self.__delegate.get_info_param(iparam_number, oparam_number) else: info = piw.mapping_info(oparam_number) elif midi_number != -1: if self.__delegate.is_mapped_midi(iparam_number, midi_number): info = self.__delegate.get_info_midi(iparam_number, midi_number) else: info = piw.mapping_info(midi_number) return (iparam_number, oparam_number, midi_number, info)