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 /**
21 * SECTION: IpatchGigSample
22 * @short_description: GigaSampler sample object
23 * @see_also: #IpatchGig
24 * @stability: Stable
25 *
26 * Object defining a GigaSampler sample object. Child of #IpatchGig objects
27 * and referenced by #IpatchGigSubRegion objects.
28 */
29 #include <stdarg.h>
30 #include <glib.h>
31 #include <glib-object.h>
32 #include "IpatchGigSample.h"
33 #include "i18n.h"
34
35 enum
36 {
37 PROP_0,
38 PROP_GROUP_NUMBER
39 };
40
41 static void ipatch_gig_sample_class_init(IpatchGigSampleClass *klass);
42 static void ipatch_gig_sample_init(IpatchGigSample *sample);
43 static void ipatch_gig_sample_set_property(GObject *object,
44 guint property_id,
45 const GValue *value,
46 GParamSpec *pspec);
47 static void ipatch_gig_sample_get_property(GObject *object,
48 guint property_id,
49 GValue *value,
50 GParamSpec *pspec);
51 static void ipatch_gig_sample_item_copy(IpatchItem *dest, IpatchItem *src,
52 IpatchItemCopyLinkFunc link_func,
53 gpointer user_data);
54
55 static gpointer parent_class = NULL;
56
57
58 GType
ipatch_gig_sample_get_type(void)59 ipatch_gig_sample_get_type(void)
60 {
61 static GType item_type = 0;
62
63 if(!item_type)
64 {
65 static const GTypeInfo item_info =
66 {
67 sizeof(IpatchGigSampleClass), NULL, NULL,
68 (GClassInitFunc)ipatch_gig_sample_class_init, NULL, NULL,
69 sizeof(IpatchGigSample), 0,
70 (GInstanceInitFunc)ipatch_gig_sample_init,
71 };
72
73 item_type = g_type_register_static(IPATCH_TYPE_DLS2_SAMPLE,
74 "IpatchGigSample", &item_info, 0);
75 }
76
77 return (item_type);
78 }
79
80 static void
ipatch_gig_sample_class_init(IpatchGigSampleClass * klass)81 ipatch_gig_sample_class_init(IpatchGigSampleClass *klass)
82 {
83 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
84 IpatchItemClass *item_class = IPATCH_ITEM_CLASS(klass);
85
86 parent_class = g_type_class_peek_parent(klass);
87
88 obj_class->get_property = ipatch_gig_sample_get_property;
89
90 /* we use the IpatchItem item_set_property method */
91 item_class->item_set_property = ipatch_gig_sample_set_property;
92 item_class->copy = ipatch_gig_sample_item_copy;
93
94 g_object_class_install_property(obj_class, PROP_GROUP_NUMBER,
95 g_param_spec_uint("group-number", _("Group number"),
96 _("Sample group index"),
97 0, G_MAXUINT, 0,
98 G_PARAM_READWRITE));
99 }
100
101 static void
ipatch_gig_sample_init(IpatchGigSample * sample)102 ipatch_gig_sample_init(IpatchGigSample *sample)
103 {
104 sample->group_number = 0;
105 }
106
107 static void
ipatch_gig_sample_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)108 ipatch_gig_sample_set_property(GObject *object, guint property_id,
109 const GValue *value, GParamSpec *pspec)
110 {
111 IpatchGigSample *sample = IPATCH_GIG_SAMPLE(object);
112
113 switch(property_id)
114 {
115 case PROP_GROUP_NUMBER:
116 sample->group_number = g_value_get_uint(value);
117 break;
118
119 default:
120 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
121 return;
122 }
123 }
124
125 static void
ipatch_gig_sample_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)126 ipatch_gig_sample_get_property(GObject *object, guint property_id,
127 GValue *value, GParamSpec *pspec)
128 {
129 IpatchGigSample *sample = IPATCH_GIG_SAMPLE(object);
130
131 switch(property_id)
132 {
133 case PROP_GROUP_NUMBER:
134 g_value_set_uint(value, sample->group_number);
135 break;
136
137 default:
138 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
139 break;
140 }
141 }
142
143 static void
ipatch_gig_sample_item_copy(IpatchItem * dest,IpatchItem * src,IpatchItemCopyLinkFunc link_func,gpointer user_data)144 ipatch_gig_sample_item_copy(IpatchItem *dest, IpatchItem *src,
145 IpatchItemCopyLinkFunc link_func,
146 gpointer user_data)
147 {
148 IpatchGigSample *src_sample, *dest_sample;
149
150 src_sample = IPATCH_GIG_SAMPLE(src);
151 dest_sample = IPATCH_GIG_SAMPLE(dest);
152
153 /* call IpatchDLS2Sample class copy function */
154 IPATCH_ITEM_CLASS(parent_class)->copy(dest, src, link_func, user_data);
155
156 /* don't need to lock for this stuff */
157 dest_sample->group_number = src_sample->group_number;
158 }
159
160 /**
161 * ipatch_gig_sample_new:
162 *
163 * Create a new GigaSampler sample object.
164 *
165 * Returns: New GigaSampler sample with a reference count of 1. Caller
166 * owns the reference and removing it will destroy the item, unless another
167 * reference is added (if its parented for example).
168 */
169 IpatchGigSample *
ipatch_gig_sample_new(void)170 ipatch_gig_sample_new(void)
171 {
172 return (IPATCH_GIG_SAMPLE(g_object_new(IPATCH_TYPE_GIG_SAMPLE, NULL)));
173 }
174
175 /**
176 * ipatch_gig_sample_first: (skip)
177 * @iter: Patch item iterator containing #IpatchGigSample items
178 *
179 * Gets the first item in a GigaSampler sample iterator. A convenience
180 * wrapper for ipatch_iter_first().
181 *
182 * Returns: The first GigaSampler sample in @iter or %NULL if empty.
183 */
184 IpatchGigSample *
ipatch_gig_sample_first(IpatchIter * iter)185 ipatch_gig_sample_first(IpatchIter *iter)
186 {
187 GObject *obj;
188 g_return_val_if_fail(iter != NULL, NULL);
189
190 obj = ipatch_iter_first(iter);
191
192 if(obj)
193 {
194 return (IPATCH_GIG_SAMPLE(obj));
195 }
196 else
197 {
198 return (NULL);
199 }
200 }
201
202 /**
203 * ipatch_gig_sample_next: (skip)
204 * @iter: Patch item iterator containing #IpatchGigSample items
205 *
206 * Gets the next item in a GigaSampler sample iterator. A convenience
207 * wrapper for ipatch_iter_next().
208 *
209 * Returns: The next GigaSampler sample in @iter or %NULL if at
210 * the end of the list.
211 */
212 IpatchGigSample *
ipatch_gig_sample_next(IpatchIter * iter)213 ipatch_gig_sample_next(IpatchIter *iter)
214 {
215 GObject *obj;
216 g_return_val_if_fail(iter != NULL, NULL);
217
218 obj = ipatch_iter_next(iter);
219
220 if(obj)
221 {
222 return (IPATCH_GIG_SAMPLE(obj));
223 }
224 else
225 {
226 return (NULL);
227 }
228 }
229