/[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 295 - (show annotations) (download) (as text)
Tue Nov 16 15:26:18 2004 UTC (19 years, 5 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9132 byte(s)
* Sampler channels strips are just created if, and only if,
  the respective channel setup dialog is actually accepted,
  following common user-interface guidelines.

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

  ViewVC Help
Powered by ViewVC