Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

pfSoundTraverser Class Reference

This is a collection of Performer traversers... More...

#include <pfSoundTraverser.h>

List of all members.

Static Public Methods

void preForkInit ()
 This function must be called pfSoundTraverser::preForkInit() in your VR Juggler app's preForkInit() member function. More...

void replace (pfNode *node, const std::string &keyName="_Sound_")
 This is a Performer traverser that will replace any node ending in keyName in your scene graph with a pfSoundNode. More...

void enable (pfNode *node)
 Enables the sound, keeping the state whether it is triggered or stopped. More...

void disable (pfNode *node)
 Disables the sound, keeping the state whether it is triggered or stopped. More...

void trigger (pfNode *node)
 Triggers the sound. More...

void stop (pfNode *node)
 Stops the sound. More...


Static Protected Methods

int soundNodesTrigger (pfuTraverser *trav)
 Triggers every Sound in the graph. More...

int soundNodesStop (pfuTraverser *trav)
 Stops every Sound in the graph. More...

int soundNodesEnable (pfuTraverser *trav)
 Enables every Sound in the graph. More...

int soundNodesDisable (pfuTraverser *trav)
 Disables every Sound in the graph. More...

int nodesReplaceWithSound (pfuTraverser *trav)
 Used to traverse - don't call. More...


Detailed Description

This is a collection of Performer traversers...

REQUIRED!!! You must call pfSoundTraverser::preForkInit() in your juggler app's preForkInit() member function. Your app is likely to crash otherwise!!

Definition at line 63 of file pfSoundTraverser.h.


Member Function Documentation

void pfSoundTraverser::preForkInit   [inline, static]
 

This function must be called pfSoundTraverser::preForkInit() in your VR Juggler app's preForkInit() member function.

Your app is likely to crash otherwise!!

Definition at line 71 of file pfSoundTraverser.h.

References pfSoundNode::init.

00072    {
00073       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00074          << "[pfSoundTraverser] pfSoundTraverser::preForkInit(): Initializing sound node class type with Performer\n"
00075          << vprDEBUG_FLUSH;
00076       pfSoundNode::init();
00077    }

void pfSoundTraverser::replace pfNode *    node,
const std::string &    keyName = "_Sound_"
[inline, static]
 

This is a Performer traverser that will replace any node ending in keyName in your scene graph with a pfSoundNode.

For example, if mKeyName == _Sound_, and your nodename == Gong_Sound_ then that node will be replaced with a new pfSoundNode of a sound called "Gong"

Definition at line 86 of file pfSoundTraverser.h.

References nodesReplaceWithSound.

00087    {
00088       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00089          << clrOutNORM(clrGREEN, "pfSoundTraverser: ")
00090          << "Checking graph for soundnodes (nodes with the "
00091          << keyName << " extension...\n" << vprDEBUG_FLUSH;
00092 
00093       // use the performer traversal mechanism
00094        pfuTraverser trav;
00095        pfuInitTraverser( &trav );
00096 
00097        trav.preFunc = pfSoundTraverser::nodesReplaceWithSound;
00098        trav.data = const_cast<std::string*>( &keyName );
00099 
00100        pfuTraverse( node, &trav );
00101    }

void pfSoundTraverser::enable pfNode *    node [inline, static]
 

Enables the sound, keeping the state whether it is triggered or stopped.

Definition at line 106 of file pfSoundTraverser.h.

References soundNodesEnable.

00107    {
00108       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00109          << clrOutNORM(clrGREEN,"pfSoundTraverser: [enable]")
00110          << " Enabling sounds in subgraph.\n"
00111          << vprDEBUG_FLUSH;
00112 
00113       // use the performer traversal mechanism
00114        pfuTraverser trav;
00115        pfuInitTraverser( &trav );
00116 
00117        trav.preFunc = pfSoundTraverser::soundNodesEnable;
00118        trav.data = NULL;
00119 
00120        pfuTraverse( node, &trav );
00121    }

void pfSoundTraverser::disable pfNode *    node [inline, static]
 

Disables the sound, keeping the state whether it is triggered or stopped.

after this, an enable would respect the previous triggered/stopped state.

Definition at line 127 of file pfSoundTraverser.h.

References soundNodesDisable.

00128    {
00129       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00130          << clrOutNORM(clrGREEN, "pfSoundTraverser: [disable]")
00131          << " Disabling sounds in subgraph.\n" << vprDEBUG_FLUSH;
00132 
00133       // use the performer traversal mechanism
00134        pfuTraverser trav;
00135        pfuInitTraverser( &trav );
00136 
00137        trav.preFunc = pfSoundTraverser::soundNodesDisable;
00138        trav.data = NULL;
00139 
00140        pfuTraverse( node, &trav );
00141    }

void pfSoundTraverser::trigger pfNode *    node [inline, static]
 

Triggers the sound.

Definition at line 144 of file pfSoundTraverser.h.

References soundNodesTrigger.

00145    {
00146       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00147          << clrOutNORM(clrGREEN, "pfSoundTraverser: [soundOn]")
00148          << " Triggering sounds in subgraph.\n" << vprDEBUG_FLUSH;
00149 
00150       // use the performer traversal mechanism
00151        pfuTraverser trav;
00152        pfuInitTraverser( &trav );
00153 
00154        trav.preFunc = pfSoundTraverser::soundNodesTrigger;
00155        trav.data = NULL;
00156 
00157        pfuTraverse( node, &trav );
00158    }

void pfSoundTraverser::stop pfNode *    node [inline, static]
 

Stops the sound.

Definition at line 161 of file pfSoundTraverser.h.

References soundNodesStop.

00162    {
00163       vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00164          << clrOutNORM(clrGREEN,"pfSoundTraverser: [soundOff]")
00165          << " Stopping sounds in subgraph.\n" << vprDEBUG_FLUSH;
00166 
00167       // use the performer traversal mechanism
00168        pfuTraverser trav;
00169        pfuInitTraverser( &trav );
00170 
00171        trav.preFunc = pfSoundTraverser::soundNodesStop;
00172        trav.data = NULL;
00173 
00174        pfuTraverse( node, &trav );
00175    }

int pfSoundTraverser::soundNodesTrigger pfuTraverser *    trav [inline, static, protected]
 

Triggers every Sound in the graph.

Definition at line 180 of file pfSoundTraverser.h.

References pfSoundNode::getClassType.

Referenced by trigger.

00181    {
00182       pfNode* currentNode = trav->node;
00183       if (currentNode->isOfType( pfSoundNode::getClassType() ))
00184       {
00185          pfSoundNode* soundNode = static_cast<pfSoundNode*>( currentNode );
00186 
00187          // get the name
00188          const char* nodeNameChar = soundNode->getName();
00189          std::string nodeName;
00190          if (nodeNameChar == NULL)
00191               nodeName = "";
00192          else
00193               nodeName = nodeNameChar;
00194 
00195          // unpause the sound, unmute it too
00196          sonix::instance()->trigger( nodeName );
00197          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) << clrOutNORM( clrYELLOW, "[SoundTrigger] " )
00198             << "Setting the " << nodeName
00199             << " sound to <triggered>\n" << vprDEBUG_FLUSH;
00200       }
00201       else
00202       {
00203          //std::cout<<"Not a sound Node: "<<currentNode->getName()<<" classtype="<<currentNode->getClassType()<<"!="<<pfSoundNode::getClassType()<<"\n"<<std::flush;
00204       }
00205 
00206       return PFTRAV_CONT;      // Return continue
00207    }

int pfSoundTraverser::soundNodesStop pfuTraverser *    trav [inline, static, protected]
 

Stops every Sound in the graph.

Definition at line 210 of file pfSoundTraverser.h.

References pfSoundNode::getClassType.

Referenced by stop.

00211    {
00212       pfNode* currentNode = trav->node;
00213       if (currentNode->isOfType( pfSoundNode::getClassType() ))
00214       {
00215          pfSoundNode* soundNode = static_cast<pfSoundNode*>( currentNode );
00216 
00217          // get the name
00218          const char* nodeNameChar = soundNode->getName();
00219          std::string nodeName;
00220          if (nodeNameChar == NULL)
00221               nodeName = "";
00222          else
00223               nodeName = nodeNameChar;
00224 
00225          // unpause the sound, unmute it too
00226          sonix::instance()->stop( nodeName );
00227 
00228          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) << clrOutNORM(clrYELLOW,"[SoundStop] ")
00229             << "Setting the " << nodeName
00230             << " sound to <stopped>\n" << vprDEBUG_FLUSH;
00231       }
00232       else
00233       {
00234          //std::cout<<"Not a sound Node: "<<currentNode->getName()<<" classtype="<<currentNode->getClassType()<<"!="<<pfSoundNode::getClassType()<<"\n"<<std::flush;
00235       }
00236 
00237       return PFTRAV_CONT;      // Return continue
00238    }

int pfSoundTraverser::soundNodesEnable pfuTraverser *    trav [inline, static, protected]
 

Enables every Sound in the graph.

Definition at line 241 of file pfSoundTraverser.h.

References pfSoundNode::getClassType.

Referenced by enable.

00242    {
00243       pfNode* currentNode = trav->node;
00244       if (currentNode->isOfType( pfSoundNode::getClassType() ))
00245       {
00246          pfSoundNode* soundNode = static_cast<pfSoundNode*>( currentNode );
00247 
00248          // get the name
00249          const char* nodeNameChar = soundNode->getName();
00250          std::string nodeName;
00251          if (nodeNameChar == NULL)
00252               nodeName = "";
00253          else
00254               nodeName = nodeNameChar;
00255 
00256          // unpause the sound, unmute it too
00257          sonix::instance()->unpause( nodeName );
00258 
00259          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) << clrOutNORM(clrYELLOW,"[SoundEnable] ")
00260             << "Setting the " << nodeName
00261             << " sound to <enabled>\n" << vprDEBUG_FLUSH;
00262       }
00263       else
00264       {
00265          //std::cout<<"Not a sound Node: "<<currentNode->getName()<<" classtype="<<currentNode->getClassType()<<"!="<<pfSoundNode::getClassType()<<"\n"<<std::flush;
00266       }
00267 
00268       return PFTRAV_CONT;      // Return continue
00269    }

int pfSoundTraverser::soundNodesDisable pfuTraverser *    trav [inline, static, protected]
 

Disables every Sound in the graph.

Definition at line 272 of file pfSoundTraverser.h.

References pfSoundNode::getClassType.

Referenced by disable.

00273    {
00274       pfNode* currentNode = trav->node;
00275       if (currentNode->isOfType( pfSoundNode::getClassType() ))
00276       {
00277          pfSoundNode* soundNode = static_cast<pfSoundNode*>( currentNode );
00278 
00279          // get the name
00280          const char* nodeNameChar = soundNode->getName();
00281          std::string nodeName;
00282          if (nodeNameChar == NULL)
00283               nodeName = "";
00284          else
00285               nodeName = nodeNameChar;
00286 
00287          // pause the sound, mute it too in case it is triggered again
00288          sonix::instance()->pause( nodeName );
00289 
00290          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) << clrOutNORM(clrYELLOW,"[SoundDisable] ")
00291             << "Setting the " << nodeName
00292             << " sound to <disabled>\n" << vprDEBUG_FLUSH;
00293       }
00294       else
00295       {
00296          //std::cout<<"Not a sound Node: "<<currentNode->getName()<<" classtype="<<currentNode->getClassType()<<"!="<<pfSoundNode::getClassType()<<"\n"<<std::flush;
00297       }
00298 
00299       return PFTRAV_CONT;      // Return continue
00300    }

int pfSoundTraverser::nodesReplaceWithSound pfuTraverser *    trav [inline, static, protected]
 

Used to traverse - don't call.

Definition at line 303 of file pfSoundTraverser.h.

Referenced by replace.

00304    {
00305       // get the keyname, usually it is "_Sound_"
00306       std::string keyName = *reinterpret_cast<std::string*>(trav->data);
00307       pfNode* currentNode = trav->node;
00308       if (currentNode == NULL)
00309       {
00310          return PFTRAV_CONT;      // Return continue
00311       }
00312 
00313       const char* nodeNameChar = currentNode->getName();
00314      std::string nodeName;
00315      if (nodeNameChar == NULL)
00316           nodeName = "";
00317      else
00318           nodeName = nodeNameChar;
00319 
00320       if (nodeName.size() <= keyName.size())
00321       {
00322          // name was too short to even be a match, discard it.
00323          return PFTRAV_CONT;      // Return continue
00324       }
00325 
00326       // for verbose output (outputs every node's name.)
00327       vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)<<"[SoundReplacer] Examining node in graph named \""<<nodeName.c_str()<<"\":\n"<<vprDEBUG_FLUSH;
00328 
00329       int startOfKeyWord = nodeName.size() - keyName.size();
00330       int endOfKeyWord = nodeName.size() - 1;
00331       std::string isThisOurKeyWord = nodeName.substr( startOfKeyWord, endOfKeyWord );
00332       if (isThisOurKeyWord == keyName)   // If node is not a Geode
00333       {
00334          vprDEBUG( vprDBG_ALL, vprDBG_STATE_LVL )<<"[SoundReplacer] Found node in graph named \""<<nodeName.c_str()<<"\":\n"<<vprDEBUG_FLUSH;
00335          vprDEBUG( vprDBG_ALL, vprDBG_STATE_LVL )<<"[SoundReplacer]     Substring "<<keyName.c_str()<<" matched, "<<vprDEBUG_FLUSH;
00336          pfGroup* parent = currentNode->getParent( 0 ); // FIXME?? will 0 work for all cases (instanced nodes?)
00337          if (parent != NULL)
00338          {
00339             std::string soundName = nodeName.substr( 0, startOfKeyWord );
00340             vprDEBUG_CONT( vprDBG_ALL, vprDBG_STATE_LVL )
00341                << "extracted sound named \"" << soundName.c_str()
00342                << "\"\n" << vprDEBUG_FLUSH;
00343 
00344             // replace the found node with a sound node.
00345             // note: only replace if the sound is valid.
00346             //        this way, the users can see where the sounds are (in case the geoset is a sphere)
00347             if (soundName != "")
00348             {
00349                parent->removeChild( currentNode );
00350                bool positional_sound_true( true );
00351                pfSoundNode* sn = new pfSoundNode( soundName, positional_sound_true );
00352                int resuln = sn->setName( nodeName.c_str() );
00353                if (resuln == 0)
00354                {
00355                   std::string newName = nodeName;
00356                   newName += "__sound";
00357                   sn->setName( newName.c_str() );
00358                }
00359                parent->addChild( sn );
00360                sonix::instance()->trigger( soundName );
00361 
00362                vprDEBUG( vprDBG_ALL, vprDBG_CONFIG_LVL )
00363                    << clrOutNORM( clrGREEN,"[SoundReplacer]     " )
00364                    << "Replaced " << clrOutNORM(clrGREEN, sn->getName())
00365                    << " node with a pfSoundNode referencing the "
00366                    << soundName.c_str() << " sound.\n" << vprDEBUG_FLUSH;
00367             }
00368             else
00369             {
00370                vprDEBUG( vprDBG_ALL, vprDBG_CRITICAL_LVL )<<clrOutNORM( clrRED,"[SoundReplacer] !!! WARNING !!! " ) <<"SOUND NOT FOUND: "<<soundName.c_str()<<"\n"<<vprDEBUG_FLUSH;
00371                vprDEBUG( vprDBG_ALL, vprDBG_CRITICAL_LVL )<<clrOutNORM( clrRED,"[SoundReplacer] !!!         !!! " ) <<"You need to enter \""<<soundName.c_str()<<"\" into your sound config file(s)\n"<<vprDEBUG_FLUSH;
00372                return PFTRAV_CONT;      // Return continue
00373             }
00374          }
00375          else
00376          {
00377             vprDEBUG_CONT( vprDBG_ALL, vprDBG_CRITICAL_LVL )<<"but Parent is NULL (nowhere to hang the pfSoundNode!)\n"<<vprDEBUG_FLUSH;
00378          }
00379       }
00380       // for very verbose output...
00381       else
00382       {
00383          vprDEBUG( vprDBG_ALL,vprDBG_STATE_LVL )
00384             << "[SoundReplacer]     Substring not matched: \""
00385             << isThisOurKeyWord.c_str() << "\" != \"" << keyName.c_str()
00386             << "\"\n" << vprDEBUG_FLUSH;
00387       }
00388 
00389       return PFTRAV_CONT;      // Return continue
00390    }


The documentation for this class was generated from the following file:
Generated on Sun May 2 15:11:05 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002