A MIDI output device.

Each instance of this class describes a MIDI output device installed on the system. You cannot create your own instances, but instead must go through the InstalledDevices property to find which devices are available. You may wish to examine the DeviceBase.Name property of each one and present the user with a choice of which device to use.

Open an output device with Open and close it with Close. While it is open, you may send MIDI messages with functions such as SendNoteOn, SendNoteOff and SendProgramChange. All notes may be silenced on the device by calling SilenceAllNotes.

Note that the above methods send their messages immediately. If you wish to arrange for a message to be sent at a specific future time, you'll need to instantiate some subclass of Message (eg NoteOnMessage) and then pass it to Clock.Schedule.

Inheritance: Midi.DeviceBase
        public LaunchpadDevice(int index)
        {
            InitialiseButtons();

            int i = 0;
            mInputDevice = InputDevice.InstalledDevices.Where(x => x.Name.Contains("Launchpad")).
                FirstOrDefault(x => i++ == index);
            i = 0;
            mOutputDevice = OutputDevice.InstalledDevices.Where(x => x.Name.Contains("Launchpad")).
                FirstOrDefault(x => i++ == index);

            if (mInputDevice == null)
                throw new LaunchpadException("Unable to find input device.");
            if (mOutputDevice == null)
                throw new LaunchpadException("Unable to find output device.");

            mInputDevice.Open();
            mOutputDevice.Open();

            mInputDevice.StartReceiving(new Clock(120));
            mInputDevice.NoteOn += mInputDevice_NoteOn;
            mInputDevice.ControlChange += mInputDevice_ControlChange;

            Reset();
        }
Exemple #2
0
 public void Schedule(OutputDevice outputDevice, NoteOnMessage msg, float noteLength)
 {
     //outputDevice.SendNoteOn(msg.Channel, msg.Pitch, msg.Velocity);
     //Thread.Sleep();
     clock.Schedule(new NoteOnMessage(outputDevice, msg.Channel, msg.Pitch, msg.Velocity, msg.Time));
     clock.Schedule(new NoteOffMessage(outputDevice, msg.Channel, msg.Pitch, msg.Velocity, msg.Time + noteLength));
 }
        public YPitchBendCube(Point3D center, double radius, 
                Pitch pitch, Instrument instrument, OutputDevice device, Channel channel)
            : base(center, radius, new InstrumentNoteAction(device, channel, pitch)) {

                outputDevice = device;
                this.channel = channel;
        }
 public InstrumentChordAction(OutputDevice device, Channel channel, Chord chord, int octave)
     : base() {
     internalDevice = device;
     internalChannel = channel;
     Chord = chord;
     Octave = octave;
 }
 public static void PlayTact(Note root, Pattern pattern, OutputDevice outputDevice)
 {
     PlayAccord(root, pattern, Direction.Down, outputDevice);
     Thread.Sleep(400);
     PlayAccord(root, pattern, Direction.Down, outputDevice);
     Thread.Sleep(150);
     PlayAccord(root, pattern, Direction.Up, outputDevice);
     Thread.Sleep(400);
     PlayAccord(root, pattern, Direction.Up, outputDevice);
     Thread.Sleep(200);
     PlayAccord(root, pattern, Direction.Down, outputDevice);
     Thread.Sleep(150);
     PlayAccord(root, pattern, Direction.Up, outputDevice);
     Thread.Sleep(200);
     PlayAccord(root, pattern, Direction.Down, outputDevice);
     Thread.Sleep(400);
     PlayAccord(root, pattern, Direction.Down, outputDevice);
     Thread.Sleep(150);
     PlayAccord(root, pattern, Direction.Up, outputDevice);
     Thread.Sleep(400);
     PlayAccord(root, pattern, Direction.Up, outputDevice);
     Thread.Sleep(200);
     PlayAccord(root, pattern, Direction.Down, outputDevice);
     //Thread.Sleep(150);
     //PlayAccord(root, pattern, Direction.Up, outputDevice);
     Thread.Sleep(400);
 }
Exemple #6
0
        public void Connect()
        {
            if (_inputDevice == null)
            {
                _inputDevice = (from device in InputDevice.InstalledDevices
                                where device.Name == _deviceName
                                select device).FirstOrDefault();
                if (_inputDevice != null)
                {
                    _inputDevice.Open();

                    _inputDevice.NoteOn += OnInputDeviceNoteOn;
                    _inputDevice.NoteOff += OnInputDeviceNoteOff;
                    _inputDevice.ControlChange += OnInputDeviewControlChange;

                    _inputDevice.StartReceiving(null);
                }
            }

            if (_outputDevice == null)
            {
                _outputDevice = (from device in OutputDevice.InstalledDevices
                                 where device.Name == _deviceName
                                 select device).FirstOrDefault();
                if (_outputDevice != null)
                {
                    _outputDevice.Open();
                    _outputDevice.SilenceAllNotes();
                }
            }
        }
Exemple #7
0
        public MidiLibRepository()
        {
            this.PlayerParameters = new PlayerParameters()
            {
                TimeSignatureNominator = 4,
                TimeSignatureDenominator = 4,
                TimeSignatureClocksPerBeat = 24,
                TimeSignatureNumberOf32ThNotePerBeat = 4,
                Tempo = 120,
                Channel = Channel.Channel1
            };
            this._clock = new Clock(this.PlayerParameters.Tempo);
            try
            {
                this._outputDevice = OutputDevice.InstalledDevices[0];
            }
            catch (Exception e)
            {
                throw new Exception();
            }
            this._velocity = 75;

            this._outputDevice.Open();
            this._clock.Start();
        }
Exemple #8
0
 public MidiDevice()
 {
     timeOuts     = new List <NoteTimeOut>();
     outputDevice = Midi.OutputDevice.InstalledDevices[0];
     outputDevice.Open();
     outputDevice.SilenceAllNotes();
     System.Threading.Thread.Sleep(200); // fixes delay during initial playing, possibly due to midi device initialization
 }
Exemple #9
0
 public MidiDevice()
 {
     timeOuts = new List<NoteTimeOut>();
     outputDevice = Midi.OutputDevice.InstalledDevices[0];
     outputDevice.Open();
     outputDevice.SilenceAllNotes();
     System.Threading.Thread.Sleep(200); // fixes delay during initial playing, possibly due to midi device initialization
 }
Exemple #10
0
 public Scaler(Clock clock, InputDevice inputDevice, OutputDevice outputDevice)
 {
     this.clock = clock;
     this.inputDevice = inputDevice;
     this.outputDevice = outputDevice;
     this.scaleToUse = 0;
     if (inputDevice != null)
     {
         inputDevice.NoteOn += new InputDevice.NoteOnHandler(this.NoteOn);
     }
 }
Exemple #11
0
        public Arpeggiator(InputDevice inputDevice, OutputDevice outputDevice, Clock clock)
        {
            this.inputDevice = inputDevice;
            this.outputDevice = outputDevice;
            this.clock = clock;

            if (inputDevice != null)
            {
                inputDevice.NoteOn += new InputDevice.NoteOnHandler(this.NoteOn);
                inputDevice.NoteOff += new InputDevice.NoteOffHandler(this.NoteOff);
            }
        }
Exemple #12
0
        public Reversi(LaunchpadDevice device)
        {
            mLaunchpadDevice = device;

            mLaunchpadDevice.DoubleBuffered = false;
            mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;

            mOutputDevice = OutputDevice.InstalledDevices[0];
            mOutputDevice.Open();

            Restart();
        }
        public Midi.OutputDevice matrixOut; // Yeet Output in

        private void requestMatrixInfo()
        {
            //Setup Midi
            Console.WriteLine("Looking for Midi input device " + matrix.Name);
            int i = 0;

            foreach (Midi.InputDevice inputDevice in Midi.InputDevice.InstalledDevices)
            {
                Console.WriteLine(inputDevice.Name);
                if (inputDevice.Name == matrix.Name)
                {
                    Console.WriteLine("Midi Input Connected: " + inputDevice.Name);
                    matrixIn = Midi.InputDevice.InstalledDevices[i];
                    if (!matrixIn.IsOpen)
                    {
                        matrixIn.Open();
                        matrixIn.SysEx += new Midi.InputDevice.SysExHandler(ReceiveSysEx);
                        matrixIn.StartReceiving(null, true);
                    }
                    break;
                }
                i++;
            }

            Console.WriteLine("Looking for Midi output device " + matrix.Name);

            i = 0;
            foreach (Midi.OutputDevice outputDevice in Midi.OutputDevice.InstalledDevices)
            {
                Console.WriteLine(outputDevice.Name);
                if (outputDevice.Name == matrix.Name)
                {
                    Console.WriteLine("Midi Output Connected: " + outputDevice.Name);
                    matrixOut = Midi.OutputDevice.InstalledDevices[i];
                    if (!matrixOut.IsOpen)
                    {
                        matrixOut.Open();
                    }
                    break;
                }
                i++;
            }

            matrixOut.SendSysEx(new byte[] { 240, 0, 2, 3, 1, 0, 17, 16, 247 });    //获取设备名字
            matrixOut.SendSysEx(new byte[] { 240, 0, 2, 3, 1, 0, 17, 17, 247 });    //获取设备序列号String
            matrixOut.SendSysEx(new byte[] { 240, 0, 2, 3, 1, 0, 17, 18, 0, 247 }); //获取设备固件String
            matrixOut.SendSysEx(new byte[] { 240, 0, 2, 3, 1, 0, 17, 18, 1, 247 }); //获取设备固件Bytes
        }
Exemple #14
0
 public Drummer(Clock clock, OutputDevice outputDevice, int beatsPerMeasure)
 {
     this.clock = clock;
     this.outputDevice = outputDevice;
     this.beatsPerMeasure = beatsPerMeasure;
     this.messagesForOneMeasure = new List<Message>();
     for (int i = 0; i < beatsPerMeasure; ++i) {
         Percussion percussion = i == 0 ? Percussion.PedalHiHat : Percussion.MidTom1;
         int velocity = i == 0 ? 100 : 40;
         messagesForOneMeasure.Add(new PercussionMessage(outputDevice, percussion,
             velocity, i));
     }
     messagesForOneMeasure.Add(new CallbackMessage(
         new CallbackMessage.CallbackType(CallbackHandler), 0));
     clock.Schedule(messagesForOneMeasure, 0);
 }
        public RainSequencer(LaunchpadDevice device)
        {
            mLaunchpadDevice = device;
            mOutputDevice = OutputDevice.InstalledDevices[0];
            mOutputDevice.Open();

            mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;

            /*
            Random rand = new Random();
            for (int y = 0; y < NumRows; y++)
                for (int x = 0; x < NumRows; x++)
                    if (rand.Next(0, 12) == 0)
                        mSequence[x, y] = true;
             * */
        }
Exemple #16
0
            public Arpeggiator(InputDevice inputDevice, OutputDevice outputDevice, Clock clock)
            {
                this.inputDevice = inputDevice;
                this.outputDevice = outputDevice;
                this.clock = clock;
                this.currentChordPattern = 0;
                this.currentScalePattern = 0;
                this.playingChords = false;
                this.lastSequenceForPitch = new Dictionary<Pitch, List<Pitch>>();

                if (inputDevice != null)
                {
                    inputDevice.NoteOn += new InputDevice.NoteOnHandler(this.NoteOn);
                    inputDevice.NoteOff += new InputDevice.NoteOffHandler(this.NoteOff);
                }
            }
Exemple #17
0
        public void DisConnect()
        {
            if (_inputDevice != null)
            {
                _inputDevice.StopReceiving();
                _inputDevice.Close();
                _inputDevice.RemoveAllEventHandlers();

                _inputDevice = null;
            }

            if (_outputDevice != null)
            {
                _outputDevice.Close();
                _outputDevice = null;
            }
        }
Exemple #18
0
        public void NoteOn(NoteOnMessage msg, OutputDevice output)
        {
            output.SilenceAllNotes();

            if (!currentNote.Equals(Pitch.A0))
            {
                total++;
                if (msg.Pitch.PositionInOctave().Equals(currentNote.PositionInOctave()))
                {
                    score++;
                    currentNote = availableNotes[random.Next(availableNotes.Count)];
                    clock.Schedule(new NoteOnOffMessage(output,msg.Channel,Pitch.G5,127,clock.Time,clock,1));
                    clock.Schedule(new NoteOnOffMessage(output,msg.Channel,Pitch.C6,127,clock.Time+1,clock,1));
                }
            }
            else
            {
                currentNote = availableNotes[random.Next(availableNotes.Count)];
            }
        }
Exemple #19
0
        public void NextOutput()
        {
            try
            {
                outputDevice.SilenceAllNotes();
                outputDevice.Close();
            }
            catch (NullReferenceException) { }
            if (++output < OutputDevice.InstalledDevices.Count)
                outputDevice = OutputDevice.InstalledDevices[output];
            else if (OutputDevice.InstalledDevices.Count != 0)
                outputDevice = OutputDevice.InstalledDevices[output = 0];
            else
            {
                outputDevice = null;
                return;
            }

            outputDevice.Open();
            Display();
        }
Exemple #20
0
 void PlayChordRun(OutputDevice outputDevice, Chord chord, int millisecondsBetween)
 {
     Pitch previousNote = (Pitch)(-1);
     for (Pitch pitch = Pitch.A0; pitch < Pitch.C8; ++pitch)
     {
         if (chord.Contains(pitch))
         {
             if (previousNote != (Pitch)(-1))
             {
                 outputDevice.SendNoteOff(Channel.Channel1, previousNote, 80);
             }
             outputDevice.SendNoteOn(Channel.Channel1, pitch, 80);
             Thread.Sleep(millisecondsBetween);
             previousNote = pitch;
         }
     }
     if (previousNote != (Pitch)(-1))
     {
         outputDevice.SendNoteOff(Channel.Channel1, previousNote, 80);
     }
 }
Exemple #21
0
 public static void PlayRunUpKeyboard(OutputDevice outputDevice, Predicate<Note> predicate,
     int millisecondsBetween)
 {
     Note previousNote = (Note)(-1);
     for (Note note = Note.A0; note < Note.C8; ++note)
     {
         if (predicate(note))
         {
             if (previousNote != (Note)(-1))
             {
                 outputDevice.SendNoteOff(Channel.Channel1, previousNote, 80);
             }
             outputDevice.SendNoteOn(Channel.Channel1, note, 80);
             Thread.Sleep(millisecondsBetween);
             previousNote = note;
         }
     }
     if (previousNote != (Note)(-1))
     {
         outputDevice.SendNoteOff(Channel.Channel1, previousNote, 80);
     }
 }
        public Launchpad(InputDevice inputDevice, OutputDevice outputDevice, Clock clock)
        {
            this.inputDevice  = inputDevice;
            this.outputDevice = outputDevice;
            this.clock        = clock;
            if (this.inputDevice.IsOpen)
            {
                this.inputDevice.Close();
            }
            if (this.outputDevice.IsOpen)
            {
                this.outputDevice.Close();
            }

            this.inputDevice.Open();
            this.inputDevice.NoteOn += new InputDevice.NoteOnHandler(NoteOn);
            this.inputDevice.StartReceiving(null);

            this.outputDevice.Open();
            this.ShowColours();
            DemoSetup();
        }
Exemple #23
0
		public GeneratorFramework(float beatsPerMinute)
		{
			_clock = new Clock(beatsPerMinute);

			char c = 'a';
			Dictionary<char, OutputDevice> _outdevices = new Dictionary<char, OutputDevice>();

			Console.WriteLine("Select output device");
			foreach (OutputDevice device in OutputDevice.InstalledDevices)
			{
				Console.WriteLine($"{c} - {device.Name}");
				_outdevices.Add(c++, device);

			}

			do
			{
				c = Console.ReadKey(true).KeyChar;
			} while (!_outdevices.ContainsKey(c));

			_outputDevice = _outdevices[c];
			Console.WriteLine("Using {0} as output", _outputDevice.Name);
			_outputDevice.Open();
		}
Exemple #24
0
        private void btnReceiveOut_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedItem == null)
            MessageBox.Show("No device selected!");
              else
              {
            outDevice = (OutputDevice)listBox2.SelectedItem;
            outDevice.Open();
            if (comboBox1.SelectedItem != null)
              outDevice.SendNoteOn(Channel.Channel1, (Pitch)comboBox1.SelectedItem, trackBar1.Value);

            outDevice.Close();
              }
        }
Exemple #25
0
 protected static void UseOutputDevice(Midi.OutputDevice odNew)
 {
     if ((odNew == _devOut) || (odNew == null)) return;
      if (_midiClock.IsRunning) { _midiClock.Stop(); _midiClock.Reset(); }
      if ((_devOut != null) && _devOut.IsOpen) _devOut.Close();
      _devOut = odNew;
      _devOut.Open();
      _midiClock.Start();
 }
Exemple #26
0
 public void NoteOff(NoteOffMessage msg, OutputDevice output)
 {
     output.SendNoteOn(msg.Channel, currentNote, 127);
 }
Exemple #27
0
 public SingleNoteCube(Point3D center, double radius,
         Pitch pitch, Instrument instrument, OutputDevice device, Channel channel)
     : base(center, radius, new InstrumentNoteAction(device, channel, pitch)) {
 }
        /// <summary>
        /// Function to connect with a LaunchpadDevice
        /// </summary>
        /// <param name="device">The Launchpad to connect to.</param>
        /// <returns>Returns bool if connection was successful.</returns>
        public bool connect(LaunchpadDevice device)
        {
            foreach(InputDevice id in Midi.InputDevice.InstalledDevices)
            {
                if (id.Name.ToLower() == device._midiName.ToLower())
                {
                    targetInput = id;
                    id.Open();
                    targetInput.NoteOn += new InputDevice.NoteOnHandler(midiPress);
                    targetInput.StartReceiving(null);
                }
            }
            foreach (OutputDevice od in Midi.OutputDevice.InstalledDevices)
            {
                if (od.Name.ToLower() == device._midiName.ToLower())
                {
                    targetOutput = od;
                    od.Open();
                }
            }

            return true; // targetInput.IsOpen && targetOutput.IsOpen;
        }
Exemple #29
0
 internal InfoObject(GeneratorFramework generatorFramework, OutputDevice device, Clock clock)
 {
     Device = device;
     Clock = clock;
 }
 /// <summary>
 /// output MIDI device has been changed
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void selectDevice(object sender, RoutedEventArgs e)
 {
     if (outputDevice != null) outputDevice.Close();
     try
     {
         outputDevice = OutputDevice.InstalledDevices[this.outDevices.SelectedIndex];
         outputDevice.Open();
     }
     catch (Midi.DeviceException exception)
     {
         log("MIDI device exception: " + exception.Message, "error");
     }
 }
 /// <summary>
 /// Private method for constructing the array of MidiOutputDevices by calling the Win32 api.
 /// </summary>
 /// <returns></returns>
 private static OutputDevice[] MakeDeviceList()
 {
     uint outDevs = Win32API.midiOutGetNumDevs();
     OutputDevice[] result = new OutputDevice[outDevs];
     for (uint deviceId = 0; deviceId < outDevs; deviceId++)
     {
         Win32API.MIDIOUTCAPS caps = new Win32API.MIDIOUTCAPS();
         Win32API.midiOutGetDevCaps((UIntPtr)deviceId, out caps);
         result[deviceId] = new OutputDevice((UIntPtr)deviceId, caps);
     }
     return result;
 }
Exemple #32
0
 public void NoteOn(NoteOnMessage msg, OutputDevice output)
 {
     if(msg.Pitch.Octave()*12+msg.Pitch.PositionInOctave() < 41)
         output.SendNoteOn(msg.Channel, msg.Pitch - 12, msg.Velocity);
 }
Exemple #33
0
 public MidiDevice(string deviceName)
 {
     OutputDevice = MidiIO.GetOutputDevice(deviceName);
 }