Created
August 8, 2016 17:18
-
-
Save reprimande/94a1f87eb42c1289473e753d92e3ff8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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