One header per mode, each ~50-130 LOC built atop ModeBase:
- `paf_synth.hpp` (4 inputs → 33 outputs, 7 voice spaces, note_on/off)
- `channel_strip.hpp` (4 → 24, 6 voice spaces)
- `xiasri.hpp` (4 → 24, 1 'Direct' voice space)
- `verb_fx.hpp` (4 → 47, 12 voice spaces)
- `memlcelium.hpp` (4 → 56, dual synth + 2-track sequencer; set_playing/update_bpm)
- `breakor.hpp` (4 → 56, 8-track ratio sequencer; pumps engine NoteOn/Off/Clock
events into ControlEvent ring buffer)
- `elysiamorf.hpp` (4 → 40, 8-track FM-pair MIDI-CC sequencer; pumps CC events)
- `sound_analysis_midi.hpp` (10 → 8; owns AnalysisEngine for input feature
extraction PLUS NoOpEngine 'thru' for audio passthrough; ML outputs
converted to MIDI CC events via on_post_inference; opts out of
output→engine routing via ModeRoutesOutputsToEngine specialisation)
Every mode satisfies `nisps::Mode` (verified via `static_assert` in each
header). Schema `output_size` is verified against engine `param_count()`
at compile time inside ModeBase.
All hardware-specific glue (MEMLNaut::Instance, pico/util/queue, MIDIInOut,
display widgets, button callbacks) is intentionally absent — that lives in
firmware/glue and playground/src/modes per architecture.md §4.3.
94 lines
3.4 KiB
C++
94 lines
3.4 KiB
C++
// nisps/modes/breakor.hpp — Break|| 8-track ratio sequencer mode binding.
|
|
//
|
|
// 4 abstract input channels → MLP[4, 10, 14, 18, 56] → BreakOrEngine.
|
|
// process() returns silence; the engine queues NoteOn/NoteOff/Clock events
|
|
// each tick. The mode forwards them through its ControlEvent ring buffer
|
|
// for the platform glue (firmware MIDI/I2C, browser WebMIDI) to drain.
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <span>
|
|
#include <string_view>
|
|
|
|
#include "../core/concepts.hpp"
|
|
#include "../core/perf.hpp"
|
|
#include "../core/types.hpp"
|
|
#include "../engines/breakor.hpp"
|
|
#include "../ml/mlp.hpp"
|
|
#include "base.hpp"
|
|
#include "generated/breakor_schema.hpp"
|
|
|
|
namespace nisps::modes {
|
|
|
|
class BreakOrMode : public ModeBase<
|
|
BreakOrMode,
|
|
BreakOrEngine,
|
|
ml::MLP<4u, 10u, 14u, 18u, 56u>,
|
|
4u> {
|
|
public:
|
|
using Base = ModeBase<BreakOrMode, BreakOrEngine,
|
|
ml::MLP<4u, 10u, 14u, 18u, 56u>, 4u>;
|
|
using Base::Base;
|
|
|
|
static constexpr std::string_view mode_id() noexcept {
|
|
return generated::kBreakorModeId;
|
|
}
|
|
static constexpr const ParamSchema& param_schema() noexcept { return kSchema; }
|
|
|
|
NISPS_FORCE_INLINE void set_playing(bool playing) noexcept {
|
|
engine_.set_playing(playing);
|
|
}
|
|
NISPS_FORCE_INLINE void update_bpm(float bpm) noexcept {
|
|
engine_.update_bpm(bpm);
|
|
}
|
|
NISPS_FORCE_INLINE void set_track_note(std::size_t track, std::uint8_t note) noexcept {
|
|
engine_.set_track_note(track, note);
|
|
}
|
|
|
|
// Drains queued engine events, repackages them as ControlEvent and pushes
|
|
// them into the mode's event ring. Called by hardware glue from the
|
|
// audio thread (or right after process()) to forward MIDI/I2C output.
|
|
void pump_engine_events() noexcept {
|
|
std::array<BreakOrEngine::Event, 32u> buf;
|
|
const std::size_t n = engine_.pop_events(std::span<BreakOrEngine::Event>(buf));
|
|
for (std::size_t i = 0u; i < n; ++i) {
|
|
const auto& e = buf[i];
|
|
ControlEvent ce{};
|
|
switch (e.kind) {
|
|
case BreakOrEngine::EventKind::NoteOn:
|
|
ce.kind = ControlEvent::Kind::NoteOn; break;
|
|
case BreakOrEngine::EventKind::NoteOff:
|
|
ce.kind = ControlEvent::Kind::NoteOff; break;
|
|
case BreakOrEngine::EventKind::Clock:
|
|
ce.kind = ControlEvent::Kind::Clock; break;
|
|
}
|
|
ce.channel = e.track;
|
|
ce.data1 = e.midi_note;
|
|
ce.data2 = e.velocity;
|
|
(void)push_control_event(ce);
|
|
}
|
|
}
|
|
|
|
private:
|
|
static inline constexpr ParamSchema kSchema = ParamSchema{
|
|
generated::kBreakorModeId,
|
|
generated::kBreakorEngineId,
|
|
std::span<const std::string_view>(generated::kBreakorInputChannels),
|
|
generated::kBreakorMLConfig.input_size,
|
|
std::span<const std::size_t>(generated::kBreakorHiddenLayers),
|
|
generated::kBreakorMLConfig.output_size,
|
|
generated::kBreakorMLConfig.default_spread,
|
|
generated::kBreakorMLConfig.default_learning_rate,
|
|
generated::kBreakorMLConfig.default_max_iterations,
|
|
std::span<const generated::Param>(generated::kBreakorParams),
|
|
std::span<const std::string_view>(generated::kBreakorVoiceSpaces),
|
|
generated::kBreakorUI,
|
|
};
|
|
};
|
|
|
|
static_assert(Mode<BreakOrMode>, "BreakOrMode must satisfy nisps::Mode");
|
|
|
|
} // namespace nisps::modes
|