1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
|
//=========================================================
// MusE
// Linux Music Editor
// $Id: audiotrack.cpp,v 1.14.2.21 2009/12/20 05:00:35 terminator356 Exp $
//
// (C) Copyright 2004 Werner Schweer (ws@seh.de)
//=========================================================
#include <values.h>
#include <stdlib.h>
#include <map>
#include <QMessageBox>
#include "track.h"
#include "event.h"
#include "song.h"
#include "audio.h"
#include "wave.h"
#include "xml.h"
#include "plugin.h"
#include "audiodev.h"
// By T356. For caching jack in/out routing names BEFORE file save.
// Jack often shuts down during file save, causing the routes to be lost in the file.
// cacheJackRouteNames() is ONLY called from MusE::save() in app.cpp
// Update: Not required any more because the real problem was Jack RT priority, which has been fixed.
/*
typedef std::multimap <const int, QString> jackRouteNameMap;
std::map <const AudioTrack*, jackRouteNameMap > jackRouteNameCache;
typedef std::multimap <const int, QString>::const_iterator ciJackRouteNameMap;
typedef std::map <const AudioTrack*, jackRouteNameMap>::const_iterator ciJackRouteNameCache;
void cacheJackRouteNames()
{
jackRouteNameCache.clear();
const InputList* il = song->inputs();
for(ciAudioInput iai = il->begin(); iai != il->end(); ++iai)
{
const RouteList* rl = (*iai)->inRoutes();
if(!rl->empty())
{
jackRouteNameMap rm = jackRouteNameMap();
for(ciRoute r = rl->begin(); r != rl->end(); ++r)
rm.insert(std::pair<const int, QString>(r->channel, r->name()));
jackRouteNameCache.insert(std::pair<const AudioTrack*, jackRouteNameMap>(*iai, rm));
}
}
const OutputList* ol = song->outputs();
for(ciAudioOutput iao = ol->begin(); iao != ol->end(); ++iao)
{
const RouteList* rl = (*iao)->outRoutes();
if(!rl->empty())
{
jackRouteNameMap rm = jackRouteNameMap();
for(ciRoute r = rl->begin(); r != rl->end(); ++r)
rm.insert(std::pair<const int, QString>(r->channel, r->name()));
jackRouteNameCache.insert(std::pair<const AudioTrack*, jackRouteNameMap>(*iao, rm));
}
}
}
*/
//---------------------------------------------------------
// AudioTrack
//---------------------------------------------------------
AudioTrack::AudioTrack(TrackType t)
//AudioTrack::AudioTrack(TrackType t, int num_out_bufs)
: Track(t)
{
//_totalOutChannels = num_out_bufs; // Is either parameter-default MAX_CHANNELS, or custom value passed (used by syntis).
_processed = false;
_haveData = false;
_sendMetronome = false;
_prefader = false;
_efxPipe = new Pipeline();
_recFile = 0;
_channels = 0;
_automationType = AUTO_OFF;
//setChannels(1);
setChannels(2);
addController(new CtrlList(AC_VOLUME,"Volume",0.0,3.16 /* roughly 10 db */));
addController(new CtrlList(AC_PAN, "Pan", -1.0, 1.0));
addController(new CtrlList(AC_MUTE,"Mute",0.0,1.0, true /*dont show in arranger */));
// Changed by Tim. p3.3.15
//outBuffers = new float*[MAX_CHANNELS];
//for (int i = 0; i < MAX_CHANNELS; ++i)
// outBuffers[i] = new float[segmentSize];
//for (int i = 0; i < MAX_CHANNELS; ++i)
// posix_memalign((void**)(outBuffers + i), 16, sizeof(float) * segmentSize);
// Let's allocate it all in one block, and just point the remaining buffer pointers into the block
// which allows faster one-shot buffer copying.
// Nope. Nice but interferes with possibility we don't know if other buffers are contiguous (jack buffers, local stack buffers etc.).
//posix_memalign((void**)(outBuffers), 16, sizeof(float) * segmentSize * MAX_CHANNELS);
//for (int i = 0; i < MAX_CHANNELS; ++i)
// *(outBuffers + i) = sizeof(float) * segmentSize * i;
// p3.3.38
// Easy way, less desirable... Start out with enough for MAX_CHANNELS. Then multi-channel syntis can re-allocate,
// via a call to (a modified!) setChannels().
// Hard way, more desirable... Creating a synti instance passes the total channels to this constructor, overriding MAX_CHANNELS.
_totalOutChannels = MAX_CHANNELS;
outBuffers = new float*[_totalOutChannels];
for (int i = 0; i < _totalOutChannels; ++i)
posix_memalign((void**)&outBuffers[i], 16, sizeof(float) * segmentSize);
// This is only set by multi-channel syntis...
_totalInChannels = 0;
bufferPos = MAXINT;
setVolume(1.0);
}
//AudioTrack::AudioTrack(const AudioTrack& t)
// : Track(t)
AudioTrack::AudioTrack(const AudioTrack& t, bool cloneParts)
: Track(t, cloneParts)
{
_totalOutChannels = t._totalOutChannels; // Is either MAX_CHANNELS, or custom value (used by syntis).
_processed = false;
_haveData = false;
_sendMetronome = t._sendMetronome;
_controller = t._controller;
_prefader = t._prefader;
_auxSend = t._auxSend;
_efxPipe = new Pipeline(*(t._efxPipe));
_automationType = t._automationType;
_inRoutes = t._inRoutes;
_outRoutes = t._outRoutes;
// Changed by Tim. p3.3.15
//outBuffers = new float*[MAX_CHANNELS];
//for (int i = 0; i < MAX_CHANNELS; ++i)
// outBuffers[i] = new float[segmentSize];
//for (int i = 0; i < MAX_CHANNELS; ++i)
// posix_memalign((void**)(outBuffers + i), 16, sizeof(float) * segmentSize);
// p3.3.38
int chans = _totalOutChannels;
// Number of allocated buffers is always MAX_CHANNELS or more, even if _totalOutChannels is less.
if(chans < MAX_CHANNELS)
chans = MAX_CHANNELS;
outBuffers = new float*[chans];
for (int i = 0; i < chans; ++i)
posix_memalign((void**)&outBuffers[i], 16, sizeof(float) * segmentSize);
bufferPos = MAXINT;
_recFile = t._recFile;
}
AudioTrack::~AudioTrack()
{
delete _efxPipe;
//for (int i = 0; i < MAX_CHANNELS; ++i)
// delete[] outBuffers[i];
//delete[] outBuffers;
// p3.3.15
//for(int i = 0; i < MAX_CHANNELS; ++i)
//{
// if(outBuffers[i])
// free(outBuffers[i]);
//}
// p3.3.38
int chans = _totalOutChannels;
// Number of allocated buffers is always MAX_CHANNELS or more, even if _totalOutChannels is less.
if(chans < MAX_CHANNELS)
chans = MAX_CHANNELS;
for(int i = 0; i < chans; ++i)
{
if(outBuffers[i])
free(outBuffers[i]);
}
delete[] outBuffers;
}
//---------------------------------------------------------
// deleteAllEfxGuis
//---------------------------------------------------------
void AudioTrack::deleteAllEfxGuis()
{
if(_efxPipe)
_efxPipe->deleteAllGuis();
}
//---------------------------------------------------------
// clearEfxList
//---------------------------------------------------------
void AudioTrack::clearEfxList()
{
if(_efxPipe)
for(int i = 0; i < PipelineDepth; i++)
(*_efxPipe)[i] = 0;
}
//---------------------------------------------------------
// newPart
//---------------------------------------------------------
Part* AudioTrack::newPart(Part*, bool /*clone*/)
{
return 0;
}
//---------------------------------------------------------
// addPlugin
//---------------------------------------------------------
void AudioTrack::addPlugin(PluginI* plugin, int idx)
{
if (plugin == 0)
{
PluginI* oldPlugin = (*_efxPipe)[idx];
if (oldPlugin)
{
oldPlugin->setID(-1);
oldPlugin->setTrack(0);
int controller = oldPlugin->parameters();
for (int i = 0; i < controller; ++i)
{
int id = genACnum(idx, i);
removeController(id);
}
}
}
efxPipe()->insert(plugin, idx);
if (plugin)
{
plugin->setID(idx);
plugin->setTrack(this);
int controller = plugin->parameters();
for (int i = 0; i < controller; ++i)
{
int id = genACnum(idx, i);
const char* name = plugin->paramName(i);
float min, max;
plugin->range(i, &min, &max);
CtrlValueType t = plugin->valueType();
CtrlList* cl = new CtrlList(id);
cl->setRange(min, max);
cl->setName(QString(name));
cl->setValueType(t);
LADSPA_PortRangeHint range = plugin->range(i);
if(LADSPA_IS_HINT_TOGGLED(range.HintDescriptor))
cl->setMode(CtrlList::DISCRETE);
else
cl->setMode(CtrlList::INTERPOLATE);
cl->setCurVal(plugin->param(i));
addController(cl);
}
}
}
//---------------------------------------------------------
// addAuxSend
//---------------------------------------------------------
void AudioTrack::addAuxSend(int n)
{
int nn = _auxSend.size();
for (int i = nn; i < n; ++i) {
_auxSend.push_back(0.0);
_auxSend[i] = 0.0; //??
}
}
//---------------------------------------------------------
// addController
//---------------------------------------------------------
void AudioTrack::addController(CtrlList* list)
{
_controller.add(list);
}
//---------------------------------------------------------
// removeController
//---------------------------------------------------------
void AudioTrack::removeController(int id)
{
iCtrlList i = _controller.find(id);
if (i == _controller.end()) {
printf("AudioTrack::removeController id %d not found\n", id);
return;
}
_controller.erase(i);
}
//---------------------------------------------------------
// swapControllerIDX
//---------------------------------------------------------
void AudioTrack::swapControllerIDX(int idx1, int idx2)
{
// FIXME This code is ugly.
// At best we would like to modify the keys (IDXs) in-place and
// do some kind of deferred re-sort, but it can't be done...
if(idx1 == idx2)
return;
if(idx1 < 0 || idx2 < 0 || idx1 >= PipelineDepth || idx2 >= PipelineDepth)
return;
CtrlList *cl;
CtrlList *newcl;
int id1 = (idx1 + 1) * AC_PLUGIN_CTL_BASE;
int id2 = (idx2 + 1) * AC_PLUGIN_CTL_BASE;
int i, j;
CtrlListList tmpcll;
CtrlVal cv(0, 0.0);
for(ciCtrlList icl = _controller.begin(); icl != _controller.end(); ++icl)
{
cl = icl->second;
i = cl->id() & AC_PLUGIN_CTL_ID_MASK;
j = cl->id() & ~((unsigned long)AC_PLUGIN_CTL_ID_MASK);
if(j == id1 || j == id2)
{
newcl = new CtrlList(i | (j == id1 ? id2 : id1));
newcl->setMode(cl->mode());
newcl->setValueType(cl->valueType());
newcl->setName(cl->name());
double min, max;
cl->range(&min, &max);
newcl->setRange(min, max);
newcl->setCurVal(cl->curVal());
newcl->setDefault(cl->getDefault());
for(iCtrl ic = cl->begin(); ic != cl->end(); ++ic)
{
cv = ic->second;
newcl->insert(std::pair<const int, CtrlVal>(cv.frame, cv));
}
tmpcll.insert(std::pair<const int, CtrlList*>(newcl->id(), newcl));
}
else
{
newcl = new CtrlList();
*newcl = *cl;
tmpcll.insert(std::pair<const int, CtrlList*>(newcl->id(), newcl));
}
}
for(iCtrlList ci = _controller.begin(); ci != _controller.end(); ++ci)
delete (*ci).second;
_controller.clear();
for(ciCtrlList icl = tmpcll.begin(); icl != tmpcll.end(); ++icl)
{
newcl = icl->second;
_controller.insert(std::pair<const int, CtrlList*>(newcl->id(), newcl));
}
/*
unsigned int idmask = ~AC_PLUGIN_CTL_ID_MASK;
CtrlList* cl;
CtrlList* ctl1 = 0;
CtrlList* ctl2 = 0;
CtrlList* newcl1 = 0;
CtrlList* newcl2 = 0;
CtrlVal cv(0, 0.0);
int id1 = (idx1 + 1) * AC_PLUGIN_CTL_BASE;
int id2 = (idx2 + 1) * AC_PLUGIN_CTL_BASE;
int i, j;
double min, max;
for(ciCtrlList icl = _controller.begin(); icl != _controller.end(); ++icl)
{
cl = icl->second;
i = cl->id() & AC_PLUGIN_CTL_ID_MASK;
j = cl->id() & idmask;
if(j == id1)
{
ctl1 = cl;
newcl1 = new CtrlList( i | id2 );
newcl1->setMode(cl->mode());
newcl1->setValueType(cl->valueType());
newcl1->setName(cl->name());
cl->range(&min, &max);
newcl1->setRange(min, max);
newcl1->setCurVal(cl->curVal());
newcl1->setDefault(cl->getDefault());
for(iCtrl ic = cl->begin(); ic != cl->end(); ++ic)
{
cv = ic->second;
newcl1->insert(std::pair<const int, CtrlVal>(cv.frame, cv));
}
}
//else
if(j == id2)
{
ctl2 = cl;
newcl2 = new CtrlList( i | id1 );
newcl2->setMode(cl->mode());
newcl2->setValueType(cl->valueType());
newcl2->setName(cl->name());
cl->range(&min, &max);
newcl2->setRange(min, max);
newcl2->setCurVal(cl->curVal());
newcl2->setDefault(cl->getDefault());
for(iCtrl ic = cl->begin(); ic != cl->end(); ++ic)
{
cv = ic->second;
newcl2->insert(std::pair<const int, CtrlVal>(cv.frame, cv));
}
}
}
if(ctl1)
_controller.erase(ctl1->id());
if(ctl2)
_controller.erase(ctl2->id());
if(newcl1)
//_controller.add(newcl1);
_controller.insert(std::pair<const int, CtrlList*>(newcl1->id(), newcl1));
if(newcl2)
_controller.insert(std::pair<const int, CtrlList*>(newcl2->id(), newcl2));
//_controller.add(newcl2);
*/
}
//---------------------------------------------------------
// setAutomationType
//---------------------------------------------------------
void AudioTrack::setAutomationType(AutomationType t)
{
// Clear pressed and touched and rec event list.
clearRecAutomation(true);
// Now set the type.
_automationType = t;
}
//---------------------------------------------------------
// processAutomationEvents
//---------------------------------------------------------
void AudioTrack::processAutomationEvents()
{
if (_automationType != AUTO_TOUCH && _automationType != AUTO_WRITE)
return;
for (iCtrlList icl = _controller.begin(); icl != _controller.end(); ++icl)
{
CtrlList* cl = icl->second;
int id = cl->id();
// Remove old events from record region.
if (_automationType == AUTO_WRITE)
{
int start = audio->getStartRecordPos().frame();
int end = audio->getEndRecordPos().frame();
iCtrl s = cl->lower_bound(start);
iCtrl e = cl->lower_bound(end);
// Erase old events only if there were recorded events.
for(iCtrlRec icr = _recEvents.begin(); icr != _recEvents.end(); ++icr)
{
if(icr->id == id) // && icr->type == ARVT_VAL && icr->frame >= s->frame && icr->frame <= e->frame)
{
cl->erase(s, e);
break;
}
}
}
else
{ // type AUTO_TOUCH
for (iCtrlRec icr = _recEvents.begin(); icr != _recEvents.end(); ++icr)
{
// Don't bother looking for start, it's OK, just take the first one.
// Needed for mousewheel and paging etc.
//if (icr->id == id && icr->type == ARVT_START)
if (icr->id == id)
{
int start = icr->frame;
if(icr == _recEvents.end())
{
int end = audio->getEndRecordPos().frame();
iCtrl s = cl->lower_bound(start);
iCtrl e = cl->lower_bound(end);
cl->erase(s, e);
break;
}
iCtrlRec icrlast = icr;
++icr;
for(; ; ++icr)
{
if(icr == _recEvents.end())
{
int end = icrlast->frame;
iCtrl s = cl->lower_bound(start);
iCtrl e = cl->lower_bound(end);
cl->erase(s, e);
break;
}
if(icr->id == id && icr->type == ARVT_STOP)
{
int end = icr->frame;
// Erase everything up to, not including, this stop event's frame.
// Because an event was already stored directly when slider released.
if(end > start)
--end;
iCtrl s = cl->lower_bound(start);
iCtrl e = cl->lower_bound(end);
cl->erase(s, e);
break;
}
if(icr->id == id)
icrlast = icr;
}
if (icr == _recEvents.end())
break;
}
}
}
// Extract all recorded events for controller "id"
// from CtrlRecList and put into cl.
for (iCtrlRec icr = _recEvents.begin(); icr != _recEvents.end(); ++icr)
{
if (icr->id == id && (icr->type == ARVT_VAL || icr->type == ARVT_START))
cl->add(icr->frame, icr->val);
}
}
// Done with the recorded automation event list. Clear it.
_recEvents.clear();
// Try muse without this, so that the user can remain in automation write mode
// after a stop.
/*
if (automationType() == AUTO_WRITE)
{
setAutomationType(AUTO_READ);
song->update(SC_AUTOMATION);
}
*/
}
//---------------------------------------------------------
// setControllerMode
//---------------------------------------------------------
void AudioTrack::setControllerMode(int ctlID, CtrlList::Mode m)
{
ciCtrlList cl = _controller.find(ctlID);
if(cl == _controller.end())
return;
cl->second->setMode(m);
}
//---------------------------------------------------------
// clearControllerEvents
//---------------------------------------------------------
void AudioTrack::clearControllerEvents(int id)
{
ciCtrlList icl = _controller.find(id);
if(icl == _controller.end())
return;
CtrlList* cl = icl->second;
cl->clear();
return;
}
//---------------------------------------------------------
// seekPrevACEvent
//---------------------------------------------------------
void AudioTrack::seekPrevACEvent(int id)
{
ciCtrlList icl = _controller.find(id);
if(icl == _controller.end())
return;
CtrlList* cl = icl->second;
if(cl->empty())
return;
iCtrl s = cl->lower_bound(song->cPos().frame());
if(s != cl->begin())
--s;
song->setPos(Song::CPOS, Pos(s->second.frame, false), true, false, true);
return;
}
//---------------------------------------------------------
// seekNextACEvent
//---------------------------------------------------------
void AudioTrack::seekNextACEvent(int id)
{
ciCtrlList icl = _controller.find(id);
if(icl == _controller.end())
return;
CtrlList* cl = icl->second;
if(cl->empty())
return;
iCtrl s = cl->upper_bound(song->cPos().frame());
if(s == cl->end())
{
--s;
}
song->setPos(Song::CPOS, Pos(s->second.frame, false), true, false, true);
return;
}
//---------------------------------------------------------
// eraseACEvent
//---------------------------------------------------------
void AudioTrack::eraseACEvent(int id, int frame)
{
ciCtrlList icl = _controller.find(id);
if(icl == _controller.end())
return;
CtrlList* cl = icl->second;
if(cl->empty())
return;
iCtrl s = cl->find(frame);
if(s != cl->end())
cl->erase(s);
return;
}
//---------------------------------------------------------
// eraseRangeACEvents
//---------------------------------------------------------
void AudioTrack::eraseRangeACEvents(int id, int frame1, int frame2)
{
ciCtrlList icl = _controller.find(id);
if(icl == _controller.end())
return;
CtrlList* cl = icl->second;
if(cl->empty())
return;
iCtrl s = cl->lower_bound(frame1);
iCtrl e = cl->lower_bound(frame2);
cl->erase(s, e);
return;
}
//---------------------------------------------------------
// addACEvent
//---------------------------------------------------------
void AudioTrack::addACEvent(int id, int frame, double val)
{
ciCtrlList icl = _controller.find(id);
if(icl == _controller.end())
return;
CtrlList* cl = icl->second;
// Add will replace if found.
cl->add(frame, val);
return;
}
//---------------------------------------------------------
// volume
//---------------------------------------------------------
double AudioTrack::volume() const
{
ciCtrlList cl = _controller.find(AC_VOLUME);
if (cl == _controller.end())
return 0.0;
if (automation &&
automationType() != AUTO_OFF && _volumeEnCtrl && _volumeEn2Ctrl )
return cl->second->value(song->cPos().frame());
else
return cl->second->curVal();
}
//---------------------------------------------------------
// setVolume
//---------------------------------------------------------
void AudioTrack::setVolume(double val)
{
iCtrlList cl = _controller.find(AC_VOLUME);
if (cl == _controller.end()) {
printf("no volume controller %s %zd\n",
name().toLatin1().constData(), _controller.size());
return;
}
cl->second->setCurVal(val);
}
//---------------------------------------------------------
// pan
//---------------------------------------------------------
double AudioTrack::pan() const
{
ciCtrlList cl = _controller.find(AC_PAN);
if (cl == _controller.end())
return 0.0;
if (automation &&
automationType() != AUTO_OFF && _panEnCtrl && _panEn2Ctrl )
return cl->second->value(song->cPos().frame());
else
return cl->second->curVal();
}
//---------------------------------------------------------
// setPan
//---------------------------------------------------------
void AudioTrack::setPan(double val)
{
iCtrlList cl = _controller.find(AC_PAN);
if (cl == _controller.end()) {
printf("no pan controller\n");
return;
}
cl->second->setCurVal(val);
}
//---------------------------------------------------------
// pluginCtrlVal
//---------------------------------------------------------
double AudioTrack::pluginCtrlVal(int ctlID) const
{
ciCtrlList cl = _controller.find(ctlID);
if (cl == _controller.end())
return 0.0;
if (automation && (automationType() != AUTO_OFF))
return cl->second->value(song->cPos().frame());
else
return cl->second->curVal();
}
//---------------------------------------------------------
// setPluginCtrlVal
//---------------------------------------------------------
void AudioTrack::setPluginCtrlVal(int param, double val)
{
iCtrlList cl = _controller.find(param);
if (cl == _controller.end())
return;
cl->second->setCurVal(val);
}
void AudioTrack::recordAutomation(int n, double v)
{
if(!automation)
return;
if(audio->isPlaying())
_recEvents.push_back(CtrlRecVal(song->cPos().frame(), n, v));
else
{
if(automationType() == AUTO_WRITE)
_recEvents.push_back(CtrlRecVal(song->cPos().frame(), n, v));
else
if(automationType() == AUTO_TOUCH)
// In touch mode and not playing. Send directly to controller list.
{
iCtrlList cl = _controller.find(n);
if (cl == _controller.end())
return;
// Add will replace if found.
cl->second->add(song->cPos().frame(), v);
}
}
}
void AudioTrack::startAutoRecord(int n, double v)
{
if(!automation)
return;
if(audio->isPlaying())
{
if(automationType() == AUTO_TOUCH)
_recEvents.push_back(CtrlRecVal(song->cPos().frame(), n, v, ARVT_START));
else
if(automationType() == AUTO_WRITE)
_recEvents.push_back(CtrlRecVal(song->cPos().frame(), n, v));
}
else
{
if(automationType() == AUTO_TOUCH)
// In touch mode and not playing. Send directly to controller list.
{
iCtrlList cl = _controller.find(n);
if (cl == _controller.end())
return;
// Add will replace if found.
cl->second->add(song->cPos().frame(), v);
}
else
if(automationType() == AUTO_WRITE)
_recEvents.push_back(CtrlRecVal(song->cPos().frame(), n, v));
}
}
void AudioTrack::stopAutoRecord(int n, double v)
{
if(!automation)
return;
if(audio->isPlaying())
{
if(automationType() == AUTO_TOUCH)
{
audio->msgAddACEvent(this, n, song->cPos().frame(), v);
_recEvents.push_back(CtrlRecVal(song->cPos().frame(), n, v, ARVT_STOP));
}
}
}
//---------------------------------------------------------
// AudioTrack::writeProperties
//---------------------------------------------------------
void AudioTrack::writeProperties(int level, Xml& xml) const
{
Track::writeProperties(level, xml);
xml.intTag(level, "prefader", prefader());
xml.intTag(level, "sendMetronome", sendMetronome());
xml.intTag(level, "automation", int(automationType()));
if (hasAuxSend()) {
int naux = song->auxs()->size();
for (int idx = 0; idx < naux; ++idx) {
//QString s("<auxSend idx=%1>%2</auxSend>\n");
QString s("<auxSend idx=\"%1\">%2</auxSend>\n"); // Aux fix from Remon, thanks.
xml.nput(level, s.arg(idx).arg(_auxSend[idx]).toAscii().constData());
}
}
for (ciPluginI ip = _efxPipe->begin(); ip != _efxPipe->end(); ++ip) {
if (*ip)
(*ip)->writeConfiguration(level, xml);
}
for (ciCtrlList icl = _controller.begin(); icl != _controller.end(); ++icl) {
const CtrlList* cl = icl->second;
QString s= QString("controller id=\"%1\" cur=\"%2\"").arg(cl->id()).arg(cl->curVal()).toAscii().constData();
s += QString(" color=\"%1\" visible=\"%2\"").arg(cl->color().name()).arg(cl->isVisible());
xml.tag(level++, s.toAscii().constData());
int i = 0;
for (ciCtrl ic = cl->begin(); ic != cl->end(); ++ic) {
QString s("%1 %2, ");
xml.nput(level, s.arg(ic->second.frame).arg(ic->second.val).toAscii().constData());
++i;
if (i >= 4) {
xml.put(level, "");
i = 0;
}
}
if (i)
xml.put(level, "");
xml.etag(level--, "controller");
}
}
//---------------------------------------------------------
// readAuxSend
//---------------------------------------------------------
void AudioTrack::readAuxSend(Xml& xml)
{
unsigned idx = 0;
double val;
for (;;) {
Xml::Token token = xml.parse();
const QString& tag = xml.s1();
switch (token) {
case Xml::Error:
case Xml::End:
return;
case Xml::Attribut:
if (tag == "idx")
idx = xml.s2().toInt();
break;
case Xml::Text:
val = tag.toDouble();
break;
case Xml::TagEnd:
if (xml.s1() == "auxSend") {
if (_auxSend.size() < idx+1)
_auxSend.push_back(val);
else
_auxSend[idx] = val;
return;
}
default:
break;
}
}
}
//---------------------------------------------------------
// AudioTrack::readProperties
//---------------------------------------------------------
bool AudioTrack::readProperties(Xml& xml, const QString& tag)
{
if (tag == "plugin")
{
int rackpos;
for(rackpos = 0; rackpos < PipelineDepth; ++rackpos)
{
if(!(*_efxPipe)[rackpos])
break;
}
if(rackpos < PipelineDepth)
{
PluginI* pi = new PluginI();
pi->setTrack(this);
pi->setID(rackpos);
if(pi->readConfiguration(xml, false))
delete pi;
else
(*_efxPipe)[rackpos] = pi;
}
else
printf("can't load plugin - plugin rack is already full\n");
}
else if (tag == "auxSend")
readAuxSend(xml);
else if (tag == "prefader")
_prefader = xml.parseInt();
else if (tag == "sendMetronome")
_sendMetronome = xml.parseInt();
else if (tag == "automation")
setAutomationType(AutomationType(xml.parseInt()));
// Removed by T356
// "recfile" tag not saved anymore
//else if (tag == "recfile")
// readRecfile(xml);
else if (tag == "controller") {
CtrlList* l = new CtrlList();
l->read(xml);
// Since (until now) muse wrote a 'zero' for plugin controller current value
// in the XML file, we can't use that value, now that plugin automation is added.
// We must take the value from the plugin control value.
// Otherwise we break all existing .med files with plugins, because the gui
// controls would all be set to zero.
// But we will allow for the (unintended, useless) possibility of a controller
// with no matching plugin control.
PluginI* p = 0;
bool ctlfound = false;
int m = l->id() & AC_PLUGIN_CTL_ID_MASK;
int n = (l->id() >> AC_PLUGIN_CTL_BASE_POW) - 1;
if(n >= 0 && n < PipelineDepth)
{
p = (*_efxPipe)[n];
if(p && m < p->parameters())
ctlfound = true;
}
iCtrlList icl = _controller.find(l->id());
if (icl == _controller.end())
_controller.add(l);
else {
CtrlList* d = icl->second;
for (iCtrl i = l->begin(); i != l->end(); ++i)
d->insert(std::pair<const int, CtrlVal> (i->first, i->second));
if(!ctlfound)
d->setCurVal(l->curVal());
d->setColor(l->color());
d->setVisible(l->isVisible());
d->setDefault(l->getDefault());
delete l;
l = d;
}
if(ctlfound)
{
l->setCurVal(p->param(m));
LADSPA_PortRangeHint range = p->range(m);
if(LADSPA_IS_HINT_TOGGLED(range.HintDescriptor))
l->setMode(CtrlList::DISCRETE);
else
l->setMode(CtrlList::INTERPOLATE);
}
}
else
return Track::readProperties(xml, tag);
return false;
}
//---------------------------------------------------------
// showPendingPluginNativeGuis
// This is needed because OSC needs all tracks with plugins to be already
// added to their track lists so it can find them and show their native guis.
//---------------------------------------------------------
void AudioTrack::showPendingPluginNativeGuis()
{
for(int idx = 0; idx < PipelineDepth; ++idx)
{
PluginI* p = (*_efxPipe)[idx];
if(!p)
continue;
if(p->isShowNativeGuiPending())
p->showNativeGui(true);
}
}
//---------------------------------------------------------
// mapRackPluginsToControllers
//---------------------------------------------------------
void AudioTrack::mapRackPluginsToControllers()
{
// Iterate all possible plugin controller indexes...
for(int idx = PipelineDepth - 1; idx >= 0; idx--)
{
iCtrlList icl = _controller.lower_bound((idx + 1) * AC_PLUGIN_CTL_BASE);
if(icl == _controller.end() || ((icl->second->id() >> AC_PLUGIN_CTL_BASE_POW) - 1) != idx)
continue;
// We found some controllers with that index. Now iterate the plugin rack...
for(int i = idx; i >= 0; i--)
{
PluginI* p = (*_efxPipe)[i];
if(!p)
continue;
// We found a plugin at a rack position. If the rack position is not the same as the controller index...
if(i != idx)
{
(*_efxPipe)[i] = 0;
(*_efxPipe)[idx] = p;
}
p->setID(idx);
// It is now safe to update the controllers.
p->updateControllers();
break;
}
}
// No matter of the outcome of the above - rack position is not too critical -
// making sure that each control has a controller is important. Otherwise they
// are stuck at zero can't be adjusted.
// Muse med files created before the automation patches (before 0.9pre1) may have broken
// controller sections, so this will allow more tolerance of them.
for(int idx = 0; idx < PipelineDepth; idx++)
{
PluginI* p = (*_efxPipe)[idx];
if(!p)
continue;
if(p->id() != idx)
p->setID(idx);
int j = p->parameters();
for(int i = 0; i < j; i++)
{
int id = genACnum(idx, i);
CtrlList* l = 0;
ciCtrlList icl = _controller.find(id);
if(icl == _controller.end())
{
l = new CtrlList(id);
addController(l);
}
else
l = icl->second;
// Force all of these now, even though they may have already been set. With a pre-
// 0.9pre1 med file with broken controller sections they may not be set correct.
float min, max;
p->range(i, &min, &max);
CtrlValueType t = p->valueType();
l->setRange(min, max);
l->setName(QString(p->paramName(i)));
l->setValueType(t);
LADSPA_PortRangeHint rh = p->range(i);
if(LADSPA_IS_HINT_TOGGLED(rh.HintDescriptor))
l->setMode(CtrlList::DISCRETE);
else
l->setMode(CtrlList::INTERPOLATE);
l->setCurVal(p->param(i));
//l->setDefault(p->defaultValue(i));
}
}
// The loop is a safe way to delete while iterating 'non-linear' lists.
bool loop;
do
{
loop = false;
for(ciCtrlList icl = _controller.begin(); icl != _controller.end(); ++icl)
{
CtrlList* l = icl->second;
int id = l->id();
// Ignore volume, pan, mute etc.
if(id < AC_PLUGIN_CTL_BASE)
continue;
int param = id & AC_PLUGIN_CTL_ID_MASK;
int idx = (id >> AC_PLUGIN_CTL_BASE_POW) - 1;
PluginI* p = (*_efxPipe)[idx];
// If there's no plugin at that rack position, or the param is out of range of
// the number of controls in the plugin, then it's a stray controller. Delete it.
// Future: Leave room for possible bypass controller at AC_PLUGIN_CTL_ID_MASK -1.
//if(!p || (param >= p->parameters() && (param != AC_PLUGIN_CTL_ID_MASK -1)))
if(!p || (param >= p->parameters()))
{
_controller.erase(id);
loop = true;
break;
}
}
}
while (loop);
// Although this tested OK, and is the 'official' way to erase while iterating,
// I don't trust it. I'm weary of this method. The technique didn't work
// in Audio::msgRemoveTracks(), see comments there.
/*
// Now delete any stray controllers which don't belong to anything.
for(iCtrlList icl = _controller.begin(); icl != _controller.end(); )
{
CtrlList* l = icl->second;
int id = l->id();
// Ignore volume, pan, mute etc.
if(id < AC_PLUGIN_CTL_BASE)
{
++icl;
continue;
}
int param = id & AC_PLUGIN_CTL_ID_MASK;
int idx = (id >> AC_PLUGIN_CTL_BASE_POW) - 1;
PluginI* p = (*_efxPipe)[idx];
// If there's no plugin at that rack position, or the param is out of range of
// the number of controls in the plugin, then it's a stray controller. Delete it.
// Future: Leave room for possible bypass controller at AC_PLUGIN_CTL_ID_MASK -1.
//if(!p || (param >= p->parameters() && (param != AC_PLUGIN_CTL_ID_MASK -1)))
if(!p || (param >= p->parameters()))
_controller.erase(icl++);
else
++icl;
}
*/
}
/*
//---------------------------------------------------------
// writeRouting
//---------------------------------------------------------
void AudioTrack::writeRouting(int level, Xml& xml) const
{
QString n;
if (type() == Track::AUDIO_INPUT) {
ciJackRouteNameCache circ = jackRouteNameCache.find(this);
if(circ != jackRouteNameCache.end())
{
jackRouteNameMap rm = circ->second;
for(ciJackRouteNameMap cirm = rm.begin(); cirm != rm.end(); ++cirm)
{
n = cirm->second;
if(!n.isEmpty())
{
Route dst(name(), true, cirm->first);
xml.tag(level++, "Route");
xml.strTag(level, "srcNode", n);
xml.strTag(level, "dstNode", dst.name());
xml.etag(level--, "Route");
}
}
}
}
if(type() == Track::AUDIO_OUTPUT)
{
ciJackRouteNameCache circ = jackRouteNameCache.find(this);
if(circ != jackRouteNameCache.end())
{
jackRouteNameMap rm = circ->second;
for(ciJackRouteNameMap cirm = rm.begin(); cirm != rm.end(); ++cirm)
{
n = cirm->second;
if(!n.isEmpty())
{
Route src(name(), false, cirm->first);
xml.tag(level++, "Route");
xml.strTag(level, "srcNode", src.name());
xml.strTag(level, "dstNode", n);
xml.etag(level--, "Route");
}
}
}
}
else
{
const RouteList* rl = &_outRoutes;
for (ciRoute r = rl->begin(); r != rl->end(); ++r) {
if(!r->name().isEmpty())
{
xml.tag(level++, "Route");
xml.strTag(level, "srcNode", name());
xml.strTag(level, "dstNode", r->name());
xml.etag(level--, "Route");
}
}
}
}
*/
//---------------------------------------------------------
// AudioInput
//---------------------------------------------------------
AudioInput::AudioInput()
: AudioTrack(AUDIO_INPUT)
{
// set Default for Input Ports:
_mute = true;
//setVolume(1.0);
for (int i = 0; i < MAX_CHANNELS; ++i)
jackPorts[i] = 0;
//_channels = 0;
//setChannels(2);
}
//AudioInput::AudioInput(const AudioInput& t)
// : AudioTrack(t)
AudioInput::AudioInput(const AudioInput& t, bool cloneParts)
: AudioTrack(t, cloneParts)
{
for (int i = 0; i < MAX_CHANNELS; ++i)
jackPorts[i] = t.jackPorts[i];
}
//---------------------------------------------------------
// ~AudioInput
//---------------------------------------------------------
AudioInput::~AudioInput()
{
if (!checkAudioDevice()) return;
for (int i = 0; i < _channels; ++i)
if(jackPorts[i])
audioDevice->unregisterPort(jackPorts[i]);
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void AudioInput::write(int level, Xml& xml) const
{
xml.tag(level++, "AudioInput");
AudioTrack::writeProperties(level, xml);
xml.etag(level, "AudioInput");
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void AudioInput::read(Xml& xml)
{
for (;;) {
Xml::Token token = xml.parse();
const QString& tag = xml.s1();
switch (token) {
case Xml::Error:
case Xml::End:
return;
case Xml::TagStart:
if (AudioTrack::readProperties(xml, tag))
xml.unknown("AudioInput");
break;
case Xml::Attribut:
break;
case Xml::TagEnd:
if (tag == "AudioInput") {
setName(name()); // allocate jack ports
mapRackPluginsToControllers();
return;
}
default:
break;
}
}
}
//---------------------------------------------------------
// AudioOutput
//---------------------------------------------------------
AudioOutput::AudioOutput()
: AudioTrack(AUDIO_OUTPUT)
{
for (int i = 0; i < MAX_CHANNELS; ++i)
jackPorts[i] = 0;
//_channels = 0;
//setChannels(2);
}
//AudioOutput::AudioOutput(const AudioOutput& t)
// : AudioTrack(t)
AudioOutput::AudioOutput(const AudioOutput& t, bool cloneParts)
: AudioTrack(t, cloneParts)
{
for (int i = 0; i < MAX_CHANNELS; ++i)
jackPorts[i] = t.jackPorts[i];
_nframes = t._nframes;
}
//---------------------------------------------------------
// ~AudioOutput
//---------------------------------------------------------
AudioOutput::~AudioOutput()
{
if (!checkAudioDevice()) return;
for (int i = 0; i < _channels; ++i)
if(jackPorts[i])
audioDevice->unregisterPort(jackPorts[i]);
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void AudioOutput::write(int level, Xml& xml) const
{
xml.tag(level++, "AudioOutput");
AudioTrack::writeProperties(level, xml);
xml.etag(level, "AudioOutput");
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void AudioOutput::read(Xml& xml)
{
for (;;) {
Xml::Token token = xml.parse();
const QString& tag = xml.s1();
switch (token) {
case Xml::Error:
case Xml::End:
return;
case Xml::TagStart:
if (AudioTrack::readProperties(xml, tag))
xml.unknown("AudioOutput");
break;
case Xml::Attribut:
break;
case Xml::TagEnd:
if (tag == "AudioOutput") {
setName(name()); // allocate jack ports
mapRackPluginsToControllers();
return;
}
default:
break;
}
}
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void AudioGroup::write(int level, Xml& xml) const
{
xml.tag(level++, "AudioGroup");
AudioTrack::writeProperties(level, xml);
xml.etag(level, "AudioGroup");
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void AudioGroup::read(Xml& xml)
{
for (;;) {
Xml::Token token = xml.parse();
const QString& tag = xml.s1();
switch (token) {
case Xml::Error:
case Xml::End:
return;
case Xml::TagStart:
if (AudioTrack::readProperties(xml, tag))
xml.unknown("AudioGroup");
break;
case Xml::Attribut:
break;
case Xml::TagEnd:
if (tag == "AudioGroup")
{
mapRackPluginsToControllers();
return;
}
default:
break;
}
}
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void AudioAux::write(int level, Xml& xml) const
{
xml.tag(level++, "AudioAux");
AudioTrack::writeProperties(level, xml);
xml.etag(level, "AudioAux");
}
//---------------------------------------------------------
// AudioAux
//---------------------------------------------------------
AudioAux::AudioAux()
: AudioTrack(AUDIO_AUX)
{
//_channels = 0;
//setChannels(2);
// Changed by Tim. p3.3.15
//for (int i = 0; i < MAX_CHANNELS; ++i)
// buffer[i] = (i < channels()) ? new float[segmentSize] : 0;
for(int i = 0; i < MAX_CHANNELS; ++i)
{
if(i < channels())
posix_memalign((void**)(buffer + i), 16, sizeof(float) * segmentSize);
else
buffer[i] = 0;
}
}
//---------------------------------------------------------
// AudioAux
//---------------------------------------------------------
AudioAux::~AudioAux()
{
// Changed by Tim. p3.3.15
//for (int i = 0; i < channels(); ++i)
// delete[] buffer[i];
for (int i = 0; i < MAX_CHANNELS; ++i) {
if (buffer[i])
free(buffer[i]);
}
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void AudioAux::read(Xml& xml)
{
for (;;) {
Xml::Token token = xml.parse();
const QString& tag = xml.s1();
switch (token) {
case Xml::Error:
case Xml::End:
return;
case Xml::TagStart:
if (AudioTrack::readProperties(xml, tag))
xml.unknown("AudioAux");
break;
case Xml::Attribut:
break;
case Xml::TagEnd:
if (tag == "AudioAux")
{
mapRackPluginsToControllers();
return;
}
default:
break;
}
}
}
//---------------------------------------------------------
// getData
//---------------------------------------------------------
bool AudioAux::getData(unsigned /*pos*/, int ch, unsigned /*samples*/, float** data)
{
for (int i = 0; i < ch; ++i)
data[i] = buffer[i % channels()];
return true;
}
//---------------------------------------------------------
// setChannels
//---------------------------------------------------------
void AudioAux::setChannels(int n)
{
if(n > channels())
{
// Changed by Tim. p3.3.15
//for (int i = channels(); i < n; ++i)
// buffer[i] = new float[segmentSize];
for(int i = channels(); i < n; ++i)
posix_memalign((void**)(buffer + i), 16, sizeof(float) * segmentSize);
}
else if(n < channels())
{
// Changed by Tim. p3.3.15
//for (int i = n; i < channels(); ++i)
// delete[] buffer[i];
for(int i = n; i < channels(); ++i)
{
if(buffer[i])
free(buffer[i]);
}
}
AudioTrack::setChannels(n);
}
//---------------------------------------------------------
// setRecordFlag1
// gui part (executed in gui thread)
//---------------------------------------------------------
bool AudioTrack::setRecordFlag1(bool f)
{
if (f == _recordFlag)
return true;
if (f) {
// do nothing
if (_recFile == 0 && song->record()) {
// this rec-enables a track if the global arm already was done
// the standard case would be that rec-enable be done there
prepareRecording();
}
}
else {
if (_recFile) {
// this file has not been processed and can be
// deleted
// We should only arrive here if going from a 'record-armed' state
// to a non record-armed state. Because otherwise after actually
// recording, the _recFile pointer is made into an event,
// then _recFile is made zero before this function is called.
QString s = _recFile->path();
// Added by Tim. p3.3.8
delete _recFile;
setRecFile(0);
remove(s.toLatin1().constData());
if(debugMsg)
printf("AudioNode::setRecordFlag1: remove file %s if it exists\n", s.toLatin1().constData());
//_recFile = 0;
}
}
return true;
}
//---------------------------------------------------------
// prepareRecording
// normally called from song->setRecord to defer creating
// wave files until MusE is globally rec-enabled
// also called from track->setRecordFlag (above)
// if global rec enable already was done
//---------------------------------------------------------
bool AudioTrack::prepareRecording()
{
if(debugMsg)
printf("prepareRecording for track %s\n", _name.toLatin1().constData());
if (_recFile == 0) {
//
// create soundfile for recording
//
char buffer[128];
QFile fil;
for (;;++recFileNumber) {
sprintf(buffer, "%s/rec%d.wav",
museProject.toLatin1().constData(),
recFileNumber);
fil.setFileName(QString(buffer));
if (!fil.exists())
break;
}
_recFile = new SndFile(QString(buffer));
_recFile->setFormat(
SF_FORMAT_WAV | SF_FORMAT_FLOAT,
_channels, sampleRate);
}
if (debugMsg)
printf("AudioNode::setRecordFlag1: init internal file %s\n", _recFile->path().toLatin1().constData());
if(_recFile->openWrite())
{
QMessageBox::critical(NULL, "MusE write error.", "Error creating target wave file\n"
"Check your configuration.");
return false;
}
return true;
}
double AudioTrack::auxSend(int idx) const
{
if (unsigned(idx) >= _auxSend.size()) {
printf("%s auxSend: bad index: %d >= %zd\n",
name().toLatin1().constData(), idx, _auxSend.size());
return 0.0;
}
return _auxSend[idx];
}
void AudioTrack::setAuxSend(int idx, double v)
{
if (unsigned(idx) >= _auxSend.size()) {
printf("%s setAuxSend: bad index: %d >= %zd\n",
name().toLatin1().constData(), idx, _auxSend.size());
return;
}
_auxSend[idx] = v;
}
|