Exemplo n.º 1
0
def test_beat3a(server):
    inp = pyo.Input([0, 1])
    mix = pyo.Mix(inp)

    ad = pyo.AttackDetector(mix, 0.005, 10, 3, -30, 0.1)
    ad.ctrl()
    tmr = pyo.Timer(ad, ad)
    prn = pyo.Print(tmr, 1, message='tmr')
    return ad, prn
Exemplo n.º 2
0
def test_beat3b(server):
    inp = pyo.Input([0, 1])
    mix = pyo.Mix(inp)

    flr1 = pyo.Follower2(mix, 0.005, 0.005)
    spl1 = pyo.AToDB(flr1)
    flr2 = pyo.Follower2(mix, 0.1, 0.1)
    spl2 = pyo.AToDB(flr2)
    diff = spl2 - spl1
    thr = pyo.Thresh(diff, 6)
    nxt = pyo.TrackHold(diff, thr, 1)
    tmr = pyo.Timer(thr, thr)
    prn = pyo.Print(tmr, 1, message='thr')

    return prn, nxt
Exemplo n.º 3
0
def test_beat1(server):

    server.server_ms = 0
    last_ms = 0
    server.last_bpm = 0
    server.bpms = []
    server.last_avg = 0

    def trig_func():
        #ct = server.getCurrentTime()
        delta = server_ms - last_ms
        last_ms = server_ms
        
        #delta = ct - last_ct
        #bpm = 
        print(delta, 'trig')

    def time_callback(hours, minutes, seconds, milliseconds):
        #print(hours, minutes, seconds, milliseconds)
        server.server_ms = hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds

    def process_callback():
        if ad.minthresh != thr.get():
            ad.minthresh = thr.get()
        #if server.last_avg != avg.get():
        #    print('avg', avg.get())
        #    server.last_avg = avg.get()
        return 
        #bpm = 120 / (tmr.get() or 0.001)
        #while bpm > 360:
        #    bpm /= 2
        #while bpm < 40:
        #    bpm *= 2
        #print('bpm?', bpm)
        data = table.getTable()
        if len(data):
            #data = [d for d in data if d]
            #print(len(data), sum(data), server.server_ms)
            bpm = len(data) * 60 / (sum(data) or 0.001)
            while bpm > 360:
                bpm /= 2
            while bpm < 40:
                bpm *= 2
            #server.bpms.append()
            bpm = int(bpm)
            if bpm != server.last_bpm:
                server.last_bpm = bpm
                print('bpm?', bpm)
        
        table.reset()
        #tfl.play()
            #print(ad.minthresh)

    server.setTimeCallable(time_callback)
    server.setCallback(process_callback)

    table = pyo.DataTable(size=32) 

    inp = pyo.Input([0, 1])
    mix = pyo.Mix(inp)
    
    flr = pyo.Follower2(mix, 0.5, 0.5)
    fla = pyo.Average(flr, server.getBufferSize())
    #flr.ctrl()
    spl = pyo.AToDB(flr)
    thr = spl - 6
    ad = pyo.AttackDetector(mix, 0.005, 1000, 12, -30, 0.05)
    #ad.ctrl()
    #prn = pyo.Print(ad, 1, message='ad')
    prn = None
    tmr = pyo.Timer(ad, ad)
    #avg = pyo.Average(tmr, server.getBufferSize())
    #bpm = 60 / pyo.Min(tmr, 0.001)
    #trg = pyo.TrigFunc(ad, trig_func)
    prn2 = pyo.Print(tmr, 1, message='tmr')
    #tfl = pyo.TableFill(tmr, table)
    return ad, prn, thr, prn2
    def __init__(self, master=None, experiment=[], logger=None):
        
        ###########################
        # INIT EXPERIMENT
        ###########################
        self.experiment=experiment

        
        ###########################
        # INIT LOGGING
        ###########################
        self.logger=logger
        self.currentTrial = 0
        self.currentBlock = 0
        self.blockType = 0
        self.mouse = 0
        
        ###########################
        # INIT TIMING
        ###########################
        #self.t = timr(1, self.runexperiment) #placeholder to make sure the variable exists
        self.timers = []
        
        ###########################
        # INIT VISUAL
        ###########################
        self.waitForRatingAnswer = False
        self.waitForRatingAnswer2 = False
        self.numRects = 4
        self.rects=range(self.numRects)
        self.screenWidth = 640
        self.screenHeight = 480
        Frame.__init__(self,master)
        self.grid()
        self.userPrompt = StringVar()
        
        # moved these up here so they only happen once
        pianoimage = Image.open(KEYBOARD_IMAGE)
        self.pianoImage = ImageTk.PhotoImage(pianoimage)
        sliderimage = Image.open(SLIDER_IMAGE)
        self.sliderImage = ImageTk.PhotoImage(sliderimage)
        self.fingerString = StringVar()
        self.qString = StringVar()
        self.countString = StringVar()

        self.create_GUI()

        
        ###########################
        # INIT AUDI
        ###########################
        self.s = pyo.Server(buffersize = 8, nchnls = 1)
        
        # before booting the server, I'll prompt the user to choose an input device
        # NOTE: This can be hard-coded later if you always want it to choose a specific MIDI input device
#         pyo.pm_list_devices()
#         self.choice = input("Which device will you choose?")        
#         self.s.setMidiInputDevice(int(self.choice))
    
        self.s.setMidiInputDevice(int(3))
        
        self.s.boot()        
        self.s.start()
        
#         test = pyo.LFO(freq=440.0).out()
        
        time.sleep(1) # settling time
        
#         test.stop()
        
        # MIDI Stuff
        self.refnote = 72
        self.polynum = 4
        self.pianosound = range(self.polynum)
        self.notes = pyo.Notein(poly=self.polynum, scale=0, mul=0.5)
        self.enablePlayback = False
        self.enableNoteLogging = False
        self.noteTrig = pyo.TrigFunc(self.notes['trigon'],self.onNoteon,range(self.polynum))
        #for p in range(polynum):
        
        # note trigger mixer
        self.trigmix = pyo.Mixer(1,self.polynum)
        for p in range(self.polynum):
            self.trigmix.addInput(p,self.notes['trigon'][p])
            self.trigmix.setAmp(p,0,1.0)
        self.polyNoteTrig = self.trigmix[0]
            
        global midikeymapping # needs to be visible everywhere
        midikeymapping = 1 # set mapping to 1 to start with

        # preload sound files
        self.melodies = []
        self.extract = []
        
        for i in range(self.polynum):
            self.pianosound[i] = pyo.SfPlayer(EXTRACT_DIR + PIANO_FILE[0], speed=1, loop=False, offset=0, interp=2, mul=1, add=0)                
        for fname in STIM_FILES:
            self.melodies.append(pyo.SfPlayer(STIM_DIR + fname, mul=0.5))
        for fname in EXTRACT_FILES:
            self.extract.append(pyo.SfPlayer(EXTRACT_DIR + fname, mul=0.5))
        self.metronome = pyo.SfPlayer(EXTRACT_DIR + METRO_FILE[0], mul=0.5)
        
        # prepare sequence and timing triggers
        # metroSeq launches the metronome
        self.trialMetroSeq = pyo.Seq(time=NOTEDUR/1000.0, seq=[3,3,3,1], poly=1, onlyonce=True, speed=1)
        self.expectedKeySeq = pyo.Seq(time=NOTEDUR/1000.0, seq=[9,1,1,1,1], poly=1, onlyonce=True, speed=1)
        # trialStartTrigger will be manually launched when we want to start a trial
        self.trialStartTrigger = pyo.Trig().stop()
        self.warmuptrialStartTrigger = pyo.Trig().stop()
        self.dummyTrigger = pyo.Trig().stop()
        self.timerLogsEnabled = False
        # eventTimer will measure the time between trial events
        # eventTimer is initially triggered by the trial start, but will later be switched to measure between note events
        self.trialEventTimer = pyo.Timer(self.polyNoteTrig,self.trialStartTrigger)
        self.expectedEventTimer = pyo.Timer(self.expectedKeySeq,self.expectedKeySeq)
        self.timerMeasurement = pyo.DataTable(1)
        self.lastTimerMeasurement = 0.0
        self.expectedMeasurement = pyo.DataTable(1)
        self.lastExpectedMeasurement = 0.0
        self.measurementRecorder = pyo.TablePut(self.trialEventTimer, self.timerMeasurement).play()
        self.expectedRecorder = pyo.TablePut(self.expectedEventTimer, self.expectedMeasurement).play()
        self.resetAtStim = False

        
        # triggers for the optimized stim delivery
        self.t1 = pyo.TrigFunc(self.trialStartTrigger,self.playAudioExtract)
        self.t2 = pyo.TrigFunc(self.trialStartTrigger,self.trialMetroSeq.out)
        self.t2b = pyo.TrigFunc(self.trialStartTrigger,self.expectedKeySeq.out)
        self.t3 = pyo.TrigFunc(self.trialMetroSeq,self.playMetronome)
#         self.t3 = pyo.TrigFunc(self.trialMetroSeq,self.metronome.out)
        self.t4 = pyo.TrigFunc(self.polyNoteTrig,self.noteTiming)
        self.t5 = pyo.TrigFunc(self.expectedKeySeq,self.expectedTiming)

        # triggers for the optimized stim delivery in training
        #self.t1 = pyo.TrigFunc(self.warmuptrialStartTrigger,self.playAudioExtract)
        self.t6 = pyo.TrigFunc(self.warmuptrialStartTrigger,self.trialMetroSeq.out)
        self.t7 = pyo.TrigFunc(self.warmuptrialStartTrigger,self.expectedKeySeq.out)
#         self.t3 = pyo.TrigFunc(self.trialMetroSeq,self.playMetronome)
#         self.t3 = pyo.TrigFunc(self.trialMetroSeq,self.metronome.out)
#         self.t4 = pyo.TrigFunc(self.notes['trigon'],self.noteTiming)
#         self.t5 = pyo.TrigFunc(self.expectedKeySeq,self.expectedTiming)

        
        ###########################
        # INIT INPUT DEVICES
        ###########################
        self.set_keybinds()
        self.waitForSpacebar = True

        ############################
        self.enableAudioFeedback = False
        self.QUIT = False
        self.pause = False