/[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 118 by capela, Tue Jun 8 18:40:06 2004 UTC revision 388 by capela, Thu Feb 17 17:27:59 2005 UTC
# Line 2  Line 2 
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-2005, 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
# Line 25  Line 25 
25  #include <qfileinfo.h>  #include <qfileinfo.h>
26  #include <qtooltip.h>  #include <qtooltip.h>
27  #include <qpopupmenu.h>  #include <qpopupmenu.h>
28    #include <qobjectlist.h>
29    
30  #include <math.h>  #include <math.h>
31    
# Line 38  Line 39 
39  void qsamplerChannelStrip::init (void)  void qsamplerChannelStrip::init (void)
40  {  {
41      // Initialize locals.      // Initialize locals.
42      m_pMainForm  = NULL;      m_pChannel     = NULL;
     m_iChannelID = 0;  
       
 //  m_sEngineName     = "(No engine)";  
 //  m_sInstrumentFile = "(No instrument)";  
     m_iInstrumentNr   = 0;  
     m_sMidiDriver     = "ALSA"; // DEPRECATED.  
     m_iMidiDevice     = 0;  
     m_iMidiPort       = 0;  
     m_iMidiChannel    = 0;  
     m_sAudioDriver    = "ALSA"; // DEPRECATED.  
     m_iAudioDevice    = 0;  
     m_fVolume         = 0.8;  
       
43      m_iDirtyChange = 0;      m_iDirtyChange = 0;
44    
45      // Try to restore normal window positioning.      // Try to restore normal window positioning.
# Line 62  void qsamplerChannelStrip::init (void) Line 50  void qsamplerChannelStrip::init (void)
50  // Kind of destructor.  // Kind of destructor.
51  void qsamplerChannelStrip::destroy (void)  void qsamplerChannelStrip::destroy (void)
52  {  {
53        // Destroy existing channel descriptor.
54        if (m_pChannel)
55            delete m_pChannel;
56        m_pChannel = NULL;
57  }  }
58    
59    
60  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
61  void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID )  void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel )
 {  
     m_iDirtyChange = 0;  
     m_pMainForm = pMainForm;  
   
     setChannelID(iChannelID);  
 }  
   
   
 // The global options settings delegated property.  
 qsamplerOptions *qsamplerChannelStrip::options (void)  
62  {  {
63      if (m_pMainForm == NULL)      // Destroy any previous channel descriptor;
64          return NULL;      // (remember that once setup we own it!)
65                if (m_pChannel)
66      return m_pMainForm->options();          delete m_pChannel;
 }  
   
67    
68  // The client descriptor delegated property.      // Set the new one...
69  lscp_client_t *qsamplerChannelStrip::client (void)      m_pChannel = pChannel;
 {  
     if (m_pMainForm == NULL)  
         return NULL;  
   
     return m_pMainForm->client();  
 }  
   
   
 // Channel-ID (aka Sammpler-Channel) accessors.  
 int qsamplerChannelStrip::channelID (void)  
 {  
     return m_iChannelID;  
 }  
   
 void qsamplerChannelStrip::setChannelID ( int iChannelID )  
 {  
     m_iChannelID = iChannelID;  
70    
71        // Stabilize this around.
72      updateChannelInfo();      updateChannelInfo();
73  }  }
74    
75    // Channel secriptor accessor.
76  // Engine name accessors.  qsamplerChannel *qsamplerChannelStrip::channel (void)
 QString& qsamplerChannelStrip::engineName (void)  
 {  
     return m_sEngineName;  
 }  
   
 bool qsamplerChannelStrip::loadEngine ( const QString& sEngineName )  
 {  
     if (client() == NULL)  
         return false;  
   
     if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {  
         appendMessagesClient("lscp_load_engine");  
         return false;  
     }  
   
     m_sEngineName = sEngineName;  
     return true;  
 }  
   
   
 // Instrument filename accessors.  
 QString& qsamplerChannelStrip::instrumentFile (void)  
 {  
     return m_sInstrumentFile;  
 }  
   
 // Instrument index accessors.  
 int qsamplerChannelStrip::instrumentNr (void)  
 {  
     return m_iInstrumentNr;  
 }  
   
 bool qsamplerChannelStrip::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  
 {  
     if (client() == NULL)  
         return false;  
   
     if (::lscp_load_instrument(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {  
         appendMessagesClient("lscp_load_instrument");  
         return false;  
     }  
   
     m_sInstrumentFile = sInstrumentFile;  
     m_iInstrumentNr = iInstrumentNr;  
     return true;  
 }  
   
   
 // MIDI driver type accessors (DEPRECATED).  
 QString& qsamplerChannelStrip::midiDriver (void)  
77  {  {
78      return m_sMidiDriver;      return m_pChannel;
79  }  }
80    
 bool qsamplerChannelStrip::setMidiDriver ( const QString& sMidiDriver )  
 {  
     if (client() == NULL)  
         return false;  
   
     if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {  
         appendMessagesClient("lscp_set_channel_midi_type");  
         return false;  
     }  
81    
82      m_sMidiDriver = sMidiDriver;  // Messages view font accessors.
83      return true;  QFont qsamplerChannelStrip::displayFont (void)
 }  
   
   
 // MIDI device accessors.  
 int qsamplerChannelStrip::midiDevice (void)  
 {  
     return m_iMidiDevice;  
 }  
   
 bool qsamplerChannelStrip::setMidiDevice ( int iMidiDevice )  
 {  
     if (client() == NULL)  
         return false;  
   
 //  FIXME: call this when LSCP becomes stable.  
 //  if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {  
 //      appendMessagesClient("lscp_set_channel_midi_device");  
 //      return false;  
 //  }  
   
     m_iMidiDevice = iMidiDevice;  
     return true;  
 }  
   
   
 // MIDI port number accessor.  
 int qsamplerChannelStrip::midiPort (void)  
 {  
     return m_iMidiPort;  
 }  
   
 bool qsamplerChannelStrip::setMidiPort ( int iMidiPort )  
 {  
     if (client() == NULL)  
         return false;  
   
 //  FIXME: call this when LSCP becomes stable.  
 //  if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {  
 //      appendMessagesClient("lscp_set_channel_midi_port");  
 //      return false;  
 //  }  
   
     m_iMidiPort = iMidiPort;  
     return true;  
 }  
   
   
 // MIDI channel accessor.  
 int qsamplerChannelStrip::midiChannel (void)  
84  {  {
85      return m_iMidiChannel;      return EngineNameTextLabel->font();
86  }  }
87    
88  bool qsamplerChannelStrip::setMidiChannel ( int iMidiChannel )  void qsamplerChannelStrip::setDisplayFont ( const QFont & font )
89  {  {
90      if (client() == NULL)      EngineNameTextLabel->setFont(font);
91          return false;      MidiPortChannelTextLabel->setFont(font);
92        InstrumentNameTextLabel->setFont(font);
93  //  FIXME: call this when LSCP becomes stable.      InstrumentStatusTextLabel->setFont(font);
 //  if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {  
 //      appendMessagesClient("lscp_set_channel_midi_channel");  
 //      return false;  
 //  }  
   
     m_iMidiChannel = iMidiChannel;  
     return true;  
94  }  }
95    
96    
97  // Audio device accessor.  // Channel display background effect.
98  int qsamplerChannelStrip::audioDevice (void)  void qsamplerChannelStrip::setDisplayEffect ( bool bDisplayEffect )
 {  
     return m_iAudioDevice;  
 }  
   
 bool qsamplerChannelStrip::setAudioDevice ( int iAudioDevice )  
99  {  {
100      if (client() == NULL)      QPixmap pm;
101          return false;      if (bDisplayEffect)
102            pm = QPixmap::fromMimeSource("displaybg1.png");
103  //  FIXME: call this when LSCP becomes stable.      setDisplayBackground(pm);
 //  if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {  
 //      appendMessagesClient("lscp_set_channel_audio_device");  
 //      return false;  
 //  }  
   
     m_iAudioDevice = iAudioDevice;  
     return true;  
104  }  }
105    
106    
107  // Audio driver type accessors (DEPRECATED).  // Update main display background pixmap.
108  QString& qsamplerChannelStrip::audioDriver (void)  void qsamplerChannelStrip::setDisplayBackground ( const QPixmap& pm )
109  {  {
110      return m_sAudioDriver;      // Set the main origin...
111  }      ChannelInfoFrame->setPaletteBackgroundPixmap(pm);
112    
113  bool qsamplerChannelStrip::setAudioDriver ( const QString& sAudioDriver )      // Iterate for every child text label...
114  {      QObjectList *pList = ChannelInfoFrame->queryList("QLabel");
115      if (client() == NULL)      if (pList) {
116          return false;          for (QLabel *pLabel = (QLabel *) pList->first(); pLabel; pLabel = (QLabel *) pList->next())
117                pLabel->setPaletteBackgroundPixmap(pm);
118      if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {          delete pList;
         appendMessagesClient("lscp_set_channel_audio_type");  
         return false;  
119      }      }
120        
121      m_sAudioDriver = sAudioDriver;      // And this standalone too.
122      return true;      StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm);
123  }  }
124    
125    
126  // Channel volume accessors.  // Channel setup dialog slot.
127  float qsamplerChannelStrip::volume (void)  bool qsamplerChannelStrip::channelSetup (void)
128  {  {
129      return m_fVolume;      bool bResult = m_pChannel->channelSetup(this);
 }  
130    
131  bool qsamplerChannelStrip::setVolume ( float fVolume )      if (bResult)
132  {          emit channelChanged(this);
     if (client() == NULL)  
         return false;  
   
     if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {  
         appendMessagesClient("lscp_set_channel_volume");  
         return false;  
     }  
133    
134      m_fVolume = fVolume;      return bResult;
     return true;  
135  }  }
136    
137    
138  // Messages view font accessors.  // Update the channel instrument name.
139  QFont qsamplerChannelStrip::displayFont (void)  bool qsamplerChannelStrip::updateInstrumentName ( bool bForce )
140  {  {
141      return EngineNameTextLabel->font();          if (m_pChannel == NULL)
142  }                  return false;
143    
144  void qsamplerChannelStrip::setDisplayFont ( const QFont & font )          // Do we refersh the actual name?
145  {          if (bForce)
146      EngineNameTextLabel->setFont(font);                  m_pChannel->updateInstrumentName();
     InstrumentNameTextLabel->setFont(font);  
     MidiPortChannelTextLabel->setFont(font);  
 }  
147    
148  // Channel setup dialog.          // Instrument name...
149  void qsamplerChannelStrip::channelSetup (void)          if (m_pChannel->instrumentName().isEmpty())
150  {                  InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());
151      qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);          else
152      if (pChannelForm) {                  InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());
153          pChannelForm->setup(this);  
154          if (pChannelForm->exec()) {          return true;    
             updateChannelInfo();  
             emit channelChanged(this);  
         }  
         delete pChannelForm;  
     }  
155  }  }
156    
157    
158  // Update whole channel info state.  // Update whole channel info state.
159  void qsamplerChannelStrip::updateChannelInfo (void)  bool qsamplerChannelStrip::updateChannelInfo (void)
160  {  {
161        if (m_pChannel == NULL)
162            return false;
163            
164      // Update strip caption.      // Update strip caption.
165      QString sText = tr("Channel %1").arg(m_iChannelID);      QString sText = m_pChannel->channelName();
166      setCaption(sText);      setCaption(sText);
167      ChannelSetupPushButton->setText(sText);      ChannelSetupPushButton->setText(sText);
168    
169      // Check if we're up and connected.      // Check if we're up and connected.
170      if (client() == NULL)      if (m_pChannel->client() == NULL)
171          return;          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_iMidiDevice     = pChannelInfo->midi_device;  
         m_iMidiPort       = pChannelInfo->midi_port;  
         m_iMidiChannel    = pChannelInfo->midi_channel;  
         m_iAudioDevice    = pChannelInfo->audio_device;  
         m_fVolume         = pChannelInfo->volume;  
     }  
172    
173      // Set some proper display values.      // Read actual channel information.
174        m_pChannel->updateChannelInfo();
175    
176      // Engine name...      // Engine name...
177      if (m_sEngineName.isEmpty())      if (m_pChannel->engineName().isEmpty())
178          EngineNameTextLabel->setText(tr("(No engine)"));          EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());
179      else      else
180          EngineNameTextLabel->setText(m_sEngineName);          EngineNameTextLabel->setText(' ' + m_pChannel->engineName());
181    
182      // Instrument name...          // Instrument name...
183      if (m_sInstrumentFile.isEmpty())          updateInstrumentName(false);
184          InstrumentNameTextLabel->setText(tr("(No instrument)"));  
185      else      // Instrument status...
186          InstrumentNameTextLabel->setText(QString("%1 [%2]")      int iInstrumentStatus = m_pChannel->instrumentStatus();
187              .arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr));      if (iInstrumentStatus < 0) {
188            InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
189            InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
190        } else {
191            InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
192            InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
193        }
194    
195      // MIDI Port/Channel...      // MIDI Port/Channel...
196      MidiPortChannelTextLabel->setText(QString("%1 / %2")      if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
197          .arg(m_iMidiPort).arg(m_iMidiChannel));          MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
198                else
199            MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1));
200    
201      // And update the both GUI volume elements.      // And update the both GUI volume elements.
202      updateChannelVolume();      return updateChannelVolume();
203  }  }
204    
205    
206  // Do the dirty volume change.  // Do the dirty volume change.
207  void qsamplerChannelStrip::updateChannelVolume (void)  bool qsamplerChannelStrip::updateChannelVolume (void)
208  {  {
209        if (m_pChannel == NULL)
210            return false;
211    
212      // Convert...      // Convert...
213  #ifdef CONFIG_ROUND  #ifdef CONFIG_ROUND
214      int iVolume = (int) ::round(100.0 * m_fVolume);      int iVolume = (int) ::round(100.0 * m_pChannel->volume());
215  #else  #else
216      double fIPart = 0.0;      double fIPart = 0.0;
217      double fFPart = ::modf(100.0 * m_fVolume, &fIPart);      double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
218      int iVolume = (int) fIPart;      int iVolume = (int) fIPart;
219      if (fFPart >= +0.5)      if (fFPart >= +0.5)
220          iVolume++;          iVolume++;
# Line 408  void qsamplerChannelStrip::updateChannel Line 224  void qsamplerChannelStrip::updateChannel
224  #endif  #endif
225    
226      // And clip...      // And clip...
227      if (iVolume > 100)      if (iVolume < 0)
         iVolume = 100;  
     else if (iVolume < 0)  
228          iVolume = 0;          iVolume = 0;
229    
230      // Flag it here, to avoid infinite recursion.      // Flag it here, to avoid infinite recursion.
# Line 418  void qsamplerChannelStrip::updateChannel Line 232  void qsamplerChannelStrip::updateChannel
232      VolumeSlider->setValue(iVolume);      VolumeSlider->setValue(iVolume);
233      VolumeSpinBox->setValue(iVolume);      VolumeSpinBox->setValue(iVolume);
234      m_iDirtyChange--;      m_iDirtyChange--;
235        
236        return true;
237  }  }
238    
239    
240  // Update whole channel usage state.  // Update whole channel usage state.
241  void qsamplerChannelStrip::updateChannelUsage (void)  bool qsamplerChannelStrip::updateChannelUsage (void)
242  {  {
243      if (client() == NULL)      if (m_pChannel == NULL)
244          return;          return false;
245        if (m_pChannel->client() == NULL)
246            return false;
247    
248        // Update whole channel status info,
249        // if instrument load is still pending...
250        if (m_pChannel->instrumentStatus() < 100) {
251            updateChannelInfo();
252            // Check (updated) status again...
253            if (m_pChannel->instrumentStatus() < 100)
254                return false;
255            // Once we get a complete instrument load,
256            // we'll try an implied channel reset...
257            m_pChannel->resetChannel();
258        }
259        
260        // Check again that we're clean.
261        if (m_pChannel->instrumentStatus() < 100)
262            return false;
263    
264      // Get current channel voice count.      // Get current channel voice count.
265      int iVoiceCount  = ::lscp_get_channel_voice_count(client(), m_iChannelID);      int iVoiceCount  = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
266      // Get current stream count.      // Get current stream count.
267      int iStreamCount = ::lscp_get_channel_stream_count(client(), m_iChannelID);      int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
268      // Get current channel buffer fill usage.      // Get current channel buffer fill usage.
269      // As benno has suggested this is the percentage usage      // As benno has suggested this is the percentage usage
270      // of the least filled buffer stream...      // of the least filled buffer stream...
271      int iStreamUsage = 0;      int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
272      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;  
             }  
         }  
     }      
273      // Update the GUI elements...      // Update the GUI elements...
274      StreamUsageProgressBar->setProgress(iStreamUsage);      StreamUsageProgressBar->setProgress(iStreamUsage);
275      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
276        
277        // We're clean.
278        return true;
279  }  }
280    
281    
282  // Volume change slot.  // Volume change slot.
283  void qsamplerChannelStrip::volumeChanged ( int iVolume )  void qsamplerChannelStrip::volumeChanged ( int iVolume )
284  {  {
285        if (m_pChannel == NULL)
286            return;
287    
288      // Avoid recursion.      // Avoid recursion.
289      if (m_iDirtyChange > 0)      if (m_iDirtyChange > 0)
290          return;          return;
291    
292      // Convert and clip.      // Convert and clip.
293      float fVolume = (float) iVolume / 100.0;      float fVolume = (float) iVolume / 100.0;
294      if (fVolume > 1.0)      if (fVolume < 0.001)
         fVolume = 1.0;  
     else if (fVolume < 0.0)  
295          fVolume = 0.0;          fVolume = 0.0;
296    
297      // Update the GUI elements.      // Update the GUI elements.
298      if (setVolume(fVolume)) {      if (m_pChannel->setVolume(fVolume)) {
299          updateChannelVolume();          updateChannelVolume();
300          emit channelChanged(this);          emit channelChanged(this);
301      }      }
302  }  }
303    
304    
305  // Redirected messages output methods.  // Context menu event handler.
306  void qsamplerChannelStrip::appendMessages( const QString& s )  void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
 {  
     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 )  
307  {  {
308      m_pMainForm->appendMessagesClient(s);      if (m_pChannel == NULL)
309            return;
310            
311        // We'll just show up the main form's edit menu (thru qsamplerChannel).
312        m_pChannel->contextMenuEvent(pEvent);
313  }  }
314    
315    
316  // Context menu event handler.  // Maximum volume slider accessors.
317  void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume )
318  {  {
319      // We'll just show up the main form's edit menu.      m_iDirtyChange++;
320      m_pMainForm->stabilizeForm();      VolumeSlider->setRange(0, iMaxVolume);
321      m_pMainForm->editMenu->exec(pEvent->globalPos());      VolumeSpinBox->setRange(0, iMaxVolume);
322        m_iDirtyChange--;
323  }  }
324    
325    
326  // end of qsamplerChannelStrip.ui.h  // end of qsamplerChannelStrip.ui.h
   

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

  ViewVC Help
Powered by ViewVC