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-2007, 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 |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License along |
18 |
along with this program; if not, write to the Free Software |
with this program; if not, write to the Free Software Foundation, Inc., |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
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> |
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. |
47 |
m_pMainForm = NULL; |
m_pChannel = NULL; |
|
m_iChannelID = 0; |
|
|
|
|
|
// m_sEngineName = tr("(No engine)"); |
|
|
// m_sInstrumentFile = tr("(No instrument)"); |
|
|
m_iInstrumentNr = -1; |
|
|
m_iInstrumentStatus = -1; |
|
|
m_sMidiDriver = "Alsa"; // DEPRECATED. |
|
|
m_iMidiDevice = -1; |
|
|
m_iMidiPort = -1; |
|
|
m_iMidiChannel = -1; |
|
|
m_sAudioDriver = "Alsa"; // DEPRECATED. |
|
|
m_iAudioDevice = -1; |
|
|
m_fVolume = 0.0; |
|
|
|
|
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(); |
56 |
// Kind of destructor. |
// Kind of destructor. |
57 |
void qsamplerChannelStrip::destroy (void) |
void qsamplerChannelStrip::destroy (void) |
58 |
{ |
{ |
59 |
|
// Destroy existing channel descriptor. |
60 |
|
if (m_pChannel) |
61 |
|
delete m_pChannel; |
62 |
|
m_pChannel = NULL; |
63 |
} |
} |
64 |
|
|
65 |
|
|
66 |
// Channel strip setup formal initializer. |
// Drag'n'drop file handler. |
67 |
void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID ) |
bool qsamplerChannelStrip::decodeDragFile ( const QMimeSource *pEvent, QString& sInstrumentFile ) |
68 |
{ |
{ |
69 |
m_iDirtyChange = 0; |
if (m_pChannel == NULL) |
70 |
m_pMainForm = pMainForm; |
return false; |
71 |
|
if (QTextDrag::canDecode(pEvent)) { |
72 |
setChannelID(iChannelID); |
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 |
// The global options settings delegated property. |
// Window drag-n-drop event handlers. |
90 |
qsamplerOptions *qsamplerChannelStrip::options (void) |
void qsamplerChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
91 |
{ |
{ |
92 |
if (m_pMainForm == NULL) |
QString sInstrumentFile; |
93 |
return NULL; |
pDragEnterEvent->accept(decodeDragFile(pDragEnterEvent, sInstrumentFile)); |
|
|
|
|
return m_pMainForm->options(); |
|
94 |
} |
} |
95 |
|
|
96 |
|
|
97 |
// The client descriptor delegated property. |
void qsamplerChannelStrip::dropEvent ( QDropEvent* pDropEvent ) |
|
lscp_client_t *qsamplerChannelStrip::client (void) |
|
98 |
{ |
{ |
99 |
if (m_pMainForm == NULL) |
QString sInstrumentFile; |
|
return NULL; |
|
100 |
|
|
101 |
return m_pMainForm->client(); |
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-ID (aka Sammpler-Channel) accessors. |
// Channel strip setup formal initializer. |
111 |
int qsamplerChannelStrip::channelID (void) |
void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel ) |
112 |
{ |
{ |
113 |
return m_iChannelID; |
// Destroy any previous channel descriptor; |
114 |
} |
// (remember that once setup we own it!) |
115 |
|
if (m_pChannel) |
116 |
|
delete m_pChannel; |
117 |
|
|
118 |
void qsamplerChannelStrip::setChannelID ( int iChannelID ) |
// Set the new one... |
119 |
{ |
m_pChannel = pChannel; |
|
m_iChannelID = iChannelID; |
|
120 |
|
|
121 |
|
// Stabilize this around. |
122 |
updateChannelInfo(); |
updateChannelInfo(); |
|
} |
|
|
|
|
123 |
|
|
124 |
// Engine name accessors. |
// We'll accept drops from now on... |
125 |
QString& qsamplerChannelStrip::engineName (void) |
if (m_pChannel) |
126 |
{ |
setAcceptDrops(true); |
|
return m_sEngineName; |
|
127 |
} |
} |
128 |
|
|
129 |
bool qsamplerChannelStrip::loadEngine ( const QString& sEngineName ) |
// Channel secriptor accessor. |
130 |
|
qsamplerChannel *qsamplerChannelStrip::channel (void) |
131 |
{ |
{ |
132 |
if (client() == NULL) |
return m_pChannel; |
|
return false; |
|
|
|
|
|
if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
|
|
appendMessagesClient("lscp_load_engine"); |
|
|
return false; |
|
|
} |
|
|
|
|
|
m_sEngineName = sEngineName; |
|
|
return true; |
|
133 |
} |
} |
134 |
|
|
135 |
|
|
136 |
// Instrument filename accessor. |
// Messages view font accessors. |
137 |
QString& qsamplerChannelStrip::instrumentFile (void) |
QFont qsamplerChannelStrip::displayFont (void) |
138 |
{ |
{ |
139 |
return m_sInstrumentFile; |
return EngineNameTextLabel->font(); |
140 |
} |
} |
141 |
|
|
142 |
// Instrument index accessor. |
void qsamplerChannelStrip::setDisplayFont ( const QFont & font ) |
|
int qsamplerChannelStrip::instrumentNr (void) |
|
143 |
{ |
{ |
144 |
return m_iInstrumentNr; |
EngineNameTextLabel->setFont(font); |
145 |
|
MidiPortChannelTextLabel->setFont(font); |
146 |
|
InstrumentNameTextLabel->setFont(font); |
147 |
|
InstrumentStatusTextLabel->setFont(font); |
148 |
} |
} |
149 |
|
|
|
// Instrument status accessor. |
|
|
int qsamplerChannelStrip::instrumentStatus (void) |
|
|
{ |
|
|
return m_iInstrumentStatus; |
|
|
} |
|
150 |
|
|
151 |
// Instrument file loader. |
// Channel display background effect. |
152 |
bool qsamplerChannelStrip::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
void qsamplerChannelStrip::setDisplayEffect ( bool bDisplayEffect ) |
153 |
{ |
{ |
154 |
if (client() == NULL) |
QPixmap pm; |
155 |
return false; |
if (bDisplayEffect) |
156 |
|
pm = QPixmap::fromMimeSource("displaybg1.png"); |
157 |
if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { |
setDisplayBackground(pm); |
|
appendMessagesClient("lscp_load_instrument"); |
|
|
return false; |
|
|
} |
|
|
|
|
|
m_sInstrumentFile = sInstrumentFile; |
|
|
m_iInstrumentNr = iInstrumentNr; |
|
|
m_iInstrumentStatus = 0; |
|
|
|
|
|
return true; |
|
158 |
} |
} |
159 |
|
|
160 |
|
|
161 |
// MIDI driver type accessors (DEPRECATED). |
// Update main display background pixmap. |
162 |
QString& qsamplerChannelStrip::midiDriver (void) |
void qsamplerChannelStrip::setDisplayBackground ( const QPixmap& pm ) |
|
{ |
|
|
return m_sMidiDriver; |
|
|
} |
|
|
|
|
|
bool qsamplerChannelStrip::setMidiDriver ( const QString& sMidiDriver ) |
|
163 |
{ |
{ |
164 |
if (client() == NULL) |
// Set the main origin... |
165 |
return false; |
ChannelInfoFrame->setPaletteBackgroundPixmap(pm); |
166 |
|
|
167 |
if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
// Iterate for every child text label... |
168 |
appendMessagesClient("lscp_set_channel_midi_type"); |
QObjectList *pList = ChannelInfoFrame->queryList("QLabel"); |
169 |
return false; |
if (pList) { |
170 |
|
for (QLabel *pLabel = (QLabel *) pList->first(); pLabel; pLabel = (QLabel *) pList->next()) |
171 |
|
pLabel->setPaletteBackgroundPixmap(pm); |
172 |
|
delete pList; |
173 |
} |
} |
174 |
|
|
175 |
m_sMidiDriver = sMidiDriver; |
// And this standalone too. |
176 |
return true; |
StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm); |
177 |
} |
} |
178 |
|
|
179 |
|
|
180 |
// MIDI device accessors. |
// Maximum volume slider accessors. |
181 |
int qsamplerChannelStrip::midiDevice (void) |
void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume ) |
182 |
{ |
{ |
183 |
return m_iMidiDevice; |
m_iDirtyChange++; |
184 |
|
VolumeSlider->setRange(0, iMaxVolume); |
185 |
|
VolumeSpinBox->setRange(0, iMaxVolume); |
186 |
|
m_iDirtyChange--; |
187 |
} |
} |
188 |
|
|
|
bool qsamplerChannelStrip::setMidiDevice ( int iMidiDevice ) |
|
|
{ |
|
|
if (client() == NULL) |
|
|
return false; |
|
189 |
|
|
190 |
if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
// Channel setup dialog slot. |
191 |
appendMessagesClient("lscp_set_channel_midi_device"); |
bool qsamplerChannelStrip::channelSetup (void) |
192 |
return false; |
{ |
193 |
} |
if (m_pChannel == NULL) |
194 |
|
return false; |
195 |
|
|
196 |
|
// Invoke the channel setup dialog. |
197 |
|
bool bResult = m_pChannel->channelSetup(this); |
198 |
|
// Notify that this channel has changed. |
199 |
|
if (bResult) |
200 |
|
emit channelChanged(this); |
201 |
|
|
202 |
m_iMidiDevice = iMidiDevice; |
return bResult; |
|
return true; |
|
203 |
} |
} |
204 |
|
|
205 |
|
|
206 |
// MIDI port number accessor. |
// Channel mute slot. |
207 |
int qsamplerChannelStrip::midiPort (void) |
bool qsamplerChannelStrip::channelMute ( bool bMute ) |
|
{ |
|
|
return m_iMidiPort; |
|
|
} |
|
|
|
|
|
bool qsamplerChannelStrip::setMidiPort ( int iMidiPort ) |
|
208 |
{ |
{ |
209 |
if (client() == NULL) |
if (m_pChannel == NULL) |
210 |
return false; |
return false; |
211 |
|
|
212 |
if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
// Invoke the channel mute method. |
213 |
appendMessagesClient("lscp_set_channel_midi_port"); |
bool bResult = m_pChannel->setChannelMute(bMute); |
214 |
return false; |
// Notify that this channel has changed. |
215 |
} |
if (bResult) |
216 |
|
emit channelChanged(this); |
217 |
|
|
218 |
m_iMidiPort = iMidiPort; |
return bResult; |
|
return true; |
|
219 |
} |
} |
220 |
|
|
221 |
|
|
222 |
// MIDI channel accessor. |
// Channel solo slot. |
223 |
int qsamplerChannelStrip::midiChannel (void) |
bool qsamplerChannelStrip::channelSolo ( bool bSolo ) |
|
{ |
|
|
return m_iMidiChannel; |
|
|
} |
|
|
|
|
|
bool qsamplerChannelStrip::setMidiChannel ( int iMidiChannel ) |
|
224 |
{ |
{ |
225 |
if (client() == NULL) |
if (m_pChannel == NULL) |
226 |
return false; |
return false; |
227 |
|
|
228 |
if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
// Invoke the channel solo method. |
229 |
appendMessagesClient("lscp_set_channel_midi_channel"); |
bool bResult = m_pChannel->setChannelSolo(bSolo); |
230 |
return false; |
// Notify that this channel has changed. |
231 |
} |
if (bResult) |
232 |
|
emit channelChanged(this); |
233 |
|
|
234 |
m_iMidiChannel = iMidiChannel; |
return bResult; |
|
return true; |
|
235 |
} |
} |
236 |
|
|
237 |
|
|
238 |
// Audio device accessor. |
// Channel reset slot. |
239 |
int qsamplerChannelStrip::audioDevice (void) |
bool qsamplerChannelStrip::channelReset (void) |
|
{ |
|
|
return m_iAudioDevice; |
|
|
} |
|
|
|
|
|
bool qsamplerChannelStrip::setAudioDevice ( int iAudioDevice ) |
|
240 |
{ |
{ |
241 |
if (client() == NULL) |
if (m_pChannel == NULL) |
242 |
return false; |
return false; |
243 |
|
|
244 |
if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
// Invoke the channel reset method. |
245 |
appendMessagesClient("lscp_set_channel_audio_device"); |
bool bResult = m_pChannel->channelReset(); |
246 |
return false; |
// Notify that this channel has changed. |
247 |
} |
if (bResult) |
248 |
|
emit channelChanged(this); |
249 |
|
|
250 |
m_iAudioDevice = iAudioDevice; |
return bResult; |
|
return true; |
|
251 |
} |
} |
252 |
|
|
253 |
|
|
254 |
// Audio driver type accessors (DEPRECATED). |
// Update the channel instrument name. |
255 |
QString& qsamplerChannelStrip::audioDriver (void) |
bool qsamplerChannelStrip::updateInstrumentName ( bool bForce ) |
256 |
{ |
{ |
257 |
return m_sAudioDriver; |
if (m_pChannel == NULL) |
258 |
} |
return false; |
259 |
|
|
260 |
bool qsamplerChannelStrip::setAudioDriver ( const QString& sAudioDriver ) |
// Do we refresh the actual name? |
261 |
{ |
if (bForce) |
262 |
if (client() == NULL) |
m_pChannel->updateInstrumentName(); |
|
return false; |
|
263 |
|
|
264 |
if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
// Instrument name... |
265 |
appendMessagesClient("lscp_set_channel_audio_type"); |
if (m_pChannel->instrumentName().isEmpty()) { |
266 |
return false; |
if (m_pChannel->instrumentStatus() >= 0) |
267 |
} |
InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument()); |
268 |
|
else |
269 |
|
InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName()); |
270 |
|
} else |
271 |
|
InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName()); |
272 |
|
|
273 |
m_sAudioDriver = sAudioDriver; |
return true; |
|
return true; |
|
274 |
} |
} |
275 |
|
|
276 |
|
|
277 |
// Channel volume accessors. |
// Do the dirty volume change. |
278 |
float qsamplerChannelStrip::volume (void) |
bool qsamplerChannelStrip::updateChannelVolume (void) |
|
{ |
|
|
return m_fVolume; |
|
|
} |
|
|
|
|
|
bool qsamplerChannelStrip::setVolume ( float fVolume ) |
|
279 |
{ |
{ |
280 |
if (client() == NULL) |
if (m_pChannel == NULL) |
281 |
return false; |
return false; |
282 |
|
|
283 |
if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { |
// Convert... |
284 |
appendMessagesClient("lscp_set_channel_volume"); |
#ifdef CONFIG_ROUND |
285 |
return false; |
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 |
m_fVolume = fVolume; |
// And clip... |
298 |
return true; |
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 |
// Messages view font accessors. |
return true; |
|
QFont qsamplerChannelStrip::displayFont (void) |
|
|
{ |
|
|
return EngineNameTextLabel->font(); |
|
308 |
} |
} |
309 |
|
|
|
void qsamplerChannelStrip::setDisplayFont ( const QFont & font ) |
|
|
{ |
|
|
EngineNameTextLabel->setFont(font); |
|
|
MidiPortChannelTextLabel->setFont(font); |
|
|
InstrumentNameTextLabel->setFont(font); |
|
|
InstrumentStatusTextLabel->setFont(font); |
|
|
} |
|
310 |
|
|
311 |
// Channel setup dialog. |
// Update whole channel info state. |
312 |
void qsamplerChannelStrip::channelSetup (void) |
bool qsamplerChannelStrip::updateChannelInfo (void) |
313 |
{ |
{ |
314 |
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this); |
if (m_pChannel == NULL) |
315 |
if (pChannelForm) { |
return false; |
|
pChannelForm->setup(this); |
|
|
if (pChannelForm->exec()) { |
|
|
updateChannelInfo(); |
|
|
emit channelChanged(this); |
|
|
} |
|
|
delete pChannelForm; |
|
|
} |
|
|
} |
|
316 |
|
|
317 |
|
// Check for error limit/recycle... |
318 |
|
if (m_iErrorCount > QSAMPLER_ERROR_LIMIT) |
319 |
|
return true; |
320 |
|
|
|
// Update whole channel info state. |
|
|
void qsamplerChannelStrip::updateChannelInfo (void) |
|
|
{ |
|
321 |
// Update strip caption. |
// Update strip caption. |
322 |
QString sText = tr("Channel %1").arg(m_iChannelID); |
QString sText = m_pChannel->channelName(); |
323 |
setCaption(sText); |
setCaption(sText); |
324 |
ChannelSetupPushButton->setText(sText); |
ChannelSetupPushButton->setText(sText); |
325 |
|
|
326 |
// Check if we're up and connected. |
// Check if we're up and connected. |
327 |
if (client() == NULL) |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
328 |
return; |
if (pMainForm->client() == NULL) |
329 |
|
return false; |
|
// Read channel information. |
|
|
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID); |
|
|
if (pChannelInfo == NULL) { |
|
|
appendMessagesClient("lscp_get_channel_info"); |
|
|
appendMessagesError(tr("Could not get channel information.\n\nSorry.")); |
|
|
} else { |
|
|
// Cache in channel information. |
|
|
m_sEngineName = pChannelInfo->engine_name; |
|
|
m_sInstrumentFile = pChannelInfo->instrument_file; |
|
|
m_iInstrumentNr = pChannelInfo->instrument_nr; |
|
|
m_iInstrumentStatus = pChannelInfo->instrument_status; |
|
|
m_iMidiDevice = pChannelInfo->midi_device; |
|
|
m_iMidiPort = pChannelInfo->midi_port; |
|
|
m_iMidiChannel = pChannelInfo->midi_channel; |
|
|
m_iAudioDevice = pChannelInfo->audio_device; |
|
|
m_fVolume = pChannelInfo->volume; |
|
|
// Some sanity checks. |
|
|
if (m_sEngineName == "NONE") |
|
|
m_sEngineName = QString::null; |
|
|
if (m_sInstrumentFile == "NONE") |
|
|
m_sInstrumentFile = QString::null; |
|
|
} |
|
330 |
|
|
331 |
// Set some proper display values. |
// Read actual channel information. |
332 |
|
m_pChannel->updateChannelInfo(); |
333 |
|
|
334 |
// Engine name... |
// Engine name... |
335 |
if (m_sEngineName.isEmpty()) |
if (m_pChannel->engineName().isEmpty()) |
336 |
EngineNameTextLabel->setText(tr("(No engine)")); |
EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName()); |
337 |
else |
else |
338 |
EngineNameTextLabel->setText(m_sEngineName); |
EngineNameTextLabel->setText(' ' + m_pChannel->engineName()); |
339 |
|
|
340 |
// Instrument name... |
// Instrument name... |
341 |
if (m_sInstrumentFile.isEmpty()) |
updateInstrumentName(false); |
342 |
InstrumentNameTextLabel->setText(tr("(No instrument)")); |
|
343 |
else |
// MIDI Port/Channel... |
344 |
InstrumentNameTextLabel->setText(QString("%1 [%2]") |
QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / "; |
345 |
.arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr)); |
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
346 |
|
sMidiPortChannel += tr("All"); |
347 |
|
else |
348 |
|
sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1); |
349 |
|
MidiPortChannelTextLabel->setText(sMidiPortChannel); |
350 |
|
|
351 |
// Instrument status... |
// Instrument status... |
352 |
if (m_iInstrumentStatus < 0) { |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
353 |
|
if (iInstrumentStatus < 0) { |
354 |
InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red); |
InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red); |
355 |
InstrumentStatusTextLabel->setText(tr("ERR%1").arg(m_iInstrumentStatus)); |
InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
356 |
} else { |
m_iErrorCount++; |
357 |
InstrumentStatusTextLabel->setPaletteForegroundColor(m_iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
return false; |
|
InstrumentStatusTextLabel->setText(QString::number(m_iInstrumentStatus) + "%"); |
|
358 |
} |
} |
359 |
|
// All seems normal... |
360 |
// MIDI Port/Channel... |
InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
361 |
MidiPortChannelTextLabel->setText(QString("%1 / %2") |
InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%'); |
362 |
.arg(m_iMidiPort).arg(m_iMidiChannel)); |
m_iErrorCount = 0; |
363 |
|
|
364 |
// And update the both GUI volume elements. |
#ifdef CONFIG_MUTE_SOLO |
365 |
updateChannelVolume(); |
// Mute/Solo button state coloring... |
366 |
} |
const QColor& rgbNormal = ChannelSetupPushButton->paletteBackgroundColor(); |
367 |
|
bool bMute = m_pChannel->channelMute(); |
368 |
|
ChannelMutePushButton->setPaletteBackgroundColor(bMute ? Qt::red : rgbNormal); |
369 |
// Do the dirty volume change. |
ChannelMutePushButton->setDown(bMute); |
370 |
void qsamplerChannelStrip::updateChannelVolume (void) |
bool bSolo = m_pChannel->channelSolo(); |
371 |
{ |
ChannelSoloPushButton->setPaletteBackgroundColor(bSolo ? Qt::yellow : rgbNormal); |
372 |
// Convert... |
ChannelSoloPushButton->setDown(bSolo); |
|
#ifdef CONFIG_ROUND |
|
|
int iVolume = (int) ::round(100.0 * m_fVolume); |
|
373 |
#else |
#else |
374 |
double fIPart = 0.0; |
ChannelMutePushButton->setEnabled(false); |
375 |
double fFPart = ::modf(100.0 * m_fVolume, &fIPart); |
ChannelSoloPushButton->setEnabled(false); |
|
int iVolume = (int) fIPart; |
|
|
if (fFPart >= +0.5) |
|
|
iVolume++; |
|
|
else |
|
|
if (fFPart <= -0.5) |
|
|
iVolume--; |
|
376 |
#endif |
#endif |
377 |
|
|
378 |
// And clip... |
// And update the both GUI volume elements; |
379 |
if (iVolume < 0) |
// return success if, and only if, intrument is fully loaded... |
380 |
iVolume = 0; |
return updateChannelVolume() && (iInstrumentStatus == 100); |
|
|
|
|
// Flag it here, to avoid infinite recursion. |
|
|
m_iDirtyChange++; |
|
|
VolumeSlider->setValue(iVolume); |
|
|
VolumeSpinBox->setValue(iVolume); |
|
|
m_iDirtyChange--; |
|
381 |
} |
} |
382 |
|
|
383 |
|
|
384 |
// Update whole channel usage state. |
// Update whole channel usage state. |
385 |
void qsamplerChannelStrip::updateChannelUsage (void) |
bool qsamplerChannelStrip::updateChannelUsage (void) |
386 |
{ |
{ |
387 |
if (client() == NULL) |
if (m_pChannel == NULL) |
388 |
return; |
return false; |
389 |
|
|
390 |
// Conditionally update whole channel status info. |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
391 |
if (m_iInstrumentStatus >= 0 && m_iInstrumentStatus < 100) |
if (pMainForm->client() == NULL) |
392 |
updateChannelInfo(); |
return false; |
393 |
// Leave, if we still have an erroneus or incomplete instrument load. |
|
394 |
if (m_iInstrumentStatus < 100) |
// This only makes sense on fully loaded channels... |
395 |
return; |
if (m_pChannel->instrumentStatus() < 100) |
396 |
|
return false; |
397 |
|
|
398 |
// Get current channel voice count. |
// Get current channel voice count. |
399 |
int iVoiceCount = ::lscp_get_channel_voice_count(client(), m_iChannelID); |
int iVoiceCount = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID()); |
400 |
// Get current stream count. |
// Get current stream count. |
401 |
int iStreamCount = ::lscp_get_channel_stream_count(client(), m_iChannelID); |
int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID()); |
402 |
// Get current channel buffer fill usage. |
// Get current channel buffer fill usage. |
403 |
// As benno has suggested this is the percentage usage |
// As benno has suggested this is the percentage usage |
404 |
// of the least filled buffer stream... |
// of the least filled buffer stream... |
405 |
int iStreamUsage = 0; |
int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());; |
406 |
if (iStreamCount > 0) { |
|
|
lscp_buffer_fill_t *pBufferFill = ::lscp_get_channel_buffer_fill(client(), LSCP_USAGE_PERCENTAGE, m_iChannelID); |
|
|
if (pBufferFill) { |
|
|
for (int iStream = 0; iStream < iStreamCount; iStream++) { |
|
|
if (iStreamUsage > (int) pBufferFill[iStream].stream_usage || iStream == 0) |
|
|
iStreamUsage = pBufferFill[iStream].stream_usage; |
|
|
} |
|
|
} |
|
|
} |
|
407 |
// Update the GUI elements... |
// Update the GUI elements... |
408 |
StreamUsageProgressBar->setProgress(iStreamUsage); |
StreamUsageProgressBar->setProgress(iStreamUsage); |
409 |
StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
410 |
|
|
411 |
|
// We're clean. |
412 |
|
return true; |
413 |
} |
} |
414 |
|
|
415 |
|
|
416 |
// Volume change slot. |
// Volume change slot. |
417 |
void qsamplerChannelStrip::volumeChanged ( int iVolume ) |
void qsamplerChannelStrip::volumeChanged ( int iVolume ) |
418 |
{ |
{ |
419 |
|
if (m_pChannel == NULL) |
420 |
|
return; |
421 |
|
|
422 |
// Avoid recursion. |
// Avoid recursion. |
423 |
if (m_iDirtyChange > 0) |
if (m_iDirtyChange > 0) |
424 |
return; |
return; |
429 |
fVolume = 0.0; |
fVolume = 0.0; |
430 |
|
|
431 |
// Update the GUI elements. |
// Update the GUI elements. |
432 |
if (setVolume(fVolume)) { |
if (m_pChannel->setVolume(fVolume)) { |
433 |
updateChannelVolume(); |
updateChannelVolume(); |
434 |
emit channelChanged(this); |
emit channelChanged(this); |
435 |
} |
} |
436 |
} |
} |
437 |
|
|
438 |
|
|
|
// Redirected messages output methods. |
|
|
void qsamplerChannelStrip::appendMessages( const QString& s ) |
|
|
{ |
|
|
m_pMainForm->appendMessages(s); |
|
|
} |
|
|
|
|
|
void qsamplerChannelStrip::appendMessagesColor( const QString& s, const QString& c ) |
|
|
{ |
|
|
m_pMainForm->appendMessagesColor(s, c); |
|
|
} |
|
|
|
|
|
void qsamplerChannelStrip::appendMessagesText( const QString& s ) |
|
|
{ |
|
|
m_pMainForm->appendMessagesText(s); |
|
|
} |
|
|
|
|
|
void qsamplerChannelStrip::appendMessagesError( const QString& s ) |
|
|
{ |
|
|
m_pMainForm->appendMessagesError(s); |
|
|
} |
|
|
|
|
|
void qsamplerChannelStrip::appendMessagesClient( const QString& s ) |
|
|
{ |
|
|
m_pMainForm->appendMessagesClient(s); |
|
|
} |
|
|
|
|
|
|
|
439 |
// Context menu event handler. |
// Context menu event handler. |
440 |
void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
441 |
{ |
{ |
442 |
// We'll just show up the main form's edit menu. |
if (m_pChannel == NULL) |
443 |
m_pMainForm->contextMenuEvent(pEvent); |
return; |
444 |
|
|
445 |
|
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
446 |
|
m_pChannel->contextMenuEvent(pEvent); |
447 |
} |
} |
448 |
|
|
449 |
|
|
450 |
// Maximum volume slider accessors. |
// Error count hackish accessors. |
451 |
void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume ) |
void qsamplerChannelStrip::resetErrorCount (void) |
452 |
{ |
{ |
453 |
m_iDirtyChange++; |
m_iErrorCount = 0; |
|
VolumeSlider->setRange(0, iMaxVolume); |
|
|
VolumeSpinBox->setRange(0, iMaxVolume); |
|
|
m_iDirtyChange--; |
|
454 |
} |
} |
455 |
|
|
456 |
|
|
457 |
// end of qsamplerChannelStrip.ui.h |
// end of qsamplerChannelStrip.ui.h |
|
|
|