Core engine (wauvio/core)

seq.hpp — notes, tracks, sequencing

Namespace wauvio::seq. A minimal, monophonic-per-track sequencing layer. (Richer instruments and arrangements are in wauvio::music.)

Note, Instrument, Track

  • Note{frequency, duration, amplitude} (440 Hz, 0.25 s, 0.8).
  • Instrument: shape, envelope (ADSR 0.01/0.05/0.7/0.08), gain, detune (Hz added to the note), use_lpf + lpf_cutoff (one-pole low-pass), duty. render_note(note) synthesises one note; frequencies below 1 Hz yield silence of the note's duration.
  • Track holds an Instrument and a note list. Chainable add(f, d, a), add(Note), rest(d); total_duration(); render() places notes back-to-back.
  • Helpers render_chord(freqs, duration, instr) and render_arpeggio(freqs, step_dur, cycles, instr).

DrumSequencer

bpm (120), steps_per_bar (16). Patterns are added with add_pattern(steps, sound, gain) where steps is a vector<bool> and sound is a std::function<Buffer(int sample_rate)> that synthesises one hit. Step length is 60 / (bpm · steps_per_bar / 4) seconds. A pattern shorter than steps_per_bar repeats cyclically. Keep steps non-empty. render(num_bars) mixes all patterns into a mono buffer.

MasterBus

A timeline mixer. schedule(buf, onset_seconds, gain) places a mono or stereo buffer at an absolute time; a movable cursor (advance, set_cursor, cursor, place) supports sequential placement. mix_stereo() sums everything to a stereo buffer (mono slots go to both channels); mix() returns mono; reset() clears. Output length is the end of the latest slot. Constructed with an optional sample rate.

Full API listing

wauvio/core/seq.hpp

wauvio::seq::struct Note

//  §25  NOTE / INSTRUMENT / TRACK  (unchanged from v1, stereo-aware)
struct Note
    double frequency = 440.0;
    double duration  = 0.25;
    double amplitude = 0.8;
    Note() = default;
    Note(double f, double d, double a = 0.8) : frequency(f), duration(d), amplitude(a) {}

wauvio::seq::struct Instrument

struct Instrument
    wauvio::osc::WaveShape shape      = wauvio::osc::WaveShape::Sine;
    wauvio::env::ADSR      envelope   = {0.01, 0.05, 0.7, 0.08};
    float     gain       = 1.0f;
    double    detune     = 0.0;
    bool      use_lpf    = false;
    double    lpf_cutoff = 2000.0;
    double    duty       = 0.5;
    Buffer render_note(const Note& note, int sample_rate = 0) const

wauvio::seq::class Track

class Track
public:
    Instrument instrument;
    Track() = default;
    explicit Track(const Instrument& i) : instrument(i) {}
    Track& add(double f, double d, double a = 0.8)
    Track& rest(double d) { notes_.push_back({0.0, d}); return *this; }
    Track& add(const Note& n) { notes_.push_back(n); return *this; }
    double total_duration() const
    Buffer render(int sample_rate = 0) const
// Helpers
inline Buffer render_chord(const std::vector<double>& freqs, double duration,
                            const Instrument& instr, int sample_rate = 0)

inline Buffer render_arpeggio(const std::vector<double>& freqs, double step_dur,
                               int cycles, const Instrument& instr, int sample_rate = 0)

wauvio::seq::class DrumSequencer

//  §26  DRUM SEQUENCER  (unchanged from v1)
class DrumSequencer
public:
    double bpm           = 120.0;
    int    steps_per_bar = 16;
    struct Pattern
        std::vector<bool>          steps;
        std::function<Buffer(int)> sound;
        float                      gain = 1.0f;
    void add_pattern(std::vector<bool> steps,
                     std::function<Buffer(int)> sound, float gain = 1.0f)
    { patterns_.push_back({ std::move(steps), std::move(sound), gain }); }
    void clear_patterns() { patterns_.clear(); }
    Buffer render(int num_bars = 1, int sample_rate = 0) const

wauvio::seq::class MasterBus

//  §27  MASTER BUS  (now handles both mono Buffer and StereoBuffer)
class MasterBus
public:
    int sample_rate;
    explicit MasterBus(int sr = 0)
        : sample_rate(sr > 0 ? sr : global_config().sample_rate) {}
    void schedule(Buffer buf, double onset, float gain = 1.0f)
    void schedule(StereoBuffer buf, double onset, float gain = 1.0f)
    void advance(double s) { cursor_ += s; }
    double cursor() const noexcept { return cursor_; }
    void set_cursor(double t) { cursor_ = t; }
    void place(Buffer buf, float gain = 1.0f)
    void place(StereoBuffer buf, float gain = 1.0f)
    /// Mix all scheduled content into a stereo output.
    StereoBuffer mix_stereo() const
    /// Mix all scheduled content into a mono output.
    Buffer mix() const
    void reset() { mono_slots_.clear(); stereo_slots_.clear(); cursor_ = 0.0; }