Notes: An iOS Music Theory Library

Thiago Lioy
Cocoa Academy
Published in
3 min readSep 13, 2017

--

A few years ago I wrote an app to help me in the process of learning how to play bass guitar. You can find out more about it in this older post. Recently, a friend of mine called Kaique Pantosi D'amato decided to start a new project with almost the same ambition, help him to learn the guitar. I’ve got inspired in the process and decided to bring back to life my old project, but this time shaped as a swift open source library. Releasing it as a library could have the potential to benefit other people with similar ideas as well as attract collaborators to enhance the project. In this post, I’d like to talk about some of the challenges of creating this music theory library, as well as the importance of unit testing.

Initial Requirements

From the start, i’d like this library to have support to both Cocoapods and Carthage. In order to do that I’ve used the iOS Cookie Cutter project template, which makes the process simpler, you can find how it works in another post of mine here.

The Notes library would need to have the following features to support both my friend’s app and my old app(If I decided to bring it back to life*):

  • Notes
  • Scales
  • Chords
  • Diatonic Harmony
  • Enharmonic Equivalents
  • Tests, Tests, and more Tests …

The reason why tests are essential during this development process is that music theory has a lot of small nuances and variations. Tests, by default are crucial in all projects, and they show how professional the code is. That aside, they are even more important in cases where the number of variations and tests conditions is so huge that manual testing is not an optional at all.

Just to bring some context, this is the file where I test the major scale. There are twelve different variations of this single “Entity” one for each key, including the accidents.

Testing would be much more verbose if I were not using Quick and Nimble, both essential test libraries that make testing in iOS a breeze.

That said, until this moment the app has 350+ tests covering everything from chords to scales, notes, and harmony, among other things, with many others to come in the future.

So, what can I do with it?

Right now the library support the generation of diatonic harmony in all keys as you can see below:

Diatonic harmony? Wait what does this mean? It means that given a key the library can generate chords that work well inside the key, allowing you to create chord progressions that will sound good.

It can also generate a few scales for you in every key, chords, find note equivalents, etc. This information can help you to create chords, scales and educational apps orbiting around the subject of music theory.

Roadmap and beyond ..

Right now the library is still in its early days, so contributors can enhance the project in many ways, however, to give some guidance or at least a first direction to the project I think it would benefit the most from features like:

  • Note frequencies
  • Sound generation from note frequency
  • Additional Scales
  • Sound to Note translation

Hope you guys can check the repository and play with it. As always contributors are more than welcome. Music is like a programming language, with its own set of rules, structure, and syntax. No wonder so many developers play an instrument.

As always any thoughts, doubts or feedbacks are more than welcome. =)

Ps: If you like this post, share it on twitter, recommend it on medium, or both =). This really helps me to reach more people. Thanks a lot ..

--

--

Thiago Lioy
Cocoa Academy

iOS developer, design enthusiast, blogger, weekend cook, guitar player, traveler. Creator of iOS mag: https://medium.com/cocoaacademymag