Metronome Project

As a musician, I practice to a metronome. I have used physical metronomes and digital ones. Up until recently, I used a metronome app on my phone which did what I needed it to do. I switched to a desktop metronome as it better suited my situation. In attempting the switch, I noticed a slight problem.

There are a limited amount of metronome apps available for the desktop!

I searched for metronomes in the mobile app stores and got dozens of hits. When I did the same search for the desktop version, I got hits, but many of them were too complex for what they should be.

I decided to take action and develop my own desktop Metronome!

The Process

Using Python as the programming language for this project made it relatively easy to code. Python comes with a GUI framework called Tkinter which suits lightweight apps and so I used it to develop the metronome.

First, I decided to draw a mock-up as to how the GUI should look. It had four main components which can be seen on the photo displayed to the left (BPM, Time, Label, Start/Stop).

Then, I worked out how the code was going to look. I decided to set the app in a class with a separate interface initiate method and interface interaction methods. The script calls main which in return calls the class app. This is a great way to create an app as it separates each component into logical parts.

After the two above steps, I then got to work coding the metronome. I designed the app around my target audience, musicians who want a desktop metronome. So, I made the metronome easy to use and added features most musicians would need out of their metronome.

Lessons and Code Snippets

There was one lesson I learned while developing this app that I would like to discuss. It came from solving an issue with Tkinter’s Label Widget. I have used this widget in other projects (such as PracticeJournal and DesktopHub), but have not encountered a problem such as the one I will explain.

In order to have the visual count on the metronome work, the label widget needed to be updated to the appropriate count. To do this, I needed to initiate what’s called a StringVar(). A StringVar() is a Tkinter variable which is a string variable that can be used with Tkinter widgets.

Below is the __init__ code I used for the metronome app (note the StringVar() variable):

def __init__(self, root, beats):
        self.root = root
        self.beats = beats

        self.start = False
        self.bpm = 0
        self.count = 0
        self.beat = 0
        self.time = 0

        self.var = StringVar()
        self.var.set(self.count)

        self.interface()

StringVar().set(self.count) is used to change the Tkinter variable. This is important as in this case, I use it to initiate the count (self.count) to 0.

Once the user presses the “Start” button, this variable must be changed and updated to show the correct count. This is done using the counter() method I defined in the class Metronome shown below:

def counter(self, spinbox):
            ...
            self.count += 1
            self.var.set(self.count)

            if self.count == 1:
                Beep(880, 100)
            elif self.count >= self.beat:
                self.count = 0
                Beep(440, 100)
            else:
                Beep(440, 100)

            # Calls this method after a certain amount of time (self.time).
            self.root.after(self.time, lambda: self.counter(spinbox))

The main code that runs the metronome’s delay is the last line in the above example. This line calls the counter method (its own method) after a certain amount of time has elapsed. This time is varied by the number the user enters into the BPM Entry widget.

Overall

This was a great project to code and is one of my favorite apps that I have developed. It’s simple, easy-to-use, and serves a purpose among the music community.

If you would like to check the metronome out, visit the Metronome repository and follow the installation and how-to-use instructions in the README.md project file.

If you are a musician wanting a desktop metronome that works, this app is for you!

Could you benefit from a desktop application such as the metronome app described above? Are you a musician who could use such an app? If so, leave your comments below and tell me your thoughts on the app!

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ivy Bell
Ivy Bell
2 months ago

I like the efforts you have put in this, regards for all the great content.