Commit c545b66e authored by TJ Horner's avatar TJ Horner

Document events

parent b7965a04
This diff is collapsed.
......@@ -39,13 +39,13 @@
</nav>
<div class="content" data-ice="content"><div class="header-notice">
<div data-ice="importPath" class="import-path"><pre class="prettyprint"><code data-ice="importPathCode">import Launchpad from &apos;<span><a href="file/src/index.js.html#lineNumber19">launchpad-mk2</a></span>&apos;</code></pre></div>
<div data-ice="importPath" class="import-path"><pre class="prettyprint"><code data-ice="importPathCode">import Launchpad from &apos;<span><a href="file/src/index.js.html#lineNumber37">launchpad-mk2</a></span>&apos;</code></pre></div>
<span data-ice="access">public</span>
<span data-ice="kind">class</span>
<span data-ice="source">| <span><a href="file/src/index.js.html#lineNumber19">source</a></span></span>
<span data-ice="source">| <span><a href="file/src/index.js.html#lineNumber37">source</a></span></span>
</div>
<div class="self-detail detail">
......@@ -66,6 +66,21 @@
<div class="description" data-ice="description"><p>A Launchpad instance.</p>
<p>This class will emit two events:</p>
<ul>
<li><code>press</code> - Emitted when a button is pressed. Example usage:</li>
</ul>
<pre><code class="lang-js"><code class="source-code prettyprint">myLaunchpad.on(&quot;press&quot;, pressInfo =&gt; {
console.log(pressInfo.button, pressInfo.velocity)
})</code>
</code></pre>
<ul>
<li><code>release</code> - Emitted when a button is released. Example usage:</li>
</ul>
<pre><code class="lang-js"><code class="source-code prettyprint">myLaunchpad.on(&quot;release&quot;, button =&gt; {
console.log(button)
})</code>
</code></pre>
</div>
......@@ -373,7 +388,7 @@ and then send it to the Launchpad.</p>
<span class="right-info">
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber35">source</a></span></span>
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber53">source</a></span></span>
</span>
</h3>
......@@ -461,7 +476,7 @@ and then send it to the Launchpad.</p>
<span class="right-info">
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber42">source</a></span></span>
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber60">source</a></span></span>
</span>
</h3>
......@@ -508,7 +523,7 @@ and then send it to the Launchpad.</p>
<span class="right-info">
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber144">source</a></span></span>
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber179">source</a></span></span>
</span>
</h3>
......@@ -559,7 +574,7 @@ and then send it to the Launchpad.</p>
<span class="right-info">
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber102">source</a></span></span>
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber137">source</a></span></span>
</span>
</h3>
......@@ -649,7 +664,7 @@ button.setRgbColor(10, 30, 10)</code></pre>
<span class="right-info">
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber116">source</a></span></span>
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber151">source</a></span></span>
</span>
</h3>
......@@ -717,7 +732,7 @@ button.setRgbColor(10, 30, 10)</code></pre>
<span class="right-info">
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber132">source</a></span></span>
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber167">source</a></span></span>
</span>
</h3>
......@@ -799,7 +814,7 @@ button.setRgbColor(10, 30, 10)</code></pre>
<span class="right-info">
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber175">source</a></span></span>
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber210">source</a></span></span>
</span>
</h3>
......@@ -888,7 +903,7 @@ button.setRgbColor(10, 30, 10)</code></pre>
<span class="right-info">
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber76">source</a></span></span>
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber111">source</a></span></span>
</span>
</h3>
......@@ -957,7 +972,7 @@ and then send it to the Launchpad.</p>
<span class="right-info">
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber158">source</a></span></span>
<span data-ice="source"><span><a href="file/src/index.js.html#lineNumber193">source</a></span></span>
</span>
</h3>
......
This diff is collapsed.
......@@ -54,6 +54,24 @@ var layouts = {
/**
* A Launchpad instance.
*
* This class will emit two events:
*
* - `press` - Emitted when a button is pressed. Example usage:
*
* ```js
* myLaunchpad.on(&quot;press&quot;, pressInfo =&gt; {
* console.log(pressInfo.button, pressInfo.velocity)
* })
* ```
*
* - `release` - Emitted when a button is released. Example usage:
*
* ```js
* myLaunchpad.on(&quot;release&quot;, button =&gt; {
* console.log(button)
* })
* ```
*
* @class Launchpad
* @extends {EventEmitter}
*/
......@@ -91,8 +109,25 @@ export default class Launchpad extends EventEmitter {
if(message[0] === 176 || message[0] === 144){
// button message
if(message[2] &gt; 0)
this.emit(&quot;press&quot;, this.buttons[message[1]], message[2])
/**
* Fired when a button is pressed.
*
* @event Launchpad#press
* @type {object}
* @property {Button} button The button that was pressed
* @property {Number} velocity The velocity at which the button was pressed
*/
this.emit(&quot;press&quot;, {
button: this.buttons[message[1]],
velocity: message[2]
})
else
/**
* Fired when a button is released.
*
* @event Launchpad#release
* @type {Button}
*/
this.emit(&quot;release&quot;, this.buttons[message[1]])
}
})
......
......@@ -39,6 +39,7 @@
</nav>
<div class="content" data-ice="content"><div data-ice="index" class="github-markdown"><h1 id="launchpad-mk2">launchpad-mk2</h1>
<p><a href="https://tjhorner.com/node-launchpad-mk2/">Documentation</a></p>
<p>A node module for interacting with the Launchpad Pro.</p>
<p>If you&apos;re looking for a module to interact with the original Launchpad or Launchpad S, check <a href="https://www.npmjs.com/package/midi-launchpad">here</a>.</p>
<h1 id="version-2-0-0-has-major-breaking-changes">VERSION 2.0.0 HAS MAJOR BREAKING CHANGES</h1>
......
{
"name": "launchpad-mk2",
"version": "2.0.0",
"version": "2.0.1",
"description": "Node module for interfacing with the Launchpad MK2 and Launchpad Pro",
"repository": "https://github.com/tjhorner/node-launchpad-mk2",
"main": "src/index.js",
......
......@@ -65,9 +65,9 @@
<td data-ice="filePath"><span><a href="file/src/index.js.html">src/index.js</a></span></td>
<td data-ice="identifier" class="identifiers"><span><a href="class/src/index.js~Launchpad.html">Launchpad</a></span></td>
<td class="coverage"><span data-ice="coverage">100 %</span><span data-ice="coverageCount" class="coverage-count">10/10</span></td>
<td style="display: none;" data-ice="size">4744 byte</td>
<td style="display: none;" data-ice="lines">185</td>
<td style="display: none;" data-ice="updated">2017-07-01 07:21:36 (UTC)</td>
<td style="display: none;" data-ice="size">5687 byte</td>
<td style="display: none;" data-ice="lines">220</td>
<td style="display: none;" data-ice="updated">2017-07-01 09:09:31 (UTC)</td>
</tr>
</tbody>
</table>
......
......@@ -13,6 +13,24 @@ var layouts = {
/**
* A Launchpad instance.
*
* This class will emit two events:
*
* - `press` - Emitted when a button is pressed. Example usage:
*
* ```js
* myLaunchpad.on("press", pressInfo => {
* console.log(pressInfo.button, pressInfo.velocity)
* })
* ```
*
* - `release` - Emitted when a button is released. Example usage:
*
* ```js
* myLaunchpad.on("release", button => {
* console.log(button)
* })
* ```
*
* @class Launchpad
* @extends {EventEmitter}
*/
......@@ -50,8 +68,25 @@ export default class Launchpad extends EventEmitter {
if(message[0] === 176 || message[0] === 144){
// button message
if(message[2] > 0)
this.emit("press", this.buttons[message[1]], message[2])
/**
* Fired when a button is pressed.
*
* @event Launchpad#press
* @type {object}
* @property {Button} button The button that was pressed
* @property {Number} velocity The velocity at which the button was pressed
*/
this.emit("press", {
button: this.buttons[message[1]],
velocity: message[2]
})
else
/**
* Fired when a button is released.
*
* @event Launchpad#release
* @type {Button}
*/
this.emit("release", this.buttons[message[1]])
}
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment