Skip to content

Instantly share code, notes, and snippets.

@Hypercoded
Last active November 18, 2022 14:38
Show Gist options
  • Save Hypercoded/4d158e19d3893d1235dbaa6df7ea7ec4 to your computer and use it in GitHub Desktop.
Save Hypercoded/4d158e19d3893d1235dbaa6df7ea7ec4 to your computer and use it in GitHub Desktop.
Fretboard Tutor: A quick program I wrote to help me memorize notes on the fretboard when I don't have my guitar with me!
import random
import os
# Settings
gameRange = (0, 5) # 0 is low E, 5 is high E.
strings = ["E", "A", "D", "G", "B", "e"] # works with other tunings too, i think
showOnlyFretboard = True
clear = lambda: os.system('cls' if os.name == 'nt' else 'clear')
def getGuitarNote(string, fret):
notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
# get the note of the open string
note = notes.index(string.upper())
# add the fret number to the note
note += fret
# if the note is greater than 12, subtract 12
if note >= 12:
note -= 12
return notes[note]
def printFretBoard(render):
# prints out a guitar fretboard, and fret markers
for i in reversed(range(0, 6)):
print(strings[i], end=" " if len(strings[i]) == 1 else "")
for j in range(1, 25):
if (strings[i], j) in render:
print(render[(strings[i], j)], end="|")
else:
print("-", end="|")
print("")
print(" • • • • ••")
def findNoteGivenFret():
fret = random.randint(0,12)
string = random.randint(gameRange[0], gameRange[1])
if showOnlyFretboard:
print("What is this note?")
else:
print("What note is on the " + str(fret) + "th fret of the " + (strings[string]) + " string?")
printFretBoard({(strings[string], fret): "X"})
answer = input("Enter the note: ").upper()
if answer == getGuitarNote(strings[string], fret % 12):
print("Correct!")
else:
print("Incorrect! The correct answer is", getGuitarNote(strings[string], fret))
def findFretGivenNoteQuiz():
note = random.randint(0,12)
string = random.randint(gameRange[0], gameRange[1])
print("What fret is the " + (strings[string]) + " string and the " + getGuitarNote(strings[string], note) + " note?")
printFretBoard({})
answer = input("Enter the fret number: ")
if answer == note or int(answer) % 12 == note:
print("Correct!")
else:
print("Incorrect! The correct answer is fret", note)
while True:
clear()
if random.randint(0,1) == 0:
findNoteGivenFret()
else:
findFretGivenNoteQuiz()
input("Press enter to continue...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment