How digitaloctet/machine-composition works
Project Overview and Main Components
• Genetic Algorithm Engine: At its heart, the project contains a genetic algorithm implemented in genetic_algo.py. This script serves as the orchestrator of the entire process.
• Core Modules:
• Individual Module (individual.py): Defines the structure or “genome” representing a single musical composition candidate.
• Population Module (population.py): Manages groups of individuals and handles operations such as selection, crossover, and mutation.
• Fitness Module (fitness.py and fitness_test.py): Evaluates each individual’s quality based on specific musical criteria. The test file verifies the correctness of the fitness implementation.
• Configuration and Environment Setup:
• The environment.yml file is used to set up the necessary Python environment with dependencies (mido, numpy, scipy, matplotlib).
• Output Generation:
• The output directory contains subdirectories (output_random, output_rank, output_roulette, output_tournament), each storing MIDI (.mid) and audio (.wav) files resulting from the algorithm using different selection strategies.
Relationships and Interactions
• The genetic_algo.py script initiates the process by creating and managing a population.
• Each individual in the population (defined in individual.py) is evaluated using fitness.py.
• Based on fitness, genetic operations (like selection, crossover, and mutation) are applied — with different selection methods hinted by the various output folders (random, rank, roulette, tournament).
• The final outcome of the genetic process is translated into MIDI and WAV files and stored in the respective output subdirectories.
• Testing of fitness calculations is managed via fitness_test.py to ensure algorithmic correctness.
Architectural Patterns and Design Principles
• Modularity: The project clearly separates concerns into distinct modules (population, individual, fitness), which is a key to maintainability.
• Separation of Concerns: The orchestration of the algorithm is separate from the evaluation (fitness) and the data structure (individual/population).
• Configurability: The use of an environment file highlights the need for replicable and controlled dependency management.