1 |
// qsamplerChannel.cpp |
2 |
// |
3 |
/**************************************************************************** |
4 |
Copyright (C) 2003-2004, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
6 |
This program is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License |
8 |
as published by the Free Software Foundation; either version 2 |
9 |
of the License, or (at your option) any later version. |
10 |
|
11 |
This program is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
15 |
|
16 |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
|
20 |
*****************************************************************************/ |
21 |
|
22 |
#include "qsamplerChannel.h" |
23 |
|
24 |
#include "qsamplerMainForm.h" |
25 |
|
26 |
#include "config.h" |
27 |
|
28 |
|
29 |
//------------------------------------------------------------------------- |
30 |
// qsamplerChannel - Sampler channel structure. |
31 |
// |
32 |
|
33 |
// Constructor. |
34 |
qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID ) |
35 |
{ |
36 |
m_pMainForm = pMainForm; |
37 |
m_iChannelID = iChannelID; |
38 |
|
39 |
// m_sEngineName = QObject::tr("(No engine)"); |
40 |
// m_sInstrumentFile = QObject::tr("(No instrument)"); |
41 |
m_iInstrumentNr = -1; |
42 |
m_iInstrumentStatus = -1; |
43 |
m_sMidiDriver = "Alsa"; // DEPRECATED. |
44 |
m_iMidiDevice = -1; |
45 |
m_iMidiPort = -1; |
46 |
m_iMidiChannel = -1; |
47 |
m_sAudioDriver = "Alsa"; // DEPRECATED. |
48 |
m_iAudioDevice = -1; |
49 |
m_fVolume = 0.0; |
50 |
|
51 |
} |
52 |
|
53 |
// Default destructor. |
54 |
qsamplerChannel::~qsamplerChannel (void) |
55 |
{ |
56 |
} |
57 |
|
58 |
|
59 |
// The global options settings delegated property. |
60 |
qsamplerOptions *qsamplerChannel::options (void) |
61 |
{ |
62 |
if (m_pMainForm == NULL) |
63 |
return NULL; |
64 |
|
65 |
return m_pMainForm->options(); |
66 |
} |
67 |
|
68 |
|
69 |
// The client descriptor delegated property. |
70 |
lscp_client_t *qsamplerChannel::client (void) |
71 |
{ |
72 |
if (m_pMainForm == NULL) |
73 |
return NULL; |
74 |
|
75 |
return m_pMainForm->client(); |
76 |
} |
77 |
|
78 |
|
79 |
// Channel-ID (aka Sammpler-Channel) accessors. |
80 |
int qsamplerChannel::channelID (void) |
81 |
{ |
82 |
return m_iChannelID; |
83 |
} |
84 |
|
85 |
void qsamplerChannel::setChannelID ( int iChannelID ) |
86 |
{ |
87 |
m_iChannelID = iChannelID; |
88 |
} |
89 |
|
90 |
|
91 |
// Engine name accessors. |
92 |
QString& qsamplerChannel::engineName (void) |
93 |
{ |
94 |
return m_sEngineName; |
95 |
} |
96 |
|
97 |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
98 |
{ |
99 |
if (client() == NULL) |
100 |
return false; |
101 |
|
102 |
if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
103 |
appendMessagesClient("lscp_load_engine"); |
104 |
return false; |
105 |
} |
106 |
|
107 |
m_sEngineName = sEngineName; |
108 |
return true; |
109 |
} |
110 |
|
111 |
|
112 |
// Instrument filename accessor. |
113 |
QString& qsamplerChannel::instrumentFile (void) |
114 |
{ |
115 |
return m_sInstrumentFile; |
116 |
} |
117 |
|
118 |
// Instrument index accessor. |
119 |
int qsamplerChannel::instrumentNr (void) |
120 |
{ |
121 |
return m_iInstrumentNr; |
122 |
} |
123 |
|
124 |
// Instrument status accessor. |
125 |
int qsamplerChannel::instrumentStatus (void) |
126 |
{ |
127 |
return m_iInstrumentStatus; |
128 |
} |
129 |
|
130 |
// Instrument file loader. |
131 |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
132 |
{ |
133 |
if (client() == NULL) |
134 |
return false; |
135 |
|
136 |
if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { |
137 |
appendMessagesClient("lscp_load_instrument"); |
138 |
return false; |
139 |
} |
140 |
|
141 |
m_sInstrumentFile = sInstrumentFile; |
142 |
m_iInstrumentNr = iInstrumentNr; |
143 |
m_iInstrumentStatus = 0; |
144 |
|
145 |
return true; |
146 |
} |
147 |
|
148 |
|
149 |
// MIDI driver type accessors (DEPRECATED). |
150 |
QString& qsamplerChannel::midiDriver (void) |
151 |
{ |
152 |
return m_sMidiDriver; |
153 |
} |
154 |
|
155 |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
156 |
{ |
157 |
if (client() == NULL) |
158 |
return false; |
159 |
|
160 |
if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
161 |
appendMessagesClient("lscp_set_channel_midi_type"); |
162 |
return false; |
163 |
} |
164 |
|
165 |
m_sMidiDriver = sMidiDriver; |
166 |
return true; |
167 |
} |
168 |
|
169 |
|
170 |
// MIDI device accessors. |
171 |
int qsamplerChannel::midiDevice (void) |
172 |
{ |
173 |
return m_iMidiDevice; |
174 |
} |
175 |
|
176 |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
177 |
{ |
178 |
if (client() == NULL) |
179 |
return false; |
180 |
|
181 |
if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
182 |
appendMessagesClient("lscp_set_channel_midi_device"); |
183 |
return false; |
184 |
} |
185 |
|
186 |
m_iMidiDevice = iMidiDevice; |
187 |
return true; |
188 |
} |
189 |
|
190 |
|
191 |
// MIDI port number accessor. |
192 |
int qsamplerChannel::midiPort (void) |
193 |
{ |
194 |
return m_iMidiPort; |
195 |
} |
196 |
|
197 |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
198 |
{ |
199 |
if (client() == NULL) |
200 |
return false; |
201 |
|
202 |
if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
203 |
appendMessagesClient("lscp_set_channel_midi_port"); |
204 |
return false; |
205 |
} |
206 |
|
207 |
m_iMidiPort = iMidiPort; |
208 |
return true; |
209 |
} |
210 |
|
211 |
|
212 |
// MIDI channel accessor. |
213 |
int qsamplerChannel::midiChannel (void) |
214 |
{ |
215 |
return m_iMidiChannel; |
216 |
} |
217 |
|
218 |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
219 |
{ |
220 |
if (client() == NULL) |
221 |
return false; |
222 |
|
223 |
if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
224 |
appendMessagesClient("lscp_set_channel_midi_channel"); |
225 |
return false; |
226 |
} |
227 |
|
228 |
m_iMidiChannel = iMidiChannel; |
229 |
return true; |
230 |
} |
231 |
|
232 |
|
233 |
// Audio device accessor. |
234 |
int qsamplerChannel::audioDevice (void) |
235 |
{ |
236 |
return m_iAudioDevice; |
237 |
} |
238 |
|
239 |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
240 |
{ |
241 |
if (client() == NULL) |
242 |
return false; |
243 |
|
244 |
if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
245 |
appendMessagesClient("lscp_set_channel_audio_device"); |
246 |
return false; |
247 |
} |
248 |
|
249 |
m_iAudioDevice = iAudioDevice; |
250 |
return true; |
251 |
} |
252 |
|
253 |
|
254 |
// Audio driver type accessors (DEPRECATED). |
255 |
QString& qsamplerChannel::audioDriver (void) |
256 |
{ |
257 |
return m_sAudioDriver; |
258 |
} |
259 |
|
260 |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
261 |
{ |
262 |
if (client() == NULL) |
263 |
return false; |
264 |
|
265 |
if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
266 |
appendMessagesClient("lscp_set_channel_audio_type"); |
267 |
return false; |
268 |
} |
269 |
|
270 |
m_sAudioDriver = sAudioDriver; |
271 |
return true; |
272 |
} |
273 |
|
274 |
|
275 |
// Channel volume accessors. |
276 |
float qsamplerChannel::volume (void) |
277 |
{ |
278 |
return m_fVolume; |
279 |
} |
280 |
|
281 |
bool qsamplerChannel::setVolume ( float fVolume ) |
282 |
{ |
283 |
if (client() == NULL) |
284 |
return false; |
285 |
|
286 |
if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { |
287 |
appendMessagesClient("lscp_set_channel_volume"); |
288 |
return false; |
289 |
} |
290 |
|
291 |
m_fVolume = fVolume; |
292 |
return true; |
293 |
} |
294 |
|
295 |
|
296 |
// Update whole channel info state. |
297 |
void qsamplerChannel::updateChannelInfo (void) |
298 |
{ |
299 |
// Check if we're up and connected. |
300 |
if (client() == NULL) |
301 |
return; |
302 |
|
303 |
// Read channel information. |
304 |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID); |
305 |
if (pChannelInfo == NULL) { |
306 |
appendMessagesClient("lscp_get_channel_info"); |
307 |
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry.")); |
308 |
} else { |
309 |
// Cache in channel information. |
310 |
m_sEngineName = pChannelInfo->engine_name; |
311 |
m_sInstrumentFile = pChannelInfo->instrument_file; |
312 |
m_iInstrumentNr = pChannelInfo->instrument_nr; |
313 |
m_iInstrumentStatus = pChannelInfo->instrument_status; |
314 |
m_iMidiDevice = pChannelInfo->midi_device; |
315 |
m_iMidiPort = pChannelInfo->midi_port; |
316 |
m_iMidiChannel = pChannelInfo->midi_channel; |
317 |
m_iAudioDevice = pChannelInfo->audio_device; |
318 |
m_fVolume = pChannelInfo->volume; |
319 |
// Some sanity checks. |
320 |
if (m_sEngineName == "NONE") |
321 |
m_sEngineName = QString::null; |
322 |
if (m_sInstrumentFile == "NONE") |
323 |
m_sInstrumentFile = QString::null; |
324 |
} |
325 |
} |
326 |
|
327 |
|
328 |
// Reset channel method. |
329 |
void qsamplerChannel::resetChannel (void) |
330 |
{ |
331 |
// Check if we're up and connected. |
332 |
if (client() == NULL) |
333 |
return; |
334 |
|
335 |
if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) |
336 |
appendMessagesClient("lscp_reset_channel"); |
337 |
else |
338 |
appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID)); |
339 |
} |
340 |
|
341 |
|
342 |
// Redirected messages output methods. |
343 |
void qsamplerChannel::appendMessages( const QString& s ) |
344 |
{ |
345 |
m_pMainForm->appendMessages(s); |
346 |
} |
347 |
|
348 |
void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) |
349 |
{ |
350 |
m_pMainForm->appendMessagesColor(s, c); |
351 |
} |
352 |
|
353 |
void qsamplerChannel::appendMessagesText( const QString& s ) |
354 |
{ |
355 |
m_pMainForm->appendMessagesText(s); |
356 |
} |
357 |
|
358 |
void qsamplerChannel::appendMessagesError( const QString& s ) |
359 |
{ |
360 |
m_pMainForm->appendMessagesError(s); |
361 |
} |
362 |
|
363 |
void qsamplerChannel::appendMessagesClient( const QString& s ) |
364 |
{ |
365 |
m_pMainForm->appendMessagesClient(s); |
366 |
} |
367 |
|
368 |
|
369 |
// end of qsamplerChannel.cpp |