Abstract
While deep learning has become the dominant paradigm for AI music generation, its "black box" nature often leads to violations of strict music theory and a lack of granular control for composers. This paper introduces Diatony, a constraint-programming (CP) model designed to formalize the rules of four-voice tonal harmony. By treating music generation as a formal logic problem, Diatony allows composers to interactively shape chord progressions with mathematical precision. We demonstrate that a restart-based search strategy significantly enhances the efficiency of finding optimal musical solutions, providing a robust tool for computer-aided composition.
Introduction
Modern music generation research is heavily focused on Machine Learning (ML). While ML models excel at stylistic mimicry, they struggle with the rigid, logical structures of music theory. Composers often find ML outputs difficult to "steer" toward a specific creative vision without extensive retraining. Furthermore, ML models frequently "hallucinate" or ignore fundamental rules, such as the prohibition of parallel fifths or octaves.
To address these issues, we propose a Computer-Aided Composition (CAC) tool that acts as a collaborative assistant. Instead of replacing the composer, the system respects the "grammar" of tonal harmony while allowing the human user to make high-level stylistic decisions.
The Diatony Model
Diatony is built using Constraint Programming (CP), a paradigm where the user defines the properties of a valid solution (the "what") rather than the specific steps to reach it (the "how"). The model formalizes classical music theory into a system of variables and constraints.
Constraints and Preferences
The model distinguishes between two types of rules:
- Strict Rules: Mandatory constraints such as the avoidance of parallel octaves and the requirement for tritones to resolve correctly.
- Preferences: "Soft rules" that the solver attempts to satisfy to improve musicality, such as minimizing melodic jumps between voices.
The system is implemented using Gecode, a high-performance C++ toolkit for constraint solving. To navigate the vast search space of potential musical sequences, we employ a lexicographic ranking of preferences, ensuring that the most critical musical qualities are prioritized.
Search Strategy and Efficiency
Finding an "optimal" musical solution is computationally intensive. We found that a standard depth-first search often struggles with complex harmonic phrases. To overcome this, Diatony utilizes a restart-based search. This strategy allows the solver to learn from its failures by generating "no-goods"—logical statements about what doesn't work—which are then used to prune the search space in subsequent attempts.
Additionally, we observed that branching from the end of the piece to the beginning is significantly more efficient. This mimics the human compositional process, where knowing the point of resolution (the cadence) simplifies the task of constructing the preceding harmonic path.
Evaluation and Results
We evaluated Diatony using a benchmark of test cases across various keys and modes. Because the system is rule-based, it requires no training data and can operate in any key immediately.
Performance Metrics
The restart-based approach demonstrated a clear advantage in solving "hard" test cases. In scenarios where standard search methods timed out at 450 seconds, the restart method successfully found and proved optimal solutions within 200–300 seconds. For standard harmonic phrases, solutions were found almost instantaneously.
Qualitative Analysis
To test the tool's practical utility, we used Diatony to recreate the harmonic structure of Billy Joel’s "Piano Man." By providing a basic chord progression and adding specific melodic constraints, the solver generated a professional-grade four-voice arrangement that strictly adhered to classical counterpoint rules. This demonstrates the system's flexibility in allowing iterative refinement without compromising harmonic integrity.
Conclusion and Future Work
Diatony successfully bridges the gap between formal music theory and automated generation. However, the current model is limited to diatonic triads and dominant seventh chords. Future work will focus on expanding the harmonic vocabulary, incorporating rhythmic variations and melodic ornaments, and developing a graphical user interface to make the tool accessible to non-technical composers.
Reference: Sprockeels, D., & Van Roy, P. (2024). Expressing Musical Ideas with Constraint Programming Using a Model of Tonal Harmony. Proceedings of the Thirty-Third International Joint Conference on Artificial Intelligence (IJCAI-24).
Summary updated