/[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 395 - (hide annotations) (download) (as text)
Sun Feb 20 19:13:33 2005 UTC (19 years, 2 months ago) by capela
File MIME type: text/x-c++hdr
File size: 10704 byte(s)
* Drag-and-drop to an existing channel strip is now also
  featured, allowing the in-place change of the channel
  sampler instrument file.

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     #define QSAMPLER_ERROR_CYCLE 33
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    
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 capela 109 // Channel strip setup formal initializer.
112 capela 303 void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel )
113 capela 109 {
114 capela 303 // Destroy any previous channel descriptor;
115     // (remember that once setup we own it!)
116 capela 264 if (m_pChannel)
117     delete m_pChannel;
118 capela 109
119 capela 303 // Set the new one...
120     m_pChannel = pChannel;
121 capela 395
122 capela 265 // Stabilize this around.
123     updateChannelInfo();
124 capela 395
125     // We'll accept drops from now on...
126     if (m_pChannel)
127     setAcceptDrops(true);
128 capela 109 }
129    
130 capela 264 // Channel secriptor accessor.
131     qsamplerChannel *qsamplerChannelStrip::channel (void)
132 capela 109 {
133 capela 264 return m_pChannel;
134 capela 109 }
135    
136    
137     // Messages view font accessors.
138     QFont qsamplerChannelStrip::displayFont (void)
139     {
140     return EngineNameTextLabel->font();
141     }
142    
143     void qsamplerChannelStrip::setDisplayFont ( const QFont & font )
144     {
145     EngineNameTextLabel->setFont(font);
146 capela 145 MidiPortChannelTextLabel->setFont(font);
147 capela 109 InstrumentNameTextLabel->setFont(font);
148 capela 145 InstrumentStatusTextLabel->setFont(font);
149 capela 109 }
150    
151 capela 263
152 capela 267 // Channel display background effect.
153     void qsamplerChannelStrip::setDisplayEffect ( bool bDisplayEffect )
154     {
155     QPixmap pm;
156     if (bDisplayEffect)
157     pm = QPixmap::fromMimeSource("displaybg1.png");
158     setDisplayBackground(pm);
159     }
160    
161    
162     // Update main display background pixmap.
163     void qsamplerChannelStrip::setDisplayBackground ( const QPixmap& pm )
164     {
165     // Set the main origin...
166     ChannelInfoFrame->setPaletteBackgroundPixmap(pm);
167    
168     // Iterate for every child text label...
169     QObjectList *pList = ChannelInfoFrame->queryList("QLabel");
170     if (pList) {
171     for (QLabel *pLabel = (QLabel *) pList->first(); pLabel; pLabel = (QLabel *) pList->next())
172     pLabel->setPaletteBackgroundPixmap(pm);
173     delete pList;
174     }
175    
176     // And this standalone too.
177     StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm);
178     }
179    
180    
181 capela 395 // 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 capela 263 // Channel setup dialog slot.
192 capela 295 bool qsamplerChannelStrip::channelSetup (void)
193 capela 263 {
194 capela 395 // Invoke the channel setup dialog.
195     bool bResult = m_pChannel->channelSetup(this);
196 capela 263
197 capela 395 if (bResult) {
198     // Reset the error/cycle.
199     m_iErrorCount = 0;
200     // Notify that thie channel has changed.
201     emit channelChanged(this);
202     }
203 capela 295
204 capela 395 return bResult;
205 capela 109 }
206    
207    
208 capela 371 // Update the channel instrument name.
209     bool qsamplerChannelStrip::updateInstrumentName ( bool bForce )
210     {
211     if (m_pChannel == NULL)
212     return false;
213    
214     // Do we refersh the actual name?
215     if (bForce)
216     m_pChannel->updateInstrumentName();
217    
218     // Instrument name...
219     if (m_pChannel->instrumentName().isEmpty())
220 capela 388 InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());
221 capela 371 else
222     InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());
223    
224     return true;
225     }
226    
227    
228 capela 109 // Update whole channel info state.
229 capela 297 bool qsamplerChannelStrip::updateChannelInfo (void)
230 capela 109 {
231 capela 264 if (m_pChannel == NULL)
232 capela 297 return false;
233 capela 264
234 capela 109 // Update strip caption.
235 capela 295 QString sText = m_pChannel->channelName();
236 capela 109 setCaption(sText);
237     ChannelSetupPushButton->setText(sText);
238    
239     // Check if we're up and connected.
240 capela 264 if (m_pChannel->client() == NULL)
241 capela 297 return false;
242 capela 109
243 capela 264 // Read actual channel information.
244     m_pChannel->updateChannelInfo();
245 capela 109
246     // Engine name...
247 capela 264 if (m_pChannel->engineName().isEmpty())
248 capela 388 EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());
249 capela 109 else
250 capela 371 EngineNameTextLabel->setText(' ' + m_pChannel->engineName());
251 capela 109
252 capela 371 // Instrument name...
253     updateInstrumentName(false);
254 capela 109
255 capela 145 // Instrument status...
256 capela 264 int iInstrumentStatus = m_pChannel->instrumentStatus();
257     if (iInstrumentStatus < 0) {
258 capela 145 InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
259 capela 264 InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
260 capela 145 } else {
261 capela 264 InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
262     InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
263 capela 145 }
264    
265 capela 109 // MIDI Port/Channel...
266 capela 280 if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
267     MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
268 capela 261 else
269 capela 280 MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1));
270 capela 261
271 capela 109 // And update the both GUI volume elements.
272 capela 297 return updateChannelVolume();
273 capela 109 }
274    
275    
276     // Do the dirty volume change.
277 capela 297 bool qsamplerChannelStrip::updateChannelVolume (void)
278 capela 109 {
279 capela 264 if (m_pChannel == NULL)
280 capela 297 return false;
281 capela 264
282 capela 109 // Convert...
283     #ifdef CONFIG_ROUND
284 capela 264 int iVolume = (int) ::round(100.0 * m_pChannel->volume());
285 capela 109 #else
286     double fIPart = 0.0;
287 capela 264 double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
288 capela 109 int iVolume = (int) fIPart;
289     if (fFPart >= +0.5)
290     iVolume++;
291     else
292     if (fFPart <= -0.5)
293     iVolume--;
294     #endif
295    
296     // And clip...
297 capela 119 if (iVolume < 0)
298 capela 109 iVolume = 0;
299    
300     // Flag it here, to avoid infinite recursion.
301     m_iDirtyChange++;
302     VolumeSlider->setValue(iVolume);
303     VolumeSpinBox->setValue(iVolume);
304     m_iDirtyChange--;
305 capela 297
306     return true;
307 capela 109 }
308    
309    
310     // Update whole channel usage state.
311 capela 297 bool qsamplerChannelStrip::updateChannelUsage (void)
312 capela 109 {
313 capela 264 if (m_pChannel == NULL)
314 capela 297 return false;
315 capela 264 if (m_pChannel->client() == NULL)
316 capela 297 return false;
317 capela 109
318 capela 395 // Check for error limit/recycle...
319     if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
320     m_iErrorCount -= QSAMPLER_ERROR_CYCLE;
321     if (m_iErrorCount < 0) {
322     m_iErrorCount++;
323     return false;
324     }
325    
326     // Update whole channel status info,
327     // 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 capela 302
345 capela 109 // Get current channel voice count.
346 capela 264 int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
347 capela 109 // Get current stream count.
348 capela 264 int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
349 capela 109 // Get current channel buffer fill usage.
350     // As benno has suggested this is the percentage usage
351     // of the least filled buffer stream...
352 capela 264 int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
353 capela 176
354 capela 109 // Update the GUI elements...
355     StreamUsageProgressBar->setProgress(iStreamUsage);
356     StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
357 capela 297
358     // We're clean.
359     return true;
360 capela 109 }
361    
362    
363     // Volume change slot.
364     void qsamplerChannelStrip::volumeChanged ( int iVolume )
365     {
366 capela 264 if (m_pChannel == NULL)
367     return;
368    
369 capela 109 // Avoid recursion.
370     if (m_iDirtyChange > 0)
371     return;
372    
373     // Convert and clip.
374     float fVolume = (float) iVolume / 100.0;
375 capela 119 if (fVolume < 0.001)
376 capela 109 fVolume = 0.0;
377    
378     // Update the GUI elements.
379 capela 264 if (m_pChannel->setVolume(fVolume)) {
380 capela 109 updateChannelVolume();
381     emit channelChanged(this);
382     }
383     }
384    
385    
386 capela 118 // Context menu event handler.
387     void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
388     {
389 capela 303 if (m_pChannel == NULL)
390 capela 264 return;
391    
392 capela 303 // We'll just show up the main form's edit menu (thru qsamplerChannel).
393     m_pChannel->contextMenuEvent(pEvent);
394 capela 118 }
395    
396    
397 capela 109 // end of qsamplerChannelStrip.ui.h

  ViewVC Help
Powered by ViewVC