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

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 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          QString("Key")
38
#define KXMLQLCVCATBarsNumber   QString("BarsNumber")
39

40
#define KXMLQLCVolumeBar    QString("VolumeBar")
41
#define KXMLQLCSpectrumBar  QString("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
    for (int i = 0; i < m_inputCapture->defaultBarsNumber(); i++)
×
111
    {
112
        AudioBar *asb = new AudioBar(AudioBar::None, 0, id());
×
113
        m_spectrumBars.append(asb);
×
114
    }
115

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

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

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

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

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

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

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

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

156
void VCAudioTriggers::enableWidgetUI(bool enable)
×
157
{
158
    if (m_button)
×
159
        m_button->setEnabled(enable);
×
160

161
    m_volumeSlider->setEnabled(enable);
×
162
}
×
163

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

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

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

188
        m_button->blockSignals(true);
×
189
        m_button->setChecked(true);
×
190
        m_button->blockSignals(false);
×
191

192
        emit captureEnabled(true);
×
193

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

208
        m_button->blockSignals(true);
×
209
        m_button->setChecked(false);
×
210
        m_button->blockSignals(false);
×
211

212
        emit captureEnabled(false);
×
213
    }
214
}
×
215

216
void VCAudioTriggers::toggleEnableButton(bool toggle)
×
217
{
218
    if (mode() == Doc::Design)
×
219
        return;
220

221
    if (m_button)
×
222
        m_button->setChecked(toggle);
×
223
}
224

225
void VCAudioTriggers::slotEnableButtonToggled(bool toggle)
×
226
{
227
    if (mode() == Doc::Design)
×
228
        return;
229

230
    enableCapture(toggle);
×
231
    updateFeedback();
×
232
}
233

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

241
    m_spectrum->displaySpectrum(spectrumBands, maxMagnitude, power);
×
242
    m_volumeBar->m_value = m_spectrum->getUcharVolume();
×
243

244
    if (mode() == Doc::Design)
×
245
        return;
246

247
    if (m_volumeBar->m_type == AudioBar::FunctionBar)
×
248
        m_volumeBar->checkFunctionThresholds(m_doc);
×
249
    else if (m_volumeBar->m_type == AudioBar::VCWidgetBar)
×
250
        m_volumeBar->checkWidgetFunctionality();
×
251

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

262
void VCAudioTriggers::slotVolumeChanged(int volume)
×
263
{
264
    m_doc->audioInputCapture()->setVolume(intensity() * qreal(volume) / 100.0);
×
265
}
×
266

267
void VCAudioTriggers::slotUpdateVolumeSlider(int volume)
×
268
{
269
    m_volumeSlider->setValue(volume);
×
270
}
×
271

272
/*********************************************************************
273
 * DMXSource
274
 *********************************************************************/
275

276
void VCAudioTriggers::writeDMX(MasterTimer *timer, QList<Universe *> universes)
×
277
{
278
    Q_UNUSED(timer);
279

280
    if (mode() == Doc::Design)
×
281
        return;
×
282

283
    quint32 lastUniverse = Universe::invalid();
284
    QSharedPointer<GenericFader> fader;
×
285

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

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

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

345
/*********************************************************************
346
 * Key sequence handler
347
 *********************************************************************/
348

349
void VCAudioTriggers::setKeySequence(const QKeySequence& keySequence)
×
350
{
351
    m_keySequence = QKeySequence(keySequence);
×
352
}
×
353

354
QKeySequence VCAudioTriggers::keySequence() const
×
355
{
356
    return m_keySequence;
×
357
}
358

359
void VCAudioTriggers::slotKeyPressed(const QKeySequence& keySequence)
×
360
{
361
    if (acceptsInput() == false)
×
362
        return;
363

364
    if (m_keySequence == keySequence)
×
365
    {
366
        if (m_button->isChecked())
×
367
            slotEnableButtonToggled(false);
×
368
        else
369
            slotEnableButtonToggled(true);
×
370
    }
371
}
372

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

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

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

400
/*********************************************************************
401
 * Clipboard
402
 *********************************************************************/
403

404
VCWidget *VCAudioTriggers::createCopy(VCWidget *parent)
×
405
{
406
    Q_ASSERT(parent != NULL);
407

408
    VCAudioTriggers* triggers = new VCAudioTriggers(parent, m_doc);
×
409
    if (triggers->copyFrom(this) == false)
×
410
    {
411
        delete triggers;
×
412
        triggers = NULL;
413
    }
414

415
    return triggers;
×
416
}
417

418
bool VCAudioTriggers::copyFrom(const VCWidget *widget)
×
419
{
420
    const VCAudioTriggers* triggers = qobject_cast <const VCAudioTriggers*> (widget);
421
    if (triggers == NULL)
×
422
        return false;
423

424
    /* TODO: Copy triggers-specific stuff */
425

426
    /* Copy common stuff */
427
    return VCWidget::copyFrom(widget);
×
428
}
429

430
/*************************************************************************
431
 * VCWidget-inherited
432
 *************************************************************************/
433

434
void VCAudioTriggers::setCaption(const QString &text)
×
435
{
436
    if (m_label != NULL)
×
437
        m_label->setText(text);
×
438

439
    VCWidget::setCaption(text);
×
440
}
×
441

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

453
QColor VCAudioTriggers::foregroundColor() const
×
454
{
455
    if (m_label != NULL)
×
456
        return m_label->palette().color(m_label->foregroundRole());
×
457
    else
458
        return VCWidget::foregroundColor();
×
459
}
460

461
void VCAudioTriggers::slotModeChanged(Doc::Mode mode)
×
462
{
463
    if (mode == Doc::Operate)
×
464
    {
465
        enableWidgetUI(true);
×
466

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

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

493
/*************************************************************************
494
 * Configuration
495
 *************************************************************************/
496

497
AudioBar *VCAudioTriggers::getSpectrumBar(int index)
×
498
{
499
    if (index == volumeBarIndex())
×
500
        return m_volumeBar;
×
501
    if (index >= 0 && index < m_spectrumBars.size())
×
502
        return m_spectrumBars.at(index);
×
503

504
    return NULL;
505
}
506

507
QList<AudioBar *> VCAudioTriggers::getAudioBars()
×
508
{
509
    QList <AudioBar *> list;
510
    list.append(m_volumeBar);
×
511
    list.append(m_spectrumBars);
×
512

513
    return list;
×
514
}
×
515

516
void VCAudioTriggers::setSpectrumBarsNumber(int num)
×
517
{
518
    if (num > m_spectrumBars.count())
×
519
    {
520
        int barsToAdd = num - m_spectrumBars.count();
×
521
        for (int i = 0 ; i < barsToAdd; i++)
×
522
        {
523
            AudioBar *asb = new AudioBar(AudioBar::None, 0, id());
×
524
            m_spectrumBars.append(asb);
×
525
        }
526
    }
527
    else if (num < m_spectrumBars.count())
×
528
    {
529
        int barsToRemove = m_spectrumBars.count() - num;
×
530
        for (int i = 0 ; i < barsToRemove; i++)
×
531
            m_spectrumBars.removeLast();
×
532
    }
533

534
    if (m_spectrum != NULL)
×
535
        m_spectrum->setBarsNumber(num);
×
536
}
×
537

538
void VCAudioTriggers::setSpectrumBarType(int index, int type)
×
539
{
540
    if (index == volumeBarIndex())
×
541
    {
542
        m_volumeBar->setType(type);
×
543
        return;
×
544
    }
545
    if (index >= 0 && index < m_spectrumBars.size())
×
546
    {
547
        m_spectrumBars[index]->setType(type);
×
548
    }
549
}
550

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

560
    AudioTriggersConfiguration atc(this, m_doc, barsNumber, AudioCapture::maxFrequency());
×
561

562
    if (atc.exec() == QDialog::Rejected)
×
563
    {
564
        // restore the previous bars backup
565
        delete m_volumeBar;
×
566
        m_volumeBar = tmpVolume;
×
567
        m_spectrumBars.clear();
×
568
        foreach (AudioBar *bar, tmpSpectrumBars)
×
569
            m_spectrumBars.append(bar);
×
570
    }
571

572
    m_spectrum->setBarsNumber(m_spectrumBars.count());
×
573

574
    if (barsNumber != m_spectrumBars.count())
×
575
    {
576
        QSharedPointer<AudioCapture> capture(m_doc->audioInputCapture());
×
577
        bool captureIsNew = m_inputCapture != capture.data();
×
578
        m_inputCapture = capture.data();
×
579

580
        if (m_button->isChecked())
×
581
        {
582
            if (!captureIsNew)
×
583
                m_inputCapture->unregisterBandsNumber(barsNumber);
×
584

585
            m_inputCapture->registerBandsNumber(m_spectrumBars.count());
×
586

587
            if (captureIsNew)
×
588
            {
589
                connect(m_inputCapture, SIGNAL(dataProcessed(double*,int,double,quint32)),
×
590
                        this, SLOT(slotDisplaySpectrum(double*,int,double,quint32)));
591
                connect(m_inputCapture, SIGNAL(volumeChanged(qreal)),
×
592
                        this, SLOT(slotUpdateVolumeSlider(int)));
593
            }
594
        }
595
    }
596
}
×
597

598
void VCAudioTriggers::adjustIntensity(qreal val)
×
599
{
600
    VCWidget::adjustIntensity(val);
×
601
    slotVolumeChanged(m_volumeSlider->value());
×
602
}
×
603

604
/*********************************************************************
605
 * Load & Save
606
 *********************************************************************/
607

608
bool VCAudioTriggers::loadXML(QXmlStreamReader &root)
×
609
{
610
    if (root.name() != KXMLQLCVCAudioTriggers)
×
611
    {
612
        qWarning() << Q_FUNC_INFO << "Audio Triggers node not found";
×
613
        return false;
×
614
    }
615
    if (root.attributes().hasAttribute(KXMLQLCVCATBarsNumber))
×
616
    {
617
        int barsNum = root.attributes().value(KXMLQLCVCATBarsNumber).toString().toInt();
×
618
        setSpectrumBarsNumber(barsNum);
×
619
    }
620

621
    /* Widget commons */
622
    loadXMLCommon(root);
×
623

624
    /* Children */
625
    while (root.readNextStartElement())
×
626
    {
627
        //qDebug() << "VC Audio triggers tag:" << root.name();
628
        QXmlStreamAttributes attrs = root.attributes();
×
629

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

669
    return true;
670
}
671

672
bool VCAudioTriggers::saveXML(QXmlStreamWriter *doc)
×
673
{
674
    Q_ASSERT(doc != NULL);
675

676
    /* VC button entry */
677
    doc->writeStartElement(KXMLQLCVCAudioTriggers);
×
678
    doc->writeAttribute(KXMLQLCVCATBarsNumber, QString::number(m_spectrumBars.count()));
×
679

680
    saveXMLCommon(doc);
×
681

682
    /* Window state */
683
    saveXMLWindowState(doc);
×
684

685
    /* Appearance */
686
    saveXMLAppearance(doc);
×
687

688
    /* Key sequence */
689
    if (m_keySequence.isEmpty() == false)
×
690
        doc->writeTextElement(KXMLQLCVCATKey, m_keySequence.toString());
×
691

692
    /* External input */
693
    saveXMLInput(doc);
×
694

695
    /* Lookup for any assigned bar */
696
    bool hasAssignment = false;
697
    if (m_volumeBar->m_type != AudioBar::None)
×
698
        hasAssignment = true;
699
    else
700
    {
701
        foreach (AudioBar *bar, m_spectrumBars)
×
702
        {
703
            if (bar->m_type != AudioBar::None)
×
704
            {
705
                hasAssignment = true;
706
                break;
707
            }
708
        }
709
    }
710

711
    if (hasAssignment == false)
×
712
    {
713
        /* End the <AudioTriggers> tag */
714
        doc->writeEndElement();
×
715
        return false;
×
716
    }
717

718
    if (m_volumeBar->m_type != AudioBar::None)
×
719
    {
720
        m_volumeBar->saveXML(doc, KXMLQLCVolumeBar, volumeBarIndex());
×
721
    }
722
    int idx = 0;
723
    foreach (AudioBar *bar, m_spectrumBars)
×
724
    {
725
        if (bar->m_type != AudioBar::None)
×
726
            bar->saveXML(doc, KXMLQLCSpectrumBar, idx);
×
727
        idx++;
×
728
    }
729

730
    /* End the <AudioTriggers> tag */
731
    doc->writeEndElement();
×
732

733
    return true;
×
734
}
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