Class: Hammelin::Note
- Inherits:
-
Object
- Object
- Hammelin::Note
- 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
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #decrease_octave(times) ⇒ Object
- #decrease_octave!(times) ⇒ Object
- #downto(note) ⇒ Object
- #increase_octave(times) ⇒ Object
- #increase_octave!(times) ⇒ Object
-
#initialize(note) ⇒ Note
constructor
A new instance of Note.
- #music_string ⇒ Object
- #play ⇒ Object
- #upto(note) ⇒ Object
- #value ⇒ Object
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
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/hammelin/note.rb', line 6 def token @token end |
Class Method Details
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_string ⇒ Object
32 33 34 |
# File 'lib/hammelin/note.rb', line 32 def music_string "[#{parse_value}]" end |
#play ⇒ Object
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 |
#value ⇒ Object
54 55 56 |
# File 'lib/hammelin/note.rb', line 54 def value parse_value end |