3 summary:: Sound file display
5 related:: Classes/SoundFile
10 A sound file viewer with numerous options.
25 An Instance of SoundFile to display.
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. ::
35 The beginning of the section, in frames.
38 The size of the section, in frames.
41 The block size - visual resolution of the display. An Integer of the form 2**n.
44 If true, closes the SoundFile after reading.
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. ::
54 An open instance of SoundFile.
57 The beginning of the section, in frames.
60 The size of the section, in frames.
63 The block size - visual resolution of the display. An Integer of the form 2**n.
66 If true, closes the SoundFile after reading.
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.
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.
78 The beginning of the section, in frames.
81 The size of the section, in frames.
84 The block size - visual resolution of the display. An Integer of the form 2**n.
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.
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.
103 An open instance of SoundFile.
105 argument:: startFrame
106 The beginning of the section, in frames.
109 The size of the section, in frames.
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::.
122 The beginning of the displayed section of the soundfile, in frames.
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::.
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.
141 An Array of Floats; multiple channel data should be interleaved.
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. ::
150 An Array of Floats; multiple channel data should be interleaved.
153 The block size - visual resolution of the display. An Integer of the form 2**n.
155 argument:: startframe
161 argument:: samplerate
165 SUBSECTION:: Navigation
169 The amount of currently visible frames in the view.
173 Zooms by a factor relative to current zoom.
180 Zooms to a specific scale.
187 Zooms to the link::#-currentSelection#current selection::.
189 METHOD:: zoomSelection
191 Zooms to a specific selection.
194 The index of the selection; an Integer between 0 an 63.
198 The scrolling position of the view, as a fraction of the total scrolling range.
201 A Float in the range of 0.0 to 1.0.
205 Scrolls to a fraction of the total scrolling range.
208 A Float in the range of 0.0 to 1.0.
212 Scrolls by a fraction of the visible range.
217 METHOD:: scrollToStart
219 Scrolls to the beginning.
226 SUBSECTION:: Selection
232 returns:: An array of 64 arrays of start frames and sizes: [ [ start0, size0 ] , [ start1, size1 ], ... ].
236 The selection at index.
239 An Array of the form code::[start, size]::, where start and size denote frames.
241 METHOD:: setSelection
243 Sets the selection at index.
246 An Integer between 0 an 63.
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
256 An integer between 0 an 63.
258 METHOD:: selectionStart
260 The start frame of a selection.
263 The index of the selection; an Integer between 0 an 63.
268 METHOD:: setSelectionStart (index, frame)
270 Sets the start frame of a selection.
273 The index of the selection; an Integer between 0 an 63.
276 The starting frame of the selection, an Integer.
278 METHOD:: selectionSize
280 The size of a selection.
283 The index of the selection; an Integer between 0 an 63.
288 METHOD:: setSelectionSize
290 Sets the size of a selection.
293 The index of the selection; an Integer between 0 an 63.
296 The size in frames of the selection, an Integer.
298 METHOD:: selectionStartTime
300 The start of a selection in seconds.
303 The index of the selection; an Integer between 0 an 63.
308 METHOD:: selectionDuration
310 The size of a selection in seconds.
313 The index of the selection; an Integer between 0 an 63.
320 Sets a selection to span the whole data range.
323 The index of the selection; an Integer between 0 an 63.
328 Sets the size of a selectino to 0.
331 The index of the selection; an Integer between 0 an 63.
333 METHOD:: setSelectionColor
335 Sets the color of a selection.
338 The index of the selection; an Integer between 0 an 63.
343 METHOD:: setEditableSelectionStart
345 Sets whether the start point of a selection can be edited.
348 The index of the selection; an Integer between 0 an 63.
353 METHOD:: setEditableSelectionSize (index, bool)
355 Whether the end point of a selection can be edited.
358 The index of the selection; an Integer between 0 an 63.
363 METHOD:: readSelection
365 note:: Not in Qt GUI ::
367 Read the data within a selection.
370 The block size - visual resolution of the display. An Integer of the form 2**n.
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.
386 Whether the grid is displayed. Defaults to code::true::.
391 METHOD:: gridResolution
393 The resolution of the grid.
396 An instance of Float.
400 Sets the grid offset.
407 The color of the grid.
412 METHOD:: drawsWaveForm
414 Whether the data is displayed. Defaults to code::true::.
419 METHOD:: timeCursorOn
421 Whether the time cursor is displayed. Defaults to code::false::.
426 METHOD:: timeCursorPosition
428 The position of the time cursor in frames.
433 METHOD:: timeCursorColor
435 The color of the time cursor.
448 The object to be evaluated whenever the user interacts with the view.
452 The object to be evaluated on Ctrl + click.
457 SUBSECTION:: Basic example
461 w = Window.new("soundfile test", Rect(200, 200, 800, 400));
462 a = SoundFileView.new(w, Rect(20,20, 700, 60));
465 f.openRead("sounds/a11wlk01.wav");
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;
477 a.gridResolution = 0.2;
483 SUBSECTION:: Step by step examples
486 ( // make a simple SoundFileView
487 w = Window.new("soundfile test", Rect(10, 700, 750, 100));
489 a = SoundFileView.new(w, Rect(20,20, 700, 60));
492 f.openRead("sounds/a11wlk01.wav");
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.
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:
520 a.zoomToFrac(0.5); // zoom to half file size
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:
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);
555 a.setSelectionColor(1, Color.white);
556 a.setSelectionStart(1, 1234).setSelectionSize(1, 1234 * 2);
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.
565 a.selections.size; // 64 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?
579 ("mouseUp, current selection is now:"
580 + a.selections[a.currentSelection]).postln;
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
606 a.setData(a.data.reverse);
609 a.zoom(0.25); // scrolling is normalized
612 a.scroll(12); // scroll is in viewFrames.