Add MIDI input driver
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
f178251d79
commit
70d2f63acc
4 changed files with 366 additions and 127 deletions
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <audio.hpp>
|
||||
#include <context.hpp>
|
||||
#include <midi.hpp>
|
||||
|
||||
#ifdef NDEBUG
|
||||
# undef DEBUG
|
||||
|
@ -54,6 +55,9 @@ struct CardinalPluginContext : rack::Context {
|
|||
|
||||
// -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
struct CardinalMidiInputDevice;
|
||||
struct CardinalMidiOutputDevice;
|
||||
|
||||
class CardinalBasePlugin : public Plugin {
|
||||
public:
|
||||
CardinalPluginContext* const context;
|
||||
|
@ -63,9 +67,12 @@ public:
|
|||
context(new CardinalPluginContext(this)) {}
|
||||
~CardinalBasePlugin() override {}
|
||||
virtual bool isActive() const noexcept = 0;
|
||||
virtual bool isProcessing() const noexcept = 0;
|
||||
virtual bool canAssignDevice() const noexcept = 0;
|
||||
virtual void assignDevice(rack::audio::Device* dev) noexcept = 0;
|
||||
virtual bool clearDevice(rack::audio::Device* dev) noexcept = 0;
|
||||
virtual void addMidiInput(CardinalMidiInputDevice* dev) = 0;
|
||||
virtual void removeMidiInput(CardinalMidiInputDevice* dev) = 0;
|
||||
|
||||
protected:
|
||||
void bufferSizeChanged(const uint32_t newBufferSize) override
|
||||
|
@ -82,128 +89,4 @@ protected:
|
|||
|
||||
// -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
struct CardinalAudioDevice : rack::audio::Device {
|
||||
CardinalBasePlugin* const fPlugin;
|
||||
|
||||
CardinalAudioDevice(CardinalBasePlugin* const plugin)
|
||||
: fPlugin(plugin) {}
|
||||
|
||||
std::string getName() override
|
||||
{
|
||||
return "Cardinal";
|
||||
}
|
||||
|
||||
int getNumInputs() override
|
||||
{
|
||||
return DISTRHO_PLUGIN_NUM_INPUTS;
|
||||
}
|
||||
|
||||
int getNumOutputs() override
|
||||
{
|
||||
return DISTRHO_PLUGIN_NUM_OUTPUTS;
|
||||
}
|
||||
|
||||
int getBlockSize() override
|
||||
{
|
||||
return fPlugin->getBufferSize();
|
||||
}
|
||||
|
||||
float getSampleRate() override
|
||||
{
|
||||
return fPlugin->getSampleRate();
|
||||
}
|
||||
|
||||
std::set<int> getBlockSizes() override
|
||||
{
|
||||
return std::set<int>({ getBlockSize() });
|
||||
}
|
||||
|
||||
std::set<float> getSampleRates() override
|
||||
{
|
||||
return std::set<float>({ getSampleRate() });
|
||||
}
|
||||
|
||||
void setBlockSize(int) override {}
|
||||
void setSampleRate(float) override {}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
struct CardinalAudioDriver : rack::audio::Driver {
|
||||
|
||||
CardinalAudioDriver() {}
|
||||
|
||||
std::string getName() override
|
||||
{
|
||||
return "Plugin Driver";
|
||||
}
|
||||
|
||||
std::vector<int> getDeviceIds() override
|
||||
{
|
||||
return std::vector<int>({ 0 });
|
||||
}
|
||||
|
||||
int getDefaultDeviceId() override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string getDeviceName(int) override
|
||||
{
|
||||
return "Plugin Device";
|
||||
}
|
||||
|
||||
int getDeviceNumInputs(int) override
|
||||
{
|
||||
return DISTRHO_PLUGIN_NUM_INPUTS;
|
||||
}
|
||||
|
||||
int getDeviceNumOutputs(int) override
|
||||
{
|
||||
return DISTRHO_PLUGIN_NUM_OUTPUTS;
|
||||
}
|
||||
|
||||
rack::audio::Device* subscribe(int, rack::audio::Port* const port) override
|
||||
{
|
||||
CardinalPluginContext* const pluginContext = reinterpret_cast<CardinalPluginContext*>(port->context);
|
||||
DISTRHO_SAFE_ASSERT_RETURN(pluginContext != nullptr, nullptr);
|
||||
|
||||
CardinalBasePlugin* const plugin = reinterpret_cast<CardinalBasePlugin*>(pluginContext->plugin);
|
||||
DISTRHO_SAFE_ASSERT_RETURN(plugin != nullptr, nullptr);
|
||||
|
||||
if (! plugin->canAssignDevice())
|
||||
throw rack::Exception("Plugin driver only allows one audio device to be used simultaneously");
|
||||
|
||||
CardinalAudioDevice* const device = new CardinalAudioDevice(plugin);
|
||||
device->subscribe(port);
|
||||
|
||||
if (plugin->isActive())
|
||||
device->onStartStream();
|
||||
|
||||
plugin->assignDevice(device);
|
||||
return device;
|
||||
}
|
||||
|
||||
void unsubscribe(int, rack::audio::Port* const port) override
|
||||
{
|
||||
CardinalAudioDevice* const device = reinterpret_cast<CardinalAudioDevice*>(port->device);
|
||||
DISTRHO_SAFE_ASSERT_RETURN(device != nullptr,);
|
||||
|
||||
CardinalPluginContext* const pluginContext = reinterpret_cast<CardinalPluginContext*>(port->context);
|
||||
DISTRHO_SAFE_ASSERT_RETURN(pluginContext != nullptr,);
|
||||
|
||||
CardinalBasePlugin* const plugin = reinterpret_cast<CardinalBasePlugin*>(pluginContext->plugin);
|
||||
DISTRHO_SAFE_ASSERT_RETURN(plugin != nullptr,);
|
||||
|
||||
if (plugin->clearDevice(device))
|
||||
{
|
||||
device->onStopStream();
|
||||
device->unsubscribe(port);
|
||||
delete device;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
END_NAMESPACE_DISTRHO
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue