GObject boilerplate
[gst-scaletempo-demo-rj.git] / src / demo-player.c
blob4a65985a758d0fde1cb7a3343f2f1e6c5090b33d
1 /* demo-player.c
2 * Copyright (C) 2008 Rov Juvano <rovjuvano@users.sourceforge.net>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "demo-player.h"
20 enum
22 SIGNAL_RATE_CHANGE,
23 LAST_SIGNAL
25 static guint demo_player_signals[LAST_SIGNAL] = { 0 };
27 enum
29 PROP_0,
30 PROP_RATE,
31 PROP_FILTER,
34 typedef struct _DemoPlayerPrivate
36 gboolean hello_word;
37 } DemoPlayerPrivate;
39 #define DEMO_PLAYER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEMO_TYPE_PLAYER, DemoPlayerPrivate))
42 /* method implementations */
43 static void demo_player_play_uri_func (DemoPlayer *player,
44 gchar *uri)
46 g_print ("Now Playing: %s\n", uri);
50 /* Method wrappers */
51 void demo_player_play_uri (DemoPlayer *player,
52 gchar *uri)
54 DEMO_PLAYER_GET_CLASS (player)->play_uri(player, uri);
58 /* GObject overrides */
59 static void
60 demo_player_get_property (GObject *object,
61 guint property_id,
62 GValue *value,
63 GParamSpec *pspec)
65 DemoPlayer *player = DEMO_PLAYER (object);
66 switch (property_id) {
67 case PROP_RATE:
68 g_value_set_double (value, player->rate);
69 break;
70 case PROP_FILTER:
71 g_value_set_string (value, player->filter);
72 break;
73 default:
74 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
75 break;
79 static void
80 demo_player_set_property (GObject *object,
81 guint property_id,
82 const GValue *value,
83 GParamSpec *pspec)
85 DemoPlayer *player = DEMO_PLAYER (object);
86 switch (property_id) {
87 case PROP_FILTER:
88 player->filter = g_value_dup_string (value);
89 break;
90 default:
91 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
92 break;
97 /* GTypeInfo functions */
98 static void
99 demo_player_init (GTypeInstance *instance,
100 gpointer g_class)
102 DemoPlayer *player = (DemoPlayer *)instance;
103 player->rate = 1.0;
104 player->filter = "identity";
107 static void
108 demo_player_class_init (gpointer g_class,
109 gpointer class_data)
111 g_type_class_add_private (g_class, sizeof (DemoPlayerPrivate));
113 /* DemiPlayer */
114 DemoPlayerClass *player_class = (DemoPlayerClass *)g_class;
115 player_class->play_uri = demo_player_play_uri_func;
117 /* GObject */
118 GObjectClass *as_object_class = G_OBJECT_CLASS (g_class);
119 as_object_class->get_property = demo_player_get_property;
120 as_object_class->set_property = demo_player_set_property;
122 g_object_class_install_property (as_object_class, PROP_RATE,
123 g_param_spec_double ("rate", "Rate", "Current playback rate",
124 -128, 128, 1.0, G_PARAM_READABLE));
126 g_object_class_install_property (as_object_class, PROP_FILTER,
127 g_param_spec_string ("filter", "Filter", "Filter to handle rate change",
128 "identity", G_PARAM_READWRITE));
130 demo_player_signals[SIGNAL_RATE_CHANGE] =
131 g_signal_new ("rate-changed", G_TYPE_FROM_CLASS (g_class), G_SIGNAL_RUN_FIRST,
132 0, NULL, NULL,
133 g_cclosure_marshal_VOID__DOUBLE, G_TYPE_NONE, 1, G_TYPE_DOUBLE);
136 GType
137 demo_player_get_type (void)
139 static GType type = 0;
140 if (G_UNLIKELY (type == 0)) {
141 static const GTypeInfo info = {
142 sizeof (DemoPlayerClass),
143 NULL, /* base_init */
144 NULL, /* base_finalize */
145 demo_player_class_init, /* class_init */
146 NULL, /* class_finalize */
147 NULL, /* class_data */
148 sizeof (DemoPlayer),
149 0, /* n_preallocs */
150 demo_player_init, /* instance_init */
151 NULL /* value_table */
153 type = g_type_register_static (G_TYPE_OBJECT,
154 "DemoPlayer",
155 &info, 0);
157 return type;