SoundFileView:
Filter:
Classes | GUI > Views

SoundFileView

Sound file display
Location: NOT INSTALLED!

Description

A sound file viewer with numerous options.

Zoom in and out using Shift + right-click + mouse-up/down;

Scroll using right-click + mouse-left/right.

Class Methods

Inherited class methods

Instance Methods

Data

.soundfile

Arguments:

An Instance of SoundFile to display.

.read

Reads a section of the -soundfile and displays it in the view. For large files, you may want to use readWithTask instead.

The 'block' argument has no effect; the display resolution is infinite.

Arguments:

startFrame

The beginning of the section, in frames.

frames

The size of the section, in frames.

block

The block size - visual resolution of the display. An Integer of the form 2**n.

closeFile

If true, closes the SoundFile after reading.

doneAction

A Function called when the file reading has completed.

.readFile

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.

The 'block' argument has no effect; the display resolution is infinite.

Arguments:

aSoundFile

An open instance of SoundFile.

startFrame

The beginning of the section, in frames.

frames

The size of the section, in frames.

block

The block size - visual resolution of the display. An Integer of the form 2**n.

closeFile

If true, closes the SoundFile after reading.

doneAction

A Function called when the file reading has completed.

.readWithTask

Reads a section of the -soundfile asynchronously (in the background), updating the -readProgress along the way. If the showProgress argument is true, a SoundFileViewProgressWindow opens to show the progress.

The 'block' argument has no effect; the display resolution is infinite. The 'showProgress' argument has no effect; the view always displays reading progress within itself.

Arguments:

startFrame

The beginning of the section, in frames.

frames

The size of the section, in frames.

block

The block size - visual resolution of the display. An Integer of the form 2**n.

doneAction

An optional function to be evaluated on completion.

showProgress

Whether to open a progress window. Defaults to true.

.readFileWithTask

Reads a section of an open instance of SoundFile asynchronously (in the background), updating the -readProgress along the way. If the showProgress argument is true, a SoundFileViewProgressWindow opens to show the progress.

The 'block' argument has no effect; the display resolution is infinite. The 'showProgress' argument has no effect; the view always displays reading progress within itself.

Arguments:

soundFile

An open instance of SoundFile.

startFrame

The beginning of the section, in frames.

frames

The size of the section, in frames.

block

The block size - visual resolution of the display. An Integer of the form 2**n.

doneAction

An optional function to be evaluated on completion.

showProgress

Whether to open a progress window. Defaults to true.

.data

Sets custom data instead of a sound file. This is a setter only; it is not possible to get the data. If you need access to the data, you must keep it in your own variable.

Setting this property assumes 1 channel and sample rate of 44100 Hz. Use -setData instead if you want more control.

Arguments:

An Array of Floats; multiple channel data should be interleaved.

.setData

Sets custom display data instead of a sound file, interpreting it using specified number of channels and sample rate.

Arguments:

data

An Array of Floats; multiple channel data should be interleaved.

block

The block size - visual resolution of the display. An Integer of the form 2**n. (since the port to QT, the 'block' argument has no effect; the display resolution is infinite).

startFrame

An integer.

channels

An integer.

samplerate

An integer.

.alloc

Allocates a desired amount of display channels and frames; all frames have initial value of 0.

Arguments:

frames

An Integer.

channels

An Integer.

samplerate

An Integer.

.set

Overwrites a range of display data with another data. This method can be used after -alloc or -setData has been called, but not while the view is displaying a sound file.

Arguments:

offset

The frame at which to start overwriting; an Integer.

data

The new data; an Array of Floats; multiple channel data should be interleaved.

.startFrame

The beginning of the read section of the soundfile, or 0 if -alloc or -setData has been used.

.numFrames

The total amount of frames in the view; this is unrelated to zooming and scrolling.

.readProgress

The reading progress, updated periodically when reading a soundfile using -readWithTask or -readFileWithTask.

Navigation

.viewFrames

The amount of currently visible frames in the view.

.zoom

Zooms by a factor relative to current zoom.

Arguments:

A Float.

.zoomToFrac

Zooms to a specific scale.

Arguments:

A Float.

.zoomAllOut

Zooms to the current selection.

.zoomSelection

Zooms to a specific selection.

Arguments:

The index of the selection; an Integer between 0 an 63.

.xZoom

The number of seconds of audio to display in the view. E.g., to zoom out by a factor of 2, view.xZoom = dataDuration / 2. (You are responsible for keeping track of the data duration.)

Returns:

A Float, in seconds of audio displayed.

.yZoom

Vertical scaling. The default yZoom = 1 sets ±1.0 to the top and bottom of the view. If yZoom = 2, the view covers ±0.5 of the value range.

Returns:

A Float scaling factor.

.yOffset

Vertical offset. The default yOffset = 0 sets value of 0.0 in the middle of the channel's view, while yOffset = 1, sets 0.0 at the top and yOffset = -1 sets 0.0 at the bottom of the view. This is performed after (and thus is not scaled by) the -yZoom factor.

Returns:

A Float offset.

.spacing

A ratio between vertical space outside of the ±1.0 value range and channel's full height. The default spacing = 0.1 makes top and bottom spaces add up to 0.1 * height (each of them occupying half of that), while ±1.0 value range occupies 0.9 * height. The value is clipped in the range from 0.0 to 1.0.

Returns:

A Float scaling factor.

.scrollPos

The scrolling position of the view, as a fraction of the total scrolling range. The total scrolling range is totalDuration - xZoom.

Returns:

A Float in the range of 0.0 to 1.0.

.scrollTo

Scrolls to a fraction of the total scrolling range. The total scrolling range is totalDuration - xZoom.

Arguments:

A Float in the range of 0.0 to 1.0.

.scroll

Scrolls by a fraction of the visible range.

Arguments:

A Float.

.scrollToStart

Scrolls to the beginning.

.scrollToEnd

Scrolls to the end.

Selection

.selections

All the selections.

Returns:

An array of 64 arrays of start frames and sizes: [ [ start0, size0 ] , [ start1, size1 ], ... ].

.selection

The selection at index.

Returns:

An Array of the form [start, size], where start and size denote frames.

.setSelection

Sets the selection at index.

Arguments:

index

An Integer between 0 an 63.

selection

An Array of the form [start, size], where start and size are Integers and denote frames.

.currentSelection

The index of the current selection

Arguments:

An integer between 0 an 63.

.selectionStart

The start frame of a selection.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

Returns:

An Integer.

.setSelectionStart

Sets the start frame of a selection.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

frame

The starting frame of the selection, an Integer.

.selectionSize

The size of a selection.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

Returns:

An Integer.

.setSelectionSize

Sets the size of a selection.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

frames

The size in frames of the selection, an Integer.

.selectionStartTime

The start of a selection in seconds.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

Returns:

A Float.

.selectionDuration

The size of a selection in seconds.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

Returns:

A Float.

.selectAll

Sets a selection to span the whole data range.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

.selectNone

Sets the size of a selection to 0.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

.setSelectionColor

Sets the color of a selection.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

color

A Color.

.setEditableSelectionStart

Sets whether the start point of a selection can be edited.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

editable

A Boolean.

.setEditableSelectionSize

Whether the end point of a selection can be edited.

Arguments:

index

The index of the selection; an Integer between 0 an 63.

editable

A Boolean.

.readSelection

NOTE: Not implemented

Read the data within a selection.

Arguments:

block

The block size - visual resolution of the display. An Integer of the form 2**n.

closeFile

If true, closes the SoundFile after reading.

.readSelectionWithTask

NOTE: Not implemented

Read the data within the current selection asynchronously (in the background), showing the progress in a separate window.

Display

.peakColor

The color of the peak-to-peak data. This can be overridden by -waveColors. Defaults to Color(0.95, 0.7).

Arguments:

A Color.

.rmsColor

The color of the RMS data. Defaults to Color(1.0, 1.0).

Arguments:

A Color.

.waveColors

An array of colors for the peak-to-peak data for each channel, allowing each channel to be represented by a different color. Defaults to [ ]. Once set, it overrides -peakColor. In order to revert to using .peakColor, set .waveColors back to an empty array: .waveColors_([]).

NOTE: -rmsColor stays the same for all channels. However, using alpha blending, it is possible to display RMS data using either a lighter (e.g. .rmsColor_(Color.grey(1, 0.3))) or a darker (e.g. .rmsColor_(Color.grey(0, 0.3))) shade of the peak-to-peak color.

Arguments:

And array of [Color].

.gridOn

Whether the grid is displayed. Defaults to true.

Arguments:

A Boolean.

.gridResolution

The resolution of the grid.

Arguments:

An instance of Float.

.gridOffset

Sets the grid offset.

Arguments:

Grid blocks are offset by this value (in seconds).

.gridColor

The color of the grid.

Arguments:

A Color.

.drawsWaveForm

Whether the data is displayed. Defaults to true.

Arguments:

A Boolean.

.drawsRMS

Whether the RMS data for the waveform is displayed. Defaults to true.

.drawsCenterLine

Whether the center line (at value 0.0) is displayed. Defaults to true.

Arguments:

A Boolean.

.drawsBoundingLines

Whether the bounding lines (at values ±1.0) are displayed. Defaults to true.

Arguments:

A Boolean.

.timeCursorOn

Whether the time cursor is displayed. Defaults to false.

Arguments:

A Boolean.

.timeCursorPosition

The position of the time cursor in frames.

Arguments:

An Integer.

.timeCursorColor

The color of the time cursor.

Arguments:

A Color.

.elasticMode

Not operational, for compatibility only.

Actions

.action

The object to be evaluated whenever the user interacts with the view.

.metaAction

The object to be evaluated on Ctrl + click.

Inherited instance methods

Examples

Basic example

Step by step examples

Adding a scroll bar

Zooming and scrolling by mouse, directly in a SoundFileView, may not be immediately intuitive. (Most users wouldn't guess to shift-right-click!) You can add a RangeSlider to act as a scrollbar.

Notes: