forked from hselasky/midipp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmidipp_devices.cpp
More file actions
203 lines (167 loc) · 5.94 KB
/
Copy pathmidipp_devices.cpp
File metadata and controls
203 lines (167 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*-
* Copyright (c) 2011-2017 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "midipp_mainwindow.h"
#include "midipp_devices.h"
#include "midipp_groupbox.h"
MppDevices :: MppDevices(QWidget *parent)
: QDialog(parent)
{
int n;
gl = new QGridLayout(this);
setWindowTitle(tr("Select playback and recording device"));
setWindowIcon(QIcon(MppIconFile));
lw_rec = new QListWidget();
lw_play = new QListWidget();
gb_rec = new MppGroupBox(tr("Recording devices"));
gb_play = new MppGroupBox(tr("Playback devices"));
gb_rec->addWidget(lw_rec, 0, 0, 1, 1);
gb_play->addWidget(lw_play, 0, 0, 1, 1);
but_ok = new QPushButton(tr("Ok"));
but_cancel = new QPushButton(tr("Cancel"));
connect(but_ok, SIGNAL(released()), this, SLOT(accept()));
connect(but_cancel, SIGNAL(released()), this, SLOT(reject()));
gl->addWidget(gb_play, 0,0,1,2);
gl->addWidget(gb_rec, 0,2,1,2);
gl->addWidget(but_ok, 1,2,1,1);
gl->addWidget(but_cancel, 1,3,1,1);
QDir dir("/dev");
QStringList filters;
filters << "umidi*" << "midi*";
dir.setFilter(QDir::Files | QDir::System);
dir.setNameFilters(filters);
dir.setSorting(QDir::Name);
QFileInfoList list = dir.entryInfoList();
new QListWidgetItem(tr("No recording device"), lw_rec);
for (n = 0; n != list.size(); n++) {
QFileInfo fileInfo = list.at(n);
if (fileInfo.fileName() == QString("midistat"))
continue;
new QListWidgetItem(QString("D:/dev/") + fileInfo.fileName(), lw_rec);
}
new QListWidgetItem(tr("No playback device"), lw_play);
for (n = 0; n != list.size(); n++) {
QFileInfo fileInfo = list.at(n);
if (fileInfo.fileName() == QString("midistat"))
continue;
new QListWidgetItem(QString("D:/dev/") + fileInfo.fileName(), lw_play);
}
rec_jack_str = umidi20_jack_alloc_outputs();
if (rec_jack_str != NULL) {
for (n = 0; rec_jack_str[n] != NULL; n++) {
if (rec_jack_str[n][0] != 0)
new QListWidgetItem(QString("A:") + QString(rec_jack_str[n]), lw_rec);
}
}
play_jack_str = umidi20_jack_alloc_inputs();
if (play_jack_str != NULL) {
for (n = 0; play_jack_str[n] != NULL; n++) {
if (play_jack_str[n][0] != 0)
new QListWidgetItem(QString("A:") + QString(play_jack_str[n]), lw_play);
}
}
rec_coremidi_str = umidi20_coremidi_alloc_outputs();
if (rec_coremidi_str != NULL) {
for (n = 0; rec_coremidi_str[n] != NULL; n++) {
if (rec_coremidi_str[n][0] != 0)
new QListWidgetItem(QString("C:") + QString(rec_coremidi_str[n]), lw_rec);
}
}
play_coremidi_str = umidi20_coremidi_alloc_inputs();
if (play_coremidi_str != NULL) {
for (n = 0; play_coremidi_str[n] != NULL; n++) {
if (play_coremidi_str[n][0] != 0)
new QListWidgetItem(QString("C:") + QString(play_coremidi_str[n]), lw_play);
}
}
rec_android_str = umidi20_android_alloc_outputs();
if (rec_android_str != NULL) {
for (n = 0; rec_android_str[n] != NULL; n++) {
if (rec_android_str[n][0] != 0)
new QListWidgetItem(QString("R:") + QString(rec_android_str[n]), lw_rec);
}
}
play_android_str = umidi20_android_alloc_inputs();
if (play_android_str != NULL) {
for (n = 0; play_android_str[n] != NULL; n++) {
if (play_android_str[n][0] != 0)
new QListWidgetItem(QString("R:") + QString(play_android_str[n]), lw_play);
}
}
lw_rec->setCurrentRow(0);
lw_play->setCurrentRow(0);
/* compute nice list width */
int w_rec = lw_rec->sizeHintForColumn(0) + 32;
int w_play = lw_play->sizeHintForColumn(0) + 32;
int w_both = (w_rec > w_play ? w_rec : w_play);
lw_rec->setMinimumWidth(w_both);
lw_play->setMinimumWidth(w_both);
}
int
MppDevices :: autoSelect()
{
/* check for zero or once choice only */
if (lw_rec->count() == 1 && lw_play->count() == 1) {
accept();
return (-1);
} else if (lw_rec->count() == 2 && lw_play->count() == 2) {
lw_rec->setCurrentRow(1);
lw_play->setCurrentRow(1);
accept();
return (1);
}
return (0);
}
MppDevices :: ~MppDevices()
{
umidi20_jack_free_outputs(rec_jack_str);
umidi20_jack_free_inputs(play_jack_str);
umidi20_coremidi_free_outputs(rec_coremidi_str);
umidi20_coremidi_free_inputs(play_coremidi_str);
umidi20_android_free_outputs(rec_android_str);
umidi20_android_free_inputs(play_android_str);
}
void
MppDevices :: accept(void)
{
QListWidgetItem *ptr;
ptr = lw_rec->currentItem();
if (ptr != NULL && lw_rec->currentRow() > 0)
rec_dev = ptr->text();
else
rec_dev = QString("X:");
ptr = lw_play->currentItem();
if (ptr != NULL && lw_play->currentRow() > 0)
play_dev = ptr->text();
else
play_dev = QString("X:");
/* filter invalid characters */
rec_dev = rec_dev.replace(QString("|"),QString(""));
play_dev = play_dev.replace(QString("|"),QString(""));
if (rec_dev == play_dev)
result_dev = play_dev;
else
result_dev = play_dev + QString("|") + rec_dev;
QDialog :: accept();
}