View on GitHub

mmlabc-to-smf

mmlabc-to-smf

mmlabc-to-smf

A conversion tool from Music Macro Language (MML) to Standard MIDI File (SMF)

Japanese English

็Šถๆณ

ใ‚ขใƒผใ‚ซใ‚คใƒ–ใ—ใพใ™ใ€‚ๅพŒ็ถ™ใฎRust็‰ˆใ‚’้–‹็™บใ—ใพใ™ใ€‚

ใ“ใฎใƒชใƒใ‚ธใƒˆใƒชใฎ็”จ้€”ใฏใ€Pythonใซใ‚ˆใ‚‹ๆœ€ไฝŽ้™ใฎๅ‚่€ƒ็”จใฎใ‚ณใƒผใƒ‰ใ‚’ๆไพ›ใ™ใ‚‹็”จใงใ™ใ€‚

Overview

This project converts Music Macro Language strings into Standard MIDI Files using a 4-pass architecture with comprehensive debug output.

Features

Requirements

Installation

pip install -r requirements.txt

Usage

Basic Usage

python mml_to_smf.py "cde"

This converts the MML string โ€œcdeโ€ (notes C, D, E) as follows:

Custom Output File

python mml_to_smf.py "cde" -o my_song.mid

Supported Notes

Currently supports basic note names: c, d, e, f, g, a, b

Example Run

$ python mml_to_smf.py "cde"
Converting MML: cde
Pass 1: Parsing MML...
  Generated 3 tokens โ†’ pass1_tokens.json
Pass 2: Creating AST...
  Generated AST with 3 notes โ†’ pass2_ast.json
Pass 3: Creating MIDI events...
  Generated 6 events โ†’ pass3_events.json
Pass 4: Creating MIDI file...
  Generated MIDI file โ†’ output.mid

Conversion complete!
Output files:
  - pass1_tokens.json (debug)
  - pass2_ast.json (debug)
  - pass3_events.json (debug)
  - output.mid (final output)

Project Structure

mmlabc-to-smf/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ pass1_parser.py    # Pass 1: MML Parsing
โ”‚   โ”œโ”€โ”€ pass2_ast.py        # Pass 2: AST Creation
โ”‚   โ”œโ”€โ”€ pass3_events.py     # Pass 3: Event Generation
โ”‚   โ””โ”€โ”€ pass4_midi.py       # Pass 4: MIDI File Creation
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_pass1.py       # Pass 1 Unit Tests
โ”‚   โ”œโ”€โ”€ test_pass2.py       # Pass 2 Unit Tests
โ”‚   โ”œโ”€โ”€ test_pass3.py       # Pass 3 Unit Tests
โ”‚   โ”œโ”€โ”€ test_pass4.py       # Pass 4 Unit Tests
โ”‚   โ””โ”€โ”€ test_integration.py # Integration Tests
โ”œโ”€โ”€ mml_to_smf.py          # Main CLI Script
โ”œโ”€โ”€ requirements.txt        # Python Dependencies
โ””โ”€โ”€ README.md              # This file

Testing

To run all tests:

python -m unittest discover -s tests -p "test_*.py" -v

To run specific test files:

python -m unittest tests.test_integration

Development

This project adheres to Test-Driven Development (TDD) principles:

  1. Each module is kept to approximately 100 lines of code or less.
  2. Each pass has corresponding unit tests.
  3. Integration tests validate the complete pipeline.
  4. Debug JSON outputs are available at each stage for troubleshooting.

License

See the LICENSE file for more details.

โ€ป The English version of README.md is automatically generated from README.ja.md using Geminiโ€™s translation via GitHub Actions.