/[svn]/qsampler/trunk/src/qsamplerChannel.cpp
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerChannel.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 295 - (hide annotations) (download)
Tue Nov 16 15:26:18 2004 UTC (19 years, 5 months ago) by capela
File size: 10705 byte(s)
* Sampler channels strips are just created if, and only if,
  the respective channel setup dialog is actually accepted,
  following common user-interface guidelines.

1 capela 264 // 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 capela 295 // Create a new sampler channel, if not already.
80     bool qsamplerChannel::addChannel (void)
81     {
82     if (client() == NULL)
83     return false;
84    
85     // Are we a new channel?
86     if (m_iChannelID < 0) {
87     m_iChannelID = ::lscp_add_channel(client());
88     if (m_iChannelID < 0) {
89     appendMessagesClient("lscp_add_channel");
90     appendMessagesError(QObject::tr("Could not create the new channel.\n\nSorry."));
91     } // Otherwise it's created...
92     else appendMessages(QObject::tr("Channel %1 created.").arg(m_iChannelID));
93     }
94    
95     // Return whether we're a valid channel...
96     return (m_iChannelID >= 0);
97     }
98    
99    
100     // Remove sampler channel.
101     bool qsamplerChannel::removeChannel (void)
102     {
103     if (client() == NULL)
104     return false;
105    
106     // Are we an existing channel?
107     if (m_iChannelID >= 0) {
108     if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {
109     appendMessagesClient("lscp_remove_channel");
110     appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
111     } else {
112     // Otherwise it's removed.
113     appendMessages(QObject::tr("Channel %1 removed.").arg(m_iChannelID));
114     m_iChannelID = -1;
115     }
116     }
117    
118     // Return whether we've removed the channel...
119     return (m_iChannelID < 0);
120     }
121    
122    
123 capela 264 // Channel-ID (aka Sammpler-Channel) accessors.
124     int qsamplerChannel::channelID (void)
125     {
126     return m_iChannelID;
127     }
128    
129     void qsamplerChannel::setChannelID ( int iChannelID )
130     {
131     m_iChannelID = iChannelID;
132     }
133    
134    
135 capela 295 // Readable channel name.
136     QString qsamplerChannel::channelName (void)
137     {
138     return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));
139     }
140    
141    
142 capela 264 // Engine name accessors.
143     QString& qsamplerChannel::engineName (void)
144     {
145     return m_sEngineName;
146     }
147    
148     bool qsamplerChannel::loadEngine ( const QString& sEngineName )
149     {
150 capela 295 if (client() == NULL || m_iChannelID < 0)
151 capela 264 return false;
152    
153     if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
154     appendMessagesClient("lscp_load_engine");
155     return false;
156     }
157    
158     m_sEngineName = sEngineName;
159     return true;
160     }
161    
162    
163     // Instrument filename accessor.
164     QString& qsamplerChannel::instrumentFile (void)
165     {
166     return m_sInstrumentFile;
167     }
168    
169     // Instrument index accessor.
170     int qsamplerChannel::instrumentNr (void)
171     {
172     return m_iInstrumentNr;
173     }
174    
175     // Instrument status accessor.
176     int qsamplerChannel::instrumentStatus (void)
177     {
178     return m_iInstrumentStatus;
179     }
180    
181     // Instrument file loader.
182     bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
183     {
184 capela 295 if (client() == NULL || m_iChannelID < 0)
185 capela 264 return false;
186    
187     if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {
188     appendMessagesClient("lscp_load_instrument");
189     return false;
190     }
191    
192     m_sInstrumentFile = sInstrumentFile;
193     m_iInstrumentNr = iInstrumentNr;
194     m_iInstrumentStatus = 0;
195    
196     return true;
197     }
198    
199    
200     // MIDI driver type accessors (DEPRECATED).
201     QString& qsamplerChannel::midiDriver (void)
202     {
203     return m_sMidiDriver;
204     }
205    
206     bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
207     {
208 capela 295 if (client() == NULL || m_iChannelID < 0)
209 capela 264 return false;
210    
211     if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
212     appendMessagesClient("lscp_set_channel_midi_type");
213     return false;
214     }
215    
216     m_sMidiDriver = sMidiDriver;
217     return true;
218     }
219    
220    
221     // MIDI device accessors.
222     int qsamplerChannel::midiDevice (void)
223     {
224     return m_iMidiDevice;
225     }
226    
227     bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
228     {
229 capela 295 if (client() == NULL || m_iChannelID < 0)
230 capela 264 return false;
231    
232     if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
233     appendMessagesClient("lscp_set_channel_midi_device");
234     return false;
235     }
236    
237     m_iMidiDevice = iMidiDevice;
238     return true;
239     }
240    
241    
242     // MIDI port number accessor.
243     int qsamplerChannel::midiPort (void)
244     {
245     return m_iMidiPort;
246     }
247    
248     bool qsamplerChannel::setMidiPort ( int iMidiPort )
249     {
250 capela 295 if (client() == NULL || m_iChannelID < 0)
251 capela 264 return false;
252    
253     if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {
254     appendMessagesClient("lscp_set_channel_midi_port");
255     return false;
256     }
257    
258     m_iMidiPort = iMidiPort;
259     return true;
260     }
261    
262    
263     // MIDI channel accessor.
264     int qsamplerChannel::midiChannel (void)
265     {
266     return m_iMidiChannel;
267     }
268    
269     bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
270     {
271 capela 295 if (client() == NULL || m_iChannelID < 0)
272 capela 264 return false;
273    
274     if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
275     appendMessagesClient("lscp_set_channel_midi_channel");
276     return false;
277     }
278    
279     m_iMidiChannel = iMidiChannel;
280     return true;
281     }
282    
283    
284     // Audio device accessor.
285     int qsamplerChannel::audioDevice (void)
286     {
287     return m_iAudioDevice;
288     }
289    
290     bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
291     {
292 capela 295 if (client() == NULL || m_iChannelID < 0)
293 capela 264 return false;
294    
295     if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
296     appendMessagesClient("lscp_set_channel_audio_device");
297     return false;
298     }
299    
300     m_iAudioDevice = iAudioDevice;
301     return true;
302     }
303    
304    
305     // Audio driver type accessors (DEPRECATED).
306     QString& qsamplerChannel::audioDriver (void)
307     {
308     return m_sAudioDriver;
309     }
310    
311     bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
312     {
313 capela 295 if (client() == NULL || m_iChannelID < 0)
314 capela 264 return false;
315    
316     if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
317     appendMessagesClient("lscp_set_channel_audio_type");
318     return false;
319     }
320    
321     m_sAudioDriver = sAudioDriver;
322     return true;
323     }
324    
325    
326     // Channel volume accessors.
327     float qsamplerChannel::volume (void)
328     {
329     return m_fVolume;
330     }
331    
332     bool qsamplerChannel::setVolume ( float fVolume )
333     {
334 capela 295 if (client() == NULL || m_iChannelID < 0)
335 capela 264 return false;
336    
337     if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {
338     appendMessagesClient("lscp_set_channel_volume");
339     return false;
340     }
341    
342     m_fVolume = fVolume;
343     return true;
344     }
345    
346    
347     // Update whole channel info state.
348 capela 295 bool qsamplerChannel::updateChannelInfo (void)
349 capela 264 {
350 capela 295 if (client() == NULL || m_iChannelID < 0)
351     return false;
352 capela 264
353     // Read channel information.
354     lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);
355     if (pChannelInfo == NULL) {
356     appendMessagesClient("lscp_get_channel_info");
357     appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
358 capela 295 return false;
359 capela 264 }
360 capela 295
361     // Cache in channel information.
362     m_sEngineName = pChannelInfo->engine_name;
363     m_sInstrumentFile = pChannelInfo->instrument_file;
364     m_iInstrumentNr = pChannelInfo->instrument_nr;
365     m_iInstrumentStatus = pChannelInfo->instrument_status;
366     m_iMidiDevice = pChannelInfo->midi_device;
367     m_iMidiPort = pChannelInfo->midi_port;
368     m_iMidiChannel = pChannelInfo->midi_channel;
369     m_iAudioDevice = pChannelInfo->audio_device;
370     m_fVolume = pChannelInfo->volume;
371     // Some sanity checks.
372     if (m_sEngineName == "NONE")
373     m_sEngineName = QString::null;
374     if (m_sInstrumentFile == "NONE")
375     m_sInstrumentFile = QString::null;
376    
377     return true;
378 capela 264 }
379    
380    
381     // Reset channel method.
382 capela 295 bool qsamplerChannel::resetChannel (void)
383 capela 264 {
384 capela 295 if (client() == NULL || m_iChannelID < 0)
385     return false;
386 capela 264
387 capela 295 if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {
388 capela 264 appendMessagesClient("lscp_reset_channel");
389 capela 295 return false;
390     }
391    
392     appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID));
393     return true;
394 capela 264 }
395    
396    
397     // Redirected messages output methods.
398     void qsamplerChannel::appendMessages( const QString& s )
399     {
400     m_pMainForm->appendMessages(s);
401     }
402    
403     void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c )
404     {
405     m_pMainForm->appendMessagesColor(s, c);
406     }
407    
408     void qsamplerChannel::appendMessagesText( const QString& s )
409     {
410     m_pMainForm->appendMessagesText(s);
411     }
412    
413     void qsamplerChannel::appendMessagesError( const QString& s )
414     {
415     m_pMainForm->appendMessagesError(s);
416     }
417    
418     void qsamplerChannel::appendMessagesClient( const QString& s )
419     {
420     m_pMainForm->appendMessagesClient(s);
421     }
422    
423    
424     // end of qsamplerChannel.cpp

  ViewVC Help
Powered by ViewVC