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
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
|
//=========================================================
// MusE
// Linux Music Editor
// $Id: song.cpp,v 1.59.2.52 2009/12/15 03:39:58 terminator356 Exp $
//
// (C) Copyright 2000-2004 Werner Schweer (ws@seh.de)
//=========================================================
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <qapplication.h>
#include <qmessagebox.h>
#include <q3popupmenu.h>
#include <qdir.h>
#include <qaction.h>
#include <qcursor.h>
#include <qpoint.h>
//#include <qbutton.h>
//Added by qt3to4:
#include <Q3TextStream>
#include "app.h"
#include "driver/jackmidi.h"
#include "driver/alsamidi.h"
#include "song.h"
#include "track.h"
#include "undo.h"
#include "key.h"
#include "globals.h"
#include "event.h"
#include "drummap.h"
#include "marker/marker.h"
#include "synth.h"
#include "audio.h"
#include "mididev.h"
#include "amixer.h"
#include "midiseq.h"
#include "audiodev.h"
#include "gconfig.h"
#include "sync.h"
#include "midictrl.h"
#include "menutitleitem.h"
#include "midi.h"
#include "sig.h"
#include <sys/wait.h>
extern void clearMidiTransforms();
extern void clearMidiInputTransforms();
Song* song;
/*
//---------------------------------------------------------
// RoutingMenuItem
//---------------------------------------------------------
class RoutingMenuItem : public QCustomMenuItem
{
Route route;
//virtual QSize sizeHint() { return QSize(80, h); }
virtual void paint(QPainter* p, const QColorGroup&, bool, bool, int x, int y, int w, int h)
{
p->fillRect(x, y, w, h, QBrush(lightGray));
p->drawText(x, y, w, h, AlignCenter, route.name());
}
public:
RoutingMenuItem(const Route& r) : route(r) { }
};
*/
//---------------------------------------------------------
// Song
//---------------------------------------------------------
Song::Song(const char* name)
:QObject(0, name)
{
_recRaster = 0; // Set to measure, the same as Arranger intial value. Arranger snap combo will set this.
noteFifoSize = 0;
noteFifoWindex = 0;
noteFifoRindex = 0;
undoList = new UndoList;
redoList = new UndoList;
_markerList = new MarkerList;
_globalPitchShift = 0;
clear(false);
}
//---------------------------------------------------------
// Song
//---------------------------------------------------------
Song::~Song()
{
delete undoList;
delete redoList;
delete _markerList;
}
//---------------------------------------------------------
// putEvent
//---------------------------------------------------------
void Song::putEvent(int pv)
{
if (noteFifoSize < REC_NOTE_FIFO_SIZE) {
recNoteFifo[noteFifoWindex] = pv;
noteFifoWindex = (noteFifoWindex + 1) % REC_NOTE_FIFO_SIZE;
++noteFifoSize;
}
}
//---------------------------------------------------------
// setTempo
// public slot
//---------------------------------------------------------
void Song::setTempo(int newTempo)
{
audio->msgSetTempo(pos[0].tick(), newTempo, true);
}
//---------------------------------------------------------
// setSig
// called from transport window
//---------------------------------------------------------
void Song::setSig(int z, int n)
{
if (_masterFlag) {
audio->msgAddSig(pos[0].tick(), z, n);
}
}
//---------------------------------------------------------
// addNewTrack
// Called from GUI context
// Besides normal track types, n includes synth menu ids from populateAddTrack()
//---------------------------------------------------------
Track* Song::addNewTrack(int n)
{
// Ignore negative numbers since this slot could be called by a menu or list etc. passing -1.
if(n < 0)
return 0;
// Synth sub-menu id?
if(n >= MENU_ADD_SYNTH_ID_BASE)
{
n -= MENU_ADD_SYNTH_ID_BASE;
if(n < (int)synthis.size())
{
//SynthI* si = createSynthI(synthis[n]->baseName());
//SynthI* si = createSynthI(synthis[n]->name());
SynthI* si = createSynthI(synthis[n]->baseName(), synthis[n]->name());
if(!si)
return 0;
// Add instance last in midi device list.
for (int i = 0; i < MIDI_PORTS; ++i)
{
MidiPort* port = &midiPorts[i];
MidiDevice* dev = port->device();
if (dev==0)
{
midiSeq->msgSetMidiDevice(port, si);
muse->changeConfig(true); // save configuration file
deselectTracks();
si->setSelected(true);
update();
return si;
}
}
deselectTracks();
si->setSelected(true);
update(SC_SELECTION);
return si;
}
else
return 0;
}
// Normal track.
else
{
// Ignore AUDIO_SOFTSYNTH, now that we have it as the synth menu id, since addTrack doesn't like it.
if((Track::TrackType)n == Track::AUDIO_SOFTSYNTH)
return 0;
Track* t = addTrack((Track::TrackType)n);
deselectTracks();
t->setSelected(true);
update(SC_SELECTION);
return t;
}
}
//---------------------------------------------------------
// addTrack
// called from GUI context
//---------------------------------------------------------
Track* Song::addTrack(int t)
{
Track::TrackType type = (Track::TrackType) t;
Track* track = 0;
int lastAuxIdx = _auxs.size();
switch(type) {
case Track::MIDI:
track = new MidiTrack();
track->setType(Track::MIDI);
break;
case Track::DRUM:
track = new MidiTrack();
track->setType(Track::DRUM);
((MidiTrack*)track)->setOutChannel(9);
break;
case Track::WAVE:
track = new WaveTrack();
((AudioTrack*)track)->addAuxSend(lastAuxIdx);
break;
case Track::AUDIO_OUTPUT:
track = new AudioOutput();
break;
case Track::AUDIO_GROUP:
track = new AudioGroup();
((AudioTrack*)track)->addAuxSend(lastAuxIdx);
break;
case Track::AUDIO_AUX:
track = new AudioAux();
break;
case Track::AUDIO_INPUT:
track = new AudioInput();
((AudioTrack*)track)->addAuxSend(lastAuxIdx);
break;
case Track::AUDIO_SOFTSYNTH:
printf("not implemented: Song::addTrack(SOFTSYNTH)\n");
// ((AudioTrack*)track)->addAuxSend(lastAuxIdx);
break;
default:
printf("Song::addTrack() illegal type %d\n", type);
abort();
}
track->setDefaultName();
insertTrack1(track, -1);
msgInsertTrack(track, -1, true);
insertTrack3(track, -1);
//
// add default route to master
//
OutputList* ol = song->outputs();
if (!ol->empty()) {
AudioOutput* ao = ol->front();
switch(type) {
case Track::MIDI:
case Track::DRUM:
case Track::AUDIO_OUTPUT:
break;
case Track::WAVE:
case Track::AUDIO_GROUP:
case Track::AUDIO_AUX:
case Track::AUDIO_INPUT:
// p3.3.38
//case Track::AUDIO_SOFTSYNTH:
audio->msgAddRoute(Route((AudioTrack*)track, -1), Route(ao, -1));
updateFlags |= SC_ROUTE;
break;
// p3.3.38 It should actually never get here now, but just in case.
case Track::AUDIO_SOFTSYNTH:
audio->msgAddRoute(Route((AudioTrack*)track, 0, ((AudioTrack*)track)->channels()), Route(ao, 0, ((AudioTrack*)track)->channels()));
updateFlags |= SC_ROUTE;
break;
}
}
audio->msgUpdateSoloStates();
return track;
}
//---------------------------------------------------------
// cmdRemoveTrack
//---------------------------------------------------------
void Song::cmdRemoveTrack(Track* track)
{
int idx = _tracks.index(track);
undoOp(UndoOp::DeleteTrack, idx, track);
removeTrack2(track);
updateFlags |= SC_TRACK_REMOVED;
}
//---------------------------------------------------------
// removeMarkedTracks
//---------------------------------------------------------
void Song::removeMarkedTracks()
{
bool loop;
do {
loop = false;
for (iTrack t = _tracks.begin(); t != _tracks.end(); ++t) {
if ((*t)->selected()) {
removeTrack2(*t);
loop = true;
break;
}
}
} while (loop);
}
//---------------------------------------------------------
// deselectTracks
//---------------------------------------------------------
void Song::deselectTracks()
{
for (iTrack t = _tracks.begin(); t != _tracks.end(); ++t)
(*t)->setSelected(false);
}
//---------------------------------------------------------
// changeTrack
// oldTrack - copy of the original track befor modification
// newTrack - modified original track
//---------------------------------------------------------
void Song::changeTrack(Track* oldTrack, Track* newTrack)
{
oldTrack->setSelected(false); //??
int idx = _tracks.index(newTrack);
//undoOp(UndoOp::ModifyTrack, oldTrack, newTrack);
undoOp(UndoOp::ModifyTrack, idx, oldTrack, newTrack);
updateFlags |= SC_TRACK_MODIFIED;
}
//---------------------------------------------------------
// addEvent
// return true if event was added
//---------------------------------------------------------
bool Song::addEvent(Event& event, Part* part)
{
/*
if (event.type() == Controller) {
MidiTrack* track = (MidiTrack*)part->track();
int ch = track->outChannel();
int tick = event.tick() + part->tick();
int cntrl = event.dataA();
int val = event.dataB();
MidiPort* mp = &midiPorts[track->outPort()];
// Is it a drum controller event, according to the track port's instrument?
if(track->type() == Track::DRUM)
{
MidiController* mc = mp->drumController(cntrl);
if(mc)
{
int note = cntrl & 0x7f;
cntrl &= ~0xff;
ch = drumMap[note].channel;
mp = &midiPorts[drumMap[note].port];
cntrl |= drumMap[note].anote;
}
}
// Changed by T356.
//if (!mp->setCtrl(ch, tick, cntrl, val)) {
// mp->addManagedController(ch, cntrl);
// if (!mp->setCtrl(ch, tick, cntrl, val))
// return false;
// }
// Changed again. Don't depend on return value of this - search for the event, below.
//if(!mp->setControllerVal(ch, tick, cntrl, val, part))
// return false;
if(mp->setControllerVal(ch, tick, cntrl, val, part))
updateFlags |= SC_MIDI_CONTROLLER;
}
*/
//addPortCtrlEvents(event, part);
// Return false if the event is already found.
// (But allow a port controller value, above, in case it is not already stored.)
if(part->events()->find(event) != part->events()->end())
{
// This can be normal for some (redundant) operations.
if(debugMsg)
printf("Song::addEvent event already found in part:%s size:%zd\n", part->name().latin1(), part->events()->size());
return false;
}
part->events()->add(event);
return true;
}
//---------------------------------------------------------
// changeEvent
//---------------------------------------------------------
void Song::changeEvent(Event& oldEvent, Event& newEvent, Part* part)
{
iEvent i = part->events()->find(oldEvent);
if (i == part->events()->end()) {
// This can be normal for some (redundant) operations.
if(debugMsg)
printf("Song::changeEvent event not found in part:%s size:%zd\n", part->name().latin1(), part->events()->size());
// abort();
// Removed by T356. Allow it to add the new event.
// (And remove the old one from the midi port controller!)
//return;
}
else
part->events()->erase(i);
part->events()->add(newEvent);
/*
if (oldEvent.type() == Controller) {
MidiTrack* track = (MidiTrack*)part->track();
int ch = track->outChannel();
int tick = oldEvent.tick() + part->tick();
int cntrl = oldEvent.dataA();
MidiPort* mp = &midiPorts[track->outPort()];
// Is it a drum controller event, according to the track port's instrument?
if(track->type() == Track::DRUM)
{
MidiController* mc = mp->drumController(cntrl);
if(mc)
{
int note = cntrl & 0x7f;
cntrl &= ~0xff;
ch = drumMap[note].channel;
mp = &midiPorts[drumMap[note].port];
cntrl |= drumMap[note].anote;
}
}
mp->deleteController(ch, tick, cntrl, part);
}
*/
//removePortCtrlEvents(oldEvent, part);
/*
if (newEvent.type() == Controller) {
MidiTrack* track = (MidiTrack*)part->track();
int ch = track->outChannel();
int tick = newEvent.tick() + part->tick();
int cntrl = newEvent.dataA();
int val = newEvent.dataB();
MidiPort* mp = &midiPorts[track->outPort()];
// Is it a drum controller event, according to the track port's instrument?
if(track->type() == Track::DRUM)
{
MidiController* mc = mp->drumController(cntrl);
if(mc)
{
int note = cntrl & 0x7f;
cntrl &= ~0xff;
ch = drumMap[note].channel;
mp = &midiPorts[drumMap[note].port];
cntrl |= drumMap[note].anote;
}
}
mp->setControllerVal(ch, tick, cntrl, val, part);
}
*/
//addPortCtrlEvents(newEvent, part);
}
//---------------------------------------------------------
// deleteEvent
//---------------------------------------------------------
void Song::deleteEvent(Event& event, Part* part)
{
/*
if (event.type() == Controller) {
MidiTrack* track = (MidiTrack*)part->track();
int ch = track->outChannel();
int tick = event.tick() + part->tick();
int cntrl = event.dataA();
MidiPort* mp = &midiPorts[track->outPort()];
// Is it a drum controller event, according to the track port's instrument?
if(track->type() == Track::DRUM)
{
MidiController* mc = mp->drumController(cntrl);
if(mc)
{
int note = cntrl & 0x7f;
cntrl &= ~0xff;
ch = drumMap[note].channel;
mp = &midiPorts[drumMap[note].port];
cntrl |= drumMap[note].anote;
}
}
mp->deleteController(ch, tick, cntrl, part);
}
*/
//removePortCtrlEvents(event, part);
iEvent ev = part->events()->find(event);
if (ev == part->events()->end()) {
// This can be normal for some (redundant) operations.
if(debugMsg)
printf("Song::deleteEvent event not found in part:%s size:%zd\n", part->name().latin1(), part->events()->size());
return;
}
part->events()->erase(ev);
}
//---------------------------------------------------------
// remapPortDrumCtrlEvents
// Called when drum map anote, channel, or port is changed.
//---------------------------------------------------------
void Song::remapPortDrumCtrlEvents(int mapidx, int newnote, int newchan, int newport)
{
if(mapidx == -1)
return;
for(ciMidiTrack it = _midis.begin(); it != _midis.end(); ++it)
{
MidiTrack* mt = *it;
if(mt->type() != Track::DRUM)
continue;
MidiPort* trackmp = &midiPorts[mt->outPort()];
const PartList* pl = mt->cparts();
for(ciPart ip = pl->begin(); ip != pl->end(); ++ip)
{
MidiPart* part = (MidiPart*)(ip->second);
const EventList* el = part->cevents();
unsigned len = part->lenTick();
for(ciEvent ie = el->begin(); ie != el->end(); ++ie)
{
const Event& ev = ie->second;
// Added by T356. Do not handle events which are past the end of the part.
if(ev.tick() >= len)
break;
if(ev.type() != Controller)
continue;
int cntrl = ev.dataA();
// Is it a drum controller event, according to the track port's instrument?
MidiController* mc = trackmp->drumController(cntrl);
if(!mc)
continue;
int note = cntrl & 0x7f;
// Does the index match?
if(note == mapidx)
{
int tick = ev.tick() + part->tick();
int ch = drumMap[note].channel;
int port = drumMap[note].port;
MidiPort* mp = &midiPorts[port];
cntrl = (cntrl & ~0xff) | drumMap[note].anote;
// Remove the port controller value.
mp->deleteController(ch, tick, cntrl, part);
if(newnote != -1 && newnote != drumMap[note].anote)
cntrl = (cntrl & ~0xff) | newnote;
if(newchan != -1 && newchan != ch)
ch = newchan;
if(newport != -1 && newport != port)
port = newport;
mp = &midiPorts[port];
// Add the port controller value.
mp->setControllerVal(ch, tick, cntrl, ev.dataB(), part);
}
}
}
}
}
//---------------------------------------------------------
// changeAllPortDrumCtlEvents
// add true: add events. false: remove events
// drumonly true: Do drum controller events ONLY. false (default): Do ALL controller events.
//---------------------------------------------------------
void Song::changeAllPortDrumCtrlEvents(bool add, bool drumonly)
{
int ch, trackch, cntrl, tick;
MidiPort* mp, *trackmp;
for(ciMidiTrack it = _midis.begin(); it != _midis.end(); ++it)
{
MidiTrack* mt = *it;
if(mt->type() != Track::DRUM)
continue;
trackmp = &midiPorts[mt->outPort()];
trackch = mt->outChannel();
const PartList* pl = mt->cparts();
for(ciPart ip = pl->begin(); ip != pl->end(); ++ip)
{
MidiPart* part = (MidiPart*)(ip->second);
const EventList* el = part->cevents();
unsigned len = part->lenTick();
for(ciEvent ie = el->begin(); ie != el->end(); ++ie)
{
const Event& ev = ie->second;
// Added by T356. Do not handle events which are past the end of the part.
if(ev.tick() >= len)
break;
if(ev.type() != Controller)
continue;
cntrl = ev.dataA();
mp = trackmp;
ch = trackch;
// Is it a drum controller event, according to the track port's instrument?
if(trackmp->drumController(cntrl))
{
int note = cntrl & 0x7f;
ch = drumMap[note].channel;
mp = &midiPorts[drumMap[note].port];
cntrl = (cntrl & ~0xff) | drumMap[note].anote;
}
else
{
if(drumonly)
continue;
}
tick = ev.tick() + part->tick();
if(add)
// Add the port controller value.
mp->setControllerVal(ch, tick, cntrl, ev.dataB(), part);
else
// Remove the port controller value.
mp->deleteController(ch, tick, cntrl, part);
}
}
}
}
//---------------------------------------------------------
// cmdAddRecordedEvents
// add recorded Events into part
//---------------------------------------------------------
void Song::cmdAddRecordedEvents(MidiTrack* mt, EventList* events, unsigned startTick)
{
if (events->empty()) {
if (debugMsg)
printf("no events recorded\n");
return;
}
iEvent s;
iEvent e;
unsigned endTick;
// Changed by Tim. p3.3.8
//if (punchin())
if((audio->loopCount() > 0 && startTick > lPos().tick()) || (punchin() && startTick < lPos().tick()))
{
startTick = lpos();
s = events->lower_bound(startTick);
}
else
{
s = events->begin();
// startTick = s->first;
}
// Changed by Tim. p3.3.8
//if (punchout())
//{
// endTick = rpos();
// e = events->lower_bound(endTick);
//}
//else
//{
// search for last noteOff:
endTick = 0;
for (iEvent i = events->begin(); i != events->end(); ++i) {
Event ev = i->second;
unsigned l = ev.endTick();
if (l > endTick)
endTick = l;
}
// e = events->end();
//}
if((audio->loopCount() > 0) || (punchout() && endTick > rPos().tick()) )
{
endTick = rpos();
e = events->lower_bound(endTick);
}
else
e = events->end();
if (startTick > endTick) {
if (debugMsg)
printf("no events in record area\n");
return;
}
//---------------------------------------------------
// if startTick points into a part,
// record to that part
// else
// create new part
//---------------------------------------------------
PartList* pl = mt->parts();
MidiPart* part = 0;
iPart ip;
for (ip = pl->begin(); ip != pl->end(); ++ip) {
part = (MidiPart*)(ip->second);
unsigned partStart = part->tick();
unsigned partEnd = part->endTick();
if (startTick >= partStart && startTick < partEnd)
break;
}
if (ip == pl->end()) {
if (debugMsg)
printf("create new part for recorded events\n");
// create new part
part = new MidiPart(mt);
// Changed by Tim. p3.3.8
// Honour the Arranger snap settings. (Set to bar by default).
//startTick = roundDownBar(startTick);
//endTick = roundUpBar(endTick);
// Round the start down using the Arranger part snap raster value.
startTick = sigmap.raster1(startTick, recRaster());
// Round the end up using the Arranger part snap raster value.
endTick = sigmap.raster2(endTick, recRaster());
part->setTick(startTick);
part->setLenTick(endTick - startTick);
part->setName(mt->name());
// copy events
for (iEvent i = s; i != e; ++i) {
Event old = i->second;
Event event = old.clone();
event.setTick(old.tick() - startTick);
// addEvent also adds port controller values. So does msgAddPart, below. Let msgAddPart handle them.
//addEvent(event, part);
if(part->events()->find(event) == part->events()->end())
part->events()->add(event);
}
audio->msgAddPart(part);
updateFlags |= SC_PART_INSERTED;
return;
}
updateFlags |= SC_EVENT_INSERTED;
unsigned partTick = part->tick();
if (endTick > part->endTick()) {
// Determine new part length...
endTick = 0;
for (iEvent i = s; i != e; ++i) {
Event event = i->second;
unsigned tick = event.tick() - partTick + event.lenTick();
if (endTick < tick)
endTick = tick;
}
// Added by Tim. p3.3.8
// Round the end up (again) using the Arranger part snap raster value.
endTick = sigmap.raster2(endTick, recRaster());
// Remove all of the part's port controller values. Indicate do not do clone parts.
removePortCtrlEvents(part, false);
// Clone the part. This doesn't increment aref count, and doesn't chain clones.
// It also gives the new part a new serial number, but it is
// overwritten with the old one by Song::changePart(), below.
Part* newPart = part->clone();
// Set the new part's length.
newPart->setLenTick(endTick);
// Change the part.
changePart(part, newPart);
// Manually adjust reference counts.
part->events()->incARef(-1);
newPart->events()->incARef(1);
// Replace the part in the clone chain with the new part.
replaceClone(part, newPart);
// Now add all of the new part's port controller values. Indicate do not do clone parts.
addPortCtrlEvents(newPart, false);
// Create an undo op. Indicate do port controller values but not clone parts.
undoOp(UndoOp::ModifyPart, part, newPart, true, false);
updateFlags |= SC_PART_MODIFIED;
if (_recMode == REC_REPLACE)
{
iEvent si = newPart->events()->lower_bound(startTick - newPart->tick());
iEvent ei = newPart->events()->lower_bound(newPart->endTick() - newPart->tick());
for (iEvent i = si; i != ei; ++i)
{
Event event = i->second;
// Create an undo op. Indicate do port controller values and clone parts.
undoOp(UndoOp::DeleteEvent, event, newPart, true, true);
// Remove the event from the new part's port controller values, and do all clone parts.
removePortCtrlEvents(event, newPart, true);
}
newPart->events()->erase(si, ei);
}
for (iEvent i = s; i != e; ++i) {
Event event = i->second;
event.setTick(event.tick() - partTick);
Event e;
// Create an undo op. Indicate do port controller values and clone parts.
undoOp(UndoOp::AddEvent, e, event, newPart, true, true);
if(newPart->events()->find(event) == newPart->events()->end())
newPart->events()->add(event);
// Add the event to the new part's port controller values, and do all clone parts.
addPortCtrlEvents(event, newPart, true);
}
/*
if (_recMode == REC_REPLACE)
{
iEvent si = part->events()->lower_bound(startTick - part->tick());
iEvent ei = part->events()->lower_bound(part->endTick() - part->tick());
for (iEvent i = si; i != ei; ++i)
{
Event event = i->second;
// Create an undo op. Indicate do port controller values and clone parts.
//undoOp(UndoOp::DeleteEvent, event, part);
undoOp(UndoOp::DeleteEvent, event, part, true, true);
//if (event.type() == Controller) {
// MidiTrack* track = (MidiTrack*)part->track();
// int ch = track->outChannel();
// int tick = event.tick() + part->tick();
// int cntrl = event.dataA();
// midiPorts[track->outPort()].deleteController(ch, tick, cntrl, part);
// }
// Remove the event from the part's port controller values, and do all clone parts.
//removePortCtrlEvents(event, part, true);
}
part->events()->erase(si, ei);
}
// Remove all of the part's port controller values, and do all clone parts.
removePortCtrlEvents(part, true);
// Clone the part. This doesn't increment aref count, and doesn't chain clones.
// It also gives the new part a new serial number, but it is
// overwritten with the old one by Song::changePart(), below.
Part* newPart = part->clone();
endTick = 0;
for (iEvent i = s; i != e; ++i) {
Event event = i->second;
unsigned tick = event.tick() - partTick;
event.setTick(tick);
Event e;
// Create an undo op. Indicate do port controller values and clone parts.
//undoOp(UndoOp::AddEvent, e, event, newPart);
undoOp(UndoOp::AddEvent, e, event, newPart, true, true);
// addEvent also adds port controller values. So does msgChangePart, below. Let msgChangePart handle them.
//addEvent(event, (MidiPart*)newPart);
if(newPart->events()->find(event) == newPart->events()->end())
newPart->events()->add(event);
if (endTick < event.tick() + event.lenTick())
endTick = event.tick() + event.lenTick();
}
newPart->setLenTick(endTick); // endTick - part->tick()
//printf("Song::cmdAddRecordedEvents before changePart part:%p events:%p refs:%d Arefs:%d newPart:%p events:%p refs:%d Arefs:%d\n", part, part->events(), part->events()->refCount(), part->events()->arefCount(), newPart, newPart->events(), newPart->events()->refCount(), newPart->events()->arefCount());
// Change the part.
changePart(part, newPart);
// Manually adjust reference counts.
part->events()->incARef(-1);
newPart->events()->incARef(1);
// Replace the part in the clone chain with the new part.
replaceClone(part, newPart);
// Now add all of the new part's port controller values, and do all clone parts.
addPortCtrlEvents(newPart, true);
//printf("Song::cmdAddRecordedEvents after changePart part:%p events:%p refs:%d Arefs:%d newPart:%p events:%p refs:%d Arefs:%d\n", part, part->events(), part->events()->refCount(), part->events()->arefCount(), newPart, newPart->events(), newPart->events()->refCount(), newPart->events()->arefCount());
//undoOp(UndoOp::ModifyPart, part, newPart);
// Create an undo op. Indicate do not do port controller values and clone parts.
undoOp(UndoOp::ModifyPart, part, newPart, false, false);
// Removed by T356.
//part->events()->incARef(-1);
updateFlags |= SC_PART_MODIFIED;
//printf("Song::cmdAddRecordedEvents final part:%p events:%p refs:%d Arefs:%d newPart:%p events:%p refs:%d Arefs:%d\n", part, part->events(), part->events()->refCount(), part->events()->arefCount(), newPart, newPart->events(), newPart->events()->refCount(), newPart->events()->arefCount());
*/
}
else {
if (_recMode == REC_REPLACE) {
iEvent si = part->events()->lower_bound(startTick - part->tick());
iEvent ei = part->events()->lower_bound(endTick - part->tick());
for (iEvent i = si; i != ei; ++i) {
Event event = i->second;
// Create an undo op. Indicate that controller values and clone parts were handled.
//undoOp(UndoOp::DeleteEvent, event, part);
undoOp(UndoOp::DeleteEvent, event, part, true, true);
/*
if (event.type() == Controller) {
MidiTrack* track = (MidiTrack*)part->track();
int ch = track->outChannel();
int tick = event.tick() + part->tick();
int cntrl = event.dataA();
midiPorts[track->outPort()].deleteController(ch, tick, cntrl, part);
}
*/
// Remove the event from the part's port controller values, and do all clone parts.
removePortCtrlEvents(event, part, true);
}
part->events()->erase(si, ei);
}
for (iEvent i = s; i != e; ++i) {
Event event = i->second;
int tick = event.tick() - partTick;
event.setTick(tick);
// Create an undo op. Indicate that controller values and clone parts were handled.
//undoOp(UndoOp::AddEvent, event, part);
undoOp(UndoOp::AddEvent, event, part, true, true);
//addEvent(event, part);
if(part->events()->find(event) == part->events()->end())
part->events()->add(event);
// Add the event to the part's port controller values, and do all clone parts.
addPortCtrlEvents(event, part, true);
}
}
}
//---------------------------------------------------------
// findTrack
//---------------------------------------------------------
MidiTrack* Song::findTrack(const Part* part) const
{
for (ciTrack t = _tracks.begin(); t != _tracks.end(); ++t) {
MidiTrack* track = dynamic_cast<MidiTrack*>(*t);
if (track == 0)
continue;
PartList* pl = track->parts();
for (iPart p = pl->begin(); p != pl->end(); ++p) {
if (part == p->second)
return track;
}
}
return 0;
}
//---------------------------------------------------------
// findTrack
// find track by name
//---------------------------------------------------------
Track* Song::findTrack(const QString& name) const
{
for (ciTrack i = _tracks.begin(); i != _tracks.end(); ++i) {
if ((*i)->name() == name)
return *i;
}
return 0;
}
//---------------------------------------------------------
// setLoop
// set transport loop flag
//---------------------------------------------------------
void Song::setLoop(bool f)
{
if (loopFlag != f) {
loopFlag = f;
loopAction->setOn(loopFlag);
emit loopChanged(loopFlag);
}
}
//---------------------------------------------------------
// clearTrackRec
//---------------------------------------------------------
void Song::clearTrackRec()
{
for (iTrack it = tracks()->begin(); it != tracks()->end(); ++it)
setRecordFlag(*it,false);
}
//---------------------------------------------------------
// setRecord
//---------------------------------------------------------
void Song::setRecord(bool f, bool autoRecEnable)
{
if (recordFlag != f) {
if (f && autoRecEnable) {
bool alreadyRecEnabled = false;
Track *selectedTrack = 0;
// loop through list and check if any track is rec enabled
// if not then rec enable the selected track
WaveTrackList* wtl = waves();
for (iWaveTrack i = wtl->begin(); i != wtl->end(); ++i) {
if((*i)->recordFlag())
{
alreadyRecEnabled = true;
break;
}
if((*i)->selected())
selectedTrack = (*i);
}
if (!alreadyRecEnabled) {
MidiTrackList* mtl = midis();
for (iMidiTrack it = mtl->begin(); it != mtl->end(); ++it) {
if((*it)->recordFlag())
{
alreadyRecEnabled = true;
break;
}
if((*it)->selected())
selectedTrack = (*it);
}
}
if (!alreadyRecEnabled && selectedTrack) {
setRecordFlag(selectedTrack, true);
}
else if (alreadyRecEnabled) {
// do nothing
}
else {
// if there are no tracks, do not enable record
if (!waves()->size() && !midis()->size()) {
printf("No track to select, won't enable record\n");
f = false;
}
}
#if 0
// check for midi devices suitable for recording
bool portFound = false;
for (int i = 0; i < MIDI_PORTS; ++i) {
MidiDevice* dev = midiPorts[i].device();
if (dev && (dev->rwFlags() & 0x2))
portFound = true;
}
if (!portFound) {
QMessageBox::critical(qApp->mainWidget(), "MusE: Record",
"There are no midi devices configured for recording");
f = false;
}
#endif
}
else {
bounceTrack = 0;
}
if (audio->isPlaying() && f)
f = false;
recordFlag = f;
recordAction->setOn(recordFlag);
emit recordChanged(recordFlag);
}
}
//---------------------------------------------------------
// setPunchin
// set punchin flag
//---------------------------------------------------------
void Song::setPunchin(bool f)
{
if (punchinFlag != f) {
punchinFlag = f;
punchinAction->setOn(punchinFlag);
emit punchinChanged(punchinFlag);
}
}
//---------------------------------------------------------
// setPunchout
// set punchout flag
//---------------------------------------------------------
void Song::setPunchout(bool f)
{
if (punchoutFlag != f) {
punchoutFlag = f;
punchoutAction->setOn(punchoutFlag);
emit punchoutChanged(punchoutFlag);
}
}
//---------------------------------------------------------
// setClick
//---------------------------------------------------------
void Song::setClick(bool val)
{
if (_click != val) {
_click = val;
emit clickChanged(_click);
}
}
//---------------------------------------------------------
// setQuantize
//---------------------------------------------------------
void Song::setQuantize(bool val)
{
if (_quantize != val) {
_quantize = val;
emit quantizeChanged(_quantize);
}
}
//---------------------------------------------------------
// setMasterFlag
//---------------------------------------------------------
void Song::setMasterFlag(bool val)
{
_masterFlag = val;
if (tempomap.setMasterFlag(cpos(), val))
{
//audioDevice->setMaster(val);
emit songChanged(SC_MASTER);
}
// Removed. p3.3.26
//audioDevice->setMaster(val);
}
//---------------------------------------------------------
// setPlay
// set transport play flag
//---------------------------------------------------------
void Song::setPlay(bool f)
{
if (extSyncFlag.value()) {
if (debugMsg)
printf("not allowed while using external sync");
return;
}
// only allow the user to set the button "on"
if (!f)
playAction->setOn(true);
else
audio->msgPlay(true);
}
void Song::setStop(bool f)
{
if (extSyncFlag.value()) {
if (debugMsg)
printf("not allowed while using external sync");
return;
}
// only allow the user to set the button "on"
if (!f)
stopAction->setOn(true);
else
audio->msgPlay(false);
}
void Song::setStopPlay(bool f)
{
playAction->blockSignals(true);
stopAction->blockSignals(true);
emit playChanged(f); // signal transport window
playAction->setOn(f);
stopAction->setOn(!f);
stopAction->blockSignals(false);
playAction->blockSignals(false);
}
//---------------------------------------------------------
// swapTracks
//---------------------------------------------------------
void Song::swapTracks(int i1, int i2)
{
undoOp(UndoOp::SwapTrack, i1, i2);
Track* track = _tracks[i1];
_tracks[i1] = _tracks[i2];
_tracks[i2] = track;
}
//---------------------------------------------------------
// setPos
// song->setPos(Song::CPOS, pos, true, true, true);
//---------------------------------------------------------
void Song::setPos(int idx, const Pos& val, bool sig,
bool isSeek, bool adjustScrollbar)
{
// printf("setPos %d sig=%d,seek=%d,scroll=%d ",
// idx, sig, isSeek, adjustScrollbar);
// val.dump(0);
// printf("\n");
// p3.3.23
//printf("Song::setPos before audio->msgSeek idx:%d isSeek:%d frame:%d\n", idx, isSeek, val.frame());
if (pos[idx] == val)
return;
if (idx == CPOS) {
_vcpos = val;
if (isSeek && !extSyncFlag.value()) {
audio->msgSeek(val);
// p3.3.23
//printf("Song::setPos after audio->msgSeek idx:%d isSeek:%d frame:%d\n", idx, isSeek, val.frame());
return;
}
}
pos[idx] = val;
bool swap = pos[LPOS] > pos[RPOS];
if (swap) { // swap lpos/rpos if lpos > rpos
Pos tmp = pos[LPOS];
pos[LPOS] = pos[RPOS];
pos[RPOS] = tmp;
}
if (sig) {
if (swap) {
emit posChanged(LPOS, pos[LPOS].tick(), adjustScrollbar);
emit posChanged(RPOS, pos[RPOS].tick(), adjustScrollbar);
if (idx != LPOS && idx != RPOS)
emit posChanged(idx, pos[idx].tick(), adjustScrollbar);
}
else
emit posChanged(idx, pos[idx].tick(), adjustScrollbar);
}
if (idx == CPOS) {
iMarker i1 = _markerList->begin();
iMarker i2 = i1;
bool currentChanged = false;
for (; i1 != _markerList->end(); ++i1) {
++i2;
if (val.tick() >= i1->first && (i2==_markerList->end() || val.tick() < i2->first)) {
if (i1->second.current())
return;
i1->second.setCurrent(true);
if (currentChanged) {
emit markerChanged(MARKER_CUR);
return;
}
++i1;
for (; i1 != _markerList->end(); ++i1) {
if (i1->second.current())
i1->second.setCurrent(false);
}
emit markerChanged(MARKER_CUR);
return;
}
else {
if (i1->second.current()) {
currentChanged = true;
i1->second.setCurrent(false);
}
}
}
if (currentChanged)
emit markerChanged(MARKER_CUR);
}
}
//---------------------------------------------------------
// forward
//---------------------------------------------------------
void Song::forward()
{
unsigned newPos = pos[0].tick() + config.division;
audio->msgSeek(Pos(newPos, true));
}
//---------------------------------------------------------
// rewind
//---------------------------------------------------------
void Song::rewind()
{
unsigned newPos;
if (unsigned(config.division) > pos[0].tick())
newPos = 0;
else
newPos = pos[0].tick() - config.division;
audio->msgSeek(Pos(newPos, true));
}
//---------------------------------------------------------
// rewindStart
//---------------------------------------------------------
void Song::rewindStart()
{
// Added by T356
//audio->msgIdle(true);
audio->msgSeek(Pos(0, true));
// Added by T356
//audio->msgIdle(false);
}
//---------------------------------------------------------
// update
//---------------------------------------------------------
void Song::update(int flags)
{
static int level = 0; // DEBUG
if (level) {
printf("Song::update %08x, level %d\n", flags, level);
return;
}
++level;
emit songChanged(flags);
--level;
}
//---------------------------------------------------------
// updatePos
//---------------------------------------------------------
void Song::updatePos()
{
emit posChanged(0, pos[0].tick(), false);
emit posChanged(1, pos[1].tick(), false);
emit posChanged(2, pos[2].tick(), false);
}
//---------------------------------------------------------
// setChannelMute
// mute all midi tracks associated with channel
//---------------------------------------------------------
void Song::setChannelMute(int channel, bool val)
{
for (iTrack i = _tracks.begin(); i != _tracks.end(); ++i) {
MidiTrack* track = dynamic_cast<MidiTrack*>(*i);
if (track == 0)
continue;
if (track->outChannel() == channel)
track->setMute(val);
}
emit songChanged(SC_MUTE);
}
//---------------------------------------------------------
// len
//---------------------------------------------------------
void Song::initLen()
{
_len = sigmap.bar2tick(40, 0, 0); // default song len
for (iTrack t = _tracks.begin(); t != _tracks.end(); ++t) {
MidiTrack* track = dynamic_cast<MidiTrack*>(*t);
if (track == 0)
continue;
PartList* parts = track->parts();
for (iPart p = parts->begin(); p != parts->end(); ++p) {
unsigned last = p->second->tick() + p->second->lenTick();
if (last > _len)
_len = last;
}
}
_len = roundUpBar(_len);
}
//---------------------------------------------------------
// tempoChanged
//---------------------------------------------------------
void Song::tempoChanged()
{
emit songChanged(SC_TEMPO);
}
//---------------------------------------------------------
// roundUpBar
//---------------------------------------------------------
int Song::roundUpBar(int t) const
{
int bar, beat;
unsigned tick;
sigmap.tickValues(t, &bar, &beat, &tick);
if (beat || tick)
return sigmap.bar2tick(bar+1, 0, 0);
return t;
}
//---------------------------------------------------------
// roundUpBeat
//---------------------------------------------------------
int Song::roundUpBeat(int t) const
{
int bar, beat;
unsigned tick;
sigmap.tickValues(t, &bar, &beat, &tick);
if (tick)
return sigmap.bar2tick(bar, beat+1, 0);
return t;
}
//---------------------------------------------------------
// roundDownBar
//---------------------------------------------------------
int Song::roundDownBar(int t) const
{
int bar, beat;
unsigned tick;
sigmap.tickValues(t, &bar, &beat, &tick);
return sigmap.bar2tick(bar, 0, 0);
}
//---------------------------------------------------------
// dumpMaster
//---------------------------------------------------------
void Song::dumpMaster()
{
tempomap.dump();
sigmap.dump();
}
//---------------------------------------------------------
// getSelectedParts
//---------------------------------------------------------
PartList* Song::getSelectedMidiParts() const
{
PartList* parts = new PartList();
//------------------------------------------------------
// wenn ein Part selektiert ist, diesen editieren
// wenn ein Track selektiert ist, den Ersten
// Part des Tracks editieren, die restlichen sind
// 'ghostparts'
// wenn mehrere Parts selektiert sind, dann Ersten
// editieren, die restlichen sind 'ghostparts'
//
// Rough translation:
/*
If a part is selected, edit that.
If a track is selected, edit the first
part of the track, the rest are
'ghost parts'
When multiple parts are selected, then edit the first,
the rest are 'ghost parts'
*/
// collect marked parts
for (ciMidiTrack t = _midis.begin(); t != _midis.end(); ++t) {
MidiTrack* track = *t;
PartList* pl = track->parts();
for (iPart p = pl->begin(); p != pl->end(); ++p) {
if (p->second->selected()) {
parts->add(p->second);
}
}
}
// if no part is selected, then search for selected track
// and collect all parts of this track
if (parts->empty()) {
for (ciTrack t = _tracks.begin(); t != _tracks.end(); ++t) {
if ((*t)->selected()) {
MidiTrack* track = dynamic_cast<MidiTrack*>(*t);
if (track == 0)
continue;
PartList* pl = track->parts();
for (iPart p = pl->begin(); p != pl->end(); ++p)
parts->add(p->second);
break;
}
}
}
return parts;
}
PartList* Song::getSelectedWaveParts() const
{
PartList* parts = new PartList();
//------------------------------------------------------
// wenn ein Part selektiert ist, diesen editieren
// wenn ein Track selektiert ist, den Ersten
// Part des Tracks editieren, die restlichen sind
// 'ghostparts'
// wenn mehrere Parts selektiert sind, dann Ersten
// editieren, die restlichen sind 'ghostparts'
//
// markierte Parts sammeln
for (ciTrack t = _tracks.begin(); t != _tracks.end(); ++t) {
WaveTrack* track = dynamic_cast<WaveTrack*>(*t);
if (track == 0)
continue;
PartList* pl = track->parts();
for (iPart p = pl->begin(); p != pl->end(); ++p) {
if (p->second->selected()) {
parts->add(p->second);
}
}
}
// wenn keine Parts selektiert, dann markierten Track suchen
// und alle Parts dieses Tracks zusammensuchen
if (parts->empty()) {
for (ciTrack t = _tracks.begin(); t != _tracks.end(); ++t) {
if ((*t)->selected()) {
WaveTrack* track = dynamic_cast<WaveTrack*>(*t);
if (track == 0)
continue;
PartList* pl = track->parts();
for (iPart p = pl->begin(); p != pl->end(); ++p)
parts->add(p->second);
break;
}
}
}
return parts;
}
void Song::setMType(MType t)
{
// printf("set MType %d\n", t);
_mtype = t;
}
//---------------------------------------------------------
// beat
//---------------------------------------------------------
void Song::beat()
{
// Keep the sync detectors running...
for(int port = 0; port < MIDI_PORTS; ++port)
{
// Must keep them running even if there's no device...
//if(midiPorts[port].device())
midiPorts[port].syncInfo().setTime();
}
int tick = audio->tickPos();
if (audio->isPlaying())
setPos(0, tick, true, false, true);
// p3.3.40 Update synth native guis at the heartbeat rate.
for(ciSynthI is = _synthIs.begin(); is != _synthIs.end(); ++is)
(*is)->guiHeartBeat();
while (noteFifoSize) {
int pv = recNoteFifo[noteFifoRindex];
noteFifoRindex = (noteFifoRindex + 1) % REC_NOTE_FIFO_SIZE;
int pitch = (pv >> 8) & 0xff;
int velo = pv & 0xff;
//---------------------------------------------------
// filter midi remote control events
//---------------------------------------------------
if (rcEnable && velo != 0) {
if (pitch == rcStopNote)
setStop(true);
else if (pitch == rcRecordNote)
setRecord(true);
else if (pitch == rcGotoLeftMarkNote)
setPos(0, pos[LPOS].tick(), true, true, true);
else if (pitch == rcPlayNote)
setPlay(true);
}
emit song->midiNote(pitch, velo);
--noteFifoSize;
}
}
//---------------------------------------------------------
// setLen
//---------------------------------------------------------
void Song::setLen(unsigned l)
{
_len = l;
update();
}
//---------------------------------------------------------
// addMarker
//---------------------------------------------------------
Marker* Song::addMarker(const QString& s, int t, bool lck)
{
Marker* marker = _markerList->add(s, t, lck);
emit markerChanged(MARKER_ADD);
return marker;
}
//---------------------------------------------------------
// addMarker
//---------------------------------------------------------
Marker* Song::getMarkerAt(int t)
{
iMarker markerI;
for (markerI=_markerList->begin(); markerI != _markerList->end(); ++markerI) {
// if (i1->second.current())
if (unsigned(t) == markerI->second.tick())//prevent of copmiler warning: comparison signed/unsigned
return &markerI->second;
}
//Marker* marker = _markerList->add(s, t, lck);
return NULL;
}
//---------------------------------------------------------
// removeMarker
//---------------------------------------------------------
void Song::removeMarker(Marker* marker)
{
_markerList->remove(marker);
emit markerChanged(MARKER_REMOVE);
}
Marker* Song::setMarkerName(Marker* m, const QString& s)
{
m->setName(s);
emit markerChanged(MARKER_NAME);
return m;
}
Marker* Song::setMarkerTick(Marker* m, int t)
{
Marker mm(*m);
_markerList->remove(m);
mm.setTick(t);
m = _markerList->add(mm);
emit markerChanged(MARKER_TICK);
return m;
}
Marker* Song::setMarkerLock(Marker* m, bool f)
{
m->setType(f ? Pos::FRAMES : Pos::TICKS);
emit markerChanged(MARKER_LOCK);
return m;
}
//---------------------------------------------------------
// setRecordFlag
//---------------------------------------------------------
void Song::setRecordFlag(Track* track, bool val)
{
if (track->type() == Track::WAVE) {
WaveTrack* audioTrack = (WaveTrack*)track;
if(!audioTrack->setRecordFlag1(val))
return;
audio->msgSetRecord(audioTrack, val);
}
else {
track->setRecordFlag1(val);
track->setRecordFlag2(val);
}
// updateFlags |= SC_RECFLAG;
update(SC_RECFLAG);
}
//---------------------------------------------------------
// rescanAlsaPorts
//---------------------------------------------------------
void Song::rescanAlsaPorts()
{
emit midiPortsChanged();
}
//---------------------------------------------------------
// endMsgCmd
//---------------------------------------------------------
void Song::endMsgCmd()
{
if (updateFlags) {
redoList->clear(); // TODO: delete elements in list
undoAction->setEnabled(true);
redoAction->setEnabled(false);
emit songChanged(updateFlags);
}
}
//---------------------------------------------------------
// undo
//---------------------------------------------------------
void Song::undo()
{
updateFlags = 0;
if (doUndo1())
return;
audio->msgUndo();
doUndo3();
redoAction->setEnabled(true);
undoAction->setEnabled(!undoList->empty());
if(updateFlags && (SC_TRACK_REMOVED | SC_TRACK_INSERTED))
audio->msgUpdateSoloStates();
emit songChanged(updateFlags);
}
//---------------------------------------------------------
// redo
//---------------------------------------------------------
void Song::redo()
{
updateFlags = 0;
if (doRedo1())
return;
audio->msgRedo();
doRedo3();
undoAction->setEnabled(true);
redoAction->setEnabled(!redoList->empty());
if(updateFlags && (SC_TRACK_REMOVED | SC_TRACK_INSERTED))
audio->msgUpdateSoloStates();
emit songChanged(updateFlags);
}
//---------------------------------------------------------
// processMsg
// executed in realtime thread context
//---------------------------------------------------------
void Song::processMsg(AudioMsg* msg)
{
switch(msg->id) {
case SEQM_UPDATE_SOLO_STATES:
updateSoloStates();
break;
case SEQM_UNDO:
doUndo2();
break;
case SEQM_REDO:
doRedo2();
break;
case SEQM_MOVE_TRACK:
if (msg->a > msg->b) {
for (int i = msg->a; i > msg->b; --i) {
swapTracks(i, i-1);
}
}
else {
for (int i = msg->a; i < msg->b; ++i) {
swapTracks(i, i+1);
}
}
updateFlags = SC_TRACK_MODIFIED;
break;
case SEQM_ADD_EVENT:
updateFlags = SC_EVENT_INSERTED;
if (addEvent(msg->ev1, (MidiPart*)msg->p2)) {
Event ev;
//undoOp(UndoOp::AddEvent, ev, msg->ev1, (Part*)msg->p2);
undoOp(UndoOp::AddEvent, ev, msg->ev1, (Part*)msg->p2, msg->a, msg->b);
}
else
updateFlags = 0;
if(msg->a)
addPortCtrlEvents(msg->ev1, (Part*)msg->p2, msg->b);
break;
case SEQM_REMOVE_EVENT:
{
Event event = msg->ev1;
MidiPart* part = (MidiPart*)msg->p2;
if(msg->a)
removePortCtrlEvents(event, part, msg->b);
Event e;
//undoOp(UndoOp::DeleteEvent, e, event, (Part*)part);
undoOp(UndoOp::DeleteEvent, e, event, (Part*)part, msg->a, msg->b);
deleteEvent(event, part);
updateFlags = SC_EVENT_REMOVED;
}
break;
case SEQM_CHANGE_EVENT:
if(msg->a)
removePortCtrlEvents(msg->ev1, (MidiPart*)msg->p3, msg->b);
changeEvent(msg->ev1, msg->ev2, (MidiPart*)msg->p3);
if(msg->a)
addPortCtrlEvents(msg->ev2, (Part*)msg->p3, msg->b);
//undoOp(UndoOp::ModifyEvent, msg->ev2, msg->ev1, (Part*)msg->p3);
undoOp(UndoOp::ModifyEvent, msg->ev2, msg->ev1, (Part*)msg->p3, msg->a, msg->b);
updateFlags = SC_EVENT_MODIFIED;
break;
case SEQM_ADD_TEMPO:
//printf("processMsg (SEQM_ADD_TEMPO) UndoOp::AddTempo. adding tempo at: %d with tempo=%d\n", msg->a, msg->b);
undoOp(UndoOp::AddTempo, msg->a, msg->b);
tempomap.addTempo(msg->a, msg->b);
updateFlags = SC_TEMPO;
break;
case SEQM_SET_TEMPO:
//printf("processMsg (SEQM_SET_TEMPO) UndoOp::AddTempo. adding tempo at: %d with tempo=%d\n", msg->a, msg->b);
undoOp(UndoOp::AddTempo, msg->a, msg->b);
tempomap.setTempo(msg->a, msg->b);
updateFlags = SC_TEMPO;
break;
case SEQM_SET_GLOBAL_TEMPO:
tempomap.setGlobalTempo(msg->a);
break;
case SEQM_REMOVE_TEMPO:
//printf("processMsg (SEQM_REMOVE_TEMPO) UndoOp::DeleteTempo. adding tempo at: %d with tempo=%d\n", msg->a, msg->b);
undoOp(UndoOp::DeleteTempo, msg->a, msg->b);
tempomap.delTempo(msg->a);
updateFlags = SC_TEMPO;
break;
case SEQM_ADD_SIG:
undoOp(UndoOp::AddSig, msg->a, msg->b, msg->c);
sigmap.add(msg->a, msg->b, msg->c);
updateFlags = SC_SIG;
break;
case SEQM_REMOVE_SIG:
undoOp(UndoOp::DeleteSig, msg->a, msg->b, msg->c);
sigmap.del(msg->a);
updateFlags = SC_SIG;
break;
default:
printf("unknown seq message %d\n", msg->id);
break;
}
}
//---------------------------------------------------------
// cmdAddPart
//---------------------------------------------------------
void Song::cmdAddPart(Part* part)
{
addPart(part);
undoOp(UndoOp::AddPart, part);
updateFlags = SC_PART_INSERTED;
}
//---------------------------------------------------------
// cmdRemovePart
//---------------------------------------------------------
void Song::cmdRemovePart(Part* part)
{
removePart(part);
undoOp(UndoOp::DeletePart, part);
part->events()->incARef(-1);
//part->unchainClone();
unchainClone(part);
updateFlags = SC_PART_REMOVED;
}
//---------------------------------------------------------
// cmdChangePart
//---------------------------------------------------------
//void Song::cmdChangePart(Part* oldPart, Part* newPart)
void Song::cmdChangePart(Part* oldPart, Part* newPart, bool doCtrls, bool doClones)
{
//printf("Song::cmdChangePart before changePart oldPart:%p events:%p refs:%d Arefs:%d sn:%d newPart:%p events:%p refs:%d Arefs:%d sn:%d\n", oldPart, oldPart->events(), oldPart->events()->refCount(), oldPart->events()->arefCount(), oldPart->sn(), newPart, newPart->events(), newPart->events()->refCount(), newPart->events()->arefCount(), newPart->sn());
if(doCtrls)
removePortCtrlEvents(oldPart, doClones);
changePart(oldPart, newPart);
//undoOp(UndoOp::ModifyPart, oldPart, newPart);
undoOp(UndoOp::ModifyPart, oldPart, newPart, doCtrls, doClones);
// Changed by T356. Do not decrement ref count if the new part is a clone of the old part, since the event list
// will still be active.
if(oldPart->cevents() != newPart->cevents())
oldPart->events()->incARef(-1);
//oldPart->replaceClone(newPart);
//printf("Song::cmdChangePart before repl/unchClone oldPart:%p events:%p refs:%d Arefs:%d sn:%d newPart:%p events:%p refs:%d Arefs:%d sn:%d\n", oldPart, oldPart->events(), oldPart->events()->refCount(), oldPart->events()->arefCount(), oldPart->sn(), newPart, newPart->events(), newPart->events()->refCount(), newPart->events()->arefCount(), newPart->sn());
replaceClone(oldPart, newPart);
if(doCtrls)
addPortCtrlEvents(newPart, doClones);
//printf("Song::cmdChangePart after repl/unchClone oldPart:%p events:%p refs:%d Arefs:%d sn:%d newPart:%p events:%p refs:%d Arefs:%d sn:%d\n", oldPart, oldPart->events(), oldPart->events()->refCount(), oldPart->events()->arefCount(), oldPart->sn(), newPart, newPart->events(), newPart->events()->refCount(), newPart->events()->arefCount(), newPart->sn());
updateFlags = SC_PART_MODIFIED;
}
//---------------------------------------------------------
// panic
//---------------------------------------------------------
void Song::panic()
{
audio->msgPanic();
}
//---------------------------------------------------------
// clear
// signal - emit signals for changes if true
// called from constructor as clear(false) and
// from MusE::clearSong() as clear(false)
//---------------------------------------------------------
void Song::clear(bool signal)
{
if(debugMsg)
printf("Song::clear\n");
bounceTrack = 0;
_tracks.clear();
_midis.clearDelete();
_waves.clearDelete();
_inputs.clearDelete(); // audio input ports
_outputs.clearDelete(); // audio output ports
_groups.clearDelete(); // mixer groups
_auxs.clearDelete(); // aux sends
// p3.3.45 Clear all midi port devices.
for(int i = 0; i < MIDI_PORTS; ++i)
{
// p3.3.50 Since midi ports are not deleted, clear all midi port in/out routes. They point to non-existant tracks now.
midiPorts[i].inRoutes()->clear();
midiPorts[i].outRoutes()->clear();
// p3.3.50 Reset this.
midiPorts[i].setFoundInSongFile(false);
// This will also close the device.
midiPorts[i].setMidiDevice(0);
}
_synthIs.clearDelete();
// p3.3.45 Make sure to delete Jack midi devices, and remove all ALSA midi device routes...
// Otherwise really nasty things happen when loading another song when one is already loaded.
// The loop is a safe way to delete while iterating.
bool loop;
do
{
loop = false;
for(iMidiDevice imd = midiDevices.begin(); imd != midiDevices.end(); ++imd)
{
//if((*imd)->deviceType() == MidiDevice::JACK_MIDI)
if(dynamic_cast< MidiJackDevice* >(*imd))
{
// Remove the device from the list.
midiDevices.erase(imd);
// Since Jack midi devices are created dynamically, we must delete them.
// The destructor unregisters the device from Jack, which also disconnects all device-to-jack routes.
// This will also delete all midi-track-to-device routes, they point to non-existant midi tracks
// which were all deleted above
delete (*imd);
loop = true;
break;
}
else
//if((*imd)->deviceType() == MidiDevice::ALSA_MIDI)
if(dynamic_cast< MidiAlsaDevice* >(*imd))
{
// With alsa devices, we must not delete them (they're always in the list). But we must
// clear all routes. They point to non-existant midi tracks, which were all deleted above.
(*imd)->inRoutes()->clear();
(*imd)->outRoutes()->clear();
}
}
}
while (loop);
tempomap.clear();
sigmap.clear();
undoList->clearDelete();
redoList->clear();
_markerList->clear();
pos[0].setTick(0);
pos[1].setTick(0);
pos[2].setTick(0);
_vcpos.setTick(0);
Track::clearSoloRefCounts();
clearMidiTransforms();
clearMidiInputTransforms();
// Clear all midi port controller values.
for(int i = 0; i < MIDI_PORTS; ++i)
// Don't remove the controllers, just the values.
midiPorts[i].controller()->clearDelete(false);
_masterFlag = true;
loopFlag = false;
loopFlag = false;
punchinFlag = false;
punchoutFlag = false;
recordFlag = false;
soloFlag = false;
// seq
_mtype = MT_UNKNOWN;
_recMode = REC_OVERDUP;
_cycleMode = CYCLE_NORMAL;
_click = false;
_quantize = false;
_len = 0; // song len in ticks
_follow = JUMP;
// _tempo = 500000; // default tempo 120
dirty = false;
initDrumMap();
if (signal) {
emit loopChanged(false);
recordChanged(false);
}
}
//---------------------------------------------------------
// cleanupForQuit
// called from Muse::closeEvent
//---------------------------------------------------------
void Song::cleanupForQuit()
{
bounceTrack = 0;
if(debugMsg)
printf("MusE: Song::cleanupForQuit...\n");
_tracks.clear();
if(debugMsg)
printf("deleting _midis\n");
_midis.clearDelete();
if(debugMsg)
printf("deleting _waves\n");
_waves.clearDelete();
if(debugMsg)
printf("deleting _inputs\n");
_inputs.clearDelete(); // audio input ports
if(debugMsg)
printf("deleting _outputs\n");
_outputs.clearDelete(); // audio output ports
if(debugMsg)
printf("deleting _groups\n");
_groups.clearDelete(); // mixer groups
if(debugMsg)
printf("deleting _auxs\n");
_auxs.clearDelete(); // aux sends
if(debugMsg)
printf("deleting _synthIs\n");
_synthIs.clearDelete(); // each ~SynthI() -> deactivate3() -> ~SynthIF()
tempomap.clear();
sigmap.clear();
if(debugMsg)
printf("deleting undoList, clearing redoList\n");
undoList->clearDelete();
redoList->clear(); // Check this - Should we do a clearDelete? IIRC it was OK this way - no clearDelete in case of same items in both lists.
_markerList->clear();
if(debugMsg)
printf("deleting transforms\n");
clearMidiTransforms(); // Deletes stuff.
clearMidiInputTransforms(); // Deletes stuff.
if(debugMsg)
printf("deleting midiport controllers\n");
// Clear all midi port controllers and values.
for(int i = 0; i < MIDI_PORTS; ++i)
// Remove the controllers and the values.
midiPorts[i].controller()->clearDelete(true);
// Can't do this here. Jack isn't running.
/*
if(debugMsg)
printf("deleting midi devices\n");
for(iMidiDevice imd = midiDevices.begin(); imd != midiDevices.end(); ++imd)
{
// Since Syntis are midi devices, there's no need to delete them below.
if((*imd)->isSynti())
continue;
delete (*imd);
}
midiDevices.clear(); // midi devices
*/
if(debugMsg)
printf("deleting synths\n");
// Delete all synths.
std::vector<Synth*>::iterator is;
for(is = synthis.begin(); is != synthis.end(); ++is)
{
Synth* s = *is;
if(s)
delete s;
}
synthis.clear();
// Nothing required for ladspa plugin list, and rack instances of them
// are handled by ~AudioTrack.
if(debugMsg)
printf("...finished cleaning up.\n");
}
//---------------------------------------------------------
// seqSignal
// sequencer message to GUI
// execution environment: gui thread
//---------------------------------------------------------
void Song::seqSignal(int fd)
{
char buffer[16];
int n = ::read(fd, buffer, 16);
if (n < 0) {
printf("Song: seqSignal(): READ PIPE failed: %s\n",
strerror(errno));
return;
}
for (int i = 0; i < n; ++i) {
// printf("seqSignal to gui:<%c>\n", buffer[i]);
switch(buffer[i]) {
case '0': // STOP
stopRolling();
break;
case '1': // PLAY
setStopPlay(true);
break;
case '2': // record
setRecord(true);
break;
case '3': // START_PLAY + jack STOP
abortRolling();
break;
case 'P': // alsa ports changed
rescanAlsaPorts();
break;
case 'G':
clearRecAutomation(true);
setPos(0, audio->tickPos(), true, false, true);
break;
case 'S': // shutdown audio
muse->seqStop();
{
// give the user a sensible explanation
int btn = QMessageBox::critical( muse, tr(QString("Jack shutdown!")),
tr(QString("Jack has detected a performance problem which has lead to\n"
"MusE being disconnected.\n"
"This could happen due to a number of reasons:\n"
"- a performance issue with your particular setup.\n"
"- a bug in MusE (or possibly in another connected software).\n"
"- a random hiccup which might never occur again.\n"
"- jack was voluntary stopped by you or someone else\n"
"- jack crashed\n"
"If there is a persisting problem you are much welcome to discuss it\n"
"on the MusE mailinglist.\n"
"(there is information about joining the mailinglist on the MusE\n"
" homepage which is available through the help menu)\n"
"\n"
"To proceed check the status of Jack and try to restart it and then .\n"
"click on the Restart button.")), "restart", "cancel");
if (btn == 0) {
printf("restarting!\n");
muse->seqRestart();
}
}
break;
case 'f': // start freewheel
if(debugMsg)
printf("Song: seqSignal: case f: setFreewheel start\n");
// Enabled by Tim. p3.3.6
if(config.freewheelMode)
audioDevice->setFreewheel(true);
break;
case 'F': // stop freewheel
if(debugMsg)
printf("Song: seqSignal: case F: setFreewheel stop\n");
// Enabled by Tim. p3.3.6
if(config.freewheelMode)
audioDevice->setFreewheel(false);
audio->msgPlay(false);
#if 0
if (record())
audio->recordStop();
setStopPlay(false);
#endif
break;
case 'C': // Graph changed
if (audioDevice)
audioDevice->graphChanged();
break;
// p3.3.37
case 'R': // Registration changed
if (audioDevice)
audioDevice->registrationChanged();
break;
default:
printf("unknown Seq Signal <%c>\n", buffer[i]);
break;
}
}
}
//---------------------------------------------------------
// recordEvent
//---------------------------------------------------------
void Song::recordEvent(MidiTrack* mt, Event& event)
{
//---------------------------------------------------
// if tick points into a part,
// record to that part
// else
// create new part
//---------------------------------------------------
unsigned tick = event.tick();
PartList* pl = mt->parts();
MidiPart* part = 0;
iPart ip;
for (ip = pl->begin(); ip != pl->end(); ++ip) {
part = (MidiPart*)(ip->second);
unsigned partStart = part->tick();
unsigned partEnd = partStart + part->lenTick();
if (tick >= partStart && tick < partEnd)
break;
}
updateFlags |= SC_EVENT_INSERTED;
if (ip == pl->end()) {
// create new part
part = new MidiPart(mt);
int startTick = roundDownBar(tick);
//int endTick = roundUpBar(tick);
int endTick = roundUpBar(tick + 1);
part->setTick(startTick);
part->setLenTick(endTick - startTick);
part->setName(mt->name());
event.move(-startTick);
part->events()->add(event);
audio->msgAddPart(part);
return;
}
part = (MidiPart*)(ip->second);
tick -= part->tick();
event.setTick(tick);
Event ev;
if(event.type() == Controller)
{
EventRange range = part->events()->equal_range(tick);
for(iEvent i = range.first; i != range.second; ++i)
{
ev = i->second;
// At the moment, Song::recordEvent() is only called by the 'Rec' buttons in the
// midi track info panel. So only controller types are fed to it. If other event types
// are to be passed, we will have to expand on this to check if equal. Instead, maybe add an isEqual() to Event class.
//if((ev.type() == Controller && event.type() == Controller || ev.type() == Controller && event.type() == Controller)
// && ev.dataA() == event.dataA() && ev.dataB() == event.dataB())
if(ev.type() == Controller && ev.dataA() == event.dataA())
{
// Don't bother if already set.
if(ev.dataB() == event.dataB())
return;
// Indicate do undo, and do port controller values and clone parts.
audio->msgChangeEvent(ev, event, part, true, true, true);
return;
}
}
}
// Indicate do undo, and do port controller values and clone parts.
//audio->msgAddEvent(event, part);
audio->msgAddEvent(event, part, true, true, true);
}
//---------------------------------------------------------
// execAutomationCtlPopup
//---------------------------------------------------------
int Song::execAutomationCtlPopup(AudioTrack* track, const QPoint& menupos, int acid)
{
//enum { HEADER, SEP1, PREV_EVENT, NEXT_EVENT, SEP2, ADD_EVENT, CLEAR_EVENT, CLEAR_RANGE, CLEAR_ALL_EVENTS };
enum { HEADER, PREV_EVENT, NEXT_EVENT, SEP2, ADD_EVENT, CLEAR_EVENT, CLEAR_RANGE, CLEAR_ALL_EVENTS };
Q3PopupMenu* menu = new Q3PopupMenu;
int count = 0;
bool isEvent = false, canSeekPrev = false, canSeekNext = false, canEraseRange = false;
bool canAdd = false;
double ctlval = 0.0;
if(track)
{
ciCtrlList icl = track->controller()->find(acid);
if(icl != track->controller()->end())
{
CtrlList *cl = icl->second;
canAdd = true;
ctlval = cl->curVal();
count = cl->size();
if(count)
{
int frame = pos[0].frame();
iCtrl s = cl->lower_bound(frame);
iCtrl e = cl->upper_bound(frame);
isEvent = (s != cl->end() && s->second.frame == frame);
canSeekPrev = s != cl->begin();
canSeekNext = e != cl->end();
s = cl->lower_bound(pos[1].frame());
canEraseRange = s != cl->end()
&& (int)pos[2].frame() > s->second.frame;
}
}
}
//menu->insertItem(tr("Automation:"), HEADER, HEADER);
//menu->setItemEnabled(HEADER, false);
//MenuTitleItem* title = new MenuTitleItem(tr("Automation:")); ddskrjo
//menu->insertItem(title, HEADER, HEADER); ddskrjo
//menu->insertSeparator(SEP1);
menu->insertItem(tr("previous event"), PREV_EVENT, PREV_EVENT);
menu->setItemEnabled(PREV_EVENT, canSeekPrev);
menu->insertItem(tr("next event"), NEXT_EVENT, NEXT_EVENT);
menu->setItemEnabled(NEXT_EVENT, canSeekNext);
menu->insertSeparator(SEP2);
if(isEvent)
menu->insertItem(tr("set event"), ADD_EVENT, ADD_EVENT);
else
menu->insertItem(tr("add event"), ADD_EVENT, ADD_EVENT);
menu->setItemEnabled(ADD_EVENT, canAdd);
menu->insertItem(tr("erase event"), CLEAR_EVENT, CLEAR_EVENT);
menu->setItemEnabled(CLEAR_EVENT, isEvent);
menu->insertItem(tr("erase range"), CLEAR_RANGE, CLEAR_RANGE);
menu->setItemEnabled(CLEAR_RANGE, canEraseRange);
menu->insertItem(tr("clear automation"), CLEAR_ALL_EVENTS, CLEAR_ALL_EVENTS);
menu->setItemEnabled(CLEAR_ALL_EVENTS, (bool)count);
int sel = menu->exec(menupos, 1);
delete menu;
if (sel == -1)
return -1;
if(!track)
return -1;
switch(sel)
{
case ADD_EVENT:
audio->msgAddACEvent(track, acid, pos[0].frame(), ctlval);
break;
case CLEAR_EVENT:
audio->msgEraseACEvent(track, acid, pos[0].frame());
break;
case CLEAR_RANGE:
audio->msgEraseRangeACEvents(track, acid, pos[1].frame(), pos[2].frame());
break;
case CLEAR_ALL_EVENTS:
if(QMessageBox::question(muse, QString("Muse"),
tr("Clear all controller events?"), tr("&Ok"), tr("&Cancel"),
QString::null, 0, 1 ) == 0)
audio->msgClearControllerEvents(track, acid);
break;
case PREV_EVENT:
audio->msgSeekPrevACEvent(track, acid);
break;
case NEXT_EVENT:
audio->msgSeekNextACEvent(track, acid);
break;
default:
return -1;
break;
}
return sel;
}
//---------------------------------------------------------
// execMidiAutomationCtlPopup
//---------------------------------------------------------
int Song::execMidiAutomationCtlPopup(MidiTrack* track, MidiPart* part, const QPoint& menupos, int ctlnum)
{
if(!track && !part)
return -1;
//enum { HEADER, SEP1, PREV_EVENT, NEXT_EVENT, SEP2, ADD_EVENT, CLEAR_EVENT, CLEAR_RANGE, CLEAR_ALL_EVENTS };
enum { HEADER, ADD_EVENT, CLEAR_EVENT };
Q3PopupMenu* menu = new Q3PopupMenu;
//int count = 0;
bool isEvent = false;
//bool canSeekPrev = false, canSeekNext = false, canEraseRange = false;
//bool canAdd = false;
//double ctlval = 0.0;
MidiTrack* mt;
if(track)
mt = track;
else
mt = (MidiTrack*)part->track();
int portno = mt->outPort();
int channel = mt->outChannel();
MidiPort* mp = &midiPorts[portno];
int dctl = ctlnum;
// Is it a drum controller, according to the track port's instrument?
MidiController *mc = mp->drumController(ctlnum);
if(mc)
{
// Change the controller event's index into the drum map to an instrument note.
int note = ctlnum & 0x7f;
dctl &= ~0xff;
channel = drumMap[note].channel;
mp = &midiPorts[drumMap[note].port];
dctl |= drumMap[note].anote;
}
//printf("Song::execMidiAutomationCtlPopup ctlnum:%d dctl:%d anote:%d\n", ctlnum, dctl, drumMap[ctlnum & 0x7f].anote);
unsigned tick = cpos();
if(!part)
{
PartList* pl = mt->parts();
iPart ip;
for(ip = pl->begin(); ip != pl->end(); ++ip)
{
MidiPart* tpart = (MidiPart*)(ip->second);
unsigned partStart = tpart->tick();
unsigned partEnd = partStart + tpart->lenTick();
if(tick >= partStart && tick < partEnd)
{
// Prefer a selected part, otherwise keep looking...
if(tpart->selected())
{
part = tpart;
break;
}
else
// Remember the first part found...
if(!part)
part = tpart;
}
}
}
Event ev;
if(part)
{
unsigned partStart = part->tick();
unsigned partEnd = partStart + part->lenTick();
if(tick >= partStart && tick < partEnd)
{
EventRange range = part->events()->equal_range(tick - partStart);
for(iEvent i = range.first; i != range.second; ++i)
{
ev = i->second;
if(ev.type() == Controller)
{
//printf("Song::execMidiAutomationCtlPopup ev.dataA:%d\n", ev.dataA());
//if(ev.dataA() == dctl)
if(ev.dataA() == ctlnum)
{
isEvent = true;
break;
}
}
}
}
}
//menu->insertItem(tr("Automation:"), HEADER, HEADER);
//menu->setItemEnabled(HEADER, false);
//MenuTitleItem* title = new MenuTitleItem(tr("Automation:")); ddskrjo
///menu->insertItem(title, HEADER, HEADER); ddskrjo
//menu->insertSeparator(SEP1);
// menu->insertItem(tr("previous event"), PREV_EVENT, PREV_EVENT);
// menu->setItemEnabled(PREV_EVENT, canSeekPrev);
// menu->insertItem(tr("next event"), NEXT_EVENT, NEXT_EVENT);
// menu->setItemEnabled(NEXT_EVENT, canSeekNext);
// menu->insertSeparator(SEP2);
if(isEvent)
menu->insertItem(tr("set event"), ADD_EVENT, ADD_EVENT);
else
menu->insertItem(tr("add event"), ADD_EVENT, ADD_EVENT);
//menu->setItemEnabled(ADD_EVENT, canAdd);
menu->setItemEnabled(ADD_EVENT, true);
menu->insertItem(tr("erase event"), CLEAR_EVENT, CLEAR_EVENT);
menu->setItemEnabled(CLEAR_EVENT, isEvent);
// menu->insertItem(tr("erase range"), CLEAR_RANGE, CLEAR_RANGE);
// menu->setItemEnabled(CLEAR_RANGE, canEraseRange);
// menu->insertItem(tr("clear automation"), CLEAR_ALL_EVENTS, CLEAR_ALL_EVENTS);
// menu->setItemEnabled(CLEAR_ALL_EVENTS, (bool)count);
int sel = menu->exec(menupos, 1);
delete menu;
if (sel == -1)
return -1;
//if(!part)
// return -1;
switch(sel)
{
case ADD_EVENT:
{
//int val = mp->hwCtrlState(channel, ctlnum);
int val = mp->hwCtrlState(channel, dctl);
if(val == CTRL_VAL_UNKNOWN)
return -1;
Event e(Controller);
//e.setA(dctl);
e.setA(ctlnum);
e.setB(val);
// Do we replace an old event?
if(isEvent)
{
// Don't bother if already set.
if(ev.dataB() == val)
return -1;
e.setTick(tick - part->tick());
// Indicate do undo, and do port controller values and clone parts.
audio->msgChangeEvent(ev, e, part, true, true, true);
}
else
{
// Store a new event...
if(part)
{
e.setTick(tick - part->tick());
// Indicate do undo, and do port controller values and clone parts.
audio->msgAddEvent(e, part, true, true, true);
}
else
{
// Create a new part...
part = new MidiPart(mt);
int startTick = roundDownBar(tick);
int endTick = roundUpBar(tick + 1);
part->setTick(startTick);
part->setLenTick(endTick - startTick);
part->setName(mt->name());
e.setTick(tick - startTick);
part->events()->add(e);
// Allow undo.
audio->msgAddPart(part);
}
}
}
break;
case CLEAR_EVENT:
// Indicate do undo, and do port controller values and clone parts.
audio->msgDeleteEvent(ev, part, true, true, true);
break;
//case CLEAR_RANGE:
//audio->msgEraseRangeACEvents(track, acid, pos[1].frame(), pos[2].frame());
//break;
//case CLEAR_ALL_EVENTS:
//if(QMessageBox::question(muse, QString("Muse"),
// tr("Clear all controller events?"), tr("&Ok"), tr("&Cancel"),
// QString::null, 0, 1 ) == 0)
//audio->msgClearControllerEvents(track, acid);
//break;
//case PREV_EVENT:
//audio->msgSeekPrevACEvent(track, acid);
//break;
//case NEXT_EVENT:
//audio->msgSeekNextACEvent(track, acid);
//break;
default:
return -1;
break;
}
return sel;
}
//---------------------------------------------------------
// updateSoloStates
// This will properly set all soloing variables (including other tracks) based entirely
// on the current values of all the tracks' _solo members.
//---------------------------------------------------------
void Song::updateSoloStates()
{
Track::clearSoloRefCounts();
for(ciTrack i = _tracks.begin(); i != _tracks.end(); ++i)
(*i)->setInternalSolo(0);
for(ciTrack i = _tracks.begin(); i != _tracks.end(); ++i)
(*i)->updateSoloStates(true);
}
//---------------------------------------------------------
// clearRecAutomation
//---------------------------------------------------------
void Song::clearRecAutomation(bool clearList)
{
// Clear all pan/vol pressed and touched flags, and all rec event lists, if needed.
for (iTrack it = tracks()->begin(); it != tracks()->end(); ++it)
((Track*)(*it))->clearRecAutomation(clearList);
}
//---------------------------------------------------------
// processAutomationEvents
//---------------------------------------------------------
void Song::processAutomationEvents()
{
// Just clear all pressed and touched flags, not rec event lists.
clearRecAutomation(false);
if (!automation)
return;
for(iTrack i = _tracks.begin(); i != _tracks.end(); ++i)
{
if(!(*i)->isMidiTrack())
// Process (and clear) rec events.
((AudioTrack*)(*i))->processAutomationEvents();
}
}
//---------------------------------------------------------
// abortRolling
//---------------------------------------------------------
void Song::abortRolling()
{
if (record())
audio->recordStop();
setStopPlay(false);
}
//---------------------------------------------------------
// stopRolling
//---------------------------------------------------------
void Song::stopRolling()
{
abortRolling();
processAutomationEvents();
}
//---------------------------------------------------------
// connectJackRoutes
//---------------------------------------------------------
void Song::connectJackRoutes(AudioTrack* track, bool disconnect)
{
switch(track->type())
{
case Track::AUDIO_OUTPUT:
{
AudioOutput* ao = (AudioOutput*)track;
// This will re-register the track's jack ports.
if(!disconnect)
ao->setName(ao->name());
// Now reconnect the output routes.
if(checkAudioDevice() && audio->isRunning())
{
for(int ch = 0; ch < ao->channels(); ++ch)
{
RouteList* ir = ao->outRoutes();
for (iRoute ii = ir->begin(); ii != ir->end(); ++ii)
{
Route r = *ii;
if ((r.type == Route::JACK_ROUTE) && (r.channel == ch))
{
if(disconnect)
audioDevice->disconnect(ao->jackPort(ch), r.jackPort);
else
audioDevice->connect(ao->jackPort(ch), r.jackPort);
break;
}
}
if(disconnect)
{
audioDevice->unregisterPort(ao->jackPort(ch));
ao->setJackPort(ch, 0);
}
}
}
}
break;
case Track::AUDIO_INPUT:
{
AudioInput* ai = (AudioInput*)track;
// This will re-register the track's jack ports.
if(!disconnect)
ai->setName(ai->name());
// Now reconnect the input routes.
if(checkAudioDevice() && audio->isRunning())
{
for(int ch = 0; ch < ai->channels(); ++ch)
{
RouteList* ir = ai->inRoutes();
for (iRoute ii = ir->begin(); ii != ir->end(); ++ii)
{
Route r = *ii;
if ((r.type == Route::JACK_ROUTE) && (r.channel == ch))
{
if(disconnect)
audioDevice->disconnect(r.jackPort, ai->jackPort(ch));
else
audioDevice->connect(r.jackPort, ai->jackPort(ch));
break;
}
}
if(disconnect)
{
audioDevice->unregisterPort(ai->jackPort(ch));
ai->setJackPort(ch, 0);
}
}
}
}
break;
default:
break;
}
}
/*
//---------------------------------------------------------
// chooseMidiRoutes
//---------------------------------------------------------
void Song::chooseMidiRoutes(QButton* parent, MidiTrack* track, bool dst)
{
if(!track)
return;
//if(!track->isMidiTrack())
// return;
QPoint ppt = QCursor::pos();
//QPoint ppt = parent->rect().bottomLeft();
//if(dst)
//{
// TODO
//}
//else
//{
RouteList* rl = dst ? track->outRoutes() : track->inRoutes();
//Route dst(track, -1);
QPopupMenu* pup = new QPopupMenu(parent);
pup->setCheckable(true);
int gid = 0;
int n;
// FIXME:
// Routes can't be re-read until the message sent from msgAddRoute1()
// has had time to be sent and actually affected the routes.
///_redisplay:
pup->clear();
gid = 0;
//MidiInPortList* tl = song->midiInPorts();
//for(iMidiInPort i = tl->begin();i != tl->end(); ++i)
for(int i = 0; i < MIDI_PORTS; ++i)
{
//MidiInPort* track = *i;
// NOTE: Could possibly list all devices, bypassing ports, but no, let's stick wth ports.
MidiPort* mp = &midiPorts[i];
MidiDevice* md = mp->device();
if(!md)
continue;
if(!(md->rwFlags() & (dst ? 1 : 2)))
continue;
//printf("MidiStrip::iRoutePressed adding submenu portnum:%d\n", i);
//QMenu* m = menu->addMenu(track->name());
QPopupMenu* subp = new QPopupMenu(parent);
for(int ch = 0; ch < MIDI_CHANNELS; ++ch)
{
//QAction* a = m->addAction(QString("Channel %1").arg(ch+1));
//subp->insertItem(QT_TR_NOOP(QString("Channel %1").arg(ch+1)), i * MIDI_CHANNELS + ch);
gid = i * MIDI_CHANNELS + ch;
//printf("MidiStrip::iRoutePressed inserting gid:%d\n", gid);
subp->insertItem(QString("Channel %1").arg(ch+1), gid);
//a->setCheckable(true);
//Route src(track, ch, RouteNode::TRACK);
//Route src(md, ch);
//Route r = Route(src, dst);
//a->setData(QVariant::fromValue(r));
//a->setChecked(rl->indexOf(r) != -1);
Route srcRoute(md, ch);
for(iRoute ir = rl->begin(); ir != rl->end(); ++ir)
{
//if(*ir == dst)
if(*ir == srcRoute)
{
subp->setItemChecked(gid, true);
break;
}
}
}
pup->insertItem(QT_TR_NOOP(md->name()), subp);
}
// QPopupMenu* pup = new QPopupMenu(iR);
// pup->setCheckable(true);
//MidiTrack* t = (MidiTrack*)track;
// RouteList* irl = track->inRoutes();
// MidiTrack* t = (MidiTrack*)track;
// int gid = 0;
// for (int i = 0; i < channel; ++i)
// {
// char buffer[128];
// snprintf(buffer, 128, "%s %d", tr("Channel").latin1(), i+1);
// MenuTitleItem* titel = new MenuTitleItem(QString(buffer));
// pup->insertItem(titel);
// if (!checkAudioDevice()) return;
// std::list<QString> ol = audioDevice->outputPorts();
// for (std::list<QString>::iterator ip = ol.begin(); ip != ol.end(); ++ip) {
// int id = pup->insertItem(*ip, (gid * 16) + i);
// Route dst(*ip, true, i);
// ++gid;
// for (iRoute ir = irl->begin(); ir != irl->end(); ++ir) {
// if (*ir == dst) {
// pup->setItemChecked(id, true);
// break;
// }
// }
// }
// if (i+1 != channel)
// pup->insertSeparator();
// }
if(pup->count() == 0)
{
delete pup;
return;
}
//n = pup->exec(QCursor::pos());
n = pup->exec(ppt);
///delete pup;
if (n != -1)
{
int mdidx = n / MIDI_CHANNELS;
int ch = n % MIDI_CHANNELS;
//if(debugMsg)
//printf("Song::chooseMidiRoutes mdidx:%d ch:%d\n", mdidx, ch);
MidiPort* mp = &midiPorts[mdidx];
MidiDevice* md = mp->device();
if(!md)
{
delete pup;
return;
}
//if(!(md->rwFlags() & 2))
if(!(md->rwFlags() & (dst ? 1 : 2)))
{
delete pup;
return;
}
//QString s(pup->text(n));
//QT_TR_NOOP(md->name())
//Route srcRoute(s, false, -1);
Route aRoute(md, ch);
//Route srcRoute(md, -1);
//Route dstRoute(track, -1);
Route bRoute(track, ch);
//if (track->type() == Track::AUDIO_INPUT)
// srcRoute.channel = dstRoute.channel = n & 0xf;
iRoute iir = rl->begin();
for (; iir != rl->end(); ++iir)
{
//if(*iir == (dst ? bRoute : aRoute))
if(*iir == aRoute)
break;
}
if (iir != rl->end())
{
// disconnect
if(dst)
{
//printf("Song::chooseMidiRoutes removing route src track name: %s dst device name: %s\n", track->name().latin1(), md->name().latin1());
audio->msgRemoveRoute(bRoute, aRoute);
}
else
{
//printf("Song::chooseMidiRoutes removing route src device name: %s dst track name: %s\n", md->name().latin1(), track->name().latin1());
audio->msgRemoveRoute(aRoute, bRoute);
}
}
else
{
// connect
if(dst)
{
//printf("Song::chooseMidiRoutes adding route src track name: %s dst device name: %s\n", track->name().latin1(), md->name().latin1());
audio->msgAddRoute(bRoute, aRoute);
}
else
{
//printf("Song::chooseMidiRoutes adding route src device name: %s dst track name: %s\n", md->name().latin1(), track->name().latin1());
audio->msgAddRoute(aRoute, bRoute);
}
}
//printf("Song::chooseMidiRoutes calling msgUpdateSoloStates\n");
audio->msgUpdateSoloStates();
//printf("Song::chooseMidiRoutes calling song->update\n");
song->update(SC_ROUTE);
// p3.3.46
///goto _redisplay;
}
delete pup;
parent->setDown(false); // pup->exec() catches mouse release event
//printf("Song::chooseMidiRoutes end\n");
//}
}
*/
//---------------------------------------------------------
// insertTrack0
//---------------------------------------------------------
void Song::insertTrack0(Track* track, int idx)
{
insertTrack1(track, idx);
insertTrack2(track, idx); // audio->msgInsertTrack(track, idx, false);
insertTrack3(track, idx);
}
//---------------------------------------------------------
// insertTrack1
// non realtime part of insertTrack
//---------------------------------------------------------
void Song::insertTrack1(Track* track, int /*idx*/)
{
//printf("Song::insertTrack1 track:%lx\n", track);
switch(track->type()) {
case Track::AUDIO_SOFTSYNTH:
{
SynthI* s = (SynthI*)track;
Synth* sy = s->synth();
if (!s->isActivated()) {
s->initInstance(sy, s->name());
}
}
break;
default:
break;
}
//printf("Song::insertTrack1 end of function\n");
}
//---------------------------------------------------------
// insertTrack2
// realtime part
//---------------------------------------------------------
void Song::insertTrack2(Track* track, int idx)
{
//printf("Song::insertTrack2 track:%lx\n", track);
int n;
switch(track->type()) {
case Track::MIDI:
case Track::DRUM:
_midis.push_back((MidiTrack*)track);
// Added by T356.
//((MidiTrack*)track)->addPortCtrlEvents();
addPortCtrlEvents(((MidiTrack*)track));
break;
case Track::WAVE:
_waves.push_back((WaveTrack*)track);
break;
case Track::AUDIO_OUTPUT:
_outputs.push_back((AudioOutput*)track);
// set default master & monitor if not defined
if (audio->audioMaster() == 0)
audio->setMaster((AudioOutput*)track);
if (audio->audioMonitor() == 0)
audio->setMonitor((AudioOutput*)track);
break;
case Track::AUDIO_GROUP:
_groups.push_back((AudioGroup*)track);
break;
case Track::AUDIO_AUX:
_auxs.push_back((AudioAux*)track);
break;
case Track::AUDIO_INPUT:
_inputs.push_back((AudioInput*)track);
break;
case Track::AUDIO_SOFTSYNTH:
{
SynthI* s = (SynthI*)track;
midiDevices.add(s);
midiInstruments.push_back(s);
_synthIs.push_back(s);
}
break;
default:
fprintf(stderr, "unknown track type %d\n", track->type());
// abort();
return;
}
//
// initialize missing aux send
//
iTrack i = _tracks.index2iterator(idx);
//printf("Song::insertTrack2 inserting into _tracks...\n");
_tracks.insert(i, track);
//printf("Song::insertTrack2 inserted\n");
n = _auxs.size();
for (iTrack i = _tracks.begin(); i != _tracks.end(); ++i) {
if ((*i)->isMidiTrack())
continue;
WaveTrack* wt = (WaveTrack*)*i;
if (wt->hasAuxSend()) {
wt->addAuxSend(n);
}
}
/*
//
// add routes
//
if (track->isMidiTrack())
return;
AudioTrack* at = (AudioTrack*)track;
Route src(at, -1);
if (at->type() == Track::AUDIO_OUTPUT) {
const RouteList* rl = at->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
r->track->outRoutes()->push_back(src);
}
else if (at->type() == Track::AUDIO_INPUT) {
const RouteList* rl = at->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
r->track->inRoutes()->push_back(src);
}
else {
const RouteList* rl = at->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
r->track->outRoutes()->push_back(src);
rl = at->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
r->track->inRoutes()->push_back(src);
}
*/
// p3.3.38
//
// add routes
//
if (track->type() == Track::AUDIO_OUTPUT)
{
const RouteList* rl = track->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//if(r->track == track)
// r->track->outRoutes()->push_back(*r);
// p3.3.50
Route src(track, r->channel, r->channels);
src.remoteChannel = r->remoteChannel;
r->track->outRoutes()->push_back(src);
}
}
else if (track->type() == Track::AUDIO_INPUT)
{
const RouteList* rl = track->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//if(r->track == track)
// r->track->inRoutes()->push_back(*r);
// p3.3.50
Route src(track, r->channel, r->channels);
src.remoteChannel = r->remoteChannel;
r->track->inRoutes()->push_back(src);
}
}
else if (track->isMidiTrack()) // p3.3.50
{
const RouteList* rl = track->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//printf("Song::insertTrack2 %s in route port:%d\n", track->name().latin1(), r->midiPort); // p3.3.50
Route src(track, r->channel);
midiPorts[r->midiPort].outRoutes()->push_back(src);
}
rl = track->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//printf("Song::insertTrack2 %s out route port:%d\n", track->name().latin1(), r->midiPort); // p3.3.50
Route src(track, r->channel);
midiPorts[r->midiPort].inRoutes()->push_back(src);
}
}
else
{
const RouteList* rl = track->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//if(r->track == track)
// r->track->outRoutes()->push_back(*r);
// p3.3.50
Route src(track, r->channel, r->channels);
src.remoteChannel = r->remoteChannel;
r->track->outRoutes()->push_back(src);
}
rl = track->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//if(r->track == track)
// r->track->inRoutes()->push_back(*r);
// p3.3.50
Route src(track, r->channel, r->channels);
src.remoteChannel = r->remoteChannel;
r->track->inRoutes()->push_back(src);
}
}
//printf("Song::insertTrack2 end of function\n");
}
//---------------------------------------------------------
// insertTrack3
// non realtime part of insertTrack
//---------------------------------------------------------
void Song::insertTrack3(Track* /*track*/, int /*idx*/)//prevent compiler warning: unused parameter
{
//printf("Song::insertTrack3\n");
/*
switch(track->type()) {
case Track::AUDIO_SOFTSYNTH:
break;
default:
break;
}
*/
}
//---------------------------------------------------------
// removeTrack0
//---------------------------------------------------------
void Song::removeTrack0(Track* track)
{
removeTrack1(track);
audio->msgRemoveTrack(track);
removeTrack3(track);
//delete track;
update(SC_TRACK_REMOVED);
}
//---------------------------------------------------------
// removeTrack1
// non realtime part of removeTrack
//---------------------------------------------------------
void Song::removeTrack1(Track* track)
{
switch(track->type())
{
case Track::WAVE:
case Track::AUDIO_OUTPUT:
case Track::AUDIO_INPUT:
case Track::AUDIO_GROUP:
case Track::AUDIO_AUX:
case Track::AUDIO_SOFTSYNTH:
((AudioTrack*)track)->deleteAllEfxGuis();
break;
default:
break;
}
switch(track->type())
{
case Track::AUDIO_OUTPUT:
case Track::AUDIO_INPUT:
connectJackRoutes((AudioTrack*)track, true);
break;
case Track::AUDIO_SOFTSYNTH:
{
SynthI* si = (SynthI*)track;
if(si->hasGui())
si->showGui(false);
}
break;
default:
break;
}
}
//---------------------------------------------------------
// removeTrack
// called from RT context
//---------------------------------------------------------
void Song::removeTrack2(Track* track)
{
//printf("Song::removeTrack2 track:%s\n", track->name().latin1()); // p3.3.50
switch(track->type()) {
case Track::MIDI:
case Track::DRUM:
// Added by T356.
//((MidiTrack*)track)->removePortCtrlEvents();
removePortCtrlEvents(((MidiTrack*)track));
unchainTrackParts(track, true);
_midis.erase(track);
break;
case Track::WAVE:
// Added by T356.
unchainTrackParts(track, true);
_waves.erase(track);
break;
case Track::AUDIO_OUTPUT:
_outputs.erase(track);
break;
case Track::AUDIO_INPUT:
_inputs.erase(track);
break;
case Track::AUDIO_GROUP:
_groups.erase(track);
break;
case Track::AUDIO_AUX:
_auxs.erase(track);
break;
case Track::AUDIO_SOFTSYNTH:
{
SynthI* s = (SynthI*) track;
s->deactivate2();
_synthIs.erase(track);
}
break;
}
_tracks.erase(track);
/*
if (track->isMidiTrack())
return;
//
// remove routes
//
AudioTrack* at = (AudioTrack*)track;
Route src(at, -1);
if (at->type() == Track::AUDIO_OUTPUT) {
const RouteList* rl = at->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
r->track->outRoutes()->removeRoute(src);
}
else if (at->type() == Track::AUDIO_INPUT) {
const RouteList* rl = at->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
r->track->inRoutes()->removeRoute(src);
}
else {
const RouteList* rl = at->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
r->track->outRoutes()->removeRoute(src);
rl = at->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
r->track->inRoutes()->removeRoute(src);
}
*/
// p3.3.38
//
// remove routes
//
if (track->type() == Track::AUDIO_OUTPUT)
{
const RouteList* rl = track->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//if(r->track == track)
// r->track->outRoutes()->removeRoute(*r);
//printf("Song::removeTrack2 %s audio out track:%s\n", track->name().latin1(), r->track->name().latin1()); // p3.3.50
// p3.3.50
Route src(track, r->channel, r->channels);
src.remoteChannel = r->remoteChannel;
r->track->outRoutes()->removeRoute(src);
}
}
else if (track->type() == Track::AUDIO_INPUT)
{
const RouteList* rl = track->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//if(r->track == track)
// r->track->inRoutes()->removeRoute(*r);
//printf("Song::removeTrack2 %s audio in track:%s\n", track->name().latin1(), r->track->name().latin1()); // p3.3.50
// p3.3.50
Route src(track, r->channel, r->channels);
src.remoteChannel = r->remoteChannel;
r->track->inRoutes()->removeRoute(src);
}
}
else if (track->isMidiTrack()) // p3.3.50
{
const RouteList* rl = track->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//printf("Song::removeTrack2 %s in route port:%d\n", track->name().latin1(), r->midiPort); // p3.3.50
Route src(track, r->channel);
midiPorts[r->midiPort].outRoutes()->removeRoute(src);
}
rl = track->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//printf("Song::removeTrack2 %s out route port:%d\n", track->name().latin1(), r->midiPort); // p3.3.50
Route src(track, r->channel);
midiPorts[r->midiPort].inRoutes()->removeRoute(src);
}
}
else
{
const RouteList* rl = track->inRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//if(r->track == track)
// r->track->outRoutes()->removeRoute(*r);
//printf("Song::removeTrack2 %s in route track:%s\n", track->name().latin1(), r->track->name().latin1()); // p3.3.50
// p3.3.50
Route src(track, r->channel, r->channels);
src.remoteChannel = r->remoteChannel;
r->track->outRoutes()->removeRoute(src);
}
rl = track->outRoutes();
for (ciRoute r = rl->begin(); r != rl->end(); ++r)
{
//if(r->track == track)
// r->track->inRoutes()->removeRoute(*r);
//printf("Song::removeTrack2 %s out route track:%s\n", track->name().latin1(), r->track->name().latin1()); // p3.3.50
// p3.3.50
Route src(track, r->channel, r->channels);
src.remoteChannel = r->remoteChannel;
r->track->inRoutes()->removeRoute(src);
}
}
}
//---------------------------------------------------------
// removeTrack3
// non realtime part of removeTrack
//---------------------------------------------------------
void Song::removeTrack3(Track* /*track*/)//prevent of compiler warning: unused parameter
{
/*
switch(track->type()) {
case Track::AUDIO_SOFTSYNTH:
{
SynthI* s = (SynthI*) track;
s->deactivate3();
}
break;
default:
break;
}
*/
}
//---------------------------------------------------------
// executeScript
//---------------------------------------------------------
void Song::executeScript(const char* scriptfile, PartList* parts, int quant, bool onlyIfSelected)
{
// a simple format for external processing
// will be extended if there is a need
//
// Semantics:
// PARTLEN <len in ticks>
// BEATLEN <len in ticks>
// QUANTLEN <len in ticks>
// NOTE <tick> <nr> <len in ticks> <velocity>
// CONTROLLER <tick> <a> <b> <c>
//
song->startUndo(); // undo this entire block
for (iPart i = parts->begin(); i != parts->end(); i++) {
const char* tmp = tmpnam(NULL);
printf("script input filename=%s\n",tmp);
FILE *fp = fopen(tmp, "w");
MidiPart *part = (MidiPart*)(i->second);
int partStart = part->endTick()-part->lenTick();
int z, n;
sigmap.timesig(0, z, n);
fprintf(fp, "TIMESIG %d %d\n", z, n);
fprintf(fp, "PART %d %d\n", partStart, part->lenTick());
fprintf(fp, "BEATLEN %d\n", sigmap.ticksBeat(0));
fprintf(fp, "QUANTLEN %d\n", quant);
//for (iCItem i = items.begin(); i != items.end(); ++i) {
for (iEvent e = part->events()->begin(); e != part->events()->end(); e++) {
Event ev = e->second;
if (ev.isNote())
{
if (onlyIfSelected && ev.selected() == false)
continue;
fprintf(fp,"NOTE %d %d %d %d\n", ev.tick(), ev.dataA(), ev.lenTick(), ev.dataB());
// Indicate no undo, and do not do port controller values and clone parts.
audio->msgDeleteEvent(ev, part, false, false, false);
} else if (ev.type()==Controller) {
fprintf(fp,"CONTROLLER %d %d %d %d\n", ev.tick(), ev.dataA(), ev.dataB(), ev.dataC());
// Indicate no undo, and do not do port controller values and clone parts.
audio->msgDeleteEvent(ev, part, false, false, false);
}
}
fclose(fp);
// Call external program, let it manipulate the file
int pid = fork();
if (pid == 0) {
if (execlp(scriptfile, scriptfile, tmp, NULL) == -1) {
perror("Failed to launch script!");
// Get out of here
// cannot report error through gui, we are in another fork!
//@!TODO: Handle unsuccessful attempts
exit(99);
}
exit(0);
}
else if (pid == -1) {
perror("fork failed");
}
else {
int status;
waitpid(pid, &status, 0);
if (WEXITSTATUS(status) != 0 ) {
QMessageBox::warning(muse, tr("MusE - external script failed"),
tr("MusE was unable to launch the script\n")
);
endUndo(SC_EVENT_REMOVED);
return;
}
else { // d0 the fun55or5!
// TODO: Create a new part, update the entire editor from it, hehh....
QFile file(tmp);
if ( file.open( QIODevice::ReadOnly ) ) {
Q3TextStream stream( &file );
QString line;
while ( !stream.atEnd() ) {
line = stream.readLine(); // line of text excluding '\n'
if (line.startsWith("NOTE"))
{
QStringList sl = QStringList::split(" ",line);
Event e(Note);
int tick = sl[1].toInt();
int pitch = sl[2].toInt();
int len = sl[3].toInt();
int velo = sl[4].toInt();
printf ("tick=%d pitch=%d velo=%d len=%d\n", tick,pitch,velo,len);
e.setTick(tick);
e.setPitch(pitch);
e.setVelo(velo);
e.setLenTick(len);
// Indicate no undo, and do not do port controller values and clone parts.
audio->msgAddEvent(e, part, false, false, false);
}
if (line.startsWith("CONTROLLER"))
{
QStringList sl = QStringList::split(" ",line);
Event e(Controller);
int tick = sl[1].toInt();
int a = sl[2].toInt();
int b = sl[3].toInt();
int c = sl[4].toInt();
printf ("tick=%d a=%d b=%d c=%d\n", tick,a,b,c);
e.setA(a);
e.setB(b);
e.setB(c);
// Indicate no undo, and do not do port controller values and clone parts.
audio->msgAddEvent(e, part, false, false, false);
}
}
file.close();
}
}
}
remove(tmp);
}
endUndo(SC_EVENT_REMOVED);
}
#define SCRIPTSSUFFIX "/share/muse/scripts/"
#define USERSCRIPTSSUFFIX "/.muse/scripts/"
void Song::populateScriptMenu(Q3PopupMenu* menuPlugins, QObject* receiver)
{
//
// List scripts
//
QString distScripts = QString(INSTPREFIX) + QString(SCRIPTSSUFFIX);
QString home = "";
if (getenv("HOME") != NULL)
home = QString(getenv("HOME"));
QString userScripts = home + QString(USERSCRIPTSSUFFIX);
QFileInfo distScriptsFi(distScripts);
if (distScriptsFi.isDir()) {
QDir dir = QDir(distScripts);
dir.setFilter(QDir::Executable | QDir::Files);
deliveredScriptNames = dir.entryList();
}
QFileInfo userScriptsFi(userScripts);
if (userScriptsFi.isDir()) {
QDir dir(userScripts);
dir.setFilter(QDir::Executable | QDir::Files);
userScriptNames = dir.entryList();
}
if (deliveredScriptNames.size() > 0 || userScriptNames.size() > 0) {
//menuPlugins = new QPopupMenu(this);
//menuBar()->insertItem(tr("&Plugins"), menuPlugins);
int id = 0;
if (deliveredScriptNames.size() > 0) {
for (QStringList::Iterator it = deliveredScriptNames.begin(); it != deliveredScriptNames.end(); it++, id++) {
//menuPlugins->insertItem(*it, this, SLOT(execDeliveredScript(int)), 0, id);
//menuPlugins->insertItem(*it, this, slot_deliveredscripts, 0, id);
menuPlugins->insertItem(*it, receiver, SLOT(execDeliveredScript(int)), 0, id);
}
menuPlugins->insertSeparator();
}
if (userScriptNames.size() > 0) {
for (QStringList::Iterator it = userScriptNames.begin(); it != userScriptNames.end(); it++, id++) {
//menuPlugins->insertItem(*it, this, slot_userscripts, 0, id);
menuPlugins->insertItem(*it, receiver, SLOT(execUserScript(int)), 0, id);
}
menuPlugins->insertSeparator();
}
}
return;
}
//---------------------------------------------------------
// getScriptPath
//---------------------------------------------------------
QString Song::getScriptPath(int id, bool isdelivered)
{
if (isdelivered) {
QString path = QString(INSTPREFIX) + SCRIPTSSUFFIX + deliveredScriptNames[id];
return path;
}
QString path = QString(getenv("HOME")) + USERSCRIPTSSUFFIX + userScriptNames[id - deliveredScriptNames.size()];
return path;
}
|