1 |
// qsamplerChannel.cpp |
// qsamplerChannel.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
GNU General Public License for more details. |
15 |
|
|
16 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License along |
17 |
along with this program; if not, write to the Free Software |
with this program; if not, write to the Free Software Foundation, Inc., |
18 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
|
20 |
*****************************************************************************/ |
*****************************************************************************/ |
21 |
|
|
22 |
|
#include "qsamplerAbout.h" |
23 |
#include "qsamplerChannel.h" |
#include "qsamplerChannel.h" |
24 |
|
|
25 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
26 |
#include "qsamplerChannelForm.h" |
#include "qsamplerChannelForm.h" |
27 |
|
|
|
#include "config.h" |
|
|
|
|
28 |
#include <qfileinfo.h> |
#include <qfileinfo.h> |
29 |
|
#include <qcombobox.h> |
30 |
|
|
31 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
32 |
#include "gig.h" |
#include "gig.h" |
33 |
#endif |
#endif |
34 |
|
|
35 |
#define QSAMPLER_INSTRUMENT_MAX 8 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
36 |
|
|
37 |
|
|
38 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
40 |
// |
// |
41 |
|
|
42 |
// Constructor. |
// Constructor. |
43 |
qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID ) |
qsamplerChannel::qsamplerChannel ( int iChannelID ) |
44 |
{ |
{ |
45 |
m_pMainForm = pMainForm; |
m_iChannelID = iChannelID; |
|
m_iChannelID = iChannelID; |
|
46 |
|
|
47 |
// m_sEngineName = QObject::tr("(No engine)"); |
// m_sEngineName = noEngineName(); |
48 |
// m_sInstrumentName = QObject::tr("(No instrument)"); |
// m_sInstrumentName = noInstrumentName(); |
49 |
// m_sInstrumentFile = m_sInstrumentName; |
// m_sInstrumentFile = m_sInstrumentName; |
50 |
m_iInstrumentNr = -1; |
m_iInstrumentNr = -1; |
51 |
m_iInstrumentStatus = -1; |
m_iInstrumentStatus = -1; |
52 |
m_sMidiDriver = "Alsa"; // DEPRECATED. |
m_sMidiDriver = "ALSA"; |
53 |
m_iMidiDevice = -1; |
m_iMidiDevice = -1; |
54 |
m_iMidiPort = -1; |
m_iMidiPort = -1; |
55 |
m_iMidiChannel = -1; |
m_iMidiChannel = -1; |
56 |
m_sAudioDriver = "Alsa"; // DEPRECATED. |
m_iMidiMap = -1; |
57 |
m_iAudioDevice = -1; |
m_sAudioDriver = "ALSA"; |
58 |
m_fVolume = 0.0; |
m_iAudioDevice = -1; |
59 |
|
m_fVolume = 0.0; |
60 |
|
m_bMute = false; |
61 |
|
m_bSolo = false; |
62 |
} |
} |
63 |
|
|
64 |
// Default destructor. |
// Default destructor. |
67 |
} |
} |
68 |
|
|
69 |
|
|
|
// The global options settings delegated property. |
|
|
qsamplerOptions *qsamplerChannel::options (void) |
|
|
{ |
|
|
if (m_pMainForm == NULL) |
|
|
return NULL; |
|
|
|
|
|
return m_pMainForm->options(); |
|
|
} |
|
|
|
|
|
|
|
|
// The client descriptor delegated property. |
|
|
lscp_client_t *qsamplerChannel::client (void) |
|
|
{ |
|
|
if (m_pMainForm == NULL) |
|
|
return NULL; |
|
|
|
|
|
return m_pMainForm->client(); |
|
|
} |
|
|
|
|
|
|
|
70 |
// Create a new sampler channel, if not already. |
// Create a new sampler channel, if not already. |
71 |
bool qsamplerChannel::addChannel (void) |
bool qsamplerChannel::addChannel (void) |
72 |
{ |
{ |
73 |
if (client() == NULL) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
74 |
return false; |
if (pMainForm == NULL) |
75 |
|
return false; |
76 |
// Are we a new channel? |
if (pMainForm->client() == NULL) |
77 |
if (m_iChannelID < 0) { |
return false; |
78 |
m_iChannelID = ::lscp_add_channel(client()); |
|
79 |
if (m_iChannelID < 0) { |
// Are we a new channel? |
80 |
appendMessagesClient("lscp_add_channel"); |
if (m_iChannelID < 0) { |
81 |
appendMessagesError(QObject::tr("Could not create the new channel.\n\nSorry.")); |
m_iChannelID = ::lscp_add_channel(pMainForm->client()); |
82 |
} // Otherwise it's created... |
if (m_iChannelID < 0) { |
83 |
else appendMessages(QObject::tr("Channel %1 created.").arg(m_iChannelID)); |
appendMessagesClient("lscp_add_channel"); |
84 |
} |
appendMessagesError( |
85 |
|
QObject::tr("Could not add channel.\n\nSorry.")); |
86 |
|
} // Otherwise it's created... |
87 |
|
else appendMessages(QObject::tr("added.")); |
88 |
|
} |
89 |
|
|
90 |
// Return whether we're a valid channel... |
// Return whether we're a valid channel... |
91 |
return (m_iChannelID >= 0); |
return (m_iChannelID >= 0); |
92 |
} |
} |
93 |
|
|
94 |
|
|
95 |
// Remove sampler channel. |
// Remove sampler channel. |
96 |
bool qsamplerChannel::removeChannel (void) |
bool qsamplerChannel::removeChannel (void) |
97 |
{ |
{ |
98 |
if (client() == NULL) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
99 |
return false; |
if (pMainForm == NULL) |
100 |
|
return false; |
101 |
|
if (pMainForm->client() == NULL) |
102 |
|
return false; |
103 |
|
|
104 |
|
// Are we an existing channel? |
105 |
|
if (m_iChannelID >= 0) { |
106 |
|
if (::lscp_remove_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) { |
107 |
|
appendMessagesClient("lscp_remove_channel"); |
108 |
|
appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry.")); |
109 |
|
} else { |
110 |
|
// Otherwise it's removed. |
111 |
|
appendMessages(QObject::tr("removed.")); |
112 |
|
m_iChannelID = -1; |
113 |
|
} |
114 |
|
} |
115 |
|
|
116 |
// Are we an existing channel? |
// Return whether we've removed the channel... |
117 |
if (m_iChannelID >= 0) { |
return (m_iChannelID < 0); |
|
if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) { |
|
|
appendMessagesClient("lscp_remove_channel"); |
|
|
appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry.")); |
|
|
} else { |
|
|
// Otherwise it's removed. |
|
|
appendMessages(QObject::tr("Channel %1 removed.").arg(m_iChannelID)); |
|
|
m_iChannelID = -1; |
|
|
} |
|
|
} |
|
|
|
|
|
// Return whether we've removed the channel... |
|
|
return (m_iChannelID < 0); |
|
118 |
} |
} |
119 |
|
|
120 |
|
|
121 |
// Channel-ID (aka Sammpler-Channel) accessors. |
// Channel-ID (aka Sammpler-Channel) accessors. |
122 |
int qsamplerChannel::channelID (void) |
int qsamplerChannel::channelID (void) const |
123 |
{ |
{ |
124 |
return m_iChannelID; |
return m_iChannelID; |
125 |
} |
} |
126 |
|
|
127 |
void qsamplerChannel::setChannelID ( int iChannelID ) |
void qsamplerChannel::setChannelID ( int iChannelID ) |
128 |
{ |
{ |
129 |
m_iChannelID = iChannelID; |
m_iChannelID = iChannelID; |
130 |
} |
} |
131 |
|
|
132 |
|
|
133 |
// Readable channel name. |
// Readable channel name. |
134 |
QString qsamplerChannel::channelName (void) |
QString qsamplerChannel::channelName (void) const |
135 |
{ |
{ |
136 |
return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID)); |
return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID)); |
137 |
} |
} |
138 |
|
|
139 |
|
|
140 |
// Engine name accessors. |
// Engine name accessors. |
141 |
QString& qsamplerChannel::engineName (void) |
const QString& qsamplerChannel::engineName (void) const |
142 |
{ |
{ |
143 |
return m_sEngineName; |
return m_sEngineName; |
144 |
} |
} |
145 |
|
|
146 |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
147 |
{ |
{ |
148 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
149 |
return false; |
if (pMainForm == NULL) |
150 |
|
return false; |
151 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
152 |
|
return false; |
153 |
|
if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName) |
154 |
|
return true; |
155 |
|
|
156 |
|
if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
157 |
|
appendMessagesClient("lscp_load_engine"); |
158 |
|
return false; |
159 |
|
} |
160 |
|
|
161 |
if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
appendMessages(QObject::tr("Engine: %1.").arg(sEngineName)); |
|
appendMessagesClient("lscp_load_engine"); |
|
|
return false; |
|
|
} |
|
162 |
|
|
163 |
m_sEngineName = sEngineName; |
m_sEngineName = sEngineName; |
164 |
return true; |
return true; |
165 |
} |
} |
166 |
|
|
167 |
|
|
168 |
// Instrument name accessor. |
// Instrument filename accessor. |
169 |
QString& qsamplerChannel::instrumentName (void) |
const QString& qsamplerChannel::instrumentFile (void) const |
170 |
{ |
{ |
171 |
return m_sInstrumentName; |
return m_sInstrumentFile; |
172 |
} |
} |
173 |
|
|
174 |
// Instrument filename accessor. |
// Instrument index accessor. |
175 |
QString& qsamplerChannel::instrumentFile (void) |
int qsamplerChannel::instrumentNr (void) const |
176 |
{ |
{ |
177 |
return m_sInstrumentFile; |
return m_iInstrumentNr; |
178 |
} |
} |
179 |
|
|
180 |
// Instrument index accessor. |
// Instrument name accessor. |
181 |
int qsamplerChannel::instrumentNr (void) |
const QString& qsamplerChannel::instrumentName (void) const |
182 |
{ |
{ |
183 |
return m_iInstrumentNr; |
return m_sInstrumentName; |
184 |
} |
} |
185 |
|
|
186 |
// Instrument status accessor. |
// Instrument status accessor. |
187 |
int qsamplerChannel::instrumentStatus (void) |
int qsamplerChannel::instrumentStatus (void) const |
188 |
{ |
{ |
189 |
return m_iInstrumentStatus; |
return m_iInstrumentStatus; |
190 |
} |
} |
191 |
|
|
192 |
// Instrument file loader. |
// Instrument file loader. |
193 |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
194 |
{ |
{ |
195 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
196 |
return false; |
if (pMainForm == NULL) |
197 |
|
return false; |
198 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
199 |
|
return false; |
200 |
|
if (!isInstrumentFile(sInstrumentFile)) |
201 |
|
return false; |
202 |
|
if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) |
203 |
|
return true; |
204 |
|
|
205 |
|
if (::lscp_load_instrument_non_modal(pMainForm->client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { |
206 |
|
appendMessagesClient("lscp_load_instrument"); |
207 |
|
return false; |
208 |
|
} |
209 |
|
|
210 |
|
appendMessages(QObject::tr("Instrument: \"%1\" (%2).") |
211 |
|
.arg(sInstrumentFile).arg(iInstrumentNr)); |
212 |
|
|
213 |
|
return setInstrument(sInstrumentFile, iInstrumentNr); |
214 |
|
} |
215 |
|
|
|
if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { |
|
|
appendMessagesClient("lscp_load_instrument"); |
|
|
return false; |
|
|
} |
|
|
|
|
|
m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); |
|
|
m_sInstrumentFile = sInstrumentFile; |
|
|
m_iInstrumentNr = iInstrumentNr; |
|
|
m_iInstrumentStatus = 0; |
|
216 |
|
|
217 |
return true; |
// Special instrument file/name/number settler. |
218 |
|
bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
219 |
|
{ |
220 |
|
m_sInstrumentFile = sInstrumentFile; |
221 |
|
m_iInstrumentNr = iInstrumentNr; |
222 |
|
#ifdef CONFIG_INSTRUMENT_NAME |
223 |
|
m_sInstrumentName = QString::null; // We'll get it, maybe later, on channel_info... |
224 |
|
#else |
225 |
|
m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); |
226 |
|
#endif |
227 |
|
m_iInstrumentStatus = 0; |
228 |
|
|
229 |
|
return true; |
230 |
} |
} |
231 |
|
|
232 |
|
|
233 |
// MIDI driver type accessors (DEPRECATED). |
// MIDI driver type accessors (DEPRECATED). |
234 |
QString& qsamplerChannel::midiDriver (void) |
const QString& qsamplerChannel::midiDriver (void) const |
235 |
{ |
{ |
236 |
return m_sMidiDriver; |
return m_sMidiDriver; |
237 |
} |
} |
238 |
|
|
239 |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
240 |
{ |
{ |
241 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
242 |
return false; |
if (pMainForm == NULL) |
243 |
|
return false; |
244 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
245 |
|
return false; |
246 |
|
if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver) |
247 |
|
return true; |
248 |
|
|
249 |
|
if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
250 |
|
appendMessagesClient("lscp_set_channel_midi_type"); |
251 |
|
return false; |
252 |
|
} |
253 |
|
|
254 |
if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
appendMessages(QObject::tr("MIDI driver: %1.").arg(sMidiDriver)); |
|
appendMessagesClient("lscp_set_channel_midi_type"); |
|
|
return false; |
|
|
} |
|
255 |
|
|
256 |
m_sMidiDriver = sMidiDriver; |
m_sMidiDriver = sMidiDriver; |
257 |
return true; |
return true; |
258 |
} |
} |
259 |
|
|
260 |
|
|
261 |
// MIDI device accessors. |
// MIDI device accessors. |
262 |
int qsamplerChannel::midiDevice (void) |
int qsamplerChannel::midiDevice (void) const |
263 |
{ |
{ |
264 |
return m_iMidiDevice; |
return m_iMidiDevice; |
265 |
} |
} |
266 |
|
|
267 |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
268 |
{ |
{ |
269 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
270 |
return false; |
if (pMainForm == NULL) |
271 |
|
return false; |
272 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
273 |
|
return false; |
274 |
|
if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice) |
275 |
|
return true; |
276 |
|
|
277 |
|
if (::lscp_set_channel_midi_device(pMainForm->client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
278 |
|
appendMessagesClient("lscp_set_channel_midi_device"); |
279 |
|
return false; |
280 |
|
} |
281 |
|
|
282 |
if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
appendMessages(QObject::tr("MIDI device: %1.").arg(iMidiDevice)); |
|
appendMessagesClient("lscp_set_channel_midi_device"); |
|
|
return false; |
|
|
} |
|
283 |
|
|
284 |
m_iMidiDevice = iMidiDevice; |
m_iMidiDevice = iMidiDevice; |
285 |
return true; |
return true; |
286 |
} |
} |
287 |
|
|
288 |
|
|
289 |
// MIDI port number accessor. |
// MIDI port number accessor. |
290 |
int qsamplerChannel::midiPort (void) |
int qsamplerChannel::midiPort (void) const |
291 |
{ |
{ |
292 |
return m_iMidiPort; |
return m_iMidiPort; |
293 |
} |
} |
294 |
|
|
295 |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
296 |
{ |
{ |
297 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
298 |
return false; |
if (pMainForm == NULL) |
299 |
|
return false; |
300 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
301 |
|
return false; |
302 |
|
if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort) |
303 |
|
return true; |
304 |
|
|
305 |
|
if (::lscp_set_channel_midi_port(pMainForm->client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
306 |
|
appendMessagesClient("lscp_set_channel_midi_port"); |
307 |
|
return false; |
308 |
|
} |
309 |
|
|
310 |
if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
appendMessages(QObject::tr("MIDI port: %1.").arg(iMidiPort)); |
|
appendMessagesClient("lscp_set_channel_midi_port"); |
|
|
return false; |
|
|
} |
|
311 |
|
|
312 |
m_iMidiPort = iMidiPort; |
m_iMidiPort = iMidiPort; |
313 |
return true; |
return true; |
314 |
} |
} |
315 |
|
|
316 |
|
|
317 |
// MIDI channel accessor. |
// MIDI channel accessor. |
318 |
int qsamplerChannel::midiChannel (void) |
int qsamplerChannel::midiChannel (void) const |
319 |
{ |
{ |
320 |
return m_iMidiChannel; |
return m_iMidiChannel; |
321 |
} |
} |
322 |
|
|
323 |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
324 |
{ |
{ |
325 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
326 |
return false; |
if (pMainForm == NULL) |
327 |
|
return false; |
328 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
329 |
|
return false; |
330 |
|
if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel) |
331 |
|
return true; |
332 |
|
|
333 |
|
if (::lscp_set_channel_midi_channel(pMainForm->client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
334 |
|
appendMessagesClient("lscp_set_channel_midi_channel"); |
335 |
|
return false; |
336 |
|
} |
337 |
|
|
338 |
|
appendMessages(QObject::tr("MIDI channel: %1.").arg(iMidiChannel)); |
339 |
|
|
340 |
|
m_iMidiChannel = iMidiChannel; |
341 |
|
return true; |
342 |
|
} |
343 |
|
|
344 |
|
|
345 |
|
// MIDI instrument map accessor. |
346 |
|
int qsamplerChannel::midiMap (void) const |
347 |
|
{ |
348 |
|
return m_iMidiMap; |
349 |
|
} |
350 |
|
|
351 |
if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
bool qsamplerChannel::setMidiMap ( int iMidiMap ) |
352 |
appendMessagesClient("lscp_set_channel_midi_channel"); |
{ |
353 |
return false; |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
354 |
} |
if (pMainForm == NULL) |
355 |
|
return false; |
356 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
357 |
|
return false; |
358 |
|
if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap) |
359 |
|
return true; |
360 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
361 |
|
if (::lscp_set_channel_midi_map(pMainForm->client(), m_iChannelID, iMidiMap) != LSCP_OK) { |
362 |
|
appendMessagesClient("lscp_set_channel_midi_map"); |
363 |
|
return false; |
364 |
|
} |
365 |
|
#endif |
366 |
|
appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap)); |
367 |
|
|
368 |
m_iMidiChannel = iMidiChannel; |
m_iMidiMap = iMidiMap; |
369 |
return true; |
return true; |
370 |
} |
} |
371 |
|
|
372 |
|
|
373 |
// Audio device accessor. |
// Audio device accessor. |
374 |
int qsamplerChannel::audioDevice (void) |
int qsamplerChannel::audioDevice (void) const |
375 |
{ |
{ |
376 |
return m_iAudioDevice; |
return m_iAudioDevice; |
377 |
} |
} |
378 |
|
|
379 |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
380 |
{ |
{ |
381 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
382 |
return false; |
if (pMainForm == NULL) |
383 |
|
return false; |
384 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
385 |
|
return false; |
386 |
|
if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice) |
387 |
|
return true; |
388 |
|
|
389 |
|
if (::lscp_set_channel_audio_device(pMainForm->client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
390 |
|
appendMessagesClient("lscp_set_channel_audio_device"); |
391 |
|
return false; |
392 |
|
} |
393 |
|
|
394 |
if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
appendMessages(QObject::tr("Audio device: %1.").arg(iAudioDevice)); |
|
appendMessagesClient("lscp_set_channel_audio_device"); |
|
|
return false; |
|
|
} |
|
395 |
|
|
396 |
m_iAudioDevice = iAudioDevice; |
m_iAudioDevice = iAudioDevice; |
397 |
return true; |
return true; |
398 |
} |
} |
399 |
|
|
400 |
|
|
401 |
// Audio driver type accessors (DEPRECATED). |
// Audio driver type accessors (DEPRECATED). |
402 |
QString& qsamplerChannel::audioDriver (void) |
const QString& qsamplerChannel::audioDriver (void) const |
403 |
{ |
{ |
404 |
return m_sAudioDriver; |
return m_sAudioDriver; |
405 |
} |
} |
406 |
|
|
407 |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
408 |
{ |
{ |
409 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
410 |
return false; |
if (pMainForm == NULL) |
411 |
|
return false; |
412 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
413 |
|
return false; |
414 |
|
if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver) |
415 |
|
return true; |
416 |
|
|
417 |
|
if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
418 |
|
appendMessagesClient("lscp_set_channel_audio_type"); |
419 |
|
return false; |
420 |
|
} |
421 |
|
|
422 |
if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
appendMessages(QObject::tr("Audio driver: %1.").arg(sAudioDriver)); |
|
appendMessagesClient("lscp_set_channel_audio_type"); |
|
|
return false; |
|
|
} |
|
423 |
|
|
424 |
m_sAudioDriver = sAudioDriver; |
m_sAudioDriver = sAudioDriver; |
425 |
return true; |
return true; |
426 |
} |
} |
427 |
|
|
428 |
|
|
429 |
// Channel volume accessors. |
// Channel volume accessors. |
430 |
float qsamplerChannel::volume (void) |
float qsamplerChannel::volume (void) const |
431 |
{ |
{ |
432 |
return m_fVolume; |
return m_fVolume; |
433 |
} |
} |
434 |
|
|
435 |
bool qsamplerChannel::setVolume ( float fVolume ) |
bool qsamplerChannel::setVolume ( float fVolume ) |
436 |
{ |
{ |
437 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
438 |
return false; |
if (pMainForm == NULL) |
439 |
|
return false; |
440 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
441 |
|
return false; |
442 |
|
if (m_iInstrumentStatus == 100 && m_fVolume == fVolume) |
443 |
|
return true; |
444 |
|
|
445 |
|
if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) { |
446 |
|
appendMessagesClient("lscp_set_channel_volume"); |
447 |
|
return false; |
448 |
|
} |
449 |
|
|
450 |
if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { |
appendMessages(QObject::tr("Volume: %1.").arg(fVolume)); |
|
appendMessagesClient("lscp_set_channel_volume"); |
|
|
return false; |
|
|
} |
|
451 |
|
|
452 |
m_fVolume = fVolume; |
m_fVolume = fVolume; |
453 |
return true; |
return true; |
454 |
|
} |
455 |
|
|
456 |
|
|
457 |
|
// Sampler channel mute state. |
458 |
|
bool qsamplerChannel::channelMute (void) const |
459 |
|
{ |
460 |
|
return m_bMute; |
461 |
|
} |
462 |
|
|
463 |
|
bool qsamplerChannel::setChannelMute ( bool bMute ) |
464 |
|
{ |
465 |
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
466 |
|
if (pMainForm == NULL) |
467 |
|
return false; |
468 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
469 |
|
return false; |
470 |
|
if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute))) |
471 |
|
return true; |
472 |
|
|
473 |
|
#ifdef CONFIG_MUTE_SOLO |
474 |
|
if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) { |
475 |
|
appendMessagesClient("lscp_set_channel_mute"); |
476 |
|
return false; |
477 |
|
} |
478 |
|
appendMessages(QObject::tr("Mute: %1.").arg((int) bMute)); |
479 |
|
m_bMute = bMute; |
480 |
|
return true; |
481 |
|
#else |
482 |
|
return false; |
483 |
|
#endif |
484 |
|
} |
485 |
|
|
486 |
|
|
487 |
|
// Sampler channel solo state. |
488 |
|
bool qsamplerChannel::channelSolo (void) const |
489 |
|
{ |
490 |
|
return m_bSolo; |
491 |
|
} |
492 |
|
|
493 |
|
bool qsamplerChannel::setChannelSolo ( bool bSolo ) |
494 |
|
{ |
495 |
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
496 |
|
if (pMainForm == NULL) |
497 |
|
return false; |
498 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
499 |
|
return false; |
500 |
|
if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo))) |
501 |
|
return true; |
502 |
|
|
503 |
|
#ifdef CONFIG_MUTE_SOLO |
504 |
|
if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) { |
505 |
|
appendMessagesClient("lscp_set_channel_solo"); |
506 |
|
return false; |
507 |
|
} |
508 |
|
appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo)); |
509 |
|
m_bSolo = bSolo; |
510 |
|
return true; |
511 |
|
#else |
512 |
|
return false; |
513 |
|
#endif |
514 |
|
} |
515 |
|
|
516 |
|
|
517 |
|
// Audio routing accessors. |
518 |
|
int qsamplerChannel::audioChannel ( int iAudioOut ) const |
519 |
|
{ |
520 |
|
return m_audioRouting[iAudioOut]; |
521 |
|
} |
522 |
|
|
523 |
|
bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn ) |
524 |
|
{ |
525 |
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
526 |
|
if (pMainForm == NULL) |
527 |
|
return false; |
528 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
529 |
|
return false; |
530 |
|
if (m_iInstrumentStatus == 100 && |
531 |
|
m_audioRouting[iAudioOut] == iAudioIn) |
532 |
|
return true; |
533 |
|
|
534 |
|
if (::lscp_set_channel_audio_channel(pMainForm->client(), |
535 |
|
m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) { |
536 |
|
appendMessagesClient("lscp_set_channel_audio_channel"); |
537 |
|
return false; |
538 |
|
} |
539 |
|
|
540 |
|
appendMessages(QObject::tr("Audio Channel: %1 -> %2.") |
541 |
|
.arg(iAudioOut).arg(iAudioIn)); |
542 |
|
|
543 |
|
m_audioRouting[iAudioOut] = iAudioIn; |
544 |
|
return true; |
545 |
|
} |
546 |
|
|
547 |
|
// The audio routing map itself. |
548 |
|
const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const |
549 |
|
{ |
550 |
|
return m_audioRouting; |
551 |
} |
} |
552 |
|
|
553 |
|
|
554 |
// Istrument name remapper. |
// Istrument name remapper. |
555 |
void qsamplerChannel::updateInstrumentName (void) |
void qsamplerChannel::updateInstrumentName (void) |
556 |
{ |
{ |
557 |
|
#ifndef CONFIG_INSTRUMENT_NAME |
558 |
m_sInstrumentName = getInstrumentName(m_sInstrumentFile, |
m_sInstrumentName = getInstrumentName(m_sInstrumentFile, |
559 |
m_iInstrumentNr, (options() && options()->bInstrumentNames)); |
m_iInstrumentNr, (options() && options()->bInstrumentNames)); |
560 |
|
#endif |
561 |
} |
} |
562 |
|
|
563 |
|
|
564 |
// Update whole channel info state. |
// Update whole channel info state. |
565 |
bool qsamplerChannel::updateChannelInfo (void) |
bool qsamplerChannel::updateChannelInfo (void) |
566 |
{ |
{ |
567 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
568 |
return false; |
if (pMainForm == NULL) |
569 |
|
return false; |
570 |
// Read channel information. |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
571 |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID); |
return false; |
572 |
if (pChannelInfo == NULL) { |
|
573 |
appendMessagesClient("lscp_get_channel_info"); |
// Read channel information. |
574 |
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry.")); |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID); |
575 |
return false; |
if (pChannelInfo == NULL) { |
576 |
} |
appendMessagesClient("lscp_get_channel_info"); |
577 |
|
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry.")); |
578 |
|
return false; |
579 |
|
} |
580 |
|
|
581 |
|
#ifdef CONFIG_INSTRUMENT_NAME |
582 |
|
// We got all actual instrument datum... |
583 |
|
m_sInstrumentFile = pChannelInfo->instrument_file; |
584 |
|
m_iInstrumentNr = pChannelInfo->instrument_nr; |
585 |
|
m_sInstrumentName = pChannelInfo->instrument_name; |
586 |
|
#else |
587 |
// First, check if intrument name has changed, |
// First, check if intrument name has changed, |
588 |
// taking care that instrument name lookup might be expensive, |
// taking care that instrument name lookup might be expensive, |
589 |
// so we better make it only once and when really needed... |
// so we better make it only once and when really needed... |
593 |
m_iInstrumentNr = pChannelInfo->instrument_nr; |
m_iInstrumentNr = pChannelInfo->instrument_nr; |
594 |
updateInstrumentName(); |
updateInstrumentName(); |
595 |
} |
} |
596 |
// Cache in other channel information. |
#endif |
597 |
m_sEngineName = pChannelInfo->engine_name; |
// Cache in other channel information. |
598 |
m_iInstrumentStatus = pChannelInfo->instrument_status; |
m_sEngineName = pChannelInfo->engine_name; |
599 |
m_iMidiDevice = pChannelInfo->midi_device; |
m_iInstrumentStatus = pChannelInfo->instrument_status; |
600 |
m_iMidiPort = pChannelInfo->midi_port; |
m_iMidiDevice = pChannelInfo->midi_device; |
601 |
m_iMidiChannel = pChannelInfo->midi_channel; |
m_iMidiPort = pChannelInfo->midi_port; |
602 |
m_iAudioDevice = pChannelInfo->audio_device; |
m_iMidiChannel = pChannelInfo->midi_channel; |
603 |
m_fVolume = pChannelInfo->volume; |
#ifdef CONFIG_MIDI_INSTRUMENT |
604 |
// Some sanity checks. |
m_iMidiMap = pChannelInfo->midi_map; |
605 |
if (m_sEngineName == "NONE") |
#endif |
606 |
m_sEngineName = QString::null; |
m_iAudioDevice = pChannelInfo->audio_device; |
607 |
if (m_sInstrumentFile == "NONE") { |
m_fVolume = pChannelInfo->volume; |
608 |
m_sInstrumentFile = QString::null; |
#ifdef CONFIG_MUTE_SOLO |
609 |
m_sInstrumentName = QString::null; |
m_bMute = pChannelInfo->mute; |
610 |
|
m_bSolo = pChannelInfo->solo; |
611 |
|
#endif |
612 |
|
// Some sanity checks. |
613 |
|
if (m_sEngineName == "NONE" || m_sEngineName.isEmpty()) |
614 |
|
m_sEngineName = QString::null; |
615 |
|
if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) { |
616 |
|
m_sInstrumentFile = QString::null; |
617 |
|
m_sInstrumentName = QString::null; |
618 |
|
} |
619 |
|
|
620 |
|
// Time for device info grabbing... |
621 |
|
lscp_device_info_t *pDeviceInfo; |
622 |
|
const QString sNone = QObject::tr("(none)"); |
623 |
|
// Audio device driver type. |
624 |
|
pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice); |
625 |
|
if (pDeviceInfo == NULL) { |
626 |
|
appendMessagesClient("lscp_get_audio_device_info"); |
627 |
|
m_sAudioDriver = sNone; |
628 |
|
} else { |
629 |
|
m_sAudioDriver = pDeviceInfo->driver; |
630 |
|
} |
631 |
|
// MIDI device driver type. |
632 |
|
pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice); |
633 |
|
if (pDeviceInfo == NULL) { |
634 |
|
appendMessagesClient("lscp_get_midi_device_info"); |
635 |
|
m_sMidiDriver = sNone; |
636 |
|
} else { |
637 |
|
m_sMidiDriver = pDeviceInfo->driver; |
638 |
} |
} |
639 |
|
|
640 |
return true; |
// Set the audio routing map. |
641 |
|
m_audioRouting.clear(); |
642 |
|
char **ppszRouting = pChannelInfo->audio_routing; |
643 |
|
for (int i = 0; ppszRouting && ppszRouting[i]; i++) { |
644 |
|
m_audioRouting[i] = ::atoi(ppszRouting[i]); |
645 |
|
} |
646 |
|
|
647 |
|
return true; |
648 |
} |
} |
649 |
|
|
650 |
|
|
651 |
// Reset channel method. |
// Reset channel method. |
652 |
bool qsamplerChannel::resetChannel (void) |
bool qsamplerChannel::channelReset (void) |
653 |
{ |
{ |
654 |
if (client() == NULL || m_iChannelID < 0) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
655 |
return false; |
if (pMainForm == NULL) |
656 |
|
return false; |
657 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
658 |
|
return false; |
659 |
|
|
660 |
|
if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) { |
661 |
|
appendMessagesClient("lscp_reset_channel"); |
662 |
|
return false; |
663 |
|
} |
664 |
|
|
665 |
if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) { |
appendMessages(QObject::tr("reset.")); |
|
appendMessagesClient("lscp_reset_channel"); |
|
|
return false; |
|
|
} |
|
666 |
|
|
667 |
appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID)); |
return true; |
|
return true; |
|
668 |
} |
} |
669 |
|
|
670 |
|
|
671 |
// Channel setup dialog form. |
// Channel setup dialog form. |
672 |
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
673 |
{ |
{ |
674 |
bool bResult = false; |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
675 |
|
if (pMainForm == NULL) |
676 |
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); |
return false; |
677 |
if (pChannelForm) { |
|
678 |
pChannelForm->setup(this); |
bool bResult = false; |
679 |
bResult = pChannelForm->exec(); |
|
680 |
delete pChannelForm; |
appendMessages(QObject::tr("setup...")); |
681 |
} |
|
682 |
|
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); |
683 |
|
if (pChannelForm) { |
684 |
|
pChannelForm->setup(this); |
685 |
|
bResult = pChannelForm->exec(); |
686 |
|
delete pChannelForm; |
687 |
|
} |
688 |
|
|
689 |
return bResult; |
return bResult; |
690 |
} |
} |
691 |
|
|
692 |
|
|
693 |
// Redirected messages output methods. |
// Redirected messages output methods. |
694 |
void qsamplerChannel::appendMessages( const QString& s ) |
void qsamplerChannel::appendMessages( const QString& s ) const |
695 |
{ |
{ |
696 |
if (m_pMainForm) m_pMainForm->appendMessages(s); |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
697 |
|
if (pMainForm) |
698 |
|
pMainForm->appendMessages(channelName() + ' ' + s); |
699 |
} |
} |
700 |
|
|
701 |
void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) |
void qsamplerChannel::appendMessagesColor( const QString& s, |
702 |
|
const QString& c ) const |
703 |
{ |
{ |
704 |
if (m_pMainForm) m_pMainForm->appendMessagesColor(s, c); |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
705 |
|
if (pMainForm) |
706 |
|
pMainForm->appendMessagesColor(channelName() + ' ' + s, c); |
707 |
} |
} |
708 |
|
|
709 |
void qsamplerChannel::appendMessagesText( const QString& s ) |
void qsamplerChannel::appendMessagesText( const QString& s ) const |
710 |
{ |
{ |
711 |
if (m_pMainForm) m_pMainForm->appendMessagesText(s); |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
712 |
|
if (pMainForm) |
713 |
|
pMainForm->appendMessagesText(channelName() + ' ' + s); |
714 |
} |
} |
715 |
|
|
716 |
void qsamplerChannel::appendMessagesError( const QString& s ) |
void qsamplerChannel::appendMessagesError( const QString& s ) const |
717 |
{ |
{ |
718 |
if (m_pMainForm) m_pMainForm->appendMessagesError(s); |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
719 |
|
if (pMainForm) |
720 |
|
pMainForm->appendMessagesError(channelName() + "\n\n" + s); |
721 |
} |
} |
722 |
|
|
723 |
void qsamplerChannel::appendMessagesClient( const QString& s ) |
void qsamplerChannel::appendMessagesClient( const QString& s ) const |
724 |
{ |
{ |
725 |
if (m_pMainForm) m_pMainForm->appendMessagesClient(s); |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
726 |
|
if (pMainForm) |
727 |
|
pMainForm->appendMessagesClient(channelName() + ' ' + s); |
728 |
} |
} |
729 |
|
|
730 |
|
|
731 |
// Context menu event handler. |
// Context menu event handler. |
732 |
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
733 |
{ |
{ |
734 |
if (m_pMainForm) m_pMainForm->contextMenuEvent(pEvent); |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
735 |
|
if (pMainForm) |
736 |
|
pMainForm->contextMenuEvent(pEvent); |
737 |
|
} |
738 |
|
|
739 |
|
|
740 |
|
// FIXME: Check whether a given file is an instrument file. |
741 |
|
bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile ) |
742 |
|
{ |
743 |
|
bool bResult = false; |
744 |
|
|
745 |
|
QFile file(sInstrumentFile); |
746 |
|
if (file.open(IO_ReadOnly)) { |
747 |
|
char achHeader[16]; |
748 |
|
if (file.readBlock(achHeader, 16)) { |
749 |
|
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
750 |
|
&& ::memcmp(&achHeader[8], "DLS LIST", 8) == 0); |
751 |
|
} |
752 |
|
file.close(); |
753 |
|
} |
754 |
|
|
755 |
|
return bResult; |
756 |
} |
} |
757 |
|
|
758 |
|
|
760 |
QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, |
QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, |
761 |
bool bInstrumentNames ) |
bool bInstrumentNames ) |
762 |
{ |
{ |
763 |
QFileInfo fileinfo(sInstrumentFile); |
QString sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
764 |
QString sInstrumentName = fileinfo.fileName(); |
QStringList instlist; |
|
QStringList instlist; |
|
765 |
|
|
766 |
if (fileinfo.exists()) { |
if (isInstrumentFile(sInstrumentFile)) { |
767 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
768 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
769 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
770 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
771 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
772 |
while (pInstrument) { |
while (pInstrument) { |
773 |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
774 |
pInstrument = pGig->GetNextInstrument(); |
pInstrument = pGig->GetNextInstrument(); |
775 |
} |
} |
776 |
delete pGig; |
delete pGig; |
777 |
delete pRiff; |
delete pRiff; |
778 |
} |
} |
779 |
else |
else |
780 |
#endif |
#endif |
781 |
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
782 |
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
783 |
} |
} |
784 |
else instlist.append(sInstrumentName); |
else instlist.append(noInstrumentName()); |
785 |
|
|
786 |
return instlist; |
return instlist; |
787 |
} |
} |
788 |
|
|
789 |
|
|
791 |
QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, |
QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, |
792 |
int iInstrumentNr, bool bInstrumentNames ) |
int iInstrumentNr, bool bInstrumentNames ) |
793 |
{ |
{ |
794 |
QFileInfo fileinfo(sInstrumentFile); |
QString sInstrumentName; |
|
QString sInstrumentName = fileinfo.fileName(); |
|
795 |
|
|
796 |
if (fileinfo.exists()) { |
if (isInstrumentFile(sInstrumentFile)) { |
797 |
|
sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
798 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
799 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
800 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
801 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
802 |
int iIndex = 0; |
int iIndex = 0; |
803 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
804 |
while (pInstrument) { |
while (pInstrument) { |
805 |
if (iIndex == iInstrumentNr) { |
if (iIndex == iInstrumentNr) { |
806 |
sInstrumentName = (pInstrument->pInfo)->Name.c_str(); |
sInstrumentName = (pInstrument->pInfo)->Name.c_str(); |
807 |
break; |
break; |
808 |
} |
} |
809 |
iIndex++; |
iIndex++; |
810 |
pInstrument = pGig->GetNextInstrument(); |
pInstrument = pGig->GetNextInstrument(); |
811 |
} |
} |
812 |
delete pGig; |
delete pGig; |
813 |
delete pRiff; |
delete pRiff; |
814 |
} |
} |
815 |
else |
else |
816 |
#endif |
#endif |
817 |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
818 |
} |
} |
819 |
|
else sInstrumentName = noInstrumentName(); |
820 |
|
|
821 |
|
return sInstrumentName; |
822 |
|
} |
823 |
|
|
824 |
|
|
825 |
|
// Common invalid name-helpers. |
826 |
|
QString qsamplerChannel::noEngineName (void) |
827 |
|
{ |
828 |
|
return QObject::tr("(No engine)"); |
829 |
|
} |
830 |
|
|
831 |
|
QString qsamplerChannel::noInstrumentName (void) |
832 |
|
{ |
833 |
|
return QObject::tr("(No instrument)"); |
834 |
|
} |
835 |
|
|
836 |
|
QString qsamplerChannel::loadingInstrument (void) { |
837 |
|
return QObject::tr("(Loading instrument...)"); |
838 |
|
} |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
//------------------------------------------------------------------------- |
843 |
|
// qsamplerChannelRoutingTable - Channel routing table. |
844 |
|
// |
845 |
|
|
846 |
|
// Constructor. |
847 |
|
qsamplerChannelRoutingTable::qsamplerChannelRoutingTable ( |
848 |
|
QWidget *pParent, const char *pszName ) |
849 |
|
: QTable(pParent, pszName) |
850 |
|
{ |
851 |
|
// Set fixed number of columns. |
852 |
|
QTable::setNumCols(2); |
853 |
|
QTable::setShowGrid(false); |
854 |
|
QTable::setSorting(false); |
855 |
|
QTable::setFocusStyle(QTable::FollowStyle); |
856 |
|
QTable::setSelectionMode(QTable::NoSelection); |
857 |
|
// No vertical header. |
858 |
|
QTable::verticalHeader()->hide(); |
859 |
|
QTable::setLeftMargin(0); |
860 |
|
// Initialize the fixed table column headings. |
861 |
|
QHeader *pHeader = QTable::horizontalHeader(); |
862 |
|
pHeader->setLabel(0, tr("Sampler Channel")); |
863 |
|
pHeader->setLabel(1, tr("Device Channel")); |
864 |
|
// Set read-onlyness of each column |
865 |
|
QTable::setColumnReadOnly(0, true); |
866 |
|
// QTable::setColumnReadOnly(1, false); -- of course not. |
867 |
|
QTable::setColumnStretchable(1, true); |
868 |
|
} |
869 |
|
|
870 |
|
// Default destructor. |
871 |
|
qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void) |
872 |
|
{ |
873 |
|
} |
874 |
|
|
875 |
|
|
876 |
|
// Routing map table renderer. |
877 |
|
void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice, |
878 |
|
const qsamplerChannelRoutingMap& routing ) |
879 |
|
{ |
880 |
|
if (pDevice == NULL) |
881 |
|
return; |
882 |
|
|
883 |
|
// Always (re)start it empty. |
884 |
|
QTable::setUpdatesEnabled(false); |
885 |
|
QTable::setNumRows(0); |
886 |
|
|
887 |
|
// The common device port item list. |
888 |
|
QStringList opts; |
889 |
|
qsamplerDevicePortList& ports = pDevice->ports(); |
890 |
|
qsamplerDevicePort *pPort; |
891 |
|
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
892 |
|
opts.append(pDevice->deviceTypeName() |
893 |
|
+ ' ' + pDevice->driverName() |
894 |
|
+ ' ' + pPort->portName()); |
895 |
|
} |
896 |
|
|
897 |
|
// Those items shall have a proper pixmap... |
898 |
|
QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png"); |
899 |
|
QPixmap pmDevice; |
900 |
|
switch (pDevice->deviceType()) { |
901 |
|
case qsamplerDevice::Audio: |
902 |
|
pmDevice = QPixmap::fromMimeSource("audio2.png"); |
903 |
|
break; |
904 |
|
case qsamplerDevice::Midi: |
905 |
|
pmDevice = QPixmap::fromMimeSource("midi2.png"); |
906 |
|
break; |
907 |
|
case qsamplerDevice::None: |
908 |
|
break; |
909 |
|
} |
910 |
|
|
911 |
|
// Fill the routing table... |
912 |
|
QTable::insertRows(0, routing.count()); |
913 |
|
int iRow = 0; |
914 |
|
qsamplerChannelRoutingMap::ConstIterator iter; |
915 |
|
for (iter = routing.begin(); iter != routing.end(); ++iter) { |
916 |
|
QTable::setPixmap(iRow, 0, pmChannel); |
917 |
|
QTable::setText(iRow, 0, pDevice->deviceTypeName() |
918 |
|
+ ' ' + QString::number(iter.key())); |
919 |
|
qsamplerChannelRoutingComboBox *pComboItem = |
920 |
|
new qsamplerChannelRoutingComboBox(this, opts, pmDevice); |
921 |
|
pComboItem->setCurrentItem(iter.data()); |
922 |
|
QTable::setItem(iRow, 1, pComboItem); |
923 |
|
++iRow; |
924 |
|
} |
925 |
|
|
926 |
|
// Adjust optimal column widths. |
927 |
|
QTable::adjustColumn(0); |
928 |
|
QTable::adjustColumn(1); |
929 |
|
|
930 |
|
QTable::setUpdatesEnabled(true); |
931 |
|
QTable::updateContents(); |
932 |
|
} |
933 |
|
|
934 |
|
|
935 |
|
// Commit any pending editing. |
936 |
|
void qsamplerChannelRoutingTable::flush (void) |
937 |
|
{ |
938 |
|
if (QTable::isEditing()) |
939 |
|
QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true); |
940 |
|
} |
941 |
|
|
942 |
|
|
943 |
return sInstrumentName; |
//------------------------------------------------------------------------- |
944 |
|
// qsamplerChannelRoutingComboBox - Custom combo box for routing table. |
945 |
|
// |
946 |
|
|
947 |
|
// Constructor. |
948 |
|
qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox ( |
949 |
|
QTable *pTable, const QStringList& list, const QPixmap& pixmap ) |
950 |
|
: QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap), |
951 |
|
m_list(list) |
952 |
|
{ |
953 |
|
m_iCurrentItem = 0; |
954 |
|
} |
955 |
|
|
956 |
|
// Public accessors. |
957 |
|
void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem ) |
958 |
|
{ |
959 |
|
m_iCurrentItem = iCurrentItem; |
960 |
|
|
961 |
|
QTableItem::setText(m_list[iCurrentItem]); |
962 |
|
} |
963 |
|
|
964 |
|
int qsamplerChannelRoutingComboBox::currentItem (void) const |
965 |
|
{ |
966 |
|
return m_iCurrentItem; |
967 |
|
} |
968 |
|
|
969 |
|
// Virtual implemetations. |
970 |
|
QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const |
971 |
|
{ |
972 |
|
QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport()); |
973 |
|
QObject::connect(pComboBox, SIGNAL(activated(int)), |
974 |
|
QTableItem::table(), SLOT(doValueChanged())); |
975 |
|
for (QStringList::ConstIterator iter = m_list.begin(); |
976 |
|
iter != m_list.end(); iter++) { |
977 |
|
pComboBox->insertItem(QTableItem::pixmap(), *iter); |
978 |
|
} |
979 |
|
pComboBox->setCurrentItem(m_iCurrentItem); |
980 |
|
return pComboBox; |
981 |
|
} |
982 |
|
|
983 |
|
void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget ) |
984 |
|
{ |
985 |
|
if (pWidget->inherits("QComboBox")) { |
986 |
|
QComboBox *pComboBox = (QComboBox *) pWidget; |
987 |
|
m_iCurrentItem = pComboBox->currentItem(); |
988 |
|
QTableItem::setText(pComboBox->currentText()); |
989 |
|
} |
990 |
|
else QTableItem::setContentFromEditor(pWidget); |
991 |
} |
} |
992 |
|
|
993 |
|
|