/[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 261 by capela, Wed Sep 29 07:43:26 2004 UTC revision 341 by capela, Tue Jan 18 11:29:01 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       = tr("(No engine)");  
 //  m_sInstrumentFile   = tr("(No instrument)");  
     m_iInstrumentNr     = -1;  
     m_iInstrumentStatus = -1;  
     m_sMidiDriver       = "Alsa";   // DEPRECATED.  
     m_iMidiDevice       = -1;  
     m_iMidiPort         = -1;  
     m_iMidiChannel      = -1;  
     m_sAudioDriver      = "Alsa";   // DEPRECATED.  
     m_iAudioDevice      = -1;  
     m_fVolume           = 0.0;  
       
43      m_iDirtyChange = 0;      m_iDirtyChange = 0;
44    
45      // Try to restore normal window positioning.      // Try to restore normal window positioning.
# Line 63  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)  
 {  
     if (m_pMainForm == NULL)  
         return NULL;  
           
     return m_pMainForm->options();  
 }  
   
   
 // The client descriptor delegated property.  
 lscp_client_t *qsamplerChannelStrip::client (void)  
 {  
     if (m_pMainForm == NULL)  
         return NULL;  
   
     return m_pMainForm->client();  
 }  
   
   
 // Channel-ID (aka Sammpler-Channel) accessors.  
 int qsamplerChannelStrip::channelID (void)  
62  {  {
63      return m_iChannelID;      // Destroy any previous channel descriptor;
64  }      // (remember that once setup we own it!)
65        if (m_pChannel)
66            delete m_pChannel;
67    
68  void qsamplerChannelStrip::setChannelID ( int iChannelID )      // Set the new one...
69  {      m_pChannel = pChannel;
     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)  
77  {  {
78      return m_sEngineName;      return m_pChannel;
79  }  }
80    
 bool qsamplerChannelStrip::loadEngine ( const QString& sEngineName )  
 {  
     if (client() == NULL)  
         return false;  
81    
82      if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {  // Messages view font accessors.
83          appendMessagesClient("lscp_load_engine");  QFont qsamplerChannelStrip::displayFont (void)
         return false;  
     }  
   
     m_sEngineName = sEngineName;  
     return true;  
 }  
   
   
 // Instrument filename accessor.  
 QString& qsamplerChannelStrip::instrumentFile (void)  
 {  
     return m_sInstrumentFile;  
 }  
   
 // Instrument index accessor.  
 int qsamplerChannelStrip::instrumentNr (void)  
 {  
     return m_iInstrumentNr;  
 }  
   
 // Instrument status accessor.  
 int qsamplerChannelStrip::instrumentStatus (void)  
 {  
     return m_iInstrumentStatus;  
 }  
   
 // Instrument file loader.  
 bool qsamplerChannelStrip::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  
 {  
     if (client() == NULL)  
         return false;  
   
     if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {  
         appendMessagesClient("lscp_load_instrument");  
         return false;  
     }  
   
     m_sInstrumentFile = sInstrumentFile;  
     m_iInstrumentNr = iInstrumentNr;  
     m_iInstrumentStatus = 0;  
       
     return true;  
 }  
   
   
 // MIDI driver type accessors (DEPRECATED).  
 QString& qsamplerChannelStrip::midiDriver (void)  
 {  
     return m_sMidiDriver;  
 }  
   
 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;  
     }  
   
     m_sMidiDriver = sMidiDriver;  
     return true;  
 }  
   
   
 // MIDI device accessors.  
 int qsamplerChannelStrip::midiDevice (void)  
 {  
     return m_iMidiDevice;  
 }  
   
 bool qsamplerChannelStrip::setMidiDevice ( int iMidiDevice )  
 {  
     if (client() == NULL)  
         return false;  
   
     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;  
   
     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)  
 {  
     return m_iMidiChannel;  
 }  
   
 bool qsamplerChannelStrip::setMidiChannel ( int iMidiChannel )  
 {  
     if (client() == NULL)  
         return false;  
   
     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;  
 }  
   
   
 // Audio device accessor.  
 int qsamplerChannelStrip::audioDevice (void)  
84  {  {
85      return m_iAudioDevice;      return EngineNameTextLabel->font();
86  }  }
87    
88  bool qsamplerChannelStrip::setAudioDevice ( int iAudioDevice )  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      if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {      InstrumentStatusTextLabel->setFont(font);
         appendMessagesClient("lscp_set_channel_audio_device");  
         return false;  
     }  
   
     m_iAudioDevice = iAudioDevice;  
     return true;  
94  }  }
95    
96    
97  // Audio driver type accessors (DEPRECATED).  // Channel display background effect.
98  QString& qsamplerChannelStrip::audioDriver (void)  void qsamplerChannelStrip::setDisplayEffect ( bool bDisplayEffect )
99  {  {
100      return m_sAudioDriver;      QPixmap pm;
101  }      if (bDisplayEffect)
102            pm = QPixmap::fromMimeSource("displaybg1.png");
103  bool qsamplerChannelStrip::setAudioDriver ( const QString& sAudioDriver )      setDisplayBackground(pm);
 {  
     if (client() == NULL)  
         return false;  
   
     if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {  
         appendMessagesClient("lscp_set_channel_audio_type");  
         return false;  
     }  
   
     m_sAudioDriver = sAudioDriver;  
     return true;  
104  }  }
105    
106    
107  // Channel volume accessors.  // Update main display background pixmap.
108  float qsamplerChannelStrip::volume (void)  void qsamplerChannelStrip::setDisplayBackground ( const QPixmap& pm )
109  {  {
110      return m_fVolume;      // Set the main origin...
111  }      ChannelInfoFrame->setPaletteBackgroundPixmap(pm);
112    
113  bool qsamplerChannelStrip::setVolume ( float fVolume )      // 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_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {          delete pList;
         appendMessagesClient("lscp_set_channel_volume");  
         return false;  
119      }      }
120        
121      m_fVolume = fVolume;      // And this standalone too.
122      return true;      StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm);
123  }  }
124    
125    
126  // Messages view font accessors.  // Channel setup dialog slot.
127  QFont qsamplerChannelStrip::displayFont (void)  bool qsamplerChannelStrip::channelSetup (void)
128  {  {
129      return EngineNameTextLabel->font();      bool bResult = m_pChannel->channelSetup(this);
 }  
130    
131  void qsamplerChannelStrip::setDisplayFont ( const QFont & font )      if (bResult)
132  {          emit channelChanged(this);
     EngineNameTextLabel->setFont(font);  
     MidiPortChannelTextLabel->setFont(font);  
     InstrumentNameTextLabel->setFont(font);  
     InstrumentStatusTextLabel->setFont(font);  
 }  
133    
134  // Channel setup dialog.      return bResult;
 void qsamplerChannelStrip::channelSetup ( bool bNew )  
 {  
     qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);  
     if (pChannelForm) {  
         pChannelForm->setup(this, bNew);  
         if (pChannelForm->exec()) {  
             updateChannelInfo();  
             emit channelChanged(this);  
         }  
         delete pChannelForm;  
     }  
135  }  }
136    
137    
138  // Update whole channel info state.  // Update whole channel info state.
139  void qsamplerChannelStrip::updateChannelInfo (void)  bool qsamplerChannelStrip::updateChannelInfo (void)
140  {  {
141        if (m_pChannel == NULL)
142            return false;
143            
144      // Update strip caption.      // Update strip caption.
145      QString sText = tr("Channel %1").arg(m_iChannelID);      QString sText = m_pChannel->channelName();
146      setCaption(sText);      setCaption(sText);
147      ChannelSetupPushButton->setText(sText);      ChannelSetupPushButton->setText(sText);
148    
149      // Check if we're up and connected.      // Check if we're up and connected.
150      if (client() == NULL)      if (m_pChannel->client() == NULL)
151          return;          return false;
152    
153      // Read channel information.      // Read actual channel information.
154      lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);      m_pChannel->updateChannelInfo();
     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_iInstrumentStatus = pChannelInfo->instrument_status;  
         m_iMidiDevice       = pChannelInfo->midi_device;  
         m_iMidiPort         = pChannelInfo->midi_port;  
         m_iMidiChannel      = pChannelInfo->midi_channel;  
         m_iAudioDevice      = pChannelInfo->audio_device;  
         m_fVolume           = pChannelInfo->volume;  
         // Some sanity checks.  
         if (m_sEngineName == "NONE")  
             m_sEngineName = QString::null;  
         if (m_sInstrumentFile == "NONE")  
             m_sInstrumentFile = QString::null;  
     }  
155    
156      // Set some proper display values.      // Set some proper display values.
157      const QString sIndent = " ";      const QString sIndent = " ";
158    
159      // Engine name...      // Engine name...
160      if (m_sEngineName.isEmpty())      if (m_pChannel->engineName().isEmpty())
161          EngineNameTextLabel->setText(sIndent + tr("(No engine)"));          EngineNameTextLabel->setText(sIndent + tr("(No engine)"));
162      else      else
163          EngineNameTextLabel->setText(sIndent + m_sEngineName);          EngineNameTextLabel->setText(sIndent + m_pChannel->engineName());
164    
165      // Instrument name...      // Instrument name...
166      if (m_sInstrumentFile.isEmpty())      if (m_pChannel->instrumentFile().isEmpty())
167          InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));          InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));
168      else      else
169          InstrumentNameTextLabel->setText(sIndent + QString("%1 [%2]")          InstrumentNameTextLabel->setText(sIndent + qsamplerChannel::getInstrumentName(m_pChannel->instrumentFile(), m_pChannel->instrumentNr()));
             .arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr));  
170    
171      // Instrument status...      // Instrument status...
172      if (m_iInstrumentStatus < 0) {      int iInstrumentStatus = m_pChannel->instrumentStatus();
173        if (iInstrumentStatus < 0) {
174          InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);          InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
175          InstrumentStatusTextLabel->setText(tr("ERR%1").arg(m_iInstrumentStatus));          InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
176      } else {      } else {
177          InstrumentStatusTextLabel->setPaletteForegroundColor(m_iInstrumentStatus < 100 ? Qt::yellow : Qt::green);          InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
178          InstrumentStatusTextLabel->setText(QString::number(m_iInstrumentStatus) + "%");          InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
179      }      }
180    
181      // MIDI Port/Channel...      // MIDI Port/Channel...
182      if (m_iMidiChannel > 0)      if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
183          MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_iMidiPort).arg(m_iMidiChannel));          MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
184      else      else
185          MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_iMidiPort));          MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1));
186    
187      // And update the both GUI volume elements.      // And update the both GUI volume elements.
188      updateChannelVolume();      return updateChannelVolume();
189  }  }
190    
191    
192  // Do the dirty volume change.  // Do the dirty volume change.
193  void qsamplerChannelStrip::updateChannelVolume (void)  bool qsamplerChannelStrip::updateChannelVolume (void)
194  {  {
195        if (m_pChannel == NULL)
196            return false;
197    
198      // Convert...      // Convert...
199  #ifdef CONFIG_ROUND  #ifdef CONFIG_ROUND
200      int iVolume = (int) ::round(100.0 * m_fVolume);      int iVolume = (int) ::round(100.0 * m_pChannel->volume());
201  #else  #else
202      double fIPart = 0.0;      double fIPart = 0.0;
203      double fFPart = ::modf(100.0 * m_fVolume, &fIPart);      double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
204      int iVolume = (int) fIPart;      int iVolume = (int) fIPart;
205      if (fFPart >= +0.5)      if (fFPart >= +0.5)
206          iVolume++;          iVolume++;
# Line 441  void qsamplerChannelStrip::updateChannel Line 218  void qsamplerChannelStrip::updateChannel
218      VolumeSlider->setValue(iVolume);      VolumeSlider->setValue(iVolume);
219      VolumeSpinBox->setValue(iVolume);      VolumeSpinBox->setValue(iVolume);
220      m_iDirtyChange--;      m_iDirtyChange--;
221        
222        return true;
223  }  }
224    
225    
226  // Update whole channel usage state.  // Update whole channel usage state.
227  void qsamplerChannelStrip::updateChannelUsage (void)  bool qsamplerChannelStrip::updateChannelUsage (void)
228  {  {
229      if (client() == NULL)      if (m_pChannel == NULL)
230          return;          return false;
231        if (m_pChannel->client() == NULL)
232            return false;
233    
234      // Conditionally update whole channel status info.      // Update whole channel status info,
235      if (m_iInstrumentStatus >= 0 && m_iInstrumentStatus < 100) {      // if instrument load is still pending...
236        if (m_pChannel->instrumentStatus() < 100) {
237          updateChannelInfo();          updateChannelInfo();
238          // Once we get a complete instrument load, try a implied reset channel....          // Check (updated) status again...
239          if (m_iInstrumentStatus == 100) {          if (m_pChannel->instrumentStatus() < 100)
240              if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK)              return false;
241                  appendMessagesClient("lscp_reset_channel");          // Once we get a complete instrument load,
242              else          // we'll try an implied channel reset...
243                  appendMessages(tr("Channel %1 reset.").arg(m_iChannelID));          m_pChannel->resetChannel();
         }  
244      }      }
245      // Leave, if we still have an erroneus or incomplete instrument load.      
246      if (m_iInstrumentStatus < 100)      // Check again that we're clean.
247          return;      if (m_pChannel->instrumentStatus() < 100)
248            return false;
249    
250      // Get current channel voice count.      // Get current channel voice count.
251      int iVoiceCount  = ::lscp_get_channel_voice_count(client(), m_iChannelID);      int iVoiceCount  = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
252      // Get current stream count.      // Get current stream count.
253      int iStreamCount = ::lscp_get_channel_stream_count(client(), m_iChannelID);      int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
254      // Get current channel buffer fill usage.      // Get current channel buffer fill usage.
255      // As benno has suggested this is the percentage usage      // As benno has suggested this is the percentage usage
256      // of the least filled buffer stream...      // of the least filled buffer stream...
257      int iStreamUsage = ::lscp_get_channel_stream_usage(client(), m_iChannelID);;      int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
258    
259      // Update the GUI elements...      // Update the GUI elements...
260      StreamUsageProgressBar->setProgress(iStreamUsage);      StreamUsageProgressBar->setProgress(iStreamUsage);
261      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
262        
263        // We're clean.
264        return true;
265  }  }
266    
267    
268  // Volume change slot.  // Volume change slot.
269  void qsamplerChannelStrip::volumeChanged ( int iVolume )  void qsamplerChannelStrip::volumeChanged ( int iVolume )
270  {  {
271        if (m_pChannel == NULL)
272            return;
273    
274      // Avoid recursion.      // Avoid recursion.
275      if (m_iDirtyChange > 0)      if (m_iDirtyChange > 0)
276          return;          return;
# Line 493  void qsamplerChannelStrip::volumeChanged Line 281  void qsamplerChannelStrip::volumeChanged
281          fVolume = 0.0;          fVolume = 0.0;
282    
283      // Update the GUI elements.      // Update the GUI elements.
284      if (setVolume(fVolume)) {      if (m_pChannel->setVolume(fVolume)) {
285          updateChannelVolume();          updateChannelVolume();
286          emit channelChanged(this);          emit channelChanged(this);
287      }      }
288  }  }
289    
290    
 // Redirected messages output methods.  
 void qsamplerChannelStrip::appendMessages( const QString& s )  
 {  
     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 )  
 {  
     m_pMainForm->appendMessagesClient(s);  
 }  
   
   
291  // Context menu event handler.  // Context menu event handler.
292  void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
293  {  {
294      // We'll just show up the main form's edit menu.      if (m_pChannel == NULL)
295      m_pMainForm->contextMenuEvent(pEvent);          return;
296            
297        // We'll just show up the main form's edit menu (thru qsamplerChannel).
298        m_pChannel->contextMenuEvent(pEvent);
299  }  }
300    
301    

Legend:
Removed from v.261  
changed lines
  Added in v.341

  ViewVC Help
Powered by ViewVC