More error vs Error().throw cleanups
[supercollider.git] / HelpSource / Classes / SoundFileView.schelp
blob68e63002e2cb73a1f894be13b52acffa54f02925
1 class:: SoundFileView
2 redirect:: implClass
3 summary:: Sound file display
4 categories:: GUI>Views
5 related:: Classes/SoundFile
8 DESCRIPTION::
10 A sound file viewer with numerous options.
13 CLASSMETHODS::
15 PRIVATE:: key
18 INSTANCEMETHODS::
20 SUBSECTION:: Data
22 METHOD:: soundfile
24     argument::
25         An Instance of SoundFile to display.
28 METHOD:: read
30     Reads a section of the link::#-soundfile:: and displays it in the view. For large files, you may want to use readWithTask instead.
32     note:: In Qt GUI, the 'block' argument has no effect; the display resolution is infinite. ::
34     argument:: startFrame
35         The beginning of the section, in frames.
37     argument:: frames
38         The size of the section, in frames.
40     argument:: block
41         The block size - visual resolution of the display. An Integer of the form 2**n.
43     argument:: closeFile
44         If true, closes the SoundFile after reading.
47 METHOD:: readFile
49     Reads a section of an open instance of SoundFile, and displays it in the view. For large files, you may want to use the method readWithTask instead.
51     note:: In Qt GUI, the 'block' argument has no effect; the display resolution is infinite. ::
53     argument:: soundfile
54         An open instance of SoundFile.
56     argument:: startFrame
57         The beginning of the section, in frames.
59     argument:: frames
60         The size of the section, in frames.
62     argument:: block
63         The block size - visual resolution of the display. An Integer of the form 2**n.
65     argument:: closeFile
66         If true, closes the SoundFile after reading.
68 METHOD:: readWithTask
70     Reads a section of the link::#-soundfile:: asynchronously (in the background), updating the link::#-readProgress:: along the way. If the code::showProgress:: argument is code::true::, a SoundFileViewProgressWindow opens to show the progress.
72     note:: In Qt GUI:
73         The 'block' argument has no effect; the display resolution is infinite.
74         The 'showProgress' argument has no effect; the view always displays reading progress within itself.
75     ::
77     argument:: startFrame
78         The beginning of the section, in frames.
80     argument:: frames
81         The size of the section, in frames.
83     argument:: block
84         The block size - visual resolution of the display. An Integer of the form 2**n.
86     argument:: doneAction
87         An optional function to be evaluated on completion.
89     argument:: showProgress
90         Whether to open a progress window. Defaults to code::true::.
93 METHOD:: readFileWithTask
95     Reads a section of an open instance of SoundFile asynchronously (in the background), updating the link::#-readProgress:: along the way. If the code::showProgress:: argument is code::true::, a SoundFileViewProgressWindow opens to show the progress.
97     note:: In Qt GUI:
98         The 'block' argument has no effect; the display resolution is infinite.
99         The 'showProgress' argument has no effect; the view always displays reading progress within itself.
100     ::
102     argument:: soundfile
103         An open instance of SoundFile.
105     argument:: startFrame
106         The beginning of the section, in frames.
108     argument:: frames
109         The size of the section, in frames.
111     argument:: block
112         The block size - visual resolution of the display. An Integer of the form 2**n.
114     argument:: doneAction
115         An optional function to be evaluated on completion.
117     argument:: showProgress
118         Whether to open a progress window. Defaults to code::true::.
120 METHOD:: startFrame
122     The beginning of the displayed section of the soundfile, in frames.
124 METHOD:: numFrames
126     The size of the displayed section of the soundfile, in frames.
128 METHOD:: readProgress
130      The reading progress, updated periodically when reading a soundfile using link::#-readWithTask:: or link::#-readFileWithTask::.
132 METHOD:: data
134     Gets the display data, or sets custom data instead of a sound file.
136     note:: In Qt and SwingOSC it is not possible to get the data. ::
138     In Cocoa and SwingOSC, setting this property is equivalent to link::#-setData:: with number of channels and sample rate of the current link::#-soundfile:: (if any), while in Qt it always assumes 1 channel and sample rate of 44100 Hz. Use link::#-setData:: instead if you want more control.
140     argument::
141         An Array of Floats; multiple channel data should be interleaved.
143 METHOD:: setData
145     Sets custom display data instead of a sound file, interpreting it using specified number of channels and sample rate.
147     note:: In Qt GUI, the 'block' argument has no effect; the display resolution is infinite. ::
149     argument:: arr
150         An Array of Floats; multiple channel data should be interleaved.
152     argument:: block
153         The block size - visual resolution of the display. An Integer of the form 2**n.
155     argument:: startframe
156         An integer.
158     argument:: channels
159         An integer.
161     argument:: samplerate
162         An integer.
165 SUBSECTION:: Navigation
167 METHOD:: viewFrames
169     The amount of currently visible frames in the view.
171 METHOD:: zoom
173     Zooms by a factor relative to current zoom.
175     argument::
176         A Float.
178 METHOD:: zoomToFrac
180     Zooms to a specific scale.
182     argument::
183         A Float.
185 METHOD:: zoomAllOut
187     Zooms to the link::#-currentSelection#current selection::.
189 METHOD:: zoomSelection
191     Zooms to a specific selection.
193     argument::
194         The index of the selection; an Integer between 0 an 63.
196 METHOD:: scrollPos
198     The scrolling position of the view, as a fraction of the total scrolling range.
200     returns::
201         A Float in the range of 0.0 to 1.0.
203 METHOD:: scrollTo
205     Scrolls to a fraction of the total scrolling range.
207     argument::
208         A Float in the range of 0.0 to 1.0.
210 METHOD:: scroll
212     Scrolls by a fraction of the visible range.
214     argument::
215         A Float.
217 METHOD:: scrollToStart
219     Scrolls to the beginning.
221 METHOD:: scrollToEnd
223     Scrolls to the end.
226 SUBSECTION:: Selection
228 METHOD:: selections
230     All the selections.
232     returns:: An array of 64 arrays of start frames and sizes: [ [ start0, size0 ] , [ start1, size1 ], ... ].
234 METHOD:: selection
236     The selection at index.
238     returns::
239         An Array of the form code::[start, size]::, where start and size denote frames.
241 METHOD:: setSelection
243     Sets the selection at index.
245     argument:: index
246         An Integer between 0 an 63.
248     argument:: selection
249         An Array of the form code::[start, size]::, where start and size are Integers and denote frames.
251 METHOD:: currentSelection
253     The index of the current selection
255     argument::
256         An integer between 0 an 63.
258 METHOD:: selectionStart
260     The start frame of a selection.
262     argument:: index
263         The index of the selection; an Integer between 0 an 63.
265     returns::
266         An Integer.
268 METHOD:: setSelectionStart (index, frame)
270     Sets the start frame of a selection.
272     argument:: index
273         The index of the selection; an Integer between 0 an 63.
275     argument:: frame
276         The starting frame of the selection, an Integer.
278 METHOD:: selectionSize
280     The size of a selection.
282     argument:: index
283         The index of the selection; an Integer between 0 an 63.
285     returns::
286         An Integer.
288 METHOD:: setSelectionSize
290     Sets the size of a selection.
292     argument:: index
293         The index of the selection; an Integer between 0 an 63.
295     argument:: frames
296         The size in frames of the selection, an Integer.
298 METHOD:: selectionStartTime
300     The start of a selection in seconds.
302     argument:: index
303         The index of the selection; an Integer between 0 an 63.
305     returns::
306         A Float.
308 METHOD:: selectionDuration
310     The size of a selection in seconds.
312     argument:: index
313         The index of the selection; an Integer between 0 an 63.
315     returns::
316         A Float.
318 METHOD:: selectAll
320     Sets a selection to span the whole data range.
322     argument:: index
323         The index of the selection; an Integer between 0 an 63.
326 METHOD:: selectNone
328     Sets the size of a selectino to 0.
330     argument:: index
331         The index of the selection; an Integer between 0 an 63.
333 METHOD:: setSelectionColor
335     Sets the color of a selection.
337     argument:: index
338         The index of the selection; an Integer between 0 an 63.
340     argument:: color
341         A Color.
343 METHOD:: setEditableSelectionStart
345     Sets whether the start point of a selection can be edited.
347     argument:: index
348         The index of the selection; an Integer between 0 an 63.
350     argument:: editable
351         A Boolean.
353 METHOD:: setEditableSelectionSize (index, bool)
355     Whether the end point of a selection can be edited.
357     argument:: index
358         The index of the selection; an Integer between 0 an 63.
360     argument:: editable
361         A Boolean.
363 METHOD:: readSelection
365     note:: Not in Qt GUI ::
367     Read the data within a selection.
369     argument:: block
370         The block size - visual resolution of the display. An Integer of the form 2**n.
372     argument:: closeFile
373         If true, closes the SoundFile after reading.
375 METHOD:: readSelectionWithTask
377     note:: Not in Qt GUI ::
379     Read the data within the current selection asynchronously (in the background), showing the progress in a separate window.
382 SUBSECTION:: Display
384 METHOD:: gridOn
386     Whether the grid is displayed. Defaults to code::true::.
388     argument::
389         A Boolean.
391 METHOD:: gridResolution
393     The resolution of the grid.
395     argument::
396         An instance of Float.
398 METHOD:: gridOffset
400     Sets the grid offset.
402     argument::
403         An integer.
405 METHOD:: gridColor
407     The color of the grid.
409     argument::
410         A Color.
412 METHOD:: drawsWaveForm
414     Whether the data is displayed. Defaults to code::true::.
416     argument::
417         A Boolean.
419 METHOD:: timeCursorOn
421     Whether the time cursor is displayed. Defaults to code::false::.
423     argument::
424         A Boolean.
426 METHOD:: timeCursorPosition
428     The position of the time cursor in frames.
430     argument::
431         An Integer.
433 METHOD:: timeCursorColor
435     The color of the time cursor.
437     argument::
438         A Color.
440 METHOD:: elasticMode
442     ???
444 SUBSECTION:: Actions
446 METHOD:: action
448     The object to be evaluated whenever the user interacts with the view.
450 METHOD:: metaAction
452     The object to be evaluated on Ctrl + click.
455 EXAMPLES::
457 SUBSECTION:: Basic example
459 code::
461 w = Window.new("soundfile test", Rect(200, 200, 800, 400));
462 a = SoundFileView.new(w, Rect(20,20, 700, 60));
464 f = SoundFile.new;
465 f.openRead("sounds/a11wlk01.wav");
466 f.inspect;
468 a.soundfile = f;
469 a.read(0, f.numFrames);
470 a.elasticMode = true;
472 a.timeCursorOn = true;
473 a.timeCursorColor = Color.red;
474 a.timeCursorPosition = 2050;
475 a.drawsWaveForm = true;
476 a.gridOn = true;
477 a.gridResolution = 0.2;
479 w.front;
483 SUBSECTION:: Step by step examples
485 code::
486 ( // make a simple SoundFileView
487 w = Window.new("soundfile test", Rect(10, 700, 750, 100));
488 w.front;
489 a = SoundFileView.new(w, Rect(20,20, 700, 60));
491 f = SoundFile.new;
492 f.openRead("sounds/a11wlk01.wav");
493 // f.inspect;
495 a.soundfile = f;            // set soundfile
496 a.read(0, f.numFrames);     // read in the entire file.
497 a.refresh;                  // refresh to display the file.
500 // reading file
501 a.read(0, f.numFrames / 2).refresh; // read first half
502 a.read.refresh;                     // read entire file by default
503 a.read(f.numFrames / 2).refresh;    // read second half
504 a.read(0, -1).refresh;              // -1 also reads entire file, like buffer.
506 // block sets visual resolution of waveform, default is 64.
507 // i.e. the view keeps peak values for each block of e.g. 64 samples
508 // rather than the entire waveform.
509 a.read(0, -1, block: 32).refresh;
510 a.read(0, -1, block: 24).refresh;
511 a.read(0, -1, block: 16).refresh;
513 // for longer files, you can use:
514 a.readWithTask;
516 // zoom is relative
517 a.zoom(0.2).refresh;
518 a.zoom(2).refresh;
519 a.zoom(2).refresh;
520 a.zoomToFrac(0.5); // zoom to half file size
521 a.zoomAllOut;
523 a.gridOn = true;            // time grid, 1 second by default,
524 a.gridResolution = 0.2;     // or set resolution in seconds
525 a.gridColor = Color.cyan;   // color is changeable.
526 a.gridOffset_(0.1);         // not sure if this is working?
528 a.timeCursorOn = true;          // a settable cursor
529 a.timeCursorPosition = 2050;    // position is in frames.
530 a.timeCursorColor = Color.white;
532 // toggle drawing on/off
533 a.drawsWaveForm = false;
534 a.drawsWaveForm = true;
536 // these methods should return view properties:
537 a.gridOn
538 a.gridResolution
539 a.gridColor
540 a.timeCursorOn
541 a.timeCursorPosition
542 a.timeCursorColor
544 // Selections: multiple selections are supported.
545 // e.g. use selection 0:
546 a.setSelectionColor(0, Color.red);  // set...( index, value )
547 a.selectionStart(0);                // at index
548 a.setSelectionStart(0, 12345);
549 a.setSelectionSize(0, 12345);
551 a.setSelectionStart(0, 1234);
552 a.selectionStart(0);
554 // now selection 1
555 a.setSelectionColor(1, Color.white);
556 a.setSelectionStart(1, 1234).setSelectionSize(1, 1234 * 2);
557 a.selectionStart(1);
558 a.setSelectionStart(0, 12345);
560 // the current selection gets changed when click/dragging in view.
561 a.currentSelection;     // index of current selection;
562 a.currentSelection_(1); // switch current selection - try click/drag white now.
563 a.currentSelection;
565 a.selections.size;      // 64 selections
566 a.selections[0];
567 a.selections[1];
568 a.selections;
570 // setSelection (index, selection);
571 a.setSelection(0, [234, 2345]);
572 a.selection(1); // returns [start, size].
575 a.elasticMode = true;   // not sure if this is working yet?
577 (       // mouseUpAction
578 a.mouseUpAction = {
579     ("mouseUp, current selection is now:"
580         + a.selections[a.currentSelection]).postln;
583 // lock selection 0:
584 a.currentSelection_(0);
585 a.setEditableSelectionStart(0, false);
586 a.setEditableSelectionSize(0, false);
589 // unlock selection 0:
590 a.setEditableSelectionStart(0, true);
591 a.setEditableSelectionSize(0, true);
593 a.selectionStartTime(0);
594 a.selectionDuration(0);
597 a.setSelectionStart(0, 12345);
598 a.setSelectionSize(0, 12345);
599 a.readSelection.refresh;
600 a.readSelection(16).refresh;    // in higher resolution
601 a.read.refresh;                 // go back to entire file.
604 a.dataNumSamples;   // visual data have this many points
605 a.data.plot;
606 a.setData(a.data.reverse);
609 a.zoom(0.25);       // scrolling is normalized
610 a.scrollTo(0.5);    //
611 a.scrollTo(0.6);    //
612 a.scroll(12);       // scroll is in viewFrames.
614 a.zoom(4);
616 w.close;