/[svn]/qsampler/trunk/src/qsamplerChannelStrip.ui.h
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerChannelStrip.ui.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 263 - (hide annotations) (download) (as text)
Wed Sep 29 09:01:35 2004 UTC (19 years, 6 months ago) by capela
File MIME type: text/x-c++hdr
File size: 14496 byte(s)
Channel strip setup dialog invokation fix.

1 capela 109 // qsamplerChannelStrip.ui.h
2     //
3     // ui.h extension file, included from the uic-generated form implementation.
4     /****************************************************************************
5     Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.
6    
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20    
21     *****************************************************************************/
22    
23     #include <qvalidator.h>
24     #include <qmessagebox.h>
25     #include <qfileinfo.h>
26     #include <qtooltip.h>
27 capela 118 #include <qpopupmenu.h>
28 capela 109
29     #include <math.h>
30    
31     #include "qsamplerMainForm.h"
32     #include "qsamplerChannelForm.h"
33    
34     #include "config.h"
35    
36    
37     // Kind of constructor.
38     void qsamplerChannelStrip::init (void)
39     {
40     // Initialize locals.
41     m_pMainForm = NULL;
42     m_iChannelID = 0;
43    
44 capela 145 // m_sEngineName = tr("(No engine)");
45     // m_sInstrumentFile = tr("(No instrument)");
46     m_iInstrumentNr = -1;
47     m_iInstrumentStatus = -1;
48     m_sMidiDriver = "Alsa"; // DEPRECATED.
49     m_iMidiDevice = -1;
50     m_iMidiPort = -1;
51     m_iMidiChannel = -1;
52     m_sAudioDriver = "Alsa"; // DEPRECATED.
53     m_iAudioDevice = -1;
54     m_fVolume = 0.0;
55 capela 109
56     m_iDirtyChange = 0;
57    
58     // Try to restore normal window positioning.
59     adjustSize();
60     }
61    
62    
63     // Kind of destructor.
64     void qsamplerChannelStrip::destroy (void)
65     {
66     }
67    
68    
69     // Channel strip setup formal initializer.
70     void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID )
71     {
72     m_iDirtyChange = 0;
73     m_pMainForm = pMainForm;
74    
75     setChannelID(iChannelID);
76     }
77    
78    
79     // The global options settings delegated property.
80     qsamplerOptions *qsamplerChannelStrip::options (void)
81     {
82     if (m_pMainForm == NULL)
83     return NULL;
84    
85     return m_pMainForm->options();
86     }
87    
88    
89     // The client descriptor delegated property.
90     lscp_client_t *qsamplerChannelStrip::client (void)
91     {
92     if (m_pMainForm == NULL)
93     return NULL;
94    
95     return m_pMainForm->client();
96     }
97    
98    
99     // Channel-ID (aka Sammpler-Channel) accessors.
100     int qsamplerChannelStrip::channelID (void)
101     {
102     return m_iChannelID;
103     }
104    
105     void qsamplerChannelStrip::setChannelID ( int iChannelID )
106     {
107     m_iChannelID = iChannelID;
108    
109     updateChannelInfo();
110     }
111    
112    
113     // Engine name accessors.
114     QString& qsamplerChannelStrip::engineName (void)
115     {
116     return m_sEngineName;
117     }
118    
119     bool qsamplerChannelStrip::loadEngine ( const QString& sEngineName )
120     {
121     if (client() == NULL)
122     return false;
123    
124     if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
125     appendMessagesClient("lscp_load_engine");
126     return false;
127     }
128    
129     m_sEngineName = sEngineName;
130     return true;
131     }
132    
133    
134 capela 145 // Instrument filename accessor.
135 capela 109 QString& qsamplerChannelStrip::instrumentFile (void)
136     {
137     return m_sInstrumentFile;
138     }
139    
140 capela 145 // Instrument index accessor.
141 capela 109 int qsamplerChannelStrip::instrumentNr (void)
142     {
143     return m_iInstrumentNr;
144     }
145    
146 capela 145 // Instrument status accessor.
147     int qsamplerChannelStrip::instrumentStatus (void)
148     {
149     return m_iInstrumentStatus;
150     }
151    
152     // Instrument file loader.
153 capela 109 bool qsamplerChannelStrip::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
154     {
155     if (client() == NULL)
156     return false;
157    
158 capela 145 if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {
159 capela 109 appendMessagesClient("lscp_load_instrument");
160     return false;
161     }
162    
163     m_sInstrumentFile = sInstrumentFile;
164     m_iInstrumentNr = iInstrumentNr;
165 capela 145 m_iInstrumentStatus = 0;
166    
167 capela 109 return true;
168     }
169    
170    
171     // MIDI driver type accessors (DEPRECATED).
172     QString& qsamplerChannelStrip::midiDriver (void)
173     {
174     return m_sMidiDriver;
175     }
176    
177     bool qsamplerChannelStrip::setMidiDriver ( const QString& sMidiDriver )
178     {
179     if (client() == NULL)
180     return false;
181    
182     if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
183     appendMessagesClient("lscp_set_channel_midi_type");
184     return false;
185     }
186    
187     m_sMidiDriver = sMidiDriver;
188     return true;
189     }
190    
191    
192     // MIDI device accessors.
193     int qsamplerChannelStrip::midiDevice (void)
194     {
195     return m_iMidiDevice;
196     }
197    
198     bool qsamplerChannelStrip::setMidiDevice ( int iMidiDevice )
199     {
200     if (client() == NULL)
201     return false;
202    
203 capela 145 if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
204     appendMessagesClient("lscp_set_channel_midi_device");
205     return false;
206     }
207 capela 109
208     m_iMidiDevice = iMidiDevice;
209     return true;
210     }
211    
212    
213     // MIDI port number accessor.
214     int qsamplerChannelStrip::midiPort (void)
215     {
216     return m_iMidiPort;
217     }
218    
219     bool qsamplerChannelStrip::setMidiPort ( int iMidiPort )
220     {
221     if (client() == NULL)
222     return false;
223    
224 capela 145 if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {
225     appendMessagesClient("lscp_set_channel_midi_port");
226     return false;
227     }
228 capela 109
229     m_iMidiPort = iMidiPort;
230     return true;
231     }
232    
233    
234     // MIDI channel accessor.
235     int qsamplerChannelStrip::midiChannel (void)
236     {
237     return m_iMidiChannel;
238     }
239    
240     bool qsamplerChannelStrip::setMidiChannel ( int iMidiChannel )
241     {
242     if (client() == NULL)
243     return false;
244    
245 capela 145 if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
246     appendMessagesClient("lscp_set_channel_midi_channel");
247     return false;
248     }
249 capela 109
250     m_iMidiChannel = iMidiChannel;
251     return true;
252     }
253    
254    
255     // Audio device accessor.
256     int qsamplerChannelStrip::audioDevice (void)
257     {
258     return m_iAudioDevice;
259     }
260    
261     bool qsamplerChannelStrip::setAudioDevice ( int iAudioDevice )
262     {
263     if (client() == NULL)
264     return false;
265    
266 capela 145 if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
267     appendMessagesClient("lscp_set_channel_audio_device");
268     return false;
269     }
270 capela 109
271     m_iAudioDevice = iAudioDevice;
272     return true;
273     }
274    
275    
276     // Audio driver type accessors (DEPRECATED).
277     QString& qsamplerChannelStrip::audioDriver (void)
278     {
279     return m_sAudioDriver;
280     }
281    
282     bool qsamplerChannelStrip::setAudioDriver ( const QString& sAudioDriver )
283     {
284     if (client() == NULL)
285     return false;
286    
287     if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
288     appendMessagesClient("lscp_set_channel_audio_type");
289     return false;
290     }
291    
292     m_sAudioDriver = sAudioDriver;
293     return true;
294     }
295    
296    
297     // Channel volume accessors.
298     float qsamplerChannelStrip::volume (void)
299     {
300     return m_fVolume;
301     }
302    
303     bool qsamplerChannelStrip::setVolume ( float fVolume )
304     {
305     if (client() == NULL)
306     return false;
307    
308     if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {
309     appendMessagesClient("lscp_set_channel_volume");
310     return false;
311     }
312    
313     m_fVolume = fVolume;
314     return true;
315     }
316    
317    
318     // Messages view font accessors.
319     QFont qsamplerChannelStrip::displayFont (void)
320     {
321     return EngineNameTextLabel->font();
322     }
323    
324     void qsamplerChannelStrip::setDisplayFont ( const QFont & font )
325     {
326     EngineNameTextLabel->setFont(font);
327 capela 145 MidiPortChannelTextLabel->setFont(font);
328 capela 109 InstrumentNameTextLabel->setFont(font);
329 capela 145 InstrumentStatusTextLabel->setFont(font);
330 capela 109 }
331    
332 capela 263
333     // Channel setup dialog slot.
334     void qsamplerChannelStrip::channelSetup (void)
335     {
336     showChannelSetup(false);
337     }
338    
339    
340 capela 109 // Channel setup dialog.
341 capela 263 void qsamplerChannelStrip::showChannelSetup ( bool bNew )
342 capela 109 {
343     qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);
344     if (pChannelForm) {
345 capela 176 pChannelForm->setup(this, bNew);
346 capela 109 if (pChannelForm->exec()) {
347     updateChannelInfo();
348     emit channelChanged(this);
349     }
350     delete pChannelForm;
351     }
352     }
353    
354    
355     // Update whole channel info state.
356     void qsamplerChannelStrip::updateChannelInfo (void)
357     {
358     // Update strip caption.
359     QString sText = tr("Channel %1").arg(m_iChannelID);
360     setCaption(sText);
361     ChannelSetupPushButton->setText(sText);
362    
363     // Check if we're up and connected.
364     if (client() == NULL)
365     return;
366    
367     // Read channel information.
368     lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);
369     if (pChannelInfo == NULL) {
370     appendMessagesClient("lscp_get_channel_info");
371 capela 145 appendMessagesError(tr("Could not get channel information.\n\nSorry."));
372 capela 109 } else {
373     // Cache in channel information.
374 capela 145 m_sEngineName = pChannelInfo->engine_name;
375     m_sInstrumentFile = pChannelInfo->instrument_file;
376     m_iInstrumentNr = pChannelInfo->instrument_nr;
377     m_iInstrumentStatus = pChannelInfo->instrument_status;
378     m_iMidiDevice = pChannelInfo->midi_device;
379     m_iMidiPort = pChannelInfo->midi_port;
380     m_iMidiChannel = pChannelInfo->midi_channel;
381     m_iAudioDevice = pChannelInfo->audio_device;
382     m_fVolume = pChannelInfo->volume;
383     // Some sanity checks.
384     if (m_sEngineName == "NONE")
385     m_sEngineName = QString::null;
386     if (m_sInstrumentFile == "NONE")
387     m_sInstrumentFile = QString::null;
388 capela 109 }
389    
390     // Set some proper display values.
391 capela 261 const QString sIndent = " ";
392 capela 109
393     // Engine name...
394     if (m_sEngineName.isEmpty())
395 capela 261 EngineNameTextLabel->setText(sIndent + tr("(No engine)"));
396 capela 109 else
397 capela 261 EngineNameTextLabel->setText(sIndent + m_sEngineName);
398 capela 109
399     // Instrument name...
400     if (m_sInstrumentFile.isEmpty())
401 capela 261 InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));
402 capela 109 else
403 capela 261 InstrumentNameTextLabel->setText(sIndent + QString("%1 [%2]")
404 capela 109 .arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr));
405    
406 capela 145 // Instrument status...
407     if (m_iInstrumentStatus < 0) {
408     InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
409     InstrumentStatusTextLabel->setText(tr("ERR%1").arg(m_iInstrumentStatus));
410     } else {
411     InstrumentStatusTextLabel->setPaletteForegroundColor(m_iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
412     InstrumentStatusTextLabel->setText(QString::number(m_iInstrumentStatus) + "%");
413     }
414    
415 capela 109 // MIDI Port/Channel...
416 capela 261 if (m_iMidiChannel > 0)
417     MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_iMidiPort).arg(m_iMidiChannel));
418     else
419     MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_iMidiPort));
420    
421 capela 109 // And update the both GUI volume elements.
422     updateChannelVolume();
423     }
424    
425    
426     // Do the dirty volume change.
427     void qsamplerChannelStrip::updateChannelVolume (void)
428     {
429     // Convert...
430     #ifdef CONFIG_ROUND
431     int iVolume = (int) ::round(100.0 * m_fVolume);
432     #else
433     double fIPart = 0.0;
434     double fFPart = ::modf(100.0 * m_fVolume, &fIPart);
435     int iVolume = (int) fIPart;
436     if (fFPart >= +0.5)
437     iVolume++;
438     else
439     if (fFPart <= -0.5)
440     iVolume--;
441     #endif
442    
443     // And clip...
444 capela 119 if (iVolume < 0)
445 capela 109 iVolume = 0;
446    
447     // Flag it here, to avoid infinite recursion.
448     m_iDirtyChange++;
449     VolumeSlider->setValue(iVolume);
450     VolumeSpinBox->setValue(iVolume);
451     m_iDirtyChange--;
452     }
453    
454    
455     // Update whole channel usage state.
456     void qsamplerChannelStrip::updateChannelUsage (void)
457     {
458     if (client() == NULL)
459     return;
460    
461 capela 145 // Conditionally update whole channel status info.
462 capela 176 if (m_iInstrumentStatus >= 0 && m_iInstrumentStatus < 100) {
463 capela 145 updateChannelInfo();
464 capela 176 // Once we get a complete instrument load, try a implied reset channel....
465     if (m_iInstrumentStatus == 100) {
466     if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK)
467     appendMessagesClient("lscp_reset_channel");
468 capela 182 else
469     appendMessages(tr("Channel %1 reset.").arg(m_iChannelID));
470 capela 176 }
471     }
472 capela 152 // Leave, if we still have an erroneus or incomplete instrument load.
473     if (m_iInstrumentStatus < 100)
474     return;
475 capela 145
476 capela 109 // Get current channel voice count.
477     int iVoiceCount = ::lscp_get_channel_voice_count(client(), m_iChannelID);
478     // Get current stream count.
479     int iStreamCount = ::lscp_get_channel_stream_count(client(), m_iChannelID);
480     // Get current channel buffer fill usage.
481     // As benno has suggested this is the percentage usage
482     // of the least filled buffer stream...
483 capela 176 int iStreamUsage = ::lscp_get_channel_stream_usage(client(), m_iChannelID);;
484    
485 capela 109 // Update the GUI elements...
486     StreamUsageProgressBar->setProgress(iStreamUsage);
487     StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
488     }
489    
490    
491     // Volume change slot.
492     void qsamplerChannelStrip::volumeChanged ( int iVolume )
493     {
494     // Avoid recursion.
495     if (m_iDirtyChange > 0)
496     return;
497    
498     // Convert and clip.
499     float fVolume = (float) iVolume / 100.0;
500 capela 119 if (fVolume < 0.001)
501 capela 109 fVolume = 0.0;
502    
503     // Update the GUI elements.
504     if (setVolume(fVolume)) {
505     updateChannelVolume();
506     emit channelChanged(this);
507     }
508     }
509    
510    
511     // Redirected messages output methods.
512     void qsamplerChannelStrip::appendMessages( const QString& s )
513     {
514     m_pMainForm->appendMessages(s);
515     }
516    
517     void qsamplerChannelStrip::appendMessagesColor( const QString& s, const QString& c )
518     {
519     m_pMainForm->appendMessagesColor(s, c);
520     }
521    
522     void qsamplerChannelStrip::appendMessagesText( const QString& s )
523     {
524     m_pMainForm->appendMessagesText(s);
525     }
526    
527     void qsamplerChannelStrip::appendMessagesError( const QString& s )
528     {
529     m_pMainForm->appendMessagesError(s);
530     }
531    
532     void qsamplerChannelStrip::appendMessagesClient( const QString& s )
533     {
534     m_pMainForm->appendMessagesClient(s);
535     }
536    
537    
538 capela 118 // Context menu event handler.
539     void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
540     {
541     // We'll just show up the main form's edit menu.
542 capela 127 m_pMainForm->contextMenuEvent(pEvent);
543 capela 118 }
544    
545    
546 capela 119 // Maximum volume slider accessors.
547     void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume )
548     {
549     m_iDirtyChange++;
550     VolumeSlider->setRange(0, iMaxVolume);
551     VolumeSpinBox->setRange(0, iMaxVolume);
552     m_iDirtyChange--;
553     }
554    
555    
556 capela 109 // end of qsamplerChannelStrip.ui.h

  ViewVC Help
Powered by ViewVC