2020-11-12 00:53:38 +01:00
|
|
|
#pragma once
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <dsp/stream.h>
|
|
|
|
#include <dsp/types.h>
|
|
|
|
#include <dsp/routing.h>
|
2020-11-29 20:55:00 +01:00
|
|
|
#include <dsp/sink.h>
|
2020-11-12 00:53:38 +01:00
|
|
|
#include <mutex>
|
|
|
|
#include <event.h>
|
2020-11-22 18:26:48 +01:00
|
|
|
#include <vector>
|
2020-11-12 00:53:38 +01:00
|
|
|
|
|
|
|
class SinkManager {
|
|
|
|
public:
|
|
|
|
SinkManager();
|
|
|
|
|
|
|
|
class Sink {
|
|
|
|
public:
|
2020-11-22 18:26:48 +01:00
|
|
|
virtual void start() = 0;
|
|
|
|
virtual void stop() = 0;
|
2020-11-12 00:53:38 +01:00
|
|
|
virtual void menuHandler() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Stream {
|
|
|
|
public:
|
|
|
|
Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate);
|
|
|
|
|
2020-11-22 18:26:48 +01:00
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
|
2020-11-12 00:53:38 +01:00
|
|
|
void setInput(dsp::stream<dsp::stereo_t>* in);
|
|
|
|
|
|
|
|
dsp::stream<dsp::stereo_t>* bindStream();
|
|
|
|
void unbindStream(dsp::stream<dsp::stereo_t>* stream);
|
|
|
|
|
|
|
|
friend SinkManager;
|
|
|
|
friend SinkManager::Sink;
|
|
|
|
|
2020-11-29 20:55:00 +01:00
|
|
|
Event<float> srChange;
|
2020-11-12 00:53:38 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setSampleRate(float sampleRate);
|
|
|
|
|
|
|
|
dsp::stream<dsp::stereo_t>* _in;
|
|
|
|
dsp::Splitter<dsp::stereo_t> splitter;
|
2020-11-29 20:55:00 +01:00
|
|
|
SinkManager::Sink* sink;
|
2020-11-12 00:53:38 +01:00
|
|
|
std::mutex ctrlMtx;
|
|
|
|
float _sampleRate;
|
2020-11-29 20:55:00 +01:00
|
|
|
int providerId = 0;
|
|
|
|
bool running = false;
|
2020-11-12 00:53:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SinkProvider {
|
2020-11-29 20:55:00 +01:00
|
|
|
SinkManager::Sink* (*create)(SinkManager::Stream* stream, std::string streamName, void* ctx);
|
2020-11-12 00:53:38 +01:00
|
|
|
void* ctx;
|
|
|
|
};
|
|
|
|
|
2020-11-29 20:55:00 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-12 00:53:38 +01:00
|
|
|
void registerSinkProvider(std::string name, SinkProvider provider);
|
|
|
|
|
|
|
|
void registerStream(std::string name, Stream* stream);
|
|
|
|
void unregisterStream(std::string name);
|
|
|
|
|
2020-11-22 18:26:48 +01:00
|
|
|
void startStream(std::string name);
|
|
|
|
void stopStream(std::string name);
|
|
|
|
|
|
|
|
void setStreamSink(std::string name, std::string providerName);
|
|
|
|
|
2020-11-12 00:53:38 +01:00
|
|
|
dsp::stream<dsp::stereo_t>* bindStream(std::string name);
|
|
|
|
void unbindStream(std::string name, dsp::stream<dsp::stereo_t>* stream);
|
|
|
|
|
|
|
|
void showMenu();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::map<std::string, SinkProvider> providers;
|
|
|
|
std::map<std::string, Stream*> streams;
|
2020-11-22 18:26:48 +01:00
|
|
|
std::vector<std::string> providerNames;
|
2020-11-12 00:53:38 +01:00
|
|
|
|
|
|
|
};
|