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> |
35 |
|
|
36 |
#include "config.h" |
#include "config.h" |
37 |
|
|
38 |
|
// Channel status/usage usage limit control. |
39 |
|
#define QSAMPLER_ERROR_LIMIT 3 |
40 |
|
#define QSAMPLER_ERROR_CYCLE 33 |
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 |
|
|
72 |
|
if (QTextDrag::canDecode(pEvent)) { |
73 |
|
QString sText; |
74 |
|
if (QTextDrag::decode(pEvent, sText)) { |
75 |
|
QStringList files = QStringList::split('\n', sText); |
76 |
|
for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) { |
77 |
|
*iter = (*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null); |
78 |
|
if (qsamplerChannel::isInstrumentFile(*iter)) { |
79 |
|
sInstrumentFile = *iter; |
80 |
|
return true; |
81 |
|
} |
82 |
|
} |
83 |
|
} |
84 |
|
} |
85 |
|
// Fail. |
86 |
|
return false; |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
// Window drag-n-drop event handlers. |
91 |
|
void qsamplerChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
92 |
|
{ |
93 |
|
QString sInstrumentFile; |
94 |
|
pDragEnterEvent->accept(decodeDragFile(pDragEnterEvent, sInstrumentFile)); |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
void qsamplerChannelStrip::dropEvent ( QDropEvent* pDropEvent ) |
99 |
|
{ |
100 |
|
QString sInstrumentFile; |
101 |
|
|
102 |
|
if (decodeDragFile(pDropEvent, sInstrumentFile)) { |
103 |
|
// Go and set the dropped instrument filename... |
104 |
|
m_pChannel->setInstrument(sInstrumentFile, 0); |
105 |
|
// Open up the channel dialog. |
106 |
|
channelSetup(); |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
// Channel strip setup formal initializer. |
// Channel strip setup formal initializer. |
112 |
void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID ) |
void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel ) |
113 |
{ |
{ |
114 |
// Set main form reference. |
// Destroy any previous channel descriptor; |
115 |
m_pMainForm = pMainForm; |
// (remember that once setup we own it!) |
|
|
|
|
// Destroy any previous channel descriptor. |
|
116 |
if (m_pChannel) |
if (m_pChannel) |
117 |
delete m_pChannel; |
delete m_pChannel; |
118 |
|
|
119 |
// Create a new one... |
// Set the new one... |
120 |
m_pChannel = new qsamplerChannel(pMainForm); |
m_pChannel = pChannel; |
|
// And set appropriate settings. |
|
|
if (m_pChannel && iChannelID >= 0) { |
|
|
m_pChannel->setChannelID(iChannelID); |
|
|
m_iDirtyChange = 0; |
|
|
} |
|
121 |
|
|
122 |
// Stabilize this around. |
// Stabilize this around. |
123 |
updateChannelInfo(); |
updateChannelInfo(); |
124 |
|
|
125 |
|
// We'll accept drops from now on... |
126 |
|
if (m_pChannel) |
127 |
|
setAcceptDrops(true); |
128 |
} |
} |
129 |
|
|
130 |
// Channel secriptor accessor. |
// Channel secriptor accessor. |
178 |
} |
} |
179 |
|
|
180 |
|
|
181 |
|
// Maximum volume slider accessors. |
182 |
|
void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume ) |
183 |
|
{ |
184 |
|
m_iDirtyChange++; |
185 |
|
VolumeSlider->setRange(0, iMaxVolume); |
186 |
|
VolumeSpinBox->setRange(0, iMaxVolume); |
187 |
|
m_iDirtyChange--; |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
// Channel setup dialog slot. |
// Channel setup dialog slot. |
192 |
bool qsamplerChannelStrip::channelSetup (void) |
bool qsamplerChannelStrip::channelSetup (void) |
193 |
{ |
{ |
194 |
bool bResult = false; |
// Invoke the channel setup dialog. |
195 |
|
bool bResult = m_pChannel->channelSetup(this); |
196 |
|
|
197 |
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this); |
if (bResult) { |
198 |
if (pChannelForm) { |
// Reset the error/cycle. |
199 |
pChannelForm->setup(m_pChannel); |
m_iErrorCount = 0; |
200 |
bResult = pChannelForm->exec(); |
// Notify that thie channel has changed. |
201 |
delete pChannelForm; |
emit channelChanged(this); |
202 |
} |
} |
203 |
|
|
204 |
if (bResult) |
return bResult; |
205 |
emit channelChanged(this); |
} |
206 |
|
|
207 |
|
|
208 |
|
// Update the channel instrument name. |
209 |
|
bool qsamplerChannelStrip::updateInstrumentName ( bool bForce ) |
210 |
|
{ |
211 |
|
if (m_pChannel == NULL) |
212 |
|
return false; |
213 |
|
|
214 |
return bResult; |
// Do we refersh the actual name? |
215 |
|
if (bForce) |
216 |
|
m_pChannel->updateInstrumentName(); |
217 |
|
|
218 |
|
// Instrument name... |
219 |
|
if (m_pChannel->instrumentName().isEmpty()) |
220 |
|
InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
221 |
|
else |
222 |
|
InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
223 |
|
|
224 |
|
return true; |
225 |
} |
} |
226 |
|
|
227 |
|
|
243 |
// Read actual channel information. |
// Read actual channel information. |
244 |
m_pChannel->updateChannelInfo(); |
m_pChannel->updateChannelInfo(); |
245 |
|
|
|
// Set some proper display values. |
|
|
const QString sIndent = " "; |
|
|
|
|
246 |
// Engine name... |
// Engine name... |
247 |
if (m_pChannel->engineName().isEmpty()) |
if (m_pChannel->engineName().isEmpty()) |
248 |
EngineNameTextLabel->setText(sIndent + tr("(No engine)")); |
EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); |
249 |
else |
else |
250 |
EngineNameTextLabel->setText(sIndent + m_pChannel->engineName()); |
EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); |
251 |
|
|
252 |
// Instrument name... |
// Instrument name... |
253 |
if (m_pChannel->instrumentFile().isEmpty()) |
updateInstrumentName(false); |
|
InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)")); |
|
|
else |
|
|
InstrumentNameTextLabel->setText(sIndent + QString("%1 [%2]") |
|
|
.arg(QFileInfo(m_pChannel->instrumentFile()).fileName()).arg(m_pChannel->instrumentNr())); |
|
254 |
|
|
255 |
// Instrument status... |
// Instrument status... |
256 |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
315 |
if (m_pChannel->client() == NULL) |
if (m_pChannel->client() == NULL) |
316 |
return false; |
return false; |
317 |
|
|
318 |
// Conditionally update whole channel status info. |
// Check for error limit/recycle... |
319 |
if (m_pChannel->instrumentStatus() >= 0 && m_pChannel->instrumentStatus() < 100) { |
if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) |
320 |
updateChannelInfo(); |
m_iErrorCount -= QSAMPLER_ERROR_CYCLE; |
321 |
// Once we get a complete instrument load, try a implied reset channel.... |
if (m_iErrorCount < 0) { |
322 |
if (m_pChannel->instrumentStatus() == 100) |
m_iErrorCount++; |
323 |
m_pChannel->resetChannel(); |
return false; |
324 |
} |
} |
325 |
// Leave, if we still have an erroneus or incomplete instrument load. |
|
326 |
if (m_pChannel->instrumentStatus() < 100) |
// Update whole channel status info, |
327 |
return false; |
// if instrument load is still pending... |
328 |
|
if (m_pChannel->instrumentStatus() < 100) { |
329 |
|
// grab the whole sampler channel data... |
330 |
|
updateChannelInfo(); |
331 |
|
// Check (updated) status again... |
332 |
|
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
333 |
|
if (iInstrumentStatus < 100) { |
334 |
|
if (iInstrumentStatus < 0) |
335 |
|
m_iErrorCount++; |
336 |
|
return false; |
337 |
|
} |
338 |
|
// Once we get a complete instrument load, |
339 |
|
// we'll try an implied channel reset... |
340 |
|
m_pChannel->resetChannel(); |
341 |
|
// Reset error count. |
342 |
|
m_iErrorCount = 0; |
343 |
|
} |
344 |
|
|
345 |
// Get current channel voice count. |
// Get current channel voice count. |
346 |
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()); |
347 |
// Get current stream count. |
// Get current stream count. |
386 |
// Context menu event handler. |
// Context menu event handler. |
387 |
void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
388 |
{ |
{ |
389 |
if (m_pMainForm == NULL) |
if (m_pChannel == NULL) |
390 |
return; |
return; |
391 |
|
|
392 |
// We'll just show up the main form's edit menu. |
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
393 |
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--; |
|
394 |
} |
} |
395 |
|
|
396 |
|
|