diff --git a/source/modules/native-plugins/Makefile b/source/modules/native-plugins/Makefile index 7f512f88e..c8620c33b 100644 --- a/source/modules/native-plugins/Makefile +++ b/source/modules/native-plugins/Makefile @@ -119,6 +119,11 @@ OBJS += \ distrho-zamulticomp.cpp.o \ distrho-zamulticompx2.cpp.o +ifeq ($(HAVE_PM_DEPS),true) +OBJS += \ + distrho-prom.cpp.o +endif + ifeq ($(HAVE_JUCE),true) # -------------------------------------------------------------- # JUCE based plugins @@ -144,13 +149,6 @@ ifeq ($(HAVE_MF_DEPS),true) OBJS += midi-file.cpp.o endif -# -------------------------------------------------------------- -# ProjectM - -ifeq ($(HAVE_PM_DEPS),true) -OBJS += projectm.cpp.o -endif - # -------------------------------------------------------------- # ZynAddSubFX @@ -261,6 +259,9 @@ distrho-nekobi.cpp.o: distrho-nekobi.cpp nekobi/*.cpp nekobi/*.h nekobi/*.hpp ne distrho-pingpongpan.cpp.o: distrho-pingpongpan.cpp pingpongpan/*.cpp pingpongpan/*.h pingpongpan/*.hpp ../distrho/* $(CXXDEPS) $(CXX) $< $(BUILD_CXX_FLAGS) -I../dgl -Ipingpongpan -DDISTRHO_NAMESPACE=DISTRHO_PingPongPan -c -o $@ +distrho-prom.cpp.o: distrho-prom.cpp prom/*.cpp prom/*.h prom/*.hpp ../distrho/* $(CXXDEPS) + $(CXX) $< $(PM_CXX_FLAGS) -I../dgl -Iprom -DDISTRHO_NAMESPACE=DISTRHO_ProM -c -o $@ + distrho-stereoenhancer.cpp.o: distrho-stereoenhancer.cpp stereoenhancer/*.cpp stereoenhancer/*.h stereoenhancer/*.hpp ../distrho/* $(CXXDEPS) $(CXX) $< $(BUILD_CXX_FLAGS) -I../dgl -Istereoenhancer -DDISTRHO_NAMESPACE=DISTRHO_StereoEnhancer -c -o $@ @@ -309,9 +310,6 @@ midi-file.cpp.o: midi-file.cpp midi-base.hpp $(CXXDEPS) midi-sequencer.cpp.o: midi-sequencer.cpp midi-base.hpp $(CXXDEPS) $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ -projectm.cpp.o: projectm.cpp $(CXXDEPS) - $(CXX) $< $(PM_CXX_FLAGS) -c -o $@ - notes.cpp.o: notes.cpp $(CXXDEPS) ../CarlaNativeExtUI.hpp $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ diff --git a/source/modules/native-plugins/_all.c b/source/modules/native-plugins/_all.c index 8ec115e11..69a50979e 100644 --- a/source/modules/native-plugins/_all.c +++ b/source/modules/native-plugins/_all.c @@ -75,7 +75,7 @@ extern void carla_register_native_plugin_midifile(); #ifdef WANT_PROJECTM // ProjectM -extern void carla_register_native_plugin_projectm(); +extern void carla_register_native_plugin_prom(); #endif // SunVox File @@ -147,7 +147,7 @@ void carla_register_all_plugins() #ifdef WANT_PROJECTM // ProjectM - carla_register_native_plugin_projectm(); + carla_register_native_plugin_prom(); #endif // SunVox File diff --git a/source/modules/native-plugins/distrho-prom.cpp b/source/modules/native-plugins/distrho-prom.cpp new file mode 100644 index 000000000..4c2b7cb81 --- /dev/null +++ b/source/modules/native-plugins/distrho-prom.cpp @@ -0,0 +1,59 @@ +/* + * Carla Native Plugins + * Copyright (C) 2012-2014 Filipe Coelho + * + * 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. + */ + +// Plugin Code +#include "prom/DistrhoPluginProM.cpp" +#include "prom/DistrhoUIProM.cpp" + +// DISTRHO Code +#define DISTRHO_PLUGIN_TARGET_CARLA +#include "DistrhoPluginMain.cpp" +#include "DistrhoUIMain.cpp" + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------- + +static const NativePluginDescriptor promDesc = { + /* category */ PLUGIN_CATEGORY_OTHER, + /* hints */ static_cast(PLUGIN_HAS_UI|PLUGIN_USES_PARENT_ID), + /* supports */ static_cast(0x0), + /* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS, + /* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS, + /* midiIns */ 0, + /* midiOuts */ 0, + /* paramIns */ 0, + /* paramOuts */ 0, + /* name */ DISTRHO_PLUGIN_NAME, + /* label */ "prom", + /* maker */ "falkTX", + /* copyright */ "LGPL", + PluginDescriptorFILL(PluginCarla) +}; + +END_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------- + +CARLA_EXPORT +void carla_register_native_plugin_prom() +{ + USE_NAMESPACE_DISTRHO + carla_register_native_plugin(&promDesc); +} + +// ----------------------------------------------------------------------- diff --git a/source/modules/native-plugins/distrho-zamulticompx2.cpp b/source/modules/native-plugins/distrho-zamulticompx2.cpp index d611663fa..4b2afa2cc 100644 --- a/source/modules/native-plugins/distrho-zamulticompx2.cpp +++ b/source/modules/native-plugins/distrho-zamulticompx2.cpp @@ -25,9 +25,6 @@ #include "DistrhoPluginMain.cpp" #include "DistrhoUIMain.cpp" -// FIXME -#include "ImageToggle.cpp" - START_NAMESPACE_DISTRHO // ----------------------------------------------------------------------- diff --git a/source/modules/native-plugins/projectm.cpp b/source/modules/native-plugins/projectm.cpp deleted file mode 100644 index b39df90b0..000000000 --- a/source/modules/native-plugins/projectm.cpp +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Carla Native Plugins - * Copyright (C) 2012-2014 Filipe Coelho - * - * 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. - */ - -#include "CarlaNative.hpp" -#include "CarlaMutex.hpp" - -#include "dgl/StandaloneWindow.hpp" -#include "dgl/Widget.hpp" - -#include "libprojectM/projectM.hpp" - -// ----------------------------------------------------------------------- - -static const projectM::Settings kSettings = { - /* meshX */ 32, - /* meshY */ 24, - /* fps */ 35, - /* textureSize */ 1024, - /* windowWidth */ 512, - /* windowHeight */ 512, - /* presetURL */ "/usr/share/projectM/presets", - /* titleFontURL */ "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", - /* menuFontURL */ "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf", - /* smoothPresetDuration */ 5, - /* presetDuration */ 30, - /* beatSensitivity */ 10.0f, - /* aspectCorrection */ true, - /* easterEgg */ 1.0f, - /* shuffleEnabled */ true, - /* softCutRatingsEnabled */ false -}; - -// ----------------------------------------------------------------------- - -class ProjectMWidget : public DGL::Widget -{ -public: - ProjectMWidget(DGL::Window& parent) - : DGL::Widget(parent), - pm(nullptr) - { - } - - ~ProjectMWidget() - { - if (pm == nullptr) - return; - - delete pm; - pm = nullptr; - } - - projectM* getPM() noexcept - { - return pm; - } - -protected: - void onDisplay() override - { - if (pm == nullptr) - return; - - pm->renderFrame(); - } - - void onClose() override - { - } - - bool onKeyboard(const bool press, const uint32_t key) override - { - if (pm == nullptr) - return false; - - projectMKeycode pmKey = PROJECTM_K_NONE; - projectMModifier pmMod = PROJECTM_KMOD_LSHIFT; - - if ((key >= PROJECTM_K_0 && key <= PROJECTM_K_9) || - (key >= PROJECTM_K_A && key <= PROJECTM_K_Z) || - (key >= PROJECTM_K_a && key <= PROJECTM_K_z)) - { - pmKey = static_cast(key); - } - else - { - switch (key) - { - case DGL::CHAR_BACKSPACE: - pmKey = PROJECTM_K_BACKSPACE; - break; - case DGL::CHAR_ESCAPE: - pmKey = PROJECTM_K_ESCAPE; - break; - case DGL::CHAR_DELETE: - pmKey = PROJECTM_K_DELETE; - break; - } - } - - if (pmKey == PROJECTM_K_NONE) - return false; - - if (const int mod = getModifiers()) - { - if (mod & DGL::MODIFIER_CTRL) - pmMod = PROJECTM_KMOD_LCTRL; - } - - pm->key_handler(press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod); - - return true; - } - - bool onSpecial(const bool press, const DGL::Key key) override - { - if (pm == nullptr) - return false; - - projectMKeycode pmKey = PROJECTM_K_NONE; - projectMModifier pmMod = PROJECTM_KMOD_LSHIFT; - - switch (key) - { - case DGL::KEY_F1: - pmKey = PROJECTM_K_F1; - break; - case DGL::KEY_F2: - pmKey = PROJECTM_K_F2; - break; - case DGL::KEY_F3: - pmKey = PROJECTM_K_F3; - break; - case DGL::KEY_F4: - pmKey = PROJECTM_K_F4; - break; - case DGL::KEY_F5: - pmKey = PROJECTM_K_F5; - break; - case DGL::KEY_F6: - pmKey = PROJECTM_K_F6; - break; - case DGL::KEY_F7: - pmKey = PROJECTM_K_F7; - break; - case DGL::KEY_F8: - pmKey = PROJECTM_K_F8; - break; - case DGL::KEY_F9: - pmKey = PROJECTM_K_F9; - break; - case DGL::KEY_F10: - pmKey = PROJECTM_K_F10; - break; - case DGL::KEY_F11: - pmKey = PROJECTM_K_F11; - break; - case DGL::KEY_F12: - pmKey = PROJECTM_K_F12; - break; - case DGL::KEY_LEFT: - pmKey = PROJECTM_K_LEFT; - break; - case DGL::KEY_UP: - pmKey = PROJECTM_K_UP; - break; - case DGL::KEY_RIGHT: - pmKey = PROJECTM_K_RIGHT; - break; - case DGL::KEY_DOWN: - pmKey = PROJECTM_K_DOWN; - break; - case DGL::KEY_PAGE_UP: - pmKey = PROJECTM_K_PAGEUP; - break; - case DGL::KEY_PAGE_DOWN: - pmKey = PROJECTM_K_PAGEDOWN; - break; - case DGL::KEY_HOME: - pmKey = PROJECTM_K_HOME; - break; - case DGL::KEY_END: - pmKey = PROJECTM_K_END; - break; - case DGL::KEY_INSERT: - pmKey = PROJECTM_K_INSERT; - break; - case DGL::KEY_SHIFT: - pmKey = PROJECTM_K_LSHIFT; - break; - case DGL::KEY_CTRL: - pmKey = PROJECTM_K_LCTRL; - break; - case DGL::KEY_ALT: - case DGL::KEY_SUPER: - break; - } - - if (pmKey == PROJECTM_K_NONE) - return false; - - if (const int mod = getModifiers()) - { - if (mod & DGL::MODIFIER_CTRL) - pmMod = PROJECTM_KMOD_LCTRL; - } - - pm->key_handler(press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod); - - return true; - } - - void onReshape(const int width, const int height) override - { - /* Our shading model--Gouraud (smooth). */ - glShadeModel(GL_SMOOTH); - - /* Set the clear color. */ - glClearColor(0, 0, 0, 0); - /* Setup our viewport. */ - glViewport(0, 0, width, height); - - /* - * Change to the projection matrix and set - * our viewing volume. - */ - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - - //gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height); - //glOrtho(0, width, height, 0, 0.0f, 1.0f); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glDrawBuffer(GL_BACK); - glReadBuffer(GL_BACK); - glEnable(GL_BLEND); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_LINE_SMOOTH); - glEnable(GL_POINT_SMOOTH); - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT); - - glLineStipple(2, 0xAAAA); - - if (pm == nullptr) - pm = new projectM(kSettings); // std::string("/usr/share/projectM/config.inp")); - - pm->projectM_resetGL(width, height); - } - -private: - projectM* pm; - - CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ProjectMWidget) -}; - -// ----------------------------------------------------------------------- - -class ProjectMUI : public DGL::StandaloneWindow -{ -public: - ProjectMUI(const NativeHostDescriptor* const host) - : DGL::StandaloneWindow(), - fWidget(getWindow()) - { - fWindow.setSize(kSettings.windowWidth, kSettings.windowHeight); - fWindow.setTitle(host->uiName); - - if (host->uiParentId != 0) - fWindow.setTransientWinId(host->uiParentId); - - fWindow.show(); - } - - projectM* getPM() noexcept - { - return fWidget.getPM(); - } - - void idle() - { - fApp.idle(); - fWindow.repaint(); - } - - void focus() - { - fWindow.focus(); - } - -private: - ProjectMWidget fWidget; - - CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ProjectMUI) -}; - -// ----------------------------------------------------------------------- - -class ProjectMPlugin : public NativePluginClass -{ -public: - ProjectMPlugin(const NativeHostDescriptor* const host) - : NativePluginClass(host), - fPM(nullptr), - fUI(nullptr) - { - } - - ~ProjectMPlugin() override - { - CARLA_SAFE_ASSERT(fUI == nullptr); - } - -protected: - // ------------------------------------------------------------------- - // Plugin process calls - - void process(float** ins, float**, const uint32_t frames, const NativeMidiEvent* const, const uint32_t) override - { - const CarlaMutexLocker csm(fMutex); - - if (fPM == nullptr) - return; - - fPM->pcm()->addPCMfloat(ins[0] ,frames); - } - - // ------------------------------------------------------------------- - // Plugin UI calls - - void uiShow(const bool show) override - { - if (show) - { - if (fUI == nullptr) - fUI = new ProjectMUI(getHostHandle()); - - fUI->focus(); - } - else if (fUI != nullptr) - { - { - const CarlaMutexLocker csm(fMutex); - fPM = nullptr; - } - - delete fUI; - fUI = nullptr; - } - } - - void uiIdle() override - { - if (fUI == nullptr) - return; - - fUI->idle(); - - if (fPM != nullptr) - return; - - const CarlaMutexLocker csm(fMutex); - fPM = fUI->getPM(); - CARLA_SAFE_ASSERT(fPM != nullptr); - } - -private: - projectM* fPM; - ProjectMUI* fUI; - - // need to ensure pm is valid - CarlaMutex fMutex; - - PluginClassEND(ProjectMPlugin) - CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ProjectMPlugin) -}; - -// ----------------------------------------------------------------------- - -static const NativePluginDescriptor projectmDesc = { - /* category */ PLUGIN_CATEGORY_UTILITY, - /* hints */ static_cast(/*PLUGIN_IS_RTSAFE|*/PLUGIN_HAS_UI|PLUGIN_USES_PARENT_ID), - /* supports */ static_cast(0x0), - /* audioIns */ 1, - /* audioOuts */ 0, - /* midiIns */ 0, - /* midiOuts */ 0, - /* paramIns */ 0, - /* paramOuts */ 0, - /* name */ "ProjectM", - /* label */ "projectm", - /* maker */ "falkTX", - /* copyright */ "GNU GPL v2+", - PluginDescriptorFILL(ProjectMPlugin) -}; - -// ----------------------------------------------------------------------- - -CARLA_EXPORT -void carla_register_native_plugin_projectm() -{ - carla_register_native_plugin(&projectmDesc); -} - -// ----------------------------------------------------------------------- diff --git a/source/modules/native-plugins/prom/DistrhoPluginInfo.h b/source/modules/native-plugins/prom/DistrhoPluginInfo.h new file mode 100644 index 000000000..57cda7fb9 --- /dev/null +++ b/source/modules/native-plugins/prom/DistrhoPluginInfo.h @@ -0,0 +1,38 @@ +/* + * DISTRHO ProM Plugin + * Copyright (C) 2014 Filipe Coelho + * + * This program 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. + * + * 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 Lesser General Public License for more details. + * + * For a full copy of the license see the LICENSE file. + */ + +#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED +#define DISTRHO_PLUGIN_INFO_H_INCLUDED + +#define DISTRHO_PLUGIN_NAME "ProM" + +#define DISTRHO_PLUGIN_HAS_UI 1 +#define DISTRHO_PLUGIN_IS_SYNTH 0 + +#define DISTRHO_PLUGIN_NUM_INPUTS 1 +#define DISTRHO_PLUGIN_NUM_OUTPUTS 1 + +#define DISTRHO_PLUGIN_WANT_LATENCY 0 +#define DISTRHO_PLUGIN_WANT_PROGRAMS 0 +#define DISTRHO_PLUGIN_WANT_STATE 0 +#define DISTRHO_PLUGIN_WANT_TIMEPOS 0 + +#define DISTRHO_PLUGIN_IS_RT_SAFE 0 +#define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 1 + +#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/ProM" + +#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED diff --git a/source/modules/native-plugins/prom/DistrhoPluginProM.cpp b/source/modules/native-plugins/prom/DistrhoPluginProM.cpp new file mode 100644 index 000000000..68cf70025 --- /dev/null +++ b/source/modules/native-plugins/prom/DistrhoPluginProM.cpp @@ -0,0 +1,84 @@ +/* + * DISTRHO ProM Plugin + * Copyright (C) 2014 Filipe Coelho + * + * This program 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. + * + * 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 Lesser General Public License for more details. + * + * For a full copy of the license see the LICENSE file. + */ + +#include "DistrhoPluginProM.hpp" + +#include "libprojectM/projectM.hpp" + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------- + +DistrhoPluginProM::DistrhoPluginProM() + : Plugin(0, 0, 0), + fPM(nullptr) +{ +} + +DistrhoPluginProM::~DistrhoPluginProM() +{ + DISTRHO_SAFE_ASSERT(fPM == nullptr); +} + +// ----------------------------------------------------------------------- +// Init + +void DistrhoPluginProM::d_initParameter(uint32_t, Parameter&) +{ +} + +// ----------------------------------------------------------------------- +// Internal data + +float DistrhoPluginProM::d_getParameterValue(uint32_t) const +{ + return 0.0f; +} + +void DistrhoPluginProM::d_setParameterValue(uint32_t, float) +{ +} + +// ----------------------------------------------------------------------- +// Process + +void DistrhoPluginProM::d_run(const float** inputs, float** outputs, uint32_t frames) +{ + const float* in = inputs[0]; + float* out = outputs[0]; + + if (in != out) + std::memcpy(out, in, sizeof(float)*frames); + + const MutexLocker csm(fMutex); + + if (fPM == nullptr) + return; + + if (PCM* const pcm = fPM->pcm()) + pcm->addPCMfloat(in, frames); +} + +// ----------------------------------------------------------------------- + +Plugin* createPlugin() +{ + return new DistrhoPluginProM(); +} + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO diff --git a/source/modules/native-plugins/prom/DistrhoPluginProM.hpp b/source/modules/native-plugins/prom/DistrhoPluginProM.hpp new file mode 100644 index 000000000..d3ae1daee --- /dev/null +++ b/source/modules/native-plugins/prom/DistrhoPluginProM.hpp @@ -0,0 +1,96 @@ +/* + * DISTRHO ProM Plugin + * Copyright (C) 2014 Filipe Coelho + * + * This program 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. + * + * 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 Lesser General Public License for more details. + * + * For a full copy of the license see the LICENSE file. + */ + +#ifndef DISTRHO_PLUGIN_3BANDEQ_HPP_INCLUDED +#define DISTRHO_PLUGIN_3BANDEQ_HPP_INCLUDED + +#include "DistrhoPlugin.hpp" + +#include "extra/d_mutex.hpp" + +class projectM; +class DistrhoUIProM; + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------- + +class DistrhoPluginProM : public Plugin +{ +public: + DistrhoPluginProM(); + ~DistrhoPluginProM() override; + +protected: + // ------------------------------------------------------------------- + // Information + + const char* d_getLabel() const noexcept override + { + return "ProM"; + } + + const char* d_getMaker() const noexcept override + { + return "DISTRHO"; + } + + const char* d_getLicense() const noexcept override + { + return "LGPL"; + } + + uint32_t d_getVersion() const noexcept override + { + return 0x1000; + } + + long d_getUniqueId() const noexcept override + { + return d_cconst('D', 'P', 'r', 'M'); + } + + // ------------------------------------------------------------------- + // Init + + void d_initParameter(uint32_t, Parameter&) override; + + // ------------------------------------------------------------------- + // Internal data + + float d_getParameterValue(uint32_t) const override; + void d_setParameterValue(uint32_t, float) override; + + // ------------------------------------------------------------------- + // Process + + void d_run(const float** inputs, float** outputs, uint32_t frames) override; + + // ------------------------------------------------------------------- + +private: + Mutex fMutex; + projectM* fPM; + friend class DistrhoUIProM; + + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoPluginProM) +}; + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO + +#endif // DISTRHO_PLUGIN_3BANDEQ_HPP_INCLUDED diff --git a/source/modules/native-plugins/prom/DistrhoUIProM.cpp b/source/modules/native-plugins/prom/DistrhoUIProM.cpp new file mode 100644 index 000000000..cfffaea35 --- /dev/null +++ b/source/modules/native-plugins/prom/DistrhoUIProM.cpp @@ -0,0 +1,276 @@ +/* + * DISTRHO ProM Plugin + * Copyright (C) 2014 Filipe Coelho + * + * This program 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. + * + * 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 Lesser General Public License for more details. + * + * For a full copy of the license see the LICENSE file. + */ + +#include "DistrhoPluginProM.hpp" +#include "DistrhoUIProM.hpp" + +#include "libprojectM/projectM.hpp" + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------- + +static const projectM::Settings kSettings = { + /* meshX */ 32, + /* meshY */ 24, + /* fps */ 35, + /* textureSize */ 1024, + /* windowWidth */ 512, + /* windowHeight */ 512, + /* presetURL */ "/usr/share/projectM/presets", + /* titleFontURL */ "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", + /* menuFontURL */ "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf", + /* smoothPresetDuration */ 5, + /* presetDuration */ 30, + /* beatSensitivity */ 10.0f, + /* aspectCorrection */ true, + /* easterEgg */ 1.0f, + /* shuffleEnabled */ true, + /* softCutRatingsEnabled */ false +}; + +// ----------------------------------------------------------------------- + +DistrhoUIProM::DistrhoUIProM() + : UI() +{ +} + +DistrhoUIProM::~DistrhoUIProM() +{ + if (DistrhoPluginProM* const dspPtr = (DistrhoPluginProM*)d_getPluginInstancePointer()) + { + const MutexLocker csm(dspPtr->fMutex); + dspPtr->fPM = nullptr; + } +} + +// ----------------------------------------------------------------------- +// DSP Callbacks + +void DistrhoUIProM::d_parameterChanged(uint32_t, float) +{ +} + +// ----------------------------------------------------------------------- +// UI Callbacks + +void DistrhoUIProM::d_uiIdle() +{ + if (fPM == nullptr) + return; + + repaint(); + + if (DistrhoPluginProM* const dspPtr = (DistrhoPluginProM*)d_getPluginInstancePointer()) + { + if (dspPtr->fPM != nullptr) + return; + + const MutexLocker csm(dspPtr->fMutex); + dspPtr->fPM = fPM; + } +} + +void DistrhoUIProM::d_uiReshape(int width, int height) +{ + glEnable(GL_BLEND); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_POINT_SMOOTH); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glShadeModel(GL_SMOOTH); + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, height, 0, 0.0f, 1.0f); + glViewport(0, 0, width, height); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glDrawBuffer(GL_BACK); + glReadBuffer(GL_BACK); + + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glLineStipple(2, 0xAAAA); + + if (fPM == nullptr) + fPM = new projectM(kSettings); // std::string("/usr/share/projectM/config.inp")); + + fPM->projectM_resetGL(width, height); +} + +// ----------------------------------------------------------------------- +// Widget Callbacks + +void DistrhoUIProM::onDisplay() +{ + if (fPM == nullptr) + return; + + fPM->renderFrame(); +} + +bool DistrhoUIProM::onKeyboard(const KeyboardEvent& ev) +{ + if (fPM == nullptr) + return false; + + projectMKeycode pmKey = PROJECTM_K_NONE; + projectMModifier pmMod = PROJECTM_KMOD_LSHIFT; + + if ((ev.key >= PROJECTM_K_0 && ev.key <= PROJECTM_K_9) || + (ev.key >= PROJECTM_K_A && ev.key <= PROJECTM_K_Z) || + (ev.key >= PROJECTM_K_a && ev.key <= PROJECTM_K_z)) + { + pmKey = static_cast(ev.key); + } + else + { + switch (ev.key) + { + case DGL::CHAR_BACKSPACE: + pmKey = PROJECTM_K_BACKSPACE; + break; + case DGL::CHAR_ESCAPE: + pmKey = PROJECTM_K_ESCAPE; + break; + case DGL::CHAR_DELETE: + pmKey = PROJECTM_K_DELETE; + break; + } + } + + if (pmKey == PROJECTM_K_NONE) + return false; + + if (ev.mod & DGL::MODIFIER_CTRL) + pmMod = PROJECTM_KMOD_LCTRL; + + fPM->key_handler(ev.press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod); + + return true; +} + +bool DistrhoUIProM::onSpecial(const SpecialEvent& ev) +{ + if (fPM == nullptr) + return false; + + projectMKeycode pmKey = PROJECTM_K_NONE; + projectMModifier pmMod = PROJECTM_KMOD_LSHIFT; + + switch (ev.key) + { + case DGL::KEY_F1: + pmKey = PROJECTM_K_F1; + break; + case DGL::KEY_F2: + pmKey = PROJECTM_K_F2; + break; + case DGL::KEY_F3: + pmKey = PROJECTM_K_F3; + break; + case DGL::KEY_F4: + pmKey = PROJECTM_K_F4; + break; + case DGL::KEY_F5: + pmKey = PROJECTM_K_F5; + break; + case DGL::KEY_F6: + pmKey = PROJECTM_K_F6; + break; + case DGL::KEY_F7: + pmKey = PROJECTM_K_F7; + break; + case DGL::KEY_F8: + pmKey = PROJECTM_K_F8; + break; + case DGL::KEY_F9: + pmKey = PROJECTM_K_F9; + break; + case DGL::KEY_F10: + pmKey = PROJECTM_K_F10; + break; + case DGL::KEY_F11: + pmKey = PROJECTM_K_F11; + break; + case DGL::KEY_F12: + pmKey = PROJECTM_K_F12; + break; + case DGL::KEY_LEFT: + pmKey = PROJECTM_K_LEFT; + break; + case DGL::KEY_UP: + pmKey = PROJECTM_K_UP; + break; + case DGL::KEY_RIGHT: + pmKey = PROJECTM_K_RIGHT; + break; + case DGL::KEY_DOWN: + pmKey = PROJECTM_K_DOWN; + break; + case DGL::KEY_PAGE_UP: + pmKey = PROJECTM_K_PAGEUP; + break; + case DGL::KEY_PAGE_DOWN: + pmKey = PROJECTM_K_PAGEDOWN; + break; + case DGL::KEY_HOME: + pmKey = PROJECTM_K_HOME; + break; + case DGL::KEY_END: + pmKey = PROJECTM_K_END; + break; + case DGL::KEY_INSERT: + pmKey = PROJECTM_K_INSERT; + break; + case DGL::KEY_SHIFT: + pmKey = PROJECTM_K_LSHIFT; + break; + case DGL::KEY_CTRL: + pmKey = PROJECTM_K_LCTRL; + break; + case DGL::KEY_ALT: + case DGL::KEY_SUPER: + break; + } + + if (pmKey == PROJECTM_K_NONE) + return false; + + if (ev.mod & DGL::MODIFIER_CTRL) + pmMod = PROJECTM_KMOD_LCTRL; + + fPM->key_handler(ev.press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod); + + return true; +} + +// ----------------------------------------------------------------------- + +UI* createUI() +{ + return new DistrhoUIProM(); +} + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO diff --git a/source/modules/native-plugins/prom/DistrhoUIProM.hpp b/source/modules/native-plugins/prom/DistrhoUIProM.hpp new file mode 100644 index 000000000..4b907d5f6 --- /dev/null +++ b/source/modules/native-plugins/prom/DistrhoUIProM.hpp @@ -0,0 +1,76 @@ +/* + * DISTRHO ProM Plugin + * Copyright (C) 2014 Filipe Coelho + * + * This program 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. + * + * 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 Lesser General Public License for more details. + * + * For a full copy of the license see the LICENSE file. + */ + +#ifndef DISTRHO_UI_3BANDEQ_HPP_INCLUDED +#define DISTRHO_UI_3BANDEQ_HPP_INCLUDED + +#include "DistrhoUI.hpp" + +class projectM; + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------- + +class DistrhoUIProM : public UI +{ +public: + DistrhoUIProM(); + ~DistrhoUIProM() override; + +protected: + // ------------------------------------------------------------------- + // Information + + uint d_getWidth() const noexcept override + { + return 512; + } + + uint d_getHeight() const noexcept override + { + return 512; + } + + // ------------------------------------------------------------------- + // DSP Callbacks + + void d_parameterChanged(uint32_t, float) override; + + // ------------------------------------------------------------------- + // UI Callbacks + + void d_uiIdle() override; + void d_uiReshape(int width, int height) override; + + // ------------------------------------------------------------------- + // Widget Callbacks + + void onDisplay() override; + bool onKeyboard(const KeyboardEvent&) override; + bool onSpecial(const SpecialEvent&) override; + +private: + ScopedPointer fPM; + + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoUIProM) +}; + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO + +#endif // DISTRHO_UI_3BANDEQ_HPP_INCLUDED