From 0e6d94e02e754a6448e90fa139221f1f660d8a0d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 13 Mar 2016 17:36:07 +0100 Subject: Initial version of DG plugin with plugingizmo wrapper code. So far only for LV2. --- plugin/Makefile.am | 37 ++++++ plugin/drumgizmo.ttl | 171 +++++++++++++++++++++++++ plugin/drumgizmo_plugin.cc | 305 +++++++++++++++++++++++++++++++++++++++++++++ plugin/drumgizmo_plugin.h | 160 ++++++++++++++++++++++++ plugin/manifest.ttl | 7 ++ 5 files changed, 680 insertions(+) create mode 100644 plugin/Makefile.am create mode 100644 plugin/drumgizmo.ttl create mode 100644 plugin/drumgizmo_plugin.cc create mode 100644 plugin/drumgizmo_plugin.h create mode 100644 plugin/manifest.ttl (limited to 'plugin') diff --git a/plugin/Makefile.am b/plugin/Makefile.am new file mode 100644 index 0000000..21cd9eb --- /dev/null +++ b/plugin/Makefile.am @@ -0,0 +1,37 @@ +include $(top_srcdir)/plugingui/Makefile.am.plugingui +include $(top_srcdir)/src/Makefile.am.drumgizmo + +plugindir = $(libdir)/lv2/drumgizmo.lv2 + +if ENABLE_LV2 +plugin_LTLIBRARIES = drumgizmo.la +endif + +plugin_DATA = manifest.ttl drumgizmo.ttl + +EXTRA_DIST = \ + $(plugin_DATA) \ + input_lv2.h \ + output_lv2.h \ + lv2_event.h \ + lv2_gui.h \ + lv2_instance.h + +drumgizmo_la_CXXFLAGS = -I$(top_srcdir)/plugin/plugingizmo -I$(top_srcdir)/src \ + -I$(top_srcdir)/plugingui \ + -DLV2 -DX11 -DLV2_PLUGIN_URI=\"http://drumgizmo.org/lv2\" \ + -I$(top_srcdir)/include $(SNDFILE_CXXFLAGS) \ + $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) $(LV2_CFLAGS) \ + $(PLUGIN_GUI_CFLAGS) $(SSEFLAGS) $(ZITA_CPPFLAGS) \ + -DUSE_THREAD $(SAMPLERATE_CFLAGS) + +drumgizmo_la_SOURCES = \ + $(DRUMGIZMO_SOURCES) \ + $(PLUGIN_GUI_SOURCES) \ + $(top_srcdir)/plugin/plugingizmo/midievent.cc \ + $(top_srcdir)/plugin/plugingizmo/pluginlv2.cc \ + drumgizmo_plugin.cc + +drumgizmo_la_LDFLAGS = -module -avoid-version +drumgizmo_la_LIBADD = $(LV2_LIBS) $(PLUGIN_GUI_LIBS) $(DRUMGIZMO_LIBS) + diff --git a/plugin/drumgizmo.ttl b/plugin/drumgizmo.ttl new file mode 100644 index 0000000..b94b09b --- /dev/null +++ b/plugin/drumgizmo.ttl @@ -0,0 +1,171 @@ +# LV2 DrumGizmo Plugin +# Copyright 2011 Bent Bisballe Nyeng +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +@prefix doap: . +@prefix foaf: . +@prefix lv2: . +@prefix atom: . +@prefix ui: . +@prefix state: . +@prefix pprops: . +@prefix lv2: . +@prefix rdfs: . + + + a ui:X11UI ; + lv2:requiredFeature ui:resize ; + lv2:extensionData ui:resize ; + lv2:requiredFeature ui:idleInterface ; + lv2:extensionData ui:idleInterface ; + ui:binary . + + + a lv2:InstrumentPlugin ; + doap:name "DrumGizmo" ; + doap:maintainer [ + foaf:name "DrumGizmo.org" ; + foaf:homepage ; + ] ; + doap:license ; + ui:ui ; + doap:license ; + lv2:optionalFeature ; + lv2:optionalFeature ; + lv2:extensionData state:interface ; + lv2:port [ + a lv2:InputPort, lv2:ControlPort ; + lv2:index 0 ; + lv2:symbol "lv2_freewheel" ; + lv2:name "Freewheel" ; + lv2:default 0.0 ; + lv2:minimum 0.0 ; + lv2:maximum 1.0 ; + lv2:designation ; + lv2:portProperty lv2:toggled ; + lv2:portProperty pprops:hasStrictBounds; + ] , [ + a lv2:OutputPort, lv2:ControlPort ; + lv2:designation ; + lv2:index 1; + lv2:symbol "latency"; + lv2:name "Latency"; + lv2:minimum 0; + lv2:maximum 192000; + lv2:portProperty lv2:reportsLatency, lv2:integer; + ] , [ + a atom:AtomPort , + lv2:InputPort; + atom:bufferType atom:Sequence ; + atom:supports ; + lv2:index 2 ; + lv2:symbol "control" ; + lv2:name "Control" + ] , [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 3 ; + lv2:symbol "out1" ; + lv2:name "Out1" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 4 ; + lv2:symbol "out2" ; + lv2:name "Out2" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 5 ; + lv2:symbol "out3" ; + lv2:name "Out3" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 6 ; + lv2:symbol "out4" ; + lv2:name "Out4" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 7 ; + lv2:symbol "out5" ; + lv2:name "Out5" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 8 ; + lv2:symbol "out6" ; + lv2:name "Out6" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 9 ; + lv2:symbol "out7" ; + lv2:name "Out7" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 10 ; + lv2:symbol "out8" ; + lv2:name "Out8" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 11 ; + lv2:symbol "out9" ; + lv2:name "Out9" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 12 ; + lv2:symbol "out10" ; + lv2:name "Out10" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 13 ; + lv2:symbol "out11" ; + lv2:name "Out11" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 14 ; + lv2:symbol "out12" ; + lv2:name "Out12" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 15 ; + lv2:symbol "out13" ; + lv2:name "Out13" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 16 ; + lv2:symbol "out14" ; + lv2:name "Out14" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 17 ; + lv2:symbol "out15" ; + lv2:name "Out15" + ], [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 18 ; + lv2:symbol "out16" ; + lv2:name "Out16" + ] . diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc new file mode 100644 index 0000000..471bacb --- /dev/null +++ b/plugin/drumgizmo_plugin.cc @@ -0,0 +1,305 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * drumgizmo_lv2.cc + * + * Wed Mar 2 17:31:32 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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 + * (at your option) any later version. + * + * DrumGizmo 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. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "drumgizmo_plugin.h" + +#include +#include +#include +#include +#include + +#include + +#include + +#ifdef LV2 +// Entry point for lv2 plugin instantiation. +PluginLV2* createEffectInstance() +{ + return new DrumGizmoPlugin(); +} +#endif + +#ifdef VST +// Entry point for vst plugin instantiation. +AudioEffect* createEffectInstance(audioMasterCallback audioMaster) +{ + return new DrumGizmoPlugin(audioMaster); +} + +DrumGizmoPlugin::DrumGizmoPlugin(audioMasterCallback audioMaster) + : PluginVST(audioMaster) +#else +DrumGizmoPlugin::DrumGizmoPlugin() +#endif +{ + drumgizmo = std::make_shared(&output, &input); + resizeWindow(370, 330); + drumgizmo->setFreeWheel(true); + drumgizmo->setSamplerate(44100); + drumgizmo->setFrameSize(2048); +} + +void DrumGizmoPlugin::onFreeWheelChange(bool freewheel) +{ + drumgizmo->setFreeWheel(freewheel); +} + +void DrumGizmoPlugin::onSamplerateChange(float samplerate) +{ + drumgizmo->setSamplerate(samplerate); +} + +void DrumGizmoPlugin::onFramesizeChange(size_t framesize) +{ + drumgizmo->setFrameSize(framesize); +} + +void DrumGizmoPlugin::onActiveChange(bool active) +{ +} + +std::string DrumGizmoPlugin::onStateSave() +{ + return drumgizmo->configString(); +} + +void DrumGizmoPlugin::onStateRestore(const std::string& config) +{ + drumgizmo->setConfigString(config); +} + +size_t DrumGizmoPlugin::getNumberOfMidiInputs() +{ + return 1; +} + +size_t DrumGizmoPlugin::getNumberOfMidiOutputs() +{ + return 0; +} + +size_t DrumGizmoPlugin::getNumberOfAudioInputs() +{ + return 0; +} + +size_t DrumGizmoPlugin::getNumberOfAudioOutputs() +{ + return 16; +} + +std::string DrumGizmoPlugin::getId() +{ + return "DrumGizmo"; +} +static float g_samples[16* 4096]; +void DrumGizmoPlugin::process(size_t pos, + const std::vector& input_events, + std::vector& output_events, + const std::vector& input_samples, + const std::vector& output_samples, + size_t count) +{ + this->input_events = &input_events; + this->output_samples = &output_samples; + + drumgizmo->run(pos, g_samples, count); + + this->input_events = nullptr; + this->output_samples = nullptr; +} + +bool DrumGizmoPlugin::hasGUI() +{ + return true; +} + +void DrumGizmoPlugin::createWindow(void *parent) +{ + plugin_gui = std::make_shared(parent); + resizeWindow(370, 330); + onShowWindow(); +} + +void DrumGizmoPlugin::onDestroyWindow() +{ + plugin_gui = nullptr; +} + +void DrumGizmoPlugin::onShowWindow() +{ + plugin_gui->show(); +} + +void DrumGizmoPlugin::onHideWindow() +{ + plugin_gui->hide(); +} + +void DrumGizmoPlugin::onIdle() +{ + plugin_gui->processEvents(); +} + +void DrumGizmoPlugin::resizeWindow(size_t width, size_t height) +{ +} + +void DrumGizmoPlugin::closeWindow() +{ +} + + +// +// Input Engine +// + +DrumGizmoPlugin::Input::Input(DrumGizmoPlugin& plugin) + : plugin(plugin) +{ +} + +bool DrumGizmoPlugin::Input::init(Instruments &instruments) +{ + this->instruments = &instruments; + return true; +} + +void DrumGizmoPlugin::Input::setParm(std::string parm, std::string value) +{ +} + +bool DrumGizmoPlugin::Input::start() +{ + return true; +} + +void DrumGizmoPlugin::Input::stop() +{ +} + +void DrumGizmoPlugin::Input::pre() +{ +} + +event_t *DrumGizmoPlugin::Input::run(size_t pos, size_t len, size_t* nevents) +{ + + assert(plugin.input_events); + + event_t* list; + size_t listsize; + + list = (event_t*)malloc(sizeof(event_t) * plugin.input_events->size()); + listsize = 0; + + for(auto& event : *plugin.input_events) + { + if(event.type != MidiEventType::NoteOn) + { + continue; + } + + int i = mmap.lookup(event.key); + if(event.velocity && (i != -1)) + { + list[listsize].type = TYPE_ONSET; + list[listsize].instrument = i; + list[listsize].velocity = (float)event.velocity / 127.0f; + list[listsize].offset = event.getTime(); + ++listsize; + } + } + + *nevents = listsize; + return list; +} + +void DrumGizmoPlugin::Input::post() +{ +} + + +// +// Output Engine +// + +DrumGizmoPlugin::Output::Output(DrumGizmoPlugin& plugin) + : plugin(plugin) +{ +} + +bool DrumGizmoPlugin::Output::init(Channels channels) +{ + return true; +} + +void DrumGizmoPlugin::Output::setParm(std::string parm, std::string value) +{ +} + +bool DrumGizmoPlugin::Output::start() +{ + return true; +} + +void DrumGizmoPlugin::Output::stop() +{ +} + +void DrumGizmoPlugin::Output::pre(size_t nsamples) +{ +} + +void DrumGizmoPlugin::Output::run(int ch, sample_t *samples, size_t nsamples) +{ +// assert(false); +} + +void DrumGizmoPlugin::Output::post(size_t nsamples) +{ +} + +sample_t* DrumGizmoPlugin::Output::getBuffer(int ch) +{ + assert(plugin.output_samples); + + if((std::size_t)ch >= plugin.output_samples->size()) + { + return nullptr; + } + + assert((*plugin.output_samples)[ch]); + + return (*plugin.output_samples)[ch]; +} + +size_t DrumGizmoPlugin::Output::getBufferSize() +{ + return plugin.getFramesize(); +} diff --git a/plugin/drumgizmo_plugin.h b/plugin/drumgizmo_plugin.h new file mode 100644 index 0000000..868263a --- /dev/null +++ b/plugin/drumgizmo_plugin.h @@ -0,0 +1,160 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * drumgizmo_lv2.h + * + * Wed Mar 2 17:31:31 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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 + * (at your option) any later version. + * + * DrumGizmo 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. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +#include + +#if defined(X11) +#include +#endif // defined(X11) + +#if defined(WIN32) +#define WIN32_LEAN_AND_MEAN +#include +#endif // defined(WIN32) + +#ifdef LV2 +#include +#endif + +#ifdef VST +#include +#endif + +#include +#include +#include +#include + +class DrumGizmoPlugin +#ifdef LV2 + : public PluginLV2 +#endif +#ifdef VST + : public PluginVST +#endif +{ +public: +#ifdef VST + DrumGizmoPlugin(audioMasterCallback audioMaster); +#else + DrumGizmoPlugin(); +#endif + + void onFreeWheelChange(bool freewheel) override; + + void onFramesizeChange(size_t framesize) override; + + void onSamplerateChange(float samplerate) override; + + void onActiveChange(bool active) override; + + std::string onStateSave() override; + void onStateRestore(const std::string& config) override; + + size_t getNumberOfMidiInputs() override; + size_t getNumberOfMidiOutputs() override; + size_t getNumberOfAudioInputs() override; + size_t getNumberOfAudioOutputs() override; + + std::string getId() override; + + void process(size_t pos, + const std::vector& input_events, + std::vector& output_events, + const std::vector& input_samples, + const std::vector& output_samples, + size_t count) override; + + // + // GUI + // + bool hasGUI() override; + void createWindow(void *parent) override; + void onDestroyWindow() override; + void onShowWindow() override; + void onHideWindow() override; + void onIdle() override; + void resizeWindow(size_t width, size_t height) override; + void closeWindow() override; + +private: + class Input + : public AudioInputEngineMidi + { + public: + Input(DrumGizmoPlugin& plugin); + + bool init(Instruments& instruments) override; + + void setParm(std::string parm, std::string value) override; + + bool start() override; + void stop() override; + + void pre() override; + event_t *run(size_t pos, size_t len, size_t* nevents) override; + void post() override; + + protected: + DrumGizmoPlugin& plugin; + Instruments* instruments{nullptr}; + }; + + class Output + : public AudioOutputEngine + { + public: + Output(DrumGizmoPlugin& plugin); + + bool init(Channels channels) override; + + void setParm(std::string parm, std::string value) override; + + bool start() override; + void stop() override; + + void pre(size_t nsamples) override; + void run(int ch, sample_t *samples, size_t nsamples) override; + void post(size_t nsamples) override; + + sample_t *getBuffer(int ch) override; + size_t getBufferSize() override; + + protected: + DrumGizmoPlugin& plugin; + }; + + Input input{*this}; + const std::vector* input_events{nullptr}; + + Output output{*this}; + const std::vector* output_samples{nullptr}; + + std::shared_ptr plugin_gui; + std::shared_ptr drumgizmo; +}; diff --git a/plugin/manifest.ttl b/plugin/manifest.ttl new file mode 100644 index 0000000..65a8953 --- /dev/null +++ b/plugin/manifest.ttl @@ -0,0 +1,7 @@ +@prefix lv2: . +@prefix rdfs: . + + + a lv2:Plugin ; + lv2:binary ; + rdfs:seeAlso . -- cgit v1.2.3