コード例 #1
0
ファイル: style_base.py プロジェクト: gperciva/vivi
 def get_simple_force(self, st, finger_position, dyn):
     # TODO: this function is icky
     low_index = 0
     high_index = 0
     # ASSUME: FINGER_MIDIS is already sorted
     fm = utils.pos2midi(finger_position)
     for i, val in enumerate(basic_training.FINGER_MIDIS):
         if fm >= val:
             low_index = i
             high_index = i+1
     if high_index >= len(basic_training.FINGER_MIDIS):
         high_index = len(basic_training.FINGER_MIDIS) - 1
     force = utils.interpolate(fm,
         basic_training.FINGER_MIDIS[low_index],
         self.controller_params[st][int(dyn+0.5)].get_attack_force(low_index),
         basic_training.FINGER_MIDIS[high_index],
         self.controller_params[st][int(dyn+0.5)].get_attack_force(high_index))
     #print force
     return force
コード例 #2
0
ファイル: note_actions_cats.py プロジェクト: gperciva/vivi
    def make_zoom_file(self, start, dur, files):
        print "make_zoom_file, range of seconds from orig:  %.3f  %.3f" % (
            start, dur)
        self.files = files
        force = 0.0
        ### get params from note
        #print starthop, endhop

        ### quantify based on hopsize
        starthop = int((start - self.note_start) * HOP_SECONDS)
        endhop = int((start + dur - self.note_start) * HOP_SECONDS)
        # no, *don't* make this based on the note,
        # otherwise it won't work in music!
        start = float(int(start * HOP_SECONDS)) / HOP_SECONDS
        dur = float(int(endhop - starthop)) / HOP_SECONDS

        print "starthop, endhop:\t%i\t%i" % (starthop, endhop)
        print "Should have lines:\t%i" % (endhop - starthop + 1)
        #print "start, dur:\t%i\t%i" % (start, dur)

        #for l in self.note_lines:
        #    print l

        #print start, dur
        ### initial note estimates
        # assume string doesn't change
        fm = self.note_finger
        bbd = 0.0
        force = 0.0
        bv = 0.0
        #for i in range(0, starthop+1):
        for i in range(0, starthop + 1):
            line = self.note_lines[i].split()
            if line[0] == 'b' or line[0] == 'a':
                bbd = float(line[3])
                force = float(line[4])
                bv = float(line[5])
            if line[0] == 'f':
                fm = utils.pos2midi(float(line[3]))
        bbd = [bbd]
        force = [force]
        bv = [bv]
        for i in range(0, starthop + 1):
            line = self.note_lines[i].split()
            if line[0] == 'b' or line[0] == 'a':
                bbd.append(float(line[3]))
                force.append(float(line[4]))
                bv.append(float(line[5]))
            if line[0] == 'f':
                fm = utils.pos2midi(float(line[3]))
        audio_params = vivi_types.AudioParams(self.note_st, fm,
                                              numpy.median(bbd),
                                              numpy.median(force),
                                              numpy.median(bv))

        ### filename
        filename = self.files.make_zoom_filename(audio_params)
        print "ZOOM file:\t", filename

        # create .wav
        cmd = 'sox %s -t wavpcm %s trim %f %f' % (self.basename + '-s%i.wav' %
                                                  (self.note_st), filename +
                                                  '.wav', start, dur)
        #print cmd
        os.system(cmd)
        # create .forces..wav
        cmd = 'sox %s -t wavpcm %s trim %f %f' % (
            self.basename + '-s%i.forces.wav' %
            (self.note_st), filename + '.forces.wav', start, dur)
        #print cmd
        os.system(cmd)
        # create .actions
        out = open(filename + '.actions', 'w')
        out.write(self.note_prelim_line)
        # TODO: clean this up!
        #first_seconds = -1
        printed_finger = False
        #num_lines = 0
        for line in self.note_lines:
            splitline = line.split()
            seconds = float(splitline[1])
            #print seconds, first_seconds, start, start+dur
            if line[0] == 'f':
                fm = float(splitline[3])
            if seconds >= (start - 0.001):
                #if first_seconds < 0:
                #    first_seconds = seconds
                #seconds = seconds - first_seconds
                if seconds <= (start + dur + 0.001):
                    now = round(seconds - start, 3)
                    if now == -0.0:
                        now = 0.0
                    splitline[1] = str(now)
                    if not printed_finger:
                        if splitline[0][0] == 'f':
                            pass
                        else:
                            data = [
                                'f',
                                str(now),
                                str(self.note_st),
                                str(utils.midi2pos(fm))
                            ]
                            finger_line = "\t".join(data) + "\n"
                            print finger_line,
                            out.write(finger_line)
                        printed_finger = True
                    done_line = "\t".join(splitline) + "\n"
                    print done_line,
                    out.write(done_line)
        out.close()

        return filename
コード例 #3
0
ファイル: note_actions_cats.py プロジェクト: gperciva/vivi
    def make_zoom_file(self, start, dur, files):
        print "make_zoom_file, range of seconds from orig:  %.3f  %.3f" % (start, dur)
        self.files = files
        force = 0.0
        ### get params from note
        #print starthop, endhop

        ### quantify based on hopsize
        starthop = int((start-self.note_start) * HOP_SECONDS)
        endhop = int((start+dur-self.note_start) * HOP_SECONDS)
        # no, *don't* make this based on the note,
        # otherwise it won't work in music!
        start = float(int(start * HOP_SECONDS)) / HOP_SECONDS
        dur = float( int(endhop-starthop)) / HOP_SECONDS

        print "starthop, endhop:\t%i\t%i" % (starthop, endhop)
        print "Should have lines:\t%i" %(endhop-starthop+1)
        #print "start, dur:\t%i\t%i" % (start, dur)

        #for l in self.note_lines:
        #    print l

        #print start, dur
        ### initial note estimates
        # assume string doesn't change
        fm = self.note_finger
        bbd = 0.0
        force = 0.0
        bv = 0.0
        #for i in range(0, starthop+1):
        for i in range(0, starthop+1):
            line = self.note_lines[i].split()
            if line[0] == 'b' or line[0] == 'a':
                bbd = float(line[3])
                force = float(line[4])
                bv = float(line[5])
            if line[0] == 'f':
                fm = utils.pos2midi(float(line[3]))
        bbd = [bbd]
        force = [force]
        bv = [bv]
        for i in range(0, starthop+1):
            line = self.note_lines[i].split()
            if line[0] == 'b' or line[0] == 'a':
                bbd.append( float(line[3]) )
                force.append( float(line[4]) )
                bv.append( float(line[5]) )
            if line[0] == 'f':
                fm = utils.pos2midi(float(line[3]))
        audio_params = vivi_types.AudioParams(
            self.note_st, fm,
                numpy.median(bbd),
                numpy.median(force),
                numpy.median(bv))

        ### filename
        filename = self.files.make_zoom_filename(audio_params)
        print "ZOOM file:\t", filename

        # create .wav
        cmd = 'sox %s -t wavpcm %s trim %f %f' % (
            self.basename+'-s%i.wav' % (self.note_st),
            filename+'.wav', start, dur)
        #print cmd
        os.system(cmd)
        # create .forces..wav
        cmd = 'sox %s -t wavpcm %s trim %f %f' % (
            self.basename+'-s%i.forces.wav' % (self.note_st),
            filename+'.forces.wav', start, dur)
        #print cmd
        os.system(cmd)
        # create .actions
        out = open(filename+'.actions', 'w')
        out.write(self.note_prelim_line)
        # TODO: clean this up!
        #first_seconds = -1
        printed_finger = False
        #num_lines = 0
        for line in self.note_lines:    
            splitline = line.split()
            seconds = float(splitline[1])
            #print seconds, first_seconds, start, start+dur
            if line[0] == 'f':
                fm = float(splitline[3])
            if seconds >= (start - 0.001):
                #if first_seconds < 0:
                #    first_seconds = seconds
                #seconds = seconds - first_seconds
                if seconds <= (start + dur + 0.001):
                    now = round(seconds - start, 3)
                    if now == -0.0:
                        now = 0.0
                    splitline[1] = str(now)
                    if not printed_finger:
                        if splitline[0][0] == 'f':
                            pass
                        else:
                            data = ['f', str(now),
                                str(self.note_st),
                                str(utils.midi2pos(fm))]
                            finger_line = "\t".join(data) + "\n"
                            print finger_line,
                            out.write(finger_line)
                        printed_finger = True
                    done_line = "\t".join(splitline) + "\n"
                    print done_line,
                    out.write(done_line)
        out.close()

        return filename