noteplayer
Version:
WebAudio musical audio note player
114 lines (77 loc) • 4.74 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Home</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Home</h1>
<h3>noteplayer 1.2.1</h3>
<section>
<article><h1>NOTEPLAYER.JS</h1><h2>Installation:</h2><p>You may import the code into an existing node.js project or import it directly into your HTML code</p>
<ul>
<li>Node module import<pre class="prettyprint source lang-shell"><code># local install to your project
npm install --save-dev noteplayer</code></pre><pre class="prettyprint source lang-javascript"><code>// import module into your js code
var np = require('noteplayer')</code></pre></li>
<li>plain JS import<pre class="prettyprint source lang-html"><code><!-- minified version, not human friendly, 55kb-->
<script type="text/javascript" src="notePlayer.min.js"></script>
<!-- uncompressed version, human friendly, 416kb -->
<script type="text/javascript" src="notePlayer.js"></script></code></pre>The module is instanciated in the object np, which you can use right away<pre class="prettyprint source lang-javascript"><code>np.buildFromName("C4").play()</code></pre></li>
</ul>
<h2>Constructors</h2><p>There are several ways to instanciate the class:</p>
<ul>
<li><p><code>buildFromFrequency(freq,[audioContext])</code></p>
<p>Builds a notePlayer from a specific frequence.
audioContext is created if not provided.</p>
<pre class="prettyprint source lang-javascript"><code>n = np.buildFromFrequency(440); //will return a A4
n = np.buildFromFrequency(439); //will return a A4
n = np.buildFromFrequency(460); //will return a A#4</code></pre></li>
<li><p><code>buildFromKeyNb(noteKeyNb, [audioContext])</code></p>
<p>Builds a notePlayer from a specific piano key number
audioContext is created if not provided</p>
<pre class="prettyprint source lang-javascript"><code>n = np.buildFromKeyNb(49); //will return a A4</code></pre></li>
<li><p><code>buildFromName(noteName, [audioContext])</code></p>
<p>Builds a notePlayer from a specific musical note name
audioContext is created if not provided</p>
<pre class="prettyprint source lang-javascript"><code>n = np.buildFromName("A4") //will return a A4</code></pre><h2>Methods</h2></li>
<li><p><code>play([callback])</code></p>
<p>Plays the note</p>
<pre class="prettyprint source lang-javascript"><code>n = np.buildFromName("A4")
o = n.play(function(){
console.log("end play")
})</code></pre><p>The note will be played for a given duration (random by default, or using setDuration() ).
The function however returns the oscillator itself, which you can use to call for stop() should you want to stop the sound at an earlier time (courtesy of <a href="https://github.com/jag82">Jag</a>)</p>
</li>
<li><p>Setters: </p>
<ul>
<li><code>setAudioContext(audioContext)</code></li>
<li><code>setDestinationNode(node)</code></li>
<li><code>setDuration(duration)</code></li>
<li><code>setVolume(volume)</code></li>
<li><code>setVerbose(bool)</code></li>
<li><code>setAttack(duration)</code></li>
<li><code>setRelease(duration)</code></li>
</ul>
</li>
</ul></article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="notePlayer.html">notePlayer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#buildFromFrequency">buildFromFrequency</a></li><li><a href="global.html#buildFromKeyNb">buildFromKeyNb</a></li><li><a href="global.html#buildFromName">buildFromName</a></li><li><a href="global.html#play">play</a></li><li><a href="global.html#setAttack">setAttack</a></li><li><a href="global.html#setAudioContext">setAudioContext</a></li><li><a href="global.html#setDestinationNode">setDestinationNode</a></li><li><a href="global.html#setDuration">setDuration</a></li><li><a href="global.html#setRelease">setRelease</a></li><li><a href="global.html#setVerbose">setVerbose</a></li><li><a href="global.html#setVolume">setVolume</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Fri Dec 02 2016 10:02:02 GMT+0000 (GMT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>