Updated copyright notice to 2014
[xboard.git] / usounds.c
1 /*
2  * usounds.c -- sound handling for XBoard (through external player)
3  *
4  * Copyright 1991 by Digital Equipment Corporation, Maynard,
5  * Massachusetts.
6  *
7  * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
8  * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
9  *
10  * The following terms apply to Digital Equipment Corporation's copyright
11  * interest in XBoard:
12  * ------------------------------------------------------------------------
13  * All Rights Reserved
14  *
15  * Permission to use, copy, modify, and distribute this software and its
16  * documentation for any purpose and without fee is hereby granted,
17  * provided that the above copyright notice appear in all copies and that
18  * both that copyright notice and this permission notice appear in
19  * supporting documentation, and that the name of Digital not be
20  * used in advertising or publicity pertaining to distribution of the
21  * software without specific, written prior permission.
22  *
23  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29  * SOFTWARE.
30  * ------------------------------------------------------------------------
31  *
32  * The following terms apply to the enhanced version of XBoard
33  * distributed by the Free Software Foundation:
34  * ------------------------------------------------------------------------
35  *
36  * GNU XBoard is free software: you can redistribute it and/or modify
37  * it under the terms of the GNU General Public License as published by
38  * the Free Software Foundation, either version 3 of the License, or (at
39  * your option) any later version.
40  *
41  * GNU XBoard is distributed in the hope that it will be useful, but
42  * WITHOUT ANY WARRANTY; without even the implied warranty of
43  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44  * General Public License for more details.
45  *
46  * You should have received a copy of the GNU General Public License
47  * along with this program. If not, see http://www.gnu.org/licenses/.  *
48  *
49  *------------------------------------------------------------------------
50  ** See the file ChangeLog for a revision history.  */
51
52 #include "config.h"
53
54 #include <stdio.h>
55 #include <ctype.h>
56 #include <sys/types.h>
57 #include <sys/stat.h>
58
59 #if STDC_HEADERS
60 # include <stdlib.h>
61 # include <string.h>
62 #else /* not STDC_HEADERS */
63 extern char *getenv();
64 # if HAVE_STRING_H
65 #  include <string.h>
66 # else /* not HAVE_STRING_H */
67 #  include <strings.h>
68 # endif /* not HAVE_STRING_H */
69 #endif /* not STDC_HEADERS */
70
71 #if HAVE_UNISTD_H
72 # include <unistd.h>
73 #endif
74
75 #include "common.h"
76 #include "frontend.h"
77
78
79 void
80 PlaySoundFile (char *name)
81 {
82   if (*name == NULLCHAR) {
83     return;
84   } else if (strcmp(name, "$") == 0) {
85     putc(BELLCHAR, stderr);
86   } else {
87     char buf[2048];
88     char *prefix = "", *sep = "";
89     if(appData.soundProgram[0] == NULLCHAR) return;
90     if(!strchr(name, '/')) { prefix = appData.soundDirectory; sep = "/"; }
91     snprintf(buf, sizeof(buf), "%s '%s%s%s' &", appData.soundProgram, prefix, sep, name);
92     system(buf);
93   }
94 }
95
96 void
97 RingBell ()
98 {
99   PlaySoundFile(appData.soundMove);
100 }
101
102 void
103 PlayIcsWinSound ()
104 {
105   PlaySoundFile(appData.soundIcsWin);
106 }
107
108 void
109 PlayIcsLossSound ()
110 {
111   PlaySoundFile(appData.soundIcsLoss);
112 }
113
114 void
115 PlayIcsDrawSound ()
116 {
117   PlaySoundFile(appData.soundIcsDraw);
118 }
119
120 void
121 PlayIcsUnfinishedSound ()
122 {
123   PlaySoundFile(appData.soundIcsUnfinished);
124 }
125
126 void
127 PlayAlarmSound ()
128 {
129   PlaySoundFile(appData.soundIcsAlarm);
130 }
131
132 void
133 PlayTellSound ()
134 {
135   PlaySoundFile(appData.soundTell);
136 }
137
138 void
139 PlaySoundForColor (ColorClass cc)
140 {
141     switch (cc) {
142     case ColorShout:
143       PlaySoundFile(appData.soundShout);
144       break;
145     case ColorSShout:
146       PlaySoundFile(appData.soundSShout);
147       break;
148     case ColorChannel1:
149       PlaySoundFile(appData.soundChannel1);
150       break;
151     case ColorChannel:
152       PlaySoundFile(appData.soundChannel);
153       break;
154     case ColorKibitz:
155       PlaySoundFile(appData.soundKibitz);
156       break;
157     case ColorTell:
158       PlaySoundFile(appData.soundTell);
159       break;
160     case ColorChallenge:
161       PlaySoundFile(appData.soundChallenge);
162       break;
163     case ColorRequest:
164       PlaySoundFile(appData.soundRequest);
165       break;
166     case ColorSeek:
167       PlaySoundFile(appData.soundSeek);
168       break;
169     case ColorNormal:
170     case ColorNone:
171     default:
172       break;
173     }
174 }