/[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 261 - (hide annotations) (download) (as text)
Wed Sep 29 07:43:26 2004 UTC (19 years, 6 months ago) by capela
File MIME type: text/x-c++hdr
File size: 14379 byte(s)
Sampler reset info message; asterisk for midi all channels input.

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     // Channel setup dialog.
333 capela 176 void qsamplerChannelStrip::channelSetup ( bool bNew )
334 capela 109 {
335     qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);
336     if (pChannelForm) {
337 capela 176 pChannelForm->setup(this, bNew);
338 capela 109 if (pChannelForm->exec()) {
339     updateChannelInfo();
340     emit channelChanged(this);
341     }
342     delete pChannelForm;
343     }
344     }
345    
346    
347     // Update whole channel info state.
348     void qsamplerChannelStrip::updateChannelInfo (void)
349     {
350     // Update strip caption.
351     QString sText = tr("Channel %1").arg(m_iChannelID);
352     setCaption(sText);
353     ChannelSetupPushButton->setText(sText);
354    
355     // Check if we're up and connected.
356     if (client() == NULL)
357     return;
358    
359     // Read channel information.
360     lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);
361     if (pChannelInfo == NULL) {
362     appendMessagesClient("lscp_get_channel_info");
363 capela 145 appendMessagesError(tr("Could not get channel information.\n\nSorry."));
364 capela 109 } else {
365     // Cache in channel information.
366 capela 145 m_sEngineName = pChannelInfo->engine_name;
367     m_sInstrumentFile = pChannelInfo->instrument_file;
368     m_iInstrumentNr = pChannelInfo->instrument_nr;
369     m_iInstrumentStatus = pChannelInfo->instrument_status;
370     m_iMidiDevice = pChannelInfo->midi_device;
371     m_iMidiPort = pChannelInfo->midi_port;
372     m_iMidiChannel = pChannelInfo->midi_channel;
373     m_iAudioDevice = pChannelInfo->audio_device;
374     m_fVolume = pChannelInfo->volume;
375     // Some sanity checks.
376     if (m_sEngineName == "NONE")
377     m_sEngineName = QString::null;
378     if (m_sInstrumentFile == "NONE")
379     m_sInstrumentFile = QString::null;
380 capela 109 }
381    
382     // Set some proper display values.
383 capela 261 const QString sIndent = " ";
384 capela 109
385     // Engine name...
386     if (m_sEngineName.isEmpty())
387 capela 261 EngineNameTextLabel->setText(sIndent + tr("(No engine)"));
388 capela 109 else
389 capela 261 EngineNameTextLabel->setText(sIndent + m_sEngineName);
390 capela 109
391     // Instrument name...
392     if (m_sInstrumentFile.isEmpty())
393 capela 261 InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));
394 capela 109 else
395 capela 261 InstrumentNameTextLabel->setText(sIndent + QString("%1 [%2]")
396 capela 109 .arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr));
397    
398 capela 145 // Instrument status...
399     if (m_iInstrumentStatus < 0) {
400     InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
401     InstrumentStatusTextLabel->setText(tr("ERR%1").arg(m_iInstrumentStatus));
402     } else {
403     InstrumentStatusTextLabel->setPaletteForegroundColor(m_iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
404     InstrumentStatusTextLabel->setText(QString::number(m_iInstrumentStatus) + "%");
405     }
406    
407 capela 109 // MIDI Port/Channel...
408 capela 261 if (m_iMidiChannel > 0)
409     MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_iMidiPort).arg(m_iMidiChannel));
410     else
411     MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_iMidiPort));
412    
413 capela 109 // And update the both GUI volume elements.
414     updateChannelVolume();
415     }
416    
417    
418     // Do the dirty volume change.
419     void qsamplerChannelStrip::updateChannelVolume (void)
420     {
421     // Convert...
422     #ifdef CONFIG_ROUND
423     int iVolume = (int) ::round(100.0 * m_fVolume);
424     #else
425     double fIPart = 0.0;
426     double fFPart = ::modf(100.0 * m_fVolume, &fIPart);
427     int iVolume = (int) fIPart;
428     if (fFPart >= +0.5)
429     iVolume++;
430     else
431     if (fFPart <= -0.5)
432     iVolume--;
433     #endif
434    
435     // And clip...
436 capela 119 if (iVolume < 0)
437 capela 109 iVolume = 0;
438    
439     // Flag it here, to avoid infinite recursion.
440     m_iDirtyChange++;
441     VolumeSlider->setValue(iVolume);
442     VolumeSpinBox->setValue(iVolume);
443     m_iDirtyChange--;
444     }
445    
446    
447     // Update whole channel usage state.
448     void qsamplerChannelStrip::updateChannelUsage (void)
449     {
450     if (client() == NULL)
451     return;
452    
453 capela 145 // Conditionally update whole channel status info.
454 capela 176 if (m_iInstrumentStatus >= 0 && m_iInstrumentStatus < 100) {
455 capela 145 updateChannelInfo();
456 capela 176 // Once we get a complete instrument load, try a implied reset channel....
457     if (m_iInstrumentStatus == 100) {
458     if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK)
459     appendMessagesClient("lscp_reset_channel");
460 capela 182 else
461     appendMessages(tr("Channel %1 reset.").arg(m_iChannelID));
462 capela 176 }
463     }
464 capela 152 // Leave, if we still have an erroneus or incomplete instrument load.
465     if (m_iInstrumentStatus < 100)
466     return;
467 capela 145
468 capela 109 // Get current channel voice count.
469     int iVoiceCount = ::lscp_get_channel_voice_count(client(), m_iChannelID);
470     // Get current stream count.
471     int iStreamCount = ::lscp_get_channel_stream_count(client(), m_iChannelID);
472     // Get current channel buffer fill usage.
473     // As benno has suggested this is the percentage usage
474     // of the least filled buffer stream...
475 capela 176 int iStreamUsage = ::lscp_get_channel_stream_usage(client(), m_iChannelID);;
476    
477 capela 109 // Update the GUI elements...
478     StreamUsageProgressBar->setProgress(iStreamUsage);
479     StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
480     }
481    
482    
483     // Volume change slot.
484     void qsamplerChannelStrip::volumeChanged ( int iVolume )
485     {
486     // Avoid recursion.
487     if (m_iDirtyChange > 0)
488     return;
489    
490     // Convert and clip.
491     float fVolume = (float) iVolume / 100.0;
492 capela 119 if (fVolume < 0.001)
493 capela 109 fVolume = 0.0;
494    
495     // Update the GUI elements.
496     if (setVolume(fVolume)) {
497     updateChannelVolume();
498     emit channelChanged(this);
499     }
500     }
501    
502    
503     // Redirected messages output methods.
504     void qsamplerChannelStrip::appendMessages( const QString& s )
505     {
506     m_pMainForm->appendMessages(s);
507     }
508    
509     void qsamplerChannelStrip::appendMessagesColor( const QString& s, const QString& c )
510     {
511     m_pMainForm->appendMessagesColor(s, c);
512     }
513    
514     void qsamplerChannelStrip::appendMessagesText( const QString& s )
515     {
516     m_pMainForm->appendMessagesText(s);
517     }
518    
519     void qsamplerChannelStrip::appendMessagesError( const QString& s )
520     {
521     m_pMainForm->appendMessagesError(s);
522     }
523    
524     void qsamplerChannelStrip::appendMessagesClient( const QString& s )
525     {
526     m_pMainForm->appendMessagesClient(s);
527     }
528    
529    
530 capela 118 // Context menu event handler.
531     void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
532     {
533     // We'll just show up the main form's edit menu.
534 capela 127 m_pMainForm->contextMenuEvent(pEvent);
535 capela 118 }
536    
537    
538 capela 119 // Maximum volume slider accessors.
539     void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume )
540     {
541     m_iDirtyChange++;
542     VolumeSlider->setRange(0, iMaxVolume);
543     VolumeSpinBox->setRange(0, iMaxVolume);
544     m_iDirtyChange--;
545     }
546    
547    
548 capela 109 // end of qsamplerChannelStrip.ui.h

  ViewVC Help
Powered by ViewVC