def now(self): """ Returns the value from self.data for time t in self.metro """ if self.inf_found == 3: val = self.inf_value else: t = self.metro.now() % self.length() val = 0 for i in range(len(self.data)): val = self.data[i] if self.time[i][0] <= t < self.time[i][1]: if isinstance(op.modi(self.dur, i), _inf): if self.inf_found == _inf.wait: self.inf_found = _inf.done self.inf_value = val elif self.inf_found == _inf.here: self.inf_found = _inf.wait break return self.calculate(val)
def now(self, time=None): t = self.current_time(time) for i in range(len(self.data)): val = self.data[i] if self.time[i][0] <= t < self.time[i][1]: break # Proportion of the way between values p = (float(t) - self.time[i][0]) / (self.time[i][1] - self.time[i][0]) # Next value q = op.modi(self.data, i + 1) # Calculate and add dependencies val = (val * (1 - p)) + (q * p) self.current_value = self.calculate(val) return self.current_value
def valueAt(self, t): if self.inf_found == 3: val = self.inf_value else: # If using a different bpm to the clock val = 0 for i in range(len(self.data)): val = self.data[i] if self.time[i][0] <= t < self.time[i][1]: if isinstance(op.modi(self.dur, i), _inf): if self.inf_found == _inf.wait: self.inf_found = _inf.done self.inf_value = val elif self.inf_found == _inf.here: self.inf_found = _inf.wait break return float(self.calculate(val))
def update(self, values, dur=None, **kwargs): """ Updates the TimeVar with new values """ self.bpm = kwargs.get('bpm', self.bpm) # if isinstance(values, str): values = [values] self.data = [] self.time = [] a, b = 0, 0 #: Update the durations of each state if dur is not None: self.dur = asStream(dur) if any([isinstance(i, _inf) for i in self.dur]): self.inf_found = _inf.here # Make equal size values = self.stream(values) length = max(len(values), len(self.dur)) values.stretch(length) self.dur.stretch(length) # Loop over the values and define time frame for i, val in enumerate(values): this_dur = op.modi(self.dur, i) a = b b = a + this_dur self.data.append(val) self.time.append((a, b)) # The contained data should be a Pattern self.data = self.stream(self.data) return self
def update(self, values, dur=None): """ Updates the TimeVar with new values """ #: If updated with a TimeVar object, copy the attribute dict if isinstance(values, self.__class__): self.__dict__ = values.__dict__ return self # if isinstance(values, str): values = [values] self.data = [] self.time = [] a, b = 0, 0 #: Update the durations of each state if dur is not None: self.dur = asStream(dur) if any([isinstance(i, _inf) for i in self.dur]): self.inf_found = _inf.here for i, val in enumerate(self.stream(values)): this_dur = op.modi(self.dur, i) a = b b = a + this_dur self.data.append( val ) self.time.append((a,b)) # The contained data should be a Pattern self.data = self.stream( self.data ) return self
def update(self, values, dur=None): """ Updates the TimeVar with new values """ #: If updated with a TimeVar object, copy the attribute dict if isinstance(values, self.__class__): self.__dict__ = values.__dict__ return self # if isinstance(values, str): values = [values] self.data = [] self.time = [] a, b = 0, 0 #: Update the durations of each state if dur is not None: self.dur = asStream(dur) if any([isinstance(i, _inf) for i in self.dur]): self.inf_found = _inf.here for i, val in enumerate(self.stream(values)): this_dur = op.modi(self.dur, i) a = b b = a + this_dur self.data.append(val) self.time.append((a, b)) # The contained data should be a Pattern self.data = self.stream(self.data) return self
def now(self, time=None): """ Returns the value from self.data for time t in self.metro """ if self.inf_found == 3: val = self.inf_value else: # If using a different bpm to the clock t = self.current_time(time) val = 0 for i in range(len(self.data)): val = self.data[i] if self.time[i][0] <= t < self.time[i][1]: if isinstance(op.modi(self.dur, i), _inf): if self.inf_found == _inf.wait: self.inf_found = _inf.done self.inf_value = val elif self.inf_found == _inf.here: self.inf_found = _inf.wait break self.current_value = self.calculate(val) return self.current_value
def _bpm_cycle_dur(self): """ Returns the time, in seconds, for a var to loop to its original value and duration if this var is a bpm value. """ return sum([(self.dur[i] / self.data[i]) for i in range(op.LCM(len(self.dur), len(self.data))) ]) * 60