/[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 176 by capela, Tue Jul 6 10:54:45 2004 UTC revision 267 by capela, Wed Oct 6 15:42:59 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) {
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;  
     }  
   
     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;  
77      }      }
78        
79      m_iMidiPort = iMidiPort;      // Stabilize this around.
80      return true;      updateChannelInfo();
 }  
   
   
 // MIDI channel accessor.  
 int qsamplerChannelStrip::midiChannel (void)  
 {  
     return m_iMidiChannel;  
81  }  }
82    
83  bool qsamplerChannelStrip::setMidiChannel ( int iMidiChannel )  // Channel secriptor accessor.
84    qsamplerChannel *qsamplerChannelStrip::channel (void)
85  {  {
86      if (client() == NULL)      return m_pChannel;
         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;  
87  }  }
88    
89    
90  // Audio device accessor.  // Messages view font accessors.
91  int qsamplerChannelStrip::audioDevice (void)  QFont qsamplerChannelStrip::displayFont (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 )
 {  
     return m_sAudioDriver;  
 }  
   
 bool qsamplerChannelStrip::setAudioDriver ( const QString& sAudioDriver )  
107  {  {
108      if (client() == NULL)      QPixmap pm;
109          return false;      if (bDisplayEffect)
110            pm = QPixmap::fromMimeSource("displaybg1.png");
111      if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {      setDisplayBackground(pm);
         appendMessagesClient("lscp_set_channel_audio_type");  
         return false;  
     }  
   
     m_sAudioDriver = sAudioDriver;  
     return true;  
112  }  }
113    
114    
115  // Channel volume accessors.  // Update main display background pixmap.
116  float qsamplerChannelStrip::volume (void)  void qsamplerChannelStrip::setDisplayBackground ( const QPixmap& pm )
117  {  {
118      return m_fVolume;      // Set the main origin...
119  }      ChannelInfoFrame->setPaletteBackgroundPixmap(pm);
120    
121  bool qsamplerChannelStrip::setVolume ( float fVolume )      // Iterate for every child text label...
122  {      QObjectList *pList = ChannelInfoFrame->queryList("QLabel");
123      if (client() == NULL)      if (pList) {
124          return false;          for (QLabel *pLabel = (QLabel *) pList->first(); pLabel; pLabel = (QLabel *) pList->next())
125                pLabel->setPaletteBackgroundPixmap(pm);
126      if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {          delete pList;
         appendMessagesClient("lscp_set_channel_volume");  
         return false;  
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)  void qsamplerChannelStrip::channelSetup (void)
136  {  {
137      return EngineNameTextLabel->font();      showChannelSetup(false);
138  }  }
139    
 void qsamplerChannelStrip::setDisplayFont ( const QFont & font )  
 {  
     EngineNameTextLabel->setFont(font);  
     MidiPortChannelTextLabel->setFont(font);  
     InstrumentNameTextLabel->setFont(font);  
     InstrumentStatusTextLabel->setFont(font);  
 }  
140    
141  // Channel setup dialog.  // Channel setup dialog.
142  void qsamplerChannelStrip::channelSetup ( bool bNew )  void qsamplerChannelStrip::showChannelSetup ( bool bNew )
143  {  {
144      qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);      qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);
145      if (pChannelForm) {      if (pChannelForm) {
146          pChannelForm->setup(this, bNew);          pChannelForm->setup(m_pChannel, bNew);
147          if (pChannelForm->exec()) {          if (pChannelForm->exec()) {
148              updateChannelInfo();              updateChannelInfo();
149              emit channelChanged(this);              emit channelChanged(this);
# Line 347  void qsamplerChannelStrip::channelSetup Line 156  void qsamplerChannelStrip::channelSetup
156  // Update whole channel info state.  // Update whole channel info state.
157  void qsamplerChannelStrip::updateChannelInfo (void)  void qsamplerChannelStrip::updateChannelInfo (void)
158  {  {
159        if (m_pChannel == NULL)
160            return;
161            
162      // Update strip caption.      // Update strip caption.
163      QString sText = tr("Channel %1").arg(m_iChannelID);      QString sText = tr("Channel %1").arg(m_pChannel->channelID());
164      setCaption(sText);      setCaption(sText);
165      ChannelSetupPushButton->setText(sText);      ChannelSetupPushButton->setText(sText);
166    
167      // Check if we're up and connected.      // Check if we're up and connected.
168      if (client() == NULL)      if (m_pChannel->client() == NULL)
169          return;          return;
170    
171      // Read channel information.      // Read actual channel information.
172      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;  
     }  
173    
174      // Set some proper display values.      // Set some proper display values.
175        const QString sIndent = " ";
176    
177      // Engine name...      // Engine name...
178      if (m_sEngineName.isEmpty())      if (m_pChannel->engineName().isEmpty())
179          EngineNameTextLabel->setText(tr("(No engine)"));          EngineNameTextLabel->setText(sIndent + tr("(No engine)"));
180      else      else
181          EngineNameTextLabel->setText(m_sEngineName);          EngineNameTextLabel->setText(sIndent + m_pChannel->engineName());
182    
183      // Instrument name...      // Instrument name...
184      if (m_sInstrumentFile.isEmpty())      if (m_pChannel->instrumentFile().isEmpty())
185          InstrumentNameTextLabel->setText(tr("(No instrument)"));          InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));
186      else      else
187          InstrumentNameTextLabel->setText(QString("%1 [%2]")          InstrumentNameTextLabel->setText(sIndent + QString("%1 [%2]")
188              .arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr));              .arg(QFileInfo(m_pChannel->instrumentFile()).fileName()).arg(m_pChannel->instrumentNr()));
189    
190      // Instrument status...      // Instrument status...
191      if (m_iInstrumentStatus < 0) {      int iInstrumentStatus = m_pChannel->instrumentStatus();
192        if (iInstrumentStatus < 0) {
193          InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);          InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
194          InstrumentStatusTextLabel->setText(tr("ERR%1").arg(m_iInstrumentStatus));          InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
195      } else {      } else {
196          InstrumentStatusTextLabel->setPaletteForegroundColor(m_iInstrumentStatus < 100 ? Qt::yellow : Qt::green);          InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
197          InstrumentStatusTextLabel->setText(QString::number(m_iInstrumentStatus) + "%");          InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
198      }      }
199    
200      // MIDI Port/Channel...      // MIDI Port/Channel...
201      MidiPortChannelTextLabel->setText(QString("%1 / %2")      if (m_pChannel->midiChannel() > 0)
202          .arg(m_iMidiPort).arg(m_iMidiChannel));          MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel()));
203                else
204            MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
205    
206      // And update the both GUI volume elements.      // And update the both GUI volume elements.
207      updateChannelVolume();      updateChannelVolume();
208  }  }
# Line 415  void qsamplerChannelStrip::updateChannel Line 211  void qsamplerChannelStrip::updateChannel
211  // Do the dirty volume change.  // Do the dirty volume change.
212  void qsamplerChannelStrip::updateChannelVolume (void)  void qsamplerChannelStrip::updateChannelVolume (void)
213  {  {
214        if (m_pChannel == NULL)
215            return;
216    
217      // Convert...      // Convert...
218  #ifdef CONFIG_ROUND  #ifdef CONFIG_ROUND
219      int iVolume = (int) ::round(100.0 * m_fVolume);      int iVolume = (int) ::round(100.0 * m_pChannel->volume());
220  #else  #else
221      double fIPart = 0.0;      double fIPart = 0.0;
222      double fFPart = ::modf(100.0 * m_fVolume, &fIPart);      double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
223      int iVolume = (int) fIPart;      int iVolume = (int) fIPart;
224      if (fFPart >= +0.5)      if (fFPart >= +0.5)
225          iVolume++;          iVolume++;
# Line 444  void qsamplerChannelStrip::updateChannel Line 243  void qsamplerChannelStrip::updateChannel
243  // Update whole channel usage state.  // Update whole channel usage state.
244  void qsamplerChannelStrip::updateChannelUsage (void)  void qsamplerChannelStrip::updateChannelUsage (void)
245  {  {
246      if (client() == NULL)      if (m_pChannel == NULL)
247            return;
248        if (m_pChannel->client() == NULL)
249          return;          return;
250    
251      // Conditionally update whole channel status info.      // Conditionally update whole channel status info.
252      if (m_iInstrumentStatus >= 0 && m_iInstrumentStatus < 100) {      if (m_pChannel->instrumentStatus() >= 0 && m_pChannel->instrumentStatus() < 100) {
253          updateChannelInfo();          updateChannelInfo();
254          // Once we get a complete instrument load, try a implied reset channel....          // Once we get a complete instrument load, try a implied reset channel....
255          if (m_iInstrumentStatus == 100) {          if (m_pChannel->instrumentStatus() == 100)
256              if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK)              m_pChannel->resetChannel();
                 appendMessagesClient("lscp_reset_channel");  
         }  
257      }      }
258      // Leave, if we still have an erroneus or incomplete instrument load.      // Leave, if we still have an erroneus or incomplete instrument load.
259      if (m_iInstrumentStatus < 100)      if (m_pChannel->instrumentStatus() < 100)
260          return;          return;
261    
262      // Get current channel voice count.      // Get current channel voice count.
263      int iVoiceCount  = ::lscp_get_channel_voice_count(client(), m_iChannelID);      int iVoiceCount  = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
264      // Get current stream count.      // Get current stream count.
265      int iStreamCount = ::lscp_get_channel_stream_count(client(), m_iChannelID);      int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
266      // Get current channel buffer fill usage.      // Get current channel buffer fill usage.
267      // As benno has suggested this is the percentage usage      // As benno has suggested this is the percentage usage
268      // of the least filled buffer stream...      // of the least filled buffer stream...
269      int iStreamUsage = ::lscp_get_channel_stream_usage(client(), m_iChannelID);;      int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
270    
271      // Update the GUI elements...      // Update the GUI elements...
272      StreamUsageProgressBar->setProgress(iStreamUsage);      StreamUsageProgressBar->setProgress(iStreamUsage);
# Line 478  void qsamplerChannelStrip::updateChannel Line 277  void qsamplerChannelStrip::updateChannel
277  // Volume change slot.  // Volume change slot.
278  void qsamplerChannelStrip::volumeChanged ( int iVolume )  void qsamplerChannelStrip::volumeChanged ( int iVolume )
279  {  {
280        if (m_pChannel == NULL)
281            return;
282    
283      // Avoid recursion.      // Avoid recursion.
284      if (m_iDirtyChange > 0)      if (m_iDirtyChange > 0)
285          return;          return;
# Line 488  void qsamplerChannelStrip::volumeChanged Line 290  void qsamplerChannelStrip::volumeChanged
290          fVolume = 0.0;          fVolume = 0.0;
291    
292      // Update the GUI elements.      // Update the GUI elements.
293      if (setVolume(fVolume)) {      if (m_pChannel->setVolume(fVolume)) {
294          updateChannelVolume();          updateChannelVolume();
295          emit channelChanged(this);          emit channelChanged(this);
296      }      }
297  }  }
298    
299    
 // 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);  
 }  
   
   
300  // Context menu event handler.  // Context menu event handler.
301  void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
302  {  {
303        if (m_pMainForm == NULL)
304            return;
305            
306      // We'll just show up the main form's edit menu.      // We'll just show up the main form's edit menu.
307      m_pMainForm->contextMenuEvent(pEvent);      m_pMainForm->contextMenuEvent(pEvent);
308  }  }
# Line 541  void qsamplerChannelStrip::setMaxVolume Line 319  void qsamplerChannelStrip::setMaxVolume
319    
320    
321  // end of qsamplerChannelStrip.ui.h  // end of qsamplerChannelStrip.ui.h
   

Legend:
Removed from v.176  
changed lines
  Added in v.267

  ViewVC Help
Powered by ViewVC