RSS Amplifier

Adrian Sieber's Website · Sep 12, 2018

<code>uku<&#x2F;code> — A Haskell CLI tool to display Ukulele fingering charts

0
Sign in to vote or save

This page did not load. You can still read it on the original site — the toolbar below keeps your place in the directory.

TLDR: This is a tutorial on how to write a CLI tool in Haskell to display fingering charts for the Ukulele in your terminal. As this post is written in literate Haskell , it also contains the complete code for the program itself. If you just want to use the tool check out the short how to at the end. While I originally started to write this 2 years ago (I thought it&#x27;s about time to finish it…

TLDR:</strong> This is a tutorial on how to write a CLI tool in Haskell to display fingering charts for the Ukulele in your terminal. As this post is written in literate Haskell</a>, it also contains the complete code for the program itself. If you just want to use the tool check out the short how to</a> at the end.</p>

While I originally started to write this 2 years ago (I thought it's about time to finish it 😛) in JavaScript, I recently got introduced to Haskell and it's awesome. Especially for building CLI tools</a>.</p>

First a short overview of what it's actually supposed to do. This is our target output:</p>

Output of command &quot;uku g&quot;</p>

You specify a chord and uku</code> pretty prints the fingering chart as an ANSI art chord box</a> to the terminal. Cool, right? So let's get started with the code:</p>

First, we need to set a few compiler settings and import some basic modules:</p>

{-#</span> OPTIONS_GHC</span> -Wall -Wincomplete-uni-patterns #-}</span></span>
{-#</span> LANGUAGE NoImplicitPrelude</span> #-}</span></span>
{-#</span> LANGUAGE OverloadedStrings</span> #-}</span></span>
{-#</span> LANGUAGE MultiWayIf</span> #-}</span></span>
</span>
module</span> </span>Main</span> where</span></span>
</span>
import</span> </span>Protolude</span> as</span> </span>Pl</span></span>
</span>
import</span> </span>Data.List.Index</span> (</span>setAt</span>,</span> imap</span>)</span></span>
import</span> </span>Data.Map.Strict</span> as</span> </span>Map</span></span>
import</span> </span>Data.Text</span> as</span> </span>Text</span></span></code></pre>

Now we need types to model our domain. Normally you'd expect something like data Note = C | Cis | D | Dis …</code>, but this notation is mostly used for historical reasons and not for its ingeniousness. E.g. the distance between E</code> and F</code> is half the distance of F</code> to G</code> 🤦. The notation just doesn't make a lot of sense in times of the twelve-tone equal temperament</a>. I'll call this notation the "arachaic notation" for the rest of the post.</p>

Actually, even the notion of absolute note values isn't particularly useful, as western music is inherently relative and you can start the same song from every note. To accommodate this we simply model everything relatively and only make the common note names and the particular tuning of the Ukulele a special instance of it. I'll call this notation the "relative notation".</p>

A Piano supports 88 notes and MIDI supports 128 notes. An octave contains 12 notes and so we can use a base 12 (duodecimal</a>) system to simplify counting in octaves. The duodecimal system uses 2 special unicode characters for ten and eleven, called Pitman digits:</p>

Read on adriansieber.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.