/[svn]/qsampler/trunk/src/qsamplerChannelStrip.ui.h
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerChannelStrip.ui.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 265 - (hide 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 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 109
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 capela 264 m_pMainForm = NULL;
42     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     void qsamplerChannelStrip::setup ( qsamplerMainForm *pMainForm, int iChannelID )
62     {
63 capela 264 // Set main form reference.
64 capela 109 m_pMainForm = pMainForm;
65 capela 145
66 capela 264 // Destroy any previous channel descriptor.
67     if (m_pChannel)
68     delete m_pChannel;
69 capela 109
70 capela 264 // 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 capela 109 }
77 capela 265
78     // Stabilize this around.
79     updateChannelInfo();
80 capela 109 }
81    
82 capela 264 // Channel secriptor accessor.
83     qsamplerChannel *qsamplerChannelStrip::channel (void)
84 capela 109 {
85 capela 264 return m_pChannel;
86 capela 109 }
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 capela 145 MidiPortChannelTextLabel->setFont(font);
99 capela 109 InstrumentNameTextLabel->setFont(font);
100 capela 145 InstrumentStatusTextLabel->setFont(font);
101 capela 109 }
102    
103 capela 263
104     // Channel setup dialog slot.
105     void qsamplerChannelStrip::channelSetup (void)
106     {
107     showChannelSetup(false);
108     }
109    
110    
111 capela 109 // Channel setup dialog.
112 capela 263 void qsamplerChannelStrip::showChannelSetup ( bool bNew )
113 capela 109 {
114     qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this);
115     if (pChannelForm) {
116 capela 264 pChannelForm->setup(m_pChannel, bNew);
117 capela 109 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 capela 264 if (m_pChannel == NULL)
130     return;
131    
132 capela 109 // Update strip caption.
133 capela 264 QString sText = tr("Channel %1").arg(m_pChannel->channelID());
134 capela 109 setCaption(sText);
135     ChannelSetupPushButton->setText(sText);
136    
137     // Check if we're up and connected.
138 capela 264 if (m_pChannel->client() == NULL)
139 capela 109 return;
140    
141 capela 264 // Read actual channel information.
142     m_pChannel->updateChannelInfo();
143 capela 109
144     // Set some proper display values.
145 capela 261 const QString sIndent = " ";
146 capela 109
147     // Engine name...
148 capela 264 if (m_pChannel->engineName().isEmpty())
149 capela 261 EngineNameTextLabel->setText(sIndent + tr("(No engine)"));
150 capela 109 else
151 capela 264 EngineNameTextLabel->setText(sIndent + m_pChannel->engineName());
152 capela 109
153     // Instrument name...
154 capela 264 if (m_pChannel->instrumentFile().isEmpty())
155 capela 261 InstrumentNameTextLabel->setText(sIndent + tr("(No instrument)"));
156 capela 109 else
157 capela 261 InstrumentNameTextLabel->setText(sIndent + QString("%1 [%2]")
158 capela 264 .arg(QFileInfo(m_pChannel->instrumentFile()).fileName()).arg(m_pChannel->instrumentNr()));
159 capela 109
160 capela 145 // Instrument status...
161 capela 264 int iInstrumentStatus = m_pChannel->instrumentStatus();
162     if (iInstrumentStatus < 0) {
163 capela 145 InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);
164 capela 264 InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
165 capela 145 } else {
166 capela 264 InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
167     InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + "%");
168 capela 145 }
169    
170 capela 109 // MIDI Port/Channel...
171 capela 264 if (m_pChannel->midiChannel() > 0)
172     MidiPortChannelTextLabel->setText(QString("%1 / %2").arg(m_pChannel->midiPort()).arg(m_pChannel->midiChannel()));
173 capela 261 else
174 capela 264 MidiPortChannelTextLabel->setText(QString("%1 / *").arg(m_pChannel->midiPort()));
175 capela 261
176 capela 109 // 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 capela 264 if (m_pChannel == NULL)
185     return;
186    
187 capela 109 // Convert...
188     #ifdef CONFIG_ROUND
189 capela 264 int iVolume = (int) ::round(100.0 * m_pChannel->volume());
190 capela 109 #else
191     double fIPart = 0.0;
192 capela 264 double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);
193 capela 109 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 capela 119 if (iVolume < 0)
203 capela 109 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 capela 264 if (m_pChannel == NULL)
217 capela 109 return;
218 capela 264 if (m_pChannel->client() == NULL)
219     return;
220 capela 109
221 capela 145 // Conditionally update whole channel status info.
222 capela 264 if (m_pChannel->instrumentStatus() >= 0 && m_pChannel->instrumentStatus() < 100) {
223 capela 145 updateChannelInfo();
224 capela 176 // Once we get a complete instrument load, try a implied reset channel....
225 capela 264 if (m_pChannel->instrumentStatus() == 100)
226     m_pChannel->resetChannel();
227 capela 176 }
228 capela 152 // Leave, if we still have an erroneus or incomplete instrument load.
229 capela 264 if (m_pChannel->instrumentStatus() < 100)
230 capela 152 return;
231 capela 145
232 capela 109 // Get current channel voice count.
233 capela 264 int iVoiceCount = ::lscp_get_channel_voice_count(m_pChannel->client(), m_pChannel->channelID());
234 capela 109 // Get current stream count.
235 capela 264 int iStreamCount = ::lscp_get_channel_stream_count(m_pChannel->client(), m_pChannel->channelID());
236 capela 109 // Get current channel buffer fill usage.
237     // As benno has suggested this is the percentage usage
238     // of the least filled buffer stream...
239 capela 264 int iStreamUsage = ::lscp_get_channel_stream_usage(m_pChannel->client(), m_pChannel->channelID());;
240 capela 176
241 capela 109 // 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 capela 264 if (m_pChannel == NULL)
251     return;
252    
253 capela 109 // Avoid recursion.
254     if (m_iDirtyChange > 0)
255     return;
256    
257     // Convert and clip.
258     float fVolume = (float) iVolume / 100.0;
259 capela 119 if (fVolume < 0.001)
260 capela 109 fVolume = 0.0;
261    
262     // Update the GUI elements.
263 capela 264 if (m_pChannel->setVolume(fVolume)) {
264 capela 109 updateChannelVolume();
265     emit channelChanged(this);
266     }
267     }
268    
269    
270 capela 118 // Context menu event handler.
271     void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
272     {
273 capela 264 if (m_pMainForm == NULL)
274     return;
275    
276 capela 118 // We'll just show up the main form's edit menu.
277 capela 127 m_pMainForm->contextMenuEvent(pEvent);
278 capela 118 }
279    
280    
281 capela 119 // 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 capela 109 // end of qsamplerChannelStrip.ui.h

  ViewVC Help
Powered by ViewVC