• 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

67.63
/engine/src/inputoutputmap.cpp
1
/*
2
  Q Light Controller Plus
3
  inputoutputmap.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
#if defined(WIN32) || defined(Q_OS_WIN)
21
#   include <Windows.h>
22
#else
23
#   include <unistd.h>
24
#endif
25

26
#include <QXmlStreamReader>
27
#include <QXmlStreamWriter>
28
#include <QElapsedTimer>
29
#include <QSettings>
30
#include <QDebug>
31
#include <qmath.h>
32

33
#include "inputoutputmap.h"
34
#include "qlcinputchannel.h"
35
#include "qlcinputsource.h"
36
#include "qlclinkservice.h"
37
#include "audiocapture.h"
38
#include "qlcioplugin.h"
39
#include "outputpatch.h"
40
#include "inputpatch.h"
41
#include "qlcconfig.h"
42
#include "universe.h"
43
#include "qlcfile.h"
44
#include "doc.h"
45

46
InputOutputMap::InputOutputMap(const Doc *doc, quint32 universes)
266 ✔
47
    : QObject(NULL)
48
    , m_doc(doc)
266 ✔
49
    , m_blackout(false)
266 ✔
50
    , m_universeChanged(false)
266 ✔
51
    , m_localProfilesLoaded(false)
266 ✔
52
    , m_currentBPM(0)
266 ✔
53
    , m_beatTime(new QElapsedTimer())
266 ✔
54
    , m_link(NULL)
266 ✔
55
    , m_linkPlaying(false)
266 ✔
56
    , m_linkPlayingValid(false)
266 ✔
57
    , m_networkServerType(NativeServer)
266 ✔
58
    , m_networkServerAutoStart(false)
532 ✔
59
{
60
    m_grandMaster = new GrandMaster(this);
266 ✔
61
    for (quint32 i = 0; i < universes; i++)
1,323 ✔
62
        addUniverse();
1,057 ✔
63

64
    connect(doc->ioPluginCache(), SIGNAL(pluginConfigurationChanged(QLCIOPlugin*)),
266 ✔
65
            this, SLOT(slotPluginConfigurationChanged(QLCIOPlugin*)));
66
    connect(doc->masterTimer(), SIGNAL(beat()), this, SLOT(slotMasterTimerBeat()));
266 ✔
67
    connect(doc->masterTimer(), SIGNAL(bpmNumberChanged(int)), this, SLOT(slotMasterTimerBpmChanged(int)));
266 ✔
68
}
266 ✔
69

70
InputOutputMap::~InputOutputMap()
508 ✔
71
{
72
    removeAllUniverses();
266 ✔
73
    delete m_grandMaster;
266 ✔
74
    delete m_beatTime;
266 ✔
75
    qDeleteAll(m_profiles);
266 ✔
76
}
508 ✔
77

78
/*****************************************************************************
79
 * Blackout
80
 *****************************************************************************/
81

82
bool InputOutputMap::toggleBlackout()
4 ✔
83
{
84
    if (m_blackout == true)
4 ✔
85
        setBlackout(false);
2 ✔
86
    else
87
        setBlackout(true);
2 ✔
88

89
    return m_blackout;
4 ✔
90
}
91

92
bool InputOutputMap::setBlackout(bool blackout)
7 ✔
93
{
94
    /* Don't do blackout twice */
95
    if (m_blackout == blackout)
7 ✔
96
        return false;
2 ✔
97

98
    m_blackout = blackout;
5 ✔
99

100
    // blackout is an atomic setting, so it's safe to do it
101
    // without mutex locking
102
    foreach (Universe *universe, m_universeArray)
25 ✔
103
    {
104
        for (int i = 0; i < universe->outputPatchesCount(); i++)
32 ✔
105
        {
106
            OutputPatch *op = universe->outputPatch(i);
12 ✔
107
            if (op != NULL)
12 ✔
108
                op->setBlackout(blackout);
12 ✔
109
        }
110

111
        const QByteArray postGM = universe->postGMValues()->mid(0, universe->usedChannels());
20 ✔
112
        universe->dumpOutput(postGM, true);
20 ✔
113
    }
25 ✔
114

115
    emit blackoutChanged(m_blackout);
5 ✔
116

117
    return true;
5 ✔
118
}
119

120
void InputOutputMap::requestBlackout(BlackoutRequest blackout)
×
121
{
122
    if (blackout != BlackoutRequestNone)
×
123
        setBlackout(blackout == BlackoutRequestOn ? true : false);
×
124
}
×
125

126
bool InputOutputMap::blackout() const
8 ✔
127
{
128
    return m_blackout;
8 ✔
129
}
130

131
/*****************************************************************************
132
 * Universes
133
 *****************************************************************************/
134

135
quint32 InputOutputMap::invalidUniverse()
2,134 ✔
136
{
137
    return UINT_MAX;
2,134 ✔
138
}
139

140
bool InputOutputMap::addUniverse(quint32 id)
1,061 ✔
141
{
142
    {
143
        QMutexLocker locker(&m_universeMutex);
1,061 ✔
144
        Universe *uni = NULL;
1,061 ✔
145

146
        if (id == InputOutputMap::invalidUniverse())
1,061 ✔
147
        {
148
            id = universesCount();
1,058 ✔
149
        }
150
        else if (id < universesCount())
3 ✔
151
        {
152
            qWarning() << Q_FUNC_INFO
2 ✔
153
                << "Universe" << id << "is already present in the list."
1 ✔
154
                << "The universe list may be unsorted.";
1 ✔
155
            return false;
1 ✔
156
        }
157
        else if (id > universesCount())
2 ✔
158
        {
159
            qDebug() << Q_FUNC_INFO
2 ✔
160
                << "Gap between universe" << (universesCount() - 1)
1 ✔
161
                << "and universe" << id << ", filling the gap...";
1 ✔
162
            while (id > universesCount())
4 ✔
163
            {
164
                uni = new Universe(universesCount(), m_grandMaster);
3 ✔
165
                connect(m_doc->masterTimer(), SIGNAL(tickReady()), uni, SLOT(tick()), Qt::QueuedConnection);
3 ✔
166
                connect(uni, SIGNAL(universeWritten(quint32,QByteArray)), this, SIGNAL(universeWritten(quint32,QByteArray)));
3 ✔
167
                m_universeArray.append(uni);
3 ✔
168
            }
169
        }
170

171
        uni = new Universe(id, m_grandMaster);
1,060 ✔
172
        connect(m_doc->masterTimer(), SIGNAL(tickReady()), uni, SLOT(tick()), Qt::QueuedConnection);
1,060 ✔
173
        connect(uni, SIGNAL(universeWritten(quint32,QByteArray)), this, SIGNAL(universeWritten(quint32,QByteArray)));
1,060 ✔
174
        m_universeArray.append(uni);
1,060 ✔
175
    }
1,061 ✔
176

177
    emit universeAdded(id);
1,060 ✔
178
    return true;
1,060 ✔
179
}
180

181
bool InputOutputMap::removeUniverse(int index)
3 ✔
182
{
183
    {
184
        QMutexLocker locker(&m_universeMutex);
3 ✔
185

186
        if (index < 0 || index >= m_universeArray.count())
3 ✔
187
            return false;
1 ✔
188

189
        if (index != (m_universeArray.size() - 1))
2 ✔
190
        {
191
            qWarning() << Q_FUNC_INFO << "Removing universe" << index
2 ✔
192
                << "would create a gap in the universe list, cancelling";
1 ✔
193
            return false;
1 ✔
194
        }
195

196
        delete  m_universeArray.takeAt(index);
1 ✔
197
    }
3 ✔
198

199
    emit universeRemoved(index);
1 ✔
200
    return true;
1 ✔
201
}
202

203
bool InputOutputMap::removeAllUniverses()
269 ✔
204
{
205
    QMutexLocker locker(&m_universeMutex);
269 ✔
206
    qDeleteAll(m_universeArray);
269 ✔
207
    m_universeArray.clear();
269 ✔
208
    return true;
269 ✔
209
}
269 ✔
210

211
void InputOutputMap::startUniverses()
1 ✔
212
{
213
    foreach (Universe *uni, m_universeArray)
6 ✔
214
        uni->start();
6 ✔
215
}
1 ✔
216

217
quint32 InputOutputMap::getUniverseID(int index) const
2 ✔
218
{
219
    if (index >= 0 && index < m_universeArray.count())
2 ✔
220
        return index;
1 ✔
221

222
    return invalidUniverse();
1 ✔
223
}
224

225
QString InputOutputMap::getUniverseNameByIndex(int index) const
4 ✔
226
{
227
    if (index >= 0 && index < m_universeArray.count())
4 ✔
228
        return m_universeArray.at(index)->name();
3 ✔
229

230
    return QString();
1 ✔
231
}
232

233
QString InputOutputMap::getUniverseNameByID(quint32 id) const
1 ✔
234
{
235
    return getUniverseNameByIndex(id);
1 ✔
236
}
237

238
void InputOutputMap::setUniverseName(int index, QString name)
2 ✔
239
{
240
    if (index < 0 || index >= m_universeArray.count())
2 ✔
241
        return;
1 ✔
242
    m_universeArray.at(index)->setName(name);
1 ✔
243
}
244

245
void InputOutputMap::setUniversePassthrough(int index, bool enable)
2 ✔
246
{
247
    if (index < 0 || index >= m_universeArray.count())
2 ✔
248
        return;
1 ✔
249
    m_universeArray.at(index)->setPassthrough(enable);
1 ✔
250
}
251

252
bool InputOutputMap::getUniversePassthrough(int index) const
2 ✔
253
{
254
    if (index < 0 || index >= m_universeArray.count())
2 ✔
255
        return false;
1 ✔
256
    return m_universeArray.at(index)->passthrough();
1 ✔
257
}
258

259
void InputOutputMap::setUniverseMonitor(int index, bool enable)
2 ✔
260
{
261
    if (index < 0 || index >= m_universeArray.count())
2 ✔
262
        return;
1 ✔
263
    m_universeArray.at(index)->setMonitor(enable);
1 ✔
264
}
265

266
bool InputOutputMap::getUniverseMonitor(int index) const
2 ✔
267
{
268
    if (index < 0 || index >= m_universeArray.count())
2 ✔
269
        return false;
1 ✔
270
    return m_universeArray.at(index)->monitor();
1 ✔
271
}
272

273
bool InputOutputMap::isUniversePatched(int index) const
3 ✔
274
{
275
    if (index < 0 || index >= m_universeArray.count())
3 ✔
276
        return false;
1 ✔
277

278
    return m_universeArray.at(index)->isPatched();
2 ✔
279
}
280

281
quint32 InputOutputMap::universesCount() const
1,799 ✔
282
{
283
    return (quint32)m_universeArray.count();
1,799 ✔
284
}
285

286
QList<Universe *> InputOutputMap::universes() const
30 ✔
287
{
288
    return m_universeArray;
30 ✔
289
}
290

291
Universe *InputOutputMap::universe(quint32 id) const
×
292
{
293
    for (int i = 0; i < m_universeArray.size(); i++)
×
294
        if (m_universeArray.at(i)->id() == id)
×
295
            return m_universeArray.at(i);
×
296

297
    return NULL;
×
298
}
299

300
QList<Universe*> InputOutputMap::claimUniverses()
1,115 ✔
301
{
302
    m_universeMutex.lock();
1,115 ✔
303
    return m_universeArray;
1,115 ✔
304
}
305

306
void InputOutputMap::releaseUniverses(bool changed)
1,115 ✔
307
{
308
    m_universeChanged = changed;
1,115 ✔
309
    m_universeMutex.unlock();
1,115 ✔
310
}
1,115 ✔
311

312
void InputOutputMap::resetUniverses()
1 ✔
313
{
314
    {
315
        QMutexLocker locker(&m_universeMutex);
1 ✔
316
        for (int i = 0; i < m_universeArray.size(); i++)
5 ✔
317
            m_universeArray.at(i)->reset();
4 ✔
318
    }
1 ✔
319

320
    /* Reset Grand Master parameters */
321
    setGrandMasterValue(255);
1 ✔
322
    setGrandMasterValueMode(GrandMaster::Reduce);
1 ✔
323
    setGrandMasterChannelMode(GrandMaster::Intensity);
1 ✔
324

325
    m_localProfilesLoaded = false;
1 ✔
326
}
1 ✔
327

328
/*********************************************************************
329
 * Grand Master
330
 *********************************************************************/
331

332
void InputOutputMap::setGrandMasterChannelMode(GrandMaster::ChannelMode mode)
4 ✔
333
{
334
    Q_ASSERT(m_grandMaster != NULL);
4 ✔
335

336
    if (m_grandMaster->channelMode() != mode)
4 ✔
337
    {
338
        m_grandMaster->setChannelMode(mode);
3 ✔
339
        m_universeChanged = true;
3 ✔
340
    }
341
}
4 ✔
342

343
GrandMaster::ChannelMode InputOutputMap::grandMasterChannelMode() const
6 ✔
344
{
345
    Q_ASSERT(m_grandMaster != NULL);
6 ✔
346

347
    return m_grandMaster->channelMode();
6 ✔
348
}
349

350
void InputOutputMap::setGrandMasterValueMode(GrandMaster::ValueMode mode)
4 ✔
351
{
352
    Q_ASSERT(m_grandMaster != NULL);
4 ✔
353

354
    if (m_grandMaster->valueMode() != mode)
4 ✔
355
    {
356
        m_grandMaster->setValueMode(mode);
3 ✔
357
        m_universeChanged = true;
3 ✔
358
    }
359

360
    emit grandMasterValueModeChanged(mode);
4 ✔
361
}
4 ✔
362

363
GrandMaster::ValueMode InputOutputMap::grandMasterValueMode() const
7 ✔
364
{
365
    Q_ASSERT(m_grandMaster != NULL);
7 ✔
366

367
    return m_grandMaster->valueMode();
7 ✔
368
}
369

370
void InputOutputMap::setGrandMasterValue(uchar value)
5 ✔
371
{
372
    Q_ASSERT(m_grandMaster != NULL);
5 ✔
373

374
    if (m_grandMaster->value() != value)
5 ✔
375
    {
376
        m_grandMaster->setValue(value);
2 ✔
377
        m_universeChanged = true;
2 ✔
378
    }
379

380
    if (m_universeChanged == true)
5 ✔
381
        emit grandMasterValueChanged(value);
3 ✔
382
}
5 ✔
383

384
uchar InputOutputMap::grandMasterValue() const
4 ✔
385
{
386
    Q_ASSERT(m_grandMaster != NULL);
4 ✔
387

388
    return m_grandMaster->value();
4 ✔
389
}
390

391
/*********************************************************************
392
 * Patch
393
 *********************************************************************/
394

395
void InputOutputMap::flushInputs()
5 ✔
396
{
397
    QMutexLocker locker(&m_universeMutex);
5 ✔
398
    foreach (Universe *universe, m_universeArray)
25 ✔
399
        universe->flushInput();
25 ✔
400
}
5 ✔
401

402
bool InputOutputMap::setInputPatch(quint32 universe, const QString &pluginName,
7 ✔
403
                                   const QString &inputUID, const QString &inputName,
404
                                   quint32 input, const QString &profileName)
405
{
406
    /* Check that the universe that we're doing mapping for is valid */
407
    if (universe >= universesCount())
7 ✔
408
    {
409
        qWarning() << Q_FUNC_INFO << "Universe" << universe << "out of bounds.";
1 ✔
410
        return false;
1 ✔
411
    }
412

413
    QMutexLocker locker(&m_universeMutex);
6 ✔
414
    InputPatch *currInPatch = m_universeArray.at(universe)->inputPatch();
6 ✔
415
    QLCInputProfile *currProfile = NULL;
6 ✔
416
    if (currInPatch != NULL)
6 ✔
417
    {
418
        currProfile = currInPatch->profile();
1 ✔
419
        disconnect(currInPatch, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)),
1 ✔
420
                this, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)));
421
        if (currInPatch->plugin()->capabilities() & QLCIOPlugin::Beats)
1 ✔
422
        {
423
            disconnect(currInPatch, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)),
×
424
                       this, SLOT(slotPluginBeat(quint32,quint32,uchar,const QString&)));
425
        }
426
    }
427
    InputPatch *ip = NULL;
6 ✔
428
    QLCIOPlugin *plugin = m_doc->ioPluginCache()->plugin(pluginName);
6 ✔
429

430
    if (plugin != NULL)
6 ✔
431
    {
432
        int lIdx = -1;
5 ✔
433
        // 1. Match by stable UID
434
        if (!inputUID.isEmpty())
5 ✔
435
            lIdx = plugin->inputsUID().indexOf(inputUID);
×
436
        // 2. Match by display name
437
        if (lIdx == -1 && !inputName.isEmpty())
5 ✔
438
            lIdx = plugin->inputs().indexOf(inputName);
5 ✔
439
        // 3. Fall back to saved line number
440
        if (lIdx != -1)
5 ✔
441
        {
442
            qDebug() << "[IOMAP] Found match on input on universe" << universe << "line" << lIdx;
5 ✔
443
            input = lIdx;
5 ✔
444
        }
445
        else
446
        {
447
            qDebug() << "[IOMAP] !!No match found!! for input on universe" << universe << "uid:" << inputUID << "name:" << inputName;
×
448
        }
449
    }
450

451
    if (m_universeArray.at(universe)->setInputPatch(
6 ✔
452
                plugin, input, profile(profileName)) == true)
6 ✔
453
    {
454
        ip = m_universeArray.at(universe)->inputPatch();
6 ✔
455
        if (ip != NULL)
6 ✔
456
        {
457
            connect(ip, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)),
5 ✔
458
                    this, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)));
459
            if (ip->plugin()->capabilities() & QLCIOPlugin::Beats)
5 ✔
460
            {
461
                connect(ip, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)),
×
462
                        this, SLOT(slotPluginBeat(quint32,quint32,uchar,const QString&)));
463
            }
464
        }
465
    }
466
    else
467
    {
468
        return false;
×
469
    }
470

471
    if (ip != NULL && currProfile != ip->profile())
6 ✔
472
        emit profileChanged(universe, ip->profileName());
3 ✔
473

474
    return true;
6 ✔
475
}
6 ✔
476

477
bool InputOutputMap::setInputProfile(quint32 universe, const QString &profileName)
×
478
{
479
    /* Check that the universe that we're doing mapping for is valid */
480
    if (universe >= universesCount())
×
481
    {
482
        qWarning() << Q_FUNC_INFO << "Universe" << universe << "out of bounds.";
×
483
        return false;
×
484
    }
485

486
    InputPatch *currInPatch = m_universeArray.at(universe)->inputPatch();
×
487
    if (currInPatch != NULL)
×
488
        currInPatch->set(profile(profileName));
×
489

490
    /* if no input patch is set, then setting a profile is useless,
491
       but there's no reason to cause an error here */
492
    return true;
×
493
}
494

495
bool InputOutputMap::setOutputPatch(quint32 universe, const QString &pluginName,
21 ✔
496
                                    const QString &outputUID, const QString &outputName,
497
                                    quint32 output, bool isFeedback, int index)
498
{
499
    /* Check that the universe that we're doing mapping for is valid */
500
    if (universe >= universesCount())
21 ✔
501
    {
502
        qWarning() << Q_FUNC_INFO << "Universe" << universe << "out of bounds.";
2 ✔
503
        return false;
2 ✔
504
    }
505

506
    QMutexLocker locker(&m_universeMutex);
19 ✔
507
    QLCIOPlugin *plugin = m_doc->ioPluginCache()->plugin(pluginName);
19 ✔
508

509
    if (plugin != NULL)
19 ✔
510
    {
511
        int lIdx = -1;
18 ✔
512
        // 1. Match by stable UID
513
        if (!outputUID.isEmpty())
18 ✔
514
            lIdx = plugin->outputsUID().indexOf(outputUID);
×
515
        // 2. Match by display name
516
        if (lIdx == -1 && !outputName.isEmpty())
18 ✔
517
            lIdx = plugin->outputs().indexOf(outputName);
12 ✔
518
        // 3. Fall back to saved line number
519
        if (lIdx != -1)
18 ✔
520
        {
521
            qDebug() << "[IOMAP] Found match on output on universe" << universe << "line" << lIdx;
12 ✔
522
            output = lIdx;
12 ✔
523
        }
524
        else
525
        {
526
            qDebug() << "[IOMAP] !!No match found!! for output on universe" << universe << "uid:" << outputUID << "name:" << outputName;
6 ✔
527
        }
528
    }
529

530
    if (isFeedback == false)
19 ✔
531
        return m_universeArray.at(universe)->setOutputPatch(plugin, output, index);
19 ✔
532
    else
533
        return m_universeArray.at(universe)->setFeedbackPatch(plugin, output);
×
534

535
    return false;
536
}
19 ✔
537

538
int InputOutputMap::outputPatchesCount(quint32 universe) const
4 ✔
539
{
540
    if (universe >= universesCount())
4 ✔
541
    {
542
        qWarning() << Q_FUNC_INFO << "Universe" << universe << "out of bounds.";
×
543
        return 0;
×
544
    }
545

546
    return m_universeArray.at(universe)->outputPatchesCount();
4 ✔
547
}
548

549
InputPatch *InputOutputMap::inputPatch(quint32 universe) const
52 ✔
550
{
551
    if (universe >= universesCount())
52 ✔
552
    {
553
        qWarning() << Q_FUNC_INFO << "Universe" << universe << "out of bounds.";
×
554
        return NULL;
×
555
    }
556
    return m_universeArray.at(universe)->inputPatch();
52 ✔
557
}
558

559
OutputPatch *InputOutputMap::outputPatch(quint32 universe, int index) const
27 ✔
560
{
561
    if (universe >= universesCount())
27 ✔
562
    {
563
        qWarning() << Q_FUNC_INFO << "Universe" << universe << "out of bounds.";
×
564
        return NULL;
×
565
    }
566
    return m_universeArray.at(universe)->outputPatch(index);
27 ✔
567
}
568

569
OutputPatch *InputOutputMap::feedbackPatch(quint32 universe) const
2 ✔
570
{
571
    if (universe >= universesCount())
2 ✔
572
    {
573
        qWarning() << Q_FUNC_INFO << "Universe" << universe << "out of bounds.";
1 ✔
574
        return NULL;
1 ✔
575
    }
576
    return m_universeArray.at(universe)->feedbackPatch();
1 ✔
577
}
578

579
QStringList InputOutputMap::universeNames() const
16 ✔
580
{
581
    QStringList list;
16 ✔
582
    for (quint32 i = 0; i < universesCount(); i++)
80 ✔
583
        list << m_universeArray.at(i)->name();
64 ✔
584

585
    return list;
16 ✔
586
}
×
587

588
quint32 InputOutputMap::inputMapping(const QString &pluginName, quint32 input) const
16 ✔
589
{
590
    for (quint32 uni = 0; uni < universesCount(); uni++)
70 ✔
591
    {
592
        const InputPatch* p = m_universeArray.at(uni)->inputPatch();
57 ✔
593
        if (p != NULL && p->pluginName() == pluginName && p->input() == input)
57 ✔
594
            return uni;
3 ✔
595
    }
596

597
    return QLCIOPlugin::invalidLine();
13 ✔
598
}
599

600
quint32 InputOutputMap::outputMapping(const QString &pluginName, quint32 output) const
2 ✔
601
{
602
    for (quint32 uni = 0; uni < universesCount(); uni++)
9 ✔
603
    {
604
        Universe *universe = m_universeArray.at(uni);
8 ✔
605
        for (int i = 0; i < universe->outputPatchesCount(); i++)
15 ✔
606
        {
607
            const OutputPatch* p = universe->outputPatch(i);
8 ✔
608
            if (p != NULL && p->pluginName() == pluginName && p->output() == output)
8 ✔
609
                return uni;
1 ✔
610
        }
611
    }
612

613
    return QLCIOPlugin::invalidLine();
1 ✔
614
}
615

616
/*****************************************************************************
617
 * Plugins
618
 *****************************************************************************/
619

620
QString InputOutputMap::pluginDescription(const QString &pluginName) const
2 ✔
621
{
622
    QLCIOPlugin* plugin = NULL;
2 ✔
623

624
    if (pluginName.isEmpty() == false)
2 ✔
625
        plugin = m_doc->ioPluginCache()->plugin(pluginName);
2 ✔
626

627
    if (plugin != NULL)
2 ✔
628
    {
629
        return plugin->pluginInfo();
1 ✔
630
    }
631
    else
632
        return "";
1 ✔
633
}
634

635
void InputOutputMap::removeDuplicates(QStringList &list) const
3 ✔
636
{
637
    if (list.count() == 1)
3 ✔
638
        return;
×
639

640
    int c = 2;
3 ✔
641

642
    for (int i = 1; i < list.count(); i++)
12 ✔
643
    {
644
        for (int j = 0; j < i; j++)
27 ✔
645
        {
646
            if (list.at(i) == list.at(j))
18 ✔
647
            {
648
                list.replace(i, QString("%1 %2").arg(list.at(j)).arg(c));
×
649
                c++;
×
650
            }
651
        }
652
    }
653
}
654

655
QStringList InputOutputMap::inputPluginNames() const
2 ✔
656
{
657
    QStringList list;
2 ✔
658
    QListIterator <QLCIOPlugin*> it(m_doc->ioPluginCache()->plugins());
2 ✔
659
    while (it.hasNext() == true)
4 ✔
660
    {
661
        QLCIOPlugin* plg(it.next());
2 ✔
662
        if (plg->capabilities() & QLCIOPlugin::Input)
2 ✔
663
            list << plg->name();
2 ✔
664
    }
665
    return list;
4 ✔
666
}
2 ✔
667

668
QStringList InputOutputMap::outputPluginNames() const
2 ✔
669
{
670
    QStringList list;
2 ✔
671
    QListIterator <QLCIOPlugin*> it(m_doc->ioPluginCache()->plugins());
2 ✔
672
    while (it.hasNext() == true)
4 ✔
673
    {
674
        QLCIOPlugin* plg(it.next());
2 ✔
675
        if (plg->capabilities() & QLCIOPlugin::Output)
2 ✔
676
            list << plg->name();
2 ✔
677
    }
678
    return list;
4 ✔
679
}
2 ✔
680

681
QStringList InputOutputMap::pluginInputs(const QString& pluginName) const
3 ✔
682
{
683
    QLCIOPlugin* ip = m_doc->ioPluginCache()->plugin(pluginName);
3 ✔
684
    if (ip == NULL)
3 ✔
685
        return QStringList();
1 ✔
686
    else
687
    {
688
        QStringList iList = ip->inputs();
2 ✔
689
        removeDuplicates(iList);
2 ✔
690
        return iList;
2 ✔
691
    }
2 ✔
692
}
693

694
QStringList InputOutputMap::pluginOutputs(const QString& pluginName) const
2 ✔
695
{
696
    QLCIOPlugin* op = m_doc->ioPluginCache()->plugin(pluginName);
2 ✔
697
    if (op == NULL)
2 ✔
698
        return QStringList();
1 ✔
699
    else
700
    {
701
        QStringList oList = op->outputs();
1 ✔
702
        removeDuplicates(oList);
1 ✔
703
        return oList;
1 ✔
704
    }
1 ✔
705
}
706

707
bool InputOutputMap::pluginSupportsFeedback(const QString& pluginName) const
1 ✔
708
{
709
    QLCIOPlugin* outputPlugin = m_doc->ioPluginCache()->plugin(pluginName);
1 ✔
710
    if (outputPlugin != NULL)
1 ✔
711
        return (outputPlugin->capabilities() & QLCIOPlugin::Feedback) > 0;
1 ✔
712
    else
713
        return false;
×
714
}
715

716
void InputOutputMap::configurePlugin(const QString& pluginName)
3 ✔
717
{
718
    QLCIOPlugin* outputPlugin = m_doc->ioPluginCache()->plugin(pluginName);
3 ✔
719
    if (outputPlugin != NULL)
3 ✔
720
        outputPlugin->configure();
3 ✔
721
}
3 ✔
722

723
bool InputOutputMap::canConfigurePlugin(const QString& pluginName) const
4 ✔
724
{
725
    QLCIOPlugin* outputPlugin = m_doc->ioPluginCache()->plugin(pluginName);
4 ✔
726
    if (outputPlugin != NULL)
4 ✔
727
        return outputPlugin->canConfigure();
2 ✔
728
    else
729
        return false;
2 ✔
730
}
731

732
QString InputOutputMap::inputPluginStatus(const QString& pluginName, quint32 input) const
9 ✔
733
{
734
    QLCIOPlugin* inputPlugin = NULL;
9 ✔
735
    QString info;
9 ✔
736

737
    if (pluginName.isEmpty() == false)
9 ✔
738
        inputPlugin = m_doc->ioPluginCache()->plugin(pluginName);
9 ✔
739

740
    if (inputPlugin != NULL)
9 ✔
741
    {
742
        info = inputPlugin->inputInfo(input);
4 ✔
743
    }
744
    else
745
    {
746
        /* Nothing selected */
747
        info += QString("<HTML><HEAD></HEAD><BODY>");
5 ✔
748
        info += QString("<H3>%1</H3>").arg(tr("Nothing selected"));
5 ✔
749
        info += QString("</BODY></HTML>");
5 ✔
750
    }
751

752
    return info;
9 ✔
753
}
×
754

755
QString InputOutputMap::outputPluginStatus(const QString& pluginName, quint32 output) const
9 ✔
756
{
757
    QLCIOPlugin* outputPlugin = m_doc->ioPluginCache()->plugin(pluginName);
9 ✔
758
    if (outputPlugin != NULL)
9 ✔
759
    {
760
        return outputPlugin->outputInfo(output);
4 ✔
761
    }
762
    else
763
    {
764
        QString info;
5 ✔
765
        info += QString("<HTML><HEAD></HEAD><BODY>");
5 ✔
766
        info += QString("<H3>%1</H3>").arg(tr("Nothing selected"));
5 ✔
767
        info += QString("</BODY></HTML>");
5 ✔
768
        return info;
5 ✔
769
    }
5 ✔
770
}
771

772
bool InputOutputMap::sendFeedBack(quint32 universe, quint32 channel, uchar value, const QVariant &params)
3 ✔
773
{
774
    if (universe >= universesCount())
3 ✔
775
        return false;
×
776

777
    OutputPatch* patch = m_universeArray.at(universe)->feedbackPatch();
3 ✔
778

779
    if (patch != NULL && patch->isPatched())
3 ✔
780
    {
781
        patch->plugin()->sendFeedBack(universe, patch->output(), channel, value, params);
×
782
        return true;
×
783
    }
784
    else
785
    {
786
        return false;
3 ✔
787
    }
788
}
789

790
void InputOutputMap::slotPluginConfigurationChanged(QLCIOPlugin* plugin)
8 ✔
791
{
792
    QMutexLocker locker(&m_universeMutex);
8 ✔
793
    bool success = true;
8 ✔
794
    for (quint32 i = 0; i < universesCount(); i++)
40 ✔
795
    {
796
        Universe *universe = m_universeArray.at(i);
32 ✔
797
        for (int oi = 0; oi < universe->outputPatchesCount(); oi++)
32 ✔
798
        {
799
            OutputPatch* op = universe->outputPatch(oi);
×
800

801
            if (op != NULL && op->plugin() == plugin)
×
802
            {
803
                /*success = */ op->reconnect();
×
804
            }
805
        }
806

807
        InputPatch* ip = m_universeArray.at(i)->inputPatch();
32 ✔
808

809
        if (ip != NULL && ip->plugin() == plugin)
32 ✔
810
        {
811
            /*success = */ ip->reconnect();
×
812
        }
813

814
        OutputPatch* fp = m_universeArray.at(i)->feedbackPatch();
32 ✔
815
        if (fp != NULL && fp->plugin() == plugin)
32 ✔
816
        {
817
            /*success = */ fp->reconnect();
×
818
        }
819
    }
820
    locker.unlock();
8 ✔
821

822
    emit pluginConfigurationChanged(plugin->name(), success);
8 ✔
823
}
8 ✔
824

825
/*****************************************************************************
826
 * Profiles
827
 *****************************************************************************/
828

829
void InputOutputMap::loadProfiles(const QDir& dir)
5 ✔
830
{
831
    if (dir.exists() == false || dir.isReadable() == false)
5 ✔
832
        return;
1 ✔
833

834
    /* Go thru all found file entries and attempt to load an input
835
       profile from each of them. */
836
    QStringListIterator it(dir.entryList());
4 ✔
837
    while (it.hasNext() == true)
127 ✔
838
    {
839
        QLCInputProfile* prof;
840
        QString path;
123 ✔
841

842
        path = dir.absoluteFilePath(it.next());
123 ✔
843
        prof = QLCInputProfile::loader(path);
123 ✔
844
        if (prof != NULL)
123 ✔
845
        {
846
            /* Check for duplicates */
847
            if (profile(prof->name()) == NULL)
123 ✔
848
                addProfile(prof);
82 ✔
849
            else
850
                delete prof;
41 ✔
851
        }
852
        else
853
        {
854
            qWarning() << Q_FUNC_INFO << "Unable to find an input profile from" << path;
×
855
        }
856
    }
123 ✔
857
}
4 ✔
858

859
QStringList InputOutputMap::profileNames() const
7 ✔
860
{
861
    QStringList list;
7 ✔
862
    QListIterator <QLCInputProfile*> it(m_profiles);
7 ✔
863
    while (it.hasNext() == true)
91 ✔
864
        list << it.next()->name();
84 ✔
865
    return list;
14 ✔
866
}
7 ✔
867

868
QLCInputProfile* InputOutputMap::profile(const QString& name)
131 ✔
869
{
870
    QListIterator <QLCInputProfile*> it(m_profiles);
131 ✔
871
    while (it.hasNext() == true)
2,649 ✔
872
    {
873
        QLCInputProfile *profile = it.next();
2,563 ✔
874
        if (profile->name() == name)
2,563 ✔
875
            return profile;
45 ✔
876
    }
877

878
    // Attempt to load input profile
879
    // from the workspace folder
880
    if (m_localProfilesLoaded == false)
86 ✔
881
    {
882
        if (m_doc->workspacePath().isEmpty())
86 ✔
883
            return NULL;
86 ✔
884

885
        m_localProfilesLoaded = true;
×
886

887
        qDebug() << "Input profile" << name << "not found. Attempt to load it from" << m_doc->workspacePath();
×
888
        QDir localDir(m_doc->workspacePath());
×
889
        localDir.setFilter(QDir::Files);
×
890
        localDir.setNameFilters(QStringList() << QString("*%1").arg(KExtInputProfile));
×
891
        loadProfiles(localDir);
×
892

893
        QListIterator <QLCInputProfile*> it(m_profiles);
×
894
        while (it.hasNext() == true)
×
895
        {
896
            QLCInputProfile *profile = it.next();
×
897
            if (profile->name() == name)
×
898
                return profile;
×
899
        }
900
    }
×
901

902
    return NULL;
×
903
}
131 ✔
904

905
bool InputOutputMap::addProfile(QLCInputProfile* profile)
85 ✔
906
{
907
    Q_ASSERT(profile != NULL);
85 ✔
908

909
    /* Don't add the same profile twice */
910
    if (m_profiles.contains(profile) == false)
85 ✔
911
    {
912
        m_profiles.append(profile);
84 ✔
913
        return true;
84 ✔
914
    }
915
    else
916
    {
917
        return false;
1 ✔
918
    }
919
}
920

921
bool InputOutputMap::removeProfile(const QString& name)
2 ✔
922
{
923
    QMutableListIterator <QLCInputProfile*> it(m_profiles);
2 ✔
924
    while (it.hasNext() == true)
3 ✔
925
    {
926
        QLCInputProfile *profile = it.next();
2 ✔
927
        if (profile->name() == name)
2 ✔
928
        {
929
            it.remove();
1 ✔
930
            delete profile;
1 ✔
931
            return true;
1 ✔
932
        }
933
    }
934

935
    return false;
1 ✔
936
}
937

938
bool InputOutputMap::inputSourceNames(const QLCInputSource *src,
9 ✔
939
                                QString& uniName, QString& chName) const
940
{
941
    if (src == NULL || src->isValid() == false)
9 ✔
942
        return false;
3 ✔
943

944
    if (src->universe() >= universesCount())
6 ✔
945
        return false;
1 ✔
946

947
    InputPatch* pat = m_universeArray.at(src->universe())->inputPatch();
5 ✔
948
    if (pat == NULL)
5 ✔
949
    {
950
        /* There is no patch for the given universe */
951
        uniName = QString("%1 -UNPATCHED-").arg(src->universe() + 1);
2 ✔
952

953
        ushort page = src->page();
2 ✔
954
        ushort channel = (src->channel() & 0x0000FFFF) + 1;
2 ✔
955

956
        if (page != 0)
2 ✔
957
            chName = QString("%1: ? (Page %2)").arg(channel).arg(page + 1);
×
958
        else
959
            chName = QString("%1: ?").arg(channel);
2 ✔
960
        return true;
2 ✔
961
    }
962

963
    QLCInputProfile* profile = pat->profile();
3 ✔
964
    if (profile == NULL)
3 ✔
965
    {
966
        /* There is no profile. Display plugin name and channel number. */
967
        if (pat->plugin() != NULL)
1 ✔
968
            uniName = QString("%1: %2").arg(src->universe() + 1).arg(pat->plugin()->name());
1 ✔
969
        else
970
            uniName = QString("%1: ??").arg(src->universe() + 1);
×
971

972
        ushort page = src->page();
1 ✔
973
        ushort channel = (src->channel() & 0x0000FFFF) + 1;
1 ✔
974

975
        if (page != 0)
1 ✔
976
            chName = QString("%1: ? (Page %2)").arg(channel).arg(page + 1);
×
977
        else
978
            chName = QString("%1: ?").arg(channel);
1 ✔
979
    }
980
    else
981
    {
982
        QLCInputChannel* ich;
983
        QString name;
2 ✔
984

985
        /* Display profile name for universe */
986
        uniName = QString("%1: %2").arg(src->universe() + 1).arg(profile->name());
2 ✔
987

988
        /* User can input the channel number by hand, so put something
989
           rational to the channel name in those cases as well. */
990
        ushort page = src->page();
2 ✔
991
        ushort channel = (src->channel() & 0x0000FFFF);
2 ✔
992

993
        ich = profile->channel(channel);
2 ✔
994
        if (ich != NULL)
2 ✔
995
            name = ich->name();
1 ✔
996
        else
997
            name = QString("?");
1 ✔
998

999
        /* Display channel name */
1000
        if (page != 0)
2 ✔
1001
            chName = QString("%1: %2 (Page %3)").arg(channel + 1).arg(name).arg(page + 1);
×
1002
        else
1003
            chName = QString("%1: %2").arg(channel + 1).arg(name);
2 ✔
1004
    }
2 ✔
1005

1006
    return true;
3 ✔
1007
}
1008

1009
bool InputOutputMap::inputSourceNames(QSharedPointer<QLCInputSource> const& src,
1 ✔
1010
                                QString& uniName, QString& chName) const
1011
{
1012
    return inputSourceNames(src.data(), uniName, chName);
1 ✔
1013
}
1014

1015
QDir InputOutputMap::systemProfileDirectory()
1 ✔
1016
{
1017
    return QLCFile::systemDirectory(QString(INPUTPROFILEDIR), QString(KExtInputProfile));
2 ✔
1018
}
1019

1020
QDir InputOutputMap::userProfileDirectory()
1 ✔
1021
{
1022
    return QLCFile::userDirectory(QString(USERINPUTPROFILEDIR), QString(INPUTPROFILEDIR),
2 ✔
1023
                                  QStringList() << QString("*%1").arg(KExtInputProfile));
4 ✔
1024
}
1025

1026
/*********************************************************************
1027
 * Beats
1028
 *********************************************************************/
1029

1030
void InputOutputMap::setBeatGeneratorType(InputOutputMap::BeatGeneratorType type)
8 ✔
1031
{
1032
    if (type == m_beatGeneratorType)
8 ✔
1033
        return;
1 ✔
1034

1035
    if (m_beatGeneratorType == Audio)
7 ✔
1036
    {
1037
        m_inputCapture->unregisterBandsNumber(4);
×
1038
        disconnect(m_inputCapture, SIGNAL(beatDetected(int)), this, SLOT(slotProcessBeat(int)));
×
1039
    }
1040

1041
    // leaving Link: stop taking part in the network session
1042
    if (m_beatGeneratorType == Link && m_link != NULL)
7 ✔
1043
        m_link->setEnabled(false);
2 ✔
1044

1045
    m_beatGeneratorType = type;
7 ✔
1046
    qDebug() << "[InputOutputMap] setting beat type:" << m_beatGeneratorType;
7 ✔
1047

1048
    switch (m_beatGeneratorType)
7 ✔
1049
    {
1050
        case Internal:
1 ✔
1051
        {
1052
            m_doc->masterTimer()->setBeatSourceType(MasterTimer::Internal);
1 ✔
1053
            setBpmNumber(m_doc->masterTimer()->bpmNumber());
1 ✔
1054
        }
1055
        break;
1 ✔
1056
        case Plugin:
×
1057
        {
1058
            m_doc->masterTimer()->setBeatSourceType(MasterTimer::External);
×
1059
            // reset the current BPM number and detect it from the MIDI beats
1060
            setBpmNumber(0);
×
1061
            m_beatTime->restart();
×
1062
        }
1063
        break;
×
1064
        case Audio:
×
1065
        {
1066
            m_doc->masterTimer()->setBeatSourceType(MasterTimer::External);
×
1067
            // reset the current BPM number and detect it from the audio input
1068
            setBpmNumber(0);
×
1069
            m_beatTime->restart();
×
1070
            QSharedPointer<AudioCapture> capture(m_doc->audioInputCapture());
×
1071
            m_inputCapture = capture.data();
×
1072
            connect(m_inputCapture, SIGNAL(beatDetected(int)), this, SLOT(slotProcessBeat(int)));
×
1073
            m_inputCapture->registerBandsNumber(4);
×
1074
        }
×
1075
        break;
×
1076
        case Link:
2 ✔
1077
        {
1078
            if (m_link == NULL)
2 ✔
1079
            {
1080
                qWarning() << "[InputOutputMap] Ableton Link is not available. Using the internal beat generator";
×
1081
                m_beatGeneratorType = Disabled;
×
1082
                setBeatGeneratorType(Internal);
×
1083
                return;
×
1084
            }
1085
            // Don't use setBpmNumber here: it would push the current
1086
            // tempo to an existing Link session, overriding its tempo
1087
            m_currentBPM = m_doc->masterTimer()->bpmNumber();
2 ✔
1088

1089
            // This is only a proposal: when joining an existing session,
1090
            // Link adopts the session tempo instead of this one
1091
            m_link->setTempo(m_currentBPM);
2 ✔
1092
            m_linkPlayingValid = false;
2 ✔
1093
            m_link->setEnabled(true);
2 ✔
1094

1095
            m_doc->masterTimer()->setBeatSourceType(MasterTimer::Timeline);
2 ✔
1096
            emit bpmNumberChanged(m_currentBPM);
2 ✔
1097
        }
1098
        break;
2 ✔
1099
        case Disabled:
4 ✔
1100
        default:
1101
            m_doc->masterTimer()->setBeatSourceType(MasterTimer::None);
4 ✔
1102
            setBpmNumber(0);
4 ✔
1103
        break;
4 ✔
1104
    }
1105

1106
    emit beatGeneratorTypeChanged();
7 ✔
1107
}
1108

1109
InputOutputMap::BeatGeneratorType InputOutputMap::beatGeneratorType() const
×
1110
{
1111
    return m_beatGeneratorType;
×
1112
}
1113

1114
QString InputOutputMap::beatTypeToString(BeatGeneratorType type) const
2 ✔
1115
{
1116
    switch (type)
2 ✔
1117
    {
1118
        case Internal:  return "Internal";
×
1119
        case Plugin:    return "Plugin";
×
1120
        case Audio:     return "Audio";
×
1121
        case Link:      return "Link";
×
1122
        default:        return "Disabled";
2 ✔
1123
    }
1124
}
1125

1126
InputOutputMap::BeatGeneratorType InputOutputMap::stringToBeatType(QString str)
2 ✔
1127
{
1128
    if (str == "Internal")
2 ✔
1129
        return Internal;
×
1130
    else if (str == "Plugin")
2 ✔
1131
        return Plugin;
×
1132
    else if (str == "Audio")
2 ✔
1133
        return Audio;
×
1134
    else if (str == "Link")
2 ✔
1135
        return Link;
×
1136

1137
    return Disabled;
2 ✔
1138
}
1139

1140
void InputOutputMap::setBpmNumber(int bpm)
9 ✔
1141
{
1142
    if (m_beatGeneratorType == Disabled || bpm == m_currentBPM)
9 ✔
1143
        return;
6 ✔
1144

1145
    //qDebug() << "[InputOutputMap] set BPM to" << bpm;
1146
    m_currentBPM = bpm;
3 ✔
1147

1148
    // with Link, a new tempo is proposed to the session. MasterTimer
1149
    // reads the resulting session tempo at the next tick and notifies it
1150
    if (bpm != 0 && m_beatGeneratorType == Link)
3 ✔
1151
        m_link->setTempo(bpm);
1 ✔
1152
    else if (bpm != 0)
2 ✔
1153
        m_doc->masterTimer()->requestBpmNumber(bpm);
2 ✔
1154

1155
    emit bpmNumberChanged(m_currentBPM);
3 ✔
1156
}
1157

1158
int InputOutputMap::bpmNumber() const
1 ✔
1159
{
1160
    if (m_beatGeneratorType == Disabled)
1 ✔
1161
        return 0;
×
1162

1163
    return m_currentBPM;
1 ✔
1164
}
1165

1166
void InputOutputMap::slotProcessBeat(int bpm)
×
1167
{
1168
    // process the timer as first thing, to avoid wasting time
1169
    // with the operations below
1170
    qint64 elapsed = m_beatTime->elapsed();
×
1171
    m_beatTime->restart();
×
1172

1173
    if (bpm > 0)
×
1174
    {
1175
        // the beat source provides its own tempo estimate
1176
        if (bpm != m_currentBPM)
×
1177
        {
1178
            qDebug() << "[InputOutputMap] beat source BPM:" << bpm;
×
1179
            setBpmNumber(bpm);
×
1180
        }
1181
    }
1182
    else
1183
    {
1184
        // no tempo estimate available: derive the BPM number from the
1185
        // wall-clock spacing of the beat signals
1186
        int elapsedBpm = qRound(60000.0 / (float)elapsed);
×
1187
        float currBpmTime = 60000.0 / (float)m_currentBPM;
×
1188
        // here we check if the difference between the current BPM duration
1189
        // and the current time elapsed is within a range of +/-1ms.
1190
        // If it isn't, then the BPM number has really changed, otherwise
1191
        // it's just a tiny time drift
1192
        if (qAbs((float)elapsed - currBpmTime) > 1)
×
1193
            setBpmNumber(elapsedBpm);
×
1194
    }
1195

1196
    m_doc->masterTimer()->requestBeat();
×
1197
    emit beat();
×
1198
}
×
1199

1200
void InputOutputMap::slotMasterTimerBeat()
7 ✔
1201
{
1202
    if (m_beatGeneratorType != Internal && m_beatGeneratorType != Link)
7 ✔
1203
        return;
6 ✔
1204

1205
    emit beat();
1 ✔
1206
}
1207

1208
void InputOutputMap::slotMasterTimerBpmChanged(int bpm)
3 ✔
1209
{
1210
    // only Link changes the tempo from MasterTimer. Don't call
1211
    // setBpmNumber, that would send the rounded tempo back to the session
1212
    if (m_beatGeneratorType != Link || bpm == m_currentBPM)
3 ✔
1213
        return;
1 ✔
1214

1215
    m_currentBPM = bpm;
2 ✔
1216
    emit bpmNumberChanged(m_currentBPM);
2 ✔
1217
}
1218

1219
/*********************************************************************
1220
 * Beat timeline & transport
1221
 *********************************************************************/
1222

1223
bool InputOutputMap::captureBeatTimeline(double &beatPosition, double &tempo)
6 ✔
1224
{
1225
    if (m_beatGeneratorType != Link || m_link == NULL)
6 ✔
1226
        return false;
×
1227

1228
    MasterTimer *timer = m_doc->masterTimer();
6 ✔
1229
    QLCLinkTimeline timeline;
1230

1231
    if (m_link->captureTimeline(timer->beatsPerBar(), timer->latencyOffset(), timeline) == false)
6 ✔
1232
        return false;
×
1233

1234
    beatPosition = timeline.beat;
6 ✔
1235
    tempo = timeline.tempo;
6 ✔
1236

1237
    // notify the transport changes. The state found when joining
1238
    // the session is just taken, not notified
1239
    if (m_linkPlayingValid && timeline.playing != m_linkPlaying)
6 ✔
1240
        emit transportChanged(timeline.playing);
2 ✔
1241
    m_linkPlaying = timeline.playing;
6 ✔
1242
    m_linkPlayingValid = true;
6 ✔
1243

1244
    return true;
6 ✔
1245
}
1246

1247
void InputOutputMap::setTransportPlaying(bool playing)
3 ✔
1248
{
1249
    if (m_beatGeneratorType != Link || m_link == NULL)
3 ✔
1250
        return;
1 ✔
1251

1252
    m_link->setPlaying(playing);
2 ✔
1253
}
1254

1255
/*********************************************************************
1256
 * Ableton Link
1257
 *********************************************************************/
1258

1259
void InputOutputMap::setLinkService(QObject *service)
2 ✔
1260
{
1261
    QLCLinkService *link = qobject_cast<QLCLinkService*>(service);
2 ✔
1262
    if (link == NULL)
2 ✔
1263
    {
1264
        qWarning() << "[InputOutputMap] The Link service doesn't implement the expected interface";
×
1265
        return;
×
1266
    }
1267

1268
    m_link = link;
2 ✔
1269

1270
    // emitted by a Link thread, so this connection is queued
1271
    connect(service, SIGNAL(numPeersChanged(int)), this, SIGNAL(linkPeersChanged(int)));
2 ✔
1272
}
1273

1274
bool InputOutputMap::linkAvailable() const
×
1275
{
1276
    return m_link != NULL;
×
1277
}
1278

1279
int InputOutputMap::linkPeers() const
×
1280
{
1281
    return m_link == NULL ? 0 : m_link->numPeers();
×
1282
}
1283

1284
void InputOutputMap::slotPluginBeat(quint32 universe, quint32 channel, uchar value, const QString &key)
×
1285
{
1286
    Q_UNUSED(universe)
1287

1288
    // not interested in synthetic release or non-beat event
1289
    if (m_beatGeneratorType != Plugin || value == 0 || key != "beat")
×
1290
        return;
×
1291

1292
    qDebug() << "Plugin beat:" << channel << m_beatTime->elapsed();
×
1293

1294
    slotProcessBeat();
×
1295
}
1296

1297
/*********************************************************************
1298
 * Network server
1299
 *********************************************************************/
1300

1301
void InputOutputMap::setNetworkServerType(int typeMask)
×
1302
{
1303
    m_networkServerType = typeMask;
×
1304
}
×
1305

1306
int InputOutputMap::networkServerType() const
×
1307
{
1308
    return m_networkServerType;
×
1309
}
1310

1311
QString InputOutputMap::networkServerTypeToString(int typeMask) const
2 ✔
1312
{
1313
    QStringList types;
2 ✔
1314

1315
    if (typeMask & NativeServer)
2 ✔
1316
        types << "Native";
2 ✔
1317
    if (typeMask & WebServer)
2 ✔
1318
        types << "Web";
×
1319

1320
    if (types.isEmpty())
2 ✔
1321
        return "None";
×
1322

1323
    return types.join("|");
2 ✔
1324
}
2 ✔
1325

1326
int InputOutputMap::stringToNetworkServerType(const QString &str) const
×
1327
{
1328
    int typeMask = NoServer;
×
1329

1330
    // a legacy project stores a single type, while a
1331
    // recent one can store a '|' separated list of types
1332

1333
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
1334
    for (const QString &token : str.split('|', QString::SkipEmptyParts))
1335
#else
1336
    for (const QString &token : str.split('|', Qt::SkipEmptyParts))
×
1337
#endif
1338
    {
1339
        QString type = token.trimmed();
×
1340

1341
        if (type.compare("Native", Qt::CaseInsensitive) == 0)
×
1342
            typeMask |= NativeServer;
×
1343
        else if (type.compare("Web", Qt::CaseInsensitive) == 0)
×
1344
            typeMask |= WebServer;
×
1345
    }
×
1346

1347
    return typeMask;
×
1348
}
1349

1350
void InputOutputMap::setNetworkServerAutoStart(bool enable)
×
1351
{
1352
    m_networkServerAutoStart = enable;
×
1353
}
×
1354

1355
bool InputOutputMap::networkServerAutoStart() const
×
1356
{
1357
    return m_networkServerAutoStart;
×
1358
}
1359

1360
void InputOutputMap::setNetworkServerName(QString name)
×
1361
{
1362
    m_networkServerName = name;
×
1363
}
×
1364

1365
QString InputOutputMap::networkServerName() const
×
1366
{
1367
    return m_networkServerName;
×
1368
}
1369

1370
void InputOutputMap::setNetworkServerPassword(QString password)
×
1371
{
1372
    m_networkServerPassword = password;
×
1373
}
×
1374

1375
QString InputOutputMap::networkServerPassword() const
×
1376
{
1377
    return m_networkServerPassword;
×
1378
}
1379

1380
/*********************************************************************
1381
 * Defaults - !! FALLBACK !!
1382
 *********************************************************************/
1383

1384
void InputOutputMap::loadDefaults()
×
1385
{
1386
    /* ************************ INPUT *********************************** */
1387
    QSettings settings;
×
1388
    QString plugin;
×
1389
    QString input;
×
1390
    QString key;
×
1391

1392
    for (quint32 i = 0; i < universesCount(); i++)
×
1393
    {
1394
        QString profileName;
×
1395
        bool passthrough;
1396

1397
        /* Plugin name */
1398
        key = QString("/inputmap/universe%1/plugin/").arg(i);
×
1399
        plugin = settings.value(key).toString();
×
1400

1401
        /* Plugin input */
1402
        key = QString("/inputmap/universe%1/input/").arg(i);
×
1403
        input = settings.value(key).toString();
×
1404

1405
        /* Input profile */
1406
        key = QString("/inputmap/universe%1/profile/").arg(i);
×
1407
        profileName = settings.value(key).toString();
×
1408

1409
        key = QString("/inputmap/universe%1/passthrough/").arg(i);
×
1410
        passthrough = settings.value(key).toBool();
×
1411
        if (passthrough == true)
×
1412
            m_universeArray.at(i)->setPassthrough(passthrough);
×
1413

1414
        /* Do the mapping */
1415
        if (plugin != KInputNone && input != KInputNone)
×
1416
            setInputPatch(i, plugin, "", "", input.toUInt(), profileName);
×
1417
    }
×
1418

1419
    /* ************************ OUTPUT *********************************** */
1420
    QString output;
×
1421
    QString fb_plugin;
×
1422
    QString feedback;
×
1423

1424
    for (quint32 i = 0; i < universesCount(); i++)
×
1425
    {
1426
        /* Plugin name */
1427
        key = QString("/outputmap/universe%1/plugin/").arg(i);
×
1428
        plugin = settings.value(key).toString();
×
1429

1430
        /* Plugin output */
1431
        key = QString("/outputmap/universe%1/output/").arg(i);
×
1432
        output = settings.value(key).toString();
×
1433

1434
        /* Feedback plugin name */
1435
        key = QString("/outputmap/universe%1/feedbackplugin/").arg(i);
×
1436
        fb_plugin = settings.value(key).toString();
×
1437

1438
        /* Feedback line */
1439
        key = QString("/outputmap/universe%1/feedback/").arg(i);
×
1440
        feedback = settings.value(key).toString();
×
1441

1442
        if (plugin != KOutputNone && output != KOutputNone)
×
1443
            setOutputPatch(i, plugin, "", "", output.toUInt());
×
1444

1445
        if (fb_plugin != KOutputNone && feedback != KOutputNone)
×
1446
            setOutputPatch(i, fb_plugin, "", "", feedback.toUInt(), true);
×
1447
    }
1448
}
×
1449

1450
void InputOutputMap::saveDefaults() const
×
1451
{
1452
    /* ************************ INPUT *********************************** */
1453
    QSettings settings;
×
1454
    QString key;
×
1455

1456
    for (quint32 i = 0; i < universesCount(); i++)
×
1457
    {
1458
        InputPatch* inPatch = inputPatch(i);
×
1459

1460
        /* Plugin name */
1461
        key = QString("/inputmap/universe%1/plugin/").arg(i);
×
1462
        if (inPatch != NULL)
×
1463
            settings.setValue(key, inPatch->pluginName());
×
1464
        else
1465
            settings.setValue(key, KInputNone);
×
1466

1467
        /* Plugin input */
1468
        key = QString("/inputmap/universe%1/input/").arg(i);
×
1469
        if (inPatch != NULL)
×
1470
            settings.setValue(key, QString::number(inPatch->input()));
×
1471
        else
1472
            settings.setValue(key, KInputNone);
×
1473

1474
        /* Input profile */
1475
        key = QString("/inputmap/universe%1/profile/").arg(i);
×
1476
        if (inPatch != NULL)
×
1477
            settings.setValue(key, inPatch->profileName());
×
1478
        else
1479
            settings.setValue(key, KInputNone);
×
1480

1481
        /* Passthrough */
1482
        key = QString("/inputmap/universe%1/passthrough/").arg(i);
×
1483
        bool passthrough = m_universeArray.at(i)->passthrough();
×
1484
        if (passthrough == true)
×
1485
            settings.setValue(key, passthrough);
×
1486
        else
1487
            settings.remove(key);
×
1488
    }
1489

1490
    /* ************************ OUTPUT *********************************** */
1491

1492
    for (quint32 i = 0; i < universesCount(); i++)
×
1493
    {
1494
        OutputPatch* outPatch = outputPatch(i);
×
1495
        OutputPatch* fbPatch = feedbackPatch(i);
×
1496

1497
        key = QString("/outputmap/universe%1/plugin/").arg(i);
×
1498

1499
        /* Plugin name */
1500
        if (outPatch != NULL)
×
1501
            settings.setValue(key, outPatch->pluginName());
×
1502
        else
1503
            settings.setValue(key, KOutputNone);
×
1504

1505
        /* Plugin output */
1506
        key = QString("/outputmap/universe%1/output/").arg(i);
×
1507
        if (outPatch != NULL)
×
1508
            settings.setValue(key, outPatch->output());
×
1509
        else
1510
            settings.setValue(key, KOutputNone);
×
1511

1512
        key = QString("/outputmap/universe%1/feedbackplugin/").arg(i);
×
1513

1514
        /* Feedback plugin name */
1515
        if (fbPatch != NULL)
×
1516
            settings.setValue(key, fbPatch->pluginName());
×
1517
        else
1518
            settings.setValue(key, KOutputNone);
×
1519

1520
        /* Feedback plugin output */
1521
        key = QString("/outputmap/universe%1/feedback/").arg(i);
×
1522
        if (fbPatch != NULL)
×
1523
            settings.setValue(key, QString::number(fbPatch->output()));
×
1524
        else
1525
            settings.setValue(key, KOutputNone);
×
1526
    }
1527
}
×
1528

1529
/*********************************************************************
1530
 * Load & Save
1531
 *********************************************************************/
1532

1533
bool InputOutputMap::loadXML(QXmlStreamReader &root)
2 ✔
1534
{
1535
    if (root.name() != KXMLIOMap)
2 ✔
1536
    {
1537
        qWarning() << Q_FUNC_INFO << "InputOutputMap node not found";
×
1538
        return false;
×
1539
    }
1540

1541
    /** Reset the current universe list and read the new one */
1542
    removeAllUniverses();
2 ✔
1543

1544
    while (root.readNextStartElement())
4 ✔
1545
    {
1546
        if (root.name() == KXMLQLCUniverse)
2 ✔
1547
        {
1548
            quint32 id = InputOutputMap::invalidUniverse();
×
1549
            if (root.attributes().hasAttribute(KXMLQLCUniverseID))
×
1550
                id = root.attributes().value(KXMLQLCUniverseID).toString().toUInt();
×
1551
            if (addUniverse(id))
×
1552
            {
1553
                Universe *uni = m_universeArray.last();
×
1554
                uni->loadXML(root, m_universeArray.count() - 1, this);
×
1555
            }
1556
        }
1557
        else if (root.name() == KXMLIOBeatGenerator)
2 ✔
1558
        {
1559
            QXmlStreamAttributes attrs = root.attributes();
2 ✔
1560

1561
            if (attrs.hasAttribute(KXMLIOBeatType))
2 ✔
1562
                setBeatGeneratorType(stringToBeatType(attrs.value(KXMLIOBeatType).toString()));
2 ✔
1563

1564
            if (attrs.hasAttribute(KXMLIOBeatsPerMinute))
2 ✔
1565
                setBpmNumber(attrs.value(KXMLIOBeatsPerMinute).toInt());
2 ✔
1566

1567
            // projects saved without it are 4/4
1568
            if (attrs.hasAttribute(KXMLIOBeatsPerBar))
2 ✔
1569
                m_doc->masterTimer()->setBeatsPerBar(attrs.value(KXMLIOBeatsPerBar).toInt());
2 ✔
1570
            else
1571
                m_doc->masterTimer()->setBeatsPerBar(MASTERTIMER_DEFAULT_BEATS_PER_BAR);
1 ✔
1572

1573
            QString quantize = attrs.value(KXMLIOLaunchQuantize).toString();
2 ✔
1574
            if (quantize == "Beat")
2 ✔
1575
                m_doc->masterTimer()->setLaunchQuantize(MasterTimer::QuantizeBeat);
×
1576
            else if (quantize == "Bar")
2 ✔
1577
                m_doc->masterTimer()->setLaunchQuantize(MasterTimer::QuantizeBar);
1 ✔
1578
            else
1579
                m_doc->masterTimer()->setLaunchQuantize(MasterTimer::QuantizeOff);
1 ✔
1580

1581
            root.skipCurrentElement();
2 ✔
1582
        }
2 ✔
1583
        else if (root.name() == KXMLIONetworkServer)
×
1584
        {
1585
            QXmlStreamAttributes attrs = root.attributes();
×
1586
            int typeMask = NativeServer;
×
1587

1588
            if (attrs.hasAttribute(KXMLIONetworkType))
×
1589
                typeMask = stringToNetworkServerType(attrs.value(KXMLIONetworkType).toString());
×
1590
            setNetworkServerType(typeMask);
×
1591

1592
            if (attrs.hasAttribute(KXMLIONetworkAutoStart))
×
1593
                setNetworkServerAutoStart(attrs.value(KXMLIONetworkAutoStart) == KXMLQLCTrue);
×
1594

1595
            if (typeMask & NativeServer)
×
1596
            {
1597
                setNetworkServerName(attrs.value(KXMLIONetworkName).toString());
×
1598
                setNetworkServerPassword(attrs.value(KXMLIONetworkPassword).toString());
×
1599
            }
1600
            else
1601
            {
1602
                setNetworkServerName(QString());
×
1603
                setNetworkServerPassword(QString());
×
1604
            }
1605

1606
            root.skipCurrentElement();
×
1607
        }
×
1608
        else
1609
        {
1610
            qWarning() << Q_FUNC_INFO << "Unknown IO Map tag:" << root.name();
×
1611
            root.skipCurrentElement();
×
1612
        }
1613
    }
1614

1615
    return true;
2 ✔
1616
}
1617

1618
bool InputOutputMap::saveXML(QXmlStreamWriter *doc) const
2 ✔
1619
{
1620
    Q_ASSERT(doc != NULL);
2 ✔
1621

1622
    /* IO Map Instance entry */
1623
    doc->writeStartElement(KXMLIOMap);
4 ✔
1624

1625
    doc->writeStartElement(KXMLIOBeatGenerator);
4 ✔
1626
    doc->writeAttribute(KXMLIOBeatType, beatTypeToString(m_beatGeneratorType));
4 ✔
1627
    doc->writeAttribute(KXMLIOBeatsPerMinute, QString::number(m_currentBPM));
4 ✔
1628
    doc->writeAttribute(KXMLIOBeatsPerBar, QString::number(m_doc->masterTimer()->beatsPerBar()));
4 ✔
1629
    switch (m_doc->masterTimer()->launchQuantize())
2 ✔
1630
    {
1631
        case MasterTimer::QuantizeBeat: doc->writeAttribute(KXMLIOLaunchQuantize, "Beat"); break;
×
1632
        case MasterTimer::QuantizeBar: doc->writeAttribute(KXMLIOLaunchQuantize, "Bar"); break;
2 ✔
1633
        default: break;
1 ✔
1634
    }
1635
    doc->writeEndElement();
2 ✔
1636

1637
    doc->writeStartElement(KXMLIONetworkServer);
4 ✔
1638
    doc->writeAttribute(KXMLIONetworkType, networkServerTypeToString(m_networkServerType));
4 ✔
1639
    doc->writeAttribute(KXMLIONetworkAutoStart, m_networkServerAutoStart ? KXMLQLCTrue : KXMLQLCFalse);
6 ✔
1640
    if (m_networkServerType & NativeServer)
2 ✔
1641
    {
1642
        doc->writeAttribute(KXMLIONetworkName, m_networkServerName);
4 ✔
1643
        doc->writeAttribute(KXMLIONetworkPassword, m_networkServerPassword);
4 ✔
1644
    }
1645
    doc->writeEndElement();
2 ✔
1646

1647
    foreach (Universe *uni, m_universeArray)
6 ✔
1648
        uni->saveXML(doc);
6 ✔
1649

1650
    doc->writeEndElement();
2 ✔
1651

1652
    return true;
2 ✔
1653
}
1654

1655
/*********************************************************************
1656
 * RDM transport
1657
 *********************************************************************/
1658

1659
QList<QLCRDMLine> InputOutputMap::lines()
×
1660
{
1661
    QList<QLCRDMLine> list;
×
1662

1663
    for (const Universe *uni : universes())
×
1664
    {
1665
        for (int i = 0; i < uni->outputPatchesCount(); i++)
×
1666
        {
1667
            OutputPatch *op = uni->outputPatch(i);
×
1668
            if (op == nullptr || op->plugin() == nullptr)
×
1669
                continue;
×
1670

1671
            if (op->plugin()->capabilities() & QLCIOPlugin::RDM)
×
1672
            {
1673
                QLCRDMLine line = { uni->id(), op->output(), op->plugin() };
×
1674
                list.append(line);
×
1675
            }
1676
        }
1677
    }
×
1678

1679
    return list;
×
1680
}
×
1681

1682
QLCIOPlugin *InputOutputMap::transport(quint32 universe, quint32 line)
×
1683
{
1684
    const QList<QLCRDMLine> list = lines();
×
1685
    for (const QLCRDMLine &l : list)
×
1686
    {
1687
        if (l.universe == universe && l.line == line)
×
1688
            return l.plugin;
×
1689
    }
1690

1691
    return nullptr;
×
1692
}
×
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