Class: Stringed::InstrumentString
- Inherits:
-
Object
- Object
- Stringed::InstrumentString
- Includes:
- Music
- Defined in:
- lib/stringed/instrument_string.rb
Instance Attribute Summary collapse
-
#fret_count ⇒ Object
readonly
Returns the value of attribute fret_count.
-
#root_note ⇒ Object
readonly
Returns the value of attribute root_note.
Class Method Summary collapse
Instance Method Summary collapse
- #find(note_name) ⇒ Object
- #find_chord(chord) ⇒ Object
- #fret_no(fret_note) ⇒ Object
- #fret_note(fret_no) ⇒ Object
-
#initialize(root_note, options = {}) ⇒ InstrumentString
constructor
A new instance of InstrumentString.
- #to_s ⇒ Object
Constructor Details
#initialize(root_note, options = {}) ⇒ InstrumentString
Returns a new instance of InstrumentString.
8 9 10 11 |
# File 'lib/stringed/instrument_string.rb', line 8 def initialize(root_note, ={}) @root_note = Music::Note.new(root_note.to_s) @fret_count = .fetch(:fret_count,14) end |
Instance Attribute Details
#fret_count ⇒ Object (readonly)
Returns the value of attribute fret_count.
6 7 8 |
# File 'lib/stringed/instrument_string.rb', line 6 def fret_count @fret_count end |
#root_note ⇒ Object (readonly)
Returns the value of attribute root_note.
6 7 8 |
# File 'lib/stringed/instrument_string.rb', line 6 def root_note @root_note end |
Class Method Details
.octave_down(fret_no) ⇒ Object
27 28 29 |
# File 'lib/stringed/instrument_string.rb', line 27 def self.octave_down(fret_no) fret_no - 12 end |
.octave_up(fret_no) ⇒ Object
23 24 25 |
# File 'lib/stringed/instrument_string.rb', line 23 def self.octave_up(fret_no) fret_no + 12 end |
Instance Method Details
#find(note_name) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/stringed/instrument_string.rb', line 35 def find(note_name) matches = [] (0..(fret_count)).each do |fret| matches.push fret if fret_note(fret).name == note_name end matches end |
#find_chord(chord) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/stringed/instrument_string.rb', line 43 def find_chord(chord) matches = [] chord.notes.each do |note| matches << find(note.name) end matches.flatten.compact.sort end |
#fret_no(fret_note) ⇒ Object
19 20 21 |
# File 'lib/stringed/instrument_string.rb', line 19 def fret_no(fret_note) Music::Note.note_distance(@root_note.to_s, fret_note.to_s) end |
#fret_note(fret_no) ⇒ Object
13 14 15 16 17 |
# File 'lib/stringed/instrument_string.rb', line 13 def fret_note(fret_no) fret_note = @root_note fret_no.times{ fret_note = fret_note.next } fret_note end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/stringed/instrument_string.rb', line 31 def to_s @root_note.to_s end |