private MidiInPort(string deviceId, MidiEndpoint endpoint) { DeviceId = deviceId; _endpoint = endpoint; _client = new MidiClient(Guid.NewGuid().ToString()); _port = _client.CreateInputPort(_endpoint.EndpointName); }
// // Creates a MidiClient which is our way of communicating with the // CoreMidi stack // void SetupMidi() { client = new MidiClient("CoreMidiSample MIDI CLient"); client.ObjectAdded += delegate(object sender, ObjectAddedOrRemovedEventArgs e) { }; client.ObjectAdded += delegate { ReloadDevices(); }; client.ObjectRemoved += delegate { ReloadDevices(); }; client.PropertyChanged += delegate(object sender, ObjectPropertyChangedEventArgs e) { Console.WriteLine("Changed"); }; client.ThruConnectionsChanged += delegate { Console.WriteLine("Thru connections changed"); }; client.SerialPortOwnerChanged += delegate { Console.WriteLine("Serial port changed"); }; outputPort = client.CreateOutputPort("CoreMidiSample Output Port"); inputPort = client.CreateInputPort("CoreMidiSample Input Port"); inputPort.MessageReceived += delegate(object sender, MidiPacketsEventArgs e) { Console.WriteLine("Got {0} packets", e.Packets.Length); }; ConnectExistingDevices(); var session = MidiNetworkSession.DefaultSession; if (session != null) { session.Enabled = true; session.ConnectionPolicy = MidiNetworkConnectionPolicy.Anyone; } }
public CoreMidiInput(CoreMidiPortDetails details) { this.details = details; client = new MidiClient("inputclient"); port = client.CreateInputPort("inputport"); port.ConnectSource(details.Endpoint); port.MessageReceived += OnMessageReceived; }
// // Creates a MidiClient which is our way of communicating with the // CoreMidi stack // void SetupMidi () { client = new MidiClient ("CoreMidiSample MIDI CLient"); client.ObjectAdded += delegate(object sender, ObjectAddedOrRemovedEventArgs e) { }; client.ObjectAdded += delegate { ReloadDevices (); }; client.ObjectRemoved += delegate { ReloadDevices (); }; client.PropertyChanged += delegate(object sender, ObjectPropertyChangedEventArgs e) { Console.WriteLine ("Changed"); }; client.ThruConnectionsChanged += delegate { Console.WriteLine ("Thru connections changed"); }; client.SerialPortOwnerChanged += delegate { Console.WriteLine ("Serial port changed"); }; outputPort = client.CreateOutputPort ("CoreMidiSample Output Port"); inputPort = client.CreateInputPort ("CoreMidiSample Input Port"); inputPort.MessageReceived += delegate(object sender, MidiPacketsEventArgs e) { Console.WriteLine ("Got {0} packets", e.Packets.Length); }; ConnectExistingDevices (); var session = MidiNetworkSession.DefaultSession; if (session != null){ session.Enabled = true; session.ConnectionPolicy = MidiNetworkConnectionPolicy.Anyone; } }
void SetupMidi() { client = new MidiClient("Stimulant iOS MIDI Client"); client.ObjectAdded += delegate(object sender, ObjectAddedOrRemovedEventArgs e) { }; client.ObjectAdded += delegate { }; client.ObjectRemoved += delegate { }; client.PropertyChanged += delegate(object sender, ObjectPropertyChangedEventArgs e) { Console.WriteLine("Changed"); }; client.ThruConnectionsChanged += delegate { Console.WriteLine("Thru connections changed"); }; client.SerialPortOwnerChanged += delegate { Console.WriteLine("Serial port changed"); }; outputPort = client.CreateOutputPort("Stimulant iOS Output Port"); inputPort = client.CreateInputPort("Stimulant iOS Input Port"); inputPort.MessageReceived += delegate(object sender, MidiPacketsEventArgs e) { foreach (MidiPacket mPacket in e.Packets) { //if (myMidiModulation.ModeNumber == 1) //{ var midiData = new byte[mPacket.Length]; Marshal.Copy(mPacket.Bytes, midiData, 0, mPacket.Length); //The first four bits of the status byte tell MIDI what command //The last four bits of the status byte tell MIDI what channel byte StatusByte = midiData[0]; byte typeData = (byte)((StatusByte & 0xF0) >> 4); byte channelData = (byte)(StatusByte & 0x0F); //We should check to see if typeData is clock/start/continue/stop/note on/note off //-----------defines each midi byte--------------- byte midi_start = 0xfa; // start byte byte midi_stop = 0xfc; // stop byte byte midi_clock = 0xf8; // clock byte byte midi_continue = 0xfb; // continue byte byte midi_note_on = 0x90; // note on byte midi_note_off = 0x80; // note off //------------------------------------------------ if ((StatusByte == midi_start) || (StatusByte == midi_continue)) { if (!myMidiModulation.IsRunning) { InvokeOnMainThread(() => { //PowerPushed(); //FlipPower(); //powerButton.SetOn(); myMidiModulation.IsRunning = powerButton.TogglePower(); // true;//powerButton.TogglePower(); Debug.WriteLine("MIDI START @ " + DateTime.Now.Millisecond.ToString()); if (myMidiModulation.IsRunning) { myMidiModulation.CatchClock(); } }); } //myMidiModulation.FireModulation = true; //I'm not sure if we should be firing one off at the start here } if (StatusByte == midi_clock) { if (myMidiModulation.ModeNumber == 1) { Debug.WriteLine("MIDI CLOCK @ " + DateTime.Now.Millisecond.ToString()); if (myMidiModulation.IsRunning) { myMidiModulation.CatchClock(); } /* * myMidiModulation.ClockCounter(); * if (myMidiModulation.StepComma > 1) * { * myMidiModulation.StepComma = 0; * } * else * { * myMidiModulation.StepComma++; * } * myMidiModulation.StepSizeSetter(); */ } } if (StatusByte == midi_stop) { if (myMidiModulation.IsRunning) { InvokeOnMainThread(() => { //PowerPushed(); //FlipPower(); myMidiModulation.IsRunning = powerButton.TogglePower(); }); //myMidiModulation.Reset(); } } if (myMidiModulation.IsTriggerOnly) { if (StatusByte == midi_note_on) { // handle note on myMidiModulation.IsNoteOn = true; myMidiModulation.NumOfNotesOn += 1; // Restart first if in restart mode if (myMidiModulation.IsRestartEachNote) { //myMidiModulation.CurrentCC = myMidiModulation.StartingLocation; myMidiModulation.CurrentXVal = myMidiModulation.StartingLocation; if (myMidiModulation.PatternNumber == 4) { myMidiModulation.EveryOther = false; } else if (myMidiModulation.PatternNumber == 5 || myMidiModulation.PatternNumber == 6) { myMidiModulation.EveryOther = true; } } } if (StatusByte == midi_note_off) { if (myMidiModulation.NumOfNotesOn > 0) { myMidiModulation.NumOfNotesOn -= 1; } if (myMidiModulation.NumOfNotesOn < 1) { // handle note off myMidiModulation.IsNoteOn = false; myMidiModulation.NumOfNotesOn = 0; } } } //} } }; ConnectExistingDevices(); //var session = MidiNetworkSession.DefaultSession; var session = MidiNetworkSession.DefaultSession; if (session != null) { session.Enabled = true; session.ConnectionPolicy = MidiNetworkConnectionPolicy.Anyone; } }