Пример #1
0
static double
qof_gobject_double_getter (gpointer data, QofParam *getter)
{
    GObject *gob = data;
    double fval;

    GParamSpec *gps = getter->param_userdata;

    /* Note that the return type must actually be of type
     * getter->param_type but we just follow the hard-coded
     * mapping below ... */
    if (G_IS_PARAM_SPEC_FLOAT(gps))
    {
        GValue gval = {G_TYPE_INVALID};
        g_value_init (&gval, G_TYPE_FLOAT);
        g_object_get_property (gob, getter->param_name, &gval);

        fval = g_value_get_float (&gval);
        return fval;
    }
    else if (G_IS_PARAM_SPEC_DOUBLE(gps))
    {
        GValue gval = {G_TYPE_INVALID};
        g_value_init (&gval, G_TYPE_DOUBLE);
        g_object_get_property (gob, getter->param_name, &gval);

        fval = g_value_get_double (&gval);
        return fval;
    }

    PWARN ("unhandled parameter type %s for paramter %s",
           G_PARAM_SPEC_TYPE_NAME(gps), getter->param_name);
    return 0.0;
}
Пример #2
0
static gpointer
qof_gobject_getter (gpointer data, QofParam *getter)
{
    GObject *gob = data;
    const char *str;

    GParamSpec *gps = getter->param_userdata;

    /* Note that the return type must actually be of type
     * getter->param_type but we just follow the hard-coded
     * mapping below ... */
    if (G_IS_PARAM_SPEC_STRING(gps))
    {
        GValue gval = {G_TYPE_INVALID};
        g_value_init (&gval, G_TYPE_STRING);
        g_object_get_property (gob, getter->param_name, &gval);

        str = g_value_get_string (&gval);
        return (gpointer) str;
    }
    else if (G_IS_PARAM_SPEC_INT(gps))
    {
        long ival;

        GValue gval = {G_TYPE_INVALID};
        g_value_init (&gval, G_TYPE_INT);
        g_object_get_property (gob, getter->param_name, &gval);

        ival = g_value_get_int (&gval);
        return (gpointer) ival;
    }
    else if (G_IS_PARAM_SPEC_UINT(gps))
    {
        long ival;
        GValue gval = {G_TYPE_INVALID};
        g_value_init (&gval, G_TYPE_UINT);
        g_object_get_property (gob, getter->param_name, &gval);

        ival = g_value_get_uint (&gval);
        return (gpointer) ival;
    }
    else if (G_IS_PARAM_SPEC_BOOLEAN(gps))
    {
        gboolean ival;

        GValue gval = {G_TYPE_INVALID};
        g_value_init (&gval, G_TYPE_BOOLEAN);
        g_object_get_property (gob, getter->param_name, &gval);

        ival = g_value_get_boolean (&gval);
        return GINT_TO_POINTER( ival);
    }

    PWARN ("unhandled parameter type %s for paramter %s",
           G_PARAM_SPEC_TYPE_NAME(gps), getter->param_name);
    return NULL;
}
Пример #3
0
static GiggleGitConfigBinding *
giggle_git_config_binding_new (GiggleGitConfig      *config,
			       GiggleGitConfigField  field,
			       GObject              *object,
			       GParamSpec           *pspec)
{
	GiggleGitConfigBinding *binding;

	binding = g_slice_new0 (GiggleGitConfigBinding);
	binding->config = config;
	binding->field = field;
	binding->object = object;
	binding->pspec = pspec;

	g_object_add_weak_pointer (G_OBJECT (binding->config),
				   (gpointer) &binding->config);
	g_object_add_weak_pointer (G_OBJECT (binding->object),
				   (gpointer) &binding->object);

	if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (pspec), G_TYPE_INT)) {
		binding->update = giggle_git_config_int_binding_update;
		binding->commit = giggle_git_config_int_binding_commit;
	} else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (pspec), G_TYPE_STRING)) {
		binding->update = giggle_git_config_string_binding_update;
		binding->commit = giggle_git_config_string_binding_commit;
	} else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (pspec), G_TYPE_BOOLEAN)) {
		binding->update = giggle_git_config_boolean_binding_update;
		binding->commit = giggle_git_config_boolean_binding_commit;
	} else {
		g_critical ("%s: unsupported property type `%s' for \"%s\" of `%s'",
			    G_STRFUNC, G_PARAM_SPEC_TYPE_NAME (pspec),
			    pspec->name, G_OBJECT_TYPE_NAME (object));

		giggle_git_config_binding_free (binding);
		binding = NULL;
	}

	return binding;
}
Пример #4
0
static void
gimp_operation_tool_color_picked (GimpImageMapTool  *im_tool,
                                  gpointer           identifier,
                                  gdouble            x,
                                  gdouble            y,
                                  const Babl        *sample_format,
                                  const GimpRGB     *color)
{
    GimpOperationTool  *tool = GIMP_OPERATION_TOOL (im_tool);
    gchar             **pspecs;

    pspecs = g_strsplit (identifier, ":", 2);

    if (pspecs[1])
    {
        GimpImageMapOptions *options      = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (tool);
        GimpDrawable        *drawable     = GIMP_TOOL (im_tool)->drawable;
        GObjectClass        *object_class = G_OBJECT_GET_CLASS (im_tool->config);
        GParamSpec          *pspec_x;
        GParamSpec          *pspec_y;
        gint                 width        = 1;
        gint                 height       = 1;

        if (drawable)
        {
            gint off_x, off_y;

            gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);

            x -= off_x;
            y -= off_y;

            switch (options->region)
            {
            case GIMP_IMAGE_MAP_REGION_SELECTION:
                if (gimp_item_mask_intersect (GIMP_ITEM (drawable),
                                              &off_x, &off_y, &width, &height))
                {
                    x -= off_x;
                    y -= off_y;
                }
                break;

            case GIMP_IMAGE_MAP_REGION_DRAWABLE:
                width  = gimp_item_get_width  (GIMP_ITEM (drawable));
                height = gimp_item_get_height (GIMP_ITEM (drawable));
                break;
            }
        }

        pspec_x = g_object_class_find_property (object_class, pspecs[0]);
        pspec_y = g_object_class_find_property (object_class, pspecs[1]);

        if (pspec_x && pspec_y &&
                G_PARAM_SPEC_TYPE (pspec_x) == G_PARAM_SPEC_TYPE (pspec_y))
        {
            GValue value_x = G_VALUE_INIT;
            GValue value_y = G_VALUE_INIT;

            g_value_init (&value_x, G_PARAM_SPEC_VALUE_TYPE (pspec_x));
            g_value_init (&value_y, G_PARAM_SPEC_VALUE_TYPE (pspec_y));

#define HAS_KEY(p,k,v) gimp_gegl_param_spec_has_key (p, k, v)

            if (HAS_KEY (pspec_x, "unit", "relative-coordinate") &&
                    HAS_KEY (pspec_y, "unit", "relative-coordinate"))
            {
                x /= (gdouble) width;
                y /= (gdouble) height;
            }

            if (G_IS_PARAM_SPEC_INT (pspec_x))
            {
                g_value_set_int (&value_x, x);
                g_value_set_int (&value_y, y);

                g_param_value_validate (pspec_x, &value_x);
                g_param_value_validate (pspec_y, &value_y);

                g_object_set (im_tool->config,
                              pspecs[0], g_value_get_int (&value_x),
                              pspecs[1], g_value_get_int (&value_y),
                              NULL);
            }
            else if (G_IS_PARAM_SPEC_DOUBLE (pspec_x))
            {
                g_value_set_double (&value_x, x);
                g_value_set_double (&value_y, y);

                g_param_value_validate (pspec_x, &value_x);
                g_param_value_validate (pspec_y, &value_y);

                g_object_set (im_tool->config,
                              pspecs[0], g_value_get_double (&value_x),
                              pspecs[1], g_value_get_double (&value_y),
                              NULL);
            }
            else
            {
                g_warning ("%s: unhandled param spec of type %s",
                           G_STRFUNC, G_PARAM_SPEC_TYPE_NAME (pspec_x));
            }

            g_value_unset (&value_x);
            g_value_unset (&value_y);
        }
    }
    else
    {
        g_object_set (im_tool->config,
                      pspecs[0], color,
                      NULL);
    }

    g_strfreev (pspecs);
}
Пример #5
0
/**
 * g_strdup_value_contents:
 * @value: #GValue which contents are to be described.
 *
 * Return a newly allocated string, which describes the contents of a
 * #GValue.  The main purpose of this function is to describe #GValue
 * contents for debugging output, the way in which the contents are
 * described may change between different GLib versions.
 *
 * Returns: Newly allocated string.
 */
gchar*
g_strdup_value_contents (const GValue *value)
{
  const gchar *src;
  gchar *contents;

  g_return_val_if_fail (G_IS_VALUE (value), NULL);
  
  if (G_VALUE_HOLDS_STRING (value))
    {
      src = g_value_get_string (value);
      
      if (!src)
	contents = g_strdup ("NULL");
      else
	{
	  gchar *s = g_strescape (src, NULL);

	  contents = g_strdup_printf ("\"%s\"", s);
	  g_free (s);
	}
    }
  else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
    {
      GValue tmp_value = { 0, };
      gchar *s;

      g_value_init (&tmp_value, G_TYPE_STRING);
      g_value_transform (value, &tmp_value);
      s = g_strescape (g_value_get_string (&tmp_value), NULL);
      g_value_unset (&tmp_value);
      if (G_VALUE_HOLDS_ENUM (value) || G_VALUE_HOLDS_FLAGS (value))
	contents = g_strdup_printf ("((%s) %s)",
				    g_type_name (G_VALUE_TYPE (value)),
				    s);
      else
	contents = g_strdup (s ? s : "NULL");
      g_free (s);
    }
  else if (g_value_fits_pointer (value))
    {
      gpointer p = g_value_peek_pointer (value);

      if (!p)
	contents = g_strdup ("NULL");
      else if (G_VALUE_HOLDS_OBJECT (value))
	contents = g_strdup_printf ("((%s*) %p)", G_OBJECT_TYPE_NAME (p), p);
      else if (G_VALUE_HOLDS_PARAM (value))
	contents = g_strdup_printf ("((%s*) %p)", G_PARAM_SPEC_TYPE_NAME (p), p);
      else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
        {
          GStrv strv = g_value_get_boxed (value);
          GString *tmp = g_string_new ("[");

          while (*strv != NULL)
            {
              gchar *escaped = g_strescape (*strv, NULL);

              g_string_append_printf (tmp, "\"%s\"", escaped);
              g_free (escaped);

              if (*++strv != NULL)
                g_string_append (tmp, ", ");
            }

          g_string_append (tmp, "]");
          contents = g_string_free (tmp, FALSE);
        }
      else if (G_VALUE_HOLDS_BOXED (value))
	contents = g_strdup_printf ("((%s*) %p)", g_type_name (G_VALUE_TYPE (value)), p);
      else if (G_VALUE_HOLDS_POINTER (value))
	contents = g_strdup_printf ("((gpointer) %p)", p);
      else
	contents = g_strdup ("???");
    }
  else
    contents = g_strdup ("???");

  return contents;
}
Пример #6
0
std::string
get_property_with_node_name(
  GParamSpec* pParamSpec, const std::string& strObjectName, const std::string& strNodeName)
{
  std::string strResult;

  // Name and type:
  const std::string strName = g_param_spec_get_name(pParamSpec);
  const std::string strTypeName = G_PARAM_SPEC_TYPE_NAME(pParamSpec);

  const gchar* pchBlurb = g_param_spec_get_blurb(pParamSpec);
  std::string strDocs = (pchBlurb) ? pchBlurb : "";
  // Quick hack to get rid of nested double quotes:
  std::replace(strDocs.begin(), strDocs.end(), '"', '\'');

  strResult += "(" + strNodeName + " " + strName + "\n";
  strResult += "  (of-object \"" + strObjectName + "\")\n";
  strResult += "  (prop-type \"" + strTypeName + "\")\n";
  strResult += "  (docs \"" + strDocs + "\")\n";

  // Flags:
  GParamFlags flags = pParamSpec->flags;
  bool bReadable = (flags & G_PARAM_READABLE) == G_PARAM_READABLE;
  bool bWritable = (flags & G_PARAM_WRITABLE) == G_PARAM_WRITABLE;
  bool bConstructOnly = (flags & G_PARAM_CONSTRUCT_ONLY) == G_PARAM_CONSTRUCT_ONLY;
  bool bDeprecated = (flags & G_PARAM_DEPRECATED) == G_PARAM_DEPRECATED;

  //#t and #f aren't documented, but I guess that it's correct based on the example in the .defs
  // spec.
  const std::string strTrue = "#t";
  const std::string strFalse = "#f";

  strResult += "  (readable " + (bReadable ? strTrue : strFalse) + ")\n";
  strResult += "  (writable " + (bWritable ? strTrue : strFalse) + ")\n";
  strResult += "  (construct-only " + (bConstructOnly ? strTrue : strFalse) + ")\n";
  if (bDeprecated)
    strResult += "  (deprecated #t)\n"; // Default: not deprecated

  // Default value:
  const GValue* defValue = g_param_spec_get_default_value(pParamSpec);
  std::string defString;
  bool defValueExists = false;
  if (G_VALUE_HOLDS_STRING(defValue))
  {
    defValueExists = true;
    const char* defCString = g_value_get_string(defValue);
    if (defCString)
    {
      // Replace newlines with \n.
      // A string default value can contain newline characters.
      // gmmproc removes all newlines when it reads .defs files.
      defString = std::regex_replace(defCString, std::regex("\n"), "\\n");
    }
    else
      defString = ""; // A NULL string pointer becomes an empty string.
  }
  else if (G_VALUE_HOLDS_FLOAT(defValue) || G_VALUE_HOLDS_DOUBLE(defValue))
  {
    // g_value_transform() can transform a floating point value to a terrible
    // string, especially if the value is huge.
    defValueExists = true;
    const double defDouble = G_VALUE_HOLDS_FLOAT(defValue) ?
      g_value_get_float(defValue) : g_value_get_double(defValue);
    std::ostringstream defStringStream;
    defStringStream << defDouble;
    defString = defStringStream.str();
  }
  else
  {
    GValue defStringValue = G_VALUE_INIT;
    g_value_init(&defStringValue, G_TYPE_STRING);

    if (g_value_transform(defValue, &defStringValue))
    {
      const char* defCString = g_value_get_string(&defStringValue);
      if (defCString)
      {
        defValueExists = true;
        defString = defCString;
      }
    }
    g_value_unset(&defStringValue);
  }

  if (defValueExists)
    strResult += "  (default-value \"" + defString + "\")\n";

  strResult += ")\n\n"; // close (strNodeName

  return strResult;
}
Пример #7
0
static GObject *
gst_direct_control_binding_constructor (GType type, guint n_construct_params,
    GObjectConstructParam * construct_params)
{
  GstDirectControlBinding *self;

  self =
      GST_DIRECT_CONTROL_BINDING (G_OBJECT_CLASS (parent_class)->constructor
      (type, n_construct_params, construct_params));

  if (GST_CONTROL_BINDING_PSPEC (self)) {
    GType type, base;

    base = type = G_PARAM_SPEC_VALUE_TYPE (GST_CONTROL_BINDING_PSPEC (self));
    g_value_init (&self->cur_value, type);
    while ((type = g_type_parent (type)))
      base = type;

    GST_DEBUG ("  using type %s", g_type_name (base));

    /* select mapping function */
    switch (base) {
      case G_TYPE_INT:
        self->convert_g_value = convert_g_value_to_int;
        self->convert_value = convert_value_to_int;
        self->byte_size = sizeof (gint);
        break;
      case G_TYPE_UINT:
        self->convert_g_value = convert_g_value_to_uint;
        self->convert_value = convert_value_to_uint;
        self->byte_size = sizeof (guint);
        break;
      case G_TYPE_LONG:
        self->convert_g_value = convert_g_value_to_long;
        self->convert_value = convert_value_to_long;
        self->byte_size = sizeof (glong);
        break;
      case G_TYPE_ULONG:
        self->convert_g_value = convert_g_value_to_ulong;
        self->convert_value = convert_value_to_ulong;
        self->byte_size = sizeof (gulong);
        break;
      case G_TYPE_INT64:
        self->convert_g_value = convert_g_value_to_int64;
        self->convert_value = convert_value_to_int64;
        self->byte_size = sizeof (gint64);
        break;
      case G_TYPE_UINT64:
        self->convert_g_value = convert_g_value_to_uint64;
        self->convert_value = convert_value_to_uint64;
        self->byte_size = sizeof (guint64);
        break;
      case G_TYPE_FLOAT:
        self->convert_g_value = convert_g_value_to_float;
        self->convert_value = convert_value_to_float;
        self->byte_size = sizeof (gfloat);
        break;
      case G_TYPE_DOUBLE:
        self->convert_g_value = convert_g_value_to_double;
        self->convert_value = convert_value_to_double;
        self->byte_size = sizeof (gdouble);
        break;
      case G_TYPE_BOOLEAN:
        self->convert_g_value = convert_g_value_to_boolean;
        self->convert_value = convert_value_to_boolean;
        self->byte_size = sizeof (gboolean);
        break;
      case G_TYPE_ENUM:
        self->convert_g_value = convert_g_value_to_enum;
        self->convert_value = convert_value_to_enum;
        self->byte_size = sizeof (gint);
        break;
      default:
        GST_WARNING ("incomplete implementation for paramspec type '%s'",
            G_PARAM_SPEC_TYPE_NAME (GST_CONTROL_BINDING_PSPEC (self)));
        GST_CONTROL_BINDING_PSPEC (self) = NULL;
        break;
    }
  }
  return (GObject *) self;
}
Пример #8
0
void
qof_gobject_register (QofType e_type, GObjectClass *obclass)
{
    int i;
    int j;
    QofParam *qof_param_list, *qpar;
    QofObject *class_def;
    GParamSpec **prop_list, *gparam;
    guint n_props;

    /* Get the GObject properties, convert to QOF properties */
    prop_list = g_object_class_list_properties (obclass, &n_props);

    qof_param_list = g_new0 (QofParam, n_props);
    paramList = g_slist_prepend (paramList, qof_param_list);

    PINFO ("object %s has %d props", e_type, n_props);
    j = 0;
    for (i = 0; i < n_props; i++)
    {
        gparam = prop_list[i];
        qpar = &qof_param_list[j];

        PINFO ("param %d %s is type %s",
               i, gparam->name, G_PARAM_SPEC_TYPE_NAME(gparam));

        qpar->param_name = g_param_spec_get_name (gparam);
        qpar->param_getfcn = (QofAccessFunc)qof_gobject_getter;
        qpar->param_setfcn = NULL;
        qpar->param_userdata = gparam;
        if ((G_IS_PARAM_SPEC_INT(gparam))  ||
                (G_IS_PARAM_SPEC_UINT(gparam)) ||
                (G_IS_PARAM_SPEC_ENUM(gparam)) ||
                (G_IS_PARAM_SPEC_FLAGS(gparam)))
        {
            qpar->param_type = QOF_TYPE_INT32;
            j++;
        }
        else if ((G_IS_PARAM_SPEC_INT64(gparam)) ||
                 (G_IS_PARAM_SPEC_UINT64(gparam)))
        {
            qpar->param_type = QOF_TYPE_INT64;
            j++;
        }
        else if (G_IS_PARAM_SPEC_BOOLEAN(gparam))
        {
            qpar->param_type = QOF_TYPE_BOOLEAN;
            j++;
        }
        else if (G_IS_PARAM_SPEC_STRING(gparam))
        {
            qpar->param_type = QOF_TYPE_STRING;
            j++;
        }
        else if ((G_IS_PARAM_SPEC_POINTER(gparam)) ||
                 (G_IS_PARAM_SPEC_OBJECT(gparam)))
        {
            /* No-op, silently ignore.  Someday we should handle this ...  */
        }
        else if ((G_IS_PARAM_SPEC_FLOAT(gparam)) ||
                 (G_IS_PARAM_SPEC_DOUBLE(gparam)))
        {
            qpar->param_getfcn = (QofAccessFunc) qof_gobject_double_getter;
            qpar->param_type = QOF_TYPE_DOUBLE;
            j++;
        }
        else if (G_IS_PARAM_SPEC_CHAR(gparam))
        {
            qpar->param_type = QOF_TYPE_CHAR;
            j++;
        }
        else
        {
            PWARN ("Unknown/unhandled parameter type %s on %s:%s\n",
                   G_PARAM_SPEC_TYPE_NAME(gparam), e_type, qpar->param_name);
        }
    }

    /* NULL-terminated list! */
    qof_param_list[j].param_type = NULL;

    qof_class_register (e_type, NULL, qof_param_list);

    /* ------------------------------------------------------ */
    /* Now do the class itself */
    class_def = g_new0 (QofObject, 1);
    classList = g_slist_prepend (classList, class_def);

    class_def->interface_version = QOF_OBJECT_VERSION;
    class_def->e_type = e_type;
    /* We could let the user specify a "nick" here, but
     * the actual class name seems reasonable, e.g. for debugging. */
    class_def->type_label = G_OBJECT_CLASS_NAME (obclass);
    class_def->create = NULL;
    class_def->book_begin = NULL;
    class_def->book_end = NULL;
    class_def->is_dirty = NULL;
    class_def->mark_clean = NULL;
    class_def->foreach = qof_gobject_foreach;
    class_def->printable = NULL;
    class_def->version_cmp = NULL;

    qof_object_register (class_def);
}
/**
 * gst_control_binding_get_g_value_array:
 * @binding: the control binding
 * @timestamp: the time that should be processed
 * @interval: the time spacing between subsequent values
 * @n_values: the number of values
 * @values: array to put control-values in
 *
 * Gets a number of #GValues for the given controlled property starting at the
 * requested time. The array @values need to hold enough space for @n_values of
 * #GValue.
 *
 * This function is useful if one wants to e.g. draw a graph of the control
 * curve or apply a control curve sample by sample.
 *
 * Returns: %TRUE if the given array could be filled, %FALSE otherwise
 */
gboolean
gst_control_binding_get_g_value_array (GstControlBinding * binding,
    GstClockTime timestamp, GstClockTime interval, guint n_values,
    GValue * values)
{
  GstControlBindingClass *klass;
  gboolean ret = FALSE;

  g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), FALSE);
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE);
  g_return_val_if_fail (values, FALSE);

  klass = GST_CONTROL_BINDING_GET_CLASS (binding);

  if (G_LIKELY (klass->get_g_value_array != NULL)) {
    ret =
        klass->get_g_value_array (binding, timestamp, interval, n_values,
        values);
  } else {
    guint i;
    GType type, base;

    base = type = G_PARAM_SPEC_VALUE_TYPE (GST_CONTROL_BINDING_PSPEC (binding));
    while ((type = g_type_parent (type)))
      base = type;

    GST_INFO_OBJECT (binding, "missing get_g_value_array implementation, we're "
        "emulating it");
    switch (base) {
      case G_TYPE_INT:
        CONVERT_ARRAY (int, INT);
        break;
      case G_TYPE_UINT:
        CONVERT_ARRAY (uint, UINT);
        break;
      case G_TYPE_LONG:
        CONVERT_ARRAY (long, LONG);
        break;
      case G_TYPE_ULONG:
        CONVERT_ARRAY (ulong, ULONG);
        break;
      case G_TYPE_INT64:
        CONVERT_ARRAY (int64, INT64);
        break;
      case G_TYPE_UINT64:
        CONVERT_ARRAY (uint64, UINT64);
        break;
      case G_TYPE_FLOAT:
        CONVERT_ARRAY (float, FLOAT);
        break;
      case G_TYPE_DOUBLE:
        CONVERT_ARRAY (double, DOUBLE);
        break;
      case G_TYPE_BOOLEAN:
        CONVERT_ARRAY (boolean, BOOLEAN);
        break;
      case G_TYPE_ENUM:
      {
        gint *v = g_new (gint, n_values);
        ret = gst_control_binding_get_value_array (binding, timestamp, interval,
            n_values, v);
        if (ret) {
          for (i = 0; i < n_values; i++) {
            g_value_init (&values[i], type);
            g_value_set_enum (&values[i], v[i]);
          }
        }
        g_free (v);
      }
        break;
      default:
        GST_WARNING ("incomplete implementation for paramspec type '%s'",
            G_PARAM_SPEC_TYPE_NAME (GST_CONTROL_BINDING_PSPEC (binding)));
        GST_CONTROL_BINDING_PSPEC (binding) = NULL;
        break;
    }
  }
  return ret;
}
Пример #10
0
static void
gimp_operation_tool_color_picked (GimpFilterTool  *filter_tool,
                                  gpointer         identifier,
                                  gdouble          x,
                                  gdouble          y,
                                  const Babl      *sample_format,
                                  const GimpRGB   *color)
{
  gchar **pspecs = g_strsplit (identifier, ":", 2);

  if (pspecs[1])
    {
      GObjectClass  *object_class = G_OBJECT_GET_CLASS (filter_tool->config);
      GParamSpec    *pspec_x;
      GParamSpec    *pspec_y;
      gint           off_x, off_y;
      GeglRectangle  area;

      gimp_filter_tool_get_drawable_area (filter_tool, &off_x, &off_y, &area);

      x -= off_x + area.x;
      y -= off_y + area.y;

      pspec_x = g_object_class_find_property (object_class, pspecs[0]);
      pspec_y = g_object_class_find_property (object_class, pspecs[1]);

      if (pspec_x && pspec_y &&
          G_PARAM_SPEC_TYPE (pspec_x) == G_PARAM_SPEC_TYPE (pspec_y))
        {
          GValue value_x = G_VALUE_INIT;
          GValue value_y = G_VALUE_INIT;

          g_value_init (&value_x, G_PARAM_SPEC_VALUE_TYPE (pspec_x));
          g_value_init (&value_y, G_PARAM_SPEC_VALUE_TYPE (pspec_y));

#define HAS_KEY(p,k,v) gimp_gegl_param_spec_has_key (p, k, v)

          if (HAS_KEY (pspec_x, "unit", "relative-coordinate") &&
              HAS_KEY (pspec_y, "unit", "relative-coordinate"))
            {
              x /= (gdouble) area.width;
              y /= (gdouble) area.height;
            }

          if (G_IS_PARAM_SPEC_INT (pspec_x))
            {
              g_value_set_int (&value_x, x);
              g_value_set_int (&value_y, y);

              g_param_value_validate (pspec_x, &value_x);
              g_param_value_validate (pspec_y, &value_y);

              g_object_set (filter_tool->config,
                            pspecs[0], g_value_get_int (&value_x),
                            pspecs[1], g_value_get_int (&value_y),
                            NULL);
            }
          else if (G_IS_PARAM_SPEC_DOUBLE (pspec_x))
            {
              g_value_set_double (&value_x, x);
              g_value_set_double (&value_y, y);

              g_param_value_validate (pspec_x, &value_x);
              g_param_value_validate (pspec_y, &value_y);

              g_object_set (filter_tool->config,
                            pspecs[0], g_value_get_double (&value_x),
                            pspecs[1], g_value_get_double (&value_y),
                            NULL);
            }
          else
            {
              g_warning ("%s: unhandled param spec of type %s",
                         G_STRFUNC, G_PARAM_SPEC_TYPE_NAME (pspec_x));
            }

          g_value_unset (&value_x);
          g_value_unset (&value_y);
        }
    }
  else
    {
      g_object_set (filter_tool->config,
                    pspecs[0], color,
                    NULL);
    }

  g_strfreev (pspecs);
}
Пример #11
0
static gboolean
gst_lfo_control_source_bind (GstControlSource * source, GParamSpec * pspec)
{
  GType type, base;
  GstLFOControlSource *self = GST_LFO_CONTROL_SOURCE (source);
  gboolean ret = TRUE;

  /* get the fundamental base type */
  self->priv->type = base = type = G_PARAM_SPEC_VALUE_TYPE (pspec);
  while ((type = g_type_parent (type)))
    base = type;

  self->priv->base = base;
  /* restore type */
  type = self->priv->type;

  switch (base) {
    case G_TYPE_INT:{
      GParamSpecInt *tpspec = G_PARAM_SPEC_INT (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_int (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_int (&self->priv->maximum_value, tpspec->maximum);

      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_int (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_int (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_UINT:{
      GParamSpecUInt *tpspec = G_PARAM_SPEC_UINT (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_uint (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_uint (&self->priv->maximum_value, tpspec->maximum);

      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_uint (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_uint (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_LONG:{
      GParamSpecLong *tpspec = G_PARAM_SPEC_LONG (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_long (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_long (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_long (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_long (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_ULONG:{
      GParamSpecULong *tpspec = G_PARAM_SPEC_ULONG (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_ulong (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_ulong (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_ulong (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_ulong (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_INT64:{
      GParamSpecInt64 *tpspec = G_PARAM_SPEC_INT64 (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_int64 (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_int64 (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_int64 (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_int64 (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_UINT64:{
      GParamSpecUInt64 *tpspec = G_PARAM_SPEC_UINT64 (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_uint64 (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_uint64 (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_uint64 (&self->priv->amplitude, 0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_uint64 (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_FLOAT:{
      GParamSpecFloat *tpspec = G_PARAM_SPEC_FLOAT (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_float (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_float (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_float (&self->priv->amplitude, 0.0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_float (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    case G_TYPE_DOUBLE:{
      GParamSpecDouble *tpspec = G_PARAM_SPEC_DOUBLE (pspec);

      g_value_init (&self->priv->minimum_value, type);
      g_value_set_double (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_double (&self->priv->maximum_value, tpspec->maximum);
      if (!G_IS_VALUE (&self->priv->amplitude)) {
        g_value_init (&self->priv->amplitude, type);
        g_value_set_float (&self->priv->amplitude, 0.0);
      }

      if (!G_IS_VALUE (&self->priv->offset)) {
        g_value_init (&self->priv->offset, type);
        g_value_set_float (&self->priv->offset, tpspec->default_value);
      }
      break;
    }
    default:
      GST_WARNING ("incomplete implementation for paramspec type '%s'",
          G_PARAM_SPEC_TYPE_NAME (pspec));
      ret = FALSE;
      break;
  }

  if (ret) {
    GValue amp = { 0, }
    , off = {
    0,};

    /* This should never fail unless the user already set amplitude or offset
     * with an incompatible type before _bind () */
    if (!g_value_type_transformable (G_VALUE_TYPE (&self->priv->amplitude),
            base)
        || !g_value_type_transformable (G_VALUE_TYPE (&self->priv->offset),
            base)) {
      GST_WARNING ("incompatible types for amplitude or offset");
      gst_lfo_control_source_reset (self);
      return FALSE;
    }

    /* Generate copies and transform to the correct type */
    g_value_init (&amp, base);
    g_value_transform (&self->priv->amplitude, &amp);
    g_value_init (&off, base);
    g_value_transform (&self->priv->offset, &off);

    ret = gst_lfo_control_source_set_waveform (self, self->priv->waveform);

    g_value_unset (&self->priv->amplitude);
    g_value_init (&self->priv->amplitude, self->priv->base);
    g_value_transform (&amp, &self->priv->amplitude);

    g_value_unset (&self->priv->offset);
    g_value_init (&self->priv->offset, self->priv->base);
    g_value_transform (&off, &self->priv->offset);

    g_value_unset (&amp);
    g_value_unset (&off);
  }

  if (!ret)
    gst_lfo_control_source_reset (self);

  return ret;
}
Пример #12
0
static gboolean
gst_interpolation_control_source_bind (GstControlSource * source,
    GParamSpec * pspec)
{
  GType type, base;
  GstInterpolationControlSource *self =
      GST_INTERPOLATION_CONTROL_SOURCE (source);
  gboolean ret = TRUE;

  /* get the fundamental base type */
  self->priv->type = base = type = G_PARAM_SPEC_VALUE_TYPE (pspec);
  while ((type = g_type_parent (type)))
    base = type;

  self->priv->base = base;
  /* restore type */
  type = self->priv->type;

  if (!gst_interpolation_control_source_set_interpolation_mode (self,
          self->priv->interpolation_mode))
    return FALSE;

  switch (base) {
    case G_TYPE_INT:{
      GParamSpecInt *tpspec = G_PARAM_SPEC_INT (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_int (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_int (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_int (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_UINT:{
      GParamSpecUInt *tpspec = G_PARAM_SPEC_UINT (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_uint (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_uint (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_uint (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_LONG:{
      GParamSpecLong *tpspec = G_PARAM_SPEC_LONG (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_long (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_long (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_long (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_ULONG:{
      GParamSpecULong *tpspec = G_PARAM_SPEC_ULONG (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_ulong (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_ulong (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_ulong (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_INT64:{
      GParamSpecInt64 *tpspec = G_PARAM_SPEC_INT64 (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_int64 (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_int64 (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_int64 (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_UINT64:{
      GParamSpecUInt64 *tpspec = G_PARAM_SPEC_UINT64 (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_uint64 (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_uint64 (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_uint64 (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_FLOAT:{
      GParamSpecFloat *tpspec = G_PARAM_SPEC_FLOAT (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_float (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_float (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_float (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_DOUBLE:{
      GParamSpecDouble *tpspec = G_PARAM_SPEC_DOUBLE (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_double (&self->priv->default_value, tpspec->default_value);
      g_value_init (&self->priv->minimum_value, type);
      g_value_set_double (&self->priv->minimum_value, tpspec->minimum);
      g_value_init (&self->priv->maximum_value, type);
      g_value_set_double (&self->priv->maximum_value, tpspec->maximum);
      break;
    }
    case G_TYPE_BOOLEAN:{
      GParamSpecBoolean *tpspec = G_PARAM_SPEC_BOOLEAN (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_boolean (&self->priv->default_value, tpspec->default_value);
      break;
    }
    case G_TYPE_ENUM:{
      GParamSpecEnum *tpspec = G_PARAM_SPEC_ENUM (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_enum (&self->priv->default_value, tpspec->default_value);
      break;
    }
    case G_TYPE_STRING:{
      GParamSpecString *tpspec = G_PARAM_SPEC_STRING (pspec);

      g_value_init (&self->priv->default_value, type);
      g_value_set_string (&self->priv->default_value, tpspec->default_value);
      break;
    }
    default:
      GST_WARNING ("incomplete implementation for paramspec type '%s'",
          G_PARAM_SPEC_TYPE_NAME (pspec));
      ret = FALSE;
      break;
  }

  if (ret) {
    self->priv->valid_cache = FALSE;
    self->priv->nvalues = 0;
  } else {
    gst_interpolation_control_source_reset (self);
  }

  return ret;
}
Пример #13
0
static GObject *
gstbt_direct_control_binding_constructor (GType type, guint n_construct_params,
    GObjectConstructParam * construct_params)
{
  GstBtDirectControlBinding *self;

  self =
      GSTBT_DIRECT_CONTROL_BINDING (G_OBJECT_CLASS (parent_class)->constructor
      (type, n_construct_params, construct_params));

  if (GST_CONTROL_BINDING_PSPEC (self)) {
    GType type, base;

    base = type = G_PARAM_SPEC_VALUE_TYPE (GST_CONTROL_BINDING_PSPEC (self));
    g_value_init (&self->cur_value, type);
    while ((type = g_type_parent (type)))
      base = type;

    GST_DEBUG ("  using type %s", g_type_name (base));

    /* select mapping function */

#define SET_CONVERT_FUNCTION(type) \
    if (self->ABI.abi.want_absolute) { \
        self->convert_g_value = abs_convert_g_value_to_##type; \
        self->convert_value = abs_convert_value_to_##type; \
    } \
    else { \
        self->convert_g_value = convert_g_value_to_##type; \
        self->convert_value = convert_value_to_##type; \
    } \
    self->byte_size = sizeof (g##type);


    switch (base) {
      case G_TYPE_INT:
        SET_CONVERT_FUNCTION (int);
        break;
      case G_TYPE_UINT:
        SET_CONVERT_FUNCTION (uint);
        break;
      case G_TYPE_LONG:
        SET_CONVERT_FUNCTION (long);
        break;
      case G_TYPE_ULONG:
        SET_CONVERT_FUNCTION (ulong);
        break;
      case G_TYPE_INT64:
        SET_CONVERT_FUNCTION (int64);
        break;
      case G_TYPE_UINT64:
        SET_CONVERT_FUNCTION (uint64);
        break;
      case G_TYPE_FLOAT:
        SET_CONVERT_FUNCTION (float);
        break;
      case G_TYPE_DOUBLE:
        SET_CONVERT_FUNCTION (double);
        break;
      case G_TYPE_BOOLEAN:
        self->convert_g_value = convert_g_value_to_boolean;
        self->convert_value = convert_value_to_boolean;
        self->byte_size = sizeof (gboolean);
        break;
      case G_TYPE_ENUM:
        self->convert_g_value = convert_g_value_to_enum;
        self->convert_value = convert_value_to_enum;
        self->byte_size = sizeof (gint);
        break;
      default:
        GST_WARNING ("incomplete implementation for paramspec type '%s'",
            G_PARAM_SPEC_TYPE_NAME (GST_CONTROL_BINDING_PSPEC (self)));
        GST_CONTROL_BINDING_PSPEC (self) = NULL;
        break;
    }
  }
  return (GObject *) self;
}