annotate src/audlegacy/hook.c @ 4848:b2ee645f3e59

Hook up the equalizer (bug #24)
author John Lindgren <john.lindgren@tds.net>
date Sun, 12 Apr 2009 23:03:39 -0400
parents 7bf7f83a217e
children c97b4291ec8b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3112
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
1 /* Audacious
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
2 * Copyright (c) 2006-2007 William Pitcock
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
3 *
3112
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
4 * This program is free software; you can redistribute it and/or modify
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
5 * it under the terms of the GNU General Public License as published by
3121
3b6d316f8b09 GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents: 3112
diff changeset
6 * the Free Software Foundation; under version 3 of the License.
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
7 *
3112
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
8 * This program is distributed in the hope that it will be useful,
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
11 * GNU General Public License for more details.
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
12 *
3112
4c758281fe8f Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents: 2865
diff changeset
13 * You should have received a copy of the GNU General Public License
3121
3b6d316f8b09 GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents: 3112
diff changeset
14 * along with this program. If not, see <http://www.gnu.org/licenses>.
3123
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3121
diff changeset
15 *
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3121
diff changeset
16 * The Audacious team does not consider modular code linking to
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3121
diff changeset
17 * Audacious or using our public API to be a derived work.
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
18 */
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
19
4848
b2ee645f3e59 Hook up the equalizer (bug #24)
John Lindgren <john.lindgren@tds.net>
parents: 4811
diff changeset
20 #include <stdio.h>
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
21 #include <glib.h>
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
22 #include "hook.h"
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
23
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
24 static GSList *hook_list;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
25
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
26 static Hook *
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
27 hook_find(const gchar *name)
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
28 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
29 GSList *list;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
30
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
31 for (list = hook_list; list != NULL; list = g_slist_next(list))
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
32 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
33 Hook *hook = (Hook *) list->data;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
34
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
35 if (!g_ascii_strcasecmp(hook->name, name))
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
36 return hook;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
37 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
38
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
39 return NULL;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
40 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
41
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
42 void
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
43 hook_register(const gchar *name)
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
44 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
45 Hook *hook;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
46
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
47 g_return_if_fail(name != NULL);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
48
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
49 if ((hook = hook_find(name)) != NULL)
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
50 return;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
51
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
52 hook = g_new0(Hook, 1);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
53 hook->name = g_strdup(name);
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
54 hook->items = NULL;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
55
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
56 hook_list = g_slist_append(hook_list, hook);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
57 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
58
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
59 gint
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
60 hook_associate(const gchar *name, HookFunction func, gpointer user_data)
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
61 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
62 Hook *hook;
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
63 HookItem *hookitem;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
64
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
65 g_return_val_if_fail(name != NULL, -1);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
66 g_return_val_if_fail(func != NULL, -1);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
67
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
68 hook = hook_find(name);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
69
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
70 if (hook == NULL)
2406
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
71 {
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
72 hook_register(name);
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
73 hook = hook_find(name);
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
74 }
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
75
6f4094cc3859 [svn] - allow for hooks to be automatically registered if they are needed
nenolod
parents: 2404
diff changeset
76 /* this *cant* happen */
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
77 g_return_val_if_fail(hook != NULL, -1);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
78
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
79 hookitem = g_new0(HookItem, 1);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
80 hookitem->func = func;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
81 hookitem->user_data = user_data;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
82
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
83 hook->items = g_slist_append(hook->items, hookitem);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
84 return 0;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
85 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
86
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
87 gint
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
88 hook_dissociate(const gchar *name, HookFunction func)
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
89 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
90 Hook *hook;
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
91 GSList *iter;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
92
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
93 g_return_val_if_fail(name != NULL, -1);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
94 g_return_val_if_fail(func != NULL, -1);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
95
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
96 hook = hook_find(name);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
97
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
98 if (hook == NULL)
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
99 return -1;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
100
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
101 iter = hook->items;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
102 while (iter != NULL)
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
103 {
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
104 HookItem *hookitem = (HookItem*)iter->data;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
105 if (hookitem->func == func)
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
106 {
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
107 hook->items = g_slist_delete_link(hook->items, iter);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
108 g_free( hookitem );
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
109 return 0;
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
110 }
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
111 iter = g_slist_next(iter);
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
112 }
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
113 return -1;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
114 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
115
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
116 void
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
117 hook_call(const gchar *name, gpointer hook_data)
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
118 {
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
119 Hook *hook;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
120 GSList *iter;
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
121
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
122 g_return_if_fail(name != NULL);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
123
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
124 hook = hook_find(name);
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
125
4848
b2ee645f3e59 Hook up the equalizer (bug #24)
John Lindgren <john.lindgren@tds.net>
parents: 4811
diff changeset
126 if (hook == NULL) {
b2ee645f3e59 Hook up the equalizer (bug #24)
John Lindgren <john.lindgren@tds.net>
parents: 4811
diff changeset
127 printf ("Warning: no hook found for \"%s\"\n", name);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
128 return;
4848
b2ee645f3e59 Hook up the equalizer (bug #24)
John Lindgren <john.lindgren@tds.net>
parents: 4811
diff changeset
129 }
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
130
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
131 for (iter = hook->items; iter != NULL; iter = g_slist_next(iter))
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
132 {
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
133 HookItem *hookitem = (HookItem*)iter->data;
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
134
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
135 g_return_if_fail(hookitem->func != NULL);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
136
2457
b7f77224ea03 [svn] - now it's possible to pass user_data along with the hook function in hook_associate
giacomo
parents: 2406
diff changeset
137 hookitem->func(hook_data, hookitem->user_data);
2404
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
138 }
60f1bc20c19c [svn] - hooking implementation.
nenolod
parents:
diff changeset
139 }