• 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/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(returnPressed()),
×
64
            this, SLOT(slotFadeInEdited()));
65
    connect(m_fadeOutEdit, SIGNAL(returnPressed()),
×
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
    m_audio->setFadeInSpeed(newValue);
×
208
    m_doc->setModified();
×
209
}
×
210

211
void AudioEditor::slotFadeOutEdited()
×
212
{
213
    uint newValue;
214
    QString text = m_fadeOutEdit->text();
×
215

216
    newValue = Function::stringToSpeed(text);
×
217
    m_fadeOutEdit->setText(Function::speedToString(newValue));
×
218

219
    m_audio->setFadeOutSpeed(newValue);
×
220
    m_doc->setModified();
×
221
}
×
222

223
void AudioEditor::slotAudioDeviceChanged(int idx)
×
224
{
225
    QString audioDev = m_audioDevCombo->itemData(idx).toString();
×
226
    qDebug() << "New audio device selected:" << audioDev;
227
    if (audioDev == "__qlcplusdefault__")
×
228
        m_audio->setAudioDevice(QString());
×
229
    else
230
        m_audio->setAudioDevice(audioDev);
×
231
}
×
232

233
void AudioEditor::slotPreviewToggled(bool state)
×
234
{
235
    if (state == true)
×
236
    {
237
        m_audio->start(m_doc->masterTimer(), functionParent());
×
238
        connect(m_audio, SIGNAL(stopped(quint32)),
×
239
                this, SLOT(slotPreviewStopped(quint32)));
240
    }
241
    else
242
        m_audio->stop(functionParent());
×
243
}
×
244

245
void AudioEditor::slotPreviewStopped(quint32 id)
×
246
{
247
    if (id == m_audio->id())
×
248
        m_previewButton->setChecked(false);
×
249
}
×
250

251
void AudioEditor::slotSingleShotCheckClicked()
×
252
{
253
    m_audio->setRunOrder(Audio::SingleShot);
×
254
}
×
255

256
void AudioEditor::slotLoopCheckClicked()
×
257
{
258
    m_audio->setRunOrder(Audio::Loop);
×
259
}
×
260

261
FunctionParent AudioEditor::functionParent() const
×
262
{
263
    return FunctionParent::master();
×
264
}
265

266
/************************************************************************
267
 * Speed dials
268
 ************************************************************************/
269

270
void AudioEditor::createSpeedDials()
×
271
{
272
    if (m_speedDials != NULL)
×
273
        return;
274

275
    m_speedDials = new SpeedDialWidget(this);
×
276
    m_speedDials->setAttribute(Qt::WA_DeleteOnClose);
×
277
    m_speedDials->setWindowTitle(m_audio->name());
×
278
    m_speedDials->setFadeInSpeed(m_audio->fadeInSpeed());
×
279
    m_speedDials->setFadeOutSpeed(m_audio->fadeOutSpeed());
×
280
    m_speedDials->setDurationEnabled(false);
×
281
    m_speedDials->setDurationVisible(false);
×
282
    connect(m_speedDials, SIGNAL(fadeInChanged(int)), this, SLOT(slotFadeInDialChanged(int)));
×
283
    connect(m_speedDials, SIGNAL(fadeOutChanged(int)), this, SLOT(slotFadeOutDialChanged(int)));
×
284
    connect(m_speedDials, SIGNAL(destroyed(QObject*)), this, SLOT(slotDialDestroyed(QObject*)));
×
285
    m_speedDials->show();
×
286
}
287

288
void AudioEditor::slotSpeedDialToggle(bool state)
×
289
{
290
    if (state == true)
×
291
        createSpeedDials();
×
292
    else
293
    {
294
        if (m_speedDials != NULL)
×
295
            m_speedDials->deleteLater();
×
296
        m_speedDials = NULL;
×
297
    }
298
}
×
299

300
void AudioEditor::slotFadeInDialChanged(int ms)
×
301
{
302
    m_fadeInEdit->setText(Function::speedToString(ms));
×
303
    m_audio->setFadeInSpeed(ms);
×
304
}
×
305

306
void AudioEditor::slotFadeOutDialChanged(int ms)
×
307
{
308
    m_fadeOutEdit->setText(Function::speedToString(ms));
×
309
    m_audio->setFadeOutSpeed(ms);
×
310
}
×
311

312
void AudioEditor::slotDialDestroyed(QObject *)
×
313
{
314
    m_speedDialButton->setChecked(false);
×
315
}
×
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

© 2025 Coveralls, Inc