[SCM] calf/master: + Framework: set Cairo context attributes via separate interface - and get Cairo headers outta DSP-specific files

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:38:29 UTC 2013


The following commit has been merged in the master branch:
commit 86aae50de5f685d0a1c2a341786aced910041a8d
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Sat Nov 15 23:24:23 2008 +0000

    + Framework: set Cairo context attributes via separate interface - and get Cairo headers outta DSP-specific files

diff --git a/src/Makefile.am b/src/Makefile.am
index 56dc419..5fbfb04 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,9 +52,9 @@ endif
 
 calf_la_SOURCES = modules.cpp modules_dsp.cpp modules_small.cpp giface.cpp monosynth.cpp organ.cpp osctl.cpp plugin.cpp preset.cpp synth.cpp utils.cpp
 if USE_DEBUG
-calf_la_LDFLAGS = -rpath $(ladspadir) -avoid-version -module -lexpat -lcairo -disable-static
+calf_la_LDFLAGS = -rpath $(ladspadir) -avoid-version -module -lexpat -disable-static
 else
-calf_la_LDFLAGS = -rpath $(ladspadir) -avoid-version -module -lexpat -lcairo -disable-static -export-symbols-regex "(ladspa_|lv2_|dssi_)descriptor"
+calf_la_LDFLAGS = -rpath $(ladspadir) -avoid-version -module -lexpat -disable-static -export-symbols-regex "(ladspa_|lv2_|dssi_)descriptor"
 endif
 
 if USE_LV2_GUI
diff --git a/src/calf/custom_ctl.h b/src/calf/custom_ctl.h
index 261c7f4..6c7e907 100644
--- a/src/calf/custom_ctl.h
+++ b/src/calf/custom_ctl.h
@@ -106,4 +106,12 @@ extern GType calf_knob_get_type();
 
 G_END_DECLS
 
+class cairo_impl: public calf_plugins::cairo_iface
+{
+public:
+    cairo_t *context;
+    virtual void set_source_rgba(float r, float g, float b, float a = 1.f) { cairo_set_source_rgba(context, r, g, b, a); }
+    virtual void set_line_width(float width) { cairo_set_line_width(context, width); }
+};
+
 #endif
diff --git a/src/calf/giface.h b/src/calf/giface.h
index e367854..91d8497 100644
--- a/src/calf/giface.h
+++ b/src/calf/giface.h
@@ -28,10 +28,6 @@
 #include "primitives.h"
 #include "preset.h"
 
-struct _cairo;
-    
-typedef struct _cairo cairo_t;
-    
 namespace calf_plugins {
 
 enum {
@@ -139,6 +135,13 @@ struct parameter_properties
     float get_increment() const;
 };
 
+struct cairo_iface
+{
+    virtual void set_source_rgba(float r, float g, float b, float a = 1.f) = 0;
+    virtual void set_line_width(float width) = 0;
+    virtual ~cairo_iface() {}
+};
+
 /// 'provides live line graph values' interface
 struct line_graph_iface
 {
@@ -150,17 +153,17 @@ struct line_graph_iface
     /// @param context cairo context to adjust (for multicolour graphs etc.)
     /// @retval true graph data was returned; subindex+1 graph may or may not be available
     /// @retval false graph data was not returned; subindex+1 graph does not exist either
-    virtual bool get_graph(int index, int subindex, float *data, int points, cairo_t *context) { return false; }
+    virtual bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context) { return false; }
 
     /// Obtain subindex'th dot of parameter 'index'
     /// @param index parameter/dot number (usually tied to particular plugin control port)
     /// @param subindex dot number (there may be multiple dots graphs for one parameter)
-    virtual bool get_dot(int index, int subindex, float &x, float &y, int &size, cairo_t *context) { return false; }
+    virtual bool get_dot(int index, int subindex, float &x, float &y, int &size, cairo_iface *context) { return false; }
     
     /// Obtain subindex'th dot of parameter 'index'
     /// @param index parameter/dot number (usually tied to particular plugin control port)
     /// @param subindex dot number (there may be multiple dots graphs for one parameter)
-    virtual bool get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_t *context) { return false; }
+    virtual bool get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_iface *context) { return false; }
     
     /// Obtain subindex'th static graph of parameter index (static graphs are only dependent on parameter value, not plugin state)
     /// @param index parameter/graph number (usually tied to particular plugin control port)
@@ -171,7 +174,7 @@ struct line_graph_iface
     /// @param context cairo context to adjust (for multicolour graphs etc.)
     /// @retval true graph data was returned; subindex+1 graph may or may not be available
     /// @retval false graph data was not returned; subindex+1 graph does not exist either
-    virtual bool get_static_graph(int index, int subindex, float value, float *data, int points, cairo_t *context) { return false; }
+    virtual bool get_static_graph(int index, int subindex, float value, float *data, int points, cairo_iface *context) { return false; }
     
     /// Standard destructor to make compiler happy
     virtual ~line_graph_iface() {}
diff --git a/src/calf/modules.h b/src/calf/modules.h
index ffac3d0..f78222d 100644
--- a/src/calf/modules.h
+++ b/src/calf/modules.h
@@ -128,8 +128,8 @@ public:
         right.process(outs[1] + offset, ins[1] + offset, nsamples);
         return outputs_mask; // XXXKF allow some delay after input going blank
     }
-    bool get_graph(int index, int subindex, float *data, int points, cairo_t *context);
-    bool get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_t *context);
+    bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context);
+    bool get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_iface *context);
     float freq_gain(int subindex, float freq, float srate);
 };
 
@@ -364,9 +364,9 @@ public:
         }
         return ostate;
     }
-    bool get_graph(int index, int subindex, float *data, int points, cairo_t *context);
+    bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context);
     float freq_gain(int subindex, float freq, float srate);
-    bool get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_t *context);
+    bool get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_iface *context);
 };
 
 class vintage_delay_audio_module: public audio_module<vintage_delay_metadata>
@@ -686,10 +686,10 @@ public:
     void activate();
     void deactivate();
     void set_sample_rate(uint32_t sr);
-    bool get_graph(int index, int subindex, float *data, int points, cairo_t *context);
+    bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context);
     float freq_gain(int subindex, float freq, float srate);
-    bool get_dot(int index, int subindex, float &x, float &y, int &size, cairo_t *context);
-    bool get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_t *context);
+    bool get_dot(int index, int subindex, float &x, float &y, int &size, cairo_iface *context);
+    bool get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_iface *context);
 };
 
 extern std::string get_builtin_modules_rdf();
diff --git a/src/calf/modules_dev.h b/src/calf/modules_dev.h
index debc16f..b04ae2a 100644
--- a/src/calf/modules_dev.h
+++ b/src/calf/modules_dev.h
@@ -174,7 +174,7 @@ public:
         }
         return slope * makeup;
     }
-    virtual bool get_graph(int index, int subindex, float *data, int points, cairo_t *context) { 
+    virtual bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context) { 
         if (subindex > 0) // 1
             return false;
         for (int i = 0; i < points; i++)
@@ -188,7 +188,7 @@ public:
         }
         return true;
     }
-    virtual bool get_dot(int index, int subindex, float &x, float &y, int &size, cairo_t *context) {
+    virtual bool get_dot(int index, int subindex, float &x, float &y, int &size, cairo_iface *context) {
         if (!subindex)
         {
             x = 1 + log(detected) / log(65536);
diff --git a/src/calf/modules_synths.h b/src/calf/modules_synths.h
index 9415d4b..01d30a8 100644
--- a/src/calf/modules_synths.h
+++ b/src/calf/modules_synths.h
@@ -137,9 +137,9 @@ public:
     /// Run oscillators and two filters (one per channel) to produce stereo output samples.
     void calculate_buffer_stereo();
     /// Retrieve filter graph (which is 'live' so it cannot be generated by get_static_graph), or fall back to get_static_graph.
-    bool get_graph(int index, int subindex, float *data, int points, cairo_t *context);
+    bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context);
     /// Retrieve waveform graph (which does not need information about synth state)
-    bool get_static_graph(int index, int subindex, float value, float *data, int points, cairo_t *context);
+    bool get_static_graph(int index, int subindex, float value, float *data, int points, cairo_iface *context);
     /// @retval true if the filter 1 is to be used for the left channel and filter 2 for the right channel
     /// @retval false if filters are to be connected in series and sent (mono) to both channels    
     inline bool is_stereo_filter() const
@@ -243,7 +243,7 @@ public:
     /// Practically all the stuff here is noisy
     bool is_noisy(int param_no) { return true; }
     void execute(int cmd_no);
-    bool get_graph(int index, int subindex, float *data, int points, cairo_t *context);
+    bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context);
     
     char *configure(const char *key, const char *value);
     void send_configures(send_configure_iface *);
diff --git a/src/custom_ctl.cpp b/src/custom_ctl.cpp
index 9f8f6ca..5e4a42c 100644
--- a/src/custom_ctl.cpp
+++ b/src/custom_ctl.cpp
@@ -60,12 +60,14 @@ calf_line_graph_expose (GtkWidget *widget, GdkEventExpose *event)
     cairo_rectangle(c, ox, oy, sx, sy);
     cairo_clip_preserve(c);
     cairo_fill(c);
+    cairo_impl cimpl;
+    cimpl.context = c;
 
     if (lg->source) {
         float pos = 0;
         bool vertical = false;
         cairo_set_line_width(c, 1);
-        for(int gn = 0; cairo_set_source_rgba(c, 1, 1, 1, 0.5), lg->source->get_gridline(lg->source_id, gn, pos, vertical, c); gn++)
+        for(int gn = 0; cairo_set_source_rgba(c, 1, 1, 1, 0.5), lg->source->get_gridline(lg->source_id, gn, pos, vertical, &cimpl); gn++)
         {
             if (vertical)
             {
@@ -86,7 +88,7 @@ calf_line_graph_expose (GtkWidget *widget, GdkEventExpose *event)
         gdk_cairo_set_source_color(c, &sc2);
         cairo_set_line_join(c, CAIRO_LINE_JOIN_MITER);
         cairo_set_line_width(c, 1);
-        for(int gn = 0; lg->source->get_graph(lg->source_id, gn, data, 2 * sx, c); gn++)
+        for(int gn = 0; lg->source->get_graph(lg->source_id, gn, data, 2 * sx, &cimpl); gn++)
         {
             for (int i = 0; i < 2 * sx; i++)
             {
@@ -105,7 +107,7 @@ calf_line_graph_expose (GtkWidget *widget, GdkEventExpose *event)
         int size = 0;
         GdkColor sc3 = { 0, 32767, 65535, 0 };
         gdk_cairo_set_source_color(c, &sc3);
-        for(int gn = 0; lg->source->get_dot(lg->source_id, gn, x, y, size = 3, c); gn++)
+        for(int gn = 0; lg->source->get_dot(lg->source_id, gn, x, y, size = 3, &cimpl); gn++)
         {
             int yv = (int)(oy + sy / 2 - (sy / 2 - 1) * y);
             cairo_arc(c, ox + x * sx, yv, size, 0, 2 * M_PI);
diff --git a/src/modules_dsp.cpp b/src/modules_dsp.cpp
index 8e7a1a2..96d9fcb 100644
--- a/src/modules_dsp.cpp
+++ b/src/modules_dsp.cpp
@@ -26,27 +26,26 @@
 #endif
 #include <calf/giface.h>
 #include <calf/modules.h>
-#include <cairo/cairo.h>
 
 using namespace dsp;
 using namespace calf_plugins;
 
-static void set_channel_color(cairo_t *context, int channel)
+static void set_channel_color(cairo_iface *context, int channel)
 {
     if (channel & 1)
-        cairo_set_source_rgb(context, 0.75, 1, 0);
+        context->set_source_rgba(0.75, 1, 0);
     else
-        cairo_set_source_rgb(context, 0, 1, 0.75);
+        context->set_source_rgba(0, 1, 0.75);
 }
 
-static bool get_freq_gridline(int subindex, float &pos, bool &vertical, cairo_t *context)
+static bool get_freq_gridline(int subindex, float &pos, bool &vertical, cairo_iface *context)
 {
     float gain = 16.0 / (1 << subindex);
     pos = log(gain) / log(1024.0) + 0.5;
     if (pos < -1)
         return false;
     if (subindex != 4)
-        cairo_set_source_rgba(context, 0.25, 0.25, 0.25, 0.5);
+        context->set_source_rgba(0.25, 0.25, 0.25, 0.5);
     vertical = false;
     return true;
 }
@@ -71,7 +70,7 @@ void flanger_audio_module::deactivate() {
     is_active = false;
 }
 
-bool flanger_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_t *context)
+bool flanger_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_iface *context)
 {
     if (!is_active)
         return false;
@@ -88,7 +87,7 @@ float flanger_audio_module::freq_gain(int subindex, float freq, float srate)
     return (subindex ? right : left).freq_gain(freq, srate);                
 }
 
-bool flanger_audio_module::get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_t *context)
+bool flanger_audio_module::get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_iface *context)
 {
     if (index == par_delay)
         return get_freq_gridline(subindex, pos, vertical, context);
@@ -161,7 +160,7 @@ void filter_audio_module::set_sample_rate(uint32_t sr)
     srate = sr;
 }
 
-bool filter_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_t *context)
+bool filter_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_iface *context)
 {
     if (!is_active)
         return false;
@@ -178,7 +177,7 @@ float filter_audio_module::freq_gain(int subindex, float freq, float srate)
     return level;
 }
 
-bool filter_audio_module::get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_t *context)
+bool filter_audio_module::get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_iface *context)
 {
     if (index == par_cutoff)
         return get_freq_gridline(subindex, pos, vertical, context);
@@ -257,7 +256,7 @@ void multichorus_audio_module::set_sample_rate(uint32_t sr) {
     right.setup(sr);
 }
 
-bool multichorus_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_t *context)
+bool multichorus_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_iface *context)
 {
     if (!is_active)
         return false;
@@ -274,7 +273,7 @@ bool multichorus_audio_module::get_graph(int index, int subindex, float *data, i
     return false;
 }
 
-bool multichorus_audio_module::get_dot(int index, int subindex, float &x, float &y, int &size, cairo_t *context)
+bool multichorus_audio_module::get_dot(int index, int subindex, float &x, float &y, int &size, cairo_iface *context)
 {
     if ((index != par_rate && index != par_depth) || subindex >= 2 * (int)*params[par_voices])
         return false;
@@ -295,7 +294,7 @@ bool multichorus_audio_module::get_dot(int index, int subindex, float &x, float
     return true;
 }
 
-bool multichorus_audio_module::get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_t *context)
+bool multichorus_audio_module::get_gridline(int index, int subindex, float &pos, bool &vertical, cairo_iface *context)
 {
     if (index == par_rate && !subindex)
     {
diff --git a/src/monosynth.cpp b/src/monosynth.cpp
index ef92c51..1726f70 100644
--- a/src/monosynth.cpp
+++ b/src/monosynth.cpp
@@ -161,7 +161,7 @@ void monosynth_audio_module::generate_waves()
     waves[wave_test8].make(bl, data);
 }
 
-bool monosynth_audio_module::get_static_graph(int index, int subindex, float value, float *data, int points, cairo_t *context)
+bool monosynth_audio_module::get_static_graph(int index, int subindex, float value, float *data, int points, cairo_iface *context)
 {
     monosynth_audio_module::generate_waves();
     if (index == par_wave1 || index == par_wave2) {
@@ -178,7 +178,7 @@ bool monosynth_audio_module::get_static_graph(int index, int subindex, float val
     return false;
 }
 
-bool monosynth_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_t *context)
+bool monosynth_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_iface *context)
 {
     monosynth_audio_module::generate_waves();
     // printf("get_graph %d %p %d wave1=%d wave2=%d\n", index, data, points, wave1, wave2);
diff --git a/src/organ.cpp b/src/organ.cpp
index dee9b74..da58108 100644
--- a/src/organ.cpp
+++ b/src/organ.cpp
@@ -36,7 +36,7 @@ using namespace calf_plugins;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-bool organ_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_t *context)
+bool organ_audio_module::get_graph(int index, int subindex, float *data, int points, cairo_iface *context)
 {
     if (index == par_master) {
         organ_voice_base::precalculate_waves();

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list