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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 388 by capela, Thu Feb 17 17:27:59 2005 UTC revision 590 by capela, Sun May 29 16:28:01 2005 UTC
# Line 22  Line 22 
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>  #include <qobjectlist.h>
30    #include <qurl.h>
31    
32  #include <math.h>  #include <math.h>
33    
# Line 34  Line 36 
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)
# Line 41  void qsamplerChannelStrip::init (void) Line 46  void qsamplerChannelStrip::init (void)
46      // Initialize locals.      // Initialize locals.
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();
# Line 57  void qsamplerChannelStrip::destroy (void Line 63  void qsamplerChannelStrip::destroy (void
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            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 = 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    // 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  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
111  void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel )  void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel )
112  {  {
# Line 70  void qsamplerChannelStrip::setup ( qsamp Line 120  void qsamplerChannelStrip::setup ( qsamp
120    
121      // Stabilize this around.      // Stabilize this around.
122      updateChannelInfo();      updateChannelInfo();
123    
124            // We'll accept drops from now on...
125            if (m_pChannel)
126                    setAcceptDrops(true);
127  }  }
128    
129  // Channel secriptor accessor.  // Channel secriptor accessor.
# Line 117  void qsamplerChannelStrip::setDisplayBac Line 171  void qsamplerChannelStrip::setDisplayBac
171              pLabel->setPaletteBackgroundPixmap(pm);              pLabel->setPaletteBackgroundPixmap(pm);
172          delete pList;          delete pList;
173      }      }
174        
175      // And this standalone too.      // And this standalone too.
176      StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm);      StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm);
177  }  }
178    
179    
180    // 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  // Channel setup dialog slot.  // Channel setup dialog slot.
191  bool qsamplerChannelStrip::channelSetup (void)  bool qsamplerChannelStrip::channelSetup (void)
192  {  {
193      bool bResult = m_pChannel->channelSetup(this);          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            return bResult;
203    }
204    
     if (bResult)  
         emit channelChanged(this);  
205    
206      return bResult;  // 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 this channel has changed.
215            if (bResult)
216                    emit channelChanged(this);
217    
218            return bResult;
219  }  }
220    
221    
# Line 141  bool qsamplerChannelStrip::updateInstrum Line 225  bool qsamplerChannelStrip::updateInstrum
225          if (m_pChannel == NULL)          if (m_pChannel == NULL)
226                  return false;                  return false;
227    
228          // Do we refersh the actual name?          // Do we refresh the actual name?
229          if (bForce)          if (bForce)
230                  m_pChannel->updateInstrumentName();                  m_pChannel->updateInstrumentName();
231    
232          // Instrument name...          // Instrument name...
233          if (m_pChannel->instrumentName().isEmpty())          if (m_pChannel->instrumentName().isEmpty()) {
234                  InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());                  if (m_pChannel->instrumentStatus() >= 0)
235          else                          InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument());
236                    else
237                            InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());
238            } else
239                  InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());                  InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());
240    
241          return true;              return true;    
242  }  }
243    
244    
245    // Do the dirty volume change.
246    bool qsamplerChannelStrip::updateChannelVolume (void)
247    {
248        if (m_pChannel == NULL)
249            return false;
250    
251        // Convert...
252    #ifdef CONFIG_ROUND
253        int iVolume = (int) ::round(100.0 * m_pChannel->volume());
254    #else
255        double fIPart = 0.0;
256        double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
257        int iVolume = (int) fIPart;
258        if (fFPart >= +0.5)
259            iVolume++;
260        else
261        if (fFPart <= -0.5)
262            iVolume--;
263    #endif
264    
265        // And clip...
266        if (iVolume < 0)
267            iVolume = 0;
268    
269        // Flag it here, to avoid infinite recursion.
270        m_iDirtyChange++;
271        VolumeSlider->setValue(iVolume);
272        VolumeSpinBox->setValue(iVolume);
273        m_iDirtyChange--;
274    
275        return true;
276    }
277    
278    
279  // Update whole channel info state.  // Update whole channel info state.
280  bool qsamplerChannelStrip::updateChannelInfo (void)  bool qsamplerChannelStrip::updateChannelInfo (void)
281  {  {
282      if (m_pChannel == NULL)      if (m_pChannel == NULL)
283          return false;          return false;
284            
285            // Check for error limit/recycle...
286            if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
287                    return true;
288    
289      // Update strip caption.      // Update strip caption.
290      QString sText = m_pChannel->channelName();      QString sText = m_pChannel->channelName();
291      setCaption(sText);      setCaption(sText);
# Line 182  bool qsamplerChannelStrip::updateChannel Line 307  bool qsamplerChannelStrip::updateChannel
307          // Instrument name...          // Instrument name...
308          updateInstrumentName(false);          updateInstrumentName(false);
309    
     // Instrument status...  
     int iInstrumentStatus = m_pChannel->instrumentStatus();  
     if (iInstrumentStatus < 0) {  
         InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);  
         InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));  
     } else {  
         InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);  
         InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");  
     }  
   
310      // MIDI Port/Channel...      // MIDI Port/Channel...
311      if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)      if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
312          MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));          MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
313      else      else
314          MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1));          MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1));
315    
316      // And update the both GUI volume elements.      // Instrument status...
317      return updateChannelVolume();      int iInstrumentStatus = m_pChannel->instrumentStatus();
318  }      if (iInstrumentStatus < 0) {
319            InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
320            InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
321  // Do the dirty volume change.          m_iErrorCount++;
 bool qsamplerChannelStrip::updateChannelVolume (void)  
 {  
     if (m_pChannel == NULL)  
322          return false;          return false;
323        }
324      // Convert...      // All seems normal...
325  #ifdef CONFIG_ROUND      InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
326      int iVolume = (int) ::round(100.0 * m_pChannel->volume());      InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');
327  #else      m_iErrorCount = 0;
328      double fIPart = 0.0;  
329      double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);      // And update the both GUI volume elements;
330      int iVolume = (int) fIPart;      // return success if, and only if, intrument is fully loaded...
331      if (fFPart >= +0.5)      return updateChannelVolume() && (iInstrumentStatus == 100);
         iVolume++;  
     else  
     if (fFPart <= -0.5)  
         iVolume--;  
 #endif  
   
     // And clip...  
     if (iVolume < 0)  
         iVolume = 0;  
   
     // Flag it here, to avoid infinite recursion.  
     m_iDirtyChange++;  
     VolumeSlider->setValue(iVolume);  
     VolumeSpinBox->setValue(iVolume);  
     m_iDirtyChange--;  
       
     return true;  
332  }  }
333    
334    
# Line 245  bool qsamplerChannelStrip::updateChannel Line 340  bool qsamplerChannelStrip::updateChannel
340      if (m_pChannel->client() == NULL)      if (m_pChannel->client() == NULL)
341          return false;          return false;
342    
343      // Update whole channel status info,          // This only makes sense on fully loaded channels...
344      // if instrument load is still pending...          if (m_pChannel->instrumentStatus() < 100)
345      if (m_pChannel->instrumentStatus() < 100) {              return false;
         updateChannelInfo();  
         // Check (updated) status again...  
         if (m_pChannel->instrumentStatus() < 100)  
             return false;  
         // Once we get a complete instrument load,  
         // we'll try an implied channel reset...  
         m_pChannel->resetChannel();  
     }  
       
     // Check again that we're clean.  
     if (m_pChannel->instrumentStatus() < 100)  
         return false;  
346    
347      // Get current channel voice count.      // Get current channel voice count.
348      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());
# Line 273  bool qsamplerChannelStrip::updateChannel Line 356  bool qsamplerChannelStrip::updateChannel
356      // Update the GUI elements...      // Update the GUI elements...
357      StreamUsageProgressBar->setProgress(iStreamUsage);      StreamUsageProgressBar->setProgress(iStreamUsage);
358      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
359        
360      // We're clean.      // We're clean.
361      return true;      return true;
362  }  }
# Line 307  void qsamplerChannelStrip::contextMenuEv Line 390  void qsamplerChannelStrip::contextMenuEv
390  {  {
391      if (m_pChannel == NULL)      if (m_pChannel == NULL)
392          return;          return;
393            
394      // We'll just show up the main form's edit menu (thru qsamplerChannel).      // We'll just show up the main form's edit menu (thru qsamplerChannel).
395      m_pChannel->contextMenuEvent(pEvent);      m_pChannel->contextMenuEvent(pEvent);
396  }  }
397    
398    
399  // Maximum volume slider accessors.  // Error count hackish accessors.
400  void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume )  void qsamplerChannelStrip::resetErrorCount (void)
401  {  {
402      m_iDirtyChange++;          m_iErrorCount = 0;
     VolumeSlider->setRange(0, iMaxVolume);  
     VolumeSpinBox->setRange(0, iMaxVolume);  
     m_iDirtyChange--;  
403  }  }
404    
405    

Legend:
Removed from v.388  
changed lines
  Added in v.590

  ViewVC Help
Powered by ViewVC