### Install Dependencies and Run Electron App Source: https://github.com/djipco/webmidi/blob/master/examples/electron/basic-example/README.md Use these commands to install project dependencies and start the Electron application. ```bash npm install ``` ```bash npm start ``` -------------------------------- ### Install Dependencies and Run Next.js App Source: https://github.com/djipco/webmidi/blob/master/examples/next.js/basic-example/README.md Use these commands to install project dependencies and start the development server for a Next.js application. ```bash npm install ``` ```bash npm run dev ``` -------------------------------- ### Idiomatic MIDI Output Usage in v3 Source: https://github.com/djipco/webmidi/blob/master/website/docs/migration/migration.md An example demonstrating idiomatic v3 usage: getting an output by name, accessing a specific channel (channel 10), and playing a note. This showcases the streamlined approach for common tasks. ```javascript const output = WebMidi.getOutputByName("My Awesome Midi Device"); const synth = output.channels[10]; synth.playNote("A4"); ``` -------------------------------- ### Start Local Development Server Source: https://github.com/djipco/webmidi/blob/master/website/README.md Starts a local development server that automatically refreshes the browser on code changes. Opens the site in a browser window. ```bash yarn start ``` -------------------------------- ### Install WEBMIDI.js with NPM Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/installation.md Use this command to install WEBMIDI.js in your project via NPM. Node.js must be installed on your system. This is the recommended approach for easier management. ```shell npm install webmidi ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/djipco/webmidi/blob/master/website/README.md Installs all necessary dependencies for the project using Yarn. ```bash yarn install ``` -------------------------------- ### Start Event Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Input.md Emitted when a start message is received, typically indicating the beginning of playback. ```APIDOC ## Event: start ### Description Input-wide (system) event emitted when a **start** message has been received. **Since**: 2.1 ### Event Properties | Property | Type | Description | |---|---|---| | **`port`** | Input | The `Input` that triggered the event. | | **`target`** | Input | The object that dispatched the event. | | **`message`** | Message | A [`Message`](Message) object containing information about the incoming MIDI message. | | **`timestamp`** | number | The moment (DOMHighResTimeStamp) when the event occurred (in milliseconds since the navigation start of the document). | | **`type`** | string | `start` | ``` -------------------------------- ### Send Start Message Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Output.md Sends a MIDI start real-time message. This message starts the playback of the current song at beat 0. ```APIDOC ## .sendStart(...) ### Description Sends a **start** real-time message. A MIDI Start message starts the playback of the current song at beat 0. To start playback elsewhere in the song, use the [`sendContinue()`](#sendContinue) method. ### Method POST ### Endpoint /djipco/webmidi ### Parameters #### Query Parameters - **options** (object) - Optional - Options for the message. - **options.time** (number | string) - Optional - If `time` is a string prefixed with `"+"` and followed by a number, the message will be delayed by that many milliseconds. If the value is a positive number, the operation will be scheduled for that time. Defaults to 'now'. ### Request Example ```json { "options": { "time": "+500" } } ``` ### Response #### Success Response (200) - **Output** (object) - The Output object so methods can be chained. #### Response Example ```json { "message": "Start message sent successfully." } ``` ``` -------------------------------- ### Enable WebMidi using Promise Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/WebMidi.md This example demonstrates how to enable WebMidi.js and execute code once it's ready by utilizing the returned Promise. Ensure your page is hosted on a secure origin (https://, localhost, or file:///) as required by modern browsers for Web MIDI API access. ```javascript WebMidi.enable().then(() => { console.log("WebMidi.js has been enabled!") }) ``` -------------------------------- ### Retrieve MIDI Output by ID, Name, or Index Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/basics.md Demonstrates multiple ways to get a reference to a MIDI output device: by its unique ID, its name, or its index in the `WebMidi.outputs` array. Note that IDs can vary across platforms. ```javascript let output1 = WebMidi.getOutputById("123456789"); let output2 = WebMidi.getOutputByName("Axiom Pro 25 Ext Out"); let output3 = WebMidi.outputs[0]; ``` -------------------------------- ### Input Methods Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Input.md Details on methods for managing MIDI inputs, including adding listeners, closing, destroying, emitting events, and getting listener counts. ```APIDOC ## .add(listener, options) ### Description Registers a new listener for MIDI events. ### Method `add` ### Parameters #### Path Parameters - **listener** (function) - Required - A callback function to execute when the specified event is detected. This function will receive an event parameter object. #### Query Parameters - **options** (object) - Optional - Configuration options for the listener. - **options.arguments** (array) - Optional - An array of arguments which will be passed separately to the callback function. - **options.channels** (number|Array) - Optional - An integer between 1 and 16 or an array of such integers representing the MIDI channel(s) to listen on. Ignored for input-wide events. - **options.context** (object) - Optional - The value of `this` in the callback function. - **options.duration** (number) - Optional - The number of milliseconds before the listener automatically expires. - **options.prepend** (boolean) - Optional - Whether the listener should be added at the beginning of the listeners array. ### Return Value > Returns: `Array.` An array of all `Listener` objects that were created. ## .close() {#close} ### Description Closes the input. When an input is closed, it cannot be used to listen to MIDI messages until the input is opened again by calling `Input.open()`. ### Method `close` ### Attributes `async` ### Return Value > Returns: `Promise.` The promise is fulfilled with the `Input` object. ### Note If the goal is to stop events from being dispatched, use `eventsSuspended` instead. ## .destroy() {#destroy} ### Description Destroys the `Input` by removing all listeners, emptying the `channels` array and unlinking the MIDI subsystem. ### Method `destroy` ### Attributes `async` ### Return Value > Returns: `Promise.` ## .emit(...) {#emit} ### Description Executes the callback function of all the `Listener` objects registered for a given event. The callback functions are passed the additional arguments passed to `emit()` (if any) followed by the arguments present in the `Listener.arguments` property (if any). ### Method `emit` ### Parameters > Signature: `emit(event, ...args)` #### Path Parameters - **event** (string) - Required - The event. - **args** (*) - Optional - Arbitrary number of arguments to pass along to the callback functions. ### Return Value > Returns: `Array` An array containing the return value of each of the executed listener functions. ### Throws - `TypeError` : The `event` parameter must be a string. ### Note If `eventsSuspended` or `Listener.suspended` is `true`, the callback functions will not be executed. Regular listeners are triggered first, followed by global listeners. ## .getListenerCount(...) {#getListenerCount} ### Description Returns the number of listeners registered for a specific event. ### Method `getListenerCount` ### Parameters > Signature: `getListenerCount(event)` #### Path Parameters - **event** (string|Symbol) - Required - The event, which is usually a string but can also be the special `EventEmitter.ANY_EVENT` symbol. ### Return Value > Returns: `number` An integer representing the number of listeners registered for the specified event. ### Note Global events (those added with `EventEmitter.ANY_EVENT`) do not count towards the remaining number for a "regular" event. To get the number of global listeners, specifically use `EventEmitter.ANY_EVENT` as the parameter. ``` -------------------------------- ### Listen for Note On Messages on All Channels Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/basics.md Add a listener to a MIDI input object to react to 'noteon' messages. This example logs the identifier of the note that was played. ```javascript const myInput = WebMidi.getInputByName("MPK mini 3"); myInput.addListener("noteon", e => { console.log(e.note.identifier); }) ``` -------------------------------- ### Get MIDI Output by Name Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/basics.md Obtain a reference to a MIDI output device by its name. This is necessary before sending any MIDI messages to the device. ```javascript const myOutput = WebMidi.getOutputByName("SP-404MKII"); ``` -------------------------------- ### Get Input by Name Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/WebMidi.md Retrieves the first MIDI input whose name contains the specified string. Port names can vary across different environments. ```APIDOC ## GET /api/inputs?name={name} ### Description Returns the first Input object whose name contains the specified string. Port names can vary across environments. ### Method GET ### Endpoint `/api/inputs` ### Parameters #### Query Parameters - **name** (string) - Required - The non-empty string to look for within the name of MIDI inputs. - **disconnected** (boolean) - Optional - Whether to retrieve a disconnected input. ### Response #### Success Response (200) - **Input** (object) - The Input object that was found or undefined if no input contained the specified name. #### Response Example ```json { "id": "another-input-id", "name": "Some MIDI Input Device", "manufacturer": "Another Manufacturer", "version": "1.1" } ``` ### Throws - **Error**: WebMidi is not enabled. ``` -------------------------------- ### Enable WebMidi Library Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/basics.md Call `WebMidi.enable()` to initialize the library. This method returns a promise that resolves when the library is ready. Handle potential errors with `.catch()`. ```javascript WebMidi .enable() .then(() => console.log("WebMidi enabled!")) .catch(err => alert(err)); ``` -------------------------------- ### Get Input by ID Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/WebMidi.md Retrieves a MIDI input by its unique string ID. IDs are specific to the environment and browser. ```APIDOC ## GET /api/inputs/{id} ### Description Returns the Input object that matches the specified ID string or false if no matching input is found. IDs are strings and can change between environments. ### Method GET ### Endpoint `/api/inputs/{id}` ### Parameters #### Path Parameters - **id** (string) - Required - The ID string of the input. IDs can be viewed in the `WebMidi.inputs` array. #### Query Parameters - **disconnected** (boolean) - Optional - Whether to retrieve a disconnected input. ### Response #### Success Response (200) - **Input** (object) - An Input object matching the specified ID string or undefined if no matching input is found. #### Response Example ```json { "id": "some-input-id", "name": "Some MIDI Input", "manufacturer": "Some Manufacturer", "version": "1.0" } ``` ### Throws - **Error**: WebMidi is not enabled. ``` -------------------------------- ### Enable WebMidi.js and Handle Initialization Source: https://github.com/djipco/webmidi/blob/master/examples/quick-start/index.html Enable WebMidi.js and trigger the onEnabled() function when ready. Handles cases where no MIDI devices are detected. ```javascript WebMidi.enable() .then(onEnabled) .catch(err => alert(err)); function onEnabled() { if (WebMidi.inputs.length < 1) { document.body.innerHTML+= "No device detected."; } else { WebMidi.inputs.forEach((device, index) => { document.body.innerHTML+= `${index}: ${device.name}
`; }); } const mySynth = WebMidi.inputs[0]; // const mySynth = WebMidi.getInputByName("TYPE NAME HERE!") mySynth.channels[1].addListener("noteon", e => { document.body.innerHTML+= `${e.note.name}
`; }); } ``` -------------------------------- ### open Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Input.md Asynchronously opens the MIDI input port for usage. This is typically handled automatically when WebMidi is enabled. ```APIDOC ## POST /api/webmidi/open ### Description Opens the input for usage. This is usually unnecessary as the port is opened automatically when WebMidi is enabled. ### Method POST ### Endpoint `/api/webmidi/open ### Response #### Success Response (200) - **input** (Input) - The opened [`Input`](Input) object. #### Response Example ```json { "input": { "name": "My MIDI Device" } } ``` ``` -------------------------------- ### Handle MIDI Permissions in Electron Main Process Source: https://github.com/djipco/webmidi/blob/master/examples/electron/README.md Set permission handlers in the Electron main process before initializing WEBMIDI.js to allow MIDI and MIDI sysex access. ```javascript mainWindow.webContents.session.setPermissionRequestHandler((webContents, permission, callback, details) => { if (permission === 'midi' || permission === 'midiSysex') { callback(true); } else { callback(false); } }) mainWindow.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin) => { if (permission === 'midi' || permission === 'midiSysex') { return true; } return false; }); ``` -------------------------------- ### Get Listeners Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Output.md Returns an array of all [`Listener`](Listener) objects registered for a specific event. Global events are not returned for regular events. ```APIDOC ## .getListeners(...) ### Description Returns an array of all the [`Listener`](Listener) objects that have been registered for a specific event. Please note that global events (those added with [`EventEmitter.ANY_EVENT`](EventEmitter#ANY_EVENT)) are not returned for "regular" events. To get the list of global listeners, specifically use [`EventEmitter.ANY_EVENT`](EventEmitter#ANY_EVENT) as the parameter. ### Method `getListeners` ### Parameters #### Path Parameters - **event** (string | Symbol) - Required - The event to get listeners for. ### Response #### Success Response (200) - **Array.** - An array of [`Listener`](Listener) objects. ``` -------------------------------- ### toTimestamp Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Utilities.md Generates a timestamp relative to the document's navigation start. It can parse numeric timestamps or string-based relative times (e.g., '+2000'). ```APIDOC ## .toTimestamp(...) ### Description Returns a valid timestamp, relative to the navigation start of the document, derived from the `time` parameter. If the parameter is a string starting with the "+" sign and followed by a number, the resulting timestamp will be the sum of the current timestamp plus that number. If the parameter is a positive number, it will be returned as is. Otherwise, false will be returned. ### Method static ### Endpoint N/A (This is a static method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **number or false** - A positive number or `false` (if the time cannot be converted). #### Response Example ```json 1678886400000 ``` ### Throws N/A ``` -------------------------------- ### Enable WebMidi.js using Promises Source: https://github.com/djipco/webmidi/blob/master/website/docs/migration/migration.md Demonstrates the promise-based approach to enabling WebMidi.js. The `.then()` block executes once WebMidi.js has been successfully initialized. ```javascript WebMidi.enable().then(() => { console.log("WebMidi.js has been enabled!"); }) ``` -------------------------------- ### Sending Universal System Exclusive Messages Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Output.md This section explains how to send universal system exclusive messages, including examples and parameter details. ```APIDOC ## POST /api/webmidi/sysex ### Description Sends a universal system exclusive message. ### Method POST ### Endpoint `/api/webmidi/sysex` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **identification** (number | Array) - Required - An unsigned integer or an array of three unsigned integers between 0 and 127 that either identify the manufacturer or sets the message to be a universal non-commercial message (0x7D), a universal non-realtime message (0x7E) or a universal realtime message (0x7F). - **data** (Array | Uint8Array) - Optional - A Uint8Array or an array of unsigned integers between 0 and 127. This is the data you wish to transfer. - **options** (object) - Optional - An object for additional options. - **options.time** (number | string) - Optional - Specifies the time to send the message. Can be a DOMHighResTimeStamp, a string prefixed with '+' followed by milliseconds, or omitted for immediate sending. ### Request Example ```json { "identification": 126, "data": [127, 6, 1] } ``` ### Response #### Success Response (200) - **Output** (object) - The Output object, allowing for method chaining. #### Response Example ```json { "message": "Sysex message sent successfully" } ``` #### Errors - **DOMException**: Failed to execute 'send' on 'MIDIOutput': System exclusive message is not allowed. - **TypeError**: Failed to execute 'send' on 'MIDIOutput': The value at index x is greater than 0xFF. ``` -------------------------------- ### Deploy Website to GitHub Pages Source: https://github.com/djipco/webmidi/blob/master/website/README.md Builds the website and deploys it to the 'gh-pages' branch, suitable for GitHub Pages hosting. Requires setting your GitHub username. ```bash GIT_USER= USE_SSH=true yarn deploy ``` -------------------------------- ### Note Constructor Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Note.md Creates a Note object with a specified value and optional playback properties. ```APIDOC ## Note Constructor Creates a `Note` object. ### Method `new Note(value, [options])` ### Parameters #### Path Parameters - **value** (string | number) - Required - The value used to create the note. If an identifier string is used, it must start with the note letter, optionally followed by an accidental and followed by the octave number (`"C3"`, `"G#4"`, `"F-1"`, `"Db7"`, etc.). If a number is used, it must be an integer between 0 and 127. In this case, middle C is considered to be C4 (note number 60). - **options** (object) - Optional - An object to configure the note's playback properties. - **options.duration** (number) - Optional - The number of milliseconds before the note should be explicitly stopped. Defaults to `Infinity`. - **options.attack** (number) - Optional - The note's attack velocity as a float between 0 and 1. Defaults to `0.5`. - **options.release** (number) - Optional - The note's release velocity as a float between 0 and 1. Defaults to `0.5`. - **options.rawAttack** (number) - Optional - The note's attack velocity as an integer between 0 and 127. Defaults to `64`. - **options.rawRelease** (number) - Optional - The note's release velocity as an integer between 0 and 127. Defaults to `64`. ### Throws - `Error`: Invalid note identifier - `RangeError`: Invalid name value - `RangeError`: Invalid accidental value - `RangeError`: Invalid octave value - `RangeError`: Invalid duration value - `RangeError`: Invalid attack value - `RangeError`: Invalid release value ``` -------------------------------- ### Build Static Website Content Source: https://github.com/djipco/webmidi/blob/master/website/README.md Generates the static content for the website, typically placed in the 'build' directory, ready for hosting. ```bash yarn build ``` -------------------------------- ### Get MIDI Input by Name Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/basics.md Retrieve a reference to a specific MIDI input device using its name. This is useful for targeting a particular hardware or software input. ```javascript const myInput = WebMidi.getInputByName("MPK mini 3"); ``` -------------------------------- ### sendSongPosition Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Output.md Sends a song position MIDI message. The value is expressed in MIDI beats (between `0` and `16383`) which are 16th note. Position `0` is always the start of the song. ```APIDOC ## sendSongPosition ### Description Sends a song position MIDI message. The value is expressed in MIDI beats (between `0` and `16383`) which are 16th note. Position `0` is always the start of the song. ### Method `sendSongPosition([value], [options])` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **value** (number) - Optional - The MIDI beat to cue to (integer between `0` and `16383`). Defaults to `0`. - **options** (object) - Optional - An object for additional options. - **options.time** (number | string) - Optional - If `time` is a string prefixed with `"+"` and followed by a number, the message will be delayed by that many milliseconds. If the value is a positive number, the operation will be scheduled for that time. The current time can be retrieved with `WebMidi.time`. If `options.time` is omitted, or in the past, the operation will be carried out as soon as possible. Defaults to `(now)`. ### Request Example ```json { "value": 1000, "options": { "time": "+500" } } ``` ### Response #### Success Response (200) - **Output** (object) - The Output object so methods can be chained. #### Response Example ```json { "message": "Song position sent successfully" } ``` ``` -------------------------------- ### Basic HTML Structure for WebMidi.js Source: https://github.com/djipco/webmidi/blob/master/website/docs/index.md Include this HTML structure and link to the WebMidi.js library to set up your page. ```html WebMidi.js Quick Start

WebMidi.js Quick Start

``` -------------------------------- ### WebMidi.enable() Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/WebMidi.md Checks for Web MIDI API availability and attempts to connect to the host's MIDI subsystem. This is an asynchronous operation that may display a security prompt to the user. ```APIDOC ## POST /enable ### Description Checks if the Web MIDI API is available and attempts to connect to the host's MIDI subsystem. This is an asynchronous operation that may display a security prompt to the user. ### Method POST ### Endpoint /enable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (object) - Optional - Configuration options for enabling WebMIDI. - **options.callback** (function) - Optional - A function to execute once the operation completes. Receives an Error object if enabling failed. - **options.sysex** (boolean) - Optional - Defaults to `false`. Whether to enable MIDI system exclusive messages. - **options.validation** (boolean) - Optional - Defaults to `true`. Whether to enable library-wide validation of method arguments and setter values. - **options.software** (boolean) - Optional - Defaults to `false`. Whether to request access to software synthesizers on the host system. - **options.requestMIDIAccessFunction** (function) - Optional - A custom function to use to return the MIDIAccess object. ### Request Example ```json { "options": { "sysex": true, "callback": "function(err) { console.log(err); }" } } ``` ### Response #### Success Response (200) - **Promise.** - The promise is fulfilled with the `WebMidi` object for chainability. #### Response Example ```json // Promise resolves with WebMidi object WebMidi.enable().then(webmidi => { console.log("WebMidi enabled", webmidi); }); ``` ### Throws - **Error** - The Web MIDI API is not supported in your environment. - **Error** - Jazz-Plugin must be installed to use WebMIDIAPIShim. ``` -------------------------------- ### Include WEBMIDI.js IIFE in HTML Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/installation.md For the IIFE (Immediately Invoked Function Expression) flavor, include this script tag in your HTML page, pointing to the installed library in your node_modules folder. ```html ``` -------------------------------- ### Send Manufacturer-Specific Sysex Message (Decimal ID) Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Output.md Equivalent to the hex ID example, this demonstrates sending a manufacturer-specific sysex message using decimal notation for the manufacturer ID. ```javascript WebMidi.outputs[0].sendSysex(66, [1, 2, 3, 4, 5]); ``` -------------------------------- ### Enable WebMidi with Sysex Support Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/basics.md To use MIDI system exclusive messages, enable the library with the `sysex: true` option. This ensures that sysex messages can be processed. ```javascript WebMidi .enable({sysex: true}) .then(() => console.log("WebMidi with sysex enabled!")) .catch(err => alert(err)); ``` -------------------------------- ### Send Pitch Bend Message on a Specific Channel Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/basics.md Send a pitch bend message to a specific MIDI channel of an output device. This example demonstrates sending a pitch bend value of -0.5 on channel 11. ```javascript const myOutput = WebMidi.getOutputByName("SP-404MKII"); const vocoder = myOutput.channels[11]; vocoder.sendPitchBend(-0.5); ``` -------------------------------- ### Listen to Note On Event Directly on InputChannel (v3 Idiomatic) Source: https://github.com/djipco/webmidi/blob/master/website/docs/migration/migration.md The most idiomatic v3 approach for listening to a 'noteon' event on MIDI channel 7 of the first input. This utilizes the dedicated InputChannel object for single-channel operations. ```javascript WebMidi.inputs[0].channels[7].addListener("noteon", someFunction); ``` -------------------------------- ### Utilities.buildNote() Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Utilities.md Converts various inputs into a valid Note object. ```APIDOC ## Utilities.buildNote() ### Description Converts the `input` parameter to a valid [`Note`](Note) object. The input usually is an unsigned integer (0-127) or a note identifier (`"C4"`, `"G#5"`, etc.). If the input is a [`Note`](Note) object, it will be returned as is. If the input is a note number or identifier, it is possible to specify options by providing the `options` parameter. ### Method static ### Endpoint N/A (static method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **`input`** (number | string | Note) - Optional - The input to convert to a Note object. - **`options`** (object) - Optional - Options for building the note. - **`options.duration`** (number) - Optional - The number of milliseconds before the note should be explicitly stopped. Defaults to `Infinity`. - **`options.attack`** (number) - Optional - The note's attack velocity as a float between 0 and 1. Defaults to `0.5`. - **`options.release`** (number) - Optional - The note's release velocity as a float between 0 and 1. Defaults to `0.5`. - **`options.rawAttack`** (number) - Optional - The note's attack velocity as an integer between 0 and 127. Defaults to `64`. - **`options.rawRelease`** (number) - Optional - The note's release velocity as an integer between 0 and 127. Defaults to `64`. - **`options.octaveOffset`** (number) - Optional - An integer to offset the octave by. This is only used when the input value is a note identifier. Defaults to `0`. ### Request Example ```json { "example": "Utilities.buildNote('C4', { octaveOffset: 1, duration: 1000 })" } ``` ### Response #### Success Response (200) - **Note** (Note) - The constructed Note object. #### Response Example ```json { "example": "Note object representing C5 with a duration of 1000ms" } ``` ### Throws - TypeError: The input could not be parsed to a note. ``` -------------------------------- ### Play a note using a Note object Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/basics.md Create a `Note` object and pass it to the `playNote()` method of an `Output` object for more complex note definitions. ```javascript const note = new Note("A4"); const output = WebMidi.outputs[0]; output.playNote(note); ``` -------------------------------- ### List Available MIDI Inputs and Outputs Source: https://github.com/djipco/webmidi/blob/master/website/docs/getting-started/basics.md After enabling WebMidi, iterate through `WebMidi.inputs` and `WebMidi.outputs` to log the manufacturer and name of connected MIDI devices. This function is called once the library is successfully enabled. ```javascript WebMidi .enable() .then(onEnabled) .catch(err => alert(err)); function onEnabled() { // Inputs WebMidi.inputs.forEach(input => console.log(input.manufacturer, input.name)); // Outputs WebMidi.outputs.forEach(output => console.log(output.manufacturer, output.name)); } ``` -------------------------------- ### Run All Tests with Coverage Source: https://github.com/djipco/webmidi/blob/master/CONTRIBUTING.md Execute all unit tests and generate code coverage reports. This command is useful for ensuring the overall health and quality of the codebase. ```bash npm run test-all ``` -------------------------------- ### Message Constructor Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Message.md Creates a new Message object from raw MIDI data. ```APIDOC ## Constructor Creates a new `Message` object from raw MIDI data. ### Parameters `new Message(data)` - **`data`** (Uint8Array) - The raw data of the MIDI message as a [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) of integers between `0` and `255`. ``` -------------------------------- ### Enable Sysex Support in WebMidi Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/Input.md To receive 'sysex' events, you must enable WebMidi with the sysex option set to true. This is typically done when initializing the library. ```javascript WebMidi.enable({"sysex": true}) .then(() => console.log("WebMidi has been enabled with sysex support.")) ``` -------------------------------- ### Enable WebMidi.js and Display Input Devices Source: https://github.com/djipco/webmidi/blob/master/website/docs/index.md Add this script to your HTML to enable WebMidi.js, handle potential errors, and display available MIDI input devices. The onEnabled function is called once WebMidi.js is ready. ```javascript WebMidi .enable() .then(onEnabled) .catch(err => alert(err)); // Function triggered when WEBMIDI.js is ready function onEnabled() { // Display available MIDI input devices if (WebMidi.inputs.length < 1) { document.body.innerHTML+= "No device detected."; } else { WebMidi.inputs.forEach((device, index) => { document.body.innerHTML+= `${index}: ${device.name}
`; }); } } ``` -------------------------------- ### Listen to Note On Event on Specific Channel (v3 Preferred) Source: https://github.com/djipco/webmidi/blob/master/website/docs/migration/migration.md The preferred v3 syntax for listening to a 'noteon' event on MIDI channel 7 of the first input. This method is more explicit about channel targeting. ```javascript WebMidi.inputs[0].addListener("noteon", someFunction, {channels: [7]}); ``` -------------------------------- ### OutputChannel Constructor Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/OutputChannel.md Creates an OutputChannel object. This object is provided by an Output port and should not be instantiated directly. ```APIDOC ## new OutputChannel(output, number) ### Description Creates an `OutputChannel` object. ### Parameters #### Path Parameters - **output** (Output) - Required - The [`Output`](Output) this channel belongs to. - **number** (number) - Required - The MIDI channel number (`1` - `16`). ``` -------------------------------- ### InputChannel Constructor Source: https://github.com/djipco/webmidi/blob/master/website/api/classes/InputChannel.md Creates an InputChannel object, which represents a single MIDI channel within a MIDI input. It requires the parent Input object and the channel's MIDI number. ```APIDOC ## new InputChannel(input, number) ### Description Creates an `InputChannel` object. ### Parameters #### Path Parameters - **input** (Input) - Required - The [`Input`](Input) object this channel belongs to. - **number** (number) - Required - The channel's MIDI number (1-16). ``` -------------------------------- ### Listen to Note On Event on Specific Channel (v2.5.x) Source: https://github.com/djipco/webmidi/blob/master/website/docs/migration/migration.md This is the older syntax for listening to a 'noteon' event on MIDI channel 7 of the first input. While still functional in v3, the preferred method has changed. ```javascript // In WebMidi.js version 2.5.x WebMidi.inputs[0].addListener("noteon", 7, someFunction); ```