-
Notifications
You must be signed in to change notification settings - Fork 0
/
fretboard_app.py
699 lines (621 loc) · 25.6 KB
/
fretboard_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
from PyQt5 import QtWidgets, QtCore, QtGui
from fretboard_ui import Ui_MainWindow
from fretboard import Fretboard
import fretboard_rc
from musthe import *
import sys
import pandas as pd
from overloadedQtClasses import QLabelClickable
from helpDialog import HelpDialog
import json
import argparse
settingsFile = "fretboard_settings.json"
helpMessages = [
['<space>', 'Toggle between scale and chord'],
['I', 'Show notes or (I)ntervals'],
['N', 'Revert number of frets to (N)ormal'],
['Arrows', 'Select root note and type'],
['M', 'Toggle between (M)ajor and (M)inor modes'],
['Fret buttons', 'Click to zoom in on frets'],
['Left click', 'Set/unset transparency on a note/interval'],
['Right click', 'Set root note to the note below the cursor'],
['?', 'Display this message']
]
fullFretboard = 2000
firstFret = fullFretboard / 18
remaining = fullFretboard - firstFret
fretWidths = [round(firstFret)]
for i in range(25):
nextFret = remaining/18
remaining = remaining - nextFret
fretWidths.append(round(nextFret))
labelColors = [
"background-color: rgba(205, 253, 205, 80%);",
"background-color: rgba(147, 223, 199, 80%);",
"background-color: rgba(173, 215, 229, 80%);",
"background-color: rgba(247, 247, 185, 80%);",
"background-color: rgba(255, 210, 127, 80%);",
"background-color: rgba(254, 160, 122, 80%);",
"background-color: rgba(217, 170, 174, 80%);"
]
interval_colors = {
'm': "background-color: lightBlue; color: black;", #labelColors[2],
'M': "background-color: lightGreen; color: black;", #labelColors[0],
'd': labelColors[6],
'P': "background-color: yellow; color: black;", #"background-color: rgba(220, 220, 170, 80%);", #labelColors[0],
'A': labelColors[5],
'P1': "background-color: red; color: white; border-color: black;"
}
replacementStrings = {
'dim ': 'diminished ',
'_': ' ',
'min ': 'minor ',
'maj ': 'major ',
'aug ': 'augmented '
}
def translate(string):
string=string.replace('b', '♭')
string=string.replace('#', '♯')
return string
def populateFretboard(ui, notes, intervals, frets):
# Set up all the labels with notes or intervals on them
ui.labels = []
if ui.showInterval:
fretboard = intervals
else:
fretboard = notes
# We don't want to show the tuning after the nut as a fret, so we cut that column out.
if min(frets) == 0:
fret_slice = range(1, frets[1]+1)
df = pd.DataFrame(fretboard)
fretboard = df[ fret_slice ].values.tolist()
# Setting up the labels...
for i, row in enumerate(fretboard):
labelRow = []
for j, column in enumerate(row, start=1):
label = QLabelClickable(ui.centralwidget, text=translate(column))
label.clicked.connect(lambda x=label: toggleTransparency(x))
label.selected.connect(lambda x=label: selectRootFromLabel(x))
label.setMinimumSize(QtCore.QSize(fretWidths[j+1], 40)) #(40, 40))
label.setMaximumSize(QtCore.QSize(fretWidths[j+1], 40)) #(40, 40))
label.setObjectName(column)
font = QtGui.QFont()
font.setPointSize(12)
label.setFont(font)
ui.gridLayout.addWidget(label, i, 2*j+1, 1, 1)
labelRow.append(label)
ui.labels.append(labelRow)
# "Flatten" the notes and intervals into a single list for easy lookup.
flattenedNotes = []
flattenedIntervals = []
for row in notes:
flattenedNotes += row
for row in intervals:
flattenedIntervals += row
# Setting up the colors corresponding to the intervals.
for row in ui.labels:
for label in row:
if label.text() != '':
label.setAlignment(QtCore.Qt.AlignCenter)
label.setFrameShape(QtWidgets.QFrame.Box)
label.setLineWidth(3)
if ui.showInterval:
interval = label.objectName()
if interval != "P1":
intervalType = interval[0]
else:
intervalType = interval
else:
try:
interval = flattenedIntervals[flattenedNotes.index(label.objectName())]
if interval != "P1":
intervalType = interval[0]
else:
intervalType = interval
except ValueError:
intervalType = ''
label.setStyleSheet("QLabel"
"{"
"border : 3px solid ;"
f"{interval_colors.get(intervalType, labelColors[6])}"
"border-color : black"
"}")
# Set up the frets themselves as ui lines.
ui.lines = []
for i in range(1, len(ui.labels[0])+1):
line = QtWidgets.QFrame(ui.centralwidget)
line.setMinimumSize(QtCore.QSize(5, 5))
line.setFrameShadow(QtWidgets.QFrame.Raised)
line.setLineWidth(3)
line.setMidLineWidth(0)
line.setFrameShape(QtWidgets.QFrame.VLine)
line.setObjectName(f"freLine{i}")
ui.gridLayout.addWidget(line, 0, 2*i, ui.strings, 1)
ui.lines.append(line)
i = i + 1
# Set up the fret buttons.
fretMarker = "●"
ui.fretMarkers = []
ui.fretButtons = []
j = 1
for fret in range(frets[0], frets[1]+1):
if fret > 0:
button = QtWidgets.QPushButton(ui.centralwidget)
button.setMinimumSize(QtCore.QSize(fretWidths[fret - frets[0]+1], 40)) #(40, 40))
button.setMaximumSize(QtCore.QSize(fretWidths[fret - frets[0]+1], 40)) #(40, 40))
font = QtGui.QFont()
font.setPointSize(12)
button.setFont(font)
button.setObjectName("fretButton" + str(fret))
button.setText(str(fret))
button.setFocusPolicy(QtCore.Qt.ClickFocus)
ui.gridLayout.addWidget(button, ui.strings, 2*j+1, 1, 1)
ui.fretButtons.append(button)
button.clicked.connect(lambda state, x=fret: setFret(x))
j = j + 1
if fret in ( ui.markers['single'] + ui.markers['double'] ):
dot = QtWidgets.QLabel(ui.centralwidget, text=translate(column))
dot.setAlignment(QtCore.Qt.AlignCenter)
if fret in ui.markers['single']:
dot.setText(fretMarker)
else:
dot.setText(fretMarker+fretMarker)
ui.gridLayout.addWidget(dot, ui.strings+1, 2*j-1, 1, 1)
ui.fretMarkers.append(dot)
# Set up the "tuning peg" values and interval colors if open strings are on the chord or scale.
for i, peg in enumerate(ui.tuningButtons):
text = ui.tuning[i]
peg.setStyleSheet("QLineEdit")
try:
interval = flattenedIntervals[flattenedNotes.index(text)]
if interval != "P1":
intervalType = interval[0]
else:
intervalType = interval
except ValueError:
interval = ''
for row in notes:
for note in row:
if text == note:
peg.setStyleSheet("QLineEdit"
"{"
"border : 3px solid ;"
f"{interval_colors.get(intervalType, labelColors[6])}"
"border-color : black"
"}")
else:
for enharmonicRow in ui.enharmonics:
if (text in enharmonicRow and note in enharmonicRow):
interval = flattenedIntervals[flattenedNotes.index(note)]
if interval != "P1":
intervalType = interval[0]
else:
intervalType = interval
peg.setStyleSheet("QLineEdit"
"{"
"border : 3px solid ;"
f"{interval_colors.get(intervalType, labelColors[6])}"
"border-color : black"
"}")
peg.setText(translate(text))
def selectRootFromLabel(label):
# Set the root note to the note right-clicked.
selected = label.objectName()
if selected in ui.rootNotes:
ui.rootNoteSelector.setCurrentText(selected)
else:
# If needed: Look up enharmonics.
for row in ui.enharmonics:
if selected in row:
for note in row:
if note in ui.rootNotes:
ui.rootNoteSelector.setCurrentText(note)
break
changeScaleOrChord()
def toggleTransparency(label):
if not label.transparency:
ui.opacity_effect = QtWidgets.QGraphicsOpacityEffect()
ui.opacity_effect.setOpacity(0.3)
else:
ui.opacity_effect = QtWidgets.QGraphicsOpacityEffect()
ui.opacity_effect.setOpacity(1.0)
label.setGraphicsEffect(ui.opacity_effect)
label.transparency = not label.transparency
def setFret(fret):
# Set new fret selection
if not ui.fretSelected:
# Is this the first or the second fret selected in the range?
ui.fretSelected = True
ui.firstFretSelected = fret
for row in ui.labels:
try:
index = fret - ui.frets[0]
if ui.frets[0] == 0:
index = index - 1
row[index].setStyleSheet("QLabel"
"{"
f"{interval_colors['m']}"
"}")
ui.statusbar.showMessage("Click the next fret to zoom in on the fretboard.", 10000)
except IndexError:
pass
else:
# If second, we set up the new fret tuple and rebuild.
ui.fretSelected = False
ui.secondFretSelected = fret
if ui.firstFretSelected != ui.secondFretSelected:
ui.frets_old = ui.frets
ui.frets = (ui.firstFretSelected, ui.secondFretSelected)
ui.frets = tuple(sorted(ui.frets)) # You can select in any order.
update()
ui.statusbar.showMessage(f"Zooming in on frets {str(ui.frets[0])} to {str(ui.frets[1])}.", 10000)
else:
update()
ui.statusbar.showMessage("Reverting to previous fret selection.", 10000)
ui.rootNoteSelector.setFocus()
def clearFromGrid(widget):
ui.gridLayout.removeWidget(widget)
widget.setParent(None)
widget.deleteLater()
def update():
# Updates the GUI.
# Track if we are switching between chord and scale or not.
showChord_old = ui.showChord
ui.showChord = ui.scaleOrChordSlider.value()
ui.showInterval = ui.notesOrIntervalsSlider.value()
# If the note/chord slider is changed, update the corresponding combo box to reflect the change.
if ui.showChord != showChord_old:
selection = ui.scaleOrChordTypeSelector.currentText()
if ui.showChord:
ui.scaleOrChordTypeSelector.clear()
ui.scaleOrChordTypeSelector.addItems(ui.allChords)
# Try to switch to minor if we're in minor.
if ('minor' in selection) or (selection == 'aeolian'):
ui.scaleOrChordTypeSelector.setCurrentText('min')
type = ui.scaleOrChordTypeSelector.currentText()
root = ui.rootNoteSelector.currentText()
ui.chord = Chord(Note(root), type)
else:
ui.scaleOrChordTypeSelector.clear()
ui.scaleOrChordTypeSelector.addItems(ui.allScales)
if 'min' in selection:
ui.scaleOrChordTypeSelector.setCurrentText('natural_minor')
type = ui.scaleOrChordTypeSelector.currentText()
root = ui.rootNoteSelector.currentText()
ui.scale = Scale(Note(root), type)
# Re-build the labels. First remove the old ones.
for row in ui.labels:
for label in row:
clearFromGrid(label)
# Remove the buttons as well.
for button in ui.fretButtons:
clearFromGrid(button)
# And the fret lines:
for line in ui.lines:
clearFromGrid(line)
# And the dots:
for dot in ui.fretMarkers:
clearFromGrid(dot)
# Generate the new notes and intervals.
f = Fretboard(tuning=ui.tuning)
if ui.showChord:
notes, intervals = f.build(chord=ui.chord, frets=ui.frets)
else:
notes, intervals = f.build(scale=ui.scale, frets=ui.frets)
# Generate and populate the new fretboard.
populateFretboard(ui, notes, intervals, ui.frets)
# Show the notes in the chord or scale in the title label.
if ui.showChord:
type = "chord"
notesString = " ".join([str(n) for n in ui.chord.notes])
#intervalsString = ", ".join(ui.chord.recipes[ui.chord.chord_type])
else:
type = "scale"
notesString = " ".join([str(n) for n in ui.scale.notes])
#intervalsString = ", ".join([str(i) for i in ui.scale.intervals])
ui.titleLabel.setText(f"{translate(ui.rootNoteSelector.currentText())} {ui.scaleOrChordTypeSelector.currentText()} {type}: {translate(notesString)}") # {translate(intervalsString)}")
title = ui.titleLabel.text()
try:
for string in replacementStrings.keys():
title = title.replace(string, replacementStrings[string])
ui.titleLabel.setText(title)
except:
pass
# Resize window if number of frets has changed.
if ui.frets_old != ui.frets:
MainWindow.resize(MainWindow.minimumSizeHint())
MainWindow.adjustSize()
ui.frets_old = ui.frets
def tuning(string):
# Deal with changes in tuning from one of the tuning peg input boxes.
old = ui.tuning[string]
ui.tuningButtons[string].setText(ui.tuningButtons[string].text().capitalize())
new = ui.tuningButtons[string].text()
match = False
for row in ui.enharmonics:
for note in row:
if new == note:
match = True
if not match:
ui.statusbar.showMessage(f"Not a valid tuning, reverting to {old}", 10000)
ui.tuningButtons[string].setText(translate(old))
elif old != new:
ui.tuning[string] = new
ui.statusbar.showMessage(f"Tuning is now {''.join(ui.tuning)}", 10000)
update()
def resetFrets():
ui.frets = ui.resetFrets
update()
ui.rootNoteSelector.setFocus()
def changeScaleOrChord():
# Change from scale to chord or back.
try:
delattr(ui, chord)
except NameError:
try:
delattr(ui, scale)
except NameError:
pass
type = ui.scaleOrChordTypeSelector.currentText()
root = ui.rootNoteSelector.currentText()
if ui.showChord:
ui.chord = Chord(Note(root), type)
ui.statusbar.showMessage(f"{root} {type}", 10000)
else:
ui.scale = Scale(Note(root), type)
ui.statusbar.showMessage(f"{root} {type}", 10000)
update()
def toggle(thing):
if thing == 'intervals':
if ui.notesOrIntervalsSlider.value() == 1:
ui.notesOrIntervalsSlider.setValue(0)
else:
ui.notesOrIntervalsSlider.setValue(1)
elif thing == 'chord':
if ui.scaleOrChordSlider.value() == 1:
ui.scaleOrChordSlider.setValue(0)
else:
ui.scaleOrChordSlider.setValue(1)
elif thing == 'majmin':
if ui.scaleOrChordSlider.value() == 1:
if 'maj' in ui.scaleOrChordTypeSelector.currentText():
ui.scaleOrChordTypeSelector.setCurrentText('min')
changeScaleOrChord()
else:
ui.scaleOrChordTypeSelector.setCurrentText('maj')
changeScaleOrChord()
else:
if ('major' in ui.scaleOrChordTypeSelector.currentText()) or (ui.scaleOrChordTypeSelector.currentText() == 'ionian'):
ui.scaleOrChordTypeSelector.setCurrentText('natural_minor')
changeScaleOrChord()
else:
ui.scaleOrChordTypeSelector.setCurrentText('major')
changeScaleOrChord()
ui.rootNoteSelector.setFocus()
return
def select(thing):
if thing == 'mode':
ui.scaleOrChordTypeSelector.setFocus()
elif thing == 'root':
ui.rootNoteSelector.setFocus()
elif thing == 'tuning':
ui.tuningButtons[0].setFocus()
ui.tuningButtons[0].selectAll()
ui.statusbar.showMessage("Change tuning. Tab or Enter to set new tuning, Esc to return.", 10000)
return
def helpMessage(showWindow):
ui.statusbar.showMessage("Press '?' to see list of commands and hotkeys.", 100000)
if showWindow:
helpDialog.show()
def initialSetup(ui):
ui.showChord = False
ui.showInterval = False
ui.fretSelected = False
# List of all the options for Chord() and Scale()
ui.allScales = [ s for s in Scale.scales.keys() ]
ui.allChords = [ c for c in Chord.valid_types ]
ui.scaleOrChordTypeSelector.addItems(ui.allScales)
ui.notesOrIntervalsSlider.valueChanged['int'].connect(update)
ui.scaleOrChordSlider.valueChanged['int'].connect(update)
ui.nutButton.clicked.connect(resetFrets)
ui.rootNoteSelector.activated.connect(changeScaleOrChord)
ui.scaleOrChordTypeSelector.activated.connect(changeScaleOrChord)
ui.rootNoteSelector.notesOrIntervals.connect(lambda thing='intervals': toggle(thing) )
ui.rootNoteSelector.chordOrScale.connect(lambda thing='chord': toggle(thing) )
ui.rootNoteSelector.nut.connect(resetFrets)
ui.rootNoteSelector.mode.connect(lambda thing='mode': select(thing))
ui.rootNoteSelector.tuning.connect(lambda thing='tuning': select(thing))
ui.rootNoteSelector.majmin.connect(lambda thing='majmin': toggle(thing))
ui.rootNoteSelector.help.connect(lambda window=True: helpMessage(window))
ui.scaleOrChordTypeSelector.notesOrIntervals.connect(lambda thing='intervals': toggle(thing) )
ui.scaleOrChordTypeSelector.chordOrScale.connect(lambda thing='chord': toggle(thing) )
ui.scaleOrChordTypeSelector.nut.connect(resetFrets)
ui.scaleOrChordTypeSelector.root.connect(lambda thing='root': select(thing))
ui.scaleOrChordTypeSelector.tuning.connect(lambda thing='tuning': select(thing))
ui.scaleOrChordTypeSelector.majmin.connect(lambda thing='majmin': toggle(thing))
ui.scaleOrChordTypeSelector.help.connect(helpMessage)
ui.nutButton.setFocusPolicy(QtCore.Qt.ClickFocus)
#ui.frets = (0,24)
ui.scale = Scale(Note('C'), 'major')
for i, t in enumerate(ui.tuningButtons):
t.returnPressed.connect(lambda string=i: tuning(string))
t.escape.connect(lambda thing='root': select(thing))
ui.frets_old = ui.frets
f = Fretboard(tuning=ui.tuning)
notes, intervals = f.build(scale=ui.scale, frets=ui.frets)
ui.enharmonics = f.enharmonics
ui.rootNotes = ['C',
'C#',
'Db',
'D',
'D#',
'Eb',
'E',
'F',
'F#',
'Gb',
'G',
'G#',
'Ab',
'A',
'A#',
'Bb',
'B',]
ui.rootNoteSelector.addItems(ui.rootNotes)
populateFretboard(ui, notes, intervals, ui.frets)
MainWindow.resize(MainWindow.minimumSizeHint())
MainWindow.adjustSize()
helpMessage(False) # Just show the prompt in the status bar.
ui.rootNoteSelector.setFocus()
return(True)
def setupHelpDialog(helpDialog):
helpDialogUi = HelpDialog()
helpDialogUi.setupUi(helpDialog)
helpDialogUi.buttonBox.accepted.connect(helpDialog.hide)
for i, row in enumerate(helpMessages):
text1 = row[0]
text2 = row[1]
label1, label2 = [ QtWidgets.QLabel(helpDialog) for i in range(2) ]
label1.setText(text1)
label1.setAlignment(QtCore.Qt.AlignCenter)
label2.setText(text2)
helpDialogUi.gridLayout.addWidget(label1, i, 0, 1, 1)
helpDialogUi.gridLayout.addWidget(label2, i, 1, 1, 1)
helpDialog.setWindowTitle("Commands and hotkeys")
helpDialog.setWindowIcon(QtGui.QIcon(":/icons/guitar.png"))
helpDialog.resize(helpDialog.minimumSizeHint())
helpDialog.adjustSize()
helpDialog.hide()
def writeSettings(settings):
with open(settingsFile, 'w') as f:
json.dump(settings, f)
class MyMainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
def closeEvent(self, event):
settings = {
'tuning': ui.tuning,
'strings': ui.strings,
'frets': ui.frets,
'resetFrets': ui.resetFrets,
'title': MainWindow.windowTitle(),
'markers': ui.markers,
}
print(f"Writing settings to {settingsFile}.")
writeSettings(settings)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
MainWindow = MyMainWindow()
helpDialog = QtWidgets.QDialog()
setupHelpDialog(helpDialog)
ui = Ui_MainWindow()
# First load settings from file if available
try:
with open(settingsFile, 'r') as f:
settings = json.load(f)
ui.tuning = settings['tuning']
ui.strings = settings['strings']
ui.frets = settings['frets']
ui.title = settings['title']
ui.markers = settings['markers']
ui.resetFrets = settings['resetFrets']
except:
ui.tuning = ['B', 'E', 'A', 'D', 'G', 'B', 'E']
ui.tuning = ui.tuning[1:]
ui.strings = 6
ui.frets = (0,24)
ui.title = "Guitar fretboard, scales and chords"
ui.markers = {
'single': [3, 5, 7, 9, 15, 17, 19, 21],
'double': [12]
}
ui.resetFrets = ui.frets
allScales = [ s for s in Scale.scales.keys() ]
allChords = [ c for c in Chord.valid_types ]
rootNotes = ['C','C#','Db','D','D#','Eb','E','F','F#','Gb','G','G#','Ab','A','A#','Bb','B',]
parser = argparse.ArgumentParser(description=f"Select rootnote and type for the scale or chord, as well as other parameters as listed below. The available scales are {allScales} and the available chords are {allChords}.")
parser.add_argument('-r', '--rootnote',
choices=rootNotes,
default='C',
help="The root note of the scale or chord.")
parser.add_argument('-t', '--type',
choices=allScales+allChords,
default='major',
help="The type of scale or chord.")
parser.add_argument('-ff', '--fromfret', type=int, help="The first fret of the fret interval.",
choices=range(1,25))
parser.add_argument('-tf', '--tofret', type=int, help="The last fret of the fret interval.",
choices=range(1,25))
parser.add_argument('-p', '--preset', choices=['ukulele', 'guitar', '7-string', 'banjo'], help="Presets for type of instrument. Edit the fretboard_settings.json for more options.")
parser.parse_args()
args = parser.parse_args()
if args.preset:
if args.preset == 'ukulele':
ui.tuning = ['G', 'C', 'E', 'A']
ui.strings = 4
ui.frets = (0,17)
ui.resetFrets = ui.frets
ui.title = "Ukulele"
ui.markers = {
'single': [3, 5, 7, 10, 15, 17, 19],
'double': [12]
}
elif args.preset == 'guitar':
ui.tuning = ['B', 'E', 'A', 'D', 'G', 'B', 'E']
ui.tuning = ui.tuning[1:]
ui.strings = 6
ui.frets = (0,24)
ui.resetFrets = ui.frets
ui.title = "6-string guitar"
ui.markers = {
'single': [3, 5, 7, 9, 15, 17, 19, 21],
'double': [12]
}
elif args.preset == '7-string':
ui.tuning = ['B', 'E', 'A', 'D', 'G', 'B', 'E']
ui.strings = 7
ui.frets = (0,24)
ui.resetFrets = ui.frets
ui.title = "7-string guitar"
ui.markers = {
'single': [3, 5, 7, 9, 15, 17, 19, 21],
'double': [12]
}
elif args.preset == 'banjo':
ui.tuning = ['G', 'D', 'G', 'B', 'D']
ui.strings = 5
ui.frets = (0,24)
ui.resetFrets = ui.frets
ui.title = "Banjo"
ui.markers = {
'single': [3, 5, 7, 10, 15, 17, 19, 22],
'double': [12]
}
ui.setupUi(MainWindow, strings=ui.strings)
MainWindow.setWindowIcon(QtGui.QIcon(":/icons/guitar.png"))
MainWindow.setWindowTitle(ui.title)
success = initialSetup(ui)
if ( not args.preset ):
if ( args.tofret and args.fromfret):
ui.frets = tuple([args.fromfret, args.tofret])
ui.frets = tuple(sorted(ui.frets))
root = args.rootnote
type = args.type
if type in ui.allScales:
ui.scale = Scale(Note(root), type)
ui.rootNoteSelector.setCurrentText(root)
ui.scaleOrChordTypeSelector.setCurrentText(type)
else:
ui.chord = Chord(Note(root), type)
ui.showChord = True
ui.scaleOrChordSlider.setValue(1)
ui.scaleOrChordTypeSelector.clear()
ui.scaleOrChordTypeSelector.addItems(ui.allChords)
ui.rootNoteSelector.setCurrentText(root)
ui.scaleOrChordTypeSelector.setCurrentText(type)
update()
if success:
MainWindow.show()
sys.exit(app.exec_())
else:
sys.exit()