Class: Banjo::Channel

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tick) ⇒ Channel

Returns a new instance of Channel.



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

def initialize(tick)
  @output = UniMIDI::Output.all[channel]
  @tick   = tick
end

Instance Attribute Details

#outputObject

Returns the value of attribute output.



3
4
5
# File 'lib/banjo/channel.rb', line 3

def output
  @output
end

#tickObject

Returns the value of attribute tick.



3
4
5
# File 'lib/banjo/channel.rb', line 3

def tick
  @tick
end

Class Method Details

.channelsObject



9
10
11
# File 'lib/banjo/channel.rb', line 9

def self.channels
  @channels ||= []
end

.inherited(child) ⇒ Object



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

def self.inherited(child)
  channels << child
end

Instance Method Details

#channelObject



5
6
7
# File 'lib/banjo/channel.rb', line 5

def channel
  0
end

#mod_note(mod, note, offset = 0, velocity = 50) ⇒ Object



26
27
28
# File 'lib/banjo/channel.rb', line 26

def mod_note(mod, note, offset = 0, velocity = 50)
  play_note(note, velocity, 0.5) if ((tick + offset) % mod == 0)
end

#play_note(note, velocity = 50, duration = 0.5) ⇒ Object



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

def play_note(note, velocity = 50, duration = 0.5)
  Thread.new { play_note!(note, velocity, duration) }
end

#play_note!(note, velocity = 50, duration = 0.5) ⇒ Object



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

def play_note!(note, velocity = 50, duration = 0.5)
  output.open do |o|
    o.puts(0x80, note, velocity)
    sleep(duration)
    o.puts(0x90, note, velocity)
  end
end

#tick_note(tick, note, velocity = 50, duration = 0.5) ⇒ Object



22
23
24
# File 'lib/banjo/channel.rb', line 22

def tick_note(tick, note, velocity = 50, duration = 0.5)
  play_note(note, velocity, duration) if tick == self.tick
end