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