• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 44419295440

18 Nov 2026 11:16PM UTC coverage: 61.964% (+25.2%) from 36.744%
44419295440

push

github

mcallegari
engine/test: add missing file

18252 of 29456 relevant lines covered (61.96%)

62667.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.97
/engine/src/mastertimer.cpp
1
/*
2
  Q Light Controller Plus
3
  mastertimer.cpp
4

5
  Copyright (C) Heikki Junnila
6
                Massimo Callegari
7

8
  Licensed under the Apache License, Version 2.0 (the "License");
9
  you may not use this file except in compliance with the License.
10
  You may obtain a copy of the License at
11

12
      http://www.apache.org/licenses/LICENSE-2.0.txt
13

14
  Unless required by applicable law or agreed to in writing, software
15
  distributed under the License is distributed on an "AS IS" BASIS,
16
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
  See the License for the specific language governing permissions and
18
  limitations under the License.
19
*/
20

21
#include <QDebug>
22
#include <QSettings>
23
#include <QMutexLocker>
24
#include <cmath>
25

26
#if defined(WIN32) || defined(Q_OS_WIN)
27
#   include "mastertimer-win32.h"
28
#else
29
#   include <unistd.h>
30
#   include "mastertimer-unix.h"
31
#endif
32

33
#include "inputoutputmap.h"
34
#include "genericfader.h"
35
#include "mastertimer.h"
36
#include "dmxsource.h"
37
#include "function.h"
38
#include "universe.h"
39
#include "doc.h"
40

41
#define MASTERTIMER_FREQUENCY "mastertimer/frequency"
42
#define MASTERTIMER_LATENCY_OFFSET "mastertimer/latencyoffset"
43
#define LATE_TO_BEAT_THRESHOLD 25
44

45
/** The highest beat fraction estimated while waiting for an external beat,
46
 *  so that the beat position never runs past a beat that didn't happen yet */
47
#define MAX_EXTERNAL_BEAT_FRACTION 0.999
48

49
/** The timer tick frequency in Hertz */
50
uint MasterTimer::s_frequency = 50;
51
uint MasterTimer::s_tick = 20;
52

53
//#define DEBUG_MASTERTIMER
54

55
#ifdef DEBUG_MASTERTIMER
56
quint64 ticksCount = 0;
57
#endif
58

59
/*****************************************************************************
60
 * Initialization
61
 *****************************************************************************/
62

63
MasterTimer::MasterTimer(Doc* doc)
286 ✔
64
    : QObject(doc)
65
    , d_ptr(new MasterTimerPrivate(this))
286 ✔
66
    , m_stopAllFunctions(false)
286 ✔
67
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
68
    , m_dmxSourceListMutex(QMutex::Recursive)
69
#endif
70
    , m_beatSourceType(None)
286 ✔
71
    , m_currentBPM(120)
286 ✔
72
    , m_beatTimeDuration(500)
286 ✔
73
    , m_beatRequested(false)
286 ✔
74
    , m_lastBeatOffset(0)
286 ✔
75
    , m_beatCount(0)
286 ✔
76
    , m_beatPosition(0)
286 ✔
77
    , m_beatsPerBar(MASTERTIMER_DEFAULT_BEATS_PER_BAR)
286 ✔
78
    , m_latencyOffset(0)
286 ✔
79
    , m_launchQuantize(QuantizeOff)
286 ✔
80
    , m_lastTimelineBeat(0)
286 ✔
81
    , m_timelineBeatValid(false)
286 ✔
82
    , m_timelineTimeToNextBeat(0)
858 ✔
83
{
84
    Q_ASSERT(doc != NULL);
286 ✔
85
    Q_ASSERT(d_ptr != NULL);
286 ✔
86

87
    QSettings settings;
286 ✔
88
    QVariant var = settings.value(MASTERTIMER_FREQUENCY);
286 ✔
89
    if (var.isValid() == true)
286 ✔
90
        s_frequency = var.toUInt();
×
91

92
    s_tick = uint(double(1000) / double(s_frequency));
286 ✔
93

94
    m_latencyOffset = settings.value(MASTERTIMER_LATENCY_OFFSET, 0).toInt();
572 ✔
95
}
286 ✔
96

97
MasterTimer::~MasterTimer()
528 ✔
98
{
99
    if (d_ptr->isRunning() == true)
286 ✔
100
        stop();
1 ✔
101

102
    delete d_ptr;
286 ✔
103
    d_ptr = NULL;
286 ✔
104
}
528 ✔
105

106
void MasterTimer::start()
9 ✔
107
{
108
    Q_ASSERT(d_ptr != NULL);
9 ✔
109
    d_ptr->start();
9 ✔
110
}
9 ✔
111

112
void MasterTimer::stop()
4 ✔
113
{
114
    Q_ASSERT(d_ptr != NULL);
4 ✔
115
    stopAllFunctions();
4 ✔
116
    d_ptr->stop();
4 ✔
117

118
    /* After the timer thread has fully stopped, clear any remaining function
119
     * pointers to prevent dangling references if a function slipped through
120
     * the stopAllFunctions/startQueue race window. */
121
    QMutexLocker locker(&m_functionListMutex);
4 ✔
122
    m_functionList.clear();
4 ✔
123
    m_startQueue.clear();
4 ✔
124

125
    // release the sources of the Functions that never started
126
    foreach (Function *f, m_heldFunctions)
4 ✔
127
        f->stop(FunctionParent::master());
4 ✔
128
    m_heldFunctions.clear();
4 ✔
129
    m_quantizeRequests.clear();
4 ✔
130
}
4 ✔
131

132
void MasterTimer::timerTick()
646 ✔
133
{
134
    Doc *doc = qobject_cast<Doc*> (parent());
646 ✔
135
    Q_ASSERT(doc != NULL);
646 ✔
136

137
#ifdef DEBUG_MASTERTIMER
138
    qDebug() << "[MasterTimer] *********** tick:" << ticksCount++ << "**********";
139
#endif
140

141
    switch (m_beatSourceType)
646 ✔
142
    {
143
        case Internal:
16 ✔
144
        {
145
            int elapsedTime = qRound((double)m_beatTimer.nsecsElapsed() / 1000000) + m_lastBeatOffset;
16 ✔
146
            //qDebug() << "Elapsed beat:" << elapsedTime;
147
            if (elapsedTime >= m_beatTimeDuration)
16 ✔
148
            {
149
                // it's time to fire a beat
150
                m_beatRequested = true;
6 ✔
151

152
                // restart the time for the next beat, starting at a delta
153
                // milliseconds, otherwise it will generate an unpleasant drift
154
                //qDebug() << "Elapsed:" << elapsedTime << ", delta:" << elapsedTime - m_beatTimeDuration;
155
                m_lastBeatOffset = elapsedTime - m_beatTimeDuration;
6 ✔
156
                m_beatTimer.restart();
6 ✔
157
                m_beatCount++;
6 ✔
158
                elapsedTime = m_lastBeatOffset;
6 ✔
159

160
                // inform the listening classes that a beat is happening
161
                emit beat();
6 ✔
162
            }
163
            m_beatPosition = m_beatCount + double(elapsedTime) / m_beatTimeDuration;
16 ✔
164
        }
165
        break;
16 ✔
166
        case External:
4 ✔
167
        {
168
            // a beat requested by the external source. Restart the beat
169
            // timer here, to estimate the position until the next one
170
            if (m_beatRequested)
4 ✔
171
            {
172
                m_beatCount++;
1 ✔
173
                m_beatTimer.restart();
1 ✔
174
            }
175
            double elapsedTime = double(m_beatTimer.nsecsElapsed()) / 1000000.0 + m_latencyOffset;
4 ✔
176
            m_beatPosition = m_beatCount +
8 ✔
177
                qBound(0.0, elapsedTime / m_beatTimeDuration, MAX_EXTERNAL_BEAT_FRACTION);
4 ✔
178
        }
179
        break;
4 ✔
180

181
        case Timeline:
6 ✔
182
            timerTickTimeline();
6 ✔
183
        break;
6 ✔
184

185
        case None:
620 ✔
186
        default:
187
            m_beatRequested = false;
620 ✔
188
        break;
620 ✔
189
    }
190

191
    QList<Universe *> universes = doc->inputOutputMap()->claimUniverses();
1,292 ✔
192

193
    timerTickFunctions(universes);
646 ✔
194
    timerTickDMXSources(universes);
646 ✔
195

196
    doc->inputOutputMap()->releaseUniverses();
646 ✔
197

198
    m_beatRequested = false;
646 ✔
199

200
    //qDebug() << ">>>>>>>> MASTERTIMER TICK";
201
    emit tickReady();
646 ✔
202
}
646 ✔
203

204
uint MasterTimer::frequency()
14 ✔
205
{
206
    return s_frequency;
14 ✔
207
}
208

209
uint MasterTimer::tick()
89,967 ✔
210
{
211
    return s_tick;
89,967 ✔
212
}
213

214
/*****************************************************************************
215
 * Functions
216
 *****************************************************************************/
217

218
void MasterTimer::startFunction(Function* function)
213 ✔
219
{
220
    if (function == NULL)
213 ✔
221
        return;
1 ✔
222

223
    QMutexLocker locker(&m_functionListMutex);
212 ✔
224
    if (m_startQueue.contains(function) == false)
212 ✔
225
        m_startQueue.append(function);
178 ✔
226
}
212 ✔
227

228
void MasterTimer::stopAllFunctions()
7 ✔
229
{
230
    m_stopAllFunctions = true;
7 ✔
231

232
    {
233
        // the Functions waiting for a quantized start are not running:
234
        // just release their sources, so they never start
235
        QMutexLocker locker(&m_functionListMutex);
7 ✔
236
        foreach (Function *f, m_heldFunctions)
8 ✔
237
            f->stop(FunctionParent::master());
8 ✔
238
        m_heldFunctions.clear();
7 ✔
239
    }
7 ✔
240

241
    /* Wait until all functions have been stopped */
242
    while (runningFunctions() > 0)
14 ✔
243
    {
244
#if defined(WIN32) || defined(Q_OS_WIN)
245
        Sleep(10);
246
#else
247
        usleep(10000);
7 ✔
248
#endif
249
    }
250

251
    m_stopAllFunctions = false;
7 ✔
252
}
7 ✔
253

254
void MasterTimer::fadeAndStopAll(int timeout)
×
255
{
256
    if (timeout)
×
257
    {
258
        Doc *doc = qobject_cast<Doc*> (parent());
×
259
        Q_ASSERT(doc != NULL);
×
260

261
        QList<Universe *> universes = doc->inputOutputMap()->claimUniverses();
×
262
        foreach (Universe *universe, universes)
×
263
            universe->setFaderFadeOut(timeout);
×
264

265
        doc->inputOutputMap()->releaseUniverses();
×
266
    }
×
267

268
    // At last, stop all functions
269
    stopAllFunctions();
×
270
}
×
271

272
int MasterTimer::runningFunctions() const
50 ✔
273
{
274
    return m_functionList.size();
50 ✔
275
}
276

277
void MasterTimer::timerTickFunctions(QList<Universe *> universes)
646 ✔
278
{
279
    // List of m_functionList indices that should be removed at the end of this
280
    // function. The functions at the indices have been stopped.
281
    QList<int> removeList;
646 ✔
282

283
    bool functionListHasChanged = false;
646 ✔
284
    bool stoppedAFunction = true;
646 ✔
285
    bool firstIteration = true;
646 ✔
286

287
    while (stoppedAFunction)
1,400 ✔
288
    {
289
        stoppedAFunction = false;
754 ✔
290
        removeList.clear();
754 ✔
291

292
        for (int i = 0; i < m_functionList.size(); i++)
1,438 ✔
293
        {
294
            Function* function = m_functionList.at(i);
684 ✔
295

296
            if (function != NULL)
684 ✔
297
            {
298
                /* Run the function unless it's supposed to be stopped */
299
                if (function->stopped() == false && m_stopAllFunctions == false)
684 ✔
300
                {
301
                    if (firstIteration)
561 ✔
302
                        function->write(this, universes);
544 ✔
303
                }
304
                else
305
                {
306
                    // Clear function's parentList
307
                    if (m_stopAllFunctions)
123 ✔
308
                        function->stop(FunctionParent::master());
12 ✔
309
                    /* Function should be stopped instead */
310
                    function->postRun(this, universes);
123 ✔
311
                    //qDebug() << "[MasterTimer] Add function (ID: " << function->id() << ") to remove list ";
312
                    removeList << i; // Don't remove the item from the list just yet.
123 ✔
313
                    functionListHasChanged = true;
123 ✔
314
                    stoppedAFunction = true;
123 ✔
315

316
                    emit functionStopped(function->id());
123 ✔
317
                }
318
            }
319
        }
320

321
        // Remove functions that need to be removed AFTER all functions have been run
322
        // for this round. This is done separately to prevent a case when a function
323
        // is first removed and then another is added (chaser, for example), keeping the
324
        // list's size the same, thus preventing the last added function from being run
325
        // on this round. The indices in removeList are automatically sorted because the
326
        // list is iterated with an int above from 0 to size, so iterating the removeList
327
        // backwards here will always remove the correct indices.
328
        QListIterator <int> it(removeList);
754 ✔
329
        it.toBack();
754 ✔
330
        while (it.hasPrevious() == true)
877 ✔
331
            m_functionList.removeAt(it.previous());
123 ✔
332

333
        firstIteration = false;
754 ✔
334
    }
754 ✔
335

336
    {
337
        QMutexLocker locker(&m_functionListMutex);
646 ✔
338

339
        // the quantize requests already there before processing the start queue
340
        QList<Function*> previousRequests(m_quantizeRequests);
646 ✔
341

342
        if (m_heldFunctions.isEmpty() == false &&
649 ✔
343
            (isQuantizing() == false || isLaunchBoundary()))
3 ✔
344
        {
345
            // the beat/bar has come: start the held Functions,
346
            // unless they have been stopped while waiting
347
            foreach (Function *f, m_heldFunctions)
6 ✔
348
            {
349
                if (f->stopped() == false && m_startQueue.contains(f) == false)
3 ✔
350
                    m_startQueue.append(f);
2 ✔
351
            }
3 ✔
352
            m_heldFunctions.clear();
3 ✔
353
        }
354

355
        while (m_startQueue.size() > 0)
783 ✔
356
        {
357
            QList<Function*> startQueue;
137 ✔
358
            foreach (Function *f, m_startQueue)
282 ✔
359
            {
360
                // a quantized start waits for the next beat/bar
361
                if (m_quantizeRequests.removeAll(f) > 0 && isQuantizing())
145 ✔
362
                {
363
                    if (m_heldFunctions.contains(f) == false)
4 ✔
364
                        m_heldFunctions.append(f);
4 ✔
365
                }
366
                else
367
                {
368
                    startQueue.append(f);
141 ✔
369
                }
370
            }
137 ✔
371
            m_startQueue.clear();
137 ✔
372
            locker.unlock();
137 ✔
373

374
            foreach (Function* f, startQueue)
278 ✔
375
            {
376
                if (m_functionList.contains(f))
141 ✔
377
                {
378
                    f->postRun(this, universes);
1 ✔
379
                }
380
                else
381
                {
382
                    m_functionList.append(f);
140 ✔
383
                    functionListHasChanged = true;
140 ✔
384
                }
385
                f->preRun(this);
141 ✔
386
                f->write(this, universes);
141 ✔
387
                emit functionStarted(f->id());
141 ✔
388
            }
137 ✔
389

390
            locker.relock();
137 ✔
391
        }
137 ✔
392

393
        // a request is meant for the start that follows it. Drop the requests
394
        // of starts that didn't happen (e.g. the Function was already running),
395
        // but keep those made while the start queue was being processed
396
        foreach (Function *f, previousRequests)
652 ✔
397
            m_quantizeRequests.removeAll(f);
652 ✔
398
    }
646 ✔
399

400
    if (functionListHasChanged)
646 ✔
401
        emit functionListChanged();
152 ✔
402
}
646 ✔
403

404
/****************************************************************************
405
 * DMX Sources
406
 ****************************************************************************/
407

408
void MasterTimer::registerDMXSource(DMXSource *source)
65 ✔
409
{
410
    Q_ASSERT(source != NULL);
65 ✔
411

412
    QMutexLocker lock(&m_dmxSourceListMutex);
65 ✔
413
    if (m_dmxSourceList.contains(source) == false)
65 ✔
414
        m_dmxSourceList.append(source);
49 ✔
415
}
65 ✔
416

417
void MasterTimer::unregisterDMXSource(DMXSource *source)
49 ✔
418
{
419
    Q_ASSERT(source != NULL);
49 ✔
420

421
    QMutexLocker lock(&m_dmxSourceListMutex);
49 ✔
422
    m_dmxSourceList.removeAll(source);
49 ✔
423
}
49 ✔
424

425
void MasterTimer::timerTickDMXSources(QList<Universe *> universes)
646 ✔
426
{
427
    /* Lock before accessing the DMX sources list. */
428
    QMutexLocker lock(&m_dmxSourceListMutex);
646 ✔
429

430
    foreach (DMXSource *source, m_dmxSourceList)
754 ✔
431
    {
432
        Q_ASSERT(source != NULL);
108 ✔
433

434
#ifdef DEBUG_MASTERTIMER
435
        qDebug() << "[MasterTimer] ticking DMX source" << i;
436
#endif
437

438
        /* Get DMX data from the source */
439
        source->writeDMX(this, universes);
108 ✔
440
    }
646 ✔
441
}
646 ✔
442

443
/*************************************************************************
444
 * Beats generation
445
 *************************************************************************/
446

447
void MasterTimer::setBeatSourceType(MasterTimer::BeatsSourceType type)
23 ✔
448
{
449
    if (type == m_beatSourceType)
23 ✔
450
        return;
2 ✔
451

452
    // alright, this causes a time drift of maximum 1ms per beat
453
    // but at the moment I am not looking for a better solution
454
    m_beatTimeDuration = 60000 / m_currentBPM;
21 ✔
455
    m_beatTimer.restart();
21 ✔
456
    m_beatCount = 0;
21 ✔
457
    m_beatPosition = 0;
21 ✔
458

459
    m_timelineBeatValid = false;
21 ✔
460

461
    m_beatSourceType = type;
21 ✔
462
}
463

464
MasterTimer::BeatsSourceType MasterTimer::beatSourceType() const
2 ✔
465
{
466
    return m_beatSourceType;
2 ✔
467
}
468

469
void MasterTimer::requestBpmNumber(int bpm)
6 ✔
470
{
471
    // the timeline provides its own tempo
472
    if (m_beatSourceType == Timeline)
6 ✔
473
        return;
×
474

475
    if (bpm == m_currentBPM)
6 ✔
476
        return;
5 ✔
477

478
    m_currentBPM = bpm;
1 ✔
479
    m_beatTimeDuration = 60000 / m_currentBPM;
1 ✔
480
    m_beatTimer.restart();
1 ✔
481

482
    emit bpmNumberChanged(bpm);
1 ✔
483
}
484

485
int MasterTimer::bpmNumber() const
16 ✔
486
{
487
    return m_currentBPM;
16 ✔
488
}
489

490
int MasterTimer::beatTimeDuration() const
1,484 ✔
491
{
492
    return m_beatTimeDuration;
1,484 ✔
493
}
494

495
int MasterTimer::timeToNextBeat() const
22 ✔
496
{
497
    if (m_beatSourceType == Timeline)
22 ✔
498
        return m_timelineTimeToNextBeat - m_beatTimer.elapsed();
×
499

500
    return m_beatTimeDuration - m_beatTimer.elapsed();
22 ✔
501
}
502

503
int MasterTimer::nextBeatTimeOffset() const
×
504
{
505
    // get the time offset to the next beat
506
    int toNext = timeToNextBeat();
×
507
    // get the percentage of beat time passed
508
    int beatPercentage = (100 * toNext) / m_beatTimeDuration;
×
509

510
    // if a Function has been started within the first LATE_TO_BEAT_THRESHOLD %
511
    // of a beat, then it means it is "late" but there's
512
    // no need to wait a whole beat
513
    if (beatPercentage <= LATE_TO_BEAT_THRESHOLD)
×
514
        return toNext;
×
515

516
    // otherwise we're running early, so we should wait the
517
    // whole remaining time
518
    return -toNext;
×
519
}
520

521
bool MasterTimer::isBeat() const
1,912 ✔
522
{
523
    return m_beatRequested;
1,912 ✔
524
}
525

526
void MasterTimer::requestBeat()
1 ✔
527
{
528
    // forceful request of a beat, processed at
529
    // the next timerTick call
530
    m_beatRequested = true;
1 ✔
531
}
1 ✔
532

533
double MasterTimer::beatPosition() const
11 ✔
534
{
535
    return m_beatPosition;
11 ✔
536
}
537

538
double MasterTimer::barPhase() const
7 ✔
539
{
540
    // a timeline beat can be negative (e.g. right after joining a session)
541
    double phase = std::fmod(m_beatPosition, double(m_beatsPerBar));
7 ✔
542
    return phase < 0 ? phase + m_beatsPerBar : phase;
7 ✔
543
}
544

545
void MasterTimer::setBeatsPerBar(int beats)
10 ✔
546
{
547
    if (beats < 1)
10 ✔
548
        return;
2 ✔
549

550
    m_beatsPerBar = beats;
8 ✔
551
}
552

553
int MasterTimer::beatsPerBar() const
14 ✔
554
{
555
    return m_beatsPerBar;
14 ✔
556
}
557

558
void MasterTimer::setLatencyOffset(int ms)
3 ✔
559
{
560
    m_latencyOffset = ms;
3 ✔
561

562
    QSettings settings;
3 ✔
563
    settings.setValue(MASTERTIMER_LATENCY_OFFSET, ms);
6 ✔
564
}
3 ✔
565

566
int MasterTimer::latencyOffset() const
10 ✔
567
{
568
    return m_latencyOffset;
10 ✔
569
}
570

571
void MasterTimer::setLaunchQuantize(MasterTimer::LaunchQuantize quantize)
12 ✔
572
{
573
    m_launchQuantize = quantize;
12 ✔
574
}
12 ✔
575

576
MasterTimer::LaunchQuantize MasterTimer::launchQuantize() const
4 ✔
577
{
578
    return m_launchQuantize;
4 ✔
579
}
580

581
void MasterTimer::requestQuantizedStart(Function *function)
11 ✔
582
{
583
    if (function == NULL)
11 ✔
584
        return;
×
585

586
    QMutexLocker locker(&m_functionListMutex);
11 ✔
587
    if (m_quantizeRequests.contains(function) == false)
11 ✔
588
        m_quantizeRequests.append(function);
11 ✔
589
}
11 ✔
590

591
bool MasterTimer::isQuantizing() const
9 ✔
592
{
593
    return m_launchQuantize != QuantizeOff && m_beatSourceType != None;
9 ✔
594
}
595

596
bool MasterTimer::isLaunchBoundary() const
3 ✔
597
{
598
    if (isBeat() == false)
3 ✔
599
        return false;
×
600

601
    if (m_launchQuantize == QuantizeBar)
3 ✔
602
    {
603
        // a beat can fire slightly before or after the exact beat
604
        // position, so round to the nearest one
605
        return qRound(barPhase()) % m_beatsPerBar == 0;
1 ✔
606
    }
607

608
    return true;
2 ✔
609
}
610

611
/*************************************************************************
612
 * Timeline beat source
613
 *************************************************************************/
614

615
void MasterTimer::timerTickTimeline()
6 ✔
616
{
617
    Doc *doc = qobject_cast<Doc*> (parent());
6 ✔
618
    double position = 0;
6 ✔
619
    double tempo = 0;
6 ✔
620

621
    // the timeline is captured ahead by the latency offset, so that beats
622
    // and positions are anticipated by the output latency
623
    if (doc->inputOutputMap()->captureBeatTimeline(position, tempo) == false || tempo <= 0)
6 ✔
624
    {
625
        m_beatRequested = false;
×
626
        return;
×
627
    }
628

629
    m_beatPosition = position;
6 ✔
630

631
    // use the exact (fractional) tempo for the beat duration,
632
    // while the BPM number is just for display and old style users
633
    double beatMs = 60000.0 / tempo;
6 ✔
634
    m_beatTimeDuration = qMax(1, qRound(beatMs));
6 ✔
635

636
    int bpm = qRound(tempo);
6 ✔
637
    if (bpm != m_currentBPM)
6 ✔
638
    {
639
        m_currentBPM = bpm;
2 ✔
640
        emit bpmNumberChanged(bpm);
2 ✔
641
    }
642

643
    // look half a tick ahead, so that a beat is fired on the tick
644
    // closest to it, instead of always on the tick after it
645
    double halfTickBeats = (double(s_tick) / 2.0) / beatMs;
6 ✔
646
    double beatIndex = std::floor(position + halfTickBeats);
6 ✔
647

648
    // a backward jump of the timeline doesn't fire a beat
649
    if (m_timelineBeatValid && beatIndex > m_lastTimelineBeat)
6 ✔
650
    {
651
        m_beatRequested = true;
1 ✔
652
        emit beat();
1 ✔
653
    }
654

655
    m_lastTimelineBeat = beatIndex;
6 ✔
656
    m_timelineBeatValid = true;
6 ✔
657

658
    // time to the beat following the last fired one. timeToNextBeat()
659
    // subtracts the time elapsed from this tick
660
    m_timelineTimeToNextBeat = qRound((beatIndex + 1.0 - position) * beatMs);
6 ✔
661
    m_beatTimer.restart();
6 ✔
662
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc