annotate src/gtksound.c @ 13646:e8e5931e7e8d

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