Class: Banjo::Channel
- Inherits:
-
Object
- Object
- Banjo::Channel
- Defined in:
- lib/banjo/channel.rb
Constant Summary collapse
- DEFAULT_DURATION =
0.5
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
- #arpeggio(notes, velocity = 50) ⇒ Object
- #channel ⇒ Object
-
#initialize(tick) ⇒ Channel
constructor
A new instance of Channel.
- #midi_channels ⇒ Object
- #mod_note(mod, note, offset = 0, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
- #modulation(value = 0) ⇒ Object
- #pitch(value = 63) ⇒ Object
- #play_note(note, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
- #play_note!(note, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
- #stfu ⇒ Object
- #sustain(value = 0) ⇒ Object
- #tick_note(tick, note, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
- #tick_notes(notes, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
Constructor Details
#initialize(tick) ⇒ Channel
Returns a new instance of Channel.
22 23 24 25 |
# File 'lib/banjo/channel.rb', line 22 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
14 15 16 |
# File 'lib/banjo/channel.rb', line 14 def self.channels @channels ||= [] end |
.inherited(child) ⇒ Object
18 19 20 |
# File 'lib/banjo/channel.rb', line 18 def self.inherited(child) channels << child end |
Instance Method Details
#arpeggio(notes, velocity = 50) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/banjo/channel.rb', line 57 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
6 7 8 |
# File 'lib/banjo/channel.rb', line 6 def channel 0 end |
#midi_channels ⇒ Object
10 11 12 |
# File 'lib/banjo/channel.rb', line 10 def midi_channels [0x90, 0x80] end |
#mod_note(mod, note, offset = 0, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
37 38 39 |
# File 'lib/banjo/channel.rb', line 37 def mod_note(mod, note, offset = 0, velocity = 50, duration = DEFAULT_DURATION) play_note(note, velocity, duration) if ((tick + offset) % mod == 0) end |
#modulation(value = 0) ⇒ Object
45 46 47 |
# File 'lib/banjo/channel.rb', line 45 def modulation(value = 0) output.puts 0xB0, 0x01, value end |
#pitch(value = 63) ⇒ Object
49 50 51 |
# File 'lib/banjo/channel.rb', line 49 def pitch(value = 63) output.puts 0xE0, 0, value end |
#play_note(note, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
41 42 43 |
# File 'lib/banjo/channel.rb', line 41 def play_note(note, velocity = 50, duration = DEFAULT_DURATION) EM.defer { play_note!(note, velocity, duration) } end |
#play_note!(note, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
68 69 70 71 72 |
# File 'lib/banjo/channel.rb', line 68 def play_note!(note, velocity = 50, duration = DEFAULT_DURATION) output.puts(midi_channels[0], note, velocity) sleep(duration) output.puts(midi_channels[1], note, velocity) end |
#stfu ⇒ Object
64 65 66 |
# File 'lib/banjo/channel.rb', line 64 def stfu output.puts 0xB0, 0x7B, 0 end |
#sustain(value = 0) ⇒ Object
53 54 55 |
# File 'lib/banjo/channel.rb', line 53 def sustain(value = 0) output.puts 0xB0, 0x40, value end |
#tick_note(tick, note, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
27 28 29 |
# File 'lib/banjo/channel.rb', line 27 def tick_note(tick, note, velocity = 50, duration = DEFAULT_DURATION) play_note(note, velocity, duration) if tick == self.tick end |
#tick_notes(notes, velocity = 50, duration = DEFAULT_DURATION) ⇒ Object
31 32 33 34 35 |
# File 'lib/banjo/channel.rb', line 31 def tick_notes(notes, velocity = 50, duration = DEFAULT_DURATION) notes.each do |tick, note| tick_note(tick, note, velocity, duration) end end |