
Music Theory for Developers: Why Scales Are Just Arrays
I'm a developer who plays guitar. One day I realized that music theory maps perfectly to programming concepts. If you code and want to learn theory, this is for you. Scales = Arrays A C major scale is just an array: const cMajor = [ ' C ' , ' D ' , ' E ' , ' F ' , ' G ' , ' A ' , ' B ' ]; The formula (in semitones): [2, 2, 1, 2, 2, 2, 1] — whole, whole, half, whole, whole, whole, half. Apply that same formula starting from any note and you get a major scale in that key. It's a function: function majorScale ( root ) { const notes = [ ' C ' , ' C# ' , ' D ' , ' D# ' , ' E ' , ' F ' , ' F# ' , ' G ' , ' G# ' , ' A ' , ' A# ' , ' B ' ]; const pattern = [ 0 , 2 , 4 , 5 , 7 , 9 , 11 ]; // semitone offsets const rootIdx = notes . indexOf ( root ); return pattern . map ( p => notes [( rootIdx + p ) % 12 ]); } Chords = Slicing Arrays A chord is just specific elements from the scale array: function majorChord ( scale ) { return [ scale [ 0 ], scale [ 2 ], scale [ 4 ]]; // 1st, 3rd, 5th } // C ma
Continue reading on Dev.to Beginners
Opens in a new tab




