Midi Miner - A Python library for tonal tension and track classification

Rui Guo, Dorien Herremans, Thor MagnussonarXiv 2019 · arXiv

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:

  1. Cloud Diameter: Serves as a proxy for dissonance.
  2. Cloud Momentum: Measures tonal movement over time.
  3. 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.

Figure 1: Tensile strain fluctuations across bars, with a visible spike indicating a detected key change.

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.

Figure 2: Performance metrics for melody, bass, and harmony track classification.

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

Abstract

We present a Python library, called Midi Miner, that can calculate tonal tension and classify different tracks. MIDI (Music Instrument Digital Interface) is a hardware and software standard for communicating musical events between digital music devices. It is often used for tasks such as music representation, communication between devices, and even music generation [5]. Tension is an essential element of the music listening experience, which can come from a number of musical features including timbre, loudness and harmony [3]. Midi Miner provides a Python implementation for the tonal tension model based on the spiral array [1] as presented by Herremans and Chew [4]. Midi Miner also performs key estimation and includes a track classifier that can disentangle melody, bass, and harmony tracks. Even though tracks are often separated in MIDI files, the musical function of each track is not always clear. The track classifier keeps the identified tracks and discards messy tracks, which can enable further analysis and training tasks.
BibTeX
@misc{guo2019midi,
  author = {Rui Guo and Dorien Herremans and Thor Magnusson},
  title = {{Midi Miner - A Python library for tonal tension and track classification}},
  year = {2019},
  eprint = {1910.02049},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1910.02049},
}
Figure