예제 #1
0
        // Called when app is suspending
        private void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
        {
            // Clean up out watchers
            inputDeviceWatcher.StopWatcher();
            inputDeviceWatcher = null;

            outputDeviceWatcher.StopWatcher();
            outputDeviceWatcher = null;

            // Remove EventHandlers and try dispose of input & output ports
            try
            {
                midiInPort.MessageReceived -= MidiInPort_MessageReceived;
                midiInPort.Dispose();
                midiInPort = null;
            }
            catch
            {
            }

            try
            {
                midiOutPort.Dispose();
                midiOutPort = null;
            }
            catch
            {
            }
        }
예제 #2
0
        // Handler for SelectionChanged on MIDI Output ComboBox
        private async void MidiOutPortComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var deviceInformationCollection = outputDeviceWatcher.DeviceInformationCollection;

            if (deviceInformationCollection == null)
            {
                return;
            }

            DeviceInformation devInfo;

            if (midiOutPortComboBox.SelectedIndex < 0)
            {
                devInfo = null;
            }
            else
            {
                devInfo = deviceInformationCollection[midiOutPortComboBox.SelectedIndex];
            }

            if (devInfo == null)
            {
                return;
            }

            midiOutPort = await MidiOutPort.FromIdAsync(devInfo.Id);

            if (midiOutPort == null)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create MidiOutPort from output device");
                return;
            }
        }
예제 #3
0
        public static uint midiOutOpen(out IntPtr lphmo, int uDeviceID, MidiWinApi.MidiMessageCallback dwCallback, IntPtr dwInstance, uint dwFlags)
        {
            if (s_midiOutPort != null)
            {
                lphmo = new IntPtr(uDeviceID);
                return(MidiWinApi.MMSYSERR_NOERROR);
            }

            try
            {
                s_midiOutPort = MidiOutPort.FromIdAsync(GetDevices()[uDeviceID].Id).AsTask().Result;

                lphmo = new IntPtr(uDeviceID);

                if (s_midiOutPort == null)
                {
                    return(MidiWinApi.MMSYSERR_ERROR);
                }
            }
            catch (Exception)
            {
                lphmo = new IntPtr(uDeviceID);
                return(MidiWinApi.MMSYSERR_ERROR);
            }

            return(MidiWinApi.MMSYSERR_NOERROR);
        }
예제 #4
0
        private async void midiOutPortListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var deviceInformationCollection = outputDeviceWatcher.DeviceInformationCollection;

            if (deviceInformationCollection == null)
            {
                return;
            }

            DeviceInformation devInfo = deviceInformationCollection[midiOutPortListBox.SelectedIndex];

            if (devInfo == null)
            {
                return;
            }

            midiOutPort = await MidiOutPort.FromIdAsync(devInfo.Id);

            if (midiOutPort == null)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create MidiOutPort from output device");
                return;
            }

            else
            {
                byte         channel           = 0;
                byte         note              = 60;
                byte         velocity          = 127;
                IMidiMessage midiMessageToSend = new MidiNoteOnMessage(channel, note, velocity);

                midiOutPort.SendMessage(midiMessageToSend);
            }
        }
예제 #5
0
        public async Task InitOutput(String outputDeviceName)
        {
            DeviceInformationCollection midiOutputDevices = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector());

            DeviceInformation midiOutDevInfo = null;

            foreach (DeviceInformation device in midiOutputDevices)
            {
                if (device.Name.Contains(outputDeviceName) && !device.Name.Contains("CTRL"))
                {
                    midiOutDevInfo = device;
                    break;
                }
            }

            if (midiOutDevInfo != null)
            {
                midiOutPort = await MidiOutPort.FromIdAsync(midiOutDevInfo.Id);
            }

            if (midiOutPort == null)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create MidiOutPort from output device");
            }
        }
예제 #6
0
 public MIDITransmitter(IMidiOutPort midiOutPort)
 {
     this.midiOutPort    = midiOutPort;
     dispatcher.Tick    += TransmitTick;
     dispatcher.Interval = new TimeSpan(20);
     dispatcher.Start();
 }
예제 #7
0
        private async void SelectMidiOutputDevices()
        {
            _midiClock.OutputPorts.Clear();

            IMidiOutPort port = null;

            foreach (var descriptor in _midiWatcher.OutputPortDescriptors)
            {
                System.Diagnostics.Debug.WriteLine(descriptor.Name);

                if (descriptor.Name.Contains(_midiDeviceName))
                {
                    port = await MidiOutPort.FromIdAsync(descriptor.Id);

                    System.Diagnostics.Debug.WriteLine("Found " + _midiDeviceName);

                    break;
                }
            }

            if (port != null)
            {
                _midiClock.OutputPorts.Add(port);
                System.Diagnostics.Debug.WriteLine("Added " + _midiDeviceName);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Cound not open " + _midiDeviceName);
            }
        }
예제 #8
0
        /// <summary>
        /// Method to enumrate all MIDI output devices connected and to setup the the first MIDI output device found.
        /// </summary>
        /// <returns></returns>
        private async Task EnumerateMidiOutputDevices()
        {
            // Create the query string for finding all MIDI output devices using MidiOutPort.GetDeviceSelector()
            string midiOutportQueryString = MidiOutPort.GetDeviceSelector();

            // Find all MIDI output devices and collect it in a DeviceInformationCollection using FindAllAsync
            DeviceInformationCollection midiOutputDevices = await DeviceInformation.FindAllAsync(midiOutportQueryString);

            // If the size of the midiOutputDevice colloction is xero,
            // set the StatusTextBlock foreground color to red and the text property to "No MIDI output devices found"
            // and return.
            // Else set the StatusTextBlock foreground color to green and the text property to midiOutputdevices[0].Name
            if (midiOutputDevices.Count == 0)
            {
                // Set the StatusTextBlock foreground color to red
                StatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);

                // Set the StatusTextBlock text to "No MIDI output devices found"
                StatusTextBlock.Text = "No MIDI output devices found";
                return;
            }
            else
            {
                // Set the StatusTextBlock foreground color to green
                StatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);

                // Set the StatusTextBlock text to the name of the first item in midiOutputDevices collection
                //StatusTextBlock.Text = midiOutputDevices[0].Name;
            }

            // Create an instance of DeviceInformation and set it to the first midi device in DeviceInformationCollection, midiOutputDevices
            DeviceInformation devInfo = midiOutputDevices[0];

            // Return if DeviceInformation, devInfo, is null
            if (devInfo == null)
            {
                // Set the midi status TextBlock
                StatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                StatusTextBlock.Text       = "No device information of MIDI output";
                return;
            }

            // Set the IMidiOutPort for the output midi device by calling MidiOutPort.FromIdAsync passing the Id property of the DevicInformation
            midiOutPort = await MidiOutPort.FromIdAsync(devInfo.Id);

            // Return if midiOutPort is null
            if (midiOutPort == null)
            {
                // Set the midi status TextBlock
                StatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                StatusTextBlock.Text       = "Unable to create MidiOutPort from output device";
                return;
            }

            // Send the Program Change midi message to port of the output midi device
            // to set the initial instrument to Acoustic Grand Piano.
            midiOutPort.SendMessage(instrumentChange);
        }
        public LaunchpadMk2(string name, MidiInPort inPort = null, IMidiOutPort outPort = null)
        {
            Name         = name;
            this.inPort  = inPort;
            this.outPort = outPort;
            gridButtons  = new List <LaunchpadMk2Button>();
            resetCount   = 0;
            sideButtons  = new List <LaunchpadMk2Button>();
            topButtons   = new List <LaunchpadMk2TopButton>();
            Grid         = new LaunchpadMk2Button[8, 8];
            GridBuffer   = new Color[8, 8];

            BuildButtons();

            // Process resets triggered from launchpad
            resetTimer = new Timer((state) => {
                // If the user is pressing the 4 corner grid buttons
                if (Grid[0, 0].State == LaunchpadButtonState.Pressed &&
                    Grid[0, 7].State == LaunchpadButtonState.Pressed &&
                    Grid[7, 7].State == LaunchpadButtonState.Pressed &&
                    Grid[7, 0].State == LaunchpadButtonState.Pressed)
                {
                    Debug.WriteLine("Reset in " + (10 - resetCount).ToString() + " seconds.");

                    // Increase the reset count
                    resetCount++;

                    // If the user has held the buttons for 10 seconds
                    if (resetCount > 10)
                    {
                        Debug.WriteLine("Launchpad was reset.");

                        // Reset the count
                        resetCount = 0;

                        // Notify anyone interested in the event
                        whenReset.OnNext(Unit.Default);
                    }
                }
                else // If the user is not pressing the 4 corner buttons
                {
                    // Reset the count
                    resetCount = 0;
                }
            }, null, 0, 1000);

            // Flag as simulated mode if no connection provided
            IsSimulated = inPort == null || outPort == null;

            if (!IsSimulated)
            {
                // Process messages from device
                inPort.MessageReceived += InPort_MessageReceived;
            }
        }
예제 #10
0
        /// <summary>
        /// Create a new MidiOutPort for the selected device
        /// </summary>
        /// <param name="sender">Element that fired the event</param>
        /// <param name="e">Event arguments</param>
        private async void outputDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Get the selected output MIDI device
            int selectedOutputDeviceIndex = outputDevices.SelectedIndex;

            messageType.IsEnabled   = false;
            JingleBells.IsEnabled   = false;
            HappyBirthday.IsEnabled = false;
            resetButton.IsEnabled   = false;

            // Try to create a MidiOutPort
            if (selectedOutputDeviceIndex < 0)
            {
                NotifyUser("Select a MIDI output device to be able to send messages to it");
                return;
            }

            DeviceInformationCollection devInfoCollection = _midiOutDeviceWatcher.GetDeviceInformationCollection();

            if (devInfoCollection == null)
            {
                NotifyUser("Device not found!");
                return;
            }

            DeviceInformation devInfo = devInfoCollection[selectedOutputDeviceIndex];

            if (devInfo == null)
            {
                NotifyUser("Device not found!");
                return;
            }

            _currentMidiOutputDevice = await MidiOutPort.FromIdAsync(devInfo.Id);

            if (_currentMidiOutputDevice == null)
            {
                NotifyUser("Unable to create MidiOutPort from output device");
                return;
            }

            // We have successfully created a MidiOutPort; add the device to the list of active devices
            if (!_midiOutPorts.Contains(_currentMidiOutputDevice))
            {
                _midiOutPorts.Add(_currentMidiOutputDevice);
            }

            // Enable message type list & reset button
            messageType.IsEnabled   = true;
            JingleBells.IsEnabled   = true;
            HappyBirthday.IsEnabled = true;
            resetButton.IsEnabled   = true;

            NotifyUser("Output Device selected successfully! Waiting for message type selection...");
        }
예제 #11
0
        public static uint midiOutClose(IntPtr hmo)
        {
            if (s_midiOutPort != null)
            {
                s_midiOutPort.Dispose();
            }

            s_midiOutPort = null;

            return(MidiWinApi.MMSYSERR_NOERROR);
        }
예제 #12
0
        private async void MidiOutputList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var info = MidiOutputList.SelectedItem as DeviceInformation;

            if (info != null)
            {
                _port = await MidiOutPort.FromIdAsync(info.Id);

                System.Diagnostics.Debug.WriteLine("MIDI Port Selected: " + info.Name);
            }
        }
예제 #13
0
        /// <summary>
        /// Passes a MIDI output port to the MIDITransmitter
        /// </summary>
        /// <param name="portID">the port that is passed</param>
        /// <returns>task</returns>
        private async Task SetTransmitter(string portID)
        {
            IMidiOutPort transmitting = await MidiOutPort.FromIdAsync(portID);

            if (transmitting == null)
            {
                Debug.WriteLine("Unable to create MIDI-out port.");
                return;
            }

            transmitter = new MIDITransmitter(transmitting);
        }
예제 #14
0
        private async void MidiDeviceSelected(object sender, SelectionChangedEventArgs e)
        {
            var selectedDevice = (MidiDeviceInfo)OutputDevicesList.SelectedItem;

            if (selectedDevice != null)
            {
                _currentDevice?.Dispose();
                _currentDevice = await MidiOutPort.FromIdAsync(selectedDevice.Id);

                KeyboardKeys.IsEnabled = true;
            }
        }
예제 #15
0
 public void ResetMidiOutput()
 {
     try
     {
         if (midiOutPort != null)
         {
             midiOutPort.Dispose();
             midiOutPort = null;
             GC.Collect();
         }
     }
     catch { }
 }
        /// <summary>
        /// Sends the control change currently being composed. A control number
        /// and value must be set before sending the event.
        /// </summary>
        /// <returns>The currently selected <see cref="IMidiOutputDevice"/>.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the control
        /// number or value have not been set yet.</exception>
        public async Task <IMidiOutputDevice> SendAsync()
        {
            if (this._controlNumber == null || this._value == null)
            {
                throw new InvalidOperationException("Both a control number and a value are required.");
            }

            IMidiOutPort port = await MidiOutPort.FromIdAsync(this._device.DeviceId);

            port.SendMessage(new MidiControlChangeMessage(this._channel, this._controlNumber.Value, this._value.Value));

            return(this._device);
        }
        /// <summary>
        /// Sends the patch change currently being composed. A patch number must be set
        /// before the sending the event.
        /// </summary>
        /// <returns>The currently selected <see cref="IMidiOutputDevice"/>.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the control
        /// number or value have not been set yet.</exception>
        public async Task <IMidiOutputDevice> SendAsync()
        {
            if (this._patchNumber == null)
            {
                throw new InvalidOperationException("A patch number is required");
            }

            IMidiOutPort port = await MidiOutPort.FromIdAsync(this._device.DeviceId);

            port.SendMessage(new MidiProgramChangeMessage(this._channel, this._patchNumber.Value));

            return(this._device);
        }
예제 #18
0
        public void PlayMessageList(IMidiOutPort midiOutPort)
        {
            int numRows = MessageList.Count;

            for (int i = 0; i < numRows; i++)
            {
                var msg = MessageList[i];
                if (msg.Number != 0)
                {
                    var noteMessage = new MidiNoteOnMessage(msg.Channel, msg.Number, msg.Velocity);
                    midiOutPort.SendMessage(noteMessage);
                }
            }
        }
예제 #19
0
        /// <summary>
        /// Eventhandler to clean up the MIDI connection, when the app is suspended.
        /// The object midiOutPort is disposed and set to null
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void App_Suspending(object sender, SuspendingEventArgs e)
        {
            try
            {
                // Dispose the Midi Output port
                midiOutPort.Dispose();

                // Set the midiOutPort to null
                midiOutPort = null;
            }
            catch
            {
                // Do noting. A cleanup has already been made
            }
        }
예제 #20
0
        public void TeardownWatchers()
        {
            inputDeviceWatcher.StopWatcher();
            inputDeviceWatcher = null;

            outputDeviceWatcher.StopWatcher();
            outputDeviceWatcher = null;

            midiInPort.MessageReceived -= MidiInPort_MessageReceived;
            midiInPort.Dispose();
            midiInPort = null;

            midiOutPort.Dispose();
            midiOutPort = null;
        }
        /// <summary>
        /// Create a new MidiOutPort for the selected device
        /// </summary>
        /// <param name="sender">Element that fired the event</param>
        /// <param name="e">Event arguments</param>
        private async void outputDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Get the selected output MIDI device
            int selectedOutputDeviceIndex = this.outputDevices.SelectedIndex;

            // Try to create a MidiOutPort
            if (selectedOutputDeviceIndex < 0)
            {
                this.rootPage.NotifyUser("Select a MIDI output device to be able to send messages to it", NotifyType.StatusMessage);
                return;
            }

            DeviceInformationCollection devInfoCollection = this.midiOutDeviceWatcher.GetDeviceInformationCollection();

            if (devInfoCollection == null)
            {
                this.rootPage.NotifyUser("Device not found!", NotifyType.ErrorMessage);
                return;
            }

            DeviceInformation devInfo = devInfoCollection[selectedOutputDeviceIndex];

            if (devInfo == null)
            {
                this.rootPage.NotifyUser("Device not found!", NotifyType.ErrorMessage);
                return;
            }

            this.currentMidiOutputDevice = await MidiOutPort.FromIdAsync(devInfo.Id);

            if (this.currentMidiOutputDevice == null)
            {
                this.rootPage.NotifyUser("Unable to create MidiOutPort from output device", NotifyType.ErrorMessage);
                return;
            }

            // We have successfully created a MidiOutPort; add the device to the list of active devices
            if (!this.midiOutPorts.Contains(this.currentMidiOutputDevice))
            {
                this.midiOutPorts.Add(this.currentMidiOutputDevice);
            }

            // Enable message type list & reset button
            this.messageType.IsEnabled = true;
            this.resetButton.IsEnabled = true;

            this.rootPage.NotifyUser("Output Device selected successfully! Waiting for message type selection...", NotifyType.StatusMessage);
        }
예제 #22
0
        public Orchestra(string deviceName, IMidiOutPort port) : base(deviceName, port)
        {
            const byte kMikuVelocity = 0;
            const byte kInstVelocity = 127;

            // element num less than 16
            channels = new List <Instrument> {
                /*
                 * new Instrument( 0, 12, 0),// Hatsune Miku
                 * //new Instrument( 33, -12, 127),// Accoustic Bass
                 * //new Instrument( 43, -12, 127),//Cello
                 * new Instrument( 44, -24, 127),// Contrabass
                 * //new Instrument( 58, -12, 127),// trombone
                 * new Instrument( 58, -24, 127),// tuba
                 * //new Instrument( 61, -12, 127),// horn
                 * //new Instrument( 71, -24, 127),// basoon
                 * new Instrument( 49, 0, 127),// String Ensemble1
                 * //new Instrument( 50, 0, 127),// String Ensemble 2
                 * //new Instrument( 56, 0, 127),// ochestra all
                 * //new Instrument( 57, 0, 127),// trumpet
                 * new Instrument( 62, 0, 127),// brass section
                 * //new Instrument( 69, 0, 127),// Oboe
                 * //new Instrument( 70, 0, 127),// english horn
                 * //new Instrument( 72, 0, 127),// clarinet
                 * new Instrument( 55, 12, 127),// voice ooh
                 * //new Instrument( 41, 12, 127),// Violin
                 * //new Instrument( 42, 12, 127),// Viola
                 * new Instrument( 73, 12, 127),// piccolo
                 * //new Instrument( 74, 12, 127),// flute*/
                new Instrument(0, 12, kMikuVelocity),   // Hatsune Miku, C
                new Instrument(44, -29, kInstVelocity), // Contrabass, G
                new Instrument(44, -24, kInstVelocity), // Contrabass, C
                new Instrument(44, -20, kInstVelocity), // Contrabass, E
                new Instrument(58, -29, kInstVelocity), // tuba, G
                new Instrument(58, -24, kInstVelocity), // tuba, C
                new Instrument(58, -20, kInstVelocity), // tuba, E
                new Instrument(49, -5, kInstVelocity),  // String Ensemble1, G
                new Instrument(49, 0, kInstVelocity),   // String Ensemble1, C
                new Percussion(0, 49, kInstVelocity),   // symbal
                new Instrument(62, 0, kInstVelocity),   // brass section, C
                new Instrument(62, 4, kInstVelocity),   // brass section, E
                new Instrument(69, 7, kInstVelocity),   // Oboe, G
                new Instrument(74, 12, kInstVelocity),  // flute, C
                new Instrument(73, 16, kInstVelocity),  // piccolo, E
            };
        }
예제 #23
0
        private void CleanUp()
        {
            // <SnippetCleanUp>
            inputDeviceWatcher.StopWatcher();
            inputDeviceWatcher = null;

            outputDeviceWatcher.StopWatcher();
            outputDeviceWatcher = null;

            midiInPort.MessageReceived -= MidiInPort_MessageReceived;
            midiInPort.Dispose();
            midiInPort = null;

            midiOutPort.Dispose();
            midiOutPort = null;
            // </SnippetCleanUp>
        }
        public async Task InitializeAsync(string deviceName)
        {
            var devices = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector()).AsTask();

            var devInfo = devices?.FirstOrDefault(d => d.Name == deviceName);

            if (devInfo == null)
            {
                throw new Exception($"Device {deviceName} not found.");
            }

            currentMidiOutputDevice = await MidiOutPort.FromIdAsync(devInfo.Id).AsTask();

            if (currentMidiOutputDevice == null)
            {
                throw new Exception($"Midi output port could not be found for device {deviceName}.");
            }
        }
예제 #25
0
        public bool PlayCurrentColumn(IMidiOutPort midiOutPort)
        {
            var start = (CurrentColumn * _rows);
            var end   = start + _cols;

            for (int i = start; i < end; i++)
            {
                var msg = MessageBlock[i];
                if (msg.Number != 0)
                {
                    var noteMessage = new MidiNoteOnMessage(msg.Channel, msg.Number, msg.Velocity);
                    midiOutPort.SendMessage(noteMessage);
                }
            }
            CurrentColumn++;
            if (CurrentColumn >= _cols)
            {
                CurrentColumn = 0;
                return(true);
            }
            return(false);
        }
예제 #26
0
        /// <summary>
        /// Handles midi creation on navigated to
        /// </summary>
        /// <param name="e"></param>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            LoadPreset(0);
            if (e.Parameter is int)
            {
                LoadPreset((int)e.Parameter);
            }

            // Find Microsoft synth and instantiate midi
            DeviceInformationCollection deviceInformationCollection = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector());

            DeviceInformation synthObject = deviceInformationCollection.FirstOrDefault(x => x.Name == "Microsoft GS Wavetable Synth");

            this.synth = await MidiOutPort.FromIdAsync(synthObject.Id);

            if (this.synth == null)
            {
                _ = await new MessageDialog("Could not find Microsoft GS Wavetable Synth.  Failed to open MIDI port.", "Error Starting App").ShowAsync();
            }

            base.OnNavigatedTo(e);
        }
예제 #27
0
        public MainPage()
        {
            this.InitializeComponent();
            App.Current.Suspending += Current_Suspending;
            mArduino        = new ArduinoManager();
            mGPIO           = new GPIOManager();
            mGameNoteIndexs = new int[5] {
                0, 0, 0, 0, 0
            };
            mCurrentGameNote = new MidiGameNote[5];
            mIsInited        = false;
            mIsPlaying       = false;


            Task.Run(async() =>
            {
                SMFReader r = new SMFReader();
                mSMF        = await r.Read(@"Assets\out.mid");
                var w       = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), Dispatcher);
                w.Start();
                var col  = w.GetDeviceInformationCollection();
                var l    = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector());
                MIDIPort = await MidiOutPort.FromIdAsync(l[0].Id);
                await mArduino.Init();
                await mGPIO.Init(GpioController.GetDefault());
                mGPIO.MidiButtonChanged += MGPIO_MidiButtonChanged;
                mGPIO.JoyButtonChanged  += MGPIO_JoyButtonChanged;
                mPlayer                   = new SMFPlayer(mSMF, MIDIPort);
                mPlayer.OnLED            += Player_OnLED;
                mPlayer.OnBarBeatChanged += Player_BarBeatChanged;
                mPlayer.OnTempoChanged   += Player_OnTempoChanged;
                mGPIO.Ack();
                mIsInited = true;
            });
            mVolTimer          = new DispatcherTimer();
            mVolTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            mVolTimer.Tick    += MVolTimer_Tick;
            mVolTimer.Start();
        }
        /// <summary>
        /// Create a launchpad instance
        /// </summary>
        /// <param name="name">The name of the launchpad. Often 'Launchpad (1)'.</param>
        public LaunchpadS(string name, MidiInPort inPort, IMidiOutPort outPort)
        {
            Name               = name;
            this.inPort        = inPort;
            this.outPort       = outPort;
            effectsDisposables = new Dictionary <ILaunchpadEffect, IDisposable>();
            effectsTimers      = new Dictionary <ILaunchpadEffect, Timer>();
            gridButtons        = new List <LaunchpadButton>();
            sideButtons        = new List <LaunchpadButton>();
            topButtons         = new List <LaunchpadTopButton>();
            Effects            = new ObservableCollection <ILaunchpadEffect>();

            // Create all the grid buttons
            for (var y = 0; y < 8; y++)
            {
                for (var x = 0; x < 8; x++)
                {
                    gridButtons.Add(new LaunchpadButton((byte)0, (byte)(y * 16 + x), (byte)LaunchpadColor.Off, outPort));
                }
            }

            // Create all the side buttons
            for (var x = 8; x < 120; x += 16)
            {
                sideButtons.Add(new LaunchpadButton((byte)0, (byte)x, (byte)LaunchpadColor.Off, outPort));
            }

            // Create all the top buttons
            for (var x = 104; x < 111; x++)
            {
                topButtons.Add(new LaunchpadTopButton((byte)x, (byte)LaunchpadColor.Off, outPort));
            }

            // Process messages from device
            inPort.MessageReceived += InPort_MessageReceived;
        }
예제 #29
0
 internal UwpMidiOutput(IMidiOutPort output, UwpMidiPortDetails details)
 {
     this.output = output;
     Details     = details;
     Connection  = MidiPortConnectionState.Open;
 }
        /// <summary>
        /// Create a new MidiOutPort for the selected device
        /// </summary>
        /// <param name="sender">Element that fired the event</param>
        /// <param name="e">Event arguments</param>
        private async void outputDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Get the selected output MIDI device
            int selectedOutputDeviceIndex = this.outputDevices.SelectedIndex;

            // Try to create a MidiOutPort
            if (selectedOutputDeviceIndex < 0)
            {
                this.rootPage.NotifyUser("Select a MIDI output device to be able to send messages to it", NotifyType.StatusMessage);
                return;
            }

            DeviceInformationCollection devInfoCollection = this.midiOutDeviceWatcher.GetDeviceInformationCollection();
            if (devInfoCollection == null)
            {
                this.rootPage.NotifyUser("Device not found!", NotifyType.ErrorMessage);
                return;
            }

            DeviceInformation devInfo = devInfoCollection[selectedOutputDeviceIndex];
            if (devInfo == null)
            {
                this.rootPage.NotifyUser("Device not found!", NotifyType.ErrorMessage);
                return;
            }

            this.currentMidiOutputDevice = await MidiOutPort.FromIdAsync(devInfo.Id);
            if (this.currentMidiOutputDevice == null)
            {
                this.rootPage.NotifyUser("Unable to create MidiOutPort from output device", NotifyType.ErrorMessage);
                return;
            }
            
            // We have successfully created a MidiOutPort; add the device to the list of active devices
            if (!this.midiOutPorts.Contains(this.currentMidiOutputDevice))
            {
                this.midiOutPorts.Add(this.currentMidiOutputDevice);
            }

            // Enable message type list & reset button
            this.messageType.IsEnabled = true;
            this.resetButton.IsEnabled = true;

            this.rootPage.NotifyUser("Output Device selected successfully! Waiting for message type selection...", NotifyType.StatusMessage);
        }
예제 #31
0
        public async void SetupMidiPorts()
        {
            var inDeviceInformationCollection  = inputDeviceWatcher.DeviceInformationCollection;
            var outDeviceInformationCollection = outputDeviceWatcher.DeviceInformationCollection;

            if (inDeviceInformationCollection == null || outDeviceInformationCollection == null)
            {
                Console.WriteLine("Could not find any MIDI devices.");
                SetupComplete = true;
                return;
            }

            DeviceInformation inDevInfo          = null;
            string            midiControllerName = "X-TOUCH MINI";

            foreach (var info in inDeviceInformationCollection)
            {
                if (info.Name.Contains(midiControllerName))
                {
                    inDevInfo = info;
                }
            }
            DeviceInformation outDevInfo = null;

            foreach (var info in outDeviceInformationCollection)
            {
                if (info.Name.Contains(midiControllerName))
                {
                    outDevInfo = info;
                }
            }

            if (inDevInfo == null || outDevInfo == null)
            {
                Console.WriteLine("Could not find a MIDI device with name: " + midiControllerName);
                SetupComplete = true;
                return;
            }

            midiInPort = await MidiInPort.FromIdAsync(inDevInfo.Id);

            if (midiInPort == null)
            {
                Console.WriteLine("Unable to create MidiInPort from input device " + inDevInfo.Name);
                SetupComplete = true;
                return;
            }
            midiInPort.MessageReceived += MidiInPort_MessageReceived;

            midiOutPort = await MidiOutPort.FromIdAsync(outDevInfo.Id);

            if (midiOutPort == null)
            {
                Console.WriteLine("Unable to create MidiOutPort from output device " + outDevInfo.Name);
                SetupComplete = true;
                return;
            }

            Console.WriteLine("Sucessfully found MIDI device with name: " + inDevInfo.Name);

            // Sending these MIDI messages to reset the knobs on this thread sometimes causes
            // a cyclic redundacny check error. Solution might be to simply call this reset sometime later...
            // Maybe from the main thread after setup is complete?
            // Or maybe this only happens the first time after resuming from sleep? Maybe because I'm not
            // cleaning up resources properly?
            for (byte controller = 0; controller < 18; controller++)
            {
                ResetKnob(controller);
            }

            SetupComplete = true;
        }
 public MidiOutputPort(IMidiOutPort port)
 {
     RawPort = port;
 }