Ejemplo n.º 1
0
        public static void Send(MidiShortMessage message)
        {
            if (!IsOutputEnabled)
            {
                return;
            }

            if (midiOut == null)
            {
                string[] devices = MidiOutputDevice.GetDeviceDescriptions();
                int      index   = devices.ToList().IndexOf("Microsoft GS Wavetable Synth");
                if (index != -1)
                {
                    midiOut = new MidiOutputDevice(index);
                    isMidiOutInitialized = midiOut.Open();
                }
            }

            if (!isMidiOutInitialized || !midiOut.IsOpened)
            {
                return;
            }

            if (message.StatusType == MIDIStatus.NoteOff)
            {
                message.Velocity = 0;
            }

            midiOut.Send(message);
        }
Ejemplo n.º 2
0
        private void MidiOutComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (null != _outputDevice)
            {
                _outputDevice.Close();
            }
            _outputDevice = MidiOutComboBox.SelectedItem as MidiOutputDevice;

            _outputDevice.Open();
        }
Ejemplo n.º 3
0
        public NanoKontrol2(string midiDeviceName = "nanoKONTROL2")
        {
            Slider = new ControlStateCollection("Slider", _Slider);
            Knob   = new ControlStateCollection("Knob", _Knob);
            Solo   = new ButtonStateCollection(this, ButtonCategory.Solo, _Solo);
            Mute   = new ButtonStateCollection(this, ButtonCategory.Mute, _Mute);
            Record = new ButtonStateCollection(this, ButtonCategory.Record, _Record);

            Input  = MidiInputDevice.OpenByName(midiDeviceName);
            Output = MidiOutputDevice.OpenByName(midiDeviceName);

            Input.OnData += Input_OnData;
        }
Ejemplo n.º 4
0
        public MidiDevices()
        {
            InitializeComponent();

            int[] inPorts = MidiInputDevice.GetMidiPorts();
            foreach (int port in inPorts)
            {
                string name = MidiInputDevice.GetDeviceDescription(port);
                Console.WriteLine("Input : {0}={1}", port, name);
                this.comboBox1.Items.Add(name);
            }

            int[] outPorts = MidiOutputDevice.GetMidiPorts();
            foreach (int port in outPorts)
            {
                string name = MidiOutputDevice.GetDeviceDescription(port);
                Console.WriteLine("Output : {0}={1}", port, name);
            }
        }
Ejemplo n.º 5
0
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            if (null != _inputDevice && _inputDevice.IsOpen)
            {
                // attempt to prevent any further
                // events from firing
                _inputDevice.Stop();
                _inputDevice.Reset();

                _inputDevice.Close();
                _inputDevice = null;
            }
            if (null != _outputDevice && _outputDevice.IsOpen)
            {
                _outputDevice.Close();
                _outputDevice = null;
            }
        }
Ejemplo n.º 6
0
 private MidiOutputDevice OpenDevice(int indevice, int outdevice)
 {
     buttons    = Helper.GetButtons();
     _outDevice = new MidiOutputDevice(indevice);
     _inDevice  = new MidiInputDevice(outdevice);
     if (!_outDevice.Open())
     {
         throw new Exception("Midi Open Error");
     }
     else
     {
         isReady = true;
     }
     if (!_inDevice.Open())
     {
         throw new Exception("Midi Open Error " + _inDevice.LastErrorCode.ToString() + _inDevice.Device);
     }
     else
     {
         isReady = true;
     }
     return(_outDevice);
 }
Ejemplo n.º 7
0
        internal static async Task <RawMidiClient> CreateAsync(MidiInputDevice inputDevice, MidiOutputDevice outputDevice, Action <RawMidiMessage> messageHandler)
        {
            // TODO: Retry this; sometimes it doesn't work first time.
            var input = await OpenInput(inputDevice.SystemDeviceId);

            var output = await MidiAccessManager.Default.OpenOutputAsync(outputDevice.SystemDeviceId);

            return(new RawMidiClient(input, inputDevice.Name, output, outputDevice.Name, messageHandler));
        }
Ejemplo n.º 8
0
 public Task <IMidiOutput> OpenOutputAsync(MidiOutputDevice output) =>
 Task.FromResult((IMidiOutput)outputs[output]);
Ejemplo n.º 9
0
 public static Task <RolandMidiClient> CreateRolandMidiClientAsync(MidiInputDevice input, MidiOutputDevice output, DeviceIdentity deviceIdentity, int modelId) =>
 RolandMidiClient.CreateAsync(input, output, deviceIdentity.RawDeviceId, modelId);
Ejemplo n.º 10
0
        public static async Task <IReadOnlyList <DeviceIdentity> > ListDeviceIdentities(MidiInputDevice input, MidiOutputDevice output, TimeSpan timeout)
        {
            List <DeviceIdentity> identities = new List <DeviceIdentity>();

            using (var client = await RawMidiClient.CreateAsync(input, output, HandleMessage))
            {
                // Identity request message for all devices IDs.
                client.Send(new RawMidiMessage(new byte[] { 0xf0, 0x7e, 0x7f, 0x06, 0x01, 0xf7 }));
                await Task.Delay(timeout);
            }
            return(identities.AsReadOnly());

            void HandleMessage(RawMidiMessage message)
            {
                // TODO: Handle 17-byte messages for "long" manufacturer IDs
                var data = message.Data;

                if (data.Length == 15 &&
                    data[0] == 0xf0 && // SysEx
                    data[1] == 0x7e && // Universal non-realtime message
                    data[3] == 0x06 && // General information
                    data[4] == 0x02)   // Identity reply
                {
                    byte rawDeviceId      = data[2];
                    var  manufacturerId   = (ManufacturerId)data[5];
                    int  familyCode       = data[6] + (data[7] << 8);
                    int  familyNumberCode = data[8] + (data[9] << 8);
                    int  revision         = data[10] + (data[11] << 8) + (data[12] << 16) + (data[13] << 24);
                    identities.Add(new DeviceIdentity(rawDeviceId, manufacturerId, familyCode, familyNumberCode, revision));
                }
            }
        }
Ejemplo n.º 11
0
        internal static async Task <RolandMidiClient> CreateAsync(MidiInputDevice inputDevice, MidiOutputDevice outputDevice, byte rawDeviceId, int modelId)
        {
            // This is all a bit nasty... we can't create a RolandMidiClient instance until we have the raw client, and we can't
            // create the raw client until we've got a method to call. LocalHandleMessage acts as a sort of trampoline.
            // If we could make the constructor asynchronous, it wouldn't be a problem.
            RolandMidiClient ret = null;
            var rawClient        = await RawMidiClient.CreateAsync(inputDevice, outputDevice, LocalHandleMessage);

            ret = new RolandMidiClient(rawClient, rawDeviceId, modelId);
            return(ret);

            void LocalHandleMessage(RawMidiMessage message) => ret?.HandleMessage(message);
        }
Ejemplo n.º 12
0
        internal static async Task <RawMidiClient> CreateAsync(MidiInputDevice inputDevice, MidiOutputDevice outputDevice, Action <RawMidiMessage> messageHandler)
        {
            var input = await MidiAccessManager.Default.OpenInputAsync(inputDevice.SystemDeviceId);

            var output = await MidiAccessManager.Default.OpenOutputAsync(outputDevice.SystemDeviceId);

            return(new RawMidiClient(input, output, messageHandler));
        }
Ejemplo n.º 13
0
        public static async Task <RolandMidiClient> CreateRolandMidiClientAsync(MidiInputDevice inputDevice, MidiOutputDevice outputDevice, DeviceIdentity deviceIdentity, ModuleIdentifier identifier)
        {
            var input = await Manager.OpenInputAsync(inputDevice);

            var output = await Manager.OpenOutputAsync(outputDevice);

            return(new RolandMidiClient(input, output, inputDevice.Name, outputDevice.Name, deviceIdentity.RawDeviceId, identifier));
        }
Ejemplo n.º 14
0
 public int[] GetDevices()
 {
     return(MidiOutputDevice.GetMidiPorts());
 }
Ejemplo n.º 15
0
 public static Task <RolandMidiClient> CreateRolandMidiClientAsync(MidiInputDevice input, MidiOutputDevice output, DeviceIdentity deviceIdentity, ModuleIdentifier identifier) =>
 RolandMidiClient.CreateAsync(input, output, deviceIdentity.RawDeviceId, identifier);