This is a new music instrument. Its design reflects harmony, explained below.

Instructions: Press keys on the right to play sounds, and occasionally press a key on the left to change the harmony. These green text links will play sound. (Make sure your sound is on. If you're on mobile, you will have to tap once before it'll let you play. On iOS, make sure the Silent Mode switch is off.) Click this to play Debussy's Passepied.

The green numbers specify a multiple of a fundamental frequency. For example, if the fundamental frequency is 100 Hz, then 4 → 400 Hz, 5 → 500 Hz. All the notes harmonize (volume warning), so rolling your elbow over the keyboard or sweeping your mouse will sound consonant. If you hold 3 notes and don't hear the 3rd note, then your keyboard can only handle 2 keys at a time, called "2-key rollover". In that case, use the mouse and keyboard simultaneously. On mobile, horizontal view will make the buttons bigger.

The blue numbers multiply the fundamental frequency. The purple numbers also multiply the fundamental, but permanently. Purple numbers come in pairs that undo each other. Multipliers on the far left (7/6) are more exotic than ones in the middle (1/2). The yellow square moves right when the fundamental is multiplied by 5, and the blue, green, and red squares correspond to 2, 3, and 7. These four colored squares show the current fundamental as a product of the 4 primes.

Don't worry if you don't understand some things, or don't know any music theory. The keyboard is designed to sound good even when you don't know what you're doing. Just press some keys on the right, and occasionally press a key on the left. Further goals are to choose some rhythm and try some chords.

An amusing exercise is to start one of the green text links at the top, then press random blue keys to interfere with the performance. This creates a strange alteration.

How harmony works

This section gives a friendly and inexact introduction to harmony. It should be new to everyone, including musicians.

A sound has a collection of frequencies. If two of these frequencies are close, but not equal, then we perceive a beating sound, called "roughness". Roughness causes dissonance. In the following graph: if one frequency is 200 Hz and the other frequency is from 200 Hz - 400 Hz, then the x-axis is the second frequency, and the y-axis is roughness.

roughness graph with 200 Hz lower tone, formula from Sethares

We can see that two frequencies are consonant when they're either very very close, or far. They're most dissonant when moderately close.

More precisely, roughness appears from the linear combinations (sums and differences) of frequencies. Consonance requires these linear combinations to be either very close to 0 or far from 0, but not moderately close to 0. For example, 200 Hz, 310 Hz, 400 Hz is slightly dissonant because 200 - 310 * 2 + 400 = 20, which is close to 0, while 200 Hz, 300 Hz, 400 Hz is consonant. The more terms in the combination, the weaker it is: so 5a + 6b - 3c, with 5 + 6 + 3 = 14 terms, matters a lot less than 2a + b - c, with 4 terms. a - b is the strongest combination, and it gives the original definition for roughness, comparing two frequencices.

A music note usually has a fundamental frequency, like 300 Hz. Playing this note will sound the multiples of 300 Hz: 300 Hz, 600 Hz, 900 Hz, 1200 Hz, etc. Higher multiples (called harmonic overtones) are lower in volume.

As a consequence, if you don't want to do any math, you can take this shortcut: frequency ratios with small numbers are consonant. For example, 8 6 is consonant because 8/6 = 4/3 has small numbers. 4 7 is dissonant because 4/7 has the large number 7. This shortcut works for pairs of notes and falls apart for triads and higher.

Here are some examples of harmony:

The major and minor chords have the same pairwise ratios: 4:5:6. These ratios are small, which contributes to consonance. However, the major chord (4 5 6) is an arithmetic progression and the minor chord (10 12 15) is not, so the minor chord is more dissonant.

A more complex example is the dissonant chord 8 10 12 15 18. This is two 4 5 6 chords stacked on each other, forming two arithmetic progressions with different spacing. But it sounds consonant as a sequence. This difference is because linear combinations matter for chords, so the differing arithmetic progressions cause dissonance, but linear combinations don't matter for sequences. On the other hand, 8 10 12 14 16 is consonant, because it's a single arithmetic progression, while its sequence has tension in the fourth note.

Musicians have vague or complicated ideas about why the major and minor scales work. Actually, the constructions are simple and logical. The major scale is 8 9 10 32/3 12 40/3 15 16, which mixes the multiples of two fundamentals: 1 and 8/3. The minor scale is 8 9 48/5 54/5 12 64/5 72/5 16, which mixes the multiples of two fundamentals: 1 and 2/5. And the major scale is more consonant, because 3 is a more consonant prime than 5.

On this instrument, it's easy to calculate the ratios and linear combinations, so harmony is simple. On a piano, harmony is considerably harder, requiring you to count keys, memorize approximations of 2n/12, and do fractional arithmetic. So musicians generally memorize the harmonies, but you don't need to. It's more fun and satisfying to understand harmony than to memorize harmony. There are too many strange and obscure chords to memorize anyway.

With this explanation of harmony, we can understand the logic behind the instrument. The green keys and their overtones are multiples of a single fundamental frequency N, so their sums and differences are also multiples of N. This means any linear combination is either 0 or at least N away from 0, satisfying the condition for consonance. Thus, the notes harmonize with each other. Conversely, if any key were not a multiple of N, its overtones and linear combinations would be dissonant with the other notes. (There are minor exceptions like 1/2 and 2/3.) So the multiples of a single frequency form a uniquely coherent set, represented by the green keys.


This instrument has a slight accuracy advantage over a piano, since it uses just intonation instead of 12 equal temperament. 12 equal temperament rounds intervals to enable modulation. This instrument modulates using the purple keys, so it doesn't need rounding. This difference is visualized: when you press green keys, sometimes the cyan square doesn't quite line up with the piano keys below, and the misalignment is the frequency difference. The biggest accuracy improvement is with 7: 5 6 7 is cleaner than the diminished triad, and 4 5 6 7 is cleaner than the dominant 7th. It's more audible at high volume, because roughness scales nonlinearly with volume.

The keys are all close together, so you can play fast and wide intervals without reaching. Fat-fingering multiple keys with one finger is useful rather than dissonant.

The fundamental is analogous to tonality, and purple/blue keys shift the fundamental. The purple keys are ratios, because ratios like 5/4 need fewer presses to modulate than integers like 5. Plus, ratios move pitch less, so random ratios sound good and random integers do not. There's a logical pattern to the green keys that accords with consonance, described at this link.

This pattern in the purple and green keys creates a wonderful map: the physical distance between notes on the keyboard is approximately their dissonance. For example, if you press 1 purple key and move 3 spaces in the green keys, the new note's dissonance is about "4". So you have an easy estimate of consonance, just looking visually at the keyboard. In improv and composition, this helps restrict your attention to the relevant choices. For beginner composers, this guidance is impactful, as they no longer have to test many wrong notes to find the ones which fit.

The numbers on the keyboard allow you to read consonance directly by calculating harmony; you don't have to test chords to know how they'll sound. That's useful when composing, but has no direct benefit for performance.

The disadvantage of this instrument is that you have to press purple/blue keys, which aren't necessary on a piano. These add 25% extra keypresses. The timing can be difficult if a purple key is between two fast notes.

This instrument can't play everything a piano can. It needs 8 thumb keys to be able to, and your computer keyboard doesn't have thumb keys. This comparison isn't quite fair; a piano also can't play everything if simulated by a computer keyboard. But you don't have thumb keys, while you might have a piano, so this is the relevant comparison.

In my testing, this instrument can play all the consonant chords and most of the moderately dissonant chords. It plays chords over 1 fundamental, which encompasses most chords. The remaining chords, like embedded tritones and minor-major chords, require 2 fundamentals and are dissonant. The next section describes this further.

A custom-designed keyboard would enable some cool things. 2 banks of green keys, one for each hand, would let you play any note with either hand. This solves all fingering issues and gives two-handed control of the melody. Purple and blue keys would be moved to the thumbs. Each blue key would modify only one bank of green keys, thus creating a second fundamental, so you can play everything a piano can. Only 48 buttons need complex sensors (polyphonic aftertouch), compared to 76 for a piano. The adjacent keys make 3D expressivity easier to control. The left and right hands can play the timbres of different instruments, so you can be two musicians in one. However, building hardware is out of my reach, so I have no product to sell.

Availability of sheet music is zero. Nobody else uses this instrument, so you have no common platform or shared language with other musicians. If you want to try playing existing songs, there are some rough and tedious steps at this link. In the future, I might write a (midi → Just Intonation) converter to produce some sheet music.

The source code is unminified in this page, and at this git repository. If you're simulating a piano on a computer keyboard or on a screen, consider using this layout instead. It can produce 12 equal temperament if needed, because just as 12 equal temperament approximates just intonation, just intonation also approximates 12 equal temperament.

Discussion: Hacker News, Tildes

Author: Kevin Yin

Appendix: Why music matches the instrument's keys

You probably don't want to bother reading this section unless you are really interested in music; it is technical and relies on many new findings in harmony. The moral of the story is that the instrument can play almost all tonal music, minus a few dissonant chords. A custom keyboard with thumb buttons can play the remaining chords.

A musical sound is a sum of sines with distinct frequencies. I define a sound as "locally consonant" if perturbing any of these frequencies makes it more dissonant. This means it is the most consonant sound in a small region. An example perturbation is changing 200 Hz to 210 Hz or 190 Hz.

The instrument can play any chord whose notes are reasonable multiples of a single fundamental. We'll show that this usually holds for locally consonant sounds. If there are only two frequencies, they are in an integer ratio by aligning overtones to reduce roughness, so clearing denominators makes them multiples of a fundamental. If there are three or more frequencies, and the frequencies are close enough like 4-5.2-6.2, then lattice tones force them to be in an arithmetic sequence, like 4-5.1-6.2. If two of the numbers are in a small-enough ratio, like 4/6.2 ~ 2/3, then lattice tones, prime-ratio harmony, and overtones will push them to be exactly that small ratio, like 4-5-6.

Most music notes are either locally consonant or completely dissonant. Locally consonant notes tend to have a single fundamental. That means the instrument can play everything with the following exceptions:

  1. The minor triad is locally consonant: 1/4, 1/5, 1/6. Its pairwise ratios are small enough to be locally consonant despite dissonance from lattice tones. Octave transformations of these notes also retain this property. Thus, 20 and 24 have been added to the instrument. I ran out of space for 40 and 48.
  2. If the lattice tones do not overlap the frequencies, there can be large denominators, and pitch rounding is allowed. For example, 1 and 6/5 and 6 and 5 8 are consonant. These pairs are less consonant when put together, but they are far apart in frequency, so their lattice tones barely interact, and their amalgam is locally consonant. Note that if we doubled the pitch of the first phrase to 2 and 12/5, the amalgam would be very dissonant.
  3. If you play notes very quietly, lattice tones scale faster than prime-ratio harmony and hence disappear. So while 1/6, 1/7, 1/8 is very dissonant, it is not dissonant if played quietly.
  4. You might not care about local maxima of consonance. For example, 1.1 10 12 is not locally consonant, because moving 1.1 to 1 makes it more consonant. However, 1.1 interacts weakly enough with the other frequencies that the sound is consonant overall. Composers sometimes seek to maximize dissonance, such as with the tritone.
  5. After aligning lattice tones, some arithmetic sequences are far from small ratios, so the pushing force is small. For example, 5 7 9 and 4.9 7 9.1 are similar in behavior, and so are 5 7 8 and 5.1 7 7.95. The piano can't play any of these variations either.

Most of the cases are unimportant or can be played anyway. For example, in the Passepied demo, the chords that can't be played are a minor chord out of range (15 40 48), the tritone at an octave (>2.83< 8 9), and the tritone repeating a prior note (15 >21.6< 40 48). The minor chord is fixed with more keys, but the tritones are not. Debussy bridges the Romantic and Modern eras, so this demo is mildly explorative in dissonance.

Tritones are used for their dissonance, so it's no surprise they cause trouble for a consonant instrument. Tritones can be played as either 7/5 = 1.4 ≈ 1.414, 10/7 = 1.429, or 45/32 = 1.406. As notes are added to a chord, these approximations may be blocked. The diminished seventh is especially dissonant, and there's no hope for rational approximation there.

Since you got to the end, here's a secret button that puts the green numbers on the instrument in descending order. It breaks the green text links and playing randomly doesn't sound good anymore, but it might be easier to find numbers.