Skip to content

Instantly share code, notes, and snippets.

Finding a tonal center

Before talking about the spelling of a note (a note has pitch and time properties) I feel it's useful to first guess the tonal center and key that that pitch resides in.

Assumptions about tonal music

To figure out the tonal center of a note we use the other notes in the piece. We make a few observations about tonal music that will help us:

#include <vector>
#include <set>
#include <array>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <math.h>
// Because C++ mod is really remainder not mod
int mod(int a, int b) { return a % b + b * (a < 0); }