# toastaspiring/autopiano architecture

> Architecture diagram of the GitHub repository toastaspiring/autopiano, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/toastaspiring/autopiano
- Repository: https://github.com/toastaspiring/autopiano

## Overview

##### Main Components
a. Input Source:
- A “MIDI Files” component that represents the directory (e.g., AutoPiano/Midi) where all MIDI files are stored.
b. MIDI Processing Module:
c. Playback Module:
d. External Dependencies & Libraries:
e. Additional Artifacts:
- Optional representation for configuration files (e.g., config.yml under MIDI player) and alternative components like the Java-based MIDI player (found in AutoPiano/MIDI player), although the core README focuses on the Python scripts.

##### Relationships & Interactions
- From “pyMIDI.py,” indicate that it outputs the file song.txt (and possibly sheet.txt) – show a file artifact linking these output files to the next stage.

##### Architectural Patterns and Design Principles
- “producer-consumer” pattern where the producer (pyMIDI.py) creates data in the song.txt file, and the consumer (playSong.py) reads that data to simulate key presses.

## Diagram (Mermaid)

```mermaid
graph TD
    %% MIDI Processing Pipeline
    subgraph "MIDI Processing Pipeline"
        A["MIDI Input Directory"]:::fileComponent
        B["MIDI Processing (pyMIDI.py)"]:::scriptComponent
        C["Output: song.txt"]:::artifact
        D["Playback Engine (playSong.py)"]:::scriptComponent
        A -->|"ingests"| B
        B -->|"outputs"| C
        C -->|"consumedBy"| D
    end

    %% Keyboard event that triggers playback operations
    F["Keyboard Events (e.g., Delete key)"]:::user
    F -->|"triggers"| D

    %% External Dependencies used by processing and playback modules
    G["pyHook"]:::external
    H["pythoncom"]:::external
    I["ctypes"]:::external
    B -->|"uses"| G
    B -->|"uses"| H
    B -->|"uses"| I
    D -->|"uses"| G
    D -->|"uses"| H
    D -->|"uses"| I

    %% Alternative Playback Option: Java-based MIDI Player
    subgraph "Alternative Playback Module"
        E["Alternative MIDI Player (Java)"]:::javaComp
    end

    %% Click Events
    click A "https://github.com/toastaspiring/autopiano/tree/main/AutoPiano/Midi"
    click B "https://github.com/toastaspiring/autopiano/blob/main/AutoPiano/Source/pyMIDI.py"
    click C "https://github.com/toastaspiring/autopiano/blob/main/AutoPiano/Source/song.txt"
    click D "https://github.com/toastaspiring/autopiano/blob/main/AutoPiano/Source/playSong.py"
    click E "https://github.com/toastaspiring/autopiano/tree/main/AutoPiano/MIDI player"

    %% Styles
    classDef fileComponent fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef scriptComponent fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef artifact fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef user fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef javaComp fill:#85C1E9,stroke:#2874A6,stroke-width:2px;
```
