/[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 152 by capela, Sun Jun 27 13:53:11 2004 UTC revision 302 by capela, Wed Nov 17 17:17:18 2004 UTC
# 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_pMainForm    = NULL;
43      m_iChannelID = 0;      m_pChannel     = NULL;
       
 //  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;  
       
44      m_iDirtyChange = 0;      m_iDirtyChange = 0;
45    
46      // Try to restore normal window positioning.      // Try to restore normal window positioning.
# Line 63  void qsamplerChannelStrip::init (void) Line 51  void qsamplerChannelStrip::init (void)
51  // Kind of destructor.  // Kind of destructor.
52  void qsamplerChannelStrip::destroy (void)  void qsamplerChannelStrip::destroy (void)
53  {  {
54        // Destroy existing channel descriptor.
55        if (m_pChannel)
56            delete m_pChannel;
57        m_pChannel = NULL;
58  }  }
59    
60    
61  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
62  void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID )  void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID )
63  {  {
64      m_iDirtyChange = 0;      // Set main form reference.
65      m_pMainForm = pMainForm;      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)  
 {  
     return m_iChannelID;  
 }  
   
 void qsamplerChannelStrip::setChannelID ( int iChannelID )  
 {  
     m_iChannelID = iChannelID;  
   
     updateChannelInfo();  
 }  
   
   
 // Engine name accessors.  
 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 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;  
66            
67      return true;      // Destroy any previous channel descriptor.
68  }      if (m_pChannel)
69            delete m_pChannel;
70    
71  // MIDI driver type accessors (DEPRECATED).      // Create a new one...
72  QString& qsamplerChannelStrip::midiDriver (void)      m_pChannel = new qsamplerChannel(pMainForm);
73  {      // And set appropriate settings.
74      return m_sMidiDriver;      if (m_pChannel && iChannelID >= 0) {
75  }          m_pChannel->setChannelID(iChannelID);
76            m_iDirtyChange = 0;
 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;  
77      }      }
78    
79      m_sMidiDriver = sMidiDriver;      // Stabilize this around.
80      return true;      updateChannelInfo();
 }  
   
   
 // 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;  
81  }  }
82    
83    // Channel secriptor accessor.
84  // MIDI channel accessor.  qsamplerChannel *qsamplerChannelStrip::channel (void)
 int qsamplerChannelStrip::midiChannel (void)  
85  {  {
86      return m_iMidiChannel;      return m_pChannel;
87  }  }
88    
 bool qsamplerChannelStrip::setMidiChannel ( int iMidiChannel )  
 {  
     if (client() == NULL)  
         return false;  
89    
90      if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {  // Messages view font accessors.
91          appendMessagesClient("lscp_set_channel_midi_channel");  QFont qsamplerChannelStrip::displayFont (void)
         return false;  
     }  
   
     m_iMidiChannel = iMidiChannel;  
     return true;  
 }  
   
   
 // Audio device accessor.  
 int qsamplerChannelStrip::audioDevice (void)  
92  {  {
93      return m_iAudioDevice;      return EngineNameTextLabel->font();
94  }  }
95    
96  bool qsamplerChannelStrip::setAudioDevice ( int iAudioDevice )  void qsamplerChannelStrip::setDisplayFont ( const QFont & font )
97  {  {
98      if (client() == NULL)      EngineNameTextLabel->setFont(font);
99          return false;      MidiPortChannelTextLabel->setFont(font);
100        InstrumentNameTextLabel->setFont(font);
101      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;  
102  }  }
103    
104    
105  // Audio driver type accessors (DEPRECATED).  // Channel display background effect.
106  QString& qsamplerChannelStrip::audioDriver (void)  void qsamplerChannelStrip::setDisplayEffect ( bool bDisplayEffect )
107  {  {
108      return m_sAudioDriver;      QPixmap pm;
109        if (bDisplayEffect)
110            pm = QPixmap::fromMimeSource("displaybg1.png");
111        setDisplayBackground(pm);
112  }  }
113    
 bool qsamplerChannelStrip::setAudioDriver ( const QString& sAudioDriver )  
 {  
     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;  
     }  
114    
115      m_sAudioDriver = sAudioDriver;  // Update main display background pixmap.
116      return true;  void qsamplerChannelStrip::setDisplayBackground ( const QPixmap& pm )
 }  
   
   
 // Channel volume accessors.  
 float qsamplerChannelStrip::volume (void)  
 {  
     return m_fVolume;  
 }  
   
 bool qsamplerChannelStrip::setVolume ( float fVolume )  
117  {  {
118      if (client() == NULL)      // Set the main origin...
119          return false;      ChannelInfoFrame->setPaletteBackgroundPixmap(pm);
120    
121      if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {      // Iterate for every child text label...
122          appendMessagesClient("lscp_set_channel_volume");      QObjectList *pList = ChannelInfoFrame->queryList("QLabel");
123          return false;      if (pList) {
124            for (QLabel *pLabel = (QLabel *) pList->first(); pLabel; pLabel = (QLabel *) pList->next())
125                pLabel->setPaletteBackgroundPixmap(pm);
126            delete pList;
127      }      }
128        
129      m_fVolume = fVolume;      // And this standalone too.
130      return true;      StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm);
131  }  }
132    
133    
134  // Messages view font accessors.  // Channel setup dialog slot.
135  QFont qsamplerChannelStrip::displayFont (void)  bool qsamplerChannelStrip::channelSetup (void)
 {  
     return EngineNameTextLabel->font();  
 }  
   
 void qsamplerChannelStrip::setDisplayFont ( const QFont & font )  
136  {  {
137      EngineNameTextLabel->setFont(font);      bool bResult = false;
     MidiPortChannelTextLabel->setFont(font);  
     InstrumentNameTextLabel->setFont(font);  
     InstrumentStatusTextLabel->setFont(font);  
 }  
138    
 // Channel setup dialog.  
 void qsamplerChannelStrip::channelSetup (void)  
 {  
139      qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);      qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);
140      if (pChannelForm) {      if (pChannelForm) {
141          pChannelForm->setup(this);          pChannelForm->setup(m_pChannel);
142          if (pChannelForm->exec()) {          bResult = pChannelForm->exec();
             updateChannelInfo();  
             emit channelChanged(this);  
         }  
143          delete pChannelForm;          delete pChannelForm;
144      }      }
145    
146        if (bResult)
147            emit channelChanged(this);
148    
149        return bResult;
150  }  }
151    
152    
153  // Update whole channel info state.  // Update whole channel info state.
154  void qsamplerChannelStrip::updateChannelInfo (void)  bool qsamplerChannelStrip::updateChannelInfo (void)
155  {  {
156        if (m_pChannel == NULL)
157            return false;
158            
159      // Update strip caption.      // Update strip caption.
160      QString sText = tr("Channel %1").arg(m_iChannelID);      QString sText = m_pChannel->channelName();
161      setCaption(sText);      setCaption(sText);
162      ChannelSetupPushButton->setText(sText);      ChannelSetupPushButton->setText(sText);
163    
164      // Check if we're up and connected.      // Check if we're up and connected.
165      if (client() == NULL)      if (m_pChannel->client() == NULL)
166          return;          return false;
167    
168      // Read channel information.      // Read actual channel information.
169      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;  
     }  
170    
171      // Set some proper display values.      // Set some proper display values.
172        const QString sIndent = " ";
173    
174      // Engine name...      // Engine name...
175      if (m_sEngineName.isEmpty())      if (m_pChannel->engineName().isEmpty())
176          EngineNameTextLabel->setText(tr("(No engine)"));          EngineNameTextLabel->setText(sIndent + tr("(No engine)"));
177      else      else
178          EngineNameTextLabel->setText(m_sEngineName);          EngineNameTextLabel->setText(sIndent + m_pChannel->engineName());
179    
180      // Instrument name...      // Instrument name...
181      if (m_sInstrumentFile.isEmpty())      if (m_pChannel->instrumentFile().isEmpty())
182          InstrumentNameTextLabel->setText(tr("(No instrument)"));          InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));
183      else      else
184          InstrumentNameTextLabel->setText(QString("%1 [%2]")          InstrumentNameTextLabel->setText(sIndent + qsamplerChannel::getInstrumentName(m_pChannel->instrumentFile(), m_pChannel->instrumentNr()));
             .arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr));  
185    
186      // Instrument status...      // Instrument status...
187      if (m_iInstrumentStatus < 0) {      int iInstrumentStatus = m_pChannel->instrumentStatus();
188        if (iInstrumentStatus < 0) {
189          InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);          InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
190          InstrumentStatusTextLabel->setText(tr("ERR%1").arg(m_iInstrumentStatus));          InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
191      } else {      } else {
192          InstrumentStatusTextLabel->setPaletteForegroundColor(m_iInstrumentStatus < 100 ? Qt::yellow : Qt::green);          InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
193          InstrumentStatusTextLabel->setText(QString::number(m_iInstrumentStatus) + "%");          InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
194      }      }
195    
196      // MIDI Port/Channel...      // MIDI Port/Channel...
197      MidiPortChannelTextLabel->setText(QString("%1 / %2")      if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
198          .arg(m_iMidiPort).arg(m_iMidiChannel));          MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
199                else
200            MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1));
201    
202      // And update the both GUI volume elements.      // And update the both GUI volume elements.
203      updateChannelVolume();      return updateChannelVolume();
204  }  }
205    
206    
207  // Do the dirty volume change.  // Do the dirty volume change.
208  void qsamplerChannelStrip::updateChannelVolume (void)  bool qsamplerChannelStrip::updateChannelVolume (void)
209  {  {
210        if (m_pChannel == NULL)
211            return false;
212    
213      // Convert...      // Convert...
214  #ifdef CONFIG_ROUND  #ifdef CONFIG_ROUND
215      int iVolume = (int) ::round(100.0 * m_fVolume);      int iVolume = (int) ::round(100.0 * m_pChannel->volume());
216  #else  #else
217      double fIPart = 0.0;      double fIPart = 0.0;
218      double fFPart = ::modf(100.0 * m_fVolume, &fIPart);      double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
219      int iVolume = (int) fIPart;      int iVolume = (int) fIPart;
220      if (fFPart >= +0.5)      if (fFPart >= +0.5)
221          iVolume++;          iVolume++;
# Line 438  void qsamplerChannelStrip::updateChannel Line 233  void qsamplerChannelStrip::updateChannel
233      VolumeSlider->setValue(iVolume);      VolumeSlider->setValue(iVolume);
234      VolumeSpinBox->setValue(iVolume);      VolumeSpinBox->setValue(iVolume);
235      m_iDirtyChange--;      m_iDirtyChange--;
236        
237        return true;
238  }  }
239    
240    
241  // Update whole channel usage state.  // Update whole channel usage state.
242  void qsamplerChannelStrip::updateChannelUsage (void)  bool qsamplerChannelStrip::updateChannelUsage (void)
243  {  {
244      if (client() == NULL)      if (m_pChannel == NULL)
245          return;          return false;
246        if (m_pChannel->client() == NULL)
247            return false;
248    
249      // Conditionally update whole channel status info.      // Update whole channel status info,
250      if (m_iInstrumentStatus >= 0 && m_iInstrumentStatus < 100)      // if instrument load is still pending...
251        if (m_pChannel->instrumentStatus() < 100) {
252          updateChannelInfo();          updateChannelInfo();
253      // Leave, if we still have an erroneus or incomplete instrument load.          // Check (updated) status again...
254      if (m_iInstrumentStatus < 100)          if (m_pChannel->instrumentStatus() < 100)
255          return;              return false;
256            // Once we get a complete instrument load,
257            // we'll try an implied channel reset...
258            m_pChannel->resetChannel();
259        }
260        
261        // Check again that we're clean.
262        if (m_pChannel->instrumentStatus() < 100)
263            return false;
264    
265      // Get current channel voice count.      // Get current channel voice count.
266      int iVoiceCount  = ::lscp_get_channel_voice_count(client(), m_iChannelID);      int iVoiceCount  = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
267      // Get current stream count.      // Get current stream count.
268      int iStreamCount = ::lscp_get_channel_stream_count(client(), m_iChannelID);      int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
269      // Get current channel buffer fill usage.      // Get current channel buffer fill usage.
270      // As benno has suggested this is the percentage usage      // As benno has suggested this is the percentage usage
271      // of the least filled buffer stream...      // of the least filled buffer stream...
272      int iStreamUsage = 0;      int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
273      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;  
             }  
         }  
     }      
274      // Update the GUI elements...      // Update the GUI elements...
275      StreamUsageProgressBar->setProgress(iStreamUsage);      StreamUsageProgressBar->setProgress(iStreamUsage);
276      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
277        
278        // We're clean.
279        return true;
280  }  }
281    
282    
283  // Volume change slot.  // Volume change slot.
284  void qsamplerChannelStrip::volumeChanged ( int iVolume )  void qsamplerChannelStrip::volumeChanged ( int iVolume )
285  {  {
286        if (m_pChannel == NULL)
287            return;
288    
289      // Avoid recursion.      // Avoid recursion.
290      if (m_iDirtyChange > 0)      if (m_iDirtyChange > 0)
291          return;          return;
# Line 490  void qsamplerChannelStrip::volumeChanged Line 296  void qsamplerChannelStrip::volumeChanged
296          fVolume = 0.0;          fVolume = 0.0;
297    
298      // Update the GUI elements.      // Update the GUI elements.
299      if (setVolume(fVolume)) {      if (m_pChannel->setVolume(fVolume)) {
300          updateChannelVolume();          updateChannelVolume();
301          emit channelChanged(this);          emit channelChanged(this);
302      }      }
303  }  }
304    
305    
 // 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);  
 }  
   
   
306  // Context menu event handler.  // Context menu event handler.
307  void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
308  {  {
309        if (m_pMainForm == NULL)
310            return;
311            
312      // We'll just show up the main form's edit menu.      // We'll just show up the main form's edit menu.
313      m_pMainForm->contextMenuEvent(pEvent);      m_pMainForm->contextMenuEvent(pEvent);
314  }  }
# Line 543  void qsamplerChannelStrip::setMaxVolume Line 325  void qsamplerChannelStrip::setMaxVolume
325    
326    
327  // end of qsamplerChannelStrip.ui.h  // end of qsamplerChannelStrip.ui.h
   

Legend:
Removed from v.152  
changed lines
  Added in v.302

  ViewVC Help
Powered by ViewVC