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); }
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; }
// 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(); }
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 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 async void OutputDeviceChanged(Picker DeviceSelector) { try { if (!String.IsNullOrEmpty((String)DeviceSelector.SelectedItem)) { var midiOutDeviceInformationCollection = midiOutputDeviceWatcher.DeviceInformationCollection; if (midiOutDeviceInformationCollection == null) { return; } DeviceInformation midiOutDevInfo = midiOutDeviceInformationCollection[DeviceSelector.SelectedIndex]; if (midiOutDevInfo == null) { return; } midiOutPort = (MidiOutPort)await MidiOutPort.FromIdAsync(midiOutDevInfo.Id); if (midiOutPort == null) { System.Diagnostics.Debug.WriteLine("Unable to create MidiOutPort from output device"); return; } } } catch { } }
// 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; } }
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); } }
/// <summary> /// Returns Device Information for all connected Launchpads /// </summary> /// <returns></returns> public static async Task <IEnumerable <DeviceInformation> > GetLaunchpadDeviceInformation() { // Get all output MIDI devices var outputs = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector()); return(outputs.Where(device => device.Name.ToLower().Contains("launchpad"))); }
private async Task LoadInputDevicesAsync() { WriteDebug("Entering LoadInputDevicesAsync"); _devices = new List <MidiDeviceInformation>(); var selector = MidiOutPort.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"); }
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"); } }
/// <summary> /// Query DeviceInformation class for Midi Output devices /// </summary> private async Task EnumerateMidiOutputDevices() { // Clear output devices OutputDevices.Clear(); OutputDeviceProperties.Clear(); outputDeviceProperties.IsEnabled = false; // Find all output MIDI devices string midiOutputQueryString = MidiOutPort.GetDeviceSelector(); DeviceInformationCollection midiOutputDevices = await DeviceInformation.FindAllAsync(midiOutputQueryString); // Return if no external devices are connected, and GS synth is not detected if (midiOutputDevices.Count == 0) { OutputDevices.Add("No MIDI output devices found!"); outputDevices.IsEnabled = false; NotifyUser("Please connect at least one external MIDI device for this demo to work correctly"); return; } // List specific device information for each output device foreach (DeviceInformation deviceInfo in midiOutputDevices) { OutputDevices.Add(deviceInfo.Name); outputDevices.IsEnabled = true; } NotifyUser("MIDI Output 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; }
// All output ports have been enumerated private async void _watcher_OutputPortsEnumerated(MidiDeviceWatcher sender) { foreach (DeviceInformation info in sender.OutputPortDescriptors) { // This diagnostic info is how you can see the IDs of all the ports. System.Diagnostics.Debug.WriteLine("- Output -----"); System.Diagnostics.Debug.WriteLine(info.Name); System.Diagnostics.Debug.WriteLine(info.Id); System.Diagnostics.Debug.WriteLine("--------------"); var port = (MidiOutPort)await MidiOutPort.FromIdAsync(info.Id); // If you don't want the clock on all ports, here's where you'd change the code if (port != null) { _clock.OutputPorts.Add(port); } else { System.Diagnostics.Debug.WriteLine("Failed to create port with id " + info.Id); } } if (_clock.OutputPorts.Count > 0) { System.Diagnostics.Debug.WriteLine("About to create clock."); _clock.SendMidiStartMessage = true; _clock.SendMidiStopMessage = true; } else { System.Diagnostics.Debug.WriteLine("No output ports to wire up."); } }
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 UwpMidiAccess(Windows.UI.Core.CoreDispatcher dispatcher) { _midiInDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), dispatcher); _midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), dispatcher); _midiInDeviceWatcher.Start(); _midiOutDeviceWatcher.Start(); }
protected override async Task ProcessRecordAsync() { if (!string.IsNullOrWhiteSpace(Id)) { var port = await MidiOutPort.FromIdAsync(Id); if (port != null) { WriteDebug("Acquired output port: " + port.DeviceId); } else { throw new ArgumentException("No output port available with that Id. You can get the Id through the MidiDeviceInformation returned from Get-Midi[Input|Output]DeviceInformation.", "Id"); } // powershell has problems with some WinRT/UWP objects, so better to wrap it here var outputPort = new MidiOutputPort(port); WriteObject(outputPort); } else { throw new ArgumentException("Parameter required. You can get the Id through the MidiDeviceInformation returned from Get-Midi[Input|Output]DeviceInformation.", "Id"); } }
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); } }
/// <summary> /// MIDIの初期化 /// </summary> /// <param name="portnum"></param> public MidiManager() { int NumOfMode = ModeList.Length; //モードの数だけトラック配列の要素数を用意する tracks = new MidiTrack[NumOfMode]; //モードの数だけコード進行配列の要素数を用意する chordProgList = new List <Chord> [NumOfMode]; //コード進行配列の初期化 for (int i = 0; i < NumOfMode; i++) { tracks[i] = new MidiTrack(); chordProgList[i] = new List <Chord>(); } //Modeの数だけコード進行配列の初期化 for (int mode = 0; mode < NumOfMode; mode++) { tracks[mode].Insert(new TempoEvent() { Tempo = 120, Tick = 0 }); //コードの開始位置を0に初期化 int ChordTickFromStart = 0; //入力コード進行(chordProgress)からコード進行リストを初期化する foreach (String chordName in inputedChord) { //Chordの初期化 Chord chord = new Chord(chordName, ChordTickFromStart, mode); //Chordをインスタンス化 chordProgList[mode].Add(chord); //Modeに対応するインデックスのコード進行配列chordを追加 ChordTickFromStart += chord.Gate; //次のchordの開始タイミングにする //Trackの初期化 tracks[mode].Insert(chord.Base); //ベース音の挿入 foreach (var note in chord.NoteList) { tracks[mode].Insert(note); //伴奏音の挿入 } } } port = new MidiOutPort(0); try { port.Open(); } catch { Console.WriteLine("no such port exists"); return; } //midiDataにtrackを対応付け midiData = new MidiData(); midiData.Tracks.Add(tracks[MODE_QUARTER]); // テンポマップを作成 domain = new MidiFileDomain(midiData); }
public async Task <IMidiOutputPort> OpenOutput(int portNumber) { var port = OutputPortInfos.First(p => p.PortNumber == portNumber); var result = MidiOutPort.FromIdAsync(port.Id); await result; return(new WindowsMidiOutputPort(result.GetResults())); }
/// <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 async Task <IMidiOutput> OpenOutputAsync(string portId) { var outputs = await GetOutputsAsync(); var details = outputs.Cast <UwpMidiPortDetails> ().FirstOrDefault(d => d.Id == portId); var output = MidiOutPort.FromIdAsync(portId).GetResults(); return(new UwpMidiOutput(output, details)); }
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 }
/// <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..."); }
public void Dispose_FreshInstance_StatusReflectsState() { MidiOutPort port = null; using (port = CreateMidiOutPort()) { // dispose } port.Status.Should().Be(MidiPortStatus.None); }
public void Dispose_FreshInstance_StatusReflectsState() { MidiOutPort port = null; using (port = CreateMidiOutPort()) { // dispose } Assert.IsTrue(port.Status == MidiPortStatus.None); }
// 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; }
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); } }
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); }
public void Dispose_AccessDisposedPort_ThrowsException() { MidiOutPort port = null; using (port = CreateMidiOutPort()) { } // Dispose port.Open(0); Assert.Fail(); }
public Form1() { InitializeComponent(); small = GetIcon(ShellIconSize.SmallIcon); large = GetIcon(ShellIconSize.LargeIcon); //set normal icons SendMessage(this.Handle, WM_SETICON, SHGFI_LARGEICON, small.Handle); SendMessage(this.Handle, WM_SETICON, SHGFI_SMALLICON, large.Handle); //fully hide window but at least load it this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; trayMenu = new ContextMenu(); trayMenu.MenuItems.Add("Exit", trayIcon_Close); trayIcon = new NotifyIcon(); trayIcon.Text = this.Text; if (SystemInformation.SmallIconSize.Width == 16 && SystemInformation.SmallIconSize.Height == 16) //get 16x16 trayIcon.Icon = new Icon(small, SystemInformation.SmallIconSize); else //just calculate from base 32x32 icon to (hopefully) look better trayIcon.Icon = new Icon(large, SystemInformation.SmallIconSize); // Add menu to tray icon and show it. trayIcon.ContextMenu = trayMenu; trayIcon.Visible = true; trayIcon.MouseClick += trayIcon_MouseClick; devInBox.DropDownStyle = ComboBoxStyle.DropDownList; devOutBox.DropDownStyle = ComboBoxStyle.DropDownList; inDevs = new List<int>(); outDevs = new List<int>(); mahPort = new TeVirtualMIDI(pString); inPort = new MidiInPort(); outPort = new MidiOutPort(); pthrough = new Thread(new ThreadStart(readInput)); config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); inPort.Successor = new MyReceiver(); this.Load += onLoad; this.FormClosed += onClosed; this.Resize += onResize; }