2 |
// |
// |
3 |
// ui.h extension file, included from the uic-generated form implementation. |
// ui.h extension file, included from the uic-generated form implementation. |
4 |
/**************************************************************************** |
/**************************************************************************** |
5 |
Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
22 |
|
|
23 |
#include <qvalidator.h> |
#include <qvalidator.h> |
24 |
#include <qmessagebox.h> |
#include <qmessagebox.h> |
25 |
|
#include <qdragobject.h> |
26 |
#include <qfileinfo.h> |
#include <qfileinfo.h> |
27 |
#include <qtooltip.h> |
#include <qtooltip.h> |
28 |
#include <qpopupmenu.h> |
#include <qpopupmenu.h> |
29 |
#include <qobjectlist.h> |
#include <qobjectlist.h> |
30 |
|
#include <qurl.h> |
31 |
|
|
32 |
#include <math.h> |
#include <math.h> |
33 |
|
|
36 |
|
|
37 |
#include "config.h" |
#include "config.h" |
38 |
|
|
39 |
|
// Channel status/usage usage limit control. |
40 |
|
#define QSAMPLER_ERROR_LIMIT 3 |
41 |
|
|
42 |
|
|
43 |
// Kind of constructor. |
// Kind of constructor. |
44 |
void qsamplerChannelStrip::init (void) |
void qsamplerChannelStrip::init (void) |
45 |
{ |
{ |
46 |
// Initialize locals. |
// Initialize locals. |
|
m_pMainForm = NULL; |
|
47 |
m_pChannel = NULL; |
m_pChannel = NULL; |
48 |
m_iDirtyChange = 0; |
m_iDirtyChange = 0; |
49 |
|
m_iErrorCount = 0; |
50 |
|
|
51 |
// Try to restore normal window positioning. |
// Try to restore normal window positioning. |
52 |
adjustSize(); |
adjustSize(); |
63 |
} |
} |
64 |
|
|
65 |
|
|
66 |
|
// Drag'n'drop file handler. |
67 |
|
bool qsamplerChannelStrip::decodeDragFile ( const QMimeSource *pEvent, QString& sInstrumentFile ) |
68 |
|
{ |
69 |
|
if (m_pChannel == NULL) |
70 |
|
return false; |
71 |
|
if (QTextDrag::canDecode(pEvent)) { |
72 |
|
QString sText; |
73 |
|
if (QTextDrag::decode(pEvent, sText)) { |
74 |
|
QStringList files = QStringList::split('\n', sText); |
75 |
|
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
76 |
|
*iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path(); |
77 |
|
if (qsamplerChannel::isInstrumentFile(*iter)) { |
78 |
|
sInstrumentFile = *iter; |
79 |
|
return true; |
80 |
|
} |
81 |
|
} |
82 |
|
} |
83 |
|
} |
84 |
|
// Fail. |
85 |
|
return false; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
// Window drag-n-drop event handlers. |
90 |
|
void qsamplerChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
91 |
|
{ |
92 |
|
QString sInstrumentFile; |
93 |
|
pDragEnterEvent->accept(decodeDragFile(pDragEnterEvent, sInstrumentFile)); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
void qsamplerChannelStrip::dropEvent ( QDropEvent* pDropEvent ) |
98 |
|
{ |
99 |
|
QString sInstrumentFile; |
100 |
|
|
101 |
|
if (decodeDragFile(pDropEvent, sInstrumentFile)) { |
102 |
|
// Go and set the dropped instrument filename... |
103 |
|
m_pChannel->setInstrument(sInstrumentFile, 0); |
104 |
|
// Open up the channel dialog. |
105 |
|
channelSetup(); |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
// Channel strip setup formal initializer. |
// Channel strip setup formal initializer. |
111 |
void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID ) |
void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel ) |
112 |
{ |
{ |
113 |
// Set main form reference. |
// Destroy any previous channel descriptor; |
114 |
m_pMainForm = pMainForm; |
// (remember that once setup we own it!) |
|
|
|
|
// Destroy any previous channel descriptor. |
|
115 |
if (m_pChannel) |
if (m_pChannel) |
116 |
delete m_pChannel; |
delete m_pChannel; |
117 |
|
|
118 |
// Create a new one... |
// Set the new one... |
119 |
m_pChannel = new qsamplerChannel(pMainForm); |
m_pChannel = pChannel; |
|
// And set appropriate settings. |
|
|
if (m_pChannel) { |
|
|
m_pChannel->setChannelID(iChannelID); |
|
|
m_iDirtyChange = 0; |
|
|
} |
|
120 |
|
|
121 |
// Stabilize this around. |
// Stabilize this around. |
122 |
updateChannelInfo(); |
updateChannelInfo(); |
123 |
|
|
124 |
|
// We'll accept drops from now on... |
125 |
|
if (m_pChannel) |
126 |
|
setAcceptDrops(true); |
127 |
} |
} |
128 |
|
|
129 |
// Channel secriptor accessor. |
// Channel secriptor accessor. |
177 |
} |
} |
178 |
|
|
179 |
|
|
180 |
// Channel setup dialog slot. |
// Maximum volume slider accessors. |
181 |
void qsamplerChannelStrip::channelSetup (void) |
void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume ) |
182 |
{ |
{ |
183 |
showChannelSetup(false); |
m_iDirtyChange++; |
184 |
|
VolumeSlider->setRange(0, iMaxVolume); |
185 |
|
VolumeSpinBox->setRange(0, iMaxVolume); |
186 |
|
m_iDirtyChange--; |
187 |
} |
} |
188 |
|
|
189 |
|
|
190 |
// Channel setup dialog. |
// Channel setup dialog slot. |
191 |
void qsamplerChannelStrip::showChannelSetup ( bool bNew ) |
bool qsamplerChannelStrip::channelSetup (void) |
192 |
{ |
{ |
193 |
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this); |
if (m_pChannel == NULL) |
194 |
if (pChannelForm) { |
return false; |
195 |
pChannelForm->setup(m_pChannel, bNew); |
|
196 |
if (pChannelForm->exec()) { |
// Invoke the channel setup dialog. |
197 |
updateChannelInfo(); |
bool bResult = m_pChannel->channelSetup(this); |
198 |
emit channelChanged(this); |
// Notify that thie channel has changed. |
199 |
} |
if (bResult) |
200 |
delete pChannelForm; |
emit channelChanged(this); |
201 |
} |
|
202 |
|
return bResult; |
203 |
} |
} |
204 |
|
|
205 |
|
|
206 |
// Update whole channel info state. |
// Channel reset slot. |
207 |
void qsamplerChannelStrip::updateChannelInfo (void) |
bool qsamplerChannelStrip::channelReset (void) |
208 |
{ |
{ |
209 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
210 |
return; |
return false; |
|
|
|
|
// Update strip caption. |
|
|
QString sText = tr("Channel %1").arg(m_pChannel->channelID()); |
|
|
setCaption(sText); |
|
|
ChannelSetupPushButton->setText(sText); |
|
211 |
|
|
212 |
// Check if we're up and connected. |
// Invoke the channel reset method. |
213 |
if (m_pChannel->client() == NULL) |
bool bResult = m_pChannel->channelReset(); |
214 |
return; |
// Notify that thie channel has changed. |
215 |
|
if (bResult) |
216 |
|
emit channelChanged(this); |
217 |
|
|
218 |
// Read actual channel information. |
return bResult; |
219 |
m_pChannel->updateChannelInfo(); |
} |
|
|
|
|
// Set some proper display values. |
|
|
const QString sIndent = " "; |
|
220 |
|
|
|
// Engine name... |
|
|
if (m_pChannel->engineName().isEmpty()) |
|
|
EngineNameTextLabel->setText(sIndent + tr("(No engine)")); |
|
|
else |
|
|
EngineNameTextLabel->setText(sIndent + m_pChannel->engineName()); |
|
221 |
|
|
222 |
// Instrument name... |
// Update the channel instrument name. |
223 |
if (m_pChannel->instrumentFile().isEmpty()) |
bool qsamplerChannelStrip::updateInstrumentName ( bool bForce ) |
224 |
InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)")); |
{ |
225 |
else |
if (m_pChannel == NULL) |
226 |
InstrumentNameTextLabel->setText(sIndent + QString("%1 [%2]") |
return false; |
|
.arg(QFileInfo(m_pChannel->instrumentFile()).fileName()).arg(m_pChannel->instrumentNr())); |
|
227 |
|
|
228 |
// Instrument status... |
// Do we refersh the actual name? |
229 |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
if (bForce) |
230 |
if (iInstrumentStatus < 0) { |
m_pChannel->updateInstrumentName(); |
|
InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red); |
|
|
InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
|
|
} else { |
|
|
InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
|
|
InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%"); |
|
|
} |
|
231 |
|
|
232 |
// MIDI Port/Channel... |
// Instrument name... |
233 |
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
if (m_pChannel->instrumentName().isEmpty()) { |
234 |
MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort())); |
if (m_pChannel->instrumentStatus() >= 0) |
235 |
else |
InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument()); |
236 |
MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1)); |
else |
237 |
|
InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
238 |
|
} else |
239 |
|
InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
240 |
|
|
241 |
// And update the both GUI volume elements. |
return true; |
|
updateChannelVolume(); |
|
242 |
} |
} |
243 |
|
|
244 |
|
|
245 |
// Do the dirty volume change. |
// Do the dirty volume change. |
246 |
void qsamplerChannelStrip::updateChannelVolume (void) |
bool qsamplerChannelStrip::updateChannelVolume (void) |
247 |
{ |
{ |
248 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
249 |
return; |
return false; |
250 |
|
|
251 |
// Convert... |
// Convert... |
252 |
#ifdef CONFIG_ROUND |
#ifdef CONFIG_ROUND |
271 |
VolumeSlider->setValue(iVolume); |
VolumeSlider->setValue(iVolume); |
272 |
VolumeSpinBox->setValue(iVolume); |
VolumeSpinBox->setValue(iVolume); |
273 |
m_iDirtyChange--; |
m_iDirtyChange--; |
274 |
|
|
275 |
|
return true; |
276 |
} |
} |
277 |
|
|
278 |
|
|
279 |
// Update whole channel usage state. |
// Update whole channel info state. |
280 |
void qsamplerChannelStrip::updateChannelUsage (void) |
bool qsamplerChannelStrip::updateChannelInfo (void) |
281 |
{ |
{ |
282 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
283 |
return; |
return false; |
284 |
|
|
285 |
|
// Check for error limit/recycle... |
286 |
|
if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) |
287 |
|
return true; |
288 |
|
|
289 |
|
// Update strip caption. |
290 |
|
QString sText = m_pChannel->channelName(); |
291 |
|
setCaption(sText); |
292 |
|
ChannelSetupPushButton->setText(sText); |
293 |
|
|
294 |
|
// Check if we're up and connected. |
295 |
if (m_pChannel->client() == NULL) |
if (m_pChannel->client() == NULL) |
296 |
return; |
return false; |
297 |
|
|
298 |
// Conditionally update whole channel status info. |
// Read actual channel information. |
299 |
if (m_pChannel->instrumentStatus() >= 0 && m_pChannel->instrumentStatus() < 100) { |
m_pChannel->updateChannelInfo(); |
300 |
updateChannelInfo(); |
|
301 |
// Once we get a complete instrument load, try a implied reset channel.... |
// Engine name... |
302 |
if (m_pChannel->instrumentStatus() == 100) |
if (m_pChannel->engineName().isEmpty()) |
303 |
m_pChannel->resetChannel(); |
EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); |
304 |
|
else |
305 |
|
EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); |
306 |
|
|
307 |
|
// Instrument name... |
308 |
|
updateInstrumentName(false); |
309 |
|
|
310 |
|
// MIDI Port/Channel... |
311 |
|
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
312 |
|
MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort())); |
313 |
|
else |
314 |
|
MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1)); |
315 |
|
|
316 |
|
// Instrument status... |
317 |
|
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
318 |
|
if (iInstrumentStatus < 0) { |
319 |
|
InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red); |
320 |
|
InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
321 |
|
m_iErrorCount++; |
322 |
|
return false; |
323 |
} |
} |
324 |
// Leave, if we still have an erroneus or incomplete instrument load. |
// All seems normal... |
325 |
if (m_pChannel->instrumentStatus() < 100) |
InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
326 |
return; |
InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%'); |
327 |
|
m_iErrorCount = 0; |
328 |
|
|
329 |
|
// And update the both GUI volume elements; |
330 |
|
// return success if, and only if, intrument is fully loaded... |
331 |
|
return updateChannelVolume() && (iInstrumentStatus == 100); |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
|
// Update whole channel usage state. |
336 |
|
bool qsamplerChannelStrip::updateChannelUsage (void) |
337 |
|
{ |
338 |
|
if (m_pChannel == NULL) |
339 |
|
return false; |
340 |
|
if (m_pChannel->client() == NULL) |
341 |
|
return false; |
342 |
|
|
343 |
|
// This only makes sense on fully loaded channels... |
344 |
|
if (m_pChannel->instrumentStatus() < 100) |
345 |
|
return false; |
346 |
|
|
347 |
// Get current channel voice count. |
// Get current channel voice count. |
348 |
int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID()); |
int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID()); |
349 |
// Get current stream count. |
// Get current stream count. |
356 |
// Update the GUI elements... |
// Update the GUI elements... |
357 |
StreamUsageProgressBar->setProgress(iStreamUsage); |
StreamUsageProgressBar->setProgress(iStreamUsage); |
358 |
StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
359 |
|
|
360 |
|
// We're clean. |
361 |
|
return true; |
362 |
} |
} |
363 |
|
|
364 |
|
|
388 |
// Context menu event handler. |
// Context menu event handler. |
389 |
void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
390 |
{ |
{ |
391 |
if (m_pMainForm == NULL) |
if (m_pChannel == NULL) |
392 |
return; |
return; |
393 |
|
|
394 |
// We'll just show up the main form's edit menu. |
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
395 |
m_pMainForm->contextMenuEvent(pEvent); |
m_pChannel->contextMenuEvent(pEvent); |
|
} |
|
|
|
|
|
|
|
|
// Maximum volume slider accessors. |
|
|
void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume ) |
|
|
{ |
|
|
m_iDirtyChange++; |
|
|
VolumeSlider->setRange(0, iMaxVolume); |
|
|
VolumeSpinBox->setRange(0, iMaxVolume); |
|
|
m_iDirtyChange--; |
|
396 |
} |
} |
397 |
|
|
398 |
|
|