Class: Banjo::Channel

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

Constant Summary collapse

DEFAULT_DURATION =
0.5

Constants included from Keys

Keys::KEYS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Keys

included

Constructor Details

#initializeChannel

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

#outputObject

Returns the value of attribute output.



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

def output
  @output
end

Class Method Details

.channelsObject



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

#channelObject



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

def channel
  0
end

#hushObject



52
53
54
# File 'lib/banjo/channel.rb', line 52

def hush
  output.puts 0xB0, 0x7B, 0
end

#midi_messagesObject



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

def midi_messages
  [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(midi_messages[0], note, velocity)
  EventMachine.add_timer(duration, proc { output.puts(midi_messages[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

#within(lower, upper, &block) ⇒ Object



61
62
63
64
65
# File 'lib/banjo/channel.rb', line 61

def within(lower, upper, &block)
  if(Banjo.tick >= lower && Banjo.tick <= upper)
    block.call
  end
end