Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

How Can Python Help Navigate the Guitar Fretboard?

Gabriele Albini
Python in Plain English
6 min readDec 7, 2023

--

Photo by Jeremy Allouche on Unsplash

Motivation

1. Creating a Guitar with Python object-oriented programming

2. Building the Guitar Fretboard layout

3. Adding audio to the app

4. Combining everything in a Callback

@callback(Output() # Several page components gets updated
Input()
)
# Inputs from filters, buttons and dcc.Store
def react():
# Step 1 > create a guitar and the complete set of questions
myGuitar, random_positions = notesBuilder() # This is udf (user's defined function) that generates the guitar layout
# Step 2 > Calculate the app mode
store_data, app_mode = calculateMode() # This is a udf that, based on button n_clicks, calculates one of the above 5 modes
# Step 3 > React to the mode
# ----------- FIRST INIT ----------- #
if app_mode == 'first call':
return ... # An empty guitar is returned, together with the play button
# ----------- NEW QUESTION ----------- #
elif app_mode == 'new question':
# Pick a random question from memory
# Display it on the guitar fretboard
# Create the html.Audio component
# Save to memory (both the question and the timestamp)
return ... # The guitar fretboard is modified, highlighting a note; the question is shown together with new buttons
# ----------- NEW ANSWER ----------- #
elif app_mode == 'new answer':
# The user input is cleaned and verified (correct / incorrect)
# The right answer is calculated (using above custom classes) and shown on the guitar
# A dcc.Alert component is generated with a feedback message
# The elapsed time, together with the correct / incorrect info is saved into dcc.Store
return ...
# ----------- STOP (Results review) ----------- #
elif app_mode == 'stop':
# Based on dcc.Store data, all right answers are highlighted on the guitar
# A new dcc.Alert component is generated with the whole results
# dcc.Store data about questions and answers is erased
return ...
# ----------- NO UPDATES ----------- #
else:
raise PreventUpdate

5. Deploying the App

Resources

Thank you for reading till here !

Want to connect? Please click here
Check out my other posts.

PlainEnglish.io 🚀

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Written by Gabriele Albini

Constant Learner, passionate about data analytics, ML and data visualization. Interested in work, tech, music & guitar

Responses (2)

Write a response