# clementrivaille/godot-simple-sampler architecture

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

- Interactive diagram: https://gitdiagram.com/clementrivaille/godot-simple-sampler
- Repository: https://github.com/clementrivaille/godot-simple-sampler

## Overview

##### Core Components

a) Input Components (Top Layer):
- Sample Files Container (showing supported formats: .wav, .ogg)
- NoteSample Resources (showing properties: Stream, Tone, Octave, Velocity)
- Input Interface (showing play_note, release methods)

b) Processing Layer (Middle):
- NoteValueCalculator (Core Utility)
- -to-Value Conversion
- Value-to-Note Conversion
- Octave Calculation
- Sampler Base Class
- Envelope Processing (Attack, Sustain, Release)
- Pitch Calculation
- Sample Selection Logic
- SamplerInstrument Class
- Polyphony Management
- Chord Processing
- Glide/Glissando Processing

c) Output Layer (Bottom):
- AudioStreamPlayer Integration
- Audio Bus System Connection
- Sound Output

##### Specific features

Create sub-sections showing:
- Polyphony System
- Max Notes Management
- Queue
- Velocity System (0-10 scale)
- Gliding System
- Single Note Glide
- Chord Glide

##### Important Relationships

- Sample File → NoteSample Resource conversion
- NoteSample → Sampler loading
- NoteValueCalculator's global accessibility
- Sampler → AudioStreamPlayer inheritance
- SamplerInstrument → Sampler inheritance

##### Technical Details

Small technical notes showing:
- Supported note formats (C, C#, Db, etc.)
- Octave range
- Velocity range (0-10)
- File format support (.wav, .ogg)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        SF[Sample Files Container]:::input
        NR[NoteSample Resources]:::input
        NI[Note Input Interface]:::input
    end

    subgraph Processing
        direction TB
        subgraph Calculator
            NVC[NoteValueCalculator]:::processing
            N2V[Note-to-Value Conversion]:::utility
            V2N[Value-to-Note Conversion]:::utility
            OCT[Octave Calculation]:::utility
        end

        subgraph SamplerSystem
            SB[Sampler Base Class]:::processing
            SI[SamplerInstrument Class]:::processing
            
            subgraph Features
                PM[Polyphony Management]:::feature
                CP[Chord Processing]:::feature
                GP[Glide Processing]:::feature
                EP[Envelope Processing]:::feature
            end
        end
    end

    subgraph Output
        ASP[AudioStreamPlayer]:::output
        ABS[Audio Bus System]:::output
        SO[Sound Output]:::output
    end

    %% Connections
    SF -->|Load| NR
    NR -->|Initialize| SB
    NI -->|Control| SI
    NVC -->|Calculations| SB
    SB -->|Audio| ASP
    ASP -->|Route| ABS
    ABS -->|Output| SO
    
    SI -->|Uses| PM
    SI -->|Uses| CP
    SI -->|Uses| GP
    SB -->|Uses| EP
    
    N2V --> NVC
    V2N --> NVC
    OCT --> NVC

    %% Technical Notes
    classDef input fill:#lightblue
    classDef processing fill:#90EE90
    classDef output fill:#DDA0DD
    classDef utility fill:#FFD700
    classDef feature fill:#F0F0F0
    
    %% Click Events
    click SF "https://github.com/ClementRivaille/godot-simple-sampler/tree/master/samples/"
    click NR "https://github.com/ClementRivaille/godot-simple-sampler/blob/master/addons/SimpleSampler/sample_resource.gd"
    click NVC "https://github.com/ClementRivaille/godot-simple-sampler/blob/master/addons/SimpleSampler/note_value.gd"
    click SB "https://github.com/ClementRivaille/godot-simple-sampler/blob/master/addons/SimpleSampler/sampler.gd"
    click SI "https://github.com/ClementRivaille/godot-simple-sampler/blob/master/addons/SimpleSampler/sampler_instrument.gd"

    %% Legend
    subgraph Legend
        L1[Input Components]:::input
        L2[Processing Components]:::processing
        L3[Output Components]:::output
        L4[Utility Functions]:::utility
        L5[Features]:::feature
    end
```
