<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="_c74_vig.xsl" type="text/xsl"?>
<vignette name="The Buffer Object" package="Max" rankfactor="2"><h1>
		The Buffer Object
	</h1><p>
		The Buffer object in JavaScript is a companion to the <o>buffer~</o> object you instantiate in Max patchers,
		and provides the ability to access samples and metadata for the <o>buffer~</o> object with the associated name.
	</p><h2>
		Buffer Constructor
	</h2><code language="javascript">
		var buf = new Buffer("name");
	</code><p>
		The name is required at the time the object is created.
	</p><br/>
	The following methods relate to the functionality from the Max <o>buffer~</o>, <o>info~</o>, <o>peak~</o>, and <o>poke~</o>, objects. Please see the references for those objects for details.
	<jsmethod_list name="Buffer">
		<jsmethod name="channelcount">
			<arglist></arglist>
			<description>
				Return the number of channels in the <o>buffer~</o> object.
			</description>
		</jsmethod>
		<jsmethod name="framecount">
			<description>
				Return the number of frames (samples in a single channel) in the <o>buffer~</o> object.
			</description>
		</jsmethod>
		<jsmethod name="freepeer">
			<description>
				Frees the <o>buffer~</o> data from the native c peer, which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based on JS allocated memory. Once called, the <o>buffer~</o> object is not available for any other use.
			</description>
		</jsmethod>
		<jsmethod name="length">
			<description>
				Return the length of the <o>buffer~</o> object in milliseconds.
			</description>
		</jsmethod>
		<jsmethod name="peek">
			<arglist>
				<arg name="channel" type="int"/><arg name="frame" type="int"/><arg name="count" type="int"/>
			</arglist>
			<description>
				Return an array with <m>count</m> samples from <m>channel</m> (1-based counting)
				starting at <m>frame</m> (zero-based counting).
			</description>
		</jsmethod>
		<jsmethod name="poke">
			<arglist>
				<arg name="channel" type="int"/><arg name="frame" type="int"/><arg name="samples" type="float/array"/>
			</arglist>
			<description>
				Write into the <o>buffer~</o> object at <m>channel</m> (1-based counting) and <m>frame</m> (0-based counting).
				Samples may be a single sample value or an array of sample values. It is computationally more efficient to use an array).
			</description>
		</jsmethod>
		<jsmethod name="send">
			<arglist>
				<arg name="message-name" type="string"/><arg name="arguments" type="anything"/>
			</arglist>
			<description>
				Send a message to the associated <o>buffer~</o> object. Can send any message that buffer~ understands.
			</description>
		</jsmethod>
	</jsmethod_list>
	<h2>
		Examples
	</h2>

	<p>
		Example code can be found in the "js" tab of the <o>buffer~</o> help patcher.
	</p>
</vignette>
