How to tune your Guitar with Powershell

I wanted to celebrate my 100th article doing something simple and out of the ordinary. Looking back one popular article using PowerShell written 2 years ago was Text-To-Speach in 3 lines of code,  so I’ve decided to play with sounds.

In this article, you will use PowerShell to tune your Guitar!

I love music and I play the guitar, I thought that would be really interesting to show how you can leverage your programming skills and create something useful with basically a one-liner.

This is a perfect example that I would use to introduce Powershell to somebody that is not coming from a background in software development.

There are enough topics to talk about for more than 1/2 hour concepts outlined here from the variable declaration, arrays, piping, foreach-object, casting, function overloading in an oneliner. 

How to tune your Guitar with Powershell

This oneliner script will play for you 6 notes (E,A,D,G,B,E) sequentially for 4 seconds each and will allow you tuning your guitar via the console. 

I’ve declared the variables on top of the oneliner in case you want to easily change the pitch from standard tuning (at 440hz) or the duration of the note.

If you play the bass guitar your E-A-D-G strings will be one octave below so you can simply divide the frequencies above by 2 (41, 55, 73, 98). 

If you play the Ukulele, Banjo or any other string instrument you can simply replace the frequencies. 

How does it work?

The .NetFramework made it possible, PowerShell is just calling a System.Console.Beep method and passing 2 integers (pitch frequency and duration).  Have a look at the documentation.

I really hope you have fun playing music and programming with PowerShell. As usual, you can find this script on my GitHub repository. 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.