Class: Nilsteps::Sequencer

Inherits:
Object
  • Object
show all
Defined in:
lib/nilsteps.rb

Overview

16 steps / bar OSC sequencer for a track

Instance Method Summary collapse

Constructor Details

#initialize(bpm: 120, length: 16, osc_server: "localhost", osc_port: 2345) ⇒ Sequencer

Returns a new instance of Sequencer.



28
29
30
31
32
33
# File 'lib/nilsteps.rb', line 28

def initialize(bpm: 120, length: 16, osc_server: "localhost", osc_port: 2345)
  @steps = Array.new(length)
  @resolution = 16 # Cannot change resolution for the moment
  @osc_client = OSC::Client.new(osc_server, osc_port)
  @bpm_to_ms = BPMToMsec.new(bpm)
end

Instance Method Details

#play(bars = 1) ⇒ Object

Play sequence

Parameters:

bars

Specify how many times it repeats a bar



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/nilsteps.rb', line 74

def play(bars = 1)
  (1..bars).each do |_i|
    @steps.each do |step|
      if block_given?
        yield step if step
      else
        @osc_client.send(step) if step
      end
      sleep(note_length / 1000)
    end
  end
end

#setup_steps(notes) ⇒ Object

Setup notes in a secuence

Parameters:

notes

A hash for notes (e.g. { 0 => “C1”, 1 => “D2”, … })



42
43
44
45
46
# File 'lib/nilsteps.rb', line 42

def setup_steps(notes)
  notes.each do |key, value|
    @steps[key.to_i] = OSC::Message.new("/" + value.to_s, 1)
  end
end