00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef OSDL_MUSIC_H_
00028 #define OSDL_MUSIC_H_
00029 
00030 
00031 #include "OSDLAudioCommon.h"    
00032 #include "OSDLAudible.h"        
00033 #include "OSDLUtils.h"          
00034 
00035 
00036 #include "Ceylan.h"             
00037 
00038 
00039 #include <string>
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 struct _Mix_Music ;
00055 
00056 
00057 
00058 
00059 namespace OSDL
00060 {
00061 
00062 
00063 
00064 #if defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS
00065     
00066     
00067     class CommandManager ;
00068     
00069     class CommandManagerSettings ;
00070 
00071 #endif // defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS 
00072 
00073     
00074          
00075     namespace Audio 
00076     {
00077 
00078 
00079 
00080 #if ! defined(OSDL_USES_SDL_MIXER) || OSDL_USES_SDL_MIXER 
00081 
00083         typedef ::_Mix_Music LowLevelMusic ;
00084                 
00085 #else // OSDL_USES_SDL_MIXER    
00086 
00087         
00088         
00093         struct LowLevelMusic
00094         {
00095         
00096         
00097             
00098         
00099             
00100             
00102             Ceylan::System::File * _musicFile ;
00103             
00104             
00106             Ceylan::Uint16 _frequency ;
00107 
00108 
00110             Ceylan::Uint8 _bitDepth ;
00111 
00112 
00118             Ceylan::Uint8 _mode ;
00119 
00120 
00121 
00123             BufferSize _size ;
00124             
00125             
00126             
00127             
00128 
00129 
00131             BufferSize _frameSizeUpperBound ;
00132             
00133         
00134         
00136             bool _requestFillOfFirstBuffer ;
00137                     
00138                         
00139             
00140 
00141 
00142 
00143 
00144             Ceylan::Byte * _startAfterDelta ;
00145             
00146             
00148             BufferSize _firstActualRefillSize ;
00149             
00150             
00152             bool _requestFillOfSecondBuffer ;
00153                 
00154                 
00155                     
00161             PlaybackCount _playbackCount ;
00162             
00163         } ;
00164         
00165         
00166 
00167 #endif // OSDL_USES_SDL_MIXER
00168 
00169 
00170             
00172         class OSDL_DLL MusicException : public AudibleException
00173         { 
00174             public: 
00175             
00176                 MusicException( const std::string & reason ) ; 
00177                 virtual ~MusicException() throw() ; 
00178         } ;
00179             
00180                         
00181                             
00197         typedef Ceylan::Uint32 MusicPosition ;
00198 
00199 
00200         
00201                 
00206         enum MusicType
00207         {
00208         
00209         
00218             Wave,
00219             
00220             
00229             MOD,
00230             
00231             
00240             MIDI,
00241             
00242             
00251             OggVorbis,
00252             
00253             
00262             MP3,
00263             
00264             
00270             CommandBased,
00271             
00272             
00279             NoMusic,
00280             
00281             
00286             Unknown
00287         
00288         
00289         } ;
00290     
00291         
00292         
00293         
00298         typedef Ceylan::Uint8 BitrateType ;
00299          
00300          
00301          
00302          
00303         
00304         extern OSDL_DLL const BitrateType CBR ;  
00305         
00306         
00307         
00308         
00309         extern OSDL_DLL const BitrateType VBR ;  
00310 
00311 
00312 
00313         
00314         class Music ;
00315         
00316         
00318         typedef Ceylan::CountedPointer<Music> MusicCountedPtr ;
00319         
00320 
00321         
00322                                                 
00351         class OSDL_DLL Music : public Audible, 
00352             public Ceylan::LoadableWithContent<LowLevelMusic>
00353         {
00354     
00355 #if defined(CEYLAN_ARCH_NINTENDO_DS) && CEYLAN_ARCH_NINTENDO_DS == 1
00356 
00357             
00358             friend class OSDL::CommandManager ;
00359 
00360 #endif // defined(CEYLAN_ARCH_NINTENDO_DS) && CEYLAN_ARCH_NINTENDO_DS == 1
00361     
00362             
00363             
00364             public:
00365                 
00366                 
00367 
00392                 explicit Music( const std::string & musicFilename, 
00393                     bool preload = true ) ;
00394                 
00395                 
00396                 
00398                 virtual ~Music() throw() ;
00399         
00400         
00401         
00402                 
00403         
00404                 
00405                 
00415                 virtual bool load() ;
00416         
00417         
00418         
00432                 virtual bool unload() ;
00433         
00434 
00435 
00436 
00437                 
00438                 
00439                 
00440                 
00450                 virtual Volume getVolume() const ;
00451         
00452         
00453         
00466                 virtual void setVolume( Volume newVolume ) ;
00467         
00468         
00469         
00477                 virtual MusicType getType() const ;
00478         
00479         
00480         
00481         
00482                 
00483 
00484 
00485 
00486 
00487 
00488 
00489                 
00490                 
00491                 
00492                 
00493                 
00494                 
00495                 
00519                 virtual void play( PlaybackCount playCount = 1 ) ; 
00520 
00521 
00522 
00523     
00524                 
00525         
00526         
00554                 virtual void playWithFadeIn( 
00555                     Ceylan::System::Millisecond fadeInMaxDuration,
00556                     PlaybackCount playCount = 1 ) ; 
00557         
00558         
00559         
00593                 virtual void playWithFadeInFromPosition( 
00594                     Ceylan::System::Millisecond fadeInMaxDuration,
00595                     MusicPosition position,
00596                     PlaybackCount playCount = 1 ) ; 
00597         
00598 
00599 
00606                 virtual bool isPlaying() ;
00607                 
00608                 
00609                 
00619                 virtual void pause() ; 
00620         
00621         
00622         
00632                 virtual void unpause() ; 
00633         
00634         
00635         
00651                 virtual void rewind() ; 
00652         
00653         
00654         
00668                 virtual void setPosition( MusicPosition newPosition ) ; 
00669         
00670         
00671         
00684                 virtual void stop() ; 
00685 
00686                 
00687                 
00701                 virtual void fadeIn( 
00702                     Ceylan::System::Millisecond fadeInMaxDuration ) ; 
00703 
00704 
00705                 
00723                 virtual void fadeOut( 
00724                     Ceylan::System::Millisecond fadeOutMaxDuration ) ; 
00725 
00726     
00727                  
00740                 virtual const std::string toString( 
00741                     Ceylan::VerbosityLevels level = Ceylan::high ) const ;
00742     
00743             
00744             
00745 #if defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS
00746     
00751                 static void SetCommandManagerSettings( 
00752                     const CommandManagerSettings & settings ) ;
00753                             
00754 #endif // defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS 
00755             
00756 
00766                 static void ManageCurrentMusic() ;
00767                 
00768                 
00769                  
00781                 static MusicType GetTypeOf( const Music * music ) ;
00782                     
00783                     
00784                     
00792                 static std::string DescribeMusicType( MusicType type ) ;
00793                     
00794                     
00795                     
00803                 static std::string DescribeBitrateType( BitrateType type ) ;
00804                                 
00805             
00806                 
00807                 
00808             
00809             protected:
00810             
00811             
00823                 OSDL::Utils::DataStream * _dataStream ;
00824 
00825 
00826 
00828                 bool _isPlaying ;
00829 
00830 
00831                 
00832 #if defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS
00833 
00841                 static const CommandManagerSettings * _CommandManagerSettings ;
00842                 
00843 #endif // defined(OSDL_ARCH_NINTENDO_DS) && OSDL_ARCH_NINTENDO_DS 
00844             
00845             
00846                 
00848                 static Music * _CurrentMusic ;
00849                 
00850                 
00851                 
00852                 
00853                 
00870                 virtual void onPlaybackEnded() ;
00871                 
00872                 
00873                 
00882                 virtual void managePlaybackEnded() ;
00883 
00884                 
00885                 
00902                 virtual void onNoMoreCurrent() ;
00903 
00904                 
00905                 
00916                 virtual void manageNoMoreCurrent() ;
00917 
00918                     
00919                 
00928                 virtual void manageBufferRefill() ;
00929 
00930                 
00931                 
00941                 void fillFirstBuffer() ; 
00942                 
00943                 
00944                 
00954                 void fillSecondBuffer() ; 
00955                 
00956 
00957 
00972                 virtual void setAsCurrent() ;
00973 
00974             
00975             
00986                 virtual void requestFillOfFirstBuffer() ;
00987                 
00988                 
00989                 
01000                 virtual void requestFillOfSecondBuffer() ;
01001                     
01002                 
01003                 
01013             private:
01014     
01015     
01016     
01025                 explicit Music( const Music & source ) ;
01026             
01027             
01028             
01037                 Music & operator = ( const Music & source ) ;
01038                 
01039                 
01040             
01041         } ;
01042         
01043 
01044         
01045         
01046     }   
01047     
01048 }   
01049 
01050 
01051 
01052 #endif // OSDL_MUSIC_H_
01053