Module: Banjo

Defined in:
lib/banjo.rb,
lib/banjo/channel.rb,
lib/banjo/version.rb

Defined Under Namespace

Classes: Channel

Constant Summary collapse

VERSION =
"0.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.tempoObject

Returns the value of attribute tempo.



12
13
14
# File 'lib/banjo.rb', line 12

def tempo
  @tempo
end

.ticks_per_periodObject

Returns the value of attribute ticks_per_period.



13
14
15
# File 'lib/banjo.rb', line 13

def ticks_per_period
  @ticks_per_period
end

Class Method Details

.load_channelsObject



16
17
18
19
20
# File 'lib/banjo.rb', line 16

def self.load_channels
  Dir['./channels/*.rb'].each do |file|
    load file
  end
end

.playObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/banjo.rb', line 22

def self.play
  tempo_in_ms = 60.0 / Banjo.tempo / ticks_per_period

  EventMachine.run do
    n = 0
    EM.add_periodic_timer(tempo_in_ms) do
      begin
        Banjo.load_channels
      end

      Banjo::Channel.channels.each do |klass|
        channel = klass.new(n)
        channel.perform
      end

      n < (ticks_per_period - 1) ? n += 1 : n = 0
    end

    puts "Banjo Reactor started..."
  end
end