Skip to content

Instantly share code, notes, and snippets.

@reprimande
Created August 8, 2016 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reprimande/94a1f87eb42c1289473e753d92e3ff8b to your computer and use it in GitHub Desktop.
Save reprimande/94a1f87eb42c1289473e753d92e3ff8b to your computer and use it in GitHub Desktop.
require 'osc-ruby'
require "celluloid/current"
class Track
attr_accessor :pattern, :name
def initialize(pattern, name)
@pattern = pattern
@name = name
@current = @pattern.dup
end
def step
val = @current.shift
@current = @pattern.dup if @current.empty?
val
end
end
class Sequencer
include Celluloid
def initialize(tracks)
@tracks = tracks
@osc = OSC::Client.new('localhost', 57110)
@node_id = 10000
end
def start
@timer = every(0.15) do
@tracks.each do |track|
val = track.step
@osc.send(OSC::Message.new("/s_new" , track.name, @node_id += 1, 1, 1)) if val == 1
end
end
end
end
tracks = []
tracks << Track.new([1,0,0,1,0,1,0,1], "kick01")
tracks << Track.new([0,0,0,0,0,0,1,0], "clap01")
tracks << Track.new([1,1,1,1,1,1,1,1], "hat01")
s = Sequencer.new(tracks)
s.start
sleep 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment