~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to muse/audiotrack.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2005-08-23 17:19:39 UTC
  • mto: (4.1.1 breezy) (1.1.9) (10.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20050823171939-hd8fgzokb4dbj007
Tags: upstream-0.7.1+0.7.2pre2
ImportĀ upstreamĀ versionĀ 0.7.1+0.7.2pre2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//  $Id: audiotrack.cpp,v 1.14 2004/07/14 15:27:26 wschweer Exp $
 
5
//
 
6
//  (C) Copyright 2004 Werner Schweer (ws@seh.de)
 
7
//=========================================================
 
8
 
 
9
#include <values.h>
 
10
 
 
11
#include "track.h"
 
12
#include "event.h"
 
13
#include "song.h"
 
14
#include "audio.h"
 
15
#include "wave.h"
 
16
#include "xml.h"
 
17
#include "plugin.h"
 
18
#include "audiodev.h"
 
19
 
 
20
//---------------------------------------------------------
 
21
//   AudioTrack
 
22
//---------------------------------------------------------
 
23
 
 
24
AudioTrack::AudioTrack(TrackType t)
 
25
   : Track(t)
 
26
      {
 
27
      _prefader = false;
 
28
      _efxPipe  = new Pipeline();
 
29
      _recFile  = 0;
 
30
      _channels = 0;
 
31
      _automationType = AUTO_READ;
 
32
      setChannels(1);
 
33
      addController(new CtrlList(AC_VOLUME));
 
34
      addController(new CtrlList(AC_PAN));
 
35
      outBuffers = new float*[2];
 
36
      for (int i = 0; i < MAX_CHANNELS; ++i)
 
37
            outBuffers[i] = new float[segmentSize];
 
38
      bufferPos = MAXINT;
 
39
      }
 
40
 
 
41
AudioTrack::AudioTrack(const AudioTrack& t)
 
42
  : Track(t)
 
43
      {
 
44
      _controller     = t._controller;
 
45
      _prefader       = t._prefader;
 
46
      _auxSend        = t._auxSend;
 
47
      _efxPipe        = new Pipeline(*(t._efxPipe));
 
48
      _automationType = t._automationType;
 
49
      _inRoutes       = t._inRoutes;
 
50
      _outRoutes      = t._outRoutes;
 
51
      outBuffers = new float*[MAX_CHANNELS];
 
52
      for (int i = 0; i < MAX_CHANNELS; ++i)
 
53
            outBuffers[i] = new float[segmentSize];
 
54
      bufferPos = MAXINT;
 
55
      _recFile  = t._recFile;
 
56
      }
 
57
 
 
58
AudioTrack::~AudioTrack()
 
59
      {
 
60
      delete _efxPipe;
 
61
      for (int i = 0; i < MAX_CHANNELS; ++i)
 
62
            delete[] outBuffers[i];
 
63
      delete[] outBuffers;
 
64
      }
 
65
 
 
66
//---------------------------------------------------------
 
67
//   newPart
 
68
//---------------------------------------------------------
 
69
 
 
70
Part* AudioTrack::newPart(Part*, bool /*clone*/)
 
71
      {
 
72
      return 0;
 
73
      }
 
74
 
 
75
//---------------------------------------------------------
 
76
//   addPlugin
 
77
//---------------------------------------------------------
 
78
 
 
79
void AudioTrack::addPlugin(PluginI* plugin, int idx)
 
80
      {
 
81
      if (plugin == 0) {
 
82
            PluginI* oldPlugin = (*_efxPipe)[idx];
 
83
            if (oldPlugin) {
 
84
                  int controller = oldPlugin->parameters();
 
85
                  for (int i = 0; i < controller; ++i) {
 
86
                        int id = (idx + 1) * 0x1000 + i;
 
87
                        removeController(id);
 
88
                        }
 
89
                  }
 
90
            }
 
91
      efxPipe()->insert(plugin, idx);
 
92
      if (plugin) {
 
93
            int controller = plugin->parameters();
 
94
            for (int i = 0; i < controller; ++i) {
 
95
                  int id = (idx + 1) * 0x1000 + i;
 
96
                  const char* name = plugin->paramName(i);
 
97
                  float min, max;
 
98
                  plugin->range(i, &min, &max);
 
99
                  CtrlValueType t = plugin->valueType();
 
100
                  CtrlList* cl = new CtrlList(id);
 
101
                  cl->setRange(min, max);
 
102
                  cl->setName(QString(name));
 
103
                  cl->setValueType(t);
 
104
                  addController(cl);
 
105
                  }
 
106
            }
 
107
      }
 
108
 
 
109
//---------------------------------------------------------
 
110
//   addAuxSend
 
111
//---------------------------------------------------------
 
112
 
 
113
void AudioTrack::addAuxSend(int n)
 
114
      {
 
115
      int nn = _auxSend.size();
 
116
      for (int i = nn; i < n; ++i) {
 
117
            _auxSend.push_back(0.0);
 
118
            _auxSend[i] = 0.0;  //??
 
119
            }
 
120
      }
 
121
 
 
122
//---------------------------------------------------------
 
123
//   addController
 
124
//---------------------------------------------------------
 
125
 
 
126
void AudioTrack::addController(CtrlList* list)
 
127
      {
 
128
      _controller.add(list);
 
129
      }
 
130
 
 
131
//---------------------------------------------------------
 
132
//   removeController
 
133
//---------------------------------------------------------
 
134
 
 
135
void AudioTrack::removeController(int id)
 
136
      {
 
137
      iCtrlList i = _controller.find(id);
 
138
      if (i == _controller.end()) {
 
139
            printf("AudioTrack::removeController id %d not found\n", id);
 
140
            return;
 
141
            }
 
142
      _controller.erase(i);
 
143
      }
 
144
 
 
145
//---------------------------------------------------------
 
146
//   volume
 
147
//---------------------------------------------------------
 
148
 
 
149
double AudioTrack::volume() const
 
150
      {
 
151
      ciCtrlList cl = _controller.find(AC_VOLUME);
 
152
      if (cl == _controller.end())
 
153
            return 0.0;
 
154
      if (automation && (automationType() == AUTO_READ
 
155
         || automationType() == AUTO_TOUCH))
 
156
            return cl->second->value(song->cPos().frame());
 
157
      else
 
158
            return cl->second->curVal();
 
159
      }
 
160
 
 
161
//---------------------------------------------------------
 
162
//   setVolume
 
163
//---------------------------------------------------------
 
164
 
 
165
void AudioTrack::setVolume(double val)
 
166
      {
 
167
      iCtrlList cl = _controller.find(AC_VOLUME);
 
168
      if (cl == _controller.end()) {
 
169
            printf("no volume controller %s %d\n",
 
170
               name().latin1(), _controller.size());
 
171
            return;
 
172
            }
 
173
      cl->second->setCurVal(val);
 
174
      }
 
175
 
 
176
//---------------------------------------------------------
 
177
//   pan
 
178
//---------------------------------------------------------
 
179
 
 
180
double AudioTrack::pan() const
 
181
      {
 
182
      ciCtrlList cl = _controller.find(AC_PAN);
 
183
      if (cl == _controller.end())
 
184
            return 0.0;
 
185
      return cl->second->value(song->cPos().frame());
 
186
      }
 
187
 
 
188
//---------------------------------------------------------
 
189
//   setPan
 
190
//---------------------------------------------------------
 
191
 
 
192
void AudioTrack::setPan(double val)
 
193
      {
 
194
      iCtrlList cl = _controller.find(AC_PAN);
 
195
      if (cl == _controller.end()) {
 
196
            printf("no pan controller\n");
 
197
            return;
 
198
            }
 
199
      cl->second->setCurVal(val);
 
200
      }
 
201
 
 
202
void AudioTrack::recordAutomation(int n, float v)
 
203
      {
 
204
      if (audio->isPlaying() && automation && automationType() == AUTO_TOUCH || automationType() == AUTO_WRITE)
 
205
            _recEvents.push_back(CtrlRecVal(song->cPos().frame(), n, v));
 
206
      }
 
207
 
 
208
void AudioTrack::startAutoRecord(int n)
 
209
      {
 
210
      if (audio->isPlaying() && automation && automationType() == AUTO_TOUCH)
 
211
            _recEvents.push_back(CtrlRecVal(song->cPos().frame(), n, 1));
 
212
      }
 
213
 
 
214
void AudioTrack::stopAutoRecord(int n)
 
215
      {
 
216
      if (audio->isPlaying() && automation && automationType() == AUTO_TOUCH)
 
217
            _recEvents.push_back(CtrlRecVal(song->cPos().frame(), n, 2));
 
218
      }
 
219
 
 
220
//---------------------------------------------------------
 
221
//   AudioTrack::writeProperties
 
222
//---------------------------------------------------------
 
223
 
 
224
void AudioTrack::writeProperties(int level, Xml& xml) const
 
225
      {
 
226
      Track::writeProperties(level, xml);
 
227
      xml.intTag(level, "prefader", prefader());
 
228
      xml.intTag(level, "automation", int(automationType()));
 
229
      if (hasAuxSend()) {
 
230
            int naux = song->auxs()->size();
 
231
            for (int idx = 0; idx < naux; ++idx) {
 
232
                  QString s("<auxSend idx=%1>%2</auxSend>\n");
 
233
                  xml.nput(level, s.arg(idx).arg(_auxSend[idx]));
 
234
                  }
 
235
            }
 
236
      for (ciPluginI ip = _efxPipe->begin(); ip != _efxPipe->end(); ++ip) {
 
237
            if (*ip)
 
238
                  (*ip)->writeConfiguration(level, xml);
 
239
            }
 
240
      for (ciCtrlList icl = _controller.begin(); icl != _controller.end(); ++icl) {
 
241
            const CtrlList* cl = icl->second;
 
242
            QString s("controller id=\"%1\" cur=\"%2\"");
 
243
            xml.tag(level++, s.arg(cl->id()).arg(cl->curVal()));
 
244
            int i = 0;
 
245
            for (ciCtrl ic = cl->begin(); ic != cl->end(); ++ic) {
 
246
                  QString s("%1 %2, ");
 
247
                  xml.nput(level, s.arg(ic->second.frame).arg(ic->second.val));
 
248
                  ++i;
 
249
                  if (i >= 4) {
 
250
                        xml.put(level, "");
 
251
                        i = 0;
 
252
                        }
 
253
                  }
 
254
            if (i)
 
255
                  xml.put(level, "");
 
256
            xml.etag(level--, "controller");
 
257
            }
 
258
      }
 
259
 
 
260
//---------------------------------------------------------
 
261
//   readAuxSend
 
262
//---------------------------------------------------------
 
263
 
 
264
void AudioTrack::readAuxSend(Xml& xml)
 
265
      {
 
266
      unsigned idx = 0;
 
267
      double val;
 
268
      for (;;) {
 
269
            Xml::Token token = xml.parse();
 
270
            const QString& tag = xml.s1();
 
271
            switch (token) {
 
272
                  case Xml::Error:
 
273
                  case Xml::End:
 
274
                        return;
 
275
                  case Xml::Attribut:
 
276
                        if (tag == "idx")
 
277
                              idx = xml.s2().toInt();
 
278
                        break;
 
279
                  case Xml::Text:
 
280
                        val = tag.toDouble();
 
281
                        break;
 
282
                  case Xml::TagEnd:
 
283
                        if (xml.s1() == "auxSend") {
 
284
                              if (_auxSend.size() < idx+1)
 
285
                                    _auxSend.push_back(val);
 
286
                              else
 
287
                                    _auxSend[idx] = val;
 
288
                              return;
 
289
                              }
 
290
                  default:
 
291
                        break;
 
292
                  }
 
293
            }
 
294
      }
 
295
 
 
296
//---------------------------------------------------------
 
297
//   AudioTrack::readProperties
 
298
//---------------------------------------------------------
 
299
 
 
300
bool AudioTrack::readProperties(Xml& xml, const QString& tag)
 
301
      {
 
302
      if (tag == "plugin") {
 
303
            PluginI* pi = new PluginI;
 
304
            if (pi->readConfiguration(xml, false)) {
 
305
                  delete pi;
 
306
                  }
 
307
            else {
 
308
                  // insert plugin into first free slot
 
309
                  // of plugin rack
 
310
                  int i = 0;
 
311
                  for (i = 0; i < 4; ++i) {
 
312
                        if ((*_efxPipe)[i] == 0) {
 
313
                              (*_efxPipe)[i] = pi;
 
314
                              break;
 
315
                              }
 
316
                        }
 
317
                  if (i == 4) {
 
318
                        printf("internal error: too many plugins\n");
 
319
                        }
 
320
                  }
 
321
            }
 
322
      else if (tag == "auxSend")
 
323
            readAuxSend(xml);
 
324
      else if (tag == "prefader")
 
325
            _prefader = xml.parseInt();
 
326
      else if (tag == "automation")
 
327
            setAutomationType(AutomationType(xml.parseInt()));
 
328
      else if (tag == "recfile")
 
329
            readRecfile(xml);
 
330
      else if (tag == "controller") {
 
331
            CtrlList* l = new CtrlList();
 
332
            l->read(xml);
 
333
            iCtrlList icl = _controller.find(l->id());
 
334
            if (icl == _controller.end())
 
335
                  _controller.add(l);
 
336
            else {
 
337
                  CtrlList* d = icl->second;
 
338
                  for (iCtrl i = l->begin(); i != l->end(); ++i)
 
339
                        d->insert(std::pair<const int, CtrlVal> (i->first, i->second));
 
340
                  d->setCurVal(l->curVal());
 
341
                  d->setDefault(l->getDefault());
 
342
                  delete l;
 
343
                  }
 
344
            }
 
345
      else
 
346
            return Track::readProperties(xml, tag);
 
347
      return false;
 
348
      }
 
349
 
 
350
//---------------------------------------------------------
 
351
//   writeRouting
 
352
//---------------------------------------------------------
 
353
 
 
354
void AudioTrack::writeRouting(int level, Xml& xml) const
 
355
      {
 
356
      if (type() == Track::AUDIO_INPUT) {
 
357
            const RouteList* rl = &_inRoutes;
 
358
            for (ciRoute r = rl->begin(); r != rl->end(); ++r) {
 
359
                  Route dst(name(), true, r->channel);
 
360
                  xml.tag(level++, "Route");
 
361
                  xml.strTag(level, "srcNode", r->name());
 
362
                  xml.strTag(level, "dstNode", dst.name());
 
363
                  xml.etag(level--, "Route");
 
364
                  }
 
365
            }
 
366
      const RouteList* rl = &_outRoutes;
 
367
      for (ciRoute r = rl->begin(); r != rl->end(); ++r) {
 
368
            QString src(name());
 
369
            if (type() == Track::AUDIO_OUTPUT) {
 
370
                  Route s(src, false, r->channel);
 
371
                  src = s.name();
 
372
                  }
 
373
            xml.tag(level++, "Route");
 
374
            xml.strTag(level, "srcNode", src);
 
375
            xml.strTag(level, "dstNode", r->name());
 
376
            xml.etag(level--, "Route");
 
377
            }
 
378
      }
 
379
 
 
380
//---------------------------------------------------------
 
381
//   AudioInput
 
382
//---------------------------------------------------------
 
383
 
 
384
AudioInput::AudioInput()
 
385
   : AudioTrack(AUDIO_INPUT)
 
386
      {
 
387
      // set Default for Input Ports:
 
388
      _mute = true;
 
389
      setVolume(0.0);
 
390
      for (int i = 0; i < MAX_CHANNELS; ++i)
 
391
            jackPorts[i] = 0;
 
392
      _channels = 0;
 
393
      setChannels(2);
 
394
      }
 
395
 
 
396
AudioInput::AudioInput(const AudioInput& t)
 
397
  : AudioTrack(t)
 
398
      {
 
399
      for (int i = 0; i < MAX_CHANNELS; ++i)
 
400
            jackPorts[i] = t.jackPorts[i];
 
401
      }
 
402
 
 
403
//---------------------------------------------------------
 
404
//   ~AudioInput
 
405
//---------------------------------------------------------
 
406
 
 
407
AudioInput::~AudioInput()
 
408
      {
 
409
      for (int i = 0; i < _channels; ++i)
 
410
            audioDevice->unregisterPort(jackPorts[i]);
 
411
      }
 
412
 
 
413
//---------------------------------------------------------
 
414
//   write
 
415
//---------------------------------------------------------
 
416
 
 
417
void AudioInput::write(int level, Xml& xml) const
 
418
      {
 
419
      xml.tag(level++, "AudioInput");
 
420
      AudioTrack::writeProperties(level, xml);
 
421
      xml.etag(level, "AudioInput");
 
422
      }
 
423
 
 
424
//---------------------------------------------------------
 
425
//   read
 
426
//---------------------------------------------------------
 
427
 
 
428
void AudioInput::read(Xml& xml)
 
429
      {
 
430
      for (;;) {
 
431
            Xml::Token token = xml.parse();
 
432
            const QString& tag = xml.s1();
 
433
            switch (token) {
 
434
                  case Xml::Error:
 
435
                  case Xml::End:
 
436
                        return;
 
437
                  case Xml::TagStart:
 
438
                        if (AudioTrack::readProperties(xml, tag))
 
439
                              xml.unknown("AudioInput");
 
440
                        break;
 
441
                  case Xml::Attribut:
 
442
                        break;
 
443
                  case Xml::TagEnd:
 
444
                        if (tag == "AudioInput") {
 
445
                              setName(name());  // allocate jack ports
 
446
                              return;
 
447
                              }
 
448
                  default:
 
449
                        break;
 
450
                  }
 
451
            }
 
452
      }
 
453
 
 
454
//---------------------------------------------------------
 
455
//   AudioOutput
 
456
//---------------------------------------------------------
 
457
 
 
458
AudioOutput::AudioOutput()
 
459
   : AudioTrack(AUDIO_OUTPUT)
 
460
      {
 
461
      for (int i = 0; i < MAX_CHANNELS; ++i)
 
462
            jackPorts[i] = 0;
 
463
      _channels = 0;
 
464
      setChannels(2);
 
465
      }
 
466
 
 
467
AudioOutput::AudioOutput(const AudioOutput& t)
 
468
  : AudioTrack(t)
 
469
      {
 
470
      for (int i = 0; i < MAX_CHANNELS; ++i)
 
471
            jackPorts[i] = t.jackPorts[i];
 
472
      _nframes = t._nframes;
 
473
      }
 
474
 
 
475
//---------------------------------------------------------
 
476
//   ~AudioOutput
 
477
//---------------------------------------------------------
 
478
 
 
479
AudioOutput::~AudioOutput()
 
480
      {
 
481
      for (int i = 0; i < _channels; ++i)
 
482
            audioDevice->unregisterPort(jackPorts[i]);
 
483
      }
 
484
 
 
485
//---------------------------------------------------------
 
486
//   write
 
487
//---------------------------------------------------------
 
488
 
 
489
void AudioOutput::write(int level, Xml& xml) const
 
490
      {
 
491
      xml.tag(level++, "AudioOutput");
 
492
      AudioTrack::writeProperties(level, xml);
 
493
      xml.etag(level, "AudioOutput");
 
494
      }
 
495
 
 
496
//---------------------------------------------------------
 
497
//   read
 
498
//---------------------------------------------------------
 
499
 
 
500
void AudioOutput::read(Xml& xml)
 
501
      {
 
502
      for (;;) {
 
503
            Xml::Token token = xml.parse();
 
504
            const QString& tag = xml.s1();
 
505
            switch (token) {
 
506
                  case Xml::Error:
 
507
                  case Xml::End:
 
508
                        return;
 
509
                  case Xml::TagStart:
 
510
                        if (AudioTrack::readProperties(xml, tag))
 
511
                              xml.unknown("AudioOutput");
 
512
                        break;
 
513
                  case Xml::Attribut:
 
514
                        break;
 
515
                  case Xml::TagEnd:
 
516
                        if (tag == "AudioOutput") {
 
517
                              setName(name());  // allocate jack ports
 
518
                              return;
 
519
                              }
 
520
                  default:
 
521
                        break;
 
522
                  }
 
523
            }
 
524
      }
 
525
 
 
526
//---------------------------------------------------------
 
527
//   write
 
528
//---------------------------------------------------------
 
529
 
 
530
void AudioGroup::write(int level, Xml& xml) const
 
531
      {
 
532
      xml.tag(level++, "AudioGroup");
 
533
      AudioTrack::writeProperties(level, xml);
 
534
      xml.etag(level, "AudioGroup");
 
535
      }
 
536
 
 
537
//---------------------------------------------------------
 
538
//   read
 
539
//---------------------------------------------------------
 
540
 
 
541
void AudioGroup::read(Xml& xml)
 
542
      {
 
543
      for (;;) {
 
544
            Xml::Token token = xml.parse();
 
545
            const QString& tag = xml.s1();
 
546
            switch (token) {
 
547
                  case Xml::Error:
 
548
                  case Xml::End:
 
549
                        return;
 
550
                  case Xml::TagStart:
 
551
                        if (AudioTrack::readProperties(xml, tag))
 
552
                              xml.unknown("AudioGroup");
 
553
                        break;
 
554
                  case Xml::Attribut:
 
555
                        break;
 
556
                  case Xml::TagEnd:
 
557
                        if (tag == "AudioGroup")
 
558
                              return;
 
559
                  default:
 
560
                        break;
 
561
                  }
 
562
            }
 
563
      }
 
564
 
 
565
//---------------------------------------------------------
 
566
//   write
 
567
//---------------------------------------------------------
 
568
 
 
569
void AudioAux::write(int level, Xml& xml) const
 
570
      {
 
571
      xml.tag(level++, "AudioAux");
 
572
      AudioTrack::writeProperties(level, xml);
 
573
      xml.etag(level, "AudioAux");
 
574
      }
 
575
 
 
576
//---------------------------------------------------------
 
577
//   AudioAux
 
578
//---------------------------------------------------------
 
579
 
 
580
AudioAux::AudioAux()
 
581
   : AudioTrack(AUDIO_AUX)
 
582
      {
 
583
      _channels = 0;
 
584
      setChannels(2);
 
585
      for (int i = 0; i < MAX_CHANNELS; ++i)
 
586
            buffer[i] = (i < channels()) ? new float[segmentSize] : 0;
 
587
      }
 
588
 
 
589
//---------------------------------------------------------
 
590
//   AudioAux
 
591
//---------------------------------------------------------
 
592
 
 
593
AudioAux::~AudioAux()
 
594
      {
 
595
      for (int i = 0; i < channels(); ++i)
 
596
            delete[] buffer[i];
 
597
      }
 
598
 
 
599
//---------------------------------------------------------
 
600
//   read
 
601
//---------------------------------------------------------
 
602
 
 
603
void AudioAux::read(Xml& xml)
 
604
      {
 
605
      for (;;) {
 
606
            Xml::Token token = xml.parse();
 
607
            const QString& tag = xml.s1();
 
608
            switch (token) {
 
609
                  case Xml::Error:
 
610
                  case Xml::End:
 
611
                        return;
 
612
                  case Xml::TagStart:
 
613
                        if (AudioTrack::readProperties(xml, tag))
 
614
                              xml.unknown("AudioAux");
 
615
                        break;
 
616
                  case Xml::Attribut:
 
617
                        break;
 
618
                  case Xml::TagEnd:
 
619
                        if (tag == "AudioAux")
 
620
                              return;
 
621
                  default:
 
622
                        break;
 
623
                  }
 
624
            }
 
625
      }
 
626
 
 
627
//---------------------------------------------------------
 
628
//   getData
 
629
//---------------------------------------------------------
 
630
 
 
631
bool AudioAux::getData(unsigned /*pos*/, int ch, unsigned /*samples*/, float** data)
 
632
      {
 
633
      for (int i = 0; i < ch; ++i)
 
634
            data[i] = buffer[i % channels()];
 
635
      return true;
 
636
      }
 
637
 
 
638
//---------------------------------------------------------
 
639
//   setChannels
 
640
//---------------------------------------------------------
 
641
 
 
642
void AudioAux::setChannels(int n)
 
643
      {
 
644
      if (n > channels()) {
 
645
            for (int i = channels(); i < n; ++i)
 
646
                  buffer[i] = new float[segmentSize];
 
647
            }
 
648
      else if (n < channels()) {
 
649
            for (int i = n; i < channels(); ++i)
 
650
                  delete[] buffer[i];
 
651
            }
 
652
      AudioTrack::setChannels(n);
 
653
      }
 
654
 
 
655
//---------------------------------------------------------
 
656
//   setRecordFlag1
 
657
//    gui part (executed in gui thread)
 
658
//---------------------------------------------------------
 
659
 
 
660
void AudioTrack::setRecordFlag1(bool f)
 
661
      {
 
662
      if (f == _recordFlag)
 
663
            return;
 
664
      if (f) {
 
665
            if (_recFile == 0) {
 
666
                  //
 
667
                  // create soundfile for recording
 
668
                  //
 
669
                  char buffer[128];
 
670
                  QFile fil;
 
671
                  for (;;++recFileNumber) {
 
672
                     sprintf(buffer, "%s/rec%d.wav",
 
673
                        museProject.latin1(),
 
674
                        recFileNumber);
 
675
                     fil.setName(QString(buffer));
 
676
                     if (!fil.exists())
 
677
                        break;
 
678
                        }
 
679
                  _recFile = new SndFile(QString(buffer));
 
680
                  _recFile->setFormat(
 
681
                     SF_FORMAT_WAV | SF_FORMAT_FLOAT,
 
682
                     _channels, sampleRate);
 
683
                  }
 
684
            _recFile->openWrite();
 
685
            if (debugMsg)
 
686
                  printf("AudioNode::setRecordFlag1: create internal file %s\n",
 
687
                     _recFile->path().latin1());
 
688
            }
 
689
      else {
 
690
            if (_recFile) {
 
691
                  // this file has not been processed and can be
 
692
                  // deleted
 
693
                    QString s = _recFile->path();
 
694
                  remove(s.latin1());
 
695
                  if (debugMsg)
 
696
                        printf("AudioNode::setRecordFlag1: remove file %s\n", s.latin1());
 
697
                  _recFile = 0;
 
698
                  }
 
699
            }
 
700
      }
 
701
double AudioTrack::auxSend(int idx) const
 
702
      {
 
703
      if (unsigned(idx) >= _auxSend.size()) {
 
704
            printf("%s auxSend: bad index: %d >= %d\n",
 
705
               name().latin1(), idx, _auxSend.size());
 
706
            return 0.0;
 
707
            }
 
708
      return _auxSend[idx];
 
709
      }
 
710
 
 
711
void AudioTrack::setAuxSend(int idx, double v)
 
712
      {
 
713
      if (unsigned(idx) >= _auxSend.size()) {
 
714
            printf("%s setAuxSend: bad index: %d >= %d\n",
 
715
               name().latin1(), idx, _auxSend.size());
 
716
            return;
 
717
            }
 
718
      _auxSend[idx] = v;
 
719
      }
 
720