/[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 264 - (hide annotations) (download) (as text)
Wed Sep 29 13:12:45 2004 UTC (19 years, 6 months ago) by capela
File MIME type: text/x-c++hdr
File size: 8240 byte(s)
Initial rewrite of sampler channel strips internal control structures.

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 capela 264 m_pMainForm = NULL;
42     m_pChannel = NULL;
43 capela 109 m_iDirtyChange = 0;
44    
45     // Try to restore normal window positioning.
46     adjustSize();
47     }
48    
49    
50     // Kind of destructor.
51     void qsamplerChannelStrip::destroy (void)
52     {
53 capela 264 // Destroy existing channel descriptor.
54     if (m_pChannel)
55     delete m_pChannel;
56     m_pChannel = NULL;
57 capela 109 }
58    
59    
60     // Channel strip setup formal initializer.
61     void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID )
62     {
63 capela 264 // Set main form reference.
64 capela 109 m_pMainForm = pMainForm;
65 capela 145
66 capela 264 // Destroy any previous channel descriptor.
67     if (m_pChannel)
68     delete m_pChannel;
69 capela 109
70 capela 264 // Create a new one...
71     m_pChannel = new qsamplerChannel(pMainForm);
72     // And set appropriate settings.
73     if (m_pChannel) {
74     m_pChannel->setChannelID(iChannelID);
75     m_iDirtyChange = 0;
76 capela 109 }
77     }
78    
79 capela 264 // Channel secriptor accessor.
80     qsamplerChannel *qsamplerChannelStrip::channel (void)
81 capela 109 {
82 capela 264 return m_pChannel;
83 capela 109 }
84    
85    
86     // Messages view font accessors.
87     QFont qsamplerChannelStrip::displayFont (void)
88     {
89     return EngineNameTextLabel->font();
90     }
91    
92     void qsamplerChannelStrip::setDisplayFont ( const QFont & font )
93     {
94     EngineNameTextLabel->setFont(font);
95 capela 145 MidiPortChannelTextLabel->setFont(font);
96 capela 109 InstrumentNameTextLabel->setFont(font);
97 capela 145 InstrumentStatusTextLabel->setFont(font);
98 capela 109 }
99    
100 capela 263
101     // Channel setup dialog slot.
102     void qsamplerChannelStrip::channelSetup (void)
103     {
104     showChannelSetup(false);
105     }
106    
107    
108 capela 109 // Channel setup dialog.
109 capela 263 void qsamplerChannelStrip::showChannelSetup ( bool bNew )
110 capela 109 {
111     qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);
112     if (pChannelForm) {
113 capela 264 pChannelForm->setup(m_pChannel, bNew);
114 capela 109 if (pChannelForm->exec()) {
115     updateChannelInfo();
116     emit channelChanged(this);
117     }
118     delete pChannelForm;
119     }
120     }
121    
122    
123     // Update whole channel info state.
124     void qsamplerChannelStrip::updateChannelInfo (void)
125     {
126 capela 264 if (m_pChannel == NULL)
127     return;
128    
129 capela 109 // Update strip caption.
130 capela 264 QString sText = tr("Channel %1").arg(m_pChannel->channelID());
131 capela 109 setCaption(sText);
132     ChannelSetupPushButton->setText(sText);
133    
134     // Check if we're up and connected.
135 capela 264 if (m_pChannel->client() == NULL)
136 capela 109 return;
137    
138 capela 264 // Read actual channel information.
139     m_pChannel->updateChannelInfo();
140 capela 109
141     // Set some proper display values.
142 capela 261 const QString sIndent = " ";
143 capela 109
144     // Engine name...
145 capela 264 if (m_pChannel->engineName().isEmpty())
146 capela 261 EngineNameTextLabel->setText(sIndent + tr("(No engine)"));
147 capela 109 else
148 capela 264 EngineNameTextLabel->setText(sIndent + m_pChannel->engineName());
149 capela 109
150     // Instrument name...
151 capela 264 if (m_pChannel->instrumentFile().isEmpty())
152 capela 261 InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));
153 capela 109 else
154 capela 261 InstrumentNameTextLabel->setText(sIndent + QString("%1 [%2]")
155 capela 264 .arg(QFileInfo(m_pChannel->instrumentFile()).fileName()).arg(m_pChannel->instrumentNr()));
156 capela 109
157 capela 145 // Instrument status...
158 capela 264 int iInstrumentStatus = m_pChannel->instrumentStatus();
159     if (iInstrumentStatus < 0) {
160 capela 145 InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
161 capela 264 InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
162 capela 145 } else {
163 capela 264 InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
164     InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
165 capela 145 }
166    
167 capela 109 // MIDI Port/Channel...
168 capela 264 if (m_pChannel->midiChannel() > 0)
169     MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel()));
170 capela 261 else
171 capela 264 MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
172 capela 261
173 capela 109 // And update the both GUI volume elements.
174     updateChannelVolume();
175     }
176    
177    
178     // Do the dirty volume change.
179     void qsamplerChannelStrip::updateChannelVolume (void)
180     {
181 capela 264 if (m_pChannel == NULL)
182     return;
183    
184 capela 109 // Convert...
185     #ifdef CONFIG_ROUND
186 capela 264 int iVolume = (int) ::round(100.0 * m_pChannel->volume());
187 capela 109 #else
188     double fIPart = 0.0;
189 capela 264 double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
190 capela 109 int iVolume = (int) fIPart;
191     if (fFPart >= +0.5)
192     iVolume++;
193     else
194     if (fFPart <= -0.5)
195     iVolume--;
196     #endif
197    
198     // And clip...
199 capela 119 if (iVolume < 0)
200 capela 109 iVolume = 0;
201    
202     // Flag it here, to avoid infinite recursion.
203     m_iDirtyChange++;
204     VolumeSlider->setValue(iVolume);
205     VolumeSpinBox->setValue(iVolume);
206     m_iDirtyChange--;
207     }
208    
209    
210     // Update whole channel usage state.
211     void qsamplerChannelStrip::updateChannelUsage (void)
212     {
213 capela 264 if (m_pChannel == NULL)
214 capela 109 return;
215 capela 264 if (m_pChannel->client() == NULL)
216     return;
217 capela 109
218 capela 145 // Conditionally update whole channel status info.
219 capela 264 if (m_pChannel->instrumentStatus() >= 0 && m_pChannel->instrumentStatus() < 100) {
220 capela 145 updateChannelInfo();
221 capela 176 // Once we get a complete instrument load, try a implied reset channel....
222 capela 264 if (m_pChannel->instrumentStatus() == 100)
223     m_pChannel->resetChannel();
224 capela 176 }
225 capela 152 // Leave, if we still have an erroneus or incomplete instrument load.
226 capela 264 if (m_pChannel->instrumentStatus() < 100)
227 capela 152 return;
228 capela 145
229 capela 109 // Get current channel voice count.
230 capela 264 int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
231 capela 109 // Get current stream count.
232 capela 264 int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
233 capela 109 // Get current channel buffer fill usage.
234     // As benno has suggested this is the percentage usage
235     // of the least filled buffer stream...
236 capela 264 int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
237 capela 176
238 capela 109 // Update the GUI elements...
239     StreamUsageProgressBar->setProgress(iStreamUsage);
240     StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
241     }
242    
243    
244     // Volume change slot.
245     void qsamplerChannelStrip::volumeChanged ( int iVolume )
246     {
247 capela 264 if (m_pChannel == NULL)
248     return;
249    
250 capela 109 // Avoid recursion.
251     if (m_iDirtyChange > 0)
252     return;
253    
254     // Convert and clip.
255     float fVolume = (float) iVolume / 100.0;
256 capela 119 if (fVolume < 0.001)
257 capela 109 fVolume = 0.0;
258    
259     // Update the GUI elements.
260 capela 264 if (m_pChannel->setVolume(fVolume)) {
261 capela 109 updateChannelVolume();
262     emit channelChanged(this);
263     }
264     }
265    
266    
267 capela 118 // Context menu event handler.
268     void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
269     {
270 capela 264 if (m_pMainForm == NULL)
271     return;
272    
273 capela 118 // We'll just show up the main form's edit menu.
274 capela 127 m_pMainForm->contextMenuEvent(pEvent);
275 capela 118 }
276    
277    
278 capela 119 // Maximum volume slider accessors.
279     void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume )
280     {
281     m_iDirtyChange++;
282     VolumeSlider->setRange(0, iMaxVolume);
283     VolumeSpinBox->setRange(0, iMaxVolume);
284     m_iDirtyChange--;
285     }
286    
287    
288 capela 109 // end of qsamplerChannelStrip.ui.h

  ViewVC Help
Powered by ViewVC