July 2009
30 posts
Bill Maher (via azspot) This has always infuriated me. (via asprettyasasong) (via mikehudack)
I feel really strongly about this. It’s one of the worst things about California, who imprisons practically as many people as Texas and whose prison guard union is one of the most powerful groups in Sacramento.
(via justinday)
def __flatten_list(parent_list):
this_list = []
child_list = []
if type(parent_list) is not list:
return [parent_list]
for i in parent_list:
if type(i) is list:
child_list = __flatten_list(i)
for j in child_list:
this_list.append(j)
else:
this_list.append(i)
return this_list
That turns: [1, [2, [3, 4], 5], 6] into [1, 2, 3, 4, 5, 6]. I’m sure I’ll discover a better pythonic way of doing this later.
I’m four weeks into learning python, and have spent most of this time writing a package for parsing and modifying Csound code. Last night, I finally got it to the point where it can do some pretty useful stuff with very little code. For example:
def swap_pan_position(x): return 1.0 - x
selection = sco.select(score, {0: ‘i’, 1: 2})
selection = sco.operate_numeric(selection, 6, swap_pan_position)
new_score = sco.merge(score, selection)
That small snippet of code selects all instrument 2 i-events, runs every 6th parameter with the swap_pan_position() function, and merges the results back with the original score.
Before:
i 2 0 4 1.0 880 1.0 ; p6 is pan
i 2 + 4 . . 0.25
i 2 + 4 . . 0.999
i 2 + 4 . . 0.0
After (look at the far right column):
i 2 0 4 1.0 880 0.0 ; p6 is pan
i 2 + . . . 0.75
i 2 + . . . 0.001
i 2 + . . . 1.0
Very convenient to have something like this, especially if one is to modify dozens, if not hundreds of fields.
Download csd_v0.0.3alpha. Online docs here.