Exemplo n.º 1
0
 private MidiInPort(string deviceId, MidiEndpoint endpoint)
 {
     DeviceId  = deviceId;
     _endpoint = endpoint;
     _client   = new MidiClient(Guid.NewGuid().ToString());
     _port     = _client.CreateInputPort(_endpoint.EndpointName);
 }
Exemplo n.º 2
0
 public CoreMidiInput(CoreMidiPortDetails details)
 {
     this.details = details;
     port         = new MidiClient("inputclient").CreateInputPort("inputport");
     port.ConnectSource(details.Endpoint);
     port.MessageReceived += OnMessageReceived;
 }
 public CoreMidiOutput(CoreMidiPortDetails details)
 {
     this.details = details;
     client       = new MidiClient("outputclient");
     port         = client.CreateOutputPort("outputport");
     Connection   = MidiPortConnectionState.Open;
 }
Exemplo n.º 4
0
        //
        // 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;
            }
        }
Exemplo n.º 5
0
 partial void DisposeNative()
 {
     _port?.Dispose();
     _client?.Dispose();
     _endpoint?.Dispose();
     _port     = null;
     _client   = null;
     _endpoint = null;
 }
Exemplo n.º 6
0
 public void Dispose()
 {
     _port?.Disconnect(_endpoint);
     _port?.Dispose();
     _client?.Dispose();
     _endpoint?.Dispose();
     _port     = null;
     _client   = null;
     _endpoint = null;
 }
Exemplo n.º 7
0
            public override IMidiInput CreateVirtualOutputReceiver(PortCreatorContext context)
            {
                var       nclient = new MidiClient(context.ApplicationName ?? "managed-midi virtual out");
                MidiError error;
                var       portName  = context.PortName ?? "managed-midi virtual out port";
                var       nendpoint = nclient.CreateVirtualDestination(portName, out error);

                nendpoint.Manufacturer = context.Manufacturer;
                nendpoint.DisplayName  = portName;
                nendpoint.Name         = portName;
                var details = new CoreMidiPortDetails(nendpoint);

                return(new CoreMidiInput(details));
            }
        public CoreMidiAccess()
        {
            _midiSynthesizer = new CoreMidiSynthesizer();
            Inputs           = new ObservableCollection <IMidiPortDetails>(GetInputDevices());

            Outputs = new ObservableCollection <IMidiPortDetails>(GetOutputDevices());
            Outputs.Add(_midiSynthesizer);

            _client              = new MidiClient("CoreMidiSample MIDI CLient");
            _client.ObjectAdded += delegate(object sender, ObjectAddedOrRemovedEventArgs e)
            {
                UpdateInputDevices(false);
                UpdateOutputDevices(false);
            };
            _client.ObjectRemoved += delegate(object sender, ObjectAddedOrRemovedEventArgs e)
            {
                UpdateInputDevices(true);
                UpdateOutputDevices(true);
            };
        }
Exemplo n.º 9
0
 public CoreMidiOutput(CoreMidiPortDetails details)
 {
     this.details = details;
     client       = new MidiClient("outputclient");
     port         = client.CreateOutputPort("outputport");
 }
Exemplo n.º 10
0
		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";
		}
Exemplo n.º 11
0
		// 
		// 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;
			}
		}
Exemplo n.º 12
0
        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;
            }
        }
Exemplo n.º 13
0
 private MidiOutPort(string deviceId, MidiEndpoint endpoint)
 {
     DeviceId  = deviceId;
     _endpoint = endpoint;
     _client   = new MidiClient(Guid.NewGuid().ToString());
 }
Exemplo n.º 14
0
        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";
        }
Exemplo n.º 15
0
 /// <summary>
 /// Initializes CoreMidi only once per application
 /// </summary>
 static MacOSXMidiDriver()
 {
     MonoMac.CoreMidi.Midi.Restart();
     _client = new MidiClient("LPToolKit MIDI Client");
 }