Beispiel #1
0
 public async Task SetValueAsync(byte value, byte controlNumber, IMidiOutputDevice device, byte channel)
 => await MidiDeviceLocator.SelectForOutput(device.DeviceId)
 .ComposeControlChange()
 .WithChannel(channel)
 .WithControlNumber(controlNumber)
 .WithValue(value)
 .SendAsync();
Beispiel #2
0
 // Start is called before the first frame update
 void Start()
 {
     if (_image != null && _image.height == 8 && _image.width == 8)
     {
         _button.onClick.AddListener(ShowImage);
     }
     else
     {
         UnityEngine.Debug.LogError("Image is null or not a perfect 8x8 - cannot use");
         _button.onClick.AddListener(ShowRandomMapRtMidi);
     }
     foreach (var outputDeviceInfo in MidiDeviceManager.Default.OutputDevices)
     {
         if (outputDeviceInfo.Name == PUSH_OUT_NAME)
         {
             Debug.Log("Creating device!");
             _midiOutput = outputDeviceInfo.CreateDevice();
             _midiOutput.Open();
         }
     }
     //foreach (var inputDeviceInfo in MidiDeviceManager.Default.InputDevices)
     //{
     //    //Debug.Log("In Device " + inputDeviceInfo.Name);
     //}
 }
Beispiel #3
0
        public void ComposeControlChangeTest()
        {
            IMidiOutputDevice device = MidiDeviceLocator.SelectForOutput(0);

            Assume.That(device != null);

            Assert.IsNotNull(device.ComposeControlChange());
        }
Beispiel #4
0
        public void SetDefaultChannel_InvalidTest(byte channel)
        {
            IMidiOutputDevice device = MidiDeviceLocator.SelectForOutput(0);

            Assume.That(device != null);

            Assert.Throws <ArgumentException>(() => device.SetDefaultChannel(channel));
        }
        private IMidiControlChangeComposer GetComposer()
        {
            IMidiOutputDevice device = MidiDeviceLocator.SelectForOutput(0);

            Assume.That(device != null);

            IMidiControlChangeComposer composer = device.ComposeControlChange();

            Assume.That(composer != null);
            return(composer);
        }
Beispiel #6
0
        public void SetDefaultChannelTest()
        {
            IMidiOutputDevice device = MidiDeviceLocator.SelectForOutput(0);

            Assume.That(device != null);

            for (byte i = 1; i <= 16; i++)
            {
                Assert.AreSame(device, device.SetDefaultChannel(i));
                Assert.AreEqual(i, device.DefaultChannel);
            }
        }
Beispiel #7
0
        public void SelectForOutputTest()
        {
            IEnumerable <IMidiOutputDevice> devices = MidiDeviceLocator.GetAllOutputDevices();

            Assume.That(devices.Any()); // whether or not there are actually any midi output devices is going to be dependant on the machine the test is running on

            IMidiOutputDevice device = MidiDeviceLocator.SelectForOutput(0);

            Assert.IsNotNull(device);
            Assert.AreEqual(0, device.DeviceId);
            Assert.False(string.IsNullOrWhiteSpace(device.Name));
        }
Beispiel #8
0
        /// <summary>
        /// Retrieves a collection of all MIDI output devices on the current system.
        /// </summary>
        /// <returns>A collection of all MIDI output devices on the current system.</returns>
        public static IEnumerable <IMidiOutputDevice> GetAllOutputDevices()
        {
            int numberOfDevices = MidiOut.NumberOfDevices;

            IMidiOutputDevice[] devices = new IMidiOutputDevice[numberOfDevices];

            for (int i = 0; i < numberOfDevices; i++)
            {
                devices[i] = GetOutputDevice(i);
            }

            return(devices);
        }
Beispiel #9
0
        public void Init()
        {
            var slIn  = MidiDeviceManager.Default.InputDevices.SingleOrDefault(i => i.Name == "SL GRAND ");
            var slOut = MidiDeviceManager.Default.OutputDevices.SingleOrDefault(i => i.Name == "kipy_loopback1 ");

            if (slIn != null)
            {
                _inputDevice = slIn.CreateDevice();
                _inputDevice.ControlChange         += InputDevice_ControlChange;
                _inputDevice.NoteOn                += InputDevice_NoteOn;
                _inputDevice.NoteOff               += _inputDevice_NoteOff;
                _inputDevice.Nrpn                  += _inputDevice_Nrpn;
                _inputDevice.ChannelPressure       += _inputDevice_ChannelPressure;
                _inputDevice.PitchBend             += _inputDevice_PitchBend;
                _inputDevice.PolyphonicKeyPressure += _inputDevice_PolyphonicKeyPressure;
                _inputDevice.ProgramChange         += _inputDevice_ProgramChange;
                _inputDevice.Open();

                _outputDevice = slOut.CreateDevice();
                _outputDevice.Open();
            }
        }
Beispiel #10
0
        protected override Task OnInitialize(MidiDeviceConfiguration configuration, CancellationToken cancellationToken)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            // Attach input device
            if (!string.IsNullOrEmpty(configuration.InputDeviceName))
            {
                var inputDeviceInfo = MidiDeviceManager.Default.InputDevices.FirstOrDefault(d => d.Name.StartsWith(configuration.InputDeviceName));
                if (inputDeviceInfo != null)
                {
                    _inputDevice = inputDeviceInfo.CreateDevice();

                    _inputDevice.NoteOn                += DeviceOnNoteOn;
                    _inputDevice.NoteOff               += DeviceOnNoteOff;
                    _inputDevice.ControlChange         += DeviceOnControlChange;
                    _inputDevice.ChannelPressure       += InputDeviceOnChannelPressure;
                    _inputDevice.PitchBend             += InputDeviceOnPitchBend;
                    _inputDevice.ProgramChange         += InputDeviceOnProgramChange;
                    _inputDevice.PolyphonicKeyPressure += InputDeviceOnPolyphonicKeyPressure;
                    _inputDevice.Nrpn  += InputDeviceOnNrpn;
                    _inputDevice.SysEx += InputDeviceOnSysEx;
                }
            }

            // Attach output device
            if (!string.IsNullOrEmpty(configuration.OutputDeviceName))
            {
                var outputDeviceInfo = MidiDeviceManager.Default.OutputDevices.FirstOrDefault(d => d.Name.StartsWith(configuration.OutputDeviceName));
                if (outputDeviceInfo != null)
                {
                    _outputDevice = outputDeviceInfo.CreateDevice();
                }
            }

            return(Task.CompletedTask);
        }
 public MidiOutputDeviceTest(ITestOutputHelper output) : base(output)
 {
     _outputDeviceMock = new RtMidiOutputDeviceMock();
     _sut = new MidiOutputDevice(_outputDeviceMock, string.Empty);
 }
Beispiel #12
0
        public static void Sample()
        {
            // List all available MIDI API's
            foreach (var api in MidiDeviceManager.Default.GetAvailableMidiApis())
            {
                Console.WriteLine($"Available API: {api}");
            }

            // Listen to all available midi devices
            void ControlChangeHandler(IMidiInputDevice sender, in ControlChangeMessage msg)
            {
                Console.WriteLine($"[{sender.Name}] ControlChange: Channel:{msg.Channel} Control:{msg.Control} Value:{msg.Value}");
            }

            var devices = new List <IMidiDevice>();

            try
            {
                IMidiOutputDevice output = null;

                foreach (var inputDeviceInfo in MidiDeviceManager.Default.InputDevices)
                {
                    Console.WriteLine($"Opening {inputDeviceInfo.Name}");

                    var inputDevice = inputDeviceInfo.CreateDevice();
                    devices.Add(inputDevice);

                    inputDevice.ControlChange += ControlChangeHandler;
                    inputDevice.NoteOn        += (IMidiInputDevice sender, in NoteOnMessage msg) =>
                    {
                        Console.WriteLine(msg);
                        output?.Send(msg);
                    };
                    inputDevice.NoteOff += (IMidiInputDevice sender, in NoteOffMessage msg) =>
                    {
                        Console.WriteLine(msg);
                        output?.Send(msg);
                    };
                    inputDevice.PolyphonicKeyPressure +=
                        (IMidiInputDevice sender, in PolyphonicKeyPressureMessage msg) =>
                        Console.WriteLine("PolyphonicKeyPressure");

                    inputDevice.Open();
                }

                foreach (var outputDeviceInfo in MidiDeviceManager.Default.OutputDevices)
                {
                    Console.WriteLine($"Opening output: {outputDeviceInfo.Name}");
                    var outputDevice = outputDeviceInfo.CreateDevice();
                    devices.Add(outputDevice);

                    outputDevice.Open();
                    output = outputDevice;
                    break;
                }

                Console.WriteLine("Press any key to stop...");
                Console.ReadKey();
            }
            finally
            {
                foreach (var device in devices)
                {
                    device.Dispose();
                }
            }
        }
 /// <summary>
 /// Initializes an instance of <see cref="MidiPatchChangeComposer"/>.
 /// </summary>
 /// <param name="device">The <see cref="IMidiOutputDevice"/> to send the composed event.</param>
 internal MidiPatchChangeComposer(IMidiOutputDevice device)
 {
     this._device  = device;
     this._channel = device.DefaultChannel;
 }
Beispiel #14
0
 public async Task SetToggleAsync(bool toggleValue, byte controlNumber, IAmpProfile profile, IMidiOutputDevice device, byte channel)
 => await MidiDeviceLocator.SelectForOutput(device.DeviceId)
 .ComposeControlChange()
 .WithChannel(channel)
 .WithControlNumber(controlNumber)
 .WithValue(this.GetToggleValue(toggleValue, profile))
 .SendAsync();
Beispiel #15
0
        public MainWindow()
        {
            InitializeComponent();
            KinectRegion.SetKinectRegion(this, kinectRegion);
            kinectRegion.KinectSensor = KinectSensor.GetDefault();
            // only one sensor is currently supported
            //kinectRegion.KinectSensor = KinectSensor.GetDefault();
            // set IsAvailableChanged event notifier
            kinectRegion.KinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;

            // open the sensor
            //kinectRegion.KinectSensor.Open();
            // set the status text
            this.StatusText = kinectRegion.KinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
                                                            : Properties.Resources.NoSensorStatusText;

            // open the reader for the body frames
            this.bodyFrameReader = kinectRegion.KinectSensor.BodyFrameSource.OpenReader();

            // set the BodyFramedArrived event notifier
            this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;
            // initialize the gesture detection objects for our gestures
            this.gestureDetectorList = new List <GestureDetector>();

            // initialize the BodyViewer object for displaying tracked bodies in the UI
            kinectBodyView = new KinectBodyView(kinectRegion.KinectSensor);

            // initialize the MainWindow
            //this.InitializeComponent();

            // set our data context objects for display in UI
            this.DataContext = this;
            //this.kinectBodyViewbox.DataContext = this.kinectBodyView;


            int col0Row   = 0;
            int col1Row   = 0;
            int maxBodies = kinectRegion.KinectSensor.BodyFrameSource.BodyCount;



            a     = 40;
            chord = 0;

            /*GestureResultView result = new GestureResultView(0, false, false, 0.0f, false);
             *
             * GestureDetector detector = new GestureDetector(kinectRegion.KinectSensor, result);
             * this.gestureDetectorList.Add(detector);
             *
             * // split gesture results across the first two columns of the content grid
             * ContentControl contentControl = new ContentControl();
             * contentControl.Content = this.gestureDetectorList[0].GestureResultView;*/

            for (int i = 0; i < maxBodies; ++i)
            {
                GestureResultView result   = new GestureResultView(i, false, false, 0.0f, false);
                GestureDetector   detector = new GestureDetector(kinectRegion.KinectSensor, result);
                this.gestureDetectorList.Add(detector);

                // split gesture results across the first two columns of the content grid
                ContentControl contentControl = new ContentControl();
                contentControl.Content = this.gestureDetectorList[i].GestureResultView;

                if (i % 2 == 0)
                {
                    // Gesture results for bodies: 0, 2, 4
                    Grid.SetColumn(contentControl, 0);
                    Grid.SetRow(contentControl, col0Row);
                    ++col0Row;
                }
                else
                {
                    // Gesture results for bodies: 1, 3, 5
                    Grid.SetColumn(contentControl, 1);
                    Grid.SetRow(contentControl, col1Row);
                    ++col1Row;
                }

                //this.contentGrid.Children.Add(contentControl);
            }

            //this.ImageSource = this.notSeatedImage;
            Loaded += MainWindow_Loaded;

            dev = devInfo.CreateDevice();
            dev.Open();
        }