Introduction
Musical Instrument Digital Interface (MIDI) serves as the industry standard for digital music representation. However, for researchers and developers, MIDI data often presents significant hurdles. Two primary issues include the lack of semantic labeling—where tracks are not explicitly identified as melody, bass, or harmony—and the "pitch spelling" problem, where MIDI's numerical note representation fails to distinguish between enharmonic notes (e.g., G# vs. Ab). These distinctions are crucial for accurate music theory analysis and the curation of clean datasets for generative AI.
Midi Miner is a Python library designed to address these challenges by providing automated tools for calculating tonal tension and classifying the musical function of MIDI tracks.
Methodology
The library's architecture is built upon two core components: the Spiral Array model and a Random Forest classifier.
The Spiral Array and Tonal Tension
Developed by Professor Elaine Chew, the Spiral Array is a 3D mathematical model that maps pitch classes, chords, and keys onto a helix. Midi Miner utilizes this model to resolve pitch spelling by estimating the most likely note names based on the global context of the file. Once mapped, the library calculates three primary measures of tonal tension:
- Cloud Diameter: Serves as a proxy for dissonance.
- Cloud Momentum: Measures tonal movement over time.
- Tensile Strain: Represents the geometric distance between current notes and the global key.
Track Classification
To automate the organization of MIDI files, Midi Miner employs a Random Forest classifier. The model uses 30 extracted features per track to determine its musical role: melody, bass, or harmony. This "disentanglement" process is vital for preparing structured data from raw, multi-track MIDI sources.
Tonal Tension Analysis
A significant capability of Midi Miner is its ability to detect structural changes in music through mathematical modeling. By monitoring fluctuations in tensile strain, the library can identify key changes. A spike in the ratio of tensile strain between adjacent windows, sustained over four consecutive windows, serves as a reliable indicator of a shift in the tonal center.
Experimental Results
The track classifier was trained and evaluated using a dataset of 5,006 Chinese pop songs. A subset of 3,265 files with manual labels provided the ground truth for melody, bass, and harmony tracks. Using a 25% test split, the classifier demonstrated high performance across all categories.
The model achieved F1 scores of 0.94 for melody, 0.95 for bass, and 0.91 for harmony, indicating a robust balance between precision and recall.
Conclusion and Future Work
Midi Miner effectively bridges the gap between raw MIDI data and high-level musical analysis. While the current version excels at tonal analysis and track classification for pop music, future iterations aim to include drum track analysis, expand the feature set, and incorporate more diverse musical genres to improve the model's generalizability.
Summary updated