/[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 264 by capela, Wed Sep 29 13:12:45 2004 UTC
# Line 38  Line 38 
38  void qsamplerChannelStrip::init (void)  void qsamplerChannelStrip::init (void)
39  {  {
40      // Initialize locals.      // Initialize locals.
41      m_pMainForm  = NULL;      m_pMainForm    = NULL;
42      m_iChannelID = 0;      m_pChannel     = NULL;
       
 //  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 ( qsamplerMainForm *pMainForm, int iChannelID )
62  {  {
63      m_iDirtyChange = 0;      // Set main form reference.
64      m_pMainForm = pMainForm;      m_pMainForm = pMainForm;
65        
66        // Destroy any previous channel descriptor.
67        if (m_pChannel)
68            delete m_pChannel;
69    
70      setChannelID(iChannelID);      // Create a new one...
71  }      m_pChannel = new qsamplerChannel(pMainForm);
72        // And set appropriate settings.
73        if (m_pChannel) {
74  // The global options settings delegated property.          m_pChannel->setChannelID(iChannelID);
75  qsamplerOptions *qsamplerChannelStrip::options (void)          m_iDirtyChange = 0;
 {  
     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 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)  
 {  
     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;  
   
 //  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)  
 {  
     return m_iMidiChannel;  
 }  
   
 bool qsamplerChannelStrip::setMidiChannel ( int iMidiChannel )  
 {  
     if (client() == NULL)  
         return false;  
   
 //  FIXME: call this when LSCP becomes stable.  
 //  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)  
 {  
     return m_iAudioDevice;  
 }  
   
 bool qsamplerChannelStrip::setAudioDevice ( int iAudioDevice )  
 {  
     if (client() == NULL)  
         return false;  
   
 //  FIXME: call this when LSCP becomes stable.  
 //  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;  
 }  
   
   
 // Audio driver type accessors (DEPRECATED).  
 QString& qsamplerChannelStrip::audioDriver (void)  
 {  
     return m_sAudioDriver;  
 }  
   
 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;  
76      }      }
   
     m_sAudioDriver = sAudioDriver;  
     return true;  
77  }  }
78    
79    // Channel secriptor accessor.
80  // Channel volume accessors.  qsamplerChannel *qsamplerChannelStrip::channel (void)
 float qsamplerChannelStrip::volume (void)  
81  {  {
82      return m_fVolume;      return m_pChannel;
 }  
   
 bool qsamplerChannelStrip::setVolume ( float fVolume )  
 {  
     if (client() == NULL)  
         return false;  
   
     if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {  
         appendMessagesClient("lscp_set_channel_volume");  
         return false;  
     }  
   
     m_fVolume = fVolume;  
     return true;  
83  }  }
84    
85    
# Line 318  QFont qsamplerChannelStrip::displayFont Line 92  QFont qsamplerChannelStrip::displayFont
92  void qsamplerChannelStrip::setDisplayFont ( const QFont & font )  void qsamplerChannelStrip::setDisplayFont ( const QFont & font )
93  {  {
94      EngineNameTextLabel->setFont(font);      EngineNameTextLabel->setFont(font);
     InstrumentNameTextLabel->setFont(font);  
95      MidiPortChannelTextLabel->setFont(font);      MidiPortChannelTextLabel->setFont(font);
96        InstrumentNameTextLabel->setFont(font);
97        InstrumentStatusTextLabel->setFont(font);
98  }  }
99    
100  // Channel setup dialog.  
101    // Channel setup dialog slot.
102  void qsamplerChannelStrip::channelSetup (void)  void qsamplerChannelStrip::channelSetup (void)
103  {  {
104        showChannelSetup(false);
105    }
106    
107    
108    // Channel setup dialog.
109    void qsamplerChannelStrip::showChannelSetup ( bool bNew )
110    {
111      qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);      qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);
112      if (pChannelForm) {      if (pChannelForm) {
113          pChannelForm->setup(this);          pChannelForm->setup(m_pChannel, bNew);
114          if (pChannelForm->exec()) {          if (pChannelForm->exec()) {
115              updateChannelInfo();              updateChannelInfo();
116              emit channelChanged(this);              emit channelChanged(this);
# Line 340  void qsamplerChannelStrip::channelSetup Line 123  void qsamplerChannelStrip::channelSetup
123  // Update whole channel info state.  // Update whole channel info state.
124  void qsamplerChannelStrip::updateChannelInfo (void)  void qsamplerChannelStrip::updateChannelInfo (void)
125  {  {
126        if (m_pChannel == NULL)
127            return;
128            
129      // Update strip caption.      // Update strip caption.
130      QString sText = tr("Channel %1").arg(m_iChannelID);      QString sText = tr("Channel %1").arg(m_pChannel->channelID());
131      setCaption(sText);      setCaption(sText);
132      ChannelSetupPushButton->setText(sText);      ChannelSetupPushButton->setText(sText);
133    
134      // Check if we're up and connected.      // Check if we're up and connected.
135      if (client() == NULL)      if (m_pChannel->client() == NULL)
136          return;          return;
137    
138      // Read channel information.      // Read actual channel information.
139      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_iMidiDevice     = pChannelInfo->midi_device;  
         m_iMidiPort       = pChannelInfo->midi_port;  
         m_iMidiChannel    = pChannelInfo->midi_channel;  
         m_iAudioDevice    = pChannelInfo->audio_device;  
         m_fVolume         = pChannelInfo->volume;  
     }  
140    
141      // Set some proper display values.      // Set some proper display values.
142        const QString sIndent = " ";
143    
144      // Engine name...      // Engine name...
145      if (m_sEngineName.isEmpty())      if (m_pChannel->engineName().isEmpty())
146          EngineNameTextLabel->setText(tr("(No engine)"));          EngineNameTextLabel->setText(sIndent + tr("(No engine)"));
147      else      else
148          EngineNameTextLabel->setText(m_sEngineName);          EngineNameTextLabel->setText(sIndent + m_pChannel->engineName());
149    
150      // Instrument name...      // Instrument name...
151      if (m_sInstrumentFile.isEmpty())      if (m_pChannel->instrumentFile().isEmpty())
152          InstrumentNameTextLabel->setText(tr("(No instrument)"));          InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));
153      else      else
154          InstrumentNameTextLabel->setText(QString("%1 [%2]")          InstrumentNameTextLabel->setText(sIndent + QString("%1 [%2]")
155              .arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr));              .arg(QFileInfo(m_pChannel->instrumentFile()).fileName()).arg(m_pChannel->instrumentNr()));
156    
157        // Instrument status...
158        int iInstrumentStatus = m_pChannel->instrumentStatus();
159        if (iInstrumentStatus < 0) {
160            InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
161            InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
162        } else {
163            InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
164            InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
165        }
166    
167      // MIDI Port/Channel...      // MIDI Port/Channel...
168      MidiPortChannelTextLabel->setText(QString("%1 / %2")      if (m_pChannel->midiChannel() > 0)
169          .arg(m_iMidiPort).arg(m_iMidiChannel));          MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel()));
170                else
171            MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
172    
173      // And update the both GUI volume elements.      // And update the both GUI volume elements.
174      updateChannelVolume();      updateChannelVolume();
175  }  }
# Line 393  void qsamplerChannelStrip::updateChannel Line 178  void qsamplerChannelStrip::updateChannel
178  // Do the dirty volume change.  // Do the dirty volume change.
179  void qsamplerChannelStrip::updateChannelVolume (void)  void qsamplerChannelStrip::updateChannelVolume (void)
180  {  {
181        if (m_pChannel == NULL)
182            return;
183    
184      // Convert...      // Convert...
185  #ifdef CONFIG_ROUND  #ifdef CONFIG_ROUND
186      int iVolume = (int) ::round(100.0 * m_fVolume);      int iVolume = (int) ::round(100.0 * m_pChannel->volume());
187  #else  #else
188      double fIPart = 0.0;      double fIPart = 0.0;
189      double fFPart = ::modf(100.0 * m_fVolume, &fIPart);      double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
190      int iVolume = (int) fIPart;      int iVolume = (int) fIPart;
191      if (fFPart >= +0.5)      if (fFPart >= +0.5)
192          iVolume++;          iVolume++;
# Line 408  void qsamplerChannelStrip::updateChannel Line 196  void qsamplerChannelStrip::updateChannel
196  #endif  #endif
197    
198      // And clip...      // And clip...
199      if (iVolume > 100)      if (iVolume < 0)
         iVolume = 100;  
     else if (iVolume < 0)  
200          iVolume = 0;          iVolume = 0;
201    
202      // Flag it here, to avoid infinite recursion.      // Flag it here, to avoid infinite recursion.
# Line 424  void qsamplerChannelStrip::updateChannel Line 210  void qsamplerChannelStrip::updateChannel
210  // Update whole channel usage state.  // Update whole channel usage state.
211  void qsamplerChannelStrip::updateChannelUsage (void)  void qsamplerChannelStrip::updateChannelUsage (void)
212  {  {
213      if (client() == NULL)      if (m_pChannel == NULL)
214            return;
215        if (m_pChannel->client() == NULL)
216            return;
217    
218        // Conditionally update whole channel status info.
219        if (m_pChannel->instrumentStatus() >= 0 && m_pChannel->instrumentStatus() < 100) {
220            updateChannelInfo();
221            // Once we get a complete instrument load, try a implied reset channel....
222            if (m_pChannel->instrumentStatus() == 100)
223                m_pChannel->resetChannel();
224        }
225        // Leave, if we still have an erroneus or incomplete instrument load.
226        if (m_pChannel->instrumentStatus() < 100)
227          return;          return;
228    
229      // Get current channel voice count.      // Get current channel voice count.
230      int iVoiceCount  = ::lscp_get_channel_voice_count(client(), m_iChannelID);      int iVoiceCount  = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
231      // Get current stream count.      // Get current stream count.
232      int iStreamCount = ::lscp_get_channel_stream_count(client(), m_iChannelID);      int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
233      // Get current channel buffer fill usage.      // Get current channel buffer fill usage.
234      // As benno has suggested this is the percentage usage      // As benno has suggested this is the percentage usage
235      // of the least filled buffer stream...      // of the least filled buffer stream...
236      int iStreamUsage = 0;      int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
237      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;  
             }  
         }  
     }      
238      // Update the GUI elements...      // Update the GUI elements...
239      StreamUsageProgressBar->setProgress(iStreamUsage);      StreamUsageProgressBar->setProgress(iStreamUsage);
240      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));      StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
# Line 453  void qsamplerChannelStrip::updateChannel Line 244  void qsamplerChannelStrip::updateChannel
244  // Volume change slot.  // Volume change slot.
245  void qsamplerChannelStrip::volumeChanged ( int iVolume )  void qsamplerChannelStrip::volumeChanged ( int iVolume )
246  {  {
247        if (m_pChannel == NULL)
248            return;
249    
250      // Avoid recursion.      // Avoid recursion.
251      if (m_iDirtyChange > 0)      if (m_iDirtyChange > 0)
252          return;          return;
253    
254      // Convert and clip.      // Convert and clip.
255      float fVolume = (float) iVolume / 100.0;      float fVolume = (float) iVolume / 100.0;
256      if (fVolume > 1.0)      if (fVolume < 0.001)
         fVolume = 1.0;  
     else if (fVolume < 0.0)  
257          fVolume = 0.0;          fVolume = 0.0;
258    
259      // Update the GUI elements.      // Update the GUI elements.
260      if (setVolume(fVolume)) {      if (m_pChannel->setVolume(fVolume)) {
261          updateChannelVolume();          updateChannelVolume();
262          emit channelChanged(this);          emit channelChanged(this);
263      }      }
264  }  }
265    
266    
267  // Redirected messages output methods.  // Context menu event handler.
268  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 )  
269  {  {
270      m_pMainForm->appendMessagesClient(s);      if (m_pMainForm == NULL)
271            return;
272            
273        // We'll just show up the main form's edit menu.
274        m_pMainForm->contextMenuEvent(pEvent);
275  }  }
276    
277    
278  // Context menu event handler.  // Maximum volume slider accessors.
279  void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume )
280  {  {
281      // We'll just show up the main form's edit menu.      m_iDirtyChange++;
282      m_pMainForm->stabilizeForm();      VolumeSlider->setRange(0, iMaxVolume);
283      m_pMainForm->editMenu->exec(pEvent->globalPos());      VolumeSpinBox->setRange(0, iMaxVolume);
284        m_iDirtyChange--;
285  }  }
286    
287    
288  // end of qsamplerChannelStrip.ui.h  // end of qsamplerChannelStrip.ui.h
   

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

  ViewVC Help
Powered by ViewVC