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