Class: Coltrane::Representation::Guitar

Inherits:
Object
  • Object
show all
Defined in:
lib/coltrane/representation/guitar.rb,
lib/coltrane/representation/guitar/note.rb,
lib/coltrane/representation/guitar/chord.rb,
lib/coltrane/representation/guitar/string.rb,
lib/coltrane/representation/guitar/note_set.rb

Direct Known Subclasses

Bass, Ukulele

Defined Under Namespace

Classes: Chord, Note, NoteSet, String

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tuning: nil, frets: nil, special_frets: nil) ⇒ Guitar

Returns a new instance of Guitar.



29
30
31
32
33
34
35
36
37
# File 'lib/coltrane/representation/guitar.rb', line 29

def initialize(tuning: nil, frets: nil, special_frets: nil)
  @tuning        = tuning        || %w[E2 A2 D3 G3 B3 E4]
  @special_frets = special_frets || [3, 5, 7, 9, 12, 15, 17, 19]
  @frets         = frets         || 23

  @strings = @tuning.map do |p|
    String.new(Theory::Pitch[p], guitar: self)
  end
end

Instance Attribute Details

#fretsObject (readonly)

A base class for operations involving Guitars



11
12
13
# File 'lib/coltrane/representation/guitar.rb', line 11

def frets
  @frets
end

#special_fretsObject (readonly)

A base class for operations involving Guitars



11
12
13
# File 'lib/coltrane/representation/guitar.rb', line 11

def special_frets
  @special_frets
end

#stringsObject (readonly)

A base class for operations involving Guitars



11
12
13
# File 'lib/coltrane/representation/guitar.rb', line 11

def strings
  @strings
end

#tuningObject (readonly)

A base class for operations involving Guitars



11
12
13
# File 'lib/coltrane/representation/guitar.rb', line 11

def tuning
  @tuning
end

Class Method Details

.find_chord_by_notation(chord_notation) ⇒ Object



25
26
27
# File 'lib/coltrane/representation/guitar.rb', line 25

def self.find_chord_by_notation(chord_notation)
  Guitar::Chord.find_by_notation(new, chord_notation)
end

.find_chords(target_chord) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/coltrane/representation/guitar.rb', line 13

def self.find_chords(target_chord)
  unless target_chord.is_a?(Theory::Chord)
    target_chord = Theory::Chord.new(name: target_chord)
  end

  Guitar::Chord.find(target_chord, guitar: new)
end

.find_notes(notes) ⇒ Object



21
22
23
# File 'lib/coltrane/representation/guitar.rb', line 21

def self.find_notes(notes)
  Guitar::NoteSet.new(notes, guitar: new)
end