Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

receiving messages from all midi devices #138

Closed
elmcapp opened this issue Apr 15, 2021 · 4 comments
Closed

receiving messages from all midi devices #138

elmcapp opened this issue Apr 15, 2021 · 4 comments
Assignees
Labels
Type: enhancement Request for improvement

Comments

@elmcapp
Copy link

elmcapp commented Apr 15, 2021

Is there a way we can listen for midi messages coming from any device connected to the computer without needing to select a midi input device to listen for. Basically if 2 midi devices are connected to the computer we can listen to both devices same time

`var input = WebMidi.getInputByName("ALL CONNECTED MIDI DEVICES");

input.addListener('pitchbend', "all", function(e) {
console.log("Pitch value: " + e.value);
});`

@takyano
Copy link

takyano commented Apr 15, 2021

WebMidi.inputs is an array of inputs that you might be looking for.

@elmcapp
Copy link
Author

elmcapp commented Apr 15, 2021

Yes I know that WebMidi.inputs is an array of midi inputs but what I am hoping to do is add an event listen that will listen to all midi message across all midi devices. Lets say that I have 3 midi controllers I would like to console log all "note on" messages from all 3 midi controllers. Basically I don't want to monitor 1 input device but I want to monitor all i midi devices

@takyano
Copy link

takyano commented Apr 15, 2021

I haven't seen a global message listener method.

You can loop over the inputs array and add a listener to each input for each type of message that you want to monitor.

for( let a = 0; a < WebMidi.inputs.length; a++ )
{
	WebMidi.inputs[ a ].addListener( 'controlchange', 'all', function( e ) {
		console.log( `Control Change (${e.target.name}): ${e.value}` );
	});
	WebMidi.inputs[ a ].addListener( 'noteon', 'all', function( e ) {
		console.log( `Note On (${e.target.name}): ${e.note.name}` );
	});
}

@djipco djipco self-assigned this Apr 15, 2021
@djipco
Copy link
Owner

djipco commented Apr 15, 2021

Is there a way we can listen for midi messages coming from any device connected to the computer without needing to select a midi input device to listen for.

Currently, there is no way to automatically do what you describe. Of course, you can always add listeners to all devices like @takyano suggested.

Having said that, it might be interesting to add this functionality. Currently, in version 3.0.0-alpha.5, you can add listeners at the device level and at the channel level. I don't see why we couldn't do the same at the WebMidi.js level. I added this suggestion to the enhancements to evaluate in the wiki.

@djipco djipco added the Type: enhancement Request for improvement label Apr 15, 2021
@djipco djipco closed this as completed Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement Request for improvement
Projects
None yet
Development

No branches or pull requests

3 participants