def execute(code, verbose=True): """ Takes a string of FoxDot code and executes as Python """ namespace = globals() try: if type(code) != CodeType: code = process(code, namespace) if verbose: print stdout(code) if not code: return else: code = compile(code, "FoxDot", "exec") exec code in namespace except: print error_stack() raise # raise the error to any foxdot code that executes foxdot code return
def __call__(self, code, verbose=True, verbose_error=None): """ Takes a string of FoxDot code and executes as Python """ if verbose_error is None: verbose_error = verbose if not code: return try: if type(code) != CodeType: code = clean(code) response = stdout(code) if verbose is True: print(response) exec(self._compile(code), self.namespace) except Exception as e: response = error_stack() if verbose_error is True: print(response) return response
def __call__(self, code, verbose=True): """ Takes a string of FoxDot code and executes as Python """ if not code: return try: if type(code) != CodeType: response = stdout(code) if verbose is True: print(response) exec self._compile(code) in self.namespace except: response = error_stack() print(response) return response
def __call__(self, code, verbose=True): """ Takes a string of FoxDot code and executes as Python """ if not code: return try: if type(code) != CodeType: if verbose is True: print(stdout(code)) ## try: ## ## sys.displayhook(eval(code, self.namespace)) ## ## except: ## ## pass code = compile(code, "FoxDot", "exec") exec code in self.namespace except: print(error_stack()) raise return
def __run_block(self, block): """ Private method for calling all the items in the queue block. This means the clock can still 'tick' while a large number of events are activated """ # Set the time to "activate" messages on SC block.time = self.osc_message_time() for item in block: if not block.called(item): try: block.call(item) except SystemExit: sys.exit() except: print(error_stack()) # Send all the message to supercollider together block.send_osc_messages() # Store the osc messages self.history.add(block.beat, block.osc_messages) return
def __call__(self, code, verbose=True): """ Takes a string of FoxDot code and executes as Python """ if not code: return try: if type(code) != CodeType: response = stdout(code) if verbose is True: print(response) code = compile(code, "FoxDot", "exec") exec code in self.namespace except: response = error_stack() print(response) #TODO - Add sys.displayhook? return response
def execute(code, verbose=True): """ Takes a string of foxdot code and calls toPython() ` and exectues the returned python string in our global namespace """ try: if type(code) != CodeType: code = toPython(code, verbose) exec code in globals() except: print error_stack() raise # raise the error to any foxdot code that executes foxdot code return
def execute(code, verbose=True): """ Takes a string of foxdot code and calls toPython() ` and exectues the returned python string in our global namespace """ try: if type(code) != CodeType: code = toPython( code, verbose ) exec code in globals() except: print error_stack() raise # raise the error to any foxdot code that executes foxdot code return
def __run_block(self, block): """ Private method for calling all the items in the queue block. This means the clock can still 'tick' while a large number of events are activated """ # Call each item in turn (they can call each other if there are dependencies # print self.now(), t1 = clock() for item in block: if not block.called(item): try: block.call(item) except SystemExit: sys.exit() except: print(error_stack()) t2 = clock() sleep_time = self.latency - (t2 - t1) # If blocks are taking longer to iterate over than the latency, adjust accordingly if sleep_time < 0: self.latency -= sleep_time sleep_time = 0 # print block print "Clock latency increased to", self.latency # Wait until the end of the latency period sleep(sleep_time) # Send all the message to supercollider together if self.ticking: block.send_osc_messages() return
def __run_block(self, block, beat): """ Private method for calling all the items in the queue block. This means the clock can still 'tick' while a large number of events are activated """ # Set the time to "activate" messages on - adjust in case the block is activated late # `beat` is the actual beat this is happening, `block.beat` is the desired time. Adjust # the osc_message_time accordingly if this is being called late block.time = self.osc_message_time() - self.beat_dur( float(beat) - block.beat) for item in block: # The item might get called by another item in the queue block output = None if item.called is False: try: output = item.__call__() except SystemExit: sys.exit() except: print(error_stack()) # TODO: Get OSC message from the call, and add to list? # Send all the message to supercollider together block.send_osc_messages() # Store the osc messages -- future idea # self.history.add(block.beat, block.osc_messages) return
def __run_block(self, block, time): """ Private method for calling all the items in the queue block. This means the clock can still 'tick' while a large number of events are activated """ # Set the time to "activate" messages on - adjust in case the block is activated late block.time = self.osc_message_time() - self.beat_dur( float(time) - block.beat) for item in block: # The item might get called by another item in the queue block if item.called is False: try: item.__call__() except SystemExit: sys.exit() except: print(error_stack()) # Send all the message to supercollider together block.send_osc_messages() # Store the osc messages -- experimental # self.history.add(block.beat, block.osc_messages) return
def run(self): self.ticking = True while self.ticking: if self.now() >= self.queue.next(): # Call any item in the popped event block = self.queue.pop() for item in block: if not block.called(item): try: block.call(item) except SystemExit: sys.exit() except: print(error_stack()) # Make sure rest is positive so any events that SHOULD # have been played are played straight away rest = max((self.queue.next() - self.now()) * 0.25, 0) # If there are no events for at least 1 beat, sleep for 1 beat # sleep(min(self.beat(1), rest)) sleep(min(0.005, rest)) return