Class: Banjo::Note

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, note) ⇒ Note

Returns a new instance of Note.



5
6
7
8
9
10
# File 'lib/banjo/note.rb', line 5

def initialize(channel, note)
  self.channel  = channel
  self.note     = note
  self.velocity = 100
  self.duration = 0.5
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



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

def channel
  @channel
end

#durationObject

Returns the value of attribute duration.



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

def duration
  @duration
end

#noteObject

Returns the value of attribute note.



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

def note
  @note
end

#velocityObject

Returns the value of attribute velocity.



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

def velocity
  @velocity
end

Instance Method Details

#at(tick) ⇒ Object



12
13
14
# File 'lib/banjo/note.rb', line 12

def at(tick)
  play if Banjo.tick == tick
end

#every(period, offset = 0) ⇒ Object



16
17
18
# File 'lib/banjo/note.rb', line 16

def every(period, offset = 0)
  play if ((Banjo.tick + offset) % period == 0)
end

#for(duration) ⇒ Object



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

def for(duration)
  self.duration = duration
  self
end

#playObject



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

def play
  channel.play_note!(note, velocity, duration)
end

#with_velocity(velocity) ⇒ Object



20
21
22
23
# File 'lib/banjo/note.rb', line 20

def with_velocity(velocity)
  self.velocity = velocity
  self
end