Giter Club home page Giter Club logo

Comments (14)

melanchall avatar melanchall commented on June 19, 2024

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.

eriveraa avatar eriveraa commented on June 19, 2024

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.

melanchall avatar melanchall commented on June 19, 2024

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.

eriveraa avatar eriveraa commented on June 19, 2024

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.

melanchall avatar melanchall commented on June 19, 2024

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.

eriveraa avatar eriveraa commented on June 19, 2024

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.

melanchall avatar melanchall commented on June 19, 2024

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.

eriveraa avatar eriveraa commented on June 19, 2024

Ok melanchall.
So, should i wait for your fix? or is there any workaround to this scenario?

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024

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.

melanchall avatar melanchall commented on June 19, 2024

I've refactored DevicesConnector so it now doesn't use midiConnect function. Changes are in develop branch.

from drywetmidi.

eriveraa avatar eriveraa commented on June 19, 2024

Hi Melanchall, what does that mean exactly? The functionality is different now? What should I expect now?

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024

It's just refactoring. Purpose of the DevicesConnector and API are still unchanged.

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024

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.

melanchall avatar melanchall commented on June 19, 2024

@eriveraa I'm closing the issue. If you have new questions regarding this issue, reopen it.

from drywetmidi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.