Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[c3bd51]: mulaclab.m Maximize Restore History

Download this file

mulaclab.m    3595 lines (3104 with data), 119.9 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
function [] = mulaclab()
%MULACLAB Graphical interface for audio processing using frame multipliers
% Usage: mulaclab;
%
% When starting the interface, the user is asked to choose the processed
% signal, named original signal in the interface. Possible signals are
% `.wav` files and `.mat` files containing decompositions preliminarily
% saved using the `mulaclab` interface. The interface only handles
% monochannel signals. So for a multichannel `.wav` files, the first channel
% is used as the original signal.
%
% After choosing the original signal, the user is presented with the main
% interface. This interface is divided in two areas:
%
% * The right part of the figure contains the visualizations, which
% represent the spectrograms of the original and modified signals.
%
% The 'Original signal' visualization is used to display the original
% signal spectrogram and to graphically define the symbol of the Gabor
% multiplier that will be applied on this signal.
%
% The 'Overview of original signal' visualization also represents the
% original signal spectrogram and can be used for fast zooming and moving
% of the other visualizations. Zooming and moving is controlled by mouse
% interaction with the white rectangle displayed on this visualization.
%
% The 'Modified signal' visualization is used to display the spectrogram
% of the modified signal after application of the multiplier.
%
% It is possible to hide the 'Overview of original signal' and 'Modified
% signal' visulizations using the 'Visualization' menu.
%
% * The left part of the figure contains panels with tools for user
% interaction.
%
% The 'Audioplayer' panel contains the controls for audio playback of the
% original and modified signal.
%
% The 'Visualization' panel contains tools used to adapt the display
% of the visualizations.
%
% The 'Selection' panel contains tools and information concerning the
% multilayered selection used to graphically specify the symbol of the
% multiplier.
%
% Known Matlab limitations:
%
% * When using Matlab on Linux with multiple screens, there might be a
% Matlab bug preventing the display of the multiplier symbol. This can be
% solved by docking the figure.
%
% * When using a Matlab version prior to 7.3 (R2006b), the rectangle
% displayed on the 'Overview of original signal' visualization is not
% automatically updated when using the zoom and pan tools of the 'Zoom'
% panel. It can be manually updated by re-clicking on the currently
% selected tool or by changing the current tool.
%
% The Matlab Image Processing Toolbox is required by the mulaclab function.
%
% MULACLAB uses the GPC library available from
% `<http://www.cs.man.ac.uk/~toby/gpc/>`_. This library is distributed
% alongside LTFAT, but under different licensing conditions. Please see
% the `ltfat/thirdparty/gpc/GPC-README.pdf` file for the exact conditions.
%
% questions : do we want to :
% - have the possibility to use Gaussian window? (any window?)
% - be able to export the symbol?
% - be able to export the coeff?
% - automatically generate a matlab file applying the corresponding gabor
% mutliplier? something like:
% [s, ...] = waveread('rightfile.wav');
% coeff = dgt(f, ...);
% load symbol.mat
% coeff = coeff.*symbol;
% res = idgt(coeff, ...);
% Known bugs:
% - visualization bug when the signal is zero everywhere
% - there might be a bug with noise level when using hole filling with
% noise, check what's happening. I tried to check, but I cannot find
% the bug. Still, something really strange is hapenning, for a given
% selection I will have a level which is too low, when everything works
% nicely with a slightly modified version of the selection.
% - when using undo it seems that parameters of the type of layer are not
% updated
% todo:
% - reorder the functions in this file to improve consistency
% - check the interface with matlab r14
% - check the looking of the interface under linux, windows and mac
% - add possibility to see individual atom of the frame (and the dual)
% (with right clic menu?)
% - possibility to have a nice view (3D?) of the mask
% - possibility to choose the channel and a time selection of wave
% - switch between original and modified when playing
% - add editable keyboard shortcuts for almost everything
% - comment the functions
% - add a simple polygon simplification function (at least for straight
% line with magic wand)
% - for changing mouse pointer, see what can be done using
% iptPointerManager
% - give possibility to use a Gaussian window
% - see if I change the scale used to display symbol (use dB?)
% - precise problems if public distribution of this file (use of
% PolygonClip and icons)
% - update information of contextual menu for layers to know what are the
% currently selected properties
% - see if I put a limit in the number of levels of undo
% - add possibility to modify afterward polygons
% Acronym used in the comments:
% PI: possible improvement, used to specify things that could be done to
% improve the current version of mulaclab. In particular, it can be
% efficiency improvements or suitable functionnality addition.
% _____________________ Description of shared data ________________________
% To share data between the different components of the Graphical User
% Interface (GUI), nested functions are used
% (search for 'Sharing Data Among a GUI's Callbacks' in matlab's
% documentation for more information about this technique).
% So all the functionnalities of the GUI are implemented using nested
% functions, and to share data, a set of variables are defined at the top
% level of the function (ie in the workspace of the function mulaclab).
% Here is a list of these variables with their description:
% sig: (struct) data describing the processed signal
%
% - sig.ori: (vector) samples of the original signal
%
% - sig.mod: (vector) samples of the modified signal
%
% - sig.sampFreq: (scalar) sampling frequency of the original and modified
% signals
%
% - sig.nbBit: (scalar) number of bits to use when saving the modified
% signal
%
% - sig.real: (bool) boolean to know if the signal is real (true)
% or complex (false)
% frame: (struct) data describing the frame
%
% - frame.type: (string) type of the frame (currently only Gabor frames are
% implemented, other frames could be added, like wavelet frames,
% nonstationnary Gabor frames, nonuniform filterbanks, general frames)
%
% - frame.def: (struct) data defining the frame (fields depend of the
% frame type)
%
% For Gabor frames, frame.def fields are:
% - frame.def.winType: (string) type of window as defined in the firwin
% function of LTFAT, see parameter 'name' in the help of firwin
% function for details
%
% - frame.def.winLen: (scalar) window length in number of samples
%
% - frame.def.hop: (scalar) hop size (ie Gabor frame time shift) in
% number of samples (parameter 'a' of LTFAT dgt function)
%
% - frame.def.nbFreq: (scalar) number of frequency bins (parameter 'M'
% of LTFAT dgt function)
% coeff: (struct) coefficients obtained by decomposition of the signal
% on the frame
%
% - coeff.ori: (matrix, dimension 1: frequency, dimension 2:time)
% coefficients for the original signal sig.ori
%
% - coeff.mod: (matrix, dimension 1: frequency, dimension 2:time)
% coefficients for the modified signal sig.mod
% sel: (struct) data describing the graphical selection
% The graphical selection contains several layers, each layer containing
% several polygons defining a region of the time-frequency that must be
% modified. These polygons can be drawn freely by the user using the two
% available tools (freehand selection and magic wand).
% sel contains data defining these polygons and layers, and data
% specifying how they should be plotted
%
% - sel.mode: (string) specifies how the next polygon drawn by the user
% must be combined with the polygons already defined in the currently
% edited layer
% possible modes are 'union', 'intersection', 'difference'
%
% - sel.curLay: index of the currently edited layer
%
% - sel.lay: (struct) data describing the layers, it's a vector of struct,
% and sel.lay(ind) contains data for layer number ind
%
% - sel.lay.convType: (string) conversion type of the layer, it specifies
% how the values of the symbol must be computed for the current layer,
% possible types are:
%
% 'constGain': apply a constant gain on the whole time-frequency region
% corresponding to the polygons of the layer
%
% 'smoothBorder': also apply a gain on the region corresponding to the
% polygons of the layer, but the gain values are smoothed at the border
% to go linearly from 1 outside the polygons to the gain value
% specified for the layer inside the polygons
%
% 'fill': try to fill the region corresponding to the polygons of the
% layer according to the neighborhood level, this is done by
% replacing the absolute value of the coefficient inside the polygons
% by the interpolated values using the level of the coefficient in a
% specified neigborhood outside the polygons
% the phase of the coefficients are left unchanged
%
% 'fillNoise': same as 'fill', but the coefficients inside the polygons
% of the layers are replaced by coefficients obtained from a noise and
% multiplied by the interpolated absolute values
%
% - sel.lay.param: (struct) parameters for the conversion of the layer,
% it's a struct array, sel.lay(indLay).param(indParam) defines the
% parameter number indParam of the layer number indLay
% the number of parameters and their nature depends of the convType
% parameter of the layer according to the following:
%
% * if convType is 'constGain': only one parameter named 'Gain' is
% defined and it contain the value of the constant gain applied to
% region corresponding to the polygons of the layer
%
% * if convType is 'smoothBorder': two parameters named 'Gain' and
% 'Border' are defined
% 'Gain' contain the value of the gain applied inside region
% corresponding to the polygons of the layer away from the border
% 'Border' specify the distance from the border (in number of
% coeffiicents) in which the gain value is linearly interpolated
% between 1 and the value given by 'Gain'
%
% * if convType is 'fill' or 'fillNoise' : two parameters 'Height' and
% 'Width' are defined
% these parameters specifiy the size of the ellipse used to define
% the size of the neighborhood used the estimate the level around the
% polygons
% 'Height' is the radius (in number of coefficients) of the ellipse
% along frequency (y axis), and 'Width' is the radius (in number of
% coefficients) of the ellipse along time (x axis)
%
% - sel.lay.param.name: (string) name of the parameter, as displayed
% in the GUI under the layer list
%
% - sel.lay.param.val: (scalar) the value of the parameter
%
% - sel.lay.lineWidth: (scalar) width of the lines representing the
% polygons of the layer
%
% - sel.lay.color: (colorspec) color of the lines representing the
% polygons of the layer
%
% - sel.lay.marker: (string) marker type of the lines representing the
% polygons of the layer
%
% - sel.lay.markerSize: (scalar) marker size of the lines representing
% the polygons of the layer
%
% - sel.lay.lineStyle: (string) line style of the lines representing the
% polygons of the layer
%
% - sel.lay.poly: (struct) data defining the polygons of the layer, it's
% a struct array, sel.lay(indLay).poly(indPoly) defines the
% polygon number indPoly of the layer number indLay
%
% - sel.lay.poly.x: (row vector) x-coordinates (ie time-coordinates)
% of the polygon points
%
% - sel.lay.poly.y: (row vector) y-coordinates (ie
% frequency-coordinates) of the polygon points
%
% - sel.lay.poly.hole: (bool) specifies if the polygon is a hole
%
% - sel.lay.poly.id: (graphics object handle) handle to the line
% representing the polygon
%
% - sel.lay.label: (string) layer label as displayed in the layer list in
% the GUI
%
% visu: (struct) data defining parameters of the visualizations
% visu is a struct array, visu(ind) contains data for the visualization
% number ind.
% The visualizations are the representations plotted on the right part of
% the GUI. They are plotted in the order specified by visu from top to
% bottom, that is to say that visu(1) is plotted on top, visu(2) is plotted
% under visu(1) and so on.
% PI: Currently only three visualizations are available: the spectrogram
% of the original signal (used as the support for graphical definition of
% the multiplier), the spectrogram of the modified signal to observe the
% effect of the multiplier, and an overview spectrogram of the original
% signal for fast navigation in the time-frequency plane.
% But it should be easy to add some new visualizations if needed. To add a
% new visualization, adding an element to vector visu with appropriate
% parameters and implementing the associated updating function should be
% enough. If the possibility to show and hide the new visualization is
% also needed, some handling of it in the menu is also required.
%
% - visu.label: (string) the title appearing on top of the visualization
%
% - visu.height: (scalar) number specifying the height of the
% visualization. It is a number between 0 and 1 specifying the ratio of
% the figure height that should be used for each visualisation. To cover
% the whole figure, values should be chosen so that they sum up to 1 when
% considering all the visible visualizations
%
% - visu.position: (vector) the position vector of the uipanels containing
% the visualizations. It is automatically computed by function resize
% using the values of visu.height.
%
% - visu.updateFcn: (function handle) the handle of the function that must
% be used to update the plot of the visualization
%
% - visu.dynamic: (scalar) colorscale dynamic of the visualization
% (positive number in dB)
%
% - visu.visible: (bool) boolean specifying if the visualization is
% visible and must be plotted (true) or not (false)
%
% - visu.linkX: (bool) boolean specifying if the visualization x axe (time
% axe) must be linked with the one of the other visualizations
%
% - visu.linkY: (bool) boolean specifying if the visualization y axe
% (frequency axe) must be linked with the one of the other visualizations
%
% - visu.linkCLim: (bool) boolean specifying if the visualization
% colorscale limits must be linked with the one of the other
% visualizations
%
% - visu.uipanelId: (graphics object handle) handle of the uipanel
% containing the visualization
%
% - visu.axesId: (graphics object handle) handle of the axes of the
% visualization
% gui: (struct) graphical user interface data
% gui contains data used to define properties of certain graphics object
% (in particular their position) and data used to dynamically handle the
% inferface (in particular many graphics object handles)
%
% - gui.mainFigPos: (4x1 vector) position of the main figure using the
% usual matlab position definition of the form [left bottom width height]
%
% - gui.fontSize: (scalar) font size (in points) for the elements appearing
% in the panels on the left part of the interface
%
% - gui.textHeight: (scalar) height (in number of pixels) for text
% uicontrol appearing in the panels on the left part of the interface
%
% - gui.textWidth: (scalar) width (in number of pixels) for text
% uicontrol appearing in the panels on the left part of the interface
%
% - gui.editWidth: (scalar) width (in number of pixels) for edit
% uicontrol appearing in the panels on the left part of the interface
%
% - gui.buttonBackgroundColor: (colorspec) background color used for
% uicontrol appearing in the panels on the left part of the interface
%
% - gui.buttonWidth: (scalar) width (in number of pixels) for button
% uicontrol appearing in the panels on the left part of the interface
%
% - gui.buttonHeight: (scalar) height (in number of pixels) for button
% uicontrol appearing in the panels on the left part of the interface
%
% - gui.horiDist: (scalar) horizontal distance (in number of pixels)
% between two elements appearing in the panels on the left part of the
% interface
%
% - gui.vertDist: (scalar) vertical distance (in number of pixels)
% between two elements appearing in the panels on the left part of the
% interface
%
% - gui.margin: (1x2 vector) distance from the border of the panel (in
% number of pixels) of the element closest to the border of the panel.
% First element is horizontal distance, second element is vertical
% distance.
%
% - gui.marginSub: (1x2 vector) same as gui.margin but for elements
% appearing in sub-panels
%
% - gui.panelWidth: (scalar) width (in number of pixels) of the panels
% appearing on the left part of the interface
%
% - gui.panelHeight: (vector) height (in number of pixels) of the panels
% appearing on the left part of the interface. These values must be
% adapted by hand if other parameters such as gui.buttonHeight are
% changed
%
% - gui.panelTitle: (cell array of strings) title of the panels appearing
% on the left part of the interface
%
% - gui.visuResizeButtonWidth: (scalar) width (in number of pixels) of
% the draggable resize buttons appearing between two visualizations on
% the right part of the interface
%
% - gui.visuResizeButtonHeight: (scalar) height (in number of pixels) of
% the draggable resize buttons appearing between two visualizations on
% the right part of the interface
%
% - gui.curTool: (string) currently used graphical tool, can be one of the
% possible names stored in gui.tool.name, which are:
% 'free' for freehand selection
% 'level' for level selection (ie magic wand)
% 'zoomIn' for zoom in mode
% 'zoomOut' for zoom out mode
% 'pan' for pan mode
%
% - gui.tool: (struct) struct array containing tool data
% gui.tool(ind) contains data for tool number ind
%
% - gui.tool.buttonId: (graphics object handle) handle of the tool button
%
% - gui.tool.name: (string) name of the tool, used to identify the
% current tool in gui.curTool
%
% - gui.tool.function (function handle) handle of the function that must
% be executed to initialize the tool when clicking the corresponding
% button
%
% - gui.tool.param: (struct) struct array containing the tool parameters
% the content of this element depends on the tool and is empty for all
% the tools except for the levele selection (magick wand), for which
% one parameter named 'Tolerance' is defined
%
% - gui.tool.param.name: (string) the name of the parameter, as
% displayed under the tools subpanel
%
% - gui.tool.param.val: (string) the value of the parameter represented
% as a string (so a conversion is needed if the parameter is a
% number)
%
% - gui.symbOpacity: (scalar) opacity value used for plotting of symbol
% (any value between 0:transparent and 1:opaque)
%
% - gui.showSymb: (bool) boolean specifying if the symbol should be plotted
% (true) or not (false)
%
% - gui.symbImageId: (graphics object handle) handle of the image used to
% plot the symbol (the symbol is plotted as a transparent image on top
% of the image of the spectrogram)
%
% - gui.player: (struct) structure containing the handles associated with
% the gui of the audioplayer
%
% - gui.player.buttongroupId: (graphics object handle) handle of the
% buttongroup used for the selection of the signal played (original or
% modified)
%
% - gui.player.buttonOriId: (graphics object handle) handle of the radio
% button for the selection of original signal
%
% - gui.player.buttonModId: (graphics object handle) handle of the radio
% button for the selection of modified signal
%
% - gui.ResizeVisuButtonId: (graphics object handle vector) vector
% containing the handles of the draggable resize buttons appearing
% between two visualizations on the right part of the interface
%
% - gui.mainFigId: (graphics object handle) handle of the main figure of
% the interface
%
% - gui.undoMenuId: (graphics object handle) handle of the 'Undo' menu
% element
%
% - gui.redoMenuId: (graphics object handle) handle of the 'Redo' menu
% element
%
% - gui.visuMenu: (struct) structure containing menu handles used to show
% and hide visualizations
%
% - gui.visuMenu.showModId: (graphics object handle) handle of the
% 'Show modified signal' menu element
%
% - gui.visuMenu.showOverviewId: (graphics object handle) handle of the
% 'Show overview of original signal' menu element
%
% - gui.exploreRect: (struct) handle of the graphical objects used to
% represent the rectangular selection on the overview of original signal
% visualization
%
% - gui.exploreRect.patchId: (graphics object handle) handle of the patch
% used to draw the movable selection rectangle
%
% - gui.exploreRect.lineId: (graphics object handle) handle of the line
% used to draw the movable points at the corners of the rectangle
%
% - gui.panelId: : (graphics object handle vector) vector containg the
% handles of the uipanels drawn on the left part of the interface
%
% - gui.editDynamicId: (graphics object handle) handle of the edit
% uicontrol used to specify the colorscale dynamic
%
% - gui.layListId: (graphics object handle) handle of the listbox
% uicontrol used to show the slection layers list
%
% - gui.layPanelId: (graphics object handle) uipanel handle of the 'Layers'
% subpanel
%
% - gui.toolPanelId: (graphics object handle) uipanel handle of the 'Tools'
% subpanel
% link: (struct) data for linking of axes of the different visualization
%
% - link.CLim: (linkprop object) link object used to link the colorscale
% limits (through the CLim property) of the visualizations having their
% parameter visu.linkCLim set to true
%
% - link.XLim: (linkprop object) link object used to link the time axe
% (through the XLim property) of the visualizations having their
% parameter visu.linkXLim set to true
%
% - link.YLim: (linkprop object) link object used to link the frequency axe
% (through the YLim property) of the visualizations having their
% parameter visu.linkYLim set to true
% player: (struct) data used for audio playing
%
% - player.ori: (audioplayer object) audioplayer used to play the original
% signal
%
% - player.mod: (audioplayer object) audioplayer used to play the modified
% signal
%
% - player.selected: (string) indicate the currently selected audio signal
% can be 'ori' for the original signal, or 'mod' for the modified signal
%
% - player.loop: (bool) indicate if the audio signal must be looped (true)
% or not (false) when playing
%
% - player.position: (scalar) sample position at which the audio playing
% will start at next pressing of start
%
% - player.forceStop: (bool) indicate to the stop function of the
% audioplayer that the player must be stopped (needed to be able to stop
% when looping)
%
% - player.positionPlotId: (graphics object handle vector) contains handles
% to the moving vertical white lines that are displayed on the
% visualizations to show the current position when playing
% default default data for some variables
% PI: This could be used more systematically to define the default value
% of all the parameters of the interface. It could then be used to
% configure the application by loading variable default from a file during
% initialization, and we could also give the possibility to the user
% to modify these default values
%
% - default.dynamic: (scalar) default value for colorscale dynamic
% (positive number in dB)
%
% - default.opacity: (scalar) default value for opacity used for plotting
% of symbol (any value between 0:transparent and 1:opaque)
%
% - default.sel: (struct) default sel variable (see the description of sel)
%
% - default.frame: (struct) default frame variable (see the description of
% frame)
% undoData: (cell) data for undo functionnality
% Each cell of undoData contain a copy of the sel variable as it was at a
% preceding state
% redoData: (cell) data for redo functionnality
% Each cell of redoData contain a copy of the sel variable as it was at a
% preceding state
% ___________________ End of description of shared data ___________________
% __________________________ Beginning of code ____________________________
% define the variables that will be used to share data between
% interface components. They are defined at the top level of the function
% so that they are usable by all the functions used by the interface (as
% these are nested functions).
coeff = struct;
default = struct;
frame = struct;
gui = struct;
link = struct;
player = struct;
redoData = {};
sel = struct;
sig = struct;
undoData = {};
visu = struct;
iconpath=[ltfatbasepath,'mulaclab',filesep,'icons',filesep];
% initialize the interface
initialize;
% end of main function, from here everything is handled with the callbacks
% using the following nested functions
% __________________________ INITIALIZATION _______________________________
function initialize()
% check that we have all the toolboxes and functions that we need
checkToolbox;
% Display spash screen
h=msgbox({['MulacLab: Matlab GUI to manipulate the short-time Fourier ' ...
'transform of a signal using Gabor multipliers.'],[],...
['MulacLab makes use of the GPC Polygon Clipping library ' ...
'available from http://www.cs.man.ac.uk/~toby/alan/software/'],[]...
['GPC and mulaclab are free for non-commercial use only. Please see the ' ...
'GPC homepage for the exact licensing conditions.']},...
'MulacLab licensing','modal');
uiwait(h,5);
if ishandle(h)
% Timeout occured, we close the box automatically.
close(h);
end;
% get an original signal or decomposition to have something to show
[fileName, pathName, filterIndex] = uigetfile('*.wav;*.mat',...
'Open original signal or decomposition');
if fileName == 0
% the user pressed cancel, we stop here
return;
else
[pathStr, name, ext] = fileparts(fileName);
switch ext
case '.wav'
% read the orginal signal in a wave file
[sig.ori, sig.sampFreq, sig.nbBit] =...
wavread([pathName, fileName]);
if size(sig.ori, 2) > 1
% multichannel wave, we keep only the first channel
sig.ori = sig.ori(:, 1);
end
sig.real = true;
case '.mat'
% read the original signal decomposition in a mat file
data = load([pathName, fileName]);
if isfield(data, 'frame') && isfield(data, 'savedSig')
frame = data.frame;
sig = data.savedSig;
else
errordlg(...
[fileName ' is not a valid signal decomposition file']);
return;
end
end
end
sig.mod = sig.ori;
% intialize the different parameters of the application
initializeParameter;
% initialize the frame definition and the coefficients
frame = default.frame;
updateCoeffOri;
coeff.mod = coeff.ori;
% initialize selection
resetSel;
% intialize audioplayers
initializePlayer;
% create main window
gui.mainFigId = figure(...
'Name', 'MulAcLab',...
'Position', gui.mainFigPos,...
'Toolbar', 'none',...
'Colormap', jet(256),...
'ResizeFcn', @resize,...
'MenuBar', 'none',...
'WindowStyle', 'normal',...
'Visible', 'off');
% create menu of main window
menuFileId = uimenu(gui.mainFigId, 'Label','File');
uimenu(menuFileId,...
'Label','Open original signal',...
'Callback',@openOriSig);
uimenu(menuFileId,...
'Label','Open original signal decomposition',...
'Callback',@openOriDecompo);
uimenu(menuFileId,...
'Label','Import selection',...
'Callback',@importSel);
uimenu(menuFileId,...
'Label','Save modified signal',...
'Callback',@saveModSig,...
'Separator', 'on');
uimenu(menuFileId,...
'Label','Save original signal decomposition',...
'Callback',@saveOriDecompo);
uimenu(menuFileId,...
'Label','Save modified signal decomposition',...
'Callback',@saveModDecompo);
uimenu(menuFileId,...
'Label','Export selection',...
'Callback',@exportSel);
menuEditId = uimenu(gui.mainFigId,...
'Label','Edit');
gui.undoMenuId = uimenu(menuEditId,...
'Label','Undo',...
'Accelerator', 'z',...
'enable', 'off',...
'Callback',@undo);
gui.redoMenuId = uimenu(menuEditId,...
'Label','Redo',...
'Accelerator', 'y',...
'enable', 'off',...
'Callback',@redo);
menuFrameId = uimenu(gui.mainFigId,...
'Label','Frame');
uimenu(menuFrameId,...
'Label','Edit frame parameters',...
'Callback',@changeFrameDef);
uimenu(menuFrameId,...
'Label','Load frame parameters',...
'Callback',@loadFrameParam,...
'Separator', 'on');
uimenu(menuFrameId,...
'Label','Save frame parameters',...
'Callback',@saveFrameParam);
menuVisuId = uimenu(gui.mainFigId,...
'Label','Visualization');
% !!! the folowing checked on or off should be set automatically
% during initialization
gui.visuMenu.showModId = uimenu(menuVisuId,...
'Label','Show modified signal',...
'Checked', 'off',...
'Callback',@toggleModVisu);
gui.visuMenu.showOverviewId = uimenu(menuVisuId,...
'Label','Show overview of original signal',...
'Checked', 'on',...
'Callback',@toggleOverviewVisu);
% intialize visualization
updateVisu(true);
% create gui panels
currentY = 1;
for indPanel = 1:length(gui.panelHeight)
gui.panelId(indPanel) = uipanel(gui.mainFigId, ...
'Title', gui.panelTitle{indPanel},...
'TitlePosition', 'centertop',...
'FontSize', gui.fontSize, ...
'Units', 'pixels', ...
'Position', [1 currentY gui.panelWidth gui.panelHeight(indPanel)]);
currentY = currentY + gui.panelHeight(indPanel);
end
% create audioplayers panel
drawAudioplayer(gui.panelId(1));
% create visualization tools panel
drawVisualizationTool(gui.panelId(2));
% create selection tools panel
drawSelectionTool(gui.panelId(3));
% activate the current tool
changeTool([], [], gui.curTool);
% end of initialization, show the interface to the user
set(gui.mainFigId, 'Visible', 'on');
end
function initializeParameter()
% set default values
% default colorscale dynamic in dB
default.dynamic = 60;
% default opacity parameter for symbol plotting (from 0:transparent to
% 1:opaque)
default.opacity = 0.5;
% default selection
default.sel.mode = 'union';
default.sel.curLay = 1;
default.sel.lay.convType = 'constGain';
default.sel.lay.param(1).name = 'Gain';
default.sel.lay.param(1).val = 0;
default.sel.lay.lineWidth = 2;
default.sel.lay.color = 'w';
default.sel.lay.marker = 'none';
default.sel.lay.markerSize = 2;
default.sel.lay.lineStyle = '-';
default.sel.lay.poly = [];
default.sel.lay.label = 'Layer';
% default frame definition
default.frame.type = 'Gabor';
default.frame.def.winType = 'hann';
default.frame.def.winLen = 256;
default.frame.def.hop = round(default.frame.def.winLen / 4);
default.frame.def.nbFreq = default.frame.def.winLen;
% define parameters for the gui (graphical user interface)
monitorPos = get(0,'monitorposition');
monitorPos = monitorPos(1, :);
ratio = 0.75;
gui.mainFigPos = round([monitorPos([3, 4])*0.5*(1-ratio),...
round(monitorPos([3, 4])*ratio)]);
gui.fontSize = 9;
gui.textHeight = gui.fontSize + 7;
gui.textWidth = 57;
gui.editWidth = 28;
gui.buttonBackgroundColor = [0.7 0.7 0.7]; % chosen to fit icons color
gui.buttonWidth = 27;
gui.buttonHeight = 22;
gui.horiDist = 3;
gui.vertDist = 2;
gui.margin = [5, 5];
gui.marginSub= [3, 3];
nbButtton = 3; % number of buttons on one line
gui.panelWidth = 2*gui.margin(2) + (nbButtton-1) * gui.horiDist +...
nbButtton*gui.buttonWidth;
gui.panelHeight(1) = 91;
gui.panelTitle{1} = 'Audioplayer';
gui.panelHeight(2) = 163;
gui.panelTitle{2} = 'Visualization';
gui.panelHeight(3) = 260;
gui.panelTitle{3} = 'Selection';
gui.visuResizeButtonWidth = 15;
gui.visuResizeButtonHeight = 15;
gui.curTool = 'freehand';
gui.tool = struct;
gui.symbOpacity = 0.5;
gui.showSymb = false;
gui.symbImageId = [];
gui.player.buttongroupId = [];
% define parameters for the visualizations
% !!! height of visu at initilisation must be choosen so that the sum
% of visible visu is 1
% Main visualization: spectrogram of the original signal
visu(1).label = 'originalMain';
visu(1).height = 0.67;
visu(1).position = [0, 0, 1, 1]; % we can initialise this with wathever
% value as it will be corrrected
% during resize
visu(1).updateFcn = @updateVisuOriSpec;
visu(1).dynamic = default.dynamic;
visu(1).visible = true; % Important: the orginalMain visu must always
% stay visible
visu(1).linkX = true;
visu(1).linkY = true;
visu(1).linkCLim = true;
visu(1).uipanelId = [];
visu(1).axesId = [];
% Visualization of the spectrogram of the modified signal
visu(2).label = 'modified';
visu(2).height = 0.;
visu(2).position = [0, 0, 1, 1];
visu(2).updateFcn = @updateVisuModSpec;
visu(2).dynamic = default.dynamic; % useless if linkCLim is true
visu(2).visible = false;
visu(2).linkX = true;
visu(2).linkY = true;
visu(2).linkCLim = true;
visu(2).uipanelId = [];
visu(2).axesId = [];
% Visualization for the overview of the original spectrogram with fast
% scrolling
visu(3).label = 'originalOverview';
visu(3).height = 0.33;
visu(3).position = [0, 0, 1, 1];
visu(3).updateFcn = @updateVisuOriOverview;
visu(3).dynamic = default.dynamic; % useless if linkCLim is true
visu(3).visible = true;
visu(3).linkX = false;
visu(3).linkY = false;
visu(3).linkCLim = true;
visu(3).uipanelId = [];
visu(3).axesId = [];
gui.ResizeVisuButtonId = NaN(length(visu), 1);
end
function checkToolbox()
if isoctave
error('This function requires Matlab.');
end;
% Check that the Image Processing Toolbox is available
if isempty(ver('images'))
error(...
'This function requires the Matlab Image Processing Toolbox.');
end
% Check that the function for polygon clipping is available
temp1.x = [1];
temp1.y = [1];
temp1.hole = false;
temp2 = temp1;
try
temp = PolygonClip(temp1, temp2);
catch
error(['This function requires the function PolygonClip for ' ...
'polygon clipping. Please compile using the "ltfatmex" ' ...
'command.']);
end
% !!! check if some other toolboxes are needed (signal processing?)
end
% ___________________ COMPUTATIONAL FUNCTIONS _____________________________
function updateCoeffOri()
%!!! modify to work with any type of frame and with multiple frames
% compute analysis window
win = firwin(frame.def.winType,frame.def.winLen);
% compute Gabor coefficients
coeff.ori = dgt(sig.ori, win, frame.def.hop, frame.def.nbFreq);
end
function updateCoeffMod()
%!!! modify to work with any type of frame and with multiple frames
% compute analysis window
win = firwin(frame.def.winType,frame.def.winLen);
% compute Gabor coefficien
coeff.mod = dgt(sig.mod, win, frame.def.hop, frame.def.nbFreq);
end
function updateSigMod()
% compute synthesis window
win = gabdual(firwin(frame.def.winType,frame.def.winLen), ...
frame.def.hop, frame.def.nbFreq);
% compute modified signal
sig.mod = idgt(coeff.mod, win, frame.def.hop, length(sig.ori));
end
function applySel(objId, eventData)
% convert the selection to get the symbol of the multiplier and apply
% the multiplier
symb = convSelToSymb;
coeff.mod = coeff.ori .* symb;
updateSigMod;
updatePlayerMod;
updateCoeffMod;
modInd = find(strcmp('modified', {visu.label}), 1);
if ~visu(modInd).visible
toggleModVisu;
end
updateVisu;
end
function mask = convPolyToMask(poly)
mask = zeros(size(coeff.ori));
% !!! Note: type of data for the mask might be optmized (bool, uint8?)
% !!! could be optimized by doing the conversion in smaller boxes
% around each polygon (not on the whole time-frequency plane)
% and also working with a smaller mask when signal is real
for ind = 1:length(poly)
if poly(ind).hole
mask = mask - poly2mask(convAxesToIndX(poly(ind).x),...
convAxesToIndY(poly(ind).y),...
size(mask,1), size(mask,2));
else
mask = mask + poly2mask(convAxesToIndX(poly(ind).x),...
convAxesToIndY(poly(ind).y),...
size(mask,1), size(mask,2));
end
end
% !!! modifiy this: don't do the symetrisation on the mask, but on the
% symbol to insure that the results is real
if sig.real
temp = ceil(size(mask, 1)/2);
mask(end:-1:end-temp+2,:) = mask(2:temp,:);
end
end
function symb = convMaskToSymb(mask, indLay)
% !!! precise that a case should be added here when creating new
% selection type
switch sel.lay(indLay).convType
case 'constGain'
gain = sel.lay(indLay).param(1).val;
symb = ones(size(mask));
symb = symb + (gain-1)*mask;
case 'smoothBorder'
gain = sel.lay(indLay).param(1).val;
threshold = sel.lay(indLay).param(2).val;
symb = bwdist(~mask);
symb(find(symb > threshold)) = threshold;
symb = symb * (gain-1)/threshold + 1;
case 'fill'
% !!! first filling test, just interpolating in 3D the modulus
% estimation of the level in the neighbourhood of the selection
timeRadius = sel.lay(indLay).param(1).val;
freqRadius = sel.lay(indLay).param(2).val;
% find the points that are just next to the selection
neighbour = imdilate(mask, strel('square',3)) - mask;
% for these points, compute mean level in a specified neighbourhood
% (but not taking into account the values of the transform inside
% the selection)
% create the matrix defining the neighbourhood
mat = computeEllipse(freqRadius, timeRadius);
% !!! this could be a more general filter if we want
temp1 = roifilt2(mat, abs(coeff.ori).^2 .* (1-mask), neighbour);
temp2 = roifilt2(mat, 1-mask, neighbour);
% !!! specifiy in comment that we have to do this to take into
% account the hole
[ind1Neigh, ind2Neigh] = find(neighbour);
valNeigh = sqrt(temp1(sub2ind(size(temp1), ind1Neigh,...
ind2Neigh))./temp2(sub2ind(size(temp2), ind1Neigh, ind2Neigh)));
[ind1Mask, ind2Mask] = find(mask);
try
valInterp = griddata(ind1Neigh, ind2Neigh, valNeigh,...
ind1Mask, ind2Mask, 'linear');
catch
% sometime griddata fail, and adding this option seem to solve
% the problem, but I don't really know what I'm doing here !!!
valInterp = griddata(ind1Neigh, ind2Neigh, valNeigh,...
ind1Mask, ind2Mask, 'linear', {'QJ'});
end
symb = ones(size(mask));
% !!! there will be division by zero problem in the following
% solve this problem
symb(sub2ind(size(symb), ind1Mask, ind2Mask)) = valInterp ./...
abs(coeff.ori(sub2ind(size(coeff.ori), ind1Mask, ind2Mask)));
% !!! temporary modif: should be removed when modification are done
% so that symetrisation is done on symbol and not mask when signal
% is real
if sig.real
temp = ceil(size(symb, 1)/2);
symb(end:-1:end-temp+2,:) = conj(symb(2:temp,:));
end
case 'fillNoise'
% other hole filling test, using coefficients taken from a noise
% estimation of the level in the neighbourhood of the selection
timeRadius = sel.lay(indLay).param(1).val;
freqRadius = sel.lay(indLay).param(2).val;
% find the points that are just next to the selection
neighbour = imdilate(mask, strel('square',3)) - mask;
% for these points, compute mean level in a specified neighbourhood
% (but not taking into account the values of the transform inside
% the selection)
% create the matrix defining the neighbourhood
mat = computeEllipse(freqRadius, timeRadius);
% !!! this could be a more general filter if we want
temp1 = roifilt2(mat, abs(coeff.ori).^2 .* (1-mask), neighbour);
temp2 = roifilt2(mat, 1-mask, neighbour);
% !!! specifiy in comment that we have to do this to take into
% account the hole
[ind1Neigh, ind2Neigh] = find(neighbour);
valNeigh = sqrt(temp1(sub2ind(size(temp1), ind1Neigh,...
ind2Neigh))./temp2(sub2ind(size(temp2), ind1Neigh, ind2Neigh)));
[ind1Mask, ind2Mask] = find(mask);
try
valInterp = griddata(ind1Neigh, ind2Neigh, valNeigh, ...
ind1Mask, ind2Mask, 'linear');
catch
% sometime griddata fail, and adding this option seem to solve
% the problem, but I don't really know what I'm doing here !!!
valInterp = griddata(ind1Neigh, ind2Neigh, valNeigh,...
ind1Mask, ind2Mask, 'linear', {'QJ'});
% !!! remove this
disp('Problem with griddata')
end
symb = ones(size(mask));
% compute the transform of a noise
% !!! should be done in a nicer way with an external function
% so that it works with any kind of frame
noiseLen = (max(ind2Mask) - min(ind2Mask) + 1) * frame.def.hop ;
noise = rand(noiseLen, 1) - 0.5;
win = firwin(frame.def.winType, frame.def.winLen);
coeffNoise = dgt(noise, win, frame.def.hop, frame.def.nbFreq);
% !!! test figure(100); imagesc(20*log10(abs(coeffNoise)))
% !!! there will be division by zero problem in the following
% solve this problem
% !!! old version
% symb(sub2ind(size(symb), ind1Mask, ind2Mask)) = valInterp .*...
% coeffNoise(sub2ind(size(coeffNoise), ind1Mask,...
% ind2Mask-min(ind2Mask)+1)) ./...
% coeff.ori(sub2ind(size(coeff.ori), ind1Mask, ind2Mask)) ./...
% abs(coeffNoise(sub2ind(size(coeffNoise), ind1Mask,...
% ind2Mask-min(ind2Mask)+1)));
% !!! here all the interpolations and mean are done directly on the
% absolute value of the coefficients, it could be more meaningfull
% to work with the sqaure of the modulus due to its possible
% intepretation a energy ditribution
meanLevelNoise = sum(abs(coeffNoise(sub2ind(size(coeffNoise), ...
ind1Mask, ind2Mask-min(ind2Mask)+1)))) / length(ind1Mask);
% !!! tests
% symb(sub2ind(size(symb), ind1Mask, ind2Mask)) = valInterp .*...
% coeffNoise(sub2ind(size(coeffNoise), ind1Mask,...
% ind2Mask-min(ind2Mask)+1)) ./...
% (coeff.ori(sub2ind(size(coeff.ori), ind1Mask, ind2Mask)) *...
% meanLevelNoise);
symb(sub2ind(size(symb), ind1Mask, ind2Mask)) = valInterp .*...
coeffNoise(sub2ind(size(coeffNoise), ind1Mask,...
ind2Mask-min(ind2Mask)+1)) ./...
(coeff.ori(sub2ind(size(coeff.ori), ind1Mask, ind2Mask)) *...
meanLevelNoise);
% meanLevelOri = sum(abs(coeff.ori(sub2ind(size(coeff.ori), ...
% ind1Mask, ind2Mask)))) / length(ind1Mask);
%
% symb(sub2ind(size(symb), ind1Mask, ind2Mask)) = ...
% meanLevelOri*coeffNoise(sub2ind(size(coeffNoise), ind1Mask,...
% ind2Mask-min(ind2Mask)+1+ 5)) ./...
% (coeff.ori(sub2ind(size(coeff.ori), ind1Mask, ind2Mask))*meanLevelNoise);
% !!! temporary modif: should be removed when modification are done
% so that symetrisation is done on symbol and not mask when signal
% is real
if sig.real
temp = ceil(size(symb, 1)/2);
symb(end:-1:end-temp+2,:) = conj(symb(2:temp,:));
end
end % of switch
end
function ellipse =computeEllipse(dim1Radius, dim2Radius)
ellipse = zeros(2*dim1Radius+1, 2*dim2Radius+1);
ellipse(dim1Radius+1, :) = 1;
ellipse(:, dim2Radius+1) = 1;
for ind1 = 1:dim1Radius-1
for ind2 = 1:dim2Radius-1
if ((ind1/dim1Radius)^2 + (ind2/dim2Radius)^2) <= 1
ellipse(dim1Radius+1+ind1, dim2Radius+1+ind2) = 1;
ellipse(dim1Radius+1-ind1, dim2Radius+1+ind2) = 1;
ellipse(dim1Radius+1+ind1, dim2Radius+1-ind2) = 1;
ellipse(dim1Radius+1-ind1, dim2Radius+1-ind2) = 1;
end
end
end
end
function symb = convSelToSymb()
symb = ones(size(coeff.mod));
for indLay = 1:length(sel.lay)
if ~isempty(sel.lay(indLay).poly)
mask = convPolyToMask(sel.lay(indLay).poly);
curSymb = convMaskToSymb(mask, indLay);
symb = symb .* curSymb;
else
warning(['Selection layer ' num2str(indLay)...
' is currently empty']);
end
end
end
function xData = convIndToAxesX(ind)
% convert scale from image index to scale used by axes along X axe
xData = (ind-1) * (frame.def.hop / sig.sampFreq);
end
function ind = convAxesToIndX(xData)
% !!! there is no round (on purpose), should be added if we really want
% an integer index
% convert scale from scale used by axes to image index along X axe
ind = xData * (sig.sampFreq / frame.def.hop) + 1;
end
function yData = convIndToAxesY(ind)
% convert scale from image index to scale used by axes along Y axe
yData = (ind-1) * (sig.sampFreq / frame.def.nbFreq);
end
function ind = convAxesToIndY(yData)
% !!! there is no round (on purpose), should be added if we really want
% an integer index
% convert scale from scale used by axes to image index along Y axe
ind = yData * (frame.def.nbFreq / sig.sampFreq) + 1;
end
% _____________________ GENERAL FUNCTIONS FOR UI __________________________
function matlabVersion = getMatlabVersion()
matlabVersion = ver('Matlab');
matlabVersion = matlabVersion.Version;
% the version number is sometime of the form X.X.X, so it cannot be
% easily converted into a number, so we need to modify it so that it
% is more usable for comparison
temp = find(matlabVersion == '.');
temp = temp(2:end);
for ind = 1:size(temp, 2)
% we remove the extra points '.' in the string
matlabVersion = matlabVersion([1:temp(ind)-1, temp(ind)+1:end]);
end
matlabVersion = str2num(matlabVersion);
end
function openOriSig(objId, eventData)
[fileName, pathName, filterIndex] = uigetfile('*.wav',...
'Open original signal');
if fileName == 0
% user pressed cancel, stop here
return;
end
[newSig, sampFreq, nbBit] = wavread([pathName, fileName]);
if size(newSig, 2) > 1
% multichannel wave, we keep only the first channel
newSig = newSig(:, 1);
end
sig.sampFreq = sampFreq;
sig.nbBit = nbBit;
sig.ori = newSig;
sig.mod = newSig;
sig.real = true;
initializePlayer;
updateCoeffOri;
coeff.mod = coeff.ori;
resetSel;
undoData = {};
updateVisu(true); % update visualization with reset of axes limits
% activate the current tool
changeTool([], [], gui.curTool);
end
function saveModSig(objId, eventData)
[fileName, pathName] = uiputfile('*.wav', 'Save modified signal');
if fileName == 0
% user pressed cancel, stop here
return;
end
wavwrite(sig.mod, sig.sampFreq, sig.nbBit, [pathName, fileName]);
end
function openOriDecompo(objId, eventData)
[fileName, pathName] = uigetfile('*.mat', 'Load frame parameters');
if fileName == 0
% user pressed cancel, stop here
return;
end
data = load([pathName, fileName]);
if ~(isfield(data, 'frame') && isfield(data, 'savedSig'))
errordlg([fileName ' is not a valid signal decomposition file']);
return;
end
frame = data.frame;
sig = data.savedSig;
sig.mod = sig.ori;
initializePlayer;
updateCoeffOri;
coeff.mod = coeff.ori;
resetSel;
undoData = {};
updateVisu(true); % update visualization with reset of axes limits
% activate the current tool
changeTool([], [], gui.curTool);
end
function saveOriDecompo(objId, eventData)
[fileName, pathName] = uiputfile('*.mat', 'Export selection');
if fileName == 0
% user pressed cancel, stop here
return;
end
savedSig = sig;
rmfield(savedSig, 'mod');
save([pathName, fileName], 'frame', 'savedSig');
end
function saveModDecompo(objId, eventData)
[fileName, pathName] = uiputfile('*.mat', 'Export selection');
if fileName == 0
% user pressed cancel, stop here
return;
end
savedSig = sig;
savedSig.ori = savedSig.mod;
rmfield(savedSig, 'mod');
save([pathName, fileName], 'frame', 'savedSig');
end
function exportSel(objId, eventData)
[fileName, pathName] = uiputfile('*.mat', 'Export selection');
if fileName == 0
% user pressed cancel, stop here
return;
end
save([pathName, fileName], 'sel');
end
function importSel(objId, eventData)
[fileName, pathName] = uigetfile('*.mat', 'Import selection');
if fileName == 0
% user pressed cancel, stop here
return;
end
data = load([pathName, fileName]);
if ~isfield(data, 'sel')
errordlg([fileName ' is not a valid signal selection file']);
return;
end
% as the saved selection might have been created using a longer signal,
% or a signal with a higher sampling frequency, it could be wider that
% the part of the time-frequency plane corresponding to the signal.
% We need to force the selection to stay in the right region
fullPoly = fullSigPoly;
for ind = 1:length(data.sel.lay)
% intersection of the polygon with a polygon covering the whole
% signal
data.sel.lay(ind).poly = PolygonClip(data.sel.lay(ind).poly,...
fullPoly, 1);
end
delSel;
sel.lay(end+1:end+length(data.sel.lay)) = data.sel.lay;
updateLayerList;
set(gui.layListId, 'Value', 1);
changeSelLay;
drawAllSel;
end
function changeFrameDef(objId, eventData)
newFrame = changeGaborFrameDialog(frame);
if ~isempty(newFrame)
frame = newFrame;
updateCoeffOri;
updateCoeffMod;
updateVisu;
end
end
function newFrame = changeGaborFrameDialog(oldFrame)
newFrame = [];
margin = [10, 10];
textSize = [170, 20];
editSize = [80, 20];
spaceSize = [10, 10];
nbParam = 4;
dialogPosition = [200, 200, ...
2*margin(1)+textSize(1)+editSize(1)+spaceSize(1),...
2*margin(2)+(nbParam+1)*textSize(2)+nbParam*spaceSize(1)];
dialogId = dialog(...
'Name', 'Frame parameters',...
'Position', dialogPosition);
buttonWidth = 50;
buttonX = round((dialogPosition(3) -...
(2*buttonWidth + spaceSize(1)))/2);
buttonOkId = uicontrol(...
'Parent', dialogId,...
'Style', 'pushbutton',...
'String', 'OK',...
'Callback', @callbackOk,...
'Position', [buttonX, margin(2), buttonWidth, textSize(2)]);
buttonCancelId = uicontrol(...
'Parent', dialogId,...
'Style', 'pushbutton',...
'String', 'Cancel',...
'Callback', @callbackCancel,...
'Position', [buttonX+buttonWidth+spaceSize(1), margin(2),...
buttonWidth, textSize(2)]);
ind = 1;
posText = [margin+[0, ind*(spaceSize(2)+textSize(2))], textSize];
posEdit = [margin+[0,...
ind*(spaceSize(2)+textSize(2))]+[textSize(1)+spaceSize(1), 0],...
editSize];
textNbFreqId = uicontrol(...
'Parent', dialogId,...
'Style', 'text',...
'String', 'Number of frequency bins',...
'Position', posText);
editNbFreqId = uicontrol(...
'Parent', dialogId,...
'Style', 'edit',...
'String', num2str(frame.def.nbFreq),...
'Position', posEdit);
ind = 2;
posText = [margin+[0, ind*(spaceSize(2)+textSize(2))], textSize];
posEdit = [margin+[0,...
ind*(spaceSize(2)+textSize(2))]+[textSize(1)+spaceSize(1), 0],...
editSize];
textHopId = uicontrol(...
'Parent', dialogId,...
'Style', 'text',...
'String', 'Hop size',...
'Position', posText);
editHopId = uicontrol(...
'Parent', dialogId,...
'Style', 'edit',...
'String', num2str(frame.def.hop),...
'Position', posEdit);
ind = 3;
posText = [margin+[0, ind*(spaceSize(2)+textSize(2))], textSize];
posEdit = [margin+[0,...
ind*(spaceSize(2)+textSize(2))]+[textSize(1)+spaceSize(1), 0],...
editSize];
textWinLenId = uicontrol(...
'Parent', dialogId,...
'Style', 'text',...
'String', 'Window length',...
'Position', posText);
editWinLenId = uicontrol(...
'Parent', dialogId,...
'Style', 'edit',...
'String', num2str(frame.def.winLen),...
'Position', posEdit);
ind = 4;
posText = [margin+[0, ind*(spaceSize(2)+textSize(2))], textSize];
posEdit = [margin+[0,...
ind*(spaceSize(2)+textSize(2))]+[textSize(1)+spaceSize(1), 0],...
editSize];
textWinTypeId = uicontrol(...
'Parent', dialogId,...
'Style', 'text',...
'String', 'Window type',...
'Position', posText);
editWinTypeId = uicontrol(...
'Parent', dialogId,...
'Style', 'edit',...
'String', frame.def.winType,...
'Position', posEdit);
uiwait(dialogId);
function callbackOk(objId, eventData)
newFrame.type = 'Gabor';
newFrame.def.winType = get(editWinTypeId, 'string');
newFrame.def.winLen = round(str2num(get(editWinLenId, 'string')));
if isempty(newFrame.def.winLen)
errordlg('Window length parameter is invalid');
return;
end
newFrame.def.hop = round(str2num(get(editHopId, 'string')));
if isempty(newFrame.def.hop)
errordlg('Hop size parameter is invalid');
return;
end
newFrame.def.nbFreq = round(str2num(get(editNbFreqId, 'string')));
if isempty(newFrame.def.nbFreq)
errordlg('Number of frequency bins is invalid');
return;
end
close(dialogId);
end
function callbackCancel(objId, eventData)
newFrame = [];
close(dialogId);
end
end
function loadFrameParam(objId, eventData)
[fileName, pathName] = uigetfile('*.mat', 'Load frame parameters');
if fileName == 0
% user pressed cancel, stop here
return;
end
data = load([pathName, fileName]);
if ~isfield(data, 'frame')
errordlg([fileName ' is not a valid signal frame file']);
return;
end
frame = data.frame;
updateCoeffOri;
updateCoeffMod;
updateVisu;
end
function saveFrameParam(objId, eventData)
[fileName, pathName] = uiputfile('*.mat', 'Save frame parameters');
if fileName == 0
% user pressed cancel, stop here
return;
end
save([pathName, fileName], 'frame');
end
function pos = buttonPos(indHori, indVert, shift)
% compute the position of a button (useful to align buttons)
% indHori: horizontal index of the button for which we want the
% position (first element with index 1 on the left)
% indVert: vertical index of the button for which we want the
% position (first element with index 1 at the bottom)
pos = [shift(1) + (indHori-1)*(gui.buttonWidth+gui.horiDist)-1,...
shift(2) + (indVert-1)*(gui.buttonHeight+gui.vertDist)-1,...
gui.buttonWidth,...
gui.buttonHeight];
end
function subSize = subpanelSize(nbRow)
subSize = [(gui.panelWidth - 4),...
(2*gui.margin(2) + nbRow*gui.buttonHeight +...
(nbRow-1) * gui.vertDist + gui.fontSize -4)];
end
function [nbFreq] = nbPlottedFreq()
if sig.real
nbFreq = floor(size(coeff.ori, 1)/2)+1;
else
nbFreq = size(coeff.ori, 1);
end
end
function [] = resize(objId, eventData)
figPos = get(gui.mainFigId, 'Position');
xVisu = gui.panelWidth / figPos(3);
% we need the follwing test to avoid a bug during creation
if isinf(xVisu) || isnan(xVisu)
xVisu = 0.5;
end
widthVisu = (figPos(3)-gui.panelWidth) / figPos(3);
% we need the follwing test to avoid a bug during creation
if ~(widthVisu > 0)
widthVisu = 0.5;
end
curY = 1;
for ind = 1:length(visu)
if visu(ind).visible
curY = curY - visu(ind).height;
visu(ind).position = [xVisu curY widthVisu visu(ind).height];
set(visu(ind).uipanelId, 'Position', visu(ind).position);
if ishandle(gui.ResizeVisuButtonId(ind))
set(gui.ResizeVisuButtonId(ind), 'Position',...
[figPos(3)-gui.visuResizeButtonWidth,...
round(curY*figPos(4)-gui.visuResizeButtonHeight/2),...
gui.visuResizeButtonWidth, ...
gui.visuResizeButtonHeight]);
end
end
end
end
function updateUndoData()
undoData{end+1} = sel;
set(gui.undoMenuId, 'Enable', 'on');
redoData = {};
set(gui.redoMenuId, 'Enable', 'off');
end
function undo(objId, eventData)
% PI: Currently the implementation of undo/redo is very rudimentary.
% Only undo/redo of actions modifying the polygons of the selection sel
% are taken into account. For example, zoom actions, or change of layer
% parameters (type of conversion, color of line, ...) are not taken
% into account. A more general handling could be implemented.
% The memory consumption for undo could also be improved. Currently for
% each action modifying the polygons, the whole old variable sel is
% stored in a cell of undoData. It's generally contains more
% information than stricly needed to undo as only one layer is modified
% at a time. If improved efficiency is needed, it could be taken into
% account to save minimally needed information. The number of undo
% levels is currently unlimited, this could be also changed if needed
if ~isempty(undoData)
delSel;
redoData{end+1} = sel;
set(gui.redoMenuId, 'Enable', 'on');
sel = undoData{end};
undoData = undoData(1:end-1);
if isempty(undoData)
set(gui.undoMenuId, 'Enable', 'off');
end
drawAllSel;
set(gui.layListId, 'Value', sel.curLay);
updateLayerList;
end
end
function redo(objId, eventData)
% PI: see the PI for undo function
if ~isempty(redoData)
delSel;
undoData{end+1} = sel;
set(gui.undoMenuId, 'Enable', 'on');
sel = redoData{end};
redoData = redoData(1:end-1);
if isempty(redoData)
set(gui.redoMenuId, 'Enable', 'off');
end
drawAllSel;
set(gui.layListId, 'Value', sel.curLay);
updateLayerList;
end
end
% ______________________ VISUALIZATION FUNCTIONS __________________________
function updateVisu(resetVisu, changeCLim)
if nargin == 0
resetVisu = false;
changeCLim = false;
end
delete(gui.symbImageId);
gui.symbImageId = [];
% keep the properties of the axes if we're not resetting the
% visualization
axesProp = struct;
if ~resetVisu
for ind = 1:length(visu)
if ~isempty(visu(ind).axesId)
axesProp(ind).xLim = get(visu(ind).axesId, 'XLim');
axesProp(ind).yLim = get(visu(ind).axesId, 'YLim');
axesProp(ind).cLim = get(visu(ind).axesId, 'CLim');
end
end
end
% update the visualization of the signal
linkXId = [];
linkYId = [];
linkCLimId=[];
for ind = 1:length(visu)
delete(visu(ind).uipanelId);
visu(ind).uipanelId = [];
visu(ind).axesId = [];
if visu(ind).visible
visu(ind).uipanelId = uipanel(gui.mainFigId, ...
'Units', 'normalized', ...
'Position', visu(ind).position);
visu(ind).axesId = visu(ind).updateFcn(visu(ind));
% plot for the visualisation of play position during playback
lim = axis(visu(ind).axesId);
xPos = convIndToAxesX((player.position-1) / frame.def.hop);
hold(visu(ind).axesId, 'on');
player.positionPlotId(ind) = plot(visu(ind).axesId, [xPos xPos],...
lim(3:4), 'w'); % !!! give possibility to change color ?
set(player.positionPlotId(ind), 'Visible', 'off', 'LineWidth', 2);
hold(visu(ind).axesId, 'off');
if visu(ind).linkX
linkXId = [linkXId visu(ind).axesId];
end
if visu(ind).linkY
linkYId = [linkYId visu(ind).axesId];
end
if visu(ind).linkCLim
linkCLimId = [linkCLimId visu(ind).axesId];
end
% the following insures the possibility to zoom out
% completely even if we are already zoomed in
axes(visu(ind).axesId);
zoom(gui.mainFigId, 'reset');
end
end
if length(linkXId) > 1
link.XLim = linkprop(linkXId,'XLim');
end
if length(linkYId) > 1
link.YLim = linkprop(linkYId,'YLim');
end
if length(linkCLimId) > 1
link.CLim = linkprop(linkCLimId,'CLim');
end
if ~resetVisu
% we go in reverse order to update axes limits so that
% all the linked axes come back to the limits of the original
% spectrogram, even if some new linked axes are added
for ind = length(visu):-1:1
if visu(ind).visible
try
set(visu(ind).axesId, 'XLim', axesProp(ind).xLim);
end
try
set(visu(ind).axesId, 'YLim', axesProp(ind).yLim);
end
if ~changeCLim
try
set(visu(ind).axesId, 'CLim', axesProp(ind).cLim);
end
end
end
end
end
drawAllSel;
overviewInd = find(strcmp('originalOverview', {visu.label}), 1);
if ~isempty(overviewInd)
if visu(overviewInd).visible
exploreOverview(visu(overviewInd).axesId);
end
end
if ~resetVisu
% restore the current tool
changeTool([], [], gui.curTool);
end
drawResizeVisuButton;
resize;
end
function [axesId] = updateVisuOriSpec(visuData)
axesId = axes('Parent',visuData.uipanelId);
% update the spectrogram of the original signal
spec = abs(coeff.ori(1:nbPlottedFreq,:)).^2; % spectrogram coefficients
maxSpec = max(spec(:));
imageId = imagesc(...
convIndToAxesX([1,size(spec,2)]),...
convIndToAxesY([1,size(spec,1)]),...
10*log10(spec+eps),...
'Parent', axesId, ...
10*log10(maxSpec)+[-visuData.dynamic 0]);
axis(axesId, 'xy');
xlabel('Time (s)');
ylabel('Frequency (Hz)');
title('Original signal');
end
function [axesId] = updateVisuModSpec(visuData)
axesId = axes('parent',visuData.uipanelId);
% update the spectrogram of the original signal
spec = abs(coeff.mod(1:nbPlottedFreq,:)).^2; % spectrogram coefficients
maxSpec = max(spec(:));
imagesc(...
convIndToAxesX([1,size(spec,2)]),...
convIndToAxesY([1,size(spec,1)]),...
10*log10(spec+eps),...
'Parent', axesId, ...
10*log10(maxSpec)+[-visuData.dynamic 0]);
axis(axesId, 'xy');
xlabel('Time (s)');
ylabel('Frequency (Hz)');
title('Modified signal');
end
function [axesId] = updateVisuOriOverview(visuData)
axesId = axes('parent',visuData.uipanelId);
% update the spectrogram of the original signal
spec = abs(coeff.ori(1:nbPlottedFreq,:)).^2; % spectrogram coefficients
maxSpec = max(spec(:));
imageId = imagesc(...
convIndToAxesX([1,size(spec,2)]),...
convIndToAxesY([1,size(spec,1)]),...
10*log10(spec+eps),...
'Parent', axesId, ...
10*log10(maxSpec)+[-visuData.dynamic 0]);
axis(axesId, 'xy');
xlabel('Time (s)');
ylabel('Frequency (Hz)');
title('Overview of original signal');
end
function drawResizeVisuButton()
for ind = 1:length(gui.ResizeVisuButtonId)
if ishandle(gui.ResizeVisuButtonId(ind))
delete(gui.ResizeVisuButtonId(ind));
end
end
nbVisibleVisu = length(find([visu.visible]));
nbButton = 0;
gui.ResizeVisuButtonId = NaN(length(visu), 1);
if nbVisibleVisu > 1
resizeButtonIcon = imread([iconpath,'resizebutton.png']);
for ind = 1:length(visu)
if visu(ind).visible
gui.ResizeVisuButtonId(ind) = uicontrol(...
'Parent', gui.mainFigId,...
'Style', 'pushbutton',...
'String', '',...
'TooltipString', 'Resize visualization',...
'CData', resizeButtonIcon,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Enable', 'off',...
'buttonDownFcn', {@resizeVisu, ind});
nbButton = nbButton + 1;
if nbButton == nbVisibleVisu-1
break;
end
end
end
end
end
function resizeVisu(objId, eventData, indVisu)
initPos = get(gui.mainFigId, 'CurrentPoint');
backupButtonMotionFcn = get(gui.mainFigId, 'WindowButtonMotionFcn');
backupButtonUpFcn = get(gui.mainFigId, 'WindowButtonUpFcn');
figPos = get(gui.mainFigId, 'Position');
buttonPos = get(gui.ResizeVisuButtonId(indVisu), 'Position');
% find the index of the visible visualization next to the one with
% index indVisu
indNextVisu = 0;
for ind = indVisu+1:length(visu)
if visu(ind).visible
indNextVisu = ind;
break;
end
end
initHeight = [visu(indVisu).height, visu(indNextVisu).height];
% As the zoom and pan mode of matlab doesn't allow to change the
% WindowButtonUpFcn, I temporarly change the tool
curTool = gui.curTool;
changeTool(objId, eventData, 'freehand');
set(gui.mainFigId,...
'WindowButtonMotionFcn', @resizeVisuButtonMotionFcn);
set(gui.mainFigId,...
'WindowButtonUpFcn', @resizeVisuButtonUpFcn);
function resizeVisuButtonMotionFcn(objId, eventData)
pos = get(gui.mainFigId, 'CurrentPoint');
shift = (pos(2) - initPos(2)) / figPos(4);
if (initHeight(1) - shift) > 0.01 && (initHeight(2) + shift) > 0.01
visu(indVisu).height = initHeight(1) - shift;
visu(indNextVisu).height = initHeight(2) + shift;
end
resize;
end
function resizeVisuButtonUpFcn(objId, eventData)
set(gui.mainFigId, 'WindowButtonMotionFcn', backupButtonMotionFcn);
set(gui.mainFigId, 'WindowButtonUpFcn', backupButtonUpFcn);
% restore the tool
changeTool(objId, eventData, curTool);
end
end
function toggleModVisu(objId, eventData)
oriInd = find(strcmp('originalMain', {visu.label}), 1);
modInd = find(strcmp('modified', {visu.label}), 1);
if visu(modInd).visible
visu(modInd).visible = false;
set(gui.visuMenu.showModId, 'Checked', 'off');
visu(oriInd).height = visu(oriInd).height + visu(modInd).height;
else
visu(modInd).visible = true;
set(gui.visuMenu.showModId, 'Checked', 'on');
visu(modInd).height = visu(oriInd).height / 2;
visu(oriInd).height = visu(oriInd).height / 2;
end
updateVisu;
resize;
end
function toggleOverviewVisu(objId, eventData)
oriInd = find(strcmp('originalMain', {visu.label}), 1);
overviewInd = find(strcmp('originalOverview', {visu.label}), 1);
if visu(overviewInd).visible
visu(overviewInd).visible = false;
set(gui.visuMenu.showOverviewId, 'Checked', 'off');
visu(oriInd).height = visu(oriInd).height + visu(overviewInd).height;
else
visu(overviewInd).visible = true;
set(gui.visuMenu.showOverviewId, 'Checked', 'on');
visu(overviewInd).height = visu(oriInd).height * 1/3;
visu(oriInd).height = visu(oriInd).height * 2/3;
end
updateVisu;
resize;
end
% ______________________ AUDIOPLAYER FUNCTIONS ____________________________
function initializePlayer()
player.ori = audioplayer(sig.ori, sig.sampFreq);
player.mod = audioplayer(sig.mod, sig.sampFreq);
set(player.ori, 'StartFcn', @playerStartFcn);
set(player.ori, 'StopFcn', @playerStopFcnOri);
set(player.ori, 'TimerFcn', @updatePlayPosition);
set(player.mod, 'StartFcn', @playerStartFcn);
set(player.mod, 'StopFcn', @playerStopFcnMod);
set(player.mod, 'TimerFcn', @updatePlayPosition);
player.selected = 'ori';
player.loop = false;
player.position = 1;
player.forceStop = false;
if ishandle(gui.player.buttongroupId)
set(gui.player.buttongroupId,...
'SelectedObject', gui.player.buttonOriId);
end
end
function drawAudioplayer(uipanelId)
subPanelHeight = 2*gui.textHeight + 2*gui.marginSub(2) +...
gui.vertDist+gui.fontSize+2;
gui.player.buttongroupId = uibuttongroup(...
'Parent', uipanelId,...
'Title', 'Signal',...
'TitlePosition', 'centertop',...
'FontSize', gui.fontSize, ...
'Units', 'pixels',...
'Position', [1, 1, gui.panelWidth-4, subPanelHeight],...
'SelectionChangeFcn', @switchAudioplayer);
gui.player.buttonOriId = uicontrol(...
'Parent', gui.player.buttongroupId,...
'Style', 'radiobutton',...
'FontSize', gui.fontSize, ...
'String', ' Original',...
'BackgroundColor', gui.buttonBackgroundColor,...
'Tag', 'ori',...
'Position', [gui.marginSub(1),...
gui.textHeight+gui.marginSub(2)+gui.vertDist,...
gui.panelWidth-4-2*gui.marginSub(2),...
gui.textHeight]);
gui.player.buttonModId = uicontrol(...
'Parent', gui.player.buttongroupId,...
'Style', 'radiobutton',...
'FontSize', gui.fontSize, ...
'String', ' Modified',...
'BackgroundColor', gui.buttonBackgroundColor,...
'Tag', 'mod',...
'Position', [gui.marginSub,...
gui.panelWidth-4-2*gui.marginSub(2),...
gui.textHeight]);
playIcon = imread([iconpath,'play.png']);
yPos = subPanelHeight;
buttonPlayPauseId = uicontrol(...
'Parent', uipanelId,...
'Style', 'pushbutton',...
'String', '',...
'TooltipString', 'Play/pause audio',...
'CData', playIcon,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(1, 1, gui.margin + [0, yPos]),...
'CallBack',@playPauseAudioplayer);
stopIcon = imread([iconpath,'stop.png']);
buttonStopId = uicontrol(...
'Parent', uipanelId,...
'Style', 'pushbutton',...
'String', '',...
'TooltipString', 'Stop audio',...
'CData', stopIcon,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(2, 1, gui.margin + [0, yPos]),...
'CallBack',@stopAudioplayer);
loopIcon = imread([iconpath,'loop.png']);
buttonLoopId = uicontrol(...
'Parent', uipanelId, ...
'Style', 'togglebutton',...
'String', '',...
'TooltipString', 'Loop audio',...
'CData', loopIcon,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(3, 1, gui.margin + [0, yPos]),...
'CallBack',@loopAudioplayer,...
'Min', false,...
'Max', true);
end
function switchAudioplayer(objId, eventData)
player.selected=get(get(objId, 'SelectedObject'),'Tag');
end
function playPauseAudioplayer(objId, eventData)
if isplaying(player.ori)
player.forceStop = true;
pause(player.ori);
elseif isplaying(player.mod)
player.forceStop = true;
pause(player.mod);
else
player.forceStop = false;
switch player.selected
case 'ori'
play(player.ori, player.position);
case 'mod'
play(player.mod, player.position);
end
end
end
function stopAudioplayer(objId, eventData)
player.forceStop = true;
stop(player.ori);
stop(player.mod);
player.position = 1;
end
function playerStartFcn(objId, eventData)
for ind = 1:length(player.positionPlotId)
if visu(ind).visible
set(player.positionPlotId(ind), 'Visible', 'on');
end
end
end
function playerStopFcnOri(objId, eventData)
for ind = 1:length(player.positionPlotId)
if visu(ind).visible
set(player.positionPlotId(ind), 'Visible', 'off');
end
end
player.position = get(player.ori, 'CurrentSample');
if player.loop && ~player.forceStop
pause(0.1); %!!! needed to avoid java error
play(player.ori, player.position);
end
end
function playerStopFcnMod(objId, eventData)
for ind = 1:length(player.positionPlotId)
if visu(ind).visible
set(player.positionPlotId(ind), 'Visible', 'off');
end
end
player.position = get(player.mod, 'CurrentSample');
if player.loop && ~player.forceStop
pause(0.1); %!!! needed to avoid java error
play(player.mod, player.position);
end
end
function loopAudioplayer(objId, eventData)
player.loop = get(objId, 'Value');
end
function updatePlayPosition(objId, eventData)
pos = convIndToAxesX((get(objId, 'CurrentSample')-1) / frame.def.hop);
for ind = 1:length(player.positionPlotId)
if visu(ind).visible
set(player.positionPlotId(ind), 'XData', [pos pos]);
end
end
end
function updatePlayerMod()
player.mod = audioplayer(sig.mod, sig.sampFreq);
set(player.mod, 'StartFcn', @playerStartFcn);
set(player.mod, 'StopFcn', @playerStopFcnMod);
set(player.mod, 'TimerFcn', @updatePlayPosition);
end
% ____________________ SELECTION TOOLS FUNCTIONS __________________________
function drawSelectionTool(uipanelId)
subSize = subpanelSize(1);
processingToolPanelId = uipanel(...
'Parent', uipanelId,...
'Title', 'Apply',...
'TitlePosition', 'centertop',...
'FontSize', gui.fontSize, ...
'Units', 'pixels',...
'Position', [1, 1, subSize]);
% draw processing tools subpanel
drawProcessingTool(processingToolPanelId);
heightLayerPanel = 115;
layerPanelId = uipanel(...
'Parent', uipanelId,...
'Title', 'Layers',...
'TitlePosition', 'centertop',...
'FontSize', gui.fontSize, ...
'Units', 'pixels',...
'Position', [1, 1+subSize(2), subSize(1), heightLayerPanel]);
% draw layer panel
drawLayerPanel(layerPanelId);
buttongroupId = uibuttongroup(...
'Parent', uipanelId,...
'Title', 'Mode',...
'TitlePosition', 'centertop',...
'FontSize', gui.fontSize, ...
'Units', 'pixels',...
'Position', [1, subSize(2)+heightLayerPanel+1, subSize],...
'SelectionChangeFcn', @switchSelMode);
unionIcon = imread([iconpath,'union.png']);
buttonUnionId = uicontrol(...
'Parent',buttongroupId,...
'Style', 'togglebutton',...
'String', '',...
'TooltipString', 'Union',...
'BackgroundColor', gui.buttonBackgroundColor,...
'CData', unionIcon,...
'Tag', 'union',...
'Position', buttonPos(1, 1, gui.marginSub));
intersectionIcon = imread([iconpath,'intersection.png']);
buttonInterId = uicontrol(...
'Parent',buttongroupId,...
'Style', 'togglebutton',...
'String', '',...
'TooltipString', 'Intersection',...
'BackgroundColor', gui.buttonBackgroundColor,...
'CData', intersectionIcon,...
'Tag', 'intersection',...
'Position', buttonPos(2, 1, gui.marginSub));
differenceIcon = imread([iconpath,'difference.png']);
buttonDiffId = uicontrol(...
'Parent',buttongroupId,...
'Style', 'togglebutton',...
'String', '',...
'TooltipString', 'Set difference',...
'BackgroundColor', gui.buttonBackgroundColor,...
'CData', differenceIcon,...
'Tag', 'difference',...
'Position', buttonPos(3, 1, gui.marginSub));
% reserved space to draw parameters of the tools
gui.toolPanelId = uipanel(...
'Parent', uipanelId,...
'Title', 'Tools',...
'TitlePosition', 'centertop',...
'FontSize', gui.fontSize,...
'Units', 'pixels',...
'Position', [1, 2*subSize(2)+heightLayerPanel+1,...
subSize(1),...
2*gui.marginSub(2) + gui.vertDist + gui.textHeight + ...
gui.buttonHeight + gui.fontSize+2]);
freeHandIcon = imread([iconpath,'freehand.png']);
buttonFreehandId = uicontrol(...
'Parent', gui.toolPanelId,...
'HandleVisibility', 'off',...
'Style', 'togglebutton',...
'String', '',...
'TooltipString', 'Free-hand selection',...
'CData', freeHandIcon,...
'Min', false,...
'Max', true,...
'Value', false,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(1, 1,...
gui.marginSub+[round(gui.buttonWidth/2),...
gui.marginSub(2)+gui.textHeight]),...
'CallBack', {@changeTool, 'freehand'});
gui.tool(end+1).buttonId = buttonFreehandId;
gui.tool(end).name = 'freehand';
gui.tool(end).function = @selecFreehand;
levelIcon = imread([iconpath,'magicwand.png']);
buttonLevelId = uicontrol(...
'Parent', gui.toolPanelId,...
'HandleVisibility', 'off',...
'Style', 'togglebutton',...
'String', '',...
'TooltipString', 'Magic wand (Level selection)',...
'CData', levelIcon,...
'Min', false,...
'Max', true,...
'Value', false,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(2, 1,...
gui.marginSub+[round(gui.buttonWidth/2),...
gui.marginSub(2)+gui.textHeight]),...
'CallBack', {@changeTool, 'level'});
gui.tool(end+1).buttonId = buttonLevelId;
gui.tool(end).name = 'level';
gui.tool(end).function = @selecLevel;
gui.tool(end).param.name = 'Tolerance';
gui.tool(end).param.val = '10'; % value of the tolerance in dB
end
function changeTool(objId, eventData, toolName)
if getMatlabVersion < 7.3
% As we cannot force automatic update of rectangle in overview when
% zooming and paning, we will at least force it when we change tool
updateExploreRect;
end
zoom(gui.mainFigId, 'off');
pan(gui.mainFigId, 'off');
for ind = 1:length(gui.tool)
set(gui.tool(ind).buttonId, 'Value', false);
end
toolNameList = {gui.tool.name}; % cell array listing the tool names
curInd = find(strcmp(toolName, toolNameList));
set(gui.tool(curInd).buttonId, 'Value', true);
gui.curTool = gui.tool(curInd).name;
gui.tool(curInd).function(curInd);
drawToolParam(curInd);
end
function drawToolParam(toolInd)
child = findobj(gui.toolPanelId);
child = setdiff(child, gui.toolPanelId);
delete(child);
for ind = 1:length(gui.tool(toolInd).param)
uicontrol(...
'Parent', gui.toolPanelId,...
'FontSize', gui.fontSize, ...
'Style', 'text',...
'String', gui.tool(toolInd).param(ind).name,...
'Position', [gui.marginSub(1),...
gui.marginSub(2)+(ind-1)*(gui.textHeight+gui.vertDist),...
gui.textWidth, gui.textHeight]) ;
uicontrol(...
'Parent', gui.toolPanelId,...
'FontSize', gui.fontSize, ...
'Style', 'edit',...
'BackgroundColor', gui.buttonBackgroundColor,...
'String', gui.tool(toolInd).param(ind).val,...
'Position', [gui.marginSub(1)+gui.textWidth,...
gui.marginSub(2)+(ind-1)*(gui.textHeight+gui.vertDist),...
gui.editWidth, gui.textHeight],...
'Callback', {@changeToolParam, toolInd, ind});
end
end
function changeToolParam(objId, eventData, toolInd, paramInd)
gui.tool(toolInd).param(paramInd).val = get(objId, 'String');
end
function selecFreehand(toolInd)
% toolInd is not used but needed as I pass a parameter to this
% function !!! precise this
figId = gui.mainFigId;
oriInd = find(strcmp('originalMain', {visu.label}), 1);
axesId = visu(oriInd).axesId;
imageId = findobj(axesId, 'Type', 'Image');
set(imageId, 'ButtonDownFcn', @selecFreeHandButtonDown);
poly.x = [];
poly.y = [];
init = true; % boolean to know if we are drawing the first point or not
lineId = [];
function selecFreeHandButtonDown(objId, eventData)
if strcmp(get(figId,'SelectionType'),'normal')
if init
point = get(axesId,'CurrentPoint');
poly.x = [point(1,1)];
poly.y = [point(1,2)];
poly.hole = false;
lineId = line(...
'XData', poly.x,...
'YData', poly.y,...
'LineWidth', sel.lay(sel.curLay).lineWidth,...
'Color', sel.lay(sel.curLay).color,...
'Marker', sel.lay(sel.curLay).marker,...
'MarkerSize', sel.lay(sel.curLay).markerSize,...
'LineStyle', sel.lay(sel.curLay).lineStyle);
init = false;
set(figId,'WindowButtonDownFcn',@selecFreeHandButtonDown);
set(figId,'WindowButtonMotionFcn',@selecFreeHandMotionDown);
set(figId,'WindowButtonUpFcn',@selecFreeHandButtonUp);
else
point = get(axesId,'CurrentPoint');
poly.x = [poly.x; point(1,1)];
poly.y = [poly.y; point(1,2)];
set(lineId, 'XData',poly.x , 'YData', poly.y);
set(figId,'WindowButtonMotionFcn',@selecFreeHandMotionDown);
drawnow;
end
end
end
function selecFreeHandMotionDown(objId, eventData)
point = get(axesId,'CurrentPoint');
poly.x = [poly.x; point(1,1)];
poly.y = [poly.y; point(1,2)];
set(lineId, 'XData', poly.x, 'YData', poly.y);
drawnow;
end
function selecFreeHandMotionUp(objId, eventData)
point = get(axesId,'CurrentPoint');
xData = [poly.x; point(1,1)];
yData = [poly.y; point(1,2)];
set(lineId, 'XData', xData, 'YData', yData);
drawnow;
end
function selecFreeHandButtonUp(objId, eventData)
switch get(figId,'SelectionType')
case 'normal'
set(figId,'WindowButtonMotionFcn',@selecFreeHandMotionUp);
case {'open', 'alt'}
set(figId,'WindowButtonMotionFcn','');
set(figId,'WindowButtonDownFcn','');
set(figId,'WindowButtonUpFcn','');
init = true;
delete(lineId);
% !!! we could simplify the polygon here to have fastest
% computation
combineSel(poly);
drawCurSel;
end
end
end
function selecLevel(toolInd)
oriInd = find(strcmp('originalMain', {visu.label}), 1);
imageId = findobj(visu(oriInd).axesId, 'Type', 'Image');
set(imageId, 'ButtonDownFcn', @selecLevelButtonDown);
function selecLevelButtonDown(objId, eventData)
point = get(visu(oriInd).axesId,'CurrentPoint');
indTime = round(convAxesToIndX(point(1,1)));
indFreq = round(convAxesToIndY(point(1,2)));
% !!! sometime log of 0, do something here
spec = 20*log10(abs(coeff.ori(1:nbPlottedFreq,:)));
refLevel = spec(indFreq, indTime);
levelTol = str2num(gui.tool(toolInd).param.val);
if isempty(levelTol) || levelTol < 0
errordlg(['Tolerance parameter for magic wand is invalid, '...
'it must be a positive number in dB']);
return;
end
lowLevel = refLevel - levelTol;
highLevel = refLevel + levelTol;
mask = (spec >= lowLevel) & (spec <= highLevel);
mask = bwselect(mask, indTime, indFreq, 4);
poly = mask2poly(mask, indTime, indFreq);
% !!! see if we simplify the selection or not
for ind = 1:length(poly)
poly(ind).x = convIndToAxesX(poly(ind).x);
poly(ind).y = convIndToAxesY(poly(ind).y);
end
combineSel(poly);
drawCurSel;
end
end
function [poly] = mask2poly(mask, indTime, indFreq)
% Convert region mask to region of interest (ROI) polygon
% !!! I'm not shure that this algorithm works in every case
maskRef = mask;
mask = zeros(size(mask, 1)+2, size(mask, 2)+2);
mask(2:end-1,2:end-1) = maskRef;
[ind1, ind2] = find(mask);
% position of segments on the edge for first dimension
seg1 = sparse(size(mask,1)+1, size(mask,2));
% position of segments on the edge for second dimension
seg2 = sparse(size(mask,1), size(mask,2)+1) ;
for n = 1:length(ind1)
if ~mask(ind1(n)-1, ind2(n))
seg1(ind1(n), ind2(n)) = 1;
end
if ~mask(ind1(n)+1, ind2(n))
seg1(ind1(n)+1, ind2(n)) = 1;
end
if ~mask(ind1(n), ind2(n)-1)
seg2(ind1(n), ind2(n)) = 1;
end
if ~mask(ind1(n), ind2(n)+1)
seg2(ind1(n), ind2(n)+1) = 1;
end
end
ind = 0;
while nnz(seg1)>1
curve = chainSeg;
if ~isempty(curve)
ind = ind+1;
poly(ind).x = curve(:,2);
poly(ind).y = curve(:,1);
poly(ind).hole = true;
end
end
poly(1).hole = false;
function curve = chainSeg()
% chaining of segments
% choose one start segment
[ind1, ind2] = find(seg1);
ind1 = ind1(1);
ind2 = ind2(1);
curve = [ind1, ind2; ind1, ind2+1];
seg1(ind1, ind2) = 0;
% pos is a variable to remember in which direction we are
% progressing
% [1 1] if we're going in a growing index number
% [-1 0] otherwise
pos = [1, 1];
% precise if the last added segment comes from seg1 or seg2
last1 = true;
while true
if last1
% the last segment was from dimension 1
if seg1(ind1, ind2+pos(1))
ind2 = ind2+pos(1);
seg1(ind1, ind2) = 0;
curve = [curve; ind1, ind2+pos(2)];
elseif seg2(ind1-1, ind2+pos(2))
ind1 = ind1-1;
ind2 = ind2+pos(2);
pos = [-1, 0];
seg2(ind1, ind2) = 0;
curve = [curve; ind1, ind2];
last1 = false;
elseif seg2(ind1, ind2+pos(2))
ind2 = ind2+pos(2);
pos = [1, 1];
seg2(ind1, ind2) = 0;
curve = [curve; ind1+1, ind2];
last1 = false;
else
break;
end
else
% the last segment was from dimension 2
if seg2(ind1+pos(1), ind2)
ind1 = ind1+pos(1);
seg2(ind1, ind2) = 0;
curve = [curve; ind1+pos(2), ind2];
elseif seg1(ind1+pos(2), ind2-1)
ind1 = ind1+pos(2);
ind2 = ind2-1;
pos = [-1, 0];
seg1(ind1, ind2) = 0;
curve = [curve; ind1, ind2];
last1 = true;
elseif seg1(ind1+pos(2), ind2)
ind1 = ind1+pos(2);
pos = [1, 1];
seg1(ind1, ind2) = 0;
curve = [curve; ind1, ind2+1];
last1 = true;
else
break;
end
end
end
curve = curve-1.5;
if size(curve, 1)==2
% the first segment couldn't be linked to some other segment,
% there is no polygon
curve = [];
end
end
end
function combineSel(poly)
if ~isempty(sel.lay(sel.curLay).poly)
% there is already a selection that should be combined with the new
% one
switch sel.mode
case 'union'
newPoly = PolygonClip(sel.lay(sel.curLay).poly, poly, 3);
case 'intersection'
newPoly = PolygonClip(sel.lay(sel.curLay).poly, poly, 1);
case 'difference'
newPoly = PolygonClip(sel.lay(sel.curLay).poly, poly, 0);
end
% we must remove the selection plot before replacing the selection
% data
delCurPoly;
sel.lay(sel.curLay).poly = newPoly;
else
% the selection was empty
if strcmp(sel.mode, 'union')
updateUndoData;
sel.lay(sel.curLay).poly = poly;
end
end
end
function delCurPoly()
updateUndoData;
if ~isempty(sel.lay(sel.curLay).poly)
for ind = 1:length(sel.lay(sel.curLay).poly)
delete(sel.lay(sel.curLay).poly(ind).id);
end
sel.lay(sel.curLay).poly = [];
end
end
function delAllPoly()
updateUndoData;
for indLay = 1:length(sel.lay)
if ~isempty(sel.lay(indLay).poly)
for ind = 1:length(sel.lay(indLay).poly)
delete(sel.lay(indLay).poly(ind).id);
end
sel.lay(indLay).poly = [];
end
end
end
function delSel() % delete graphical selection (but keep the polygons)
for indLay = 1:length(sel.lay)
if ~isempty(sel.lay(indLay).poly)
for ind = 1:length(sel.lay(indLay).poly)
delete(sel.lay(indLay).poly(ind).id);
end
end
end
end
function resetSel() % erase sel and put it to default value
sel = default.sel;
if isfield(gui, 'layListId')
if ishandle(gui.layListId)
set(gui.layListId, 'Value', sel.curLay);
drawLayParam(sel.curLay);
updateLayerList;
end
end
end
function drawCurSel()
handleSymb;
oriInd = find(strcmp('originalMain', {visu.label}), 1);
hold(visu(oriInd).axesId, 'on');
if ~isempty(sel.lay(sel.curLay).poly)
for ind = 1:length(sel.lay(sel.curLay).poly)
sel.lay(sel.curLay).poly(ind).id = line(...
'XData', [sel.lay(sel.curLay).poly(ind).x;...
sel.lay(sel.curLay).poly(ind).x(1)],...
'YData', [sel.lay(sel.curLay).poly(ind).y;...
sel.lay(sel.curLay).poly(ind).y(1)],...
'LineWidth', sel.lay(sel.curLay).lineWidth,...
'Color', sel.lay(sel.curLay).color,...
'Marker', sel.lay(sel.curLay).marker,...
'MarkerSize', sel.lay(sel.curLay).markerSize,...
'LineStyle', sel.lay(sel.curLay).lineStyle,...
'Parent', visu(oriInd).axesId);
end
end
hold(visu(oriInd).axesId, 'off');
end
function drawAllSel()
handleSymb;
oriInd = find(strcmp('originalMain', {visu.label}), 1);
hold(visu(oriInd).axesId, 'on');
for indLay = 1:length(sel.lay)
if ~isempty(sel.lay(indLay).poly)
for ind = 1:length(sel.lay(indLay).poly)
sel.lay(indLay).poly(ind).id = line(...
'XData', [sel.lay(indLay).poly(ind).x;...
sel.lay(indLay).poly(ind).x(1)],...
'YData', [sel.lay(indLay).poly(ind).y;...
sel.lay(indLay).poly(ind).y(1)],...
'LineWidth', sel.lay(indLay).lineWidth,...
'Color', sel.lay(indLay).color,...
'Marker', sel.lay(indLay).marker,...
'MarkerSize', sel.lay(indLay).markerSize,...
'LineStyle', sel.lay(indLay).lineStyle,...
'Parent', visu(oriInd).axesId);
end
end
end
hold(visu(oriInd).axesId, 'off');
end
function handleSymb()
delete(gui.symbImageId);
gui.symbImageId = [];
if gui.showSymb
showSymb;
gui.showSymb = false;
end
end
function showSymb()
% plot symbol of the multiplier
oriInd = find(strcmp('originalMain', {visu.label}), 1);
axesId = visu(oriInd).axesId;
hold(axesId, 'on');
absSymb = abs(convSelToSymb);
% Symbol is represented using transparency, with two different
% colors for absolute values of the symbol in [0,1] and for values > 1.
% Transparency is total for absolute value of 1, and opacity
% grows when going away from 1
% !!! these colors should be set as variables that the user can set
color1 = [0 0 0]; % black
color2 = [1 1 1]; % white
% !!! I should probably use a dB scale for transparency
nbTime = size(coeff.ori, 2);
% construct the image with white for value > 1 and black in other parts
tempIm = repmat(reshape(color1, [1 1 3]), [nbPlottedFreq nbTime 1]);
[ind1, ind2] = find(absSymb(1:nbPlottedFreq, :) > 1);
if ~isempty(ind1)
for ind3 = 1:size(tempIm, 3)
ind = sub2ind(size(tempIm), ind1, ind2, ind3 * ones(size(ind1)));
tempIm(ind) = color2(ind3);
end
end
% construct transparency data
% initialisation using formula valid for values in [0, 1]
tempAlpha = (1 - absSymb(1:nbPlottedFreq, :));
% correction for values > 1 % !!! I don't really know what to use here
tempAlpha(ind1, ind2) = 1 - 1./absSymb(ind1, ind2);
gui.symbImageId = image(...
convIndToAxesX([1, nbTime]),...
convIndToAxesY([1, nbPlottedFreq]),...
tempIm,...
'alphaData',gui.symbOpacity * tempAlpha,...
'Parent', axesId);
hold(axesId, 'off');
% restore the current tool
changeTool([], [], gui.curTool);
end
function switchSelMode(objId, eventData)
sel.mode = get(get(objId, 'SelectedObject'),'Tag');
end
function drawProcessingTool(uipanelId)
% creation of apply button
applyIcon = imread([iconpath,'apply.png']);
applyId = uicontrol(...
'Parent', uipanelId,...
'Style', 'pushbutton',...
'String', '',...
'TooltipString', 'Apply multiplier',...
'CData', applyIcon,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(2, 1, gui.marginSub),...
'CallBack',@applySel);
end
% __________________________ LAYERS FUNCTIONS _____________________________
function drawLayerPanel(uipanelId)
layUicontextmenu = uicontextmenu;
uimenu(layUicontextmenu,...
'Label', 'Line color',...
'Callback', @changeSelLayColor);
layStyleMenuId = uimenu(layUicontextmenu,...
'Label', 'Line style');
uimenu(layStyleMenuId,...
'Label', 'Solid',...
'Callback', {@changeSelLayStyle, '-'});
uimenu(layStyleMenuId,...
'Label', 'Dashed',...
'Callback', {@changeSelLayStyle, '--'});
uimenu(layStyleMenuId,...
'Label', 'Dot',...
'Callback', {@changeSelLayStyle, ':'});
uimenu(layStyleMenuId,...
'Label', 'Dash-dot',...
'Callback', {@changeSelLayStyle, '-.'});
uimenu(layStyleMenuId,...
'Label', 'None',...
'Callback', {@changeSelLayStyle, 'none'});
layWidthMenuId = uimenu(layUicontextmenu,...
'Label', 'Line width');
uimenu(layWidthMenuId,...
'Label', '1.0',...
'Callback', {@changeSelLayWidth, 1});
uimenu(layWidthMenuId,...
'Label', '2.0',...
'Callback', {@changeSelLayWidth, 2});
uimenu(layWidthMenuId,...
'Label', '3.0',...
'Callback', {@changeSelLayWidth, 3});
uimenu(layWidthMenuId,...
'Label', '4.0',...
'Callback', {@changeSelLayWidth, 4});
uimenu(layWidthMenuId,...
'Label', '5.0',...
'Callback', {@changeSelLayWidth, 5});
uimenu(layWidthMenuId,...
'Label', '6.0',...
'Callback', {@changeSelLayWidth, 6});
uimenu(layWidthMenuId,...
'Label', '7.0',...
'Callback', {@changeSelLayWidth, 7});
uimenu(layWidthMenuId,...
'Label', '8.0',...
'Callback', {@changeSelLayWidth, 8});
uimenu(layWidthMenuId,...
'Label', '9.0',...
'Callback', {@changeSelLayWidth, 9});
uimenu(layWidthMenuId,...
'Label', '10.0',...
'Callback', {@changeSelLayWidth, 10});
layMarkerMenuId = uimenu(layUicontextmenu,...
'Label', 'Marker');
uimenu(layMarkerMenuId,...
'Label', 'None',...
'Callback', {@changeSelLayMarker, 'none'});
uimenu(layMarkerMenuId,...
'Label', '+',...
'Callback', {@changeSelLayMarker, '+'});
uimenu(layMarkerMenuId,...
'Label', 'o',...
'Callback', {@changeSelLayMarker, 'o'});
uimenu(layMarkerMenuId,...
'Label', '*',...
'Callback', {@changeSelLayMarker, '*'});
uimenu(layMarkerMenuId,...
'Label', '.',...
'Callback', {@changeSelLayMarker, '.'});
uimenu(layMarkerMenuId,...
'Label', 'x',...
'Callback', {@changeSelLayMarker, 'x'});
uimenu(layMarkerMenuId,...
'Label', 'Square',...
'Callback', {@changeSelLayMarker, 'square'});
uimenu(layMarkerMenuId,...
'Label', 'Diamond',...
'Callback', {@changeSelLayMarker, 'diamond'});
uimenu(layMarkerMenuId,...
'Label', '^',...
'Callback', {@changeSelLayMarker, '^'});
uimenu(layMarkerMenuId,...
'Label', 'v',...
'Callback', {@changeSelLayMarker, 'v'});
uimenu(layMarkerMenuId,...
'Label', '>',...
'Callback', {@changeSelLayMarker, '>'});
uimenu(layMarkerMenuId,...
'Label', '<',...
'Callback', {@changeSelLayMarker, '<'});
uimenu(layMarkerMenuId,...
'Label', 'Pentagram',...
'Callback', {@changeSelLayMarker, 'pentagram'});
uimenu(layMarkerMenuId,...
'Label', 'Hexagram',...
'Callback', {@changeSelLayMarker, 'hexagram'});
layMarkerSizeMenuId = uimenu(layUicontextmenu,...
'Label', 'Marker Size');
uimenu(layMarkerSizeMenuId,...
'Label', '2.0',...
'Callback', {@changeSelLayMarkerSize, 2});
uimenu(layMarkerSizeMenuId,...
'Label', '3.0',...
'Callback', {@changeSelLayMarkerSize, 3});
uimenu(layMarkerSizeMenuId,...
'Label', '4.0',...
'Callback', {@changeSelLayMarkerSize, 4});
uimenu(layMarkerSizeMenuId,...
'Label', '5.0',...
'Callback', {@changeSelLayMarkerSize, 5});
uimenu(layMarkerSizeMenuId,...
'Label', '6.0',...
'Callback', {@changeSelLayMarkerSize, 6});
uimenu(layMarkerSizeMenuId,...
'Label', '7.0',...
'Callback', {@changeSelLayMarkerSize, 7});
uimenu(layMarkerSizeMenuId,...
'Label', '8.0',...
'Callback', {@changeSelLayMarkerSize, 8});
uimenu(layMarkerSizeMenuId,...
'Label', '9.0',...
'Callback', {@changeSelLayMarkerSize, 9});
uimenu(layMarkerSizeMenuId,...
'Label', '10.0',...
'Callback', {@changeSelLayMarkerSize, 10});
uimenu(layUicontextmenu,...
'Label', 'Edit label',...
'Callback', @changeSelLayLabel);
layTypeMenuId = uimenu(layUicontextmenu,...
'Label', 'Layer type');
uimenu(layTypeMenuId,...
'Label', 'Constant gain',...
'Callback', {@changeSelLayConvType, 'constGain'});
uimenu(layTypeMenuId,...
'Label', 'Gain with smoothed border',...
'Callback', {@changeSelLayConvType, 'smoothBorder'});
uimenu(layTypeMenuId,...
'Label', 'Hole filling',...
'Callback', {@changeSelLayConvType, 'fill'});
uimenu(layTypeMenuId,...
'Label', 'Hole filling with noise phase',...
'Callback', {@changeSelLayConvType, 'fillNoise'});
uimenu(layUicontextmenu,...
'Label', 'Invert layer',...
'Callback', @invertSelLay);
uimenu(layUicontextmenu,...
'Label', 'Duplicate layer',...
'Callback', @duplicateSelLay);
uimenu(layUicontextmenu,...
'Label', 'Clear layer',...
'Callback', @clearSelLay);
uimenu(layUicontextmenu,...
'Label', 'Delete layer',...
'Callback', @delSelLay);
uimenu(layUicontextmenu,...
'Label', 'Add new layer',...
'Callback', @addSelLay);
gui.layListId = uicontrol(...
'Parent', uipanelId,...
'HandleVisibility', 'off',...
'Style', 'listbox',...
'Fontsize', gui.fontSize,...
'String', '',...
'UIContextMenu', layUicontextmenu,...
'BackgroundColor', [1 1 1],...
'Position', [gui.marginSub(1),...
gui.marginSub(2)+2*gui.textHeight+2*gui.vertDist+1,...
gui.panelWidth-2*gui.margin(1)-1, 60],...
'CallBack',@changeSelLay);
gui.layPanelId = uipanelId;
updateLayerList;
changeSelLay;
end
function updateLayerList()
layCell = {};
for ind = 1:length(sel.lay)
layCell{end+1} = sel.lay(ind).label;
end
set(gui.layListId, 'String', layCell);
end
function changeSelLayColor(objId, eventData)
sel.lay(sel.curLay).color = uisetcolor;
delSel;
drawAllSel;
end
function changeSelLayStyle(objId, eventData, lineStyle)
sel.lay(sel.curLay).lineStyle = lineStyle;
delSel;
drawAllSel;
end
function changeSelLayWidth(objId, eventData, lineWidth)
sel.lay(sel.curLay).lineWidth = lineWidth;
delSel;
drawAllSel;
end
function changeSelLayMarker(objId, eventData, marker)
sel.lay(sel.curLay).marker = marker;
delSel;
drawAllSel;
end
function changeSelLayMarkerSize(objId, eventData, markerSize)
sel.lay(sel.curLay).markerSize = markerSize;
delSel;
drawAllSel;
end
function changeSelLayLabel(objId, eventData)
newLabel = inputdlg('New label for the current selection layer',...
'Change layer label');
sel.lay(sel.curLay).label = newLabel{1};
updateLayerList;
end
function changeSelLayConvType(objId, eventData, convType)
delSel;
sel.lay(sel.curLay).convType = convType;
% !!! see if I put the default value somewhere
% and if I keep a memory of the preceeding values
sel.lay(sel.curLay).param = [];
switch convType
case 'constGain'
sel.lay(sel.curLay).param(1).name = 'Gain';
sel.lay(sel.curLay).param(1).val = 0;
case 'smoothBorder'
sel.lay(sel.curLay).param(1).name = 'Gain';
sel.lay(sel.curLay).param(1).val = 0;
sel.lay(sel.curLay).param(2).name = 'Border';
sel.lay(sel.curLay).param(2).val = 10;
case 'fill'
sel.lay(sel.curLay).param(1).name = 'Width';
sel.lay(sel.curLay).param(1).val = 2;
sel.lay(sel.curLay).param(2).name = 'Height';
sel.lay(sel.curLay).param(2).val = 3;
case 'fillNoise'
sel.lay(sel.curLay).param(1).name = 'Width';
sel.lay(sel.curLay).param(1).val = 2;
sel.lay(sel.curLay).param(2).name = 'Height ';
sel.lay(sel.curLay).param(2).val = 3;
end
changeSelLay;
drawAllSel;
end
function invertSelLay(objId, eventData)
if isempty(sel.lay(sel.curLay).poly)
sel.lay(sel.curLay).poly = fullSigPoly;
else
% compute difference between a polygon around the whole signal and
% the current selection to inverse current selection
newPoly = PolygonClip(fullSigPoly, sel.lay(sel.curLay).poly, 0);
delCurPoly;
sel.lay(sel.curLay).poly = newPoly;
end
drawCurSel;
end
function poly = fullSigPoly()
% compute a polygon corresponding to the whole signal
temp = convIndToAxesX([1, 2]);
temp = (temp(2) - temp(1)) / 2;
tempX = convIndToAxesX([1, size(coeff.ori, 2)]);
tempX = [tempX(1) - temp, tempX(2) + temp];
temp = convIndToAxesY([1, 2]);
temp = (temp(2) - temp(1)) / 2;
tempY = convIndToAxesY([1, nbPlottedFreq]);
tempY = [tempY(1) - temp, tempY(2) + temp];
poly.x = [tempX(1); tempX(2); tempX(2); tempX(1)];
poly.y = [tempY(1); tempY(1); tempY(2); tempY(2)];
poly.hole = false;
end
function duplicateSelLay(objId, eventData)
sel.lay(end+1) = sel.lay(sel.curLay);
sel.lay(end).label = [sel.lay(end).label ' copy'];
if isfield(sel.lay(end).poly, 'id')
sel.lay(end).poly.id = [];
end
updateLayerList;
end
function clearSelLay(objId, eventData)
delSel;
updateUndoData;
sel.lay(sel.curLay).poly = [];
drawAllSel;
end
function delSelLay(objId, eventData)
% check that we leave at least one layer
if length(sel.lay) == 1
warndlg('The selection must contain at least one layer');
return;
end
delSel;
updateUndoData;
sel.lay = sel.lay([1:sel.curLay-1 sel.curLay+1:end]);
updateLayerList;
set(gui.layListId, 'Value', 1);
changeSelLay;
drawAllSel;
end
function addSelLay(objId, eventData)
sel.lay(end+1) = default.sel.lay;
sel.lay(end).label = 'New layer';
updateLayerList;
end
function changeSelLay(objId, eventData)
sel.curLay = get(gui.layListId, 'Value');
drawLayParam(sel.curLay);
end
function drawLayParam(layInd)
child = findobj(gui.layPanelId);
child = setdiff(child, gui.layPanelId);
delete(child);
for ind = 1:length(sel.lay(layInd).param)
uicontrol(...
'Parent', gui.layPanelId,...
'FontSize', gui.fontSize, ...
'Style', 'text',...
'String', sel.lay(layInd).param(ind).name,...
'Position', [gui.marginSub(1),...
gui.marginSub(2)+(ind-1)*(gui.textHeight+gui.vertDist),...
gui.textWidth, gui.textHeight]) ;
uicontrol(...
'Parent', gui.layPanelId,...
'FontSize', gui.fontSize, ...
'Style', 'edit',...
'String', num2str(sel.lay(layInd).param(ind).val),...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', [gui.marginSub(1)+gui.textWidth,...
gui.marginSub(2)+(ind-1)*(gui.textHeight+gui.vertDist),...
gui.editWidth, gui.textHeight],...
'Callback', {@changeLayParam, layInd, ind});
end
end
function changeLayParam(objId, eventData, layInd, paramInd)
handleSymb;
temp = str2num(get(objId, 'String'));
if isempty(temp)
errordlg([sel.lay(layInd).param(paramInd).name...
' parameter is invalid']);
set(objId, 'String', num2str(sel.lay(layInd).param(paramInd).val));
return;
end
sel.lay(layInd).param(paramInd).val = temp;
end
function changeOpacity(objId, eventData)
temp = str2num(get(objId, 'String'));
if isempty(temp) || temp < 0 || temp > 1
errordlg(['Opacity parameter is invalid, it must be a number '...
'between 0 (transparent) and 1 (opaque)']);
set(objId, 'String', num2str(gui.symbOpacity));
return;
end
gui.symbOpacity = temp;
end
% __________________ VISUALIZATION TOOLS FUNCTIONS ________________________
function drawVisualizationTool(uipanelId)
subPanelHeight = gui.margin(2) + gui.buttonHeight +...
gui.textHeight + gui.fontSize + 4;
symbolPanelId = uipanel(...
'Parent', uipanelId,...
'Title', 'Symbol',...
'TitlePosition', 'centertop',...
'FontSize', gui.fontSize, ...
'Units', 'pixels',...
'Position', [1, 1, gui.panelWidth-4 , subPanelHeight]);
showSymbolIcon = imread([iconpath,'showsymbol.png']);
symbId = uicontrol(...
'Parent', symbolPanelId,...
'Style', 'pushbutton',...
'String', '',...
'TooltipString', 'Show multiplier symbol',...
'CData', showSymbolIcon,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(2, 1, gui.marginSub),...
'CallBack',@clicSymb);
uicontrol(...
'Parent', symbolPanelId,...
'FontSize', gui.fontSize, ...
'Style', 'Text',...
'FontSize', gui.fontSize, ...
'String', 'Opacity',...
'Position', [gui.marginSub(1),...
gui.marginSub(2)+gui.buttonHeight,...
gui.textWidth,...
gui.textHeight],...
'CallBack',@changeOpacity);
opacityId = uicontrol(...
'Parent', symbolPanelId,...
'FontSize', gui.fontSize, ...
'Style', 'edit',...
'String', num2str(default.opacity),...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', [gui.marginSub(1)+gui.textWidth,...
gui.marginSub(2)+gui.buttonHeight,...
gui.editWidth,...
gui.textHeight],...
'CallBack',@changeOpacity);
colormapPanelId = uipanel(...
'Parent', uipanelId,...
'Title', 'Colormap',...
'TitlePosition', 'centertop',...
'FontSize', gui.fontSize, ...
'Units', 'pixels',...
'Position', [1, subPanelHeight+1,...
gui.panelWidth-4 , subPanelHeight]);
colormapIcon = imread([iconpath,'colormap.png']);
buttonColormapId = uicontrol(...
'Parent', colormapPanelId,...
'Style', 'pushbutton',...
'String', '',...
'TooltipString', 'Edit colormap',...
'CData', colormapIcon,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(2, 1, gui.marginSub),...
'CallBack',@editColormap);
uicontrol(...
'Parent', colormapPanelId,...
'FontSize', gui.fontSize, ...
'Style', 'Text',...
'FontSize', gui.fontSize, ...
'String', 'Dynamic',...
'Position', [gui.marginSub(1), gui.marginSub(2)+gui.buttonHeight,...
gui.textWidth, gui.textHeight],...
'CallBack',@changeOpacity);
gui.editDynamicId = uicontrol(...
'Parent', colormapPanelId,...
'FontSize', gui.fontSize, ...
'Style', 'edit',...
'BackgroundColor', gui.buttonBackgroundColor,...
'String', num2str(default.dynamic),...
'Position', [gui.marginSub(1)+gui.textWidth,...
gui.marginSub(2)+gui.buttonHeight,...
gui.editWidth,...
gui.textHeight],...
'CallBack',@changeDynamic);
zoomPanelId = uipanel(...
'Parent', uipanelId,...
'Title', 'Zoom',...
'TitlePosition', 'centertop',...
'FontSize', gui.fontSize, ...
'Units', 'pixels',...
'Position', [1, 2*subPanelHeight+1, subpanelSize(1)]);
zoomInIcon = imread([iconpath,'zoomin.png']);
buttonZoomInId = uicontrol(...
'Parent', zoomPanelId,...
'Style', 'togglebutton',...
'String', '',...
'TooltipString', 'Zoom in',...
'CData', zoomInIcon,...
'Min', false,...
'Max', true,...
'Value', false,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(1, 1, gui.marginSub),...
'CallBack', {@changeTool, 'zoomIn'});
gui.tool(end).buttonId = buttonZoomInId;
gui.tool(end).name= 'zoomIn';
gui.tool(end).function = @switchZoomIn;
zoomOutIcon = imread([iconpath,'zoomout.png']);
buttonZoomOutId = uicontrol(...
'Parent', zoomPanelId,...
'Style', 'togglebutton',...
'String', '',...
'TooltipString', 'Zoom out',...
'CData', zoomOutIcon,...
'Min', false,...
'Max', true,...
'Value', false,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(2, 1, gui.marginSub),...
'CallBack', {@changeTool, 'zoomOut'});
gui.tool(end+1).buttonId = buttonZoomOutId;
gui.tool(end).name = 'zoomOut';
gui.tool(end).function = @switchZoomOut;
panIcon = imread([iconpath,'pan.png']);
buttonPanId = uicontrol(...
'Parent', zoomPanelId,...
'Style', 'togglebutton',...
'String', '',...
'TooltipString', 'Pan',...
'CData', panIcon,...
'Min', false,...
'Max', true,...
'Value', false,...
'BackgroundColor', gui.buttonBackgroundColor,...
'Position', buttonPos(3, 1, gui.marginSub),...
'CallBack', {@changeTool, 'pan'});
gui.tool(end+1).buttonId = buttonPanId;
gui.tool(end).name = 'pan';
gui.tool(end).function = @switchPan;
end
function clicSymb(objId, eventData)
delSel;
gui.showSymb = true;
drawAllSel;
end
function switchZoomIn(toolInd)
% toolInd is not used but needed as I pass a parameter to this
% function !!! precise this
if getMatlabVersion >= 7.3
zoomId = zoom(gui.mainFigId);
set(zoomId,...
'Direction', 'in',...
'Enable', 'on',...
'ActionPostCallback', @updateExploreRect);
else
zoom(gui.mainFigId, 'on');
% !!! this is undocumented in version 7.2 but it works, do something
% more general
zoom(gui.mainFigId, 'Direction', 'in');
% !!! problem: we miss something here to force update rectangle in
% overview after a zoom
end
end
function switchZoomOut(toolInd)
% toolInd is not used but needed as I pass a parameter to this function
% !!! precise this
if getMatlabVersion >= 7.3
zoomId = zoom(gui.mainFigId);
set(zoomId,...
'Direction', 'out',...
'Enable', 'on',...
'ActionPostCallback', @updateExploreRect);
else
zoom(gui.mainFigId, 'on');
% !!! this is undocumented in version 7.2 but it works, do something
% more general
zoom(gui.mainFigId, 'Direction', 'out');
% !!! problem: we miss something here to force update rectangle in
% overview after a zoom
end
end
function switchPan(toolInd)
% toolInd is not used but needed as I pass a parameter to this function
% !!! precise this
if getMatlabVersion >= 7.3
panId = pan(gui.mainFigId);
set(panId,...
'Enable', 'on',...
'ActionPostCallback', @updateExploreRect);
else
pan(gui.mainFigId, 'on');
% !!! problem: we miss something here to force update rectangle in
% overview after a pan
end
end
function [res] = updateExploreRect(objId, eventData)
oriInd = find(strcmp('originalMain', {visu.label}), 1);
exploreSetRect(get(visu(oriInd).axesId, 'XLim'),...
get(visu(oriInd).axesId, 'YLim'));
end
function editColormap(objId, eventData)
colormapeditor(gui.mainFigId);
end
function changeDynamic(objId, eventData)
oriInd = find(strcmp('originalMain', {visu.label}), 1);
temp = str2num(get(gui.editDynamicId, 'String'));
if isempty(temp) || temp < 0
errordlg(['Dynamic parameter is invalid, it must be a positive '...
'number in dB']);
set(gui.editDynamicId, 'String', num2str(visu(oriInd).dynamic));
return;
end
visu(oriInd).dynamic = temp;
updateVisu(false, true);
end
function exploreOverview(axesId)
oriInd = find(strcmp('originalMain', {visu.label}), 1);
axLim = axis(visu(oriInd).axesId);
xLim = axLim(1:2);
yLim = axLim(3:4);
indXData = [1, 2, 2, 1];
indYData = [1, 1, 2, 2];
gui.exploreRect.patchId = patch(...
'Parent', axesId,...
'XData', xLim(indXData),...
'YData', yLim(indYData),...
'FaceColor', 'none',...
'LineWidth', 2,...
'EdgeColor', 'w',... % !!! put the color and width as variables
'ButtonDownFcn', @explorePatchButtonDown);
gui.exploreRect.lineId = line(...
'Parent', axesId,...
'XData', xLim(indXData),...
'YData', yLim(indYData),...
'LineStyle', 'None',...
'LineWidth', 2,...
'Color', 'w',... % !!! put the color and width as variables
'Marker', 'o',...
'MarkerSize', 7,...
'ButtonDownFcn', @exploreLineButtonDown);
patchId = gui.exploreRect.patchId;
lineId = gui.exploreRect.lineId;
figId = gui.mainFigId;
initPoint = [];
indX = [];
indY = [];
exploreAxesXLim = [];
exploreAxesYLim = [];
function exploreLineButtonDown(objId, eventData)
% the coordinate that should be modified depends on the selected
% corner
point = get(axesId,'CurrentPoint');
xData = get(lineId, 'XData');
yData = get(lineId, 'YData');
xLim = xData(1:2);
yLim = yData(2:3);
[mi, indX] = min(abs(xLim - point(1,1)));
[mi, indY] = min(abs(yLim - point(1,2)));
set(figId,'WindowButtonMotionFcn',@exploreMotionLine);
set(figId,'WindowButtonUpFcn',@exploreButtonUp);
end
function exploreMotionLine(objId, eventData)
point = get(axesId,'CurrentPoint');
xLim(indX) = point(1,1);
yLim(indY) = point(1,2);
% reorder the values
xLimSort = sort(xLim);
yLimSort = sort(yLim);
set(patchId,...
'XData', xLimSort(indXData),...
'YData', yLimSort(indYData));
set(lineId,...
'XData', xLimSort(indXData),...
'YData', yLimSort(indYData));
oriInd = find(strcmp('originalMain', {visu.label}), 1);
axis(visu(oriInd).axesId, [xLimSort, yLimSort]);
% !!! this plot can be removed if it's to heavy
drawnow;
end
function explorePatchButtonDown(objId, eventData)
initPoint = get(axesId,'CurrentPoint');
exploreAxesXLim = get(axesId, 'XLim');
exploreAxesYLim = get(axesId, 'YLim');
xData = get(patchId, 'XData');
yData = get(patchId, 'YData');
xLim = xData(1:2);
yLim = yData(2:3);
set(figId,'WindowButtonMotionFcn',@exploreMotionPatch);
set(figId,'WindowButtonUpFcn',@exploreButtonUp);
end
function exploreMotionPatch(objId, eventData)
point = get(axesId,'CurrentPoint');
newXLim = xLim + (point(1,1)-initPoint(1,1));
newYLim = yLim + (point(1,2)-initPoint(1,2));
if ~(newXLim(2) < exploreAxesXLim(1) ||...
newXLim(1) > exploreAxesXLim(2) ||...
newYLim(2) < exploreAxesYLim(1) ||...
newYLim(1) > exploreAxesYLim(2))
set(patchId,...
'XData', newXLim(indXData),...
'YData', newYLim(indYData));
set(lineId,...
'XData', newXLim(indXData),...
'YData', newYLim(indYData));
oriInd = find(strcmp('originalMain', {visu.label}), 1);
axis(visu(oriInd).axesId, [newXLim; newYLim]);
% !!! this plot can be removed if it's to heavy
drawnow;
end
end
function exploreButtonUp(objId, eventData)
set(figId,'WindowButtonMotionFcn','');
set(figId,'WindowButtonUpFcn','');
xData = get(patchId, 'XData');
yData = get(patchId, 'YData');
oriInd = find(strcmp('originalMain', {visu.label}), 1);
axis(visu(oriInd).axesId, [xData(1:2); yData(2:3)]);
end
end
function exploreSetRect(xLim, yLim)
indXData = [1, 2, 2, 1];
indYData = [1, 1, 2, 2];
if ishandle(gui.exploreRect.patchId)
set(gui.exploreRect.patchId,...
'XData', xLim(indXData),...
'YData', yLim(indYData));
end
if ishandle(gui.exploreRect.lineId)
set(gui.exploreRect.lineId,...
'XData', xLim(indXData),...
'YData', yLim(indYData));
end
end
end