annotate src/sound.c @ 5361:953aa05279f4

[gaim-migrate @ 5737] Merged the state code and away code into state.[ch]. You can now see what users are using MSN Mobile. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 13 May 2003 02:51:13 +0000
parents eae93f3e46bd
children ad445074d239
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
4562
2c8372d4fb2a [gaim-migrate @ 4843]
Nathan Walp <nwalp@pidgin.im>
parents: 4561
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
5 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
23 #ifdef HAVE_CONFIG_H
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
24 #include <config.h>
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
25 #endif
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26 #include <stdio.h>
1057
d50d3abb9eb7 [gaim-migrate @ 1067]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1006
diff changeset
27 #include <stdlib.h>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 #include <string.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
29
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
30 #ifndef _WIN32
63
12894b62d206 [gaim-migrate @ 73]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1
diff changeset
31 #include <unistd.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
32 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
33 #include <windows.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
34 #include <mmsystem.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
35 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
36
4592
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
37 #ifdef HAVE_ENDIAN_H
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
38 #include <endian.h>
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
39 #endif
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
40
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
41 #ifdef USE_AO
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
42 #include <ao/ao.h>
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
43 #include <audiofile.h>
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
44 #endif /* USE_AO */
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
45 #ifdef USE_NAS_AUDIO
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
46 #include <audio/audiolib.h>
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
47 #include <audio/soundlib.h>
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
48 #endif /* USE_NAS_AUDIO */
4012
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
49
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50 #include "gaim.h"
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
51 #include "sound.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52
4019
e53d9f9969d0 [gaim-migrate @ 4219]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4014
diff changeset
53 #ifdef _WIN32
e53d9f9969d0 [gaim-migrate @ 4219]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4014
diff changeset
54 #include "win32dep.h"
e53d9f9969d0 [gaim-migrate @ 4219]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4014
diff changeset
55 #endif
e53d9f9969d0 [gaim-migrate @ 4219]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4014
diff changeset
56
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
57 struct gaim_sound_event {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
58 char *label;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
59 guint opt;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
60 char *def;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
61 };
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
62
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
63 #ifdef USE_AO
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
64 static gboolean ao_initialized=FALSE;
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
65 static int ao_driver = -1;
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
66 #endif /* USE_AO */
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
67
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
68
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
69 static gboolean mute_login_sounds = FALSE;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
70 static gboolean mute_sounds = FALSE;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
71 static char *sound_cmd = NULL;
3319
3a05fcb133c4 [gaim-migrate @ 3337]
Sean Egan <seanegan@gmail.com>
parents: 3284
diff changeset
72
4082
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4019
diff changeset
73 /* description, option bit, default sound file *
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4019
diff changeset
74 * set the option bit to 0 to have it not display in prefs *
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4019
diff changeset
75 * the order here has to match the defines in gaim.h. *
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4019
diff changeset
76 * -Robot101 */
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
77 static struct gaim_sound_event sounds[GAIM_NUM_SOUNDS] = {
4013
73853a0a1a77 [gaim-migrate @ 4213]
Sean Egan <seanegan@gmail.com>
parents: 4012
diff changeset
78 {N_("Buddy logs in"), OPT_SOUND_LOGIN, "arrive.wav"},
73853a0a1a77 [gaim-migrate @ 4213]
Sean Egan <seanegan@gmail.com>
parents: 4012
diff changeset
79 {N_("Buddy logs out"), OPT_SOUND_LOGOUT, "leave.wav"},
4012
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
80 {N_("Message received"), OPT_SOUND_RECV, "receive.wav"},
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
81 {N_("Message received begins conversation"), OPT_SOUND_FIRST_RCV, "receive.wav"},
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
82 {N_("Message sent"), OPT_SOUND_SEND, "send.wav"},
4013
73853a0a1a77 [gaim-migrate @ 4213]
Sean Egan <seanegan@gmail.com>
parents: 4012
diff changeset
83 {N_("Person enters chat"), OPT_SOUND_CHAT_JOIN, "arrive.wav"},
73853a0a1a77 [gaim-migrate @ 4213]
Sean Egan <seanegan@gmail.com>
parents: 4012
diff changeset
84 {N_("Person leaves chat"), OPT_SOUND_CHAT_PART, "leave.wav"},
4012
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
85 {N_("You talk in chat"), OPT_SOUND_CHAT_YOU_SAY, "send.wav"},
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
86 {N_("Others talk in chat"), OPT_SOUND_CHAT_SAY, "receive.wav"},
3326
03daf01a8000 [gaim-migrate @ 3344]
Jim Seymour <jseymour>
parents: 3319
diff changeset
87 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */
4012
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
88 {NULL, 0, "redalert.wav"},
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
89 {N_("Someone says your name in chat"), OPT_SOUND_CHAT_NICK, "redalert.wav"}
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
90 };
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
91
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
92 static char *sound_file[GAIM_NUM_SOUNDS];
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
93
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
94
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
95 #ifdef USE_AO
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
96 static void check_ao_init()
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
97 {
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
98 if(!ao_initialized) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
99 gaim_debug(GAIM_DEBUG_INFO, "sound",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
100 "Initializing sound output drivers.\n");
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
101 ao_initialize();
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
102 ao_initialized = TRUE;
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
103 }
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
104 }
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
105 #endif /* USE_AO */
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
106
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
107 void gaim_sound_change_output_method() {
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
108 #ifdef USE_AO
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
109 ao_driver = -1;
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
110
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
111 if ((sound_options & OPT_SOUND_ESD) || (sound_options & OPT_SOUND_ARTS) ||
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
112 (sound_options & OPT_SOUND_NORMAL)) {
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
113 check_ao_init();
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
114 if (ao_driver == -1 && (sound_options & OPT_SOUND_ESD)) {
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
115 ao_driver = ao_driver_id("esd");
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
116 }
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
117 if(ao_driver == -1 && (sound_options & OPT_SOUND_ARTS)) {
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
118 ao_driver = ao_driver_id("arts");
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
119 }
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
120 if (ao_driver == -1) {
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
121 ao_driver = ao_default_driver_id();
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
122 }
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
123 }
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
124 if(ao_driver != -1) {
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
125 ao_info *info = ao_driver_info(ao_driver);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
126 gaim_debug(GAIM_DEBUG_INFO, "sound",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
127 "Sound output driver loaded: %s\n", info->name);
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
128 }
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
129 #endif /* USE_AO */
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
130 #ifdef USE_NAS
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
131 if((sound_options & OPT_SOUND_NAS))
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
132 gaim_debug(GAIM_DEBUG_INFO, "sound",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
133 "Sound output driver loaded: NAS output\n");
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
134 #endif /* USE_NAS */
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
135 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
136
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
137 void gaim_sound_quit()
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
138 {
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
139 #ifdef USE_AO
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
140 if(ao_initialized)
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
141 ao_shutdown();
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
142 #endif
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
143 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
144
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
145
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
146 #ifdef USE_NAS_AUDIO
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
147 static gboolean play_file_nas(const char *filename)
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
148 {
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
149 AuServer *nas_serv;
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
150 gboolean ret = FALSE;
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
151
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
152 if((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) {
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
153 ret = AuSoundPlaySynchronousFromFile(nas_serv, filename, 100);
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
154 AuCloseServer(nas_serv);
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
155 }
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
156
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
157 return ret;
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
158 }
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
159
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
160 #endif /* USE_NAS_AUDIO */
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
161
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
162 void gaim_sound_play_file(char *filename)
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
163 {
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
164 #if defined(USE_NAS_AUDIO) || defined(USE_AO)
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
165 pid_t pid;
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
166 #ifdef USE_AO
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
167 AFfilehandle file;
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
168 #endif
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
169 #endif
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
170
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
171 if (mute_sounds)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
172 return;
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
173
3901
7740c891537e [gaim-migrate @ 4054]
Luke Schierer <lschiere@pidgin.im>
parents: 3630
diff changeset
174 if (awaymessage && !(sound_options & OPT_SOUND_WHEN_AWAY))
7740c891537e [gaim-migrate @ 4054]
Luke Schierer <lschiere@pidgin.im>
parents: 3630
diff changeset
175 return; /* check here in case a buddy pounce plays a file while away */
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
176
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
177 if (sound_options & OPT_SOUND_BEEP) {
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
178 gdk_beep();
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
179 return;
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
180 }
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
181
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
182 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
5281
eae93f3e46bd [gaim-migrate @ 5653]
Luke Schierer <lschiere@pidgin.im>
parents: 5211
diff changeset
183 char *tmp = g_strdup_printf(_("Unable to play sound because the chosen file (%s) does not exist."), filename);
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
184 do_error_dialog(tmp, NULL, GAIM_ERROR);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
185 g_free(tmp);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
186 return;
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
187 }
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
188
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
189 #ifndef _WIN32
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
190 if ((sound_options & OPT_SOUND_CMD)) {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
191 char *command;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
192 GError *error = NULL;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
193
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
194 if(!sound_cmd) {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
195 do_error_dialog(_("Unable to play sound because the 'Command' sound method has been chosen, but no command has been set."), NULL, GAIM_ERROR);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
196 return;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
197 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
198
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
199 command = g_strdup_printf(sound_cmd, filename);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
200
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
201 if(!g_spawn_command_line_async(command, &error)) {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
202 char *tmp = g_strdup_printf(_("Unable to play sound because the configured sound command could not be launched: %s"), error->message);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
203 do_error_dialog(tmp, NULL, GAIM_ERROR);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
204 g_free(tmp);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
205 g_error_free(error);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
206 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
207
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
208 g_free(command);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
209 return;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
210 }
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
211 #if defined(USE_NAS_AUDIO) || defined(USE_AO)
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
212 pid = fork();
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
213 if (pid < 0)
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
214 return;
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
215 else if (pid == 0) {
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
216 #ifdef USE_NAS_AUDIO
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
217 if ((sound_options & OPT_SOUND_NAS)) {
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
218 if (play_file_nas(filename))
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
219 _exit(0);
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
220 }
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
221 #endif /* USE_NAS_AUDIO */
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
222
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
223 #ifdef USE_AO
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
224 file = afOpenFile(filename, "rb", NULL);
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
225 if(file) {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
226 ao_device *device;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
227 ao_sample_format format;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
228 int in_fmt;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
229 int bytes_per_frame;
4429
bf770f11132b [gaim-migrate @ 4704]
Luke Schierer <lschiere@pidgin.im>
parents: 4082
diff changeset
230
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
231 format.rate = afGetRate(file, AF_DEFAULT_TRACK);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
232 format.channels = afGetChannels(file, AF_DEFAULT_TRACK);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
233 afGetSampleFormat(file, AF_DEFAULT_TRACK, &in_fmt,
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
234 &format.bits);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
235
4878
77b04219f3e2 [gaim-migrate @ 5208]
Nathan Walp <nwalp@pidgin.im>
parents: 4592
diff changeset
236 /* XXX: libao doesn't seem to like 8-bit sounds, so we'll
77b04219f3e2 [gaim-migrate @ 5208]
Nathan Walp <nwalp@pidgin.im>
parents: 4592
diff changeset
237 * let libaudiofile make them a bit better for us */
77b04219f3e2 [gaim-migrate @ 5208]
Nathan Walp <nwalp@pidgin.im>
parents: 4592
diff changeset
238 if(format.bits == 8)
77b04219f3e2 [gaim-migrate @ 5208]
Nathan Walp <nwalp@pidgin.im>
parents: 4592
diff changeset
239 format.bits = 16;
77b04219f3e2 [gaim-migrate @ 5208]
Nathan Walp <nwalp@pidgin.im>
parents: 4592
diff changeset
240
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
241 afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK,
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
242 AF_SAMPFMT_TWOSCOMP, format.bits);
4429
bf770f11132b [gaim-migrate @ 4704]
Luke Schierer <lschiere@pidgin.im>
parents: 4082
diff changeset
243
4592
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
244 #if __BYTE_ORDER == __BIG_ENDIAN
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
245 format.byte_format = AO_FMT_BIG;
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
246 afSetVirtualByteOrder(file, AF_DEFAULT_TRACK,
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
247 AF_BYTEORDER_BIGENDIAN);
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
248 #elif __BYTE_ORDER == __LITTLE_ENDIAN
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
249 format.byte_format = AO_FMT_LITTLE;
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
250 afSetVirtualByteOrder(file, AF_DEFAULT_TRACK,
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
251 AF_BYTEORDER_LITTLEENDIAN);
b69bbf9b1044 [gaim-migrate @ 4876]
Nathan Walp <nwalp@pidgin.im>
parents: 4581
diff changeset
252 #endif
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
253
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
254 bytes_per_frame = format.bits * format.channels / 8;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
255
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
256 device = ao_open_live(ao_driver, &format, NULL);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
257
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
258 if(device) {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
259 int frames_read;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
260 char buf[4096];
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
261 int buf_frames = sizeof(buf) / bytes_per_frame;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
262
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
263 while((frames_read = afReadFrames(file, AF_DEFAULT_TRACK,
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
264 buf, buf_frames))) {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
265 if(!ao_play(device, buf, frames_read * bytes_per_frame))
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
266 break;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
267 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
268 ao_close(device);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
269 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
270 afCloseFile(file);
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
271 }
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
272 ao_shutdown();
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
273 #endif /* USE_AO */
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
274 _exit(0);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
275 }
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
276 #else /* USE_NAS_AUDIO || USE_AO */
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
277 gdk_beep();
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
278 return;
4581
4b1e24835bbf [gaim-migrate @ 4864]
Nathan Walp <nwalp@pidgin.im>
parents: 4579
diff changeset
279 #endif /* USE_NAS_AUDIO || USE_AO */
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
280 #else /* _WIN32 */
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
281 gaim_debug(GAIM_DEBUG_INFO, "sound", "Playing %s\n", filename);
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
282
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
283 if (!PlaySound(filename, 0, SND_ASYNC | SND_FILENAME))
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
284 gaim_debug(GAIM_DEBUG_ERROR, "sound", "Error playing sound.\n");
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
285 #endif /* _WIN32 */
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
286 }
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
287
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
288 void gaim_sound_play_event(GaimSoundEventID event)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
289 {
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
290 if ((event == GAIM_SOUND_BUDDY_ARRIVE) && mute_login_sounds)
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
291 return;
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
292
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
293 if (event >= GAIM_NUM_SOUNDS) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
294 gaim_debug(GAIM_DEBUG_MISC, "sound",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4878
diff changeset
295 "got request for unknown sound: %d\n", event);
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
296 return;
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
297 }
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
298
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
299 /* check NULL for sounds that don't have an option, ie buddy pounce */
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
300 if ((sound_options & sounds[event].opt) || (sounds[event].opt == 0)) {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
301 if (sound_file[event]) {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
302 gaim_sound_play_file(sound_file[event]);
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
303 } else {
4004
b2520034b62f [gaim-migrate @ 4204]
Sean Egan <seanegan@gmail.com>
parents: 3901
diff changeset
304 gchar *filename = NULL;
b2520034b62f [gaim-migrate @ 4204]
Sean Egan <seanegan@gmail.com>
parents: 3901
diff changeset
305
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
306 filename = g_build_filename(DATADIR, "sounds", "gaim", sounds[event].def, NULL);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
307 gaim_sound_play_file(filename);
4004
b2520034b62f [gaim-migrate @ 4204]
Sean Egan <seanegan@gmail.com>
parents: 3901
diff changeset
308 g_free(filename);
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
309 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
310 }
64
b1d7336cba85 [gaim-migrate @ 74]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 63
diff changeset
311 }
4561
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
312
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
313 void gaim_sound_set_mute(gboolean mute)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
314 {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
315 mute_sounds = mute;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
316 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
317
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
318 gboolean gaim_sound_get_mute()
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
319 {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
320 return mute_sounds;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
321 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
322
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
323 void gaim_sound_set_login_mute(gboolean mute)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
324 {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
325 mute_login_sounds = mute;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
326 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
327
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
328 void gaim_sound_set_event_file(GaimSoundEventID event, const char *filename)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
329 {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
330 if(event >= GAIM_NUM_SOUNDS)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
331 return;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
332
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
333 if(sound_file[event])
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
334 g_free(sound_file[event]);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
335
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
336 sound_file[event] = g_strdup(filename);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
337 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
338
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
339
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
340 char *gaim_sound_get_event_file(GaimSoundEventID event)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
341 {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
342 if(event >= GAIM_NUM_SOUNDS)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
343 return NULL;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
344
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
345 return sound_file[event];
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
346 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
347
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
348 guint gaim_sound_get_event_option(GaimSoundEventID event)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
349 {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
350 if(event >= GAIM_NUM_SOUNDS)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
351 return 0;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
352
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
353 return sounds[event].opt;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
354 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
355
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
356 char *gaim_sound_get_event_label(GaimSoundEventID event)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
357 {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
358 if(event >= GAIM_NUM_SOUNDS)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
359 return NULL;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
360
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
361 return sounds[event].label;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
362 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
363
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
364
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
365 void gaim_sound_set_command(const char *cmd)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
366 {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
367 if(sound_cmd)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
368 g_free(sound_cmd);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
369 if(strlen(cmd) > 0)
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
370 sound_cmd = g_strdup(cmd);
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
371 else
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
372 sound_cmd = NULL;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
373 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
374
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
375 char *gaim_sound_get_command()
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
376 {
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
377 return sound_cmd;
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
378 }
9df99116840a [gaim-migrate @ 4842]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
379