class Buffer

Bind to a Max buffer~ object.

The Buffer object in JavaScript is a companion to the buffer~ object in Max. Through it, you can to access samples and metadata for the buffer~ object with the given name.

Constructors

new Buffer(name: string);

Constructs a new instance of the Buffer class

ParameterTypeDescription
namestringname of the Max buffer~ to bind to.

Methods

channelcount

Buffer channel count

channelcount(): number;
NameTypeDescription
Return ValuenumberThe number of channels in the buffer~ object.

framecount

Buffer frame count

Return the number of frames (samples in a single channel) in the buffer~ object.

framecount(): number;
NameTypeDescription
Return ValuenumberThe number of frames in the buffer~ object.

freepeer

Free the native C peer

Frees the buffer~ data from the native C peer (created when making a object), which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based JS allocated memory. Once called, the object is not available for any other use. It's not necessary to call this function, as the memory will be freed eventually, but you can call it whenever you're done with your object.

freepeer(): void;

length

Length of the buffer in milliseconds

length(): number;
NameTypeDescription
Return Valuenumber

peek

Fetch an array of samples from the buffer

peek(channel: number, frame: number, count: number): number[];
NameTypeDescription
channelnumberchannel to fetch samples from (indexed from 1)
framenumberframe at which to start fetching samples (indexed from 0)
countnumbernumber of samples to fetch
Return Valuenumber[]

poke

Write samples into the buffer

It is more efficient to call this function once with an array, than to call it mulpitle times, each time with a single sample.

poke(channel: number, frame: number, samples: number | number[]): void;
NameTypeDescription
channelnumberchannel to write samples to (indexed from 1)
framenumberframe at which to start writing samples (indexed from 0)
samplesnumber | number[]samples to write (or a single sample to write)

send

Send a message to the buffer.

Can send any message that buffer~ understands. See buffer~ reference.

send(message: string, ...args: any[]): void;
NameTypeDescription
messagestringthe name of message
argsany[]arguments that follow the name of the message