3 summary:: Sound file display
5 related:: Classes/SoundFile
10 A sound file viewer with numerous options.
12 In strong::Qt GUI:: you can strong::zoom:: in and out using Shift + right-click + mouse-up/down; likewise, you can strong::scroll:: using right-click + mouse-left/right.
26 An Instance of SoundFile to display.
31 Reads a section of the link::#-soundfile:: and displays it in the view. For large files, you may want to use readWithTask instead.
33 note:: In Qt GUI, the 'block' argument has no effect; the display resolution is infinite. ::
36 The beginning of the section, in frames.
39 The size of the section, in frames.
42 The block size - visual resolution of the display. An Integer of the form 2**n.
45 If true, closes the SoundFile after reading.
50 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.
52 note:: In Qt GUI, the 'block' argument has no effect; the display resolution is infinite. ::
55 An open instance of SoundFile.
58 The beginning of the section, in frames.
61 The size of the section, in frames.
64 The block size - visual resolution of the display. An Integer of the form 2**n.
67 If true, closes the SoundFile after reading.
71 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.
74 The 'block' argument has no effect; the display resolution is infinite.
75 The 'showProgress' argument has no effect; the view always displays reading progress within itself.
79 The beginning of the section, in frames.
82 The size of the section, in frames.
85 The block size - visual resolution of the display. An Integer of the form 2**n.
88 An optional function to be evaluated on completion.
90 argument:: showProgress
91 Whether to open a progress window. Defaults to code::true::.
94 METHOD:: readFileWithTask
96 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.
99 The 'block' argument has no effect; the display resolution is infinite.
100 The 'showProgress' argument has no effect; the view always displays reading progress within itself.
104 An open instance of SoundFile.
106 argument:: startFrame
107 The beginning of the section, in frames.
110 The size of the section, in frames.
113 The block size - visual resolution of the display. An Integer of the form 2**n.
115 argument:: doneAction
116 An optional function to be evaluated on completion.
118 argument:: showProgress
119 Whether to open a progress window. Defaults to code::true::.
123 Gets the display data, or sets custom data instead of a sound file.
125 note:: In Qt and SwingOSC it is not possible to get the data. ::
127 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.
130 An Array of Floats; multiple channel data should be interleaved.
134 Sets custom display data instead of a sound file, interpreting it using specified number of channels and sample rate.
136 note:: In Qt GUI, the 'block' argument has no effect; the display resolution is infinite. ::
139 An Array of Floats; multiple channel data should be interleaved.
142 The block size - visual resolution of the display. An Integer of the form 2**n.
144 argument:: startframe
150 argument:: samplerate
154 NOTE:: Only in Qt GUI ::
155 Allocates a desired amount of display channels and frames; all frames have initial value of 0.
160 argument:: samplerate
164 NOTE:: Only in Qt GUI ::
165 Overwrites a range of display data with another data. This method can be used after link::#-alloc:: or link::#-setData:: has been called, but not while the view is displaying a sound file.
168 The frame at which to start overwriting; an Integer.
170 The new data; an Array of Floats; multiple channel data should be interleaved.
174 The beginning of the read section of the soundfile, or 0 if link::#-alloc:: or link::#-setData:: has been used.
178 The total amount of frames in the view; this is unrelated to link::#-zoom#zooming:: and link::#-scroll#scrolling::.
180 METHOD:: readProgress
182 The reading progress, updated periodically when reading a soundfile using link::#-readWithTask:: or link::#-readFileWithTask::.
184 SUBSECTION:: Navigation
188 The amount of currently visible frames in the view.
192 Zooms by a factor relative to current zoom.
199 Zooms to a specific scale.
206 Zooms to the link::#-currentSelection#current selection::.
208 METHOD:: zoomSelection
210 Zooms to a specific selection.
213 The index of the selection; an Integer between 0 an 63.
217 The scrolling position of the view, as a fraction of the total scrolling range.
220 A Float in the range of 0.0 to 1.0.
224 Scrolls to a fraction of the total scrolling range.
227 A Float in the range of 0.0 to 1.0.
231 Scrolls by a fraction of the visible range.
236 METHOD:: scrollToStart
238 Scrolls to the beginning.
245 SUBSECTION:: Selection
251 returns:: An array of 64 arrays of start frames and sizes: [ [ start0, size0 ] , [ start1, size1 ], ... ].
255 The selection at index.
258 An Array of the form code::[start, size]::, where start and size denote frames.
260 METHOD:: setSelection
262 Sets the selection at index.
265 An Integer between 0 an 63.
268 An Array of the form code::[start, size]::, where start and size are Integers and denote frames.
270 METHOD:: currentSelection
272 The index of the current selection
275 An integer between 0 an 63.
277 METHOD:: selectionStart
279 The start frame of a selection.
282 The index of the selection; an Integer between 0 an 63.
287 METHOD:: setSelectionStart
289 Sets the start frame of a selection.
292 The index of the selection; an Integer between 0 an 63.
295 The starting frame of the selection, an Integer.
297 METHOD:: selectionSize
299 The size of a selection.
302 The index of the selection; an Integer between 0 an 63.
307 METHOD:: setSelectionSize
309 Sets the size of a selection.
312 The index of the selection; an Integer between 0 an 63.
315 The size in frames of the selection, an Integer.
317 METHOD:: selectionStartTime
319 The start of a selection in seconds.
322 The index of the selection; an Integer between 0 an 63.
327 METHOD:: selectionDuration
329 The size of a selection in seconds.
332 The index of the selection; an Integer between 0 an 63.
339 Sets a selection to span the whole data range.
342 The index of the selection; an Integer between 0 an 63.
347 Sets the size of a selectino to 0.
350 The index of the selection; an Integer between 0 an 63.
352 METHOD:: setSelectionColor
354 Sets the color of a selection.
357 The index of the selection; an Integer between 0 an 63.
362 METHOD:: setEditableSelectionStart
364 Sets whether the start point of a selection can be edited.
367 The index of the selection; an Integer between 0 an 63.
372 METHOD:: setEditableSelectionSize
374 Whether the end point of a selection can be edited.
377 The index of the selection; an Integer between 0 an 63.
382 METHOD:: readSelection
384 note:: Not in Qt GUI ::
386 Read the data within a selection.
389 The block size - visual resolution of the display. An Integer of the form 2**n.
392 If true, closes the SoundFile after reading.
394 METHOD:: readSelectionWithTask
396 note:: Not in Qt GUI ::
398 Read the data within the current selection asynchronously (in the background), showing the progress in a separate window.
405 Whether the grid is displayed. Defaults to code::true::.
410 METHOD:: gridResolution
412 The resolution of the grid.
415 An instance of Float.
419 Sets the grid offset.
426 The color of the grid.
431 METHOD:: drawsWaveForm
433 Whether the data is displayed. Defaults to code::true::.
438 METHOD:: timeCursorOn
440 Whether the time cursor is displayed. Defaults to code::false::.
445 METHOD:: timeCursorPosition
447 The position of the time cursor in frames.
452 METHOD:: timeCursorColor
454 The color of the time cursor.
467 The object to be evaluated whenever the user interacts with the view.
471 The object to be evaluated on Ctrl + click.
476 SUBSECTION:: Basic example
480 // To zoom in/out: Shift + right-click + mouse-up/down
481 // To scroll: right-click + mouse-left/right
483 w = Window.new("soundfile test", Rect(200, 300, 740, 100));
484 a = SoundFileView.new(w, Rect(20,20, 700, 60));
487 f.openRead(Platform.resourceDir +/+ "sounds/a11wlk01.wav");
491 a.read(0, f.numFrames);
492 a.elasticMode = true;
494 a.timeCursorOn = true;
495 a.timeCursorColor = Color.red;
496 a.timeCursorPosition = 2050;
497 a.drawsWaveForm = true;
499 a.gridResolution = 0.2;
505 SUBSECTION:: Step by step examples
508 ( // make a simple SoundFileView
509 y = Window.screenBounds.height - 120;
510 w = Window.new("soundfile test", Rect(200, y, 740, 100)).alwaysOnTop_(true);
512 a = SoundFileView.new(w, Rect(20,20, 700, 60));
515 f.openRead(Platform.resourceDir +/+ "sounds/a11wlk01.wav");
518 a.soundfile = f; // set soundfile
519 a.read(0, f.numFrames); // read in the entire file.
520 a.refresh; // refresh to display the file.
524 // To zoom in/out: Shift + right-click + mouse-up/down
525 // To scroll: right-click + mouse-left/right
528 a.read(0, f.numFrames / 2).refresh; // read first half
529 a.read.refresh; // read entire file by default
530 a.read(f.numFrames / 2).refresh; // read second half
531 a.read(0, -1).refresh; // -1 also reads entire file, like buffer.
533 // In Qt GUI, the resolution of the view is always infinite;
534 // you can always zoom in until you see a single sample.
536 // In other GUI kits, 'block' sets the resolution of the view (default is 64).
537 // i.e. the view keeps peak values for each block of e.g. 64 samples
538 // rather than the entire waveform.
539 a.read(0, -1, block: 32).refresh;
540 a.read(0, -1, block: 24).refresh;
541 a.read(0, -1, block: 16).refresh;
543 // for longer files, you can use:
550 a.zoomToFrac(0.5); // zoom to half file size
553 a.gridOn = true; // time grid, 1 second by default,
554 a.gridResolution = 0.2; // or set resolution in seconds
555 a.gridColor = Color.cyan; // color is changeable.
556 a.gridOffset_(0.1); // not sure if this is working?
558 a.timeCursorOn = true; // a settable cursor
559 a.timeCursorPosition = 2050; // position is in frames.
560 a.timeCursorColor = Color.white;
562 // toggle drawing on/off
563 a.drawsWaveForm = false;
564 a.drawsWaveForm = true;
566 // these methods should return view properties:
574 // Selections: multiple selections are supported.
575 // e.g. use selection 0:
576 a.setSelectionColor(0, Color.red); // set...( index, value )
577 a.selectionStart(0); // at index
578 a.setSelectionStart(0, 12345);
579 a.setSelectionSize(0, 12345);
581 a.setSelectionStart(0, 1234);
585 a.setSelectionColor(1, Color.white);
586 a.setSelectionStart(1, 1234).setSelectionSize(1, 1234 * 2);
588 a.setSelectionStart(0, 12345);
590 // the current selection gets changed when click/dragging in view.
591 a.currentSelection; // index of current selection;
592 a.currentSelection_(1); // switch current selection - try click/drag white now.
595 a.selections.size; // 64 selections
600 // setSelection (index, selection);
601 a.setSelection(0, [234, 2345]);
602 a.selection(1); // returns [start, size].
605 a.elasticMode = true; // not sure if this is working yet?
609 ("mouseUp, current selection is now:"
610 + a.selections[a.currentSelection]).postln;
614 a.currentSelection_(0);
615 a.setEditableSelectionStart(0, false);
616 a.setEditableSelectionSize(0, false);
619 // unlock selection 0:
620 a.setEditableSelectionStart(0, true);
621 a.setEditableSelectionSize(0, true);
623 a.selectionStartTime(0);
624 a.selectionDuration(0);
627 a.setSelectionStart(0, 12345);
628 a.setSelectionSize(0, 12345);
629 a.readSelection.refresh;
630 a.readSelection(16).refresh; // in higher resolution
631 a.read.refresh; // go back to entire file.
634 a.dataNumSamples; // visual data have this many points
636 a.setData(a.data.reverse);
639 a.zoom(0.25); // scrolling is normalized
642 a.scroll(12); // scroll is in viewFrames.