//// MultimediatiMer.h: interface for the cmultimediatimer class.//25.3.9 // if this code works, it was write by Ty.// if not, I don't know who wrote it.//// Use this CMultimediaTimer class as the fellows: // step 1: create a CMultimediaTimer object // step 2: define the Timer Callback Proc function in your programe, // the function must be the same type as below: // void PASCAL TimerProc ( UINT wTimerID, UINT msg, DWORD dwUser, DWORD dwl, DWORD dw2); // step 3: use class member function SetProcParameter, set TimerProc and Parameter, // if you need you can also use SetRange & SetCurRes functions to Modify // CMultimediaTimer Object Initial State In this step // step 4: Use Class Play Control Function As you need // Welcome Any Advice Wangjianddy@gmail.com//
#if! defined (TY_MULTIMEDITIMER) #define TY_MULTIMEDITIMER
#if _MSC_VER> 1000 # prgma overce # endif //_MSC_VER> 1000
#include "mmsystem.h" // Media Timer #pragma Comment (LIB, "WINMM")
const UINT TIMER_ACCURACY = 1; // definition of the clock resolution, in ms #define MTIMER_MAXLIMIT 0x0001 # define MTIMER_MINLIMIT 0x0002 # define MTIMER_NORMAL 0x0004 # define MCONTROL_NOSPEEDUP MTIMER_MINLIMIT # define MCONTROL_NOSLOWDOWN MTIMER_MAXLIMIT # define MCONTROL_NOLIMIT MTIMER_NORMAL
Class cmultimediatimer {public: cmultimediatimer (); virtual ~ cmultimediatiMer ();
Public: // Play Control Function Void Start (Uint Timurcurres); // Start Timer Void Start (Bool BoneShot = FALSE); Void Stop (); // Stop Timer Void Pause (); // Tempted Time Bool speedup (); // speed up the playback speed BOOL SLOWDOWN (); // Slow slow play speed void setRange (UINT LOWER, UINT UPPER); // Set the timing adjustment range, the START and SETCURRES functions for the belt, invalid VOID GetRange (Uint & Lower, Uint & Upper) const; // Get timing time range void setcurres (// Gets the current interval Void SetProcParameter (DWORD DWUSER); // Set the callback function and incoming parameters BOOL ISSTART () const; // Timer Whether running BOOL ISSTOP () const; // Timer Terminates the Bool ISPAUSE () const; // Timer suspension uint getressTate (); // Get timer time interval state uint getCurres ) const; // Get Current Time Intervals const timecaps & timegetDevcaps () const; // gets the timer resolution range protected: virtual void onspeedup (uint & timercurres); // is called Virtual Void OnSlowDown when the speed is improved (UINT & Timercurres); // When the speed is reduced, the status private: timecaps m_tc; // returns the status: timecaps m_tc; uint m_curtimerres; // Current time interval BOOL M_BTIMERSTOP; // Whether the Timer has started BOOL m_btimerpause; // Whether the timer pause DWORD M_DWUSER; // The incoming parameter uint m_waccuracy; // uses the resolution uint m_timerid; // Defines the timer handle LPTIMECALLBACK M_PCALLBACKPROC; // Pickup function pointer uint m_maxtimespace; // Maximum timer interval uint m_mintimespace; // minimum timer interval};
#ndif //! defined (Ty_MultiMediatiMer)
// Multimediatimer.cpp: importation of the cmultimediatimer class.h "#include" multimediatimer.h "
#ifdef _debug # undef this_filestatic char this_file [] = __ file __; # Define new debug_new # Endif
//// construction / destruction //
CMULTIMEDITIMER :: cmultimediatimer () {m_maxtimespace = 2560; // Maximum timer interval is 2560 ms [2 ^ x] m_mintimespace = 10; // minimum timer interval is 10 ms [race] // m_curtimerRES = 10; // Initial multimedia fixed time across 10ms m_btimerstop = true; m_btimerpause = true; m_pcallbackproc = null;
if (:: timeGetDevCaps (& m_tc, sizeof (TIMECAPS)) == TIMERR_NOERROR) {m_wAccuracy = min (max (m_tc.wPeriodMin, TIMER_ACCURACY), m_tc.wPeriodMax); timeBeginPeriod (m_wAccuracy);}}
CMULTIMEDITIMER :: ~ cmultimediatimer () {timekillevent (m_timerid); timeEndPeriod;}
// start timer void CMultimediaTimer :: Start (BOOL bOneShot / * = FALSE / ** /) {ASSERT (m_pCallBackProc = NULL!); UINT fuEvent = (bOneShot TIME_ONESHOT:? TIME_PERIODIC); if (m_bTimerStop || m_bTimerPause) { m_timerid = TimeSetEvent (m_curtimerres, m_waccuracy, (lptimecallback) m_pcallbackproc, m_dwuser, fuevent; m_btimerstop = false; m_btimerpause = false;}}
void CMultimediaTimer :: Start (UINT timerCurRes, BOOL bOneShot) {ASSERT (m_pCallBackProc = NULL!); m_CurTimerRes = max (min (timerCurRes, m_tc.wPeriodMax), m_wAccuracy); UINT fuEvent = (bOneShot TIME_ONESHOT:? TIME_PERIODIC); if ( m_btimerstop || m_btimerpause) {m_timerid = timesetevent (m_curtimerres, m_waccuracy, m_pcallbackproc, m_dwuser, fuevent); m_btimerstop = false; m_btimerpause = false;}}
// stop timer void CMultimediaTimer :: Stop () {timeKillEvent (m_TimerID); m_bTimerStop = TRUE; m_bTimerPause = FALSE;} // pause timer void CMultimediaTimer :: Pause () {timeKillEvent (m_TimerID); if (m_bTimerStop &&! ! m_btimerpause) {m_btimerpause = true;}}
// increase the playback speed reduction timing interval BOOL CMultimediaTimer :: SpeedUp () {switch (GetResState ()) {case MTIMER_MAXLIMIT: m_CurTimerRes = m_MaxTimeSpace; break; case MTIMER_MINLIMIT: m_CurTimerRes = m_MinTimeSpace; break; default :;} UINT nOldRes = m_CurTimerRes ; OnSpeedUp (nOldRes); if (GetResState (nOldRes) == MTIMER_NORMAL) m_CurTimerRes = nOldRes; else return FALSE; if {timeKillEvent (m_TimerID) (m_bTimerStop && m_bTimerPause!!); m_TimerID = timeSetEvent (m_CurTimerRes, m_wAccuracy, m_pCallBackProc, m_dwUser, Time_periodic;} return true;
// slow down playback speed, increasing the timing interval BOOL CMultimediaTimer :: SlowDown () {switch (GetResState ()) {case MTIMER_MAXLIMIT: m_CurTimerRes = m_MaxTimeSpace; break; case MTIMER_MINLIMIT: m_CurTimerRes = m_MinTimeSpace; break; default :;} UINT nOldRes = m_CurTimerRes; OnSlowDown (nOldRes); if (GetResState (nOldRes) == MTIMER_NORMAL) m_CurTimerRes = nOldRes; else return FALSE; if (m_bTimerStop && m_bTimerPause!!) {timeKillEvent (m_TimerID); m_TimerID = timeSetEvent (m_CurTimerRes, m_wAccuracy, m_pCallBackProc, m_dwUser , Time_Periodic;} Return True;
// Set the timing adjustment range, the START and SETCURRES functions for the belt, invalid CMULTIMEDITIMER :: setRregs (uint limited, uint Upper) {uint temp = lower; lower = Upper; Upper = temp;} m_MinTimeSpace = max (min (Lower, m_tc.wPeriodMax), m_wAccuracy); m_MaxTimeSpace = max (min (m_tc.wPeriodMax, Upper), m_MinTimeSpace);} // get the timing of time void CMultimediaTimer :: GetRange ( UINT & LOWER, UINT & UPPER) Const {Lower = m_mintimespace; Upper = m_maxtimespace;}
// Get the current interval vid cmultimediatimer :: setCurres (uint timercurres) {m_curtimerres = max (min (timercurres, m_tc.wperiodmax), m_waccuracy;}
// Set the callback function and the incoming parameter void cmultimediatimer :: setProcparameter (LPTIMECALLBACK CALLBACKPROC, DWORD DWUSER) {m_pcallbackproc = CallbackProc; m_dwuser = dwuser;}
/ / The timer is running Bool CMULTIMEDITIMER :: Isstart () const {return (! M_btimerpause "; m_btimerstop);
// Whether the timer has started Bool CMULTIMEDITIMER :: Isstop () const {return m_btimerstop;}
/ / Get Timer Pause State Bool CMULTIMEDITIMER :: ISPAUSE () Const {Return M_Btimerpause;}
/ / Returns the status of RES UINT CMULTIMEDITIMER :: GetResState (uint res) const {if (res
// get the timer status UINT CMultimediaTimer :: GetResState () {UINT temp, r1, r2; temp = m_CurTimerRes; OnSpeedUp (temp); r1 = GetResState (temp); temp = m_CurTimerRes; OnSlowDown (temp); r2 = GetResState ( temp); if (r1 == MTIMER_MINLIMIT && r2 == MTIMER_MAXLIMIT) return MTIMER_MINLIMIT | MTIMER_MAXLIMIT; if (r1 == MTIMER_MINLIMIT) return MTIMER_MINLIMIT; if (r2 == MTIMER_MAXLIMIT) return MTIMER_MAXLIMIT; return MTIMER_NORMAL;}
// Get the current interval uint cmultimediatiMER :: getCurres () const {return m_curtimerres;} // get timer resolution range const timecaps & cmultimediatiMER :: TimeGetDevcaps () const {return m_tc;}
// When the speed is improved, Void cmultimediatiTimer :: ONSPEEDUP (UINT & TIMERCURRES) {// spetedup algorithm Timercurres = Timercurres / 2;
// When the speed is lowered, Void cmultimediatimer :: OnsLowDown (Uint & Timercurres) {// Slowdown Algorithm Timercurres = Timercurres * 2;