logoBMates

Wave

Wave is a class that visually represents audio waveforms. This class generates waveforms based on audio data and provides drag and selection functionalities.

Related: Node

Properties

name: string

The name of the Wave. The default value is 'Wave'.

x: number

The x-coordinate of the Wave.

y: number

The y-coordinate of the Wave.

width: number

The width of the Wave.

height: number

The height of the Wave.

waveform: Float32Array

Contains the audio waveform data of the Wave.

data: SongDataType

The audio data associated with the Wave.

style: EditorStyleType

Contains the style settings for the Wave.

Constructor

constructor(data: SongDataType, style: EditorStyleType)

data: SongDataType

The audio data associated with the Wave.

style: EditorStyleType

The style settings for the Wave.

Methods

update (dT)

Updates the state of the Wave.

NameTypeDescription
dTnumberDelta time

draw (ctx)

Draws the Wave.

NameTypeDescription
ctxCanvasRenderingContext2DThe rendering context for the drawing surface

setX (x)

Sets the x-coordinate of the Wave.

NameTypeDescription
xnumberThe new x-coordinate of the Wave.

setSelected (selected)

Sets the selection state of the Wave.

NameTypeDescription
selectedbooleanThe selection state of the Wave.

checkCollision (newX)

Checks for collisions with other Waves at the given x-coordinate.

NameTypeDescription
newXnumberThe new x-coordinate to check for collisions.
  • Return: boolean

extractWaveform (buffer)

Extracts waveform data from the given audio buffer.

NameTypeDescription
bufferAudioBufferThe audio buffer to extract waveform data from.
  • Return: Float32Array

Usage Example

const waveData: SongDataType = {
  /* ... */
};
const waveStyle: EditorStyleType = {
  /* ... */
};

const wave = new Wave(waveData, waveStyle);
this.add(wave);
PREVTrackNEXTPlayhead
logoBMates