aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/ui_hd24connect.fl
blob: eae32ad585e17d44cb6858e15883dd6573c15830 (plain)
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
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
# data file for the Fltk User Interface Designer (fluid)
version 1.0109 
header_name {.h} 
code_name {.cxx}
decl {class HD24TrackChannel;} {public
} 

decl {class TrackInfo;} {public
} 

decl {class HD24UserInterface;} {public
} 

decl {class MixerUI;} {public
} 

decl {class RecorderUI;} {public
} 

decl {class PortAudioWrapper;} {public
} 

decl {class JackWrapper;} {public
} 

decl {class hd24transferengine;} {public
} 

decl {\#define HD24DEBUG 0} {public
} 

decl {\#define BLINKRATE 25} {public
} 

decl {\#define PA_FRAMESPERBUF 512} {public
} 

decl {\#define MAXCHANNELS 24} {public
} 

decl {\#define UIREFRESH 1 /* 1=best, 10=1/10 refresh rate */} {public
} 

decl {\#define HD24MODE hd24fs::MODE_RDWR} {public
} 

decl {\#define TIMEOUT 0.03} {public
} 

decl {\#define SPLITFILESIZE_BYTES ((__uint64)(1024*1024*1024))} {public
} 

decl {\#include <config.h>} {public
} 

decl {\#include <string>} {public
} 

decl {\#include <vector>} {public
} 

decl {\#include <portwin.h>} {public
} 

decl {\#include <soundlibs.h> /* portaudio, libjack */} {public
} 

decl {\#include <iostream>} {public
} 

decl {\#include <FL/FLTKstuff.H>} {public
} 

decl {\#include <FL/Fl_Menu_Bar.H>} {public
} 

decl {\#include <FL/Fl_File_Chooser.H>} {public
} 

decl {\#include <FL/filename.H>} {public
} 

decl {\#include <xplat_dlfcn.h>} {public
} 

decl {\#include <sndfile.h>} {public
} 

decl {\#include <convertlib.h>} {public
} 

decl {\#include <memutils.h>} {public
} 

decl {\#include <hd24fs.h>} {public
} 

decl {\#include <hd24utils.h>} {public
} 

decl {\#include <hd24transferengine.h>} {public
} 

decl {\#include <smpte.h>} {public
} 

decl {\#include <WidgetPDial.h>} {public
} 

decl {\#include <dialog_newproject.h>} {public
} 

decl {\#include <dialog_newsong.h>} {public
} 

decl {\#include <dialog_setlocate.h>} {public
} 

decl {\#include <dialog_filesize.h>} {public
} 

decl {\#include <dialog_setlength.h>} {public
} 

decl {\#include <dialog_fromto.h>} {public
} 

decl {\#include <dialog_rename.h>} {public
} 

decl {\#include <dialog_options.h>} {public
} 

decl {\#include <dialog_choosedevice.h>} {public
} 

decl {\#include <ui_help_about.h>} {public
} 

decl {\#include <ui_mixer.h>} {public
} 

decl {\#include <time.h>} {public
} 

decl {\#include <math.h>} {public
} 

decl {\#include <ui_hd24trackchannel.h>} {public
} 

decl {\#include <ui_recorder.h>} {public
} 

decl {class HD24UserInterface;} {public
} 

decl {class HD24control;} {public
} 

decl {class SoundFileWrapper;} {public
} 

class HD24data {} {
  decl {HD24UserInterface* parentui;} {}
  decl {friend class HD24control;} {}
  decl {int ready;} {public
  }
} 

class HD24control {} {
  decl {HD24data* data;} {}
  Function {parentui(HD24UserInterface* p_parentui)} {open
  } {
    code {data->parentui=p_parentui;} {}
  }
  Function {parentui()} {open return_type {HD24UserInterface*}
  } {
    code {return data->parentui;} {}
  }
  Function {HD24control()} {open
  } {
    code {data=new HD24data();} {}
  }
  Function {~HD24control()} {open
  } {
    code {delete data;} {}
  }
  Function {ready()} {open return_type int
  } {
    code {return data->ready;} {}
  }
  Function {ready(int p_ready)} {open return_type void
  } {
    code {data->ready=p_ready;} {}
  }
} 

decl {\#include <hd24sndfile.h>} {public
} 

class HD24UserInterface {open
} {
  decl {hd24transferengine* transeng;} {}
  decl {HD24control* control;} {public
  }
  decl {PortAudioWrapper* portaudio;} {public
  }
  decl {SoundFileWrapper* soundfile;} {public
  }
  decl {JackWrapper* libjack;} {public
  }
  decl {int busy;} {public
  }
  decl {hd24fs* defaulthd24;} {}
  decl {hd24fs* currenthd24;} {public
  }
  decl {int trackselected[24];} {public
  }
  decl {hd24project* currproj;} {public
  }
  decl {hd24song* currsong;} {public
  }
  decl {Fl_Check_Button* track[24];} {public
  }
  decl {int tracksave[24]; /* to keep track[24] settings */} {public
  }
  decl {vector<string> format_outputextension;} {public
  }
  decl {vector<string> format_shortdesc;} {public
  }
  Function {deactivate_ui()} {open return_type void
  } {
    code {drivename->deactivate();
rename_drive->deactivate();
projectname->deactivate();
rename_project->deactivate();
songname->deactivate();
songinfogroup->deactivate();
tabDrive->deactivate();
rename_song->deactivate();
locatepoints->deactivate();
fromto->deactivate();
transfercanvas->deactivate();
menufile->deactivate();
tabRecorder->deactivate();
tabMixer->deactivate();
menuhelp->deactivate();} {}
  }
  Function {disable_program_controls()} {return_type void
  } {
    code {drivename->deactivate();
rename_drive->deactivate();
projectname->deactivate();
rename_project->deactivate();
songname->deactivate();
rename_song->deactivate();
transfercanvas->deactivate();
locatepoints->deactivate();
fromto->deactivate();
button_golocatepoint->deactivate();
recorder->control->disable();} {}
  }
  Function {activate_ui()} {open return_type void
  } {
    code {drivename->activate();
transfercanvas->activate();
tabRecorder->activate();
projectname->activate();
songname->activate();
songinfogroup->activate();
tabDrive->activate();
tabMixer->activate();
locatepoints->activate();
fromto->activate();
menufile->activate();
menuhelp->activate();} {}
  }
  Function {addsongtodropdown(int i)} {} {
    code {\#if (HD24DEBUG==1) 
		cout << "addsongtodropdown " << i << endl;
		cout << "set song" << endl;
\#endif
    hd24song* song=currproj->getsong(i);
\#if (HD24DEBUG==1) 
		cout << "song is set" << endl;
\#endif
    string* strsongname=Convert::int2str(i);
    *strsongname+=": ";
    string* actualname=song->songname();
    *strsongname+=*actualname;
    delete actualname;

\#if (HD24DEBUG==1) 
		cout << "song is set2" << endl;
\#endif
    songname->add(strsongname->c_str(),0,(void (*)(Fl_Widget*,void*))(&(songname_cb)),(void*)this);
\#if (HD24DEBUG==1)
	cout << "song is set3" << endl;
\#endif
    delete song;
    delete(strsongname);} {}
  }
  Function {populate_projectlist(int projectid)} {return_type void
  } {
    code {/* Set project info */
int i;
\#if (HD24DEBUG==1)
	cout << "clear project list" << endl;
\#endif
for (i=0;i<=100;i++) {
	projectname->remove(0);
}
int numprojs=0;
if (currenthd24==NULL) {
    return;
}
numprojs=currenthd24->projectcount();
for (i=1; i<=numprojs; i++) {
    hd24project* currproj=currenthd24->getproject(i);
    string* projname1=Convert::int2str(i);
	*projname1+=": ";
	string* currpname=currproj->projectname();
	*projname1+=*currpname;
    projectname->add(projname1->c_str(),0,(void (*)(Fl_Widget*,void*))(&(projectname_cb)),(void*)this);
	delete(currpname);
	delete(projname1);
    delete currproj;
}

select_project(projectid);} {}
  }
  Function {populate_songlist(int songid)} {open return_type void
  } {
    code {int i;
int numsongs=currproj->songcount();
\#if (HD24DEBUG==1) 
	cout << "populate_songlist" << endl;
\#endif
if (numsongs==0) 
{
\#if (HD24DEBUG==1) 
		cout << "no songs" << endl;
\#endif
	for (i=0;i<=100;i++) {
		songname->remove(0);
	}
	songname->add("-- Empty project --",0,NULL,(void*)this);
	songname->value(0);
	refresh(songname);
	return;
}
songname->activate();
\#if (HD24DEBUG==1) 
	cout << "clear songlist" << endl;
\#endif
for (i=0;i<=100;i++) {
	songname->remove(0);
}

songname->add("-- All songs --",0,(void (*)(Fl_Widget*,void*))(&(songname_cb)),(void*)this);

\#if (HD24DEBUG==1) 
	cout << "Add songs to dropdown" << endl;
\#endif
for (i=1; i<=numsongs; i++) {
	addsongtodropdown(i);
}
control->ready(1);
this->busy=0;
    
\#if (HD24DEBUG==1) 
	cout << "about to select last used song" << endl;
\#endif
signed long lastsong=currproj->lastsongid();
if (lastsong<1) {
	lastsong=0;
}
\#if (HD24DEBUG==1) 
	cout << "got last song id:" << lastsong << endl;
\#endif
if (lastsong==0) {
	songname->value(0);
	songname->redraw();
	return;
}
select_song(lastsong);
songname->redraw();} {}
  }
  Function {populate_drivelist(int driveid)} {open return_type void
  } {
    code {// when another drive has been selected, init dropdown lists.
for (unsigned int q=0;q<=99;q++) {
	drivename->remove(0);
}
// find out how many ADAT drives are detected.
unsigned int devcount=defaulthd24->hd24devicecount();
\#if (HD24DEBUG==1) 
	cout << "devcount=" << devcount << endl;
\#endif
unsigned int usedevcount=devcount;
if (devcount==0) usedevcount=1; // we are using a file image. 
for (unsigned int devnum=0;devnum<usedevcount;devnum++) 
{
\#if (HD24DEBUG==1) 
cout << "devnum" << devnum << endl; 
\#endif
        // currhd24 is not a spelling error. it is for local use.
       	string* idir=hd24utils::getlastdir("driveimagedir"); 
	hd24fs* currhd24 = new hd24fs(idir->c_str(),defaulthd24->mode(),devnum);
	delete idir;
	if (!(currhd24->isOpen())) {
		if (!(defaulthd24->isOpen())) {
			disable_program_controls();
		}
	}
\#if (HD24DEBUG==1) 
cout << "newfs" << devnum << endl; 
\#endif
	
	string* drivename1=Convert::int2str(devnum+1);
	
	*drivename1+=": ";
	string* volname;
	
\#if (HD24DEBUG==1) 
cout << "getvolname" << devnum << endl; 
\#endif
	
	if (devcount!=usedevcount) 
	{
		volname=currenthd24->volumename();
	} else {
		volname=currhd24->volumename();
	}
	
\#if (HD24DEBUG==1) 
cout << "gotvolname" << devnum << endl; 
\#endif
	
	*drivename1+=*volname;
	// NULL=callback
	drivename->add(drivename1->c_str(),0,(void (*)(Fl_Widget*,void*))(&(drivename_cb)),(void*)this);
	delete(currhd24);
	delete(volname);
	delete(drivename1);
}

/* Set drive info */
\#if (HD24DEBUG==1) 
cout << "set drivename dropdown value to " << driveid << endl;
\#endif
drivename->value(driveid);} {}
  }
  Function {populate_locatepoints(hd24song* locsong,Fl_Choice* lpoints)} {open return_type int
  } {
    code {int i;
int numpoints=0;
if (locsong!=NULL) 
{
 	numpoints=locsong->locatepointcount();
}

\#if (HD24DEBUG==1) 
	cout << "populate_lpoints" << endl;
\#endif
if (numpoints==0) 
{
\#if (HD24DEBUG==1) 
		cout << "no locate points." << endl;
\#endif
	for (i=0;i<=99;i++) {
		lpoints->remove(0);
	}
	lpoints->deactivate();
	refresh(lpoints);
	return numpoints;
}
lpoints->activate();
\#if (HD24DEBUG==1) 
	cout << "clear lpoints" << endl;
\#endif
for (i=0;i<=99;i++) {
	lpoints->remove(0);
}
for (i=0; i<numpoints+1; i++) {
	// locatepoint (max+1) is a virtual locate point 'END'.
\#if (HD24DEBUG==1) 
		cout << "set locate point" << endl;
\#endif
	__uint32 locatepos=locsong->getlocatepos(i);
\#if (HD24DEBUG==1) 
		cout << "locate pos "<<i<<" is " << locatepos << endl;
\#endif
    	string* locname1;
	if ((i==0)||(i==numpoints)) {
		locname1=locsong->getlocatename(i);
		
		if ((locname1->length())>0) {
			while (locname1->substr(0,1)==" ") {
			  *locname1=locname1->substr(1,locname1->length()-1);
			}
			while (locname1->substr(locname1->length()-1,1)==" ") {
			  *locname1=locname1->substr(0,locname1->length()-1);
			}
		} else {
			*locname1+="START";
		}
		*locname1+=": ";
		if (i==numpoints) {
			*locname1+="+";
		}
		string* dur=locsong->display_duration(locatepos);
		*locname1+=*dur;
		delete (dur);
	} else {
		locname1=Convert::int2str(i,2,"0");
		*locname1+=": +";
		string* dur=locsong->display_duration(locatepos);
		*locname1+=*dur;
		delete (dur);
		*locname1+="  ";		
		string* lni=locsong->getlocatename(i);
		*locname1+=*lni;
		delete(lni);
	}

\#if (HD24DEBUG==1) 
	cout << "add lpoints" << endl;
\#endif
	lpoints->add(locname1->c_str(),0,NULL,(void*)this);
	delete locname1;
	lpoints->redraw();
\#if (HD24DEBUG==1) 
	cout << "added lpoints" << endl;
\#endif
}

button_setlocatepoint->activate();
lpoints->value(0);
this->setlocbuttonlabel(0);
return numpoints;} {}
  }
  Function {init_vars()} {open return_type void
  } {
    code {\#if (HD24DEBUG == 1)
cout << "init_vars" << endl;
\#endif
//jackclient=NULL; 
//jackmtsample=NULL; 
currsong=NULL;
currproj=NULL;
//portaudiostream=NULL;
//inputParameters=new PaStreamParameters;
//outputParameters=new PaStreamParameters;
//portaudiooffset=0;
//pa_streamtime=0;
//portaudio_initialized=0;
//portaudio_mustloop=0;
//portaudio_looppos=0;
mustdisplaytimer=true;
mustdispsavemessage=false;
closingdown=false;
savemessage[0]='\\0';
refreshingui=0;
//loopmode=0;
//dispwritecountdown=0;
init_gui(0);
Fl::add_timeout(TIMEOUT,poll_callback,this);} {}
  }
  Function {ui_refresh(const char* orig)} {open
  } {
    code {/* to prevent re-refresh by selecting current project
   which will select a song which will refresh the current
   ui again...(in case of corrupt 'unexpected end of song'
   songs): */
if (refreshingui>1) return;
refreshingui++;

// init dropdown lists.
\#if (HD24DEBUG==1) 
cout << "==TRIGGER GUI REFRESH FROM "<<orig << "==" << endl;
cout << "going to clear dropdown lists" << endl; 
\#endif
for (unsigned int q=0;q<=99;q++) {
	projectname->remove(0);
	songname->remove(0);
}
int devid=0;
if ((currenthd24!=NULL)&&(currenthd24!=defaulthd24))
{
	devid=currenthd24->getdeviceid();
	if (devid<0)
	{
		devid=0;
	}
}
\#if (HD24DEBUG==1) 
cout << "going to populate drive list (" << devid << ")" << endl; 
\#endif

populate_drivelist(devid);

// following uses fsys (the default drive)
\#if (HD24DEBUG==1) 
cout << "get projcount then?" << endl; 
\#endif
string* nump=Convert::int2str(currenthd24->projectcount());
\#if (HD24DEBUG==1) 
cout << "got projcount=" << *nump <<  endl; 
\#endif
number_of_projects->value(nump->c_str());
delete (nump);
\#if (HD24DEBUG==1) 
cout << "last project id=" << currenthd24->lastprojectid() << endl;
\#endif

populate_projectlist(currenthd24->lastprojectid());


string* cat=new string("");
if (hd24utils::gencatalog(this->currenthd24,cat)==0) {
	this->catalogbuffer->remove(0,this->catalogbuffer->length()-1);
	this->catalogbuffer->append(cat->c_str());
	
//	if (this->catalog->buffer()!=NULL) {
//		free(this->catalog->buffer());
//	}
//	this->catalog->buffer(cat->c_str());
}
delete(cat);
\#if (HD24DEBUG==1) 
cout << "get version" << endl; 
\#endif
string* version1=currenthd24->version();
\#if (HD24DEBUG==1) 
cout << "got version" << endl; 
\#endif
fsversion->value(version1->c_str());
delete(version1);

calcspace();
Fl::add_timeout(TIMEOUT,poll_callback,this);

refreshingui--;} {}
  }
  Function {init_gui(int drive)} {open return_type void
  } {
    code {// int drive is for multi drive support.

// deselect all tracks on ' copy to hd24 tab' 
for (unsigned int i=1; i<=MAXCHANNELS; i++) {
   trackselected[i-1]=0;
}
// Neither jack or portaudio were found by configure.
// This means no sound is available, so hide the transport controls.
recorder->control->disable();
recorder->control->audio->mixer(this->mixer->control);

\#if (HD24DEBUG==1) 
	cout << "init_gui" << endl; 
\#endif
Fl::remove_timeout(poll_callback);
ui_refresh("init gui");
Fl::add_timeout(TIMEOUT,poll_callback,this);

populate_formats();
\#if (HD24DEBUG==1) 
	cout << "formats populated" << endl;
\#endif
fromtime->value("START");
totime->value("END");
refresh(fromtime);
refresh(totime);
\#if (HD24DEBUG==1) 
	cout << "init gui complete" << endl;
\#endif

calcspace();
showprogtitle();
            

setstatus("Ready.");} {}
  }
  Function {drivename_cb(Fl_Widget* w, void* data)} {return_type {static void}
  } {
    code {\#if (HD24DEBUG==1) 
	cout << "drivename_cb" << endl;
\#endif
HD24UserInterface *o=(HD24UserInterface *)data;
o->drivename_callback(w,data);} {}
  }
  Function {drivename_callback(Fl_Widget* w, void* data)} {return_type void
  } {
    code {\#if (HD24DEBUG==1) 
	cout << "drivename_callback" << endl;
\#endif
int choicemade=((Fl_Choice*)(w))->value();
\#if (HD24DEBUG==1) 
cout << "chose drive " << choicemade+1 << endl;
\#endif


string* idir=hd24utils::getlastdir("driveimagedir"); 
hd24fs* newcurrenthd=new hd24fs(idir->c_str(),defaulthd24->mode(),choicemade);
delete idir;
currenthd24=newcurrenthd;

init_gui(choicemade);} {}
  }
  Function {trackaction_callback(Fl_Widget* w, void* data)} {return_type void
  } {
    code {\#if (HD24DEBUG==1) 
	cout << "trackaction_callback" << endl;
\#endif
int choicemade=((Fl_Choice*)(w))->value();
if (choicemade==0) {
	((Fl_Choice*)(w))->color(1);
} else {
	((Fl_Choice*)(w))->color(7);
}
\#if (HD24DEBUG==1) 
cout << "chose item " << choicemade << endl;
\#endif} {}
  }
  Function {projectname_cb(Fl_Widget* w, void* data)} {return_type {static void}
  } {
    code {\#if (HD24DEBUG==1) 
	cout << "projectname_cb" << endl;
\#endif
HD24UserInterface *o=(HD24UserInterface *)data;
o->projectname_callback(w,data);} {}
  }
  Function {projectname_callback(Fl_Widget* w, void* data)} {return_type void
  } {
    code {\#if (HD24DEBUG==1) 
	cout << "projectname_callback" << endl;
\#endif
int choicemade=((Fl_Choice*)(w))->value();
select_project(choicemade+1);} {}
  }
  Function {songname_cb(Fl_Widget* w, void* data)} {open return_type {static void}
  } {
    code {\#if (HD24DEBUG == 1 )
	cout << "songname_cb" << endl;
\#endif
HD24UserInterface *o=(HD24UserInterface *)data;
o->songname_callback(w,data);} {}
  }
  Function {songname_callback(Fl_Widget* w, void* data)} {open return_type void
  } {
    code {\#if (HD24DEBUG==1) 
	cout << "songname_callback" << endl;
\#endif
int choicemade=((Fl_Choice*)(w))->value();
if (currproj!=NULL) delete currproj;
currproj=currenthd24->getproject(projectname->value()+1);
//songname->value(choicemade); // should not be needed
select_song(choicemade); // song id=choicemade} {}
  }
  Function {refresh(Fl_Widget * w)} {open return_type void
  } {
    code {w->deactivate();
w->activate();} {}
  }
  decl {time_t starttime,endtime} {}
  Function {calcspace()} {return_type void
  } {
    code {__uint32 rate;
__uint32 tracks;

switch (atrate->value()) {
    case 0: rate=44100; break;
    case 1: rate=48000; break;
    case 2: rate=88200; break;
    case 3: rate=96000; break;
    default: return;
}
switch (attracks->value()) {
    case 0: tracks=2; break;
    case 1: tracks=6; break;
    case 2: tracks=8; break;
    case 3: tracks=12; break;
    case 4: tracks=16; break;
    case 5: tracks=24; break;
    default: return;
}
string* strfree=currenthd24->freespace(rate,tracks);
freespace->value(strfree->c_str());
delete (strfree);} {}
  }
  Function {transferstatus(void* ui,const char* message,double pct)} {open return_type {static void}
  } {
    code {if (ui==NULL) return;
((HD24UserInterface*)ui)->statusmsg->value(message);
((HD24UserInterface*)ui)->fl_check();} {}
  }
  Function {setstatus(string message)} {open return_type void
  } {
    code {statusmsg->value(message.c_str());
fl_check();} {}
  }
  decl {/* ===File transfer stuff ===================================================== */} {}
  decl {Fl_Widget* trackaction[24];} {public
  }
  decl {int transfer_cancel;} {public
  }
  decl {Fl_Output* filename[24];} {public
  }
  Function {savemessage_callback(void* user)} {open return_type {static void}
  } {
    code {HD24UserInterface* mythis=(HD24UserInterface*)user;
string* stat=new string(mythis->savemessage);
mythis->setstatus(*stat);
//mythis->uicanvas->redraw();
mythis->statusbar->damage();
mythis->statusbar->redraw();

delete (stat);
if (mythis->mustdispsavemessage) {
Fl::repeat_timeout(.25,savemessage_callback,user);
}} {}
  }
  Function {countfiletracks(const char* filename)} {open return_type int
  } {
    code {SF_INFO sfinfo;
SNDFILE* infile=NULL;
if (strlen(filename)==0) 
{
	return 0;
}
infile=soundfile->sf_open(filename,SFM_READ,&sfinfo);
if (!infile) 
{
	return 0;
}
int numchans=sfinfo.channels;
soundfile->sf_close(infile);
return numchans;} {}
  }
  decl {char savemessage[300];} {public
  }
  Function {populate_trackaction(HD24UserInterface* ui,Fl_Widget* o,int tracknum)} {open return_type void
  } {
    code {if (tracknum<1) {
return;
}
if (tracknum>24) {
 return;
}

trackaction[tracknum-1]=o;

((Fl_Choice*)o)->clear();
((Fl_Choice*)o)->add("Erase",0,(void (*)(Fl_Widget*,void*))(&(trackaction_cb)),(void*)this);
((Fl_Choice*)o)->add("SMPTE",0,(void (*)(Fl_Widget*,void*))(&(trackaction_cb)),(void*)this);
((Fl_Choice*)o)->add("Mono",0,(void (*)(Fl_Widget*,void*))(&(trackaction_cb)),(void*)this);
// count number of tracks in file given by filename
// when >1, for each track add a line.
int numtracks=countfiletracks(filename[tracknum-1]->value());
if (numtracks>1) {
	for (int i=1; i<=numtracks; i++) {
		string strtrack="Tr.";
		string* strnum=Convert::int2str(i);
		strtrack+=*strnum;
		((Fl_Choice*)o)->add(strtrack.c_str(),0,(void (*)(Fl_Widget*,void*))(&(trackaction_cb)),(void*)this);
		delete strnum;
	}
}
((Fl_Choice*)o)->value(2); // default 0=erase, 1=SMPTE, 2=mono
((Fl_Choice*)o)->redraw();
fl_check();} {}
  }
  Function {populate_trackactionbyfile(__uint32 slotnum,int trackchoice)} {open return_type void
  } {
    code {if (slotnum<0) return;
if (slotnum>23) return;

Fl_Choice* o=(Fl_Choice*)trackaction[slotnum];
if (o==NULL) return;
for (unsigned int i=0;i<128;i++) { o->remove(0); }
o->add("Erase",0,(void (*)(Fl_Widget*,void*))(&(trackaction_cb)),(void*)this);
o->add("SMPTE",0,(void (*)(Fl_Widget*,void*))(&(trackaction_cb)),(void*)this);
o->add("Mono",0,(void (*)(Fl_Widget*,void*))(&(trackaction_cb)),(void*)this);
// count number of tracks in file given by filename
// when >1, for each track add a line.
int numtracks=countfiletracks(filename[slotnum]->value());
if (numtracks>1) {
	for (int i=1; i<=numtracks; i++) {
		string strtrack="Tr.";
		string* strnum=Convert::int2str(i);
		strtrack+=*strnum;
		o->add(strtrack.c_str(),0,(void (*)(Fl_Widget*,void*))(&(trackaction_cb)),(void*)this);
		delete strnum;
	}
}
o->value(trackchoice);
trackaction_callback(o,NULL);
o->redraw();

fl_check();} {}
  }
  Function {moveselected(__sint32 direction)} {open return_type void
  } {
    code {__uint32 firsttrack=0;
__uint32 lasttrack=0;
if (currsong==NULL) 
{
	return;
}
if (direction==-1) 
{
	firsttrack=1;
	lasttrack=currsong->logical_channels();
	if (trackselected[0]==1) 
	{
		// move up, but first track is selected
		// and already upper choice- cannot move up
		return;
	}
} 
else 
{
	if (direction==1)
	{
		lasttrack=1;
		firsttrack=currsong->logical_channels();
		
		if (trackselected[currsong->logical_channels()-1]==1) 
		{
			return;
		}
	}
}
// we need to move stuff.
if (firsttrack==0) return; // direction==0, don't move.

__uint32 tracknum=firsttrack;
while (tracknum!=lasttrack) 
{
	if (trackselected[tracknum-1]!=trackselected[tracknum-1-direction]) 
	{
		int dummy=trackselected[tracknum-1];
		string* trackval=new string(filename[tracknum-1]->value());
		
		trackselected[tracknum-1]=trackselected[tracknum-1-direction];		
		trackselected[tracknum-1-direction]=dummy;
		
		int a=((Fl_Choice*)(trackaction[tracknum-1]))->value();
		int b=((Fl_Choice*)(trackaction[tracknum-1-direction]))->value();
		
		filename[tracknum-1]->value(filename[tracknum-1-direction]->value());		
		filename[tracknum-1-direction]->value(trackval->c_str());		
		
		populate_trackactionbyfile(tracknum-1,b);
		populate_trackactionbyfile(tracknum-1-direction,a);
		
		delete trackval;
	}
	tracknum-=direction;
}

redrawtracks();} {}
  }
  Function {trackaction_cb(Fl_Widget* w, void* data)} {open return_type {static void}
  } {
    code {\#if (HD24DEBUG==1) 
	cout << "trackaction_cb" << endl;
\#endif
HD24UserInterface *o=(HD24UserInterface *)data;
o->trackaction_callback(w,data);} {}
  }
  Function {redrawtracks()} {open return_type void
  } {
    code {bool track_active;
if (currsong==NULL) {
	return;
}

for (unsigned int tracknum=1;tracknum<=MAXCHANNELS;tracknum++) 
{
	if (currsong->logical_channels()>=tracknum) {
		track_active=true;
		filename[tracknum-1]->activate();
	} else {
		track_active=false;
		((Fl_Output*)filename[tracknum-1])->color(7);
		filename[tracknum-1]->deactivate();
	}
	
	if (track_active) {
		if (trackselected[tracknum-1]==1) {
			((Fl_Output*)filename[tracknum-1])->color(3);
		} else {
			((Fl_Output*)filename[tracknum-1])->color(7);
		}
	}

	((Fl_Output*)filename[tracknum-1])->redraw();
}} {}
  }
  decl {/* ===UI stuff ===================================================== */} {}
  Function {populate_formats()} {open return_type void
  } {
    code {\#if (HD24DEBUG==1) 
	cout << "populate_formats" << endl;
\#endif

for (int i=0;i<transeng->supportedformatcount();i++)
{
    fileformat->add(transeng->getformatdesc(i),0,NULL,(void*)this);
}
fileformat->value(0);} {}
  }
  Function {selectfilename(int tracknum)} {return_type void
  } {
    code {this->trackselected[tracknum-1]=1-this->trackselected[tracknum-1];
if (this->trackselected[tracknum-1]==1) {
	this->filename[tracknum-1]->color(3);
} else {
	this->filename[tracknum-1]->color(7);
}
this->filename[tracknum-1]->redraw();} {}
  }
  Function {select_project(int projectid)} {open return_type void
  } {
    code {if (currproj!=NULL) {
	if (currsong!=NULL)
	{
		hd24song* tmpsong=currsong;
		currsong=NULL;
		delete tmpsong;
	}
	hd24project* tmpproj=currproj;
	currproj=NULL;
	delete tmpproj;
}
currproj=currenthd24->getproject(projectid);
\#if (HD24DEBUG==1) 
	cout << "select_project \#" << projectid << endl;
\#endif
currenthd24->lastprojectid(projectid);
projectname->value(projectid-1); /* project id is 1-based */
int currsongcount=0;
if (currproj==NULL)
{
    delete_project->deactivate();
} 
else
{
    delete_project->activate();
    currsongcount=currproj->songcount();
}

if (currsongcount==0) 
{
	number_of_songs->value("0");
	populate_songlist(0); // shows -- EMPTY PROJECT --
	select_song(0);
	return;
}

// currproj is defined at this point.

string* nums=Convert::int2str(currproj->songcount());
number_of_songs->value(nums->c_str());
\#if (HD24DEBUG==1) 
	cout << "number of songs=" << currproj->songcount() << endl;
\#endif
delete(nums);

int lastsongid=currproj->lastsongid();
\#if (HD24DEBUG==1) 
	cout << "lastsongid=" << lastsongid << endl;
\#endif
populate_songlist(lastsongid);} {}
  }
  Function {select_song(int songid)} {open return_type void
  } {
    code {unsigned int i;
button_setlocatepoint->deactivate();
\#if (HD24DEBUG==1) 
cout << "select_song \#" << songid << endl; 
\#endif



if (songid==0) {

	// This represents the choice "all songs"
	if (currsong!=NULL) {
		hd24song* tmpsong=currsong;
		currsong=NULL;		
		delete tmpsong;
	}
	transfersource->value("(All songs in the current project)");
	if (number_of_tracks==NULL) 
	{
		return; // ui not yet initialized?
	}
	tab_tohd24->deactivate();
	rename_song->deactivate();
	delete_song->deactivate();
        number_of_tracks->value("");
	number_of_tracks->deactivate();
	sample_rate->value("");
	sample_rate->deactivate();
	bitdepth->value("");
	bitdepth->deactivate();
	duration->value("");
	duration->deactivate();
	//refresh (songname);
	for (i=0; i<MAXCHANNELS;i++) {
	    track[i]->deactivate();
	    track[i]->value(1);
	    track[i]->show();
	}
	button_setlocatepoint->deactivate();
	button_golocatepoint->deactivate();
	button_invert_tracks->deactivate();
	choice_startloc=0; // use default 
	// disable locatepoint dropdown:
	choice_endloc=populate_locatepoints(currsong,locatepoints);	
	choice_endloc=0;
	update_fromto();	
	fromto->deactivate();
	refresh (tab_tohd24);
	return;

} else {
\#if (HD24DEBUG==1) 
cout << "activate buttons" << endl;
\#endif
	delete_song->activate();
	rename_song->activate();
	tab_tohd24->activate();
	button_golocatepoint->activate();
	button_setlocatepoint->activate();
	button_invert_tracks->activate();
	rename_song->activate();
	sample_rate->activate();
	bitdepth->activate();
	duration->activate();
	refresh (rename_song);
	refresh (number_of_tracks);
	refresh (sample_rate);
	refresh (bitdepth);
	refresh (duration);
	refresh (tab_tohd24);
\#if (HD24DEBUG==1) 
cout << "deselect old song" << endl;
\#endif
	if (currsong!=NULL) {
		recorder->control->song(NULL); /* tell recorder that the song is gone */			
		delete currsong;
		currsong=NULL;
	}	
\#if (HD24DEBUG==1) 
cout << "currprojgetsong" << endl;
\#endif
	currsong=currproj->getsong(songid);
	currproj->lastsongid(songid);
	if (currsong->has_unexpected_end()) {
		if (currsong->is_fixable_unexpected_end()) {
			song_messages->value("Unexpected end of song.\\nTrying to find the rest of the audio...");
//		currenthd24->dumpclusterusage2(currenthd24->findorphanclusters());
			unsigned char* orphans=currenthd24->findorphanclusters();
			if (orphans != NULL) {
				currsong->appendorphanclusters(orphans,true /*allowsongresize*/);
				song_messages->value(
				"Unexpected end of song. I think I found back the rest of it.\\n"
				"However, you really should backup all audio and reformat this drive.");
				if (currenthd24->getmaintenancemode()==1) {
					if (confirm("Song was recovered. Do you wish to save the changes?\\nAnswer Yes only if you have verified that the audio is OK)")) {
						currsong->save();
					}
				}
			}
		}			
		else
		{
			ui_refresh("selectsong");
			song_messages->value("Unexpected end of song.\\nHD24tools can not automatically fix this specific occurence.");
		}
	} else {
		song_messages->value("No messages.");
	}
}


\#if (HD24DEBUG==1) 
cout << "songname->value" << endl;
\#endif

songname->value(songid); // entry 0=all songs, 1=song id 1
string* dummy=currsong->songname();
transfersource->value(dummy->c_str());

/* This should al be done by the recorder.... 
string disp="S";
string* idstr=Convert::int2str(songid,2,"0");
disp+=*idstr;
delete idstr;
disp+=":\\"";
string* dummy=currsong->songname();
transfersource->value(dummy->c_str());
string* dummy2=Convert::readstring((unsigned char*)dummy->c_str(),0,10);
string* dummy3=Convert::readstring((unsigned char*)dummy->c_str(),0,11);

disp+=*dummy2;
delete dummy;
delete dummy2;
if (dummy3->length()>10)
{
disp+="\\4"; // arrow right
} else {
disp+="\\"";
}
delete dummy3;
string* disp2=Convert::padright(disp,16," ");

string* dur=currsong->display_duration();

*disp2+=dur->substr(0,8);
*disp2+=":";
*disp2+=dur->substr(9,2);
*disp2+=" ";
if (currsong->iswriteprotected())
{
*disp2+="\\1";
} else {
*disp2+="\\2";
}
string* strtracksb=Convert::int2str(currsong->logical_channels(),2,"0");
*disp2+=*strtracksb;
delete strtracksb;
*disp2+="t";

recorder->control->dispwrite(0,disp2->c_str());
delete disp2;
 ............. until this point */
recorder->control->song(currsong); /* load song into recorder */

redrawtracks(); // enable/disable tracks for export to HD24	
string* strtracks=Convert::int2str(currsong->logical_channels());
number_of_tracks->value(strtracks->c_str());
number_of_tracks->activate();
delete (strtracks);
string* samrat=Convert::int2str(currsong->samplerate());
sample_rate->value(samrat->c_str());
sample_rate->activate();
delete samrat;
if (mixer!=NULL) {
	mixer->control->samplerate(this->samplerate());
}

string* bitd=Convert::int2str(currsong->bitdepth());
bitdepth->value(bitd->c_str());
bitdepth->activate();
delete(bitd);

string* dur=currsong->display_duration();
duration->value(dur->c_str());
duration->activate();
delete(dur);

if (currsong->iswriteprotected()) {
   writeprotected->value(1); 
} else {
   writeprotected->value(0);
}

refresh (songname);
refresh (number_of_tracks);
refresh (sample_rate);
refresh (bitdepth);
refresh (duration);
refresh (writeprotected);// writeprotected->deactivate();

for (i=0; i<currsong->logical_channels();i++) {
    track[i]->activate();
    track[i]->show();
    trackled[i]->show();
}
for (i=currsong->logical_channels();i<MAXCHANNELS;i++) {
    track[i]->deactivate();
    track[i]->hide();
    trackled[i]->hide();
}

choice_startloc=0; // use default 
choice_endloc=populate_locatepoints(currsong,locatepoints);
button_golocatepoint->activate();
if (choice_endloc>0) {
	fromto->activate();
}
update_fromto();} {}
  }
  decl {int choice_startloc;} {}
  decl {int choice_endloc;} {}
  decl {bool mustdispsavemessage;} {public
  }
  decl {int loopmode;} {public
  }
  decl {int uiredrawcount; /* to limit refreshing UI */} {public
  }
  Function {update_fromto()} {return_type void
  } {
    code {if (currsong==NULL)
{
fromtime->value("START");
totime->value("END");
return;
}
string* dummy1=currsong->getlocatename(choice_startloc);
string* dummy2=currsong->getlocatename(choice_endloc);
string* strfrom=Convert::trim(dummy1);
string* strto=Convert::trim(dummy2);


fromtime->value(strfrom->c_str());
totime->value(strto->c_str());
delete(dummy1);
delete(dummy2);
delete (strfrom);
delete (strto);} {}
  }
  Function {make_window(hd24fs* p_fsys) /* <------------------------------------------- */} {open
  } {
    Fl_Window {} {
      label HD24connect open
      xywh {485 44 605 530} type Double color 52 align 5
      code0 {defaulthd24=p_fsys;}
      code1 {currenthd24=p_fsys; // current and default to allow multi drive support}
      code2 {init_vars();} visible
    } {
      Fl_Group {} {open
        xywh {-5 0 1720 540}
      } {
        Fl_Group menucanvas {open
          xywh {0 0 640 24}
        } {
          Fl_Menu_Bar {} {open
            xywh {0 0 640 24} color 52
          } {
            Submenu menufile {
              label {&File} open
              xywh {0 0 100 20} labelsize 12
            } {
              MenuItem {} {
                label {&Detect HD24 drives}
                callback {if (currenthd24!=NULL) {
    delete currenthd24;
    currenthd24=NULL;
}

string* idir=hd24utils::getlastdir("driveimagedir"); 
currenthd24=new hd24fs(idir->c_str(),hd24fs::MODE_RDWR);
delete idir;
defaulthd24=currenthd24;
if (!(currenthd24->isOpen())) 
{
   fl_message("Sorry, during detection no valid HD24 drive was found connected to the system.\\nPlease switch on and connect the drive, or try another File menu option.");
}
ui_restart();}
                xywh {0 0 34 21} labelsize 12 divider
              }
              MenuItem {} {
                label {&Open drive image...}
                callback {string* driveimgdir=hd24utils::getlastdir("driveimagedir");

Fl_Native_File_Chooser chooser;
chooser.directory(driveimgdir->c_str());
delete driveimgdir;
chooser.title("Select HD24 drive image\\0");
chooser.type(Fl_Native_File_Chooser::BROWSE_FILE);
chooser.filter("Drive Images\\t*.{img,bin,h24,hd24}\\0");
//chooser.preview(0);
switch (chooser.show()) {
	case -1: break; //error
	case 1: break; //cancel
	default:
		if (chooser.filename()) {
			string* cfilename=new string(chooser.filename());
		
			//cout << "filename = " << *strfile << endl;
			string* fpath=new string("");
			*fpath+=cfilename->substr(0,strlen(cfilename->c_str())-strlen(fl_filename_name(cfilename->c_str())));
			hd24utils::setlastdir("driveimagedir",fpath->c_str());
					
			hd24fs* sysob=new hd24fs(fpath->c_str(),hd24fs::MODE_RDWR,cfilename,false);
			delete cfilename;
			if (currenthd24!=NULL) 
			{
				currenthd24->~hd24fs();
			}
			if (defaulthd24!=NULL) 
			{
				if (defaulthd24!=currenthd24)
				{
					defaulthd24->~hd24fs();
				}
			}
			currenthd24=sysob;
			defaulthd24=sysob;
			
			if (!(currenthd24->isOpen())) 
			{
	  		   bool choice=confirm(
				"File does not appear to be a valid HD24 device image.\\nDo you want to try using it anyway?\\nWarning: Choosing 'Yes' may result in\\ncrashes and other unpredictable behavior."
				);
			
			   if (choice) {
			        if (sysob!=NULL) {
				   	delete (sysob);
				}
				bool wantheader=confirm("Do you want to load a header file?");
				
				cfilename=new string(chooser.filename());
       				string* idir=hd24utils::getlastdir("driveimagedir"); 
			   	sysob=new hd24fs(idir->c_str(),hd24fs::MODE_RDWR,cfilename,true); //force
				delete idir;
				delete cfilename;
				if (currenthd24!=NULL) 
				{
					currenthd24->~hd24fs();
				}
				if (defaulthd24!=NULL) 
				{
					if (defaulthd24!=currenthd24)
					{
						defaulthd24->~hd24fs();
					}

				}
				
				currenthd24=sysob;
				defaulthd24=sysob;
				if (currenthd24->isOpen()) {
					if (wantheader) {
					   loadheaderfile();
					}
					ui_restart();
					return;
				}
				fl_message("Cannot open HD24 device image.");
			   }
			   
			   return;
			}
			ui_restart();			
		}
		break;
}}
                xywh {0 0 34 21} labelsize 12
              }
              MenuItem {} {
                label {&Save drive image...}
                callback {string* driveimgdir=new string("");
*driveimgdir+=*hd24utils::getlastdir("driveimagedir");

Fl_Native_File_Chooser chooser;
chooser.filter("Drive Images\\t*.{img,bin,h24,hd24}\\0");
chooser.title("Export full drive image file");
chooser.directory(driveimgdir->c_str());
chooser.options(Fl_Native_File_Chooser::NEW_FOLDER);
chooser.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);

switch (chooser.show()) {
	case -1: break; //error
	case 1: break; //cancel
	default:
		// save header to chooser.filename()

		bool bFileexists=hd24utils::fileExists(chooser.filename());
		if (bFileexists) {
			bool choice=confirm(
				"A file with this name already exists. Do you wish to overwrite it?"
				);			
			if (!(choice)) return;
		}
		string* strfile=new string(chooser.filename());
		//cout << "filename = " << *strfile << endl;
		string* fpath=new string("");
		*fpath+=strfile->substr(0,strlen(strfile->c_str())-strlen(fl_filename_name(strfile->c_str())));
		hd24utils::setlastdir("driveimagedir",fpath->c_str());
		this->transfer_cancel=0;
		this->mustdispsavemessage=true;
		Fl::add_timeout(.25,savemessage_callback,this);
		int result=hd24utils::savedriveimage(currenthd24,strfile,&this->savemessage[0],&this->transfer_cancel);
		delete strfile;
		if (result==0) {
			fl_message("Drive image created successfully.");
			setstatus("Done.");
		} else {
			fl_message("Could not write drive image to file. Access denied? Disk full?");	
		}
		this->mustdispsavemessage=false;
		break;
}
delete driveimgdir;}
                xywh {10 10 34 21} labelsize 12
              }
              Submenu {} {
                label {&Catalog} open
                xywh {0 0 70 21} labelsize 12
              } {
                MenuItem {} {
                  label {&Export catalog...}
                  callback {string* catdir=new string("");
*catdir+=*hd24utils::getlastdir("catalogdir");

Fl_Native_File_Chooser chooser;
chooser.filter("Text files\\t*.txt");
chooser.title("Export disk catalog to file");
chooser.directory(catdir->c_str());
chooser.options(Fl_Native_File_Chooser::NEW_FOLDER);
chooser.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);

switch (chooser.show()) {
	case -1: break; //error
	case 1: break; //cancel
	default:
		// save header to chooser.filename()

		bool bFileexists=hd24utils::fileExists(chooser.filename());
		if (bFileexists) {
			bool choice=confirm(
				"A file with this name already exists. Do you wish to overwrite it?"
				);			
			if (!(choice)) return;
		}
		string* strfile=new string(chooser.filename());
		//cout << "filename = " << *strfile << endl;
		string* fpath=new string("");
		*fpath+=strfile->substr(0,strlen(strfile->c_str())-strlen(fl_filename_name(strfile->c_str())));
		hd24utils::setlastdir("catalogdir",fpath->c_str());
		string* anyerrors=hd24utils::savecatalog(currenthd24,strfile);
		delete strfile;
		if (anyerrors==NULL) {
			fl_message("Catalog file created successfully.");
		} else {	
			delete anyerrors;
			fl_message("Could not write catalog file. Access denied? Disk full?");	
		}
		break;
}
delete catdir;}
                  tooltip {Save the disk directory to a printable text file} xywh {40 40 34 21} labelsize 12
                }
                MenuItem {} {
                  label {&Print catalog}
                  callback {string* result=hd24utils::printcatalog(currenthd24);
if (result!=NULL) 
{
	if (strlen(result->c_str())!=0) 
	{
		fl_message("%s",result->c_str());
	}
}
delete result;}
                  tooltip {Save the disk directory to a printable text file} xywh {30 30 34 21} labelsize 12 divider
                }
              }
              Submenu {} {
                label {&Mixer} open
                xywh {10 10 70 21} labelsize 12
              } {
                MenuItem {} {
                  label {&Save mixer settings to file,,,}
                  callback {mixer->savetofile();}
                  tooltip {Save the current mixer settings to a file} xywh {50 50 34 21} labelsize 12
                }
                MenuItem {} {
                  label {&Load mixer settings from file...}
                  callback {mixer->loadfromfile();}
                  tooltip {Recall mixer settings from a previously saved mix} xywh {60 60 34 21} labelsize 12 divider
                }
                MenuItem {} {
                  label {&Save mixer settings to HD24 drive,,,}
                  tooltip {Save the current mix onto the HD24 drive} xywh {60 60 34 21} labelsize 12 deactivate
                }
                MenuItem {} {
                  label {&Load mixer settings from HD24 drive...}
                  tooltip {Recall mixer settings from a mix previously saved to the current HD24 drive} xywh {70 70 34 21} labelsize 12 deactivate
                }
              }
              Submenu {} {
                label {&Recovery} open
                xywh {0 0 70 21} labelsize 12 divider
              } {
                MenuItem {} {
                  label {&Select device...}
                  callback {dialog_choosedevice* chooser=new dialog_choosedevice();
Fl_Double_Window* w=chooser->make_window(currenthd24);
w->end();
w->show();
while (w->visible()) { 
Fl::wait();
}
string* cfilename;
hd24fs* sysob;
string* idir=NULL;
switch (chooser->buttonclicked) {
	case 1:
		// OK
		cfilename=new string(chooser->devicename->c_str());
		idir=hd24utils::getlastdir("driveimagedir"); 
		sysob=new hd24fs(idir->c_str(),hd24fs::MODE_RDWR,cfilename,false);
		delete idir; idir=NULL;

		currenthd24=sysob;
		defaulthd24=sysob;
			
		if (!(currenthd24->isOpen())) 
		{
	  	   bool choice=confirm(
			"Device does not appear to be a valid HD24 device.\\nDo you want to try using it anyway?\\nWarning: Choosing 'Yes' may result in\\ncrashes and other unpredictable behavior."
		   );
		
		   if (choice) {
		        if (sysob!=NULL) {
			   	delete (sysob);
			}
       			string* idir=hd24utils::getlastdir("driveimagedir"); 
		   	sysob=new hd24fs(idir->c_str(),hd24fs::MODE_RDWR,cfilename,true); //force
			delete idir;
			currenthd24=sysob;
			defaulthd24=sysob;
			int tryheader=0;
			if (currenthd24->isOpen()) {
			        tryheader=1;
				bool wantheader=confirm("Do you want to load a header file?");
				if (wantheader) {
				   loadheaderfile();
				}
			
				ui_restart();
				delete cfilename;
				return;
			}
			if (tryheader==1) {
  			    fl_message("Cannot open HD24 device.");
  			} else {
    			    fl_message("Cannot open HD24 device. Access denied?");
  			}
		   }
		   delete cfilename;
		   break;
		}
		ui_restart();			
		delete cfilename;		
		break;
	case 2:
		// cancel
		break;
	default:
		// unknown
		break;
}
delete chooser;}
                  xywh {5 5 34 21} labelsize 12
                }
                MenuItem {} {
                  label {Load &header file...}
                  callback {loadheaderfile();}
                  xywh {5 5 34 21} labelsize 12
                }
                MenuItem {} {
                  label {&Create header file...}
                  callback {string* headerdir=new string("");
*headerdir+=*hd24utils::getlastdir("headerdir");

Fl_Native_File_Chooser chooser;
chooser.filter("Header files (*.h24)\\t");
chooser.title("Create header file");
chooser.options(Fl_Native_File_Chooser::NEW_FOLDER);
chooser.directory(headerdir->c_str());
chooser.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);

switch (chooser.show()) {
	case -1: break; //error
	case 1: break; //cancel
	default:
		// save header to chooser.filename()
		bool bFileexists=hd24utils::fileExists(chooser.filename());
		if (bFileexists) {
			bool choice=confirm(
				"A file with this name already exists. Do you wish to overwrite it?"
				);			
			if (!(choice)) return;
		}
		string* strfile=new string(chooser.filename());
		string* fpath=new string("");
		*fpath+=strfile->substr(0,strlen(strfile->c_str())-strlen(fl_filename_name(strfile->c_str())));
		hd24utils::setlastdir("headerdir",fpath->c_str());
		
		int result=hd24utils::saveheader(currenthd24,strfile);
		delete strfile;
		if (result==0) {
			fl_message("Header file created successfully.");
		} else {
			fl_message("Could not write header file. Access denied? Disk full?");		
		}
		break;
}}
                  xywh {15 15 34 21} labelsize 12
                }
                MenuItem {} {
                  label {Recover song from &power failure}
                  callback {if (currsong==NULL) {
	fl_message("First select the song to recover.");
	return;
}

dialog_setlength* ui_setlength;
ui_setlength=new dialog_setlength;
int currlocchoice=locatepoints->value();
Fl_Window *win=ui_setlength->make_window(currsong,currlocchoice);
win->end();
win->show();

while (win->visible()) { Fl::wait(); }

if (ui_setlength->buttonclicked==1) {
	// TODO:
	// - create header file
	//   getuserdatapath. 
	//    
	
	char userdatapath[FL_PATH_MAX];
	Fl_Preferences* prefs=new Fl_Preferences(Fl_Preferences::USER,"HD24","HD24connect");
	prefs->getUserdataPath(userdatapath,FL_PATH_MAX);
	delete prefs;
	string* headerfilename=new string(userdatapath);
	
	// add OS directory slash if forgotten
\#ifdef WINDOWS
\#define OSSLASH '\\\\'
\#else
\#define OSSLASH '/'
\#endif
const char* x=headerfilename->c_str();
int q=strlen(x);
if (q>0) 
{
	if (x[q-1]!=OSSLASH) 
  	{
  		*headerfilename+=OSSLASH;
  	}
}		
*headerfilename+="livefix.h24";
	
	int createtempheaderresult=hd24utils::savedrivesectors(currenthd24,headerfilename,0,0x10c76,NULL,NULL);

	if (createtempheaderresult!=0)
	{
		delete headerfilename;
		fl_message("Couldn't create a temporary header file, cannot continue. Sorry.");
		return;
	}
	// header was created successfully.
	currenthd24->useheaderfile(*headerfilename);	
	//cout << "Userdatapath="<<userdatapath << endl;

	// - use header file
	// - this makes sure any writes go to header file

	bool clearnew=false;
	currsong->songlength_in_samples(ui_setlength->locpoint,clearnew);
	currsong->save();
	ui_refresh("liverec");
}
delete ui_setlength;}
                  xywh {10 10 36 21} labelsize 12
                }
              }
              MenuItem {} {
                label {E&xit}
                callback {/* Find current window */
this->finish();

Fl_Window * x=Fl::first_window();
x->~Fl_Window();
delete x;
x=NULL;}
                xywh {0 0 100 20} labelsize 12
              }
            }
            Submenu menutools {
              label {&Tools} open
              xywh {10 10 100 20} labelsize 12
            } {
              Submenu {} {
                label {Alter &order of songs in project} open
                xywh {20 20 100 20} labelsize 12 divider
              } {
                MenuItem {} {
                  label {Sort &Alphabetically}
                  callback {if (this->currproj==NULL)
{
	fl_message("Cannot sort project- no project selected.");
	return;
}
this->currproj->sort();
this->currproj->save();
this->ui_refresh("sort");}
                  xywh {30 30 34 21} labelsize 12
                }
              }
              MenuItem {} {
                label {&Options...}
                callback {dialog_options* ui_options;
ui_options=new dialog_options;
Fl_Window *win=ui_options->make_window();
win->end();
win->show();

while (win->visible()) { Fl::wait(); }

delete ui_options;}
                xywh {30 30 34 21} labelsize 12
              }
            }
            Submenu menuhelp {
              label {&Help} open
              xywh {0 0 100 20} labelsize 12
            } {
              MenuItem {} {
                label {&About}
                callback {UserInterface_HelpAbout* ui_help_about;
ui_help_about=new UserInterface_HelpAbout;

Fl_Window *helpaboutdialog=ui_help_about->make_window();
helpaboutdialog->end();
helpaboutdialog->show();

while (helpaboutdialog->visible()) { Fl::wait(); }}
                xywh {0 0 100 20} labelsize 12
              }
              MenuItem {} {
                label {System &Info}
                callback {string info="HD24connect system info\\n";
info+="JACK: ";
if (libjack->libloaded) {
	info+="Loaded";
} else {
	info+="Not present";
}
info+="\\n";

info+="LIBSNDFILE: ";
if (soundfile->libloaded) {
	info+="Loaded";
} else {
	info+="Not present";
}
info+="\\n";


info+="PORTAUDIO: ";
if (portaudio->libloaded) {
	info+="Loaded";
} else {
	info+="Not present";
}
info+="\\n";


fl_message("%s",info.c_str());}
                xywh {20 20 100 20} labelsize 12
              }
              MenuItem {} {
                label {Report a &Bug}
                callback {string bug="No warranty of any kind is given on this program.\\n\\n";
bug+="However, if you find any defects or faults in it, they\\n";
bug+="will most likely be fixed with high priority in the next\\n";
bug+="release, as long as the author is aware of them.\\n\\n";
bug+="Should you find any defects, please email the author at\\n";
bug+="the following e-mail address:\\n\\n";
bug+="mrjb@@dnd.utwente.nl.\\n\\n";
bug+="Make sure to include 'hd24' in the subject line.";
fl_message("%s",bug.c_str());}
                xywh {0 0 100 20} labelsize 12
              }
              MenuItem {} {
                label {Request a &Feature}
                callback {string bug="If you would like a specific feature to be added, please\\n";
bug+="please email your request to the author at the following \\n";
bug+="e-mail address:\\n\\n";
bug+="mrjb@@dnd.utwente.nl.\\n\\n";
bug+="Make sure to include 'hd24 feature request' in the subject line.\\n";
bug+="You can increase the priority of the request by donating.";
fl_message("%s",bug.c_str());}
                xywh {10 10 100 20} labelsize 12
              }
              MenuItem {} {
                label {&Credits}
                callback {string thanks="Extra Special thanks go out to: \\n\\n";
thanks+="Randy Bryant for trusting me to use his Mac\\n";
thanks+="Mike Crute for hosting and builder support\\n";
thanks+="Cabbage for building various Mac package installers\\n";
thanks+="Edward van Westerlaak for Windows and Mac/OSX beta testing, hardware support and suggestions\\n";
thanks+="Erik de Castro Lopo and other contributors for libsndfile\\n";
thanks+="Ross Bencina, Phil Burk, Bjorn Roche and other contributors for the portaudio library\\n";
thanks+="Bill Spitzak and others for the Fast Light Toolkit\\n";
thanks+="Sveinn Kjartansson for providing the means for high sample rate support\\n\\n";
thanks+="Special thanks go out to the Yahoo Groups HD24 community\\n";
thanks+="for additional beta testing, suggestions and general encouragement.\\n\\n";
fl_message("%s",thanks.c_str());}
                xywh {10 10 100 20} labelsize 12
              }
            }
          }
        }
        Fl_Group uicanvas {open
          xywh {-5 0 1720 540} resizable
        } {
          Fl_Group transfercanvas {
            label Transfer
            xywh {10 360 590 150} box UP_BOX color 52 labelfont 1 labelsize 12 align 5
          } {}
          Fl_Group statusbar {
            xywh {-5 510 725 20} box DOWN_BOX color 23
          } {
            Fl_Output backgroundbox {
              xywh {0 510 605 20} color 52 labelsize 12 textsize 12
            }
            Fl_Button stop_transfer {
              label Cancel
              callback {transfer_cancel=1;
stop_transfer->hide();}
              xywh {525 510 80 20} labelsize 12 align 16
              code0 {o->hide();}
            }
            Fl_Output statusmsg {
              xywh {0 510 525 20} color 52 labelsize 12 textsize 12
            }
          }
          Fl_Tabs Tabs {
            callback {this->readmixer();
this->mixer->damage();
if (o->value()==tabRecorder)
{
	if (recorder->button_play->value()==0)
	{
		showprogtitle();
	}
}} open
            xywh {-5 25 1600 485}
            code0 {o->value(tabDrive);}
          } {
            Fl_Group tabDrive {
              label Drive open
              xywh {0 45 605 465} box UP_BOX color 52 labelfont 1 labelsize 12 align 5 hide
            } {
              Fl_Choice drivename {
                label {Drive name:}
                xywh {155 80 440 20} down_box BORDER_BOX labelsize 12 textsize 12
              } {}
              Fl_Output fsversion {
                label {FS version:}
                xywh {305 105 50 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Output number_of_projects {
                label {Number of projects:}
                xywh {155 105 70 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Button rename_drive {
                label {Rename...}
                callback {if (currenthd24==NULL) return;
dialog_rename* ui_rename;
ui_rename=new dialog_rename();
string* currname=currenthd24->volumename();
string* strname=new string("Rename project");
Fl_Window* win=ui_rename->make_window(currname,strname);
if (strname!=NULL) 
{ 
 	delete strname;
}
if (currname!=NULL)
{	
	delete currname;
}
win->end();
win->show();

while (win->visible()) { Fl::wait(); }
if (ui_rename->buttonclicked==1) 
{
  // OK clicked
  if (confirm("Do you wish to write the changes to disk?")) {
        currenthd24->setvolumename(*(ui_rename->itemname));
  	currenthd24->savedriveinfo();
	populate_drivelist(1+drivename->value());
	drivename->redraw();
  }  
}
delete ui_rename;
ui_refresh("ren proj");}
                xywh {510 105 85 20} labelsize 12 align 16
              }
              Fl_Output freespace {
                label {Free space preview:}
                xywh {155 130 140 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Choice atrate {
                label {at }
                callback {calcspace();} open
                xywh {320 130 85 20} down_box BORDER_BOX labelsize 12 textsize 12
                code0 {o->value(0);}
              } {
                MenuItem {} {
                  label 44100
                  xywh {5 5 100 20} value 1 labelsize 12
                }
                MenuItem {} {
                  label 48000
                  xywh {15 15 100 20} value 1 labelsize 12
                }
                MenuItem {} {
                  label 88200
                  xywh {25 25 100 20} value 1 labelsize 12
                }
                MenuItem {} {
                  label 96000
                  xywh {35 35 100 20} value 1 labelsize 12
                }
              }
              Fl_Choice attracks {
                label {Hz, }
                callback {calcspace();} open
                xywh {435 130 75 20} down_box BORDER_BOX labelsize 12 textsize 12
                code0 {o->value(5);}
              } {
                MenuItem {} {
                  label 2
                  xywh {15 15 100 20} value 1 labelsize 12
                }
                MenuItem {} {
                  label 6
                  xywh {25 25 100 20} value 1 labelsize 12
                }
                MenuItem {} {
                  label 8
                  xywh {35 35 100 20} value 1 labelsize 12
                }
                MenuItem {} {
                  label 12
                  xywh {45 45 100 20} value 1 labelsize 12
                }
                MenuItem {} {
                  label 16
                  xywh {55 55 100 20} value 1 labelsize 12
                }
                MenuItem {} {
                  label 24
                  xywh {65 65 100 20} value 1 labelsize 12
                }
              }
              Fl_Box {} {
                label tracks
                xywh {510 130 55 20} labelsize 12 align 20
              }
              Fl_Group {} {open
                xywh {25 70 15 15}
              } {}
              Fl_Box {} {
                label {Drive information}
                xywh {0 58 5 17} labelfont 1 labelsize 12 align 8
              }
              Fl_Text_Display catalog {
                label {Drive contents}
                xywh {5 190 595 310} box DOWN_BOX labelfont 1 labelsize 12 align 5 textfont 4 textsize 12
                code0 {if (catalogbuffer==NULL) catalogbuffer=new Fl_Text_Buffer(); string* cat=new string("\\n"); catalogbuffer->append(cat->c_str()); delete cat;}
                code1 {o->buffer(catalogbuffer); o->scrollbar_align(FL_ALIGN_RIGHT);}
              }
              Fl_Button format_driveimage {
                label Format
                callback {bool wantformat=confirm("This will COMPLETELY ERASE\\nALL projects and songs on this drive.\\nAre you SURE you want to format the current drive?\\n");
if (!wantformat) return;
// Okay, user is absolutely sure.
currenthd24->write_enable();
currenthd24->quickformat(NULL);
// there's no point in re-enabling write 
// protection again now, is there?
ui_refresh("format");
setstatus("Format complete.");
return;}
                xywh {455 105 55 20} labelsize 12 align 16
              }
              Fl_Button create_driveimage {
                label {New Image...}
                callback {dialog_filesize* ui_filesize;
ui_filesize=new dialog_filesize();
Fl_Window *win=ui_filesize->make_window();
win->end();
win->show();

while (win->visible()) { Fl::wait(); }
__uint32 lastsector=0;

if (ui_filesize->buttonclicked!=1) 
{
	delete ui_filesize;
	return;
}

lastsector=ui_filesize->lastsector;
delete ui_filesize;

string* driveimgdir=new string("");
*driveimgdir+=*hd24utils::getlastdir("driveimagedir");

Fl_Native_File_Chooser chooser;
chooser.filter("Drive Images\\t*.{img,bin,h24,hd24}\\0");
chooser.title("Create empty drive image in file");
chooser.directory(driveimgdir->c_str());
chooser.options(Fl_Native_File_Chooser::NEW_FOLDER);
chooser.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);

switch (chooser.show()) {
	case -1: break; //error
	case 1: break; //cancel
	default:
		// save header to chooser.filename()

		bool bFileexists=hd24utils::fileExists(chooser.filename());
		if (bFileexists) {
			bool choice=confirm(
				"A file with this name already exists. Do you wish to overwrite it?"
				);			
			if (!(choice)) return;
		}
		string* strfile=new string(chooser.filename());
		//cout << "filename = " << *strfile << endl;
		string* fpath=new string("");
		*fpath+=strfile->substr(0,strlen(strfile->c_str())-strlen(fl_filename_name(strfile->c_str())));
		hd24utils::setlastdir("driveimagedir",fpath->c_str());
		this->transfer_cancel=0;
		this->mustdispsavemessage=true;
		Fl::add_timeout(.25,savemessage_callback,this);
//		__uint32 lastsector=2097151; // 1 GiB
		int result=hd24utils::newdriveimage(strfile,lastsector,&this->savemessage[0],&this->transfer_cancel);

		this->mustdispsavemessage=false;
		setstatus("Done.");
		if (result==0) {
			setstatus("Done.");
			int wantopen=confirm("Drive image created successfully.\\nDo you want to open it now?");
			if (wantopen==1)
			{
       				string* idir=hd24utils::getlastdir("driveimagedir"); 
				hd24fs* sysob=new hd24fs(idir->c_str(),hd24fs::MODE_RDWR,strfile,false);
				delete idir;
				if (currenthd24!=NULL) 
				{
					currenthd24->~hd24fs();
				}
				if (defaulthd24!=NULL) 
				{
					if (defaulthd24!=currenthd24)
					{
						defaulthd24->~hd24fs();
					}

				}
				currenthd24=sysob;
				defaulthd24=sysob;
			}
			
		} else {
			fl_message("Could not write drive image to file. Access denied? Disk full?");	
		}
		delete strfile;		
		break;
}
setstatus("Done.");
ui_refresh("newdriveimage");
delete driveimgdir;}
                xywh {360 105 95 20} labelsize 12 align 16
              }
              Fl_Box {} {
                label {Songs marked * are write-protected.}
                xywh {235 175 365 15} labelfont 2 labelsize 12 align 24
              }
            }
            Fl_Group songinfogroup {
              label {Project/Song}
              xywh {0 50 605 460} box UP_BOX color 52 labelfont 1 labelsize 12 align 5 hide
            } {
              Fl_Choice songname {
                label {Song name:} open
                xywh {155 155 440 20} down_box BORDER_BOX labelsize 12 textsize 12
              } {}
              Fl_Output number_of_tracks {
                label {Number of tracks:}
                xywh {155 180 90 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Output sample_rate {
                label {Sample rate:}
                callback {if (currsong==NULL) return;
bool confirmrate=false;
if (strcmp(o->value(),"44100")==0) {
	o->value("48000");
	currsong->samplerate(48000);
	if (mixer!=NULL) mixer->control->samplerate(48000);
	confirmrate=confirm("Re-stamp song as 48000Hz on disk?");
} else {
	if (strcmp(o->value(),"48000")==0) {
		o->value("44100");
		currsong->samplerate(44100);
		if (mixer!=NULL) mixer->control->samplerate(44100);
		confirmrate=confirm("Re-stamp song as 44100Hz on disk?");
	}
}
if (strcmp(o->value(),"88200")==0) {
	o->value("96000");
	currsong->samplerate(96000);
	if (mixer!=NULL) mixer->control->samplerate(48000);
	confirmrate=confirm("Re-stamp song as 96000Hz on disk?");
} else {
	if (strcmp(o->value(),"96000")==0) {
		o->value("88200");
		if (mixer!=NULL) mixer->control->samplerate(44100);
		confirmrate=confirm("Re-stamp song as 88200Hz on disk?");
	}
}

  if (confirmrate) {
//	currsong->songname(*(ui_rename->itemname));
  	currsong->save();
  	populate_songlist(songname->value());
  } else {



if (strcmp(o->value(),"44100")==0) {
	o->value("48000");
	currsong->samplerate(48000);
	if (mixer!=NULL) mixer->control->samplerate(48000);
} else {
	if (strcmp(o->value(),"48000")==0) {
		o->value("44100");
		currsong->samplerate(44100);
		if (mixer!=NULL) mixer->control->samplerate(44100);
	}
}
if (strcmp(o->value(),"88200")==0) {
	o->value("96000");
	currsong->samplerate(96000);
	if (mixer!=NULL) mixer->control->samplerate(48000);
} else {
	if (strcmp(o->value(),"96000")==0) {
		o->value("88200");
		currsong->samplerate(88200);
		if (mixer!=NULL) mixer->control->samplerate(44100);
	}
}


  }
ui_refresh("stamprate");}
                xywh {155 230 90 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Output bitdepth {
                label {Bit depth:}
                xywh {155 255 90 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Output duration {
                label {Duration:}
                xywh {155 205 90 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Button rename_song {
                label {Rename...}
                callback {if (currsong==NULL) return;
dialog_rename* ui_rename;
ui_rename=new dialog_rename();
string* currname=currsong->songname();
string* strsong=new string("Rename song");
Fl_Window* win=ui_rename->make_window(currname,strsong);
delete strsong;
win->end();
win->show();

while (win->visible()) { Fl::wait(); }
if (ui_rename->buttonclicked==1) 
{
  // OK clicked
  if (confirm("Do you wish to write the changes to disk?")) {
	currsong->songname(*(ui_rename->itemname));
  	currsong->save();
	populate_songlist(songname->value());
  }
}

delete ui_rename;
ui_refresh("rename song");}
                xywh {510 180 85 20} labelsize 12 align 16
              }
              Fl_Choice locatepoints {
                label {Locate points:}
                callback {setlocbuttonlabel(locatepoints->value());
if ((locatepoints->value())==25) {
button_setlocatepoint->deactivate();
} else {
button_setlocatepoint->activate();
}} open
                xywh {155 280 215 20} down_box BORDER_BOX labelsize 12 textsize 12 deactivate
              } {}
              Fl_Button button_setlocatepoint {
                label {Edit...}
                callback {if (currsong==NULL) return;
dialog_setlocate* ui_setlocate;
ui_setlocate=new dialog_setlocate;
int currlocchoice=locatepoints->value();
Fl_Window *win=ui_setlocate->make_window(currsong,locatepoints->value());
win->end();
win->show();

while (win->visible()) { Fl::wait(); }

/* Dialog has closed, read the results */

populate_locatepoints(currsong,locatepoints);
locatepoints->value(currlocchoice);

if (ui_setlocate->useasrange==1) {
   if (currlocchoice==1) 
   {
	choice_startloc=1;	
   }
   if (currlocchoice==2) 
   {
   	choice_endloc=2;
   }
}
currsong->save();
	
update_fromto();
delete ui_setlocate;}
                xywh {370 280 60 20} labelsize 12 align 16 deactivate
              }
              Fl_Check_Button writeprotected {
                label {Write protected}
                callback {if (currsong==NULL) return;
bool confirmprot=false;
if (o->value()==0) {
	currsong->setwriteprotected(false);
	confirmprot=confirm("Write-enable song on disk?");
} else {
	if (o->value()==1) {
		currsong->setwriteprotected(true);
		confirmprot=confirm("Write-protect song on disk?");
	}
}

if (confirmprot) {
	currsong->save();
        populate_songlist(songname->value());
} else {
	if (o->value()==0) {
		o->value(1);
	} else {
		o->value(0);
	}
}
ui_refresh("writeprot");}
                xywh {155 300 20 25} down_box DOWN_BOX labelsize 12 align 8
              }
              Fl_Button button_golocatepoint {
                label Go
                callback {if (currsong==NULL) return;
if (recorder==NULL) return;
recorder->control->hd24_transport_goloc(currsong->getlocatepos(locatepoints->value()));}
                xywh {435 280 155 20} labelsize 12 align 16
              }
              Fl_Output number_of_songs {
                label {Number of songs:}
                xywh {155 105 85 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Choice projectname {
                label {Project name:} open
                xywh {155 80 440 20} down_box BORDER_BOX labelsize 12 textsize 12
              } {}
              Fl_Button rename_project {
                label {Rename...}
                callback {if (currproj==NULL) return;
dialog_rename* ui_rename;
ui_rename=new dialog_rename();

string* currname=currproj->projectname();
string* strproject=new string("Rename project");
Fl_Window* win=ui_rename->make_window(currname,strproject);
if (strproject!=NULL) 
{ 
 	delete strproject;
}
win->end();
win->show();

while (win->visible()) { Fl::wait(); }
if (ui_rename->buttonclicked==1) 
{
  // OK clicked
  if (confirm("Do you wish to write the changes to disk?")) {
	currproj->projectname(*(ui_rename->itemname));
  	currproj->save();
	populate_projectlist(1+projectname->value());
  }  
  

  
  
}
delete ui_rename;
ui_refresh("ren proj 2");}
                xywh {510 105 85 20} labelsize 12 align 16
              }
              Fl_Box {} {
                label {Project information}
                xywh {0 58 5 17} labelfont 1 labelsize 12 align 8
              }
              Fl_Box {} {
                label {Song information}
                xywh {0 138 5 17} labelfont 1 labelsize 12 align 8
              }
              Fl_Output song_messages_label {
                label {Recovery messages:}
                xywh {155 325 10 20} type Multiline labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Output song_messages {
                xywh {155 325 440 40} type Multiline labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Button delete_project {
                label Delete
                callback {bool wantdel=confirm("Are you sure you want to delete this project, all songs in it and their recorded audio?\\nThis operation cannot be undone!");
if (!wantdel) return;
__sint32 projtodel=currproj->projectid();
__uint32 result=currenthd24->deleteproject(projtodel);
result++; result--; // ignore for now
ui_refresh("del proj");}
                xywh {455 105 55 20} labelsize 12 align 16
              }
              Fl_Button delete_song {
                label Delete
                callback {if (currproj==NULL) return;
if (currsong==NULL) return;

bool wantdel=confirm("Are you sure you want to delete this song and its recorded audio?\\nThis operation cannot be undone!");
if (!wantdel) return;
__uint32 songtodel=currsong->songid();
__uint32 result=currproj->deletesong(songtodel);
result++; result--; //ignore for now
ui_refresh("del song");}
                xywh {455 180 55 20} labelsize 12 align 16
              }
              Fl_Button create_project {
                label {New Project...}
                callback {if (currenthd24==NULL) {
	fl_message("No drive is currently selected.");
	return;
}

if (currenthd24->projectcount() == currenthd24->maxprojects()) 
{
	fl_message("Cannot create project.\\nThe maximum number of projects is already in use!");
	return;
}
// - check if current project is NULL
// - check if there's song space left in it
dialog_newproject* ui_newproject;
ui_newproject=new dialog_newproject();
Fl_Window *win=ui_newproject->make_window();
win->end();
win->show();

while (win->visible()) { Fl::wait(); }

if (ui_newproject->buttonclicked!=1) 
{
	delete ui_newproject;
	return;
}
char projname[65];
for (int i=0;i<65;i++) {
	projname[i]=0;
}
hd24project* newproj=currenthd24->createproject(
(const char*)strncpy(projname,ui_newproject->projectname,64)
);
if (newproj==NULL) 
{
    fl_message("Could not create the project. Access denied?");
    delete ui_newproject;
    return;    
}

//if (ui_newsong->buttonclicked==1) {
//	lastsector=ui_filesize->lastsector;
//} 
ui_refresh("createproj");
delete ui_newproject;}
                xywh {360 105 95 20} labelsize 12 align 16
              }
              Fl_Button create_song {
                label {New Song...}
                callback {if (currenthd24==NULL) {
	fl_message("No drive is currently selected.");
	return;
}

if (currproj==NULL) {
	fl_message("No project is currently selected.");
	return;	
}

if (currproj->songcount() == currproj->maxsongs()) 
{
	fl_message("Cannot create song.\\nThe maximum number of songs is already in use!");
	return;	
}
savemessage[0]='\\0';
transfer_cancel=0;

this->mustdispsavemessage=true;
Fl::add_timeout(0,savemessage_callback,this);

dialog_newsong* ui_newsong;
ui_newsong=new dialog_newsong();
Fl_Window *win=ui_newsong->make_window();
win->end();
win->show();



while (win->visible()) { Fl::wait(); }



//__uint32 lastsector=0;

if (ui_newsong->buttonclicked!=1) 
{
	mustdispsavemessage=false;
	transfer_cancel=1;	
	delete ui_newsong;
	return;
}

char songname[65];
for (int i=0;i<65;i++) {
	songname[i]=0;
}
hd24song* newsong=currproj->createsong(
(const char*)strncpy(songname,ui_newsong->songname,64),ui_newsong->trackcount,ui_newsong->samplerate
);


if (newsong==NULL) 
{
    fl_message("Could not create the song. Access denied?");
	mustdispsavemessage=false;
	transfer_cancel=1;    
    delete ui_newsong;
    return;    
}
__uint32 samlen=ui_newsong->songlength_in_samples;
win->~Fl_Window();
delete ui_newsong;
// optionally, lengthen song to specified size.
if (samlen>0) {
	setstatus("Lengthening song... ");
	
		
\#if (HD24DEBUG==1) 
	cout << "about to start lengthening song to maxlen=" << samlen << endl;
\#endif
	bool clearnew=true; // clear lengthened part

	__uint32 translen=newsong->songlength_in_samples(samlen,clearnew,&this->savemessage[0],&this->transfer_cancel,Fl::check); 


\#if (HD24DEBUG==1) 
	cout << "verifying actual song length " << endl;
	cout << "new len=" << translen << endl;
\#endif
	if (translen!=samlen) 
	{
\#if (HD24DEBUG==1) 
		
		cout << "new len<> maxlen so not enough space." << endl;
\#endif
		if (transfer_cancel==0)
		{
			fl_message("Not enough space on HD24 drive.");
		} else
		{
			fl_message("Song lengthening cancelled by user.");
		}
		return;
	}
	newsong->save(); 

\#if (HD24DEBUG==1) 
cout << "translen is now " << translen << endl;
\#endif
}
stop_transfer->hide();	
this->mustdispsavemessage=false;	
delete newsong; // ui refresh will pick it up as currsong.
ui_refresh("newsong");
setstatus("Ready.");
return;}
                xywh {360 180 95 20} labelsize 12 align 16
              }
              Fl_Box {} {
                label Hz
                xywh {245 230 19 20} labelsize 12 align 20
              }
              Fl_Box {} {
                label {hours:minutes:seconds.frames}
                xywh {245 205 195 20} labelsize 12 align 20
              }
            }
            Fl_Group tabRecorder {
              label Recorder open
              xywh {-5 46 620 464} color 52 labelfont 1 labelsize 12 hide
            } {
              Fl_Group recorder {open
                xywh {-5 49 610 457} color 53 selection_color 53 align 0
                code0 {o->set_ui(this);}
                code1 {o->control->audiolib(AUDIOLIB_PORTAUDIO,(void*)(this->portaudio));}
                code2 {o->control->audiolib(AUDIOLIB_JACK,(void*)(this->libjack));}
                code3 {o->control->audiolib(AUDIOLIB_SNDFILE,(void*)(this->soundfile));}
                class RecorderUI
              } {}
            }
            Fl_Group tabMixer {
              label Mixer open
              xywh {0 45 605 463} color 52 labelfont 1 labelsize 12 hide
            } {
              Fl_Group mixer {open
                xywh {0 49 605 456} color 53 selection_color 53 align 0
                code0 {o->set_ui(this);}
                class MixerUI
              } {}
            }
            Fl_Group tabCopyToPC {
              label {Copy to PC} open
              xywh {5 50 600 455} color 52 labelfont 1 labelsize 12 hide
            } {
              Fl_Check_Button {} {
                xywh {85 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[0]=o;}
              }
              Fl_Check_Button {} {
                xywh {105 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[1]=o;}
              }
              Fl_Check_Button {} {
                xywh {125 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[2]=o;}
              }
              Fl_Check_Button {} {
                xywh {145 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[3]=o;}
              }
              Fl_Check_Button {} {
                xywh {165 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[4]=o;}
              }
              Fl_Check_Button {} {
                xywh {185 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[5]=o;}
              }
              Fl_Check_Button {} {
                xywh {205 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[6]=o;}
              }
              Fl_Check_Button {} {
                xywh {225 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[7]=o;}
              }
              Fl_Check_Button {} {
                xywh {255 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[8]=o;}
              }
              Fl_Check_Button {} {
                xywh {275 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[9]=o;}
              }
              Fl_Check_Button {} {
                xywh {295 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[10]=o;}
              }
              Fl_Check_Button {} {
                xywh {315 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[11]=o;}
              }
              Fl_Check_Button {} {
                xywh {335 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[12]=o;}
              }
              Fl_Check_Button {} {
                xywh {355 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[13]=o;}
              }
              Fl_Check_Button {} {
                xywh {375 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[14]=o;}
              }
              Fl_Check_Button {} {
                xywh {395 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[15]=o;}
              }
              Fl_Check_Button {} {
                xywh {425 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[16]=o;}
              }
              Fl_Check_Button {} {
                xywh {445 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[17]=o;}
              }
              Fl_Check_Button {} {
                xywh {465 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[18]=o;}
              }
              Fl_Check_Button {} {
                xywh {485 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[19]=o;}
              }
              Fl_Check_Button {} {
                xywh {505 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[20]=o;}
              }
              Fl_Check_Button {} {
                xywh {525 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[21]=o;}
              }
              Fl_Check_Button {} {
                xywh {545 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[22]=o;}
              }
              Fl_Check_Button {} {
                xywh {565 92 20 20} down_box DOWN_BOX value 1 labelsize 12 align 1
                code0 {track[23]=o;}
              }
              Fl_Box {} {
                label {Tracks:}
                xywh {15 79 70 16} box FLAT_BOX color 52 labelsize 12 align 20
              }
              Fl_Button button_invert_tracks {
                label Invert
                callback {int i;
for (i=0; i<MAXCHANNELS; i++) {
   track[i]->value(1-track[i]->value());
}}
                xywh {15 92 65 20} labelsize 12 align 16
              }
              Fl_Box led1 {
                label 01
                xywh {85 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[0]=o;}
              }
              Fl_Box led2 {
                label 02
                xywh {105 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[1]=o;}
              }
              Fl_Box led3 {
                label 03
                xywh {125 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[2]=o;}
              }
              Fl_Box led4 {
                label 04
                xywh {145 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[3]=o;}
              }
              Fl_Box led5 {
                label 05
                xywh {165 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[4]=o;}
              }
              Fl_Box led6 {
                label 06
                xywh {185 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[5]=o;}
              }
              Fl_Box led7 {
                label 07
                xywh {205 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[6]=o;}
              }
              Fl_Box led8 {
                label 08
                xywh {225 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[7]=o;}
              }
              Fl_Box led9 {
                label 09
                xywh {255 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[8]=o;}
              }
              Fl_Box led10 {
                label 10
                xywh {275 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[9]=o;}
              }
              Fl_Box led11 {
                label 11
                xywh {295 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[10]=o;}
              }
              Fl_Box led12 {
                label 12
                xywh {315 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[11]=o;}
              }
              Fl_Box led13 {
                label 13
                xywh {335 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[12]=o;}
              }
              Fl_Box led14 {
                label 14
                xywh {355 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[13]=o;}
              }
              Fl_Box led15 {
                label 15
                xywh {375 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[14]=o;}
              }
              Fl_Box led16 {
                label 16
                xywh {395 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[15]=o;}
              }
              Fl_Box led17 {
                label 17
                xywh {424 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[16]=o;}
              }
              Fl_Box led18 {
                label 18
                xywh {444 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[17]=o;}
              }
              Fl_Box led19 {
                label 19
                xywh {464 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[18]=o;}
              }
              Fl_Box led20 {
                label 20
                xywh {484 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[19]=o;}
              }
              Fl_Box led21 {
                label 21
                xywh {504 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[20]=o;}
              }
              Fl_Box led22 {
                label 22
                xywh {524 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[21]=o;}
              }
              Fl_Box led23 {
                label 23
                xywh {544 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[22]=o;}
              }
              Fl_Box led24 {
                label 24
                xywh {564 80 20 14} box FLAT_BOX color 52 selection_color 0 labelsize 12
                code0 {this->trackled[23]=o;}
              }
              Fl_Button button_transfertopc {
                label Transfer
                callback {recorder->control->button_stop_call();
mustdisplaytimer=false;
__sint64 bytestransferred=0;
transeng->sizelimit(strtoll(sizelimit->value(),0,10));

int bytespersam;
int wantsplit=0;
__uint32 numsongs=1;
double dif;
__sint64 totbytestotransfer=0; 

bool needoverwrite=false;
bool isproblem=false;	
__uint32 channelstotransfer=0;

__uint32 i=0;

transfer_cancel=0;

if (currproj==NULL) 
{
\#if (HD24DEBUG==1) 
	cout << "No current project." << endl;
\#endif			
	return;	
}

/* TODO: DISABLE/ENABLE JACK BEFORE/AFTER TRANSFER */
//jack_client_t* saveclient=jackclient;
//jackclient=NULL;
/* TODO: DISABLE/ENABLE JACK BEFORE/AFTER TRANSFER */

if (!(hd24utils::dirExists(projectdir->value()))) 
{
	fl_message("Project directory no longer exists.\\nPlease select another directory and try again.");
	//jackclient=saveclient;
\#if (HD24DEBUG==1) 
	cout << "project dir no longer exists, transfer cancelled." << endl;
\#endif			
	
	return;
}
transeng->setstatusfunction=HD24UserInterface::transferstatus;
transeng->projectdir(projectdir->value());
transeng->set_ui((void*)this);
transeng->mixer(this->mixer->control);
transeng->soundfile=soundfile;
bool channelwarning=false;
int currfileformat=0;
bool multisong=false;
if (currsong==NULL) 
{
	multisong=true;
}  
else 
{
	// count channels to transfer
	__uint32 channels=currsong->logical_channels();
	for (unsigned int handle=0;handle<channels;handle++) 
	{
		if (track[handle]->value()!=0) 
		{
			channelstotransfer++;
			transeng->trackselected(handle,true);
		} 
		else 
		{
			transeng->trackselected(handle,false);
		}
	}
	
	transeng->mixleft( (transfersource_mixleft->value())==1);
	transeng->mixright( (transfersource_mixright->value()) ==1);

	currfileformat=fileformat->value();
	
	transeng->selectedformat(currfileformat);
	
	if (transeng->format_outputchannels(currfileformat)>1) 
	{
		if ((channelstotransfer%(transeng->format_outputchannels(currfileformat)))!=0) 
		{
			channelwarning=true;
		}
	}
	
} 
	
if (multisong) 
{
	numsongs=currproj->songcount();
}
if (channelwarning) 
{
	string multiple="Number of channels to export must be a multiple of ";
	string* mynum=Convert::int2str(transeng->format_outputchannels(currfileformat));
	multiple+=*mynum;
	if (transeng->format_outputchannels(currfileformat)==2) 
	{
		multiple+="\\nto export to stereo pairs.";
	} else {
		multiple+="\\nfor export to groups of ";
		multiple+=*mynum;
		multiple+=" channels.";
	}
	fl_message("%s",multiple.c_str());
	delete mynum;
/* TODO: DISABLE/ENABLE JACK BEFORE/AFTER TRANSFER */	
//	jackclient=saveclient;


	return;
	
}
if (numsongs==0) 
{
\#if (HD24DEBUG==1) 
	cout << "multisong transfer: no songs in current project." << endl;
\#endif			
	fl_message("Nothing to do!");
/* TODO: DISABLE/ENABLE JACK BEFORE/AFTER TRANSFER */	
//	jackclient=saveclient;

	return;
}
int havedoublesongname=0;
if (multisong && (numsongs>1)) 
{
	// check if any song names are duplicated
	hd24song* s1=NULL;
	hd24song* s2=NULL;
	for (unsigned i=1; i<numsongs; i++) 
	{
		if (s1!=NULL) {
                        delete s1;
                        s1=NULL;
		}
		s1=currproj->getsong(i);
		string* songname1=s1->songname();
		for (unsigned int j=i+1; j<=numsongs; j++) {
			if (s2!=NULL) {
                                delete s2;
                                s2=NULL;
			}
			s2=currproj->getsong(j);
			string* songname2=s2->songname();
			if (*songname1==*songname2) {
				havedoublesongname=1;
			}
			delete songname2;
			if (havedoublesongname==1) break;
		}
		delete songname1;
		if (havedoublesongname==1) break;
	}
	if (s1!=NULL) {
                delete s1;
                s1=NULL;
	}
	if (s2!=NULL) {
                delete s2;
                s2=NULL;
	}
}	
if (havedoublesongname==1) 
{
 if (!confirm(
		"Duplicate song names were detected. If you continue, \\n"
		"exported songs will be prefixed with the song number. \\n\\n"
		"If you prefer to name the songs before export, you will\\n"
		"want to stop now.\\n\\n"
		"Do you wish to continue?"
	)
  ) {
/* TODO: DISABLE/ENABLE JACK BEFORE/AFTER TRANSFER */  
//  	jackclient=saveclient;
	return;	
  };
}
// preparation for the transfers
for (i=1; i<=numsongs; i++) 
{
	if (multisong) 
	{
		if (currsong!=NULL) {
                        delete currsong;
			currsong=NULL;
		}
		currsong=currproj->getsong(i);
		if (currsong!=NULL) 
		{
			channelstotransfer=currsong->logical_channels();
			choice_startloc=0;
			choice_endloc=currsong->locatepointcount();
		}
	}
\#if (HD24DEBUG==1) 
	cout << "channels to transfer=" << channelstotransfer << endl;	
\#endif			
	__uint64 bytestotransfer_perchannel=0;
	__uint64 bytestotransfer_thissong=0;
	transeng->sourcesong(currsong);	
	if (currsong!=NULL)
	{
		bytespersam=(currsong->bitdepth())/8;
		// for kb/sec calculation
		// because of this, double at higher sample rates

		__uint32 samstotrans_thissong;
		if (multisong) 
		{
			samstotrans_thissong=currsong->songlength_in_samples();
			transeng->startoffset(0);
			transeng->endoffset(currsong->songlength_in_samples());
		}
		else
		{
			__uint32 startoffset=0;
			__uint32 endoffset=0;	

			if (choice_startloc!=0) {
				startoffset=currsong->getlocatepos(choice_startloc);
			}
			if (choice_endloc!=0)
			{
				endoffset=currsong->getlocatepos(choice_endloc);
			}
			transeng->startoffset(startoffset);
			transeng->endoffset(endoffset);
			if (endoffset>startoffset) 
			{		
				samstotrans_thissong=endoffset-startoffset;
			} 
			else 
			{
				samstotrans_thissong=startoffset-endoffset;
			}
		}
\#if (HD24DEBUG==1) 	
	cout << "sams to transfer for this song=" << samstotrans_thissong << endl ;
\#endif		
		if (samstotrans_thissong==0xFFFFFFFF)
		{
			bool wanttransfer=confirm(
			"You are trying to transfer the maximum song size possible\\n"
			"(more than twenty hours or 300 Gigabytes of audio). \\n\\n"
			"HD24tools will gladly try to perform this transfer for you,\\n"
			"but it will take VERY LONG, and is probably not very helpful\\n"
			"to you.\\n\\n"
			"If you are currently trying to recover audio, you probably\\n"
			"forgot to set the export range (with the 'Range...' button\\n"
			"above). It is highly recommended to listen to your audio\\n"
			"and set two locate points before setting the export range.\\n\\n"
			"Do you want to perform this long and possibly useless\\n"
			"transfer anyway?");
			if (!(wanttransfer)) return;
		}
		
		bytestotransfer_perchannel=(__sint64)((__sint64)samstotrans_thissong*(__sint64)bytespersam);
		
		// hi-samplerate correction:
		bytestotransfer_perchannel*=(currsong->physical_channels()/currsong->logical_channels());	
		bytestotransfer_thissong=(channelstotransfer*bytestotransfer_perchannel);
		
		totbytestotransfer+=bytestotransfer_thissong;
		
		if (!(needoverwrite)) 
		{
			needoverwrite=anyfilesexist(currsong);
		}			
	}	
		
		
	/* The above number equals 2 giga/4, to bypass format limitations. 
	   For 24-bit samples 2 giga/3 would suffice but some space could 
	   be needed by headers etc. */
	__uint64 MAXBYTES=transeng->sizelimit();
	// max number of samples per giga is half for high samplerate files
	if (multisong)
	{
                delete currsong;
		currsong=NULL;
	}
\#if (HD24DEBUG==1) 	
	cout << "Maxbytes per channel=" << MAXBYTES ;
	cout << "bytes per channel=" << bytestotransfer_perchannel << endl;
\#endif	
	if (bytestotransfer_perchannel>MAXBYTES) 
	{
	        if (wantsplit!=1)
	        {
/*	        
			int choice=fl_choice(
				"Exported audio files may be too large to play or edit. \\nDo you want to export the file as multiple smaller chunks?",
				"Yes","No","Cancel"
				);
			if (choice==2) 
			{
\#if (HD24DEBUG==1) 
				cout << "user cancelled too large file transfer" << endl;
\#endif			
				//jackclient=saveclient;
				return; // cancelled
			}
			if (choice==0) 
			{
				wantsplit=1;
			}
*/
			if (autosplit->value()==1) {
				wantsplit=1;
			}			
		}		
	}
}
if (multisong)
{
	if (currsong!=NULL) {
                delete currsong;
		currsong=NULL;
	}
}

// do we need to overwrite any files? Are we allowed to?
if (needoverwrite) 
{
	isproblem=(!(confirm("One or more output files already exist. Do you want to overwrite them?")));
}

if (isproblem) 
{
\#if (HD24DEBUG==1) 
	cout << "user does not wish to perform needed overwrite." << endl;
\#endif
/* TODO: DISABLE/ENABLE JACK BEFORE/AFTER TRANSFER */
//	jackclient=saveclient;
	return;	
}

// needed to check for dir to make sure about existence of output files
// but the previous question may have given the user the time to mess up.
// check the dir again :)

if (!(hd24utils::dirExists(projectdir->value()))) 
{
	fl_message("Project directory no longer exists.\\nPlease select another directory and try again.");
/* TODO: DISABLE/ENABLE JACK BEFORE/AFTER TRANSFER */	
//	jackclient=saveclient;
\#if (HD24DEBUG==1) 
	cout << "project directory deleted" << endl;
\#endif	
	return;
}	
\#if (HD24DEBUG==1) 
	cout << "by calc, tot bytes to transfer=" << totbytestotransfer << endl;	
\#endif			

deactivate_ui();	
setstatus("Transferring audio to PC... 0%");	
time (&starttime);		
int somethingwrong=0;
for (i=1; i<=numsongs; i++) 
{
\#if (HD24DEBUG==1) 
	cout << "set song" << endl;
\#endif
	if (transfer_cancel!=0) 
	{ 
\#if (HD24DEBUG==1) 
		cout << "transfer cancelled by user." << endl;
\#endif	
		break;
	}

	if (multisong) 
	{
		if (currsong!=NULL) {
                        delete currsong;
			currsong=NULL;
		}
		currsong=currproj->getsong(i);
	}
	transeng->sourcesong(currsong);
	if (currsong==NULL) 
  	{	
\#if (HD24DEBUG==1) 
		cout << "currsong=null, nothing to transfer" << endl;
\#endif
  		continue;
   	}
\#if (HD24DEBUG==1) 
	cout << "calling ftransfer with ";
	cout << "sonnum=" << i;
	cout << ", numsongs=" << numsongs;
	cout << ", totlen(bytes)=" << totbytestotransfer;
	cout << ", bytestransferred=" << bytestransferred;
	cout << ", wantsplit=" << wantsplit << endl;
\#endif

	transeng->prepare_transfer_to_pc(i,numsongs,totbytestotransfer,bytestransferred,wantsplit,(havedoublesongname==1)?(i):(0));
	__sint64 currtransferred=transeng->transfer_to_pc();
	if (currtransferred==0) 
	{
		somethingwrong=1;
		break;
	}
	bytestransferred+=currtransferred;
			
	if (multisong)
	{
                delete currsong;
		currsong=NULL;
	}
	
} 


if (multisong)
{
	if (currsong!=NULL)
	{
                delete currsong;
		currsong=NULL;
	}				
}	

/* TODO: DISABLE/ENABLE JACK BEFORE/AFTER TRANSFER */
//jackclient=saveclient;
if (somethingwrong==1) 
{
	activate_ui();
	if (transeng->lasterror()!=NULL)
	{
		
		setstatus(transeng->lasterror()->c_str());
	}
	else
	{
		setstatus((const char*)&"Unexpected error transferring files.");
	}
	stop_transfer->hide();
	return;		
}

time (&endtime);
dif=difftime(endtime,starttime);
//__uint32 subsecs=(__uint32)(100*(dif-floor(dif)));
dif=floor(dif);
__uint32 minutes=((__uint32)dif-((__uint32)dif%60))/60;
__uint32 seconds=((__uint32)dif%60);

string minsec="Ready. Transfer time: ";
if (transfer_cancel==1) 
{
	minsec="Transfer cancelled. Elapsed transfer time: ";
}
transfer_cancel=0;
string* strmins=Convert::int2str(minutes,2,"0");
minsec+=*strmins;
delete (strmins);
minsec+=":";
string* strsecs=Convert::int2str(seconds,2,"0");
minsec+=*strsecs;
delete(strsecs);

if (dif>=1) 
{
	__uint32 kbps=(__uint32)(((bytestransferred)/1024)/dif);

	minsec+=" (";
	string* strkbps=Convert::int2str(kbps);
	minsec+=*strkbps;
	minsec+=" kB/sec)";
	delete(strkbps);
}
activate_ui();
setstatus(minsec.c_str());
stop_transfer->hide();}
                xywh {530 480 70 20} labelsize 12 align 16
                code0 {o->label("Transfer");}
              }
              Fl_Button {} {
                label {Browse...}
                callback {Fl_Native_File_Chooser chooser;
chooser.title("Select project directory");
chooser.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
chooser.options(Fl_Native_File_Chooser::NEW_FOLDER);
chooser.filter("");

string currdir="";
currdir+=projectdir->value();

chooser.directory(currdir.c_str());
switch (chooser.show()) {
	case -1: break; //error
	case 1: break; //cancel
	default:
		if (chooser.filename()) {
			projectdir->value(chooser.filename());
			hd24utils::setlastdir("projdir",chooser.filename());
		}

		break;
}}
                xywh {505 175 85 20} labelsize 12 align 16
              }
              Fl_Input projectdir {
                label {Project dir:}
                callback {/* callback when release: add a 
   (back)slash to the end of the
   pathname if one is not present. */

\#ifdef WINDOWS
\#define MYSLASH '\\\\'
\#else
\#define MYSLASH '/'
\#endif
char* x=(char*)projectdir->value();
if (strlen(x)==0) {
   x[0]=MYSLASH;
   x[1]=0;
} else {
  int q=strlen(x);
  if (x[q-1]!=MYSLASH) {
     x[q]=MYSLASH;
     x[q+1]=0;
  }
}
projectdir->value(x);
hd24utils::setlastdir("projdir",projectdir->value());}
                xywh {85 175 415 20} labelsize 12 textsize 12
                code0 {getlastprojdir(o);}
                code1 {/*o->clear_visible_focus();*/}
              }
              Fl_Output fromtime {
                label {From:}
                xywh {265 115 105 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Output totime {
                label {To:}
                xywh {395 115 105 20} labelsize 12 textsize 12
                code0 {o->clear_visible_focus();}
              }
              Fl_Button fromto {
                label {Range...}
                callback {if (currsong==NULL) return;
dialog_fromto* ui_fromto;
ui_fromto=new dialog_fromto;

Fl_Window *win=ui_fromto->make_window(currsong);
populate_locatepoints(currsong,ui_fromto->fromloc);
populate_locatepoints(currsong,ui_fromto->toloc);
ui_fromto->fromloc->value(choice_startloc);
ui_fromto->toloc->value(choice_endloc);
win->end();
win->show();

while (win->visible()) { Fl::wait(); }

/* Dialog has closed, read the results */
//if (ui_fromto->buttonclicked==0) 
//{ fl_message("No OK nor Cancel clicked"); }
if (ui_fromto->buttonclicked==1) 
{
	// OK clicked
	choice_startloc=ui_fromto->choice_startloc;
	choice_endloc=ui_fromto->choice_endloc;
	update_fromto();
}
//if (ui_fromto->buttonclicked==2) 
//{ fl_message("Cancel clicked"); }
delete ui_fromto;}
                xywh {505 115 85 20} labelsize 12 align 16
              }
              Fl_Choice fileformat {
                label {File format:} open
                xywh {85 200 160 20} down_box BORDER_BOX labelsize 12 textsize 12
              } {}
              Fl_Check_Button autosplit {
                label {Automatically limit size of exported files}
                callback {if (autosplit->value()==1) {
	sizelimitdropdown->activate();

	if (sizelimitdropdown->value()==6) {
		sizelimit->activate();
	} else {
		sizelimit->deactivate();
	}
} else {
	sizelimitdropdown->deactivate();
	sizelimit->deactivate();
}}
                xywh {10 265 20 20} box FLAT_BOX down_box DOWN_BOX value 1 color 52 labelsize 12 align 8
              }
              Fl_Input sizelimit {
                label bytes
                xywh {425 290 120 20} labelsize 12 align 8 textsize 12
                code0 {long long x=1073741824LL; string* sval=Convert::int64tostr(x); o->value(sval->c_str()); delete sval; o->deactivate();}
                code1 {o->maximum_size(17);}
              }
              Fl_Box {} {
                label {Transfer target:}
                xywh {10 153 305 17} box FLAT_BOX color 52 labelfont 1 labelsize 12 align 20
              }
              Fl_Box {} {
                label {Transfer options:}
                xywh {10 243 305 17} box FLAT_BOX color 52 labelfont 1 labelsize 12 align 20
              }
              Fl_Box {} {
                label {Note: The actual file size will be a rough approximation of the requested split size.}
                xywh {30 318 550 17} box FLAT_BOX color 52 labelfont 2 labelsize 12 align 20
              }
              Fl_Check_Button customrate {
                label {Stamp files with a custom sample rate}
                callback {if (customrate->value()==1) {
	ratechoice->activate();
	if (ratechoice->value()==4) {
		stamprate->activate();	
	} else {
		stamprate->deactivate();	
	}
} else {
	ratechoice->deactivate();
	stamprate->deactivate();	
}}
                xywh {10 345 20 20} box FLAT_BOX down_box DOWN_BOX color 52 labelsize 12 align 8
              }
              Fl_Choice ratechoice {
                label {Sample rate:} open
                xywh {105 370 295 20} down_box BORDER_BOX labelsize 12 textsize 12 deactivate
                code0 {o->value(1);}
              } {
                MenuItem {} {
                  label {44100 Hz}
                  callback {long long x=44100LL;
string* sval=Convert::int64tostr(x);
stamprate->value(sval->c_str());
delete sval;
stamprate->deactivate();}
                  xywh {25 25 36 21} labelsize 12
                }
                MenuItem {} {
                  label {48000 Hz}
                  callback {long long x=48000LL;
string* sval=Convert::int64tostr(x);
stamprate->value(sval->c_str());
delete sval;
stamprate->deactivate();}
                  xywh {35 35 36 21} labelsize 12
                }
                MenuItem {} {
                  label {88200 Hz}
                  callback {long long x=88200LL;
string* sval=Convert::int64tostr(x);
stamprate->value(sval->c_str());
delete sval;
stamprate->deactivate();}
                  xywh {45 45 36 21} labelsize 12
                }
                MenuItem {} {
                  label {96000 Hz}
                  callback {long long x=96000LL;
string* sval=Convert::int64tostr(x);
stamprate->value(sval->c_str());
delete sval;
stamprate->deactivate();}
                  xywh {55 55 36 21} labelsize 12
                }
                MenuItem {} {
                  label {User defined, specify -->}
                  callback {stamprate->activate();}
                  xywh {85 85 36 21} labelsize 12
                }
              }
              Fl_Input stamprate {
                label Hz
                xywh {425 370 120 20} labelsize 12 align 8 textsize 12 deactivate
                code0 {long long x=48000; string* sval=Convert::int64tostr(x); o->value(sval->c_str()); delete sval; o->deactivate();}
                code1 {o->maximum_size(5);}
              }
              Fl_Choice sizelimitdropdown {
                label {Split every:} open
                tooltip 1 xywh {105 290 295 20} down_box BORDER_BOX labelsize 12 textsize 12
                code0 {o->value(2);}
              } {
                MenuItem {} {
                  label {650 MB (74 minute CD)}
                  callback {long long x=650000000LL;
string* sval=Convert::int64tostr(x);
sizelimit->value(sval->c_str());
delete sval;
sizelimit->deactivate();}
                  xywh {20 20 36 21} labelsize 12
                }
                MenuItem {} {
                  label {700 MB (80 minute CD)}
                  callback {long long x=700000000LL;
string* sval=Convert::int64tostr(x);
sizelimit->value(sval->c_str());
delete sval;
sizelimit->deactivate();}
                  xywh {30 30 36 21} labelsize 12
                }
                MenuItem {} {
                  label {1 GiB (Recommended for wave editors)}
                  callback {long long x=1073741824LL;
string* sval=Convert::int64tostr(x);
sizelimit->value(sval->c_str());
delete sval;
sizelimit->deactivate();}
                  xywh {40 40 36 21} labelsize 12
                }
                MenuItem {} {
                  label {2 GiB (Max. legal WAV size)}
                  callback {long long x=2147483648LL;
string* sval=Convert::int64tostr(x);
sizelimit->value(sval->c_str());
delete sval;
sizelimit->deactivate();}
                  xywh {50 50 36 21} labelsize 12
                }
                MenuItem {} {
                  label {4 GiB (Max. 32-bit limit)}
                  callback {long long x=4294967296LL;
string* sval=Convert::int64tostr(x);
sizelimit->value(sval->c_str());
delete sval;
sizelimit->deactivate();}
                  xywh {60 60 36 21} labelsize 12
                }
                MenuItem {} {
                  label {4.7 GB (DVD size)}
                  callback {long long x=4700000000LL;
string* sval=Convert::int64tostr(x);
sizelimit->value(sval->c_str());
delete sval;
sizelimit->deactivate();}
                  xywh {70 70 36 21} labelsize 12
                }
                MenuItem {} {
                  label {User defined, specify -->}
                  callback {sizelimit->activate();}
                  xywh {80 80 36 21} labelsize 12
                }
              }
              Fl_Check_Button transfersource_mixleft {
                label {Mixer Left}
                callback {saverestoretrackselection(o);}
                xywh {85 115 20 20} down_box DOWN_BOX labelsize 12 align 4
              }
              Fl_Check_Button transfersource_mixright {
                label Right
                callback {saverestoretrackselection(o);}
                xywh {105 115 20 20} down_box DOWN_BOX labelsize 12 align 8
              }
              Fl_Group batch_stuff {
                label {batch stuff } open
                xywh {5 390 600 115} align 16 hide deactivate
              } {
                Fl_Box {} {
                  label {Batch transfer list:}
                  xywh {10 393 305 17} box FLAT_BOX color 52 labelfont 1 labelsize 12 align 20 deactivate
                }
                Fl_Output transfer_list {
                  xywh {10 410 515 90} type Multiline labelsize 12 textsize 12 deactivate
                  code0 {o->clear_visible_focus();}
                }
                Fl_Button button_addtobatch {
                  label {To Batch}
                  xywh {530 410 70 20} labelsize 12 align 16 deactivate
                }
                Fl_Button button_removefrombatch {
                  label Remove
                  xywh {530 430 70 20} labelsize 12 align 16 deactivate
                }
              }
              Fl_Output transfersource {
                label {Transfer source:}
                xywh {127 57 458 20} box NO_BOX labelfont 1 labelsize 12 textsize 12
              }
              Fl_Button {} {
                label {?}
                callback {fl_message("This option allows you to limit the size of exported files. \\n"
"In the dropdown box, the following units are used:\\n\\n"
"MB - Megabyte, 1000x1000 bytes\\n"
"GB - Gigabyte, 1000x1000x1000 bytes\\n"
"GiB - Binary Gigabyte or Gibibyte, 1024x1024x1024 bytes\\n\\n"
"In any situation, the actual byte count is displayed on the right.");}
                tooltip {Click here for an explanation about file splitting.} xywh {400 290 20 20} box FLAT_BOX down_box FLAT_BOX color 15 selection_color 15 labelfont 1 labelsize 11 labelcolor 7
              }
              Fl_Button {} {
                label {?}
                callback {fl_message("Stamping files with another sample rates allows you \\n"
"to export files with a sample rate that differs from the sample \\n"
"rate at which the song was recorded. When using this option, \\n"
"note that no resampling takes place; both the pitch and playback \\n"
"speed will change compared to the original sample rate. ");}
                tooltip {Click here for an explanation about sample rate stamping} xywh {400 370 20 20} box FLAT_BOX down_box FLAT_BOX color 15 selection_color 15 labelfont 1 labelsize 11 labelcolor 7
              }
            }
            Fl_Group tab_tohd24 {
              label {Copy to HD24} open
              xywh {0 45 605 461} color 52 labelfont 1 labelsize 12
            } {
              Fl_Button button_transfertohd24 {
                label Transfer
                callback {recorder->control->button_stop_call(); //stop transport
bool have_smpte=false;
if (currproj==NULL) 
{
	fl_message("No project selected, nothing to do!\\nSelect a project on the Project/Song tab and try again.");
	return;	
}
if (currsong==NULL) 
{
	fl_message("No song selected, nothing to do!\\nSelect a song on the Project/Song tab and try again.");
	return;
}

int havefiles=0;
for (unsigned int ch=1;ch<=currsong->logical_channels();ch++) {

	if (strlen(filename[ch-1]->value())>0) {
		// track has a file selected
		havefiles=1;
		currsong->trackarmed(ch,true);
		continue;
	}
	int action=((Fl_Choice*)(trackaction[ch-1]))->value();
	if (action==0) { /* 0=ERASE */
		// track action says 'erase'
		havefiles=1;
		currsong->trackarmed(ch,true);	
		continue;
	} 
	if (action==1) { /* 1=SMPTE */
		// track action says 'stripe with SMPTE/LTC'
		havefiles=1;
		have_smpte=true;
		currsong->trackarmed(ch,true);	
		continue;
	} 
	// no file, no timecode stripe and no erase, keep track.
	currsong->trackarmed(ch,false);	
	
}
if (havefiles==0) {
	fl_message(
		"To transfer files to the HD24, load one or more files.\\n"
		"Each file will be assigned to an empty track slot.\\n\\n"
		"Before transferring, you will be able to rearrange the\\n"
		"order of the tracks by clicking on one or more tracks\\n"
		"and clicking the up or down arrow buttons.\\n\\n"
		"When a track slot is empty, the existing track will be\\n"
		"preserved, unless 'Erase' or 'SMPTE' is selected on \\n"
		"the right of the track.\\n\\n"
		"When a file to transfer contains multiple tracks, you\\n"
                "can choose to mixdown the file to mono (the default), \\n"
                "or you can select the track that you want to transfer \\n"
                "to the HD24 drive." 
	);
	for (unsigned int ch=1;ch<=currsong->logical_channels();ch++) {
		currsong->trackarmed(ch,false);	
	}
	return;
}
if (currsong->iswriteprotected())
{
	fl_message("The song is write protected.");
	for (unsigned int ch=1;ch<=currsong->logical_channels();ch++) {
		currsong->trackarmed(ch,false);
	}
	return;
}
// ask ARE YOU SURE????
bool sure=confirm("Are you sure you want to overwrite the existing audio?");
if (!sure) return;

// check if all files still exist

int filemissing=0;
for (unsigned int misscheck=1;misscheck<=currsong->logical_channels();misscheck++) {
	if (strlen(filename[misscheck-1]->value())==0) continue;	
	if (!(hd24utils::fileExists(filename[misscheck-1]->value()))) 
	{
		filemissing=1;
		break;
	}	
}

if (filemissing==1) {
	fl_message("One or more files no longer exist. \\nPlease clear and reload the files, then try again.");
	return;
}
// end of checking if all files still exist
transeng->targetsong(currsong);
transeng->soundfile=soundfile;
for (unsigned int filenum=1;filenum<=currsong->logical_channels();filenum++) 
{
    transeng->sourcefilename(filenum,filename[filenum-1]->value());
    transeng->trackaction(filenum,((Fl_Choice*)(trackaction[filenum-1]))->value());
}
transeng->transfer_to_hd24();
stop_transfer->hide();
if (transeng->lasterror()!=NULL)
{
    if (transeng->lasterror()->c_str()!=NULL)
    {
	    setstatus(transeng->lasterror()->c_str());
    }
    else 
    {
        setstatus("Done. No error messages.");
    }	 
} else {
    setstatus("Done.");
}
ui_refresh("tohd24_done");
activate_ui();	
fl_check();} selected
                xywh {530 480 70 20} labelsize 12
              }
              Fl_Output filename1 {
                label {01  }
                callback {selectfilename(1);}
                xywh {40 50 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[0]=o;}
              }
              Fl_Output filename2 {
                label {02  }
                callback {selectfilename(2);}
                xywh {40 69 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[1]=o;}
              }
              Fl_Output filename3 {
                label {03  }
                callback {selectfilename(3);}
                xywh {40 88 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[2]=o;}
              }
              Fl_Output filename4 {
                label {04  }
                callback {selectfilename(4);}
                xywh {40 107 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[3]=o;}
              }
              Fl_Output filename5 {
                label {05  }
                callback {selectfilename(5);}
                xywh {40 126 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[4]=o;}
              }
              Fl_Output filename6 {
                label {06  }
                callback {selectfilename(6);}
                xywh {40 145 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[5]=o;}
              }
              Fl_Output filename7 {
                label {07  }
                callback {selectfilename(7);}
                xywh {40 164 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[6]=o;}
              }
              Fl_Output filename8 {
                label {08  }
                callback {selectfilename(8);}
                xywh {40 183 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[7]=o;}
              }
              Fl_Output filename9 {
                label {09  }
                callback {selectfilename(9);}
                xywh {40 202 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[8]=o;}
              }
              Fl_Output filename10 {
                label {10  }
                callback {selectfilename(10);}
                xywh {40 221 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[9]=o;}
              }
              Fl_Output filename11 {
                label {11  }
                callback {selectfilename(11);}
                xywh {40 240 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[10]=o;}
              }
              Fl_Output filename12 {
                label {12  }
                callback {selectfilename(12);}
                xywh {40 259 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[11]=o;}
              }
              Fl_Output filename13 {
                label {13  }
                callback {selectfilename(13);}
                xywh {40 278 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[12]=o;}
              }
              Fl_Output filename14 {
                label {14  }
                callback {selectfilename(14);}
                xywh {40 297 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[13]=o;}
              }
              Fl_Output filename15 {
                label {15  }
                callback {selectfilename(15);}
                xywh {40 316 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[14]=o;}
              }
              Fl_Output filename16 {
                label {16  }
                callback {selectfilename(16);}
                xywh {40 335 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[15]=o;}
              }
              Fl_Output filename17 {
                label {17  }
                callback {selectfilename(17);}
                xywh {40 354 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[16]=o;}
              }
              Fl_Output filename18 {
                label {18  }
                callback {selectfilename(18);}
                xywh {40 373 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[17]=o;}
              }
              Fl_Output filename19 {
                label {19  }
                callback {selectfilename(19);}
                xywh {40 392 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[18]=o;}
              }
              Fl_Output filename20 {
                label {20  }
                callback {selectfilename(20);}
                xywh {40 411 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[19]=o;}
              }
              Fl_Output filename21 {
                label {21  }
                callback {selectfilename(21);}
                xywh {40 430 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[20]=o;}
              }
              Fl_Output filename22 {
                label {22  }
                callback {selectfilename(22);}
                xywh {40 449 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[21]=o;}
              }
              Fl_Output filename23 {
                label {23  }
                callback {selectfilename(23);}
                xywh {40 468 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[22]=o;}
              }
              Fl_Output filename24 {
                label {24  }
                callback {selectfilename(24);}
                xywh {40 487 430 19} labelfont 1 labelsize 12 textsize 12
                code0 {filename[23]=o;}
              }
              Fl_Repeat_Button button_moveup {
                callback {moveselected(-1);}
                image {images/up.gif} xywh {530 255 70 20} labelsize 12 align 17
              }
              Fl_Repeat_Button button_movedown {
                callback {moveselected(1);}
                image {images/down.gif} xywh {530 275 70 20} labelsize 12
              }
              Fl_Button button_load {
                label {Load...}
                callback {if (currsong == NULL) {
	fl_message("No song selected.\\nSelect a song on the Project/Song tab and try again.");
	return;
	return;
}
string* audiofiledir=hd24utils::getlastdir("audiofiledir");

Fl_Native_File_Chooser chooser;
chooser.directory(audiofiledir->c_str());
delete audiofiledir;
chooser.title("Select the files to transfer:\\0");
chooser.type(Fl_Native_File_Chooser::BROWSE_MULTI_FILE);
chooser.filter("Audio files\\t*.{wav,aif}\\0");
//chooser.preview(0);
int tosplitornottosplit=0;

switch (chooser.show()) {
	case -1: break; //error
	case 1: break; //cancel
	default:
		if (chooser.filename()) {
			string* cfilename=new string(chooser.filename());		

			string* fpath=new string("");
			*fpath+=cfilename->substr(0,strlen(cfilename->c_str())-strlen(fl_filename_name(cfilename->c_str())));
			hd24utils::setlastdir("audiofiledir",fpath->c_str());				
			delete cfilename;
			for (int n = 0; n < chooser.count(); n++ ) {
				string* cfilename=new string(chooser.filename(n));
				int currfiletracks=countfiletracks(cfilename->c_str());
				int totfiletracks=currfiletracks;
				int haveslot=0;	
				while (currfiletracks>0) {
					if (totfiletracks>1) {
						if (tosplitornottosplit==0) {
							bool wantsplit=
							confirm("One or more selected files have more than 1 track. Do you wish to split them up?");
							if (!wantsplit) {
								tosplitornottosplit=1;
							} else {
								tosplitornottosplit=2;
							}
						}
					}
				
					haveslot=0;	
					for (unsigned int freeslot=0;freeslot<currsong->logical_channels();freeslot++) {
						if (strlen(filename[freeslot]->value())==0) {
							haveslot=1;
							filename[freeslot]->value(chooser.filename(n));
//							cout << "Clear slot " << freeslot << endl;
							((Fl_Choice*)(trackaction[freeslot]))->clear();
							if (tosplitornottosplit>1) {
								populate_trackactionbyfile(freeslot,3+(totfiletracks-currfiletracks));					
							} else {
								populate_trackactionbyfile(freeslot,2);									
							}
							break;
						}
					}
					if (haveslot==0) {
						break;
					}
					if (tosplitornottosplit==1) {					
						currfiletracks=0;
					} else {
						currfiletracks--;
					}
				}
				delete cfilename;
				if (haveslot==0) {
					fl_message("One or more files could not be assigned to a track slot.\\n"
						   "Please clear one or more track slots and try again.");
					break;
				}				
		        }
		}
}}
                xywh {530 50 70 20} labelsize 12
              }
              Fl_Button button_clear {
                label Clear
                callback {for (unsigned int i=0;i<MAXCHANNELS;i++) {
	if (trackselected[i]==1) {
		filename[i]->value("");
		trackselected[i]=0;

	}
};
redrawtracks();}
                xywh {530 70 70 20} labelsize 12
              }
              Fl_Choice trackaction1 {open
                xywh {470 50 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,1);}
              } {}
              Fl_Choice trackaction2 {open
                xywh {470 69 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,2);}
              } {}
              Fl_Choice trackaction3 {open
                xywh {470 88 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,3);}
              } {}
              Fl_Choice trackaction4 {open
                xywh {470 107 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,4);}
              } {}
              Fl_Choice trackaction5 {open
                xywh {470 126 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,5);}
              } {}
              Fl_Choice trackaction6 {open
                xywh {470 145 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,6);}
              } {}
              Fl_Choice trackaction7 {open
                xywh {470 164 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,7);}
              } {}
              Fl_Choice trackaction8 {open
                xywh {470 183 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,8);}
              } {}
              Fl_Choice trackaction9 {open
                xywh {470 202 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,9);}
              } {}
              Fl_Choice trackaction10 {open
                xywh {470 221 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,10);}
              } {}
              Fl_Choice trackaction11 {open
                xywh {470 240 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,11);}
              } {}
              Fl_Choice trackaction12 {open
                xywh {470 259 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,12);}
              } {}
              Fl_Choice trackaction13 {open
                xywh {470 278 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,13);}
              } {}
              Fl_Choice trackaction14 {open
                xywh {470 297 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,14);}
              } {}
              Fl_Choice trackaction15 {open
                xywh {470 316 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,15);}
              } {}
              Fl_Choice trackaction16 {open
                xywh {470 335 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,16);}
              } {}
              Fl_Choice trackaction17 {open
                xywh {470 354 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,17);}
              } {}
              Fl_Choice trackaction18 {open
                xywh {470 373 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,18);}
              } {}
              Fl_Choice trackaction19 {open
                xywh {470 392 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,19);}
              } {}
              Fl_Choice trackaction20 {open
                xywh {470 411 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,20);}
              } {}
              Fl_Choice trackaction21 {open
                xywh {470 430 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,21);}
              } {}
              Fl_Choice trackaction22 {open
                xywh {470 449 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,22);}
              } {}
              Fl_Choice trackaction23 {open
                xywh {470 468 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,23);}
              } {}
              Fl_Choice trackaction24 {open
                xywh {470 487 55 19} down_box BORDER_BOX labelsize 11 textsize 11
                code0 {this->populate_trackaction(this,o,24);}
              } {}
              Fl_Button button_transfertohd24help {
                label Help
                callback {fl_message(
		"To transfer files to the HD24, load one or more files.\\n"
		"Each file will be assigned to an empty track slot.\\n\\n"
		"Before transferring, you will be able to rearrange the\\n"
		"order of the tracks by clicking on one or more tracks\\n"
		"and clicking the up or down arrow buttons.\\n\\n"
		"When a track slot is empty, the existing track will be\\n"
		"preserved, unless 'Erase' or 'SMPTE' is selected on \\n"
		"the right of the track.\\n\\n"
		"When a file to transfer contains multiple tracks, you\\n"
                "can choose to mixdown the file to mono (the default), \\n"
                "or you can select the track that you want to transfer \\n"
                "to the HD24 drive." 
	);}
                xywh {530 455 70 20} labelsize 12
              }
            }
          }
          Fl_Group uicanvas_futureversions {open
            xywh {5 10 1710 530} hide resizable
          } {
            Fl_Tabs Future_Tabs {open
              xywh {10 35 1595 485}
            } {
              Fl_Group tab_wave {
                label Wave open
                xywh {15 60 595 455} color 52 labelfont 1 labelsize 12 deactivate
                code0 {o->hide();}
              } {
                Fl_Box {} {
                  label {A future version of HD24connect may display a wave form here.
Initially, the purpose of this wave form would be to make it 
easier to select an export range.}
                  xywh {15 68 460 222} align 21
                }
              }
              Fl_Group tab_data {
                label Data open
                xywh {15 60 595 455} color 52 labelfont 1 labelsize 12 hide deactivate
                code0 {o->hide();}
              } {
                Fl_Box {} {
                  label {A future version of HD24connect may display a list of data files here. 
Specifically, this would be a list of files associated with the current
project and/or song. To make this possible, a single song on the
HD24 drive may be sacrificed as data area. This tab would then contain
functionality to import/export/list those files, as well as functionality to 
create a data area on the drive.
Without data area on the HD24 drive itself, songs may still be given a 
unique identifier to allow, for instance, automatically associating a mix 
on the DAW computer with a song. }
                  xywh {15 63 505 222} align 21
                }
              }
            }
          }
        }
      }
    }
  }
  Function {make_cli(hd24fs* p_fsys)} {return_type void
  } {
    code {// make_cli: stands for make commandline interface
// (intended to allow batch processing and regression testing)
// both current and default to allow multi drive support
defaulthd24=p_fsys; 
currenthd24=p_fsys;} {}
  }
  decl {/* ===RECORDER UI stuff ===================================================== */} {}
  Function {readmixer()} {open return_type void
  } {
    code {// set solo status of channel to value
/*
for (unsigned int i=0;i<MAXCHANNELS;i++) {
	solobutton[i]->value(mixer->mixerchannel[i]->control->solo());
	solobutton[i]->redraw();
	mutebutton[i]->value(mixer->mixerchannel[i]->control->mute());
	mutebutton[i]->redraw();
}
*/} {}
  }
  decl {/* === UTILS ===================================================== */} {}
  Function {getlastprojdir(Fl_Input* o)} {return_type void
  } {
    code {string* projdir=hd24utils::getlastdir("projdir");
o->value(projdir->c_str());
delete projdir;} {}
  }
  Function {ui_restart()} {open
  } {
    code {//if (isportaudioinitialized()) {
//	portaudio_transport_stop();
//}
if (recorder!=NULL) {
	if (recorder->control!=NULL) {
		recorder->control->button_stop_call();
	}
}
Fl::remove_timeout(poll_callback);

recorder->~RecorderUI();
delete recorder;

Fl_Window * winx=Fl::first_window();
if (currproj!=NULL)
{
    delete currproj;
    currproj=NULL;
}

if (currsong!=NULL)
{
    delete currsong;
    currsong=NULL;
}

Fl_Window * winy=make_window(currenthd24);

winy->position(winx->x(),winx->y());
winy->end();
winy->show();
\#ifdef LINUX
XSetWMHints(fl_display, fl_xid(winy), XGetWMHints(fl_display, fl_xid(winx)));
\#endif
winx->~Fl_Window();
delete winx;
winx=NULL;
//if (jackmtsample!=NULL)
//{
//	free(jackmtsample);
//}} {}
  }
  Function {loadheaderfile()} {} {
    code {Fl_Native_File_Chooser chooser;
chooser.title("Select header file\\0");
chooser.filter("Drive Images\\t*.{img,bin,h24,hd24}\\0");
chooser.type(Fl_Native_File_Chooser::BROWSE_FILE);

string* headerdir=hd24utils::getlastdir("headerdir");
chooser.directory(headerdir->c_str());
delete headerdir;
switch (chooser.show()) {
	case -1: break; //error
	case 1: break; //cancel
	default:
		if (chooser.filename()) {
			if (!(currenthd24->useheaderfile (chooser.filename()))) {
				fl_message("Couldn't load headerfile. Possible causes: \\n- Most likely you haven't selected a device or drive image yet.\\n- Maybe you have no read access to the file.");
				return;
			}
			string* strfile=new string(chooser.filename());			
			string* fpath=new string("");
			*fpath+=strfile->substr(0,strlen(strfile->c_str())-strlen(fl_filename_name(strfile->c_str())));
			hd24utils::setlastdir("headerdir",fpath->c_str());			
			ui_restart();
			return;
		}
		break;
}} {}
  }
  Function {anyfilesexist(hd24song* thesong)} {return_type bool
  } {
    code {bool anyexist=false;

struct stat fi;
__uint32 channels=thesong->logical_channels();
for (unsigned int q=0; q<100; q++)
{
    for (unsigned int handle=0;handle<channels;handle++) 
    {
        if (track[handle]->value()==0) {
    	    // channel not selected for export
	    continue;
        }
        string* fname=transeng->generate_filename(handle,0,q);
\#if (HD24DEBUG==1) 
      cout << "check if file exists:" << *fname << endl; 
\#endif    
        if ((stat (fname->c_str(), &fi) != -1) && ((fi.st_mode & S_IFDIR) == 0)) {
            anyexist=true;
\#if (HD24DEBUG==1) 
  cout << "yes, exists" << *fname << endl; 
\#endif            
            delete fname;
            break;
        }
    
        fname=transeng->generate_filename(handle,1,q);
\#if (HD24DEBUG==1) 
  cout << "check if file exists:" << *fname << endl; 
\#endif    
        if ((stat (fname->c_str(), &fi) != -1) && ((fi.st_mode & S_IFDIR) == 0)) {
            anyexist=true;
\#if (HD24DEBUG==1) 
  cout << "yes, exists" << *fname << endl; 
\#endif            
            delete fname;
            break;
        }    
\#if (HD24DEBUG==1) 
      cout << "no, doesnt exist" << endl;
\#endif            

        delete fname;
    }  
    if (anyexist==true) break;
}
return anyexist;} {}
  }
  Function {fl_check()} {open return_type void
  } {
    code {refresh(stop_transfer);
refresh(statusmsg);
Fl::check();} {}
  }
  decl {bool mustdisplaytimer;} {public
  }
  decl {bool polling;} {public
  }
  decl {Fl_Text_Buffer* catalogbuffer;} {public
  }
  Function {HD24UserInterface(int argc,char** argv,char* absprogpath)} {open
  } {
    code {control=new HD24control();
control->parentui(this);
control->ready(0);
/*currpeakmode=0;
for (unsigned int i=0;i<MAXCHANNELS;i++) { trackpeak[i]=0; } */
catalogbuffer=NULL;
portaudio=new PortAudioWrapper(absprogpath);
soundfile=new SoundFileWrapper(absprogpath);
libjack=new JackWrapper(absprogpath);
this->recorder=NULL; // will be initialized by make_window code
this->transeng=new hd24transferengine();} {}
  }
  Function {~HD24UserInterface()} {open
  } {
    code {if (control!=NULL) delete control;
if (portaudio!=NULL) delete portaudio;
if (soundfile!=NULL) delete soundfile;
if (libjack!=NULL) delete libjack;
if (currsong!=NULL) delete currsong;
if (currproj!=NULL) delete currproj;
if (currenthd24==defaulthd24)
{
	if (currenthd24!=NULL) delete currenthd24;
} else {
	if (currenthd24!=NULL) delete currenthd24;
	if (defaulthd24!=NULL) delete defaulthd24;
}
if (transeng!=NULL) 
{
	delete transeng;
	transeng=NULL;
}} {}
  }
  Function {confirm(const char* question)} {open return_type bool
  } {
    code {int result=fl_choice("%s","No","Yes",NULL,question);
if (result==1) {
	return true;
}
return false;} {}
  }
  Function {samplerate()} {open return_type __uint32
  } {
    code {// returns current samplerate of the UI, used by mixer
if (currsong==NULL) return 44100;
return currsong->samplerate();} {}
  }
  decl {friend class ScrubWheel;} {}
  decl {int refreshingui;} {}
  Function {saverestoretrackselection(Fl_Check_Button* o)} {open return_type void
  } {
    code {int i;
if (o->value()==1)
{
	if (
	     (transfersource_mixleft->value()
    	    +transfersource_mixright->value())
		==1)
	{
		// save selected tracks
		// disable track selection
		// (repopulate formats list/file name/whatever?)
		for (i=0;i<MAXCHANNELS;i++)
		{
			tracksave[i]=track[i]->value();
			track[i]->value(1);
			track[i]->deactivate();
			button_invert_tracks->deactivate();
		}
		fileformat->deactivate();
		return;
	}
}

if (o->value()==0)
{
	if (
	     (transfersource_mixleft->value()
    	    +transfersource_mixright->value())
		==0)
	{
		// restore tracks
		// enable track selection		
		for (i=0;i<MAXCHANNELS;i++)
		{		
			track[i]->value(tracksave[i]);			
			track[i]->activate();
			button_invert_tracks->activate();
			
		}
		fileformat->activate();
	}		
}} {}
  }
  Function {showprogtitle()} {open return_type void
  } {
    code {recorder->control->dispwrite(0,"HD24connect     "
           "HD24VERSION                ",3000);} {}
  }
  decl {bool closingdown;} {public
  }
  Function {finish()} {open return_type void
  } {
    code {this->control->ready(0);
this->closingdown=true;
this->recorder->finish();} {}
  }
  Function {poll_callback(void* user)} {open return_type {static void}
  } {
    code {HD24UserInterface* mythis=(HD24UserInterface*)user;
//RecorderUI* mythis=(RecorderUI*)user;
\#if (HD24DEBUG==1) 
      //cout << "poll_callback" << endl;
\#endif    
if (mythis->control->ready()!=1) { return; }


if (mythis->busy!=1) {
	mythis->busy=1;
	hd24song* mycurrsong=mythis->currsong;
	
	if (mythis->recorder->control->song()!=mythis->currsong)
	{
		mythis->recorder->control->song(mythis->currsong); /* tell recorder that the song is gone */				
	}
		
	if (mycurrsong!=NULL) {
		mycurrsong->bufferpoll();
	}


	mythis->uiredrawcount=(mythis->uiredrawcount+1)%UIREFRESH;
	if (mythis->uiredrawcount==0) {

	   for (unsigned int i=0;i<MAXCHANNELS;i++) {
//		if (mythis->Tabs->value()==mythis->tabCopyToPC) {
//			if (mythis->trackpeak[i]>.01) {
//			       if (mythis->trackpeak[i]>.9) 
//			       {
//				    mythis->trackled[i]->color(1);
//				    mythis->trackled[i]->redraw();
//			       } else {
//		                    if (mythis->trackpeak[i]>.7) {
//		           		mythis->trackled[i]->color(3);
//					mythis->trackled[i]->redraw();
//		                    } else {
//				        mythis->trackled[i]->color(2);
//				   	mythis->trackled[i]->redraw();
//				    }
//        		        }
//			} else {
//				mythis->trackled[i]->color(52);
//				mythis->trackled[i]->redraw();
//			}
//		} 
	   }

	   if (mythis->Tabs->value()==mythis->tabMixer) {
//                   mythis->mixer->redraw();
		   mythis->mixer->control->updatemeters();
	   }
	   if (mythis->Tabs->value()==mythis->tabRecorder) {
//                mythis->mixer->redraw();
//		mythis->recorder->control->updatemeters();
           }
           // Fl check??
	}
}
if (mythis->recorder!=NULL) {
	RecorderUI::poll_callback(mythis->recorder);
}
mythis->busy=0;
Fl::add_timeout(TIMEOUT,poll_callback,user);} {}
  }
  decl {Fl_Box* trackled[24];} {public
  }
  Function {setlocbuttonlabel(int i)} {open return_type void
  } {
    code {hd24song* locsong=this->currsong;
int numpoints=0;
if (locsong!=NULL) 
{
 	numpoints=locsong->locatepointcount();
}
__uint32 locatepos=locsong->getlocatepos(i);
string* locname1=new string("");
	if (!(((i==0)||(i==numpoints)))) {
		*locname1+="+";
		string* dur=locsong->display_duration(locatepos);
		*locname1+=*dur;
		delete (dur);	
	} else {
		if (i!=0)
		{
			*locname1+="+";
			string* dur=locsong->display_duration(locatepos);
			*locname1+=*dur;
			delete (dur);		
		} else {
			*locname1+="START";		
		}
	}
	
	*locname1="Seek to "+*locname1;
	int l=strlen(locname1->c_str());
	for (i=0;i<l;i++) {
		locbuttonlabel[i]=locname1->c_str()[i];
		locbuttonlabel[i+1]=(char)0;		
	}
	
	button_golocatepoint->label(&(this->locbuttonlabel[0]));
	delete locname1;} {}
  }
  decl {char locbuttonlabel[64];} {}
}