76 lines
1.8 KiB
C
Raw Normal View History

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>
#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;
Event<float> srChange;
2020-11-22 18:26:48 +01:00
SinkManager::Sink* sink;
int providerId = 0;
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;
std::mutex ctrlMtx;
float _sampleRate;
};
struct SinkProvider {
SinkManager::Sink* (*create)(SinkManager::Stream* stream, void* ctx);
void* ctx;
};
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
};