Functions as Reusable Score Clips

I’m not a fan of the copy and paste method for composing computer music scores. I’d rather write something once, and reuse it as needed. Slipmat uses function definitions as one method for creating reusable score clips.

The following function rock_drums() stores a simple rock drum pattern with 8th note hats:

def rock_drums():
    @[0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5] hat()
    @[1, 3]                           snare()
    @[0, 2]                           kick()

Here, the rock_drum() clip is played 4 times:

@0  rock_drums()
@4  rock_drums()
@8  rock_drums()
@12 rock_drums()

Here are 16 bars using the range() shorthand method:

@range(0, 64, 4) rock_drums()

Using functions as clips can save time and keystrokes while greatly improving legibility. The easier your code is to read, the more likely others will remix your work. If they can’t make heads or tails out of it, they’re more likely to move on.

Comments are closed.