Veda/VirtualMedia.h

Go to the documentation of this file.
00001 /*! \file 
00002     \author victorien ferry & www.m4nkind.com
00003     \brief This file applies the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 , read file COPYING.
00004 */
00005 #ifndef COM_M4NKIND_VirtualMedia_H
00006 #define COM_M4NKIND_VirtualMedia_H
00007 
00008 #include "BaseObject.h"
00009 #include "VirtualMachine.h"
00010 /*!
00011     \class  VirtualMedia
00012     \ingroup BaseObjectInheritedDocGroup BaseObjectInherited_Veda
00013     \brief  Base model for all class that plays a suit of animations and/or sounds.
00014             You should extend ProcessMedia() for animations, and ProcessSoundInterupt() for sounds,
00015             in any way. This \ref Example_MinimalMedia "example" extends a VirtualMedia and plays it.
00016             Note this class is not registered to BaseContext by default. you got to register it or not, 
00017             according to your needs. Thus, it got to be registered first if you use inherited 
00018             classes. ( through BaseContext::RegisterClassList() )
00019              Also note that VirtualMedia::ProcessSoundInterupt() manages the sound
00020              registration to the machine itself.
00021 */
00022 class VirtualMedia : public BaseObject
00023 {
00024 /*==================================================================
00025                                 PUBLIC
00026 ==================================================================*/
00027 public:
00028     /*!
00029         \brief  Constructor. There should only be members initialisation there.
00030     */
00031     VirtualMedia(void);
00032     /*!
00033         \brief  Class Inheritance Descriptors. Also forces a destructor. See BASEOBJECT_DECLARE_... in .cpp
00034     */
00035     BASEOBJECT_DEFINE_VIRTUALCLASS(VirtualMedia);
00036 
00037     /*!
00038         \brief   Process a media at a given date, 
00039                 or do anything) using a machine. 
00040                 Note there are no play/pause or speed concept here, by default, a date is passed.
00041                 This version redirect the drawing to the main screen viewport.
00042                 It should the main entry to play a media.
00043                 Developpers should extend 
00044         \param  _frameDate a date, in second, which defines the effect cinematic.
00045     */
00046     void ProcessMediaOnDefaultViewport( double _frameDate );
00047     
00048     /*!
00049         \brief   Process a media at a given date, 
00050                 or do anything) using a machine. You must process the media on machine this->GetMachine().
00051                 Note there are no play/pause or speed concept here, by default, a date is passed.
00052                 By default, does nothing.
00053         \param  _frameDate a date, in second, which defines the effect cinematic.
00054         \param  _pViewPort the viewport to render. Can't be 0L.
00055     */
00056     virtual void ProcessMedia( double _frameDate,VirtualMachine::InternalViewPort *_pViewPort );
00057 
00058     /*!
00059         \brief   returns the Total Time length of this media, in seconds, when played at 
00060                 normal speed. This is just an information about the time length of this media,
00061                 and you can pass any date to ProcessMedia().
00062         \return Total Time length of this media, in seconds, when played at normal speed. Can be used or not.
00063     */
00064     inline double   GetTimeLength(){ return m_MediaTimeLength; };
00065 
00066     /*!
00067         \brief   Use SetSound() to enable  sound capabilities for a media object, 
00068                 and the machine should then send ProcessSoundInterupt() to mix it.
00069                 SetSound(true) at start and SetSound(false) at closing, have to be 
00070                 performed by external code, and should not be used by AzurVeda objects 
00071                 in their methods.
00072                 Note: SetSound(true) enable One object, but this object
00073                 can point other Media objects in the context with SetSound(false),
00074                 and use ProcessSoundInterupt() recursively to mix all of them. So an 
00075                 object with SetSound(false) can still be noisy. 
00076 
00077                 In its default behaviour, SetSound() uses the default AzurVeda machine,
00078                 GetMachine()
00079 
00080         \param  _Enable true start sound, false stop it.
00081     */
00082     virtual void SetSound( bool _Enable );
00083 
00084     /*!
00085         \brief   If the media had to generate real time sounds, 
00086                 ProcessSoundInterupt will be called by a machine. There is a default 
00087                 behaviour for this method, which does nothing. the float buffer 
00088                 accumulate the whole machine sound.
00089         \param  _SoundBufferToAddYourSignal description of the buffer to fill.
00090     */
00091     virtual void ProcessSoundInterupt( VirtualMachine::SoundBufferToAddYourSignal &_SoundBufferToAddYourSignal );
00092 #ifdef _ENGINE_EDITABLE_
00093     /*!
00094         \brief  any suit of call to ProcessPreview() should be done between
00095                 StartPreview() and EndPreview() .
00096                 EndPreview(). This is needed to stop sound mixing from the object
00097                 when the preview change.
00098     */
00099     virtual     void    StartPreview();
00100 #endif
00101 #ifdef _ENGINE_EDITABLE_
00102     /*!
00103         \brief  a GUI could need to play, draw, print, or output from any way, a preview of a 
00104                 created object. This is done with this method. sub classes can implement it (or not) in
00105                 any way, to explicit current shape of an object.<br>
00106 
00107         \param  _frameDate a date, in second, which defines the effect cinematic.
00108         \param  _pPreviewViewPort the viewport to render. Can't be 0L.
00109         \param  _pPreviewConfiguration
00110     */
00111     virtual void ProcessPreview(double _frameDate,VirtualMachine::InternalViewPort *_pPreviewViewPort,const PreviewConfiguration *_pPreviewConfiguration);
00112 #endif
00113 #ifdef _ENGINE_EDITABLE_
00114     /*!
00115         \brief  any suit of call to ProcessPreview() should be done between
00116                 StartPreview() and EndPreview() .
00117                 EndPreview(). This is needed to stop sound mixing from the object
00118                 when the preview change.
00119     */
00120     virtual     void    EndPreview();
00121 #endif
00122 /*==================================================================
00123                                 PROTECTED
00124 ==================================================================*/
00125 protected:
00126 
00127     //! true if m_MediaSoundInterface is currently registered to VirtualMachine as playing sound.
00128     bool    m_SoundIsMixed;
00129     //! Total Time length of this media, in seconds, when played at normal speed. Can be used or not.
00130     double  m_MediaTimeLength;
00131 
00132     // no CreateInternal or CloseInternal for this one.
00133     /*!
00134         \brief  Method that really build the object using the serializable parameters.
00135                 Close() should close everything opened by CreateInternal().
00136     */
00137     //virtual bool CreateInternal(void);
00138 
00139 #ifdef _ENGINE_EDITABLE_
00140     /*!
00141         \brief  that closes everything. Still, the object exist and can be rebuild the same using Create()
00142     */
00143     virtual void    CloseInternal(void);
00144 #endif
00145 #ifdef _ENGINE_EDITABLE_
00146     /*!
00147         \brief  Tool to draw a preview of the current sound signal.
00148         \param  _pViewport  where to draw
00149         \param  _pSoundBuffer float left/right table
00150         \param  _bufferlength number of right/left on the table.
00151     */
00152     virtual void ProcessPreview_DrawSoundBuffer(    
00153                                 VirtualMachine::InternalViewPort *_pViewport,
00154                                 float   *_pSoundBuffer,
00155                                 unsigned int    _bufferlength );
00156 #endif
00157 /*==================================================================
00158                                 PRIVATE
00159 ==================================================================*/
00160 private:
00161     /*!
00162         \class  MediaSoundInterface
00163         \brief  Implements VirtualMachine::SoundInterface as a protected member.
00164                 This mecanism just redirect the machine's sound mixing to VirtualMedia::ProcessSoundInterupt()
00165     */
00166     class MediaSoundInterface : public VirtualMachine::SoundInterface
00167     {
00168         public:
00169         /*!
00170             \brief  Method thrown by the sound creation thread to add a new signal in a float buffer.
00171                     The whole result is played As soon as possible.
00172             \param  _SoundBufferToAddYourSignal the sound to write description.
00173         */
00174         virtual void ProcessSoundInterupt( VirtualMachine::SoundBufferToAddYourSignal &_SoundBufferToAddYourSignal );
00175 
00176         //! when inited, MediaSoundInterface receive the object that implement it. 
00177         VirtualMedia    *m_pVirtualMedia;
00178 
00179     };
00180     //! this aggregate member is the object touch by the Virtual Machine
00181     MediaSoundInterface m_MediaSoundInterface;
00182 };
00183 
00184 #endif

      /\/\        4         N         k         !         N         D
                      _______  _ __ ___  _____            ___ _ _  ____
     ___________  __//___   /________  |/    / ___________\_______/    \
    /   _   _   \/   _     /    _   /      _/_/____/    _       __     /
   /    /   /       /     /    /    \      \/     /    /    \   \     /
  \\___/___/___/    ¯    _____/_____/       ______\___/_____/\________\\
               \________/_ ___ __ l____\      /elD!  
                 http://www.m4nkind.com \____/