/[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 303 - (show annotations) (download) (as text)
Fri Nov 19 10:18:59 2004 UTC (15 years, 2 months ago) by capela
File MIME type: text/x-c++hdr
File size: 8800 byte(s)
* Sampler channel is now completely detached from UI strip class.

1 // 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 #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 whole channel info state.
139 bool qsamplerChannelStrip::updateChannelInfo (void)
140 {
141 if (m_pChannel == NULL)
142 return false;
143
144 // Update strip caption.
145 QString sText = m_pChannel->channelName();
146 setCaption(sText);
147 ChannelSetupPushButton->setText(sText);
148
149 // Check if we're up and connected.
150 if (m_pChannel->client() == NULL)
151 return false;
152
153 // Read actual channel information.
154 m_pChannel->updateChannelInfo();
155
156 // Set some proper display values.
157 const QString sIndent = " ";
158
159 // Engine name...
160 if (m_pChannel->engineName().isEmpty())
161 EngineNameTextLabel->setText(sIndent + tr("(No engine)"));
162 else
163 EngineNameTextLabel->setText(sIndent + m_pChannel->engineName());
164
165 // Instrument name...
166 if (m_pChannel->instrumentFile().isEmpty())
167 InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));
168 else
169 InstrumentNameTextLabel->setText(sIndent + qsamplerChannel::getInstrumentName(m_pChannel->instrumentFile(), m_pChannel->instrumentNr()));
170
171 // Instrument status...
172 int iInstrumentStatus = m_pChannel->instrumentStatus();
173 if (iInstrumentStatus < 0) {
174 InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
175 InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
176 } else {
177 InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
178 InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
179 }
180
181 // MIDI Port/Channel...
182 if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
183 MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
184 else
185 MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1));
186
187 // And update the both GUI volume elements.
188 return updateChannelVolume();
189 }
190
191
192 // Do the dirty volume change.
193 bool qsamplerChannelStrip::updateChannelVolume (void)
194 {
195 if (m_pChannel == NULL)
196 return false;
197
198 // Convert...
199 #ifdef CONFIG_ROUND
200 int iVolume = (int) ::round(100.0 * m_pChannel->volume());
201 #else
202 double fIPart = 0.0;
203 double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
204 int iVolume = (int) fIPart;
205 if (fFPart >= +0.5)
206 iVolume++;
207 else
208 if (fFPart <= -0.5)
209 iVolume--;
210 #endif
211
212 // And clip...
213 if (iVolume < 0)
214 iVolume = 0;
215
216 // Flag it here, to avoid infinite recursion.
217 m_iDirtyChange++;
218 VolumeSlider->setValue(iVolume);
219 VolumeSpinBox->setValue(iVolume);
220 m_iDirtyChange--;
221
222 return true;
223 }
224
225
226 // Update whole channel usage state.
227 bool qsamplerChannelStrip::updateChannelUsage (void)
228 {
229 if (m_pChannel == NULL)
230 return false;
231 if (m_pChannel->client() == NULL)
232 return false;
233
234 // Update whole channel status info,
235 // if instrument load is still pending...
236 if (m_pChannel->instrumentStatus() < 100) {
237 updateChannelInfo();
238 // Check (updated) status again...
239 if (m_pChannel->instrumentStatus() < 100)
240 return false;
241 // Once we get a complete instrument load,
242 // we'll try an implied channel reset...
243 m_pChannel->resetChannel();
244 }
245
246 // Check again that we're clean.
247 if (m_pChannel->instrumentStatus() < 100)
248 return false;
249
250 // Get current channel voice count.
251 int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
252 // Get current stream count.
253 int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
254 // Get current channel buffer fill usage.
255 // As benno has suggested this is the percentage usage
256 // of the least filled buffer stream...
257 int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
258
259 // Update the GUI elements...
260 StreamUsageProgressBar->setProgress(iStreamUsage);
261 StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
262
263 // We're clean.
264 return true;
265 }
266
267
268 // Volume change slot.
269 void qsamplerChannelStrip::volumeChanged ( int iVolume )
270 {
271 if (m_pChannel == NULL)
272 return;
273
274 // Avoid recursion.
275 if (m_iDirtyChange > 0)
276 return;
277
278 // Convert and clip.
279 float fVolume = (float) iVolume / 100.0;
280 if (fVolume < 0.001)
281 fVolume = 0.0;
282
283 // Update the GUI elements.
284 if (m_pChannel->setVolume(fVolume)) {
285 updateChannelVolume();
286 emit channelChanged(this);
287 }
288 }
289
290
291 // Context menu event handler.
292 void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
293 {
294 if (m_pChannel == NULL)
295 return;
296
297 // We'll just show up the main form's edit menu (thru qsamplerChannel).
298 m_pChannel->contextMenuEvent(pEvent);
299 }
300
301
302 // Maximum volume slider accessors.
303 void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume )
304 {
305 m_iDirtyChange++;
306 VolumeSlider->setRange(0, iMaxVolume);
307 VolumeSpinBox->setRange(0, iMaxVolume);
308 m_iDirtyChange--;
309 }
310
311
312 // end of qsamplerChannelStrip.ui.h

  ViewVC Help
Powered by ViewVC