Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: VampPluginSDK: RealTime.h Source File Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: Chris@1: Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1:
VampPluginSDK Chris@1:  2.1 Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1:
Chris@1:
vamp-sdk/RealTime.h
Chris@1:
Chris@1:
Chris@1: Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@1: 00002 
Chris@1: 00003 /*
Chris@1: 00004     Vamp
Chris@1: 00005 
Chris@1: 00006     An API for audio analysis and feature extraction plugins.
Chris@1: 00007 
Chris@1: 00008     Centre for Digital Music, Queen Mary, University of London.
Chris@1: 00009     Copyright 2006 Chris Cannam.
Chris@1: 00010   
Chris@1: 00011     Permission is hereby granted, free of charge, to any person
Chris@1: 00012     obtaining a copy of this software and associated documentation
Chris@1: 00013     files (the "Software"), to deal in the Software without
Chris@1: 00014     restriction, including without limitation the rights to use, copy,
Chris@1: 00015     modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@1: 00016     of the Software, and to permit persons to whom the Software is
Chris@1: 00017     furnished to do so, subject to the following conditions:
Chris@1: 00018 
Chris@1: 00019     The above copyright notice and this permission notice shall be
Chris@1: 00020     included in all copies or substantial portions of the Software.
Chris@1: 00021 
Chris@1: 00022     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@1: 00023     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@1: 00024     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@1: 00025     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
Chris@1: 00026     ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@1: 00027     CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@1: 00028     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@1: 00029 
Chris@1: 00030     Except as contained in this notice, the names of the Centre for
Chris@1: 00031     Digital Music; Queen Mary, University of London; and Chris Cannam
Chris@1: 00032     shall not be used in advertising or otherwise to promote the sale,
Chris@1: 00033     use or other dealings in this Software without prior written
Chris@1: 00034     authorization.
Chris@1: 00035 */
Chris@1: 00036 
Chris@1: 00037 /*
Chris@1: 00038    This is a modified version of a source file from the 
Chris@1: 00039    Rosegarden MIDI and audio sequencer and notation editor.
Chris@1: 00040    This file copyright 2000-2006 Chris Cannam.
Chris@1: 00041    Relicensed by the author as detailed above.
Chris@1: 00042 */
Chris@1: 00043 
Chris@1: 00044 #ifndef _VAMP_REAL_TIME_H_
Chris@1: 00045 #define _VAMP_REAL_TIME_H_
Chris@1: 00046 
Chris@1: 00047 #include <iostream>
Chris@1: 00048 #include <string>
Chris@1: 00049 
Chris@1: 00050 #ifndef _WIN32
Chris@1: 00051 struct timeval;
Chris@1: 00052 #endif
Chris@1: 00053 
Chris@1: 00054 #include "plugguard.h"
Chris@1: 00055 _VAMP_SDK_PLUGSPACE_BEGIN(RealTime.h)
Chris@1: 00056 
Chris@1: 00057 namespace Vamp {
Chris@1: 00058 
Chris@1: 00066 struct RealTime
Chris@1: 00067 {
Chris@1: 00068     int sec;
Chris@1: 00069     int nsec;
Chris@1: 00070 
Chris@1: 00071     int usec() const { return nsec / 1000; }
Chris@1: 00072     int msec() const { return nsec / 1000000; }
Chris@1: 00073 
Chris@1: 00074     RealTime(): sec(0), nsec(0) {}
Chris@1: 00075     RealTime(int s, int n);
Chris@1: 00076 
Chris@1: 00077     RealTime(const RealTime &r) :
Chris@1: 00078         sec(r.sec), nsec(r.nsec) { }
Chris@1: 00079 
Chris@1: 00080     static RealTime fromSeconds(double sec);
Chris@1: 00081     static RealTime fromMilliseconds(int msec);
Chris@1: 00082 
Chris@1: 00083 #ifndef _WIN32
Chris@1: 00084     static RealTime fromTimeval(const struct timeval &);
Chris@1: 00085 #endif
Chris@1: 00086 
Chris@1: 00087     RealTime &operator=(const RealTime &r) {
Chris@1: 00088         sec = r.sec; nsec = r.nsec; return *this;
Chris@1: 00089     }
Chris@1: 00090 
Chris@1: 00091     RealTime operator+(const RealTime &r) const {
Chris@1: 00092         return RealTime(sec + r.sec, nsec + r.nsec);
Chris@1: 00093     }
Chris@1: 00094     RealTime operator-(const RealTime &r) const {
Chris@1: 00095         return RealTime(sec - r.sec, nsec - r.nsec);
Chris@1: 00096     }
Chris@1: 00097     RealTime operator-() const {
Chris@1: 00098         return RealTime(-sec, -nsec);
Chris@1: 00099     }
Chris@1: 00100 
Chris@1: 00101     bool operator <(const RealTime &r) const {
Chris@1: 00102         if (sec == r.sec) return nsec < r.nsec;
Chris@1: 00103         else return sec < r.sec;
Chris@1: 00104     }
Chris@1: 00105 
Chris@1: 00106     bool operator >(const RealTime &r) const {
Chris@1: 00107         if (sec == r.sec) return nsec > r.nsec;
Chris@1: 00108         else return sec > r.sec;
Chris@1: 00109     }
Chris@1: 00110 
Chris@1: 00111     bool operator==(const RealTime &r) const {
Chris@1: 00112         return (sec == r.sec && nsec == r.nsec);
Chris@1: 00113     }
Chris@1: 00114  
Chris@1: 00115     bool operator!=(const RealTime &r) const {
Chris@1: 00116         return !(r == *this);
Chris@1: 00117     }
Chris@1: 00118  
Chris@1: 00119     bool operator>=(const RealTime &r) const {
Chris@1: 00120         if (sec == r.sec) return nsec >= r.nsec;
Chris@1: 00121         else return sec >= r.sec;
Chris@1: 00122     }
Chris@1: 00123 
Chris@1: 00124     bool operator<=(const RealTime &r) const {
Chris@1: 00125         if (sec == r.sec) return nsec <= r.nsec;
Chris@1: 00126         else return sec <= r.sec;
Chris@1: 00127     }
Chris@1: 00128 
Chris@1: 00129     RealTime operator/(int d) const;
Chris@1: 00130 
Chris@1: 00134     double operator/(const RealTime &r) const;
Chris@1: 00135 
Chris@1: 00140     std::string toString() const;
Chris@1: 00141 
Chris@1: 00146     std::string toText(bool fixedDp = false) const;
Chris@1: 00147 
Chris@1: 00151     static long realTime2Frame(const RealTime &r, unsigned int sampleRate);
Chris@1: 00152 
Chris@1: 00156     static RealTime frame2RealTime(long frame, unsigned int sampleRate);
Chris@1: 00157 
Chris@1: 00158     static const RealTime zeroTime;
Chris@1: 00159 };
Chris@1: 00160 
Chris@1: 00161 std::ostream &operator<<(std::ostream &out, const RealTime &rt);
Chris@1: 00162 
Chris@1: 00163 }
Chris@1: 00164 
Chris@1: 00165 _VAMP_SDK_PLUGSPACE_END(RealTime.h)
Chris@1: 00166     
Chris@1: 00167 #endif
Chris@1: 
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: