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

mcallegari / qlcplus / 27867971263

20 Jun 2026 10:09AM UTC coverage: 35.268% (-0.1%) from 35.377%
27867971263

push

github

mcallegari
Back to 5.3.0 debug

18433 of 52265 relevant lines covered (35.27%)

41250.48 hits per line

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

0.0
/ui/src/audioeditor.cpp
1
/*
2
  Q Light Controller Plus
3
  audioeditor.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 <QFileDialog>
21
#include <QLineEdit>
22
#include <QSettings>
23
#include <QLabel>
24
#include <QDebug>
25
#include <QUrl>
26

27
#include "audioplugincache.h"
28
#include "speeddialwidget.h"
29
#include "audiodecoder.h"
30
#include "audioeditor.h"
31
#include "audio.h"
32
#include "doc.h"
33

34
AudioEditor::AudioEditor(QWidget* parent, Audio *audio, Doc* doc)
×
35
    : QWidget(parent)
36
    , m_doc(doc)
×
37
    , m_audio(audio)
×
38
    , m_speedDials(NULL)
×
39
{
40
    Q_ASSERT(doc != NULL);
×
41
    Q_ASSERT(audio != NULL);
×
42

43
    setupUi(this);
×
44

45
    m_nameEdit->setText(m_audio->name());
×
46
    m_nameEdit->setSelection(0, m_nameEdit->text().length());
×
47

48
    m_fadeInEdit->setText(Function::speedToString(audio->fadeInSpeed()));
×
49
    m_fadeOutEdit->setText(Function::speedToString(audio->fadeOutSpeed()));
×
50
    m_volumeSpin->setValue(m_audio->volume() * 100);
×
51

52
    connect(m_nameEdit, SIGNAL(textEdited(const QString&)),
×
53
            this, SLOT(slotNameEdited(const QString&)));
54
    connect(m_fileButton, SIGNAL(clicked()),
×
55
            this, SLOT(slotSourceFileClicked()));
56

57
    connect(m_volumeSpin, SIGNAL(valueChanged(int)),
×
58
            this, SLOT(slotVolumeChanged(int)));
59

60
    connect(m_speedDialButton, SIGNAL(toggled(bool)),
×
61
            this, SLOT(slotSpeedDialToggle(bool)));
62

63
    connect(m_fadeInEdit, SIGNAL(editingFinished()),
×
64
            this, SLOT(slotFadeInEdited()));
65
    connect(m_fadeOutEdit, SIGNAL(editingFinished()),
×
66
            this, SLOT(slotFadeOutEdited()));
67

68
    connect(m_previewButton, SIGNAL(toggled(bool)),
×
69
            this, SLOT(slotPreviewToggled(bool)));
70

71
    AudioDecoder *adec = m_audio->getAudioDecoder();
×
72

73
    m_filenameLabel->setText(m_audio->getSourceFileName());
×
74
    if (adec != NULL)
×
75
    {
76
        AudioParameters ap = adec->audioParameters();
×
77
        m_durationLabel->setText(Function::speedToString(m_audio->totalDuration()));
×
78
        m_srateLabel->setText(QString("%1 Hz").arg(ap.sampleRate()));
×
79
        m_channelsLabel->setText(QString("%1").arg(ap.channels()));
×
80
        m_bitrateLabel->setText(QString("%1 kb/s").arg(adec->bitrate()));
×
81
    }
82

83
    QList<AudioDeviceInfo> devList = m_doc->audioPluginCache()->audioDevicesList();
×
84
    QSettings settings;
×
85
    QString outputName;
×
86
    int i = 1, selIdx = 0;
×
87

88
    m_audioDevCombo->addItem(tr("Default device"), "__qlcplusdefault__");
×
89
    if (m_audio->audioDevice().isEmpty())
×
90
    {
91
        QVariant var = settings.value(SETTINGS_AUDIO_OUTPUT_DEVICE);
×
92
        if (var.isValid() == true)
×
93
            outputName = var.toString();
×
94
    }
×
95
    else
96
    {
97
        outputName = m_audio->audioDevice();
×
98
    }
99

100
    foreach (AudioDeviceInfo info, devList)
×
101
    {
102
        if (info.capabilities & AUDIO_CAP_OUTPUT)
×
103
        {
104
            m_audioDevCombo->addItem(info.deviceName, info.privateName);
×
105

106
            if (info.privateName == outputName)
×
107
                selIdx = i;
×
108
            i++;
×
109
        }
110
    }
×
111
    m_audioDevCombo->setCurrentIndex(selIdx);
×
112
    connect(m_audioDevCombo, SIGNAL(currentIndexChanged(int)),
×
113
            this, SLOT(slotAudioDeviceChanged(int)));
114

115
    if (m_audio->runOrder() == Audio::Loop)
×
116
        m_loopCheck->setChecked(true);
×
117
    else
118
        m_singleCheck->setChecked(true);
×
119

120
    connect(m_loopCheck, SIGNAL(clicked()),
×
121
            this, SLOT(slotLoopCheckClicked()));
122
    connect(m_singleCheck, SIGNAL(clicked()),
×
123
            this, SLOT(slotSingleShotCheckClicked()));
124

125
    // Set focus to the editor
126
    m_nameEdit->setFocus();
×
127
}
×
128

129
AudioEditor::~AudioEditor()
×
130
{
131
    if (m_previewButton->isChecked())
×
132
        m_audio->stop(functionParent());
×
133
}
×
134

135
void AudioEditor::slotNameEdited(const QString& text)
×
136
{
137
    m_audio->setName(text);
×
138
    m_doc->setModified();
×
139
}
×
140

141
void AudioEditor::slotSourceFileClicked()
×
142
{
143
    QString fn;
×
144

145
    /* Create a file open dialog */
146
    QFileDialog dialog(this);
×
147
    dialog.setWindowTitle(tr("Open Audio File"));
×
148
    dialog.setAcceptMode(QFileDialog::AcceptOpen);
×
149

150
    /* Append file filters to the dialog */
151
    QStringList extList = m_doc->audioPluginCache()->getSupportedFormats();
×
152

153
    QStringList filters;
×
154
    qDebug() << Q_FUNC_INFO << "Extensions: " << extList.join(" ");
×
155
    filters << tr("Audio Files (%1)").arg(extList.join(" "));
×
156
#if defined(WIN32) || defined(Q_OS_WIN)
157
    filters << tr("All Files (*.*)");
158
#else
159
    filters << tr("All Files (*)");
×
160
#endif
161
    dialog.setNameFilters(filters);
×
162

163
    /* Append useful URLs to the dialog */
164
    QList <QUrl> sidebar;
×
165
    sidebar.append(QUrl::fromLocalFile(QDir::homePath()));
×
166
    sidebar.append(QUrl::fromLocalFile(QDir::rootPath()));
×
167
    dialog.setSidebarUrls(sidebar);
×
168

169
    /* Get file name */
170
    if (dialog.exec() != QDialog::Accepted)
×
171
        return;
×
172

173
    fn = dialog.selectedFiles().first();
×
174
    if (fn.isEmpty() == true)
×
175
        return;
×
176

177
    if (m_audio->isRunning())
×
178
        m_audio->stopAndWait();
×
179

180
    m_audio->setSourceFileName(fn);
×
181
    m_filenameLabel->setText(m_audio->getSourceFileName());
×
182

183
    AudioDecoder *adec = m_audio->getAudioDecoder();
×
184
    if (adec != NULL)
×
185
    {
186
        AudioParameters ap = adec->audioParameters();
×
187
        m_durationLabel->setText(Function::speedToString(m_audio->totalDuration()));
×
188
        m_srateLabel->setText(QString("%1 Hz").arg(ap.sampleRate()));
×
189
        m_channelsLabel->setText(QString("%1").arg(ap.channels()));
×
190
        m_bitrateLabel->setText(QString("%1 kb/s").arg(adec->bitrate()));
×
191
    }
192
}
×
193

194
void AudioEditor::slotVolumeChanged(int value)
×
195
{
196
    m_audio->setVolume(qreal(value) / 100.0);
×
197
}
×
198

199
void AudioEditor::slotFadeInEdited()
×
200
{
201
    uint newValue;
202
    QString text = m_fadeInEdit->text();
×
203

204
    newValue = Function::stringToSpeed(text);
×
205
    m_fadeInEdit->setText(Function::speedToString(newValue));
×
206

207
    if (m_audio->fadeInSpeed() == newValue)
×
208
        return;
×
209

210
    m_audio->setFadeInSpeed(newValue);
×
211
    m_doc->setModified();
×
212
}
×
213

214
void AudioEditor::slotFadeOutEdited()
×
215
{
216
    uint newValue;
217
    QString text = m_fadeOutEdit->text();
×
218

219
    newValue = Function::stringToSpeed(text);
×
220
    m_fadeOutEdit->setText(Function::speedToString(newValue));
×
221

222
    if (m_audio->fadeOutSpeed() == newValue)
×
223
        return;
×
224

225
    m_audio->setFadeOutSpeed(newValue);
×
226
    m_doc->setModified();
×
227
}
×
228

229
void AudioEditor::slotAudioDeviceChanged(int idx)
×
230
{
231
    QString audioDev = m_audioDevCombo->itemData(idx).toString();
×
232
    qDebug() << "New audio device selected:" << audioDev;
×
233
    if (audioDev == "__qlcplusdefault__")
×
234
        m_audio->setAudioDevice(QString());
×
235
    else
236
        m_audio->setAudioDevice(audioDev);
×
237
}
×
238

239
void AudioEditor::slotPreviewToggled(bool state)
×
240
{
241
    if (state == true)
×
242
    {
243
        m_audio->start(m_doc->masterTimer(), functionParent());
×
244
        connect(m_audio, SIGNAL(stopped(quint32)),
×
245
                this, SLOT(slotPreviewStopped(quint32)));
246
    }
247
    else
248
        m_audio->stop(functionParent());
×
249
}
×
250

251
void AudioEditor::slotPreviewStopped(quint32 id)
×
252
{
253
    if (id == m_audio->id())
×
254
        m_previewButton->setChecked(false);
×
255
}
×
256

257
void AudioEditor::slotSingleShotCheckClicked()
×
258
{
259
    m_audio->setRunOrder(Audio::SingleShot);
×
260
}
×
261

262
void AudioEditor::slotLoopCheckClicked()
×
263
{
264
    m_audio->setRunOrder(Audio::Loop);
×
265
}
×
266

267
FunctionParent AudioEditor::functionParent() const
×
268
{
269
    return FunctionParent::master();
×
270
}
271

272
/************************************************************************
273
 * Speed dials
274
 ************************************************************************/
275

276
void AudioEditor::createSpeedDials()
×
277
{
278
    if (m_speedDials != NULL)
×
279
        return;
×
280

281
    m_speedDials = new SpeedDialWidget(this);
×
282
    m_speedDials->setAttribute(Qt::WA_DeleteOnClose);
×
283
    m_speedDials->setWindowTitle(m_audio->name());
×
284
    m_speedDials->setFadeInSpeed(m_audio->fadeInSpeed());
×
285
    m_speedDials->setFadeOutSpeed(m_audio->fadeOutSpeed());
×
286
    m_speedDials->setDurationEnabled(false);
×
287
    m_speedDials->setDurationVisible(false);
×
288
    connect(m_speedDials, SIGNAL(fadeInChanged(int)), this, SLOT(slotFadeInDialChanged(int)));
×
289
    connect(m_speedDials, SIGNAL(fadeOutChanged(int)), this, SLOT(slotFadeOutDialChanged(int)));
×
290
    connect(m_speedDials, SIGNAL(destroyed(QObject*)), this, SLOT(slotDialDestroyed(QObject*)));
×
291
    m_speedDials->show();
×
292
}
293

294
void AudioEditor::slotSpeedDialToggle(bool state)
×
295
{
296
    if (state == true)
×
297
        createSpeedDials();
×
298
    else
299
    {
300
        if (m_speedDials != NULL)
×
301
            m_speedDials->deleteLater();
×
302
        m_speedDials = NULL;
×
303
    }
304
}
×
305

306
void AudioEditor::slotFadeInDialChanged(int ms)
×
307
{
308
    m_fadeInEdit->setText(Function::speedToString(ms));
×
309
    m_audio->setFadeInSpeed(ms);
×
310
}
×
311

312
void AudioEditor::slotFadeOutDialChanged(int ms)
×
313
{
314
    m_fadeOutEdit->setText(Function::speedToString(ms));
×
315
    m_audio->setFadeOutSpeed(ms);
×
316
}
×
317

318
void AudioEditor::slotDialDestroyed(QObject *)
×
319
{
320
    m_speedDialButton->setChecked(false);
×
321
}
×
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