Class: Hammelin::Note

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/hammelin/note.rb

Constant Summary collapse

OCTAVE_JUMP =
12
MAX_VALUE =
127
CAPPED_VALUE =
MAX_VALUE - OCTAVE_JUMP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(note) ⇒ Note

Returns a new instance of Note.



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

def initialize(note)
  self.token = note
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/hammelin/note.rb', line 6

def token
  @token
end

Class Method Details

.from_value(value) ⇒ Object



28
29
30
# File 'lib/hammelin/note.rb', line 28

def self.from_value(value)
  Note.new("[#{value}]")
end

Instance Method Details

#<=>(other) ⇒ Object



58
59
60
# File 'lib/hammelin/note.rb', line 58

def <=>(other)
  self.value <=> other.value
end

#decrease_octave(times) ⇒ Object



40
41
42
# File 'lib/hammelin/note.rb', line 40

def decrease_octave(times)
  Note.from_value(lower_octave(times))
end

#decrease_octave!(times) ⇒ Object



49
50
51
52
# File 'lib/hammelin/note.rb', line 49

def decrease_octave!(times)
  value = decrease_octave(times).value
  self.token = "[#{value}]"
end

#downto(note) ⇒ Object



24
25
26
# File 'lib/hammelin/note.rb', line 24

def downto(note)
  NotesRange.from_range(Note.new(note),self)
end

#increase_octave(times) ⇒ Object



36
37
38
# File 'lib/hammelin/note.rb', line 36

def increase_octave(times)
  Note.from_value(higher_octave(times))
end

#increase_octave!(times) ⇒ Object



44
45
46
47
# File 'lib/hammelin/note.rb', line 44

def increase_octave!(times)
  value = increase_octave(times).value
  self.token = "[#{value}]"
end

#music_stringObject



32
33
34
# File 'lib/hammelin/note.rb', line 32

def music_string
  "[#{parse_value}]"
end

#playObject



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

def play
  Hammelin.play_string (music_string)
end

#upto(note) ⇒ Object



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

def upto(note)
  NotesRange.from_range(self,Note.new(note))
end

#valueObject



54
55
56
# File 'lib/hammelin/note.rb', line 54

def value
  parse_value
end