• 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/inputchanneleditor.cpp
1
/*
2
  Q Light Controller
3
  inputchanneleditor.cpp
4

5
  Copyright (C) Heikki Junnila
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 <QLineEdit>
21
#include <QComboBox>
22
#include <QSpinBox>
23
#include <QIcon>
24
#include <QAction>
25
#include <QSettings>
26

27
#include "inputchanneleditor.h"
28
#include "qlcinputprofile.h"
29
#include "qlcinputchannel.h"
30
#include "qlcchannel.h"
31

32
#define KMidiMessageCC                  0
33
#define KMidiMessageNoteOnOff           1
34
#define KMidiMessageNoteAftertouch      2
35
#define KMidiMessagePC                  3
36
#define KMidiMessageChannelAftertouch   4
37
#define KMidiMessagePitchWheel          5
38
#define KMidiMessageMBCPlayback         6
39
#define KMidiMessageMBCBeat             7
40
#define KMidiMessageMBCStop             8
41

42
#define KMidiChannelOffset 4096
43

44
#include "../../plugins/midi/src/common/midiprotocol.h"
45

46
#define SETTINGS_GEOMETRY "inputchanneleditor/geometry"
47

48
/****************************************************************************
49
 * Initialization
50
 ****************************************************************************/
51

52
InputChannelEditor::InputChannelEditor(QWidget* parent,
×
53
                                       const QLCInputProfile* profile,
54
                                       const QLCInputChannel* channel,
55
                                       QLCInputProfile::Type profileType)
×
56
        : QDialog(parent)
×
57
{
58
    m_channel = 0;
×
59
    m_type = QLCInputChannel::NoType;
×
60

61
    setupUi(this);
×
62

63
    QAction* action = new QAction(this);
×
64
    action->setShortcut(QKeySequence(QKeySequence::Close));
×
65
    connect(action, SIGNAL(triggered(bool)), this, SLOT(reject()));
×
66
    addAction(action);
×
67

68
    QSettings settings;
×
69
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
×
70
    if (geometrySettings.isValid() == true)
×
71
        restoreGeometry(geometrySettings.toByteArray());
×
72

73
    /* Connect to these already now so that the handlers get called
74
       during initialization. */
75
    connect(m_numberSpin, SIGNAL(valueChanged(int)),
×
76
            this, SLOT(slotNumberChanged(int)));
77
    connect(m_nameEdit, SIGNAL(textEdited(const QString&)),
×
78
            this, SLOT(slotNameEdited(const QString&)));
79
    connect(m_typeCombo, SIGNAL(activated(int)),
×
80
            this, SLOT(slotTypeActivated(int)));
81

82
    /* Fill type combo with type icons and names */
83
    QStringListIterator it(QLCInputChannel::types());
×
84
    while (it.hasNext() == true)
×
85
    {
86
        QString str(it.next());
87
        m_typeCombo->addItem(QLCInputChannel::stringToIcon(str), str);
×
88
    }
×
89

90
    if (channel != NULL && profile != NULL)
×
91
    {
92
        QString type;
93
        quint32 num;
94

95
        /* Channel number */
96
        num = profile->channelNumber(channel);
×
97
        if (num != QLCChannel::invalid())
×
98
            m_numberSpin->setValue(num + 1);
×
99
        else
100
            m_numberSpin->setValue(1);
×
101

102
        /* Channel name */
103
        m_nameEdit->setText(channel->name());
×
104

105
        /* Channel type */
106
        m_type = channel->type();
×
107
        type = QLCInputChannel::typeToString(channel->type());
×
108
        m_typeCombo->setCurrentIndex(m_typeCombo->findText(type));
×
109

110
        if (profileType == QLCInputProfile::MIDI)
×
111
        {
112
            slotNumberChanged(m_numberSpin->value());
×
113

114
            connect(m_midiChannelSpin, SIGNAL(valueChanged(int)),
×
115
                this, SLOT(slotMidiChanged()));
116
            connect(m_midiMessageCombo, SIGNAL(activated(int)),
×
117
                this, SLOT(slotMidiChanged()));
118
            connect(m_midiParamSpin, SIGNAL(valueChanged(int)),
×
119
                this, SLOT(slotMidiChanged()));
120
        }
121
        else
122
        {
123
            m_midiGroup->hide();
×
124
            adjustSize();
×
125
        }
126
    }
×
127
    else
128
    {
129
        /* Multiple channels are being edited. Disable the channel
130
           number spin. */
131
        m_numberSpin->setEnabled(false);
×
132
        m_midiGroup->hide();
×
133
        adjustSize();
×
134
    }
135
}
×
136

137
InputChannelEditor::~InputChannelEditor()
×
138
{
139
    QSettings settings;
×
140
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
×
141
}
×
142

143
/****************************************************************************
144
 * Properties
145
 ****************************************************************************/
146

147
quint32 InputChannelEditor::channel() const
×
148
{
149
    return m_channel;
×
150
}
151

152
QString InputChannelEditor::name() const
×
153
{
154
    return m_name;
×
155
}
156

157
QLCInputChannel::Type InputChannelEditor::type() const
×
158
{
159
    return m_type;
×
160
}
161

162
void InputChannelEditor::slotNumberChanged(int number)
×
163
{
164
    m_channel = number - 1;
×
165

166
    int midiChannel = 0;
×
167
    int midiMessage = 0;
×
168
    int midiParam = 0;
×
169

170
    numberToMidi(m_channel, midiChannel, midiMessage, midiParam);
×
171

172
    m_midiChannelSpin->setValue(midiChannel);
×
173
    m_midiMessageCombo->setCurrentIndex(midiMessage);
×
174
    if (midiParam >= 0)
×
175
        m_midiParamSpin->setValue(midiParam);
×
176

177
    enableMidiParam(midiMessage, midiParam);
×
178
}
×
179

180
void InputChannelEditor::slotNameEdited(const QString& text)
×
181
{
182
    m_name = text;
×
183
}
×
184

185
void InputChannelEditor::slotTypeActivated(int index)
×
186
{
187
    m_type = QLCInputChannel::stringToType(m_typeCombo->itemText(index));
×
188
}
×
189

190
/****************************************************************************
191
 * MIDI
192
 ****************************************************************************/
193

194
void InputChannelEditor::numberToMidi(int number, int & channel, int & message, int & param)
×
195
{
196
    channel = number / KMidiChannelOffset + 1;
×
197
    number = number % KMidiChannelOffset;
×
198
    param = -1;
×
199
    if (number <= CHANNEL_OFFSET_CONTROL_CHANGE_MAX)
×
200
    {
201
        message = KMidiMessageCC;
×
202
        param = number - CHANNEL_OFFSET_CONTROL_CHANGE;
×
203
    }
204
    else if (number <= CHANNEL_OFFSET_NOTE_MAX)
×
205
    {
206
        message = KMidiMessageNoteOnOff;
×
207
        param = number - CHANNEL_OFFSET_NOTE;
×
208
    }
209
    else if (number <= CHANNEL_OFFSET_NOTE_AFTERTOUCH_MAX)
×
210
    {
211
        message = KMidiMessageNoteAftertouch;
×
212
        param = number - CHANNEL_OFFSET_NOTE_AFTERTOUCH;
×
213
    }
214
    else if (number <= CHANNEL_OFFSET_PROGRAM_CHANGE_MAX)
×
215
    {
216
        message = KMidiMessagePC;
×
217
        param = number - CHANNEL_OFFSET_PROGRAM_CHANGE;
×
218
    }
219
    else if (number == CHANNEL_OFFSET_CHANNEL_AFTERTOUCH)
×
220
    {
221
        message = KMidiMessageChannelAftertouch;
×
222
    }
223
    else if (number == CHANNEL_OFFSET_PITCH_WHEEL)
×
224
    {
225
        message = KMidiMessagePitchWheel;
×
226
    }
227
    else if (number == CHANNEL_OFFSET_MBC_PLAYBACK)
×
228
    {
229
        message = KMidiMessageMBCPlayback;
×
230
    }
231
    else if (number == CHANNEL_OFFSET_MBC_STOP)
×
232
    {
233
        message = KMidiMessageMBCStop;
×
234
    }
235
    else // if (number == CHANNEL_OFFSET_MBC_BEAT)
236
    {
237
        message = KMidiMessageMBCBeat;
×
238
    }
239
}
×
240

241
int InputChannelEditor::midiToNumber(int channel, int message, int param)
×
242
{
243
    switch (message)
×
244
    {
245
    case KMidiMessageCC:
×
246
        return (channel - 1) * KMidiChannelOffset + CHANNEL_OFFSET_CONTROL_CHANGE + (param);
×
247
    case KMidiMessageNoteOnOff:
×
248
        return (channel - 1) * KMidiChannelOffset + CHANNEL_OFFSET_NOTE + (param);
×
249
    case KMidiMessageNoteAftertouch:
×
250
        return (channel - 1) * KMidiChannelOffset + CHANNEL_OFFSET_NOTE_AFTERTOUCH + (param);
×
251
    case KMidiMessagePC:
×
252
        return (channel - 1) * KMidiChannelOffset + CHANNEL_OFFSET_PROGRAM_CHANGE + (param);
×
253
    case KMidiMessageChannelAftertouch:
×
254
        return (channel - 1) * KMidiChannelOffset + CHANNEL_OFFSET_CHANNEL_AFTERTOUCH;
×
255
    case KMidiMessagePitchWheel:
×
256
        return (channel - 1) * KMidiChannelOffset + CHANNEL_OFFSET_PITCH_WHEEL;
×
257
    case KMidiMessageMBCPlayback:
×
258
        return (channel - 1) * KMidiChannelOffset + CHANNEL_OFFSET_MBC_PLAYBACK;
×
259
    case KMidiMessageMBCBeat:
×
260
        return (channel - 1) * KMidiChannelOffset + CHANNEL_OFFSET_MBC_BEAT;
×
261
    case KMidiMessageMBCStop:
×
262
        return (channel - 1) * KMidiChannelOffset + CHANNEL_OFFSET_MBC_STOP;
×
263
    default:
264
        return 0;
265
    }
266
}
267

268
void InputChannelEditor::slotMidiChanged()
×
269
{
270
    int midiChannel = m_midiChannelSpin->value();
×
271
    int midiMessage = m_midiMessageCombo->currentIndex();
×
272
    int midiParam = m_midiParamSpin->value();
×
273

274
    enableMidiParam(midiMessage, midiParam);
×
275

276
    m_channel = midiToNumber(midiChannel, midiMessage, midiParam);
×
277
    m_numberSpin->setValue(m_channel + 1);
×
278
}
×
279

280
void InputChannelEditor::enableMidiParam(int midiMessage, int midiParam)
×
281
{
282
    switch (midiMessage)
×
283
    {
284
    case KMidiMessageNoteOnOff:
×
285
    case KMidiMessageNoteAftertouch:
286
        m_midiParamLabel->setEnabled(true);
×
287
        m_midiParamSpin->setEnabled(true);
×
288

289
        m_midiNoteLabel->setEnabled(true);
×
290
        m_midiNote->setEnabled(true);
×
291
        m_midiNote->setText(noteToString(midiParam));
×
292
        break;
×
293

294
    case KMidiMessageCC:
×
295
    case KMidiMessagePC:
296
        m_midiParamLabel->setEnabled(true);
×
297
        m_midiParamSpin->setEnabled(true);
×
298

299
        m_midiNoteLabel->setEnabled(false);
×
300
        m_midiNote->setEnabled(false);
×
301
        m_midiNote->setText("--");
×
302
        break;
×
303

304
    case KMidiMessageChannelAftertouch:
×
305
    case KMidiMessagePitchWheel:
306
    case KMidiMessageMBCPlayback:
307
    case KMidiMessageMBCBeat:
308
    case KMidiMessageMBCStop:
309
        m_midiParamLabel->setEnabled(false);
×
310
        m_midiParamSpin->setEnabled(false);
×
311

312
        m_midiNoteLabel->setEnabled(false);
×
313
        m_midiNote->setEnabled(false);
×
314
        m_midiNote->setText("--");
×
315
        break;
×
316
    }
317
}
×
318

319
QString InputChannelEditor::noteToString(int note)
×
320
{
321
    int octave = note / 12 - 1;
×
322
    int pitch = note % 12;
×
323

324
    switch(pitch)
×
325
    {
326
    case 0:
×
327
        return QString("C%1").arg(octave);
×
328
    case 1:
×
329
        return QString("C#%1").arg(octave);
×
330
    case 2:
×
331
        return QString("D%1").arg(octave);
×
332
    case 3:
×
333
        return QString("D#%1").arg(octave);
×
334
    case 4:
×
335
        return QString("E%1").arg(octave);
×
336
    case 5:
×
337
        return QString("F%1").arg(octave);
×
338
    case 6:
×
339
        return QString("F#%1").arg(octave);
×
340
    case 7:
×
341
        return QString("G%1").arg(octave);
×
342
    case 8:
×
343
        return QString("G#%1").arg(octave);
×
344
    case 9:
×
345
        return QString("A%1").arg(octave);
×
346
    case 10:
×
347
        return QString("A#%1").arg(octave);
×
348
    case 11:
×
349
        return QString("B%1").arg(octave);
×
350
    default:
×
351
        return "--";
×
352
    }
353
}
354

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