1 // OSXSoundPlayer.cc --- Sound player
2 //
3 // Copyright (C) 2002 - 2008, 2010 Raymond Penners & Ray Satiro
4 // All rights reserved.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "debug.hh"
25 #include <strings.h>
26 
27 #include "OSXSoundPlayer.hh"
28 #include "SoundPlayer.hh"
29 #include "Util.hh"
30 #import <AppKit/AppKit.h>
31 
OSXSoundPlayer()32 OSXSoundPlayer::OSXSoundPlayer()
33 {
34   soundDictionary = [NSMutableDictionary dictionaryWithCapacity:10];
35 }
36 
37 
~OSXSoundPlayer()38 OSXSoundPlayer::~OSXSoundPlayer()
39 {
40   [soundDictionary removeAllObjects];
41   [soundDictionary release];
42 }
43 
44 bool
capability(SoundCapability cap)45 OSXSoundPlayer::capability(SoundCapability cap)
46 {
47   if (cap == SOUND_CAP_EDIT)
48     {
49       return true;
50     }
51   return false;
52 }
53 
54 
55 void
play_sound(SoundEvent snd)56 OSXSoundPlayer::play_sound(SoundEvent snd)
57 {
58   (void) snd;
59 }
60 
61 
62 void
play_sound(string file)63 OSXSoundPlayer::play_sound(string file)
64 {
65   if (wav_file == NULL)
66     {
67       wav_file = strdup(file.c_str());
68       run();
69     }
70 }
71 
72 
73 void
run()74 OSXSoundPlayer::run()
75 {
76   NSString* filename = [NSString stringWithUTF8String: wav_file];
77   NSSound *sound = [soundDictionary objectForKey:filename];
78   if (sound == nil) {
79     sound = [[NSSound alloc] initWithContentsOfFile:filename byReference:NO];
80     [soundDictionary setObject:sound forKey:filename];
81   }
82   [sound stop];
83   [sound play];
84   free((void*)wav_file);
85   wav_file = NULL;
86 }
87 
88 
get_sound_enabled(SoundEvent snd,bool & enabled)89 bool OSXSoundPlayer::get_sound_enabled(SoundEvent snd, bool &enabled)
90 {
91   (void) snd;
92   (void) enabled;
93   return false;
94 }
95 
set_sound_enabled(SoundEvent snd,bool enabled)96 void OSXSoundPlayer::set_sound_enabled(SoundEvent snd, bool enabled)
97 {
98   (void) snd;
99   (void) enabled;
100 }
101 
get_sound_wav_file(SoundEvent snd,std::string & wav_file)102 bool OSXSoundPlayer::get_sound_wav_file(SoundEvent snd, std::string &wav_file)
103 {
104   (void) snd;
105   (void) wav_file;
106   return false;
107 }
108 
set_sound_wav_file(SoundEvent snd,const std::string & wav_file)109 void OSXSoundPlayer::set_sound_wav_file(SoundEvent snd, const std::string &wav_file)
110 {
111   (void) snd;
112   (void) wav_file;
113 }
114 
115