def single_file(filename, x): controller.reset() controller.filesNew(filename, st) finger_midi = 0.0 controller.comment("attack inst %i st %i dyn %i finger_midi %.3f" % (inst_type, st, dyn, finger_midi)) begin = vivi_controller.NoteBeginning() begin.physical.string_number = st begin.physical.bow_force = fbi begin.physical.dynamic = prev_dyn begin.physical.bow_bridge_distance = dynamics.get_distance( inst_type, prev_dyn) begin.physical.bow_velocity = dynamics.get_velocity( inst_type, prev_dyn) end = vivi_controller.NoteEnding() for i in range(REPS): controller.reset(True) finger_midi = prev_fmi begin.physical.finger_position = utils.midi2pos(finger_midi) controller.note(begin, NOTE_LENGTH, end) #controller.rest(0.1) begin.physical.dynamic = dyn begin.physical.bow_bridge_distance = dynamics.get_distance( inst_type, dyn) begin.physical.bow_velocity = dynamics.get_velocity(inst_type, dyn) finger_midi = 0.0 begin.physical.bow_force = x begin.physical.finger_position = utils.midi2pos(finger_midi) begin.physical.bow_velocity *= -1 controller.note(begin, NOTE_LENGTH, end) controller.filesClose()
def single_file(bow_force, count, K): finger_midi = basic_training.FINGER_MIDIS[self.fmi] # FIXME: oh god ick ap = vivi_types.AudioParams( self.st, finger_midi, dynamics.get_distance(self.inst_type, self.dyn), bow_force, dynamics.get_velocity(self.inst_type, self.dyn)) attack_filename = self.files.make_attack_filename( self.taskname+'-%.2f' % K, ap, count) #print attack_filename self.controller.reset() self.controller.filesNew(attack_filename, self.st) self.controller.comment("attack inst %i st %i dyn %i finger_midi %.3f" % (self.inst_type, self.st, self.dyn, finger_midi)) begin = vivi_controller.NoteBeginning() begin.physical.string_number = self.st begin.physical.dynamic = self.dyn begin.physical.finger_position = utils.midi2pos(finger_midi) begin.physical.bow_force = bow_force begin.physical.bow_bridge_distance = dynamics.get_distance( self.inst_type, self.dyn) begin.physical.bow_velocity = dynamics.get_velocity( self.inst_type, self.dyn) orig_velocity = begin.physical.bow_velocity end = vivi_controller.NoteEnding() #if finger_midi != 0: # self.process_step.emit() # return #print "------" for i, bow_direction in enumerate([1, -1]*RAPS): self.controller.reset(True) #print i, bow_direction begin.physical.bow_velocity = orig_velocity * bow_direction self.controller.note(begin, ATTACK_LENGTH, end) #if i % 4 < 2: # self.controller.note(begin, ATTACK_LENGTH, end) #else: # self.controller.note(begin, SHORT_ATTACK_LENGTH, end) #if i % 4 == 3: #if i % 2 == 1: #if True: #print "reset" # self.controller.reset(True) self.controller.filesClose() self.kept_files.append(attack_filename) self.process_step.emit()
def make_file_force(bow_force, fmi, count): self.controller.set_stable_K(self.st, self.dyn, fmi, K) self.controller.set_stable_K_main(self.st, self.dyn, fmi, K_main) finger_midi = basic_training.FINGER_MIDIS[fmi] # FIXME: oh god ick ap = vivi_types.AudioParams( self.st, finger_midi, dynamics.get_distance(self.inst_type, self.dyn), bow_force, dynamics.get_velocity(self.inst_type, self.dyn)) attack_filename = self.files.make_attack_filename( self.taskname, ap, count) #print attack_filename self.controller.reset() self.controller.filesNew(attack_filename, self.st) self.controller.comment( "verify inst %i st %i dyn %i finger_midi %.3f" % (self.inst_type, self.st, self.dyn, finger_midi)) begin = vivi_controller.NoteBeginning() begin.physical.string_number = self.st begin.physical.dynamic = self.dyn begin.physical.finger_position = utils.midi2pos(finger_midi) begin.physical.bow_force = bow_force begin.physical.bow_bridge_distance = dynamics.get_distance( self.inst_type, self.dyn) begin.physical.bow_velocity = dynamics.get_velocity( self.inst_type, self.dyn) end = vivi_controller.NoteEnding() #end.keep_bow_velocity = True for bow_direction in [1, -1, 1, -1]: self.controller.reset(True) begin.physical.bow_velocity *= bow_direction #begin.physical.bow_force = bow_force #begin.keep_ears = False #begin.keep_bow_force = False #self.controller.note(begin, ATTACK_LENGTH, end) #begin.physical.bow_force = bow_force*0.8 #begin.keep_ears = True #begin.keep_bow_force = True #self.controller.note(begin, STABLE_LENGTH-ATTACK_LENGTH, end) self.controller.note(begin, STABLE_LENGTH, end) self.controller.filesClose() #self.process_step.emit() return attack_filename
def basic_physical_begin_end(self): for note in self.notes: if not self.is_note(note): continue note.begin = vivi_controller.NoteBeginning() note.begin.physical.string_number = self.get_string(note.details) note.begin.physical.finger_position = self.get_finger_naive( note.details, note.begin.physical.string_number) if USE_PITCH: note.begin.midi_target = float(note.details[0][1][0]) else: note.begin.midi_target = -1 note.end = vivi_controller.NoteEnding() if shared.skill > 0: if note.begin.physical.finger_position > 0.0: bad_midi = utils.norm_bounded( float(note.details[0][1][0]), INTONATION_SKILL_BASE * shared.skill) note.begin.physical.finger_position = self.get_finger( bad_midi, note.begin.physical.string_number) note.begin.midi_target = -1
def _make_files(self): self._setup_controller() #print self.test_range #print self.keep_bow_velocity for damp in self.test_range: self.controller.set_dampen(self.st, self.dyn, damp) for count in range(1, self.REPS + 1): begin = vivi_controller.NoteBeginning() begin.physical.string_number = self.st begin.physical.dynamic = self.dyn begin.physical.finger_position = 0.0 begin.physical.bow_force = self.initial_force begin.physical.bow_bridge_distance = dynamics.get_distance( self.inst_type, self.dyn) begin.physical.bow_velocity = dynamics.get_velocity( self.inst_type, self.dyn) filename = self.files.make_dampen_filename( self.taskname, vivi_types.AudioParams( self.st, midi_pos.pos2midi(begin.physical.finger_position), dynamics.get_distance(self.inst_type, self.dyn), begin.physical.bow_force, dynamics.get_velocity(self.inst_type, self.dyn)), damp, count) end = vivi_controller.NoteEnding() end.lighten_bow_force = True end.keep_bow_velocity = self.keep_bow_velocity self.controller.filesNew(filename) self.controller.note(begin, DAMPEN_NOTE_SECONDS, end) self.controller.rest(DAMPEN_WAIT_SECONDS) self.controller.filesClose() self.process_step.emit() return
def _make_files(self): self._setup_controller() #Ks = numpy.linspace(1.0, 2.5, STEPS_X) # skip K=1.0 #Ks = numpy.exp(numpy.linspace( # numpy.log(self.LOW_INIT), # numpy.log(self.HIGH_INIT), # STEPS_X+1))[1:] Ks = numpy.exp(numpy.linspace( numpy.log(self.LOW_INIT), numpy.log(self.HIGH_INIT), STEPS_Y)) #f = self.force_init #forces = [ 0.25*f, 0.5*f, f, 2*f, 4*f ] #forces = [ 0.5*f, f, 2*f ] #forces = self._make_forces(self.force_init, num=9) #forces = [forces[3], forces[4], forces[5]] #forces = numpy.linspace(forces[4], forces[5], num=3) #self.forces_initial = forces #print forces self.forces_init_used = [] #emits = 0 for fmi, finger_midi in enumerate(basic_training.FINGER_MIDIS): #forces = self._make_forces(self.forces_initial[fmi], 9) #forces = numpy.linspace(forces[4], forces[6], num=3, # endpoint=True) #forces = [1.2, 1.35, 1.5] forces = numpy.linspace( self.forces_initial[fmi][1], self.forces_initial[fmi][1] + self.forces_initial[fmi][0], num=3, endpoint=True) #print forces self.forces_init_used.extend(forces) for K in Ks: for bow_force in forces: for count in range(self.REPS): audio_params = vivi_types.AudioParams( self.st, finger_midi, dynamics.get_distance(self.inst_type, self.dyn), bow_force, dynamics.get_velocity(self.inst_type, self.dyn)) stable_filename = self.files.make_stable_filename( audio_params, K, count+1) self.controller.set_stable_K(self.st, self.dyn, K) self.controller.filesNew(stable_filename) self.controller.comment( "stable inst %i st %i dyn %i finger_midi %.3f" % (self.inst_type, self.st, self.dyn, finger_midi)) begin = vivi_controller.NoteBeginning() vivi_types.audio_params_to_physical( audio_params, self.dyn, begin.physical) end = vivi_controller.NoteEnding() #end.keep_bow_velocity = True for bow_direction in [1, -1]: begin.physical.bow_velocity *= bow_direction self.controller.note(begin, STABLE_LENGTH, end) self.controller.filesClose() #emits += 1 #print "emit: %i / %i" % (emits, self.steps_full()) self.process_step.emit()
DAMPEN_NOTE_SECONDS = 1.0 vivi = vivi_controller.ViviController() vivi.set_stable_K(0, 0, 1.1) vivi.load_ears_training(0, "../final/violin/0.mpl") begin = vivi_controller.NoteBeginning() begin.physical.string_number = 0 begin.physical.dynamic = 0 begin.physical.finger_position = 0.0 begin.physical.bow_force = 2.0 begin.physical.bow_bridge_distance = 0.1 begin.physical.bow_velocity = 0.4 end = vivi_controller.NoteEnding() #end.lighten_bow_force = False end.keep_bow_velocity = True DAMPEN_HOPS = 10 DAMPEN_WAIT = 172 def try_thing(basename): vivi.filesNew("test-%s" % basename) vivi.note(begin, DAMPEN_NOTE_SECONDS, end) vivi.m_feedback_adjust_force = False init_force = vivi.actions.bow_force for i in range(DAMPEN_HOPS): if basename == "instant":
def _make_files(self): self._setup_controller() #K = 0.01 K = 0.0 K_main = 0.05 def make_file_force(bow_force, fmi, count): self.controller.set_stable_K(self.st, self.dyn, fmi, K) self.controller.set_stable_K_main(self.st, self.dyn, fmi, K_main) finger_midi = basic_training.FINGER_MIDIS[fmi] # FIXME: oh god ick ap = vivi_types.AudioParams( self.st, finger_midi, dynamics.get_distance(self.inst_type, self.dyn), bow_force, dynamics.get_velocity(self.inst_type, self.dyn)) attack_filename = self.files.make_attack_filename( self.taskname, ap, count) #print attack_filename self.controller.reset() self.controller.filesNew(attack_filename, self.st) self.controller.comment( "verify inst %i st %i dyn %i finger_midi %.3f" % (self.inst_type, self.st, self.dyn, finger_midi)) begin = vivi_controller.NoteBeginning() begin.physical.string_number = self.st begin.physical.dynamic = self.dyn begin.physical.finger_position = utils.midi2pos(finger_midi) begin.physical.bow_force = bow_force begin.physical.bow_bridge_distance = dynamics.get_distance( self.inst_type, self.dyn) begin.physical.bow_velocity = dynamics.get_velocity( self.inst_type, self.dyn) end = vivi_controller.NoteEnding() #end.keep_bow_velocity = True for bow_direction in [1, -1, 1, -1]: self.controller.reset(True) begin.physical.bow_velocity *= bow_direction #begin.physical.bow_force = bow_force #begin.keep_ears = False #begin.keep_bow_force = False #self.controller.note(begin, ATTACK_LENGTH, end) #begin.physical.bow_force = bow_force*0.8 #begin.keep_ears = True #begin.keep_bow_force = True #self.controller.note(begin, STABLE_LENGTH-ATTACK_LENGTH, end) self.controller.note(begin, STABLE_LENGTH, end) self.controller.filesClose() #self.process_step.emit() return attack_filename def split_cats(cats): #notes = [[],[]] notes = [[], [], [], []] notes_i = -1 prev = None for i, cat in enumerate(cats): if cat is None: continue if cat == vivi_defines.CATEGORY_WAIT: continue if cat == vivi_defines.CATEGORY_NULL: prev = None continue if prev is None: notes_i += 1 prev = cat notes[notes_i].append(cat) return notes def get_cats(basename): nac = note_actions_cats.NoteActionsCats() nac.load_file(basename, self.files) #to_find = "finger_midi %i" % basic_training.FINGER_MIDIS[self.fm] to_find = "finger_midi" nac.load_note(to_find, full=True) cats = [b for a, b in nac.get_note_cats()] #att = self.portion_attack(cats_means) #att = cats_means # consider entire note #cost = self.get_cost(att) notes = split_cats(cats) return notes def process_cats(cats): #print len(cats) mean = numpy.mean(cats) return mean # #std = numpy.std(cats) # #exit(1) # #if std > 0.5: # return 0 # if mean < -0.5: # direction = -1 # elif mean > 0.5: # direction = 1 # else: # direction = 0 # return direction def handle_finger(fmi): files = [] init = self.force_init[fmi] #low = scipy.stats.gmean( [init[0], init[1]]) #high = scipy.mean( [init[1], init[2]]) low = init[0] #if low < 0.01: # low = 0.01 high = init[2] # sanity check lows = [] highs = [] mids = [] low_files = [] high_files = [] lows.append(low) highs.append(high) for count in range(1, self.REPS + 1): low_filename = make_file_force(low, fmi, count) low_cats = [] low_cats.extend(sum(get_cats(low_filename), [])) low_direction = process_cats(low_cats) low_files.append((low, low_filename, low_direction)) high_filename = make_file_force(high, fmi, count) high_cats = [] high_cats.extend(sum(get_cats(high_filename), [])) high_direction = process_cats(high_cats) high_files.append((high, high_filename, high_direction)) #print low_direction, high_direction if low_direction > LOW_MEAN_ACCEPTED or high_direction < HIGH_MEAN_ACCEPTED: #print "PANIC: fail to begin attack search" self.verify_good = False self.process_step.emit() self.process_step.emit() def process(force, fmi, lows, mids, highs, low_files, high_files): #print "%.3f\t%.3f\t%.3f" % ( # low, force, high) these_files = [] directions = [] for count in range(1, self.REPS + 1): mid_filename = make_file_force(force, fmi, count) mid_cats = get_cats(mid_filename) mid_direction1 = process_cats(mid_cats[0]) mid_direction2 = process_cats(mid_cats[1]) mid_direction = numpy.mean( (mid_direction1, mid_direction2)) #if mid_direction1 != mid_direction2: # mid_direction1 = 0 these_files.append((force, mid_filename, mid_direction)) directions.append(mid_direction1) if numpy.mean(directions) < LOW_MEAN_ACCEPTED: lows.append(force) #low_files = these_files low_files.extend(these_files) #print "low" elif numpy.mean(directions) > HIGH_MEAN_ACCEPTED: highs.append(force) #high_files = these_files high_files.extend(these_files) #print "high" else: mids.append(force) files.extend(these_files) #print "mid" for count in range(self.REPS): self.process_step.emit() return low_files, high_files while len(mids) == 0: if (len(lows) + len(highs) + len(mids)) >= STEPS: break #force = numpy.mean( (max(lows), min(highs)) ) force = scipy.stats.gmean((max(lows), min(highs))) #print "init", fmi, max(lows), force, min(highs) low_files, high_files = process(force, fmi, lows, mids, highs, low_files, high_files) while True: if (len(lows) + len(highs) + len(mids)) >= STEPS: break #print max(lows), min(mids), max(mids), min(highs) lowdistrel = min(mids) / max(lows) highdistrel = min(highs) / max(mids) #print lowdistrel, highdistrel if lowdistrel > highdistrel: force = scipy.stats.gmean((max(lows), min(mids))) force *= random.uniform(0.95, 1.05) else: force = scipy.stats.gmean((max(mids), min(highs))) force *= random.uniform(0.95, 1.05) #print "main", max(lows), min(mids), max(mids), min(highs) #print "new force:\t", force # do force low_files, high_files = process(force, fmi, lows, mids, highs, low_files, high_files) files.extend(low_files) files.extend(high_files) files.sort() if len(mids) == 1: mids.append(mids[0] * 1.05) elif len(mids) == 0: mids.append(max(lows)) mids.append(min(highs)) self.verify_good = False #self.mids[fmi] = [ min(mids), max(mids) ] self.mids[fmi] = [max(lows), min(highs)] #mids.sort() #print mids return files self.kept_files = [[], [], []] self.mids = [[], [], []] for fmi in range(3): #print '-------------- ', fmi self.kept_files[fmi] = handle_finger(fmi) #print self.mids[fmi] #handle_finger(1, self.kept_files[1]) #handle_finger(2, self.kept_files[2]) #print self.kept_files #print self.mids return #print self.forces #import scipy.special #agm = scipy.special.agm(min(self.forces), max(self.forces)) #agm /= 4.0 #mid = (min(self.forces) + max(self.forces)) / 2 #mid /= 8.0 #lower = list(numpy.linspace(min(self.forces), mid, STEPS/2+1)) ###upper = list(numpy.linspace(agm, max(self.forces), STEPS/2+2))[:-1] #upper = list(numpy.exp( # numpy.linspace( # numpy.log(mid), # numpy.log(max(self.forces)), # STEPS/2+1))) #self.test_range = list(set(lower + upper)) #self.test_range = list(numpy.linspace(min(self.forces), # max(self.forces), STEPS)) #self.test_range = list(numpy.exp( #numpy.linspace( # numpy.log(min(self.forces)), # numpy.log(max(self.forces)), # STEPS))) #print "TEST:", self.test_range #print "fmi:", self.finger_midi_index #print self.forces #self.test_range = self._make_forces(self.forces, 7) self.test_range = [] #forces = self.test_range #self.test_range = numpy.array([forces[0], forces[1], forces[2], # forces[4], # forces[6], forces[7], forces[8]]) #forces = self.test_range K = 1.0 self.controller.set_stable_K(self.st, self.dyn, K) for fmi, finger_midi in enumerate(FINGERS): test_forces = self._make_forces(self.forces[fmi], 9) test_forces = test_forces[3:6] self.test_range.extend(list(test_forces)) #print self.test_range for count in range(self.REPS): # ick #fmi = self.finger_midi_index #finger_midi = self.finger_midi #finger_midi = basic_training.FINGER_MIDIS[fmi] #test_forces = numpy.append(numpy.linspace( # self.forces[fmi][0], # self.forces[fmi][1], # num=3, endpoint=False), # numpy.linspace( # self.forces[fmi][1], # self.forces[fmi][2], # num=4, endpoint=True)) #for a in test_forces: # print "%.3f " % a, #print #test_forces = self.test_range #print test_forces #for fmi, finger_midi in enumerate(basic_training.FINGER_MIDIS): for bow_force in test_forces: audio_params = vivi_types.AudioParams( self.st, finger_midi, dynamics.get_distance(self.inst_type, self.dyn), bow_force, dynamics.get_velocity(self.inst_type, self.dyn)) verify_filename = self.files.make_verify_filename( self.taskname, audio_params, count) #print verify_filename self.controller.filesNew(verify_filename) self.controller.comment( "verify int %i st %i dyn %i finger_midi %.3f" % (self.inst_type, self.st, self.dyn, finger_midi)) begin = vivi_controller.NoteBeginning() vivi_types.audio_params_to_physical( audio_params, self.dyn, begin.physical) end = vivi_controller.NoteEnding() end.keep_bow_velocity = True #for bow_direction in [1, -1]: # begin.physical.bow_velocity *= bow_direction # self.controller.note(begin, STABLE_LENGTH, end) #print "Starting note, force:", bow_force self.controller.note(begin, STABLE_LENGTH, end) self.controller.filesClose() self.process_step.emit()