CurveData proposal



   Hi!

As I'd really like to add a curve to the compressor, here is my proposal
for curves. I also attached a patch against artscompressor.cc /
artscompressor.idl, so there is an example how code using this proposal
would look. It compiles here (with some tiny hackery you also see in the
patch, as I #impl-included it into bse.idl).

Some comments:

While it would have been possible to make the proposal n-dimensional
using sequences for axis and point coordinates, as I see no really
practical way to display 3D or even higher dimensional data at the
gui, I left it with x and y. This also has the advantage that a plugin
writer will have a good idea how the corresponding widget will look.

The proposal allows drawing two or more functions into one graph,
because I think there will be scenarios where a filter for instance
displays a "desired" curve (like: an ideal lowpass) and an "achieved"
curve (like: a lowpass with ripples).

When it comes to editing, there is probably room for improvement, as
maybe if there are two functions in one graph, one of them might be
editable and one not. In fact, I didn't think too much about editing at
all yet, so when it comes to this, the proposal doesn't say much.

I wasn't so sure about whether the CurveData should be containing
colors. Since obviously, which colors might make sense might depend on
the users theme, I ommitted this part.

Finally, I choose not to open a subnamespace, although there are some
curve related data structures now; prefixing them with Curve seemed to
be okay. Not sure whether it should be Curve or Graph.

   Cu... Stefan
-- 
  -* Stefan Westerfeld, stefan space twc de (PGP!), Hamburg/Germany
     KDE Developer, project infos at http://space.twc.de/~stefan/kde *-         
/* BSE - Bedevilled Sound Engine                        -*-mode: c++;-*-
 * Copyright (C) 2004 Stefan Westerfeld
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

/*
 * module for drawing curves
 */

namespace Bse {
using namespace Sfi;

record CurvePoint {
  Real x;
  Real y;
};

sequence CurvePointSeq {
  CurvePoint points;
};

choice CurveStyle 
{
  CURVE_STYLE_DOTS,
  CURVE_STYLE_LINE
};

record CurveFunction {
  /*
   * how this function is called
   */
  String label;

  /*
   * the style to use to draw this function
   */
  CurveStyle style;

  /*
   * the points of this function
   */
  CurvePointSeq points;
};

sequence CurveFunctionSeq {
  CurveFunction functions;
};

record CurveData {
  /*
   * the x-Axis
   */
  String	    x_axis_label;
  Real		    x_min;
  Real              x_max;

  /*
   * the y-Axis
   */
  String	    y_axis_label;
  Real		    y_min;
  Real              y_max;

  /*
   * the functions to draw in this diagram
   */
  CurveFunctionSeq  functions;
};

};
Index: artscompressor.cc
===================================================================
RCS file: /cvs/gnome/beast/plugins/artscompressor.cc,v
retrieving revision 1.6
diff -u -r1.6 artscompressor.cc
--- artscompressor.cc	15 Sep 2004 14:49:19 -0000	1.6
+++ artscompressor.cc	15 Sep 2004 16:59:11 -0000
@@ -17,6 +17,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  */
+#define BSE_PATH_USER_DATA
+#include <bse/bsecore.gen-idl.h>
 #include "artscompressor.gen-idl.h"
 
 #include <math.h>
@@ -181,6 +183,7 @@
 	    /* keep CLAMP range in sync with .idl file */
 	    output_db = CLAMP ((threshold_db / ratio_to_one - threshold_db) * MUG_CORR_FACT, -20.0, 20.0);
 	  }
+	update_characteristic();
         notify ("output_db");
         break;
       /* compat properties */
@@ -189,17 +192,52 @@
 	  set ("ratio_to_one", 1 / ratio, NULL);
 	else
 	  set ("ratio_to_one", 20.0, NULL); /* max ratio */
+	update_characteristic();
 	break;
       case PROP_THRESHOLD:
 	/* keep CLAMP range in sync with .idl file */
         set ("threshold_db", CLAMP (bse_db_from_factor (threshold, -100), -100.0, 0.0), NULL);
+	update_characteristic();
         break;
       case PROP_OUTPUT:
 	/* keep CLAMP range in sync with .idl file */
         set ("output_db", CLAMP (bse_db_from_factor (output, -100), -20.0, 20.0), NULL);
+	update_characteristic();
         break;
       default: ;
       }
+  }
+  void update_characteristic()
+  {
+    characteristic = Sfi::INIT_DEFAULT;
+
+    characteristic->x_axis_label = _("input signal volume [dB]");
+    characteristic->x_min = -100;
+    characteristic->x_max = 0;
+
+    characteristic->y_axis_label = _("output signal volume [dB]");
+    characteristic->y_min = -100;
+    characteristic->y_max = 0;
+
+    Bse::CurveFunctionHandle function = Sfi::INIT_DEFAULT;
+    characteristic->functions += function;
+
+    function->label = _("compressor characteristic");
+    function->style = CURVE_STYLE_LINE;
+    function->points.resize (100);
+
+    double ratio = 1 / ratio_to_one;
+    for (int i = 0; i <= 100; i++)
+      {
+	Bse::CurvePointHandle point = Sfi::INIT_DEFAULT;
+
+	double in_db = 100 - i;
+	point->x = in_db;
+	point->y = in_db >= threshold_db ? (in_db - threshold_db) * ratio + in_db : in_db;
+
+	function->points += point;
+      }
+    notify ("characteristic");
   }
   BSE_EFFECT_INTEGRATE_MODULE (Compressor, Module, CompressorProperties);
 };
Index: artscompressor.idl
===================================================================
RCS file: /cvs/gnome/beast/plugins/artscompressor.idl,v
retrieving revision 1.13
diff -u -r1.13 artscompressor.idl
--- artscompressor.idl	15 Sep 2004 14:49:19 -0000	1.13
+++ artscompressor.idl	15 Sep 2004 16:59:14 -0000
@@ -20,6 +20,7 @@
 #include <bse/bse.idl>
 
 namespace Bse {
+
 namespace Arts {
 
 class Compressor : Effect {
@@ -59,6 +60,7 @@
     Real ratio_to_one = Real (_("Ratio [x:1]"), _("Set the compression ratio to x:1"), 2, 1.0, 20.0, 1, STANDARD ":scale");
     Real output_db    = Gain (_("Output [dB]"), _("Set the output amplification"), 0, -20, 20, 1, STANDARD ":scale");
     Bool auto_output  = Bool (_("Auto Output"), _("Adjust the output amplification automatically"), FALSE, SFI_PARAM_GUI);
+    CurveData characteristic;
   };
   group "compat" {    /* compatibility properties */
     Real threshold    = Real (NULL, NULL, 1, 0.00001, 1, 0.01, "w");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]