Module: Banjo

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

Defined Under Namespace

Modules: Keys Classes: Channel, Note

Constant Summary collapse

VERSION =
"0.0.5"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.beats_per_measureObject

Returns the value of attribute beats_per_measure.



15
16
17
# File 'lib/banjo.rb', line 15

def beats_per_measure
  @beats_per_measure
end

.loop_countObject

Returns the value of attribute loop_count.



20
21
22
# File 'lib/banjo.rb', line 20

def loop_count
  @loop_count
end

.measures_per_loopObject

Returns the value of attribute measures_per_loop.



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

def measures_per_loop
  @measures_per_loop
end

.tempoObject

Returns the value of attribute tempo.



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

def tempo
  @tempo
end

.tickObject

Returns the value of attribute tick.



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

def tick
  @tick
end

.ticks_per_beatObject

Returns the value of attribute ticks_per_beat.



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

def ticks_per_beat
  @ticks_per_beat
end

.ticks_per_periodObject

Returns the value of attribute ticks_per_period.



19
20
21
# File 'lib/banjo.rb', line 19

def ticks_per_period
  @ticks_per_period
end

Class Method Details

.hush_allObject



34
35
36
37
38
# File 'lib/banjo.rb', line 34

def self.hush_all
  Banjo::Channel.channels.each do |channel|
    channel.new.hush
  end
end

.load_channelsObject



23
24
25
26
# File 'lib/banjo.rb', line 23

def self.load_channels
  load_channels!
rescue Exception
end

.load_channels!Object



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

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

.playObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/banjo.rb', line 40

def self.play
  Banjo.measures_per_loop ||= 1
  Banjo.ticks_per_period    = Banjo.ticks_per_beat * Banjo.beats_per_measure * Banjo.measures_per_loop
  poll_rate                 = (60.0 / Banjo.tempo / Banjo.ticks_per_beat)
  p "Tick every: #{poll_rate} seconds"

  EventMachine.run do
    Banjo.tick      = 0
    self.loop_count = 0

    # Display available channels
    p Banjo::Channel.channels

    # Shut down all channels
    hush_all

    EM.add_periodic_timer(poll_rate) do
      #puts Time.now if (Banjo.tick % 4 == 0)
      p Banjo.tick

      Banjo.load_channels if Banjo.tick == 0

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

      Banjo.tick = update_counters(Banjo.tick)
    end

    puts "Banjo Reactor started..."
  end
end

.update_counters(tick) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/banjo.rb', line 74

def self.update_counters(tick)
  if tick < (ticks_per_period - 1)
    tick += 1
  else
    puts "Loop: #{self.loop_count += 1}"
    tick = 0
  end
  tick
end