 # Bitwise Sequencer for Crow

## Bitwise Sequencer for Crow

Using bitwise operators to create simple yet effective 4 channel step sequencer

Inspired by the old drum machines like the Rhythm Ace, this idea leverages bits as a representation of a 16-step drum pattern. The script will generate 4 random 16-bit integers and will cycle through each bit from a clock pulse. A random drum fill is generated on the last two beats for every 4 bars.

Bitwise operators provide really convenient means of manipulating patterns. In this demo, << and >> operators are used to advance and offset a sequence, & operators are used to slice patterns and mask subdivisions and | operators can combine two sequences together. These techniques provide very succinct ways of generating and manipulating rhythms.

Currently written as a demo to control through Druid, but could easily be modified or added into other scripts. Just received the Crow last week and I’m enamored with what this little device can do!

Crow

### Documentation

Input 1: Clock
Outputs 1-4: Trigger Outputs

### Script

``````--- Bitwise Trigger Sequencer
-- Input 1 Clock
-- Output 1-4

-- Global Variables
track = {}
current = {}
track_divisions = {2,2,4,1}
divisions = {257,4369,21845,65535}
divisions = 1
count = 0
step = 0

-- Functions
function cycle(pattern)
return (pattern >> 1) | (pattern << 15) & 65535
end

function seed(t)
if t then
return math.random(1,65535) & divisions[t]
else
return math.random(1,65535)
end
end

function reset()
for i = 1,4 do
track[i] = seed(track_divisions[i])
end
end

-- Runtime!
function init ()
input.mode('change')
reset()
end

input.change = function (c)
if c then
step = count % 16

-- Any changes to the track are applied on the first beat
if(step == 0) then
for i = 1,4 do
current[i] = track[i]
end
end

-- Lets spice it up every 4 measures
if count % 64 == 48 then
for i = 1,4 do
current[i] = (track[i] & 255) | (seed() & 65280)
end
end

-- Play triggers and cycle the pattern 1 step
for i = 1, 4 do
output[i].volts = (current[i] & 1 == 1) and 5 or 0
current[i] = cycle(current[i])
end

count = count + 1
else
-- Turn off outputs
for i = 1, 4 do
output[i].volts = 0
end
end
end``````
15 Likes

Sorry, new here… can’t seem to figure out how to properly tag this post. If anyone can help point out what I’m missing, I will gladly update.