dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / application / UiBuilder / SimpleSoundCanvas.cpp
blobfae34fd52e9a545dcd7ae95a8d970e29e7f8c5b2
1 #include "FirstUiBuilder.h"
2 #include "SimpleSoundCanvas.h"
4 #include "FileLocator.h"
6 #include <cstdio>
8 SimpleSoundCanvas::SimpleSoundCanvas() :
9 UISoundCanvas (),
10 m_soundMap ()
15 SimpleSoundCanvas::~SimpleSoundCanvas()
18 for (SoundMap_t::iterator iter = m_soundMap.begin (); iter != m_soundMap.end (); ++iter)
20 delete (*iter).second;
21 (*iter).second = 0;
24 m_soundMap.clear ();
28 void SimpleSoundCanvas::Play( const char *name )
31 assert (name);
33 SoundMap_t::const_iterator find_iter = m_soundMap.find (name);
35 if (find_iter == m_soundMap.end ())
37 UINarrowString filename (name);
38 filename += ".wav";
40 UINarrowString result;
42 if ( FileLocator::gFileLocator ().findFile (filename.c_str (), result) == false)
43 return;
45 FILE * fl = fopen (result.c_str (), "rb");
47 if (fl == 0)
48 return;
50 fseek (fl, 0, SEEK_END);
51 long len = ftell (fl);
52 fseek (fl, 0, SEEK_SET);
54 char * buf = new char [len];
56 if (!fread (buf, len, 1, fl))
58 delete[] buf;
59 return;
62 fclose (fl);
64 std::pair<SoundMap_t::const_iterator, bool> retval = m_soundMap.insert (SoundMap_t::value_type (name, buf));
66 find_iter = retval.first;
69 PlaySound ((*find_iter).second, NULL, SND_MEMORY | SND_ASYNC | SND_NOWAIT | SND_NOSTOP);