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