# xiphonics/picotracker architecture

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

- Interactive diagram: https://gitdiagram.com/xiphonics/picotracker
- Repository: https://github.com/xiphonics/picotracker

## Overview

##### Main System Components

a) Hardware Layer:
- Raspberry Pi Pico (CPU/Memory)
- Audio Output (I2S)
- (ILI9341)
- SD Card (SDIO)
- USB Interface
- MIDI Interface

b) System Layer:
- File System
- Timer Services
- Process Management
- Error Handling
- I/O Management

c) Foundation Layer:
- Service Registry
- Observable Pattern Implementation
- Variable Management
- Factory Implementations

d) Application Layer:
- Audio Engine
- Mixer
- Instruments (Sample, MIDI, SID, OPAL)
- Audio Output
- UI Framework
- Window Management
- Event Handling
- Graphics System
- Controllers
- Input Management
- MIDI Control
- Project Management
- Song/Chain/Phrase Management
- Persistence

##### Component Relationships

- Data flow (→): Audio signal path, MIDI messages
- Dependencies (⇢): Service dependencies
- Event flow (⇢): UI events, timer events
- Control flow (⇨): System control paths

##### Implementation Details

Technical specifications:
- 8 monophonic channels
- 16-bit/44.1kHz stereo output
- Flash memory allocation for samples
- MIDI channel configuration
- Service registration system
- Observable pattern implementation

##### Architectural Patterns

Use of:
- Service-oriented architecture
- Observer pattern (for UI updates)
- Factory pattern (for UI and audio components)
- Command pattern (for UI actions)
- MVC pattern (for project management)

##### External Dependencies

Integration with:
- SdFat library
- TinyXML2
- Braids synthesizer
- OPAL synthesizer
- C64 SID emulation

Remember to maintain a balance between showing enough detail to understand the system's architecture while keeping it readable and not overwhelming with implementation details.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Hardware
        CPU[Raspberry Pi Pico]
        AO["Audio Output (I2S)"]:::hardware
        DISP["Display (ILI9341)"]:::hardware
        SDC["SD Card (SDIO)"]:::hardware
        USB["USB Interface"]:::hardware
        MIDI["MIDI Interface"]:::hardware
    end

    subgraph System
        FS["File System"]:::system
        TS["Timer Services"]:::system
        PM["Process Management"]:::system
        EH["Error Handling"]:::system
        IO["I/O Management"]:::system
    end

    subgraph Foundation
        SR["Service Registry"]:::foundation
        OBS["Observable Pattern"]:::foundation
        VM["Variable Management"]:::foundation
        FI["Factory Implementation"]:::foundation
    end

    subgraph Application
        subgraph AudioEngine
            MIX["Mixer"]:::audio
            INST["Instruments"]:::audio
            AOUT["Audio Output"]:::audio
        end

        subgraph UIFramework
            WM["Window Management"]:::ui
            EVH["Event Handling"]:::ui
            GS["Graphics System"]:::ui
        end

        subgraph Controllers
            IM["Input Management"]:::controller
            MC["MIDI Control"]:::controller
        end

        subgraph ProjectManagement
            SONG["Song Management"]:::project
            CHAIN["Chain Management"]:::project
            PHRASE["Phrase Management"]:::project
            PLAYER["Player"]:::project
        end
    end

    %% Relationships
    CPU --> |hardware control| AO & DISP & SDC & USB & MIDI
    SDC --> FS
    FS --> PM
    TS --> PM
    SR --> |manages| OBS & VM & FI
    MIX --> AOUT
    INST --> MIX
    WM --> EVH
    EVH --> GS
    IM --> MC
    SONG --> CHAIN --> PHRASE
    PLAYER --> MIX

    %% Click Events
    click AO "https://github.com/xiphonics/picoTracker/blob/master/sources/Adapters/picoTracker/audio/picoTrackerAudio.h"
    click DISP "https://github.com/xiphonics/picoTracker/blob/master/sources/Adapters/picoTracker/display/ili9341.h"
    click SDC "https://github.com/xiphonics/picoTracker/blob/master/sources/Adapters/picoTracker/sdcard/sdcard.h"
    click MIDI "https://github.com/xiphonics/picoTracker/blob/master/sources/Adapters/picoTracker/midi/picoTrackerMidiDevice.h"
    click USB "https://github.com/xiphonics/picoTracker/blob/master/sources/Adapters/picoTracker/usb/usb_utils.h"
    click FS "https://github.com/xiphonics/picoTracker/blob/master/sources/System/FileSystem/PicoFileSystem.h"
    click TS "https://github.com/xiphonics/picoTracker/blob/master/sources/System/Timer/Timer.h"
    click PM "https://github.com/xiphonics/picoTracker/tree/master/sources/System/Process"
    click EH "https://github.com/xiphonics/picoTracker/blob/master/sources/System/Errors/Result.h"
    click IO "https://github.com/xiphonics/picoTracker/tree/master/sources/System/io"
    click SR "https://github.com/xiphonics/picoTracker/blob/master/sources/Foundation/Services/ServiceRegistry.h"
    click OBS "https://github.com/xiphonics/picoTracker/blob/master/sources/Foundation/Observable.h"
    click VM "https://github.com/xiphonics/picoTracker/blob/master/sources/Foundation/Variables/Variable.h"
    click FI "https://github.com/xiphonics/picoTracker/blob/master/sources/Foundation/T_Factory.h"
    click MIX "https://github.com/xiphonics/picoTracker/blob/master/sources/Application/Mixer/MixerService.h"
    click INST "https://github.com/xiphonics/picoTracker/tree/master/sources/Application/Instruments"
    click WM "https://github.com/xiphonics/picoTracker/tree/master/sources/UIFramework"
    click IM "https://github.com/xiphonics/picoTracker/blob/master/sources/Services/Controllers/ControllerService.h"
    click SONG "https://github.com/xiphonics/picoTracker/blob/master/sources/Application/Model/Song.h"
    click CHAIN "https://github.com/xiphonics/picoTracker/blob/master/sources/Application/Model/Chain.h"
    click PHRASE "https://github.com/xiphonics/picoTracker/blob/master/sources/Application/Model/Phrase.h"
    click PLAYER "https://github.com/xiphonics/picoTracker/blob/master/sources/Application/Player/Player.h"

    %% Styles
    classDef hardware fill:#A9A9A9
    classDef system fill:#87CEEB
    classDef foundation fill:#FFB6C1
    classDef audio fill:#90EE90
    classDef ui fill:#FFA500
    classDef controller fill:#FF6347
    classDef project fill:#DDA0DD

    %% Legend
    subgraph Legend
        H[Hardware]:::hardware
        S[System]:::system
        F[Foundation]:::foundation
        A[Audio]:::audio
        U[UI]:::ui
        C[Controller]:::controller
        P[Project]:::project
    end
```
