### Install node-easymidi Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Use npm to install the package. ```bash npm install easymidi ``` -------------------------------- ### Installation Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Install node-easymidi using npm. ```APIDOC ## Installation Install with NPM: ```bash npm install easymidi ``` ``` -------------------------------- ### Example: Listen for MIDI Clock Messages Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Example of how to listen for 'clock' MIDI messages. ```APIDOC Listen for midi clock messages: ```javascript input.on('clock', function () { // do something on every clock tick }); ``` ``` -------------------------------- ### Basic Usage Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Examples of how to use node-easymidi to listen for MIDI events and send MIDI messages. ```APIDOC ## Usage Overview The module can interface with existing MIDI inputs/outputs or create virtual inputs/outputs. Here's a simple example to listen for note on events from an existing MIDI input: ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('MIDI Input Name'); input.on('noteon', function (msg) { // do something with msg }); ``` Here's an example of sending a note on message to an existing MIDI output: ```javascript const easymidi = require('easymidi'); const output = new easymidi.Output('MIDI Output Name'); output.send('noteon', { note: 64, velocity: 127, channel: 3 }); ``` The Input and Output objects are [EventEmitters](http://nodejs.org/api/events.html#events_class_events_eventemitter) and you can use the EventEmitter functions such as `once()`, `removeListener()`, and `removeAllListeners()` as well. ``` -------------------------------- ### Example: Receive Note On Message Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Example of how to listen for and receive a 'noteon' MIDI message. ```APIDOC ## Examples Receive a noteon message: ```javascript input.on('noteon', function (params) { // params = {note: ..., velocity: ..., channel: ...} }); ``` ``` -------------------------------- ### Example: Send System Exclusive (Sysex) Message Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Example of how to send a 'sysex' MIDI message. Note that the byte array must start with 0xf0 and end with 0xf7. ```APIDOC Send a sysex message. Throws an error if array does not start with 0xf0 (240) and end with 0xf7 (247). ```javascript output.send('sysex',[240, 126, 1, 6, 1, 247]); ``` ``` -------------------------------- ### Example: Send Control Change Message Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Example of how to send a 'cc' (Control Change) MIDI message. ```APIDOC Send a control change message: ```javascript output.send('cc', { controller: 37, value: 80, channel: 0 }) ``` ``` -------------------------------- ### Device Lists Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Get a list of available MIDI input and output device names. ```APIDOC ## Device Lists You can get an array of existing MIDI input or output names using the `getInputs()` and `getOutputs` functions: ```javascript const inputs = easymidi.getInputs(); const outputs = easymidi.getOutputs(); ``` ``` -------------------------------- ### Get Available MIDI Ports Source: https://context7.com/dinchak/node-easymidi/llms.txt Retrieve lists of available MIDI input and output device names. ```javascript const easymidi = require('easymidi'); // Get all available MIDI input port names const inputs = easymidi.getInputs(); console.log('MIDI inputs:', inputs); // Output: MIDI inputs: ['USB MIDI Interface', 'Virtual MIDI Port'] // Get all available MIDI output port names const outputs = easymidi.getOutputs(); console.log('MIDI outputs:', outputs); // Output: MIDI outputs: ['USB MIDI Interface', 'Virtual MIDI Port'] ``` -------------------------------- ### Receive and Send MIDI Clock and Transport Messages with Easymidi Source: https://context7.com/dinchak/node-easymidi/llms.txt Handle MIDI clock synchronization and transport control. Listen for 'clock', 'start', 'continue', and 'stop' events. Send these messages using the respective 'send' methods. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Interface'); const output = new easymidi.Output('USB MIDI Interface'); // Listen for MIDI clock ticks (24 ticks per quarter note) input.on('clock', () => { console.log('Clock tick received'); }); // Listen for transport control messages input.on('start', () => console.log('Start received')); input.on('continue', () => console.log('Continue received')); input.on('stop', () => console.log('Stop received')); // Send transport control messages output.send('clock'); // Send clock tick output.send('start'); // Start playback output.send('continue'); // Continue playback output.send('stop'); // Stop playback ``` -------------------------------- ### Send and Receive System Exclusive (Sysex) Messages with Easymidi Source: https://context7.com/dinchak/node-easymidi/llms.txt Handle manufacturer-specific sysex messages. Ensure messages start with 0xF0 and end with 0xF7. The 'sysex' event provides message bytes. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Interface'); const output = new easymidi.Output('USB MIDI Interface'); // Listen for sysex messages input.on('sysex', (msg) => { console.log('Sysex bytes:', msg.bytes); // Output: Sysex bytes: [240, 126, 1, 6, 1, 247] }); // Send a sysex message (must start with 0xF0/240 and end with 0xF7/247) output.send('sysex', [240, 126, 1, 6, 1, 247]); // Throws error if message doesn't start with 0xF0 and end with 0xF7 ``` -------------------------------- ### Send Sysex Message Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Send a system exclusive message. The array must start with 0xf0 and end with 0xf7. ```javascript output.send('sysex',[240, 126, 1, 6, 1, 247]); ``` -------------------------------- ### Virtual Devices Source: https://github.com/dinchak/node-easymidi/blob/master/README.md How to create virtual MIDI input and output devices. ```APIDOC ## Virtual Devices Virtual devices can be created by passing a `true` argument to the Input or Output constructors: ```javascript const virtualInput = new easymidi.Input('Virtual input name', true); const virtualOutput = new easymidi.Output('Virtual output name', true); ``` ``` -------------------------------- ### Create a MIDI Input Source: https://context7.com/dinchak/node-easymidi/llms.txt Initialize a MIDI input port to receive messages, supporting both physical devices and virtual ports. ```javascript const easymidi = require('easymidi'); // Connect to an existing MIDI input device by name const input = new easymidi.Input('USB MIDI Interface'); // Create a virtual MIDI input (visible to other applications) const virtualInput = new easymidi.Input('My Virtual Input', true); // Check if port is open console.log('Port open:', input.isPortOpen()); // Output: Port open: true // Close the input when finished input.close(); ``` -------------------------------- ### Create Virtual MIDI Devices Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Pass true as the second argument to the constructor to create virtual MIDI ports. ```javascript const virtualInput = new easymidi.Input('Virtual input name', true); const virtualOutput = new easymidi.Output('Virtual output name', true); ``` -------------------------------- ### Create a MIDI Output Source: https://context7.com/dinchak/node-easymidi/llms.txt Initialize a MIDI output port to send messages, supporting both physical devices and virtual ports. ```javascript const easymidi = require('easymidi'); // Connect to an existing MIDI output device by name const output = new easymidi.Output('USB MIDI Interface'); // Create a virtual MIDI output (visible to other applications) const virtualOutput = new easymidi.Output('My Virtual Output', true); // Check if port is open console.log('Port open:', output.isPortOpen()); // Output: Port open: true // Close the output when finished output.close(); ``` -------------------------------- ### Listen for MIDI Input Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Initialize an Input object and listen for specific MIDI events. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('MIDI Input Name'); input.on('noteon', function (msg) { // do something with msg }); ``` -------------------------------- ### Send MIDI Output Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Initialize an Output object and send MIDI messages. ```javascript const easymidi = require('easymidi'); const output = new easymidi.Output('MIDI Output Name'); output.send('noteon', { note: 64, velocity: 127, channel: 3 }); ``` -------------------------------- ### List MIDI Devices Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Retrieve arrays of available MIDI input and output device names. ```javascript const inputs = easymidi.getInputs(); const outputs = easymidi.getOutputs(); ``` -------------------------------- ### Send and Receive Program Change Messages with Easymidi Source: https://context7.com/dinchak/node-easymidi/llms.txt Handle program changes for switching instrument patches. Listen for incoming 'program' events and send new ones using the 'program' type. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Interface'); const output = new easymidi.Output('USB MIDI Interface'); // Listen for program change messages input.on('program', (msg) => { console.log('Program:', msg.number, 'Channel:', msg.channel); // Output: Program: 5 Channel: 0 }); // Send a program change message output.send('program', { number: 5, // Program number (0-127) channel: 0 // MIDI channel (0-15) }); ``` -------------------------------- ### Send Control Change Messages with Easymidi Source: https://context7.com/dinchak/node-easymidi/llms.txt Use this to control parameters like volume, pan, or modulation. Ensure the output port is correctly initialized. ```javascript const easymidi = require('easymidi'); const output = new easymidi.Output('USB MIDI Interface'); // Send modulation wheel (CC 1) output.send('cc', { controller: 1, // Controller number (0-127) value: 64, // Controller value (0-127) channel: 0 // MIDI channel (0-15) }); // Send sustain pedal on (CC 64) output.send('cc', { controller: 64, value: 127, channel: 0 }); // Send sustain pedal off output.send('cc', { controller: 64, value: 0, channel: 0 }); ``` -------------------------------- ### Listen for MIDI Clock Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Handle incoming clock messages. ```javascript input.on('clock', function () { // do something on every clock tick }); ``` -------------------------------- ### Handle Song Position and Song Select Messages Source: https://context7.com/dinchak/node-easymidi/llms.txt Use these listeners and send methods to manage sequencer control via MIDI position and song select events. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Interface'); const output = new easymidi.Output('USB MIDI Interface'); // Listen for song position pointer input.on('position', (msg) => { console.log('Position:', msg.value); // Value is in MIDI beats (1 beat = 6 MIDI clocks) }); // Listen for song select input.on('select', (msg) => { console.log('Song:', msg.song); }); // Send song position output.send('position', { value: 12345 // Position value (0-16383) }); // Send song select output.send('select', { song: 10 // Song number (0-127) }); ``` -------------------------------- ### Implement MIDI Message Pass-Through Source: https://context7.com/dinchak/node-easymidi/llms.txt Forward incoming MIDI messages to an output port, ensuring sysex messages are handled correctly by stripping the internal type property. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Input'); const output = new easymidi.Output('USB MIDI Output'); // Forward all messages from input to output input.on('message', (msg) => { const type = msg._type; delete msg._type; // Remove internal type property // Handle sysex separately (uses array instead of object) if (type === 'sysex') { output.send(type, msg.bytes); } else { output.send(type, msg); } }); // Cleanup on exit process.on('SIGINT', () => { input.close(); output.close(); process.exit(); }); ``` -------------------------------- ### Receive MTC and SMPTE Timecode with Easymidi Source: https://context7.com/dinchak/node-easymidi/llms.txt Handle MIDI Time Code (MTC) for timecode synchronization. Listen for raw 'mtc' quarter-frame messages or assembled 'smpte' formatted timecode. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Interface'); // Listen for raw MTC quarter-frame messages input.on('mtc', (msg) => { console.log('MTC type:', msg.type, 'value:', msg.value); }); // Listen for formatted SMPTE timecode (assembled from MTC messages) // SMPTE Types: 0 = 24fps, 1 = 25fps, 2 = 30fps drop-frame, 3 = 30fps input.on('smpte', (smpte) => { console.log('SMPTE:', smpte.smpte, 'Type:', smpte.smpteType); // Output: SMPTE: 01:23:45:12 Type: 0 }); ``` -------------------------------- ### Close MIDI Devices Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Release resources by calling close() on the device instance. ```javascript const input = new easymidi.Input('My input', true); input.close(); const output = new easymidi.Output('My output', true); output.close(); ``` -------------------------------- ### Send and Receive Aftertouch Messages with Easymidi Source: https://context7.com/dinchak/node-easymidi/llms.txt Handle both polyphonic (per-note) and channel (overall) aftertouch messages. Use 'poly aftertouch' and 'channel aftertouch' events and send methods. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Interface'); const output = new easymidi.Output('USB MIDI Interface'); // Listen for polyphonic aftertouch (per-note pressure) input.on('poly aftertouch', (msg) => { console.log('Note:', msg.note, 'Pressure:', msg.pressure, 'Channel:', msg.channel); }); // Listen for channel aftertouch (overall pressure) input.on('channel aftertouch', (msg) => { console.log('Pressure:', msg.pressure, 'Channel:', msg.channel); }); // Send polyphonic aftertouch output.send('poly aftertouch', { note: 64, pressure: 100, channel: 0 }); // Send channel aftertouch output.send('channel aftertouch', { pressure: 100, channel: 0 }); ``` -------------------------------- ### Receive Note Messages Source: https://context7.com/dinchak/node-easymidi/llms.txt Listen for note on and note off events from an input port. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Interface'); // Listen for note on events input.on('noteon', (msg) => { console.log('Note On:', msg.note, 'Velocity:', msg.velocity, 'Channel:', msg.channel); // Output: Note On: 64 Velocity: 127 Channel: 0 }); // Listen for note off events input.on('noteoff', (msg) => { console.log('Note Off:', msg.note, 'Velocity:', msg.velocity, 'Channel:', msg.channel); // Output: Note Off: 64 Velocity: 0 Channel: 0 }); ``` -------------------------------- ### Monitor All MIDI Messages Source: https://context7.com/dinchak/node-easymidi/llms.txt Iterate through all available MIDI inputs to attach a generic 'message' listener for logging or processing. ```javascript const easymidi = require('easymidi'); // Monitor all messages from all MIDI inputs easymidi.getInputs().forEach((inputName) => { const input = new easymidi.Input(inputName); input.on('message', (msg) => { // msg._type contains the message type const vals = Object.keys(msg).map((key) => `${key}: ${msg[key]}`); console.log(`${inputName}: ${vals.join(', ')}`); // Output: USB MIDI Interface: _type: noteon, note: 64, velocity: 127, channel: 0 }); }); ``` -------------------------------- ### Message Reference Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Reference for supported MIDI message types and their parameters. ```APIDOC ## Message Reference The following table describes the MIDI message types that are supported and the parameters of each: | Type | Parameter | Parameter | Parameter | |--------------------|--------------------|------------------|----------------| | noteon | note [0-127] | velocity [0-127] | channel [0-15] | | noteoff | note [0-127] | velocity [0-127] | channel [0-15] | | poly aftertouch | note [0-127] | velocity [0-127] | channel [0-15] | | cc | controller [0-127] | value [0-127] | channel [0-15] | | program | number [0-127] | | channel [0-15] | | channel aftertouch | pressure [0-127] | | channel [0-15] | | pitch | value [0-16384] | | channel [0-15] | | position | value [0-16384] | | | | mtc | type [0-7] | value [0-15] | | | select | song [0-127] | | | | clock | | | | | start | | | | | continue | | | | | stop | | | | | activesense | | | | | reset | | | | | sysex | bytes (variable length array) | | | ``` -------------------------------- ### Closing Devices Source: https://github.com/dinchak/node-easymidi/blob/master/README.md How to close MIDI devices when they are no longer needed. ```APIDOC ## Closing Devices When you're finished with a MIDI device you can `close()` it: ```javascript const input = new easymidi.Input('My input', true); input.close(); const output = new easymidi.Output('My output', true); output.close(); ``` ``` -------------------------------- ### Receive Control Change Messages Source: https://context7.com/dinchak/node-easymidi/llms.txt Listen for control change (CC) messages from an input port. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Interface'); // Listen for control change messages input.on('cc', (msg) => { console.log('Controller:', msg.controller, 'Value:', msg.value, 'Channel:', msg.channel); // Output: Controller: 1 Value: 64 Channel: 0 }); ``` -------------------------------- ### Send Control Change Message Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Send a cc message to an output device. ```javascript output.send('cc', { controller: 37, value: 80, channel: 0 }) ``` -------------------------------- ### Receive noteon Message Source: https://github.com/dinchak/node-easymidi/blob/master/README.md Handle incoming noteon events with a callback function. ```javascript input.on('noteon', function (params) { // params = {note: ..., velocity: ..., channel: ...} }); ``` -------------------------------- ### Send and Receive Pitch Bend Messages with Easymidi Source: https://context7.com/dinchak/node-easymidi/llms.txt Handle pitch bend messages for smooth pitch variations. The 'pitch' event provides the value and channel, while 'send' accepts a value between 0 and 16383. ```javascript const easymidi = require('easymidi'); const input = new easymidi.Input('USB MIDI Interface'); const output = new easymidi.Output('USB MIDI Interface'); // Listen for pitch bend messages input.on('pitch', (msg) => { console.log('Pitch value:', msg.value, 'Channel:', msg.channel); // Output: Pitch value: 8192 Channel: 0 (center position) }); // Send a pitch bend message output.send('pitch', { value: 12345, // Pitch value (0-16383, 8192 = center/no bend) channel: 0 // MIDI channel (0-15) }); ``` -------------------------------- ### Send Note Messages Source: https://context7.com/dinchak/node-easymidi/llms.txt Transmit note on and note off messages to an output port. ```javascript const easymidi = require('easymidi'); const output = new easymidi.Output('USB MIDI Interface'); // Send a note on message (play middle C at full velocity on channel 1) output.send('noteon', { note: 60, // MIDI note number (60 = middle C) velocity: 127, // Note velocity (0-127) channel: 0 // MIDI channel (0-15) }); // Send a note off message to stop the note output.send('noteoff', { note: 60, velocity: 0, channel: 0 }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.