# bingmann/sound-of-sorting architecture

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

- Interactive diagram: https://gitdiagram.com/bingmann/sound-of-sorting
- Repository: https://github.com/bingmann/sound-of-sorting

## Overview

##### Project type and purpose
- This is a native desktop demo application written in C++ that visualizes and “audibilizes” sorting algorithms in real time. It uses wxWidgets for GUI/dialogs/painting and SDL for audio output.

##### File structure
- Top-level files (configure, Makefile.am/in, aclocal.m4, etc.): an Autotools-based build system for cross-platform compilation.
- `/src`: all application sources.
- WMain.{cpp,h} and generated wxGlade files (`/src/wxg/*`): the main window, menu, controls, and event wiring.
- SortAlgo.{cpp,h}: orchestration of all sorting algorithm implementations (calls into the instrumented array).
- algorithms/*.cpp: individual algorithm variants (timsort, wikisort, etc.).
- SortSound.cpp: the SDL-based audio oscillator/mixing classes that turn comparisons into beeps.
- wxClickText.*, resources.rc, sos.xcf, sos.xpm: auxiliary UI/image resources.
- Tests (SortTest.cpp) and utility scripts (acscripts/*).

##### Key insights from README
- MVC-style separation:
- Model: the instrumented array (`WSortView`) + ArrayItem that counts accesses/comparisons.
- Controller: user events—Run, Step, Reset, Speed, Algorithm selection, Sound on/off—handled in `WMain`.
- Sorting algorithms call into `WSortView`, triggering painting and sound via `ArrayItem` overrides.
- Sound engine: `Oscillator` objects generate triangular waveforms via SDL audio callbacks.

##### Detail
- Event flow for Run/Step/Reset and how speed slider influences delay in the Sorting Engine.
- That ArrayItem overloads are the interception points for both counters and audio triggers.
- Resource files (images, dialogs) feeding into the GUI.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User["User"]:::external

    %% GUI Layer
    subgraph "GUI Layer"  
        direction TB
        WMain_cpp["WMain.cpp"]:::ui
        WMain_h["WMain.h"]:::ui
        WMain_wxg_cpp["WMain_wxg.cpp"]:::ui
        WMain_wxg_h["WMain_wxg.h"]:::ui
        WAbout_wxg_cpp["WAbout_wxg.cpp"]:::ui
        WAbout_wxg_h["WAbout_wxg.h"]:::ui
        sos_wxg["sos.wxg"]:::ui
        wxClickText_cpp["wxClickText.cpp"]:::ui
        wxClickText_h["wxClickText.h"]:::ui
        resources_rc["resources.rc"]:::ui
        sos_xcf["sos.xcf"]:::ui
        sos_xpm["sos.xpm"]:::ui
    end

    %% Controller (same nodes as GUI WMain)
    subgraph "Controller"  
        direction TB
        Controller_cpp["WMain.cpp"]:::core
        Controller_h["WMain.h"]:::core
    end

    %% Sorting Engine
    subgraph "Sorting Engine"  
        direction TB
        SortAlgo_cpp["SortAlgo.cpp"]:::core
        SortAlgo_h["SortAlgo.h"]:::core
        timsort_cpp["timsort.cpp"]:::core
        wikisort_cpp["wikisort.cpp"]:::core
    end

    %% Instrumented Array & Visualization
    subgraph "Instrumented Array & Visualization"  
        direction TB
        WSortView_cpp["WSortView.cpp"]:::core
        WSortView_h["WSortView.h"]:::core
        SortArray_cpp["SortArray.cpp"]:::core
        SortArray_h["SortArray.h"]:::core
    end

    %% Sound Engine
    SortSound_cpp["SortSound.cpp"]:::core

    %% Tests
    SortTest_cpp["SortTest.cpp"]:::core

    %% Build System
    subgraph "Build System"  
        direction TB
        configure["configure"]:::build
        configure_ac["configure.ac"]:::build
        aclocal_m4["aclocal.m4"]:::build
        Makefile_am["Makefile.am"]:::build
        Makefile_in["Makefile.in"]:::build
        travis[".travis.yml"]:::build
        acscripts["acscripts/"]:::build
        src_Makefile_am["src/Makefile.am"]:::build
        src_Makefile_in["src/Makefile.in"]:::build
    end

    %% External Libraries
    subgraph "External Libraries"  
        direction TB
        wxWidgets["wxWidgets"]:::external
        SDL["SDL"]:::external
    end

    %% Compiled App
    CompiledApp["Compiled Application"]:::build

    %% Data Flows
    User -->|"interacts with"| WMain_cpp
    WMain_cpp -->|handles events| SortAlgo_cpp
    SortAlgo_cpp -->|invokes| timsort_cpp
    SortAlgo_cpp -->|invokes| wikisort_cpp
    SortAlgo_cpp -->|operates on| WSortView_cpp
    WSortView_cpp -->|visualizes| WSortView_cpp
    WSortView_cpp -->|calls| SortSound_cpp
    SortSound_cpp -->|uses audio| SDL
    WSortView_cpp -->|uses GUI| wxWidgets
    WMain_cpp -->|renders| wxWidgets
    CompiledApp -->|links against| wxWidgets
    CompiledApp -->|links against| SDL
    BuildSystem-->|builds|CompiledApp

    %% Build System link
    configure --> CompiledApp
    configure_ac --> CompiledApp
    aclocal_m4 --> CompiledApp
    Makefile_am --> CompiledApp
    Makefile_in --> CompiledApp
    travis --> CompiledApp
    acscripts --> CompiledApp
    src_Makefile_am --> CompiledApp
    src_Makefile_in --> CompiledApp

    %% Click Events
    click WMain_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/WMain.cpp"
    click WMain_h "https://github.com/bingmann/sound-of-sorting/blob/master/src/WMain.h"
    click WMain_wxg_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/wxg/WMain_wxg.cpp"
    click WMain_wxg_h "https://github.com/bingmann/sound-of-sorting/blob/master/src/wxg/WMain_wxg.h"
    click WAbout_wxg_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/wxg/WAbout_wxg.cpp"
    click WAbout_wxg_h "https://github.com/bingmann/sound-of-sorting/blob/master/src/wxg/WAbout_wxg.h"
    click sos_wxg "https://github.com/bingmann/sound-of-sorting/blob/master/src/wxg/sos.wxg"
    click wxClickText_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/wxClickText.cpp"
    click wxClickText_h "https://github.com/bingmann/sound-of-sorting/blob/master/src/wxClickText.h"
    click resources_rc "https://github.com/bingmann/sound-of-sorting/blob/master/src/resources.rc"
    click sos_xcf "https://github.com/bingmann/sound-of-sorting/blob/master/src/sos.xcf"
    click sos_xpm "https://github.com/bingmann/sound-of-sorting/blob/master/src/sos.xpm"
    click Controller_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/WMain.cpp"
    click Controller_h "https://github.com/bingmann/sound-of-sorting/blob/master/src/WMain.h"
    click SortAlgo_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/SortAlgo.cpp"
    click SortAlgo_h "https://github.com/bingmann/sound-of-sorting/blob/master/src/SortAlgo.h"
    click timsort_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/algorithms/timsort.cpp"
    click wikisort_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/algorithms/wikisort.cpp"
    click WSortView_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/WSortView.cpp"
    click WSortView_h "https://github.com/bingmann/sound-of-sorting/blob/master/src/WSortView.h"
    click SortArray_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/SortArray.cpp"
    click SortArray_h "https://github.com/bingmann/sound-of-sorting/blob/master/src/SortArray.h"
    click SortSound_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/SortSound.cpp"
    click SortTest_cpp "https://github.com/bingmann/sound-of-sorting/blob/master/src/SortTest.cpp"
    click configure "https://github.com/bingmann/sound-of-sorting/tree/master/configure"
    click configure_ac "https://github.com/bingmann/sound-of-sorting/blob/master/configure.ac"
    click aclocal_m4 "https://github.com/bingmann/sound-of-sorting/blob/master/aclocal.m4"
    click Makefile_am "https://github.com/bingmann/sound-of-sorting/blob/master/Makefile.am"
    click Makefile_in "https://github.com/bingmann/sound-of-sorting/blob/master/Makefile.in"
    click travis "https://github.com/bingmann/sound-of-sorting/blob/master/.travis.yml"
    click acscripts "https://github.com/bingmann/sound-of-sorting/tree/master/acscripts/"
    click src_Makefile_am "https://github.com/bingmann/sound-of-sorting/blob/master/src/Makefile.am"
    click src_Makefile_in "https://github.com/bingmann/sound-of-sorting/blob/master/src/Makefile.in"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085
    classDef core fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef build fill:#ffeeba,stroke:#856404,color:#856404

    class BuildSystem build
    class CompiledApp build
```
