// I don't think this is required RootElement MakeHardware() { int sources = (int)Midi.SourceCount; int destinations = (int)Midi.DestinationCount; var sourcesSection = new Section("Sources"); sourcesSection.AddAll( from x in Enumerable.Range(0, sources) let source = MidiEndpoint.GetSource(x) select(Element) new StringElement(source.DisplayName, source.IsNetworkSession ? "Network" : "Local") ); var targetsSection = new Section("Targets"); targetsSection.AddAll( from x in Enumerable.Range(0, destinations) let target = MidiEndpoint.GetDestination(x) select(Element) new StringElement(target.DisplayName, target.IsNetworkSession ? "Network" : "Local") ); return(new RootElement("Endpoints (" + sources + ", " + destinations + ")") { sourcesSection, targetsSection }); }
void ConnectExistingDevices() { for (int i = 0; i < Midi.SourceCount; i++) { var code = inputPort.ConnectSource(MidiEndpoint.GetSource(i)); if (code != MidiError.Ok) { Console.WriteLine("Failed to connect"); } } }
/// <summary> /// Returns all connected devices. /// </summary> protected override List <LPM.MidiDevice> GetDeviceList() { var ret = new List <LPM.MidiDevice>(); // grab all the input devices for (var i = 0; i < MonoMac.CoreMidi.Midi.SourceCount; i++) { MidiEndpoint src = MidiEndpoint.GetSource(i); var device = new LPM.MidiDevice(); device.ID = GetDeviceID(src); device.Name = device.ID; device.Direction = MidiDirection.Input; ret.Add(device); } // grab all output devices, and combine devices that are // already in the input list for (var i = 0; i < MonoMac.CoreMidi.Midi.DestinationCount; i++) { MidiEndpoint dest = MidiEndpoint.GetDestination(i); string outputID = GetDeviceID(dest); // look for the same device in the inputs LPM.MidiDevice inDevice = null; foreach (var d in ret) { if (d.ID == outputID) { inDevice = d; break; } } // mark as IO device if found in input if (inDevice != null) { inDevice.Direction = MidiDirection.IO; } // otherwise create a new output-only device else { var device = new LPM.MidiDevice(); device.ID = outputID; device.Name = outputID; device.Direction = MidiDirection.Output; ret.Add(device); } } return(ret); }
public void CorrectDisposeTest() { // Test for bug 43582 - https://bugzilla.xamarin.com/show_bug.cgi?id=43582 // This will throw if bug dispose code isn't fixed // System.InvalidOperationException: Handle is not initialized Assert.DoesNotThrow(() => { for (int i = 0; i < Midi.SourceCount; i++) { using (var endpoint = MidiEndpoint.GetSource(i)) { if (endpoint.Handle == 0) { continue; } } } }); }
public void MidiEndPointProperty() { // get one of the endpoints, and set it and get it for (int i = 0; i < Midi.SourceCount; i++) { using (var endpoint = MidiEndpoint.GetSource(i)) { if (endpoint.Handle == 0) { continue; } track.SetDestMidiEndpoint(endpoint); MidiEndpoint outEnpoint; var status = track.GetDestMidiEndpoint(out outEnpoint); Assert.AreEqual(endpoint.Handle, outEnpoint.Handle, "Track endpoint."); } } }
private IEnumerable <IMidiPortDetails> GetInputDevices() { return(Enumerable.Range(0, (int)CoreMidi.Midi.SourceCount).Select(i => (IMidiPortDetails) new CoreMidiPortDetails(MidiEndpoint.GetSource(i))));; }
/// <summary> /// Gets all MIDI resources needed to use the selected device. /// </summary> private void Acquire(LPM.MidiDevice device) { if (device != null) { // setup the input device if (device.CanRead) { _inputEndpoint = null; for (var i = 0; i < MonoMac.CoreMidi.Midi.SourceCount; i++) { MidiEndpoint dest = MidiEndpoint.GetSource(i); if (GetDeviceID(dest) == device.ID) { _inputEndpoint = dest; break; } } if (_inputEndpoint == null) { throw new Exception("Could not find MIDI input device " + device.ID); } // setup the device _inputPort.ConnectSource(_inputEndpoint); // send all input events to Receive() _inputPort.MessageReceived += (object sender, MidiPacketsEventArgs e) => { for (var i = 0; i < e.Packets.Length; i++) { var packet = e.Packets[i]; var managedArray = new byte[packet.Length]; Marshal.Copy(packet.Bytes, managedArray, 0, packet.Length); if (managedArray.Length >= 3) { MidiMessageType type; int channel; MidiHelpers.ParseTypeAndChannel(managedArray[0], out type, out channel); Receive(new MidiMessage() { //Type = managedArray[0].GetMidiMessageType(), //Channel = 0, Type = type, Channel = channel, Pitch = (int)managedArray[1], Velocity = (int)managedArray[2] }); } } }; } else { _inputEndpoint = null; } if (device.CanWrite) { _outputEndpoint = null; for (var i = 0; i < MonoMac.CoreMidi.Midi.DestinationCount; i++) { MidiEndpoint dest = MidiEndpoint.GetDestination(i); if (GetDeviceID(dest) == device.ID) { _outputEndpoint = dest; break; } } if (_outputEndpoint == null) { throw new Exception("Could not find MIDI output device " + device.ID); } } else { _outputEndpoint = null; } } }