Class: Banjo::Channel
- Inherits:
-
Object
- Object
- Banjo::Channel
- Defined in:
- lib/banjo/channel.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
-
#tick ⇒ Object
Returns the value of attribute tick.
Class Method Summary collapse
Instance Method Summary collapse
- #channel ⇒ Object
-
#initialize(tick) ⇒ Channel
constructor
A new instance of Channel.
- #mod_note(mod, note, offset = 0, velocity = 50) ⇒ Object
- #play_note(note, velocity = 50, duration = 0.5) ⇒ Object
- #play_note!(note, velocity = 50, duration = 0.5) ⇒ Object
- #tick_note(tick, note, velocity = 50, duration = 0.5) ⇒ Object
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
#output ⇒ Object
Returns the value of attribute output.
3 4 5 |
# File 'lib/banjo/channel.rb', line 3 def output @output end |
#tick ⇒ Object
Returns the value of attribute tick.
3 4 5 |
# File 'lib/banjo/channel.rb', line 3 def tick @tick end |
Class Method Details
.channels ⇒ Object
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
#channel ⇒ Object
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 |