|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- /*
- * Carla Native Plugin API (C++)
- * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program 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 General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- #ifndef CARLA_NATIVE_HPP_INCLUDED
- #define CARLA_NATIVE_HPP_INCLUDED
-
- #include "CarlaNative.h"
- #include "CarlaMIDI.h"
- #include "CarlaJuceUtils.hpp"
-
- /*!
- * @defgroup CarlaNativeAPI Carla Native API
- * @{
- */
-
- // -----------------------------------------------------------------------
- // Plugin Descriptor Class
-
- class PluginDescriptorClass
- {
- public:
- PluginDescriptorClass(const HostDescriptor* const host)
- : pHost(host)
- {
- CARLA_ASSERT(host != nullptr);
- }
-
- virtual ~PluginDescriptorClass()
- {
- }
-
- protected:
- // -------------------------------------------------------------------
- // Host calls
-
- const HostDescriptor* getHostHandle() const noexcept
- {
- return pHost;
- }
-
- const char* getResourceDir() const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, nullptr);
-
- return pHost->resourceDir;
- }
-
- const char* getUiName() const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, nullptr);
-
- return pHost->uiName;
- }
-
- uint32_t getBufferSize() const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, 0);
-
- return pHost->get_buffer_size(pHost->handle);
- }
-
- double getSampleRate() const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, 0.0);
-
- return pHost->get_sample_rate(pHost->handle);
- }
-
- bool isOffline() const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, false);
-
- return pHost->is_offline(pHost->handle);
- }
-
- const TimeInfo* getTimeInfo() const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, nullptr);
-
- return pHost->get_time_info(pHost->handle);
- }
-
- void writeMidiEvent(const MidiEvent* const event) const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr,);
-
- pHost->write_midi_event(pHost->handle, event);
- }
-
- void uiParameterChanged(const uint32_t index, const float value) const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr,);
-
- pHost->ui_parameter_changed(pHost->handle, index, value);
- }
-
- void uiMidiProgramChanged(const uint8_t channel, const uint32_t bank, const uint32_t program) const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr,);
-
- pHost->ui_midi_program_changed(pHost->handle, channel, bank, program);
- }
-
- void uiCustomDataChanged(const char* const key, const char* const value) const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr,);
-
- pHost->ui_custom_data_changed(pHost->handle, key, value);
- }
-
- void uiClosed() const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr,);
-
- pHost->ui_closed(pHost->handle);
- }
-
- const char* uiOpenFile(const bool isDir, const char* const title, const char* const filter) const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, nullptr);
-
- return pHost->ui_open_file(pHost->handle, isDir, title, filter);
- }
-
- const char* uiSaveFile(const bool isDir, const char* const title, const char* const filter) const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, nullptr);
-
- return pHost->ui_save_file(pHost->handle, isDir, title, filter);
- }
-
- intptr_t hostDispatcher(const HostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt) const
- {
- CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, 0);
-
- return pHost->dispatcher(pHost->handle, opcode, index, value, ptr, opt);
- }
-
- // -------------------------------------------------------------------
- // Plugin parameter calls
-
- virtual uint32_t getParameterCount()
- {
- return 0;
- }
-
- virtual const Parameter* getParameterInfo(const uint32_t index)
- {
- CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(), nullptr);
- return nullptr;
- }
-
- virtual float getParameterValue(const uint32_t index)
- {
- CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(), 0.0f);
- return 0.0f;
- }
-
- virtual const char* getParameterText(const uint32_t index, const float value)
- {
- CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(), nullptr);
- return nullptr;
-
- // unused
- (void)value;
- }
-
- // -------------------------------------------------------------------
- // Plugin midi-program calls
-
- virtual uint32_t getMidiProgramCount()
- {
- return 0;
- }
-
- virtual const MidiProgram* getMidiProgramInfo(const uint32_t index)
- {
- CARLA_SAFE_ASSERT_RETURN(index < getMidiProgramCount(), nullptr);
- return nullptr;
- }
-
- // -------------------------------------------------------------------
- // Plugin state calls
-
- virtual void setParameterValue(const uint32_t index, const float value)
- {
- CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),);
- return;
-
- // unused
- (void)value;
- }
-
- virtual void setMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program)
- {
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- return;
-
- // unused
- (void)bank;
- (void)program;
- }
-
- virtual void setCustomData(const char* const key, const char* const value)
- {
- CARLA_SAFE_ASSERT_RETURN(key != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
- }
-
- // -------------------------------------------------------------------
- // Plugin process calls
-
- virtual void activate()
- {
- }
-
- virtual void deactivate()
- {
- }
-
- virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t midiEventCount, const MidiEvent* const midiEvents) = 0;
-
- // -------------------------------------------------------------------
- // Plugin UI calls
-
- virtual void uiShow(const bool show)
- {
- return;
-
- // unused
- (void)show;
- }
-
- virtual void uiIdle()
- {
- }
-
- virtual void uiSetParameterValue(const uint32_t index, const float value)
- {
- CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),);
- return;
-
- // unused
- (void)value;
- }
-
- virtual void uiSetMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program)
- {
- CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
- return;
-
- // unused
- (void)bank;
- (void)program;
- }
-
- virtual void uiSetCustomData(const char* const key, const char* const value)
- {
- CARLA_SAFE_ASSERT_RETURN(key != nullptr,);
- CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
- }
-
- // -------------------------------------------------------------------
- // Plugin state calls
-
- virtual char* getState()
- {
- return nullptr;
- }
-
- virtual void setState(const char* const data)
- {
- CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
- }
-
- // -------------------------------------------------------------------
- // Plugin dispatcher
-
- virtual intptr_t pluginDispatcher(const PluginDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
- {
- return 0;
-
- // unused
- (void)opcode;
- (void)index;
- (void)value;
- (void)ptr;
- (void)opt;
- }
-
- // -------------------------------------------------------------------
-
- private:
- const HostDescriptor* const pHost;
-
- // -------------------------------------------------------------------
-
- #ifndef DOXYGEN
- public:
- #define handlePtr ((PluginDescriptorClass*)handle)
-
- static uint32_t _get_parameter_count(PluginHandle handle)
- {
- return handlePtr->getParameterCount();
- }
-
- static const Parameter* _get_parameter_info(PluginHandle handle, uint32_t index)
- {
- return handlePtr->getParameterInfo(index);
- }
-
- static float _get_parameter_value(PluginHandle handle, uint32_t index)
- {
- return handlePtr->getParameterValue(index);
- }
-
- static const char* _get_parameter_text(PluginHandle handle, uint32_t index, float value)
- {
- return handlePtr->getParameterText(index, value);
- }
-
- static uint32_t _get_midi_program_count(PluginHandle handle)
- {
- return handlePtr->getMidiProgramCount();
- }
-
- static const MidiProgram* _get_midi_program_info(PluginHandle handle, uint32_t index)
- {
- return handlePtr->getMidiProgramInfo(index);
- }
-
- static void _set_parameter_value(PluginHandle handle, uint32_t index, float value)
- {
- handlePtr->setParameterValue(index, value);
- }
-
- static void _set_midi_program(PluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program)
- {
- handlePtr->setMidiProgram(channel, bank, program);
- }
-
- static void _set_custom_data(PluginHandle handle, const char* key, const char* value)
- {
- handlePtr->setCustomData(key, value);
- }
-
- static void _ui_show(PluginHandle handle, bool show)
- {
- handlePtr->uiShow(show);
- }
-
- static void _ui_idle(PluginHandle handle)
- {
- handlePtr->uiIdle();
- }
-
- static void _ui_set_parameter_value(PluginHandle handle, uint32_t index, float value)
- {
- handlePtr->uiSetParameterValue(index, value);
- }
-
- static void _ui_set_midi_program(PluginHandle handle, uint8_t channel, uint32_t bank, uint32_t program)
- {
- handlePtr->uiSetMidiProgram(channel, bank, program);
- }
-
- static void _ui_set_custom_data(PluginHandle handle, const char* key, const char* value)
- {
- handlePtr->uiSetCustomData(key, value);
- }
-
- static void _activate(PluginHandle handle)
- {
- handlePtr->activate();
- }
-
- static void _deactivate(PluginHandle handle)
- {
- handlePtr->deactivate();
- }
-
- static void _process(PluginHandle handle, float** inBuffer, float** outBuffer, const uint32_t frames, uint32_t midiEventCount, const MidiEvent* midiEvents)
- {
- handlePtr->process(inBuffer, outBuffer, frames, midiEventCount, midiEvents);
- }
-
- static char* _get_state(PluginHandle handle)
- {
- return handlePtr->getState();
- }
-
- static void _set_state(PluginHandle handle, const char* data)
- {
- handlePtr->setState(data);
- }
-
- static intptr_t _dispatcher(PluginHandle handle, PluginDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt)
- {
- return handlePtr->pluginDispatcher(opcode, index, value, ptr, opt);
- }
-
- #undef handlePtr
-
- CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginDescriptorClass)
- #endif
- };
-
- /**@}*/
-
- // -----------------------------------------------------------------------
-
- #define PluginDescriptorClassEND(ClassName) \
- public: \
- static PluginHandle _instantiate(HostDescriptor* host) \
- { \
- return new ClassName(host); \
- } \
- static void _cleanup(PluginHandle handle) \
- { \
- delete (ClassName*)handle; \
- }
-
- #define PluginDescriptorFILL(ClassName) \
- ClassName::_instantiate, \
- ClassName::_cleanup, \
- ClassName::_get_parameter_count, \
- ClassName::_get_parameter_info, \
- ClassName::_get_parameter_value, \
- ClassName::_get_parameter_text, \
- ClassName::_get_midi_program_count, \
- ClassName::_get_midi_program_info, \
- ClassName::_set_parameter_value, \
- ClassName::_set_midi_program, \
- ClassName::_set_custom_data, \
- ClassName::_ui_show, \
- ClassName::_ui_idle, \
- ClassName::_ui_set_parameter_value, \
- ClassName::_ui_set_midi_program, \
- ClassName::_ui_set_custom_data, \
- ClassName::_activate, \
- ClassName::_deactivate, \
- ClassName::_process, \
- ClassName::_get_state, \
- ClassName::_set_state, \
- ClassName::_dispatcher
-
- #endif // CARLA_NATIVE_HPP_INCLUDED
|