SwamiControl

SwamiControl

Synopsis

GParamSpec *        (*SwamiControlGetSpecFunc)          (SwamiControl *control);
gboolean            (*SwamiControlSetSpecFunc)          (SwamiControl *control,
                                                         GParamSpec *pspec);
void                (*SwamiControlGetValueFunc)         (SwamiControl *control,
                                                         GValue *value);
void                (*SwamiControlSetValueFunc)         (SwamiControl *control,
                                                         SwamiControlEvent *event,
                                                         const GValue *value);
                    SwamiControl;
enum                SwamiControlFlags;
#define             SWAMI_CONTROL_FLAGS_USER_MASK
#define             SWAMI_CONTROL_SENDRECV
#define             SWAMI_CONTROL_UNUSED_FLAG_SHIFT
enum                SwamiControlConnPriority;
#define             SWAMI_CONTROL_CONN_PRIORITY_MASK
#define             SWAMI_CONTROL_CONN_DEFAULT_PRIORITY_VALUE
enum                SwamiControlConnFlags;
#define             SWAMI_CONTROL_CONN_BIDIR_INIT
#define             SWAMI_CONTROL_CONN_BIDIR_SPEC_INIT
SwamiControl *      swami_control_new                   (void);
void                swami_control_connect               (SwamiControl *src,
                                                         SwamiControl *dest,
                                                         guint flags);
void                swami_control_connect_transform     (SwamiControl *src,
                                                         SwamiControl *dest,
                                                         guint flags,
                                                         SwamiValueTransform trans1,
                                                         SwamiValueTransform trans2,
                                                         gpointer data1,
                                                         gpointer data2,
                                                         GDestroyNotify destroy1,
                                                         GDestroyNotify destroy2);
void                swami_control_connect_item_prop     (SwamiControl *dest,
                                                         GObject *object,
                                                         GParamSpec *pspec);
void                swami_control_disconnect            (SwamiControl *src,
                                                         SwamiControl *dest);
void                swami_control_disconnect_all        (SwamiControl *control);
void                swami_control_disconnect_unref      (SwamiControl *control);
IpatchList *        swami_control_get_connections       (SwamiControl *control,
                                                         SwamiControlConnFlags dir);
void                swami_control_set_transform         (SwamiControl *src,
                                                         SwamiControl *dest,
                                                         SwamiValueTransform trans,
                                                         gpointer data,
                                                         GDestroyNotify destroy);
void                swami_control_get_transform         (SwamiControl *src,
                                                         SwamiControl *dest,
                                                         SwamiValueTransform *trans);
void                swami_control_set_flags             (SwamiControl *control,
                                                         int flags);
int                 swami_control_get_flags             (SwamiControl *control);
void                swami_control_set_queue             (SwamiControl *control,
                                                         SwamiControlQueue *queue);
SwamiControlQueue * swami_control_get_queue             (SwamiControl *control);
GParamSpec *        swami_control_get_spec              (SwamiControl *control);
gboolean            swami_control_set_spec              (SwamiControl *control,
                                                         GParamSpec *pspec);
gboolean            swami_control_sync_spec             (SwamiControl *control,
                                                         SwamiControl *source,
                                                         SwamiValueTransform trans,
                                                         gpointer data);
GParamSpec *        swami_control_transform_spec        (SwamiControl *control,
                                                         SwamiControl *source,
                                                         SwamiValueTransform trans,
                                                         gpointer data);
void                swami_control_set_value_type        (SwamiControl *control,
                                                         GType type);
void                swami_control_get_value             (SwamiControl *control,
                                                         GValue *value);
void                swami_control_get_value_native      (SwamiControl *control,
                                                         GValue *value);
void                swami_control_set_value             (SwamiControl *control,
                                                         const GValue *value);
void                swami_control_set_value_no_queue    (SwamiControl *control,
                                                         const GValue *value);
void                swami_control_set_event             (SwamiControl *control,
                                                         SwamiControlEvent *event);
void                swami_control_set_event_no_queue    (SwamiControl *control,
                                                         SwamiControlEvent *event);
void                swami_control_set_event_no_queue_loop
                                                        (SwamiControl *control,
                                                         SwamiControlEvent *event);
void                swami_control_transmit_value        (SwamiControl *control,
                                                         const GValue *value);
void                swami_control_transmit_event        (SwamiControl *control,
                                                         SwamiControlEvent *event);
void                swami_control_transmit_event_loop   (SwamiControl *control,
                                                         SwamiControlEvent *event);
void                swami_control_do_event_expiration   (void);
SwamiControlEvent * swami_control_new_event             (SwamiControl *control,
                                                         SwamiControlEvent *origin,
                                                         const GValue *value);

Object Hierarchy

  GObject
   +----SwamiLock
         +----SwamiControl
               +----SwamiControlFunc
               +----SwamiControlHub
               +----SwamiControlValue
               +----SwamiControlProp

Signals

  "connect"                                        : Run First
  "disconnect"                                     : Run Last
  "spec-changed"                                   : Run Last

Description

Details

SwamiControlGetSpecFunc ()

GParamSpec *        (*SwamiControlGetSpecFunc)          (SwamiControl *control);

A SwamiControlClass optional method type to get the parameter spec from a control. If this method is not used or it returns NULL then the control is assumed to accept control events of any type.

Note: The control is locked while calling this method. Also, this method should return the parameter spec quickly, to speed up the event emission process.

control :

Control to get parameter spec for

Returns :

Should return the parameter specification for the control or NULL for type independent controls. Reference count should not be modified, this is handled by the caller.

SwamiControlSetSpecFunc ()

gboolean            (*SwamiControlSetSpecFunc)          (SwamiControl *control,
                                                         GParamSpec *pspec);

A SwamiControlClass optional method type to set the parameter spec for a control. The method should call g_param_spec_ref() followed by g_param_spec_sink() to take over the reference. If a control has a specific value type and the SWAMI_CONTROL_SPEC_NO_CONV is not set then the parameter spec is converted to the parameter spec type used for the given value type and the min/max/default values of the parameter spec will be processed with the set_trans value transform function if assigned, otherwise the parameter spec is passed as is without conversion.

Note: The control is locked while calling this method.

control :

Control to get parameter spec for

pspec :

Parameter specification to assign

Returns :

Should return TRUE if parameter spec change was allowed, FALSE otherwise.

SwamiControlGetValueFunc ()

void                (*SwamiControlGetValueFunc)         (SwamiControl *control,
                                                         GValue *value);

A SwamiControlClass optional method type to get the value from a value control that is readable (SWAMI_CONTROL_SENDS flag must be set). The value has been initialized to the native type of the control's parameter spec. If this method is used then SwamiControlGetSpecFunc must also be set.

Note: The control is not locked when calling this method.

control :

Control to get value from

value :

Caller supplied value to store control value in

SwamiControlSetValueFunc ()

void                (*SwamiControlSetValueFunc)         (SwamiControl *control,
                                                         SwamiControlEvent *event,
                                                         const GValue *value);

A SwamiControlClass optional method type to receive control values. If the SWAMI_CONTROL_NO_CONV flag is not set for this control and the SwamiControlGetSpecFunc returns a parameter spec then value will be the result of the original event value converted to the control's native type.

This method gets called for events received via a control's inputs or when swami_control_set_event() or swami_control_set_value() is called.

Note: The control is not locked during this method call.

control :

Control that is receiving an event

event :

Control event being received

value :

Value which is being received (possibly converted from original event value depending on the control's settings)

SwamiControl

typedef struct _SwamiControl SwamiControl;

enum SwamiControlFlags

typedef enum
{
  SWAMI_CONTROL_SENDS        = 1 << 0, /* control is readable/sends */
  SWAMI_CONTROL_RECVS        = 1 << 1, /* control is writable/receives */
  SWAMI_CONTROL_NO_CONV      = 1 << 2, /* don't convert incoming values */
  SWAMI_CONTROL_NATIVE       = 1 << 3, /* values of native value type only */
  SWAMI_CONTROL_VALUE        = 1 << 4, /* value control - queue optimization */
  SWAMI_CONTROL_SPEC_NO_CONV = 1 << 5  /* don't convert parameter spec type */
} SwamiControlFlags;

SWAMI_CONTROL_FLAGS_USER_MASK

#define SWAMI_CONTROL_FLAGS_USER_MASK 0x7F

SWAMI_CONTROL_SENDRECV

#define SWAMI_CONTROL_SENDRECV  (SWAMI_CONTROL_SENDS | SWAMI_CONTROL_RECVS)

SWAMI_CONTROL_UNUSED_FLAG_SHIFT

#define SWAMI_CONTROL_UNUSED_FLAG_SHIFT 12

enum SwamiControlConnPriority

typedef enum
{
  SWAMI_CONTROL_CONN_PRIORITY_DEFAULT = 0,
  SWAMI_CONTROL_CONN_PRIORITY_LOW     = 1,
  SWAMI_CONTROL_CONN_PRIORITY_MEDIUM  = 2,
  SWAMI_CONTROL_CONN_PRIORITY_HIGH    = 3
} SwamiControlConnPriority;

SWAMI_CONTROL_CONN_PRIORITY_MASK

#define SWAMI_CONTROL_CONN_PRIORITY_MASK  (0x2)

SWAMI_CONTROL_CONN_DEFAULT_PRIORITY_VALUE

#define             SWAMI_CONTROL_CONN_DEFAULT_PRIORITY_VALUE

enum SwamiControlConnFlags

typedef enum /*< flags >*/
{
  SWAMI_CONTROL_CONN_INPUT  = 1 << 2, /* set for inputs (used internally) */
  SWAMI_CONTROL_CONN_OUTPUT = 1 << 3, /* set for outputs (used internally) */
  SWAMI_CONTROL_CONN_INIT   = 1 << 4, /* update value on connect */
  SWAMI_CONTROL_CONN_BIDIR  = 1 << 5, /* make a bi-directional connection */
  SWAMI_CONTROL_CONN_SPEC   = 1 << 6  /* synchronize the parameter spec on connect */
} SwamiControlConnFlags;

SWAMI_CONTROL_CONN_BIDIR_INIT

#define             SWAMI_CONTROL_CONN_BIDIR_INIT

SWAMI_CONTROL_CONN_BIDIR_SPEC_INIT

#define             SWAMI_CONTROL_CONN_BIDIR_SPEC_INIT

swami_control_new ()

SwamiControl *      swami_control_new                   (void);

Create a new SwamiControl instance. SwamiControl is the base class for other control types as well. Creating an instance of a SwamiControl will create a send only event control.

Returns :

New SwamiControl object, the caller owns a reference.

swami_control_connect ()

void                swami_control_connect               (SwamiControl *src,
                                                         SwamiControl *dest,
                                                         guint flags);

Connect two controls (i.e., when the src control's value changes the dest control is set to this value). Useful flags include the SWAMI_CONTROL_CONN_INIT flag which will cause dest to be set to the current value of src and SWAMI_CONTROL_CONN_BIDIR which will cause a bi-directional connection to be made (as if 2 calls where made to this function with the src and dest swapped the second time). The connection priority can also be set via the flags field by or-ing in SwamiControlConnPriority values (assumes default priority if not specified). The priority determines the order in which connections are processed. The SWAMI_CONTROL_CONN_SPEC flag will cause the parameter spec of the dest control to be set to that of src.

src :

Source control to connect (readable)

dest :

Destination control to connect (writable)

flags :

Flags for this connection (SwamiControlConnFlags)

swami_control_connect_transform ()

void                swami_control_connect_transform     (SwamiControl *src,
                                                         SwamiControl *dest,
                                                         guint flags,
                                                         SwamiValueTransform trans1,
                                                         SwamiValueTransform trans2,
                                                         gpointer data1,
                                                         gpointer data2,
                                                         GDestroyNotify destroy1,
                                                         GDestroyNotify destroy2);

Like swami_control_connect() but transform functions can be specified during connect, rather than having to call swami_control_set_transform() later.

src :

Source control to connect (readable)

dest :

Destination control to connect (writable)

flags :

Flags for this connection (SwamiControlConnFlags).

trans1 :

Value transform function from src to dest (or NULL for no transform)

trans2 :

Value transform function from dest to src (SWAMI_CONTROL_CONN_BIDIR only, NULL for no transform).

data1 :

User data to pass to trans1 function.

data2 :

User data to pass to trans2 function. (SWAMI_CONTROL_CONN_BIDIR only, NULL for no transform).

destroy1 :

Optional callback to free data1 when trans1 is disconnected.

destroy2 :

Optional callback to free data2 when trans2 is disconnected.

swami_control_connect_item_prop ()

void                swami_control_connect_item_prop     (SwamiControl *dest,
                                                         GObject *object,
                                                         GParamSpec *pspec);

An ultra-convenience function to connect an existing control to a synthesis property of an object (IpatchItem property for example). The connection is bi-directional and transform functions are used to convert between the two unit types as needed.

dest :

Destination control

object :

Object of source parameter to convert to user units

pspec :

Parameter spec of property of object to connect to

swami_control_disconnect ()

void                swami_control_disconnect            (SwamiControl *src,
                                                         SwamiControl *dest);

Disconnects a connection specified by its src and dest controls.

src :

Source control of an existing connection

dest :

Destination control of an existing connection

swami_control_disconnect_all ()

void                swami_control_disconnect_all        (SwamiControl *control);

Disconnect all connections from a control.

control :

Swami control object

swami_control_disconnect_unref ()

void                swami_control_disconnect_unref      (SwamiControl *control);

A convenience function to disconnect all connections of a control and unref it. This is often useful for GDestroyNotify callbacks where a control's creator wishes to destroy the control. The control is only destroyed if it is not referenced by anything else.

control :

Swami control object

swami_control_get_connections ()

IpatchList *        swami_control_get_connections       (SwamiControl *control,
                                                         SwamiControlConnFlags dir);

Get a list of connections to a control.

control :

Control to get connections of

dir :

Direction of connections to get, SWAMI_CONTROL_CONN_INPUT for incoming connections, SWAMI_CONTROL_CONN_OUTPUT for outgoing (values can be OR'd to return all connections).

Returns :

List of SwamiControl objects connected to control or NULL if none. Caller owns reference to returned list and should unref when done.

swami_control_set_transform ()

void                swami_control_set_transform         (SwamiControl *src,
                                                         SwamiControl *dest,
                                                         SwamiValueTransform trans,
                                                         gpointer data,
                                                         GDestroyNotify destroy);

Assigns a value transform function to an existing control connection. The connection is specified by src and dest controls. The transform function will receive values from the src control and should transform them appropriately for the dest.

src :

Source control of the connection

dest :

Destination control of the connection

trans :

Transform function to assign to the connection (or NULL for none)

data :

User data to pass to trans function (or NULL).

destroy :

Optional callback to free data when trans is disconnected.

swami_control_get_transform ()

void                swami_control_get_transform         (SwamiControl *src,
                                                         SwamiControl *dest,
                                                         SwamiValueTransform *trans);

Gets the current value transform function to an existing control connection. The connection is specified by src and dest controls. The value stored to trans may be NULL if no transform function is assigned.

src :

Source control of the connection

dest :

Destination control of the connection

trans :

Pointer to store transform function of the connection

swami_control_set_flags ()

void                swami_control_set_flags             (SwamiControl *control,
                                                         int flags);

Set flags of a control object. Flags can only be set for controls that don't have any connections yet.

control :

Control object

flags :

Value to assign to control flags (SwamiControlFlags)

swami_control_get_flags ()

int                 swami_control_get_flags             (SwamiControl *control);

Get the flags from a control object.

control :

Control object

Returns :

Flags value (SwamiControlFlags) for control

swami_control_set_queue ()

void                swami_control_set_queue             (SwamiControl *control,
                                                         SwamiControlQueue *queue);

Set the queue used by a control object. When a control has a queue all receive/set events are sent to the queue. This queue can then be processed at a later time (a GUI thread for example).

control :

Control object

queue :

Queue to use for control or NULL to disable queuing

swami_control_get_queue ()

SwamiControlQueue * swami_control_get_queue             (SwamiControl *control);

Get the queue used by a control object.

control :

Control object

Returns :

The queue assigned to a control or NULL if it does not have one. The caller owns a reference to the returned queue object.

swami_control_get_spec ()

GParamSpec *        swami_control_get_spec              (SwamiControl *control);

Get a control object's parameter specification.

control :

Control object

Returns :

The parameter spec or NULL on error or if the given control is type independent. The returned spec is used internally and should not be modified or freed, however the caller does own a reference to it and should unref it with g_param_spec_unref when finished.

swami_control_set_spec ()

gboolean            swami_control_set_spec              (SwamiControl *control,
                                                         GParamSpec *pspec);

Set a control object's parameter specification. This function uses the pspec directly (its refcount is incremented and ownership is taken). The parameter spec is not permitted to be of a different type than the previous parameter spec.

control :

Control object

pspec :

The parameter specification to assign (used directly)

Returns :

TRUE if parameter specification successfully set, FALSE otherwise (in which case the pspec is unreferenced).

swami_control_sync_spec ()

gboolean            swami_control_sync_spec             (SwamiControl *control,
                                                         SwamiControl *source,
                                                         SwamiValueTransform trans,
                                                         gpointer data);

Synchronizes a control object's parameter spec to the source control. The source control must already have an assigned parameter spec and the control should have an assigned value type. The optional trans parameter can be used to specify a transform function, which is executed on the min, max and default components of the parameter spec when creating the new param spec.

control :

Control to set parameter spec control of

source :

The source control to get the parameter spec from

trans :

Optional value transform function

data :

User data to pass to transform function

Returns :

TRUE on success, FALSE otherwise (param spec conversion error)

swami_control_transform_spec ()

GParamSpec *        swami_control_transform_spec        (SwamiControl *control,
                                                         SwamiControl *source,
                                                         SwamiValueTransform trans,
                                                         gpointer data);

Transforms a parameter spec from a source control in preperation for assignment to control (but doesn't actually assign it).

control :

Destination control for the transformed parameter spec

source :

Source control with the parameter spec to transform

trans :

Transform function

data :

User defined data to pass to transform function

Returns :

Transformed parameter spec or NULL on error, the reference count is 1 and floating, which means it should be taken over by calling g_param_spec_ref() followed by g_param_spec_sink().

swami_control_set_value_type ()

void                swami_control_set_value_type        (SwamiControl *control,
                                                         GType type);

Usually only called by SwamiControl derived types from within their instance init function. Sets the parameter spec value type for control and should be called once for specific type value based controls before being used and cannot be changed afterwards. If the type is not set then the control is a wild card control (can handle any value). For GBoxed and GObject based values use the specific GType for type.

control :

Control to set value type of

type :

Value type to assign to control

swami_control_get_value ()

void                swami_control_get_value             (SwamiControl *control,
                                                         GValue *value);

Get the current value of a value control object. The control must have the SWAMI_CONTROL_SENDS flag set and be a value type control with an assigned parameter spec. The value parameter should be initialized to the type of the control or a transformable type.

control :

Control object of type SWAMI_CONTROL_VALUE

value :

Caller supplied initialized GValue structure to store the value in.

swami_control_get_value_native ()

void                swami_control_get_value_native      (SwamiControl *control,
                                                         GValue *value);

Like swami_control_get_value() but forces value to be the native type of the control, rather than transforming the value to the initialized value type. Therefore value should be un-initialized, contrary to swami_control_get_value().

control :

Control object of type SWAMI_CONTROL_VALUE

value :

Caller supplied uninitalized GValue structure to store the value in.

swami_control_set_value ()

void                swami_control_set_value             (SwamiControl *control,
                                                         const GValue *value);

Sets/sends a value to a control object. If the control has a queue assigned to it then the value is queued. The value parameter should be of a type transformable to the type used by control (see g_value_transformable). The control must have the SWAMI_CONTROL_RECVS flag set.

control :

Control object

value :

Value to set control to

swami_control_set_value_no_queue ()

void                swami_control_set_value_no_queue    (SwamiControl *control,
                                                         const GValue *value);

Sets/sends a value to a control object bypassing the control's queue if it has one assigned to it. The value parameter should be of a type transformable to the type used by control (see g_value_transformable). The control must have the SWAMI_CONTROL_RECVS flag set. Normally the swami_control_set_value() function should be used instead to send a value to a control, use this only if you know what you are doing since some controls are sensitive to when they are processed (within a GUI thread for instance).

control :

Control object

value :

Value to set control to

swami_control_set_event ()

void                swami_control_set_event             (SwamiControl *control,
                                                         SwamiControlEvent *event);

Sets the value of a control object (value controls) or sends an event (stream controls). This is like swami_control_set_value() but uses an existing event, rather than creating a new one. The control must have the SWAMI_CONTROL_RECVS flag set. If the control has a queue then the event will be added to the queue.

control :

Control object

event :

Event to set control to

swami_control_set_event_no_queue ()

void                swami_control_set_event_no_queue    (SwamiControl *control,
                                                         SwamiControlEvent *event);

Like swami_control_set_event() but bypasses any queue that a control might have. The control must have the SWAMI_CONTROL_RECVS flag set.

control :

Control object

event :

Event to set control to

swami_control_set_event_no_queue_loop ()

void                swami_control_set_event_no_queue_loop
                                                        (SwamiControl *control,
                                                         SwamiControlEvent *event);

Like swami_control_set_event_no_queue() but doesn't do an event loop check. This function is usually only used by SwamiControlQueue objects. The control must have the SWAMI_CONTROL_RECVS flag set.

control :

Control object

event :

Event to set control to

swami_control_transmit_value ()

void                swami_control_transmit_value        (SwamiControl *control,
                                                         const GValue *value);

Sends a value to all output connections of control. Usually only used by SwamiControl object implementations. The value is used if not NULL or the control's value is used (readable value controls only). This is a convenience function that creates a SwamiControlEvent based on the new transmit value, use swami_control_transmit_event() to send an existing event.

control :

Control object

value :

Value to transmit or NULL (readable value controls only, sends value changed event).

swami_control_transmit_event ()

void                swami_control_transmit_event        (SwamiControl *control,
                                                         SwamiControlEvent *event);

This function sends an event to all destination connected controls. Usually only used by SwamiControl object implementations.

control :

Control object

event :

Event to send to output connections of control

swami_control_transmit_event_loop ()

void                swami_control_transmit_event_loop   (SwamiControl *control,
                                                         SwamiControlEvent *event);

Like swami_control_transmit_event() but doesn't do an event loop check. This is useful for control implementations that receive an event and want to re-transmit it (swami_control_transmit_event() would stop it, since the event is already in the active list for the control).

control :

Control object

event :

Event to send to output connections of control

swami_control_do_event_expiration ()

void                swami_control_do_event_expiration   (void);

Processes all controls in search of inactive expired events. This should be called periodically to expire events in controls that don't receive any events for a long period after previous activity. Note that currently this is handled automatically if swami_init() is called.


swami_control_new_event ()

SwamiControlEvent * swami_control_new_event             (SwamiControl *control,
                                                         SwamiControlEvent *origin,
                                                         const GValue *value);

Create an event for control. If value is non NULL then it is used as the value of the event otherwise the control is used as the value of the event (a value changed event).

control :

Control object

origin :

Origin event or NULL if new event is origin

value :

Value to use as event value or NULL to use control as the value (a value change event)

Returns :

New event with a refcount of 1 which the caller owns. Remember that a SwamiControlEvent is not a GObject and has its own reference counting routines swami_control_event_ref() and swami_control_event_unref().

Signal Details

The "connect" signal

void                user_function                      (SwamiControl *swamicontrol,
                                                        GObject      *arg1,
                                                        guint         arg2,
                                                        gpointer      user_data)         : Run First

The "disconnect" signal

void                user_function                      (SwamiControl *swamicontrol,
                                                        GObject      *arg1,
                                                        guint         arg2,
                                                        gpointer      user_data)         : Run Last

The "spec-changed" signal

void                user_function                      (SwamiControl *swamicontrol,
                                                        GParamSpec   *arg1,
                                                        gpointer      user_data)         : Run Last