def __init__(self, audiolist): threading.Thread.__init__(self) self.thread_init() self.AudioFiles = audiolist ###preload sounds into vizard. for af in self.AudioFiles: viz.playsound(af, viz.SOUND_PRELOAD) #NEEDS TO PRE-LOAD THE SOUND
def updateCounter(objBeingSold): global counter, SELLABLES, sellNarrative, selector, APARTMENT, SCENE if objBeingSold in SELLABLES: counter.decrementValue(LABEL_DATA, objBeingSold.cost, DAYS_PASS_PER_SELL) LABEL_DATA[1].value -= objBeingSold.cost LABEL_DATA[0].value -= DAYS_PASS_PER_SELL print "decremented" print LABEL_DATA[1].value print LABEL_DATA[0].value if LABEL_DATA[0].value == 0: yield viztask.waitTime(1) finalEvictNarrative.play() selector.disable() duration = finalEvictNarrative.getDuration() yield viztask.waitTime(duration) vizact.ontimer2(0.1,10,Events.addFlickeringLight,APARTMENT,SCENE) Events.stopFan(APARTMENT, SCENE) else: yield viztask.waitTime(1) viz.playsound(PLEASE_SELL_AUDIO)
def sellSelectedObject(objectToSell=None): if SELL_ON_CLICK: global SELLABLES if selector.select() not in SELLABLES: selector.disable() waitForNextClick() else: objectToSell = selector.select() global dc print 'selling object...' objectToSell.addAction(OBJ_FADE_ACTION) viztask.waitTime(0.2) viztask.schedule(updateCounter(objectToSell)) viz.playsound(SELL_AUDIO) recordSellData(objectToSell, dc) yield viztask.waitTime(OBJ_FADETIME) objectToSell.remove() selector.crosshairWithCallback.visible(False) #hide green cross hair if SELL_ON_CLICK and selector.enabled: waitForNextClick()
def __PlayNextSound(): global SOUND_QUEUE, LAST_INDEX, PLAYING_SOUND, SOUND_FINISHED_CALLBACK if PLAYING_SOUND == None: # This shouldn't happen return # Search through the sound queue, starting at the last played sound # to find the next sound waiting to be played index = PLAYING_SOUND while index <= LAST_INDEX and not SOUND_QUEUE.has_key(index): index = index + 1 if index <= LAST_INDEX: PLAYING_SOUND = index # play the next sound viz.playsound(SOUND_QUEUE[index]["filename"]) # start a timer to tell us when the sound is finished viz.starttimer(SOUND_FINISHED_CALLBACK, SOUND_QUEUE[index]["length"]) else: # No sounds were waiting to be played PLAYING_SOUND = None
def __init__(self, filename, maxtargetnumber, ppid, triallength, ntrials=None, startscreentime=2): viz.EventClass.__init__(self) #needs to be an eventclass for timer to work. self.callback(viz.EXIT_EVENT, self.CloseConnections) #if exited, save the data. ##PARAMETERS THAT DO NOT VARY PER TRIAL self.ppid = ppid self.filename = filename self.AudioList = [] #load once at start. List of audio-files self.StartScreen_DisplayTime = startscreentime #amount of seconds that the targets for that trial are shown. #letters = ['a','b','c','d','e','i','o']#,'f','g']#,'h','i','j','k','l']#,'m','n','o'] #letters = ['a','b','k','h','f','i','o']#,'f','g']#,'h','i','j','k','l']#,'m','n','o'] #don't rhyme. self.letters = [ 'b', 'o', 'h', 'k', 't', 'l', 'f', 's', 'i', 'a', 'm', 'n', 'y', 'r', 'j' ] #target letters are the front two. Need to be paired with three distractors. l = len(self.letters) #self.LetterLength for i in range(l): a = self.letters[i] #self.AudioList.append(viz.addAudio('..\\textures\\audio-numbers\\' + a + '.wav')) #self.AudioList.append(viz.addAudio('C:\\VENLAB data\\shared_modules\\textures\\Alphabet_Sounds\\' + a + '.wav')) self.AudioList.append( 'C:\\VENLAB data\\shared_modules\\textures\\Alphabet_Sounds\\' + a + '.wav') #append file paths so you can use viz.SOUND_PRELOAD #preload sounds for af in self.AudioList: viz.playsound(af, viz.SOUND_PRELOAD) # self.SoundPlayer_threaded = SoundPlayer_threaded(self.AudioList) #load thread # self.SoundPlayer_threaded.start() #start the threaed self.Target_pool = self.letters[: maxtargetnumber] #returns list up to maxtargetnumber self.Distractor_pool = self.letters[maxtargetnumber:] self.nTrials = ntrials self.Trial_length = triallength #length of trial. Is usually constant. self.EndofTrial_Data, self.WithinTrial_Data_writer, self.WithinTrial_Data_file = self.BuildDataFrames( maxtargetnumber) self.MaxTargetNumber = maxtargetnumber #PARAMETERS THAT ARE SET AT THE START OF EACH TRIAL self.Trial_targets = [] #targets for that particular trial. self.Trial_audioindexes = [ ] #empty list that is populated with indexes corresponding to places on the audio list. Targets will be the first N of the letter array, depending on trial number. self.Trial_targetoccurence_prob = 0 #trial parameters, target occurence self.Trial_targetnumber = 0 #trial parameters, target number self.Trial_targetcounts = [ ] #empty list with actual self.Trial_targetnumber counts. self.Trial_EoTscores = [ ] #empty list with self.Trial_targetnumber user inputted counts. self.Trial_N = 0 self.Trial_Timer = 0 #keeps track of trial length. self.StartScreen_Timer = 0 #self.Trial_Index = 0 #count for number of Trails, to index Trial dataframe. Isn't needed as Trial_N gets passed on StartTrial. # PARAMETERS THAT VARY WITHIN TRIALS self.ON = 0 #flag denoting whether to enter the loop that records data self.targetDelay = [] #randomly varies between 1-1.5s self.currentaudio = None # currently heard stimuli self.currentaudio_type = None # currently heard stimuli self.ResponseStamp = 0 #time of response self.Stimuli_PlayedStamp = 0 #time of stimuli presentation self.delay = 1.25 #this is how quickly you want items repeated. Changes per stimuli. self.Overall_Stimuli_Index = 0 #count for number of stimuli, to index response dataframe. self.Trial_Stimuli_Index = 0 #count for number of stimuli, to index response dataframe. self.callback(viz.TIMER_EVENT, self.onTimer, priority=0) self.Stimuli_Timer = 0 #between - presentation timer. self.interval = 0.1 #delay randomly varies between 1 - 1.5 at .1 increments. self.targetTimer = 0 self.targetInterval = 0 self.starttimer(0, self.interval, viz.FOREVER) self.QuitFlag = 0 self.ppresp = 0 #flag to say that participant has responded. self.EoTFlag = False #set to True when it is the EoT screen. self.PlaySoundFlag = False #set to true when start screen time elapses. #Flag that is called by the main experiment to know when to stop pausing. self.EoT_NumberofResponses = 0 #count to say how many counts have been inputted. ### END OF TRIALS SCREEN ### self.EoTScreen = viz.addTexQuad(viz.SCREEN) self.EoTScreen.color(viz.BLACK) self.EoTScreen.setPosition(.5, .6) self.EoTScreen.setScale(100, 100) self.EoTScreen.visible(viz.OFF) self.EndofTrial_Question = 'How many Xs did you hear? \n \n Press a single gear pad to register your count' self.Question = viz.addText(self.EndofTrial_Question, viz.SCREEN) self.Question.color(1, 1, 0) self.Question.setPosition(0.5, 0.75) self.Question.fontSize(36) self.Question.alignment(viz.TEXT_CENTER_TOP) self.Question.visible(viz.OFF) self.lblscore = viz.addText('-1', viz.SCREEN) self.lblscore.setPosition(0.5, 0.4) self.lblscore.fontSize(50) self.lblscore.alignment(viz.TEXT_CENTER_CENTER) self.lblscore.visible(viz.OFF) self.CurrentScore = -1 #for on-screen score to be submitted as user count. ### START OF TRIALS SCREEN #### self.StartScreen = viz.addTexQuad(viz.SCREEN) self.StartScreen.color(viz.BLACK) self.StartScreen.setPosition(.5, .5) self.StartScreen.setScale(100, 100) self.StartScreen.visible(viz.OFF) self.Start_msg = 'Listen out for: \n \n' self.Starttxt = viz.addText(self.Start_msg, viz.SCREEN) self.Starttxt.color(1, 1, 0) self.Starttxt.setPosition(0.5, 0.5) self.Starttxt.fontSize(36) self.Starttxt.alignment(viz.TEXT_CENTER_TOP) self.Starttxt.visible(viz.OFF)