/// <summary>
        /// Query DeviceInformation class for Midi Input devices
        /// </summary>
        private async Task EnumerateMidiInputDevices()
        {
            // Clear input devices
            InputDevices.Clear();
            InputDeviceProperties.Clear();
            inputDeviceProperties.IsEnabled = false;

            // Find all input MIDI devices
            string midiInputQueryString = MidiInPort.GetDeviceSelector();
            DeviceInformationCollection midiInputDevices = await DeviceInformation.FindAllAsync(midiInputQueryString);

            // Return if no external devices are connected
            if (midiInputDevices.Count == 0)
            {
                InputDevices.Add("No MIDI input devices found!");
                inputDevices.IsEnabled = false;

                NotifyUser("Please connect at least one external MIDI device for this demo to work correctly");
                return;
            }

            // Else, add each connected input device to the list
            foreach (DeviceInformation deviceInfo in midiInputDevices)
            {
                InputDevices.Add(deviceInfo.Name);
                inputDevices.IsEnabled = true;
            }

            NotifyUser("MIDI Input devices found!");
        }
        /// <summary>
        /// Constructor: Empty device lists, start the device watchers and
        /// set initial states for buttons
        /// </summary>
        public MidiDeviceEnumerationTests()
        {
            InitializeComponent();

            rootGrid.DataContext = this;

            // Start with a clean slate
            ClearAllDeviceValues();

            // Ensure Auto-detect devices toggle is on
            deviceAutoDetectToggle.IsOn = true;

            // Set up the MIDI input and output device watchers
            _midiInDeviceWatcher  = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), Dispatcher, inputDevices, InputDevices);
            _midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), Dispatcher, outputDevices, OutputDevices);

            // Start watching for devices
            _midiInDeviceWatcher.Start();
            _midiOutDeviceWatcher.Start();

            // Disable manual enumeration buttons
            listInputDevicesButton.IsEnabled  = false;
            listOutputDevicesButton.IsEnabled = false;

            Unloaded += MidiDeviceEnumerationTests_Unloaded;
        }
        public PianoPage()
        {
            this.InitializeComponent();

            // Setup our device watchers for input and output MIDI devices.
            // Let's us know if devices are connected/disconnected while we're running
            // (And hopefully catches these gracefully so that we don't crash!)
            inputDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortComboBox, Dispatcher);
            inputDeviceWatcher.StartWatcher();

            outputDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortComboBox, Dispatcher);
            outputDeviceWatcher.StartWatcher();

            // Helper class to take care of MIDI Control messages, set it up here with the sliders
            msgHelper = new ControlMessageHelper(KB, SliderPitch, SliderMod, SliderVolume, SliderPan, Dispatcher);

            // Register Suspending to clean up any connections we have
            Application.Current.Suspending += Current_Suspending;

            // Register event handlers for KeyTapped and KeyReleased
            // (These events only occur when user taps/clicks on keys on screen)
            KB.K_KeyTapped   += KB_K_KeyTapped;
            KB.K_KeyReleased += KB_K_KeyReleased;

            // Wait until page has finished loading before doing some UI/layout changes
            Loaded += PianoPage_Loaded;
        }
        public SettingsPage()
        {
            this.InitializeComponent();

            inputDeviceWatcher =
                new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher);

            inputDeviceWatcher.StartWatcher();

            outputDeviceWatcher =
                new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher);

            outputDeviceWatcher.StartWatcher();

            //Set the slider back to the values the user put in
            velocitySlider.Value = (Settings.velocity - 27);
            volumeSlider.Value   = (Settings.volume + 50);
            if (Settings.feedback == true)
            {
                volumeSlider.IsEnabled   = true;
                velocitySlider.IsEnabled = false;
            }
            else
            {
                Feedback.IsChecked       = true;
                volumeSlider.IsEnabled   = false;
                velocitySlider.IsEnabled = true;
            }
        }
        public MainPage()
        {
            this.InitializeComponent();

            var appView = ApplicationView.GetForCurrentView();

            appView.Title = "";

            // Titlebar
            var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;

            coreTitleBar.ExtendViewIntoTitleBar = false;

            CreateKeyboard();
            CreateSidebar();

            // MIDI
            inputDeviceWatcher =
                new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher);

            inputDeviceWatcher.StartWatcher();

            outputDeviceWatcher =
                new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher);

            outputDeviceWatcher.StartWatcher();
        }
 public UwpMidiAccess(Windows.UI.Core.CoreDispatcher dispatcher)
 {
     _midiInDeviceWatcher  = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), dispatcher);
     _midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), dispatcher);
     _midiInDeviceWatcher.Start();
     _midiOutDeviceWatcher.Start();
 }
        private async Task LoadInputDevicesAsync()
        {
            WriteDebug("Entering LoadInputDevicesAsync");

            _devices = new List <MidiDeviceInformation>();

            var selector = MidiInPort.GetDeviceSelector();

            WriteDebug("Selector = " + selector);

            var devices = await DeviceInformation.FindAllAsync(selector);

            WriteDebug("Devices count = " + devices.Count);

            foreach (DeviceInformation info in devices)
            {
                WriteDebug("Loading device information into collection " + info.Id);

                var midiDevice = new MidiDeviceInformation();

                midiDevice.Id        = info.Id;
                midiDevice.IsDefault = info.IsDefault;
                midiDevice.IsEnabled = info.IsEnabled;
                midiDevice.Name      = info.Name;

                _devices.Add(midiDevice);
            }

            WriteDebug("Exiting LoadInputDevicesAsync");
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public MidiController()
        {
            // Get an instance to the event handler and subscribe to the SequencerPositionChanged event.
            this.globalEventHandlerInstance = GlobalEventHandler.GetInstance();

            // Selected MIDI device.
            deviceSelectorString = MidiInPort.GetDeviceSelector();

            // Activate device watcher and add callbacks for state changes.
            deviceWatcher          = DeviceInformation.CreateWatcher(deviceSelectorString);
            deviceWatcher.Added   += DeviceWatcher_Added;
            deviceWatcher.Removed += DeviceWatcher_Removed;
            deviceWatcher.Updated += DeviceWatcher_Updated;
            deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;

            // Subscribe to changed MIDI device.
            this.globalEventHandlerInstance.SelectedMidiDeviceChanged += this.SelectedMidiDeviceChanged;

            // Subscribe to event to learn MIDI messages.
            this.globalEventHandlerInstance.LearnMidiEvent += this.LearnMidiEvent;

            // Initialize MIDI event triggers.
            for (int i = 0; i < Enum.GetNames(typeof(MidiEventType)).Length; i++)
            {
                learnedMidiTriggers[i] = new MidiEventTrigger();
            }
        }
        private async Task EnumerateDevices()
        {
            var inputDevices = await DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector());

            deepMind = null;

            foreach (DeviceInformation device in inputDevices)
            {
                if (device.Name.Contains("DeepMind"))
                {
                    if (deepMind != null)
                    {
                        deepMind.Dispose();
                    }
                    deepMind = await MidiInPort.FromIdAsync(device.Id);

                    this.textBlock.Text = "Captured device!";
                }
            }

            if (deepMind == null)
            {
                return;
            }

            deepMind.MessageReceived += DeepMind_MessageReceived;
        }
        // using an Initialize method here instead of the constructor in order to
        // prevent a race condition between wiring up the event handlers and
        // finishing enumeration
        public void Initialize()
        {
            ConnectedInputDevices  = new List <MidiDeviceInformation>();
            ConnectedOutputDevices = new List <MidiDeviceInformation>();


            // set up watchers so we know when input devices are added or removed
            _inputWatcher = DeviceInformation.CreateWatcher(MidiInPort.GetDeviceSelector());

            _inputWatcher.EnumerationCompleted += InputWatcher_EnumerationCompleted;
            _inputWatcher.Updated += InputWatcher_Updated;
            _inputWatcher.Removed += InputWatcher_Removed;
            _inputWatcher.Added   += InputWatcher_Added;

            _inputWatcher.Start();

            // set up watcher so we know when output devices are added or removed
            _outputWatcher = DeviceInformation.CreateWatcher(MidiOutPort.GetDeviceSelector());

            _outputWatcher.EnumerationCompleted += OutputWatcher_EnumerationCompleted;
            _outputWatcher.Updated += OutputWatcher_Updated;
            _outputWatcher.Removed += OutputWatcher_Removed;
            _outputWatcher.Added   += OutputWatcher_Added;

            _outputWatcher.Start();
        }
Beispiel #11
0
        public MidiDeviceWatcher(MidiDeviceType ioType, CoreDispatcher dispatcher)
        {
            this.DeviceInformationList = new ObservableCollection <DeviceInformation>();

            m_coreDispatcher = dispatcher;

            switch (ioType)
            {
            case MidiDeviceType.Input:
            {
                m_deviceSelectorString = MidiInPort.GetDeviceSelector();
                break;
            }

            case MidiDeviceType.Output:
            {
                m_deviceSelectorString = MidiOutPort.GetDeviceSelector();
                break;
            }

            default:
            {
                break;
            }
            }

            m_deviceWatcher          = DeviceInformation.CreateWatcher(m_deviceSelectorString);
            m_deviceWatcher.Added   += DeviceWatcher_Added;
            m_deviceWatcher.Removed += DeviceWatcher_Removed;
            m_deviceWatcher.Updated += DeviceWatcher_Updated;
            m_deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;

            m_deviceType = ioType;
        }
Beispiel #12
0
        private static async Task <List <MidiInDevice> > _GetAllDevices(bool returnEmptyNames = false)
        {
            var midiInputQueryString = MidiInPort.GetDeviceSelector();
            var midiInputDevices     = await DeviceInformation.FindAllAsync(midiInputQueryString);

            return((from device in midiInputDevices where returnEmptyNames || device.Name.Length != 0
                    select new MidiInDevice(device)).ToList());
        }
Beispiel #13
0
            public FakeMidiDevice()
            {
                int ports = 0;

                Inputs          = DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector()).GetResults();
                InputPortInfos  = Inputs.Select(i => new WindowsPortInfo(i.Id, MidiPortType.Input, i.Name, ports++)).ToArray();  // freeze for port number
                Outputs         = DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector()).GetResults();
                OutputPortInfos = Outputs.Select(i => new WindowsPortInfo(i.Id, MidiPortType.Input, i.Name, ports++)).ToArray(); // freeze for port number
            }
Beispiel #14
0
 // Constructor using a combobox for full device watch:
 public MIDI(Integra7Random_Xamarin.MainPage mainPage, MainPage mainPage_UWP, Picker OutputDeviceSelector, Picker InputDeviceSelector, byte MidiOutPortChannel, byte MidiInPortChannel)
 {
     this.mainPage           = mainPage;
     this.MainPage_UWP       = mainPage_UWP;
     midiOutputDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), OutputDeviceSelector, mainPage_UWP.Dispatcher_UWP);
     midiInputDeviceWatcher  = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), InputDeviceSelector, mainPage_UWP.Dispatcher_UWP);
     midiOutputDeviceWatcher.StartWatcher();
     midiInputDeviceWatcher.StartWatcher();
     this.MidiOutPortChannel = MidiOutPortChannel;
     this.MidiInPortChannel  = MidiInPortChannel;
 }
Beispiel #15
0
 public void Init(Integra7Random_Xamarin.MainPage mainPage, String deviceName, Picker OutputDeviceSelector, Picker InputDeviceSelector, object Dispatcher, byte MidiOutPortChannel, byte MidiInPortChannel)
 {
     this.mainPage           = mainPage;
     midiOutputDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), OutputDeviceSelector, (CoreDispatcher)Dispatcher);
     midiInputDeviceWatcher  = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), InputDeviceSelector, (CoreDispatcher)Dispatcher);
     midiOutputDeviceWatcher.StartWatcher();
     midiInputDeviceWatcher.StartWatcher();
     this.MidiOutPortChannel = MidiOutPortChannel;
     this.MidiInPortChannel  = MidiInPortChannel;
     Init(deviceName);
 }
Beispiel #16
0
        static MidiIn()
        {
            callbacks        = new ConcurrentDictionary <string, ConcurrentDictionary <Tuple <byte, byte>, List <Action <MidiControlChangeMessage> > > >();
            generalCallbacks = new List <Action <MidiInPort, MidiControlChangeMessage> >();
            watchedDevices   = new List <string>();

            deviceWatcher          = DeviceInformation.CreateWatcher(MidiInPort.GetDeviceSelector());
            deviceWatcher.Added   += Added;
            deviceWatcher.Removed += Removed;

            deviceWatcher.Start();
        }
        /// <summary>
        /// Constructor: Start the device watcher
        /// </summary>
        public Scenario2_ReceiveMIDIMessages()
        {
            this.InitializeComponent();

            // Initialize the list of active MIDI input devices
            this.midiInPorts = new List <MidiInPort>();

            // Set up the MIDI input device watcher
            this.midiInDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), Dispatcher, this.inputDevices);

            // Start watching for devices
            this.midiInDeviceWatcher.Start();
        }
Beispiel #18
0
        public MyMidi(ListBox inBox, ListBox outBox, CoreDispatcher d)
        {
            midiInPortListBox  = inBox;
            midiOutPortListBox = outBox;

            dispatcher = d;

            inputDeviceWatcher = new MyMidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, dispatcher);
            inputDeviceWatcher.StartWatcher();

            outputDeviceWatcher = new MyMidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, dispatcher);
            outputDeviceWatcher.StartWatcher();
        }
Beispiel #19
0
        public async Task <IEnumerable <Device> > ListInputDevices()
        {
            // Find all input MIDI devices
            string midiInputQueryString = MidiInPort.GetDeviceSelector();
            DeviceInformationCollection midiInputDevices = await DeviceInformation.FindAllAsync(midiInputQueryString);

            return(midiInputDevices.Select(x =>
            {
                return new MidiDevice {
                    info = x
                };
            }));
        }
Beispiel #20
0
        public MainPage()
        {
            InitializeComponent();
            Background = new SolidColorBrush(Windows.UI.Colors.LightGray);
            // Keep up to date with connected MIDI devices
            deviceInFinder = new MIDIDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher);
            deviceInFinder.StartWatcher();
            deviceOutFinder = new MIDIDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher);
            deviceOutFinder.StartWatcher();

            DrawLayout();
            uiDrawClock.Tick    += ShowCurChord;
            uiDrawClock.Interval = new TimeSpan(20);
        }
        //
        //
        //
        private async Task PopulateMidiInputDeviceList()
        {
            MidiInputDevicesListBox.Items.Clear();
            //
            midiInputDevicesCollection = await DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector());

            //
            foreach (var device in midiInputDevicesCollection)
            {
                MidiInputDevicesListBox.Items.Add(device.Name);
            }
            //
            MidiInputDevicesListBox.SelectedIndex = 0;
        }
Beispiel #22
0
        public void SetupWatchersAndPorts()
        {
            Action enumerationInComplete = new Action(delegate() {
                Action enumerationOutComplete = new Action(delegate() {
                    SetupMidiPorts();
                });

                outputDeviceWatcher = new MyMidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), enumerationOutComplete);
                outputDeviceWatcher.StartWatcher();
            });

            inputDeviceWatcher = new MyMidiDeviceWatcher(MidiInPort.GetDeviceSelector(), enumerationInComplete);
            inputDeviceWatcher.StartWatcher();
        }
Beispiel #23
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Reading Devices and subscribing to events...");
            string deviceSelector   = MidiInPort.GetDeviceSelector();
            var    midiInputDevices = await DeviceInformation.FindAllAsync(deviceSelector);

            var device = midiInputDevices.FirstOrDefault();

            Console.WriteLine($"Reading from device {device.Name}");

            var port = await MidiInPort.FromIdAsync(device.Id);

            port.MessageReceived += MidiDeviceService_MessageReceived;

            Console.ReadKey();
        }
Beispiel #24
0
        /// <summary>
        /// Gets a launchpad object for a connected device
        /// </summary>
        /// <param name="id">The id of the launchpad</param>
        /// <returns></returns>
        public static async Task <Launchpad> Launchpad(string id)
        {
            List <DeviceInformation> inputs  = (await DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector())).ToList();
            List <DeviceInformation> outputs = (await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector())).ToList();

            // Find the launchpad input
            foreach (var inputDeviceInfo in inputs)
            {
                try
                {
                    if (inputDeviceInfo.Id.Contains(id))
                    {
                        // Find the launchpad output
                        foreach (var outputDeviceInfo in outputs)
                        {
                            // If not a match continue
                            if (!outputDeviceInfo.Id.Contains(id))
                            {
                                continue;
                            }

                            var inPort = await MidiInPort.FromIdAsync(inputDeviceInfo.Id);

                            var outPort = await MidiOutPort.FromIdAsync(outputDeviceInfo.Id);

                            // Return an MK2 if detected
                            if (outputDeviceInfo.Name.ToLower().Contains("mk2"))
                            {
                                return(new LaunchpadMk2(outputDeviceInfo.Name, inPort, outPort));
                            }

                            return(null);
                            // Otherwise return Standard
                            //return new LaunchpadS(outputDeviceInfo.Name, inPort, outPort);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }

            // Return null if no devices matched the device name provided
            return(null);
        }
Beispiel #25
0
        /// <summary>
        /// Constructor: Start the device watcher
        /// </summary>
        public MidiDeviceInput()
        {
            InitializeComponent();

            rootGrid.DataContext = this;

            // Initialize the list of active MIDI input devices
            _midiInPorts = new List <MidiInPort>();

            // Set up the MIDI input device watcher
            _midiInDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), Dispatcher, inputDevices, InputDevices);

            // Start watching for devices
            _midiInDeviceWatcher.Start();

            Unloaded += MidiDeviceInput_Unloaded;
        }
Beispiel #26
0
        // </SnippetEnumerateMidiOutputDevices>



        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            //EnumerateMidiInputDevices();
            //EnumerateMidiOutputDevices();


            // <SnippetStartWatchers>
            inputDeviceWatcher =
                new MyMidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher);

            inputDeviceWatcher.StartWatcher();

            outputDeviceWatcher =
                new MyMidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher);

            outputDeviceWatcher.StartWatcher();
            // </SnippetStartWatchers>
        }
Beispiel #27
0
        public MainPage()
        {
            this.InitializeComponent();

            inputDeviceWatcher =
                new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher);

            inputDeviceWatcher.StartWatcher();

            outputDeviceWatcher =
                new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher);

            outputDeviceWatcher.StartWatcher();

            byte         channel           = 0;
            byte         note              = 60;
            byte         velocity          = 127;
            IMidiMessage midiMessageToSend = new MidiNoteOnMessage(channel, note, velocity);
        }
Beispiel #28
0
        protected override void ProcessRecord()
        {
            string selector;

            switch (DeviceType.ToLower())
            {
            case "inputport":
                selector = MidiInPort.GetDeviceSelector();
                break;

            case "outputport":
                selector = MidiOutPort.GetDeviceSelector();
                break;
            }

            var deviceWatcher = DeviceInformation.CreateWatcher(MidiInPort.GetDeviceSelector());

            var midiDeviceWatcher = new MidiDeviceWatcher(deviceWatcher);

            WriteObject(midiDeviceWatcher);
        }
Beispiel #29
0
        private async void DefaultMidiDevices()
        {
            string midiOutputQueryString = MidiOutPort.GetDeviceSelector();
            string midiInputQueryString  = MidiInPort.GetDeviceSelector();

            // Find all MIDI output and input devices and collect it
            DeviceInformationCollection midiOutDevices = await DeviceInformation.FindAllAsync(midiOutputQueryString);

            DeviceInformationCollection midiInDevices = await DeviceInformation.FindAllAsync(midiInputQueryString);

            // Set the MIDI device from the found MIDI devices
            if (midiInDevices.Count > 0)
            {
                Settings.midiInPort = await MidiInPort.FromIdAsync(midiInDevices[0].Id);
            }

            if (midiOutDevices.Count > 0)
            {
                Settings.midiOutPort = await MidiOutPort.FromIdAsync(midiOutDevices[0].Id);
            }
        }
        /// <summary>
        /// Constructor: Empty device lists, start the device watchers and
        /// set initial states for buttons
        /// </summary>
        public Scenario1_MIDIDeviceEnumeration()
        {
            this.InitializeComponent();

            // Start with a clean slate
            ClearAllDeviceValues();

            // Ensure Auto-detect devices toggle is on
            this.deviceAutoDetectToggle.IsOn = true;

            // Set up the MIDI input and output device watchers
            this.midiInDeviceWatcher  = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), Dispatcher, this.inputDevices);
            this.midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), Dispatcher, this.outputDevices);

            // Start watching for devices
            this.midiInDeviceWatcher.Start();
            this.midiOutDeviceWatcher.Start();

            // Disable manual enumeration buttons
            this.listInputDevicesButton.IsEnabled  = false;
            this.listOutputDevicesButton.IsEnabled = false;
        }