forked from ltfat/ltfat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulaclab.m
4905 lines (4111 loc) · 143 KB
/
mulaclab.m
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
function [] = mulaclab(file, varargin)
%MULACLAB Graphical interface for audio processing using frame multipliers
% Usage: mulaclab;
% mulaclab(filename);
% mulaclab(signal, fs);
%
% Input parameters:
% filename : File name of the signal to process.
% signal : Signal to process, which must be a vector.
% fs : Sampling frequency of the signal.
%
% When starting `mulaclab` without any input parameter, 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 multichannel `.wav` files, the first
% channel is used as the original signal.
%
% Optionnaly, the file name of the original signal can be directly passed as
% an input parameter. The original signal can also be directly passed as a
% vector along its sampling frequency.
%
% 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 frame
% 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.
%AUTHOR: Florent Jaillet
% Known bugs:
% - There might be a bug with noise level when using selection layers of type
% hole filling with noise.
% Something really strange is hapenning, for a given selection we 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
%
% 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.
%
% Some PI :
% - add possibility to see an individual atom of the frame (and the dual)
% (with right clic menu?)
% - possibility to have a nice view (3D?) of the symbol
% - possibility to choose the channel and a time selection of wave files
% - switch between original and modified when audio playing without stopping
% playback
% - add editable keyboard shortcuts for almost everything
% - add something to show that a processing is currently running
% (progressbar? change of mouse pointer?)
% - give possibility to use a Gaussian window
% - update information of contextual menu for layers to know what are the
% currently selected properties
% - add possibility to modify afterward the polygons
% List of functions used from the image toolbox :
% bwselect: used for the magic wand.
% In Octave, uses bwfill which is written in c++
% imdilate: used to convert layers of type fill and fillNoise.
% In Octave, uses imerode which is written in c++
% _____________________ Description of shared data ________________________
%
% Mulaclab was initially developped only for MATLAB as Octave was at that time
% missing the needed features to build advanced GUIs.
%
% In this original version, nested functions were used to share data among GUI
% callbacks and a set of variables where defined at the top level of the
% mulaclab function to share the data between the GUI components.
%
% With its version 4.0.0, Octave gained most of the GUI features needed by
% mulaclab, so mulaclab was then adapted to work on both MATLAB and Octave.
%
% But Octave 4.0.0 doesn't support the use of nested functions in GUI callbacks.
% So the new version of mulaclab now uses global variables to share data
% among GUI callbacks (even if it's not an elegant solution, but we do with the
% limitations that we face...) .
%
% Here is a list of these global variables with their description:
% NOTE: This list has not been fully updated with the evolution of the mulaclab
% code. So it misses the description of some shared variables introduced later
% in the developement and might be incomplete and inaccurate in some places.
%
% 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.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
%
% - coeff.oriC: (matrix, dimension 1: frequency, dimension 2:time)
% plotted spectrogram as image in DB
%
% - coeff.info: (struct)
% additonal data necesary for the reconstruction
%
% 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 varargin
% 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).
global coeff default export frame gui link player redoData sel sig symbol
global undoData visu visucommon
% initialize the interface
if(nargin<1)
file = [];
end
if ~isempty(file)
if handleMulaclabAction(file,varargin{:})
return;
end
end
forceSingleInstanceOfMulaclab();
coeff = struct;
default = struct;
export = struct;
frame = struct;
gui = struct;
link = struct;
player = struct;
redoData = {};
sel = struct;
sig = struct;
symbol = struct;
undoData = {};
visu = struct;
visucommon = struct;
% possible values for default.backendClipPoly: 'clipper' or 'polygonclip' or
% 'binmasks'
default.backendClipPoly = 'clipper';
initialize(file, varargin{:});
end
% end of main function, from here everything is handled with the callbacks
% using the following functions
function forceSingleInstanceOfMulaclab()
figNumber = getMulaclabFigNo();
if ~isempty(figNumber)
error(['Only one single instance of the MulAcLab gui can be run at a '...
'time and MulAcLab is already running in figure ', figNumber]);
end
end
function figNumber = getMulaclabFigNo()
% as we use global variables to share data between callbacks, we need to
% insure that only one instance of the mulaclab gui is running
mulaclabFigId = findall(0, 'name', 'MulAcLab');
% depending on the version of MATLAB, the figure number can either be
% known through its handle or through the property Number
try
figNumber = num2str(mulaclabFigId);
catch
figNumber = num2str(get(mulaclabFigId, 'Number'));
end
end
function wasaction = handleMulaclabAction(action,varargin)
wasaction = 1;
isrunning = ~isempty(getMulaclabFigNo());
actions = {'playori','applySel'};
if ~any(strcmpi(action,actions))
wasaction = 0;
if isrunning
error('Mulaclab is already running. Unrecognized action');
end
return;
end
if ~isrunning
error('MulacLab is not running!!');
end
action = lower(action);
disp(action);
disp(varargin);
switch action
case 'playori'
global sig
soundsc(sig.ori,sig.sampFreq);
case 'applysel'
applySel();
end
end
% __________________________ INITIALIZATION _______________________________
function initialize(file, varargin)
global coeff default export frame gui link player redoData sel sig symbol
global undoData visu visucommon
% check that we have all the toolboxes and functions that we need
checkToolbox;
loadFile = 0;
if nargin==0 || isempty(file)
% get an original signal or decomposition to have something to show
[fileName, pathName] = uigetfile({'*.wav;*.mat',...
'Supported formats'},...
'Open original signal or decomposition');
if fileName == 0
% the user pressed cancel, we stop here
return;
end
loadFile = 1;
elseif(ischar(file))
fileName = file;
pathName = '';
loadFile = 1;
end
if loadFile
[~, ~, ext] = fileparts(fileName);
switch lower(ext)
case '.wav'
% read the orginal signal in a wave file
[sig.ori, sig.sampFreq] =...
wavload([pathName, fileName]);
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
otherwise
error('Unrecognized file. Only wav and mat files are supported');
end
elseif(nargin>=1)
definput.keyvals.Fs=[];
[flags,kv,Fs]=ltfatarghelper({'Fs'},definput,varargin);
if(isempty(Fs))
error('%s: Second parameter: sampling frequency is missing. ',...
upper(mfilename));
end
if(numel(find(size(file)>1))>1)
error('%s: Input has to be one channel signal.',upper(mfilename));
end
% normalize and change to column vector
tmpMax = max(abs(file(:)));
if tmpMax ~= 0
sig.ori=file(:)/tmpMax;
else
sig.ori=file(:);
end
sig.real=isreal(file);
sig.sampFreq = Fs;
else
errordlg(sprintf('%s: Unrecognized input parameters.',upper(mfilename)));
return;
end
if size(sig.ori, 2) > 1
% multichannel wave, we keep only the first channel
sig.ori = sig.ori(:, 1);
end
sig.mod = sig.ori;
% initialize the different parameters of the application
initializeParameter();
% initialize the frame definition and the coefficients
frame = default.frame;
% 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','Import original signal decomposition',...
'Callback',@openOriDecompo);
uimenu(menuFileId,...
'Label','Import selection',...
'Callback',@importSel);
uimenu(menuFileId,...
'Label','Import symbol',...
'Callback',@importSymbol);
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 as ...',...
'Callback',@exportSel);
uimenu(menuFileId,...
'Label','Export symbol as ...',...
'Callback',@exportSymbol);
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');
menuFrameTypeId = uimenu(menuFrameId,...
'Label','Choose frame type');
for ind=1:length(gui.supportedFrames)
uimenu(menuFrameTypeId,...
'Label',gui.supportedFrames{ind}.type,...
'Callback',@changeFrameType,...
'UserData',ind);
end
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');
% PI: 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', 'off',...
'Callback',@toggleOverviewVisu);
% 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));
resetMulaclab();
toggleOverviewVisu(); % Do not show te overview window
resetSel();
resetSymbol();
% end of initialization, show the interface to the user
set(gui.mainFigId, 'Visible', 'on');
end
function [] = initializeParameter()
global default gui visu export
% Dictionary of structures field names string expansions
gui.mulaclabDict = struct('winType','Window type',...
'nbFreq','Number of frequency bins',...
'hop','Hop size',...
'winLen','Window length',...
'wavelet','Wavelet type',...
'J','Decomposition depth');
% Cellaray of supported frames
gui.supportedFramesIdx = 1;
gui.supportedFrames = ...
{...
struct('type','Gabreal','def',...
struct('winType','hann','winLen',1024,'hop',256,...
'nbFreq',2048)),...
struct('type','erblet','def',...
struct('M',300,'downsampling','fractionaluniform')),...
...
struct('type','cqt','def',...
struct('fmin',50,'fmax',20000,'bins',32,'downsampling','uniform')),...
...
struct('type','Gabor','def',...
struct('winType','hann','winLen',1024,'hop',256,...
'nbFreq',2048)),...
...
struct('type','DWT','def',...
struct('wavelet','sym10','J',8)),...
...
struct('type','UDWT','def',...
struct('wavelet','sym10','J',8)),...
...
struct('type','WFBT','def',...
struct('wavelet','sym10','J',7)),...
...
struct('type','UWFBT','def',...
struct('wavelet','sym10','J',4)),...
};
% 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 = gui.supportedFrames{gui.supportedFramesIdx};
default.symbol.data.name = 'Selection';
default.symbol.data.val = [];
default.symbol.data.invert = false;
default.symbol.curSymb = 1;
default.zerotodb = -100;
% define parameters for the gui (graphical user interface)
set(0,'Units','Pixels');
screenSize = get(0,'ScreenSize');
screenSize = screenSize(3:4);
if screenSize(1) > 1920
screenSize(1) = 1920;
end
if screenSize(2) > 1080
screenSize(2) = 1080;
end
ratio = 0.8;
gui.mainFigPos = round([screenSize*0.5*(1-ratio), round(screenSize*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
if isoctave()
gui.buttonWidth = 40;
else
gui.buttonWidth = 27;
end
gui.buttonHeight = 22;
gui.horiDist = 3;
gui.vertDist = 2;
gui.margin = [6, 6];
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) = 96;
gui.panelTitle{1} = 'Audioplayer';
gui.panelHeight(2) = 228;
gui.panelTitle{2} = 'Visualization';
gui.panelHeight(3) = 268;
gui.panelTitle{3} = 'Selection';
gui.visuResizeButtonWidth = 15;