# cqjjjzr/musicbee-desktoplyrics architecture

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

- Interactive diagram: https://gitdiagram.com/cqjjjzr/musicbee-desktoplyrics
- Repository: https://github.com/cqjjjzr/musicbee-desktoplyrics

## Overview

##### Project type and purpose
- This is a Windows‐based plugin for the MusicBee media player.
- Purpose: display synchronized LRC lyrics on the desktop, optionally in cooperation with a separate NeteaseLyrics plugin to render double‐line lyrics.

##### File structure
- Top level: solution and project files (.sln, .csproj), source files (.cs), config files (app.config, packages.config), Fody configuration (FodyWeavers.xml/xsd).
- Source folders:
– Forms/UI: FrmLyrics.{cs,Designer.cs,resx}, FrmSettings.{cs,Designer.cs,resx}
– Controllers and services: LyricsController.cs, LyricsRenderer.cs, MusicBeeInterface.cs
– Parsing: LyricParser.cs
– Rendering support: Gdiplus.cs, GdiplusPInvoke.cs, UnmanagedHelper.cs
– Utilities: FontConverter.cs
- Properties: AssemblyInfo.cs
- No client/server split – all logic lives in a single .NET assembly loaded by MusicBee.

##### README for additional insights
- Confirms plugin nature and LRC format requirement.
- Mentions optional integration with NeteaseLyrics plugin for double‐line support.

##### Main components to capture
a. MusicBee Host
b. DesktopLyrics Plugin
- Entry point & integration: MusicBeeInterface (implements plugin callbacks)
- Core Controller: LyricsController (orchestrates parsing, rendering)
- Parser: LyricParser (parses LRC files, builds time‐tagged lyric model; handles offset)
- Renderer: LyricsRenderer (drives the lyrics update loop, computes current line)
- Desktop UI: FrmLyrics (borderless, transparent form that draws lyrics)
- Rendering infrastructure: Gdiplus wrappers (Gdiplus.cs, GdiplusPInvoke.cs), UnmanagedHelper (native interop), FontConverter
- Configuration: app.config (plugin settings persistence), FodyWeavers (assembly weaving)
- Optional integration point: NeteaseLyrics plugin (external service for splitting double‐line LRC)
c. External LRC files (local or downloaded by other plugins)
d. User configuration store

##### Relationships and data flow
1. MusicBee triggers “song changed” event → MusicBeeInterface receives callback.
2. MusicBeeInterface asks LyricsController to load and synchronize LRC.
3. LyricsController calls LyricParser to read .lrc file, builds in‐memory model.
5. LyricsController passes model + style to LyricsRenderer.
7. If NeteaseLyrics is present and double‐line tokens exist, input is pre‐split by slash.
8. User may open FrmSettings at any time; changes are persisted and immediately affect rendering.

##### Architectural patterns and principles
- Plugin‐host boundary: clear separation between MusicBeeInterface (host adapter) and internal logic.
- MVC‐like structure inside plugin:
– Model: lyric data, style settings
– View: FrmLyrics (display), FrmSettings (configuration)
– Controller: LyricsController orchestrates parsing → rendering → UI update
- Single assembly, event‐driven flow
- Use of native interop wrappers for GDI+ to render custom text

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef host fill:#D3D3D3,stroke:#333;
    classDef plugin fill:#ADD8E6,stroke:#333;
    classDef data fill:#98FB98,stroke:#333;
    classDef native fill:#FFA500,stroke:#333;
    classDef ui fill:#87CEFA,stroke:#333;

    ExternalHost["MusicBee Host"]:::host
    ExternalHost -->|"OnTrackChanged event"| MI

    subgraph "DesktopLyrics Plugin"
        direction TB
        MI["MusicBeeInterface"]:::plugin
        LC["LyricsController"]:::plugin
        LP["LyricParser"]:::plugin
        LR["LyricsRenderer"]:::plugin

        subgraph "UI"
            direction TB
            FS["FrmSettings"]:::ui
            FL["FrmLyrics"]:::ui
        end

        subgraph "Rendering Infrastructure"
            direction TB
            GP["Gdiplus"]:::native
            GPInvoke["GdiplusPInvoke"]:::native
            UH["UnmanagedHelper"]:::native
            FC["FontConverter"]:::native
        end

        MI -->|"calls LoadLyrics()/Sync"| LC
        LC -->|"Parse LRC"| LP
        LC -->|"Init Renderer"| LR
        LR -->|"Draw Text"| FL
        FS -->|"Reads/Writes"| ConfigStore
        FC --> FS
        GP --> LR
        GPInvoke --> GP
        UH --> GPInvoke
        FC --> LR
        LP -->|"Model"| LC
    end

    subgraph "External Data Stores"
        direction TB
        LRC["LRC Files"]:::data
        ConfigStore["Config Store"]:::data
    end

    LRC -->|"LRC file I/O"| LP

    Netease["NeteaseLyrics Plugin"]:::host
    LC -->|"Double-line hook"| Netease

    subgraph "Configuration Files"
        direction TB
        AC["app.config"]:::data
        PC["packages.config"]:::data
        FW1["FodyWeavers.xml"]:::data
        FW2["FodyWeavers.xsd"]:::data
        AC --> ConfigStore
        PC --> ConfigStore
        FW1 --> ConfigStore
        FW2 --> ConfigStore
    end

    subgraph "Project & Metadata"
        direction TB
        DP["DesktopLyrics.csproj"]:::data
        SL["DesktopLyrics.sln"]:::data
        AI["Properties/AssemblyInfo.cs"]:::data
        DP --> ConfigStore
        SL --> ConfigStore
        AI --> ConfigStore
    end

    click MI "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/MusicBeeInterface.cs"
    click FS "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/FrmSettings.cs"
    click FL "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/FrmLyrics.cs"
    click LC "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/LyricsController.cs"
    click LP "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/LyricParser.cs"
    click LR "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/LyricsRenderer.cs"
    click GP "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/Gdiplus.cs"
    click GPInvoke "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/GdiplusPInvoke.cs"
    click UH "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/UnmanagedHelper.cs"
    click FC "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/FontConverter.cs"
    click AC "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/app.config"
    click PC "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/packages.config"
    click FW1 "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/FodyWeavers.xml"
    click FW2 "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/FodyWeavers.xsd"
    click DP "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/DesktopLyrics.csproj"
    click SL "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/DesktopLyrics.sln"
    click AI "https://github.com/cqjjjzr/musicbee-desktoplyrics/blob/master/Properties/AssemblyInfo.cs"
```
