[r741]: trunk / src / qjackctlMainForm.cpp Maximize Restore History

Download this file

qjackctlMainForm.cpp    3934 lines (3439 with data), 114.2 kB

   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
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
// qjackctlMainForm.cpp
//
/****************************************************************************
Copyright (C) 2003-2012, rncbc aka Rui Nuno Capela. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
#include "qjackctlAbout.h"
#include "qjackctlMainForm.h"
#include "qjackctlStatus.h"
#include "qjackctlPatchbay.h"
#include "qjackctlPatchbayFile.h"
#include "qjackctlMessagesStatusForm.h"
#include "qjackctlSessionForm.h"
#include "qjackctlConnectionsForm.h"
#include "qjackctlPatchbayForm.h"
#include "qjackctlSetupForm.h"
#include "qjackctlAboutForm.h"
#include "qjackctlSystemTray.h"
#include <QApplication>
#include <QSocketNotifier>
#include <QMessageBox>
#include <QTextStream>
#include <QRegExp>
#include <QMenu>
#include <QTimer>
#include <QLabel>
#include <QPixmap>
#include <QFileInfo>
#include <QDir>
#include <QContextMenuEvent>
#include <QCustomEvent>
#include <QCloseEvent>
#if QT_VERSION < 0x040500
namespace Qt {
const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000);
#if QT_VERSION < 0x040200
const WindowFlags CustomizeWindowHint = WindowFlags(0x02000000);
#endif
}
#endif
#ifdef CONFIG_DBUS
#include <QDBusInterface>
#include <QThread>
#endif
#ifdef CONFIG_JACK_STATISTICS
#include <jack/statistics.h>
#endif
// Timer constant stuff.
#define QJACKCTL_TIMER_MSECS 200
// Status refresh cycle (~2 secs)
#define QJACKCTL_STATUS_CYCLE 10
// Server display enumerated states.
#define QJACKCTL_INACTIVE 0
#define QJACKCTL_ACTIVATING 1
#define QJACKCTL_ACTIVE 2
#define QJACKCTL_STARTING 3
#define QJACKCTL_STARTED 4
#define QJACKCTL_STOPPING 5
#define QJACKCTL_STOPPED 6
#if defined(WIN32)
#include <io.h>
#undef HAVE_POLL_H
#undef HAVE_SIGNAL_H
#else
#include <unistd.h>
// Notification pipes descriptors
#define QJACKCTL_FDNIL -1
#define QJACKCTL_FDREAD 0
#define QJACKCTL_FDWRITE 1
static int g_fdStdout[2] = { QJACKCTL_FDNIL, QJACKCTL_FDNIL };
#endif
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
// Custom event types.
#define QJACKCTL_PORT_EVENT QEvent::Type(QEvent::User + 1)
#define QJACKCTL_XRUN_EVENT QEvent::Type(QEvent::User + 2)
#define QJACKCTL_BUFF_EVENT QEvent::Type(QEvent::User + 3)
#define QJACKCTL_SHUT_EVENT QEvent::Type(QEvent::User + 4)
#define QJACKCTL_EXIT_EVENT QEvent::Type(QEvent::User + 5)
#ifdef CONFIG_DBUS
#define QJACKCTL_LINE_EVENT QEvent::Type(QEvent::User + 6)
#endif
//----------------------------------------------------------------------------
// qjackctl -- Static callback posters.
// To have clue about current buffer size (in frames).
static jack_nframes_t g_nframes = 0;
static QProcess::ProcessError g_error = QProcess::UnknownError;
// Jack port registration callback funtion, called
// whenever a jack port is registered or unregistered.
static void qjackctl_port_registration_callback ( jack_port_id_t, int, void * )
{
QApplication::postEvent(
qjackctlMainForm::getInstance(),
new QEvent(QJACKCTL_PORT_EVENT));
}
// Jack graph order callback function, called
// whenever the processing graph is reordered.
static int qjackctl_graph_order_callback ( void * )
{
QApplication::postEvent(
qjackctlMainForm::getInstance(),
new QEvent(QJACKCTL_PORT_EVENT));
return 0;
}
// Jack XRUN callback function, called
// whenever there is a xrun.
static int qjackctl_xrun_callback ( void * )
{
QApplication::postEvent(
qjackctlMainForm::getInstance(),
new QEvent(QJACKCTL_XRUN_EVENT));
return 0;
}
// Jack buffer size function, called
// whenever the server changes buffer size.
static int qjackctl_buffer_size_callback ( jack_nframes_t nframes, void * )
{
// Update our global static variable.
g_nframes = nframes;
QApplication::postEvent(
qjackctlMainForm::getInstance(),
new QEvent(QJACKCTL_BUFF_EVENT));
return 0;
}
// Jack shutdown function, called
// whenever the server terminates this client.
static void qjackctl_on_shutdown ( void * )
{
QApplication::postEvent(
qjackctlMainForm::getInstance(),
new QEvent(QJACKCTL_SHUT_EVENT));
}
// Jack process exit function, called
// whenever the server terminates abnormally.
static void qjackctl_on_error ( QProcess::ProcessError error )
{
g_error = error;
QApplication::postEvent(
qjackctlMainForm::getInstance(),
new QEvent(QJACKCTL_EXIT_EVENT));
}
#ifdef CONFIG_DBUS
//----------------------------------------------------------------------
// class qjackctlDBusLogWatcher -- Simple D-BUS log watcher thread.
//
class qjackctlDBusLogWatcher : public QThread
{
public:
// Constructor.
qjackctlDBusLogWatcher(const QString& sFilename) : QThread(),
m_sFilename(sFilename), m_bRunState(false) {}
// Destructor.
~qjackctlDBusLogWatcher()
{ if (isRunning()) do { m_bRunState = false; } while (!wait(1000)); }
// Custom log event.
class LineEvent : public QEvent
{
public:
// Constructor.
LineEvent(QEvent::Type eType, const QString& sLine)
: QEvent(eType), m_sLine(sLine)
{ m_sLine.remove(QRegExp("\x1B\[[0-9|;]+m")); }
// Accessor.
const QString& line() const
{ return m_sLine; }
private:
// Custom event data.
QString m_sLine;
};
protected:
// The main thread executive.
void run()
{
QFile file(m_sFilename);
m_bRunState = true;
while (m_bRunState) {
if (file.isOpen()) {
char achBuffer[1024];
while (file.readLine(achBuffer, sizeof(achBuffer)) > 0) {
QApplication::postEvent(
qjackctlMainForm::getInstance(),
new LineEvent(QJACKCTL_LINE_EVENT, achBuffer));
}
if (file.size() == file.pos() &&
file.error() == QFile::NoError) {
msleep(1000);
} else {
file.close();
}
}
else
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
file.seek(file.size());
}
else msleep(1000);
}
}
private:
// The log filename to watch.
QString m_sFilename;
// Whether the thread is logically running.
volatile bool m_bRunState;
};
#endif // CONFIG_DBUS
//----------------------------------------------------------------------------
// qjackctlMainForm -- UI wrapper form.
// Kind of singleton reference.
qjackctlMainForm *qjackctlMainForm::g_pMainForm = NULL;
// Constructor.
qjackctlMainForm::qjackctlMainForm (
QWidget *pParent, Qt::WindowFlags wflags )
: QWidget(pParent, wflags)
{
// Setup UI struct...
m_ui.setupUi(this);
// Pseudo-singleton reference setup.
g_pMainForm = this;
m_pSetup = NULL;
m_iServerState = QJACKCTL_INACTIVE;
m_pJack = NULL;
m_pJackClient = NULL;
m_bJackDetach = false;
m_bJackShutdown = false;
m_pAlsaSeq = NULL;
#ifdef CONFIG_DBUS
m_pDBusControl = NULL;
m_pDBusConfig = NULL;
m_pDBusLogWatcher = NULL;
m_bDBusStarted = false;
#endif
m_iStartDelay = 0;
m_iTimerDelay = 0;
m_iTimerRefresh = 0;
m_iJackRefresh = 0;
m_iAlsaRefresh = 0;
m_iJackDirty = 0;
m_iAlsaDirty = 0;
m_iStatusRefresh = 0;
m_iStatusBlink = 0;
m_iPatchbayRefresh = 0;
m_pStdoutNotifier = NULL;
m_pAlsaNotifier = NULL;
// All forms are to be created later on setup.
m_pMessagesStatusForm = NULL;
m_pSessionForm = NULL;
m_pConnectionsForm = NULL;
m_pPatchbayForm = NULL;
// Patchbay rack can be readily created.
m_pPatchbayRack = new qjackctlPatchbayRack();
// The eventual system tray widget.
m_pSystemTray = NULL;
// We're not quitting so early :)
m_bQuitForce = false;
// Transport skip accelerate factor.
m_fSkipAccel = 1.0;
// Avoid extra transport toggles (play/stop)
m_iTransportPlay = 0;
// Whether we've Qt::Tool flag (from bKeepOnTop),
// this is actually the main last application window...
QWidget::setAttribute(Qt::WA_QuitOnClose);
#ifdef HAVE_SIGNAL_H
// Set to ignore any fatal "Broken pipe" signals.
signal(SIGPIPE, SIG_IGN);
#endif
#if 0
// FIXME: Iterate for every child text label...
m_ui.StatusDisplayFrame->setAutoFillBackground(true);
QList<QLabel *> labels = m_ui.StatusDisplayFrame->findChildren<QLabel *> ();
QListIterator<QLabel *> iter(labels);
while (iter.hasNext())
iter.next()->setAutoFillBackground(false);
#endif
// UI connections...
QObject::connect(m_ui.StartToolButton,
SIGNAL(clicked()),
SLOT(startJack()));
QObject::connect(m_ui.StopToolButton,
SIGNAL(clicked()),
SLOT(stopJack()));
QObject::connect(m_ui.MessagesStatusToolButton,
SIGNAL(clicked()),
SLOT(toggleMessagesStatusForm()));
QObject::connect(m_ui.SessionToolButton,
SIGNAL(clicked()),
SLOT(toggleSessionForm()));
QObject::connect(m_ui.ConnectionsToolButton,
SIGNAL(clicked()),
SLOT(toggleConnectionsForm()));
QObject::connect(m_ui.PatchbayToolButton,
SIGNAL(clicked()),
SLOT(togglePatchbayForm()));
QObject::connect(m_ui.QuitToolButton,
SIGNAL(clicked()),
SLOT(quitMainForm()));
QObject::connect(m_ui.SetupToolButton,
SIGNAL(clicked()),
SLOT(showSetupForm()));
QObject::connect(m_ui.AboutToolButton,
SIGNAL(clicked()),
SLOT(showAboutForm()));
QObject::connect(m_ui.RewindToolButton,
SIGNAL(clicked()),
SLOT(transportRewind()));
QObject::connect(m_ui.BackwardToolButton,
SIGNAL(clicked()),
SLOT(transportBackward()));
QObject::connect(m_ui.PlayToolButton,
SIGNAL(toggled(bool)),
SLOT(transportPlay(bool)));
QObject::connect(m_ui.PauseToolButton,
SIGNAL(clicked()),
SLOT(transportStop()));
QObject::connect(m_ui.ForwardToolButton,
SIGNAL(clicked()),
SLOT(transportForward()));
}
// Destructor.
qjackctlMainForm::~qjackctlMainForm (void)
{
// Stop server, if not already...
#ifdef CONFIG_DBUS
if (m_pSetup->bStopJack || !m_pSetup->bDBusEnabled)
stopJackServer();
if (m_pDBusLogWatcher)
delete m_pDBusLogWatcher;
if (m_pDBusConfig)
delete m_pDBusConfig;
if (m_pDBusControl)
delete m_pDBusControl;
m_pDBusControl = NULL;
m_pDBusConfig = NULL;
m_pDBusLogWatcher = NULL;
m_bDBusStarted = false;
#else
stopJackServer();
#endif
// Terminate local ALSA sequencer interface.
if (m_pAlsaNotifier)
delete m_pAlsaNotifier;
#ifdef CONFIG_ALSA_SEQ
if (m_pAlsaSeq)
snd_seq_close(m_pAlsaSeq);
#endif
m_pAlsaNotifier = NULL;
m_pAlsaSeq = NULL;
// Finally drop any popup widgets around...
if (m_pMessagesStatusForm)
delete m_pMessagesStatusForm;
if (m_pSessionForm)
delete m_pSessionForm;
if (m_pConnectionsForm)
delete m_pConnectionsForm;
if (m_pPatchbayForm)
delete m_pPatchbayForm;
// Quit off system tray widget.
if (m_pSystemTray)
delete m_pSystemTray;
// Patchbay rack is also dead.
if (m_pPatchbayRack)
delete m_pPatchbayRack;
// Pseudo-singleton reference shut-down.
g_pMainForm = NULL;
}
// Kind of singleton reference.
qjackctlMainForm *qjackctlMainForm::getInstance (void)
{
return g_pMainForm;
}
// Make and set a proper setup step.
bool qjackctlMainForm::setup ( qjackctlSetup *pSetup )
{
// Finally, fix settings descriptor
// and stabilize the form.
m_pSetup = pSetup;
// To avoid any background flickering,
// we'll hide the main display.
m_ui.StatusDisplayFrame->hide();
updateButtons();
// What style do we create these forms?
QWidget *pParent = NULL;
Qt::WindowFlags wflags = Qt::Window
| Qt::CustomizeWindowHint
| Qt::WindowTitleHint
| Qt::WindowSystemMenuHint
| Qt::WindowMinMaxButtonsHint
| Qt::WindowCloseButtonHint;
if (m_pSetup->bKeepOnTop) {
pParent = this;
wflags |= Qt::Tool;
}
// All forms are to be created right now.
m_pMessagesStatusForm = new qjackctlMessagesStatusForm (pParent, wflags);
m_pSessionForm = new qjackctlSessionForm (pParent, wflags);
m_pConnectionsForm = new qjackctlConnectionsForm (pParent, wflags);
m_pPatchbayForm = new qjackctlPatchbayForm (pParent, wflags);
// Setup appropriately...
m_pMessagesStatusForm->setTabPage(m_pSetup->iMessagesStatusTabPage);
m_pMessagesStatusForm->setLogging(
m_pSetup->bMessagesLog, m_pSetup->sMessagesLogPath);
m_pSessionForm->setup(m_pSetup);
m_pConnectionsForm->setTabPage(m_pSetup->iConnectionsTabPage);
m_pConnectionsForm->setup(m_pSetup);
m_pPatchbayForm->setup(m_pSetup);
// Set the patchbay cable connection notification signal/slot.
QObject::connect(m_pPatchbayRack, SIGNAL(cableConnected(const QString&, const QString&, unsigned int)),
this, SLOT(cableConnectSlot(const QString&, const QString&, unsigned int)));
// Try to restore old window positioning and appearence.
m_pSetup->loadWidgetGeometry(this, true);
// Make it final show...
m_ui.StatusDisplayFrame->show();
// Set other defaults...
updateDisplayEffect();
updateTimeDisplayFonts();
updateTimeDisplayToolTips();
updateTimeFormat();
updateMessagesFont();
updateMessagesLimit();
updateConnectionsFont();
updateConnectionsIconSize();
updateJackClientPortAlias();
updateBezierLines();
updateActivePatchbay();
updateSystemTray();
// And for the whole widget gallore...
m_pSetup->loadWidgetGeometry(m_pMessagesStatusForm);
m_pSetup->loadWidgetGeometry(m_pSessionForm);
m_pSetup->loadWidgetGeometry(m_pConnectionsForm);
m_pSetup->loadWidgetGeometry(m_pPatchbayForm);
// Initial XRUN statistics reset.
resetXrunStats();
// Check if we can redirect our own stdout/stderr...
#if !defined(WIN32)
if (m_pSetup->bStdoutCapture && ::pipe(g_fdStdout) == 0) {
::dup2(g_fdStdout[QJACKCTL_FDWRITE], STDOUT_FILENO);
::dup2(g_fdStdout[QJACKCTL_FDWRITE], STDERR_FILENO);
m_pStdoutNotifier = new QSocketNotifier(g_fdStdout[QJACKCTL_FDREAD], QSocketNotifier::Read, this);
QObject::connect(m_pStdoutNotifier, SIGNAL(activated(int)), this, SLOT(stdoutNotifySlot(int)));
}
#endif
#ifdef CONFIG_ALSA_SEQ
if (m_pSetup->bAlsaSeqEnabled) {
// Start our ALSA sequencer interface.
if (snd_seq_open(&m_pAlsaSeq, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0)
m_pAlsaSeq = NULL;
if (m_pAlsaSeq) {
snd_seq_port_subscribe_t *pAlsaSubs;
snd_seq_addr_t seq_addr;
struct pollfd pfd[1];
int iPort = snd_seq_create_simple_port(
m_pAlsaSeq, "qjackctl",
SND_SEQ_PORT_CAP_WRITE
| SND_SEQ_PORT_CAP_SUBS_WRITE
| SND_SEQ_PORT_CAP_NO_EXPORT,
SND_SEQ_PORT_TYPE_APPLICATION
);
if (iPort >= 0) {
snd_seq_port_subscribe_alloca(&pAlsaSubs);
seq_addr.client = SND_SEQ_CLIENT_SYSTEM;
seq_addr.port = SND_SEQ_PORT_SYSTEM_ANNOUNCE;
snd_seq_port_subscribe_set_sender(pAlsaSubs, &seq_addr);
seq_addr.client = snd_seq_client_id(m_pAlsaSeq);
seq_addr.port = iPort;
snd_seq_port_subscribe_set_dest(pAlsaSubs, &seq_addr);
snd_seq_subscribe_port(m_pAlsaSeq, pAlsaSubs);
snd_seq_poll_descriptors(m_pAlsaSeq, pfd, 1, POLLIN);
m_pAlsaNotifier
= new QSocketNotifier(pfd[0].fd, QSocketNotifier::Read);
QObject::connect(m_pAlsaNotifier,
SIGNAL(activated(int)),
SLOT(alsaNotifySlot(int)));
}
}
// Could we start without it?
if (m_pAlsaSeq) {
// Rather obvious setup.
if (m_pConnectionsForm)
m_pConnectionsForm->stabilizeAlsa(true);
} else {
appendMessagesError(
tr("Could not open ALSA sequencer as a client.\n\n"
"ALSA MIDI patchbay will be not available."));
}
}
#endif
#ifdef CONFIG_DBUS
// Register D-Bus service...
if (m_pSetup->bDBusEnabled) {
const QString s; // Just an empty string.
const QString sDBusName("org.rncbc.qjackctl");
QDBusConnection dbus = QDBusConnection::systemBus();
dbus.connect(s, s, sDBusName, "start",
this, SLOT(startJack()));
dbus.connect(s, s, sDBusName, "stop",
this, SLOT(stopJack()));
dbus.connect(s, s, sDBusName, "main",
this, SLOT(toggleMainForm()));
dbus.connect(s, s, sDBusName, "messages",
this, SLOT(toggleMessagesForm()));
dbus.connect(s, s, sDBusName, "status",
this, SLOT(toggleStatusForm()));
dbus.connect(s, s, sDBusName, "session",
this, SLOT(toggleSessionForm()));
dbus.connect(s, s, sDBusName, "connections",
this, SLOT(toggleConnectionsForm()));
dbus.connect(s, s, sDBusName, "patchbay",
this, SLOT(togglePatchbayForm()));
dbus.connect(s, s, sDBusName, "rewind",
this, SLOT(transportRewind()));
dbus.connect(s, s, sDBusName, "backward",
this, SLOT(transportBackward()));
dbus.connect(s, s, sDBusName, "play",
this, SLOT(transportStart()));
dbus.connect(s, s, sDBusName, "pause",
this, SLOT(transportStop()));
dbus.connect(s, s, sDBusName, "forward",
this, SLOT(transportForward()));
dbus.connect(s, s, sDBusName, "setup",
this, SLOT(showSetupForm()));
dbus.connect(s, s, sDBusName, "about",
this, SLOT(showAboutForm()));
dbus.connect(s, s, sDBusName, "quit",
this, SLOT(quitMainForm()));
dbus.connect(s, s, sDBusName, "preset",
this, SLOT(activatePreset(const QString&)));
// Session related slots...
if (m_pSessionForm) {
dbus.connect(s, s, sDBusName, "load",
m_pSessionForm, SLOT(loadSession()));
dbus.connect(s, s, sDBusName, "save",
m_pSessionForm, SLOT(saveSessionSave()));
#ifdef CONFIG_JACK_SESSION
dbus.connect(s, s, sDBusName, "savequit",
m_pSessionForm, SLOT(saveSessionSaveAndQuit()));
dbus.connect(s, s, sDBusName, "savetemplate",
m_pSessionForm, SLOT(saveSessionSaveTemplate()));
#endif
}
// Detect whether jackdbus is avaliable...
QDBusConnection dbusc = QDBusConnection::sessionBus();
m_pDBusControl = new QDBusInterface(
"org.jackaudio.service", // Service
"/org/jackaudio/Controller", // Path
"org.jackaudio.JackControl", // Interface
dbusc); // Connection
QDBusMessage dbusm = m_pDBusControl->call("IsStarted");
if (dbusm.type() == QDBusMessage::ReplyMessage) {
// Yes, jackdbus is available and/or already started
// -- use jackdbus control interface...
appendMessages(tr("D-BUS: Service is available (%1 aka jackdbus).")
.arg(m_pDBusControl->service()));
// Parse reply (should be boolean)
m_bDBusStarted = dbusm.arguments().first().toBool();
// Register server start/stop notification slots...
dbusc.connect(
m_pDBusControl->service(),
m_pDBusControl->path(),
m_pDBusControl->interface(),
"ServerStarted", this,
SLOT(jackStarted()));
dbusc.connect(
m_pDBusControl->service(),
m_pDBusControl->path(),
m_pDBusControl->interface(),
"ServerStopped", this,
SLOT(jackFinished()));
// -- use jackdbus configure interface...
m_pDBusConfig = new QDBusInterface(
m_pDBusControl->service(), // Service
m_pDBusControl->path(), // Path
"org.jackaudio.Configure", // Interface
m_pDBusControl->connection()); // Connection
// Start our log watcher thread...
m_pDBusLogWatcher = new qjackctlDBusLogWatcher(
QDir::homePath() + "/.log/jack/jackdbus.log");
m_pDBusLogWatcher->start();
// Ready now.
} else {
// No, jackdbus is not available, not started
// or not even installed -- use classic jackd, BAU...
appendMessages(tr("D-BUS: Service not available (%1 aka jackdbus).")
.arg(m_pDBusControl->service()));
// Destroy tentative jackdbus interface.
delete m_pDBusControl;
m_pDBusControl = NULL;
}
}
#endif
// Load patchbay form recent paths...
if (m_pPatchbayForm) {
m_pPatchbayForm->setRecentPatchbays(m_pSetup->patchbays);
if (!m_pSetup->sPatchbayPath.isEmpty()
&& QFileInfo(m_pSetup->sPatchbayPath).exists())
m_pPatchbayForm->loadPatchbayFile(m_pSetup->sPatchbayPath);
m_pPatchbayForm->updateRecentPatchbays();
m_pPatchbayForm->stabilizeForm();
}
// Try to find if we can start in detached mode (client-only)
// just in case there's a JACK server already running.
startJackClient(true);
// Final startup stabilization...
stabilizeForm();
jackStabilize();
// Look for immediate server startup?...
if (m_pSetup->bStartJack || !m_pSetup->sCmdLine.isEmpty())
m_pSetup->bStartJackCmd = true;
if (m_pSetup->bStartJackCmd)
startJack();
// Register the first timer slot.
QTimer::singleShot(QJACKCTL_TIMER_MSECS, this, SLOT(timerSlot()));
// We're ready to go...
return true;
}
// Window close event handlers.
bool qjackctlMainForm::queryClose (void)
{
bool bQueryClose = true;
#ifdef CONFIG_SYSTEM_TRAY
// If we're not quitting explicitly and there's an
// active system tray icon, then just hide ourselves.
if (!m_bQuitForce && isVisible()
&& m_pSetup->bSystemTray && m_pSystemTray) {
m_pSetup->saveWidgetGeometry(this, true);
const QString& sTitle = tr("Information") + " - " QJACKCTL_SUBTITLE1;
const QString& sText
= tr("The program will keep running in the system tray.\n\n"
"To terminate the program, please choose \"Quit\"\n"
"in the context menu of the system tray icon.");
#ifdef QJACKCTL_QT4_SYSTEM_TRAY
#if QT_VERSION >= 0x040300
if (QSystemTrayIcon::supportsMessages()) {
m_pSystemTray->showMessage(
sTitle, sText, QSystemTrayIcon::Information);
}
else
#endif
#endif
QMessageBox::information(this, sTitle, sText);
hide();
bQueryClose = false;
}
#endif
// Check if JACK daemon is currently running...
if (bQueryClose && m_pJack && m_pJack->state() == QProcess::Running
&& (m_pSetup->bQueryClose || m_pSetup->bQueryShutdown)) {
bQueryClose = (QMessageBox::warning(this,
tr("Warning") + " - " QJACKCTL_SUBTITLE1,
tr("JACK is currently running.\n\n"
"Do you want to terminate the JACK audio server?"),
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok);
}
// Try to save current aliases default settings.
if (bQueryClose && m_pConnectionsForm) {
bQueryClose = m_pConnectionsForm->queryClose();
if (bQueryClose)
m_pSetup->iConnectionsTabPage = m_pConnectionsForm->tabPage();
}
// Try to save current patchbay default settings.
if (bQueryClose && m_pPatchbayForm) {
bQueryClose = m_pPatchbayForm->queryClose();
if (bQueryClose && !m_pPatchbayForm->patchbayPath().isEmpty())
m_pSetup->sPatchbayPath = m_pPatchbayForm->patchbayPath();
}
// Try to save current session directories list...
if (bQueryClose && m_pSessionForm) {
m_pSetup->sessionDirs = m_pSessionForm->sessionDirs();
m_pSetup->bSessionSaveVersion = m_pSessionForm->isSaveSessionVersion();
}
// Some windows default fonts are here on demand too.
if (bQueryClose && m_pMessagesStatusForm) {
m_pSetup->sMessagesFont = m_pMessagesStatusForm->messagesFont().toString();
m_pSetup->iMessagesStatusTabPage = m_pMessagesStatusForm->tabPage();
}
// Whether we're really quitting.
m_bQuitForce = bQueryClose;
// Try to save current positioning.
if (bQueryClose) {
m_pSetup->saveWidgetGeometry(m_pMessagesStatusForm);
m_pSetup->saveWidgetGeometry(m_pSessionForm);
m_pSetup->saveWidgetGeometry(m_pConnectionsForm);
m_pSetup->saveWidgetGeometry(m_pPatchbayForm);
m_pSetup->saveWidgetGeometry(this);
// Close popup widgets.
if (m_pMessagesStatusForm)
m_pMessagesStatusForm->close();
if (m_pSessionForm)
m_pSessionForm->close();
if (m_pConnectionsForm)
m_pConnectionsForm->close();
if (m_pPatchbayForm)
m_pPatchbayForm->close();
// And the system tray icon too.
if (m_pSystemTray)
m_pSystemTray->close();
// Stop any service out there...
if (m_pSetup->bStopJack)
stopJackServer();
}
return bQueryClose;
}
void qjackctlMainForm::closeEvent ( QCloseEvent *pCloseEvent )
{
// Let's be sure about that...
if (queryClose()) {
pCloseEvent->accept();
QApplication::quit();
} else {
pCloseEvent->ignore();
}
}
void qjackctlMainForm::customEvent ( QEvent *pEvent )
{
switch (int(pEvent->type())) {
case QJACKCTL_PORT_EVENT:
portNotifyEvent();
break;
case QJACKCTL_XRUN_EVENT:
xrunNotifyEvent();
break;
case QJACKCTL_BUFF_EVENT:
buffNotifyEvent();
break;
case QJACKCTL_SHUT_EVENT:
shutNotifyEvent();
break;
case QJACKCTL_EXIT_EVENT:
exitNotifyEvent();
break;
#ifdef CONFIG_DBUS
case QJACKCTL_LINE_EVENT:
appendStdoutBuffer(
static_cast<qjackctlDBusLogWatcher::LineEvent *> (pEvent)->line());
break;
#endif
default:
QWidget::customEvent(pEvent);
break;
}
}
// Common exit status text formatter...
QString qjackctlMainForm::formatExitStatus ( int iExitStatus ) const
{
QString sTemp = " ";
if (iExitStatus == 0)
sTemp += tr("successfully");
else
sTemp += tr("with exit status=%1").arg(iExitStatus);
return sTemp + ".";
}
// Common shell script executive, with placeholder substitution...
void qjackctlMainForm::shellExecute ( const QString& sShellCommand, const QString& sStartMessage, const QString& sStopMessage )
{
QString sTemp = sShellCommand;
sTemp.replace("%P", m_pSetup->sDefPreset);
sTemp.replace("%N", m_pSetup->sServerName);
sTemp.replace("%s", m_preset.sServerPrefix);
sTemp.replace("%d", m_preset.sDriver);
sTemp.replace("%i", m_preset.sInterface);
sTemp.replace("%r", QString::number(m_preset.iSampleRate));
sTemp.replace("%p", QString::number(m_preset.iFrames));
sTemp.replace("%n", QString::number(m_preset.iPeriods));
appendMessages(sStartMessage);
appendMessagesColor(sTemp.trimmed(), "#990099");
stabilize(QJACKCTL_TIMER_MSECS);
// Execute and set exit status message...
sTemp = sStopMessage + formatExitStatus(
::system(sTemp.toUtf8().constData()));
// Wait a litle bit before continue...
stabilize(QJACKCTL_TIMER_MSECS);
// Final log message...
appendMessages(sTemp);
}
// Start jack audio server...
void qjackctlMainForm::startJack (void)
{
// If can't be already a client, are we?
if (m_pJackClient)
return;
// Is the server process instance still here?
if (m_pJack) {
if (QMessageBox::warning(this,
tr("Warning") + " - " QJACKCTL_SUBTITLE1,
tr("Could not start JACK.\n\n"
"Maybe JACK audio server is already started."),
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
m_pJack->terminate();
m_pJack->kill();
}
return;
}
// Stabilize emerging server state...
QPalette pal;
pal.setColor(QPalette::Foreground, Qt::yellow);
m_ui.ServerStateTextLabel->setPalette(pal);
m_ui.StartToolButton->setEnabled(false);
updateServerState(QJACKCTL_ACTIVATING);
// Reset our timer counters...
m_iStartDelay = 0;
m_iTimerDelay = 0;
m_iJackRefresh = 0;
// Now we're sure it ain't detached.
m_bJackShutdown = false;
m_bJackDetach = false;
// Load primary/default server preset...
if (!m_pSetup->loadPreset(m_preset, m_pSetup->sDefPreset)) {
appendMessagesError(tr("Could not load preset \"%1\".\n\nRetrying with default.").arg(m_pSetup->sDefPreset));
m_pSetup->sDefPreset = m_pSetup->sDefPresetName;
if (!m_pSetup->loadPreset(m_preset, m_pSetup->sDefPreset)) {
appendMessagesError(tr("Could not load default preset.\n\nSorry."));
jackCleanup();
return;
}
}
// Override server name now...
if (m_pSetup->sServerName.isEmpty())
m_pSetup->sServerName = m_preset.sServerName;
#if 0 // defined(__GNUC__) && defined(Q_OS_LINUX)
// Take care for the environment as well...
if (!m_pSetup->sServerName.isEmpty()) {
setenv("JACK_DEFAULT_SERVER",
m_pSetup->sServerName.toUtf8().constData(), 1);
}
#endif
// If we ain't to be the server master, maybe we'll start
// detached as client only (jackd server already running?)
if (startJackClient(true)) {
m_ui.StopToolButton->setEnabled(true);
return;
}
// Say that we're starting...
updateServerState(QJACKCTL_STARTING);
// Do we have any startup script?...
if (m_pSetup->bStartupScript
&& !m_pSetup->sStartupScriptShell.isEmpty()) {
shellExecute(m_pSetup->sStartupScriptShell,
tr("Startup script..."),
tr("Startup script terminated"));
}
// Split the server path into arguments...
QStringList args = m_preset.sServerPrefix.split(' ');
// Look for the executable in the search path;
// this enforces the server command to be an
// executable absolute path whenever possible.
QString sCommand = args[0];
QFileInfo fi(sCommand);
if (fi.isRelative()) {
#if defined(WIN32)
const char chPathSep = ';';
if (fi.suffix().isEmpty())
sCommand += ".exe";
#else
const char chPathSep = ':';
#endif
const QString sPath = ::getenv("PATH");
QStringList paths = sPath.split(chPathSep);
QStringListIterator iter(paths);
while (iter.hasNext()) {
const QString& sDirectory = iter.next();
fi.setFile(QDir(sDirectory), sCommand);
if (fi.isExecutable()) {
sCommand = fi.filePath();
break;
}
}
}
// Now that we got a command, remove it from args list...
args.removeAt(0);
// Build process arguments...
bool bDummy = (m_preset.sDriver == "dummy");
bool bSun = (m_preset.sDriver == "sun");
bool bOss = (m_preset.sDriver == "oss");
bool bAlsa = (m_preset.sDriver == "alsa");
bool bPortaudio = (m_preset.sDriver == "portaudio");
bool bCoreaudio = (m_preset.sDriver == "coreaudio");
bool bFreebob = (m_preset.sDriver == "freebob");
bool bFirewire = (m_preset.sDriver == "firewire");
bool bNet = (m_preset.sDriver == "net" || m_preset.sDriver == "netone");
if (!m_pSetup->sServerName.isEmpty())
args.append("-n" + m_pSetup->sServerName);
if (m_preset.bVerbose)
args.append("-v");
if (m_preset.bRealtime) {
// args.append("-R");
if (m_preset.iPriority > 0 && !bCoreaudio)
args.append("-P" + QString::number(m_preset.iPriority));
}
else args.append("-r");
if (m_preset.iPortMax > 0 && m_preset.iPortMax != 256)
args.append("-p" + QString::number(m_preset.iPortMax));
if (m_preset.iTimeout > 0 && m_preset.iTimeout != 500)
args.append("-t" + QString::number(m_preset.iTimeout));
if (m_preset.bNoMemLock)
args.append("-m");
else if (m_preset.bUnlockMem)
args.append("-u");
args.append("-d" + m_preset.sDriver);
if ((bAlsa || bPortaudio) && (m_preset.iAudio != QJACKCTL_DUPLEX ||
m_preset.sInDevice.isEmpty() || m_preset.sOutDevice.isEmpty())) {
QString sInterface = m_preset.sInterface;
if (bAlsa && sInterface.isEmpty())
sInterface = "hw:0";
if (!sInterface.isEmpty())
args.append("-d" + formatQuoted(sInterface));
}
if (bPortaudio && m_preset.iChan > 0)
args.append("-c" + QString::number(m_preset.iChan));
if ((bCoreaudio || bFreebob || bFirewire) && !m_preset.sInterface.isEmpty())
args.append("-d" + formatQuoted(m_preset.sInterface));
if (m_preset.iSampleRate > 0 && !bNet)
args.append("-r" + QString::number(m_preset.iSampleRate));
if (m_preset.iFrames > 0 && !bNet)
args.append("-p" + QString::number(m_preset.iFrames));
if (bAlsa || bSun || bOss || bFreebob || bFirewire) {
if (m_preset.iPeriods > 0)
args.append("-n" + QString::number(m_preset.iPeriods));
}
if (bAlsa) {
if (m_preset.bSoftMode)
args.append("-s");
if (m_preset.bMonitor)
args.append("-m");
if (m_preset.bShorts)
args.append("-S");
if (m_preset.bHWMon)
args.append("-H");
if (m_preset.bHWMeter)
args.append("-M");
#ifdef CONFIG_JACK_MIDI
if (!m_preset.sMidiDriver.isEmpty())
args.append("-X" + formatQuoted(m_preset.sMidiDriver));
#endif
}
if (bAlsa || bPortaudio) {
switch (m_preset.iAudio) {
case QJACKCTL_DUPLEX:
if (!m_preset.sInDevice.isEmpty() || !m_preset.sOutDevice.isEmpty())
args.append("-D");
if (!m_preset.sInDevice.isEmpty())
args.append("-C" + formatQuoted(m_preset.sInDevice));
if (!m_preset.sOutDevice.isEmpty())
args.append("-P" + formatQuoted(m_preset.sOutDevice));
break;
case QJACKCTL_CAPTURE:
args.append("-C" + formatQuoted(m_preset.sInDevice));
break;
case QJACKCTL_PLAYBACK:
args.append("-P" + formatQuoted(m_preset.sOutDevice));
break;
}
if (m_preset.iInChannels > 0 && m_preset.iAudio != QJACKCTL_PLAYBACK)
args.append("-i" + QString::number(m_preset.iInChannels));
if (m_preset.iOutChannels > 0 && m_preset.iAudio != QJACKCTL_CAPTURE)
args.append("-o" + QString::number(m_preset.iOutChannels));
switch (m_preset.iDither) {
case 0:
// args.append("-z-");
break;
case 1:
args.append("-zr");
break;
case 2:
args.append("-zs");
break;
case 3:
args.append("-zt");
break;
}
}
else if (bOss || bSun) {
if (m_preset.bIgnoreHW)
args.append("-b");
if (m_preset.iWordLength > 0)
args.append("-w" + QString::number(m_preset.iWordLength));
if (!m_preset.sInDevice.isEmpty() && m_preset.iAudio != QJACKCTL_PLAYBACK)
args.append("-C" + formatQuoted(m_preset.sInDevice));
if (!m_preset.sOutDevice.isEmpty() && m_preset.iAudio != QJACKCTL_CAPTURE)
args.append("-P" + formatQuoted(m_preset.sOutDevice));
if (m_preset.iAudio == QJACKCTL_PLAYBACK)
args.append("-i0");
else if (m_preset.iInChannels > 0)
args.append("-i" + QString::number(m_preset.iInChannels));
if (m_preset.iAudio == QJACKCTL_CAPTURE)
args.append("-o0");
else if (m_preset.iOutChannels > 0)
args.append("-o" + QString::number(m_preset.iOutChannels));
}
else if (bCoreaudio || bFirewire || bNet) {
if (m_preset.iInChannels > 0 && m_preset.iAudio != QJACKCTL_PLAYBACK)
args.append("-i" + QString::number(m_preset.iInChannels));
if (m_preset.iOutChannels > 0 && m_preset.iAudio != QJACKCTL_CAPTURE)
args.append("-o" + QString::number(m_preset.iOutChannels));
}
else if (bFreebob) {
switch (m_preset.iAudio) {
case QJACKCTL_DUPLEX:
args.append("-D");
break;
case QJACKCTL_CAPTURE:
args.append("-C");
args.append("-o0");
break;
case QJACKCTL_PLAYBACK:
args.append("-P");
args.append("-i0");
break;
}
}
if (bDummy && m_preset.iWait > 0 && m_preset.iWait != 21333)
args.append("-w" + QString::number(m_preset.iWait));
if (bAlsa || bSun || bOss || bCoreaudio || bPortaudio || bFreebob || bFirewire) {
if (m_preset.iInLatency > 0)
args.append("-I" + QString::number(m_preset.iInLatency));
if (m_preset.iOutLatency > 0)
args.append("-O" + QString::number(m_preset.iOutLatency));
}
// Split the server path into arguments...
if (!m_preset.sServerSuffix.isEmpty())
args.append(m_preset.sServerSuffix.split(' '));
// This is emulated jackd command line, for future reference purposes...
m_sJackCmdLine = sCommand + ' ' + args.join(" ").trimmed();
#ifdef CONFIG_DBUS
// Jack D-BUS server backend startup method...
if (m_pDBusControl) {
// Jack D-BUS server backend configuration...
setDBusParameters();
QDBusMessage dbusm = m_pDBusControl->call("StartServer");
if (dbusm.type() == QDBusMessage::ReplyMessage) {
appendMessages(
tr("D-BUS: JACK server is starting..."));
} else {
appendMessagesError(
tr("D-BUS: JACK server could not be started.\n\nSorry"));
}
// Delay our control client...
startJackClientDelay();
} else {
#endif // !CONFIG_DBUS
// Jack classic server backend startup process...
m_pJack = new QProcess(this);
// Setup stdout/stderr capture...
if (m_pSetup->bStdoutCapture) {
#if QT_VERSION >= 0x040200
m_pJack->setProcessChannelMode(QProcess::ForwardedChannels);
#endif
QObject::connect(m_pJack,
SIGNAL(readyReadStandardOutput()),
SLOT(readStdout()));
QObject::connect(m_pJack,
SIGNAL(readyReadStandardError()),
SLOT(readStdout()));
}
// The unforgiveable signal communication...
QObject::connect(m_pJack,
SIGNAL(started()),
SLOT(jackStarted()));
QObject::connect(m_pJack,
SIGNAL(error(QProcess::ProcessError)),
SLOT(jackError(QProcess::ProcessError)));
QObject::connect(m_pJack,
SIGNAL(finished(int, QProcess::ExitStatus)),
SLOT(jackFinished()));
appendMessages(tr("JACK is starting..."));
appendMessagesColor(m_sJackCmdLine, "#990099");
#if defined(WIN32)
const QString& sCurrentDir = QFileInfo(sCommand).dir().absolutePath();
m_pJack->setWorkingDirectory(sCurrentDir);
// QDir::setCurrent(sCurrentDir);
#endif
// Unquote arguments as necessary...
const QChar q = '"';
QStringList cmd_args;
QStringListIterator iter(args);
while (iter.hasNext()) {
const QString& arg = iter.next();
if (arg.contains(q)) {
cmd_args.append(arg.section(q, 0, 0));
cmd_args.append(arg.section(q, 1, 1));
} else {
cmd_args.append(arg);
}
}
// Go jack, go...
m_pJack->start(sCommand, cmd_args);
#ifdef CONFIG_DBUS
}
#endif
}
// Stop jack audio server...
void qjackctlMainForm::stopJack (void)
{
// Check if we're allowed to stop (shutdown)...
if (m_pSetup->bQueryShutdown && m_pConnectionsForm
&& (m_pConnectionsForm->isAudioConnected() ||
m_pConnectionsForm->isMidiConnected())
&& QMessageBox::warning(this,
tr("Warning") + " - " QJACKCTL_SUBTITLE1,
tr("Some client audio applications\n"
"are still active and connected.\n\n"
"Do you want to stop the JACK audio server?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
return;
}
// Stop the server unconditionally.
stopJackServer();
}
// Stop jack audio server...
void qjackctlMainForm::stopJackServer (void)
{
// Clear timer counters...
m_iStartDelay = 0;
m_iTimerDelay = 0;
m_iJackRefresh = 0;
// Stop client code.
stopJackClient();
// And try to stop server.
#ifdef CONFIG_DBUS
if ((m_pJack && m_pJack->state() == QProcess::Running)
|| (m_pDBusControl && m_bDBusStarted)) {
#else
if (m_pJack && m_pJack->state() == QProcess::Running) {
#endif
updateServerState(QJACKCTL_STOPPING);
// Do we have any pre-shutdown script?...
if (m_pSetup->bShutdownScript
&& !m_pSetup->sShutdownScriptShell.isEmpty()) {
shellExecute(m_pSetup->sShutdownScriptShell,
tr("Shutdown script..."),
tr("Shutdown script terminated"));
}
// Now it's the time to real try stopping the server daemon...
if (!m_bJackShutdown) {
// Jack classic server backend...
if (m_pJack) {
appendMessages(tr("JACK is stopping..."));
#if defined(WIN32)
// Try harder...
m_pJack->kill();
#else
// Try softly...
m_pJack->terminate();
#endif
}
#ifdef CONFIG_DBUS
// Jack D-BUS server backend...
if (m_pDBusControl) {
QDBusMessage dbusm = m_pDBusControl->call("StopServer");
if (dbusm.type() == QDBusMessage::ReplyMessage) {
appendMessages(
tr("D-BUS: JACK server is stopping..."));
} else {
appendMessagesError(
tr("D-BUS: JACK server could not be stopped.\n\nSorry"));
}
}
#endif
// Give it some time to terminate gracefully and stabilize...
stabilize(QJACKCTL_TIMER_MSECS);
// Keep on, if not exiting for good.
if (!m_bQuitForce)
return;
}
}
// Do final processing anyway.
jackCleanup();
}
// Stdout handler...
void qjackctlMainForm::readStdout (void)
{
appendStdoutBuffer(m_pJack->readAllStandardOutput());
}
// Stdout buffer handler -- now splitted by complete new-lines...
void qjackctlMainForm::appendStdoutBuffer ( const QString& s )
{
m_sStdoutBuffer.append(s);
int iLength = m_sStdoutBuffer.lastIndexOf('\n') + 1;
if (iLength > 0) {
QString sTemp = m_sStdoutBuffer.left(iLength);
m_sStdoutBuffer.remove(0, iLength);
QStringListIterator iter(sTemp.split('\n'));
while (iter.hasNext()) {
sTemp = iter.next();
if (!sTemp.isEmpty())
appendMessagesText(detectXrun(sTemp));
}
}
}
// Stdout flusher -- show up any unfinished line...
void qjackctlMainForm::flushStdoutBuffer (void)
{
if (!m_sStdoutBuffer.isEmpty()) {
appendMessagesText(detectXrun(m_sStdoutBuffer));
m_sStdoutBuffer.truncate(0);
}
}
// Jack audio server startup.
void qjackctlMainForm::jackStarted (void)
{
// Show startup results...
if (m_pJack) {
appendMessages(tr("JACK was started with PID=%1.")
.arg(long(m_pJack->pid())));
}
#ifdef CONFIG_DBUS
// Special for D-BUS control....
if (m_pDBusControl) {
m_bDBusStarted = true;
appendMessages(tr("D-BUS: JACK server was started (%1 aka jackdbus).")
.arg(m_pDBusControl->service()));
}
#endif
// Delay our control client...
startJackClientDelay();
}
// Jack audio server got an error.
void qjackctlMainForm::jackError ( QProcess::ProcessError error )
{
qjackctl_on_error(error);
}
// Jack audio server finish.
void qjackctlMainForm::jackFinished (void)
{
// Force client code cleanup.
if (!m_bJackShutdown)
jackCleanup();
}
// Jack audio server cleanup.
void qjackctlMainForm::jackCleanup (void)
{
// Force client code cleanup.
bool bPostShutdown = m_bJackDetach;
if (!bPostShutdown)
stopJackClient();
// Flush anything that maybe pending...
flushStdoutBuffer();
// Classic server control...
if (m_pJack) {
if (m_pJack->state() != QProcess::NotRunning) {
appendMessages(tr("JACK is being forced..."));
// Force final server shutdown...
m_pJack->kill();
// Give it some time to terminate gracefully and stabilize...
stabilize(QJACKCTL_TIMER_MSECS);
}
// Force final server shutdown...
appendMessages(tr("JACK was stopped")
+ formatExitStatus(m_pJack->exitCode()));
// Destroy it.
delete m_pJack;
m_pJack = NULL;
// Flag we need a post-shutdown script...
bPostShutdown = true;
}
#ifdef CONFIG_DBUS
// Special for D-BUS control...
if (m_pDBusControl && m_bDBusStarted) {
m_bDBusStarted = false;
appendMessages(tr("D-BUS: JACK server was stopped (%1 aka jackdbus).")
.arg(m_pDBusControl->service()));
// Flag we need a post-shutdown script...
bPostShutdown = true;
}
#endif
// Cannot be detached anymore.
m_bJackDetach = false;
// Do we have any post-shutdown script?...
// (this will be always called, despite we've started the server or not)
if (bPostShutdown && m_pSetup->bPostShutdownScript
&& !m_pSetup->sPostShutdownScriptShell.isEmpty()) {
shellExecute(m_pSetup->sPostShutdownScriptShell,
tr("Post-shutdown script..."),
tr("Post-shutdown script terminated"));
}
// Reset server name.
m_pSetup->sServerName.clear();
// Stabilize final server state...
jackStabilize();
}
// Stabilize server state...
void qjackctlMainForm::jackStabilize (void)
{
QPalette pal;
pal.setColor(QPalette::Foreground,
m_pJackClient == NULL ? Qt::darkYellow : Qt::yellow);
m_ui.ServerStateTextLabel->setPalette(pal);
m_ui.StartToolButton->setEnabled(m_pJackClient == NULL);
m_ui.StopToolButton->setEnabled(m_pJackClient != NULL);
m_ui.RewindToolButton->setEnabled(false);
m_ui.BackwardToolButton->setEnabled(false);
m_ui.PlayToolButton->setEnabled(false);
m_ui.PauseToolButton->setEnabled(false);
m_ui.ForwardToolButton->setEnabled(false);
transportPlayStatus(false);
int iServerState;
if (m_bJackDetach)
iServerState = (m_pJackClient ? QJACKCTL_ACTIVE : QJACKCTL_INACTIVE);
else
iServerState = QJACKCTL_STOPPED;
updateServerState(iServerState);
}
// XRUN detection routine.
QString& qjackctlMainForm::detectXrun ( QString& s )
{
if (m_iXrunSkips > 1)
return s;
QRegExp rx(m_pSetup->sXrunRegex);
int iPos = rx.indexIn(s);
if (iPos >= 0) {
s.insert(iPos + rx.matchedLength(), "</font>");
s.insert(iPos, "<font color=\"#cc0000\">");
#ifndef CONFIG_JACK_XRUN_DELAY
m_tXrunLast.restart();
updateXrunStats(rx.cap(1).toFloat());
refreshXrunStats();
#endif
}
return s;
}
// Update the XRUN last delay and immediate statistical values (in msecs).
void qjackctlMainForm::updateXrunStats ( float fXrunLast )
{
if (m_iXrunStats > 0) {
m_fXrunLast = fXrunLast;
m_fXrunTotal += m_fXrunLast;
if (m_fXrunLast < m_fXrunMin || m_iXrunCount == 0)
m_fXrunMin = m_fXrunLast;
if (m_fXrunLast > m_fXrunMax || m_iXrunCount == 0)
m_fXrunMax = m_fXrunLast;
m_iXrunCount++;
// refreshXrunStats();
}
m_iXrunStats++;
}
// Own stdout/stderr socket notifier slot.
void qjackctlMainForm::stdoutNotifySlot ( int fd )
{
char achBuffer[1024];
int cchBuffer = ::read(fd, achBuffer, sizeof(achBuffer) - 1);
if (cchBuffer > 0) {
achBuffer[cchBuffer] = (char) 0;
appendStdoutBuffer(achBuffer);
}
}
// Messages output methods.
void qjackctlMainForm::appendMessages ( const QString& s )
{
if (m_pMessagesStatusForm)
m_pMessagesStatusForm->appendMessages(s);
}
void qjackctlMainForm::appendMessagesColor ( const QString& s, const QString& c )
{
if (m_pMessagesStatusForm)
m_pMessagesStatusForm->appendMessagesColor(s, c);
}
void qjackctlMainForm::appendMessagesText ( const QString& s )
{
if (m_pMessagesStatusForm)
m_pMessagesStatusForm->appendMessagesText(s);
}
void qjackctlMainForm::appendMessagesError ( const QString& s )
{
if (m_pMessagesStatusForm) {
m_pMessagesStatusForm->setTabPage(
int(qjackctlMessagesStatusForm::MessagesTab));
m_pMessagesStatusForm->show();
}
appendMessagesColor(s.simplified(), "#ff0000");
const QString& sTitle = tr("Error") + " - " QJACKCTL_SUBTITLE1;
#ifdef CONFIG_SYSTEM_TRAY
#ifdef QJACKCTL_QT4_SYSTEM_TRAY
#if QT_VERSION >= 0x040300
if (m_pSetup->bSystemTray && m_pSystemTray
&& QSystemTrayIcon::supportsMessages()) {
m_pSystemTray->showMessage(sTitle, s, QSystemTrayIcon::Critical);
}
else
#endif
#endif
#endif
QMessageBox::critical(this, sTitle, s, QMessageBox::Cancel);
}
// Force update of the messages font.
void qjackctlMainForm::updateMessagesFont (void)
{
if (m_pSetup == NULL)
return;
if (m_pMessagesStatusForm && !m_pSetup->sMessagesFont.isEmpty()) {
QFont font;
if (font.fromString(m_pSetup->sMessagesFont))
m_pMessagesStatusForm->setMessagesFont(font);
}
}
// Update messages window line limit.
void qjackctlMainForm::updateMessagesLimit (void)
{
if (m_pSetup == NULL)
return;
if (m_pMessagesStatusForm) {
if (m_pSetup->bMessagesLimit)
m_pMessagesStatusForm->setMessagesLimit(m_pSetup->iMessagesLimitLines);
else
m_pMessagesStatusForm->setMessagesLimit(-1);
}
}
// Force update of the connections font.
void qjackctlMainForm::updateConnectionsFont (void)
{
if (m_pSetup == NULL)
return;
if (m_pConnectionsForm && !m_pSetup->sConnectionsFont.isEmpty()) {
QFont font;
if (font.fromString(m_pSetup->sConnectionsFont))
m_pConnectionsForm->setConnectionsFont(font);
}
}
// Update of the connections view icon size.
void qjackctlMainForm::updateConnectionsIconSize (void)
{
if (m_pSetup == NULL)
return;
if (m_pConnectionsForm)
m_pConnectionsForm->setConnectionsIconSize(m_pSetup->iConnectionsIconSize);
}
// Update of JACK client/port alias display mode.
void qjackctlMainForm::updateJackClientPortAlias (void)
{
if (m_pSetup == NULL)
return;
qjackctlJackClientList::setJackClientPortAlias(m_pSetup->iJackClientPortAlias);
refreshJackConnections();
}
// Update the connection and patchbay line style.
void qjackctlMainForm::updateBezierLines (void)
{
if (m_pSetup == NULL)
return;
if (m_pConnectionsForm) {
m_pConnectionsForm->audioConnectView()->setBezierLines(m_pSetup->bBezierLines);
m_pConnectionsForm->midiConnectView()->setBezierLines(m_pSetup->bBezierLines);
m_pConnectionsForm->alsaConnectView()->setBezierLines(m_pSetup->bBezierLines);
m_pConnectionsForm->audioConnectView()->ConnectorView()->update();
m_pConnectionsForm->midiConnectView()->ConnectorView()->update();
m_pConnectionsForm->alsaConnectView()->ConnectorView()->update();
}
if (m_pPatchbayForm) {
m_pPatchbayForm->patchbayView()->setBezierLines(m_pSetup->bBezierLines);
m_pPatchbayForm->patchbayView()->PatchworkView()->update();
}
}
// Update main display background effect.
void qjackctlMainForm::updateDisplayEffect (void)
{
if (m_pSetup == NULL)
return;
// Set the main background...
QPalette pal;
if (m_pSetup->bDisplayEffect) {
QPixmap pm(":/images/displaybg1.png");
pal.setBrush(QPalette::Background, QBrush(pm));
} else {
pal.setColor(QPalette::Background, Qt::black);
}
m_ui.StatusDisplayFrame->setPalette(pal);
}
// Force update of big time display related fonts.
void qjackctlMainForm::updateTimeDisplayFonts (void)
{
QFont font;
if (!m_pSetup->sDisplayFont1.isEmpty() && font.fromString(m_pSetup->sDisplayFont1))
m_ui.TimeDisplayTextLabel->setFont(font);
if (!m_pSetup->sDisplayFont2.isEmpty() && font.fromString(m_pSetup->sDisplayFont2)) {
m_ui.ServerStateTextLabel->setFont(font);
m_ui.ServerModeTextLabel->setFont(font);
m_ui.DspLoadTextLabel->setFont(font);
m_ui.SampleRateTextLabel->setFont(font);
m_ui.XrunCountTextLabel->setFont(font);
m_ui.TransportStateTextLabel->setFont(font);
m_ui.TransportBPMTextLabel->setFont(font);
font.setBold(true);
m_ui.TransportTimeTextLabel->setFont(font);
}
}
// Force update of big time display related tooltips.
void qjackctlMainForm::updateTimeDisplayToolTips (void)
{
QString sTimeDisplay = tr("Transport BBT (bar.beat.ticks)");
QString sTransportTime = tr("Transport time code");
switch (m_pSetup->iTimeDisplay) {
case DISPLAY_TRANSPORT_TIME:
{
QString sTemp = sTimeDisplay;
sTimeDisplay = sTransportTime;
sTransportTime = sTemp;
break;
}
case DISPLAY_RESET_TIME:
sTimeDisplay = tr("Elapsed time since last reset");
break;
case DISPLAY_XRUN_TIME:
sTimeDisplay = tr("Elapsed time since last XRUN");
break;
}
m_ui.TimeDisplayTextLabel->setToolTip(sTimeDisplay);
m_ui.TransportTimeTextLabel->setToolTip(sTransportTime);
}
// Force update of time format dependant stuff.
void qjackctlMainForm::updateTimeFormat (void)
{
// Time dashes format helper.
m_sTimeDashes = "--:--:--";
switch (m_pSetup->iTimeFormat) {
case 1: // Tenths of second.
m_sTimeDashes += ".-";
break;
case 2: // Hundredths of second.
m_sTimeDashes += ".--";
break;
case 3: // Raw milliseconds
m_sTimeDashes += ".---";
break;
}
}
// Update the connections client/port aliases.
void qjackctlMainForm::updateAliases (void)
{
if (m_pConnectionsForm)
m_pConnectionsForm->updateAliases();
}
// Update the main form buttons display.
void qjackctlMainForm::updateButtons (void)
{
updateTitleStatus();
if (m_pSetup->bLeftButtons) {
m_ui.StartToolButton->show();
m_ui.StopToolButton->show();
m_ui.MessagesStatusToolButton->show();
m_ui.SessionToolButton->show();
m_ui.ConnectionsToolButton->show();
m_ui.PatchbayToolButton->show();
} else {
m_ui.StartToolButton->hide();
m_ui.StopToolButton->hide();
m_ui.MessagesStatusToolButton->hide();
m_ui.SessionToolButton->hide();
m_ui.ConnectionsToolButton->hide();
m_ui.PatchbayToolButton->hide();
}
if (m_pSetup->bRightButtons) {
m_ui.QuitToolButton->show();
m_ui.SetupToolButton->show();
} else {
m_ui.QuitToolButton->hide();
m_ui.SetupToolButton->hide();
}
if (m_pSetup->bRightButtons &&
(m_pSetup->bLeftButtons || m_pSetup->bTransportButtons)) {
m_ui.AboutToolButton->show();
} else {
m_ui.AboutToolButton->hide();
}
if (m_pSetup->bLeftButtons || m_pSetup->bTransportButtons) {
m_ui.RewindToolButton->show();
m_ui.BackwardToolButton->show();
m_ui.PlayToolButton->show();
m_ui.PauseToolButton->show();
m_ui.ForwardToolButton->show();
} else {
m_ui.RewindToolButton->hide();
m_ui.BackwardToolButton->hide();
m_ui.PlayToolButton->hide();
m_ui.PauseToolButton->hide();
m_ui.ForwardToolButton->hide();
}
Qt::ToolButtonStyle toolButtonStyle = (m_pSetup->bTextLabels
? Qt::ToolButtonTextBesideIcon : Qt::ToolButtonIconOnly);
m_ui.StartToolButton->setToolButtonStyle(toolButtonStyle);
m_ui.StopToolButton->setToolButtonStyle(toolButtonStyle);
m_ui.MessagesStatusToolButton->setToolButtonStyle(toolButtonStyle);
m_ui.SessionToolButton->setToolButtonStyle(toolButtonStyle);
m_ui.ConnectionsToolButton->setToolButtonStyle(toolButtonStyle);
m_ui.PatchbayToolButton->setToolButtonStyle(toolButtonStyle);
m_ui.QuitToolButton->setToolButtonStyle(toolButtonStyle);
m_ui.SetupToolButton->setToolButtonStyle(toolButtonStyle);
m_ui.AboutToolButton->setToolButtonStyle(toolButtonStyle);
adjustSize();
}
// Force update of active patchbay definition profile, if applicable.
bool qjackctlMainForm::isActivePatchbay ( const QString& sPatchbayPath ) const
{
bool bActive = false;
if (m_pSetup && m_pSetup->bActivePatchbay && !m_pSetup->sActivePatchbayPath.isEmpty())
bActive = (m_pSetup->sActivePatchbayPath == sPatchbayPath);
return bActive;
}
// Force update of active patchbay definition profile, if applicable.
void qjackctlMainForm::updateActivePatchbay (void)
{
if (m_pSetup == NULL)
return;
// Time to load the active patchbay rack profiler?
if (m_pSetup->bActivePatchbay && !m_pSetup->sActivePatchbayPath.isEmpty()) {
QFileInfo fi(m_pSetup->sActivePatchbayPath);
if (fi.isRelative())
m_pSetup->sActivePatchbayPath = fi.absoluteFilePath();
if (!qjackctlPatchbayFile::load(m_pPatchbayRack, m_pSetup->sActivePatchbayPath)) {
appendMessagesError(
tr("Could not load active patchbay definition.\n\n\"%1\"\n\nDisabled.")
.arg(m_pSetup->sActivePatchbayPath));
m_pSetup->bActivePatchbay = false;
} else {
appendMessages(tr("Patchbay activated."));
// If we're up and running, make it dirty :)
if (m_pJackClient)
m_iJackDirty++;
if (m_pAlsaSeq)
m_iAlsaDirty++;
}
} // We're sure there's no active patchbay...
else appendMessages(tr("Patchbay deactivated."));
// Should refresh anyway.
m_iPatchbayRefresh++;
}
// Toggle active patchbay setting.
void qjackctlMainForm::setActivePatchbay ( const QString& sPatchbayPath )
{
if (m_pSetup == NULL)
return;
if (sPatchbayPath.isEmpty()) {
m_pSetup->bActivePatchbay = false;
} else {
m_pSetup->bActivePatchbay = true;
m_pSetup->sActivePatchbayPath = sPatchbayPath;
}
updateActivePatchbay();
}
// Reset the MRU patchbay list.
void qjackctlMainForm::setRecentPatchbays ( const QStringList& patchbays )
{
m_pSetup->patchbays = patchbays;
}
// Stabilize current form toggle buttons that may be astray.
void qjackctlMainForm::stabilizeForm (void)
{
m_ui.MessagesStatusToolButton->setChecked(
m_pMessagesStatusForm && m_pMessagesStatusForm->isVisible());
m_ui.SessionToolButton->setChecked(
m_pSessionForm && m_pSessionForm->isVisible());
m_ui.ConnectionsToolButton->setChecked(
m_pConnectionsForm && m_pConnectionsForm->isVisible());
m_ui.PatchbayToolButton->setChecked(
m_pPatchbayForm && m_pPatchbayForm->isVisible());
}
// Stabilize current business over the application event loop.
void qjackctlMainForm::stabilize ( int msecs )
{
QTime t;
t.start();
while (t.elapsed() < msecs)
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
// Reset XRUN cache items.
void qjackctlMainForm::resetXrunStats (void)
{
m_tResetLast = QTime::currentTime();
m_iXrunStats = 0;
m_iXrunCount = 0;
m_fXrunTotal = 0.0f;
m_fXrunMin = 0.0f;
m_fXrunMax = 0.0f;
m_fXrunLast = 0.0f;
m_tXrunLast.setHMS(0, 0, 0);
m_iXrunCallbacks = 0;
m_iXrunSkips = 0;
#ifdef CONFIG_JACK_MAX_DELAY
if (m_pJackClient)
jack_reset_max_delayed_usecs(m_pJackClient);
#endif
refreshXrunStats();
appendMessages(tr("Statistics reset."));
// Make sure all status(es) will be updated ASAP.
m_iStatusRefresh += QJACKCTL_STATUS_CYCLE;
}
// Update the XRUN count/callbacks item.
void qjackctlMainForm::updateXrunCount (void)
{
// We'll change XRUN status colors here!
QColor color = (m_pJackClient ? Qt::green : Qt::darkGreen);
if ((m_iXrunCount + m_iXrunCallbacks) > 0) {
if (m_iXrunCallbacks > 0)
color = (m_pJackClient ? Qt::red : Qt::darkRed);
else
color = (m_pJackClient ? Qt::yellow : Qt::darkYellow);
// Change the system tray icon background color!
if (m_pSystemTray)
m_pSystemTray->setBackground(color);
} // Reset the system tray icon background!
else if (m_pSystemTray)
m_pSystemTray->setBackground(Qt::transparent);
QPalette pal;
pal.setColor(QPalette::Foreground, color);
m_ui.XrunCountTextLabel->setPalette(pal);
QString sText = QString::number(m_iXrunCount);
sText += " (";
sText += QString::number(m_iXrunCallbacks);
sText += ")";
updateStatusItem(STATUS_XRUN_COUNT, sText);
}
// Convert whole elapsed seconds to hh:mm:ss time format.
QString qjackctlMainForm::formatTime ( float secs ) const
{
unsigned int hh, mm, ss;
hh = mm = ss = 0;
if (secs >= 3600.0f) {
hh = (unsigned int) (secs / 3600.0f);
secs -= (float) hh * 3600.0f;
}
if (secs >= 60.0f) {
mm = (unsigned int) (secs / 60.0f);
secs -= (float) mm * 60.0f;
}
if (secs >= 0.0) {
ss = (unsigned int) secs;
secs -= (float) ss;
}
QString sTemp;
switch (m_pSetup->iTimeFormat) {
case 1: // Tenths of second.
sTemp.sprintf("%02u:%02u:%02u.%u", hh, mm, ss,
(unsigned int) (secs * 10.0f));
break;
case 2: // Hundredths of second.
sTemp.sprintf("%02u:%02u:%02u.%02u", hh, mm, ss,
(unsigned int) (secs * 100.0f));
break;
case 3: // Raw milliseconds
sTemp.sprintf("%02u:%02u:%02u.%03u", hh, mm, ss,
(unsigned int) (secs * 1000.0f));
break;
default: // No second decimation.
sTemp.sprintf("%02u:%02u:%02u", hh, mm, ss);
break;
}
return sTemp;
}
// Update the XRUN last/elapsed time item.
QString qjackctlMainForm::formatElapsedTime ( int iStatusItem,
const QTime& t, bool bElapsed ) const
{
QString sTemp = m_sTimeDashes;
QString sText;
// Compute and format elapsed time.
if (t.isNull()) {
sText = sTemp;
} else {
sText = t.toString();
if (m_pJackClient) {
float secs = float(t.elapsed()) / 1000.0f;
if (bElapsed && secs > 0) {
sTemp = formatTime(secs);
sText += " (" + sTemp + ")";
}
}
}
// Display elapsed time as big time?
if ((iStatusItem == STATUS_RESET_TIME
&& m_pSetup->iTimeDisplay == DISPLAY_RESET_TIME) ||
(iStatusItem == STATUS_XRUN_TIME
&& m_pSetup->iTimeDisplay == DISPLAY_XRUN_TIME)) {
m_ui.TimeDisplayTextLabel->setText(sTemp);
}
return sText;
}
// Update the XRUN last/elapsed time item.
void qjackctlMainForm::updateElapsedTimes (void)
{
// Display time remaining on start delay...
if (m_iTimerDelay < m_iStartDelay)
m_ui.TimeDisplayTextLabel->setText(formatTime(
float(m_iStartDelay - m_iTimerDelay) / 1000.0f));
else {
updateStatusItem(STATUS_RESET_TIME,
formatElapsedTime(STATUS_RESET_TIME,
m_tResetLast, true));
updateStatusItem(STATUS_XRUN_TIME,
formatElapsedTime(STATUS_XRUN_TIME,
m_tXrunLast, ((m_iXrunCount + m_iXrunCallbacks) > 0)));
}
}
// Update the XRUN list view items.
void qjackctlMainForm::refreshXrunStats (void)
{
updateXrunCount();
if (m_fXrunTotal < 0.001f) {
QString n = "--";
updateStatusItem(STATUS_XRUN_TOTAL, n);
updateStatusItem(STATUS_XRUN_MIN, n);
updateStatusItem(STATUS_XRUN_MAX, n);
updateStatusItem(STATUS_XRUN_AVG, n);
updateStatusItem(STATUS_XRUN_LAST, n);
} else {
float fXrunAverage = 0.0f;
if (m_iXrunCount > 0)
fXrunAverage = (m_fXrunTotal / m_iXrunCount);
QString s = " " + tr("msec");
updateStatusItem(STATUS_XRUN_TOTAL, QString::number(m_fXrunTotal) + s);
updateStatusItem(STATUS_XRUN_MIN, QString::number(m_fXrunMin) + s);
updateStatusItem(STATUS_XRUN_MAX, QString::number(m_fXrunMax) + s);
updateStatusItem(STATUS_XRUN_AVG, QString::number(fXrunAverage) + s);
updateStatusItem(STATUS_XRUN_LAST, QString::number(m_fXrunLast) + s);
}
updateElapsedTimes();
}
// Jack socket notifier port/graph callback funtion.
void qjackctlMainForm::portNotifyEvent (void)
{
// Log some message here, if new.
if (m_iJackRefresh == 0)
appendMessagesColor(tr("JACK connection graph change."), "#cc9966");
// Do what has to be done.
refreshJackConnections();
// We'll be dirty too...
m_iJackDirty++;
}
// Jack socket notifier XRUN callback funtion.
void qjackctlMainForm::xrunNotifyEvent (void)
{
// Just increment callback counter.
m_iXrunCallbacks++;
// Skip this one? Maybe we're under some kind of storm...
m_iXrunSkips++;
// Report rate must be under one second...
if (m_tXrunLast.restart() < 1000)
return;
#ifdef CONFIG_JACK_XRUN_DELAY
// We have an official XRUN delay value (convert usecs to msecs)...
updateXrunStats(0.001f * jack_get_xrun_delayed_usecs(m_pJackClient));
#endif
// Just log this single event...
appendMessagesColor(tr("XRUN callback (%1).")
.arg(m_iXrunCallbacks), "#cc66cc");
}
// Jack buffer size notifier callback funtion.
void qjackctlMainForm::buffNotifyEvent (void)
{
// Don't need to nothing, it was handled on qjackctl_buffer_size_callback;
// just log this event as routine.
appendMessagesColor(tr("Buffer size change (%1).")
.arg((int) g_nframes), "#996633");
}
// Jack socket notifier callback funtion.
void qjackctlMainForm::shutNotifyEvent (void)
{
// Log this event.
appendMessagesColor(tr("Shutdown notification."), "#cc6666");
// SHUTDOWN: JACK client handle might not be valid anymore...
m_bJackShutdown = true;
// m_pJackClient = NULL;
// Do what has to be done.
stopJackServer();
}
// Process error slot
void qjackctlMainForm::exitNotifyEvent (void)
{
// Poor-mans read, copy, update (RCU)
QProcess::ProcessError error = g_error;
g_error = QProcess::UnknownError;
switch (error) {
case QProcess::FailedToStart:
appendMessagesError(tr("Could not start JACK.\n\nSorry."));
jackFinished();
break;
case QProcess::Crashed:
appendMessagesColor(tr("JACK has crashed."), "#cc3366");
break;
case QProcess::Timedout:
appendMessagesColor(tr("JACK timed out."), "#cc3366");
break;
case QProcess::WriteError:
appendMessagesColor(tr("JACK write error."), "#cc3366");
break;
case QProcess::ReadError:
appendMessagesColor(tr("JACK read error."), "#cc3366");
break;
case QProcess::UnknownError:
default:
appendMessagesColor(tr("Unknown JACK error (%d).")
.arg(int(error)), "#990099");
break;
}
}
// ALSA announce slot.
void qjackctlMainForm::alsaNotifySlot ( int /*fd*/ )
{
#ifdef CONFIG_ALSA_SEQ
snd_seq_event_t *pAlsaEvent;
snd_seq_event_input(m_pAlsaSeq, &pAlsaEvent);
snd_seq_free_event(pAlsaEvent);
#endif
// Log some message here, if new.
if (m_iAlsaRefresh == 0)
appendMessagesColor(tr("ALSA connection graph change."), "#66cc99");
// Do what has to be done.
refreshAlsaConnections();
// We'll be dirty too...
m_iAlsaDirty++;
}
// Timer callback funtion.
void qjackctlMainForm::timerSlot (void)
{
// Is it the first shot on server start after a few delay?
if (m_iTimerDelay < m_iStartDelay) {
m_iTimerDelay += QJACKCTL_TIMER_MSECS;
if (m_iTimerDelay >= m_iStartDelay) {
// If we cannot start it now,
// maybe we ought to cease & desist...
if (!startJackClient(false))
stopJackServer();
}
}
// Is the connection patchbay dirty enough?
if (m_pConnectionsForm) {
const QString sEllipsis = "...";
// Are we about to enforce an audio connections persistence profile?
if (m_iJackDirty > 0) {
m_iJackDirty = 0;
if (m_pSessionForm)
m_pSessionForm->updateSession();
if (m_pSetup->bActivePatchbay) {
appendMessagesColor(
tr("JACK active patchbay scan") + sEllipsis, "#6699cc");
m_pPatchbayRack->connectJackScan(m_pJackClient);
}
refreshJackConnections();
}
// Or is it from the MIDI field?
if (m_iAlsaDirty > 0) {
m_iAlsaDirty = 0;
if (m_pSetup->bActivePatchbay) {
appendMessagesColor(
tr("ALSA active patchbay scan") + sEllipsis, "#99cc66");
m_pPatchbayRack->connectAlsaScan(m_pAlsaSeq);
}
refreshAlsaConnections();
}
#ifdef CONFIG_AUTO_REFRESH
// Shall we refresh connections now and then?
if (m_pSetup->bAutoRefresh) {
m_iTimerRefresh += QJACKCTL_TIMER_MSECS;
if (m_iTimerRefresh >= (m_pSetup->iTimeRefresh * 1000)) {
m_iTimerRefresh = 0;
refreshConnections();
}
}
#endif
// Are we about to refresh it, really?
if (m_iJackRefresh > 0 && m_pJackClient != NULL) {
m_iJackRefresh = 0;
m_pConnectionsForm->refreshAudio(true);
m_pConnectionsForm->refreshMidi(true);
}
if (m_iAlsaRefresh > 0 && m_pAlsaSeq != NULL) {
m_iAlsaRefresh = 0;
m_pConnectionsForm->refreshAlsa(true);
}
}
// Is the patchbay dirty enough?
if (m_pPatchbayForm && m_iPatchbayRefresh > 0) {
m_iPatchbayRefresh = 0;
m_pPatchbayForm->refreshForm();
}
// Update some statistical fields, directly.
refreshStatus();
// Register the next timer slot.
QTimer::singleShot(QJACKCTL_TIMER_MSECS, this, SLOT(timerSlot()));
}
// JACK connection notification slot.
void qjackctlMainForm::jackConnectChanged (void)
{
// Just shake the audio connections status quo.
if (++m_iJackDirty == 1)
appendMessagesColor(tr("JACK connection change."), "#9999cc");
}
// ALSA connection notification slot.
void qjackctlMainForm::alsaConnectChanged (void)
{
// Just shake the MIDI connections status quo.
if (++m_iAlsaDirty == 1)
appendMessagesColor(tr("ALSA connection change."), "#cccc99");
}
// Cable connection notification slot.
void qjackctlMainForm::cableConnectSlot (
const QString& sOutputPort, const QString& sInputPort,
unsigned int ulCableFlags )
{
QString sText = QFileInfo(m_pSetup->sActivePatchbayPath).baseName() + ": ";
QString sColor;
sText += sOutputPort;
sText += " -> ";
sText += sInputPort;
sText += " ";
switch (ulCableFlags) {
case QJACKCTL_CABLE_CHECKED:
sText += tr("checked");
sColor = "#99cccc";
break;
case QJACKCTL_CABLE_CONNECTED:
sText += tr("connected");
sColor = "#669999";
break;
case QJACKCTL_CABLE_DISCONNECTED:
sText += tr("disconnected");
sColor = "#cc9999";
break;
case QJACKCTL_CABLE_FAILED:
default:
sText += tr("failed");
sColor = "#cc6699";
break;
}
appendMessagesColor(sText + '.', sColor);
}
// Patchbay (dis)connection slot.
void qjackctlMainForm::queryDisconnect (
qjackctlPortItem *pOPort, qjackctlPortItem *pIPort, int iSocketType )
{
if (m_pSetup->bActivePatchbay) {
qjackctlPatchbayCable *pCable = m_pPatchbayRack->findCable(
pOPort->clientName(), pOPort->portName(),
pIPort->clientName(), pIPort->portName(), iSocketType);
if (pCable && QMessageBox::warning(this,
tr("Warning") + " - " QJACKCTL_SUBTITLE1,
tr("A patchbay definition is currently active,\n"
"which is probable to redo this connection:\n\n"
"%1 -> %2\n\n"
"Do you want to remove the patchbay connection?")
.arg(pCable->outputSocket()->name())
.arg(pCable->inputSocket()->name()),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
m_pPatchbayRack->removeCable(pCable);
if (m_pPatchbayForm
&& isActivePatchbay(m_pPatchbayForm->patchbayPath()))
m_pPatchbayForm->loadPatchbayRack(m_pPatchbayRack);
}
}
}
// Delay jack control client start...
void qjackctlMainForm::startJackClientDelay (void)
{
// Sloppy boy fix: may the serve be stopped, just in case
// the client will nerver make it...
m_ui.StopToolButton->setEnabled(true);
// Make sure all status(es) will be updated ASAP...
m_iStatusRefresh += QJACKCTL_STATUS_CYCLE;
m_iStatusBlink = 0;
// Reset (yet again) the timer counters...
m_iStartDelay = 1 + (m_preset.iStartDelay * 1000);
m_iTimerDelay = 0;
m_iJackRefresh = 0;
}
// Start our jack audio control client...
bool qjackctlMainForm::startJackClient ( bool bDetach )
{
// If can't be already started, are we?
if (m_pJackClient)
return true;
// Have it a setup?
if (m_pSetup == NULL)
return false;
// Time to (re)load current preset aliases?
if (m_pConnectionsForm && !m_pConnectionsForm->loadAliases())
return false;
// Make sure all status(es) will be updated ASAP.
m_iStatusRefresh += QJACKCTL_STATUS_CYCLE;
m_iStatusBlink = 0;
// Are we about to start detached?
if (bDetach) {
// To fool timed client initialization delay.
m_iTimerDelay += (m_iStartDelay + 1);
// Refresh status (with dashes?)
refreshStatus();
}
// Create the jack client handle, using a distinct identifier (PID?)
const char *pszClientName = "qjackctl";
jack_status_t status = JackFailure;
if (m_pSetup->sServerName.isEmpty()) {
m_pJackClient = jack_client_open(pszClientName,
JackNoStartServer, &status);
} else {
m_pJackClient = jack_client_open(pszClientName,
jack_options_t(JackNoStartServer | JackServerName), &status,
m_pSetup->sServerName.toUtf8().constData());
}
if (m_pJackClient == NULL) {
if (!bDetach) {
QStringList errs;
if (status & JackFailure)
errs << tr("Overall operation failed.");
if (status & JackInvalidOption)
errs << tr("Invalid or unsupported option.");
if (status & JackNameNotUnique)
errs << tr("Client name not unique.");
if (status & JackServerStarted)
errs << tr("Server is started.");
if (status & JackServerFailed)
errs << tr("Unable to connect to server.");
if (status & JackServerError)
errs << tr("Server communication error.");
if (status & JackNoSuchClient)
errs << tr("Client does not exist.");
if (status & JackLoadFailure)
errs << tr("Unable to load internal client.");
if (status & JackInitFailure)
errs << tr("Unable to initialize client.");
if (status & JackShmFailure)
errs << tr("Unable to access shared memory.");
if (status & JackVersionError)
errs << tr("Client protocol version mismatch.");
appendMessagesError(
tr("Could not connect to JACK server as client.\n"
"- %1\nPlease check the messages window for more info.")
.arg(errs.join("\n- ")));
}
return false;
}
// Set notification callbacks.
jack_set_graph_order_callback(m_pJackClient,
qjackctl_graph_order_callback, this);
jack_set_port_registration_callback(m_pJackClient,
qjackctl_port_registration_callback, this);
jack_set_xrun_callback(m_pJackClient,
qjackctl_xrun_callback, this);
jack_set_buffer_size_callback(m_pJackClient,
qjackctl_buffer_size_callback, this);
jack_on_shutdown(m_pJackClient,
qjackctl_on_shutdown, this);
// First knowledge about buffer size.
g_nframes = jack_get_buffer_size(m_pJackClient);
// Reconstruct our connections and session...
if (m_pConnectionsForm) {
m_pConnectionsForm->stabilizeAudio(true);
m_pConnectionsForm->stabilizeMidi(true);
}
if (m_pSessionForm)
m_pSessionForm->stabilizeForm(true);
// Save server configuration file.
if (m_pSetup->bServerConfig && !m_sJackCmdLine.isEmpty()) {
QString sJackCmdLine = m_sJackCmdLine;
if (m_pSetup->bServerConfigTemp) {
int iPos = sJackCmdLine.indexOf(' ');
if (iPos > 0)
sJackCmdLine = sJackCmdLine.insert(iPos, " -T");
}
QString sFilename = ::getenv("HOME");
sFilename += '/' + m_pSetup->sServerConfigName;
QFile file(sFilename);
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QTextStream(&file) << sJackCmdLine << endl;
file.close();
appendMessagesColor(
tr("Server configuration saved to \"%1\".")
.arg(sFilename), "#999933");
}
}
// Do not forget to reset XRUN stats variables.
if (!bDetach)
resetXrunStats();
else // We'll flag that we've been detached!
m_bJackDetach = true;
// Activate us as a client...
jack_activate(m_pJackClient);
// Remember to schedule an initial connection refreshment.
refreshConnections();
// All displays are highlighted from now on.
QPalette pal;
pal.setColor(QPalette::Foreground, Qt::yellow);
m_ui.ServerStateTextLabel->setPalette(pal);
m_ui.DspLoadTextLabel->setPalette(pal);
m_ui.ServerModeTextLabel->setPalette(pal);
pal.setColor(QPalette::Foreground, Qt::darkYellow);
m_ui.SampleRateTextLabel->setPalette(pal);
pal.setColor(QPalette::Foreground, Qt::green);
m_ui.TimeDisplayTextLabel->setPalette(pal);
m_ui.TransportStateTextLabel->setPalette(pal);
m_ui.TransportBPMTextLabel->setPalette(pal);
m_ui.TransportTimeTextLabel->setPalette(pal);
// Whether we've started detached, just change active status.
updateServerState(m_bJackDetach ? QJACKCTL_ACTIVE : QJACKCTL_STARTED);
m_ui.StopToolButton->setEnabled(true);
// Log success here.
appendMessages(tr("Client activated."));
// Do we have any post-startup scripting?...
// (only if we're not a detached client)
if (!bDetach && !m_bJackDetach) {
if (m_pSetup->bPostStartupScript
&& !m_pSetup->sPostStartupScriptShell.isEmpty()) {
shellExecute(m_pSetup->sPostStartupScriptShell,
tr("Post-startup script..."),
tr("Post-startup script terminated"));
}
}
// Have we an initial command-line to start away?
if (!m_pSetup->sCmdLine.isEmpty()) {
// Run it dettached...
shellExecute(m_pSetup->sCmdLine,
tr("Command line argument..."),
tr("Command line argument started"));
// And reset it forever more...
m_pSetup->sCmdLine.clear();
}
// OK, we're at it!
return true;
}
// Stop jack audio client...
void qjackctlMainForm::stopJackClient (void)
{
// Deactivate and close us as a client...
if (m_pJackClient) {
jack_deactivate(m_pJackClient);
jack_client_close(m_pJackClient);
m_pJackClient = NULL;
// Log deactivation here.
appendMessages(tr("Client deactivated."));
}
// Reset command-line configuration info.
m_sJackCmdLine.clear();
// Clear out the connections and session...
if (m_pConnectionsForm) {
m_pConnectionsForm->stabilizeAudio(false);
m_pConnectionsForm->stabilizeMidi(false);
}
if (m_pSessionForm)
m_pSessionForm->stabilizeForm(false);
// Displays are dimmed again.
QPalette pal;
pal.setColor(QPalette::Foreground, Qt::darkYellow);
m_ui.ServerModeTextLabel->setPalette(pal);
m_ui.DspLoadTextLabel->setPalette(pal);
m_ui.SampleRateTextLabel->setPalette(pal);
pal.setColor(QPalette::Foreground, Qt::darkGreen);
m_ui.TimeDisplayTextLabel->setPalette(pal);
m_ui.TransportStateTextLabel->setPalette(pal);
m_ui.TransportBPMTextLabel->setPalette(pal);
m_ui.TransportTimeTextLabel->setPalette(pal);
// Refresh jack client statistics explicitly.
refreshXrunStats();
}
// JACK client accessor.
jack_client_t *qjackctlMainForm::jackClient (void) const
{
return (m_bJackShutdown ? NULL : m_pJackClient);
}
// ALSA sequencer client accessor.
snd_seq_t *qjackctlMainForm::alsaSeq (void) const
{
return m_pAlsaSeq;
}
// Rebuild all patchbay items.
void qjackctlMainForm::refreshConnections (void)
{
refreshJackConnections();
refreshAlsaConnections();
}
void qjackctlMainForm::refreshJackConnections (void)
{
#if 0
// Hack this as for a while...
if (m_pConnectionsForm && m_iJackRefresh == 0) {
m_pConnectionsForm->stabilizeAudio(false);
m_pConnectionsForm->stabilizeMidi(false);
}
#endif
// Just increment our intentions; it will be deferred
// to be executed just on timer slot processing...
m_iJackRefresh++;
}
void qjackctlMainForm::refreshAlsaConnections (void)
{
#if 0
// Hack this as for a while...
if (m_pConnectionsForm && m_iAlsaRefresh == 0)
m_pConnectionsForm->stabilizeAlsa(false);
#endif
// Just increment our intentions; it will be deferred
// to be executed just on timer slot processing...
m_iAlsaRefresh++;
}
void qjackctlMainForm::refreshPatchbay (void)
{
// Just increment our intentions; it will be deferred
// to be executed just on timer slot processing...
m_iPatchbayRefresh++;
}
// Main form visibility requester slot.
void qjackctlMainForm::toggleMainForm (void)
{
m_pSetup->saveWidgetGeometry(this, true);
if (isVisible()) {
if (m_pSetup->bSystemTray && m_pSystemTray) {
// Hide away from sight, if not active...
if (isActiveWindow()) {
hide();
} else {
raise();
activateWindow();
}
} else {
// Minimize (iconify) normally.
showMinimized();
}
} else {
show();
raise();
activateWindow();
}
}
// Message log/status form requester slot.
void qjackctlMainForm::toggleMessagesStatusForm (void)
{
if (m_pMessagesStatusForm) {
m_pSetup->saveWidgetGeometry(m_pMessagesStatusForm);
if (m_pMessagesStatusForm->isVisible()) {
m_pMessagesStatusForm->hide();
} else {
m_pMessagesStatusForm->show();
m_pMessagesStatusForm->raise();
m_pMessagesStatusForm->activateWindow();
}
}
}
void qjackctlMainForm::toggleMessagesForm (void)
{
if (m_pMessagesStatusForm) {
int iTabPage = m_pMessagesStatusForm->tabPage();
m_pMessagesStatusForm->setTabPage(
int(qjackctlMessagesStatusForm::MessagesTab));
if (m_pMessagesStatusForm->isVisible()
&& iTabPage != m_pMessagesStatusForm->tabPage())
return;
}
toggleMessagesStatusForm();
}
void qjackctlMainForm::toggleStatusForm (void)
{
if (m_pMessagesStatusForm) {
int iTabPage = m_pMessagesStatusForm->tabPage();
m_pMessagesStatusForm->setTabPage(
int(qjackctlMessagesStatusForm::StatusTab));
if (m_pMessagesStatusForm->isVisible()
&& iTabPage != m_pMessagesStatusForm->tabPage())
return;
}
toggleMessagesStatusForm();
}
// Session form requester slot.
void qjackctlMainForm::toggleSessionForm (void)
{
if (m_pSessionForm) {
m_pSetup->saveWidgetGeometry(m_pSessionForm);
m_pSessionForm->stabilizeForm(m_pJackClient != NULL);
if (m_pSessionForm->isVisible()) {
m_pSessionForm->hide();
} else {
m_pSessionForm->show();
m_pSessionForm->raise();
m_pSessionForm->activateWindow();
}
}
}
// Connections form requester slot.
void qjackctlMainForm::toggleConnectionsForm (void)
{
if (m_pConnectionsForm) {
m_pSetup->saveWidgetGeometry(m_pConnectionsForm);
m_pConnectionsForm->stabilizeAudio(m_pJackClient != NULL);
m_pConnectionsForm->stabilizeMidi(m_pJackClient != NULL);
m_pConnectionsForm->stabilizeAlsa(m_pAlsaSeq != NULL);
if (m_pConnectionsForm->isVisible()) {
m_pConnectionsForm->hide();
} else {
m_pConnectionsForm->show();
m_pConnectionsForm->raise();
m_pConnectionsForm->activateWindow();
}
}
}
// Patchbay form requester slot.
void qjackctlMainForm::togglePatchbayForm (void)
{
if (m_pPatchbayForm) {
m_pSetup->saveWidgetGeometry(m_pPatchbayForm);
if (m_pPatchbayForm->isVisible()) {
m_pPatchbayForm->hide();
} else {
m_pPatchbayForm->show();
m_pPatchbayForm->raise();
m_pPatchbayForm->activateWindow();
}
}
}
// Setup dialog requester slot.
void qjackctlMainForm::showSetupForm (void)
{
qjackctlSetupForm *pSetupForm = new qjackctlSetupForm(this);
if (pSetupForm) {
// Check out some initial nullities(tm)...
if (m_pSetup->sMessagesFont.isEmpty() && m_pMessagesStatusForm)
m_pSetup->sMessagesFont = m_pMessagesStatusForm->messagesFont().toString();
if (m_pSetup->sDisplayFont1.isEmpty())
m_pSetup->sDisplayFont1 = m_ui.TimeDisplayTextLabel->font().toString();
if (m_pSetup->sDisplayFont2.isEmpty())
m_pSetup->sDisplayFont2 = m_ui.ServerStateTextLabel->font().toString();
if (m_pSetup->sConnectionsFont.isEmpty() && m_pConnectionsForm)
m_pSetup->sConnectionsFont = m_pConnectionsForm->connectionsFont().toString();
// To track down deferred or immediate changes.
bool bOldMessagesLog = m_pSetup->bMessagesLog;
QString sOldMessagesLogPath = m_pSetup->sMessagesLogPath;
QString sOldMessagesFont = m_pSetup->sMessagesFont;
QString sOldDisplayFont1 = m_pSetup->sDisplayFont1;
QString sOldDisplayFont2 = m_pSetup->sDisplayFont2;
QString sOldConnectionsFont = m_pSetup->sConnectionsFont;
int iOldConnectionsIconSize = m_pSetup->iConnectionsIconSize;
int iOldJackClientPortAlias = m_pSetup->iJackClientPortAlias;
int iOldTimeDisplay = m_pSetup->iTimeDisplay;
int iOldTimeFormat = m_pSetup->iTimeFormat;
bool bOldDisplayEffect = m_pSetup->bDisplayEffect;
bool bOldActivePatchbay = m_pSetup->bActivePatchbay;
QString sOldActivePatchbayPath = m_pSetup->sActivePatchbayPath;
bool bOldStdoutCapture = m_pSetup->bStdoutCapture;
bool bOldKeepOnTop = m_pSetup->bKeepOnTop;
bool bOldSystemTray = m_pSetup->bSystemTray;
bool bOldDelayedSetup = m_pSetup->bDelayedSetup;
int bOldMessagesLimit = m_pSetup->bMessagesLimit;
int iOldMessagesLimitLines = m_pSetup->iMessagesLimitLines;
bool bOldBezierLines = m_pSetup->bBezierLines;
bool bOldAlsaSeqEnabled = m_pSetup->bAlsaSeqEnabled;
bool bOldDBusEnabled = m_pSetup->bDBusEnabled;
bool bOldAliasesEnabled = m_pSetup->bAliasesEnabled;
bool bOldAliasesEditing = m_pSetup->bAliasesEditing;
bool bOldLeftButtons = m_pSetup->bLeftButtons;
bool bOldRightButtons = m_pSetup->bRightButtons;
bool bOldTransportButtons = m_pSetup->bTransportButtons;
bool bOldTextLabels = m_pSetup->bTextLabels;
int iOldBaseFontSize = m_pSetup->iBaseFontSize;
// Load the current setup settings.
pSetupForm->setup(m_pSetup);
// Show the setup dialog...
if (pSetupForm->exec()) {
// Check wheather something immediate has changed.
if (( bOldMessagesLog && !m_pSetup->bMessagesLog) ||
(!bOldMessagesLog && m_pSetup->bMessagesLog) ||
(sOldMessagesLogPath != m_pSetup->sMessagesLogPath))
m_pMessagesStatusForm->setLogging(
m_pSetup->bMessagesLog, m_pSetup->sMessagesLogPath);
if (( bOldBezierLines && !m_pSetup->bBezierLines) ||
(!bOldBezierLines && m_pSetup->bBezierLines))
updateBezierLines();
if (( bOldDisplayEffect && !m_pSetup->bDisplayEffect) ||
(!bOldDisplayEffect && m_pSetup->bDisplayEffect))
updateDisplayEffect();
if (iOldJackClientPortAlias != m_pSetup->iJackClientPortAlias)
updateJackClientPortAlias();
if (iOldConnectionsIconSize != m_pSetup->iConnectionsIconSize)
updateConnectionsIconSize();
if (sOldConnectionsFont != m_pSetup->sConnectionsFont)
updateConnectionsFont();
if (sOldMessagesFont != m_pSetup->sMessagesFont)
updateMessagesFont();
if (( bOldMessagesLimit && !m_pSetup->bMessagesLimit) ||
(!bOldMessagesLimit && m_pSetup->bMessagesLimit) ||
(iOldMessagesLimitLines != m_pSetup->iMessagesLimitLines))
updateMessagesLimit();
if (sOldDisplayFont1 != m_pSetup->sDisplayFont1 ||
sOldDisplayFont2 != m_pSetup->sDisplayFont2)
updateTimeDisplayFonts();
if (iOldTimeDisplay |= m_pSetup->iTimeDisplay)
updateTimeDisplayToolTips();
if (iOldTimeFormat |= m_pSetup->iTimeFormat)
updateTimeFormat();
if ((!bOldActivePatchbay && m_pSetup->bActivePatchbay) ||
(sOldActivePatchbayPath != m_pSetup->sActivePatchbayPath))
updateActivePatchbay();
if (( bOldSystemTray && !m_pSetup->bSystemTray) ||
(!bOldSystemTray && m_pSetup->bSystemTray))
updateSystemTray();
if (( bOldAliasesEnabled && !m_pSetup->bAliasesEnabled) ||
(!bOldAliasesEnabled && m_pSetup->bAliasesEnabled) ||
( bOldAliasesEditing && !m_pSetup->bAliasesEditing) ||
(!bOldAliasesEditing && m_pSetup->bAliasesEditing))
updateAliases();
if (( bOldLeftButtons && !m_pSetup->bLeftButtons) ||
(!bOldLeftButtons && m_pSetup->bLeftButtons) ||
( bOldRightButtons && !m_pSetup->bRightButtons) ||
(!bOldRightButtons && m_pSetup->bRightButtons) ||
( bOldTransportButtons && !m_pSetup->bTransportButtons) ||
(!bOldTransportButtons && m_pSetup->bTransportButtons) ||
( bOldTextLabels && !m_pSetup->bTextLabels) ||
(!bOldTextLabels && m_pSetup->bTextLabels))
updateButtons();
// Warn if something will be only effective on next run.
if (( bOldStdoutCapture && !m_pSetup->bStdoutCapture) ||
(!bOldStdoutCapture && m_pSetup->bStdoutCapture) ||
( bOldKeepOnTop && !m_pSetup->bKeepOnTop) ||
(!bOldKeepOnTop && m_pSetup->bKeepOnTop) ||
( bOldDelayedSetup && !m_pSetup->bDelayedSetup) ||
(!bOldDelayedSetup && m_pSetup->bDelayedSetup) ||
( bOldAlsaSeqEnabled && !m_pSetup->bAlsaSeqEnabled) ||
(!bOldAlsaSeqEnabled && m_pSetup->bAlsaSeqEnabled) ||
( bOldDBusEnabled && !m_pSetup->bDBusEnabled) ||
(!bOldDBusEnabled && m_pSetup->bDBusEnabled) ||
(iOldBaseFontSize != m_pSetup->iBaseFontSize))
showDirtySetupWarning();
// If server is currently running, warn user...
showDirtySettingsWarning();
}
delete pSetupForm;
}
}
// About dialog requester slot.
void qjackctlMainForm::showAboutForm (void)
{
qjackctlAboutForm(this).exec();
}
// Transport rewind.
void qjackctlMainForm::transportRewind (void)
{
#ifdef CONFIG_JACK_TRANSPORT
if (m_pJackClient) {
jack_transport_locate(m_pJackClient, 0);
// Log this here.
appendMessages(tr("Transport rewind."));
// Make sure all status(es) will be updated ASAP...
m_iStatusRefresh += QJACKCTL_STATUS_CYCLE;
}
#endif
}
// Transport backward.
void qjackctlMainForm::transportBackward (void)
{
#ifdef CONFIG_JACK_TRANSPORT
if (m_pJackClient) {
jack_position_t tpos;
jack_transport_query(m_pJackClient, &tpos);
float rate = float(tpos.frame_rate);
float tloc = ((float(tpos.frame) / rate) - m_fSkipAccel) * rate;
if (tloc < 0.0f) tloc = 0.0f;
jack_transport_locate(m_pJackClient, (jack_nframes_t) tloc);
// Log this here (if on initial toggle).
if (m_fSkipAccel < 1.1f)
appendMessages(tr("Transport backward."));
// Take care of backward acceleration...
if (m_ui.BackwardToolButton->isDown() && m_fSkipAccel < 60.0)
m_fSkipAccel *= 1.1f;
// Make sure all status(es) will be updated ASAP...
m_iStatusRefresh += QJACKCTL_STATUS_CYCLE;
}
#endif
}
// Transport toggle (start/stop)
void qjackctlMainForm::transportPlay ( bool bOn )
{
if (m_iTransportPlay > 0)
return;
if (bOn)
transportStart();
else
transportStop();
}
// Transport start (play)
void qjackctlMainForm::transportStart (void)
{
#ifdef CONFIG_JACK_TRANSPORT
if (m_pJackClient) {
jack_transport_start(m_pJackClient);
updateStatusItem(STATUS_TRANSPORT_STATE, tr("Starting"));
// Log this here.
appendMessages(tr("Transport start."));
// Make sure all status(es) will be updated ASAP...
m_iStatusRefresh += QJACKCTL_STATUS_CYCLE;
}
#endif
}
// Transport stop (pause).
void qjackctlMainForm::transportStop (void)
{
#ifdef CONFIG_JACK_TRANSPORT
if (m_pJackClient) {
jack_transport_stop(m_pJackClient);
updateStatusItem(STATUS_TRANSPORT_STATE, tr("Stopping"));
// Log this here.
appendMessages(tr("Transport stop."));
// Make sure all status(es) will be updated ASAP...
m_iStatusRefresh += QJACKCTL_STATUS_CYCLE;
}
#endif
}
// Transport forward.
void qjackctlMainForm::transportForward (void)
{
#ifdef CONFIG_JACK_TRANSPORT
if (m_pJackClient) {
jack_position_t tpos;
jack_transport_query(m_pJackClient, &tpos);
float rate = float(tpos.frame_rate);
float tloc = ((float(tpos.frame) / rate) + m_fSkipAccel) * rate;
if (tloc < 0.0f) tloc = 0.0f;
jack_transport_locate(m_pJackClient, (jack_nframes_t) tloc);
// Log this here.
if (m_fSkipAccel < 1.1f)
appendMessages(tr("Transport forward."));
// Take care of forward acceleration...
if (m_ui.ForwardToolButton->isDown() && m_fSkipAccel < 60.0f)
m_fSkipAccel *= 1.1f;
// Make sure all status(es) will be updated ASAP...
m_iStatusRefresh += QJACKCTL_STATUS_CYCLE;
}
#endif
}
// Almost-complete running status refresher.
void qjackctlMainForm::refreshStatus (void)
{
const QString n = "--";
const QString b = "-.-.---";
const QString sStopped = tr("Stopped");
m_iStatusRefresh++;
if (m_pJackClient) {
const QString s = " ";
#ifdef CONFIG_JACK_TRANSPORT
QString sText = n;
jack_position_t tpos;
jack_transport_state_t tstate = jack_transport_query(m_pJackClient, &tpos);
bool bPlaying = (tstate == JackTransportRolling || tstate == JackTransportLooping);
// Transport timecode position.
// if (bPlaying)
updateStatusItem(STATUS_TRANSPORT_TIME,
formatTime(float(tpos.frame) / float(tpos.frame_rate)));
// else
// updateStatusItem(STATUS_TRANSPORT_TIME, m_sTimeDashes);
// Transport barcode position (bar:beat.tick)
if (tpos.valid & JackPositionBBT) {
updateStatusItem(STATUS_TRANSPORT_BBT,
QString().sprintf("%u.%u.%03u", tpos.bar, tpos.beat, tpos.tick));
updateStatusItem(STATUS_TRANSPORT_BPM,
QString::number(tpos.beats_per_minute, 'g', 4));
} else {
updateStatusItem(STATUS_TRANSPORT_BBT, b);
updateStatusItem(STATUS_TRANSPORT_BPM, n);
}
#endif // !CONFIG_JACK_TRANSPORT
// Less frequent status items update...
if (m_iStatusRefresh >= QJACKCTL_STATUS_CYCLE) {
m_iStatusRefresh = 0;
float fDspLoad = jack_cpu_load(m_pJackClient);
const char f = (fDspLoad > 0.1f ? 'f' : 'g'); // format
const int p = (fDspLoad > 1.0f ? 1 : 2 ); // precision
if (m_pSystemTray) {
if (m_iXrunCount > 0) {
m_pSystemTray->setToolTip(tr("%1 (%2%)")
.arg(windowTitle())
.arg(fDspLoad, 0, f, p));
} else {
m_pSystemTray->setToolTip(tr("%1 (%2%, %3 xruns)")
.arg(windowTitle())
.arg(fDspLoad, 0, f, p)
.arg(m_iXrunCount));
}
}
updateStatusItem(STATUS_DSP_LOAD,
tr("%1 %").arg(fDspLoad, 0, f, p));
updateStatusItem(STATUS_SAMPLE_RATE,
tr("%1 Hz").arg(jack_get_sample_rate(m_pJackClient)));
updateStatusItem(STATUS_BUFFER_SIZE,
tr("%1 frames").arg(g_nframes));
// Blink server mode indicator?...
if (m_pSetup && m_pSetup->bDisplayBlink) {
QPalette pal;
pal.setColor(QPalette::Foreground,
(++m_iStatusBlink % 2) ? Qt::darkYellow: Qt::yellow);
m_ui.ServerModeTextLabel->setPalette(pal);
}
#ifdef CONFIG_JACK_REALTIME
bool bRealtime = jack_is_realtime(m_pJackClient);
updateStatusItem(STATUS_REALTIME,
(bRealtime ? tr("Yes") : tr("No")));
m_ui.ServerModeTextLabel->setText(bRealtime ? tr("RT") : n);
#else
updateStatusItem(STATUS_REALTIME, n);
m_ui.ServerModeTextLabel->setText(n);
#endif // !CONFIG_JACK_REALTIME
#ifdef CONFIG_JACK_TRANSPORT
switch (tstate) {
case JackTransportStarting:
sText = tr("Starting");
break;
case JackTransportRolling:
sText = tr("Rolling");
break;
case JackTransportLooping:
sText = tr("Looping");
break;
case JackTransportStopped:
default:
sText = sStopped;
break;
}
updateStatusItem(STATUS_TRANSPORT_STATE, sText);
m_ui.RewindToolButton->setEnabled(tpos.frame > 0);
m_ui.BackwardToolButton->setEnabled(tpos.frame > 0);
m_ui.PlayToolButton->setEnabled(true);
m_ui.PauseToolButton->setEnabled(bPlaying);
m_ui.ForwardToolButton->setEnabled(true);
transportPlayStatus(bPlaying);
if (!m_ui.BackwardToolButton->isDown() &&
!m_ui.ForwardToolButton->isDown())
m_fSkipAccel = 1.0;
#else
updateStatusItem(STATUS_TRANSPORT_STATE, n);
m_ui.RewindToolButton->setEnabled(false);
m_ui.BackwardToolButton->setEnabled(false);
m_ui.PlayToolButton->setEnabled(false);
m_ui.PauseToolButton->setEnabled(false);
m_ui.ForwardToolButton->setEnabled(false);
transportPlayStatus(false);
updateStatusItem(STATUS_TRANSPORT_TIME, m_sTimeDashes);
updateStatusItem(STATUS_TRANSPORT_BBT, b);
updateStatusItem(STATUS_TRANSPORT_BPM, n);
#endif // !CONFIG_JACK_TRANSPORT
#ifdef CONFIG_JACK_MAX_DELAY
updateStatusItem(STATUS_MAX_DELAY, tr("%1 msec")
.arg(0.001f * jack_get_max_delayed_usecs(m_pJackClient)));
#endif
// Check if we're have some XRUNs to report...
if (m_iXrunSkips > 0) {
// Maybe we've skipped some...
if (m_iXrunSkips > 1) {
appendMessagesColor(tr("XRUN callback (%1 skipped).")
.arg(m_iXrunSkips - 1), "#cc99cc");
}
// Reset skip count.
m_iXrunSkips = 0;
// Highlight the (new) status...
refreshXrunStats();
}
}
} // No need to update often if we're just idle...
else if (m_iStatusRefresh >= QJACKCTL_STATUS_CYCLE) {
m_iStatusRefresh = 0;
updateStatusItem(STATUS_DSP_LOAD, n);
updateStatusItem(STATUS_SAMPLE_RATE, n);
updateStatusItem(STATUS_BUFFER_SIZE, n);
updateStatusItem(STATUS_REALTIME, n);
m_ui.ServerModeTextLabel->setText(n);
updateStatusItem(STATUS_TRANSPORT_STATE, n);
updateStatusItem(STATUS_TRANSPORT_TIME, m_sTimeDashes);
updateStatusItem(STATUS_TRANSPORT_BBT, b);
updateStatusItem(STATUS_TRANSPORT_BPM, n);
m_ui.RewindToolButton->setEnabled(false);
m_ui.BackwardToolButton->setEnabled(false);
m_ui.PlayToolButton->setEnabled(false);
m_ui.PauseToolButton->setEnabled(false);
m_ui.ForwardToolButton->setEnabled(false);
transportPlayStatus(false);
}
// Elapsed times should be rigorous...
updateElapsedTimes();
}
// Status item updater.
void qjackctlMainForm::updateStatusItem( int iStatusItem, const QString& sText )
{
switch (iStatusItem) {
case STATUS_SERVER_STATE:
m_ui.ServerStateTextLabel->setText(sText);
break;
case STATUS_DSP_LOAD:
m_ui.DspLoadTextLabel->setText(sText);
break;
case STATUS_SAMPLE_RATE:
m_ui.SampleRateTextLabel->setText(sText);
break;
case STATUS_XRUN_COUNT:
m_ui.XrunCountTextLabel->setText(sText);
break;
case STATUS_TRANSPORT_STATE:
m_ui.TransportStateTextLabel->setText(sText);
break;
case STATUS_TRANSPORT_TIME:
if (m_pSetup->iTimeDisplay == DISPLAY_TRANSPORT_TIME)
m_ui.TimeDisplayTextLabel->setText(sText);
else
m_ui.TransportTimeTextLabel->setText(sText);
break;
case STATUS_TRANSPORT_BBT:
if (m_pSetup->iTimeDisplay == DISPLAY_TRANSPORT_BBT)
m_ui.TimeDisplayTextLabel->setText(sText);
else
if (m_pSetup->iTimeDisplay == DISPLAY_TRANSPORT_TIME)
m_ui.TransportTimeTextLabel->setText(sText);
break;
case STATUS_TRANSPORT_BPM:
m_ui.TransportBPMTextLabel->setText(sText);
break;
}
if (m_pMessagesStatusForm)
m_pMessagesStatusForm->updateStatusItem(iStatusItem, sText);
}
// Main window caption title and system tray icon and tooltip update.
void qjackctlMainForm::updateTitleStatus (void)
{
QString sTitle;
if (!m_pSetup->bLeftButtons ||
!m_pSetup->bRightButtons ||
!m_pSetup->bTextLabels) {
sTitle = QJACKCTL_SUBTITLE0;
} else {
sTitle = QJACKCTL_SUBTITLE1;
}
sTitle += " [" + m_pSetup->sDefPreset + "] ";
QString sState;
QString sDots = ".";
const QString s = "..";
switch (m_iServerState) {
case QJACKCTL_STARTING:
sState = tr("Starting");
sDots += s;
break;
case QJACKCTL_STARTED:
sState = tr("Started");
break;
case QJACKCTL_STOPPING:
sState = tr("Stopping");
sDots += s;
break;
case QJACKCTL_STOPPED:
sState = tr("Stopped");
break;
case QJACKCTL_ACTIVE:
sState = tr("Active");
break;
case QJACKCTL_ACTIVATING:
sState = tr("Activating");
sDots += s;
break;
case QJACKCTL_INACTIVE:
default:
sState = tr("Inactive");
break;
}
sTitle += sState + sDots;
setWindowTitle(sTitle);
updateStatusItem(STATUS_SERVER_STATE, sState);
if (m_pSystemTray) {
switch (m_iServerState) {
case QJACKCTL_STARTING:
m_pSystemTray->setPixmapOverlay(QPixmap(":/images/xstarting1.png"));
break;
case QJACKCTL_STARTED:
m_pSystemTray->setPixmapOverlay(QPixmap(":/images/xstarted1.png"));
break;
case QJACKCTL_STOPPING:
m_pSystemTray->setPixmapOverlay(QPixmap(":/images/xstopping1.png"));
break;
case QJACKCTL_STOPPED:
m_pSystemTray->setPixmapOverlay(QPixmap(":/images/xstopped1.png"));
break;
case QJACKCTL_ACTIVE:
m_pSystemTray->setPixmapOverlay(QPixmap(":/images/xactive1.png"));
break;
case QJACKCTL_ACTIVATING:
m_pSystemTray->setPixmapOverlay(QPixmap(":/images/xactivating1.png"));
break;
case QJACKCTL_INACTIVE:
default:
m_pSystemTray->setPixmapOverlay(QPixmap(":/images/xinactive1.png"));
break;
}
m_pSystemTray->setToolTip(sTitle);
}
sTitle = m_pSetup->sServerName;
if (sTitle.isEmpty())
sTitle = ::getenv("JACK_DEFAULT_SERVER");
if (sTitle.isEmpty())
sTitle = m_pSetup->sDefPresetName;
updateStatusItem(STATUS_SERVER_NAME, sTitle);
}
// Main server state status update helper.
void qjackctlMainForm::updateServerState ( int iServerState )
{
// Just set the new server state.
m_iServerState = iServerState;
// Now's time to update main window
// caption title and status immediately.
updateTitleStatus();
}
// System tray master switcher.
void qjackctlMainForm::updateSystemTray (void)
{
#ifdef CONFIG_SYSTEM_TRAY
if (!m_pSetup->bSystemTray && m_pSystemTray) {
// Strange enough, this would close the application too.
// m_pSystemTray->close();
delete m_pSystemTray;
m_pSystemTray = NULL;
}
if (m_pSetup->bSystemTray && m_pSystemTray == NULL) {
m_pSystemTray = new qjackctlSystemTray(this);
QObject::connect(m_pSystemTray,
SIGNAL(clicked()),
SLOT(toggleMainForm()));
QObject::connect(m_pSystemTray,
SIGNAL(middleClicked()),
SLOT(resetXrunStats()));
QObject::connect(m_pSystemTray,
SIGNAL(contextMenuRequested(const QPoint &)),
SLOT(systemTrayContextMenu(const QPoint &)));
m_pSystemTray->show();
} else {
// Make sure the main widget is visible.
show();
raise();
activateWindow();
}
#endif
}
// System tray context menu request slot.
void qjackctlMainForm::systemTrayContextMenu ( const QPoint& pos )
{
QMenu menu(this);
QAction *pAction;
QString sHideMinimize = (m_pSetup->bSystemTray && m_pSystemTray
? tr("&Hide") : tr("Mi&nimize"));
QString sShowRestore = (m_pSetup->bSystemTray && m_pSystemTray
? tr("S&how") : tr("Rest&ore"));
pAction = menu.addAction(isVisible()
? sHideMinimize : sShowRestore, this, SLOT(toggleMainForm()));
menu.addSeparator();
if (m_pJackClient == NULL) {
pAction = menu.addAction(QIcon(":/images/start1.png"),
tr("&Start"), this, SLOT(startJack()));
} else {
pAction = menu.addAction(QIcon(":/images/stop1.png"),
tr("&Stop"), this, SLOT(stopJack()));
}
pAction = menu.addAction(QIcon(":/images/reset1.png"),
tr("&Reset"), this, SLOT(resetXrunStats()));
// pAction->setEnabled(m_pJackClient != NULL);
menu.addSeparator();
// Construct the actual presets menu,
// overriding the last one, if any...
QMenu *pPresetsMenu = menu.addMenu(tr("&Presets"));
// Assume QStringList iteration follows item index order (0,1,2...)
int iPreset = 0;
QStringListIterator iter(m_pSetup->presets);
while (iter.hasNext()) {
const QString& sPreset = iter.next();
pAction = pPresetsMenu->addAction(sPreset);
pAction->setCheckable(true);
pAction->setChecked(sPreset == m_pSetup->sDefPreset);
pAction->setData(iPreset);
iPreset++;
}
// Default preset always present, and has invalid index parameter (-1)...
if (iPreset > 0)
pPresetsMenu->addSeparator();
pAction = pPresetsMenu->addAction(m_pSetup->sDefPresetName);
pAction->setCheckable(true);
pAction->setChecked(m_pSetup->sDefPresetName == m_pSetup->sDefPreset);
pAction->setData(-1);
QObject::connect(pPresetsMenu,
SIGNAL(triggered(QAction*)),
SLOT(activatePresetsMenu(QAction*)));
menu.addSeparator();
if (m_pSessionForm) {
bool bEnabled = (m_pJackClient != NULL);
const QString sTitle = tr("S&ession");
const QIcon iconSession(":/images/session1.png");
QMenu *pSessionMenu = menu.addMenu(sTitle);
pSessionMenu->setIcon(iconSession);
pAction = pSessionMenu->addAction(m_pSessionForm->isVisible()
? tr("&Hide") : tr("S&how"),
this, SLOT(toggleSessionForm()));
pSessionMenu->addSeparator();
pAction = pSessionMenu->addAction(QIcon(":/images/open1.png"),
tr("&Load..."),
m_pSessionForm, SLOT(loadSession()));
pAction->setEnabled(bEnabled);
QMenu *pRecentMenu = m_pSessionForm->recentMenu();
pAction = pSessionMenu->addMenu(pRecentMenu);
pAction->setEnabled(m_pJackClient != NULL && !pRecentMenu->isEmpty());
pSessionMenu->addSeparator();
pAction = pSessionMenu->addAction(QIcon(":/images/save1.png"),
tr("&Save..."),
m_pSessionForm, SLOT(saveSessionSave()));
pAction->setEnabled(bEnabled);
#ifdef CONFIG_JACK_SESSION
pAction = pSessionMenu->addAction(
tr("Save and &Quit..."),
m_pSessionForm, SLOT(saveSessionSaveAndQuit()));
pAction->setEnabled(bEnabled);
pAction = pSessionMenu->addAction(
tr("Save &Template..."),
m_pSessionForm, SLOT(saveSessionSaveTemplate()));
pAction->setEnabled(bEnabled);
#endif
pSessionMenu->addSeparator();
pAction = pSessionMenu->addAction(
tr("&Versioning"),
m_pSessionForm, SLOT(saveSessionVersion(bool)));
pAction->setCheckable(true);
pAction->setChecked(m_pSessionForm->isSaveSessionVersion());
pAction->setEnabled(bEnabled);
pSessionMenu->addSeparator();
pAction = pSessionMenu->addAction(QIcon(":/images/refresh1.png"),
tr("Re&fresh"),
m_pSessionForm, SLOT(updateSession()));
pAction->setEnabled(bEnabled);
}
pAction = menu.addAction(QIcon(":/images/messages1.png"),
tr("&Messages"), this, SLOT(toggleMessagesForm()));
pAction->setCheckable(true);
pAction->setChecked(m_pMessagesStatusForm
&& m_pMessagesStatusForm->isVisible()
&& m_pMessagesStatusForm->tabPage() == qjackctlMessagesStatusForm::MessagesTab);
pAction = menu.addAction(QIcon(":/images/status1.png"),
tr("St&atus"), this, SLOT(toggleStatusForm()));
pAction->setCheckable(true);
pAction->setChecked(m_pMessagesStatusForm
&& m_pMessagesStatusForm->isVisible()
&& m_pMessagesStatusForm->tabPage() == qjackctlMessagesStatusForm::StatusTab);
pAction = menu.addAction(QIcon(":/images/connections1.png"),
tr("&Connections"), this, SLOT(toggleConnectionsForm()));
pAction->setCheckable(true);
pAction->setChecked(m_pConnectionsForm && m_pConnectionsForm->isVisible());
pAction = menu.addAction(QIcon(":/images/patchbay1.png"),
tr("Patch&bay"), this, SLOT(togglePatchbayForm()));
pAction->setCheckable(true);
pAction->setChecked(m_pPatchbayForm && m_pPatchbayForm->isVisible());
menu.addSeparator();
QMenu *pTransportMenu = menu.addMenu(tr("&Transport"));
pAction = pTransportMenu->addAction(QIcon(":/images/rewind1.png"),
tr("&Rewind"), this, SLOT(transportRewind()));
pAction->setEnabled(m_ui.RewindToolButton->isEnabled());
// pAction = pTransportMenu->addAction(QIcon(":/images/backward1.png"),
// tr("&Backward"), this, SLOT(transportBackward()));
// pAction->setEnabled(m_ui.BackwardToolButton->isEnabled());
pAction = pTransportMenu->addAction(QIcon(":/images/play1.png"),
tr("&Play"), this, SLOT(transportStart()));
pAction->setEnabled(!m_ui.PlayToolButton->isChecked());
pAction = pTransportMenu->addAction(QIcon(":/images/pause1.png"),
tr("Pa&use"), this, SLOT(transportStop()));
pAction->setEnabled(m_ui.PauseToolButton->isEnabled());
// pAction = pTransportMenu->addAction(QIcon(":/images/forward1.png"),
// tr("&Forward"), this, SLOT(transportForward()));
// pAction->setEnabled(m_ui.ForwardToolButton->isEnabled());
menu.addSeparator();
pAction = menu.addAction(QIcon(":/images/setup1.png"),
tr("Set&up..."), this, SLOT(showSetupForm()));
if (!m_pSetup->bRightButtons || !m_pSetup->bTransportButtons) {
pAction = menu.addAction(QIcon(":/images/about1.png"),
tr("Ab&out..."), this, SLOT(showAboutForm()));
}
menu.addSeparator();
pAction = menu.addAction(QIcon(":/images/quit1.png"),
tr("&Quit"), this, SLOT(quitMainForm()));
menu.exec(pos);
}
// Server settings change warning.
void qjackctlMainForm::showDirtySettingsWarning (void)
{
// If client service is currently running,
// prompt the effective warning...
if (m_pJackClient) {
const QString& sTitle
= tr("Warning") + " - " QJACKCTL_SUBTITLE1;
const QString& sText
= tr("Server settings will be only effective after\n"
"restarting the JACK audio server.");
#ifdef CONFIG_SYSTEM_TRAY
#ifdef QJACKCTL_QT4_SYSTEM_TRAY
#if QT_VERSION >= 0x040300
if (m_pSetup->bSystemTray && m_pSystemTray
&& QSystemTrayIcon::supportsMessages()) {
m_pSystemTray->showMessage(sTitle, sText, QSystemTrayIcon::Warning);
}
else
#endif
#endif
#endif
QMessageBox::warning(this, sTitle, sText);
} // Otherwise, it will be just as convenient to update status...
else updateTitleStatus();
}
// Setup otions change warning.
void qjackctlMainForm::showDirtySetupWarning (void)
{
const QString& sTitle
= tr("Information") + " - " QJACKCTL_SUBTITLE1;
const QString& sText
= tr("Some settings will be only effective\n"
"the next time you start this program.");
#ifdef CONFIG_SYSTEM_TRAY
#ifdef QJACKCTL_QT4_SYSTEM_TRAY
#if QT_VERSION >= 0x040300
if (m_pSetup->bSystemTray && m_pSystemTray
&& QSystemTrayIcon::supportsMessages()) {
m_pSystemTray->showMessage(sTitle, sText, QSystemTrayIcon::Information);
}
else
#endif
#endif
#endif
QMessageBox::information(this, sTitle, sText);
}
// Select the current default preset (by name from context menu).
void qjackctlMainForm::activatePresetsMenu ( QAction *pAction )
{
activatePreset(pAction->data().toInt());
}
// Select the current default preset (by name).
void qjackctlMainForm::activatePreset ( const QString& sPreset )
{
activatePreset(m_pSetup->presets.indexOf(sPreset));
}
// Select the current default preset (by index).
void qjackctlMainForm::activatePreset ( int iPreset )
{
if (m_pConnectionsForm && !m_pConnectionsForm->queryClose())
return;
if (iPreset >= 0 && iPreset < m_pSetup->presets.count())
m_pSetup->sDefPreset = m_pSetup->presets[iPreset];
else
m_pSetup->sDefPreset = m_pSetup->sDefPresetName;
showDirtySettingsWarning();
}
// Close main form slot.
void qjackctlMainForm::quitMainForm (void)
{
// Flag that we're quitting explicitly.
m_bQuitForce = true;
// And then, do the closing dance.
close();
}
// Context menu event handler.
void qjackctlMainForm::contextMenuEvent ( QContextMenuEvent *pEvent )
{
// We'll just show up the usual system tray menu.
systemTrayContextMenu(pEvent->globalPos());
}
void qjackctlMainForm::mousePressEvent(QMouseEvent *pMouseEvent)
{
if (pMouseEvent->button() == Qt::MidButton &&
m_ui.StatusDisplayFrame->geometry().contains(pMouseEvent->pos())) {
resetXrunStats();
}
}
#ifdef CONFIG_DBUS
// D-BUS: Set/reset parameter values from current selected preset options.
void qjackctlMainForm::setDBusParameters (void)
{
// Set configuration parameters...
bool bDummy = (m_preset.sDriver == "dummy");
bool bSun = (m_preset.sDriver == "sun");
bool bOss = (m_preset.sDriver == "oss");
bool bAlsa = (m_preset.sDriver == "alsa");
bool bPortaudio = (m_preset.sDriver == "portaudio");
bool bCoreaudio = (m_preset.sDriver == "coreaudio");
bool bFreebob = (m_preset.sDriver == "freebob");
bool bFirewire = (m_preset.sDriver == "firewire");
bool bNet = (m_preset.sDriver == "net" || m_preset.sDriver == "netone");
setDBusEngineParameter("name",
m_pSetup->sServerName,
!m_pSetup->sServerName.isEmpty());
setDBusEngineParameter("verbose", m_preset.bVerbose);
setDBusEngineParameter("realtime", m_preset.bRealtime);
setDBusEngineParameter("realtime-priority",
m_preset.iPriority,
m_preset.bRealtime && m_preset.iPriority > 0);
// setDBusEngineParameter("port-max",
// m_preset.iPortMax,
// m_preset.iPortMax > 0);
setDBusEngineParameter("client-timeout",
m_preset.iTimeout,
m_preset.iTimeout > 0);
// setDBusEngineParameter("no-memlock", m_preset.bNoMemLock);
// setDBusEngineParameter("unlock-mem",
// m_preset.bUnlockMem,
// !m_preset.bNoMemLock);
setDBusEngineParameter("driver", m_preset.sDriver);
if ((bAlsa || bPortaudio) && (m_preset.iAudio != QJACKCTL_DUPLEX ||
m_preset.sInDevice.isEmpty() || m_preset.sOutDevice.isEmpty())) {
QString sInterface = m_preset.sInterface;
if (bAlsa && sInterface.isEmpty())
sInterface = "hw:0";
setDBusDriverParameter("device", sInterface);
}
if (bPortaudio) {
setDBusDriverParameter("channel",
(unsigned int) m_preset.iChan,
m_preset.iChan > 0);
}
if (bCoreaudio || bFreebob || bFirewire) {
setDBusDriverParameter("device",
m_preset.sInterface,
!m_preset.sInterface.isEmpty());
}
if (!bNet) {
setDBusDriverParameter("rate",
(unsigned int) m_preset.iSampleRate,
m_preset.iSampleRate > 0);
setDBusDriverParameter("period",
(unsigned int) m_preset.iFrames,
m_preset.iFrames > 0);
}
if (bAlsa || bSun || bOss || bFreebob || bFirewire) {
setDBusDriverParameter("nperiods",
(unsigned int) m_preset.iPeriods,
m_preset.iPeriods > 0);
}
if (bAlsa) {
setDBusDriverParameter("softmode", m_preset.bSoftMode);
setDBusDriverParameter("monitor", m_preset.bMonitor);
setDBusDriverParameter("shorts", m_preset.bShorts);
setDBusDriverParameter("hwmon", m_preset.bHWMon);
setDBusDriverParameter("hwmeter", m_preset.bHWMeter);
#ifdef CONFIG_JACK_MIDI
setDBusDriverParameter("midi-driver",
m_preset.sMidiDriver,
!m_preset.sMidiDriver.isEmpty());
#endif
}
if (bAlsa || bPortaudio) {
QString sInterface = m_preset.sInterface;
if (bAlsa && sInterface.isEmpty())
sInterface = "hw:0";
QString sInDevice = m_preset.sInDevice;
if (sInDevice.isEmpty())
sInDevice = sInterface;
QString sOutDevice = m_preset.sOutDevice;
if (sOutDevice.isEmpty())
sOutDevice = sInterface;
switch (m_preset.iAudio) {
case QJACKCTL_DUPLEX:
setDBusDriverParameter("duplex", true);
setDBusDriverParameter("capture", sInDevice);
setDBusDriverParameter("playback", sOutDevice);
break;
case QJACKCTL_CAPTURE:
resetDBusDriverParameter("duplex");
setDBusDriverParameter("capture", sInDevice);
resetDBusDriverParameter("playback");
break;
case QJACKCTL_PLAYBACK:
resetDBusDriverParameter("duplex");
setDBusDriverParameter("playback", sOutDevice);
resetDBusDriverParameter("capture");
break;
}
setDBusDriverParameter("inchannels",
(unsigned int) m_preset.iInChannels,
m_preset.iInChannels > 0 && m_preset.iAudio != QJACKCTL_PLAYBACK);
setDBusDriverParameter("outchannels",
(unsigned int) m_preset.iOutChannels,
m_preset.iOutChannels > 0 && m_preset.iAudio != QJACKCTL_CAPTURE);
unsigned char dither = 0;
switch (m_preset.iDither) {
case 0: dither = 'n'; break;
case 1: dither = 'r'; break;
case 2: dither = 's'; break;
case 3: dither = 't'; break; }
setDBusDriverParameter("dither",
QVariant::fromValue(dither),
dither > 0);
}
else if (bOss || bSun) {
setDBusDriverParameter("ignorehw", m_preset.bIgnoreHW);
setDBusDriverParameter("wordlength",
(unsigned int) m_preset.iWordLength,
m_preset.iWordLength > 0);
QString sInDevice = m_preset.sInDevice;
if (sInDevice.isEmpty() && m_preset.iAudio == QJACKCTL_CAPTURE)
sInDevice = m_preset.sInterface;
setDBusDriverParameter("capture",
sInDevice,
!sInDevice.isEmpty() && m_preset.iAudio != QJACKCTL_PLAYBACK);
QString sOutDevice = m_preset.sOutDevice;
if (sOutDevice.isEmpty() && m_preset.iAudio == QJACKCTL_PLAYBACK)
sOutDevice = m_preset.sInterface;
setDBusDriverParameter("playback",
sOutDevice,
!sOutDevice.isEmpty() && m_preset.iAudio != QJACKCTL_CAPTURE);
setDBusDriverParameter("inchannels",
(unsigned int) m_preset.iInChannels,
m_preset.iInChannels > 0 && m_preset.iAudio != QJACKCTL_PLAYBACK);
setDBusDriverParameter("outchannels",
(unsigned int) m_preset.iOutChannels,
m_preset.iOutChannels > 0 && m_preset.iAudio != QJACKCTL_CAPTURE);
}
else if (bCoreaudio || bFirewire || bNet) {
setDBusDriverParameter("inchannels",
(unsigned int) m_preset.iInChannels,
m_preset.iInChannels > 0 && m_preset.iAudio != QJACKCTL_PLAYBACK);
setDBusDriverParameter("outchannels",
(unsigned int) m_preset.iOutChannels,
m_preset.iOutChannels > 0 && m_preset.iAudio != QJACKCTL_CAPTURE);
}
else if (bFreebob) {
setDBusDriverParameter("duplex",
bool(m_preset.iAudio == QJACKCTL_DUPLEX));
resetDBusDriverParameter("capture");
resetDBusDriverParameter("playback");
resetDBusDriverParameter("outchannels");
resetDBusDriverParameter("inchannels");
}
if (bDummy) {
setDBusDriverParameter("wait",
(unsigned int) m_preset.iWait,
m_preset.iWait > 0);
}
if (bAlsa || bSun || bOss || bCoreaudio || bPortaudio || bFreebob) {
setDBusDriverParameter("input-latency",
(unsigned int) m_preset.iInLatency,
m_preset.iInLatency > 0);
setDBusDriverParameter("output-latency",
(unsigned int) m_preset.iOutLatency,
m_preset.iOutLatency > 0);
}
}
// D-BUS: Set parameter values (with reset option).
bool qjackctlMainForm::setDBusEngineParameter (
const QString& param, const QVariant& value, bool bSet )
{
return setDBusParameter(QStringList() << "engine" << param, value, bSet);
}
bool qjackctlMainForm::setDBusDriverParameter (
const QString& param, const QVariant& value, bool bSet )
{
return setDBusParameter(QStringList() << "driver" << param, value, bSet);
}
bool qjackctlMainForm::setDBusParameter (
const QStringList& path, const QVariant& value, bool bSet )
{
if (m_pDBusConfig == NULL)
return false;
if (!bSet) return resetDBusParameter(path); // Reset option.
QDBusMessage dbusm = m_pDBusConfig->call(
"SetParameterValue", path, QVariant::fromValue(QDBusVariant(value)));
if (dbusm.type() == QDBusMessage::ErrorMessage) {
appendMessagesError(
tr("D-BUS: SetParameterValue('%1', '%2'):\n\n"
"%3.\n(%4)").arg(path.join(":")).arg(value.toString())
.arg(dbusm.errorMessage())
.arg(dbusm.errorName()));
return false;
}
return true;
}
// D-BUS: Reset parameter (to default) values.
bool qjackctlMainForm::resetDBusEngineParameter ( const QString& param )
{
return resetDBusParameter(QStringList() << "engine" << param);
}
bool qjackctlMainForm::resetDBusDriverParameter ( const QString& param )
{
return resetDBusParameter(QStringList() << "driver" << param);
}
bool qjackctlMainForm::resetDBusParameter ( const QStringList& path )
{
if (m_pDBusConfig == NULL)
return false;
QDBusMessage dbusm = m_pDBusConfig->call("ResetParameterValue", path);
if (dbusm.type() == QDBusMessage::ErrorMessage) {
appendMessagesError(
tr("D-BUS: ResetParameterValue('%1'):\n\n"
"%2.\n(%3)").arg(path.join(":"))
.arg(dbusm.errorMessage())
.arg(dbusm.errorName()));
return false;
}
return true;
}
// D-BUS: Get parameter values.
QVariant qjackctlMainForm::getDBusEngineParameter ( const QString& param )
{
return getDBusParameter(QStringList() << "engine" << param);
}
QVariant qjackctlMainForm::getDBusDriverParameter ( const QString& param )
{
return getDBusParameter(QStringList() << "driver" << param);
}
QVariant qjackctlMainForm::getDBusParameter ( const QStringList& path )
{
if (m_pDBusConfig == NULL)
return QVariant();
QDBusMessage dbusm = m_pDBusConfig->call("GetParameterValue", path);
if (dbusm.type() == QDBusMessage::ErrorMessage) {
appendMessagesError(
tr("D-BUS: GetParameterValue('%1'):\n\n"
"%2.\n(%3)").arg(path.join(":"))
.arg(dbusm.errorMessage())
.arg(dbusm.errorName()));
return QVariant();
}
return dbusm.arguments().at(2);
}
#endif // CONFIG_DBUS
// Quotes string with embedded whitespace.
QString qjackctlMainForm::formatQuoted ( const QString& s ) const
{
const QChar b = ' ';
const QChar q = '"';
return (s.contains(b) && !s.contains(q) ? q + s + q : s);
}
// Guarded transport play/pause toggle.
void qjackctlMainForm::transportPlayStatus ( bool bOn )
{
++m_iTransportPlay;
m_ui.PlayToolButton->setChecked(bOn);
--m_iTransportPlay;
}
// Session (desktop) shutdown signal handler.
void qjackctlMainForm::setQuitForce ( bool bQuitForce )
{
m_bQuitForce = bQuitForce;
}
bool qjackctlMainForm::isQuitForce (void) const
{
return m_bQuitForce;
}
// end of qjackctlMainForm.cpp