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