Animatroller.Framework.Expander.MidiInput2.MidiInput2 C# (CSharp) Method

MidiInput2() public method

public MidiInput2 ( string deviceName = null, bool ignoreMissingDevice = false, [ name = "" ) : System
deviceName string
ignoreMissingDevice bool
name [
return System
        public MidiInput2(string deviceName = null, bool ignoreMissingDevice = false, [System.Runtime.CompilerServices.CallerMemberName] string name = "")
        {
            this.name = name;
            string midiDeviceName = deviceName;
            if (string.IsNullOrEmpty(deviceName))
                midiDeviceName = Executor.Current.GetSetKey(this, name + ".DeviceName", string.Empty);

            this.messageMapper = new Dictionary<Tuple<int, ChannelCommand, int>, Action<ChannelMessage>>();

            this.midiMessages = new Subject<ChannelMessage>();

            int selectedDeviceId = -1;
            for (int i = 0; i < InputDevice.DeviceCount; i++)
            {
                var midiCap = InputDevice.GetDeviceCapabilities(i);

                if (midiCap.name == midiDeviceName)
                {
                    selectedDeviceId = i;
                    break;
                }
            }

            if (selectedDeviceId == -1)
            {
                if (!ignoreMissingDevice)
                    throw new ArgumentException("Midi device not detected");
                else
                    log.Warn("Midi device not detected");
            }
            else
            {
                this.inputDevice = new InputDevice(selectedDeviceId);
                this.inputDevice.ChannelMessageReceived += inputDevice_ChannelMessageReceived;

                if (string.IsNullOrEmpty(deviceName))
                    Executor.Current.SetKey(this, name + ".DeviceName", midiDeviceName);
            }

            Executor.Current.Register(this);
        }