# rhythmicdias/korg-ek50-live-flow architecture

> Architecture diagram of the GitHub repository rhythmicdias/korg-ek50-live-flow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rhythmicdias/korg-ek50-live-flow
- Repository: https://github.com/rhythmicdias/korg-ek50-live-flow

## Overview

#### Purpose and launch
Korg EK50 Live Flow is a desktop Python companion for a USB-connected Korg EK-50. It receives live MIDI, controls keyboard parts, adds arpeggiation, recognizes chords, visualizes performance state, and captures playable MIDI for DAWs. The application starts at `src/main.py`, with its primary desktop UI in `src/ui/main_window.py`.

#### Application orchestration and UI
`src/main.py` assembles the MIDI, storage, and UI subsystems and owns application lifecycle. `src/ui/main_window.py` is the live-control surface for mixer/idea-generation and feature control. `src/ui/visualizer.py` supplies the separate large chord-display surface, consuming analyzed chord state rather than raw device interaction.

#### MIDI device boundary
`src/midi/connection.py` encapsulates physical MIDI port discovery, input/output connection, and message transport to/from the EK-50. This is the principal hardware boundary: upstream events enter from USB MIDI, while transformed notes and control changes leave for the keyboard. Device-specific controller/part mappings are centralized in `src/midi/ek50_map.py`.

#### Event processing pipeline
Incoming MIDI messages are normalized and classified by `src/midi/messages.py`, then fan out to live features. `src/midi/chord_analyzer.py` maintains currently held notes and derives chord names for the UI. `src/midi/arpeggiator.py` transforms playing into timed, multi-octave note sequences and sends resulting events back through the MIDI connection. The application must coordinate note lifecycle carefully so generated notes, passthrough notes, and note-offs remain consistent.

#### Recording and DAW export
`src/midi/recorder.py` captures relevant performance events while excluding unwanted system traffic. Recorded material is persisted as standard MIDI files under `captured_midi/`. `src/storage/daw_export.py` defines the export boundary for DAW-oriented output, separating performance capture from downstream file formatting/export behavior.

#### Persistent musical data and presets
`src/storage/presets.py` manages saved performance/preset state in `saved_presets/`. `src/storage/database.py` provides the storage access layer for bundled or persisted musical metadata. Sound and style catalogs are packaged as `src/storage/sounds.json` and `src/storage/styles.json`; these support sound/style selection and idea-generation rather than requiring a remote service.

#### Runtime and external dependencies
The runtime is Python 3.9+ on macOS or Windows, launched directly with `python src/main.py`; dependencies are declared in `requirements.txt`. The only material external integration described is local USB MIDI with the Korg EK-50 and filesystem-based MIDI/preset storage. No server, cloud service, or web application boundary is indicated.

Main entry points: [`src/ui/main_window.py`](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/ui/main_window.py) (Live control UI), [`src/midi/connection.py`](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/connection.py) (MIDI connection), [`src/main.py`](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/main.py) (Application lifecycle), [`src/midi/messages.py`](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/messages.py) (Message normalization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Desktop application"]
  node_main["Application lifecycle<br/>Python entrypoint<br/>[main.py]"]
  node_main_window["Live control UI<br/>desktop UI<br/>[main_window.py]"]
  node_visualizer["Chord visualizer<br/>desktop UI<br/>[visualizer.py]"]
end

subgraph group_midi["MIDI pipeline"]
  node_connection["MIDI connection<br/>device boundary<br/>[connection.py]"]
  node_ek50_map["EK-50 mappings<br/>device map<br/>[ek50_map.py]"]
  node_messages["Message normalization<br/>event processing<br/>[messages.py]"]
  node_chords["Chord analyzer<br/>live analysis<br/>[chord_analyzer.py]"]
  node_arpeggiator["Arpeggiator<br/>event transformation<br/>[arpeggiator.py]"]
  node_recorder["Performance recorder<br/>MIDI capture<br/>[recorder.py]"]
end

subgraph group_storage["Local storage"]
  node_daw_export["DAW export<br/>export boundary<br/>[daw_export.py]"]
  node_captured_midi["Captured MIDI files<br/>local MIDI files"]
  node_presets["Preset manager<br/>persistent state<br/>[presets.py]"]
  node_saved_presets["Saved presets<br/>local preset files"]
  node_database[("Musical metadata<br/>storage access<br/>[database.py]")]
  node_sounds["Sound catalog<br/>bundled catalog<br/>[sounds.json]"]
  node_styles["Style catalog<br/>bundled catalog<br/>[styles.json]"]
end

subgraph group_device["EK-50 device"]
  node_usb_midi{{"USB MIDI<br/>hardware integration"}}
  node_ek50["Korg EK-50<br/>keyboard hardware"]
end

node_main -->|"initializes"| node_connection
node_main -->|"launches"| node_main_window
node_main -->|"loads state"| node_presets
node_main -->|"uses"| node_database
node_usb_midi -->|"connects"| node_ek50
node_usb_midi -->|"MIDI input/output"| node_connection
node_connection -->|"incoming messages"| node_messages
node_ek50_map -->|"device mappings"| node_connection
node_messages -->|"note state"| node_chords
node_messages -->|"play events"| node_arpeggiator
node_messages -->|"performance events"| node_recorder
node_chords -->|"chord state"| node_visualizer
node_chords -->|"chord state"| node_main_window
node_main_window -->|"feature control"| node_arpeggiator
node_arpeggiator -->|"generated notes"| node_connection
node_recorder -->|"recorded events"| node_daw_export
node_daw_export -->|"writes MIDI files"| node_captured_midi
node_presets -->|"reads and writes"| node_saved_presets
node_database -->|"loads"| node_sounds
node_database -->|"loads"| node_styles
node_sounds -->|"sound selection"| node_main_window
node_styles -->|"style and ideas"| node_main_window

click node_main "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/main.py"
click node_main_window "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/ui/main_window.py"
click node_visualizer "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/ui/visualizer.py"
click node_connection "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/connection.py"
click node_ek50_map "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/ek50_map.py"
click node_messages "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/messages.py"
click node_chords "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/chord_analyzer.py"
click node_arpeggiator "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/arpeggiator.py"
click node_recorder "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/recorder.py"
click node_daw_export "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/daw_export.py"
click node_captured_midi "https://github.com/rhythmicdias/korg-ek50-live-flow/tree/main/captured_midi"
click node_presets "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/presets.py"
click node_saved_presets "https://github.com/rhythmicdias/korg-ek50-live-flow/tree/main/saved_presets"
click node_database "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/database.py"
click node_sounds "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/sounds.json"
click node_styles "https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/styles.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_main_window,node_visualizer toneBlue
class node_connection,node_ek50_map,node_messages,node_chords,node_arpeggiator,node_recorder toneAmber
class node_daw_export,node_captured_midi,node_presets,node_saved_presets,node_database,node_sounds,node_styles toneMint
class node_usb_midi,node_ek50 toneRose
```

## Components

### Desktop application

- [Application lifecycle](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/main.py): Python entrypoint · Assembles subsystems and owns desktop lifecycle. · `src/main.py`
- [Live control UI](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/ui/main_window.py): desktop UI · Mixer, idea-generation, and feature controls. · `src/ui/main_window.py`
- [Chord visualizer](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/ui/visualizer.py): desktop UI · Large display driven by analyzed chord state. · `src/ui/visualizer.py`

### MIDI pipeline

- [MIDI connection](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/connection.py): device boundary · Discovers ports and transports MIDI messages. · `src/midi/connection.py`
- [EK-50 mappings](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/ek50_map.py): device map · Central controller and part mappings. · `src/midi/ek50_map.py`
- [Message normalization](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/messages.py): event processing · Normalizes and classifies incoming MIDI. · `src/midi/messages.py`
- [Chord analyzer](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/chord_analyzer.py): live analysis · Tracks held notes and derives chord names. · `src/midi/chord_analyzer.py`
- [Arpeggiator](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/arpeggiator.py): event transformation · Generates timed multi-octave note sequences. · `src/midi/arpeggiator.py`
- [Performance recorder](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/midi/recorder.py): MIDI capture · Captures playable events and filters system traffic. · `src/midi/recorder.py`

### Local storage

- [DAW export](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/daw_export.py): export boundary · Separates capture from MIDI formatting and export. · `src/storage/daw_export.py`
- [Captured MIDI files](https://github.com/rhythmicdias/korg-ek50-live-flow/tree/main/captured_midi): local MIDI files · `captured_midi`
- [Preset manager](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/presets.py): persistent state · Manages saved performance and preset state. · `src/storage/presets.py`
- [Saved presets](https://github.com/rhythmicdias/korg-ek50-live-flow/tree/main/saved_presets): local preset files · `saved_presets`
- [Musical metadata](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/database.py): storage access · Access layer for bundled or persisted metadata. · `src/storage/database.py`
- [Sound catalog](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/sounds.json): bundled catalog · `src/storage/sounds.json`
- [Style catalog](https://github.com/rhythmicdias/korg-ek50-live-flow/blob/main/src/storage/styles.json): bundled catalog · `src/storage/styles.json`

### EK-50 device

- **USB MIDI**: hardware integration · Local connection to the Korg EK-50.
- **Korg EK-50**: keyboard hardware

## Connections

- Application lifecycle → MIDI connection: initializes
- Application lifecycle → Live control UI: launches
- Application lifecycle → Preset manager: loads state
- Application lifecycle → Musical metadata: uses
- USB MIDI → Korg EK-50: connects
- USB MIDI → MIDI connection: MIDI input/output
- MIDI connection → Message normalization: incoming messages
- EK-50 mappings → MIDI connection: device mappings
- Message normalization → Chord analyzer: note state
- Message normalization → Arpeggiator: play events
- Message normalization → Performance recorder: performance events
- Chord analyzer → Chord visualizer: chord state
- Chord analyzer → Live control UI: chord state
- Live control UI → Arpeggiator: feature control
- Arpeggiator → MIDI connection: generated notes
- Performance recorder → DAW export: recorded events
- DAW export → Captured MIDI files: writes MIDI files
- Preset manager → Saved presets: reads and writes
- Musical metadata → Sound catalog: loads
- Musical metadata → Style catalog: loads
- Sound catalog → Live control UI: sound selection
- Style catalog → Live control UI: style and ideas
