69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/fret_viewer/do_something.rb', line 69
def show
root_note = @options[:key].upcase
unless NOTES[:sharp].include? root_note
puts "Note #{@options[:key]} not recognized yet"
exit 1
end
full_scale = [0, 2, 4, 5, 7, 9, 11]
chords = {
"a" => {
scale: [ 0, 4, 7],
label: ''
},
"s" => {
scale: [ 2, 5, 9],
label: 'm'
},
"d" => {
scale: [ 4, 7,11],
label: 'm'
},
"f" => {
scale: [ 5, 9, 0],
label: ''
},
"g" => {
scale: [ 7,11, 2],
label: ''
},
"h" => {
scale: [ 9, 0, 4],
label: 'm'
},
"j" => {
scale: [11, 2, 5],
label: '0'
},
"q" => {
scale: [ 0, 4, 7,11],
label: 'maj7'
},
"w" => {
scale: [ 2, 5, 9, 0],
label: 'm7'
},
"e" => {
scale: [ 4, 7,11, 2],
label: 'm7'
},
"r" => {
scale: [ 5, 9, 0, 4],
label: 'maj7'
},
"t" => {
scale: [ 7,11, 2, 5],
label: '7'
},
"y" => {
scale: [ 9, 0, 4, 7],
label: 'm7'
},
"u" => {
scale: [11, 2, 5, 9],
label: 'o'
},
"1" => {
scale: [0, 2, 4, 7, 9],
label: ' M pent'
},
"2" => {
scale: [0, 2, 5, 7, 9],
label: ' m pent'
},
"3" => {
scale: [2, 4, 7, 9, 11],
label: ' m pent'
},
}
note_index_of_root_note = NOTES[:sharp].index root_note
key_name = root_note
init_screen
begin
crmode
input_key = nil
input_to_show = " "
until input_key == ' ' do
if input_key == input_to_show && chords.keys.include?(input_key)
input_key = 'p' end
if input_key == 'z'
note_index_of_root_note = (note_index_of_root_note + 5) % 12
elsif input_key == 'x'
note_index_of_root_note = (note_index_of_root_note - 5) % 12
else
input_to_show = input_key
end
root_note = NOTES[:sharp][note_index_of_root_note]
chord = chords[input_to_show]
scale = chord && chord[:scale] || full_scale
note_name = NOTES[:sharp][(scale[0] + note_index_of_root_note) % 12]
flat_or_sharp = SHARP_FLAT_MAP[note_name]
note_name_human = NOTES[flat_or_sharp][(scale[0] + note_index_of_root_note) % 12]
root_note_human = NOTES[flat_or_sharp][note_index_of_root_note]
label = chord && "#{note_name_human}#{chord[:label]}" || "#{root_note_human} major"
refresh
STRINGS.reverse.each_with_index do |s, index|
setpos(index,0)
addstr(show_string(s, root_note:, scale:, flat_or_sharp:))
end
setpos(6,0)
if chords.keys.include?(input_to_show)
chord_num = ['a', 's', 'd', 'f', 'g', 'h', 'j', 'q', 'w', 'e', 'r', 't', 'y', 'u', '1', '2', '3'].index(input_to_show) % 7 + 1
roman = ROMAN[chord_num]
addstr("Chord: #{label} (#{roman}#{chord[:label]})#{" " * 40}")
else
addstr("Scale: #{label}#{" " * 40}")
end
setpos(7,0)
addstr("Key: #{root_note_human} ")
setpos(8,0)
input_key = getch
end
ensure
close_screen
end
end
|