From 5a838e44308db34ac30fc71c4fde5b570110b988 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 7 Jul 2011 19:19:12 +0000 Subject: Add amp example plugin. Upgrade to waf 1.6.6. Don't depend on a C++ compiler being present. --- core.lv2/waf | Bin 87718 -> 88585 bytes core.lv2/wscript | 2 +- plugins/eg-amp.lv2/amp.c | 126 ++++++++++++++++++++++++++++++++++++++++ plugins/eg-amp.lv2/amp.ttl | 83 ++++++++++++++++++++++++++ plugins/eg-amp.lv2/manifest.ttl | 10 ++++ plugins/eg-amp.lv2/waf | 1 + plugins/eg-amp.lv2/wscript | 72 +++++++++++++++++++++++ waf | Bin 87718 -> 88585 bytes wscript | 4 ++ 9 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 plugins/eg-amp.lv2/amp.c create mode 100644 plugins/eg-amp.lv2/amp.ttl create mode 100644 plugins/eg-amp.lv2/manifest.ttl create mode 120000 plugins/eg-amp.lv2/waf create mode 100644 plugins/eg-amp.lv2/wscript diff --git a/core.lv2/waf b/core.lv2/waf index 86ffb67..ef338a3 100755 Binary files a/core.lv2/waf and b/core.lv2/waf differ diff --git a/core.lv2/wscript b/core.lv2/wscript index aa0edba..ae0b262 100644 --- a/core.lv2/wscript +++ b/core.lv2/wscript @@ -86,7 +86,7 @@ def build(bld): bld.install_files('${LV2DIR}/lv2core.lv2', 'lv2.h') # Pkgconfig file - autowaf.build_pc(bld, 'LV2CORE', LV2CORE_VERSION, []) + autowaf.build_pc(bld, 'LV2CORE', LV2CORE_VERSION, '', []) # Bundle (data) bld.install_files('${LV2DIR}/lv2core.lv2', 'lv2.ttl manifest.ttl') diff --git a/plugins/eg-amp.lv2/amp.c b/plugins/eg-amp.lv2/amp.c new file mode 100644 index 0000000..1f2b824 --- /dev/null +++ b/plugins/eg-amp.lv2/amp.c @@ -0,0 +1,126 @@ +/* + LV2 Amp Example Plugin + Copyright 2006-2011 Steve Harris, David Robillard. + 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. +*/ + +#include +#include +#include + +#include "lv2/lv2plug.in/ns/lv2core/lv2.h" + +#define AMP_URI "http://lv2plug.in/plugins/eg-amp" +#define AMP_GAIN 0 +#define AMP_INPUT 1 +#define AMP_OUTPUT 2 + +typedef struct { + float* gain; + float* input; + float* output; +} Amp; + +static LV2_Handle +instantiate(const LV2_Descriptor* descriptor, + double rate, + const char* bundle_path, + const LV2_Feature* const* features) +{ + Amp* amp = (Amp*)malloc(sizeof(Amp)); + + return (LV2_Handle)amp; +} + +static void +connect_port(LV2_Handle instance, + uint32_t port, + void* data) +{ + Amp* amp = (Amp*)instance; + + switch (port) { + case AMP_GAIN: + amp->gain = data; + break; + case AMP_INPUT: + amp->input = data; + break; + case AMP_OUTPUT: + amp->output = data; + break; + } +} + +static void +activate(LV2_Handle instance) +{ +} + +#define DB_CO(g) ((g) > -90.0f ? powf(10.0f, (g) * 0.05f) : 0.0f) + +static void +run(LV2_Handle instance, uint32_t n_samples) +{ + Amp* amp = (Amp*)instance; + + const float gain = *(amp->gain); + const float* const input = amp->input; + float* const output = amp->output; + + const float coef = DB_CO(gain); + + for (uint32_t pos = 0; pos < n_samples; pos++) { + output[pos] = input[pos] * coef; + } +} + +static void +deactivate(LV2_Handle instance) +{ +} + +static void +cleanup(LV2_Handle instance) +{ + free(instance); +} + +const void* +extension_data(const char * uri) +{ + return NULL; +} + +static const LV2_Descriptor descriptor = { + AMP_URI, + instantiate, + connect_port, + activate, + run, + deactivate, + cleanup, + extension_data +}; + +LV2_SYMBOL_EXPORT +const LV2_Descriptor* +lv2_descriptor(uint32_t index) +{ + switch (index) { + case 0: + return &descriptor; + default: + return NULL; + } +} diff --git a/plugins/eg-amp.lv2/amp.ttl b/plugins/eg-amp.lv2/amp.ttl new file mode 100644 index 0000000..24e99d4 --- /dev/null +++ b/plugins/eg-amp.lv2/amp.ttl @@ -0,0 +1,83 @@ +# LV2 Amp Example Plugin +# Copyright 2006-2011 Steve Harris, David Robillard +# +# 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 rdf: . +@prefix rdfs: . + + + a lv2:Plugin , + lv2:AmplifierPlugin ; + doap:maintainer [ + foaf:name "David Robillard" ; + foaf:homepage ; + foaf:mbox + ] ; + doap:name "Simple Amplifier" , + "简单放大器"@ch , + "Einfacher Verstärker"@de , + "Simple Amp"@en-gb , + "Amplificador Simple"@es , + "Amplificateur de Base"@fr , + "Amplificatore Semplice"@it , + "簡単なアンプ"@jp , + "Просто Усилитель"@ru ; + doap:license ; + lv2:property lv2:hardRtCapable ; + lv2:port [ + a lv2:InputPort , + lv2:ControlPort ; + lv2:index 0 ; + lv2:symbol "gain" ; + lv2:name "Gain" , + "收益"@ch , + "Gewinn"@de , + "Gain"@en-gb , + "Aumento"@es , + "Gain"@fr , + "Guadagno"@it , + "利益"@jp , + "Увеличение"@ru ; + lv2:default 0.0 ; + lv2:minimum -90.0 ; + lv2:maximum 24.0 ; + lv2:scalePoint [ + rdfs:label "+5" ; + rdf:value 5.0 + ] , [ + rdfs:label "0" ; + rdf:value 0.0 + ] , [ + rdfs:label "-5" ; + rdf:value -5.0 + ] , [ + rdfs:label "-10" ; + rdf:value -10.0 + ] + ] , [ + a lv2:AudioPort , + lv2:InputPort ; + lv2:index 1 ; + lv2:symbol "in" ; + lv2:name "In" + ] , [ + a lv2:AudioPort , + lv2:OutputPort ; + lv2:index 2 ; + lv2:symbol "out" ; + lv2:name "Out" + ] . diff --git a/plugins/eg-amp.lv2/manifest.ttl b/plugins/eg-amp.lv2/manifest.ttl new file mode 100644 index 0000000..5ca1ada --- /dev/null +++ b/plugins/eg-amp.lv2/manifest.ttl @@ -0,0 +1,10 @@ +# LV2 Plugin Manifest +# Lists where plugins' data files and shared objects reside. + +@prefix lv2: . +@prefix rdfs: . + + + a lv2:Plugin ; + lv2:binary ; + rdfs:seeAlso . diff --git a/plugins/eg-amp.lv2/waf b/plugins/eg-amp.lv2/waf new file mode 120000 index 0000000..59a1ac9 --- /dev/null +++ b/plugins/eg-amp.lv2/waf @@ -0,0 +1 @@ +../../waf \ No newline at end of file diff --git a/plugins/eg-amp.lv2/wscript b/plugins/eg-amp.lv2/wscript new file mode 100644 index 0000000..e6a906a --- /dev/null +++ b/plugins/eg-amp.lv2/wscript @@ -0,0 +1,72 @@ +#!/usr/bin/env python +import os +import shutil +from waflib import Logs +from waflib.extras import autowaf as autowaf + +# Variables for 'waf dist' +APPNAME = 'eg-amp.lv2' +VERSION = '1.0.0' + +# Mandatory variables +top = '.' +out = 'build' + +def options(opt): + autowaf.set_options(opt) + opt.load('compiler_c') + +def configure(conf): + autowaf.configure(conf) + + conf.line_just = 51 + autowaf.display_header('Amp Configuration') + conf.load('compiler_c') + + autowaf.check_header(conf, 'c', 'lv2/lv2plug.in/ns/lv2core/lv2.h') + + conf.env.append_value('CFLAGS', '-std=c99') + + # Set env['pluginlib_PATTERN'] + pat = conf.env['cshlib_PATTERN'] + if pat.startswith('lib'): + pat = pat[3:] + conf.env['pluginlib_PATTERN'] = pat + conf.env['pluginlib_EXT'] = pat[pat.rfind('.'):] + + autowaf.display_msg(conf, "LV2 bundle directory", + conf.env['LV2DIR']) + print('') + +def build_plugin(bld, lang, bundle, name, source, cflags=[], libs=[]): + + if cflags != []: + obj.cflags = cflags + obj.cxxflags = cflags + if libs != []: + autowaf.use_lib(bld, obj, libs) + +def build(bld): + bundle = 'eg-amp.lv2' + + # Copy data files to build bundle (build/eg-amp.lv2) + for i in [ 'amp.ttl', 'manifest.ttl' ]: + bld(rule = 'cp ${SRC} ${TGT}', + source = i, + target = bld.path.get_bld().make_node('%s/%s' % (bundle, i)), + install_path = '${LV2DIR}/%s' % bundle) + + # Create a build environment that builds module-style library names + # e.g. eg-amp.so instead of libeg-amp.so + # Note for C++ you must set cxxshlib_PATTERN instead + penv = bld.env.derive() + penv['cshlib_PATTERN'] = bld.env['pluginlib_PATTERN'] + + # Build plugin library + obj = bld(features = 'c cshlib', + env = penv, + source = 'amp.c', + name = 'amp', + target = '%s/amp' % bundle, + install_path = '${LV2DIR}/%s' % bundle) + diff --git a/waf b/waf index 86ffb67..ef338a3 100755 Binary files a/waf and b/waf differ diff --git a/wscript b/wscript index b0aac6b..a1f6ced 100644 --- a/wscript +++ b/wscript @@ -21,11 +21,13 @@ def options(opt): opt.load('compiler_cc') opt.load('compiler_cxx') opt.recurse('core.lv2') + opt.recurse('plugins/eg-amp.lv2') def configure(conf): autowaf.set_recursive() autowaf.configure(conf) conf.recurse('core.lv2'); + conf.recurse('plugins/eg-amp.lv2'); conf.load('compiler_cc') conf.load('compiler_cxx') conf.env.append_value('CFLAGS', '-std=c99') @@ -80,6 +82,8 @@ def build(bld): bld.add_post_fun(warn_lv2config) + bld.recurse('plugins/eg-amp.lv2') + def warn_lv2config(ctx): if ctx.cmd == 'install': Logs.warn(''' -- cgit v1.2.1