File: gap_cme_gui.c

package info (click to toggle)
gimp-gap 2.6.0+dfsg-5
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 20,720 kB
  • ctags: 7,997
  • sloc: ansic: 119,817; sh: 3,890; makefile: 932; lisp: 97; pascal: 55
file content (4429 lines) | stat: -rw-r--r-- 146,742 bytes parent folder | download | duplicates (3)
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
/* gap_cme_gui.c
 * 2001.04.08 hof (Wolfgang Hofer)
 *
 * GAP ... Gimp Animation Plugins
 *
 * This Module contains GUI Procedures for common Video Encoder Dialog
 * it calls the galde GTK GUI modules and aditional GUI related stuff
 *
 */
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */


/* revision history:
 * version 2.2.0;   2005.10.08   hof: ported from pthread to gthread
 * version 2.1.0a;  2004.11.10   hof: reorganized dialog creation procedures
 *                                    and replaced the deprecated GtkOptionMenu widget by gimp_int_combo_box
 * version 2.1.0a;  2004.10.26   hof: added input_mode radiobuttons
 * version 2.1.0a;  2004.05.06   hof: integration into gimp-gap project
 * version 1.2.2b;  2003.03.08   hof: thread for storyboard_file processing
 * version 1.2.2b;  2002.11.23   hof: added filtermacro_file, storyboard_file
 * version 1.2.1a;  2001.06.30   hof: created
 */


/* the gui can run even if we dont have gthread library
 * (but the main window refresh will not be done while the encoder
 * parameter dialog -- that is called via pdb -- is open)
 */
#define GAP_USE_GTHREAD


#include <config.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#include <glib/gstdio.h>
#include <gtk/gtk.h>

#include "gap-intl.h"

#include "gap_libgapbase.h"
#include "gap_cme_main.h"
#include "gap_cme_gui.h"
#include "gap_cme_callbacks.h"

#include "gap_gve_sox.h"
#include "gap_gve_story.h"
#include "gap_arr_dialog.h"
#include "gap_audio_wav.h"
#include "gap_stock.h"

#define RADIO_ITEM_INDEX_KEY "gap_radio_item_index_key"

typedef struct t_global_stb
{
  gdouble framerate;
  gdouble aud_total_sec;
  gchar  composite_audio[1000];
  gchar *errtext;
  gchar *errline;
  gchar *warntext;
  gchar *warnline;
  gint32 errline_nr;
  gint32 warnline_nr;
  gboolean vidhand_open_ok;
  gint32 first_frame_limit;
  gint32 last_frame_nr;
  gint32 master_width;
  gint32 master_height;

  gdouble progress;
  gchar   status_msg[65];

  gint32 total_stroyboard_frames;

  gint32 poll_timertag;
  gboolean stb_job_done;
  GapGveStoryVidHandle *vidhand;
} t_global_stb;

static t_global_stb  global_stb;

static void            p_gap_message(const char *msg);
static gint            p_overwrite_dialog(GapCmeGlobalParams *gpp, gchar *filename, gint overwrite_mode);
static GapGveEncList*  pdb_find_video_encoders(void);
static void            p_replace_combo_encodername(GapCmeGlobalParams *gpp);
static void            p_get_range_from_type (GapCmeGlobalParams *gpp
                           , GapLibTypeInputRange range_type
                           , gint32 *lower
                           , gint32 *upper
                           );
static void            p_get_range_and_type (GapCmeGlobalParams *gpp
                           , gint32 *lower
                           , gint32 *upper
                           , GapLibTypeInputRange *range_type);
static void            p_print_storyboard_text_label(GapCmeGlobalParams *gpp, char *msg);
static void            p_print_time_label( GtkLabel *lbl, gint32   tmsec);
static gint32          p_update_aud_info (GapCmeGlobalParams *gpp
                           , GtkLabel *lbl_info
                           , GtkLabel *lbl_time
                           , GtkLabel *lbl_time0
                           , char *audioname);
static void            p_range_widgets_set_limits(GapCmeGlobalParams *gpp
                           , gint32 lower_limit
                           , gint32 upper_limit
                           , GapLibTypeInputRange range_type);
static void            p_init_shell_window_widgets (GapCmeGlobalParams *gpp);
static void            p_status_progress(GapCmeGlobalParams *gpp, t_global_stb *gstb);
static void            p_storybord_job_finished(GapCmeGlobalParams *gpp, t_global_stb *gstb);
static void            on_timer_poll(gpointer   user_data);
static gpointer        p_thread_storyboard_file(gpointer data);


/* procedures to create the dialog windows */
static GtkWidget*      create_ow__dialog (GapCmeGlobalParams *gpp);
static void            p_input_mode_radio_callback(GtkWidget *widget, GapCmeGlobalParams *gpp);
static void            p_create_input_mode_widgets(GtkWidget *table, int row, int col, GapCmeGlobalParams *gpp);

static GtkWidget*      p_create_encoder_status_frame (GapCmeGlobalParams *gpp);
static GtkWidget*      p_create_encode_extras_frame (GapCmeGlobalParams *gpp);
static GtkWidget*      p_create_audiotool_cfg_frame (GapCmeGlobalParams *gpp);
static GtkWidget*      p_create_audio_options_frame (GapCmeGlobalParams *gpp);
static GtkWidget*      p_create_video_timing_table (GapCmeGlobalParams *gpp);
static GtkWidget*      p_create_video_options_frame (GapCmeGlobalParams *gpp);
static GtkWidget*      p_create_shell_window (GapCmeGlobalParams *gpp);

static gint            p_overwrite_dialog(GapCmeGlobalParams *gpp, gchar *filename, gint overwrite_mode);
static gint            p_call_encoder_procedure(GapCmeGlobalParams *gpp);

/* ----------------------------------------
 * p_gap_message
 * ----------------------------------------
 */
static void
p_gap_message(const char *msg)
{
  static GapArrButtonArg  l_argv[1];
  int               l_argc;

  l_argv[0].but_txt  = GTK_STOCK_OK;
  l_argv[0].but_val  = 0;
  l_argc             = 1;

  if(msg)
  {
    if(*msg)
    {
       if(gap_debug) printf("%s\n", msg);
       gap_arr_buttons_dialog  (_("GAP Message"), msg, l_argc, l_argv, -1);
    }
  }
}  /* end p_gap_message */

/* ----------------------------------------
 * gap_cme_gui_check_gui_thread_is_active
 * ----------------------------------------
 */
gboolean
gap_cme_gui_check_gui_thread_is_active(GapCmeGlobalParams *gpp)
{
   static gboolean l_gap_message_open = FALSE;

   if(gpp->val.gui_proc_thread)
   {
     /* only one of the threads (Master or GUI thread) can use the PDB Interface (or call gimp_xxx procedures)
      * If 2 threads are talking to the gimp main app parallel it comes to crash.
      */
     if(gap_debug) printf("MASTER: GUI thread %d is already active\n", (int)gpp->val.gui_proc_thread);
     if(l_gap_message_open == FALSE)
     {
       l_gap_message_open = TRUE;
       p_gap_message(_("Encoder specific Parameter Window still open"));
       l_gap_message_open = FALSE;
     }
     return (TRUE);
   }
   return (FALSE);
}  /* end gap_cme_gui_check_gui_thread_is_active */


/* ----------------------------------------
 * gap_cme_gui_pdb_call_encoder_gui_plugin
 * ----------------------------------------
 */
gint
gap_cme_gui_pdb_call_encoder_gui_plugin(GapCmeGlobalParams *gpp)
{
  gboolean joinable;
  if(gpp->ecp == NULL)
  {
    return -1;
  }

#ifdef GAP_USE_GTHREAD
  if(gap_cme_gui_check_gui_thread_is_active(gpp)) return -1;

  /* start a thread for asynchron PDB call of the gui_ procedure
   */
  if(gap_debug) printf("MASTER: Before g_thread_create\n");

  joinable = TRUE;
  gpp->val.gui_proc_thread =
      g_thread_create((GThreadFunc)gap_cme_gui_thread_async_pdb_call
                     , NULL  /* data */
                     , joinable
                     , NULL  /* GError **error (NULL dont report errors) */
                     );

  if(gap_debug) printf("MASTER: After g_thread_create\n");
#else
  /* if threads are not used simply call the procedure
   * (the common GUI window is not refreshed until the called gui_proc ends)
   */
  gap_cme_gui_thread_async_pdb_call(NULL);

#endif

  return 0;
}  /* end gap_cme_gui_pdb_call_encoder_gui_plugin */


/* ----------------------------------------
 * gap_cme_gui_thread_async_pdb_call
 * ----------------------------------------
 */
gpointer
gap_cme_gui_thread_async_pdb_call(gpointer data)
{
   GapCmeGlobalParams *gpp;
   GimpParam       *l_ret_params;
   GimpParam       *l_argv;
   gint             l_retvals;
   gint             l_idx;
   gint             l_nparams;
   gint             l_nreturn_vals;
   GimpPDBProcType  l_proc_type;
   gchar           *l_proc_blurb;
   gchar           *l_proc_help;
   gchar           *l_proc_author;
   gchar           *l_proc_copyright;
   gchar           *l_proc_date;
   GimpParamDef    *l_params;
   GimpParamDef    *l_return_vals;
   gchar           *plugin_name;


  gpp = gap_cme_main_get_global_params();

  if(gap_debug) printf("THREAD: gap_cme_gui_thread_async_pdb_call &gpp: %d\n", (int)gpp);

  plugin_name = gpp->val.ecp_sel.gui_proc;

  /* query for plugin_name to get its argument types */
  if (!gimp_procedural_db_proc_info (plugin_name,
                                     &l_proc_blurb,
                                     &l_proc_help,
                                     &l_proc_author,
                                     &l_proc_copyright,
                                     &l_proc_date,
                                     &l_proc_type,
                                     &l_nparams,
                                     &l_nreturn_vals,
                                     &l_params,
                                     &l_return_vals))
  {
    printf("ERROR: Plugin not available, Name was %s\n", plugin_name);

    if(gap_debug) printf("THREAD gui_proc err TERMINATING: %d\n", (int)gpp->val.gui_proc_thread);

    gpp->val.gui_proc_thread = NULL;
    return (NULL);
  }

  /* construct the procedures arguments */
  l_argv = g_new (GimpParam, l_nparams);
  memset (l_argv, 0, (sizeof (GimpParam) * l_nparams));

  /* initialize the argument types */
  for (l_idx = 0; l_idx < l_nparams; l_idx++)
  {
    l_argv[l_idx].type = l_params[l_idx].type;
    switch(l_params[l_idx].type)
    {
      case GIMP_PDB_DISPLAY:
        l_argv[l_idx].data.d_display  = -1;
        break;
      case GIMP_PDB_DRAWABLE:
      case GIMP_PDB_LAYER:
      case GIMP_PDB_CHANNEL:
        l_argv[l_idx].data.d_drawable  = -1;
        break;
      case GIMP_PDB_IMAGE:
        l_argv[l_idx].data.d_image  = -1;
        break;
      case GIMP_PDB_INT32:
      case GIMP_PDB_INT16:
      case GIMP_PDB_INT8:
        l_argv[l_idx].data.d_int32  = 0;
        break;
      case GIMP_PDB_FLOAT:
        l_argv[l_idx].data.d_float  = 0.0;
        break;
      case GIMP_PDB_STRING:
        l_argv[l_idx].data.d_string  =  g_strdup("\0");
        break;
      default:
        l_argv[l_idx].data.d_int32  = 0;
        break;

    }
  }


  /* init the standard parameters, that should be common to all plugins */
  l_argv[0].data.d_int32     =  GIMP_RUN_INTERACTIVE;  /* run_mode */
  l_argv[1].data.d_string    =  g_strdup_printf("GAP_KEY_VIDENC_STDPAR_%d", (int)gpp->val.image_ID);

  gimp_set_data(l_argv[1].data.d_string, &gpp->val, sizeof(GapGveCommonValues));


  if(gap_debug)
  {
      printf("THREAD Common GUI key: %s\n", l_argv[1].data.d_string);
      printf("THREAD Common GUI rate: %f  w:%d h:%d\n", (float)gpp->val.framerate, (int)gpp->val.vid_width, (int)gpp->val.vid_height);
  }


  /* run the plug-in procedure */
  l_ret_params = gimp_run_procedure2 (plugin_name, &l_retvals, l_nparams, l_argv);

  /*  free up arguments and values  */
  gimp_destroy_params (l_argv, l_nparams);


  /*  free the query information  */
  g_free (l_proc_blurb);
  g_free (l_proc_help);
  g_free (l_proc_author);
  g_free (l_proc_copyright);
  g_free (l_proc_date);
  g_free (l_params);
  g_free (l_return_vals);



  if (l_ret_params[0].data.d_status != GIMP_PDB_SUCCESS)
  {
    printf("THREAD ERROR: p_call_plugin %s failed.\n", plugin_name);
  }
  else
  {
    if(gap_debug) printf("THREAD DEBUG: p_call_plugin: %s successful.\n", plugin_name);
  }

  /* the GUI of the encoder plugin might have changed the current video filename extension
   * (therefore we repeat the query for extension here)
   */
  gap_cme_gui_requery_vid_extension(gpp);

  if(gap_debug) printf("THREAD gui_proc TERMINATING: %d\n", (int)gpp->val.gui_proc_thread);

  gpp->val.gui_proc_thread = NULL;

  return (NULL);
}  /* end gap_cme_gui_thread_async_pdb_call */



/* ----------------------------------------
 * pdb_find_video_encoders
 * ----------------------------------------
 */
static GapGveEncList*
pdb_find_video_encoders(void)
{
  GapGveEncList *l_ecp;
  GapGveEncList *list_ecp;
  char **proc_list;
  int num_procs;
  int i;
  int j;
  gint             l_nparams;
  gint             l_nreturn_vals;
  GimpPDBProcType   l_proc_type;
  gchar            *l_proc_blurb;
  gchar            *l_proc_help;
  gchar            *l_proc_author;
  gchar            *l_proc_copyright;
  gchar            *l_proc_date;
  GimpParamDef    *l_paramdef;
  GimpParamDef    *l_return_vals;


  if(gap_debug)
  {
    printf("pdb_find_video_encoders: START\n");
  }

  list_ecp = NULL;
  l_ecp = NULL;

  gimp_procedural_db_query (GAP_WILDCARD_VIDEO_ENCODERS, ".*", ".*", ".*", ".*", ".*", ".*",
                           &num_procs, &proc_list);
  if(gap_debug)
  {
    printf("pdb_find_video_encoders: num_procs:%d (matching the wildcard:%s)\n"
      ,(int)num_procs
      , GAP_WILDCARD_VIDEO_ENCODERS
      );
  }

  for (j = 0; j < num_procs; j++)
  {
     gboolean l_has_proc_info;

     i = (num_procs -1) - j;

     l_has_proc_info = gimp_procedural_db_proc_info (proc_list[i],
                             &l_proc_blurb,
                             &l_proc_help,
                             &l_proc_author,
                             &l_proc_copyright,
                             &l_proc_date,
                             &l_proc_type,
                             &l_nparams,
                             &l_nreturn_vals,
                             &l_paramdef,
                             &l_return_vals);

     if(gap_debug)
     {
       printf("pdb_find_video_encoders: check proc:%s  has_proc_info:%d\n"
         , proc_list[i]
         , (int)l_has_proc_info
         );
     }

     if(l_has_proc_info == TRUE)
     {
        char *ecp_infoproc;

        if (l_nparams != GAP_VENC_NUM_STANDARD_PARAM)
        {
           if(gap_debug)
           {
             printf("pdb_find_video_encoders: procedure %s is skipped (nparams %d != %d)\n"
                               , proc_list[i], (int)l_nparams, (int)GAP_VENC_NUM_STANDARD_PARAM );
           }
           continue;
        }

        l_ecp = g_malloc(sizeof(GapGveEncList));

        /* pepare default values for menu_name short_description and video_extensions */
        g_snprintf(l_ecp->menu_name, sizeof(l_ecp->menu_name), "%s", proc_list[i]);
        g_snprintf(l_ecp->video_extension, sizeof(l_ecp->video_extension), ".%d", (int)i);
        g_snprintf(l_ecp->short_description, sizeof(l_ecp->short_description), "%s", _("no description available"));

        /* get Menuname and video_extension via ecp_infoproc */
        ecp_infoproc = g_strdup_printf("%s%s", GAP_QUERY_PREFIX_VIDEO_ENCODERS, proc_list[i]);

        if(TRUE == gimp_procedural_db_proc_info (ecp_infoproc,
                             &l_proc_blurb,
                             &l_proc_help,
                             &l_proc_author,
                             &l_proc_copyright,
                             &l_proc_date,
                             &l_proc_type,
                             &l_nparams,
                             &l_nreturn_vals,
                             &l_paramdef,
                             &l_return_vals))
        {
           if(gap_debug)
           {
             printf("pdb_find_video_encoders: run procedure %s nparams:%d nretrun_vals:%d\n"
                     , ecp_infoproc, (int)l_nparams, (int)l_nreturn_vals);
           }

           if(l_nreturn_vals >= 1)
           {
              GimpParam* l_params;
              gint       l_retvals;

              /* query for menu_name */
              l_params = gimp_run_procedure (ecp_infoproc,
                          &l_retvals,
                          GIMP_PDB_STRING, GAP_VENC_PAR_MENU_NAME,
                          GIMP_PDB_END);

              if((l_params[0].data.d_status == GIMP_PDB_SUCCESS) && (l_retvals >= 2))
              {
                if((l_params[1].data.d_string != NULL) && (l_params[1].type == GIMP_PDB_STRING))
                {
                  if(gap_debug)
                  {
                    printf("[1].d_string %s\n", l_params[1].data.d_string);
                  }
                  g_snprintf(l_ecp->menu_name, sizeof(l_ecp->menu_name), "%s", l_params[1].data.d_string);
                }
              }
              g_free(l_params);

              /* query for video_extension */
              l_params = gimp_run_procedure (ecp_infoproc,
                          &l_retvals,
                          GIMP_PDB_STRING, GAP_VENC_PAR_VID_EXTENSION,
                          GIMP_PDB_END);

              if((l_params[0].data.d_status == GIMP_PDB_SUCCESS) && (l_retvals >= 2))
              {
                if((l_params[1].data.d_string) && (l_params[1].type == GIMP_PDB_STRING))
                {
                  if(gap_debug)
                  {
                    printf("[1].d_string %s\n", l_params[1].data.d_string);
                  }
                  g_snprintf(l_ecp->video_extension, sizeof(l_ecp->video_extension), "%s",  l_params[1].data.d_string);
                }
              }
              g_free(l_params);

              /* query for short_description */
              l_params = gimp_run_procedure (ecp_infoproc,
                          &l_retvals,
                          GIMP_PDB_STRING, GAP_VENC_PAR_SHORT_DESCRIPTION,
                          GIMP_PDB_END);

              if((l_params[0].data.d_status == GIMP_PDB_SUCCESS) && (l_retvals >= 2))
              {
                if((l_params[1].data.d_string) && (l_params[1].type == GIMP_PDB_STRING))
                {
                  if(gap_debug)
                  {
                    printf("[1].d_string %s\n", l_params[1].data.d_string);
                  }
                  g_snprintf(l_ecp->short_description, sizeof(l_ecp->short_description), "%s",  l_params[1].data.d_string);
                }
              }
              g_free(l_params);


              /* query for (optional) gui_proc (to set encoder soecific params) */
              l_params = gimp_run_procedure (ecp_infoproc,
                          &l_retvals,
                          GIMP_PDB_STRING, GAP_VENC_PAR_GUI_PROC,
                          GIMP_PDB_END);

              if((l_params[0].data.d_status == GIMP_PDB_SUCCESS) && (l_retvals >= 2))
              {
                if((l_params[1].data.d_string) && (l_params[1].type == GIMP_PDB_STRING))
                {
                  if(gap_debug)
                  {
                    printf("[1].d_string %s\n", l_params[1].data.d_string);
                  }
                  g_snprintf(l_ecp->gui_proc, sizeof(l_ecp->gui_proc), "%s",  l_params[1].data.d_string);
                }
              }
              g_free(l_params);
           }
        }

        g_snprintf(l_ecp->vid_enc_plugin, sizeof(l_ecp->vid_enc_plugin), "%s", proc_list[i]);
        l_ecp->menu_nr = i+1;
        l_ecp->next = list_ecp;

        list_ecp = l_ecp;
     }
  }
  if(list_ecp == NULL)
  {
    list_ecp = g_malloc(sizeof(GapGveEncList));
    list_ecp->menu_nr = 0;
    list_ecp->vid_enc_plugin[0] = '\0';
    g_snprintf(list_ecp->menu_name, sizeof(list_ecp->menu_name), "none");
    g_snprintf(list_ecp->video_extension, sizeof(l_ecp->video_extension), ".0");
    list_ecp->next = NULL;
  }

  return(list_ecp);
}  /* end pdb_find_video_encoders */


/* ----------------------------------------
 * gap_cme_gui_requery_vid_extension
 * ----------------------------------------
 * some encoders do support more than 1 extension
 * therefore we do repeat the query for extension
 * to get the current one
 */
void
gap_cme_gui_requery_vid_extension(GapCmeGlobalParams *gpp)
{
  GapGveEncList *l_ecp;

  if(gap_debug) printf("gap_cme_gui_requery_vid_extension START\n");

  for(l_ecp = gpp->ecp; l_ecp != NULL; l_ecp = (GapGveEncList *)l_ecp->next)
  {
    if(strcmp(l_ecp->vid_enc_plugin , gpp->val.ecp_sel.vid_enc_plugin) == 0)
    {
        char      *ecp_infoproc;
        GimpParam *l_params;
        gint       l_retvals;

        /* get video_extension via ecp_infoproc */
        ecp_infoproc = g_strdup_printf("%s%s", GAP_QUERY_PREFIX_VIDEO_ENCODERS, l_ecp->vid_enc_plugin);


        /* (re) query for video_extension */
        l_params = gimp_run_procedure (ecp_infoproc,
                    &l_retvals,
                    GIMP_PDB_STRING, GAP_VENC_PAR_VID_EXTENSION,
                    GIMP_PDB_END);

        if((l_params[0].data.d_status == GIMP_PDB_SUCCESS) && (l_retvals >= 2))
        {
          if((l_params[1].data.d_string) && (l_params[1].type == GIMP_PDB_STRING))
          {
            if(gap_debug) printf("gap_cme_gui_requery_vid_extension: [1].d_string %s\n", l_params[1].data.d_string);
            g_snprintf(l_ecp->video_extension, sizeof(l_ecp->video_extension), "%s",  l_params[1].data.d_string);
            g_snprintf(gpp->val.ecp_sel.video_extension, sizeof(gpp->val.ecp_sel.video_extension), "%s",  l_params[1].data.d_string);
          }
        }
        g_free(l_params);
        g_free(ecp_infoproc);
        gap_cme_gui_upd_vid_extension(gpp);

        return;
    }
  }
}  /* end gap_cme_gui_requery_vid_extension */


/* ----------------------------------------
 * p_replace_combo_encodername
 * ----------------------------------------
 * replace encodername combo by dynamic menu we got from the PDB
 */
static void
p_replace_combo_encodername(GapCmeGlobalParams *gpp)
{
  GtkWidget *combo;
  GapGveEncList *l_ecp;
  gint  l_active_menu_nr;
  gint  l_idx;

  if(gap_debug) printf("p_replace_combo_encodername: START\n");

  combo = gpp->cme__combo_encodername;
  if(combo == NULL)
  {
    return;
  }

  l_idx = 0;
  l_active_menu_nr = 0;
  l_ecp = gpp->ecp;
  while(l_ecp)
  {
     if(gap_debug)
     {
        printf("p_replace_combo_encodername: %d, %s %s\n"
              , (int)l_ecp->menu_nr
              , l_ecp->menu_name
              , l_ecp->vid_enc_plugin);
     }


     gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (combo),
                                GIMP_INT_STORE_VALUE, l_ecp->menu_nr,
                                GIMP_INT_STORE_LABEL, l_ecp->menu_name,
                                -1);

#ifdef ENABLE_GVA_LIBAVFORMAT
     /* set FFMPEG as default encoder (if this encoder is installed) */
     if(strcmp(l_ecp->vid_enc_plugin, GAP_PLUGIN_NAME_FFMPEG_ENCODE) == 0)
     {
         l_active_menu_nr = l_ecp->menu_nr;
     }
#else
     /* set AVI as default encoder (if this encoder is installed) */
     if(strcmp(l_ecp->vid_enc_plugin, GAP_PLUGIN_NAME_AVI_ENCODE) == 0)
     {
         l_active_menu_nr = l_ecp->menu_nr;
     }
#endif
     l_ecp =  (GapGveEncList *)l_ecp->next;
     l_idx++;
  }

  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo)
                             , l_active_menu_nr,
                              G_CALLBACK (on_cme__combo_enocder),
                              gpp);
}  /* end p_replace_combo_encodername */


/* ----------------------------------------
 * p_get_range_from_type
 * ----------------------------------------
 */
static void
p_get_range_from_type (GapCmeGlobalParams *gpp
                           , GapLibTypeInputRange range_type
                           , gint32 *lower
                           , gint32 *upper
                           )
{
  switch(range_type)
  {
    case GAP_RNGTYPE_STORYBOARD:
      {
        t_global_stb  *gstb;

        *lower = 0;

        gstb = &global_stb;
        *upper = gstb->total_stroyboard_frames;
        if(*upper > 0)
        {
          *lower = 1;
        }
      }
      break;
    case GAP_RNGTYPE_LAYER:
      {
        gint          l_nlayers;
        gint32       *l_layers_list;


        l_layers_list = gimp_image_get_layers(gpp->val.image_ID, &l_nlayers);
        g_free(l_layers_list);
        *lower = 0;
        *upper = l_nlayers -1;
      }
      break;
    default:
      *lower = gpp->ainfo.first_frame_nr;
      *upper = gpp->ainfo.last_frame_nr;
      break;
  }
}  /* end p_get_range_from_type */


/* ----------------------------------------
 * p_get_range_and_type
 * ----------------------------------------
 */
static void
p_get_range_and_type (GapCmeGlobalParams *gpp, gint32 *lower, gint32 *upper, GapLibTypeInputRange *range_type)

{
  gint32 l_frame_cnt;

 /* Range limits for widgets "cme__spinbutton_from" and "cme__spinbutton_to"
  * If there is just one frame, we operate on layers
  */

  l_frame_cnt = abs(gpp->ainfo.last_frame_nr - gpp->ainfo.first_frame_nr);
  if(l_frame_cnt > 1)
  {
    *range_type = GAP_RNGTYPE_FRAMES;
  }
  else
  {
    *range_type = GAP_RNGTYPE_LAYER;
  }

  p_get_range_from_type(gpp, *range_type, lower, upper);

}   /* end p_get_range_and_type */


/* ----------------------------------------
 * p_print_storyboard_text_label
 * ----------------------------------------
 */
static void
p_print_storyboard_text_label(GapCmeGlobalParams *gpp, char *msg)
{
  GtkWidget  *lbl;

  lbl = gpp->cme__label_storyboard_helptext;
  if(lbl==NULL) { return; }


  if(msg)
  {
     gtk_label_set_text(GTK_LABEL(lbl), msg);
  }
  else
  {
     gtk_label_set_text(GTK_LABEL(lbl),
      _("Storyboardfiles are textfiles that are used to\n"
        "assemble a video from a list of single images,\n"
        "frameranges, videoclips, gif animations or audiofiles.\n"
        "the frames are organized in tracks,\n"
        "and allow fade, scale and move\n"
        "operations between the tracks.\n"
        "(see STORYBOARD_FILE_DOC.txt for details)")
        );
  }
}  /* end p_print_storyboard_text_label */


/* ----------------------------------------
 * p_print_time_label
 * ----------------------------------------
 */
static void
p_print_time_label( GtkLabel *lbl, gint32   tmsec)
{
  gint32   tms;
  gint32   tsec;
  gint32   tmin;
  gchar    txt[20];

  if(lbl == NULL)
  {
    return;
  }

  tms = tmsec % 1000;
  tsec = (tmsec / 1000) % 60;
  tmin = tmsec / 60000;

  g_snprintf(txt, sizeof(txt), "%02d:%02d:%03d"
                               , (int)tmin
                               , (int)tsec
                               , (int)tms
                               );
  gtk_label_set_text(lbl, txt);
}  /* end p_print_time_label */



/* ----------------------------------------
 * p_update_aud_info
 * ----------------------------------------
 */
static gint32
p_update_aud_info (GapCmeGlobalParams *gpp
                  , GtkLabel *lbl_info
                  , GtkLabel *lbl_time
                  , GtkLabel *lbl_time0
                  , char *audioname)
{
  gchar       txt[200];
  long        samplerate;
  long        disp_samplerate;   /* samplerate to display (rate after resampling by sox) */
  long        channels;
  long        bytes_per_sample;
  long        bits;
  long        samples;
  long        all_playlist_references;
  long        valid_playlist_references;
  int         l_rc;
  gint32      tmsec;        /* audioplaytime in milli secs */
  gboolean    l_audioname_empty;

  if(gap_debug)
  {
    printf("p_update_aud_info: START lbl_info:%d lbl_time:%d lbl_time0:%d\n"
       ,(int)lbl_info
       ,(int)lbl_time
       ,(int)lbl_time0
       );
  }

  if ((lbl_info == NULL) || (lbl_time == NULL) || (lbl_time0 == NULL))
  {
    return 0;
  }
  
  l_audioname_empty = TRUE;
  if(audioname != NULL)
  {
    if(*audioname != '\0')
    {
      l_audioname_empty = FALSE;
    }
  }
  
  
  if(l_audioname_empty == TRUE)
  {
     if(gap_debug)
     {
       printf("p_update_aud_info: audioname is null or empty\n");
     }

     p_print_time_label(lbl_time, 0);
     p_print_time_label(lbl_time0, 0);
     return 0;
  }

  all_playlist_references = 0;
  valid_playlist_references = 0;
  g_snprintf(txt, sizeof(txt), "??:??:???");
  gtk_label_set_text(lbl_time, txt);
  gtk_label_set_text(lbl_time0, txt);

  samplerate = 0;
  disp_samplerate = gpp->val.samplerate;
  g_snprintf(txt, sizeof(txt), " ");

  if(gap_debug)
  {
    printf("p_update_aud_info: audioname %s\n", audioname);
  }


  if(g_file_test(audioname, G_FILE_TEST_EXISTS))
  {
     tmsec = 0;

     /* check for WAV file or valid audio playlist, and get audio informations */
     l_rc = gap_audio_playlist_wav_file_check(audioname
                     , &samplerate
                     , &channels
                     , &bytes_per_sample
                     , &bits
                     , &samples
                     , &all_playlist_references
                     , &valid_playlist_references
                     , gpp->val.samplerate          /* desired_samplerate */
                     );

     if(gap_debug)
     {
       printf("p_update_aud_info: l_rc:%d all_playlist_references:%d\n"
         ,(int)l_rc
         ,(int)all_playlist_references
         );
     }

     if((l_rc == 0)
     || (all_playlist_references >0))
     {
       if((samplerate > 0) && (channels > 0))
       {
         disp_samplerate = samplerate;
         /* have to calculate in gdouble, because samples * 1000
          * may not fit into gint32 datasize and brings negative results
          */
         tmsec = (gint32)((((gdouble)samples / (gdouble)channels) * 1000.0) / (gdouble)disp_samplerate);
       }

       if(all_playlist_references > 0)
       {
         /* audioname is a audio playlist with references to
          * audiofiles for multiple audio track encding
          * valid_playlist_references holds the number of valid tracks
          * (where samplerate matches the desired samplerate and bits == 16)
          */
         g_snprintf(txt, sizeof(txt), _("List[%d] has [%d] valid tracks, Bit:%d Chan:%d Rate:%d")
                                  , (int)all_playlist_references
                                  , (int)valid_playlist_references
                                  , (int)bits
                                  , (int)channels
                                  , (int)samplerate
                                  );
       }
       else
       {
         g_snprintf(txt, sizeof(txt), _("%s, Bit:%d Chan:%d Rate:%d")
                                  , "WAV"
                                  , (int)bits
                                  , (int)channels
                                  , (int)samplerate
                                  );
       }

       p_print_time_label(lbl_time, tmsec);
       p_print_time_label(lbl_time0, tmsec);
     }
     else
     {
       g_snprintf(txt, sizeof(txt), _("UNKNOWN (using sox)"));
     }
  }

  gtk_label_set_text(lbl_info, txt);
  return (samplerate);
}  /* end p_update_aud_info */

/* ----------------------------------------
 * gap_cme_gui_upd_vid_extension
 * ----------------------------------------
 */
void
gap_cme_gui_upd_vid_extension (GapCmeGlobalParams *gpp)
{
  gchar *l_vid;
  gint   l_idx;
  char *videoname;

 l_vid = g_strdup(gpp->val.videoname);
 for(l_idx = strlen(l_vid) -1;  l_idx > 0; l_idx--)
 {
   if(l_vid[l_idx] == '.')
   {
      l_vid[l_idx] = '\0';
      break;
   }
 }
 videoname = g_strdup_printf("%s%s", l_vid, &gpp->val.ecp_sel.video_extension[0]);
 g_snprintf(gpp->val.videoname, sizeof(gpp->val.videoname), "%s", videoname);

 if(gpp->cme__entry_video != NULL)
 {
   gtk_entry_set_text(GTK_ENTRY(gpp->cme__entry_video), videoname);
 }
 
 if(gpp->cme__short_description != NULL)
 {
   gtk_label_set_text(GTK_LABEL(gpp->cme__short_description)
                  , &gpp->val.ecp_sel.short_description[0]);
 }

 g_free(l_vid);
 g_free(videoname);
}  /* end gap_cme_gui_upd_vid_extension */

/* ----------------------------------------
 * gap_cme_gui_upd_wgt_sensitivity
 * ----------------------------------------
 */
void
gap_cme_gui_upd_wgt_sensitivity (GapCmeGlobalParams *gpp)
{
  gboolean   sensitive;

  sensitive = FALSE;
  if(gpp->val.audioname1[0] != '\0')
  {
    if(g_file_test(gpp->val.audioname1, G_FILE_TEST_EXISTS))
    {
      sensitive = TRUE;
    }
  }

  gtk_widget_set_sensitive(gpp->cme__spinbutton_samplerate, sensitive);
  gtk_widget_set_sensitive(gpp->cme__button_gen_tmp_audfile, sensitive);

  sensitive = FALSE;
  if(gpp->val.ecp_sel.gui_proc[0] != '\0')
  {
      sensitive = TRUE;
  }

  gtk_widget_set_sensitive(gpp->cme__button_params, sensitive);

  sensitive = FALSE;
  if(gpp->val.storyboard_file[0] != '\0')
  {
    if(g_file_test(gpp->val.storyboard_file, G_FILE_TEST_EXISTS))
    {
      t_global_stb         *gstb;

      /* check if storyboard file is valid and has audio */
      gstb = &global_stb;
      if((gstb->aud_total_sec > 0.0)
      && (gstb->vidhand_open_ok))
      {
        sensitive = TRUE;
      }
    }
  }
  gtk_widget_set_sensitive(gpp->cme__button_stb_audio, sensitive);

}  /* end gap_cme_gui_upd_wgt_sensitivity */

/* ----------------------------------------
 * gap_cme_gui_update_aud_labels
 * ----------------------------------------
 */
void
gap_cme_gui_update_aud_labels (GapCmeGlobalParams *gpp)
{
  GtkLabel *lbl_tmp_audfile;
  GtkLabel *lbl_info;
  GtkLabel *lbl_info_tmp;
  GtkLabel *lbl_time;
  GtkLabel *lbl_time0;
  GtkLabel *lbl_time_tmp;

  lbl_info  = GTK_LABEL(gpp->cme__label_aud1_info);
  lbl_time  = GTK_LABEL(gpp->cme__label_aud1_time);
  lbl_time0 = GTK_LABEL(gpp->cme__label_aud0_time);
  lbl_time_tmp = GTK_LABEL(gpp->cme__label_aud_tmp_time);
  lbl_info_tmp = GTK_LABEL(gpp->cme__label_aud_tmp_info);
  lbl_tmp_audfile = GTK_LABEL(gpp->cme__label_tmp_audfile);

  if ((lbl_info != NULL)
  &&  (lbl_time != NULL)
  &&  (lbl_time0 != NULL)
  &&  (lbl_time_tmp != NULL)
  &&  (lbl_info_tmp != NULL)
  &&  (lbl_tmp_audfile != NULL))
  {
    gtk_label_set_text(lbl_info, " ");

    gpp->val.wav_samplerate1  =
    p_update_aud_info(gpp, lbl_info, lbl_time, lbl_time0, gpp->val.audioname1);
 

    gtk_label_set_text(lbl_time_tmp, " ");
    gtk_label_set_text(lbl_info_tmp, " ");
    gtk_label_set_text(lbl_tmp_audfile, " ");

    if(gpp->val.tmp_audfile[0] != '\0')
    {
      if(g_file_test(gpp->val.tmp_audfile, G_FILE_TEST_EXISTS))
      {
         gpp->val.wav_samplerate_tmp =
         p_update_aud_info(gpp, lbl_info_tmp, lbl_time_tmp, lbl_time0, gpp->val.tmp_audfile);
         gtk_label_set_text(lbl_tmp_audfile, gpp->val.tmp_audfile);
      }
    }
  }
  gap_cme_gui_upd_wgt_sensitivity (gpp);
}  /* end gap_cme_gui_update_aud_labels */


/* ----------------------------------------
 * gap_cme_gui_update_vid_labels
 * ----------------------------------------
 */
void
gap_cme_gui_update_vid_labels (GapCmeGlobalParams *gpp)
{
  GtkLabel   *lbl;
  gint32      tmsec;        /* audioplaytime in milli secs */
  gint32      first_offset;
  gint32      range_from;
  gint32      range_to;
  gdouble     msec_per_frame;

  if(gpp->val.framerate > 0)
  {
    msec_per_frame = 1000.0 / gpp->val.framerate;
  }
  else
  {
    msec_per_frame = 1000.0;
  }

  first_offset = gpp->ainfo.first_frame_nr;
  range_from = gpp->val.range_from;
  range_to = gpp->val.range_to;

  if(gpp->val.input_mode == GAP_RNGTYPE_STORYBOARD)
  {
    first_offset = MIN(1, MIN(range_from, range_to));
  }
  if(gpp->val.input_mode == GAP_RNGTYPE_LAYER)
  {
    range_from = gpp->val.range_to;
    range_to = gpp->val.range_from;
    first_offset = 0;
  }

  lbl = GTK_LABEL(gpp->cme__label_fromtime);
  tmsec = (range_from - first_offset) * msec_per_frame;
  p_print_time_label(lbl, tmsec);

  lbl = GTK_LABEL(gpp->cme__label_totime);
  tmsec = (range_to - first_offset) * msec_per_frame;
  p_print_time_label(lbl, tmsec);

  lbl = GTK_LABEL(gpp->cme__label_totaltime);
  tmsec = abs(gpp->val.range_to - gpp->val.range_from) * msec_per_frame;
  p_print_time_label(lbl, tmsec);
}  /* end gap_cme_gui_update_vid_labels */


/* ----------------------------------------
 * gap_cme_gui_util_sox_widgets
 * ----------------------------------------
 */
void
gap_cme_gui_util_sox_widgets (GapCmeGlobalParams *gpp)
{
  GtkEntry *entry;

  if(gap_debug) printf("gap_cme_gui_util_sox_widgets\n");

  entry = GTK_ENTRY(gpp->cme__entry_sox);
  if(entry != NULL)
  {
    gtk_entry_set_text(entry, gpp->val.util_sox);
  }

  entry = GTK_ENTRY(gpp->cme__entry_sox_options);
  if(entry != NULL)
  {
    gtk_entry_set_text(entry, gpp->val.util_sox_options);
  }
}  /* end gap_cme_gui_util_sox_widgets */


/* ----------------------------------------
 * p_range_widgets_set_limits
 * ----------------------------------------
 */
static void
p_range_widgets_set_limits(GapCmeGlobalParams *gpp
                          , gint32 lower_limit
                          , gint32 upper_limit
                          , GapLibTypeInputRange range_type)
{
  GtkAdjustment *adj;
  gchar *lbl_text;
  gchar *range_text;

  if(gap_debug)
  {
    printf("(++)p_range_widgets_set_limits lower_limit:%d upper_limit:%d input_mode:%d\n"
       , (int)lower_limit
       , (int)upper_limit
       , (int)range_type
       );
  }

  /* constraint range into lower_limit / upper_limit */
  /*
   * gpp->val.range_from = MAX(lower_limit, gpp->val.range_from);
   * gpp->val.range_from = MIN(upper_limit, gpp->val.range_from);
   * gpp->val.range_to = MAX(lower_limit, gpp->val.range_to);
   * gpp->val.range_to = MIN(upper_limit, gpp->val.range_to);
   */
  if(range_type == GAP_RNGTYPE_LAYER)
  {
    /* invers range for encoding Multilayer images
     * (top layer is usually the last frame but has index 0 in gimp images)
     */
    gpp->val.range_from = upper_limit;
    gpp->val.range_to = lower_limit;
  }
  else
  {
    gpp->val.range_from = lower_limit;
    gpp->val.range_to = upper_limit;
  }

  /* update spinbutton limits and values */
  adj = GTK_ADJUSTMENT(gpp->cme__spinbutton_from_adj);
  adj->lower = (gfloat) lower_limit;
  adj->upper = (gfloat) upper_limit;
  gtk_adjustment_set_value(adj, (gfloat)gpp->val.range_from);

  adj = GTK_ADJUSTMENT(gpp->cme__spinbutton_to_adj);
  adj->lower = (gfloat) lower_limit;
  adj->upper = (gfloat) upper_limit;
  gtk_adjustment_set_value(adj, (gfloat)gpp->val.range_to);

  switch(range_type)
  {
    case GAP_RNGTYPE_STORYBOARD:
      range_text = g_strdup(_("Storyframe"));
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gpp->cme__radio_button_storyboard), TRUE);
      break;
    case GAP_RNGTYPE_LAYER:
      range_text = g_strdup(_("Layer"));
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gpp->cme__radio_button_layer), TRUE);
      break;
    default:
      range_text = g_strdup(_("Frame"));
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gpp->cme__radio_button_frame), TRUE);
      break;
  }

  /* label changes dependent from rangetype "From Frame", "From Layer" or "From Storyframe" */
  if(gpp->cme__label_from != NULL)
  {
    lbl_text = g_strdup_printf(_("From %s:"),  range_text);
    gtk_label_set_text(GTK_LABEL(gpp->cme__label_from), lbl_text);
    g_free(lbl_text);
  }

  if(gpp->cme__label_to != NULL)
  {
    lbl_text = g_strdup_printf(_("To %s:"),  range_text);
    gtk_label_set_text(GTK_LABEL(gpp->cme__label_to), lbl_text);
    g_free(lbl_text);
  }

  g_free(range_text);

  gap_cme_gui_update_vid_labels (gpp);
  gap_cme_gui_update_aud_labels (gpp);
}       /* end p_range_widgets_set_limits */

/* ----------------------------------------
 * p_init_shell_window_widgets
 * ----------------------------------------
 */
static void
p_init_shell_window_widgets (GapCmeGlobalParams *gpp)
{
 if(gap_debug) printf("p_init_shell_window_widgets: Start INIT\n");

 /* put initial values to the widgets */

 /* widgets "cme__spinbutton_from" and "cme__spinbutton_to" */
 {
   GapLibTypeInputRange l_rangetype;
   gint32  l_first_frame_limit;
   gint32  l_last_frame_nr;

   p_get_range_and_type (gpp, &l_first_frame_limit, &l_last_frame_nr, &l_rangetype);
   gpp->val.input_mode     = l_rangetype;

   p_range_widgets_set_limits(gpp
                             , l_first_frame_limit
                             , l_last_frame_nr
                             , l_rangetype
                             );
 }

 gtk_adjustment_set_value(GTK_ADJUSTMENT(gpp->cme__spinbutton_framerate_adj)
                         , (gfloat)gpp->val.framerate);
 gtk_adjustment_set_value(GTK_ADJUSTMENT(gpp->cme__spinbutton_samplerate_adj)
                         , (gfloat)gpp->val.samplerate);
 gtk_adjustment_set_value(GTK_ADJUSTMENT(gpp->cme__spinbutton_width_adj)
                         , (gfloat)gpp->val.vid_width);
 gtk_adjustment_set_value(GTK_ADJUSTMENT(gpp->cme__spinbutton_height_adj)
                         , (gfloat)gpp->val.vid_height);

 if(gpp->cme__entry_video != NULL)
 {
   gtk_entry_set_text(GTK_ENTRY(gpp->cme__entry_video), gpp->val.videoname);
 }
 if(gpp->cme__entry_audio1 != NULL)
 {
   gtk_entry_set_text(GTK_ENTRY(gpp->cme__entry_audio1), gpp->val.audioname1);
 }
 if (gpp->cme__entry_mac != NULL)
 {
   gtk_entry_set_text(GTK_ENTRY(gpp->cme__entry_mac), gpp->val.filtermacro_file);
 }

 gap_cme_gui_update_aud_labels (gpp);
 gap_cme_gui_update_vid_labels (gpp);

 /* dynamic combo for all encoders that are registered at runtime */
 p_replace_combo_encodername(gpp);
 gap_cme_gui_util_sox_widgets(gpp);
}    /* end p_init_shell_window_widgets */


/* ------------------
 * p_status_progress
 * ------------------
 */
static void
p_status_progress(GapCmeGlobalParams *gpp, t_global_stb *gstb)
{
  GtkWidget  *pbar;
  GtkWidget  *status_lbl;
  /* storyboard thread job still running
   * update status, and restart poll timer
   */

  status_lbl = gpp->cme__label_status;
  if(status_lbl)
  {
    gtk_label_set_text(GTK_LABEL(status_lbl), gstb->status_msg);
  }

  pbar = gpp->cme__progressbar_status;
  if(pbar)
  {
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (pbar), gstb->progress);
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pbar), gstb->status_msg);
  }

  if(gap_debug) printf("progress: %f\n", (float)gstb->progress );
}  /* end p_status_progress */


/* ------------------------
 * p_storybord_job_finished
 * ------------------------
 * This is called from polling_timer
 * when the storyboard thread has finished
 *
 *  print storyboard parse report, update widgets
 *
 *   check if storyboard open was successful,
 *   if successful, set lower and upper limit of the range spinbutton widgets
 *   to 1 and the total number of frames found in the storyboard_file.
 *
 *   if no storyboard file exists then use the first/last frame_nr from the ainfo structure
 *   that describes the animation frames from the invoking image_frame.
 */
static void
p_storybord_job_finished(GapCmeGlobalParams *gpp, t_global_stb *gstb)
{
  char *l_msg;
  char *l_framerate_info;
  char *l_size_info;
  char *l_playtime_info;
  gdouble l_vid_total_sec;



  if(gap_debug)
  {
    printf("p_storybord_job_finished: START\n");
  }

  gstb->progress = 1.0;
  g_snprintf(gstb->status_msg, sizeof(gstb->status_msg), _("ready"));
  p_status_progress(gpp, gstb);

#ifdef GAP_USE_GTHREAD
   /* is the encoder specific gui_thread still open ? */
   if(gpp->val.gui_proc_thread)
   {
      /* wait until thread exits */
      if(gap_debug)
      {
        printf("p_storybord_job_finished: before g_thread_join\n");
      }

      g_thread_join(gpp->val.gui_proc_thread);

      if(gap_debug)
      {
        printf("p_storybord_job_finished: after g_thread_join\n");
      }
      gpp->val.gui_proc_thread = NULL;
   }
#endif

  l_vid_total_sec = 0.0;
  if(gstb->vidhand_open_ok)
  {
    if(gstb->framerate != 0.0)
    {
       l_framerate_info = g_strdup_printf(_("using master_framerate %2.2f found in file")
                                         ,(float)gstb->framerate);
       gtk_adjustment_set_value(GTK_ADJUSTMENT(gpp->cme__spinbutton_framerate_adj)
                                , (gfloat)gstb->framerate);
       gpp->val.framerate = gstb->framerate;

    }
    else
    {
       l_framerate_info = g_strdup_printf(_("file has no master_framerate setting"));
    }
    if(gpp->val.framerate > 0)
    {
      l_vid_total_sec = gpp->val.storyboard_total_frames / gpp->val.framerate;
    }

    if(gstb->aud_total_sec > 0.0)
    {
      if(gstb->composite_audio[0] != '\0')
      {
         if(g_file_test(gstb->composite_audio, G_FILE_TEST_EXISTS))
         {
            GtkEntry *entry;

            g_snprintf(gpp->val.audioname1, sizeof(gpp->val.audioname1), "%s"
                      , gstb->composite_audio);
            gpp->val.audioname_ptr = &gpp->val.audioname1[0];
            entry = GTK_ENTRY(gpp->cme__entry_audio1);
            if(entry)
            {
              gtk_entry_set_text(entry, gstb->composite_audio);
            }

            gstb->composite_audio[0] = '\0';
         }
      }

      l_playtime_info = g_strdup_printf(_("composite video track playtime %.3fsec (%d frames)\ncomposite audiotrack playtime %.3f secs")
                                           , (float)l_vid_total_sec
                                           , (int) gpp->val.storyboard_total_frames
                                           , (float)gstb->aud_total_sec
                                           );
    }
    else
    {
      l_playtime_info = g_strdup_printf(_("composite video track playtime %.3fsec (%d frames)\nhas NO audiotracks")
                                           , (float)l_vid_total_sec
                                           , (int) gpp->val.storyboard_total_frames
                                           );
    }

    if(gstb->master_width != 0)
    {
       l_size_info = g_strdup_printf(_("using master_size %d x %d found in file")
                                         ,(int)gstb->master_width
                                         ,(int)gstb->master_height);
       gtk_adjustment_set_value(GTK_ADJUSTMENT(gpp->cme__spinbutton_width_adj)
                               , (gfloat)gstb->master_width);

       gtk_adjustment_set_value(GTK_ADJUSTMENT(gpp->cme__spinbutton_height_adj)
                               , (gfloat)gstb->master_height);
       gpp->val.vid_width = gstb->master_width;
       gpp->val.vid_height = gstb->master_height;
    }
    else
    {
       l_size_info = g_strdup_printf(_("file has no master_size setting"));
    }

   if(gstb->errtext)
   {
       if(gstb->warntext)
       {
         l_msg = g_strdup_printf(_("Storyboard file %s checkreport:\n\n%s\n%s\n%s\n\n%s\n[%d:] %s\n\n%s\n[%d:] %s")
                                 , " " /* gpp->val.storyboard_file */
                                 , l_playtime_info
                                 , l_size_info
                                 , l_framerate_info
                                 , gstb->errtext
                                 , (int)gstb->errline_nr
                                 , gstb->errline
                                 , gstb->warntext
                                 , (int)gstb->warnline_nr
                                 , gstb->warnline
                                 );
       }
       else
       {
         l_msg = g_strdup_printf(_("Storyboard file %s checkreport:\n\n%s\n%s\n%s\n\n%s\n[%d:] %s")
                                 , " " /* gpp->val.storyboard_file */
                                 , l_playtime_info
                                 , l_size_info
                                 , l_framerate_info
                                 , gstb->errtext
                                 , (int)gstb->errline_nr
                                 , gstb->errline
                                 );
       }
    }
    else
    {
       if(gstb->warntext)
       {
         l_msg = g_strdup_printf(_("Storyboard file %s checkreport:\n\n%s\n%s\n%s\n\n%s\n[%d:] %s")
                                 , " " /* gpp->val.storyboard_file */
                                 , l_playtime_info
                                 , l_size_info
                                 , l_framerate_info
                                 , gstb->warntext
                                 , (int)gstb->warnline_nr
                                 , gstb->warnline
                                 );
       }
       else
       {
         l_msg = g_strdup_printf(_("Storyboard file %s checkreport:\n\n%s\n%s\n%s\n\nno errors found, file is OK")
                                 ,  " " /* gpp->val.storyboard_file */
                                 , l_playtime_info
                                 , l_size_info
                                 , l_framerate_info
                                );
       }
    }
    g_free(l_size_info);
    g_free(l_framerate_info);
  }
  else
  {
     l_msg = g_strdup_printf(_("Storyboard file %s checkreport:\n\nSYNTAX check failed (internal error occurred)")
                               , gpp->val.storyboard_file
                                 );
  }

  /* info window of storyboard parsing report */
  /* g_message(l_msg); */
  p_print_storyboard_text_label(gpp, l_msg);

  gstb->progress = 0.0;
  g_snprintf(gstb->status_msg, sizeof(gstb->status_msg), _("ready"));
  p_status_progress(gpp, gstb);

  if(gap_debug)
  {
    printf("p_storybord_job_finished:\nMSG: %s\n", l_msg);
    printf("(##) first:%d last:%d input_mode:%d\n"
       , (int)gstb->first_frame_limit
       , (int)gstb->last_frame_nr
       , (int)gpp->val.input_mode
       );
  }

  g_free(l_msg);

  p_range_widgets_set_limits(gpp
                             , gstb->first_frame_limit
                             , gstb->last_frame_nr
                             , gpp->val.input_mode
                             );

  gap_cme_gui_upd_wgt_sensitivity(gpp);

}  /* end p_storybord_job_finished */

/* -----------------------------
 * gap_cme_gui_remove_poll_timer
 * -----------------------------
 */
void
gap_cme_gui_remove_poll_timer(GapCmeGlobalParams *gpp)
{
  t_global_stb *gstb;

  gstb = &global_stb;

  if(gstb->poll_timertag >= 0)
  {
    g_source_remove(gstb->poll_timertag);
    gstb->poll_timertag = -1;
  }
}  /* end gap_cme_gui_remove_poll_timer */


/* ------------------
 * on_timer_poll
 * ------------------
 * This timer callback is called periodical
 * (The poll timer is restarted at each call with intervall of 1/4 sec)
 */
static void
on_timer_poll(gpointer   user_data)
{
  t_global_stb *gstb;
  GapCmeGlobalParams *gpp;

  if(gap_debug) printf("\non_timer_poll: START\n");

  gstb = (t_global_stb *)user_data;
  gpp = gap_cme_main_get_global_params();

  if(gstb)
  {
     g_source_remove(gstb->poll_timertag);
     if(gstb->stb_job_done)
     {
       gstb->poll_timertag = -1;
       gstb->stb_job_done = FALSE;
       p_storybord_job_finished(gpp, gstb);
     }
     else
     {
       if(gstb->poll_timertag >= 0)
       {
          /* storyboard thread job still running
          * update status, and restart poll timer
          */
          p_status_progress(gpp, gstb);

          gstb->poll_timertag =
            (gint32) g_timeout_add (500, (GSourceFunc)on_timer_poll, gstb);
       }
     }
  }
}  /* end on_timer_poll */



/* ----------------------------------------
 * p_thread_storyboard_file
 * ----------------------------------------
 * p_thread_storyboard_file
 *   check if storyboard exists,
 *   if exists, set lower and upper limit of the range spinbutton widgets
 *   to 1 and the total number of frames found in the storyboard_file.
 *
 *   if no storyboard file exists then use the first/last frame_nr from the ainfo structure
 *   that describes the animation frames from the invoking image_frame.
 */
static gpointer
p_thread_storyboard_file(gpointer data)
{
  GapCmeGlobalParams   *gpp;
  t_global_stb         *gstb;
  GapGveStoryVidHandle *vidhand;
  gint32                l_first_frame_limit;
  gint32                l_last_frame_nr;
  GapLibTypeInputRange  l_rangetype;
  gdouble               l_aud_total_sec;
  gboolean              l_create_audio_tmp_files;

  gpp = gap_cme_main_get_global_params();

  if(gap_debug)
  {
    printf("THREAD: p_thread_storyboard_file &gpp: %d\n", (int)gpp);
  }

  gstb = &global_stb;
  gstb->total_stroyboard_frames = 0;

  p_get_range_and_type (gpp, &l_first_frame_limit, &l_last_frame_nr, &l_rangetype);


  gstb->vidhand_open_ok = FALSE;

  l_create_audio_tmp_files = FALSE;
  if(gpp->storyboard_create_composite_audio)
  {
    l_create_audio_tmp_files = TRUE;
  }

  vidhand = gap_gve_story_open_extended_video_handle
           ( FALSE   /* dont ignore video */
           , FALSE   /* dont ignore audio */
           , l_create_audio_tmp_files
           , &gstb->progress
           , &gstb->status_msg[0]
           , sizeof(gstb->status_msg)
           , GAP_RNGTYPE_STORYBOARD
           , NULL      /* use no imagename */
           , gpp->val.storyboard_file
           , NULL      /* use no basename */
           , NULL      /* use no extension */
           , -1        /* frame_from */
           , 999999    /* frame_to */
           , &gpp->val.storyboard_total_frames
           );

  if(vidhand)
  {
    gstb->vidhand_open_ok = TRUE;
    gap_gve_story_set_audio_resampling_program(vidhand
                       , gpp->val.util_sox
                       , gpp->val.util_sox_options
                       );

    if(vidhand->master_framerate != 0.0)
    {
        gpp->val.framerate = vidhand->master_framerate;
        gstb->framerate = vidhand->master_framerate;

    }


    gap_gve_story_calc_audio_playtime(vidhand, &l_aud_total_sec);
    gstb->aud_total_sec = l_aud_total_sec;

    if((gpp->storyboard_create_composite_audio)
    && (l_aud_total_sec > 0.0))
    {
      char *l_composite_audio;

      if(gap_debug) gap_gve_story_debug_print_audiorange_list(vidhand->aud_list, -1);

      /* name for the composite audio that should be created */
      l_composite_audio = g_strdup_printf("%s_composite_audio.wav", gpp->val.storyboard_file);


      gstb->composite_audio[0] = '\0';
      if(l_composite_audio)
      {
         gap_gve_story_create_composite_audiofile(vidhand, l_composite_audio);
         if(g_file_test(l_composite_audio, G_FILE_TEST_EXISTS))
         {
            g_snprintf(gstb->composite_audio, sizeof(gstb->composite_audio)
                      , "%s"
                      ,l_composite_audio
                      );

            if(gap_debug) gap_gve_story_debug_print_audiorange_list(vidhand->aud_list, -1);
            gap_gve_story_drop_audio_cache();
         }
         g_free(l_composite_audio);
      }
      gap_gve_story_remove_tmp_audiofiles(vidhand);

    }

    gstb->master_width = vidhand->master_width;
    gstb->master_height = vidhand->master_height;


    gstb->errtext = NULL;
    gstb->errline = NULL;
    gstb->warntext = NULL;
    gstb->warnline = NULL;

    if(vidhand->sterr->errtext)
    {
      gstb->errline_nr = vidhand->sterr->errline_nr;
      gstb->errtext = g_strdup(vidhand->sterr->errtext);
      gstb->errline = g_strdup(vidhand->sterr->errline);
    }
    if(vidhand->sterr->warntext)
    {
      gstb->warnline_nr = vidhand->sterr->warnline_nr;
      gstb->warntext = g_strdup(vidhand->sterr->warntext);
      gstb->warnline = g_strdup(vidhand->sterr->warnline);
    }

    if(vidhand->frn_list)
    {
        l_first_frame_limit = 1;
        l_last_frame_nr = gpp->val.storyboard_total_frames;
        l_rangetype = GAP_RNGTYPE_STORYBOARD;
        gstb->total_stroyboard_frames = gpp->val.storyboard_total_frames;
    }
    gap_gve_story_close_vid_handle(vidhand);
  }

  gstb->first_frame_limit = l_first_frame_limit;
  gstb->last_frame_nr     = l_last_frame_nr;
  gpp->val.input_mode     = l_rangetype;

  if(gap_debug)
  {
    printf("THREAD storyboard TERMINATING: tid:%d first:%d last:%d input_mode:%d\n"
       , (int)gpp->val.gui_proc_thread
       , (int)gstb->first_frame_limit
       , (int)gstb->last_frame_nr
       , (int)gpp->val.input_mode
       );
  }

  gstb->stb_job_done = TRUE;
  /* gpp->val.gui_proc_thread = NULL; */

  return (NULL);
} /* end p_thread_storyboard_file */



/* ----------------------------------------
 * gap_cme_gui_check_storyboard_file
 * ----------------------------------------
 */
void
gap_cme_gui_check_storyboard_file(GapCmeGlobalParams *gpp)
{
   gboolean joinable;
   t_global_stb    *gstb;
  gint32 l_first_frame_limit;
  gint32 l_last_frame_nr;
  GapLibTypeInputRange l_rangetype;

  gstb = &global_stb;
  p_get_range_and_type (gpp, &l_first_frame_limit, &l_last_frame_nr, &l_rangetype);

  gstb->total_stroyboard_frames = 0;
  gstb->first_frame_limit  = l_first_frame_limit;
  gstb->last_frame_nr      = l_last_frame_nr;
  gpp->val.input_mode      = l_rangetype;
  gstb->composite_audio[0] = '\0';
  gstb->aud_total_sec      = 0.0;

  p_range_widgets_set_limits(gpp
                             , l_first_frame_limit
                             , l_last_frame_nr
                             , l_rangetype
                             );

  if(gpp->ecp == NULL)
  {
    return;
  }


  if(gpp->val.storyboard_file[0] == '\0')
  {
    p_print_storyboard_text_label(gpp, NULL);
    return;
  }
  if(!g_file_test(gpp->val.storyboard_file, G_FILE_TEST_EXISTS))
  {
    p_print_storyboard_text_label(gpp, NULL);
     return;
  }



#ifdef GAP_USE_GTHREAD
  if(gap_cme_gui_check_gui_thread_is_active(gpp))  { return; }
  if(gstb->poll_timertag >= 0)           { return; }

  /* g_message(_("Go for checking storyboard file")); */
  p_print_storyboard_text_label(gpp, _("Checking Storyboard File") );

  gstb->progress = 0.0;
  g_snprintf(gstb->status_msg, sizeof(gstb->status_msg), _("Parsing Storyboardfile"));

  gstb->stb_job_done  = FALSE;

  /* start a thread for asynchron PDB call of the gui_ procedure
   */
  if(gap_debug) printf("MASTER: Before storyborad g_thread_create\n");

  joinable = TRUE;
  gpp->val.gui_proc_thread =
      g_thread_create((GThreadFunc)p_thread_storyboard_file
                     , NULL  /* data */
                     , joinable
                     , NULL  /* GError **error (NULL dont report errors) */
                     );

  if(gap_debug) printf("MASTER: After storyborad g_thread_create\n");

  /* start poll timer to update progress and notify when storyboard job finished */
  gstb->poll_timertag =
    (gint32) g_timeout_add(500, (GSourceFunc) on_timer_poll, gstb);


#else
  /* if threads are not used simply call the procedure
   * (the common GUI window is not refreshed until the called gui_proc ends)
   */
  {
    gboolean do_processing;

    do_processing = TRUE;

    /* if storyboard_create_composite_audio button was pressed
     * there is no need for extra pop-up dialog
     * before start processing
     */
    if (!gpp->storyboard_create_composite_audio)
    {
      static GapArrArg  argv[1];

      do_processing = FALSE;

      gap_arr_arg_init(&argv[0], GAP_ARR_WGT_LABEL);
      argv[0].label_txt = _("Go for checking storyboard file");

      if(gap_arr_ok_cancel_dialog(_("Storyboardfile Check")
                               ,_("Storyboardfile Check")
                               ,1
                               ,argv
                               ))
      {
        do_processing = TRUE;
      }
    }

    if(do_processing)
    {
      p_thread_storyboard_file(NULL);
      p_storybord_job_finished(gpp, gstb);
    }
  }
#endif


}  /* end gap_cme_gui_check_storyboard_file */



/* ----------------------------------------
 * gap_cme_gui_check_encode_OK
 * ----------------------------------------
 *
 *   check the (dialog) parameters if everything is OK
 *   this is done before we can start encoding
 *
 *   return  TRUE  .. OK
 *           FALSE .. in case of Error
 */
gboolean
gap_cme_gui_check_encode_OK (GapCmeGlobalParams *gpp)
{
  gchar       *l_msg;
  long        samplerate, samplerate2;
  long        channels;
  long        bytes_per_sample;
  long        bits, bits2;
  long        samples;
  gint         l_rc;
  gint32      tmsec;        /* audioplaytime in milli secs */

  samplerate = 0;
  samplerate2 = 0;
  bits = 16;
  bits2 = 16;

  if(gap_debug) printf("gap_cme_gui_check_encode_OK: Start\n");

  if(gpp->val.gui_proc_thread)
  {
     p_gap_message(_("Encoder specific parameter window is still open" ));
     return (FALSE);
  }

  if(gpp->val.input_mode == GAP_RNGTYPE_STORYBOARD )
  {
    if((!g_file_test(gpp->val.storyboard_file, G_FILE_TEST_EXISTS))
    || (gpp->val.storyboard_total_frames < 1))
    {
      p_gap_message(_("ERROR: No valid storyboardfile was specified.\n"
                      "(a storyboard file can be specified in the extras tab)"));
      return (FALSE);
    }
  }

  if ((strcmp(gpp->val.ecp_sel.vid_enc_plugin, GAP_PLUGIN_NAME_MPG2_ENCODE) == 0)
  ||  (strcmp(gpp->val.ecp_sel.vid_enc_plugin, GAP_PLUGIN_NAME_MPG1_ENCODE) == 0))
  {
    if(((gpp->val.vid_width % 16)  != 0)
    || ((gpp->val.vid_height % 16)  != 0))
    {
      l_msg = g_strdup_printf(_("Error:\nfor MPEG width and height must be a multiple of 16\n"
                         "set Width to %d\n"
                         "set Height to %d")
                         , (int)(gpp->val.vid_width / 16) * 16
                         , (int)(gpp->val.vid_height / 16) * 16
                         );
      g_message("%s", l_msg);
      g_free(l_msg);
      return (FALSE);
    }
  }

  if(g_file_test(gpp->val.audioname1, G_FILE_TEST_EXISTS))
  {
     tmsec = 0;
     l_rc = gap_audio_wav_file_check(gpp->val.audioname1
                     , &samplerate, &channels
                     , &bytes_per_sample, &bits, &samples);

     if(l_rc == 0)
     {
       if((bits != 8) && (bits != 16))
       {
         l_msg = g_strdup_printf(_("Error: Unsupported Bit per Sample %d\n"
                            "file: %s\n"
                            "supported are 8 or 16 Bit")
                            , (int)bits
                            , gpp->val.audioname1
                            );
         g_message("%s", l_msg);
         g_free(l_msg);
         return (FALSE);
       }

       if((samplerate > 0) && (channels > 0))
       {
         tmsec = ((samples / channels) * 1000) / samplerate;
       }
     }
  }
  else
  {
    if(gpp->val.audioname1[0] != '\0')
    {
         l_msg = g_strdup_printf(_("Error: Audiofile not found\n"
                            "file: %s\n")
                            , gpp->val.audioname1
                            );
         g_message("%s", l_msg);
         g_free(l_msg);
         return (FALSE);
    }
  }

  if(gpp->val.audioname1[0] != '\0')
  {
    if (strcmp(gpp->val.ecp_sel.vid_enc_plugin, GAP_PLUGIN_NAME_MPG1_ENCODE) == 0)
    {
      switch(gpp->val.samplerate)
      {
         case 22050:
         case 24000:
         case 32000:
         case 44100:
         case 48000:
             break;
         default:
             l_msg = g_strdup_printf(_("Error: Unsupported Samplerate for MPEG1 Layer2 Audio Encoding\n"
                                "current rate: %d\n"
                                "supported rates: \n"
                                " 22050, 24000, 32000, 44100, 48000")
                                , (int)gpp->val.samplerate);
             g_message("%s", l_msg);
             g_free(l_msg);
             return (FALSE);
             break;
      }
    }


    if (strcmp(gpp->val.ecp_sel.vid_enc_plugin, GAP_PLUGIN_NAME_MPG2_ENCODE) == 0)
    {
      switch(gpp->val.samplerate)
      {
         case 8000:
         case 11025:
         case 12000:
         case 16000:
         case 22050:
         case 24000:
         case 32000:
         case 44100:
         case 48000:
             break;
         default:
             l_msg = g_strdup_printf(_("Error: Unsupported Samplerate for MPEG2 Layer3 Audio Encoding\n"
                                "current rate: %d\n"
                                "supported rates:\n"
                                " 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000")
                                , (int)gpp->val.samplerate);
             g_message("%s", l_msg);
             g_free(l_msg);
             return (FALSE);
             break;
      }
    }
  }

  if(g_file_test(gpp->val.videoname, G_FILE_TEST_EXISTS))
  {
    if(p_overwrite_dialog(gpp, gpp->val.videoname, 0) < 0)
    {
      return (FALSE);
    }
  }

  if(0 != gap_gve_sox_chk_and_resample(&gpp->val))
  {
     g_message(_("Can't process the audio input file."
                 " You should check audio options and audio tool configuration"));
     return (FALSE);
  }

  if(gap_debug) printf("gap_cme_gui_check_encode_OK: End OK\n");
  return (TRUE); /* OK */
}  /* end gap_cme_gui_check_encode_OK */


/* ----------------------------------------
 * gap_cme_gui_create_fss__fileselection
 * ----------------------------------------
 */
GtkWidget*
gap_cme_gui_create_fss__fileselection (GapCmeGlobalParams *gpp)
{
  GtkWidget *fss__fileselection;
  GtkWidget *fss__button_OK;
  GtkWidget *fss__button_cancel;

  fss__fileselection = gtk_file_selection_new (_("Select Storyboardfile"));
  gtk_container_set_border_width (GTK_CONTAINER (fss__fileselection), 10);

  fss__button_OK = GTK_FILE_SELECTION (fss__fileselection)->ok_button;
  gtk_widget_show (fss__button_OK);
  GTK_WIDGET_SET_FLAGS (fss__button_OK, GTK_CAN_DEFAULT);

  fss__button_cancel = GTK_FILE_SELECTION (fss__fileselection)->cancel_button;
  gtk_widget_show (fss__button_cancel);
  GTK_WIDGET_SET_FLAGS (fss__button_cancel, GTK_CAN_DEFAULT);

  g_signal_connect (G_OBJECT (fss__fileselection), "destroy",
                      G_CALLBACK (on_fss__fileselection_destroy),
                      gpp);
  g_signal_connect (G_OBJECT (fss__button_OK), "clicked",
                      G_CALLBACK (on_fss__button_OK_clicked),
                      gpp);
  g_signal_connect (G_OBJECT (fss__button_cancel), "clicked",
                      G_CALLBACK (on_fss__button_cancel_clicked),
                      gpp);

  return fss__fileselection;
}  /* end gap_cme_gui_create_fss__fileselection */


/* ----------------------------------------
 * gap_cme_gui_create_fsv__fileselection
 * ----------------------------------------
 */
GtkWidget*
gap_cme_gui_create_fsv__fileselection (GapCmeGlobalParams *gpp)
{
  GtkWidget *fsv__fileselection;
  GtkWidget *fsv__button_OK;
  GtkWidget *fsv__button_cancel;

  fsv__fileselection = gtk_file_selection_new (_("Select Videofile"));
  gtk_container_set_border_width (GTK_CONTAINER (fsv__fileselection), 10);

  fsv__button_OK = GTK_FILE_SELECTION (fsv__fileselection)->ok_button;
  gtk_widget_show (fsv__button_OK);
  GTK_WIDGET_SET_FLAGS (fsv__button_OK, GTK_CAN_DEFAULT);

  fsv__button_cancel = GTK_FILE_SELECTION (fsv__fileselection)->cancel_button;
  gtk_widget_show (fsv__button_cancel);
  GTK_WIDGET_SET_FLAGS (fsv__button_cancel, GTK_CAN_DEFAULT);

  g_signal_connect (G_OBJECT (fsv__fileselection), "destroy",
                      G_CALLBACK (on_fsv__fileselection_destroy),
                      gpp);
  g_signal_connect (G_OBJECT (fsv__button_OK), "clicked",
                      G_CALLBACK (on_fsv__button_OK_clicked),
                      gpp);
  g_signal_connect (G_OBJECT (fsv__button_cancel), "clicked",
                      G_CALLBACK (on_fsv__button_cancel_clicked),
                      gpp);

  gtk_widget_grab_default (fsv__button_cancel);
  return fsv__fileselection;
}  /* end gap_cme_gui_create_fsv__fileselection */


/* ----------------------------------------
 * gap_cme_gui_create_fsb__fileselection
 * ----------------------------------------
 */
GtkWidget*
gap_cme_gui_create_fsb__fileselection (GapCmeGlobalParams *gpp)
{
  GtkWidget *fsb__fileselection;
  GtkWidget *fsb__button_OK;
  GtkWidget *fsb__button_cancel;

  fsb__fileselection = gtk_file_selection_new (_("Select Macrofile"));
  gtk_container_set_border_width (GTK_CONTAINER (fsb__fileselection), 10);

  fsb__button_OK = GTK_FILE_SELECTION (fsb__fileselection)->ok_button;
  gtk_widget_show (fsb__button_OK);
  GTK_WIDGET_SET_FLAGS (fsb__button_OK, GTK_CAN_DEFAULT);

  fsb__button_cancel = GTK_FILE_SELECTION (fsb__fileselection)->cancel_button;
  gtk_widget_show (fsb__button_cancel);
  GTK_WIDGET_SET_FLAGS (fsb__button_cancel, GTK_CAN_DEFAULT);

  g_signal_connect (G_OBJECT (fsb__fileselection), "destroy",
                      G_CALLBACK (on_fsb__fileselection_destroy),
                      gpp);
  g_signal_connect (G_OBJECT (fsb__button_OK), "clicked",
                      G_CALLBACK (on_fsb__button_OK_clicked),
                      gpp);
  g_signal_connect (G_OBJECT (fsb__button_cancel), "clicked",
                      G_CALLBACK (on_fsb__button_cancel_clicked),
                      gpp);

  gtk_widget_grab_default (fsb__button_cancel);
  return fsb__fileselection;
}  /* end gap_cme_gui_create_fsb__fileselection */

/* ----------------------------------------
 * gap_cme_gui_create_fsa__fileselection
 * ----------------------------------------
 */
GtkWidget*
gap_cme_gui_create_fsa__fileselection (GapCmeGlobalParams *gpp)
{
  GtkWidget *fsa__fileselection;
  GtkWidget *fsa__button_OK;
  GtkWidget *fsa__button_cancel;

  fsa__fileselection = gtk_file_selection_new (_("Select Audiofilename"));
  gtk_container_set_border_width (GTK_CONTAINER (fsa__fileselection), 10);

  fsa__button_OK = GTK_FILE_SELECTION (fsa__fileselection)->ok_button;
  gtk_widget_show (fsa__button_OK);
  GTK_WIDGET_SET_FLAGS (fsa__button_OK, GTK_CAN_DEFAULT);

  fsa__button_cancel = GTK_FILE_SELECTION (fsa__fileselection)->cancel_button;
  gtk_widget_show (fsa__button_cancel);
  GTK_WIDGET_SET_FLAGS (fsa__button_cancel, GTK_CAN_DEFAULT);

  g_signal_connect (G_OBJECT (fsa__fileselection), "destroy",
                      G_CALLBACK (on_fsa__fileselection_destroy),
                      gpp);
  g_signal_connect (G_OBJECT (fsa__button_OK), "clicked",
                      G_CALLBACK (on_fsa__button_OK_clicked),
                      gpp);
  g_signal_connect (G_OBJECT (fsa__button_cancel), "clicked",
                      G_CALLBACK (on_fsa__button_cancel_clicked),
                      gpp);

  gtk_widget_grab_default (fsa__button_cancel);
  return fsa__fileselection;
}  /* end gap_cme_gui_create_fsa__fileselection */


/* ----------------------------------------
 * create_ow__dialog
 * ----------------------------------------
 */
static GtkWidget*
create_ow__dialog (GapCmeGlobalParams *gpp)
{
  GtkWidget *ow__dialog;
  GtkWidget *ow__dialog_vbox0;
  GtkWidget *ow__frame1;
  GtkWidget *ow__vbox1;
  GtkWidget *ow__hbox2;
  GtkWidget *ow__label1;
  GtkWidget *ow__hbox3;
  GtkWidget *ow__filename;
  GtkWidget *ow__action_area1;
  GtkWidget *ow__hbox1;
  GtkWidget *ow__label_dummy22;
  GtkWidget *ow__button_one;
  GtkWidget *ow__button_cancel;

  ow__dialog = gtk_dialog_new ();
  gtk_window_set_title (GTK_WINDOW (ow__dialog), _("Overwrite warning"));

  ow__dialog_vbox0 = GTK_DIALOG (ow__dialog)->vbox;
  gtk_widget_show (ow__dialog_vbox0);

  ow__frame1 = gimp_frame_new (NULL);
  gtk_widget_show (ow__frame1);
  gtk_box_pack_start (GTK_BOX (ow__dialog_vbox0), ow__frame1, TRUE, TRUE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (ow__frame1), 5);

  ow__vbox1 = gtk_vbox_new (FALSE, 1);
  gtk_widget_show (ow__vbox1);
  gtk_container_add (GTK_CONTAINER (ow__frame1), ow__vbox1);
  gtk_container_set_border_width (GTK_CONTAINER (ow__vbox1), 5);

  ow__hbox2 = gtk_hbox_new (FALSE, 0);
  gtk_widget_show (ow__hbox2);
  gtk_box_pack_start (GTK_BOX (ow__vbox1), ow__hbox2, FALSE, FALSE, 0);

  ow__label1 = gtk_label_new (_("File already exists:"));
  gtk_widget_show (ow__label1);
  gtk_box_pack_start (GTK_BOX (ow__hbox2), ow__label1, FALSE, FALSE, 0);
  gtk_label_set_justify (GTK_LABEL (ow__label1), GTK_JUSTIFY_LEFT);

  ow__hbox3 = gtk_hbox_new (FALSE, 0);
  gtk_widget_show (ow__hbox3);
  gtk_box_pack_start (GTK_BOX (ow__vbox1), ow__hbox3, FALSE, FALSE, 0);

  ow__filename = gtk_label_new (_("filename"));
  gtk_widget_show (ow__filename);
  gtk_box_pack_start (GTK_BOX (ow__hbox3), ow__filename, FALSE, FALSE, 0);
  gtk_label_set_justify (GTK_LABEL (ow__filename), GTK_JUSTIFY_LEFT);

  ow__action_area1 = GTK_DIALOG (ow__dialog)->action_area;
  gtk_widget_show (ow__action_area1);
  gtk_container_set_border_width (GTK_CONTAINER (ow__action_area1), 10);

  ow__hbox1 = gtk_hbox_new (FALSE, 0);
  gtk_widget_show (ow__hbox1);
  gtk_box_pack_start (GTK_BOX (ow__action_area1), ow__hbox1, TRUE, TRUE, 0);

  ow__label_dummy22 = gtk_label_new (_("  "));
  gtk_widget_show (ow__label_dummy22);
  gtk_box_pack_start (GTK_BOX (ow__hbox1), ow__label_dummy22, TRUE, FALSE, 0);

  ow__button_one = gtk_button_new_with_label (_("Overwrite"));
  gtk_widget_show (ow__button_one);
  gtk_box_pack_start (GTK_BOX (ow__hbox1), ow__button_one, FALSE, FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (ow__button_one), 2);
  GTK_WIDGET_SET_FLAGS (ow__button_one, GTK_CAN_DEFAULT);

  ow__button_cancel = gtk_button_new_with_label (_("Cancel"));
  gtk_widget_show (ow__button_cancel);
  gtk_box_pack_start (GTK_BOX (ow__hbox1), ow__button_cancel, FALSE, FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (ow__button_cancel), 2);
  GTK_WIDGET_SET_FLAGS (ow__button_cancel, GTK_CAN_DEFAULT);

  g_signal_connect (G_OBJECT (ow__dialog), "destroy",
                      G_CALLBACK (on_ow__dialog_destroy),
                      gpp);
  g_signal_connect (G_OBJECT (ow__button_one), "clicked",
                      G_CALLBACK (on_ow__button_one_clicked),
                      gpp);
  g_signal_connect (G_OBJECT (ow__button_cancel), "clicked",
                      G_CALLBACK (on_ow__button_cancel_clicked),
                      gpp);

  gtk_widget_grab_default (ow__button_cancel);

  gpp->ow__filename = ow__filename;

  return ow__dialog;
}  /* end create_ow__dialog */


/* ---------------------------------
 * p_input_mode_radio_callback
 * ---------------------------------
 */
static void
p_input_mode_radio_callback(GtkWidget *widget, GapCmeGlobalParams *gpp)
{
  GapLibTypeInputRange l_rangetype;

  l_rangetype = (GapLibTypeInputRange) g_object_get_data (G_OBJECT (widget)
                                                        , RADIO_ITEM_INDEX_KEY);


  if((gpp) && (GTK_TOGGLE_BUTTON (widget)->active))
  {
    gint32  l_first_frame_limit;
    gint32  l_last_frame_nr;

    gpp->val.input_mode = l_rangetype;

    p_get_range_from_type (gpp, l_rangetype, &l_first_frame_limit, &l_last_frame_nr);

    /* update range limits and label texts */
    p_range_widgets_set_limits(gpp
                             , l_first_frame_limit
                             , l_last_frame_nr
                             , l_rangetype
                             );
  }
}  /* end p_input_mode_radio_callback */


/* ---------------------------------
 * p_create_input_mode_widgets
 * ---------------------------------
 */
static void
p_create_input_mode_widgets(GtkWidget *table, int row, int col, GapCmeGlobalParams *gpp)
{
  GtkWidget *label;
  GtkWidget *radio_table;
  GtkWidget *radio_button;
  GSList    *radio_group = NULL;
  gint      l_idx;
  gboolean  l_radio_pressed;

  label = gtk_label_new(_("Input Mode:"));
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
  gtk_table_attach( GTK_TABLE (table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 10);
  gtk_widget_show(label);

  /* radio_table */
  radio_table = gtk_table_new (1, 3, FALSE);

  l_idx = 0;
  /* radio button Frames input_mode */
  radio_button = gtk_radio_button_new_with_label ( radio_group, _("Frames") );
  gpp->cme__radio_button_frame = radio_button;
  radio_group = gtk_radio_button_get_group ( GTK_RADIO_BUTTON (radio_button) );
  gtk_table_attach ( GTK_TABLE (radio_table), radio_button, l_idx, l_idx+1
                   , 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0);


  l_radio_pressed = (gpp->val.input_mode == GAP_RNGTYPE_FRAMES);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button),
                                   l_radio_pressed);
  gimp_help_set_help_data(radio_button, _("Input is a sequence of frame images"), NULL);

  gtk_widget_show (radio_button);
  g_object_set_data (G_OBJECT (radio_button), RADIO_ITEM_INDEX_KEY
                    , (gpointer)GAP_RNGTYPE_FRAMES
                    );
  g_signal_connect ( G_OBJECT (radio_button), "toggled",
                     G_CALLBACK (p_input_mode_radio_callback),
                     gpp);


  l_idx = 1;

  /* radio button Layers input_mode */
  radio_button = gtk_radio_button_new_with_label ( radio_group, _("Layers") );
  gpp->cme__radio_button_layer = radio_button;
  radio_group = gtk_radio_button_get_group ( GTK_RADIO_BUTTON (radio_button) );
  gtk_table_attach ( GTK_TABLE (radio_table), radio_button, l_idx, l_idx+1, 0, 1
                   , GTK_FILL | GTK_EXPAND, 0, 0, 0);

  l_radio_pressed = (gpp->val.input_mode == GAP_RNGTYPE_LAYER);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button),
                                   l_radio_pressed);
  gimp_help_set_help_data(radio_button, _("Input is all the layers of one image"), NULL);

  gtk_widget_show (radio_button);
  g_object_set_data (G_OBJECT (radio_button), RADIO_ITEM_INDEX_KEY
                    , (gpointer)GAP_RNGTYPE_LAYER
                    );
  g_signal_connect ( G_OBJECT (radio_button), "toggled",
                     G_CALLBACK (p_input_mode_radio_callback),
                     gpp);



  l_idx = 2;

  /* radio button Storyboard input_mode */
  radio_button = gtk_radio_button_new_with_label ( radio_group, _("Storyboard") );
  gpp->cme__radio_button_storyboard = radio_button;
  radio_group = gtk_radio_button_get_group ( GTK_RADIO_BUTTON (radio_button) );
  gtk_table_attach ( GTK_TABLE (radio_table), radio_button, l_idx, l_idx+1, 0, 1
                   , GTK_FILL | GTK_EXPAND, 0, 0, 0);

  l_radio_pressed = (gpp->val.input_mode == GAP_RNGTYPE_STORYBOARD);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button),
                                   l_radio_pressed);
  gimp_help_set_help_data(radio_button, _("Input is videoclips and frames, defined via storyboard file. "
                                          "(specify the storyboard filename in the extras tab)")
                                          , NULL);

  gtk_widget_show (radio_button);
  g_object_set_data (G_OBJECT (radio_button), RADIO_ITEM_INDEX_KEY
                    , (gpointer)GAP_RNGTYPE_STORYBOARD
                    );
  g_signal_connect ( G_OBJECT (radio_button), "toggled",
                     G_CALLBACK (p_input_mode_radio_callback),
                     gpp);


  /* attach radio_table */
  gtk_table_attach ( GTK_TABLE (table), radio_table, col+1, col+2, row, row+1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
  gtk_widget_show (radio_table);

}  /* end p_create_input_mode_widgets */



/* ----------------------------------------
 * p_create_shell_window
 * ----------------------------------------
 */
static GtkWidget*
p_create_shell_window (GapCmeGlobalParams *gpp)
{
  GtkWidget *shell_window;
  GtkWidget *cme__dialog_vbox1;
  GtkWidget *cme__vbox_main;
  GtkWidget *notebook;
  GtkWidget *frame;
  GtkWidget *label;
  GtkWidget *hbox;
  GtkWidget *entry;
  GtkWidget *button;
  GtkWidget *cme__table_status;
  GtkWidget *progressbar;


  gpp->cme__spinbutton_width_adj = NULL;
  gpp->cme__spinbutton_height_adj = NULL;
  gpp->cme__spinbutton_framerate_adj = NULL;
  gpp->cme__spinbutton_samplerate_adj = NULL;

  shell_window = gimp_dialog_new (_("Master Videoencoder"),
                         GAP_CME_PLUGIN_NAME_VID_ENCODE_MASTER,
                         NULL, 0,
                         gimp_standard_help_func, GAP_CME_PLUGIN_HELP_ID_VID_ENCODE_MASTER,

                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                         GTK_STOCK_OK,     GTK_RESPONSE_OK,
                         NULL);
  gtk_window_set_type_hint (shell_window, GDK_WINDOW_TYPE_HINT_NORMAL);
  
  g_signal_connect (G_OBJECT (shell_window), "response",
                    G_CALLBACK (on_cme__response),
                    gpp);


  cme__dialog_vbox1 = GTK_DIALOG (shell_window)->vbox;
  gtk_widget_show (cme__dialog_vbox1);

  cme__vbox_main = gtk_vbox_new (FALSE, 0);
  gpp->cme__vbox_main = cme__vbox_main;
  gtk_widget_show (cme__vbox_main);
  gtk_box_pack_start (GTK_BOX (cme__dialog_vbox1), cme__vbox_main, TRUE, TRUE, 0);


  /* the notebook with encoding options */
  notebook = gtk_notebook_new ();
  gpp->cme__notebook = notebook;
  gtk_widget_show (notebook);
  gtk_box_pack_start (GTK_BOX (cme__vbox_main), notebook, TRUE, TRUE, 0);


  /* the video options notebook tab */
  label = gtk_label_new (_("Video Options"));
  gtk_widget_show (label);
  frame = p_create_video_options_frame(gpp);
  gtk_widget_show (frame);
  gtk_container_add (GTK_CONTAINER (notebook), frame);
  gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                            , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 0)
                            , label);


  /* the Audio Options notebook tab */
  label = gtk_label_new (_("Audio Options"));
  gtk_widget_show (label);
  frame = p_create_audio_options_frame (gpp);
  gtk_widget_show (frame);
  gtk_container_add (GTK_CONTAINER (notebook), frame);
  gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                             , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 1)
                             , label);


  /* the Audio Tool notebook tab */
  label = gtk_label_new (_("Audio Tool Configuration"));
  gtk_widget_show (label);
  frame = p_create_audiotool_cfg_frame (gpp);
  gtk_widget_show (frame);
  gtk_container_add (GTK_CONTAINER (notebook), frame);
  gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                             , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 2)
                             , label);



  /* the Extras notebook tab */
  label = gtk_label_new (_("Extras"));
  gtk_widget_show (label);
  frame = p_create_encode_extras_frame (gpp);
  gtk_widget_show (frame);
  gtk_container_add (GTK_CONTAINER (notebook), frame);
  gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                             , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 3)
                             , label);

  /* add the Encoding notebook tab */
  label = gtk_label_new (_("Encoding"));
  gtk_widget_show (label);
  frame = p_create_encoder_status_frame(gpp);
  gpp->cme__encoder_status_frame = frame;
  gtk_widget_show (frame);
  gtk_container_add (GTK_CONTAINER (notebook), frame);
  gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                            , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 4)
                            , label);


  /* the output frame */

  /* the hbox */
  frame = gimp_frame_new (_("Output"));
  gtk_widget_show (frame);
  gtk_box_pack_start (GTK_BOX (cme__vbox_main), frame, FALSE /* expand*/, TRUE /* fill */, 0);
  gtk_container_set_border_width (GTK_CONTAINER (frame), 4);


  hbox = gtk_hbox_new (FALSE, 0);
  gtk_widget_show (hbox);
  gtk_container_add (GTK_CONTAINER (frame), hbox);

  /* the (output) video label */
  label = gtk_label_new (_("Video :"));
  gtk_widget_show (label);
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);

  /* the (output) video entry */
  entry = gtk_entry_new ();
  gpp->cme__entry_video = entry;
  gtk_widget_show (entry);
  gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
  gimp_help_set_help_data (entry, _("Name of output videofile"), NULL);
  g_signal_connect (G_OBJECT (entry), "changed",
                      G_CALLBACK (on_cme__entry_video_changed),
                      gpp);

  /* the (output) video filebrowser button */

  button = gtk_button_new_with_label (_("..."));
  gpp->cme__button_video_filesel = button;
  gtk_widget_show (button);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  gtk_widget_set_size_request (button, 80, -1);
  gimp_help_set_help_data (button, _("Select output videofile via browser"), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_video_clicked),
                      gpp);


  /* the Status frame */
  frame = gimp_frame_new (_("Status"));
  gtk_widget_show (frame);
  gtk_box_pack_start (GTK_BOX (cme__vbox_main), frame, TRUE, TRUE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (frame), 4);

  /* the Status table */
  cme__table_status = gtk_table_new (2, 2, FALSE);
  gtk_widget_show (cme__table_status);
  gtk_container_add (GTK_CONTAINER (frame), cme__table_status);

  /* the Status label */
  label = gtk_label_new (_("READY"));
  gpp->cme__label_status = label;

  /* hide cme__label_status, because status is now displayed
   * via gtk_progress_bar_set_text
   */
  gtk_widget_hide (label);
  gtk_table_attach (GTK_TABLE (cme__table_status), label, 0, 2, 0, 1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_misc_set_padding (GTK_MISC (label), 2, 0);

  /* the Status progressbar */
  progressbar = gtk_progress_bar_new ();
  gpp->cme__progressbar_status = progressbar;
  gtk_widget_show (progressbar);
  gtk_table_attach (GTK_TABLE (cme__table_status), progressbar, 0, 2, 1, 2,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 2, 0);


  return shell_window;
}  /* end p_create_shell_window */


/* ----------------------------------------
 * p_overwrite_dialog
 * ----------------------------------------
 */
static gint
p_overwrite_dialog(GapCmeGlobalParams *gpp, gchar *filename, gint overwrite_mode)
{
  if(g_file_test(filename, G_FILE_TEST_EXISTS))
  {
    if (overwrite_mode < 1)
    {
       if(gpp->val.run_mode != GIMP_RUN_NONINTERACTIVE)
       {
         gpp->val.ow_mode = -1; /* prepare Cancel as default */
         gpp->ow__dialog_window = create_ow__dialog (gpp);

         gtk_label_set_text(GTK_LABEL(gpp->ow__filename), filename);
         gtk_widget_show (gpp->ow__dialog_window);
         gtk_main ();
         /* set ow_mode 0: Overwrite One
          *             1: Overwrite All
          *            -1: Cancel
          */
         gpp->ow__dialog_window = NULL;
       }
       return(gpp->val.ow_mode);
    }
  }
  return (overwrite_mode);
}  /* end p_overwrite_dialog */


/* ----------------------------------------
 * p_create_encoder_status_frame
 * ----------------------------------------
 */
static GtkWidget*
p_create_encoder_status_frame (GapCmeGlobalParams *gpp)
{
  GtkWidget *frame;
  GtkWidget *table;
  GtkWidget *label;
  GtkObject *adj;
  GtkWidget *spinbutton;
  GtkWidget *combo;
  GtkWidget *button;
  GtkWidget *entry;
  gint       row;

  frame = gimp_frame_new (_("Video Encoder Status"));


  table = gtk_table_new (4, 2, FALSE);
  gtk_widget_show (table);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 2);


  row = 0;

  label = gtk_label_new (_("Active Encoder:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  label = gtk_label_new ("#");
  gpp->cme__label_active_encoder_name          = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  row++;

  label = gtk_label_new (" ");
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  row++;

  label = gtk_label_new (_("Total Frames:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  label = gtk_label_new ("######");
  gpp->cme__label_enc_stat_frames_total          = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  row++;


  label = gtk_label_new (_("Frames Done:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  label = gtk_label_new ("######");
  gpp->cme__label_enc_stat_frames_done          = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  row++;


  label = gtk_label_new (_("Frames Encoded:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  label = gtk_label_new ("######");
  gpp->cme__label_enc_stat_frames_encoded          = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  row++;


  label = gtk_label_new (_("Frames Copied (lossless):"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  label = gtk_label_new ("######");
  gpp->cme__label_enc_stat_frames_copied_lossless          = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  row++;


  label = gtk_label_new (_("Encoding Time Elapsed:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  label = gtk_label_new ("######");
  gpp->cme__label_enc_time_elapsed          = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  return(frame);
}  /* end p_create_encoder_status_frame */

/* ----------------------------------------
 * p_create_encode_extras_frame
 * ----------------------------------------
 */
static GtkWidget*
p_create_encode_extras_frame (GapCmeGlobalParams *gpp)
{
  GtkWidget *frame;
  GtkWidget *table1;
  GtkWidget *button;
  GtkWidget *entry;
  GtkWidget *label;
  GtkWidget *checkbutton;
  gint       row;

  frame = gimp_frame_new (_("Encoding Extras"));


  table1 = gtk_table_new (7, 3, FALSE);
  gtk_widget_show (table1);
  gtk_container_add (GTK_CONTAINER (frame), table1);

  row = 0;

  /* the Macrofile label */
  label = gtk_label_new (_("Macrofile:"));
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table1), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);


  /* the Macrofile entry */
  entry = gtk_entry_new ();
  gpp->cme__entry_mac = entry;
  gtk_widget_show (entry);
  gtk_table_attach (GTK_TABLE (table1), entry, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (entry, _("optional filtermacro file to be performed on each handled frame "), NULL);
  g_signal_connect (G_OBJECT (entry), "changed",
                      G_CALLBACK (on_cme__entry_mac_changed),
                      gpp);


  /* the Macrofile filebrowser button */
  button = gtk_button_new_with_label (_("..."));
  gtk_widget_show (button);
  gtk_table_attach (GTK_TABLE (table1), button, 2, 3, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_widget_set_size_request (button, 70, -1);
  gimp_help_set_help_data (button, _("select macrofile via browser"), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_mac_clicked),
                      gpp);


  row++;

  /* the Storyboard label */
  label = gtk_label_new (_("Storyboard File:"));
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table1), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

  /* the Storyboard entry */
  entry = gtk_entry_new ();
  gpp->cme__entry_stb = entry;
  gtk_widget_show (entry);
  gtk_table_attach (GTK_TABLE (table1), entry, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (entry, _("optionally use a storyboard file to feed the encoder"), NULL);
  g_signal_connect (G_OBJECT (entry), "changed",
                      G_CALLBACK (on_cme__entry_stb_changed),
                      gpp);


  /* the Storyboard filebrowser button */
  button = gtk_button_new_with_label (_("..."));
  gtk_widget_show (button);
  gtk_table_attach (GTK_TABLE (table1), button, 2, 3, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (button, _("select storyboard file via browser"), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_stb_clicked),
                      gpp);
  row++;

  /* the Storyboard Audio */
  label = gtk_label_new (_("Storyboard Audio:"));
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table1), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

  /* the Storyboard filebrowser button */
  button = gtk_button_new_with_label (_("Create Composite Audiofile"));
  gpp->cme__button_stb_audio = button;
  gtk_widget_show (button);
  gtk_table_attach (GTK_TABLE (table1), button, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (button
                          , _("create a composite audiofile "
                              "as mixdown of all audio tracks in the "
                              "storyboard file and use the created composite audiofile "
                              "as input for encoding")
                          , NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_stb_audio_clicked),
                      gpp);

  row++;

  /* the  storyboard helptext & parsing report label */
  label = gtk_label_new (_("Storyboardfiles are textfiles that are used to\n"
                           "assemble a video from a list of single images,\n"
                           "frameranges, videoclips, gif animations or audiofiles.\n"
                           "(see STORYBOARD_FILE_DOC.txt for details)"));
  gpp->cme__label_storyboard_helptext   = label;
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table1), label, 0, 3, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 2, 6);
  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_FILL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

  row++;

  /* the Monitor label */
  label = gtk_label_new (_("Monitor"));
  gtk_widget_hide (label);
  gtk_table_attach (GTK_TABLE (table1), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

  /* the Monitor checkbutton */
  checkbutton = gtk_check_button_new_with_label (_("Monitor Frames while Encoding"));
  gtk_widget_show (checkbutton);
  gtk_table_attach (GTK_TABLE (table1), checkbutton, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (checkbutton, _("Show each frame before passed to encoder"), NULL);
  g_signal_connect (G_OBJECT (checkbutton), "toggled",
                      G_CALLBACK (on_cme__checkbutton_enc_monitor_toggled),
                      gpp);


  row++;

  /* the Debug Flat File label */
  label = gtk_label_new (_("Debug\nFlat File:"));
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table1), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

  /* the Debug Flat File entry */
  entry = gtk_entry_new ();
  gpp->cme__entry_debug_flat = entry;
  gtk_widget_show (entry);
  gtk_table_attach (GTK_TABLE (table1), entry, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (entry, _("optional Save each composite frame to JPEG file, before it is passed to the encoder"), NULL);
  g_signal_connect (G_OBJECT (entry), "changed",
                      G_CALLBACK (on_cme__entry_debug_flat_changed),
                      gpp);


  row++;

  /* the Debug Multilayer File label */
  label = gtk_label_new (_("Debug\nMultilayer File:"));
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table1), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

  /* the Debug Multilayer File entry */
  entry = gtk_entry_new ();
  gpp->cme__entry_debug_multi = entry;
  gtk_widget_show (entry);
  gtk_table_attach (GTK_TABLE (table1), entry, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (entry, _("optional save each composite multilayer frame to XCF file, before flattening and executing macro"), NULL);
  g_signal_connect (G_OBJECT (entry), "changed",
                      G_CALLBACK (on_cme__entry_debug_multi_changed),
                      gpp);



  return(frame);
}  /* end p_create_encode_extras_frame */


/* ----------------------------------------
 * p_create_audiotool_cfg_frame
 * ----------------------------------------
 */
static GtkWidget*
p_create_audiotool_cfg_frame (GapCmeGlobalParams *gpp)
{
  GtkWidget *frame;
  GtkWidget *table;
  GtkWidget *button;
  GtkWidget *entry;
  GtkWidget *label;
  GtkWidget *hbox;
  gint       row;

  frame = gimp_frame_new (_("Configuration of external audiotool program"));


  table = gtk_table_new (4, 2, FALSE);
  gtk_widget_show (table);
  gtk_container_add (GTK_CONTAINER (frame), table);

  row = 0;

  /* the audiotool (sox) label */
  label = gtk_label_new (_("Audiotool:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  /* the audiotool (sox)  entry */
  entry = gtk_entry_new ();
  gpp->cme__entry_sox = entry;
  gtk_widget_show (entry);
  gtk_table_attach (GTK_TABLE (table), entry, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 2, 2);
  gimp_help_set_help_data (entry, _("name of audiotool (something like sox with or without path)"), NULL);
  g_signal_connect (G_OBJECT (entry), "changed",
                      G_CALLBACK (on_cme__entry_sox_changed),
                      gpp);



  row++;

  /* the audiotool options (sox options) label */
  label = gtk_label_new (_("Options:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  /* the audiotool options (sox options) entry */
  entry = gtk_entry_new ();
  gpp->cme__entry_sox_options           = entry;
  gtk_widget_show (entry);
  gtk_table_attach (GTK_TABLE (table), entry, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 2, 2);
  gimp_help_set_help_data (entry, _("Options to call the audiotool ($IN, $OUT $RATE are replaced)"), NULL);
  g_signal_connect (G_OBJECT (entry), "changed",
                      G_CALLBACK (on_cme__entry_sox_options_changed),
                      gpp);


  row++;

  /* the multitextline information label
   * (explains how params are passed to audiotool)
   */
  label =
    gtk_label_new (_("Configuration of an audiotool (like sox on UNIX).\n\n"
                     "$IN .. is replaced by the input audiofile\n"
                     "$OUT .. is replaced by audiofile with suffix  _tmp.wav\n"
                     "$RATE .. is replaced by samplerate in byte/sec\n"
                     "\n"
                     "This tool is called for audio conversions  if\n"
                     "a) the input audiofile is not WAV 16Bit format\n"
                     "b) Desired Samplerate does not match the\n"
                     "     rate in the .wav file"));
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table), label, 0, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 2, 2);
  gtk_widget_set_size_request (label, 300, -1);
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);


  row++;

  /* the hbox for LOAD/SAVE/DEFAULT buttons */

  hbox = gtk_hbox_new (TRUE, 0);
  gtk_widget_show (hbox);
  gtk_table_attach (GTK_TABLE (table), hbox, 0, 2, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (GTK_EXPAND), 0, 2);

  /* the Save button */
  button = gtk_button_new_with_label (_("Save"));
  gtk_widget_show (button);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 2);
  gimp_help_set_help_data (button, _("Save audiotool configuration to gimprc"), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_sox_save_clicked),
                      gpp);

  /* the Load button */
  button = gtk_button_new_with_label (_("Load"));
  gtk_widget_show (button);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 2);
  gimp_help_set_help_data (button, _("Load audiotool configuration from gimprc"), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_sox_load_clicked),
                      gpp);

  /* the Default button */
  button = gtk_button_new_with_label (_("Default"));
  gtk_widget_show (button);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 2);
  gimp_help_set_help_data (button, _("Set default audiotool configuration "), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_sox_default_clicked),
                      gpp);


  return(frame);
}  /* end p_create_audiotool_cfg_frame */


/* ----------------------------------------
 * p_create_audio_options_frame
 * ----------------------------------------
 */
static GtkWidget*
p_create_audio_options_frame (GapCmeGlobalParams *gpp)
{
  GtkWidget *frame;
  GtkWidget *table;
  GtkWidget *label;
  GtkObject *adj;
  GtkWidget *spinbutton;
  GtkWidget *combo;
  GtkWidget *button;
  GtkWidget *entry;
  gint       row;

  frame = gimp_frame_new (_("Audio Input"));


  table = gtk_table_new (6, 3, FALSE);
  gtk_widget_show (table);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 2);


  row = 0;

  /* the Audiofile label */
  label = gtk_label_new (_("Audiofile:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  /* the Audiofile entry */
  entry = gtk_entry_new ();
  gpp->cme__entry_audio1                = entry;
  gtk_widget_show (entry);
  gtk_table_attach (GTK_TABLE (table), entry, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (entry
                   , _("Name of audiofile (.wav 16 bit mono or stereo samples preferred). "
                       "Optionally you may select a textfile that contains a list "
                       "of file names referring to audio files. "
                       "Each of those audio files will be encoded as a separate audio track.")
                   , NULL)
                   ;
  g_signal_connect (G_OBJECT (entry), "changed",
                      G_CALLBACK (on_cme__entry_audio1_changed),
                      gpp);

  /* the Audiofile filebrowser button */
  button = gtk_button_new_with_label (_("..."));
  gtk_widget_show (button);
  gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_widget_set_size_request (button, 80, -1);
  gimp_help_set_help_data (button, _("Select input audiofile via browser"), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_audio1_clicked),
                      gpp);


  row++;

  /* the audiofile information label */
  label = gtk_label_new (_("WAV, 16 Bit stereo, rate: 44100"));
  gpp->cme__label_aud1_info             = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);

  /* the audiofile total playtime information label */
  label = gtk_label_new (_("00:00:000"));
  gpp->cme__label_aud1_time             = label;
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table), label, 2, 3, row, row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);


  row++;

  /* the Samplerate label */
  label = gtk_label_new (_("Samplerate:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  /* the Samplerate spinbutton */
  adj = gtk_adjustment_new (44100, 1000, 100000, 10, 100, 0);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 1, 0);
  gpp->cme__spinbutton_samplerate_adj   = adj;
  gpp->cme__spinbutton_samplerate       = spinbutton;
  gtk_widget_show (spinbutton);
  gtk_table_attach (GTK_TABLE (table), spinbutton, 1, 2, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (spinbutton, _("Output samplerate in samples/sec"), NULL);
  g_signal_connect (G_OBJECT (spinbutton), "value_changed",
                      G_CALLBACK (on_cme__spinbutton_samplerate_changed),
                      gpp);

  /* the Samplerate combo */
  combo = gimp_int_combo_box_new (_(" 8k Phone"),       8000,
                                  _("11.025k"),        11025,
                                  _("12k Voice"),      12000,
                                  _("16k FM"),         16000,
                                  _("22.05k"),         22050,
                                  _("24k Tape"),       24000,
                                  _("32k HiFi"),       32000,
                                  _("44.1k CD"),       44100,
                                  _("48 k Studio"),    48000,
                                  NULL);


  gpp->cme__combo_outsamplerate    = combo;
  gtk_widget_show (combo);
  gtk_table_attach (GTK_TABLE (table), combo, 2, 3, row, row+1,
                    (GtkAttachOptions) (GTK_EXPAND),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (combo, _("Select a commonly-used samplerate"), NULL);
  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              44100,  /* initial gint value */
                              G_CALLBACK (on_cme__combo_outsamplerate),
                              gpp);


  row++;

  /* the Tmp audiofile label */
  label = gtk_label_new (_("Tmpfile:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 4);

  /* the Tmp audiofilefilename label */
  label = gtk_label_new ("");
  gpp->cme__label_tmp_audfile           = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);

  /* the convert Tmp audiofilefile button */
  button = gtk_button_new_with_label (_("Audioconvert"));
  gpp->cme__button_gen_tmp_audfile      = button;
  gtk_widget_show (button);
  gtk_table_attach (GTK_TABLE (table), button, 2, 3, row, row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 2, 0);
  gimp_help_set_help_data (button, _("Convert audio input file to a temporary file\n"
                                     "and feed the temporary file to the selected encoder\n"
                                     "(the temporary file is deleted when encoding is done)"), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_gen_tmp_audfile_clicked),
                      gpp);

  row++;

  /* the Tmp audioinformation  label */
  label = gtk_label_new (_("WAV, 16 Bit stereo, rate: 44100"));
  gpp->cme__label_aud_tmp_info = label;
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);


  /* the Tmp audio playtime information  label */
  label = gtk_label_new (_("00:00:000"));
  gpp->cme__label_aud_tmp_time          = label;
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table), label, 2, 3, row, row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);

  row++;

  /* the resample general information label */
  label = gtk_label_new (_("\nNote:\n"
                           "if you set samplerate lower than\n"
                           "rate of the WAV file, you lose sound quality,\n"
                           "but higher samplerates can not improve the\n"
                           "quality of the original sound.")
                         );
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);


  return(frame);
}  /* end p_create_audio_options_frame */


/* ----------------------------------------
 * p_create_video_timing_table
 * ----------------------------------------
 */
static GtkWidget*
p_create_video_timing_table (GapCmeGlobalParams *gpp)
{
  GtkWidget *cme__table_times;
  GtkWidget *label;


  /* table for the video timing info labels */
  cme__table_times = gtk_table_new (2, 3, FALSE);

  gtk_table_set_row_spacings (GTK_TABLE (cme__table_times), 10);

  /* the timestamp of the first frame */
  label = gtk_label_new ("00:00:000");
  gpp->cme__label_fromtime              = label;
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (cme__table_times), label, 0, 1, 0, 1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);


  /* the video timing information labels */
  label = gtk_label_new (_("Videotime:"));
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (cme__table_times), label, 1, 2, 0, 1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_misc_set_padding (GTK_MISC (label), 7, 0);


  label = gtk_label_new ("00:00:000");
  gpp->cme__label_totaltime = label;
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (cme__table_times), label, 2, 3, 0, 1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);



  /* the timestamp of the last frame */
  label = gtk_label_new (_("00:00:000"));
  gpp->cme__label_totime = label;
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (cme__table_times), label, 0, 1, 1, 2,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);

  /* the audio timing information labels */

  label = gtk_label_new (_("Audiotime:"));
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (cme__table_times), label, 1, 2, 1, 2,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);

  label = gtk_label_new (_("00:00:000"));
  gpp->cme__label_aud0_time = label;
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (cme__table_times), label, 2, 3, 1, 2,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);


  return(cme__table_times);
}  /* end p_create_video_timing_table */


/* ----------------------------------------
 * p_create_video_options_frame
 * ----------------------------------------
 */
static GtkWidget*
p_create_video_options_frame (GapCmeGlobalParams *gpp)
{
  GtkWidget *frame;
  GtkWidget *cme__table1;
  GtkWidget *cme__table_times;
  GtkWidget *label;
  GtkObject *adj;
  GtkWidget *spinbutton;
  GtkWidget *combo;
  GtkWidget *button;
  gint       l_row;


  frame = gimp_frame_new (_("Video Encode Options"));



  cme__table1 = gtk_table_new (10, 3, FALSE);

  gtk_widget_show (cme__table1);
  gtk_container_add (GTK_CONTAINER (frame), cme__table1);
  gtk_container_set_border_width (GTK_CONTAINER (cme__table1), 5);
  gtk_table_set_row_spacings (GTK_TABLE (cme__table1), 2);
  gtk_table_set_col_spacings (GTK_TABLE (cme__table1), 2);


  l_row = 0;
  p_create_input_mode_widgets(cme__table1, l_row, 0, gpp);

  l_row++;

  /* the from_frame label */
  label = gtk_label_new (_("From Frame:"));
  gpp->cme__label_from = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (cme__table1), label, 0, 1, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  /* the from_frame spinbutton */
  adj = gtk_adjustment_new (1, 0, 100000, 1, 10, 0);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 1, 0);
  gpp->cme__spinbutton_from_adj         = adj;
  gpp->cme__spinbutton_from             = spinbutton;
  gtk_widget_show (spinbutton);
  gtk_table_attach (GTK_TABLE (cme__table1), spinbutton, 1, 2, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (spinbutton, _("Start encoding at this frame"), NULL);
  g_signal_connect (G_OBJECT (spinbutton), "value_changed",
                      G_CALLBACK (on_cme__spinbutton_from_changed),
                      gpp);

  /* subtable for the video timing info labels (takes 2 rows) */
  cme__table_times = p_create_video_timing_table (gpp);
  gtk_widget_show (cme__table_times);
  gtk_table_attach (GTK_TABLE (cme__table1), cme__table_times, 2, 3, l_row, l_row+2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (GTK_FILL), 0, 0);


  l_row++;

  /* the to_frame label */
  label = gtk_label_new (_("To Frame:"));
  gpp->cme__label_to                    = label;
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (cme__table1), label, 0, 1, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  /* the to_frame spinbutton */
  adj = gtk_adjustment_new (1, 0, 100000, 1, 10, 0);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 1, 0);
  gpp->cme__spinbutton_to_adj           = adj;
  gpp->cme__spinbutton_to               = spinbutton;
  gtk_widget_show (spinbutton);
  gtk_table_attach (GTK_TABLE (cme__table1), spinbutton, 1, 2, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (spinbutton, _("Stop encoding at this frame"), NULL);
  g_signal_connect (G_OBJECT (spinbutton), "value_changed",
                      G_CALLBACK (on_cme__spinbutton_to_changed),
                      gpp);


  l_row++;

  /* the width label */
  label = gtk_label_new (_("Width:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (cme__table1), label, 0, 1, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  /* the width spinbutton */
  adj = gtk_adjustment_new (10, 10, 10000, 1, 10, 0);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 1, 0);
  gpp->cme__spinbutton_width_adj        = adj;
  gpp->cme__spinbutton_width            = spinbutton;
  gtk_widget_show (spinbutton);
  gtk_table_attach (GTK_TABLE (cme__table1), spinbutton, 1, 2, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (spinbutton, _("Width of the output video (pixels)"), NULL);
  g_signal_connect (G_OBJECT (spinbutton), "value_changed",
                      G_CALLBACK (on_cme__spinbutton_width_changed),
                      gpp);


  /* the Frame width/height scale combo (for picking common used video sizes) */
  combo = gimp_int_combo_box_new (_("Framesize (1:1)"),     GAP_CME_STANDARD_SIZE_IMAGE,
                                  _("320x240 NTSC"),        GAP_CME_STANDARD_SIZE_320x240,
                                  _("320x288 PAL"),         GAP_CME_STANDARD_SIZE_320x288,
                                  _("640x480"),             GAP_CME_STANDARD_SIZE_640x480,
                                  _("720x480 NTSC"),        GAP_CME_STANDARD_SIZE_720x480,
                                  _("720x576 PAL"),         GAP_CME_STANDARD_SIZE_720x576,
                                  NULL);

  gpp->cme__combo_scale            = combo;
  gtk_widget_show (combo);
  gtk_table_attach (GTK_TABLE (cme__table1), combo, 2, 3, l_row, l_row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_widget_set_size_request (combo, 160, -1);
  gimp_help_set_help_data (combo, _("Scale width/height to common size"), NULL);
  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              GAP_CME_STANDARD_SIZE_IMAGE,  /* initial gint value */
                              G_CALLBACK (on_cme__combo_scale),
                              gpp);



  l_row++;

  /* the height label */
  label = gtk_label_new (_("Height:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (cme__table1), label, 0, 1, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  /* the height spinbutton */
  adj = gtk_adjustment_new (10, 10, 10000, 1, 10, 0);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 1, 0);
  gpp->cme__spinbutton_height_adj       = adj;
  gpp->cme__spinbutton_height           = spinbutton;
  gtk_widget_show (spinbutton);
  gtk_table_attach (GTK_TABLE (cme__table1), spinbutton, 1, 2, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (spinbutton, _("Height of the output video (pixels)"), NULL);
  g_signal_connect (G_OBJECT (spinbutton), "value_changed",
                      G_CALLBACK (on_cme__spinbutton_height_changed),
                      gpp);



  l_row++;

  /* the Framerate lable */
  label = gtk_label_new (_("Framerate:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (cme__table1), label, 0, 1, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  /* the framerate spinbutton */
  adj = gtk_adjustment_new (24, 1, 100, 0.1, 1, 0);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 1, 2);
  gpp->cme__spinbutton_framerate_adj    = adj;
  gpp->cme__spinbutton_framerate        = spinbutton;
  gtk_widget_show (spinbutton);
  gtk_table_attach (GTK_TABLE (cme__table1), spinbutton, 1, 2, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (spinbutton, _("Framerate of the output video (frames/sec)"), NULL);
  g_signal_connect (G_OBJECT (spinbutton), "value_changed",
                      G_CALLBACK (on_cme__spinbutton_framerate_changed),
                      gpp);


  /* the framerate combo (to select common used video framerates) */
  combo = gimp_int_combo_box_new (_("unchanged"),   GAP_CME_STANDARD_FRAMERATE_00_UNCHANGED,
                                  "23.98",          GAP_CME_STANDARD_FRAMERATE_01_23_98,
                                  "24",             GAP_CME_STANDARD_FRAMERATE_02_24,
                                  "25",             GAP_CME_STANDARD_FRAMERATE_03_25,
                                  "29.97",          GAP_CME_STANDARD_FRAMERATE_04_29_97,
                                  "30",             GAP_CME_STANDARD_FRAMERATE_05_30,
                                  "50",             GAP_CME_STANDARD_FRAMERATE_06_50,
                                  "59.94",          GAP_CME_STANDARD_FRAMERATE_07_59_94,
                                  "60",             GAP_CME_STANDARD_FRAMERATE_08_60,
                                  "1",              GAP_CME_STANDARD_FRAMERATE_09_1,
                                  "5",              GAP_CME_STANDARD_FRAMERATE_10_5,
                                  "10",             GAP_CME_STANDARD_FRAMERATE_11_10,
                                  "12",             GAP_CME_STANDARD_FRAMERATE_12_12,
                                  "15",             GAP_CME_STANDARD_FRAMERATE_13_15,
                                   NULL);

  gpp->cme__combo_framerate        = combo;
  gtk_widget_show (combo);
  gtk_table_attach (GTK_TABLE (cme__table1), combo, 2, 3, l_row, l_row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_widget_set_size_request (combo, 160, -1);
  gimp_help_set_help_data (combo, _("Set framerate"), NULL);
  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              GAP_CME_STANDARD_FRAMERATE_00_UNCHANGED,  /* initial gint value */
                              G_CALLBACK (on_cme__combo_framerate),
                              gpp);


  l_row++;


  /* the Videonorm label */
  label = gtk_label_new (_("Videonorm:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (cme__table1), label, 0, 1, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  /* the Videonorm combo */
  combo = gimp_int_combo_box_new (_("NTSC"),       VID_FMT_NTSC,
                                  _("PAL"),        VID_FMT_PAL,
                                  _("SECAM"),      VID_FMT_SECAM,
                                  _("MAC"),        VID_FMT_MAC,
                                  _("COMP"),       VID_FMT_COMP,
                                  _("undefined"),  VID_FMT_UNDEF,
                                  NULL);


  gtk_widget_show (combo);
  gtk_table_attach (GTK_TABLE (cme__table1), combo, 2, 3, l_row, l_row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_widget_set_size_request (combo, 160, -1);
  gimp_help_set_help_data (combo, _("Select videonorm"), NULL);
  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              VID_FMT_NTSC,  /* initial gint value */
                              G_CALLBACK (on_cme__combo_vid_norm),
                              gpp);


  l_row++;

  /* the videoencoder label */
  label = gtk_label_new (_("Encoder:"));
  gtk_widget_show (label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (cme__table1), label, 0, 1, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);

  /* the parameters button (invokes videoencoder specific GUI dialog) */
  button = gtk_button_new_with_label (_("Parameters"));
  gpp->cme__button_params               = button;
  gtk_widget_show (button);
  gtk_table_attach (GTK_TABLE (cme__table1), button, 1, 2, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (button, _("Edit encoder specific parameters"), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_cme__button_params_clicked),
                      gpp);




  /* the videoencoder combo */
  combo = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
  gpp->cme__combo_encodername      = combo;
  gtk_widget_show (combo);
  gtk_table_attach (GTK_TABLE (cme__table1), combo, 2, 3, l_row, l_row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_widget_set_size_request (combo, 160, -1);
  gimp_help_set_help_data (combo, _("Select video encoder plugin"), NULL);

  /* the  videoencoder combo items are set later by query the PDB
   * for all registered video encoder plug-ins
   */


  l_row++;

  /* videoencoder short description label */
  label = gtk_label_new ("");
  gpp->cme__short_description           = label;
  gtk_widget_show (label);
  gtk_table_attach (GTK_TABLE (cme__table1), label, 1, 3, l_row, l_row+1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);


  return(frame);
}  /* end p_create_video_options_frame */


/* ----------------------------------------
 * p_call_encoder_procedure
 * ----------------------------------------
 */
static gint
p_call_encoder_procedure(GapCmeGlobalParams *gpp)
{
  GimpParam* l_params;
  gint   l_retvals;
  gint             l_nparams;
  gint             l_nreturn_vals;
  GimpPDBProcType   l_proc_type;
  gchar            *l_proc_blurb;
  gchar            *l_proc_help;
  gchar            *l_proc_author;
  gchar            *l_proc_copyright;
  gchar            *l_proc_date;
  GimpParamDef    *l_paramdef;
  GimpParamDef    *l_return_vals;
  char *l_msg;
  gint  l_use_encoderspecific_params;
  gint  l_rc;
  gchar            *l_16bit_wav_file;
  gint32           dummy_layer_id;

  l_rc = -1;

  l_use_encoderspecific_params = 0;  /* run with default values */


  if(gpp->val.ecp_sel.vid_enc_plugin[0] == '\0')
  {
     printf("p_call_encoder_procedure: No encoder available (exit)\n");
     return -1;
  }

  if(gpp->val.ecp_sel.gui_proc[0] != '\0')
  {
    l_use_encoderspecific_params = 1;  /* run with encoder specific values */
  }

  if(gap_debug)
  {
     printf("p_call_encoder_procedure %s: START\n", gpp->val.ecp_sel.vid_enc_plugin);
     printf("  videoname: %s\n", gpp->val.videoname);
     printf("  audioname1: %s\n", gpp->val.audioname1);
     printf("  basename: %s\n", gpp->ainfo.basename);
     printf("  extension: %s\n", gpp->ainfo.extension);
     printf("  range_from: %d\n", (int)gpp->val.range_from);
     printf("  range_to: %d\n", (int)gpp->val.range_to);
     printf("  framerate: %f\n", (float)gpp->val.framerate);
     printf("  samplerate: %d\n", (int)gpp->val.samplerate);
     printf("  wav_samplerate: %d\n", (int)gpp->val.wav_samplerate1);
     printf("  vid_width: %d\n", (int)gpp->val.vid_width);
     printf("  vid_height: %d\n", (int)gpp->val.vid_height);
     printf("  vid_format: %d\n", (int)gpp->val.vid_format);
     printf("  image_ID: %d\n", (int)gpp->val.image_ID);
     printf("  l_use_encoderspecific_params: %d\n", (int)l_use_encoderspecific_params);
     printf("  filtermacro_file: %s\n", gpp->val.filtermacro_file);
     printf("  storyboard_file: %s\n", gpp->val.storyboard_file);
     printf("  input_mode: %d\n", gpp->val.input_mode);
  }

  if(FALSE == gimp_procedural_db_proc_info (gpp->val.ecp_sel.vid_enc_plugin,
                          &l_proc_blurb,
                          &l_proc_help,
                          &l_proc_author,
                          &l_proc_copyright,
                          &l_proc_date,
                          &l_proc_type,
                          &l_nparams,
                          &l_nreturn_vals,
                          &l_paramdef,
                          &l_return_vals))
  {
     l_msg = g_strdup_printf(_("Required Plugin %s not available"), gpp->val.ecp_sel.vid_enc_plugin);
     if(gpp->val.run_mode == GIMP_RUN_INTERACTIVE)
     {
       g_message("%s", l_msg);
     }
     g_free(l_msg);
     return -1;
  }

  l_16bit_wav_file = &gpp->val.audioname1[0];
  if(gpp->val.tmp_audfile[0] != '\0')
  {
     l_16bit_wav_file = &gpp->val.tmp_audfile[0];
  }


  /* generic call of GAP video encoder plugin */
  dummy_layer_id = gap_image_get_any_layer(gpp->val.image_ID);
  l_params = gimp_run_procedure (gpp->val.ecp_sel.vid_enc_plugin,
                     &l_retvals,
                     GIMP_PDB_INT32,  gpp->val.run_mode,
                     GIMP_PDB_IMAGE,  gpp->val.image_ID,
                     GIMP_PDB_DRAWABLE, dummy_layer_id,
                     GIMP_PDB_STRING, gpp->val.videoname,
                     GIMP_PDB_INT32,  gpp->val.range_from,
                     GIMP_PDB_INT32,  gpp->val.range_to,
                     GIMP_PDB_INT32,  gpp->val.vid_width,
                     GIMP_PDB_INT32,  gpp->val.vid_height,
                     GIMP_PDB_INT32,  gpp->val.vid_format,
                     GIMP_PDB_FLOAT,  gpp->val.framerate,
                     GIMP_PDB_INT32,  gpp->val.samplerate,
                     GIMP_PDB_STRING, l_16bit_wav_file,
                     GIMP_PDB_INT32,  l_use_encoderspecific_params,
                     GIMP_PDB_STRING, gpp->val.filtermacro_file,
                     GIMP_PDB_STRING, gpp->val.storyboard_file,
                     GIMP_PDB_INT32,  gpp->val.input_mode,
                     GIMP_PDB_INT32,  gpp->encStatus.master_encoder_id,
                     GIMP_PDB_END);
  if(l_params[0].data.d_status == GIMP_PDB_SUCCESS)
  {
    l_rc = 0;
  }
  g_free(l_params);
  
  if(gap_debug)
  {
     printf("p_call_encoder_procedure %s: DONE\n", gpp->val.ecp_sel.vid_enc_plugin);
  }
  
  
  if(l_rc < 0)
  {
     l_msg = g_strdup_printf(_("Call of Required Plugin %s failed"), gpp->val.ecp_sel.vid_enc_plugin);
     if(gpp->val.run_mode == GIMP_RUN_INTERACTIVE)
     {
       g_message("%s", l_msg);
     }
     g_free(l_msg);
  }


  return (l_rc);
}  /* end p_call_encoder_procedure */



static void
p_set_label_to_numeric_value(GtkWidget *label, gint32 value)
{
  if(label != NULL)
  {
    char *buffer;
    buffer = g_strdup_printf("%6d", value);
    /* repeat the right alingnment of the label
     * (without this workaround my gtk version 2.10.14 shows just
     * the highest digit of the number, probably because the size at creation time
     * was only one character)
     *
     */
    gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
    gtk_label_set_text(GTK_LABEL(label), buffer);
    gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
    g_free(buffer);
  }
}

/* ----------------------------------------
 * gap_cme_gui_update_encoder_status
 * ----------------------------------------
 * called via polling timer while the encoder plug-in
 * is running (as separete process).
 * The displyed information is sent by the running encoder process
 * and received here (in the master videoencoder GUI process)
 * via procedure gap_gve_misc_get_master_encoder_progress
 */
void
gap_cme_gui_update_encoder_status(GapCmeGlobalParams *gpp)
{
  if(gap_debug)
  {
    printf("  gap_cme_gui_update_encoder_status -- frames_processed:%d\n"
      , gpp->encStatus.frames_processed
      );
  }

  if (gpp)
  {
    GtkWidget  *pbar;
    GtkWidget *label;
    
    gap_gve_misc_get_master_encoder_progress(&gpp->encStatus);

    gtk_widget_show(gpp->cme__encoder_status_frame);

 
    p_set_label_to_numeric_value(gpp->cme__label_enc_stat_frames_total, gpp->encStatus.total_frames);
    p_set_label_to_numeric_value(gpp->cme__label_enc_stat_frames_done, gpp->encStatus.frames_processed);
    p_set_label_to_numeric_value(gpp->cme__label_enc_stat_frames_encoded, gpp->encStatus.frames_encoded);
    p_set_label_to_numeric_value(gpp->cme__label_enc_stat_frames_copied_lossless, gpp->encStatus.frames_copied_lossless);
    
    

    pbar = gpp->cme__progressbar_status;
    if(pbar)
    {
      gdouble l_progress;
      char *l_msg;
      
      switch (gpp->encStatus.current_pass)
      {
        case 1:
          l_progress = CLAMP(
                       (gdouble)gpp->encStatus.frames_processed 
                        / (gdouble)(MAX(1.0, 2.0 * gpp->encStatus.total_frames))
                      , 0.0
                      , 1.0
                      );
          l_msg = g_strdup_printf(_("Video encoding %d of %d frames done, PASS 1 of 2")
                             , gpp->encStatus.frames_processed
                             , gpp->encStatus.total_frames
                             );
          break;
        case 2:
          l_progress = CLAMP(
                     (gdouble)(gpp->encStatus.frames_processed + gpp->encStatus.total_frames)
                      / (gdouble)(MAX(1.0, 2.0 * gpp->encStatus.total_frames))
                      , 0.0
                      , 1.0
                      );
          l_msg = g_strdup_printf(_("Video encoding %d of %d frames done, PASS 2 of 2")
                             , gpp->encStatus.frames_processed
                             , gpp->encStatus.total_frames
                             );
          break;
        default: 
          /* current_pass is 0 for single pass encoders */
          l_progress = CLAMP(
                      (gdouble)gpp->encStatus.frames_processed
                      / (gdouble)(MAX(1.0, gpp->encStatus.total_frames))
                      , 0.0
                      , 1.0
                      );
          l_msg = g_strdup_printf(_("Video encoding %d of %d frames done")
                             , gpp->encStatus.frames_processed
                             , gpp->encStatus.total_frames
                             );
          break;
      }

      gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (pbar), l_progress);
      gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pbar), l_msg);
      g_free(l_msg);

      if (gpp->encStatus.pidOfRunningEncoder != 0)
      {
        if (!gap_base_is_pid_alive(gpp->encStatus.pidOfRunningEncoder))
        {
          if (gpp->video_encoder_run_state ==  GAP_CME_ENC_RUN_STATE_RUNNING)
          {
            gpp->video_encoder_run_state =  GAP_CME_ENC_RUN_STATE_FINISHED;
          }
          gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pbar), _("ENCODER process has terminated"));
          return;
        }
      }
    }


    label = gpp->cme__label_enc_time_elapsed;
    if((label != NULL)
    && (gpp->video_encoder_run_state ==  GAP_CME_ENC_RUN_STATE_RUNNING))
    {
      time_t l_currentUtcTimeInSecs;
      gint32 l_secsElapsed;
      char *buffer;

      l_currentUtcTimeInSecs = time(NULL);
      l_secsElapsed = l_currentUtcTimeInSecs - gpp->encoder_started_on_utc_seconds;
      
      buffer = g_strdup_printf("%d:%02d:%02d"
                              , (int)l_secsElapsed / 3600
                              , (int)(l_secsElapsed / 60) % 60
                              , (int)l_secsElapsed % 60
                              );
      gtk_label_set_text(GTK_LABEL(label), buffer);
      g_free(buffer);
    }


//    if (gpp->video_encoder_run_state ==  GAP_CME_ENC_RUN_STATE_RUNNING)
//    {
//      /* detect if encoder has finished (required for asynchron calls since GIMP-2.6)  */
//      if(gpp->encStatus.frames_processed >= gpp->encStatus.total_frames)
//      {
//        if(gap_debug)
//        {
//          printf("  gap_cme_gui_update_encoder_status -- detected encoder FINISHED via progress\n"
//            , gpp->encStatus.frames_processed
//            );
//        }
//        gpp->video_encoder_run_state =  GAP_CME_ENC_RUN_STATE_FINISHED;
//      }
//    }
  }
}  /* end gap_cme_gui_update_encoder_status */


/* ----------------------------------------
 * gap_cme_gui_start_video_encoder
 * ----------------------------------------
 * start the selected video encoder plug-in
 */
gint32
gap_cme_gui_start_video_encoder(GapCmeGlobalParams *gpp)
{
   gint32     l_rc;
   char *l_tmpname;
   gint32 l_tmp_image_id;

   l_tmpname = NULL;
   l_tmp_image_id = -1;

   /* cheks for encoding a multilayer image as video
    * (this may require save of a temporary imge before we can start the encoder plugin)
    */
   if((gpp->ainfo.last_frame_nr - gpp->ainfo.first_frame_nr == 0)
   && (gpp->val.storyboard_file[0] == '\0'))
   {
     char *l_current_name;

     if((strcmp(gpp->ainfo.extension, ".xcf") == 0)
     || (strcmp(gpp->ainfo.extension, ".xjt") == 0))
     {
       /* for xcf and xjt just save without making a temp copy */
       l_tmpname = gimp_image_get_filename(gpp->val.image_ID);
     }
     else
     {
       /* prepare encoder params to run the encoder on the (saved) duplicate of the image */
       g_snprintf(gpp->ainfo.basename, sizeof(gpp->ainfo.basename), "%s", l_tmpname);

       /* save a temporary copy of the image */
       l_tmp_image_id = gimp_image_duplicate(gpp->val.image_ID);

       /* l_tmpname = gimp_temp_name("xcf"); */
       l_current_name = gimp_image_get_filename(gpp->val.image_ID);
       l_tmpname = g_strdup_printf("%s_temp_copy.xcf", l_current_name);
       gimp_image_set_filename (l_tmp_image_id, l_tmpname);
       gpp->ainfo.extension[0] = '\0';
       gpp->val.image_ID = l_tmp_image_id;
       g_free(l_current_name);
     }

     gimp_file_save(GIMP_RUN_NONINTERACTIVE
                   , gpp->val.image_ID
                   , 1 /* dummy layer_id */
                   ,l_tmpname
                   ,l_tmpname
                   );

   }

   gap_gve_misc_initGapGveMasterEncoderStatus(&gpp->encStatus
       , gap_base_getpid() /* master_encoder_id */
       , abs(gpp->val.range_to - gpp->val.range_from) + 1   /* total_frames */
       );

   /* ------------------------------------------- HERE WE GO, start the selected Video Encoder ----
    * the encoder will run as separate process, started by the GIMP core.
    * note that any further calls of GIMP core procedures .. from another thread ...
    * will be blocked by the GIMP core while the encoder process is running.
    */
   l_rc = p_call_encoder_procedure(gpp);
   
   gpp->video_encoder_run_state =  GAP_CME_ENC_RUN_STATE_FINISHED;

   if(l_tmp_image_id >= 0)
   {
     gap_image_delete_immediate(l_tmp_image_id);
     g_remove(l_tmpname);
   }


   if(l_tmpname)
   {
     g_free(l_tmpname);
   }

   return (l_rc);
}  /* end gap_cme_gui_start_video_encoder */


/* ----------------------------------------
 * gap_cme_encoder_worker_thread
 * ----------------------------------------
 */
gpointer
gap_cme_encoder_worker_thread(gpointer data)
{
  GapCmeGlobalParams *gpp;

  gpp = (GapCmeGlobalParams *) data;

  if(gap_debug)
  {
    printf("THREAD: gap_cme_encoder_worker_thread &gpp: %d\n", (int)gpp);
  }

  gap_cme_gui_start_video_encoder(gpp);

  if(gap_debug)
  {
    printf("THREAD gap_cme_encoder_worker_thread TERMINATING: %d\n", (int)gpp->val.gui_proc_thread);
  }

  gpp->productive_encoder_thread = NULL;

  return (NULL);
}  /* end gap_cme_encoder_worker_thread */


/* ----------------------------------------
 * gap_cme_gui_start_video_encoder
 * ----------------------------------------
 * start the selected video encoder plug-in
 */
gint32
gap_cme_gui_start_video_encoder_as_thread(GapCmeGlobalParams *gpp)
{
  gboolean joinable;
  if(gpp->ecp == NULL)
  {
    return -1;
  }

#ifdef GAP_USE_GTHREAD
  if(gpp->productive_encoder_thread != NULL)
  {
    return -1;
  }

  /* start a thread for asynchron PDB call of the gui_ procedure
   */
  if(gap_debug)
  {
    printf("MASTER: Before g_thread_create encode video worker\n");
  }

  joinable = TRUE;
  gpp->productive_encoder_thread =
      g_thread_create((GThreadFunc)gap_cme_encoder_worker_thread
                     , gpp  /* data */
                     , joinable
                     , NULL  /* GError **error (NULL dont report errors) */
                     );

  if(gap_debug)
  {
    printf("MASTER: After g_thread_create encode video worker\n");
  }
#else
  /* if threads are not used simply call the procedure
   * (the common GUI window is not refreshed until the called gui_proc ends)
   */
  gap_cme_encoder_worker_thread(gpp);

#endif

  return 0;
}  /* end gap_cme_gui_start_video_encoder_as_thread */






/* ----------------------------------------
 * gap_cme_gui_master_encoder_dialog
 * ----------------------------------------
 * common GUI dialog
 *
 *   return  0 .. OK
 *          -1 .. in case of Error or cancel
 */
gint32
gap_cme_gui_master_encoder_dialog(GapCmeGlobalParams *gpp)
{
  t_global_stb    *gstb;
  GapLibTypeInputRange l_rangetype;

  if(gap_debug) printf("gap_cme_gui_master_encoder_dialog: Start\n");

#ifdef GAP_USE_GTHREAD
  g_thread_init (NULL);
  gdk_threads_init ();
  gdk_threads_enter ();
#endif
  gstb = &global_stb;
  gstb->stb_job_done = FALSE;
  gstb->vidhand_open_ok = FALSE;
  gstb->poll_timertag = -1;
  gstb->total_stroyboard_frames = 0;
  gstb->aud_total_sec = 0.0;

  gimp_ui_init ("gap_master_video_encoder", FALSE);
  gap_stock_init();

  l_rangetype = gpp->val.input_mode;

  /* debug: disable debug save of encoded frames */
  gimp_set_data( GAP_VID_ENC_SAVE_MULTILAYER, "\0\0", 2);
  gimp_set_data( GAP_VID_ENC_SAVE_FLAT, "\0\0", 2);
  gimp_set_data( GAP_VID_ENC_MONITOR, "FALSE", strlen("FALSE") +1);


  /* ---------- dialog ----------*/
  gap_gve_misc_initGapGveMasterEncoderStatus(&gpp->encStatus
       , gap_base_getpid()  /* master_encoder_id */
       , 1         /* total_frames */
       );
  gap_gve_misc_set_master_encoder_cancel_request(&gpp->encStatus, FALSE);
  gpp->video_encoder_run_state = GAP_CME_ENC_RUN_STATE_READY;
  gpp->productive_encoder_thread = NULL;
  gpp->productive_encoder_timertag = -1;
  gpp->encoder_status_poll_timertag = -1;
  gpp->storyboard_create_composite_audio = FALSE;
  gpp->fsv__fileselection = NULL;
  gpp->fsb__fileselection = NULL;
  gpp->fsa__fileselection = NULL;
  gpp->fss__fileselection = NULL;
  gpp->ow__dialog_window = NULL;
  gpp->ecp = pdb_find_video_encoders();

  if(gap_debug) printf("gap_cme_gui_master_encoder_dialog: Before p_create_shell_window\n");

  gpp->shell_window = p_create_shell_window (gpp);

  if(gap_debug) printf("gap_cme_gui_master_encoder_dialog: After p_create_shell_window\n");

  p_init_shell_window_widgets(gpp);
  gtk_widget_show (gpp->shell_window);
  
  if(l_rangetype == GAP_RNGTYPE_STORYBOARD)
  {
    if((gpp->val.storyboard_file[0] != '\0')
    && (gpp->cme__entry_stb != NULL))
    {
      gtk_entry_set_text(GTK_ENTRY(gpp->cme__entry_stb), gpp->val.storyboard_file);
    }
  }

  gpp->val.run = 0;
  gtk_main ();
#ifdef GAP_USE_GTHREAD
  gdk_threads_leave ();
#endif

  if(gap_debug) printf("A F T E R gtk_main run:%d\n", (int)gpp->val.run);

  gpp->shell_window = NULL;

  /* is the encoder specific gui_thread still open ? */
  if(gpp->val.gui_proc_thread != NULL)
  {
     /* wait until thread exits */
     g_thread_join(gpp->val.gui_proc_thread);
     gpp->val.gui_proc_thread = NULL;
  }
  if(gpp->productive_encoder_thread != NULL)
  {
     /* wait until thread exits */
     g_thread_join(gpp->productive_encoder_thread);
     gpp->productive_encoder_thread = NULL;
  }

  if(gpp->val.run)
  {
    return 0;
  }
  return -1;
}  /* end gap_cme_gui_master_encoder_dialog */