1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
* plugin.h
*
* Sun Feb 7 14:11:40 CET 2016
* Copyright 2016 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
/*
* This file is part of PluginGizmo.
*
* PluginGizmo is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* PluginGizmo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PluginGizmo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#pragma once
#include <vector>
#include <string>
#include <cstdint>
#include <cstdlib>
#if defined(WIN32)
#define PG_EXPORT extern "C" __declspec(dllexport)
#else
#define PG_EXPORT extern "C" __attribute__((visibility("default")))
#endif
class MidiEvent;
//! Plugin categories.
enum class PluginCategory
{
Unknown = 0, // Unknown, category not implemented
Effect, // Simple Effect
Synth, // Instrument (Synths, samplers,...)
Analysis, // Scope, Tuner, ...
Mastering, // Dynamics, ...
Spacializer, // Panners, ...
RoomFx, // Delays and Reverbs
SurroundFx, // Dedicated surround processor
Restoration, // Denoiser, ...
OfflineProcess, // Offline Process
Shell, // Plug-in is container of other plug-ins
Generator // ToneGenerator, ...
};
//! Abstract base-class for plugin implementations.
class Plugin {
public:
//! Implement this to create a new plugin instance.
static Plugin* create();
//! Init function for setting up plugin parameters.
virtual void init() = 0;
//! Get current free-wheel mode.
virtual bool getFreeWheel() const = 0;
//! This method is called by the host when the free-wheel mode changes.
virtual void onFreeWheelChange(bool freewheel) {}
//! Call this to get current samplerate.
virtual float getSamplerate() = 0;
//! This method is called by the host when the samplerate changes.
virtual void onSamplerateChange(float samplerate) = 0;
//! Call this to get current frame-size.
virtual std::size_t getFramesize() = 0;
//! This method is called by the host when the frame-size changes.
virtual void onFramesizeChange(std::size_t framesize) = 0;
//! Call this to get current active state
virtual bool getActive() = 0;
//! This method is called by the host when the active state changes.
virtual void onActiveChange(bool active) = 0;
//! This method is called by the host to get the current state for storing.
virtual std::string onStateSave() = 0;
//! This method is called by the host when a new state has been loaded.
virtual void onStateRestore(const std::string& config) = 0;
//! This is method is called by the host to get the current latency.
//! \param The latency in samples.
virtual float getLatency() = 0;
//! Call this method to signal a latency change to the host.
//! \param latency The latency in samples.
virtual void setLatency(float latency) = 0;
//! Called by the the host to get the number of midi input channels.
//! This must remain constant during the lifespan of the plugin instance.
virtual std::size_t getNumberOfMidiInputs() = 0;
//! Called by the the host to get the number of midi output channels.
//! This must remain constant during the lifespan of the plugin instance.
virtual std::size_t getNumberOfMidiOutputs() = 0;
//! Called by the the host to get the number of audio input channels.
//! This must remain constant during the lifespan of the plugin instance.
virtual std::size_t getNumberOfAudioInputs() = 0;
//! Called by the the host to get the number of audio output channels.
//! This must remain constant during the lifespan of the plugin instance.
virtual std::size_t getNumberOfAudioOutputs() = 0;
//! Call this method to set midnam data for midi input
virtual void setMidnamData(const std::vector<std::pair<int, std::string>>& midnam) {}
//! Get unique plugin id.
virtual std::string getId() = 0;
// Functions used to set plugin information.
virtual std::string getURI() = 0;
virtual std::string getEffectName() = 0;
virtual std::string getVendorString() = 0;
virtual std::string getProductString() = 0;
virtual std::string getHomepage() = 0;
virtual PluginCategory getPluginCategory() = 0;
//! Process callback.
virtual void process(std::size_t pos,
const std::vector<MidiEvent>& input_events,
std::vector<MidiEvent>& output_events,
const std::vector<const float*>& input_samples,
const std::vector<float*>& output_samples,
std::size_t count) = 0;
//
// Inline GUI (optional)
//
//! Return true if a GUI implementation is to be used.
virtual bool hasInlineGUI()
{
return false;
}
struct InlineDrawContext
{
std::size_t width{0}; //< Width of the render buffer.
std::size_t height{0}; //< Height of the render buffer.
std::uint8_t* data{nullptr}; //< Allocated (or reused) RGBA buffer, filled by the plugin.
};
#define pgzRGBA(r, g, b, a) ((b) | (g) << 8 | (r) << 16 | (a) << 24)
//! Render call back.
//! \param width The client area width as specified by the host.
//! \param max_height The maximum allowed clieant area height as specified
//! by the host.
//! \param context The render context filled an maintained by the plugin.
virtual void onInlineRedraw(std::size_t width,
std::size_t max_height,
InlineDrawContext& context) {}
//
// GUI (optional)
//
//! Return true if a GUI implementation is to be used.
virtual bool hasGUI()
{
return false;
}
//! Create new window.
virtual void* createWindow(void *parent) { return nullptr; }
//! Destroy window.
virtual void onDestroyWindow() {}
//! Show window.
virtual void onShowWindow() {}
//! Hide window.
virtual void onHideWindow() {}
//! Called regularly by host; process ui events.
virtual void onIdle() {}
//! Signal new window size to host.
virtual void resizeWindow(std::size_t width, std::size_t height) = 0;
//! Signal close window event to the host.
virtual void closeWindow() = 0;
};
|