def partition_recur(n, partitions, homogeneity, minval, maxval, kind='fib'): """ partition the value @n in @partitions where partitions is a list of partition numbers if partition = (2, 7) then first partition n in 2, then the two resulting partitions are also partitioned so that the final number of partitions = 7 the last number in partition indicate always the final number of partitions for each partition step an homogeneity step is also needed, so len(partitions) == len(homogeneity) must be true """ func = { 'fib': partition_fib, 'expon': partition_expon } p = partitions[0] h = homogeneity[0] subns = func[kind](n, p, minval, maxval, h) if len(partitions) == 1: return subns collected = [] for subn in subns: ps = list(partitions[1:]) ps[0] = max(int(ps[0] * (subn / n) + 0.5), 1) collected.append(partition_recur(subn, ps, homogeneity[1:], minval, subn, type)) tmp = iterlib.flatten(collected) assert abs(sum(tmp) - n) < 0.0001 return collected
def _asbpf(obj): if isinstance(obj, dict): return bpf.util.dict_to_bpf(obj) elif isinstance(obj, list): # can be either a flat list of [x0, y0, x1, y1, ...] or [[x0, y0], [x1, y1], ...] if isinstance(obj[0], (tuple, list)): obj = list(flatten(obj, levels=1)) assert len(obj) % 2 == 0 Xs = obj[::2] Ys = obj[1::2] return bpf.core.Linear(Xs, Ys) else: return bpf.util.asbpf(obj)
def ringmod(*pitches: pitch_t) -> List[Note]: """ Calculate the ring-modulation between the given notes pitches: a midinote, a notename or a Note (no frequencies!) Many notenames can be given as one string, separated by spaces Returns the notes of the sidebands, as Notes """ for p in pitches: _checkpitch(p) midis = _parsePitches(*pitches) freqs = list(map(m2f, midis)) sidebands = [_ringmod2f(f1, f2) for f1, f2 in combinations(freqs, 2)] all_sidebands: List[float] = list(set(flatten(sidebands))) all_sidebands.sort() return [Note(f2m(sideband)) for sideband in all_sidebands]
def getArgs(self) -> List[float]: """ returns pargs, beginning with p2 idx parg desc 0 2 delay 1 3 duration 2 4 tabnum 3 5 gain 4 6 chan 5 7 position 6 8 fade0 7 9 fade1 8 0 pitchinterpol 9 1 fadeshape 1 3 numbps 2 4 bplen . . reserved space for user pargs . ---- breakpoint data tabnum: if 0 it is discarded and filled with a valid number later """ pitchinterpol = _pitchinterpolToInt[self.pitchinterpol] fadeshape = _fadeshapeToInt[self.fadeshape] args = [float(self.delay), self.getDur(), 0, # table index, to be filled later self.gain, self.chan, self.position, self.fadein, self.fadeout, pitchinterpol, fadeshape, len(self.bps), self.breakpointSize()] args.extend(iterlib.flatten(self.bps)) assert all(isinstance(arg, (float, int, Fraction)) for arg in args), args return args
def clients_connected_to(name_pattern): """ Returns a list of clients connected to the ports matched by name_pattern Example ======= clientA:out_1 -----> system:playback1 clientB:out_1 -----> system:playback1 clientB:out_2 -----> system:playback2 clientC:out_1 -----> clinetA:in_1 clients_connected_to("system:playback") --> {"clientA", "clientB"} """ myjack = get_client() connectedto_ports = myjack.get_ports(name_pattern, is_audio=True, is_input=True) connections = flatten(myjack.get_all_connections(p) for p in connectedto_ports) clients = set(conn.name.split(":")[0] for conn in connections) return clients
def instrData(vowel: U[str, Vowel]) -> List[float]: vowel = asVowel(vowel) amps = [db2amp(db) for db in vowel.dbs] data = list(flatten(zip(vowel.freqs, vowel.bws, amps))) return data