Reiji's Explorationsin Sound & Structure

October 14, 2026

Independent Knee-Lever Pitch Switching in a Python Just-Intonation Keyboard v1.3 Referencing Tanaka Shōhei’s Organ

Overview:
This project is version 1.3 of a Python just-intonation keyboard developed by Reiji (age 10), referencing Dr. Tanaka Shōhei’s just-intonation organ.

The main update is the separation of pitch-ratio switching into two independently controllable systems, based on the two knee levers of the historical instrument. In v1.2, ordinary alternative intervals and the alternative intervals used for harmonic-seventh-related notes were switched together using a single P key. It was therefore not possible to operate the two groups separately.

In v1.3, the newly introduced O key controls the four harmonic-seventh-related alternatives, while the P key continues to control the other six alternatives. P and O can be switched on or off independently or activated at the same time. The underlying pitch ratios have not been changed; the update changes how the existing alternatives can be selected during performance.

The octave-shift functions, reed-organ-like synthesized timbre, and short attack echo introduced in v1.2 remain available. A performance trial using Fly Me to the Moon demonstrates the v1.3 instrument and its switching mechanism.

Note: The observations and design ideas originate from Reiji and are explained in Japanese. A parent organizes the documentation, and AI assists with English translation and coding. The distinction between Reiji's own observations and the AI assistant's inferences is maintained below.

Reiji's Words and Ideas

Technical Implementation

1. Two independent pitch-switching systems
The six notes controlled by P correspond to the central knee-lever function described for this project. The four notes controlled by O correspond to the left knee-lever function. The following ratios are defined in the v1.3 source code.

P switching — central knee lever

PC keyP OFFP ON
425/2416/15
R75/646/5
F675/51227/20
725/1864/45
U25/168/5
I225/1289/5

O / 7th switching — left knee lever

PC keyO OFFO ON
X9/8800/729
D81/64100/81
G40/273200/2187
H27/16400/243

All ten alternative ratios already existed in v1.2. This version does not change their numerical values. It changes which switching system controls each ratio.

There are four possible operating states: P OFF / O OFF (both groups at their default ratios), P ON / O OFF (six P-group alternatives), P OFF / O ON (four O-group alternatives), and P ON / O ON (both groups of alternatives at once).

The code checks the O override first. However, because the P and O groups contain different keys, they do not conflict in normal operation.

2. State management and frequency calculation
The O key is defined as SEPTIMAL_TOGGLE_KEY = "O". The ratios for X, D, G, and H are stored in SEPTIMAL_OVERRIDES, while the septimal_mode state tracks whether O switching is enabled.

The selected state affects the ratio lookup, frequency and cent calculations, visual ratio labels, and the playback cache. The key labels are refreshed through refresh_ratio_labels() whenever P or O is toggled.

3. Reusing generated audio at identical frequencies
v1.2 prepared sounds for combinations of P state and octave position. v1.3 needs combinations of P state, O state, and octave position. Different combinations can nevertheless produce identical frequencies.

To avoid generating the same sound repeatedly, v1.3 introduces sound_by_freq and attack_echo_by_freq. Once the sustained tone and attack echo for a frequency have been generated, other switching states that use the same frequency can reuse them.

4. Interface and controls
A new O / 7th button appears to the left of the keyboard, below the existing P button. It is purple when OFF and orange when ON. Either the physical O key or a mouse click on the button toggles this state. The visible pitch-ratio labels update when the state changes.

5. Features retained from v1.2
The reference frequency (1/1 = 261.625565 Hz), reed-organ-like harmonic synthesis, short attack echo, and arrangement of white, black, and gray keys remain unchanged.

Q and W still shift the entire keyboard down or up by one octave, A restores the original octave, and the supported shift range remains −2 to +2 octaves. Notes played from the PC keyboard are sustained while the keys are held, while clicking a note with the mouse sounds it for about 0.45 seconds. The display continues to show the last-played note's ratio, frequency, and cent value, and copies its ratio to the clipboard.

Images

Version 1.3 keyboard interface showing separate P and O switching buttons, both OFF

Python Just-Intonation Keyboard v1.3 — Default State

The complete v1.3 interface with two separate switching buttons on the left. Both P and O are OFF, so the default pitch ratios are displayed. The purple O / 7th button indicates that the harmonic-seventh-related alternatives are disabled.

Version 1.3 keyboard interface with O switching ON and alternative ratios shown for X, D, G, and H

O / 7th Switching Enabled

The O button has turned orange. X, D, G, and H now show the alternative ratios 800/729, 100/81, 3200/2187, and 400/243, respectively. P remains OFF, demonstrating that these four notes can be switched independently of the six notes assigned to P.

How to Run the Program

This application is written in Python using tkinter and pygame. Save tanakaOrgan_v1_3.py to a folder. The following example assumes that the file is saved in the Downloads folder. Open PowerShell or a terminal and run:

cd Downloads
python -m pip install pygame
python tanakaOrgan_v1_3.py

To build a Windows executable with PyInstaller, install the tool and run:

python -m pip install pyinstaller
python -m PyInstaller --onefile --windowed tanakaOrgan_v1_3.py

These commands assume Python is available from the command line. Replace Downloads with the actual folder path if needed. The executable will be generated in the dist folder.

Source Code Download tanakaOrgan_v1_3.py
Performance Trial Video Fly Me to the Moon — Python Just-Intonation Keyboard v1.3 Performance Trial
Application Used

Python / tkinter / pygame / AI-assisted coding

Tuning Settings

Reference frequency: 1/1 = 261.625565 Hz

Pitch ratios are represented by rational numbers in a just-intonation framework.

P and O independently select the existing groups of alternative pitch ratios.

Version 1.3 Updates

Separate P and O switching corresponding to two knee-lever functions.

Independent or simultaneous selection of the two groups of alternative intervals.

O / 7th on-screen button and live ratio-label updates.

Frequency-based reuse of generated sound and attack-echo data.

Retained Functions

Reed-organ-like synthesized timbre and attack echo.

Octave shifting from −2 to +2 through Q, W, and A.

The same keyboard layout, default ratios, and alternative ratios as v1.2.

Update Date

October 14, 2026 — Reiji, age 10

Previous Version Python Just-Intonation Keyboard v1.2 — August 31, 2026
Reference

Tanaka Shōhei’s Just-Intonation Organ

Historical organ held in the collection of the Musical Instrument Museum, Kunitachi College of Music.

Kunitachi College of Music, Musical Instrument Museum, Musical Instrument Collection Management Materials 2: Activity Report, 2018 Edition (English rendering of the Japanese publication title), pp. 5–28.

AI Assistant’s Notes and Inferences

The defining feature of v1.3 is not the introduction of new pitch ratios, but a redesign of the control structure to reflect the independently operated knee levers of the historical instrument. The following observations distinguish implemented behavior from possible musical interpretations.

  • From ratio mapping to control-mechanism modeling. The ten alternative ratios were already present in v1.2, but one switch controlled all of them. Separating the switching groups makes it possible to reproduce more combinations of settings. This extends the project from mapping pitches numerically toward modeling how they are selected in performance.
  • A possible explanation for the improved consonance. Reiji reports that certain harmonic-seventh-related passages sound less muddy after the update. Since the ratios themselves are unchanged, one plausible explanation is that O can now select its four alternative notes without simultaneously changing the six P-group notes. The benefit may therefore come from choosing more suitable combinations of pitches, rather than from improving the accuracy of individual ratios. No quantitative beating or spectrum measurements are supplied here.
  • Distinguishing the label “harmonic seventh” from a strict 7-limit ratio. Although the O switch is described in this project as a harmonic-seventh-related function, the four programmed ratios—800/729, 100/81, 3200/2187, and 400/243—contain only the prime factors 2, 3, and 5. They are therefore 5-limit ratios, not exact 7-limit intervals such as 7/4. They should also be distinguished from the seventh harmonic component used in v1.2's timbre synthesis.
  • State management and audio reuse. Adding a second switch multiplies the number of control-state combinations. The frequency-keyed caches allow states that result in the same pitch to share their generated audio. This avoids redundant sound generation while preserving the independent P/O controls.
  • Position in the project's development. Earlier versions focused on pitch-ratio playback, sound design, and extending the playable octave range. Version 1.3 preserves those functions while bringing the switching interface closer to the described operation of Tanaka Shōhei’s organ. Reiji's decision to address an audible performance problem through control restructuring, rather than by changing the numerical ratios, is a notable feature of this iteration.