/[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 265 - (show annotations) (download) (as text)
Wed Sep 29 16:05:24 2004 UTC (19 years, 6 months ago) by capela
File MIME type: text/x-c++hdr
File size: 8300 byte(s)
Continued rewrite of sampler channel strips internal control structures.

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

  ViewVC Help
Powered by ViewVC