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_pChannel = NULL; |
43 |
capela |
109 |
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 |
capela |
264 |
// Destroy existing channel descriptor. |
54 |
|
|
if (m_pChannel) |
55 |
|
|
delete m_pChannel; |
56 |
|
|
m_pChannel = NULL; |
57 |
capela |
109 |
} |
58 |
|
|
|
59 |
|
|
|
60 |
|
|
// Channel strip setup formal initializer. |
61 |
capela |
303 |
void qsamplerChannelStrip::setup ( qsamplerChannel *pChannel ) |
62 |
capela |
109 |
{ |
63 |
capela |
303 |
// Destroy any previous channel descriptor; |
64 |
|
|
// (remember that once setup we own it!) |
65 |
capela |
264 |
if (m_pChannel) |
66 |
|
|
delete m_pChannel; |
67 |
capela |
109 |
|
68 |
capela |
303 |
// Set the new one... |
69 |
|
|
m_pChannel = pChannel; |
70 |
capela |
302 |
|
71 |
capela |
265 |
// Stabilize this around. |
72 |
|
|
updateChannelInfo(); |
73 |
capela |
109 |
} |
74 |
|
|
|
75 |
capela |
264 |
// Channel secriptor accessor. |
76 |
|
|
qsamplerChannel *qsamplerChannelStrip::channel (void) |
77 |
capela |
109 |
{ |
78 |
capela |
264 |
return m_pChannel; |
79 |
capela |
109 |
} |
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 |
capela |
145 |
MidiPortChannelTextLabel->setFont(font); |
92 |
capela |
109 |
InstrumentNameTextLabel->setFont(font); |
93 |
capela |
145 |
InstrumentStatusTextLabel->setFont(font); |
94 |
capela |
109 |
} |
95 |
|
|
|
96 |
capela |
263 |
|
97 |
capela |
267 |
// 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 |
capela |
263 |
// Channel setup dialog slot. |
127 |
capela |
295 |
bool qsamplerChannelStrip::channelSetup (void) |
128 |
capela |
263 |
{ |
129 |
capela |
303 |
bool bResult = m_pChannel->channelSetup(this); |
130 |
capela |
263 |
|
131 |
capela |
296 |
if (bResult) |
132 |
capela |
295 |
emit channelChanged(this); |
133 |
|
|
|
134 |
|
|
return bResult; |
135 |
capela |
109 |
} |
136 |
|
|
|
137 |
|
|
|
138 |
|
|
// Update whole channel info state. |
139 |
capela |
297 |
bool qsamplerChannelStrip::updateChannelInfo (void) |
140 |
capela |
109 |
{ |
141 |
capela |
264 |
if (m_pChannel == NULL) |
142 |
capela |
297 |
return false; |
143 |
capela |
264 |
|
144 |
capela |
109 |
// Update strip caption. |
145 |
capela |
295 |
QString sText = m_pChannel->channelName(); |
146 |
capela |
109 |
setCaption(sText); |
147 |
|
|
ChannelSetupPushButton->setText(sText); |
148 |
|
|
|
149 |
|
|
// Check if we're up and connected. |
150 |
capela |
264 |
if (m_pChannel->client() == NULL) |
151 |
capela |
297 |
return false; |
152 |
capela |
109 |
|
153 |
capela |
264 |
// Read actual channel information. |
154 |
|
|
m_pChannel->updateChannelInfo(); |
155 |
capela |
109 |
|
156 |
|
|
// Set some proper display values. |
157 |
capela |
261 |
const QString sIndent = " "; |
158 |
capela |
109 |
|
159 |
|
|
// Engine name... |
160 |
capela |
264 |
if (m_pChannel->engineName().isEmpty()) |
161 |
capela |
261 |
EngineNameTextLabel->setText(sIndent + tr("(No engine)")); |
162 |
capela |
109 |
else |
163 |
capela |
264 |
EngineNameTextLabel->setText(sIndent + m_pChannel->engineName()); |
164 |
capela |
109 |
|
165 |
|
|
// Instrument name... |
166 |
capela |
264 |
if (m_pChannel->instrumentFile().isEmpty()) |
167 |
capela |
261 |
InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)")); |
168 |
capela |
109 |
else |
169 |
capela |
299 |
InstrumentNameTextLabel->setText(sIndent + qsamplerChannel::getInstrumentName(m_pChannel->instrumentFile(), m_pChannel->instrumentNr())); |
170 |
capela |
109 |
|
171 |
capela |
145 |
// Instrument status... |
172 |
capela |
264 |
int iInstrumentStatus = m_pChannel->instrumentStatus(); |
173 |
|
|
if (iInstrumentStatus < 0) { |
174 |
capela |
145 |
InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red); |
175 |
capela |
264 |
InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus)); |
176 |
capela |
145 |
} else { |
177 |
capela |
264 |
InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green); |
178 |
|
|
InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%"); |
179 |
capela |
145 |
} |
180 |
|
|
|
181 |
capela |
109 |
// MIDI Port/Channel... |
182 |
capela |
280 |
if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL) |
183 |
|
|
MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort())); |
184 |
capela |
261 |
else |
185 |
capela |
280 |
MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel() + 1)); |
186 |
capela |
261 |
|
187 |
capela |
109 |
// And update the both GUI volume elements. |
188 |
capela |
297 |
return updateChannelVolume(); |
189 |
capela |
109 |
} |
190 |
|
|
|
191 |
|
|
|
192 |
|
|
// Do the dirty volume change. |
193 |
capela |
297 |
bool qsamplerChannelStrip::updateChannelVolume (void) |
194 |
capela |
109 |
{ |
195 |
capela |
264 |
if (m_pChannel == NULL) |
196 |
capela |
297 |
return false; |
197 |
capela |
264 |
|
198 |
capela |
109 |
// Convert... |
199 |
|
|
#ifdef CONFIG_ROUND |
200 |
capela |
264 |
int iVolume = (int) ::round(100.0 * m_pChannel->volume()); |
201 |
capela |
109 |
#else |
202 |
|
|
double fIPart = 0.0; |
203 |
capela |
264 |
double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart); |
204 |
capela |
109 |
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 |
capela |
119 |
if (iVolume < 0) |
214 |
capela |
109 |
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 |
capela |
297 |
|
222 |
|
|
return true; |
223 |
capela |
109 |
} |
224 |
|
|
|
225 |
|
|
|
226 |
|
|
// Update whole channel usage state. |
227 |
capela |
297 |
bool qsamplerChannelStrip::updateChannelUsage (void) |
228 |
capela |
109 |
{ |
229 |
capela |
264 |
if (m_pChannel == NULL) |
230 |
capela |
297 |
return false; |
231 |
capela |
264 |
if (m_pChannel->client() == NULL) |
232 |
capela |
297 |
return false; |
233 |
capela |
109 |
|
234 |
capela |
302 |
// Update whole channel status info, |
235 |
|
|
// if instrument load is still pending... |
236 |
|
|
if (m_pChannel->instrumentStatus() < 100) { |
237 |
capela |
145 |
updateChannelInfo(); |
238 |
capela |
302 |
// 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 |
capela |
176 |
} |
245 |
capela |
302 |
|
246 |
|
|
// Check again that we're clean. |
247 |
capela |
264 |
if (m_pChannel->instrumentStatus() < 100) |
248 |
capela |
297 |
return false; |
249 |
capela |
145 |
|
250 |
capela |
109 |
// Get current channel voice count. |
251 |
capela |
264 |
int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID()); |
252 |
capela |
109 |
// Get current stream count. |
253 |
capela |
264 |
int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID()); |
254 |
capela |
109 |
// Get current channel buffer fill usage. |
255 |
|
|
// As benno has suggested this is the percentage usage |
256 |
|
|
// of the least filled buffer stream... |
257 |
capela |
264 |
int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());; |
258 |
capela |
176 |
|
259 |
capela |
109 |
// Update the GUI elements... |
260 |
|
|
StreamUsageProgressBar->setProgress(iStreamUsage); |
261 |
|
|
StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); |
262 |
capela |
297 |
|
263 |
|
|
// We're clean. |
264 |
|
|
return true; |
265 |
capela |
109 |
} |
266 |
|
|
|
267 |
|
|
|
268 |
|
|
// Volume change slot. |
269 |
|
|
void qsamplerChannelStrip::volumeChanged ( int iVolume ) |
270 |
|
|
{ |
271 |
capela |
264 |
if (m_pChannel == NULL) |
272 |
|
|
return; |
273 |
|
|
|
274 |
capela |
109 |
// Avoid recursion. |
275 |
|
|
if (m_iDirtyChange > 0) |
276 |
|
|
return; |
277 |
|
|
|
278 |
|
|
// Convert and clip. |
279 |
|
|
float fVolume = (float) iVolume / 100.0; |
280 |
capela |
119 |
if (fVolume < 0.001) |
281 |
capela |
109 |
fVolume = 0.0; |
282 |
|
|
|
283 |
|
|
// Update the GUI elements. |
284 |
capela |
264 |
if (m_pChannel->setVolume(fVolume)) { |
285 |
capela |
109 |
updateChannelVolume(); |
286 |
|
|
emit channelChanged(this); |
287 |
|
|
} |
288 |
|
|
} |
289 |
|
|
|
290 |
|
|
|
291 |
capela |
118 |
// Context menu event handler. |
292 |
|
|
void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) |
293 |
|
|
{ |
294 |
capela |
303 |
if (m_pChannel == NULL) |
295 |
capela |
264 |
return; |
296 |
|
|
|
297 |
capela |
303 |
// We'll just show up the main form's edit menu (thru qsamplerChannel). |
298 |
|
|
m_pChannel->contextMenuEvent(pEvent); |
299 |
capela |
118 |
} |
300 |
|
|
|
301 |
|
|
|
302 |
capela |
119 |
// 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 |
capela |
109 |
// end of qsamplerChannelStrip.ui.h |