1 |
// qsamplerChannelStrip.ui.h |
2 |
// |
3 |
// ui.h extension file, included from the uic-generated form implementation. |
4 |
/**************************************************************************** |
5 |
Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
7 |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
9 |
as published by the Free Software Foundation; either version 2 |
10 |
of the License, or (at your option) any later version. |
11 |
|
12 |
This program is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License |
18 |
along with this program; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 |
|
21 |
*****************************************************************************/ |
22 |
|
23 |
#include <qvalidator.h> |
24 |
#include <qmessagebox.h> |
25 |
#include <qfileinfo.h> |
26 |
#include <qtooltip.h> |
27 |
|
28 |
#include <math.h> |
29 |
|
30 |
#include "qsamplerMainForm.h" |
31 |
#include "qsamplerChannelForm.h" |
32 |
|
33 |
#include "config.h" |
34 |
|
35 |
|
36 |
// Kind of constructor. |
37 |
void qsamplerChannelStrip::init (void) |
38 |
{ |
39 |
// Initialize locals. |
40 |
m_pMainForm = NULL; |
41 |
m_iChannelID = 0; |
42 |
|
43 |
// m_sEngineName = "(No engine)"; |
44 |
// m_sInstrumentFile = "(No instrument)"; |
45 |
m_iInstrumentNr = 0; |
46 |
m_sMidiDriver = "ALSA"; // DEPRECATED. |
47 |
m_iMidiDevice = 0; |
48 |
m_iMidiPort = 0; |
49 |
m_iMidiChannel = 0; |
50 |
m_sAudioDriver = "ALSA"; // DEPRECATED. |
51 |
m_iAudioDevice = 0; |
52 |
m_fVolume = 0.8; |
53 |
|
54 |
m_iDirtyChange = 0; |
55 |
|
56 |
// Try to restore normal window positioning. |
57 |
adjustSize(); |
58 |
} |
59 |
|
60 |
|
61 |
// Kind of destructor. |
62 |
void qsamplerChannelStrip::destroy (void) |
63 |
{ |
64 |
} |
65 |
|
66 |
|
67 |
// Channel strip setup formal initializer. |
68 |
void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID ) |
69 |
{ |
70 |
m_iDirtyChange = 0; |
71 |
m_pMainForm = pMainForm; |
72 |
|
73 |
setChannelID(iChannelID); |
74 |
} |
75 |
|
76 |
|
77 |
// The global options settings delegated property. |
78 |
qsamplerOptions *qsamplerChannelStrip::options (void) |
79 |
{ |
80 |
if (m_pMainForm == NULL) |
81 |
return NULL; |
82 |
|
83 |
return m_pMainForm->options(); |
84 |
} |
85 |
|
86 |
|
87 |
// The client descriptor delegated property. |
88 |
lscp_client_t *qsamplerChannelStrip::client (void) |
89 |
{ |
90 |
if (m_pMainForm == NULL) |
91 |
return NULL; |
92 |
|
93 |
return m_pMainForm->client(); |
94 |
} |
95 |
|
96 |
|
97 |
// Channel-ID (aka Sammpler-Channel) accessors. |
98 |
int qsamplerChannelStrip::channelID (void) |
99 |
{ |
100 |
return m_iChannelID; |
101 |
} |
102 |
|
103 |
void qsamplerChannelStrip::setChannelID ( int iChannelID ) |
104 |
{ |
105 |
m_iChannelID = iChannelID; |
106 |
|
107 |
updateChannelInfo(); |
108 |
} |
109 |
|
110 |
|
111 |
// Engine name accessors. |
112 |
QString& qsamplerChannelStrip::engineName (void) |
113 |
{ |
114 |
return m_sEngineName; |
115 |
} |
116 |
|
117 |
bool qsamplerChannelStrip::loadEngine ( const QString& sEngineName ) |
118 |
{ |
119 |
if (client() == NULL) |
120 |
return false; |
121 |
|
122 |
if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
123 |
appendMessagesClient("lscp_load_engine"); |
124 |
return false; |
125 |
} |
126 |
|
127 |
m_sEngineName = sEngineName; |
128 |
return true; |
129 |
} |
130 |
|
131 |
|
132 |
// Instrument filename accessors. |
133 |
QString& qsamplerChannelStrip::instrumentFile (void) |
134 |
{ |
135 |
return m_sInstrumentFile; |
136 |
} |
137 |
|
138 |
// Instrument index accessors. |
139 |
int qsamplerChannelStrip::instrumentNr (void) |
140 |
{ |
141 |
return m_iInstrumentNr; |
142 |
} |
143 |
|
144 |
bool qsamplerChannelStrip::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
145 |
{ |
146 |
if (client() == NULL) |
147 |
return false; |
148 |
|
149 |
if (::lscp_load_instrument(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { |
150 |
appendMessagesClient("lscp_load_instrument"); |
151 |
return false; |
152 |
} |
153 |
|
154 |
m_sInstrumentFile = sInstrumentFile; |
155 |
m_iInstrumentNr = iInstrumentNr; |
156 |
return true; |
157 |
} |
158 |
|
159 |
|
160 |
// MIDI driver type accessors (DEPRECATED). |
161 |
QString& qsamplerChannelStrip::midiDriver (void) |
162 |
{ |
163 |
return m_sMidiDriver; |
164 |
} |
165 |
|
166 |
bool qsamplerChannelStrip::setMidiDriver ( const QString& sMidiDriver ) |
167 |
{ |
168 |
if (client() == NULL) |
169 |
return false; |
170 |
|
171 |
if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
172 |
appendMessagesClient("lscp_set_channel_midi_type"); |
173 |
return false; |
174 |
} |
175 |
|
176 |
m_sMidiDriver = sMidiDriver; |
177 |
return true; |
178 |
} |
179 |
|
180 |
|
181 |
// MIDI device accessors. |
182 |
int qsamplerChannelStrip::midiDevice (void) |
183 |
{ |
184 |
return m_iMidiDevice; |
185 |
} |
186 |
|
187 |
bool qsamplerChannelStrip::setMidiDevice ( int iMidiDevice ) |
188 |
{ |
189 |
if (client() == NULL) |
190 |
return false; |
191 |
|
192 |
// FIXME: call this when LSCP becomes stable. |
193 |
// if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
194 |
// appendMessagesClient("lscp_set_channel_midi_device"); |
195 |
// return false; |
196 |
// } |
197 |
|
198 |
m_iMidiDevice = iMidiDevice; |
199 |
return true; |
200 |
} |
201 |
|
202 |
|
203 |
// MIDI port number accessor. |
204 |
int qsamplerChannelStrip::midiPort (void) |
205 |
{ |
206 |
return m_iMidiPort; |
207 |
} |
208 |
|
209 |
bool qsamplerChannelStrip::setMidiPort ( int iMidiPort ) |
210 |
{ |
211 |
if (client() == NULL) |
212 |
return false; |
213 |
|
214 |
// FIXME: call this when LSCP becomes stable. |
215 |
// if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
216 |
// appendMessagesClient("lscp_set_channel_midi_port"); |
217 |
// return false; |
218 |
// } |
219 |
|
220 |
m_iMidiPort = iMidiPort; |
221 |
return true; |
222 |
} |
223 |
|
224 |
|
225 |
// MIDI channel accessor. |
226 |
int qsamplerChannelStrip::midiChannel (void) |
227 |
{ |
228 |
return m_iMidiChannel; |
229 |
} |
230 |
|
231 |
bool qsamplerChannelStrip::setMidiChannel ( int iMidiChannel ) |
232 |
{ |
233 |
if (client() == NULL) |
234 |
return false; |
235 |
|
236 |
// FIXME: call this when LSCP becomes stable. |
237 |
// if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
238 |
// appendMessagesClient("lscp_set_channel_midi_channel"); |
239 |
// return false; |
240 |
// } |
241 |
|
242 |
m_iMidiChannel = iMidiChannel; |
243 |
return true; |
244 |
} |
245 |
|
246 |
|
247 |
// Audio device accessor. |
248 |
int qsamplerChannelStrip::audioDevice (void) |
249 |
{ |
250 |
return m_iAudioDevice; |
251 |
} |
252 |
|
253 |
bool qsamplerChannelStrip::setAudioDevice ( int iAudioDevice ) |
254 |
{ |
255 |
if (client() == NULL) |
256 |
return false; |
257 |
|
258 |
// FIXME: call this when LSCP becomes stable. |
259 |
// if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
260 |
// appendMessagesClient("lscp_set_channel_audio_device"); |
261 |
// return false; |
262 |
// } |
263 |
|
264 |
m_iAudioDevice = iAudioDevice; |
265 |
return true; |
266 |
} |
267 |
|
268 |
|
269 |
// Audio driver type accessors (DEPRECATED). |
270 |
QString& qsamplerChannelStrip::audioDriver (void) |
271 |
{ |
272 |
return m_sAudioDriver; |
273 |
} |
274 |
|
275 |
bool qsamplerChannelStrip::setAudioDriver ( const QString& sAudioDriver ) |
276 |
{ |
277 |
if (client() == NULL) |
278 |
return false; |
279 |
|
280 |
if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
281 |
appendMessagesClient("lscp_set_channel_audio_type"); |
282 |
return false; |
283 |
} |
284 |
|
285 |
m_sAudioDriver = sAudioDriver; |
286 |
return true; |
287 |
} |
288 |
|
289 |
|
290 |
// Channel volume accessors. |
291 |
float qsamplerChannelStrip::volume (void) |
292 |
{ |
293 |
return m_fVolume; |
294 |
} |
295 |
|
296 |
bool qsamplerChannelStrip::setVolume ( float fVolume ) |
297 |
{ |
298 |
if (client() == NULL) |
299 |
return false; |
300 |
|
301 |
if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { |
302 |
appendMessagesClient("lscp_set_channel_volume"); |
303 |
return false; |
304 |
} |
305 |
|
306 |
m_fVolume = fVolume; |
307 |
return true; |
308 |
} |
309 |
|
310 |
|
311 |
// Messages view font accessors. |
312 |
QFont qsamplerChannelStrip::displayFont (void) |
313 |
{ |
314 |
return EngineNameTextLabel->font(); |
315 |
} |
316 |
|
317 |
void qsamplerChannelStrip::setDisplayFont ( const QFont & font ) |
318 |
{ |
319 |
EngineNameTextLabel->setFont(font); |
320 |
InstrumentNameTextLabel->setFont(font); |
321 |
MidiPortChannelTextLabel->setFont(font); |
322 |
} |
323 |
|
324 |
// Channel setup dialog. |
325 |
void qsamplerChannelStrip::channelSetup (void) |
326 |
{ |
327 |
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this); |
328 |
if (pChannelForm) { |
329 |
pChannelForm->setup(this); |
330 |
if (pChannelForm->exec()) { |
331 |
updateChannelInfo(); |
332 |
emit channelChanged(this); |
333 |
} |
334 |
delete pChannelForm; |
335 |
} |
336 |
} |
337 |
|
338 |
|
339 |
// Update whole channel info state. |
340 |
void qsamplerChannelStrip::updateChannelInfo (void) |
341 |
{ |
342 |
// Update strip caption. |
343 |
QString sText = tr("Channel %1").arg(m_iChannelID); |
344 |
setCaption(sText); |
345 |
ChannelSetupPushButton->setText(sText); |
346 |
|
347 |
// Check if we're up and connected. |
348 |
if (client() == NULL) |
349 |
return; |
350 |
|
351 |
// Read channel information. |
352 |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID); |
353 |
if (pChannelInfo == NULL) { |
354 |
appendMessagesClient("lscp_get_channel_info"); |
355 |
// appendMessagesError(tr("Could not get channel information.\n\nSorry.")); |
356 |
} else { |
357 |
// Cache in channel information. |
358 |
m_sEngineName = pChannelInfo->engine_name; |
359 |
m_sInstrumentFile = pChannelInfo->instrument_file; |
360 |
m_iInstrumentNr = pChannelInfo->instrument_nr; |
361 |
m_iMidiDevice = pChannelInfo->midi_device; |
362 |
m_iMidiPort = pChannelInfo->midi_port; |
363 |
m_iMidiChannel = pChannelInfo->midi_channel; |
364 |
m_iAudioDevice = pChannelInfo->audio_device; |
365 |
m_fVolume = pChannelInfo->volume; |
366 |
} |
367 |
|
368 |
// Set some proper display values. |
369 |
|
370 |
// Engine name... |
371 |
if (m_sEngineName.isEmpty()) |
372 |
EngineNameTextLabel->setText(tr("(No engine)")); |
373 |
else |
374 |
EngineNameTextLabel->setText(m_sEngineName); |
375 |
|
376 |
// Instrument name... |
377 |
if (m_sInstrumentFile.isEmpty()) |
378 |
InstrumentNameTextLabel->setText(tr("(No instrument)")); |
379 |
else |
380 |
InstrumentNameTextLabel->setText(QString("%1 [%2]") |
381 |
.arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr)); |
382 |
|
383 |
// MIDI Port/Channel... |
384 |
MidiPortChannelTextLabel->setText(QString("%1 / %2") |
385 |
.arg(m_iMidiPort).arg(m_iMidiChannel)); |
386 |
|
387 |
// And update the both GUI volume elements. |
388 |
updateChannelVolume(); |
389 |
} |
390 |
|
391 |
|
392 |
// Do the dirty volume change. |
393 |
void qsamplerChannelStrip::updateChannelVolume (void) |
394 |
{ |
395 |
// Convert... |
396 |
#ifdef CONFIG_ROUND |
397 |
int iVolume = (int) ::round(100.0 * m_fVolume); |
398 |
#else |
399 |
double fIPart = 0.0; |
400 |
double fFPart = ::modf(100.0 * m_fVolume, &fIPart); |
401 |
int iVolume = (int) fIPart; |
402 |
if (fFPart >= +0.5) |
403 |
iVolume++; |
404 |
else |
405 |
if (fFPart <= -0.5) |
406 |
iVolume--; |
407 |
#endif |
408 |
|
409 |
// And clip... |
410 |
if (iVolume > 100) |
411 |
iVolume = 100; |
412 |
else if (iVolume < 0) |
413 |
iVolume = 0; |
414 |
|
415 |
// Flag it here, to avoid infinite recursion. |
416 |
m_iDirtyChange++; |
417 |
VolumeSlider->setValue(iVolume); |
418 |
VolumeSpinBox->setValue(iVolume); |
419 |
m_iDirtyChange--; |
420 |
} |
421 |
|
422 |
|
423 |
// Update whole channel usage state. |
424 |
void qsamplerChannelStrip::updateChannelUsage (void) |
425 |
{ |
426 |
if (client() == NULL) |
427 |
return; |
428 |
|
429 |
// Get current channel voice count. |
430 |
int iVoiceCount = ::lscp_get_channel_voice_count(client(), m_iChannelID); |
431 |
// Get current stream count. |
432 |
int iStreamCount = ::lscp_get_channel_stream_count(client(), m_iChannelID); |
433 |
// Get current channel buffer fill usage. |
434 |
// As benno has suggested this is the percentage usage |
435 |
// of the least filled buffer stream... |
436 |
int iStreamUsage = 0; |
437 |
if (iStreamCount > 0) { |
438 |
lscp_buffer_fill_t *pBufferFill = ::lscp_get_channel_buffer_fill(client(), LSCP_USAGE_PERCENTAGE, m_iChannelID); |
439 |
if (pBufferFill) { |
440 |
for (int iStream = 0; iStream < iStreamCount; iStream++) { |
441 |
if (iStreamUsage > (int) pBufferFill[iStream].stream_usage || iStream == 0) |
442 |
iStreamUsage = pBufferFill[iStream].stream_usage; |
443 |
} |
444 |
} |
445 |
} |
446 |
// Update the GUI elements... |
447 |
StreamUsageProgressBar->setProgress(iStreamUsage); |
448 |
StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
449 |
} |
450 |
|
451 |
|
452 |
// Volume change slot. |
453 |
void qsamplerChannelStrip::volumeChanged ( int iVolume ) |
454 |
{ |
455 |
// Avoid recursion. |
456 |
if (m_iDirtyChange > 0) |
457 |
return; |
458 |
|
459 |
// Convert and clip. |
460 |
float fVolume = (float) iVolume / 100.0; |
461 |
if (fVolume > 1.0) |
462 |
fVolume = 1.0; |
463 |
else if (fVolume < 0.0) |
464 |
fVolume = 0.0; |
465 |
|
466 |
// Update the GUI elements. |
467 |
if (setVolume(fVolume)) { |
468 |
updateChannelVolume(); |
469 |
emit channelChanged(this); |
470 |
} |
471 |
} |
472 |
|
473 |
|
474 |
// Redirected messages output methods. |
475 |
void qsamplerChannelStrip::appendMessages( const QString& s ) |
476 |
{ |
477 |
m_pMainForm->appendMessages(s); |
478 |
} |
479 |
|
480 |
void qsamplerChannelStrip::appendMessagesColor( const QString& s, const QString& c ) |
481 |
{ |
482 |
m_pMainForm->appendMessagesColor(s, c); |
483 |
} |
484 |
|
485 |
void qsamplerChannelStrip::appendMessagesText( const QString& s ) |
486 |
{ |
487 |
m_pMainForm->appendMessagesText(s); |
488 |
} |
489 |
|
490 |
void qsamplerChannelStrip::appendMessagesError( const QString& s ) |
491 |
{ |
492 |
m_pMainForm->appendMessagesError(s); |
493 |
} |
494 |
|
495 |
void qsamplerChannelStrip::appendMessagesClient( const QString& s ) |
496 |
{ |
497 |
m_pMainForm->appendMessagesClient(s); |
498 |
} |
499 |
|
500 |
|
501 |
// end of qsamplerChannelStrip.ui.h |
502 |
|