예제 #1
0
def update_task(worker, target_time=0):
    successful_response = None
    print('update_task')
    worker.send(state.request)
    lagging = False
    while True:
        response = worker.recv()
        if isinstance(response, Failure):
            raise FailureException(response)
        elif isinstance(response, Success):
            successful_response = response
            break
        if target_time < get_time():
            lagging = True
            audio.stop()
        yield CB_TIME

    while True:
        current_time = get_time()
        if target_time < current_time:
            state.buffer_surface = successful_response.data.get_surface(
            )  #type: ignore
            set_output(successful_response.result, '')
            drawing_area.queue_draw()
            break
        yield CB_TIME
    return lagging
예제 #2
0
def play_snd(fname):
    frame = audio.AudioFrame()
    with open(fname, 'rb') as sndfile:
        audio.play(frames_from_file(sndfile, frame), wait=False)
        sleep(1000)
        audio.stop()
    del frame
예제 #3
0
def play_snd(fname, num_times):
    frame = audio.AudioFrame()

    for i in range(num_times):
        with open(fname, 'rb') as sndfile:
            audio.play(frames_from_file(sndfile, frame), wait=True)
    del frame
    audio.stop()
예제 #4
0
def show_wave(name, frame, duration=1500):
    display.scroll(name + " wave", wait=False,delay=100)
    audio.play(repeated_frame(frame, duration),wait=False)
    for i in range(75):
        sleep(100)
        if button_a.is_pressed():
            display.clear()
            audio.stop()
            break
예제 #5
0
def show_wave(name, frame, duration=1500):
    display.scroll(name + " wave", wait=False, delay=100)
    audio.play(repeated_frame(frame, duration), wait=False)
    for i in range(75):
        sleep(100)
        if button_a.is_pressed():
            display.clear()
            audio.stop()
            break
예제 #6
0
def main_task():
    while True:
        while not state.running:
            print('IDELE')
            yield None
        worker = Worker()
        state.compile_needed = True
        try:
            while True:
                if state.compile_needed:
                    state.compile_needed = False
                    set_status_bar_text('Program starting.')
                    # wait until worker is ready
                    for i in range(10):
                        if not worker.is_working():
                            break
                        yield CB_TIME
                    else:  # tired of waiting
                        worker = Worker()  # kill and replace

                    yield from yield_from_while(
                        compile_task(worker),
                        lambda: state.running and not state.compile_needed)
                    if not state.running:
                        raise FailureException('Program aborted.')
                    set_status_bar_text('Program running.')

                else:
                    yield from yield_from_while(
                        show_task(worker),
                        lambda: state.running and not state.compile_needed)
                    if not state.running:
                        raise FailureException('Program aborted.')
        except FailureException as e:
            f = e.failure
            set_output(f.output, f.error)
            audio.stop()
            if state.playing:
                state.switch_playing(None)
        del worker
        if not state.running:
            set_status_bar_text('No program running.')
        else:
            set_status_bar_text(
                'An error occured, program temporarily paused.')
        yield None
예제 #7
0
 def present_trial(self, trial):
     if trial['stim1'] != '':
         self.image.image = self.stimuli_folder + trial['stim1'] + trial[
             'stimFormat']
         self.image.draw()
     elif trial['text'] != '':
         self.text.text = trial['text']
         self.text.draw()
     self.win.callOnFlip(self.clock.reset)
     self.isi.complete()
     self.win.flip()
     if trial['trialAudio'] != '':
         #self.instructions[trial['trialAudio']].play()
         audio.play(self.instructions[trial['trialAudio']], wait=False)
     if trial['keyboard'] != '':
         keys = event.waitKeys(keyList=['escape'] +
                               trial['keyboard'].split(' '),
                               timeStamped=self.clock)
         trial['keypress'], trial['RT'] = keys[0]
         if trial['keypress'] == 'escape':
             core.quit()
         if trial['keypress'] == trial['key']:
             trial['ACC'] = 1
         else:
             trial['ACC'] = 0
         if trial['trialAudio'] != '':
             #self.instructions[trial['trialAudio']].stop()
             audio.stop()
     else:
         if trial['presTime'] != '':
             core.wait(float(trial['presTime']) / 1000 - self.frame_dur)
         elif trial['trialAudio'] != '':
             core.wait(
                 len(self.instructions[trial['trialAudio']]) / 44100.0)
             #core.wait(self.instructions[trial['trialAudio']].getDuration())
     self.win.callOnFlip(self.isi.start,
                         float(trial['ITI']) / 1000 - self.frame_dur)
     # flip buffer again and start ISI timer
     self.win.flip()
     return trial
예제 #8
0
def listen():
    '''Listens for input, delegating input to the processing when recieved.'''

    #ui.write_cmd_line('Type \'' + __INPUT_TRIGGER__ + '\' to begin command input.')
    #audio.add_to_playlist(['test.mp3'])
    #audio.add_to_playlist(['test2.mp3'])
    #audio.add_to_playlist(['test.flac'])
    #audio.add_to_playlist(['test.m4a'])
    #audio.play_playlist_no(1)

    # Enter infinite (blocking) loop waiting for input.
    # We refresh to clear previous input / output, then await input trigger, at which point we capture input (terminated with ENTER) and process it.
    # NOTE: Resizing the terminal window is processed as input. This causes the loop to execute and refreshes the UI to match the new window size.
    quit_app = False
    while not quit_app:
        update()
        key = ui.__stdscr.getkey()

        if key in __PLAY_PAUSE__:
            audio.play_pause()
        elif key in __STOP__:
            audio.stop()
        elif key in __SEL_NEXT__:
            audio.sel_next_track()
        elif key in __PLAY_NEXT__:
            audio.sel_next_track()
            audio.play_current()
        elif key in __SEL_PREV__:
            audio.sel_prev_track()
        elif key in __PLAY_PREV__:
            audio.sel_prev_track()
            audio.play_current()

        elif key == __INPUT_TRIGGER__:
            cmd = ui.read_cmd_line()

            try:
                quit_app = process_input(cmd)
            except:
                update("Invalid input")
예제 #9
0
 def OnPause(self, endoflist=False):
     self.cue.resume = audio.stop(self.cue.hStream)
     if endoflist or self.cue.resume == -1.0:
         self.cue.resume = self.GetTrackFinishTime()
     self.parent.ListBox.List.reInitBuffer = True
예제 #10
0
 def OnStop(self):
     audio.stop(self.cue.hStream)
예제 #11
0
파일: interface.py 프로젝트: modrzew/ekoie
def quit():
    """Close application gracefully"""
    audio.stop()
    sys.exit(0)
예제 #12
0
파일: interface.py 프로젝트: modrzew/ekoie
 def h_stop(self, key):
     """Stops currently played track"""
     audio.stop()
     self.parentApp.notify('Stopped.')
     self.set_status('Ready to play')
예제 #13
0
def main():
    '''Start terminal screen and set up'''

    if "-h" in sys.argv or "-help" in sys.argv:
        print (___HELP__);

    else:
        start_app()


# -----------------------------------------
# Entry point
# -----------------------------------------

failure = False
failure_msg = ''

try:
    main()
except BaseException as e:
    failure = True
    failure_msg = str(e)
finally:
    if app_started:
        ui.deinit()
    audio.stop()

    if failure:
        print("Unexpected failure! Safely handled.\nException:{}".format(failure_msg))
def stop():
    audio.stop()
예제 #15
0
 def do_quit(self):
     self.master.destroy()
     audio.stop()
예제 #16
0
def process_input(cmd):
    '''Processes the provided input command, executing appropriate logic.'''

    cmd_list = cmd.split()

    def is_command(expected_cmds):
        '''Helper method to check if the first element of the command args matches any provided element of a list
           If true is returned, the app should be terminated.'''
        for cmd_i in expected_cmds:
            if cmd_list[0] == cmd_i:
                return True
        return False

    def has_arg(expected_args):
        '''Helper method to check if the command contains any of the provided expected_args'''
        for arg_i in expected_args:
            if arg_i in cmd_list:
                return True
        return False

    # If we have one or more args, attempt to process
    if len(cmd_list) > 0:

        # Basic commands without args
        if is_command(['help', 'h']):
            show_help()
        elif is_command(['refresh', 'rf']):
            ui.refresh()
        elif is_command(['quit', 'q']):
            return True

        # Commands with optional/mandatory args

        # Play the specified file.
        elif is_command(['play', 'p']):
            if len(cmd_list) > 1:
                if audio.get_playback_state(
                ) is not audio.PlaybackState.STOPPED:
                    audio.stop()
                if has_arg(['-file', '-f']):  # play filename
                    audio.play(cmd_list[2])
                    update('Playing file {}'.format(cmd_list[2]))
                else:  # play playlist index
                    audio.play_playlist_no(int(cmd_list[1]))
                    update('Playing playlist item {}'.format(cmd_list[1]))
            else:
                audio.play_pause()
                update('Playing/pausing current track')

        # Stops playback
        elif is_command(['stop', 's']):
            audio.stop()
            update('Stopped current track')

        # Add all files listed to the playlist
        elif is_command(['add', 'a']):
            if has_arg(["-dir"]):
                count = 0
                directory = os.fsencode(os.getcwd())
                for filename in os.listdir(directory):
                    filen = os.fsdecode(filename)
                    count = count + audio.add_to_playlist([filen])
                update('Added {} file(s) from directory: {}'.format(
                    count, os.getcwd()))
            else:
                count = audio.add_to_playlist(cmd_list[1:len(cmd_list)])
                update('Added {} file(s) to playlist: {}'.format(
                    count, cmd_list[1:len(cmd_list)]))

        # Remove all listed playlists indices
        elif is_command(['remove', 'r']):
            if has_arg(['-all', '-a']):
                audio.clear_playlist()
                update('Playlist cleared')
            else:
                audio.rem_from_playlist(cmd_list[1:len(cmd_list)])
                update('Removed from playlist: {}'.format(
                    cmd_list[1:len(cmd_list)]))

        # Change main panel mode
        elif is_command(['mode', 'm']):
            if has_arg(['help']):
                ui.set_mode(ui.MainPanelMode.HELP)
            if has_arg(['details']):
                ui.set_mode(ui.MainPanelMode.DETAILS)
            update('Changed mode to {}'.format(cmd_list[1]))

        # Unrecognized command
        else:
            update('Unrecognized command.')

    return False