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.
-
#frets ⇒ Object
readonly
Returns the value of attribute frets.
-
#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(format, options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(root_note, options = {}) ⇒ InstrumentString
Returns a new instance of InstrumentString.
8 9 10 11 12 |
# 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) @frets =* (1..@fret_count) 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 |
#frets ⇒ Object (readonly)
Returns the value of attribute frets.
6 7 8 |
# File 'lib/stringed/instrument_string.rb', line 6 def frets @frets 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
28 29 30 |
# File 'lib/stringed/instrument_string.rb', line 28 def self.octave_down(fret_no) fret_no - 12 end |
.octave_up(fret_no) ⇒ Object
24 25 26 |
# File 'lib/stringed/instrument_string.rb', line 24 def self.octave_up(fret_no) fret_no + 12 end |
Instance Method Details
#find(note_name) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/stringed/instrument_string.rb', line 36 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
44 45 46 47 48 49 50 |
# File 'lib/stringed/instrument_string.rb', line 44 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
20 21 22 |
# File 'lib/stringed/instrument_string.rb', line 20 def fret_no(fret_note) Music::Note.note_distance(@root_note.to_s, fret_note.to_s) end |
#fret_note(fret_no) ⇒ Object
14 15 16 17 18 |
# File 'lib/stringed/instrument_string.rb', line 14 def fret_note(fret_no) fret_note = @root_note fret_no.times{ fret_note = fret_note.next } fret_note end |
#to(format, options = {}) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/stringed/instrument_string.rb', line 52 def to(format,={}) require "stringed/formatters" if format == :ascii then Formatters::ASCIIString.new(self,) end end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/stringed/instrument_string.rb', line 32 def to_s @root_note.to_s end |