Skip to content

Python : MIDI Data & Text Practice #354

Description

@kimpro82

1. Overview

  • Objective: Understand the structure of MIDI data in a Python environment without an external DAW, and directly create, edit, and play the song [School Bell] using bidirectional JSON and ABC notation formats.
  • Target Audience: Developers and music data processing beginners who want to learn the principles of converting binary music data into human-readable text formats through programming.

2. Core Features

2.1. JSON-based MIDI Parser & Builder (JSON Pipeline)

  • Binary to JSON Conversion: Parse existing MIDI files (.mid) containing metadata and events (note_on, note_off, tempo, etc.) into structured JSON text.
  • JSON to Binary Compilation: Modify note values (velocity, delta times, etc.) within the JSON structure programmatically and recompile them back into standard MIDI binary files.

2.2. ABC Notation-based Text Editor (ABC Pipeline)

  • Text Score Loading: Load ABC text format files (.abc) containing aligned melodies and lyrics for [School Bell].
  • Parsing & Validation: Parse the 1:1 matching structure between musical notes and lyric syllables, including validation checks for note-to-syllable consistency.
  • MIDI Conversion: Convert the parsed ABC data into MIDI byte streams using specialized processing libraries.

2.3. Built-in Audio Playback Engine

  • Real-time Rendering & Playback: Utilize Python's internal sound engines or virtual synthesizers (e.g., pygame.mixer) to instantly output the generated MIDI file as audio without an external DAW.
  • Playback Controls: Support basic controls such as start (play), stop (stop), and loop playback.

3. Tech Stack

  • Language: Python 3.x
  • MIDI Processing: mido (Binary and message manipulation), music21 (ABC notation parsing and MIDI conversion)
  • Audio Playback: pygame (MIDI sound output and synthesizer execution)
  • Data Formats: .json, .abc, .mid

4. Implementation Milestones

  1. Phase 1 (Environment Setup & Sample Preparation):
    • Install required Python libraries (mido, pygame, music21).
    • Create JSON structure templates and .abc text files for [School Bell].
  2. Phase 2 (JSON Pipeline Implementation):
    • Write scripts to read JSON files, convert them into mido objects, and play them via pygame.
  3. Phase 3 (ABC Pipeline Implementation):
    • Implement an ABC parser including alignment exception handling for lyrics (w:) and notes, followed by MIDI file generation.
  4. Phase 4 (Integration & Verification):
    • Final testing to ensure both formats (JSON and ABC) successfully generate and play the exact same melody.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions