[SCM] calf/master: + Framework: general refactoring (move LV2 helper classes to separate files, use "curiously recursive template pattern" instead of a macro for wavetable storage, do not define large/small per item macro if not used, add missing copyright/license header to lv2wrap.h)

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:37:43 UTC 2013


The following commit has been merged in the master branch:
commit 07f70740cc997967e0acb15594ff3c9763185cf4
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date:   Fri Oct 10 18:29:59 2008 +0000

    + Framework: general refactoring (move LV2 helper classes to separate files, use "curiously recursive template pattern" instead of a macro for wavetable storage, do not define large/small per item macro if not used, add missing copyright/license header to lv2wrap.h)
    
    
    git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@325 78b06b96-2940-0410-b7fc-879d825d01d8

diff --git a/src/calf/Makefile.am b/src/calf/Makefile.am
index 19d9adb..ba6fed5 100644
--- a/src/calf/Makefile.am
+++ b/src/calf/Makefile.am
@@ -3,7 +3,7 @@ calfdir = $(includedir)/calf
 calf_HEADERS = audio_fx.h benchmark.h biquad.h buffer.h custom_ctl.h \
     ctl_curve.h ctl_keyboard.h \
     delay.h fft.h fixed_point.h giface.h gui.h inertia.h \
-    jackhost.h lv2_event.h lv2_ui.h lv2_uri_map.h lv2-midiport.h lv2wrap.h \
+    jackhost.h lv2_event.h lv2_ui.h lv2_uri_map.h lv2-midiport.h lv2helpers.h lv2wrap.h \
     main_win.h modules.h modules_dev.h modules_small.h modules_synths.h modulelist.h \
     onepole.h organ.h osc.h osctl.h osctlnet.h plugininfo.h preset.h \
     preset_gui.h primitives.h synth.h utils.h wave.h
diff --git a/src/calf/lv2helpers.h b/src/calf/lv2helpers.h
new file mode 100644
index 0000000..94e847e
--- /dev/null
+++ b/src/calf/lv2helpers.h
@@ -0,0 +1,149 @@
+/* Calf DSP Library
+ * LV2-related helper classes and functions
+ *
+ * Copyright (C) 2001-2008 Krzysztof Foltman
+ *
+ * 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; either
+ * version 2 of the License, or (at your option) 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef CALF_LV2HELPERS_H
+#define CALF_LV2HELPERS_H
+
+#if USE_LV2
+
+/// A mixin for adding the event feature, URI map and MIDI event type retrieval to small plugins
+/// @todo refactor into separate event feature, URI map and MIDI event type mixins some day
+template<class T>
+class midi_mixin: public T
+{
+public:
+    LV2_URI_Map_Feature *uri_map;
+    uint32_t midi_event_type;
+    LV2_Event_Feature *event_feature;
+    virtual void use_feature(const char *URI, void *data) {
+        if (!strcmp(URI, LV2_URI_MAP_URI))
+        {
+            uri_map = (LV2_URI_Map_Feature *)data;
+            midi_event_type = uri_map->uri_to_id(uri_map->callback_data, 
+                "http://lv2plug.in/ns/ext/event",
+                "http://lv2plug.in/ns/ext/midi#MidiEvent");
+        }
+        else if (!strcmp(URI, LV2_EVENT_URI))
+        {
+            event_feature = (LV2_Event_Feature *)data;
+        }
+        T::use_feature(URI, data);
+    }
+};
+
+/// LV2 event structure + payload as 0-length array for easy access
+struct lv2_event: public LV2_Event
+{
+    uint8_t data[0];
+    inline lv2_event &operator=(const lv2_event &src) {
+        *(LV2_Event *)this = (const LV2_Event &)src;
+        memcpy(data, src.data, src.size);
+        return *this;
+    }
+};
+
+/// A read-only iterator-like object for reading from event buffers
+class event_port_read_iterator
+{
+protected:
+    const LV2_Event_Buffer *buffer;
+    uint32_t offset;
+public:
+    /// Default constructor creating a useless iterator you can assign to
+    event_port_read_iterator()
+    : buffer(NULL)
+    , offset(0)
+    {
+    }
+    
+    /// Create an iterator based on specified buffer and index/offset values
+    event_port_read_iterator(const LV2_Event_Buffer *_buffer, uint32_t _offset = 0)
+    : buffer(_buffer)
+    , offset(0)
+    {
+    }
+
+    /// Are any data left to be read?
+    inline operator bool() const {
+        return offset < buffer->size;
+    }
+    
+    /// Read pointer
+    inline const lv2_event &operator*() const {
+        return *(const lv2_event *)(buffer->data + offset);
+    }
+
+    /// Move to the next element
+    inline event_port_read_iterator operator++() {
+        offset += ((**this).size + 19) &~7;
+        return *this;
+    }
+
+    /// Move to the next element
+    inline event_port_read_iterator operator++(int) {
+        event_port_read_iterator old = *this;
+        offset += ((**this).size + 19) &~7;
+        return old;
+    }
+};
+
+/// A write-only iterator-like object for writing to event buffers
+class event_port_write_iterator
+{
+protected:
+    LV2_Event_Buffer *buffer;
+public:
+    /// Default constructor creating a useless iterator you can assign to
+    event_port_write_iterator()
+    : buffer(NULL)
+    {
+    }
+    
+    /// Create a write iterator based on specified buffer and index/offset values
+    event_port_write_iterator(LV2_Event_Buffer *_buffer)
+    : buffer(_buffer)
+    {
+    }
+
+    /// @return the remaining buffer space
+    inline uint32_t space_left() const {
+        return buffer->capacity - buffer->size;
+    }
+    /// @return write pointer
+    inline lv2_event &operator*() {
+        return *(lv2_event *)(buffer->data + buffer->size);
+    }
+    /// Move to the next element after the current one has been written (must be called after each write)
+    inline event_port_write_iterator operator++() {
+        buffer->size += ((**this).size + 19) &~7;
+        buffer->event_count ++;
+        return *this;
+    }
+    /// Move to the next element after the current one has been written
+    inline lv2_event *operator++(int) {
+        lv2_event *ptr = &**this;
+        buffer->size += ((**this).size + 19) &~7;
+        buffer->event_count ++;
+        return ptr;
+    }
+};
+
+#endif
+#endif
diff --git a/src/calf/lv2wrap.h b/src/calf/lv2wrap.h
index a9bbfce..72dd9c5 100644
--- a/src/calf/lv2wrap.h
+++ b/src/calf/lv2wrap.h
@@ -1,3 +1,26 @@
+/* Calf DSP Library
+ * LV2 wrapper templates
+ *
+ * Copyright (C) 2001-2008 Krzysztof Foltman
+ *
+ * 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; either
+ * version 2 of the License, or (at your option) 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef CALF_LV2WRAP_H
+#define CALF_LV2WRAP_H
+
 #if USE_LV2
 
 #include <string>
@@ -318,3 +341,4 @@ extern const LV2_Descriptor *lv2_small_descriptor(uint32_t index);
 };
 
 #endif
+#endif
diff --git a/src/calf/modulelist.h b/src/calf/modulelist.h
index 293de41..70137d7 100644
--- a/src/calf/modulelist.h
+++ b/src/calf/modulelist.h
@@ -1,3 +1,4 @@
+#ifdef PER_MODULE_ITEM
     PER_MODULE_ITEM(filter, false, "filter")
     PER_MODULE_ITEM(flanger, false, "flanger")
     PER_MODULE_ITEM(reverb, false, "reverb")
@@ -6,6 +7,9 @@
     PER_MODULE_ITEM(organ, true, "organ")
     PER_MODULE_ITEM(rotary_speaker, false, "rotaryspeaker")
     PER_MODULE_ITEM(phaser, false, "phaser")
+#undef PER_MODULE_ITEM
+#endif
+#ifdef PER_SMALL_MODULE_ITEM
 #ifdef ENABLE_EXPERIMENTAL
     PER_SMALL_MODULE_ITEM(lp_filter, "lowpass12")
     PER_SMALL_MODULE_ITEM(hp_filter, "highpass12")
@@ -67,5 +71,5 @@
     PER_SMALL_MODULE_ITEM(mux8_c, "mux8_c")
     PER_SMALL_MODULE_ITEM(mux16_c, "mux16_c")
 #endif
-#undef PER_MODULE_ITEM
 #undef PER_SMALL_MODULE_ITEM
+#endif
\ No newline at end of file
diff --git a/src/modules_small.cpp b/src/modules_small.cpp
index 675c234..06c1deb 100644
--- a/src/modules_small.cpp
+++ b/src/modules_small.cpp
@@ -30,6 +30,7 @@
 #include <calf/lv2wrap.h>
 #include <calf/osc.h>
 #include <calf/modules_small.h>
+#include <calf/lv2helpers.h>
 
 #ifdef ENABLE_EXPERIMENTAL
 
@@ -1076,7 +1077,7 @@ public:
 
 #define SMALL_OSC_TABLE_BITS 12
 
-class freq_only_osc_base: public null_small_audio_module
+class freq_only_osc_base_common: public null_small_audio_module
 {
 public:    
     typedef waveform_family<SMALL_OSC_TABLE_BITS> waves_type;
@@ -1123,19 +1124,20 @@ public:
     }
 };
 
-#define OSC_MODULE_GET_WAVES() \
-    virtual waves_type *get_waves() { \
-        static waves_type *waves = NULL; \
-        if (!waves) \
-            waves = create_waves(); \
-        return waves; \
+template<class T>
+class freq_only_osc_base: public freq_only_osc_base_common
+{
+    virtual waves_type *get_waves() {
+        static waves_type *waves = NULL;
+        if (!waves)
+            waves = create_waves();
+        return waves;
     }
+};
 
-class square_osc_audio_module: public freq_only_osc_base
+class square_osc_audio_module: public freq_only_osc_base<square_osc_audio_module>
 {
 public:
-    OSC_MODULE_GET_WAVES()
-
     virtual void get_original_waveform(float data[wave_size]) {
         for (int i = 0; i < wave_size; i++)
             data[i] = (i < wave_size / 2) ? +1 : -1;
@@ -1147,11 +1149,9 @@ public:
     }
 };
 
-class saw_osc_audio_module: public freq_only_osc_base
+class saw_osc_audio_module: public freq_only_osc_base<saw_osc_audio_module>
 {
 public:
-    OSC_MODULE_GET_WAVES()
-
     virtual void get_original_waveform(float data[wave_size]) {
         for (int i = 0; i < wave_size; i++)
             data[i] = (i * 2.0 / wave_size) - 1;
@@ -1177,101 +1177,6 @@ public:
     }
 };
 
-/// LV2 event structure + payload as 0-length array for easy access
-struct lv2_event: public LV2_Event
-{
-    uint8_t data[0];
-    inline lv2_event &operator=(const lv2_event &src) {
-        *(LV2_Event *)this = (const LV2_Event &)src;
-        memcpy(data, src.data, src.size);
-        return *this;
-    }
-};
-
-class event_port_read_iterator
-{
-protected:
-    const LV2_Event_Buffer *buffer;
-    uint32_t offset;
-public:
-    /// Default constructor creating a useless iterator you can assign to
-    event_port_read_iterator()
-    : buffer(NULL)
-    , offset(0)
-    {
-    }
-    
-    /// Create an iterator based on specified buffer and index/offset values
-    event_port_read_iterator(const LV2_Event_Buffer *_buffer, uint32_t _offset = 0)
-    : buffer(_buffer)
-    , offset(0)
-    {
-    }
-
-    /// Are any data left to be read?
-    inline operator bool() const {
-        return offset < buffer->size;
-    }
-    
-    /// Read pointer
-    inline const lv2_event &operator*() const {
-        return *(const lv2_event *)(buffer->data + offset);
-    }
-
-    /// Move to the next element
-    inline event_port_read_iterator operator++() {
-        offset += ((**this).size + 19) &~7;
-        return *this;
-    }
-
-    /// Move to the next element
-    inline event_port_read_iterator operator++(int) {
-        event_port_read_iterator old = *this;
-        offset += ((**this).size + 19) &~7;
-        return old;
-    }
-};
-
-class event_port_write_iterator
-{
-protected:
-    LV2_Event_Buffer *buffer;
-public:
-    /// Default constructor creating a useless iterator you can assign to
-    event_port_write_iterator()
-    : buffer(NULL)
-    {
-    }
-    
-    /// Create a write iterator based on specified buffer and index/offset values
-    event_port_write_iterator(LV2_Event_Buffer *_buffer)
-    : buffer(_buffer)
-    {
-    }
-
-    /// @return the remaining buffer space
-    inline uint32_t space_left() const {
-        return buffer->capacity - buffer->size;
-    }
-    /// @return write pointer
-    inline lv2_event &operator*() {
-        return *(lv2_event *)(buffer->data + buffer->size);
-    }
-    /// Move to the next element after the current one has been written (must be called after each write)
-    inline event_port_write_iterator operator++() {
-        buffer->size += ((**this).size + 19) &~7;
-        buffer->event_count ++;
-        return *this;
-    }
-    /// Move to the next element after the current one has been written
-    inline lv2_event *operator++(int) {
-        lv2_event *ptr = &**this;
-        buffer->size += ((**this).size + 19) &~7;
-        buffer->event_count ++;
-        return ptr;
-    }
-};
-
 class print_e_audio_module: public small_audio_module_base<1, 0>
 {
 public:    
@@ -1401,29 +1306,6 @@ public:
     }
 };
 
-template<class T>
-class midi_mixin: public T
-{
-public:
-    LV2_URI_Map_Feature *uri_map;
-    uint32_t midi_event_type;
-    LV2_Event_Feature *event_feature;
-    virtual void use_feature(const char *URI, void *data) {
-        if (!strcmp(URI, LV2_URI_MAP_URI))
-        {
-            uri_map = (LV2_URI_Map_Feature *)data;
-            midi_event_type = uri_map->uri_to_id(uri_map->callback_data, 
-                "http://lv2plug.in/ns/ext/event",
-                "http://lv2plug.in/ns/ext/midi#MidiEvent");
-        }
-        else if (!strcmp(URI, LV2_EVENT_URI))
-        {
-            event_feature = (LV2_Event_Feature *)data;
-        }
-        T::use_feature(URI, data);
-    }
-};
-
 class notefilter_e_audio_module: public midi_mixin<small_audio_module_base<1, 1> >
 {
 public:    
@@ -1667,13 +1549,11 @@ public:
 };
 };
 
-#define PER_MODULE_ITEM(...) 
 #define PER_SMALL_MODULE_ITEM(name, id) SMALL_WRAPPERS(name, id)
 #include <calf/modulelist.h>
 
 const LV2_Descriptor *synth::lv2_small_descriptor(uint32_t index)
 {
-    #define PER_MODULE_ITEM(...) 
     #define PER_SMALL_MODULE_ITEM(name, id) if (!(index--)) return &::lv2_small_##name.descriptor;
     #include <calf/modulelist.h>
     return NULL;
@@ -1683,7 +1563,6 @@ const LV2_Descriptor *synth::lv2_small_descriptor(uint32_t index)
 
 void synth::get_all_small_plugins(plugin_list_info_iface *iface)
 {
-    #define PER_MODULE_ITEM(name, isSynth, jackname) 
     #define PER_SMALL_MODULE_ITEM(name, id) { plugin_info_iface *pii = &iface->plugin(id); small_plugins::name##_audio_module::plugin_info(pii); pii->finalize(); }
     #include <calf/modulelist.h>
 }
diff --git a/src/plugin.cpp b/src/plugin.cpp
index 7923038..1315859 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -39,7 +39,6 @@ using namespace synth;
 #define ALL_WRAPPERS(mod) LADSPA_WRAPPER(mod) LV2_WRAPPER(mod)
 
 #define PER_MODULE_ITEM(name, isSynth, jackname) ALL_WRAPPERS(name)
-#define PER_SMALL_MODULE_ITEM(...)
 #include <calf/modulelist.h>
 
 #if USE_LV2
@@ -51,7 +50,6 @@ extern "C" {
 const LV2_Descriptor *lv2_descriptor(uint32_t index)
 {
     #define PER_MODULE_ITEM(name, isSynth, jackname) if (!(index--)) return &::lv2_##name.descriptor;
-    #define PER_SMALL_MODULE_ITEM(...) 
     #include <calf/modulelist.h>
 #ifdef ENABLE_EXPERIMENTAL
     return lv2_small_descriptor(index);
@@ -70,7 +68,6 @@ extern "C" {
 const LADSPA_Descriptor *ladspa_descriptor(unsigned long Index)
 {
     #define PER_MODULE_ITEM(name, isSynth, jackname) if (!isSynth && !(Index--)) return &::ladspa_##name.descriptor;
-    #define PER_SMALL_MODULE_ITEM(...)
     #include <calf/modulelist.h>
     return NULL;
 }
@@ -83,7 +80,6 @@ extern "C" {
 const DSSI_Descriptor *dssi_descriptor(unsigned long Index)
 {
     #define PER_MODULE_ITEM(name, isSynth, jackname) if (!(Index--)) return &::ladspa_##name.dssi_descriptor;
-    #define PER_SMALL_MODULE_ITEM(...)
     #include <calf/modulelist.h>
     return NULL;
 }

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list