Element MakeEndpoint(MidiEndpoint endpoint) { Section s; var root = new RootElement(endpoint.Name) { (s = new Section("Properties") { new StringElement("Driver Owner", endpoint.DriverOwner), new StringElement("Manufacturer", endpoint.Manufacturer), new StringElement("MaxSysExSpeed", endpoint.MaxSysExSpeed.ToString()), new StringElement("Network Session", endpoint.IsNetworkSession ? "yes" : "no") }) }; try { s.Add(new StringElement("Offline", endpoint.Offline ? "yes" : "no")); } catch { } try { s.Add(new StringElement("Receive Channels", endpoint.ReceiveChannels.ToString())); } catch { } try { s.Add(new StringElement("Transmit Channels", endpoint.TransmitChannels.ToString())); } catch { } return(root); }
// 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 }); }
private MidiInPort(string deviceId, MidiEndpoint endpoint) { DeviceId = deviceId; _endpoint = endpoint; _client = new MidiClient(Guid.NewGuid().ToString()); _port = _client.CreateInputPort(_endpoint.EndpointName); }
public MusicPlayerStatus SetMidiEndpoint(MidiEndpoint endpoint) { if (endpoint == null) { throw new ArgumentNullException("endpoint"); } return(MusicSequenceSetMIDIEndpoint(handle, endpoint.handle)); }
public MusicPlayerStatus GetDestMidiEndpoint(out MidiEndpoint outEndpoint) { MidiEndpointRef midiHandle; var result = MusicTrackGetDestMIDIEndpoint(handle, out midiHandle); outEndpoint = (result == MusicPlayerStatus.Success)? new MidiEndpoint(midiHandle): null; return(result); }
public MusicPlayerStatus SetMidiEndpoint(MidiEndpoint endpoint) { if (endpoint is null) { ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(endpoint)); } return(MusicSequenceSetMIDIEndpoint(Handle, endpoint.handle)); }
public IOSMidiInputPort(CMidiPort port, MidiEndpoint endpoint, MidiPortDetails details) : base(details) { this.port = port; this.endpoint = endpoint; endpoint.MessageReceived += (sender, e) => MessageReceived( sender, new MidiMessageEventArgs(e.Packets.Select(p => new MidiMessage(new ArraySegment <byte> (GetBytes(p)), p.TimeStamp)))); port.ConnectSource(endpoint); }
partial void DisposeNative() { _port?.Dispose(); _client?.Dispose(); _endpoint?.Dispose(); _port = null; _client = null; _endpoint = null; }
/// <summary> /// Gets the unique ID to use from a device, currently the name /// </summary> private string GetDeviceID(MidiEndpoint d) { string name = d.DisplayName; if (name.Contains(d.Name) == false) { name = d.Name + "(" + name + ")"; } return(name); }
public void Dispose() { _port?.Disconnect(_endpoint); _port?.Dispose(); _client?.Dispose(); _endpoint?.Dispose(); _port = null; _client = null; _endpoint = null; }
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> /// Releases all currently used MIDI resources. /// </summary> private void Release() { if (_inputEndpoint != null) { _inputPort.Disconnect(_inputEndpoint); _inputEndpoint = null; } if (_outputEndpoint != null) { _outputEndpoint = null; } }
/// <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 CoreMidiPortDetails(MidiEndpoint src) { Endpoint = src; Id = src.Name + "__" + src.EndpointName; Manufacturer = src.Manufacturer; Name = string.IsNullOrEmpty(src.DisplayName) ? src.Name : src.EndpointName; try { Version = src.DriverVersion.ToString(); } catch { Version = "N/A"; } }
void SendNote() { for (int i = 0; i < Midi.DestinationCount; i++) { var endpoint = MidiEndpoint.GetDestination(i); var note = (byte)(rand.Next() % 127); // play note outputPort.Send(endpoint, new MidiPacket [] { new MidiPacket(0, new byte [] { 0x90, note, 127 }) }); Thread.Sleep(300); // turn it off outputPort.Send(endpoint, new MidiPacket [] { new MidiPacket(0, new byte [] { 0x80, note, 0 }) }); } }
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."); } } }
void SendMIDI(byte type, byte channel, byte value) { for (int i = 0; i < Midi.DestinationCount; i++) { var endpoint = MidiEndpoint.GetDestination(i); outputPort.Send(endpoint, new MidiPacket[] { new MidiPacket(0, new byte[] { type, channel, value }) }); Debug.WriteLine("Midi Value: " + value + " Sent @ " + DateTime.Now.Millisecond.ToString() + "\r\n"); //outputPort.Send(endpoint, new MidiPacket[] { new MidiPacket(0, new byte[] { 0xB0, (byte)(myMidiModulation.CCNumber), ccByte }) }); //var ccVal = (byte)(rand.Next () % 127); // play ccVal then turn off after 300 miliseconds /* * outputPort.Send (endpoint, new MidiPacket [] { new MidiPacket (0, new byte [] { 0x90, ccVal, 127 }) }); * Thread.Sleep (300); * outputPort.Send (endpoint, new MidiPacket [] { new MidiPacket (0, new byte [] { 0x80, ccVal, 0 }) }); */ } }
public IOSMidiOutputPort(CMidiPort port, MidiEndpoint endpoint, MidiPortDetails details) : base(details) { this.port = port; this.endpoint = endpoint; }
public async void MidiTest (UILabel label) { this.label = label; CreateAUGraph (); ConfigureAndStartAudioProcessingGraph (processingGraph); virtualMidi = new MidiClient ("VirtualClient"); virtualMidi.IOError += (object sender, IOErrorEventArgs e) => { Console.WriteLine ("IO Error, messageId={0}", e.ErrorCode); }; virtualMidi.PropertyChanged += (object sender, ObjectPropertyChangedEventArgs e) => { Console.WriteLine ("Property changed: " + e.MidiObject + ", " + e.PropertyName); }; MidiError error; virtualEndpoint = virtualMidi.CreateVirtualDestination ("Virtual Destination", out error); if (error != MidiError.Ok) throw new Exception ("Error creating virtual destination: " + error); virtualEndpoint.MessageReceived += MidiMessageReceived; var sequence = new MusicSequence (); var midiFilePath = NSBundle.MainBundle.PathForResource ("simpletest", "mid"); var midiFileurl = NSUrl.FromFilename (midiFilePath); sequence.LoadFile (midiFileurl, MusicSequenceFileTypeID.Midi); var player = new MusicPlayer (); sequence.SetMidiEndpoint (virtualEndpoint); var presetUrl = CFUrl.FromFile (NSBundle.MainBundle.PathForResource ("Gorts_Filters", "sf2")); LoadFromDLSOrSoundFont (presetUrl, 10); player.MusicSequence = sequence; player.Preroll (); player.Start (); MusicTrack track; track = sequence.GetTrack (1); var length = track.TrackLength; while (true) { await Task.Delay (TimeSpan.FromSeconds (3)); double now = player.Time; if (now > length) break; } player.Stop (); sequence.Dispose (); player.Dispose (); label.Text = "Done"; }
Element MakeEndpoint (MidiEndpoint endpoint) { Section s; var root = new RootElement (endpoint.Name){ (s = new Section ("Properties") { new StringElement ("Driver Owner", endpoint.DriverOwner), new StringElement ("Manufacturer", endpoint.Manufacturer), new StringElement ("MaxSysExSpeed", endpoint.MaxSysExSpeed.ToString ()), new StringElement ("Network Session", endpoint.IsNetworkSession ? "yes" : "no") }) }; try { s.Add (new StringElement ("Offline", endpoint.Offline ? "yes" : "no")); } catch {} try { s.Add (new StringElement ("Receive Channels", endpoint.ReceiveChannels.ToString ())); } catch {} try { s.Add (new StringElement ("Transmit Channels", endpoint.TransmitChannels.ToString ())); } catch {} return root; }
private IEnumerable <IMidiPortDetails> GetOutputDevices() { return(Enumerable.Range(0, (int)CoreMidi.Midi.DestinationCount).Select(i => (IMidiPortDetails) new CoreMidiPortDetails(MidiEndpoint.GetDestination(i))));; }
public IOSMidiPortDetails(MidiEndpoint endpoint, MidiPortType portType, string name, string portId) : base(portType, name, portId) { Endpoint = endpoint; }
public async void MidiTest(UILabel label) { this.label = label; CreateAUGraph(); ConfigureAndStartAudioProcessingGraph(processingGraph); virtualMidi = new MidiClient("VirtualClient"); virtualMidi.IOError += (object sender, IOErrorEventArgs e) => { Console.WriteLine("IO Error, messageId={0}", e.ErrorCode); }; virtualMidi.PropertyChanged += (object sender, ObjectPropertyChangedEventArgs e) => { Console.WriteLine("Property changed: " + e.MidiObject + ", " + e.PropertyName); }; MidiError error; virtualEndpoint = virtualMidi.CreateVirtualDestination("Virtual Destination", out error); if (error != MidiError.Ok) { throw new Exception("Error creating virtual destination: " + error); } virtualEndpoint.MessageReceived += MidiMessageReceived; var sequence = new MusicSequence(); var midiFilePath = NSBundle.MainBundle.PathForResource("simpletest", "mid"); var midiFileurl = NSUrl.FromFilename(midiFilePath); sequence.LoadFile(midiFileurl, MusicSequenceFileTypeID.Midi); var player = new MusicPlayer(); sequence.SetMidiEndpoint(virtualEndpoint); var presetUrl = CFUrl.FromFile(NSBundle.MainBundle.PathForResource("gorts_filters", "sf2")); LoadFromDLSOrSoundFont(presetUrl, 10); player.MusicSequence = sequence; player.Preroll(); player.Start(); MusicTrack track; track = sequence.GetTrack(1); var length = track.TrackLength; while (true) { await Task.Delay(TimeSpan.FromSeconds(3)); double now = player.Time; if (now > length) { break; } } player.Stop(); sequence.Dispose(); player.Dispose(); label.Text = "Done"; }
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; } } }
MidiPortDetails CreatePortDetails(MidiEndpoint endpoint, MidiPortType type) { return(new IOSMidiPortDetails(endpoint, type, endpoint.DisplayName, endpoint.EndpointName)); }
private MidiOutPort(string deviceId, MidiEndpoint endpoint) { DeviceId = deviceId; _endpoint = endpoint; _client = new MidiClient(Guid.NewGuid().ToString()); }
public MusicPlayerStatus SetDestMidiEndpoint(MidiEndpoint endpoint) { return(MusicTrackSetDestMIDIEndpoint(handle, endpoint == null ? MidiObject.InvalidRef : endpoint.MidiHandle)); }