Class: Banjo::Channel
Constant Summary collapse
- DEFAULT_DURATION =
0.5
Constants included from Keys
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
- #arpeggio(notes, velocity = 50) ⇒ Object
- #channel ⇒ Object
- #hush ⇒ Object
-
#initialize ⇒ Channel
constructor
A new instance of Channel.
- #midi_messages ⇒ Object
- #modulation(value = 0) ⇒ Object
- #pitch(value = 63) ⇒ Object
- #play(note) ⇒ Object
- #play_note!(note, velocity = 100, duration = DEFAULT_DURATION) ⇒ Object
- #sustain(value = 0) ⇒ Object
- #within(lower, upper, &block) ⇒ Object
Methods included from Keys
Constructor Details
#initialize ⇒ Channel
Returns a new instance of Channel.
29 30 31 |
# File 'lib/banjo/channel.rb', line 29 def initialize @output = UniMIDI::Output.all[channel] end |
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
5 6 7 |
# File 'lib/banjo/channel.rb', line 5 def output @output end |
Class Method Details
.channels ⇒ Object
21 22 23 |
# File 'lib/banjo/channel.rb', line 21 def self.channels @channels ||= [] end |
.inherited(child) ⇒ Object
25 26 27 |
# File 'lib/banjo/channel.rb', line 25 def self.inherited(child) channels << child end |
Instance Method Details
#arpeggio(notes, velocity = 50) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/banjo/channel.rb', line 45 def arpeggio(notes, velocity = 50) step = (1.0 * Banjo.ticks_per_period / notes.size).round notes.each_with_index do |note, index| tick_note((index * step), note, velocity) end end |
#channel ⇒ Object
9 10 11 |
# File 'lib/banjo/channel.rb', line 9 def channel 0 end |
#hush ⇒ Object
52 53 54 |
# File 'lib/banjo/channel.rb', line 52 def hush output.puts 0xB0, 0x7B, 0 end |
#midi_messages ⇒ Object
17 18 19 |
# File 'lib/banjo/channel.rb', line 17 def [0x90, 0x80] end |
#modulation(value = 0) ⇒ Object
33 34 35 |
# File 'lib/banjo/channel.rb', line 33 def modulation(value = 0) output.puts 0xB0, 0x01, value end |
#pitch(value = 63) ⇒ Object
37 38 39 |
# File 'lib/banjo/channel.rb', line 37 def pitch(value = 63) output.puts 0xE0, 0, value end |
#play(note) ⇒ Object
13 14 15 |
# File 'lib/banjo/channel.rb', line 13 def play(note) Note.new(self, note) end |
#play_note!(note, velocity = 100, duration = DEFAULT_DURATION) ⇒ Object
56 57 58 59 |
# File 'lib/banjo/channel.rb', line 56 def play_note!(note, velocity = 100, duration = DEFAULT_DURATION) output.puts([0], note, velocity) EventMachine.add_timer(duration, proc { output.puts([1], note, 100) }) end |
#sustain(value = 0) ⇒ Object
41 42 43 |
# File 'lib/banjo/channel.rb', line 41 def sustain(value = 0) output.puts 0xB0, 0x40, value end |