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

mcallegari / qlcplus / 6683238402

29 Oct 2023 12:10PM UTC coverage: 28.07%. Remained the same
6683238402

push

github

mcallegari
engine: fix build

15385 of 54809 relevant lines covered (28.07%)

20267.63 hits per line

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

0.0
/engine/src/showrunner.cpp
1
/*
2
  Q Light Controller
3
  showrunner.cpp
4

5
  Copyright (c) Massimo Callegari
6

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

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

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

20
#include <QMutex>
21
#include <QDebug>
22

23
#include "showrunner.h"
24
#include "function.h"
25
#include "track.h"
26
#include "show.h"
27

28
#define TIMER_INTERVAL 50
29

30
static bool compareShowFunctions(const ShowFunction *sf1, const ShowFunction *sf2)
×
31
{
32
    if (sf1->startTime() < sf2->startTime())
×
33
        return true;
×
34
    return false;
×
35
}
36

37
ShowRunner::ShowRunner(const Doc* doc, quint32 showID, quint32 startTime)
×
38
    : QObject(NULL)
39
    , m_doc(doc)
40
    , m_elapsedTime(startTime)
41
    , m_totalRunTime(0)
42
    , m_currentFunctionIndex(0)
×
43
{
44
    Q_ASSERT(m_doc != NULL);
×
45
    Q_ASSERT(showID != Show::invalidId());
×
46

47
    m_show = qobject_cast<Show*>(m_doc->function(showID));
×
48
    if (m_show == NULL)
×
49
        return;
×
50

51
    foreach(Track *track, m_show->tracks())
×
52
    {
53
        // some sanity checks
54
        if (track == NULL ||
×
55
            track->id() == Track::invalidId())
×
56
                continue;
×
57

58
        if (track->isMute())
×
59
            continue;
×
60

61
        // get all the functions of the track and append them to the runner queue
62
        foreach(ShowFunction *sfunc, track->showFunctions())
×
63
        {
64
            if (sfunc->startTime() + sfunc->duration(m_doc) <= startTime)
×
65
                continue;
×
66

67
            Function *f = m_doc->function(sfunc->functionID());
×
68
            if (f == NULL)
×
69
                continue;
×
70

71
            m_functions.append(sfunc);
×
72

73
            if (sfunc->startTime() + sfunc->duration(m_doc) > m_totalRunTime)
×
74
                m_totalRunTime = sfunc->startTime() + sfunc->duration(m_doc);
×
75
        }
76

77
        // Initialize the intensity map
78
        m_intensityMap[track->id()] = 1.0;
×
79
    }
80

81
    std::sort(m_functions.begin(), m_functions.end(), compareShowFunctions);
×
82

83
#if 1
84
    qDebug() << "Ordered list of ShowFunctions:";
×
85
    foreach (ShowFunction *sfunc, m_functions)
×
86
        qDebug() << "ID:" << sfunc->functionID() << "st:" << sfunc->startTime() << "dur:" << sfunc->duration(m_doc);
×
87
#endif
88
    m_runningQueue.clear();
×
89

90
    qDebug() << "ShowRunner created";
×
91
}
92

93
ShowRunner::~ShowRunner()
×
94
{
95
}
×
96

97
void ShowRunner::start()
×
98
{
99
    qDebug() << "ShowRunner started";
×
100
}
×
101

102
void ShowRunner::setPause(bool enable)
×
103
{
104
    for (int i = 0; i < m_runningQueue.count(); i++)
×
105
    {
106
        Function *f = m_runningQueue.at(i).first;
×
107
        f->setPause(enable);
×
108
    }
109
}
×
110

111
void ShowRunner::stop()
×
112
{
113
    m_elapsedTime = 0;
×
114
    m_currentFunctionIndex = 0;
×
115
    for (int i = 0; i < m_runningQueue.count(); i++)
×
116
    {
117
        Function *f = m_runningQueue.at(i).first;
×
118
        f->stop(functionParent());
×
119
    }
120

121
    m_runningQueue.clear();
×
122
    qDebug() << "ShowRunner stopped";
×
123
}
×
124

125
FunctionParent ShowRunner::functionParent() const
×
126
{
127
    return FunctionParent(FunctionParent::Function, m_show->id());
×
128
}
129

130
void ShowRunner::write()
×
131
{
132
    //qDebug() << Q_FUNC_INFO << "elapsed:" << m_elapsedTime << ", total:" << m_totalRunTime;
133

134
    // Phase 1. Check all the Functions that need to be started
135
    // m_functions is ordered by startup time, so when we found an entry
136
    // with start time greater than m_elapsed, this phase is over
137
    bool startupDone = false;
×
138

139
    while(startupDone == false)
×
140
    {
141
        if (m_currentFunctionIndex == m_functions.count())
×
142
            break;
×
143

144
        ShowFunction *sf = m_functions.at(m_currentFunctionIndex);
×
145
        quint32 funcStartTime = sf->startTime();
×
146
        quint32 functionTimeOffset = 0;
×
147
        Function *f = m_doc->function(sf->functionID());
×
148

149
        // this should happen only when a Show is not started from 0
150
        if (m_elapsedTime > funcStartTime)
×
151
        {
152
            functionTimeOffset = m_elapsedTime - funcStartTime;
×
153
            funcStartTime = m_elapsedTime;
×
154
        }
155
        if (m_elapsedTime >= funcStartTime)
×
156
        {
157
            foreach (Track *track, m_show->tracks())
×
158
            {
159
                if (track->showFunctions().contains(sf))
×
160
                {
161
                    int intOverrideId = f->requestAttributeOverride(Function::Intensity, m_intensityMap[track->id()]);
×
162
                    //f->adjustAttribute(m_intensityMap[track->id()], Function::Intensity);
163
                    sf->setIntensityOverrideId(intOverrideId);
×
164
                    break;
×
165
                }
166
            }
167

168
            f->start(m_doc->masterTimer(), functionParent(), functionTimeOffset);
×
169
            m_runningQueue.append(QPair<Function *, quint32>(f, sf->startTime() + sf->duration(m_doc)));
×
170
            m_currentFunctionIndex++;
×
171
        }
172
        else
173
            startupDone = true;
×
174
    }
175

176
    // Phase 2. Check if we need to stop some running Functions
177
    // It is done in reverse order for two reasons:
178
    // 1- m_runningQueue is not ordered by stop time
179
    // 2- to avoid messing up with indices when an entry is removed
180
    for(int i = m_runningQueue.count() - 1; i >= 0; i--)
×
181
    {
182
        Function *func = m_runningQueue.at(i).first;
×
183
        quint32 stopTime = m_runningQueue.at(i).second;
×
184

185
        // if we passed the function stop time
186
        if (m_elapsedTime >= stopTime)
×
187
        {
188
            // stop the function
189
            func->stop(functionParent());
×
190
            // remove it from the running queue
191
            m_runningQueue.removeAt(i);
×
192
        }
193
    }
194

195
    // Phase 3. Check if this is the end of the Show
196
    if (m_elapsedTime >= m_totalRunTime)
×
197
    {
198
        if (m_show != NULL)
×
199
            m_show->stop(functionParent());
×
200
        emit showFinished();
×
201
        return;
×
202
    }
203

204
    m_elapsedTime += MasterTimer::tick();
×
205
    emit timeChanged(m_elapsedTime);
×
206
}
207

208
/************************************************************************
209
 * Intensity
210
 ************************************************************************/
211

212
void ShowRunner::adjustIntensity(qreal fraction, Track *track)
×
213
{
214
    if (track == NULL)
×
215
        return;
×
216

217
    qDebug() << Q_FUNC_INFO << "Track ID: " << track->id() << ", val:" << fraction;
×
218
    m_intensityMap[track->id()] = fraction;
×
219

220
    foreach (ShowFunction *sf, track->showFunctions())
×
221
    {
222
        Function *f = m_doc->function(sf->functionID());
×
223
        if (f == NULL)
×
224
            continue;
×
225

226
        for (int i = 0; i < m_runningQueue.count(); i++)
×
227
        {
228
            Function *rf = m_runningQueue.at(i).first;
×
229
            if (f == rf)
×
230
                f->adjustAttribute(fraction, sf->intensityOverrideId());
×
231
        }
232
    }
233
}
234

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc