diff options
Diffstat (limited to 'lvz')
-rw-r--r-- | lvz/audioeffectx.h | 48 | ||||
-rw-r--r-- | lvz/gendata.cpp | 126 | ||||
-rw-r--r-- | lvz/wrapper.cpp | 24 |
3 files changed, 174 insertions, 24 deletions
diff --git a/lvz/audioeffectx.h b/lvz/audioeffectx.h index f2f696b..07a6302 100644 --- a/lvz/audioeffectx.h +++ b/lvz/audioeffectx.h @@ -66,38 +66,48 @@ class AudioEffect { class AudioEffectX : public AudioEffect { public: AudioEffectX(audioMasterCallback audioMaster, int progs, int params) - : curProgram(0) + : uniqueID("NIL") + , URI("NIL") + , curProgram(0) , numPrograms(progs) , numInputs(0) , numOutputs(0) + , sampleRate(44100) { } - float getSampleRate() { return sampleRate; } - uint32_t getNumInputs() { return numInputs; } - uint32_t getNumOutputs() { return numOutputs; } - void setNumInputs(uint32_t num) { numInputs = num; } - void setNumOutputs(uint32_t num) { numOutputs = num;} - void setUniqueID(const char* id) {} - void setSampleRate(float rate) { sampleRate = rate; } + const char* getURI() { return URI; } + const char* getUniqueID() { return uniqueID; } + float getSampleRate() { return sampleRate; } + uint32_t getNumInputs() { return numInputs; } + uint32_t getNumOutputs() { return numOutputs; } + + virtual bool getProductString(char* text) = 0; + void canMono() {} - void wantEvents() {} void canProcessReplacing() {} void isSynth() {} - void suspend() {} + void process(float **inputs, float **outputs, uint32_t nframes) {} void setBlockSize(uint32_t blockSize) {} + void setNumInputs(uint32_t num) { numInputs = num; } + void setNumOutputs(uint32_t num) { numOutputs = num;} void setParameter(uint32_t index, float value) {} - - void process(float **inputs, float **outputs, uint32_t nframes) {} + void setSampleRate(float rate) { sampleRate = rate; } + void setUniqueID(const char* id) { uniqueID = id; } + void setURI(const char* uri) { URI = uri; } + void suspend() {} + void wantEvents() {} protected: - uint32_t curProgram; - uint32_t numPrograms; - uint32_t numInputs; - uint32_t numOutputs; - float sampleRate; - - AEffGUIEditor* editor; + const char* uniqueID; + const char* URI; + uint32_t curProgram; + uint32_t numPrograms; + uint32_t numInputs; + uint32_t numOutputs; + float sampleRate; + + AEffGUIEditor* editor; }; #endif // __lvz_audioeffectx_h diff --git a/lvz/gendata.cpp b/lvz/gendata.cpp new file mode 100644 index 0000000..f1337a1 --- /dev/null +++ b/lvz/gendata.cpp @@ -0,0 +1,126 @@ +/* LVZ - A C++ interface for writing LV2 plugins. + * Copyright (C) 2008 Dave Robillard <http://drobilla.net> + * + * This library 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. + * + * This library 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <iostream> +#include <fstream> +#include <dlfcn.h> +#include "audioeffectx.h" + +using namespace std; + +typedef AudioEffectX* (*new_effect_func)(); +typedef AudioEffectX* (*plugin_uri_func)(); + +// VST is so incredibly awful. Just.. wow. +#define MAX_NAME_LENGTH 1024 +char name[MAX_NAME_LENGTH]; + +#define NS_LV2CORE "http://lv2plug.in/ns/lv2core#" + +void +write_data(AudioEffectX* effect, const char* lib_file_name) +{ + string data_file_name = lib_file_name; + data_file_name = data_file_name.substr(0, data_file_name.find_last_of(".")); + data_file_name += ".ttl"; + + //ostream& os = cout; + fstream os(data_file_name.c_str(), ios::out); + effect->getProductString(name); + + os << "@prefix : <http://lv2plug.in/ns/lv2core#> ." << endl; + os << "@prefix doap: <http://usefulinc.com/ns/doap#> ." << endl << endl; + os << "<" << effect->getURI() << ">" << endl; + os << "\t:symbol \"" << effect->getUniqueID() << "\" ;" << endl; + os << "\tdoap:name \"" << name << "\""; + + if (effect->getNumInputs() + effect->getNumOutputs() == 0) + os << " ." << endl; + else + os << " ;" << endl; + + for (uint32_t i = 0; i < effect->getNumInputs(); ++i) { + if (i == 0) + os << "\t:port [" << endl; + + os << "\t\ta :InputPort, :AudioPort ;" << endl; + os << "\t\t:index" << " " << i << " ;" << endl; + + if (i == effect->getNumInputs() - 1) { + os << "\t] " << (effect->getNumOutputs() ? ";" : ".") << endl; + } else { + os << "\t] , [" << endl; + } + } + + for (uint32_t i = 0; i < effect->getNumOutputs(); ++i) { + if (i == 0) + os << "\t:port [" << endl; + + os << "\t\ta :OutputPort, :AudioPort ;" << endl; + os << "\t\t:index" << " " << effect->getNumInputs() + i << " ;" << endl; + + if (i == effect->getNumInputs() - 1) { + os << "\t] ." << endl; + } else { + os << "\t] , [" << endl; + } + } + + os.close(); + cout << "Wrote " << data_file_name << endl; +} + + +int +main(int argc, char** argv) +{ + if (argc == 0) { + cout << "Usage: gendata [PLUGINLIB1] [PLUGINLIB2]..." << endl; + cout << "Each argument is a path to a LVZ plugin library." << endl; + cout << "For each library an LV2 data file with the same name" << endl; + cout << "will be output containing the data for that plugin." << endl; + return 1; + } + + new_effect_func constructor = NULL; + AudioEffectX* effect = NULL; + + for (int i = 1; i < argc; ++i) { + void* handle = dlopen(argv[i], RTLD_NOW); + if (handle == NULL) { + cerr << "ERROR: " << argv[i] << " is not a shared library, ignoring" << endl; + continue; + } + + constructor = (new_effect_func)dlsym(handle, "lvz_new_audioeffectx"); + if (constructor == NULL) { + dlclose(handle); + cerr << "ERROR: " << argv[i] << " is not an LVZ plugin library, ignoring" << endl; + continue; + } + + effect = constructor(); + write_data(effect, argv[i]); + + dlclose(handle); + } + + return 0; +} + diff --git a/lvz/wrapper.cpp b/lvz/wrapper.cpp index 5916b13..14f73a9 100644 --- a/lvz/wrapper.cpp +++ b/lvz/wrapper.cpp @@ -16,13 +16,15 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef PLUGIN_URI -#error "This file requires PLUGIN_URI to be defined" -#endif - #ifndef PLUGIN_CLASS #error "This file requires PLUGIN_CLASS to be defined" #endif +#ifndef PLUGIN_URI_PREFIX +#error "This file requires PLUGIN_URI_PREFIX to be defined" +#endif +#ifndef PLUGIN_URI_SUFFIX +#error "This file requires PLUGIN_URI_SUFFIX to be defined" +#endif #include <stdlib.h> #include "audioeffectx.h" @@ -60,6 +62,7 @@ mda_instantiate(const LV2_Descriptor* descriptor, const LV2_Feature*const* features) { PLUGIN_CLASS* effect = new PLUGIN_CLASS(NULL); + effect->setURI(PLUGIN_URI_PREFIX PLUGIN_URI_SUFFIX); effect->setSampleRate(rate); MDAPlugin* plugin = (MDAPlugin*)malloc(sizeof(MDAPlugin)); @@ -87,7 +90,7 @@ init_descriptor() { mda_descriptor = (LV2_Descriptor*)malloc(sizeof(LV2_Descriptor)); - mda_descriptor->URI = PLUGIN_URI; + mda_descriptor->URI = PLUGIN_URI_PREFIX PLUGIN_URI_SUFFIX; mda_descriptor->activate = NULL; mda_descriptor->cleanup = mda_cleanup; mda_descriptor->connect_port = mda_connect_port; @@ -112,4 +115,15 @@ lv2_descriptor(uint32_t index) } } + +LV2_SYMBOL_EXPORT +AudioEffectX* +lvz_new_audioeffectx() +{ + PLUGIN_CLASS* effect = new PLUGIN_CLASS(NULL); + effect->setURI(PLUGIN_URI_PREFIX PLUGIN_URI_SUFFIX); + return effect; +} + + } // extern "C" |