/[svn]/qsampler/trunk/src/qsamplerChannelStrip.ui.h
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerChannelStrip.ui.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1372 - (hide annotations) (download) (as text)
Wed Oct 3 11:34:30 2007 UTC (16 years, 6 months ago) by capela
File MIME type: text/x-c++hdr
File size: 12319 byte(s)
* The new channel instrument editor tool is now also accessible
  from the main menu and toolbar.

1 capela 109 // qsamplerChannelStrip.ui.h
2     //
3     // ui.h extension file, included from the uic-generated form implementation.
4     /****************************************************************************
5 capela 1016 Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
6 capela 109
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 capela 920 You should have received a copy of the GNU General Public License along
18     with this program; if not, write to the Free Software Foundation, Inc.,
19     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 capela 109
21     *****************************************************************************/
22    
23     #include <qvalidator.h>
24     #include <qmessagebox.h>
25 capela 395 #include <qdragobject.h>
26 capela 109 #include <qfileinfo.h>
27     #include <qtooltip.h>
28 capela 118 #include <qpopupmenu.h>
29 capela 267 #include <qobjectlist.h>
30 capela 409 #include <qurl.h>
31 capela 109
32     #include <math.h>
33    
34     #include "qsamplerMainForm.h"
35     #include "qsamplerChannelForm.h"
36    
37     #include "config.h"
38    
39 capela 395 // Channel status/usage usage limit control.
40     #define QSAMPLER_ERROR_LIMIT 3
41 capela 109
42 capela 395
43 capela 109 // Kind of constructor.
44     void qsamplerChannelStrip::init (void)
45     {
46     // Initialize locals.
47 capela 264 m_pChannel = NULL;
48 capela 109 m_iDirtyChange = 0;
49 capela 395 m_iErrorCount = 0;
50 capela 109
51     // Try to restore normal window positioning.
52     adjustSize();
53     }
54    
55    
56     // Kind of destructor.
57     void qsamplerChannelStrip::destroy (void)
58     {
59 capela 264 // Destroy existing channel descriptor.
60     if (m_pChannel)
61     delete m_pChannel;
62     m_pChannel = NULL;
63 capela 109 }
64    
65    
66 capela 395 // 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 capela 409 *iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path();
77 capela 395 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 capela 109 // Channel strip setup formal initializer.
111 capela 303 void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel )
112 capela 109 {
113 capela 303 // Destroy any previous channel descriptor;
114     // (remember that once setup we own it!)
115 capela 264 if (m_pChannel)
116     delete m_pChannel;
117 capela 109
118 capela 303 // Set the new one...
119     m_pChannel = pChannel;
120 capela 586
121 capela 265 // Stabilize this around.
122     updateChannelInfo();
123 capela 395
124     // We'll accept drops from now on...
125     if (m_pChannel)
126     setAcceptDrops(true);
127 capela 109 }
128    
129 capela 264 // Channel secriptor accessor.
130     qsamplerChannel *qsamplerChannelStrip::channel (void)
131 capela 109 {
132 capela 264 return m_pChannel;
133 capela 109 }
134    
135    
136     // Messages view font accessors.
137     QFont qsamplerChannelStrip::displayFont (void)
138     {
139     return EngineNameTextLabel->font();
140     }
141    
142     void qsamplerChannelStrip::setDisplayFont ( const QFont & font )
143     {
144     EngineNameTextLabel->setFont(font);
145 capela 145 MidiPortChannelTextLabel->setFont(font);
146 capela 109 InstrumentNameTextLabel->setFont(font);
147 capela 145 InstrumentStatusTextLabel->setFont(font);
148 capela 109 }
149    
150 capela 263
151 capela 267 // Channel display background effect.
152     void qsamplerChannelStrip::setDisplayEffect ( bool bDisplayEffect )
153     {
154     QPixmap pm;
155     if (bDisplayEffect)
156     pm = QPixmap::fromMimeSource("displaybg1.png");
157     setDisplayBackground(pm);
158     }
159    
160    
161     // Update main display background pixmap.
162     void qsamplerChannelStrip::setDisplayBackground ( const QPixmap& pm )
163     {
164     // Set the main origin...
165     ChannelInfoFrame->setPaletteBackgroundPixmap(pm);
166    
167     // Iterate for every child text label...
168     QObjectList *pList = ChannelInfoFrame->queryList("QLabel");
169     if (pList) {
170     for (QLabel *pLabel = (QLabel *) pList->first(); pLabel; pLabel = (QLabel *) pList->next())
171     pLabel->setPaletteBackgroundPixmap(pm);
172     delete pList;
173     }
174 capela 586
175 capela 267 // And this standalone too.
176     StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm);
177     }
178    
179    
180 capela 395 // Maximum volume slider accessors.
181     void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume )
182     {
183     m_iDirtyChange++;
184     VolumeSlider->setRange(0, iMaxVolume);
185     VolumeSpinBox->setRange(0, iMaxVolume);
186     m_iDirtyChange--;
187     }
188    
189    
190 capela 263 // Channel setup dialog slot.
191 capela 295 bool qsamplerChannelStrip::channelSetup (void)
192 capela 263 {
193 capela 400 if (m_pChannel == NULL)
194     return false;
195    
196 capela 395 // Invoke the channel setup dialog.
197     bool bResult = m_pChannel->channelSetup(this);
198 capela 590 // Notify that this channel has changed.
199 capela 400 if (bResult)
200     emit channelChanged(this);
201 capela 263
202 capela 400 return bResult;
203     }
204    
205    
206 capela 751 // Channel mute slot.
207     bool qsamplerChannelStrip::channelMute ( bool bMute )
208     {
209     if (m_pChannel == NULL)
210     return false;
211    
212     // Invoke the channel mute method.
213     bool bResult = m_pChannel->setChannelMute(bMute);
214     // Notify that this channel has changed.
215     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 schoenebeck 1366 // Channel edit slot.
239 capela 1372 void qsamplerChannelStrip::channelEdit (void)
240 schoenebeck 1366 {
241     if (m_pChannel == NULL)
242     return;
243    
244     m_pChannel->editChannel();
245     }
246    
247    
248 capela 400 // Channel reset slot.
249     bool qsamplerChannelStrip::channelReset (void)
250     {
251     if (m_pChannel == NULL)
252     return false;
253    
254     // Invoke the channel reset method.
255     bool bResult = m_pChannel->channelReset();
256 capela 590 // Notify that this channel has changed.
257 capela 400 if (bResult)
258 capela 395 emit channelChanged(this);
259 capela 295
260 capela 395 return bResult;
261 capela 109 }
262    
263    
264 capela 371 // Update the channel instrument name.
265     bool qsamplerChannelStrip::updateInstrumentName ( bool bForce )
266     {
267     if (m_pChannel == NULL)
268     return false;
269    
270 capela 590 // Do we refresh the actual name?
271 capela 371 if (bForce)
272     m_pChannel->updateInstrumentName();
273    
274     // Instrument name...
275 schoenebeck 519 if (m_pChannel->instrumentName().isEmpty()) {
276     if (m_pChannel->instrumentStatus() >= 0)
277     InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument());
278     else
279     InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());
280     } else
281 capela 371 InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());
282    
283     return true;
284     }
285    
286    
287 capela 400 // Do the dirty volume change.
288     bool qsamplerChannelStrip::updateChannelVolume (void)
289     {
290     if (m_pChannel == NULL)
291     return false;
292    
293     // Convert...
294     #ifdef CONFIG_ROUND
295     int iVolume = (int) ::round(100.0 * m_pChannel->volume());
296     #else
297     double fIPart = 0.0;
298     double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
299     int iVolume = (int) fIPart;
300     if (fFPart >= +0.5)
301     iVolume++;
302     else
303     if (fFPart <= -0.5)
304     iVolume--;
305     #endif
306    
307     // And clip...
308     if (iVolume < 0)
309     iVolume = 0;
310    
311     // Flag it here, to avoid infinite recursion.
312     m_iDirtyChange++;
313     VolumeSlider->setValue(iVolume);
314     VolumeSpinBox->setValue(iVolume);
315     m_iDirtyChange--;
316    
317     return true;
318     }
319    
320    
321 capela 109 // Update whole channel info state.
322 capela 297 bool qsamplerChannelStrip::updateChannelInfo (void)
323 capela 109 {
324 capela 264 if (m_pChannel == NULL)
325 capela 297 return false;
326 capela 586
327 capela 400 // Check for error limit/recycle...
328     if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
329     return true;
330    
331 capela 109 // Update strip caption.
332 capela 295 QString sText = m_pChannel->channelName();
333 capela 109 setCaption(sText);
334     ChannelSetupPushButton->setText(sText);
335    
336     // Check if we're up and connected.
337 capela 961 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
338     if (pMainForm->client() == NULL)
339     return false;
340 capela 109
341 capela 264 // Read actual channel information.
342     m_pChannel->updateChannelInfo();
343 capela 109
344     // Engine name...
345 capela 264 if (m_pChannel->engineName().isEmpty())
346 capela 388 EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());
347 capela 109 else
348 capela 371 EngineNameTextLabel->setText(' ' + m_pChannel->engineName());
349 capela 109
350 capela 371 // Instrument name...
351     updateInstrumentName(false);
352 capela 109
353     // MIDI Port/Channel...
354 capela 1018 QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";
355 capela 1016 if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
356 capela 1018 sMidiPortChannel += tr("All");
357 capela 1016 else
358 capela 1018 sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1);
359     MidiPortChannelTextLabel->setText(sMidiPortChannel);
360 capela 261
361 capela 400 // Instrument status...
362     int iInstrumentStatus = m_pChannel->instrumentStatus();
363     if (iInstrumentStatus < 0) {
364     InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
365     InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
366     m_iErrorCount++;
367 capela 297 return false;
368 capela 400 }
369     // All seems normal...
370     InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
371     InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');
372     m_iErrorCount = 0;
373 capela 264
374 capela 751 #ifdef CONFIG_MUTE_SOLO
375     // Mute/Solo button state coloring...
376     const QColor& rgbNormal = ChannelSetupPushButton->paletteBackgroundColor();
377     bool bMute = m_pChannel->channelMute();
378 capela 1036 ChannelMutePushButton->setPaletteBackgroundColor(bMute ? Qt::yellow : rgbNormal);
379 capela 751 ChannelMutePushButton->setDown(bMute);
380     bool bSolo = m_pChannel->channelSolo();
381 capela 1036 ChannelSoloPushButton->setPaletteBackgroundColor(bSolo ? Qt::cyan : rgbNormal);
382 capela 751 ChannelSoloPushButton->setDown(bSolo);
383     #else
384     ChannelMutePushButton->setEnabled(false);
385     ChannelSoloPushButton->setEnabled(false);
386     #endif
387    
388 capela 400 // And update the both GUI volume elements;
389     // return success if, and only if, intrument is fully loaded...
390     return updateChannelVolume() && (iInstrumentStatus == 100);
391 capela 109 }
392    
393    
394     // Update whole channel usage state.
395 capela 297 bool qsamplerChannelStrip::updateChannelUsage (void)
396 capela 109 {
397 capela 264 if (m_pChannel == NULL)
398 capela 297 return false;
399 capela 109
400 capela 961 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
401     if (pMainForm->client() == NULL)
402     return false;
403    
404 capela 400 // This only makes sense on fully loaded channels...
405     if (m_pChannel->instrumentStatus() < 100)
406     return false;
407 capela 586
408 capela 109 // Get current channel voice count.
409 capela 961 int iVoiceCount = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID());
410 capela 109 // Get current stream count.
411 capela 961 int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID());
412 capela 109 // Get current channel buffer fill usage.
413     // As benno has suggested this is the percentage usage
414     // of the least filled buffer stream...
415 capela 961 int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());;
416 capela 176
417 capela 109 // Update the GUI elements...
418     StreamUsageProgressBar->setProgress(iStreamUsage);
419     StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
420 capela 586
421 capela 297 // We're clean.
422     return true;
423 capela 109 }
424    
425    
426     // Volume change slot.
427     void qsamplerChannelStrip::volumeChanged ( int iVolume )
428     {
429 capela 264 if (m_pChannel == NULL)
430     return;
431    
432 capela 109 // Avoid recursion.
433     if (m_iDirtyChange > 0)
434     return;
435    
436     // Convert and clip.
437     float fVolume = (float) iVolume / 100.0;
438 capela 119 if (fVolume < 0.001)
439 capela 109 fVolume = 0.0;
440    
441     // Update the GUI elements.
442 capela 264 if (m_pChannel->setVolume(fVolume)) {
443 capela 109 updateChannelVolume();
444     emit channelChanged(this);
445     }
446     }
447    
448    
449 capela 118 // Context menu event handler.
450     void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
451     {
452 capela 303 if (m_pChannel == NULL)
453 capela 264 return;
454 capela 586
455 capela 303 // We'll just show up the main form's edit menu (thru qsamplerChannel).
456     m_pChannel->contextMenuEvent(pEvent);
457 capela 118 }
458    
459    
460 capela 586 // Error count hackish accessors.
461     void qsamplerChannelStrip::resetErrorCount (void)
462     {
463     m_iErrorCount = 0;
464     }
465    
466    
467 capela 109 // end of qsamplerChannelStrip.ui.h

  ViewVC Help
Powered by ViewVC