#pragma once #include #include #include #include #include #include #include #include #include #include class SinkManager { public: SinkManager(); class Sink { public: virtual ~Sink() {} virtual void start() = 0; virtual void stop() = 0; virtual void menuHandler() = 0; }; class Stream { public: Stream() {} Stream(dsp::stream* in, const EventHandler& srChangeHandler, float sampleRate); void init(dsp::stream* in, const EventHandler& srChangeHandler, float sampleRate); void start(); void stop(); void setVolume(float volume); float getVolume(); void setSampleRate(float sampleRate); float getSampleRate(); void setInput(dsp::stream* in); dsp::stream* bindStream(); void unbindStream(dsp::stream* stream); friend SinkManager; friend SinkManager::Sink; dsp::stream* sinkOut; Event srChange; private: dsp::stream* _in; dsp::Splitter splitter; SinkManager::Sink* sink; dsp::stream volumeInput; dsp::Volume volumeAjust; std::mutex ctrlMtx; float _sampleRate; int providerId = 0; bool running = false; float guiVolume = 1.0f; }; struct SinkProvider { SinkManager::Sink* (*create)(SinkManager::Stream* stream, std::string streamName, void* ctx); void* ctx; }; class NullSink : SinkManager::Sink { public: NullSink(SinkManager::Stream* stream) { ns.init(stream->sinkOut); } void start() { ns.start(); } void stop() { ns.stop(); } void menuHandler() {} static SinkManager::Sink* create(SinkManager::Stream* stream, std::string streamName, void* ctx) { stream->setSampleRate(48000); return new SinkManager::NullSink(stream); } private: dsp::NullSink ns; }; 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); float getStreamSampleRate(std::string name); void setStreamSink(std::string name, std::string providerName); void showVolumeSlider(std::string name, std::string prefix, float width, float btnHeight = -1.0f, int btwBorder = 0, bool sameLine = false); dsp::stream* bindStream(std::string name); void unbindStream(std::string name, dsp::stream* stream); void loadSinksFromConfig(); void showMenu(); std::vector getStreamNames(); Event streamRegisteredEvnt; Event streamUnregisteredEvnt; private: void loadStreamConfig(std::string name); void saveStreamConfig(std::string name); std::map providers; std::map streams; std::vector providerNames; std::vector streamNames; };