root/juggler/tags/1.0.7/Sound/vjSoundManager.cpp

Revision 8789, 4.9 kB (checked in by patrickh, 7 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002
4  *   by Iowa State University
5  *
6  * Original Authors:
7  *   Allen Bierbaum, Christopher Just,
8  *   Patrick Hartling, Kevin Meinert,
9  *   Carolina Cruz-Neira, Albert Baker
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * -----------------------------------------------------------------
27  * File:          $RCSfile$
28  * Date modified: $Date$
29  * Version:       $Revision$
30  * -----------------------------------------------------------------
31  *
32  *************** <auto-copyright.pl END do not edit this line> ***************/
33
34 #include <vjConfig.h>
35 #include <Sound/vjSoundManager.h>
36 #include <Sound/vjSoundFactory.h>
37
38 //vjSoundManager* vjSoundManager::_instance = NULL;   //: The instance ptr
39 vjSingletonImp(vjSoundManager);
40
41 vjSoundManager::vjSoundManager() : mSoundEngine( NULL )
42 {
43
44 }
45
46
47 //: Add the chunk to the configuration
48 //! PRE: configCanHandle(chunk) == true
49 bool vjSoundManager::configAdd(vjConfigChunk* chunk)
50 {
51    if (!configCanHandle( chunk ))
52    {
53       return false;
54    }
55
56    if (mSoundEngine == NULL)
57    {
58       // if not created yet, create it, adding the first config.
59       mSoundEngine = vjSoundFactory::instance()->loadEngine(chunk);
60       vjDEBUG(vjDBG_ALL,vjDBG_CONFIG_LVL) << clrOutNORM(clrGREEN,"vjSoundEngine:") << " created and added config" << "\n" << vjDEBUG_FLUSH;
61    }
62    else
63    {
64       // if already created, then add to it.
65       mSoundEngine->config( chunk );
66       vjDEBUG(vjDBG_ALL,vjDBG_CONFIG_LVL) << clrOutNORM(clrGREEN,"vjSoundEngine:")  << " Added config." << "\n" << vjDEBUG_FLUSH;
67
68    }
69
70    if(mSoundEngine == NULL)
71    {
72       vjDEBUG(vjDBG_ALL,vjDBG_CRITICAL_LVL)
73                << clrOutNORM(clrRED,"ERROR:")
74                << "Failed to load sound engine\n" << vjDEBUG_FLUSH;
75       return false;
76    }
77
78    return true;
79 }
80
81 //: Remove the chunk from the current configuration
82 //! PRE: configCanHandle(chunk) == true
83 bool vjSoundManager::configRemove(vjConfigChunk* chunk)
84 {
85    return false;
86 }
87
88 //: Can the handler handle the given chunk?
89 //! RETURNS: true - Can handle it
90 //+          false - Can't handle it
91 bool vjSoundManager::configCanHandle(vjConfigChunk* chunk)
92 {
93    return vjSoundFactory::instance()->recognizeEngine( chunk );
94 }
95
96 //: Enable a frame to be drawn
97 void vjSoundManager::update()
98 {
99    if(mSoundEngine == NULL)
100    {
101       printAlert();
102       mSoundEngine = new vjSoundEngine;
103    }
104
105    if(mSoundEngine != NULL)
106       mSoundEngine->update();
107 }
108
109 //: Blocks until the end of the frame
110 //! POST: The frame has been drawn
111 void vjSoundManager::sync()
112 {
113    if(mSoundEngine == NULL)
114    {
115       printAlert();
116       mSoundEngine = new vjSoundEngine;
117    }
118
119    if(mSoundEngine != NULL)
120       mSoundEngine->sync();
121 }
122
123 // given an alias, return the handle.
124 // TODO: if called twice with name alias, should return same pointer.
125 // memory managed by engine...
126 // returns NULL if invalid name.
127 vjSound* vjSoundManager::getHandle( const char* const alias )
128 {
129    if(mSoundEngine == NULL)
130    {
131       printAlert();
132       mSoundEngine = new vjSoundEngine;
133    }
134
135    if(mSoundEngine != NULL)
136       return mSoundEngine->getHandle( alias );
137    else
138       return NULL;
139 }
140
141 //: Factory function to create a new sound.
142 // memory managed by engine
143 vjSound* vjSoundManager::newSound()
144 {
145    if(mSoundEngine == NULL)
146    {
147       printAlert();
148       mSoundEngine = new vjSoundEngine;
149    }
150
151    if(mSoundEngine != NULL)
152       return mSoundEngine->newSound();
153    else
154       return NULL;
155 }
156
157 void vjSoundManager::printAlert()
158 {
159    vjDEBUG(vjDBG_ALL,vjDBG_CRITICAL_LVL)
160       << clrOutNORM(clrYELLOW,"[SoundEngine] ALERT:") << std::endl
161       << vjDEBUG_FLUSH;
162    vjDEBUG_NEXT(vjDBG_ALL,vjDBG_CRITICAL_LVL)
163       << "A sound engine wasn't created yet, so VR Juggler is using\n"
164       << vjDEBUG_FLUSH;
165    vjDEBUG_NEXT(vjDBG_ALL,vjDBG_CRITICAL_LVL)
166       << "stubbed out version--your app should run, but you will\n"
167       << vjDEBUG_FLUSH;
168    vjDEBUG_NEXT(vjDBG_ALL,vjDBG_CRITICAL_LVL)
169       << "not hear sound (run-time reconfiguration of the SoundEngine\n"
170       << vjDEBUG_FLUSH;
171    vjDEBUG_NEXT(vjDBG_ALL,vjDBG_CRITICAL_LVL)
172       << "at this point may fail or crash the system).\n"
173       << vjDEBUG_FLUSH;
174 }
Note: See TracBrowser for help on using the browser.