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

mcallegari / qlcplus / 19144422256

06 Nov 2025 05:33PM UTC coverage: 34.256% (-0.1%) from 34.358%
19144422256

push

github

mcallegari
Back to 5.1.0 debug

17718 of 51723 relevant lines covered (34.26%)

19528.23 hits per line

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

0.0
/ui/src/virtualconsole/vcaudiotriggers.cpp
1
/*
2
  Q Light Controller Plus
3
  vcaudiotriggers.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 <QXmlStreamReader>
21
#include <QXmlStreamWriter>
22
#include <QMessageBox>
23
#include <QSettings>
24
#include <QDebug>
25

26
#include "vcaudiotriggersproperties.h"
27
#include "vcpropertieseditor.h"
28
#include "vcaudiotriggers.h"
29
#include "audiocapture.h"
30
#include "genericfader.h"
31
#include "fadechannel.h"
32
#include "universe.h"
33
#include "audiobar.h"
34
#include "apputil.h"
35
#include "doc.h"
36

37
#define KXMLQLCVCATKey          QStringLiteral("Key")
38
#define KXMLQLCVCATBarsNumber   QStringLiteral("BarsNumber")
39

40
#define KXMLQLCVolumeBar    QStringLiteral("VolumeBar")
41
#define KXMLQLCSpectrumBar  QStringLiteral("SpectrumBar")
42

43
const QSize VCAudioTriggers::defaultSize(QSize(300, 200));
44

45
VCAudioTriggers::VCAudioTriggers(QWidget* parent, Doc* doc)
×
46
    : VCWidget(parent, doc)
47
    , m_hbox(NULL)
×
48
    , m_button(NULL)
×
49
    , m_label(NULL)
×
50
    , m_spectrum(NULL)
×
51
    , m_volumeSlider(NULL)
×
52
    , m_inputCapture(NULL)
×
53
{
54
    /* Set the class name "VCAudioTriggers" as the object name as well */
55
    setObjectName(VCAudioTriggers::staticMetaObject.className());
×
56

57
    setType(VCWidget::AudioTriggersWidget);
×
58
    setFrameStyle(KVCFrameStyleSunken);
×
59

60
    new QVBoxLayout(this);
×
61

62
    /* Main HBox */
63
    m_hbox = new QHBoxLayout();
×
64
    m_hbox->setGeometry(QRect(0, 0, 300, 40));
×
65

66
    layout()->setSpacing(2);
×
67
    layout()->setContentsMargins(4, 4, 4, 4);
×
68
    layout()->addItem(m_hbox);
×
69

70
    m_button = new QToolButton(this);
×
71
    m_button->setStyle(AppUtil::saneStyle());
×
72
    m_button->setIconSize(QSize(32, 32));
×
73
    m_button->setMinimumSize(QSize(32, 32));
×
74
    m_button->setMaximumSize(QSize(32, 32));
×
75
    m_button->setIcon(QIcon(":/check.png"));
×
76
    m_button->setCheckable(true);
×
77
    QString btnSS = "QToolButton { background-color: #E0DFDF; border: 1px solid gray; border-radius: 3px; padding: 3px; } ";
×
78
    btnSS += "QToolButton:checked { background-color: #D7DE75; border: 1px solid gray; border-radius: 3px; padding: 3px; } ";
×
79
    m_button->setStyleSheet(btnSS);
×
80
    m_button->setEnabled(false);
×
81

82
    m_hbox->addWidget(m_button);
×
83
    connect(m_button, SIGNAL(toggled(bool)), this, SLOT(slotEnableButtonToggled(bool)));
×
84

85
    m_label = new QLabel(this);
×
86
    m_label->setText(this->caption());
×
87
    QString txtColor = "white";
×
88
    if (m_hasCustomForegroundColor)
×
89
        txtColor = this->foregroundColor().name();
×
90
    m_label->setStyleSheet("QLabel { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #345D27, stop: 1 #0E1A0A); "
×
91
                           "color: " + txtColor + "; border-radius: 3px; padding: 3px; margin-left: 2px; }");
×
92

93
    if (m_hasCustomFont)
×
94
        m_label->setFont(font());
×
95
    else
96
    {
97
        QFont m_font = QApplication::font();
×
98
        m_font.setBold(true);
×
99
        m_font.setPixelSize(12);
×
100
        m_label->setFont(m_font);
×
101
    }
×
102
    m_hbox->addWidget(m_label);
×
103

104
    QSharedPointer<AudioCapture> capture(m_doc->audioInputCapture());
×
105
    m_inputCapture = capture.data();
×
106

107
    // create the  AudioBar items to hold the spectrum data.
108
    // To be loaded from the project
109
    m_volumeBar = new AudioBar(AudioBar::None, 0, id());
×
110
    m_spectrumBars.reserve(m_inputCapture->defaultBarsNumber());
×
111
    for (int i = 0; i < m_inputCapture->defaultBarsNumber(); i++)
×
112
    {
113
        AudioBar *asb = new AudioBar(AudioBar::None, 0, id());
×
114
        m_spectrumBars.append(asb);
×
115
    }
116

117
    QHBoxLayout *hbox2 = new QHBoxLayout();
×
118
    m_volumeSlider = new ClickAndGoSlider(this);
×
119
    m_volumeSlider->setOrientation(Qt::Vertical);
×
120
    m_volumeSlider->setRange(0, 100);
×
121
    m_volumeSlider->setSliderStyleSheet(CNG_DEFAULT_STYLE);
×
122
    m_volumeSlider->setValue(100);
×
123
    m_volumeSlider->setFixedWidth(32);
×
124
    m_volumeSlider->setEnabled(false);
×
125

126
    connect(m_volumeSlider, SIGNAL(valueChanged(int)),
×
127
            this, SLOT(slotVolumeChanged(int)));
128

129
    m_spectrum = new AudioTriggerWidget(this);
×
130
    m_spectrum->setBarsNumber(m_inputCapture->defaultBarsNumber());
×
131
    m_spectrum->setMaxFrequency(AudioCapture::maxFrequency());
×
132
    m_spectrum->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
×
133

134
    layout()->addItem(hbox2);
×
135
    hbox2->addWidget(m_spectrum);
×
136
    hbox2->addWidget(m_volumeSlider);
×
137

138
    /* Initial size */
139
    QSettings settings;
×
140
    QVariant var = settings.value(SETTINGS_AUDIOTRIGGERS_SIZE);
×
141
    if (var.isValid() == true)
×
142
        resize(var.toSize());
×
143
    else
144
        resize(defaultSize);
×
145

146
    slotModeChanged(m_doc->mode());
×
147
}
×
148

149
VCAudioTriggers::~VCAudioTriggers()
×
150
{
151
    QSharedPointer<AudioCapture> capture(m_doc->audioInputCapture());
×
152

153
    if (m_inputCapture == capture.data())
×
154
        m_inputCapture->unregisterBandsNumber(m_spectrum->barsNumber());
×
155

156
    qDeleteAll(m_spectrumBars);
×
157
    delete m_volumeBar;
×
158
}
×
159

160
void VCAudioTriggers::enableWidgetUI(bool enable)
×
161
{
162
    if (m_button)
×
163
        m_button->setEnabled(enable);
×
164

165
    m_volumeSlider->setEnabled(enable);
×
166
}
×
167

168
void VCAudioTriggers::notifyFunctionStarting(quint32 fid, qreal intensity)
×
169
{
170
    // Stop on any other function started
171
    Q_UNUSED(fid);
172
    Q_UNUSED(intensity);
173
    if (m_button->isChecked() == true)
×
174
        enableCapture(false);
×
175
}
×
176

177
void VCAudioTriggers::enableCapture(bool enable)
×
178
{
179
    // in case the audio input device has been changed in the meantime...
180
    QSharedPointer<AudioCapture> capture(m_doc->audioInputCapture());
×
181
    bool captureIsNew = m_inputCapture != capture.data();
×
182
    m_inputCapture = capture.data();
×
183

184
    if (enable == true)
×
185
    {
186
        connect(m_inputCapture, SIGNAL(dataProcessed(double*,int,double,quint32)),
×
187
                this, SLOT(slotDisplaySpectrum(double*,int,double,quint32)));
188
        connect(m_inputCapture, SIGNAL(volumeChanged(int)),
×
189
                this, SLOT(slotUpdateVolumeSlider(int)));
190
        m_inputCapture->registerBandsNumber(m_spectrum->barsNumber());
×
191

192
        m_button->blockSignals(true);
×
193
        m_button->setChecked(true);
×
194
        m_button->blockSignals(false);
×
195

196
        emit captureEnabled(true);
×
197

198
        // Invalid ID: Stop every other widget
199
        emit functionStarting(Function::invalidId());
×
200
    }
201
    else
202
    {
203
        if (!captureIsNew)
×
204
        {
205
            m_inputCapture->unregisterBandsNumber(m_spectrum->barsNumber());
×
206
            disconnect(m_inputCapture, SIGNAL(dataProcessed(double*,int,double,quint32)),
×
207
                       this, SLOT(slotDisplaySpectrum(double*,int,double,quint32)));
208
            disconnect(m_inputCapture, SIGNAL(volumeChanged(int)),
×
209
                       this, SLOT(slotUpdateVolumeSlider(int)));
210
        }
211

212
        m_button->blockSignals(true);
×
213
        m_button->setChecked(false);
×
214
        m_button->blockSignals(false);
×
215

216
        emit captureEnabled(false);
×
217
    }
218
}
×
219

220
void VCAudioTriggers::toggleEnableButton(bool toggle)
×
221
{
222
    if (mode() == Doc::Design)
×
223
        return;
×
224

225
    if (m_button)
×
226
        m_button->setChecked(toggle);
×
227
}
228

229
void VCAudioTriggers::slotEnableButtonToggled(bool toggle)
×
230
{
231
    if (mode() == Doc::Design)
×
232
        return;
×
233

234
    enableCapture(toggle);
×
235
    updateFeedback();
×
236
}
237

238
void VCAudioTriggers::slotDisplaySpectrum(double *spectrumBands, int size,
×
239
                                          double maxMagnitude, quint32 power)
240
{
241
    //qDebug() << "Display spectrum ----- bars:" << size;
242
    if (size != m_spectrum->barsNumber())
×
243
        return;
×
244

245
    m_spectrum->displaySpectrum(spectrumBands, maxMagnitude, power);
×
246
    m_volumeBar->m_value = m_spectrum->getUcharVolume();
×
247

248
    if (mode() == Doc::Design)
×
249
        return;
×
250

251
    if (m_volumeBar->m_type == AudioBar::FunctionBar)
×
252
        m_volumeBar->checkFunctionThresholds(m_doc);
×
253
    else if (m_volumeBar->m_type == AudioBar::VCWidgetBar)
×
254
        m_volumeBar->checkWidgetFunctionality();
×
255

256
    for (int i = 0; i < m_spectrumBars.count(); i++)
×
257
    {
258
        m_spectrumBars[i]->m_value = m_spectrum->getUcharBand(i);
×
259
        if (m_spectrumBars[i]->m_type == AudioBar::FunctionBar)
×
260
            m_spectrumBars[i]->checkFunctionThresholds(m_doc);
×
261
        else if (m_spectrumBars[i]->m_type == AudioBar::VCWidgetBar)
×
262
            m_spectrumBars[i]->checkWidgetFunctionality();
×
263
    }
264
}
265

266
void VCAudioTriggers::slotVolumeChanged(int volume)
×
267
{
268
    m_doc->audioInputCapture()->setVolume(intensity() * qreal(volume) / 100.0);
×
269
}
×
270

271
void VCAudioTriggers::slotUpdateVolumeSlider(int volume)
×
272
{
273
    m_volumeSlider->setValue(volume);
×
274
}
×
275

276
/*********************************************************************
277
 * DMXSource
278
 *********************************************************************/
279

280
void VCAudioTriggers::writeDMX(MasterTimer *timer, QList<Universe *> universes)
×
281
{
282
    Q_UNUSED(timer);
283

284
    if (mode() == Doc::Design)
×
285
        return;
×
286

287
    quint32 lastUniverse = Universe::invalid();
×
288
    QSharedPointer<GenericFader> fader;
×
289

290
    if (m_volumeBar->m_type == AudioBar::DMXBar)
×
291
    {
292
        for (int i = 0; i < m_volumeBar->m_absDmxChannels.count(); i++)
×
293
        {
294
            int absAddress = m_volumeBar->m_absDmxChannels.at(i);
×
295
            //quint32 address = absAddress & 0x01FF;
296
            quint32 universe = absAddress >> 9;
×
297
            if (universe != lastUniverse)
×
298
            {
299
                fader = m_fadersMap.value(universe, QSharedPointer<GenericFader>());
×
300
                if (fader.isNull())
×
301
                {
302
                    fader = universes[universe]->requestFader();
×
303
                    fader->adjustIntensity(intensity());
×
304
                    m_fadersMap[universe] = fader;
×
305
                }
306
                lastUniverse = universe;
×
307
                fader->setEnabled(m_button->isChecked() ? true : false);
×
308
            }
309

310
            FadeChannel *fc = fader->getChannelFader(m_doc, universes[universe], Fixture::invalidId(), absAddress);           
×
311
            fc->setStart(fc->current());
×
312
            fc->setTarget(m_volumeBar->m_value);
×
313
            fc->setReady(false);
×
314
            fc->setElapsed(0);
×
315
        }
316
    }
317
    foreach (AudioBar *sb, m_spectrumBars)
×
318
    {
319
        if (sb->m_type == AudioBar::DMXBar)
×
320
        {
321
            for (int i = 0; i < sb->m_absDmxChannels.count(); i++)
×
322
            {
323
                int absAddress = sb->m_absDmxChannels.at(i);
×
324
                //quint32 address = absAddress & 0x01FF;
325
                quint32 universe = absAddress >> 9;
×
326
                if (universe != lastUniverse)
×
327
                {
328
                    fader = m_fadersMap.value(universe, QSharedPointer<GenericFader>());
×
329
                    if (fader == NULL)
×
330
                    {
331
                        fader = universes[universe]->requestFader();
×
332
                        fader->adjustIntensity(intensity());
×
333
                        m_fadersMap[universe] = fader;
×
334
                    }
335
                    fader->setEnabled(m_button->isChecked() ? true : false);
×
336
                    lastUniverse = universe;
×
337
                }
338

339
                FadeChannel *fc = fader->getChannelFader(m_doc, universes[universe], Fixture::invalidId(), absAddress);
×
340
                fc->setStart(fc->current());
×
341
                fc->setTarget(sb->m_value);
×
342
                fc->setReady(false);
×
343
                fc->setElapsed(0);
×
344
            }
345
        }
346
    }
×
347
}
×
348

349
/*********************************************************************
350
 * Key sequence handler
351
 *********************************************************************/
352

353
void VCAudioTriggers::setKeySequence(const QKeySequence& keySequence)
×
354
{
355
    m_keySequence = QKeySequence(keySequence);
×
356
}
×
357

358
QKeySequence VCAudioTriggers::keySequence() const
×
359
{
360
    return m_keySequence;
×
361
}
362

363
void VCAudioTriggers::slotKeyPressed(const QKeySequence& keySequence)
×
364
{
365
    if (acceptsInput() == false)
×
366
        return;
×
367

368
    if (m_keySequence == keySequence)
×
369
    {
370
        if (m_button->isChecked())
×
371
            slotEnableButtonToggled(false);
×
372
        else
373
            slotEnableButtonToggled(true);
×
374
    }
375
}
376

377
void VCAudioTriggers::updateFeedback()
×
378
{
379
    QSharedPointer<QLCInputSource> src = inputSource();
×
380
    if (!src.isNull() && src->isValid() == true)
×
381
    {
382
        if (m_button->isChecked())
×
383
            sendFeedback(src->feedbackValue(QLCInputFeedback::UpperValue));
×
384
        else
385
            sendFeedback(src->feedbackValue(QLCInputFeedback::LowerValue));
×
386
    }
387
}
×
388

389
void VCAudioTriggers::slotInputValueChanged(quint32 universe, quint32 channel, uchar value)
×
390
{
391
    /* Don't let input data through in design mode or if disabled */
392
    if (acceptsInput() == false)
×
393
        return;
×
394

395
    if (checkInputSource(universe, (page() << 16) | channel, value, sender()) && value > 0)
×
396
    {
397
        if (m_button->isChecked())
×
398
            slotEnableButtonToggled(false);
×
399
        else
400
            slotEnableButtonToggled(true);
×
401
    }
402
}
403

404
/*********************************************************************
405
 * Clipboard
406
 *********************************************************************/
407

408
VCWidget *VCAudioTriggers::createCopy(VCWidget *parent)
×
409
{
410
    Q_ASSERT(parent != NULL);
×
411

412
    VCAudioTriggers* triggers = new VCAudioTriggers(parent, m_doc);
×
413
    if (triggers->copyFrom(this) == false)
×
414
    {
415
        delete triggers;
×
416
        triggers = NULL;
×
417
    }
418

419
    return triggers;
×
420
}
421

422
bool VCAudioTriggers::copyFrom(const VCWidget *widget)
×
423
{
424
    const VCAudioTriggers* triggers = qobject_cast <const VCAudioTriggers*> (widget);
×
425
    if (triggers == NULL)
×
426
        return false;
×
427

428
    /* TODO: Copy triggers-specific stuff */
429

430
    /* Copy common stuff */
431
    return VCWidget::copyFrom(widget);
×
432
}
433

434
/*************************************************************************
435
 * VCWidget-inherited
436
 *************************************************************************/
437

438
void VCAudioTriggers::setCaption(const QString &text)
×
439
{
440
    if (m_label != NULL)
×
441
        m_label->setText(text);
×
442

443
    VCWidget::setCaption(text);
×
444
}
×
445

446
void VCAudioTriggers::setForegroundColor(const QColor &color)
×
447
{
448
    if (m_label != NULL)
×
449
    {
450
        m_label->setStyleSheet("QLabel { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #345D27, stop: 1 #0E1A0A); "
×
451
                               "color: " + color.name() + "; border-radius: 3px; padding: 3px; margin-left: 2px; }");
×
452
        m_hasCustomForegroundColor = true;
×
453
        m_doc->setModified();
×
454
    }
455
}
×
456

457
QColor VCAudioTriggers::foregroundColor() const
×
458
{
459
    if (m_label != NULL)
×
460
        return m_label->palette().color(m_label->foregroundRole());
×
461
    else
462
        return VCWidget::foregroundColor();
×
463
}
464

465
void VCAudioTriggers::slotModeChanged(Doc::Mode mode)
×
466
{
467
    if (mode == Doc::Operate)
×
468
    {
469
        enableWidgetUI(true);
×
470

471
        foreach (AudioBar *bar, getAudioBars())
×
472
        {
473
            if (bar->m_type == AudioBar::DMXBar)
×
474
            {
475
                m_doc->masterTimer()->registerDMXSource(this);
×
476
                break;
×
477
            }
478
        }
×
479
    }
480
    else
481
    {
482
        enableWidgetUI(false);
×
483
        enableCapture(false);
×
484
        m_doc->masterTimer()->unregisterDMXSource(this);
×
485

486
        // request to delete all the active faders
487
        foreach (QSharedPointer<GenericFader> fader, m_fadersMap)
×
488
        {
489
            if (!fader.isNull())
×
490
                fader->requestDelete();
×
491
        }
×
492
        m_fadersMap.clear();
×
493
    }
494
    VCWidget::slotModeChanged(mode);
×
495
}
×
496

497
/*************************************************************************
498
 * Configuration
499
 *************************************************************************/
500

501
AudioBar *VCAudioTriggers::getSpectrumBar(int index)
×
502
{
503
    if (index == volumeBarIndex())
×
504
        return m_volumeBar;
×
505
    if (index >= 0 && index < m_spectrumBars.size())
×
506
        return m_spectrumBars.at(index);
×
507

508
    return NULL;
×
509
}
510

511
QList<AudioBar *> VCAudioTriggers::getAudioBars()
×
512
{
513
    QList <AudioBar *> list;
×
514
    list.reserve(1 + m_spectrumBars.size());
×
515
    list.append(m_volumeBar);
×
516
    list.append(m_spectrumBars);
×
517

518
    return list;
×
519
}
×
520

521
void VCAudioTriggers::setSpectrumBarsNumber(int num)
×
522
{
523
    if (num > m_spectrumBars.count())
×
524
    {
525
        int barsToAdd = num - m_spectrumBars.count();
×
526
        for (int i = 0 ; i < barsToAdd; i++)
×
527
        {
528
            AudioBar *asb = new AudioBar(AudioBar::None, 0, id());
×
529
            m_spectrumBars.append(asb);
×
530
        }
531
    }
532
    else if (num < m_spectrumBars.count())
×
533
    {
534
        int barsToRemove = m_spectrumBars.count() - num;
×
535
        for (int i = 0 ; i < barsToRemove; i++)
×
536
            delete m_spectrumBars.takeLast();
×
537
    }
538

539
    if (m_spectrum != NULL)
×
540
        m_spectrum->setBarsNumber(num);
×
541
}
×
542

543
void VCAudioTriggers::setSpectrumBarType(int index, int type)
×
544
{
545
    if (index == volumeBarIndex())
×
546
    {
547
        m_volumeBar->setType(type);
×
548
        return;
×
549
    }
550
    if (index >= 0 && index < m_spectrumBars.size())
×
551
    {
552
        m_spectrumBars[index]->setType(type);
×
553
    }
554
}
555

556
void VCAudioTriggers::editProperties()
×
557
{
558
    // make a backup copy of the current bars
559
    AudioBar *tmpVolume = m_volumeBar->createCopy();
×
560
    QList <AudioBar *> tmpSpectrumBars;
×
561
    foreach (AudioBar *bar, m_spectrumBars)
×
562
        tmpSpectrumBars.append(bar->createCopy());
×
563
    int barsNumber = m_spectrumBars.count();
×
564

565
    AudioTriggersConfiguration atc(this, m_doc, barsNumber, AudioCapture::maxFrequency());
×
566

567
    if (atc.exec() == QDialog::Rejected)
×
568
    {
569
        // restore the previous bars backup
570
        delete m_volumeBar;
×
571
        m_volumeBar = tmpVolume;
×
572
        qDeleteAll(m_spectrumBars);
×
573
        m_spectrumBars.clear();
×
574
        foreach (AudioBar *bar, tmpSpectrumBars)
×
575
            m_spectrumBars.append(bar);
×
576
    }
577

578
    m_spectrum->setBarsNumber(m_spectrumBars.count());
×
579

580
    if (barsNumber != m_spectrumBars.count())
×
581
    {
582
        QSharedPointer<AudioCapture> capture(m_doc->audioInputCapture());
×
583
        bool captureIsNew = m_inputCapture != capture.data();
×
584
        m_inputCapture = capture.data();
×
585

586
        if (m_button->isChecked())
×
587
        {
588
            if (!captureIsNew)
×
589
                m_inputCapture->unregisterBandsNumber(barsNumber);
×
590

591
            m_inputCapture->registerBandsNumber(m_spectrumBars.count());
×
592

593
            if (captureIsNew)
×
594
            {
595
                connect(m_inputCapture, SIGNAL(dataProcessed(double*,int,double,quint32)),
×
596
                        this, SLOT(slotDisplaySpectrum(double*,int,double,quint32)));
597
                connect(m_inputCapture, SIGNAL(volumeChanged(qreal)),
×
598
                        this, SLOT(slotUpdateVolumeSlider(int)));
599
            }
600
        }
601
    }
×
602
}
×
603

604
void VCAudioTriggers::adjustIntensity(qreal val)
×
605
{
606
    VCWidget::adjustIntensity(val);
×
607
    slotVolumeChanged(m_volumeSlider->value());
×
608
}
×
609

610
/*********************************************************************
611
 * Load & Save
612
 *********************************************************************/
613

614
bool VCAudioTriggers::loadXML(QXmlStreamReader &root)
×
615
{
616
    if (root.name() != KXMLQLCVCAudioTriggers)
×
617
    {
618
        qWarning() << Q_FUNC_INFO << "Audio Triggers node not found";
×
619
        return false;
×
620
    }
621
    if (root.attributes().hasAttribute(KXMLQLCVCATBarsNumber))
×
622
    {
623
        int barsNum = root.attributes().value(KXMLQLCVCATBarsNumber).toString().toInt();
×
624
        setSpectrumBarsNumber(barsNum);
×
625
    }
626

627
    /* Widget commons */
628
    loadXMLCommon(root);
×
629

630
    /* Children */
631
    while (root.readNextStartElement())
×
632
    {
633
        //qDebug() << "VC Audio triggers tag:" << root.name();
634
        QXmlStreamAttributes attrs = root.attributes();
×
635

636
        if (root.name() == KXMLQLCWindowState)
×
637
        {
638
            int x = 0, y = 0, w = 0, h = 0;
×
639
            bool visible = false;
×
640
            loadXMLWindowState(root, &x, &y, &w, &h, &visible);
×
641
            setGeometry(x, y, w, h);
×
642
        }
643
        else if (root.name() == KXMLQLCVCWidgetAppearance)
×
644
        {
645
            loadXMLAppearance(root);
×
646
        }
647
        else if (root.name() == KXMLQLCVCWidgetInput)
×
648
        {
649
            loadXMLInput(root);
×
650
        }
651
        else if (root.name() == KXMLQLCVCATKey)
×
652
        {
653
            setKeySequence(stripKeySequence(QKeySequence(root.readElementText())));
×
654
        }
655
        else if (root.name() == KXMLQLCVolumeBar)
×
656
        {
657
            m_volumeBar->loadXML(root, m_doc);
×
658
        }
659
        else if (root.name() == KXMLQLCSpectrumBar)
×
660
        {
661
            if (attrs.hasAttribute(KXMLQLCAudioBarIndex))
×
662
            {
663
                int idx = attrs.value(KXMLQLCAudioBarIndex).toString().toInt();
×
664
                if (idx >= 0 && idx < m_spectrumBars.count())
×
665
                    m_spectrumBars[idx]->loadXML(root, m_doc);
×
666
            }
667
        }
668
        else
669
        {
670
            qWarning() << Q_FUNC_INFO << "Unknown audio triggers tag:" << root.name().toString();
×
671
            root.skipCurrentElement();
×
672
        }
673
    }
×
674

675
    return true;
×
676
}
677

678
bool VCAudioTriggers::saveXML(QXmlStreamWriter *doc)
×
679
{
680
    Q_ASSERT(doc != NULL);
×
681

682
    /* VC button entry */
683
    doc->writeStartElement(KXMLQLCVCAudioTriggers);
×
684
    doc->writeAttribute(KXMLQLCVCATBarsNumber, QString::number(m_spectrumBars.count()));
×
685

686
    saveXMLCommon(doc);
×
687

688
    /* Window state */
689
    saveXMLWindowState(doc);
×
690

691
    /* Appearance */
692
    saveXMLAppearance(doc);
×
693

694
    /* Key sequence */
695
    if (m_keySequence.isEmpty() == false)
×
696
        doc->writeTextElement(KXMLQLCVCATKey, m_keySequence.toString());
×
697

698
    /* External input */
699
    saveXMLInput(doc);
×
700

701
    /* Lookup for any assigned bar */
702
    bool hasAssignment = false;
×
703
    if (m_volumeBar->m_type != AudioBar::None)
×
704
        hasAssignment = true;
×
705
    else
706
    {
707
        foreach (AudioBar *bar, m_spectrumBars)
×
708
        {
709
            if (bar->m_type != AudioBar::None)
×
710
            {
711
                hasAssignment = true;
×
712
                break;
×
713
            }
714
        }
×
715
    }
716

717
    if (hasAssignment == false)
×
718
    {
719
        /* End the <AudioTriggers> tag */
720
        doc->writeEndElement();
×
721
        return false;
×
722
    }
723

724
    if (m_volumeBar->m_type != AudioBar::None)
×
725
    {
726
        m_volumeBar->saveXML(doc, KXMLQLCVolumeBar, volumeBarIndex());
×
727
    }
728
    int idx = 0;
×
729
    foreach (AudioBar *bar, m_spectrumBars)
×
730
    {
731
        if (bar->m_type != AudioBar::None)
×
732
            bar->saveXML(doc, KXMLQLCSpectrumBar, idx);
×
733
        idx++;
×
734
    }
×
735

736
    /* End the <AudioTriggers> tag */
737
    doc->writeEndElement();
×
738

739
    return true;
×
740
}
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