# bgribble/mfp architecture

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

- Interactive diagram: https://gitdiagram.com/bgribble/mfp
- Repository: https://github.com/bgribble/mfp

## Overview

##### Project Type and Purpose
- MFP (“music for programmers”) is an environment for visually composing computer programs, with a specific focus on music, audio synthesis, and real-time processing.
- Its design is inspired by systems like Pure Data, Max/MSP, LabView, and TouchOSC and supports both live coding (in Python and Faust) and dynamic patch creation.
- The project encompasses a core interpreter/patch engine, a DSP subsystem for audio signal processing, built-in objects for various sound and control operations, and multiple GUI frontends.

##### File Structure for Architectural Clues
- Top-level directories and files such as “mfp”, “mfpdsp”, and “pluginfo” indicate separation between the core application logic (patching/interpreter), DSP processing, and plugin interfaces (e.g., LV2 support).
- The “mfp/builtins” directory lists all the built-in processing objects – these are the fundamental DSP/patch elements that users employ to create modular patches.
- The “mfp/gui” directory, along with its “clutter” and “imgui” subdirectories, reveals that there are at least two separate UI backends. This handles the visual display of patches and interacts with user events.
- There are test directories and “lib” folders (e.g., lib/alsaseq) which integrate external libraries like ALSA MIDI support.
- Configuration files (e.g., .github/workflows, setup.py, waf, wscript) indicate an established build and continuous integration process.

##### Major Components
a. Core Application Layer:
- MFP Interpreter/Patch Engine (files like mfp/interpreter.py, mfp/mfp_app.py, mfp/patch.py)
- Built-in objects and processing modules (mfp/builtins/* modules), which perform audio DSP and control tasks.
- Delegation systems, logging, and command parsing (mfp/delegate.py, mfp/log.py, mfp/method.py).

b. DSP Engine:
- The mfpdsp directory shows numerous C files for DSP operations (e.g., mfp_dsp.c, various builtin_*.c files).
- This layer is responsible for real-time audio synthesis, interfacing with external audio systems (like ALSA/jack via mfp_jack.c).
- Communication between interpreted patch instructions and compiled DSP routines.

c. GUI Frontends:
- Two parallel GUI systems: the “Clutter” UI interface (mfp/gui/clutter/*) and the “ImGUI” UI interface (mfp/gui/imgui/*).
- These frontends render the patch editor, display elements, parameter panels, and capture user input (touch, keyboard and mouse events).
- Core UI interactions include creating, editing, moving, and connecting patch elements.

d. Live Coding and Custom Code Integration:
- Support for embedding custom Python (and Faust) code in processors (as highlighted in the README for live coding and the “Custom code” parameters).
- This subprocess should be represented as an extension branch interacting with both the interpreter layer and the DSP execution flow.

e. External Services and Tools:
- Integration with external libraries like ALSA (in lib/alsaseq) for MIDI, and plugins support (pluginfo) for LV2.
- The “testext” directory suggests that external modules/extensions can be added to expand system functionality.

##### Relationships and Interactions
- The main UI (Clutter/ImGUI) receives user input and sends commands to the core patch engine.
- The patch engine loads a patch and maps it to built-in processing objects, which then invoke underlying DSP routines in the mfpdsp layer.
- Live coding functionality provides a dynamic link – updates from custom code immediately affect the behavior of processors.
- Audio processing flows from the DSP layer to the output hardware (with interfacing modules like mfp_jack.c handling real-time constraints).
- Testing and external tools (such as LV2 plugin wrappers) indicate that patches can be deployed in external hosts.

##### Detailing Specific Technologies and Libraries
- That the ImGUI backend relies on Dear ImGUI and the imgui-bundle.
- That the Clutter backend is available but legacy.
- That external libraries include ALSA (and possibly JACK) for MIDI/audio sequencing and LV2 for plugin support.
- Make a reference that Python is used for live coding, and Faust integration is allowed for DSP programming.

## Diagram (Mermaid)

```mermaid
flowchart TD
    userInput("User Input"):::external
    clutterUI("Clutter Frontend"):::ui
    imguiUI("ImGUI Frontend"):::ui
    coreEngine("Core Interpreter & Patching Engine"):::core
    builtins("Built-in Objects & Processing Modules"):::core
    liveCoding("Live Coding & Custom Code Integration"):::live
    dspEngine("DSP Engine"):::dsp
    audioHW("Audio Hardware"):::external
    externalInterfaces("External Interfaces & Libraries"):::external
    pluginSupport("External Plugin Support"):::external

    %% Data flow
    userInput -->|"triggers"| clutterUI
    userInput -->|"triggers"| imguiUI
    clutterUI -->|"sends"| coreEngine
    imguiUI -->|"sends"| coreEngine
    liveCoding -->|"updates"| coreEngine
    coreEngine -->|"loads_patch"| builtins
    liveCoding -->|"updates"| builtins
    builtins -->|"invokes_DSP"| dspEngine
    dspEngine -->|"audio_out"| audioHW
    dspEngine -->|"interfaces"| externalInterfaces
    dspEngine -->|"interfaces"| pluginSupport

    %% Click Events
    click coreEngine "https://github.com/bgribble/mfp/blob/master/mfp/interpreter.py"
    click builtins "https://github.com/bgribble/mfp/tree/master/mfp/builtins"
    click dspEngine "https://github.com/bgribble/mfp/tree/master/mfpdsp"
    click clutterUI "https://github.com/bgribble/mfp/tree/master/mfp/gui/clutter"
    click imguiUI "https://github.com/bgribble/mfp/tree/master/mfp/gui/imgui"
    click externalInterfaces "https://github.com/bgribble/mfp/blob/master/lib/alsaseq-0.4.1"
    click pluginSupport "https://github.com/bgribble/mfp/tree/master/pluginfo"

    %% Styles
    classDef ui fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef core fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef dsp fill:#a9dfbf,stroke:#1e8449,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#922b21,stroke-width:2px;
    classDef live fill:#f9e79f,stroke:#af601a,stroke-width:2px;
```
