Mercurial > pidgin
annotate src/gtksound.c @ 12828:09ac562f0813
[gaim-migrate @ 15176]
(2006-01-11 11:17:55) charkins: can someone with cvs access remove the
"#define SQRT2_2 ..." line from gtksound.c, I forgot to remove it when I
submitted the last software volume control patch
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 11 Jan 2006 16:19:39 +0000 |
parents | ff267281e882 |
children | 49b2347863b2 |
rev | line source |
---|---|
5684 | 1 /* |
10297
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10158
diff
changeset
|
2 * @file gtksound.h GTK+ Sound |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10158
diff
changeset
|
3 * @ingroup gtkui |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10158
diff
changeset
|
4 * |
5684 | 5 * gaim |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
5684 | 10 * |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 * | |
25 */ | |
9791 | 26 #include "internal.h" |
27 #include "gtkgaim.h" | |
5684 | 28 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
29 #ifdef _WIN32 |
5684 | 30 #include <windows.h> |
31 #include <mmsystem.h> | |
32 #endif | |
33 | |
34 #ifdef USE_AO | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
35 # include <ao/ao.h> |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
36 # include <audiofile.h> |
5684 | 37 #endif /* USE_AO */ |
38 | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
39 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
40 #include "notify.h" |
5684 | 41 #include "prefs.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
42 #include "sound.h" |
7465 | 43 #include "util.h" |
5684 | 44 |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
45 #include "gtkconv.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5794
diff
changeset
|
46 #include "gtksound.h" |
5684 | 47 |
48 struct gaim_sound_event { | |
49 char *label; | |
50 char *pref; | |
51 char *def; | |
52 }; | |
53 | |
10074 | 54 #define PLAY_SOUND_TIMEOUT 15000 |
5684 | 55 |
10320 | 56 static guint mute_login_sounds_timeout = 0; |
5684 | 57 static gboolean mute_login_sounds = FALSE; |
6199 | 58 static gboolean sound_initialized = FALSE; |
5684 | 59 |
60 static struct gaim_sound_event sounds[GAIM_NUM_SOUNDS] = { | |
10158 | 61 {N_("Buddy logs in"), "login", "login.wav"}, |
62 {N_("Buddy logs out"), "logout", "logout.wav"}, | |
5684 | 63 {N_("Message received"), "im_recv", "receive.wav"}, |
64 {N_("Message received begins conversation"), "first_im_recv", "receive.wav"}, | |
65 {N_("Message sent"), "send_im", "send.wav"}, | |
10158 | 66 {N_("Person enters chat"), "join_chat", "login.wav"}, |
67 {N_("Person leaves chat"), "left_chat", "logout.wav"}, | |
5684 | 68 {N_("You talk in chat"), "send_chat_msg", "send.wav"}, |
69 {N_("Others talk in chat"), "chat_msg_recv", "receive.wav"}, | |
70 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */ | |
10158 | 71 {NULL, "pounce_default", "alert.wav"}, |
72 {N_("Someone says your name in chat"), "nick_said", "alert.wav"} | |
5684 | 73 }; |
74 | |
75 #ifdef USE_AO | |
76 static int ao_driver = -1; | |
77 #endif /* USE_AO */ | |
78 | |
10320 | 79 static gboolean |
11463 | 80 unmute_login_sounds_cb(gpointer data) |
10320 | 81 { |
82 mute_login_sounds = FALSE; | |
83 mute_login_sounds_timeout = 0; | |
84 return FALSE; | |
85 } | |
86 | |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
87 static gboolean |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
88 chat_nick_matches_name(GaimConversation *conv, const char *aname) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
89 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
90 GaimConvChat *chat = NULL; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
91 char *nick = NULL; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
92 char *name = NULL; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
93 gboolean ret = FALSE; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
94 chat = gaim_conversation_get_chat_data(conv); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
95 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
96 if (chat==NULL) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
97 return ret; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
98 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
99 nick = g_strdup(gaim_normalize(conv->account, chat->nick)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
100 name = g_strdup(gaim_normalize(conv->account, aname)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
101 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
102 if (g_utf8_collate(nick, name) == 0) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
103 ret = TRUE; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
104 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
105 g_free(nick); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
106 g_free(name); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
107 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
108 return ret; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
109 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
110 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
111 /* |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
112 * play a sound event for a conversation, honoring make_sound flag |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
113 * of conversation and checking for focus if conv_focus pref is set |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
114 */ |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
115 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
116 play_conv_event(GaimConversation *conv, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
117 { |
11642 | 118 /* If we should not play the sound for some reason, then exit early */ |
119 if (conv != NULL) | |
120 { | |
121 GaimGtkConversation *gtkconv; | |
122 GaimGtkWindow *win; | |
123 gboolean has_focus; | |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
124 |
11642 | 125 gtkconv = GAIM_GTK_CONVERSATION(conv); |
126 win = gtkconv->win; | |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
127 |
11642 | 128 has_focus = gaim_conversation_has_focus(conv); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
129 |
11642 | 130 if (!gtkconv->make_sound || |
11687
941aa045f9f6
[gaim-migrate @ 13973]
Richard Laager <rlaager@wiktel.com>
parents:
11642
diff
changeset
|
131 (has_focus && !gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus"))) |
11642 | 132 { |
133 return; | |
134 } | |
135 } | |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
136 |
11642 | 137 gaim_sound_play_event(event, conv ? gaim_conversation_get_account(conv) : NULL); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
138 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
139 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
140 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
141 buddy_state_cb(GaimBuddy *buddy, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
142 { |
11642 | 143 gaim_sound_play_event(event, gaim_buddy_get_account(buddy)); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
144 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
145 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
146 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
147 im_msg_received_cb(GaimAccount *account, char *sender, |
11581 | 148 char *message, GaimConversation *conv, |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
149 int flags, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
150 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
151 if (conv==NULL) |
11642 | 152 gaim_sound_play_event(GAIM_SOUND_FIRST_RECEIVE, account); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
153 else |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
154 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
155 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
156 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
157 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
158 im_msg_sent_cb(GaimAccount *account, const char *receiver, |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
159 const char *message, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
160 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
161 GaimConversation *conv = gaim_find_conversation_with_account( |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
162 GAIM_CONV_TYPE_ANY, receiver, account); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
163 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
164 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
165 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
166 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
167 chat_buddy_join_cb(GaimConversation *conv, const char *name, |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
168 GaimConvChatBuddyFlags flags, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
169 { |
11581 | 170 if (!chat_nick_matches_name(conv, name)) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
171 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
172 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
173 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
174 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
175 chat_buddy_left_cb(GaimConversation *conv, const char *name, |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
176 const char *reason, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
177 { |
11581 | 178 if (!chat_nick_matches_name(conv, name)) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
179 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
180 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
181 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
182 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
183 chat_msg_sent_cb(GaimAccount *account, const char *message, |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
184 int id, GaimSoundEventID event) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
185 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
186 GaimConnection *conn = gaim_account_get_connection(account); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
187 GaimConversation *conv = NULL; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
188 |
11581 | 189 if (conn!=NULL) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
190 conv = gaim_find_chat(conn,id); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
191 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
192 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
193 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
194 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
195 static void |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
196 chat_msg_received_cb(GaimAccount *account, char *sender, |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
197 char *message, GaimConversation *conv, |
12216 | 198 GaimMessageFlags flags, GaimSoundEventID event) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
199 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
200 GaimConvChat *chat; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
201 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
202 chat = gaim_conversation_get_chat_data(conv); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
203 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
204 if (chat!=NULL && gaim_conv_chat_is_user_ignored(chat, sender)) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
205 return; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
206 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
207 if (chat_nick_matches_name(conv, sender)) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
208 return; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
209 |
12216 | 210 if (flags & GAIM_MESSAGE_NICK || gaim_utf8_has_word(message, chat->nick)) |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
211 play_conv_event(conv, GAIM_SOUND_CHAT_NICK); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
212 else |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
213 play_conv_event(conv, event); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
214 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
215 |
10320 | 216 /* |
217 * We mute sounds for the 10 seconds after you log in so that | |
218 * you don't get flooded with sounds when the blist shows all | |
219 * your buddies logging in. | |
220 */ | |
221 static void | |
222 account_signon_cb(GaimConnection *gc, gpointer data) | |
223 { | |
224 if (mute_login_sounds_timeout != 0) | |
225 g_source_remove(mute_login_sounds_timeout); | |
226 mute_login_sounds = TRUE; | |
11463 | 227 mute_login_sounds_timeout = gaim_timeout_add(10000, unmute_login_sounds_cb, NULL); |
10320 | 228 } |
229 | |
10322 | 230 static void |
231 _pref_sound_method_changed(const char *name, GaimPrefType type, | |
12816 | 232 gconstpointer val, gpointer data) |
233 { | |
10322 | 234 if(type != GAIM_PREF_STRING || strcmp(name, "/gaim/gtk/sound/method")) |
235 return; | |
236 | |
237 sound_initialized = TRUE; | |
238 | |
239 #ifdef USE_AO | |
240 ao_driver = -1; | |
241 | |
242 if(!strcmp(val, "esd")) | |
243 ao_driver = ao_driver_id("esd"); | |
244 else if(!strcmp(val, "arts")) | |
245 ao_driver = ao_driver_id("arts"); | |
11082 | 246 else if(!strcmp(val, "nas")) |
247 ao_driver = ao_driver_id("nas"); | |
10322 | 248 else if(!strcmp(val, "automatic")) |
249 ao_driver = ao_default_driver_id(); | |
250 | |
251 if(ao_driver != -1) { | |
252 ao_info *info = ao_driver_info(ao_driver); | |
253 gaim_debug_info("sound", | |
254 "Sound output driver loaded: %s\n", info->name); | |
255 } | |
256 #endif /* USE_AO */ | |
257 } | |
258 | |
259 const char * | |
260 gaim_gtk_sound_get_event_option(GaimSoundEventID event) | |
261 { | |
262 if(event >= GAIM_NUM_SOUNDS) | |
263 return 0; | |
264 | |
265 return sounds[event].pref; | |
266 } | |
267 | |
268 char * | |
269 gaim_gtk_sound_get_event_label(GaimSoundEventID event) | |
270 { | |
271 if(event >= GAIM_NUM_SOUNDS) | |
272 return NULL; | |
273 | |
274 return sounds[event].label; | |
275 } | |
276 | |
277 void * | |
278 gaim_gtk_sound_get_handle() | |
279 { | |
280 static int handle; | |
281 | |
282 return &handle; | |
283 } | |
284 | |
285 static void | |
286 gaim_gtk_sound_init(void) | |
5684 | 287 { |
10320 | 288 void *gtk_sound_handle = gaim_gtk_sound_get_handle(); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
289 void *blist_handle = gaim_blist_get_handle(); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
290 void *conv_handle = gaim_conversations_get_handle(); |
10320 | 291 |
292 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
293 gtk_sound_handle, GAIM_CALLBACK(account_signon_cb), | |
294 NULL); | |
295 | |
5684 | 296 gaim_prefs_add_none("/gaim/gtk/sound"); |
297 gaim_prefs_add_none("/gaim/gtk/sound/enabled"); | |
298 gaim_prefs_add_none("/gaim/gtk/sound/file"); | |
299 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/login", TRUE); | |
300 gaim_prefs_add_string("/gaim/gtk/sound/file/login", ""); | |
301 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/logout", TRUE); | |
302 gaim_prefs_add_string("/gaim/gtk/sound/file/logout", ""); | |
303 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/im_recv", TRUE); | |
304 gaim_prefs_add_string("/gaim/gtk/sound/file/im_recv", ""); | |
305 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/first_im_recv", FALSE); | |
306 gaim_prefs_add_string("/gaim/gtk/sound/file/first_im_recv", ""); | |
307 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/send_im", TRUE); | |
308 gaim_prefs_add_string("/gaim/gtk/sound/file/send_im", ""); | |
309 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/join_chat", FALSE); | |
310 gaim_prefs_add_string("/gaim/gtk/sound/file/join_chat", ""); | |
311 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/left_chat", FALSE); | |
312 gaim_prefs_add_string("/gaim/gtk/sound/file/left_chat", ""); | |
313 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/send_chat_msg", FALSE); | |
314 gaim_prefs_add_string("/gaim/gtk/sound/file/send_chat_msg", ""); | |
315 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/chat_msg_recv", FALSE); | |
316 gaim_prefs_add_string("/gaim/gtk/sound/file/chat_msg_recv", ""); | |
317 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/nick_said", FALSE); | |
318 gaim_prefs_add_string("/gaim/gtk/sound/file/nick_said", ""); | |
7460
3973a09525b3
[gaim-migrate @ 8073]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
319 gaim_prefs_add_bool("/gaim/gtk/sound/enabled/pounce_default", TRUE); |
3973a09525b3
[gaim-migrate @ 8073]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
320 gaim_prefs_add_string("/gaim/gtk/sound/file/pounce_default", ""); |
8633 | 321 gaim_prefs_add_bool("/gaim/gtk/sound/conv_focus", TRUE); |
10074 | 322 gaim_prefs_add_bool("/gaim/gtk/sound/mute", FALSE); |
5684 | 323 gaim_prefs_add_string("/gaim/gtk/sound/command", ""); |
324 gaim_prefs_add_string("/gaim/gtk/sound/method", "automatic"); | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
325 gaim_prefs_add_int("/gaim/gtk/sound/volume", 50); |
5684 | 326 |
327 #ifdef USE_AO | |
10322 | 328 gaim_debug_info("sound", "Initializing sound output drivers.\n"); |
5684 | 329 ao_initialize(); |
330 #endif /* USE_AO */ | |
331 | |
10087 | 332 gaim_prefs_connect_callback(gaim_gtk_sound_get_handle(), "/gaim/gtk/sound/method", |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
333 _pref_sound_method_changed, NULL); |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
334 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
335 gaim_signal_connect(blist_handle, "buddy-signed-on", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
336 gtk_sound_handle, GAIM_CALLBACK(buddy_state_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
337 GINT_TO_POINTER(GAIM_SOUND_BUDDY_ARRIVE)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
338 gaim_signal_connect(blist_handle, "buddy-signed-off", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
339 gtk_sound_handle, GAIM_CALLBACK(buddy_state_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
340 GINT_TO_POINTER(GAIM_SOUND_BUDDY_LEAVE)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
341 gaim_signal_connect(conv_handle, "received-im-msg", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
342 gtk_sound_handle, GAIM_CALLBACK(im_msg_received_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
343 GINT_TO_POINTER(GAIM_SOUND_RECEIVE)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
344 gaim_signal_connect(conv_handle, "sent-im-msg", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
345 gtk_sound_handle, GAIM_CALLBACK(im_msg_sent_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
346 GINT_TO_POINTER(GAIM_SOUND_SEND)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
347 gaim_signal_connect(conv_handle, "chat-buddy-joined", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
348 gtk_sound_handle, GAIM_CALLBACK(chat_buddy_join_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
349 GINT_TO_POINTER(GAIM_SOUND_CHAT_JOIN)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
350 gaim_signal_connect(conv_handle, "chat-buddy-left", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
351 gtk_sound_handle, GAIM_CALLBACK(chat_buddy_left_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
352 GINT_TO_POINTER(GAIM_SOUND_CHAT_LEAVE)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
353 gaim_signal_connect(conv_handle, "sent-chat-msg", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
354 gtk_sound_handle, GAIM_CALLBACK(chat_msg_sent_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
355 GINT_TO_POINTER(GAIM_SOUND_CHAT_YOU_SAY)); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
356 gaim_signal_connect(conv_handle, "received-chat-msg", |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
357 gtk_sound_handle, GAIM_CALLBACK(chat_msg_received_cb), |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
358 GINT_TO_POINTER(GAIM_SOUND_CHAT_SAY)); |
5684 | 359 } |
360 | |
10322 | 361 static void |
362 gaim_gtk_sound_uninit(void) | |
5684 | 363 { |
364 #ifdef USE_AO | |
365 ao_shutdown(); | |
366 #endif | |
6199 | 367 sound_initialized = FALSE; |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
368 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11463
diff
changeset
|
369 gaim_signals_disconnect_by_handle(gaim_gtk_sound_get_handle()); |
5684 | 370 } |
371 | |
11463 | 372 #ifdef USE_AO |
10322 | 373 static gboolean |
374 expire_old_child(gpointer data) | |
10074 | 375 { |
376 int ret; | |
377 pid_t pid = GPOINTER_TO_INT(data); | |
378 | |
379 ret = waitpid(pid, NULL, WNOHANG | WUNTRACED); | |
380 | |
381 if(ret == 0) { | |
382 if(kill(pid, SIGKILL) < 0) | |
10322 | 383 gaim_debug_error("gtksound", "Killing process %d failed (%s)\n", |
384 pid, strerror(errno)); | |
10074 | 385 } |
386 | |
387 return FALSE; /* do not run again */ | |
388 } | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
389 |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
390 static void |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
391 scale_pcm_data(char *data, int nframes, ao_sample_format *format, |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
392 double intercept, double minclip, double maxclip, |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
393 float scale) |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
394 { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
395 int i; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
396 float v; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
397 gint16 *data16 = (gint16*)data; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
398 gint32 *data32 = (gint32*)data; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
399 #ifdef G_HAVE_GINT64 |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
400 gint64 *data64 = (gint64*)data; |
10074 | 401 #endif |
402 | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
403 switch(format->bits) { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
404 case 16: |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
405 for(i = 0; i < nframes * format->channels; i++) { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
406 v = ((data16[i] - intercept) * scale) + intercept; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
407 v = CLAMP(v, minclip, maxclip); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
408 data16[i]=(gint16)v; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
409 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
410 break; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
411 case 32: |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
412 for(i = 0; i < nframes * format->channels; i++) { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
413 v = ((data32[i] - intercept) * scale) + intercept; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
414 v = CLAMP(v, minclip, maxclip); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
415 data32[i]=(gint32)v; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
416 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
417 break; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
418 #ifdef G_HAVE_GINT64 |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
419 case 64: |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
420 for(i = 0; i < nframes * format->channels; i++) { |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
421 v = ((data64[i] - intercept) * scale) + intercept; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
422 v = CLAMP(v, minclip, maxclip); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
423 data64[i]=(gint64)v; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
424 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
425 break; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
426 #endif |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
427 default: |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
428 gaim_debug_warning("gtksound", "Cannot scale %d bit pcm data.\n", format->bits); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
429 break; |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
430 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
431 } |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
432 #endif /* USE_AO */ |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
433 |
10322 | 434 static void |
435 gaim_gtk_sound_play_file(const char *filename) | |
5684 | 436 { |
437 const char *method; | |
11463 | 438 #ifdef USE_AO |
5684 | 439 pid_t pid; |
440 AFfilehandle file; | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
441 int volume = 50; |
5684 | 442 #endif |
443 | |
6199 | 444 if (!sound_initialized) |
445 gaim_prefs_trigger_callback("/gaim/gtk/sound/method"); | |
446 | |
10074 | 447 if (gaim_prefs_get_bool("/gaim/gtk/sound/mute")) |
5684 | 448 return; |
449 | |
450 method = gaim_prefs_get_string("/gaim/gtk/sound/method"); | |
451 | |
10074 | 452 if (!strcmp(method, "none")) { |
453 return; | |
454 } else if (!strcmp(method, "beep")) { | |
5684 | 455 gdk_beep(); |
456 return; | |
457 } | |
458 | |
459 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
460 char *tmp = g_strdup_printf(_("Unable to play sound because the chosen file (%s) does not exist."), filename); | |
461 gaim_notify_error(NULL, NULL, tmp, NULL); | |
462 g_free(tmp); | |
463 return; | |
464 } | |
465 | |
466 #ifndef _WIN32 | |
467 if (!strcmp(method, "custom")) { | |
468 const char *sound_cmd; | |
469 char *command; | |
470 GError *error = NULL; | |
471 | |
472 sound_cmd = gaim_prefs_get_string("/gaim/gtk/sound/command"); | |
473 | |
474 if (!sound_cmd || *sound_cmd == '\0') { | |
475 gaim_notify_error(NULL, NULL, | |
476 _("Unable to play sound because the " | |
477 "'Command' sound method has been chosen, " | |
478 "but no command has been set."), NULL); | |
479 return; | |
480 } | |
481 | |
7464 | 482 if(strstr(sound_cmd, "%s")) |
483 command = gaim_strreplace(sound_cmd, "%s", filename); | |
484 else | |
485 command = g_strdup_printf("%s %s", sound_cmd, filename); | |
5684 | 486 |
487 if(!g_spawn_command_line_async(command, &error)) { | |
488 char *tmp = g_strdup_printf(_("Unable to play sound because the configured sound command could not be launched: %s"), error->message); | |
489 gaim_notify_error(NULL, NULL, tmp, NULL); | |
490 g_free(tmp); | |
491 g_error_free(error); | |
492 } | |
493 | |
494 g_free(command); | |
495 return; | |
496 } | |
11463 | 497 #ifdef USE_AO |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
498 volume = gaim_prefs_get_int("/gaim/gtk/sound/volume"); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
499 volume = CLAMP(volume, 0, 100); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
500 |
5684 | 501 pid = fork(); |
502 if (pid < 0) | |
503 return; | |
504 else if (pid == 0) { | |
11463 | 505 /* Child process */ |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
506 float scale = ((float) volume * volume) / 2500; |
5684 | 507 file = afOpenFile(filename, "rb", NULL); |
508 if(file) { | |
509 ao_device *device; | |
510 ao_sample_format format; | |
511 int in_fmt; | |
512 int bytes_per_frame; | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
513 double slope, intercept, minclip, maxclip; |
5684 | 514 |
515 format.rate = afGetRate(file, AF_DEFAULT_TRACK); | |
516 format.channels = afGetChannels(file, AF_DEFAULT_TRACK); | |
517 afGetSampleFormat(file, AF_DEFAULT_TRACK, &in_fmt, | |
518 &format.bits); | |
519 | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
520 afGetPCMMapping(file, AF_DEFAULT_TRACK, &slope, |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
521 &intercept, &minclip, &maxclip); |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
522 |
5684 | 523 /* XXX: libao doesn't seem to like 8-bit sounds, so we'll |
524 * let libaudiofile make them a bit better for us */ | |
525 if(format.bits == 8) | |
526 format.bits = 16; | |
527 | |
528 afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, | |
529 AF_SAMPFMT_TWOSCOMP, format.bits); | |
530 | |
12411
8c339d9f1bb4
[gaim-migrate @ 14718]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
531 #if G_BYTE_ORDER == G_BIG_ENDIAN |
5684 | 532 format.byte_format = AO_FMT_BIG; |
533 afSetVirtualByteOrder(file, AF_DEFAULT_TRACK, | |
534 AF_BYTEORDER_BIGENDIAN); | |
12411
8c339d9f1bb4
[gaim-migrate @ 14718]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
535 #elif G_BYTE_ORDER == G_LITTLE_ENDIAN |
5684 | 536 format.byte_format = AO_FMT_LITTLE; |
537 afSetVirtualByteOrder(file, AF_DEFAULT_TRACK, | |
538 AF_BYTEORDER_LITTLEENDIAN); | |
12411
8c339d9f1bb4
[gaim-migrate @ 14718]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
539 #else |
8c339d9f1bb4
[gaim-migrate @ 14718]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
540 #warning Unknown endianness |
5684 | 541 #endif |
542 | |
543 bytes_per_frame = format.bits * format.channels / 8; | |
544 | |
545 device = ao_open_live(ao_driver, &format, NULL); | |
546 | |
547 if(device) { | |
548 int frames_read; | |
549 char buf[4096]; | |
550 int buf_frames = sizeof(buf) / bytes_per_frame; | |
551 | |
552 while((frames_read = afReadFrames(file, AF_DEFAULT_TRACK, | |
553 buf, buf_frames))) { | |
12815
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
554 if(volume != 50) |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
555 scale_pcm_data(buf, frames_read, &format, intercept, |
a8bffa7fb6ac
[gaim-migrate @ 15163]
Richard Laager <rlaager@wiktel.com>
parents:
12411
diff
changeset
|
556 minclip, maxclip, scale); |
5684 | 557 if(!ao_play(device, buf, frames_read * bytes_per_frame)) |
558 break; | |
559 } | |
560 ao_close(device); | |
561 } | |
562 afCloseFile(file); | |
563 } | |
564 ao_shutdown(); | |
565 _exit(0); | |
10074 | 566 } else { |
11463 | 567 /* Parent process */ |
10074 | 568 gaim_timeout_add(PLAY_SOUND_TIMEOUT, expire_old_child, GINT_TO_POINTER(pid)); |
5684 | 569 } |
11082 | 570 #else /* USE_AO */ |
5684 | 571 gdk_beep(); |
572 return; | |
11082 | 573 #endif /* USE_AO */ |
5684 | 574 #else /* _WIN32 */ |
10322 | 575 gaim_debug_info("sound", "Playing %s\n", filename); |
5684 | 576 |
10922
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
577 if (G_WIN32_HAVE_WIDECHAR_API ()) { |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
578 wchar_t *wc_filename = g_utf8_to_utf16(filename, |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
579 -1, NULL, NULL, NULL); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
580 if (!PlaySoundW(wc_filename, NULL, SND_ASYNC | SND_FILENAME)) |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
581 gaim_debug(GAIM_DEBUG_ERROR, "sound", "Error playing sound.\n"); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
582 g_free(wc_filename); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
583 } else { |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
584 char *l_filename = g_locale_from_utf8(filename, |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
585 -1, NULL, NULL, NULL); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
586 if (!PlaySoundA(l_filename, NULL, SND_ASYNC | SND_FILENAME)) |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
587 gaim_debug(GAIM_DEBUG_ERROR, "sound", "Error playing sound.\n"); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
588 g_free(l_filename); |
68083504217c
[gaim-migrate @ 12691]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10322
diff
changeset
|
589 } |
5684 | 590 #endif /* _WIN32 */ |
591 } | |
592 | |
10322 | 593 static void |
594 gaim_gtk_sound_play_event(GaimSoundEventID event) | |
5684 | 595 { |
596 char *enable_pref; | |
597 char *file_pref; | |
598 | |
599 if ((event == GAIM_SOUND_BUDDY_ARRIVE) && mute_login_sounds) | |
600 return; | |
601 | |
602 if (event >= GAIM_NUM_SOUNDS) { | |
10322 | 603 gaim_debug_error("sound", "got request for unknown sound: %d\n", event); |
5684 | 604 return; |
605 } | |
606 | |
607 enable_pref = g_strdup_printf("/gaim/gtk/sound/enabled/%s", | |
608 sounds[event].pref); | |
609 file_pref = g_strdup_printf("/gaim/gtk/sound/file/%s", sounds[event].pref); | |
610 | |
611 /* check NULL for sounds that don't have an option, ie buddy pounce */ | |
612 if (gaim_prefs_get_bool(enable_pref)) { | |
613 char *filename = g_strdup(gaim_prefs_get_string(file_pref)); | |
614 if(!filename || !strlen(filename)) { | |
615 if(filename) g_free(filename); | |
616 filename = g_build_filename(DATADIR, "sounds", "gaim", sounds[event].def, NULL); | |
617 } | |
618 | |
11642 | 619 gaim_sound_play_file(filename, NULL); |
5684 | 620 g_free(filename); |
621 } | |
622 | |
623 g_free(enable_pref); | |
624 g_free(file_pref); | |
625 } | |
626 | |
627 static GaimSoundUiOps sound_ui_ops = | |
628 { | |
629 gaim_gtk_sound_init, | |
10322 | 630 gaim_gtk_sound_uninit, |
5684 | 631 gaim_gtk_sound_play_file, |
632 gaim_gtk_sound_play_event | |
633 }; | |
634 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6778
diff
changeset
|
635 GaimSoundUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6778
diff
changeset
|
636 gaim_gtk_sound_get_ui_ops(void) |
5684 | 637 { |
638 return &sound_ui_ops; | |
639 } |