diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-03-13 17:36:07 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-03-13 17:36:07 +0100 |
commit | 0e6d94e02e754a6448e90fa139221f1f660d8a0d (patch) | |
tree | 4b879b518b75833c4e8c97266d49b7dcb70683d0 /plugin | |
parent | 948e2a04f446109c369e28580c6193027685d3e8 (diff) |
Initial version of DG plugin with plugingizmo wrapper code. So far only for LV2.
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/Makefile.am | 37 | ||||
-rw-r--r-- | plugin/drumgizmo.ttl | 171 | ||||
-rw-r--r-- | plugin/drumgizmo_plugin.cc | 305 | ||||
-rw-r--r-- | plugin/drumgizmo_plugin.h | 160 | ||||
-rw-r--r-- | plugin/manifest.ttl | 7 |
5 files changed, 680 insertions, 0 deletions
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 <deva@aasimon.org> +# +# 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: <http://usefulinc.com/ns/doap#> . +@prefix foaf: <http://xmlns.com/foaf/0.1/> . +@prefix lv2: <http://lv2plug.in/ns/lv2core#> . +@prefix atom: <http://lv2plug.in/ns/ext/atom#> . +@prefix ui: <http://lv2plug.in/ns/extensions/ui#> . +@prefix state: <http://lv2plug.in/ns/ext/state#> . +@prefix pprops: <http://lv2plug.in/ns/ext/port-props#> . +@prefix lv2: <http://lv2plug.in/ns/lv2core#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +<http://drumgizmo.org/lv2#ui> + a ui:X11UI ; + lv2:requiredFeature ui:resize ; + lv2:extensionData ui:resize ; + lv2:requiredFeature ui:idleInterface ; + lv2:extensionData ui:idleInterface ; + ui:binary <drumgizmo.so> . + +<http://drumgizmo.org/lv2> + a lv2:InstrumentPlugin ; + doap:name "DrumGizmo" ; + doap:maintainer [ + foaf:name "DrumGizmo.org" ; + foaf:homepage <http://www.drumgizmo.org> ; + ] ; + doap:license <http://usefulinc.com/doap/licenses/gpl> ; + ui:ui <http://drumgizmo.org/lv2#ui> ; + doap:license <http://opensource.org/licenses/gpl-3.0> ; + lv2:optionalFeature <http://lv2plug.in/ns/ext/uri-map> ; + lv2:optionalFeature <http://lv2plug.in/ns/ext/event> ; + 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 <http://lv2plug.in/ns/lv2core#freeWheeling> ; + lv2:portProperty lv2:toggled ; + lv2:portProperty pprops:hasStrictBounds; + ] , [ + a lv2:OutputPort, lv2:ControlPort ; + lv2:designation <http://lv2plug.in/ns/lv2core#latency>; + 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 <http://lv2plug.in/ns/ext/midi#MidiEvent> ; + 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 <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include <iostream> + +#include <midievent.h> + +#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<DrumGizmo>(&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<MidiEvent>& input_events, + std::vector<MidiEvent>& output_events, + const std::vector<const float*>& input_samples, + const std::vector<float*>& 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<GUI::PluginGUI>(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 <memory> + +#if defined(X11) +#include <X11/Xlib.h> +#endif // defined(X11) + +#if defined(WIN32) +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#endif // defined(WIN32) + +#ifdef LV2 +#include <pluginlv2.h> +#endif + +#ifdef VST +#include <pluginvst.h> +#endif + +#include <drumgizmo.h> +#include <audioinputenginemidi.h> +#include <audiooutputengine.h> +#include <plugingui.h> + +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<MidiEvent>& input_events, + std::vector<MidiEvent>& output_events, + const std::vector<const float*>& input_samples, + const std::vector<float*>& 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<MidiEvent>* input_events{nullptr}; + + Output output{*this}; + const std::vector<float*>* output_samples{nullptr}; + + std::shared_ptr<GUI::PluginGUI> plugin_gui; + std::shared_ptr<DrumGizmo> 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: <http://lv2plug.in/ns/lv2core#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +<http://drumgizmo.org/lv2> + a lv2:Plugin ; + lv2:binary <drumgizmo.so> ; + rdfs:seeAlso <drumgizmo.ttl> . |