1 /* Libvisual - The audio visualisation framework. 2 * 3 * Copyright (C) 2004, 2005 Dennis Smit <ds@nerds-incorporated.org> 4 * 5 * Authors: Dennis Smit <ds@nerds-incorporated.org> 6 * 7 * $Id: 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation; either version 2.1 12 * of the License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24 #ifndef _LV_PARAM_H 25 #define _LV_PARAM_H 26 27 #include <libvisual/lv_common.h> 28 #include <libvisual/lv_color.h> 29 #include <libvisual/lv_palette.h> 30 #include <libvisual/lv_list.h> 31 #include <libvisual/lv_event.h> 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif /* __cplusplus */ 36 37 #define VISUAL_PARAMCONTAINER(obj) (VISUAL_CHECK_CAST ((obj), 0, VisParamContainer)) 38 #define VISUAL_PARAMENTRY_CALLBACK(obj) (VISUAL_CHECK_CAST ((obj), 0, VisParamEntryCallback)) 39 #define VISUAL_PARAMENTRY(obj) (VISUAL_CHECK_CAST ((obj), 0, VisParamEntry)) 40 41 #define VISUAL_PARAM_LIST_ENTRY(name) { {}, NULL, name, VISUAL_PARAM_ENTRY_TYPE_NULL } 42 #define VISUAL_PARAM_LIST_ENTRY_STRING(name, string) { {}, NULL, name, VISUAL_PARAM_ENTRY_TYPE_STRING, string, {0, 0, 0}} 43 #define VISUAL_PARAM_LIST_ENTRY_INTEGER(name, val) { {}, NULL, name, VISUAL_PARAM_ENTRY_TYPE_INTEGER, NULL, {val, 0, 0}} 44 #define VISUAL_PARAM_LIST_ENTRY_FLOAT(name, val) { {}, NULL, name, VISUAL_PARAM_ENTRY_TYPE_FLOAT, NULL, {0, val, 0}} 45 #define VISUAL_PARAM_LIST_ENTRY_DOUBLE(name, val) { {}, NULL, name, VISUAL_PARAM_ENTRY_TYPE_DOUBLE, NULL, {0, 0, val}} 46 #define VISUAL_PARAM_LIST_ENTRY_COLOR(name, r, g, b) { {}, NULL, name, VISUAL_PARAM_ENTRY_TYPE_COLOR, NULL, {0, 0, 0}, {{}, r, g, b, 0}} 47 #define VISUAL_PARAM_LIST_END { {}, NULL, NULL, VISUAL_PARAM_ENTRY_TYPE_END } 48 49 #define VISUAL_PARAM_CALLBACK_ID_MAX 2147483647 50 51 /** 52 * Different types of parameters that can be used. 53 */ 54 typedef enum { 55 VISUAL_PARAM_ENTRY_TYPE_NULL, /**< No parameter. */ 56 VISUAL_PARAM_ENTRY_TYPE_STRING, /**< String parameter. */ 57 VISUAL_PARAM_ENTRY_TYPE_INTEGER, /**< Integer parameter. */ 58 VISUAL_PARAM_ENTRY_TYPE_FLOAT, /**< Floating point parameter. */ 59 VISUAL_PARAM_ENTRY_TYPE_DOUBLE, /**< Double floating point parameter. */ 60 VISUAL_PARAM_ENTRY_TYPE_COLOR, /**< VisColor parameter. */ 61 VISUAL_PARAM_ENTRY_TYPE_PALETTE, /**< VisPalette parameter. */ 62 VISUAL_PARAM_ENTRY_TYPE_OBJECT, /**< VisObject parameter. */ 63 VISUAL_PARAM_ENTRY_TYPE_END /**< List end, and used as terminator for VisParamEntry lists. */ 64 } VisParamEntryType; 65 66 typedef struct _VisParamContainer VisParamContainer; 67 typedef struct _VisParamEntryCallback VisParamEntryCallback; 68 typedef struct _VisParamEntry VisParamEntry; 69 70 /** 71 * The param changed callback is used to be able to notify of changes within parameters. This should 72 * not be used within the plugin itself, instead use the event queue there. This is so it's possible to 73 * notify of changes outside the plugin. For example, this is needed by VisUI. 74 * 75 * @arg param Pointer to the param that has been changed, and to which the callback was set. 76 * @arg priv Private argument, that can be set when adding the callback to the callback list. 77 */ 78 typedef void (*VisParamChangedCallbackFunc)(VisParamEntry *param, void *priv); 79 80 81 /** 82 * Parameter container, is the container for a set of parameters. 83 * 84 * All members should never be accessed directly, instead methods should be used. 85 */ 86 struct _VisParamContainer { 87 VisObject object; /**< The VisObject data. */ 88 VisList entries; /**< The list that contains all the parameters. */ 89 VisEventQueue *eventqueue; /**< Pointer to an optional eventqueue to which events can be emitted 90 * on parameter changes. */ 91 }; 92 93 /** 94 * A parameter callback entry, used for change notification callbacks. 95 */ 96 struct _VisParamEntryCallback { 97 VisObject object; /**< The VisObject data. */ 98 int id; /**< Callback ID. */ 99 VisParamChangedCallbackFunc callback; /**< The param change callback function. */ 100 }; 101 102 /** 103 * A parameter entry, used for plugin parameters and such. 104 * 105 * All members should never be accessed directly, instead methods should be used. 106 */ 107 struct _VisParamEntry { 108 VisObject object; /**< The VisObject data. */ 109 VisParamContainer *parent; /**< Parameter container in which the param entry is encapsulated. */ 110 char *name; /**< Parameter name. */ 111 VisParamEntryType type; /**< Parameter type. */ 112 113 char *string; /**< String data. */ 114 115 /* No union, we can't choose a member of the union using static initializers */ 116 struct { 117 int integer; /**< Integer data. */ 118 float floating; /**< Floating point data. */ 119 double doubleflt; /**< Double floating point data. */ 120 } numeric; 121 122 VisColor color; /**< VisColor data. */ 123 VisPalette pal; /**< VisPalette data. */ 124 VisObject *objdata; /**< VisObject data for a VisObject parameter. */ 125 126 VisList callbacks; /**< The change notify callbacks. */ 127 }; 128 129 /* prototypes */ 130 VisParamContainer *visual_param_container_new (void); 131 int visual_param_container_set_eventqueue (VisParamContainer *paramcontainer, VisEventQueue *eventqueue); 132 VisEventQueue *visual_param_container_get_eventqueue (VisParamContainer *paramcontainer); 133 134 int visual_param_container_add (VisParamContainer *paramcontainer, VisParamEntry *param); 135 int visual_param_container_add_many (VisParamContainer *paramcontainer, VisParamEntry *params); 136 int visual_param_container_remove (VisParamContainer *paramcontainer, const char *name); 137 int visual_param_container_copy (VisParamContainer *destcont, VisParamContainer *srccont); 138 int visual_param_container_copy_match (VisParamContainer *destcont, VisParamContainer *srccont); 139 VisParamEntry *visual_param_container_get (VisParamContainer *paramcontainer, const char *name); 140 141 VisParamEntry *visual_param_entry_new (char *name); 142 int visual_param_entry_add_callback (VisParamEntry *param, VisParamChangedCallbackFunc callback, void *priv); 143 int visual_param_entry_remove_callback (VisParamEntry *param, int id); 144 int visual_param_entry_notify_callbacks (VisParamEntry *param); 145 int visual_param_entry_is (VisParamEntry *param, const char *name); 146 int visual_param_entry_compare (VisParamEntry *src1, VisParamEntry *src2); 147 int visual_param_entry_changed (VisParamEntry *param); 148 VisParamEntryType visual_param_entry_get_type (VisParamEntry *param); 149 150 int visual_param_entry_set_from_param (VisParamEntry *param, VisParamEntry *src); 151 int visual_param_entry_set_name (VisParamEntry *param, char *name); 152 int visual_param_entry_set_string (VisParamEntry *param, char *string); 153 int visual_param_entry_set_integer (VisParamEntry *param, int integer); 154 int visual_param_entry_set_float (VisParamEntry *param, float floating); 155 int visual_param_entry_set_double (VisParamEntry *param, double doubleflt); 156 int visual_param_entry_set_color (VisParamEntry *param, uint8_t r, uint8_t g, uint8_t b); 157 int visual_param_entry_set_color_by_color (VisParamEntry *param, VisColor *color); 158 int visual_param_entry_set_palette (VisParamEntry *param, VisPalette *pal); 159 int visual_param_entry_set_object (VisParamEntry *param, VisObject *object); 160 161 char *visual_param_entry_get_name (VisParamEntry *param); 162 char *visual_param_entry_get_string (VisParamEntry *param); 163 int visual_param_entry_get_integer (VisParamEntry *param); 164 float visual_param_entry_get_float (VisParamEntry *param); 165 double visual_param_entry_get_double (VisParamEntry *param); 166 VisColor *visual_param_entry_get_color (VisParamEntry *param); 167 VisPalette *visual_param_entry_get_palette (VisParamEntry *param); 168 VisObject *visual_param_entry_get_object (VisParamEntry *param); 169 170 #ifdef __cplusplus 171 } 172 #endif /* __cplusplus */ 173 174 #endif /* _LV_PARAM_H */ 175