Comments (14)
Hi,
You can just open several output devices and call SendEvent
method:
var outputDevices = new[]
{
OutputDevice.GetByName("Output Device 1"),
OutputDevice.GetByName("Output Device 2"),
OutputDevice.GetByName("Output Device 3")
};
//
var inputDevice = InputDevice.GetByName("Input Device");
inputDevice.StartEventsListening();
inputDevice.EventReceived += (sender, args) =>
{
foreach (var outputDevice in outputDevices)
{
outputDevice.SendEvent(args.Event);
}
};
//
inputDevice.Dispose();
foreach (var outputDevice in outputDevices)
{
outputDevice.Dispose();
}
Also there is the DeviceConnector
class which you can use to automatically redirect incoming events to another device. But I didn't test it with multiple devices.
foreach (var outputDevice in outputDevices)
{
var deviceConnector = inputDevice.Connect(outputDevice);
}
from drywetmidi.
Hi, i will try the first aproach.
However, the second aproach (using DeviceConnector) does not working even with one to one. I created an input device and connected to a virtual port, and no luck. The automatic redirect is not working.
I am monitoring the virtual port, and no data was received. (the input device is working fine receiving events), but it looks like the DeviceConnector is not passing the events automatically.
Any ideas?
from drywetmidi.
I've created simple test which works on virtual MIDI ports:
var inputDevice = InputDevice.GetByName("MIDI A");
var inputDeviceOutput = OutputDevice.GetByName("MIDI A");
var outputDevice = OutputDevice.GetByName("MIDI B");
var outputDeviceInput = InputDevice.GetByName("MIDI B");
var devicesConnector = inputDevice.Connect(outputDevice);
inputDevice.StartEventsListening();
outputDeviceInput.StartEventsListening();
outputDeviceInput.EventReceived += (sender, args) =>
{
// Program falls into this place with Note On event
};
inputDeviceOutput.SendEvent(new NoteOnEvent());
from drywetmidi.
Hi, i am trying to understand your code, but i dont get it how to adapt this code to this scenario:
- I have a external midi controller that would be an inputDevice. (This controller has only midi output port connected to computer, so it becomes inputDevice in your library - and does not apear as a output device).
- How do i route/connect this midi controller to 2 or more output virtual ports (so i can use the with other programs / daws).
from drywetmidi.
Hi,
Please try this code:
var inputDevice = InputDevice.GetByName("MIDI Controller Name");
var outputDevice1 = OutputDevice.GetByName("MIDI Out 1");
var outputDevice2 = OutputDevice.GetByName("MIDI Out 2");
var devicesConnector1 = inputDevice.Connect(outputDevice1);
var devicesConnector2 = inputDevice.Connect(outputDevice2);
inputDevice.StartEventsListening();
But I think the second Connect
will fail since an input device will be locked for use (DevicesConnector
uses WinAPI Connect
function and from my experience any such function locks device until it is released). But please try it. Also try connection with one output device. If it won't work, please use approach with manual events redirection since it definitely will work.
from drywetmidi.
I have tried your code, unfortunately it doesn´t work even with just one output device. I think there is something wrong in the DeviceConnector.
I verified that i receive input events on inputDevice, however the deviceConnector is not handling the messages to the ouputDevice1.
How is the deviceConnector supposed to work?.
Waiting your response. Thanks!
from drywetmidi.
DevicesConnector
is supposed to redirect events from input device to output one. At now it uses WinAPI midiConnect function.
It seems it's difficult to make it work as expected in real scenarios. I'll try to get rid of midiConnect
and do manual redirection since it's much more stable and also allows transfer incoming events to multiple output devices. Also it will give more flexibility in adjusting devices connections.
Thanks for reporting your use case and new ideas!
from drywetmidi.
Ok melanchall.
So, should i wait for your fix? or is there any workaround to this scenario?
from drywetmidi.
Workaround is the approach I've suggested in my first comment. Of course Dispose
on devices should be called only when you've completely finished working with devices (for example, at the end of your program).
from drywetmidi.
I've refactored DevicesConnector
so it now doesn't use midiConnect
function. Changes are in develop branch.
from drywetmidi.
Hi Melanchall, what does that mean exactly? The functionality is different now? What should I expect now?
from drywetmidi.
It's just refactoring. Purpose of the DevicesConnector
and API are still unchanged.
from drywetmidi.
With last change you can write:
var inputDevice = InputDevice.GetByName("MIDI In");
var outputDevice1 = OutputDevice.GetByName("MIDI Out 1");
var outputDevice2 = OutputDevice.GetByName("MIDI Out 2");
var devicesConnector = inputDevice.Connect(outputDevice1, outputDevice2);
inputDevice.StartEventsListening();
After that all events from inputDevice
will be redirected to outputDevice1
and outputDevice2
.
from drywetmidi.
@eriveraa I'm closing the issue. If you have new questions regarding this issue, reopen it.
from drywetmidi.
Related Issues (20)
- HELP !!! Notes in panel to midi file?? HOT 9
- please help a noob HOT 6
- Remove all notes example from the README not working HOT 9
- Using wetdrymidi in C# project causes error CS0009
- InputDevice event listening crash HOT 2
- Crash when running in Unity on M2 MacBook HOT 3
- MidiDeviceException Internal error HOT 9
- Android Support
- Unity cannot exit after use HOT 10
- MidiClock sync problem HOT 6
- MIDI Tempo changes count returns 1 but the song has 6 tempo changes. HOT 1
- add il2cpp mode HOT 5
- CustomChunk no mididata throw error HOT 4
- CSharp Code Error HOT 2
- MIDI File returns error: InvalidMetaEventParameterValueException HOT 1
- Unable to send Note-On event to device HOT 8
- Cannot get track name to change HOT 10
- How to use DryWetMidi in Visual Basic (VS 2022) ? HOT 20
- Plans for MIDI 2.0 Support? HOT 2
- Skipping notes HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drywetmidi.