1 /*
2  * libInstPatch
3  * Copyright (C) 1999-2014 Element Green <element@elementsofsound.org>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation; version 2.1
8  * of the License only.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA or on the web at http://www.gnu.org.
19  */
20 #ifndef __IPATCH_UNIT_H__
21 #define __IPATCH_UNIT_H__
22 
23 #include <glib.h>
24 #include <glib-object.h>
25 
26 typedef struct _IpatchUnitInfo IpatchUnitInfo;
27 
28 /* structure defining a unit type */
29 struct _IpatchUnitInfo
30 {
31     guint16 id;			/* unit type ID */
32     guint8 digits;	   	/* significant digits to display to user */
33     guint8 flags;			/* IpatchUnitFlags */
34     GType value_type;		/* unit value type */
35     char *name;			/* name identifier (constant) */
36     char *label;			/* unit label (translated) */
37     char *descr;			/* unit description (translated) */
38 };
39 
40 typedef enum
41 {
42     IPATCH_UNIT_LOGARITHMIC = 1 << 0, /* unit is logarithmic */
43     IPATCH_UNIT_USER = 1 << 1	/* a user friendly unit type */
44 } IpatchUnitFlags;
45 
46 /**
47  * IpatchValueTransform:
48  * @src: Source value to transform from
49  * @dest: Destination value to transform to
50  *
51  * Transform from one value to another.  The @src and @dest values have
52  * already been initialized to specific types and the transform function
53  * should convert/process them as necessary.
54  */
55 typedef void (*IpatchValueTransform)(const GValue *src, GValue *dest);
56 
57 /* built-in unit types */
58 typedef enum
59 {
60     IPATCH_UNIT_TYPE_NONE = 0,	/* a NULL value */
61     IPATCH_UNIT_TYPE_INT = 1,
62     IPATCH_UNIT_TYPE_UINT = 2,
63     IPATCH_UNIT_TYPE_RANGE = 3,
64     IPATCH_UNIT_TYPE_DECIBELS = 4,
65     IPATCH_UNIT_TYPE_PERCENT = 5,
66     IPATCH_UNIT_TYPE_SEMITONES = 6,
67     IPATCH_UNIT_TYPE_CENTS = 7,
68     IPATCH_UNIT_TYPE_TIME_CENTS = 8,
69     IPATCH_UNIT_TYPE_SAMPLE_RATE = 9,
70     IPATCH_UNIT_TYPE_SAMPLES = 10,
71     IPATCH_UNIT_TYPE_HERTZ = 11,
72     IPATCH_UNIT_TYPE_SECONDS = 12,
73     IPATCH_UNIT_TYPE_MULTIPLIER = 13,
74 
75     /* 128 - 159 reserved for IpatchUnit_DLS.h */
76     IPATCH_UNIT_TYPE_DLS_GAIN = 128,
77     IPATCH_UNIT_TYPE_DLS_ABS_TIME = 129,
78     IPATCH_UNIT_TYPE_DLS_REL_TIME = 130,
79     IPATCH_UNIT_TYPE_DLS_ABS_PITCH = 131,
80     IPATCH_UNIT_TYPE_DLS_REL_PITCH = 132,
81     IPATCH_UNIT_TYPE_DLS_PERCENT = 133,
82 
83     /* 160 - 169 reserved for IpatchUnit_SF2.h */
84     IPATCH_UNIT_TYPE_SF2_ABS_PITCH = 160,
85     IPATCH_UNIT_TYPE_SF2_OFS_PITCH = 161,
86     IPATCH_UNIT_TYPE_SF2_ABS_TIME = 162,
87     IPATCH_UNIT_TYPE_SF2_OFS_TIME = 163,
88     IPATCH_UNIT_TYPE_CENTIBELS = 164,
89     IPATCH_UNIT_TYPE_32K_SAMPLES = 165,
90     IPATCH_UNIT_TYPE_TENTH_PERCENT = 166
91 } IpatchUnitType;
92 
93 /*
94  * Unit class types define domains of conversion, an example is the "user"
95  * unit class which is used to convert values to units digestable by a human.
96  * A conversion class is essentially a mapping between unit types, which can
97  * then be used to lookup conversion functions.
98  */
99 typedef enum
100 {
101     IPATCH_UNIT_CLASS_NONE,	/* a NULL value */
102     IPATCH_UNIT_CLASS_USER,   /* "user" conversion class (for humans) */
103     IPATCH_UNIT_CLASS_DLS,	/* DLS (native patch type) class */
104     IPATCH_UNIT_CLASS_COUNT   /* NOT A VALID CLASS - count of classes */
105 } IpatchUnitClassType;
106 
107 
108 GType ipatch_unit_info_get_type(void);
109 IpatchUnitInfo *ipatch_unit_info_new(void);
110 void ipatch_unit_info_free(IpatchUnitInfo *info);
111 IpatchUnitInfo *ipatch_unit_info_duplicate(const IpatchUnitInfo *info);
112 guint16 ipatch_unit_register(const IpatchUnitInfo *info);
113 IpatchUnitInfo *ipatch_unit_lookup(guint16 id);
114 IpatchUnitInfo *ipatch_unit_lookup_by_name(const char *name);
115 void ipatch_unit_class_register_map(guint16 class_type, guint16 src_units,
116                                     guint16 dest_units);
117 IpatchUnitInfo *ipatch_unit_class_lookup_map(guint16 class_type,
118         guint16 src_units);
119 void ipatch_unit_conversion_register(guint16 src_units, guint16 dest_units,
120                                      IpatchValueTransform func);
121 void ipatch_unit_conversion_register_full(guint16 src_units, guint16 dest_units,
122         IpatchValueTransform func,
123         GDestroyNotify notify_func, gpointer user_data);
124 IpatchValueTransform ipatch_unit_conversion_lookup(guint16 src_units,
125         guint16 dest_units,
126         gboolean *set);
127 gboolean ipatch_unit_convert(guint16 src_units, guint16 dest_units,
128                              const GValue *src_val, GValue *dest_val);
129 double ipatch_unit_user_class_convert(guint16 src_units,
130                                       const GValue *src_val);
131 
132 #endif
133