#pragma once #include #include #include #include #include #include #include #include #include class SinkManager { public: SinkManager(); class Sink { public: virtual void start() = 0; virtual void stop() = 0; virtual void menuHandler() = 0; }; class Stream { public: Stream(dsp::stream* in, const Event::EventHandler& srChangeHandler, float sampleRate); void start(); void stop(); void setInput(dsp::stream* in); dsp::stream* bindStream(); void unbindStream(dsp::stream* stream); friend SinkManager; friend SinkManager::Sink; Event srChange; private: void setSampleRate(float sampleRate); dsp::stream* _in; dsp::Splitter splitter; SinkManager::Sink* sink; std::mutex ctrlMtx; float _sampleRate; int providerId = 0; bool running = false; }; struct SinkProvider { SinkManager::Sink* (*create)(SinkManager::Stream* stream, std::string streamName, void* ctx); void* ctx; }; class NullSink : SinkManager::Sink { public: void start() {} void stop() {} void menuHandler() {} static SinkManager::Sink* create(SinkManager::Stream* stream, std::string streamName, void* ctx) { return new SinkManager::NullSink; } }; void registerSinkProvider(std::string name, SinkProvider provider); void registerStream(std::string name, Stream* stream); void unregisterStream(std::string name); void startStream(std::string name); void stopStream(std::string name); void setStreamSink(std::string name, std::string providerName); dsp::stream* bindStream(std::string name); void unbindStream(std::string name, dsp::stream* stream); void showMenu(); private: std::map providers; std::map streams; std::vector providerNames; };