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 |
|
|
38 |
|
|
39 |
// Channel status/usage usage limit control. |
// Channel status/usage usage limit control. |
40 |
#define QSAMPLER_ERROR_LIMIT 3 |
#define QSAMPLER_ERROR_LIMIT 3 |
|
#define QSAMPLER_ERROR_CYCLE 33 |
|
41 |
|
|
42 |
|
|
43 |
// Kind of constructor. |
// Kind of constructor. |
68 |
{ |
{ |
69 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
70 |
return false; |
return false; |
|
|
|
71 |
if (QTextDrag::canDecode(pEvent)) { |
if (QTextDrag::canDecode(pEvent)) { |
72 |
QString sText; |
QString sText; |
73 |
if (QTextDrag::decode(pEvent, sText)) { |
if (QTextDrag::decode(pEvent, sText)) { |
74 |
QStringList files = QStringList::split('\n', sText); |
QStringList files = QStringList::split('\n', sText); |
75 |
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
76 |
*iter = (*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null); |
*iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path(); |
77 |
if (qsamplerChannel::isInstrumentFile(*iter)) { |
if (qsamplerChannel::isInstrumentFile(*iter)) { |
78 |
sInstrumentFile = *iter; |
sInstrumentFile = *iter; |
79 |
return true; |
return true; |
117 |
|
|
118 |
// Set the new one... |
// Set the new one... |
119 |
m_pChannel = pChannel; |
m_pChannel = pChannel; |
120 |
|
|
121 |
// Stabilize this around. |
// Stabilize this around. |
122 |
updateChannelInfo(); |
updateChannelInfo(); |
123 |
|
|
171 |
pLabel->setPaletteBackgroundPixmap(pm); |
pLabel->setPaletteBackgroundPixmap(pm); |
172 |
delete pList; |
delete pList; |
173 |
} |
} |
174 |
|
|
175 |
// And this standalone too. |
// And this standalone too. |
176 |
StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm); |
StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm); |
177 |
} |
} |
190 |
// Channel setup dialog slot. |
// Channel setup dialog slot. |
191 |
bool qsamplerChannelStrip::channelSetup (void) |
bool qsamplerChannelStrip::channelSetup (void) |
192 |
{ |
{ |
193 |
|
if (m_pChannel == NULL) |
194 |
|
return false; |
195 |
|
|
196 |
// Invoke the channel setup dialog. |
// Invoke the channel setup dialog. |
197 |
bool bResult = m_pChannel->channelSetup(this); |
bool bResult = m_pChannel->channelSetup(this); |
198 |
|
// Notify that this channel has changed. |
199 |
|
if (bResult) |
200 |
|
emit channelChanged(this); |
201 |
|
|
202 |
|
return bResult; |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
// Channel mute slot. |
207 |
|
bool qsamplerChannelStrip::channelMute ( bool bMute ) |
208 |
|
{ |
209 |
|
if (m_pChannel == NULL) |
210 |
|
return false; |
211 |
|
|
212 |
if (bResult) { |
// Invoke the channel mute method. |
213 |
// Reset the error/cycle. |
bool bResult = m_pChannel->setChannelMute(bMute); |
214 |
m_iErrorCount = 0; |
// Notify that this channel has changed. |
215 |
// Notify that thie channel has changed. |
if (bResult) |
216 |
|
emit channelChanged(this); |
217 |
|
|
218 |
|
return bResult; |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
// Channel solo slot. |
223 |
|
bool qsamplerChannelStrip::channelSolo ( bool bSolo ) |
224 |
|
{ |
225 |
|
if (m_pChannel == NULL) |
226 |
|
return false; |
227 |
|
|
228 |
|
// Invoke the channel solo method. |
229 |
|
bool bResult = m_pChannel->setChannelSolo(bSolo); |
230 |
|
// Notify that this channel has changed. |
231 |
|
if (bResult) |
232 |
|
emit channelChanged(this); |
233 |
|
|
234 |
|
return bResult; |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
|
// Channel reset slot. |
239 |
|
bool qsamplerChannelStrip::channelReset (void) |
240 |
|
{ |
241 |
|
if (m_pChannel == NULL) |
242 |
|
return false; |
243 |
|
|
244 |
|
// Invoke the channel reset method. |
245 |
|
bool bResult = m_pChannel->channelReset(); |
246 |
|
// Notify that this channel has changed. |
247 |
|
if (bResult) |
248 |
emit channelChanged(this); |
emit channelChanged(this); |
|
} |
|
249 |
|
|
250 |
return bResult; |
return bResult; |
251 |
} |
} |
257 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
258 |
return false; |
return false; |
259 |
|
|
260 |
// Do we refersh the actual name? |
// Do we refresh the actual name? |
261 |
if (bForce) |
if (bForce) |
262 |
m_pChannel->updateInstrumentName(); |
m_pChannel->updateInstrumentName(); |
263 |
|
|
264 |
// Instrument name... |
// Instrument name... |
265 |
if (m_pChannel->instrumentName().isEmpty()) |
if (m_pChannel->instrumentName().isEmpty()) { |
266 |
InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
if (m_pChannel->instrumentStatus() >= 0) |
267 |
else |
InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument()); |
268 |
|
else |
269 |
|
InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
270 |
|
} else |
271 |
InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
272 |
|
|
273 |
return true; |
return true; |
274 |
} |
} |
275 |
|
|
276 |
|
|
277 |
|
// Do the dirty volume change. |
278 |
|
bool qsamplerChannelStrip::updateChannelVolume (void) |
279 |
|
{ |
280 |
|
if (m_pChannel == NULL) |
281 |
|
return false; |
282 |
|
|
283 |
|
// Convert... |
284 |
|
#ifdef CONFIG_ROUND |
285 |
|
int iVolume = (int) ::round(100.0 * m_pChannel->volume()); |
286 |
|
#else |
287 |
|
double fIPart = 0.0; |
288 |
|
double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart); |
289 |
|
int iVolume = (int) fIPart; |
290 |
|
if (fFPart >= +0.5) |
291 |
|
iVolume++; |
292 |
|
else |
293 |
|
if (fFPart <= -0.5) |
294 |
|
iVolume--; |
295 |
|
#endif |
296 |
|
|
297 |
|
// And clip... |
298 |
|
if (iVolume < 0) |
299 |
|
iVolume = 0; |
300 |
|
|
301 |
|
// Flag it here, to avoid infinite recursion. |
302 |
|
m_iDirtyChange++; |
303 |
|
VolumeSlider->setValue(iVolume); |
304 |
|
VolumeSpinBox->setValue(iVolume); |
305 |
|
m_iDirtyChange--; |
306 |
|
|
307 |
|
return true; |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
// Update whole channel info state. |
// Update whole channel info state. |
312 |
bool qsamplerChannelStrip::updateChannelInfo (void) |
bool qsamplerChannelStrip::updateChannelInfo (void) |
313 |
{ |
{ |
314 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
315 |
return false; |
return false; |
316 |
|
|
317 |
|
// Check for error limit/recycle... |
318 |
|
if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) |
319 |
|
return true; |
320 |
|
|
321 |
// Update strip caption. |
// Update strip caption. |
322 |
QString sText = m_pChannel->channelName(); |
QString sText = m_pChannel->channelName(); |
323 |
setCaption(sText); |
setCaption(sText); |
339 |
// Instrument name... |
// Instrument name... |
340 |
updateInstrumentName(false); |
updateInstrumentName(false); |
341 |
|
|
|
// Instrument status... |
|
|
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
|
|
if (iInstrumentStatus < 0) { |
|
|
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) + "%"); |
|
|
} |
|
|
|
|
342 |
// MIDI Port/Channel... |
// MIDI Port/Channel... |
343 |
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
344 |
MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort())); |
MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort())); |
345 |
else |
else |
346 |
MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1)); |
MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1)); |
347 |
|
|
348 |
// And update the both GUI volume elements. |
// Instrument status... |
349 |
return updateChannelVolume(); |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
350 |
} |
if (iInstrumentStatus < 0) { |
351 |
|
InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red); |
352 |
|
InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
353 |
// Do the dirty volume change. |
m_iErrorCount++; |
|
bool qsamplerChannelStrip::updateChannelVolume (void) |
|
|
{ |
|
|
if (m_pChannel == NULL) |
|
354 |
return false; |
return false; |
355 |
|
} |
356 |
// Convert... |
// All seems normal... |
357 |
#ifdef CONFIG_ROUND |
InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
358 |
int iVolume = (int) ::round(100.0 * m_pChannel->volume()); |
InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%'); |
359 |
|
m_iErrorCount = 0; |
360 |
|
|
361 |
|
#ifdef CONFIG_MUTE_SOLO |
362 |
|
// Mute/Solo button state coloring... |
363 |
|
const QColor& rgbNormal = ChannelSetupPushButton->paletteBackgroundColor(); |
364 |
|
bool bMute = m_pChannel->channelMute(); |
365 |
|
ChannelMutePushButton->setPaletteBackgroundColor(bMute ? Qt::red : rgbNormal); |
366 |
|
ChannelMutePushButton->setDown(bMute); |
367 |
|
bool bSolo = m_pChannel->channelSolo(); |
368 |
|
ChannelSoloPushButton->setPaletteBackgroundColor(bSolo ? Qt::yellow : rgbNormal); |
369 |
|
ChannelSoloPushButton->setDown(bSolo); |
370 |
#else |
#else |
371 |
double fIPart = 0.0; |
ChannelMutePushButton->setEnabled(false); |
372 |
double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart); |
ChannelSoloPushButton->setEnabled(false); |
|
int iVolume = (int) fIPart; |
|
|
if (fFPart >= +0.5) |
|
|
iVolume++; |
|
|
else |
|
|
if (fFPart <= -0.5) |
|
|
iVolume--; |
|
373 |
#endif |
#endif |
374 |
|
|
375 |
// And clip... |
// And update the both GUI volume elements; |
376 |
if (iVolume < 0) |
// return success if, and only if, intrument is fully loaded... |
377 |
iVolume = 0; |
return updateChannelVolume() && (iInstrumentStatus == 100); |
|
|
|
|
// Flag it here, to avoid infinite recursion. |
|
|
m_iDirtyChange++; |
|
|
VolumeSlider->setValue(iVolume); |
|
|
VolumeSpinBox->setValue(iVolume); |
|
|
m_iDirtyChange--; |
|
|
|
|
|
return true; |
|
378 |
} |
} |
379 |
|
|
380 |
|
|
386 |
if (m_pChannel->client() == NULL) |
if (m_pChannel->client() == NULL) |
387 |
return false; |
return false; |
388 |
|
|
389 |
// Check for error limit/recycle... |
// This only makes sense on fully loaded channels... |
390 |
if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) |
if (m_pChannel->instrumentStatus() < 100) |
391 |
m_iErrorCount -= QSAMPLER_ERROR_CYCLE; |
return false; |
|
if (m_iErrorCount < 0) { |
|
|
m_iErrorCount++; |
|
|
return false; |
|
|
} |
|
392 |
|
|
|
// Update whole channel status info, |
|
|
// if instrument load is still pending... |
|
|
if (m_pChannel->instrumentStatus() < 100) { |
|
|
// grab the whole sampler channel data... |
|
|
updateChannelInfo(); |
|
|
// Check (updated) status again... |
|
|
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
|
|
if (iInstrumentStatus < 100) { |
|
|
if (iInstrumentStatus < 0) |
|
|
m_iErrorCount++; |
|
|
return false; |
|
|
} |
|
|
// Once we get a complete instrument load, |
|
|
// we'll try an implied channel reset... |
|
|
m_pChannel->resetChannel(); |
|
|
// Reset error count. |
|
|
m_iErrorCount = 0; |
|
|
} |
|
|
|
|
393 |
// Get current channel voice count. |
// Get current channel voice count. |
394 |
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()); |
395 |
// Get current stream count. |
// Get current stream count. |
402 |
// Update the GUI elements... |
// Update the GUI elements... |
403 |
StreamUsageProgressBar->setProgress(iStreamUsage); |
StreamUsageProgressBar->setProgress(iStreamUsage); |
404 |
StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
405 |
|
|
406 |
// We're clean. |
// We're clean. |
407 |
return true; |
return true; |
408 |
} |
} |
436 |
{ |
{ |
437 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
438 |
return; |
return; |
439 |
|
|
440 |
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
441 |
m_pChannel->contextMenuEvent(pEvent); |
m_pChannel->contextMenuEvent(pEvent); |
442 |
} |
} |
443 |
|
|
444 |
|
|
445 |
|
// Error count hackish accessors. |
446 |
|
void qsamplerChannelStrip::resetErrorCount (void) |
447 |
|
{ |
448 |
|
m_iErrorCount = 0; |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
// end of qsamplerChannelStrip.ui.h |
// end of qsamplerChannelStrip.ui.h |