sound.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 1999-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Thu Jul  8 11:43:07 1999
00010 // commit: $Id: sound.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/visx/sound.cc $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_VISX_SOUND_CC_UTC20050626084015_DEFINED
00035 #define GROOVX_VISX_SOUND_CC_UTC20050626084015_DEFINED
00036 
00037 #include "sound.h"
00038 
00039 #include "io/reader.h"
00040 #include "io/writer.h"
00041 
00042 #include "nub/ref.h"
00043 
00044 #include "rutz/error.h"
00045 
00046 #if defined(HAVE_ALIB_H)
00047 #  include "media/hpsound.h"
00048    typedef hp_audio_sound_rep sound_rep_t;
00049 
00050 #elif defined(HAVE_DMEDIA_AUDIO_H)
00051 #  include "media/irixsound.h"
00052    typedef media::irix_audio_sound_rep sound_rep_t;
00053 
00054 #elif defined(HAVE_QUICKTIME_MOVIES_H)
00055 #  include "media/quicktimesound.h"
00056    typedef media::quicktime_sound_rep sound_rep_t;
00057 
00058 #elif defined(HAVE_ESD_H)
00059 #  include "media/esdsound.h"
00060    typedef media::esd_sound_rep sound_rep_t;
00061 
00062 #else
00063 #  include "media/dummysound.h"
00064    typedef media::dummy_sound_rep sound_rep_t;
00065 
00066 #endif
00067 
00068 #include "rutz/trace.h"
00069 #include "rutz/debug.h"
00070 GVX_DBG_REGISTER
00071 
00072 namespace
00073 {
00074   nub::soft_ref<Sound> theOkSound;
00075   nub::soft_ref<Sound> theErrSound;
00076 }
00077 
00078 void Sound::setOkSound(nub::ref<Sound> ok_sound)
00079 {
00080   theOkSound = ok_sound;
00081 }
00082 
00083 void Sound::setErrSound(nub::ref<Sound> err_sound)
00084 {
00085   theErrSound = err_sound;
00086 }
00087 
00088 nub::ref<Sound> Sound::getOkSound()
00089 {
00090   return nub::ref<Sound>(theOkSound.get());
00091 }
00092 
00093 nub::ref<Sound> Sound::getErrSound()
00094 {
00095   return nub::ref<Sound>(theErrSound.get());
00096 }
00097 
00098 Sound* Sound::make()
00099 {
00100 GVX_TRACE("Sound::make");
00101   return new Sound;
00102 }
00103 
00104 Sound* Sound::makeFrom(const char* filename)
00105 {
00106 GVX_TRACE("Sound::make");
00107   return new Sound(filename);
00108 }
00109 
00110 Sound::Sound(const char* filename) :
00111   itsFilename(""),
00112   itsRep()
00113 {
00114 GVX_TRACE("Sound::Sound");
00115   setFile(filename);
00116 }
00117 
00118 Sound::~Sound() throw()
00119 {
00120 GVX_TRACE("Sound::~Sound");
00121 }
00122 
00123 void Sound::read_from(io::reader& reader)
00124 {
00125 GVX_TRACE("Sound::read_from");
00126 
00127   reader.read_value("filename", itsFilename);
00128 
00129   if (!itsFilename.is_empty())
00130     setFile(itsFilename.c_str());
00131 }
00132 
00133 void Sound::write_to(io::writer& writer) const
00134 {
00135 GVX_TRACE("Sound::write_to");
00136 
00137   writer.write_value("filename", itsFilename);
00138 }
00139 
00140 void Sound::play()
00141 {
00142 GVX_TRACE("Sound::play");
00143 
00144   forceLoad();
00145 
00146   if (itsRep.get() != 0)
00147     itsRep->play();
00148 }
00149 
00150 void Sound::forceLoad()
00151 {
00152 GVX_TRACE("Sound::forceLoad");
00153   // check if we have a valid filename without a corresponding valid rep
00154   if (itsRep.get() == 0 && !itsFilename.is_empty())
00155     itsRep.reset(new sound_rep_t(itsFilename.c_str()));
00156 }
00157 
00158 void Sound::setFile(const char* filename)
00159 {
00160 GVX_TRACE("Sound::setFile");
00161 
00162   if (filename == 0)
00163     filename = "";
00164 
00165   if (itsFilename != filename)
00166     {
00167       // itsRep is only lazily updated, so just mark it as invalid
00168       // here... we won't have to update it until someone actually tries to
00169       // play() the sound
00170       itsRep.reset();
00171       itsFilename = filename;
00172     }
00173 }
00174 
00175 const char* Sound::getFile() const
00176 {
00177 GVX_TRACE("Sound::getFile");
00178   return itsFilename.c_str();
00179 }
00180 
00181 static const char __attribute__((used)) vcid_groovx_visx_sound_cc_utc20050626084015[] = "$Id: sound.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00182 #endif // !GROOVX_VISX_SOUND_CC_UTC20050626084015_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:42 2008 by Doxygen version 1.5.5.