Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vuStopWatch.cpp

Go to the documentation of this file.
00001 #include "vuStopWatch.h"
00002 
00003 #include <wx/timer.h>
00004 
00005 vuStopWatch::vuStopWatch (int time_in_ms)
00006 
00007 {
00008         m_timer_1 = new wxStopWatch;
00009         m_timer_2 = new wxStopWatch;
00010         m_timer_3 = new wxStopWatch;
00011 
00012         Start (time_in_ms);
00013 
00014         setIsReversing (false);
00015         setIsRewinding (false);
00016         setIsFastForwarding (false);
00017 
00018         setIsLooping (false);
00019         setIsBouncing (false);
00020 }
00021 
00022 vuStopWatch::~vuStopWatch ()
00023 
00024 {
00025         delete [] (wxStopWatch *) (m_timer_1);
00026         delete [] (wxStopWatch *) (m_timer_2);
00027         delete [] (wxStopWatch *) (m_timer_3);
00028 }
00029 
00030 void vuStopWatch::Start (int time_in_ms)
00031 
00032 {
00033 /*      m_timer_1.Resume ();
00034         m_timer_2.Resume ();
00035         m_timer_3.Resume ();
00036 
00037         m_timer_1.Start (time_in_ms);
00038         m_timer_2.Start (0);
00039         m_timer_3.Start (0);*/
00040 
00041         ((wxStopWatch *) (m_timer_1))->Resume ();
00042         ((wxStopWatch *) (m_timer_2))->Resume ();
00043         ((wxStopWatch *) (m_timer_3))->Resume ();
00044 
00045         ((wxStopWatch *) (m_timer_1))->Start (time_in_ms);
00046         ((wxStopWatch *) (m_timer_2))->Start (0);
00047         ((wxStopWatch *) (m_timer_3))->Start (0);
00048 }
00049 
00050 int vuStopWatch::Time ()
00051 
00052 {
00053         int time1 = ((wxStopWatch *) (m_timer_1))->Time ();
00054         int time2 = ((wxStopWatch *) (m_timer_2))->Time ();
00055 
00056         if (IsReversing ())
00057 
00058         {
00059                 time1 -= 2 * time2;
00060 
00061                 if ((IsBouncing ()) && (time1 <= 0))
00062                         setIsReversing (false);
00063 
00064                 if ((IsLooping ()) && (time1 <= 0))
00065                         time1 = m_maxtime;
00066 
00067                 if (time1 < 0)
00068                         time1 = 0;
00069 
00070                 ((wxStopWatch *) (m_timer_1))->Start (time1);
00071                 ((wxStopWatch *) (m_timer_2))->Start (0);
00072 
00073                 return time1;
00074         }
00075 
00076         if (IsRewinding ())
00077 
00078         {
00079                 time1 -= int ((getFastSpeed () + 1) * time2);
00080 
00081                 if ((IsBouncing ()) && (time1 <= 0))
00082 
00083                 {
00084                         setIsRewinding (false);
00085                         setIsFastForwarding (true);
00086                 }
00087 
00088                 if ((IsLooping ()) && (time1 <= 0))
00089                         time1 = m_maxtime;
00090 
00091                 if (time1 < 0)
00092                         time1 = 0;
00093 
00094                 ((wxStopWatch *) (m_timer_1))->Start (time1);
00095                 ((wxStopWatch *) (m_timer_2))->Start (0);
00096 
00097                 return time1;
00098         }
00099 
00100         if (IsFastForwarding ())
00101 
00102         {
00103                 time1 += int ((getFastSpeed () - 1) * time2);
00104 
00105                 if ((IsBouncing ()) && (time1 >= m_maxtime))
00106 
00107                 {
00108                         setIsRewinding (true);
00109                         setIsFastForwarding (false);
00110                 }
00111 
00112                 if ((IsLooping ()) && (time1 >= m_maxtime))
00113                         time1 = 0;
00114 
00115                 if (time1 >= getMaxTime ())
00116                         time1 = getMaxTime ();
00117 
00118                 ((wxStopWatch *) (m_timer_1))->Start (time1);
00119                 ((wxStopWatch *) (m_timer_2))->Start (0);
00120 
00121                 return time1;
00122         }
00123 
00124         if ((IsBouncing ()) && (time1 >= getMaxTime ()))
00125 
00126         {
00127                 setIsReversing (true);
00128 
00129                 time1 = getMaxTime ();
00130         }
00131 
00132         if ((IsLooping ()) && (time1 >= getMaxTime ()))
00133 
00134         {
00135                 time1 = 0;
00136         }
00137 
00138         if (time1 > getMaxTime ())
00139                 time1 = getMaxTime ();
00140 
00141         ((wxStopWatch *) (m_timer_1))->Start (time1);
00142         ((wxStopWatch *) (m_timer_2))->Start (0);
00143 
00144         return time1;
00145 
00146 /*      int time1 = m_timer_1.Time ();
00147         int time2 = m_timer_2.Time ();
00148 
00149         if (IsReversing ())
00150 
00151         {
00152                 time1 -= 2 * time2;
00153 
00154                 if ((IsBouncing ()) && (time1 <= 0))
00155                         setIsReversing (false);
00156 
00157                 if ((IsLooping ()) && (time1 <= 0))
00158                         time1 = m_maxtime;
00159 
00160                 if (time1 < 0)
00161                         time1 = 0;
00162 
00163                 m_timer_1.Start (time1);
00164                 m_timer_2.Start (0);
00165 
00166                 return time1;
00167         }
00168 
00169         if (IsRewinding ())
00170 
00171         {
00172                 time1 -= int ((getFastSpeed () + 1) * time2);
00173 
00174                 if ((IsBouncing ()) && (time1 <= 0))
00175 
00176                 {
00177                         setIsRewinding (false);
00178                         setIsFastForwarding (true);
00179                 }
00180 
00181                 if ((IsLooping ()) && (time1 <= 0))
00182                         time1 = m_maxtime;
00183 
00184                 if (time1 < 0)
00185                         time1 = 0;
00186 
00187                 m_timer_1.Start (time1);
00188                 m_timer_2.Start (0);
00189 
00190                 return time1;
00191         }
00192 
00193         if (IsFastForwarding ())
00194 
00195         {
00196                 time1 += int ((getFastSpeed () - 1) * time2);
00197 
00198                 if ((IsBouncing ()) && (time1 >= m_maxtime))
00199 
00200                 {
00201                         setIsRewinding (true);
00202                         setIsFastForwarding (false);
00203                 }
00204 
00205                 if ((IsLooping ()) && (time1 >= m_maxtime))
00206                         time1 = 0;
00207 
00208                 if (time1 >= getMaxTime ())
00209                         time1 = getMaxTime ();
00210 
00211                 m_timer_1.Start (time1);
00212                 m_timer_2.Start (0);
00213 
00214                 return time1;
00215         }
00216 
00217         if ((IsBouncing ()) && (time1 >= getMaxTime ()))
00218 
00219         {
00220                 setIsReversing (true);
00221 
00222                 time1 = getMaxTime ();
00223         }
00224 
00225         if ((IsLooping ()) && (time1 >= getMaxTime ()))
00226 
00227         {
00228                 time1 = 0;
00229         }
00230 
00231         if (time1 > getMaxTime ())
00232                 time1 = getMaxTime ();
00233 
00234         m_timer_1.Start (time1);
00235         m_timer_2.Start (0);
00236 
00237         return time1;*/
00238 }
00239 
00240 void vuStopWatch::Pause ()
00241 
00242 {
00243         ((wxStopWatch *) (m_timer_1))->Pause ();
00244         ((wxStopWatch *) (m_timer_2))->Pause ();
00245 
00246 //      m_timer_1.Pause ();
00247 //      m_timer_2.Pause ();
00248 }
00249 
00250 void vuStopWatch::Resume ()
00251 
00252 {
00253         ((wxStopWatch *) (m_timer_1))->Resume ();
00254         ((wxStopWatch *) (m_timer_2))->Resume ();
00255 
00256 //      m_timer_1.Resume ();
00257 //      m_timer_2.Resume ();
00258 }
00259 
00260 int vuStopWatch::TotalTime ()
00261 
00262 {
00263         return ((wxStopWatch *) (m_timer_3))->Time ();
00264 
00265 //      return m_timer_3.Time ();
00266 }
00267 
00268 void vuStopWatch::setIsReversing (bool isit)
00269 
00270 {
00271 //      cout << "setting reversing" << endl;
00272 //      cout << "maxtime:" << m_maxtime << endl;
00273 
00274         mb_reversing = isit;
00275 
00276         if (isit)
00277 
00278         {
00279                 setIsRewinding (false);
00280                 setIsFastForwarding (false);
00281         }
00282 
00283         ((wxStopWatch *) (m_timer_2))->Start (0);
00284 
00285 //      m_timer_2.Start (0);
00286 }
00287 
00288 #include <stdlib.h>
00289 
00290 void vuStopWatch::setIsRewinding (bool isit)
00291 
00292 {
00293 //      cout << "setting rewinding" << endl;
00294 
00295 //      exit (0);
00296 
00297         mb_rewinding = isit;
00298 
00299         if (isit)
00300 
00301         {
00302                 setIsReversing (false);
00303                 setIsFastForwarding (false);
00304         }
00305 
00306         ((wxStopWatch *) (m_timer_2))->Start (0);
00307 
00308 //      m_timer_2.Start (0);
00309 }
00310 
00311 void vuStopWatch::setIsFastForwarding (bool isit)
00312 
00313 {
00314         mb_fastforwarding = isit;
00315 
00316         if (isit)
00317 
00318         {
00319                 setIsReversing (false);
00320                 setIsRewinding (false);
00321         }
00322 
00323         ((wxStopWatch *) (m_timer_2))->Start (0);
00324 
00325 //      m_timer_2.Start (0);
00326 }
00327 
00328 void vuStopWatch::setIsLooping (bool isit)
00329 
00330 {
00331         mb_looping = isit;
00332 
00333         if (isit)
00334                 setIsBouncing (false);
00335 }
00336 
00337 void vuStopWatch::setIsBouncing (bool isit)
00338 
00339 {
00340         mb_bouncing = isit;
00341 
00342         if (isit)
00343                 setIsLooping (false);
00344 }
00345 
00346 bool vuStopWatch::IsReversing ()
00347 
00348 {
00349         return mb_reversing;
00350 }
00351 
00352 bool vuStopWatch::IsRewinding ()
00353 
00354 {
00355         return mb_rewinding;
00356 }
00357 
00358 bool vuStopWatch::IsFastForwarding ()
00359 
00360 {
00361         return mb_fastforwarding;
00362 }
00363 
00364 bool vuStopWatch::IsLooping ()
00365 
00366 {
00367         return mb_looping;
00368 }
00369 
00370 bool vuStopWatch::IsBouncing ()
00371 
00372 {
00373         return mb_bouncing;
00374 }
00375 
00376 void vuStopWatch::setFastSpeed (float mul)
00377 
00378 {
00379         m_fastspeed = mul;
00380 }
00381 
00382 float vuStopWatch::getFastSpeed ()
00383 
00384 {
00385         return m_fastspeed;
00386 }
00387 
00388 void vuStopWatch::setMaxTime (int maxtime)
00389 
00390 {
00391         m_maxtime = maxtime;
00392 
00393 //      cout << "max_timer = " << m_maxtime << ' ' << Time ();
00394 
00395 //      if (IsBouncing ()) cout << " bouncing:" << endl;
00396 }
00397 
00398 int vuStopWatch::getMaxTime ()
00399 
00400 {
00401         return m_maxtime;
00402 }
00403 
00404 
00405 
00406 
00407 
00408 

Generated on Wed Dec 15 21:20:38 2004 for vuVolume by  doxygen 1.3.9.1