/[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 400 - (hide annotations) (download) (as text)
Mon Feb 21 15:02:58 2005 UTC (19 years, 1 month ago) by capela
File MIME type: text/x-c++hdr
File size: 10599 byte(s)
Major internal switch regarding channel strip change management.

1 capela 109 // qsamplerChannelStrip.ui.h
2     //
3     // ui.h extension file, included from the uic-generated form implementation.
4     /****************************************************************************
5 capela 341 Copyright (C) 2004-2005, 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     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20    
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 109
31     #include <math.h>
32    
33     #include "qsamplerMainForm.h"
34     #include "qsamplerChannelForm.h"
35    
36     #include "config.h"
37    
38 capela 395 // Channel status/usage usage limit control.
39     #define QSAMPLER_ERROR_LIMIT 3
40 capela 109
41 capela 395
42 capela 109 // Kind of constructor.
43     void qsamplerChannelStrip::init (void)
44     {
45     // Initialize locals.
46 capela 264 m_pChannel = NULL;
47 capela 109 m_iDirtyChange = 0;
48 capela 395 m_iErrorCount = 0;
49 capela 109
50     // Try to restore normal window positioning.
51     adjustSize();
52     }
53    
54    
55     // Kind of destructor.
56     void qsamplerChannelStrip::destroy (void)
57     {
58 capela 264 // Destroy existing channel descriptor.
59     if (m_pChannel)
60     delete m_pChannel;
61     m_pChannel = NULL;
62 capela 109 }
63    
64    
65 capela 395 // Drag'n'drop file handler.
66     bool qsamplerChannelStrip::decodeDragFile ( const QMimeSource *pEvent, QString& sInstrumentFile )
67     {
68     if (m_pChannel == NULL)
69     return false;
70    
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 = (*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null);
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 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 395
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    
175     // 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 400 // Notify that thie channel has changed.
199     if (bResult)
200     emit channelChanged(this);
201 capela 263
202 capela 400 return bResult;
203     }
204    
205    
206     // Channel reset slot.
207     bool qsamplerChannelStrip::channelReset (void)
208     {
209     if (m_pChannel == NULL)
210     return false;
211    
212     // Invoke the channel reset method.
213     bool bResult = m_pChannel->channelReset();
214     // Notify that thie channel has changed.
215     if (bResult)
216 capela 395 emit channelChanged(this);
217 capela 295
218 capela 395 return bResult;
219 capela 109 }
220    
221    
222 capela 371 // Update the channel instrument name.
223     bool qsamplerChannelStrip::updateInstrumentName ( bool bForce )
224     {
225     if (m_pChannel == NULL)
226     return false;
227    
228     // Do we refersh the actual name?
229     if (bForce)
230     m_pChannel->updateInstrumentName();
231    
232     // Instrument name...
233     if (m_pChannel->instrumentName().isEmpty())
234 capela 388 InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());
235 capela 371 else
236     InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());
237    
238     return true;
239     }
240    
241    
242 capela 400 // Do the dirty volume change.
243     bool qsamplerChannelStrip::updateChannelVolume (void)
244     {
245     if (m_pChannel == NULL)
246     return false;
247    
248     // Convert...
249     #ifdef CONFIG_ROUND
250     int iVolume = (int) ::round(100.0 * m_pChannel->volume());
251     #else
252     double fIPart = 0.0;
253     double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
254     int iVolume = (int) fIPart;
255     if (fFPart >= +0.5)
256     iVolume++;
257     else
258     if (fFPart <= -0.5)
259     iVolume--;
260     #endif
261    
262     // And clip...
263     if (iVolume < 0)
264     iVolume = 0;
265    
266     // Flag it here, to avoid infinite recursion.
267     m_iDirtyChange++;
268     VolumeSlider->setValue(iVolume);
269     VolumeSpinBox->setValue(iVolume);
270     m_iDirtyChange--;
271    
272     return true;
273     }
274    
275    
276 capela 109 // Update whole channel info state.
277 capela 297 bool qsamplerChannelStrip::updateChannelInfo (void)
278 capela 109 {
279 capela 264 if (m_pChannel == NULL)
280 capela 297 return false;
281 capela 264
282 capela 400 // Check for error limit/recycle...
283     if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
284     return true;
285    
286 capela 109 // Update strip caption.
287 capela 295 QString sText = m_pChannel->channelName();
288 capela 109 setCaption(sText);
289     ChannelSetupPushButton->setText(sText);
290    
291     // Check if we're up and connected.
292 capela 264 if (m_pChannel->client() == NULL)
293 capela 297 return false;
294 capela 109
295 capela 264 // Read actual channel information.
296     m_pChannel->updateChannelInfo();
297 capela 109
298     // Engine name...
299 capela 264 if (m_pChannel->engineName().isEmpty())
300 capela 388 EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());
301 capela 109 else
302 capela 371 EngineNameTextLabel->setText(' ' + m_pChannel->engineName());
303 capela 109
304 capela 371 // Instrument name...
305     updateInstrumentName(false);
306 capela 109
307     // MIDI Port/Channel...
308 capela 280 if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
309     MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
310 capela 261 else
311 capela 280 MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1));
312 capela 261
313 capela 400 // Instrument status...
314     int iInstrumentStatus = m_pChannel->instrumentStatus();
315     if (iInstrumentStatus < 0) {
316     InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
317     InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
318     m_iErrorCount++;
319 capela 297 return false;
320 capela 400 }
321     // All seems normal...
322     InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
323     InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');
324     m_iErrorCount = 0;
325 capela 264
326 capela 400 // And update the both GUI volume elements;
327     // return success if, and only if, intrument is fully loaded...
328     return updateChannelVolume() && (iInstrumentStatus == 100);
329 capela 109 }
330    
331    
332     // Update whole channel usage state.
333 capela 297 bool qsamplerChannelStrip::updateChannelUsage (void)
334 capela 109 {
335 capela 264 if (m_pChannel == NULL)
336 capela 297 return false;
337 capela 264 if (m_pChannel->client() == NULL)
338 capela 297 return false;
339 capela 109
340 capela 400 // This only makes sense on fully loaded channels...
341     if (m_pChannel->instrumentStatus() < 100)
342     return false;
343    
344 capela 109 // Get current channel voice count.
345 capela 264 int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
346 capela 109 // Get current stream count.
347 capela 264 int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
348 capela 109 // Get current channel buffer fill usage.
349     // As benno has suggested this is the percentage usage
350     // of the least filled buffer stream...
351 capela 264 int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
352 capela 176
353 capela 109 // Update the GUI elements...
354     StreamUsageProgressBar->setProgress(iStreamUsage);
355     StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
356 capela 297
357     // We're clean.
358     return true;
359 capela 109 }
360    
361    
362     // Volume change slot.
363     void qsamplerChannelStrip::volumeChanged ( int iVolume )
364     {
365 capela 264 if (m_pChannel == NULL)
366     return;
367    
368 capela 109 // Avoid recursion.
369     if (m_iDirtyChange > 0)
370     return;
371    
372     // Convert and clip.
373     float fVolume = (float) iVolume / 100.0;
374 capela 119 if (fVolume < 0.001)
375 capela 109 fVolume = 0.0;
376    
377     // Update the GUI elements.
378 capela 264 if (m_pChannel->setVolume(fVolume)) {
379 capela 109 updateChannelVolume();
380     emit channelChanged(this);
381     }
382     }
383    
384    
385 capela 118 // Context menu event handler.
386     void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
387     {
388 capela 303 if (m_pChannel == NULL)
389 capela 264 return;
390    
391 capela 303 // We'll just show up the main form's edit menu (thru qsamplerChannel).
392     m_pChannel->contextMenuEvent(pEvent);
393 capela 118 }
394    
395    
396 capela 109 // end of qsamplerChannelStrip.ui.h

  ViewVC Help
Powered by ViewVC