# DrumPattern quark

Hoping that it might be of use to somebody out there, I just wanted to share a DrumPattern quark for storing and using 808-like drum machine patterns, much like the Scale class is used for storing and using scale info.

It’s structured and works similarly to the Scale class.

DrumPattern.directory;

DrumPattern.house.kick; //[ 1,\r,\r,\r, 1,\r,\r,\r, 1,\r,\r,\r, 1,\r,\r,\r]
DrumPattern.house.sn;   //[\r,\r,\r,\r, 1,\r,\r,\r,\r,\r,\r,\r, 1,\r,\r,\r]
DrumPattern.house.oh;   //[\r,\r, 1,\r,\r,\r, 1,\r,\r,\r, 1,\r,\r,\r, 1,\r]
DrumPattern.house.cym;  //[ 1,\r,\r,\r,\r,\r,\r,\r,\r,\r,\r,\r,\r,\r,\r,\r]


I’d love to have feedback from potential users in order to improve it.

this is a great idea looking forward to playing with it!

I think though that \r is being deprecated - maybe better to use Rest() ?

random ideas:

I think a method that lets you add a pattern with a string might be nice: DrumPattern.fromString(“x…x xx… x…x x…”) or “x…x|x…|x…x|x…|” (I use a method like this and its nice for readability…)

It would be cool if there was some way to store a pattern that had a multiple sounds like for hihat - like [0,1,0,1,r,1,0,1] …hmmmm Maybe just a method that makes two patterns from a string like [“01… 0101”]?

Anyhow I can see this getting heavy use…

1 Like

oh, is it? I’ll have to check that out. Thanks for pointing it out.

Wow, thanks for the input! These are great ideas! I will definitely implement them.
I already developed a pattern that does just that, so it should be easy to port.

Not sure I understand this. You mean filling up multiple parts with just one string? Like DrumPattern.fromString("xoxo") would convert to DrumPattern(kick: [1,\r, 1, \r], sn: [\r, 1, \r, 1]) ?

I’d love to see that!

I’m not aware of any plans to deprecate \r.

Rest was introduced because without it, there’s no way to use the rhythm stream (\dur or \delta) to denote an event as a rest. Doing this in the rhythm stream means that a single entity has to carry both the rest status and the numeric value, which \r can’t do.

But we recognize that in other streams, it’s inconvenient to mark a rest by writing Rest() and supplying a dummy value that won’t be used. So \r or even \ are still there.

I guess it would have to. It looks like you’re handling hi-hats by having separate patterns for open and closed hats, but it might be easier to write hi-hat patterns with both in the same string.

In my live coding system, a drum process loads one sample but a hi-hat process loads two samples. Then I can write:

/hh = "..- |..- |..-.| .- ";


hjh

Hi,
looks cool. I will give it a shot at some point.

I think the basic idea is interesting but perhaps some refinements are needed to more accurately model real-life grooves.

What is the physical interpretation of the numbers you return? Are they durations? Or just on-off switches? (In the latter case, one could use 0, 2,3,…,127 to indicate different volumes e.g.)
Should there be a way to represent tuplets or other more complex rhythmic stuff?

e.g. in https://sccode.org/1-5da#c917 I used lowercase x and capital X to distinguish between non-accented and accented notes, and I made provisions to define polyrhythms (but maybe such extensions do not fit naturally in a pure “scale-like” object).

… all of which my live coding system does… https://github.com/jamshark70/ddwChucklib-livecode

hjh

That’s interesting, but I like keeping things as simple as possible and try to do things just one way. I do have a class to play a whole drum set, so I can load a collection of samples for the different drum instruments (kick, snare, ch, hh, etc), . It’s like your hh but for the whole drum kit. Then I can pass it a DrumPattern and each instrument plays it’s corresponding rhythm.

They represent triggers, like in the 808 drum machine.

I reckon this depends on the piece where the pattern is used, not the rhythm itself, like in a Scale you can apply it different volumes, legatos, etc, to each note, depending on where you’re using it. That has nothing to do with the scale itself. I use other Pbind attributes for that.

The default pattern length is 16 beats, but you can set it to whatever you need. You can combine this with \dur to get complex patterns.

chucklib was very inspiring. But with this class I was not trying to build a livecoding language, just an aid to store and use drum machine patterns. I may take the one-string-pattern idea, though, I really like it.
For accents there’s an independent “track” in the class conveniently called accent, like in the common 808-style pattern notation syntax.

Anyhow, thanks for all the input! All this comments are very helpful!