[SCM] calf/master: + Small modules: add Event Merge plugin based on the new merging event buffer iterator

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 d56e951dc44f3d119bef4e497b8a97336f5f6b4f
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date:   Fri Oct 10 18:57:36 2008 +0000

    + Small modules: add Event Merge plugin based on the new merging event buffer iterator
    
    
    git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@326 78b06b96-2940-0410-b7fc-879d825d01d8

diff --git a/src/calf/lv2helpers.h b/src/calf/lv2helpers.h
index 94e847e..565e8de 100644
--- a/src/calf/lv2helpers.h
+++ b/src/calf/lv2helpers.h
@@ -57,6 +57,10 @@ struct lv2_event: public LV2_Event
         memcpy(data, src.data, src.size);
         return *this;
     }
+    /// Returns a 64-bit timestamp for easy and inefficient comparison
+    inline uint64_t timestamp() const {
+        return ((uint64_t)frames << 32) | subframes;
+    }
 };
 
 /// A read-only iterator-like object for reading from event buffers
@@ -89,6 +93,10 @@ public:
     inline const lv2_event &operator*() const {
         return *(const lv2_event *)(buffer->data + offset);
     }
+    /// Pointer to member
+    inline const lv2_event *operator->() const {
+        return &**this;
+    }
 
     /// Move to the next element
     inline event_port_read_iterator operator++() {
@@ -130,6 +138,10 @@ public:
     inline lv2_event &operator*() {
         return *(lv2_event *)(buffer->data + buffer->size);
     }
+    /// Pointer to member
+    inline lv2_event *operator->() {
+        return &**this;
+    }
     /// 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;
@@ -145,5 +157,63 @@ public:
     }
 };
 
+template<class Iter1, class Iter2>
+class event_port_merge_iterator
+{
+public:
+    Iter1 first;
+    Iter2 second;
+public:
+    event_port_merge_iterator() {}
+    event_port_merge_iterator(const Iter1 &_first, const Iter2 &_second)
+    : first(_first)
+    , second(_second)
+    {
+    }
+    /// @retval true if any of the iterators have any data left
+    inline operator bool() const {
+        return ((bool)first) || ((bool)second);
+    }
+    inline bool select_first() const
+    {
+        if (!(bool)second)
+            return true;
+        if (!(bool)first)
+            return false;
+        return first->timestamp() < second->timestamp();
+    }
+    /// Returns the earliest of (*first, *second)
+    inline const lv2_event &operator*() const {
+        if (select_first())
+        {
+            assert((bool)first);
+            return *first;
+        }
+        assert((bool)second);
+        return *second;
+    }
+    /// Pointer to member
+    inline const lv2_event *operator->() const {
+        return &**this;
+    }
+    /// Prefix increment
+    inline event_port_merge_iterator operator++() {
+        if (select_first())
+            first++;
+        else
+            second++;
+        return *this;
+    }
+    /// Postfix increment
+    inline event_port_merge_iterator operator++(int) {
+        event_port_merge_iterator ptr = *this;
+        if (select_first())
+            first++;
+        else
+            second++;
+        return ptr;
+    }
+};
+
 #endif
 #endif
diff --git a/src/calf/modulelist.h b/src/calf/modulelist.h
index 70137d7..b7e2dae 100644
--- a/src/calf/modulelist.h
+++ b/src/calf/modulelist.h
@@ -42,6 +42,7 @@
     PER_SMALL_MODULE_ITEM(copy_em, "copy_em")
     PER_SMALL_MODULE_ITEM(notefilter_e, "notefilter_e")
     PER_SMALL_MODULE_ITEM(notefilter2_e, "notefilter2_e")
+    PER_SMALL_MODULE_ITEM(eventmerge_e, "eventmerge_e")
     PER_SMALL_MODULE_ITEM(quadpower_a, "quadpower_a")
     PER_SMALL_MODULE_ITEM(quadpower_c, "quadpower_c")
     PER_SMALL_MODULE_ITEM(crossfader2_a, "crossfader2_a")
diff --git a/src/modules_small.cpp b/src/modules_small.cpp
index 06c1deb..3e05d5d 100644
--- a/src/modules_small.cpp
+++ b/src/modules_small.cpp
@@ -1354,6 +1354,28 @@ public:
     }
 };
 
+class eventmerge_e_audio_module: public midi_mixin<small_audio_module_base<2, 1> >
+{
+public:    
+    static void plugin_info(plugin_info_iface *pii)
+    {
+        pii->names("eventmerge_e", "Event Merge (M)", "lv2:UtilityPlugin");
+        pii->event_port("in_1", "In").input();
+        pii->event_port("in_2", "In").input();
+        pii->event_port("out", "Out").output();
+    }
+    void process(uint32_t)
+    {
+        event_port_merge_iterator<event_port_read_iterator, event_port_read_iterator> ri((const LV2_Event_Buffer *)ins[0], (const LV2_Event_Buffer *)ins[1]);
+        event_port_write_iterator wi((LV2_Event_Buffer *)outs[0]);
+        while(ri)
+        {
+            const lv2_event &event = *ri++;
+            *wi++ = event;
+        }
+    }
+};
+
 class print_a_audio_module: public small_audio_module_base<1, 0>
 {
 public:    

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list