Class: WTFChord::GuitarString
Instance Attribute Summary collapse
#interval
Attributes inherited from Pitch
#note, #octave
Instance Method Summary
collapse
Methods inherited from Pitch
#-, #-@, #==, #chord, #move, #to_i, #to_s, #to_str
Constructor Details
#initialize(note, capo = 0) ⇒ GuitarString
Returns a new instance of GuitarString.
9
10
11
12
13
|
# File 'lib/wtf_chord/guitar_string.rb', line 9
def initialize(note, capo = 0)
@fret = nil
@capo = capo
super(note)
end
|
Instance Attribute Details
#capo ⇒ Object
Returns the value of attribute capo.
7
8
9
|
# File 'lib/wtf_chord/guitar_string.rb', line 7
def capo
@capo
end
|
#fret ⇒ Object
Returns the value of attribute fret.
7
8
9
|
# File 'lib/wtf_chord/guitar_string.rb', line 7
def fret
@fret
end
|
#original ⇒ Object
Returns the value of attribute original.
7
8
9
|
# File 'lib/wtf_chord/guitar_string.rb', line 7
def original
@original
end
|
Instance Method Details
#<=>(other) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/wtf_chord/guitar_string.rb', line 63
def <=> other
return if dead?
case other
when Integer then @fret <=> other
when GuitarString then @fret <=> other.fret
end
end
|
#code ⇒ Object
52
53
54
|
# File 'lib/wtf_chord/guitar_string.rb', line 52
def code
dead? ? -1 : to_i
end
|
#dead ⇒ Object
39
40
41
42
|
# File 'lib/wtf_chord/guitar_string.rb', line 39
def dead
@fret = nil
calculate_note!
end
|
#dead? ⇒ Boolean
44
45
46
|
# File 'lib/wtf_chord/guitar_string.rb', line 44
def dead?
@fret.nil?
end
|
#distance_to(pitch) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/wtf_chord/guitar_string.rb', line 56
def distance_to(pitch)
pos = 0
opened = dup.open
pos += 1 while (opened + pos) != pitch
pos
end
|
#hold_on(fret) ⇒ Object
29
30
31
32
|
# File 'lib/wtf_chord/guitar_string.rb', line 29
def hold_on(fret)
@fret = fret
calculate_note!
end
|
#holded? ⇒ Boolean
48
49
50
|
# File 'lib/wtf_chord/guitar_string.rb', line 48
def holded?
!dead? && @fret > 0
end
|
#init_pitch ⇒ Object
15
16
17
|
# File 'lib/wtf_chord/guitar_string.rb', line 15
def init_pitch
@original + capo
end
|
#initialize_dup(other) ⇒ Object
19
20
21
22
|
# File 'lib/wtf_chord/guitar_string.rb', line 19
def initialize_dup(other)
super
__setobj__(@original.dup)
end
|
#open ⇒ Object
34
35
36
37
|
# File 'lib/wtf_chord/guitar_string.rb', line 34
def open
@fret = 0
calculate_note!
end
|
#set_capo(capo) ⇒ Object
24
25
26
27
|
# File 'lib/wtf_chord/guitar_string.rb', line 24
def set_capo(capo)
@capo = capo
calculate_note!
end
|