quicktimesound.h

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2002-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: Mon May 19 07:38:09 2003
00010 // commit: $Id: quicktimesound.h 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/media/quicktimesound.h $
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_MEDIA_QUICKTIMESOUND_H_UTC20050626084018_DEFINED
00035 #define GROOVX_MEDIA_QUICKTIMESOUND_H_UTC20050626084018_DEFINED
00036 
00037 #include "media/soundrep.h"
00038 
00039 #include "rutz/error.h"
00040 #include "rutz/fstring.h"
00041 #include "rutz/sfmt.h"
00042 
00043 #include <Carbon/Carbon.h>
00044 #include <QuickTime/Movies.h>
00045 
00046 #include "rutz/trace.h"
00047 #include "rutz/debug.h"
00048 
00049 namespace media
00050 {
00052   class quicktime_sound_rep : public sound_rep
00053   {
00054   public:
00055     quicktime_sound_rep(const char* filename);
00056 
00057     virtual ~quicktime_sound_rep() throw();
00058 
00059     virtual void play();
00060 
00061     bool init_sound();
00062     void close_sound();
00063 
00064     short m_file_ref_num;
00065     Movie m_movie;
00066 
00067     static bool quicktime_inited;
00068   };
00069 }
00070 
00071 bool media::quicktime_sound_rep::quicktime_inited = false;
00072 
00073 media::quicktime_sound_rep::quicktime_sound_rep(const char* filename)
00074 {
00075 GVX_TRACE("media::quicktime_sound_rep::quicktime_sound_rep");
00076 
00077   init_sound();
00078 
00079   // (1) Get an FSRef from the filename
00080   FSRef ref;
00081 
00082   OSErr err = FSPathMakeRef(reinterpret_cast<const UInt8*>(filename),
00083                             &ref, 0);
00084 
00085   if (noErr != err)
00086     throw rutz::error(rutz::sfmt("error in FSPathMakeRef: %d", int(err)),
00087                       SRC_POS);
00088 
00089   // (2) Get an FSSpec from the FSRef
00090   FSSpec spec;
00091 
00092   err = FSGetCatalogInfo(&ref, kFSCatInfoNone,
00093                          NULL, NULL, &spec, NULL);
00094 
00095   if (noErr != err)
00096     throw rutz::error(rutz::sfmt("error in FSGetCatalogInfo: %d", int(err)),
00097                       SRC_POS);
00098 
00099   // (3) Get a movie file descriptor from the FSSpec
00100   err = OpenMovieFile(&spec, &m_file_ref_num, fsRdPerm);
00101 
00102   if (noErr != err)
00103     throw rutz::error(rutz::sfmt("error in OpenMovieFile: %d", int(err)),
00104                       SRC_POS);
00105 
00106   // (4) Get a movie object from the movie file
00107   err = NewMovieFromFile(&m_movie, m_file_ref_num, 0, nil,
00108                          newMovieActive, nil);
00109 
00110   if (noErr != err)
00111     {
00112       CloseMovieFile(m_file_ref_num);
00113       throw rutz::error(rutz::sfmt("error in NewMovieFromFile: %d", int(err)),
00114                         SRC_POS);
00115     }
00116 }
00117 
00118 media::quicktime_sound_rep::~quicktime_sound_rep() throw()
00119 {
00120 GVX_TRACE("media::quicktime_sound_rep::~quicktime_sound_rep");
00121   DisposeMovie(m_movie);
00122   CloseMovieFile(m_file_ref_num);
00123 }
00124 
00125 void media::quicktime_sound_rep::play()
00126 {
00127 GVX_TRACE("media::quicktime_sound_rep::play");
00128   GoToBeginningOfMovie(m_movie);
00129 
00130   StartMovie(m_movie);
00131 
00132   while (!IsMovieDone (m_movie))
00133     {
00134       MoviesTask(m_movie, 0);
00135     }
00136 }
00137 
00138 bool media::quicktime_sound_rep::init_sound()
00139 {
00140 GVX_TRACE("media::quicktime_sound_rep::init_sound");
00141   if (!quicktime_inited)
00142     {
00143       const OSErr err = EnterMovies();
00144 
00145       if (noErr == err)
00146         quicktime_inited = true;
00147     }
00148 
00149   return quicktime_inited;
00150 }
00151 
00152 void media::quicktime_sound_rep::close_sound()
00153 {
00154 GVX_TRACE("quicktime_sound_rep::close_sound");
00155   if (quicktime_inited)
00156     {
00157       ExitMovies();
00158     }
00159 }
00160 
00161 static const char __attribute__((used)) vcid_groovx_media_quicktimesound_h_utc20050626084018[] = "$Id: quicktimesound.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00162 #endif // !GROOVX_MEDIA_QUICKTIMESOUND_H_UTC20050626084018_DEFINED

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