def main(): # Get argv from command-line statement = list(sys.argv[1]) identifier = eval(sys.argv[2]) a = int(sys.argv[3]) b = int(sys.argv[4]) # Get stdin stdin = sys.stdin.readlines() s = ''.join(stdin) selected = sco.select(s, {0: statement, 1: identifier}) selected = selection.swap(selected, a, b) print sco.merge(s, selected),
def _map_process(self, data, statement, identifier, pfield, function, *args, **kwargs): convert_numeric = True sco_statements_enabled = True # Convert pfield to list if it isn't one if not isinstance(pfield, list): pfield = [pfield] selection = sco.select(data, {0: statement, 1: identifier}) for k, v in selection.iteritems(): for p in pfield: element = sco.event.get(v, p) # Bypass if score statement like carry # TODO: ^+x, npx, ppx, etc... if sco_statements_enabled and element in ['.', '+', '<', '!']: break # Convert value to float if convert_numeric: try: element = float(element) except Exception: pass deez_args = (element, ) + args selection[k] = sco.event.set(v, p, function(*deez_args, **kwargs)) return sco.merge(data, selection)
def _map_process(self, data, statement, identifier, pfield, function, *args, **kwargs): convert_numeric = True sco_statements_enabled = True # Convert pfield to list if it isn't one if not isinstance(pfield, list): pfield = [pfield] selection = sco.select(data, {0: statement, 1: identifier}) for k, v in selection.iteritems(): for p in pfield: element = sco.event.get(v, p) # Bypass if score statement like carry # TODO: ^+x, npx, ppx, etc... if sco_statements_enabled and element in ['.', '+', '<', '!']: break # Convert value to float if convert_numeric: try: element = float(element) except Exception: pass deez_args = (element,) + args selection[k] = sco.event.set(v, p, function(*deez_args, **kwargs)) return sco.merge(data, selection)
def complex_play(start, measure): selected = sco.select(measure, {0: 'i'}) # Add 1 selected = selection.operate_numeric(selected, 5, lambda x: x + 1) # Delay, transpose, swap pan, half amp s2 = selected.copy() s2 = selection.operate_numeric(s2, 2, lambda x: x + start + 0.125) _transpose = lambda x: x * pow(2, 7 / 12.0) s2 = selection.operate_numeric(s2, 5, _transpose) s2 = selection.operate_numeric(s2, 6, lambda x: 1.0 - x) s2 = selection.operate_numeric(s2, 4, lambda x: x * 0.5) output = [] output.append(sco.merge(measure, selected)) output.append(sco.merge(measure, s2)) return ''.join(output)
def simple_mod(start, measure, transpose): selected = sco.select(measure, {0: 'i'}) # Change start times selected = selection.operate_numeric(selected, 2, lambda x: x + start) # Transpose _transpose = lambda x: x * pow(2, transpose / 12.0) selected = selection.operate_numeric(selected, 5, _transpose) return sco.merge(measure, selected)
def score(self, data): # Apply pfield callbacks for L in self.p_callbacks: for cb in L: data = self._map_process(data, cb.statement, cb.identifier, cb.pfield, cb.function, *cb.args, **cb.kwargs) # Apply time stack selected = sco.select(data, {0: 'i'}) op = sco.selection.operate_numeric(selected, 2, lambda x: x + self.slipcue.now()) self.score_data.append(sco.merge(data, op))
return ''.join(output) #for i in range(0, 8): # print simple_mod(i * 4, my_measure, i * 2), #print complex_play(0, my_measure) #print complex_play(4, my_measure) # Serializing functions f_list = (lambda x: x + 1, lambda x: x * 2) this_measure = my_measure selected = sco.select(this_measure, {0: 'i'}) for f in f_list: selected = selection.operate_numeric(selected, 5, f) this_measure = sco.merge(this_measure, selected) print 'this measure', this_measure # Functions need arguments, specify pfield(s) # Multiple types of functional pfunc type things: # do_all(pfield_index_list, pfunc, *args) # processes all ievents # # in block # do(pattern, pfield_index_list, [pfunc, *args], ...) # with pattern ''' def punch(score, *func_args): this_measure = my_measure punch(this_measure, [do_all(5, lambda x: (x + y), 1)], [do({1: 2}, 6, lambda x: 1.0 - x)])
def test(n, score, score_dict, expect): result = sco.merge(score, score_dict) did_pass = result == expect return did_pass, n, 'merge()', str(expect), str(result)
def arpeggiator(score, pattern, pfield_index_list, value_list): selected = sco.select(score, pattern) arp = Arpeggiator(value_list) selected = selection.replace(selected, pfield_index_list, arp.next) return ''.join(sco.merge(score, selected))
#for i in range(0, 8): # print simple_mod(i * 4, my_measure, i * 2), #print complex_play(0, my_measure) #print complex_play(4, my_measure) # Serializing functions f_list = (lambda x: x + 1, lambda x: x * 2) this_measure = my_measure selected = sco.select(this_measure, {0: 'i'}) for f in f_list: selected = selection.operate_numeric(selected, 5, f) this_measure = sco.merge(this_measure, selected) print 'this measure', this_measure # Functions need arguments, specify pfield(s) # Multiple types of functional pfunc type things: # do_all(pfield_index_list, pfunc, *args) # processes all ievents # # in block # do(pattern, pfield_index_list, [pfunc, *args], ...) # with pattern ''' def punch(score, *func_args): this_measure = my_measure punch(this_measure, [do_all(5, lambda x: (x + y), 1)], [do({1: 2}, 6, lambda x: 1.0 - x)])