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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 371 - (show annotations) (download) (as text)
Fri Feb 11 15:36:06 2005 UTC (14 years, 9 months ago) by capela
File MIME type: text/x-c++hdr
File size: 8941 byte(s)
Instrument names display mode update on all channels.

1 // qsamplerChannelStrip.ui.h
2 //
3 // ui.h extension file, included from the uic-generated form implementation.
4 /****************************************************************************
5 Copyright (C) 2004-2005, 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 #include <qpopupmenu.h>
28 #include <qobjectlist.h>
29
30 #include <math.h>
31
32 #include "qsamplerMainForm.h"
33 #include "qsamplerChannelForm.h"
34
35 #include "config.h"
36
37
38 // Kind of constructor.
39 void qsamplerChannelStrip::init (void)
40 {
41 // Initialize locals.
42 m_pChannel = NULL;
43 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 // 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.
61 void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel )
62 {
63 // Destroy any previous channel descriptor;
64 // (remember that once setup we own it!)
65 if (m_pChannel)
66 delete m_pChannel;
67
68 // Set the new one...
69 m_pChannel = pChannel;
70
71 // Stabilize this around.
72 updateChannelInfo();
73 }
74
75 // Channel secriptor accessor.
76 qsamplerChannel *qsamplerChannelStrip::channel (void)
77 {
78 return m_pChannel;
79 }
80
81
82 // Messages view font accessors.
83 QFont qsamplerChannelStrip::displayFont (void)
84 {
85 return EngineNameTextLabel->font();
86 }
87
88 void qsamplerChannelStrip::setDisplayFont ( const QFont & font )
89 {
90 EngineNameTextLabel->setFont(font);
91 MidiPortChannelTextLabel->setFont(font);
92 InstrumentNameTextLabel->setFont(font);
93 InstrumentStatusTextLabel->setFont(font);
94 }
95
96
97 // Channel display background effect.
98 void qsamplerChannelStrip::setDisplayEffect ( bool bDisplayEffect )
99 {
100 QPixmap pm;
101 if (bDisplayEffect)
102 pm = QPixmap::fromMimeSource("displaybg1.png");
103 setDisplayBackground(pm);
104 }
105
106
107 // Update main display background pixmap.
108 void qsamplerChannelStrip::setDisplayBackground ( const QPixmap& pm )
109 {
110 // Set the main origin...
111 ChannelInfoFrame->setPaletteBackgroundPixmap(pm);
112
113 // Iterate for every child text label...
114 QObjectList *pList = ChannelInfoFrame->queryList("QLabel");
115 if (pList) {
116 for (QLabel *pLabel = (QLabel *) pList->first(); pLabel; pLabel = (QLabel *) pList->next())
117 pLabel->setPaletteBackgroundPixmap(pm);
118 delete pList;
119 }
120
121 // And this standalone too.
122 StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm);
123 }
124
125
126 // Channel setup dialog slot.
127 bool qsamplerChannelStrip::channelSetup (void)
128 {
129 bool bResult = m_pChannel->channelSetup(this);
130
131 if (bResult)
132 emit channelChanged(this);
133
134 return bResult;
135 }
136
137
138 // Update the channel instrument name.
139 bool qsamplerChannelStrip::updateInstrumentName ( bool bForce )
140 {
141 if (m_pChannel == NULL)
142 return false;
143
144 // Do we refersh the actual name?
145 if (bForce)
146 m_pChannel->updateInstrumentName();
147
148 // Instrument name...
149 if (m_pChannel->instrumentName().isEmpty())
150 InstrumentNameTextLabel->setText(' ' + tr("(No instrument)"));
151 else
152 InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());
153
154 return true;
155 }
156
157
158 // Update whole channel info state.
159 bool qsamplerChannelStrip::updateChannelInfo (void)
160 {
161 if (m_pChannel == NULL)
162 return false;
163
164 // Update strip caption.
165 QString sText = m_pChannel->channelName();
166 setCaption(sText);
167 ChannelSetupPushButton->setText(sText);
168
169 // Check if we're up and connected.
170 if (m_pChannel->client() == NULL)
171 return false;
172
173 // Read actual channel information.
174 m_pChannel->updateChannelInfo();
175
176 // Engine name...
177 if (m_pChannel->engineName().isEmpty())
178 EngineNameTextLabel->setText(' ' + tr("(No engine)"));
179 else
180 EngineNameTextLabel->setText(' ' + m_pChannel->engineName());
181
182 // Instrument name...
183 updateInstrumentName(false);
184
185 // Instrument status...
186 int iInstrumentStatus = m_pChannel->instrumentStatus();
187 if (iInstrumentStatus < 0) {
188 InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
189 InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
190 } else {
191 InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
192 InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
193 }
194
195 // MIDI Port/Channel...
196 if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
197 MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
198 else
199 MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1));
200
201 // And update the both GUI volume elements.
202 return updateChannelVolume();
203 }
204
205
206 // Do the dirty volume change.
207 bool qsamplerChannelStrip::updateChannelVolume (void)
208 {
209 if (m_pChannel == NULL)
210 return false;
211
212 // Convert...
213 #ifdef CONFIG_ROUND
214 int iVolume = (int) ::round(100.0 * m_pChannel->volume());
215 #else
216 double fIPart = 0.0;
217 double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
218 int iVolume = (int) fIPart;
219 if (fFPart >= +0.5)
220 iVolume++;
221 else
222 if (fFPart <= -0.5)
223 iVolume--;
224 #endif
225
226 // And clip...
227 if (iVolume < 0)
228 iVolume = 0;
229
230 // Flag it here, to avoid infinite recursion.
231 m_iDirtyChange++;
232 VolumeSlider->setValue(iVolume);
233 VolumeSpinBox->setValue(iVolume);
234 m_iDirtyChange--;
235
236 return true;
237 }
238
239
240 // Update whole channel usage state.
241 bool qsamplerChannelStrip::updateChannelUsage (void)
242 {
243 if (m_pChannel == NULL)
244 return false;
245 if (m_pChannel->client() == NULL)
246 return false;
247
248 // Update whole channel status info,
249 // if instrument load is still pending...
250 if (m_pChannel->instrumentStatus() < 100) {
251 updateChannelInfo();
252 // Check (updated) status again...
253 if (m_pChannel->instrumentStatus() < 100)
254 return false;
255 // Once we get a complete instrument load,
256 // we'll try an implied channel reset...
257 m_pChannel->resetChannel();
258 }
259
260 // Check again that we're clean.
261 if (m_pChannel->instrumentStatus() < 100)
262 return false;
263
264 // Get current channel voice count.
265 int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
266 // Get current stream count.
267 int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
268 // Get current channel buffer fill usage.
269 // As benno has suggested this is the percentage usage
270 // of the least filled buffer stream...
271 int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
272
273 // Update the GUI elements...
274 StreamUsageProgressBar->setProgress(iStreamUsage);
275 StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
276
277 // We're clean.
278 return true;
279 }
280
281
282 // Volume change slot.
283 void qsamplerChannelStrip::volumeChanged ( int iVolume )
284 {
285 if (m_pChannel == NULL)
286 return;
287
288 // Avoid recursion.
289 if (m_iDirtyChange > 0)
290 return;
291
292 // Convert and clip.
293 float fVolume = (float) iVolume / 100.0;
294 if (fVolume < 0.001)
295 fVolume = 0.0;
296
297 // Update the GUI elements.
298 if (m_pChannel->setVolume(fVolume)) {
299 updateChannelVolume();
300 emit channelChanged(this);
301 }
302 }
303
304
305 // Context menu event handler.
306 void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
307 {
308 if (m_pChannel == NULL)
309 return;
310
311 // We'll just show up the main form's edit menu (thru qsamplerChannel).
312 m_pChannel->contextMenuEvent(pEvent);
313 }
314
315
316 // Maximum volume slider accessors.
317 void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume )
318 {
319 m_iDirtyChange++;
320 VolumeSlider->setRange(0, iMaxVolume);
321 VolumeSpinBox->setRange(0, iMaxVolume);
322 m_iDirtyChange--;
323 }
324
325
326 // end of qsamplerChannelStrip.ui.h

  ViewVC Help
Powered by ViewVC