18 #define thisTTClass System
19 #define thisTTClassName "system"
20 #define thisTTClassTags "clock, System"
22 #define thisClockVersion "0.1"
23 #define thisClockAuthor "Theo de la Hogue"
24 #define thisClockStretchable YES
26 extern "C" TT_EXTENSION_EXPORT
TTErr TTLoadJamomaExtension_System(
void)
29 System::registerClass();
59 if (mDuration <= mOffset)
67 (mCallback)(mBaton, mPosition, mDate);
70 sendNotification(
TTSymbol(
"ClockRunningChanged"), mRunning);
73 else if (mExternalTick)
82 sendNotification(
TTSymbol(
"ClockRunningChanged"), mRunning);
91 if (mThread.joinable())
95 mThread = std::thread(&System::SystemThreadCallback,
this);
109 sendNotification(
TTSymbol(
"ClockRunningChanged"), mRunning);
121 TTFloat64 delta = computeDeltaTime() * mSpeed;
124 if (mPaused || !mRunning)
127 mPosition += delta / mDuration;
130 if (mPosition < 1. || mInfinite)
133 (mCallback)(mBaton, mPosition, mDate);
144 (mCallback)(mBaton, mPosition, mDate);
158 TTErr System::Pause()
165 TTErr System::Resume()
175 TTUInt64 granularityInUs = mGranularity * 1000;
180 #ifdef TT_PLATFORM_WIN
182 time2.gettimeofday(&tv, NULL);
185 gettimeofday(&tv, &tz);
188 TTUInt64 currentTime = tv.tv_sec * 1000000L + tv.tv_usec;
193 if (currentTime < mLastTime)
195 TTLogMessage(
"System::computeDeltaTime() : current time is lower than last time\n");
199 deltaInUs = (currentTime - mLastTime);
201 if (deltaInUs < granularityInUs)
203 std::this_thread::sleep_for(std::chrono::microseconds(granularityInUs - deltaInUs));
205 deltaInUs = granularityInUs;
208 mLastTime += deltaInUs;
211 mLastTime = currentTime;
217 void System::SystemThreadCallback()
225 sendNotification(
TTSymbol(
"ClockRunningChanged"), mRunning);
233 void System::stopThread()
238 while (!mThread.joinable())
239 std::this_thread::sleep_for(std::chrono::milliseconds(500));
245 catch (std::system_error& e)
247 TTLogError(
"System::stopThread() : %s\n", e.what());
std::uint64_t TTUInt64
64 bit unsigned integer
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
double TTFloat64
64 bit floating point number
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
System clock class is based on the time of the system.
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
void clear()
Clear all values from the vector, leaving with size of 0.
void TTFOUNDATION_EXPORT TTLogMessage(TTImmutableCString message,...)
Platform and host independent method for posting log messages.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
[doxygenAppendixC_copyExample]