partial void Execute_MidiOnCommand()
        {
            _MidiDevices.Clear();
            for (var device = 0; device < NAudio.Midi.MidiIn.NumberOfDevices; device++)
            {
                _MidiDevices.Add(NAudio.Midi.MidiIn.DeviceInfo(device).ProductName);
            }
            if (_MidiDevices.Count > 0)
            {
                MidiDevice = MidiDevices[0];
            }
            var selectedMidiDevice = MidiDevices.IndexOf(MidiDevice);

            try {
                if (selectedMidiDevice >= 0)
                {
                    MidiEnabled = true;

                    midiIn = new MidiIn(selectedMidiDevice);
                    midiIn.MessageReceived += MidiMessageReceived;

                    midiIn.Start();
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 2
0
 private int NanoFind() //polling is mandatory, naudio does not implement a watcher
 {
     for (int device = 0; device < MidiIn.NumberOfDevices; device++)
     {
         if ((MidiIn.DeviceInfo(device).ProductId == 65535))//checks that nano slider is present
         {
             if (nanoID != device)
             {
                 nanoID = device;
                 try
                 {
                     midiIn = new MidiIn(nanoID);
                 }
                 catch (Exception e)
                 {
                     Debug.WriteLine(e.Message);
                     nanoSliderTray.midiAlredyInUse();
                 }
                 midiIn.MessageReceived        += MidiIn_MessageReceived;
                 SystemEvents.PowerModeChanged += OnPowerChange;
                 midiIn.Start();
                 nanoSliderTray.Ready();
                 if (settings.notifyStatus)
                 {
                     nanoSliderTray.ReadyBaloon();
                 }
             }
             showed = false;
             return(nanoID);
         }
     }
     nanoID = -1;
     showed = nanoSliderTray.NanoNotPresentMB(showed);
     return(nanoID);
 }
Exemplo n.º 3
0
 private void openDevice(int i)
 {
     if (i < 1)
     {
         return;
     }
     if (midiIn != null)
     {
         midiIn.Stop();
         midiIn.Dispose();
         midiIn         = null;
         selectedDevice = 0;
     }
     try
     {
         midiIn = new MidiIn(i - 1);
         midiIn.MessageReceived += MIDIMessageReceived;
         midiIn.ErrorReceived   += MIDIErrorReceived;
         midiIn.Start();
         selectedDevice = i;
     }
     catch (Exception e)
     {
         midiIn         = null;
         selectedDevice = 0;
         owner.logText(string.Format("Error: Cannot Open MIDI Device {0}: {1}",
                                     devices[i], e.Message));
     }
     if (selectedDevice > 0)
     {
         slDev.selectedItem = selectedDevice;
         slDev.Enabled      = false;
         online             = true;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 割り込みスタート
 /// MIDIキー操作があるとmidiIn_MessageRecievedが呼ばれる
 /// </summary>
 /// <returns>-1:No MIDI INPUT DEVICE 0:OK</returns>
 public int StartMonitoring()
 {
     if (MIDIInList.Count == 0 || _index == -1)
     {
         //MessageBox.Show("No MIDI input devices available");
         return(-1);
     }
     if (midiIn != null)
     {
         midiIn.Dispose();
         midiIn.MessageReceived -= midiIn_MessageReceived;
         midiIn.ErrorReceived   -= midiIn_ErrorReceived;
         midiIn = null;
     }
     if (midiIn == null)
     {
         midiIn = new MidiIn(_index);
         midiIn.MessageReceived += midiIn_MessageReceived;
         midiIn.ErrorReceived   += midiIn_ErrorReceived;
     }
     midiIn.Start();
     monitoring   = true;
     turntable[0] = new MIDITurnTable();
     turntable[1] = new MIDITurnTable();
     return(0);
 }
Exemplo n.º 5
0
 private void handleMidiMessages()
 {
     midiIn = new MidiIn(selectedDevice);
     midiIn.MessageReceived += midiIn_MessageReceived;
     midiIn.ErrorReceived   += midiIn_ErrorReceived;
     midiIn.Start();
 }
Exemplo n.º 6
0
        private void midiInConfirmButton_Click(object sender, EventArgs e)
        {
            if (inReady)
            {
                midiInput.Stop();
                midiInput.Close();
                midiInput.Dispose();

                midiInDevicesCB.Enabled        = true;
                refreshMidiInButton.Enabled    = true;
                midiInConfirmButton.ImageIndex = 0;
                inReady = false;
                checkReady(true);
            }
            else
            {
                midiInDevicesCB.Enabled     = false;
                refreshMidiInButton.Enabled = false;

                midiInput = new MidiIn(midiInDevicesCB.SelectedIndex);
                midiInput.MessageReceived += midiInput_MessageReceived;
                midiInput.ErrorReceived   += midiInput_ErrorReceived;
                midiInput.Start();

                midiInConfirmButton.ImageIndex = 1;
                inReady = true;
                checkReady(true);
            }
        }
Exemplo n.º 7
0
        private static void ScanAndRegisterToMidiDevices(bool logInformation = false)
        {
            for (int index = 0; index < MidiIn.NumberOfDevices; index++)
            {
                var deviceInfo = MidiIn.DeviceInfo(index);

                if (logInformation)
                {
                    Log.Debug("Scanning " + deviceInfo.ProductName);
                }

                MidiIn newMidiIn;
                try
                {
                    newMidiIn = new MidiIn(index);
                }
                catch (NAudio.MmException e)
                {
                    Log.Error(" > " + e.Message + " " + MidiIn.DeviceInfo(index).ProductName);
                    continue;
                }

                foreach (var midiConsumer in MidiConsumers)
                {
                    newMidiIn.MessageReceived += midiConsumer.MessageReceivedHandler;
                    newMidiIn.ErrorReceived   += midiConsumer.ErrorReceivedHandler;
                }

                newMidiIn.Start();
                MidiInsWithDevices[newMidiIn] = deviceInfo;
                MidiInsByDeviceIdHash[deviceInfo.ProductName.GetHashCode()] = newMidiIn;
            }
        }
Exemplo n.º 8
0
 private void StartMonitoring()
 {
     if (comboBoxMidiInDevices.Items.Count == 0)
     {
         MessageBox.Show("No MIDI input devices available");
         return;
     }
     if (midiIn != null)
     {
         midiIn.Dispose();
         midiIn.MessageReceived -= midiIn_MessageReceived;
         midiIn.ErrorReceived   -= midiIn_ErrorReceived;
         midiIn = null;
     }
     if (midiIn == null)
     {
         midiIn = new MidiIn(comboBoxMidiInDevices.SelectedIndex);
         midiIn.MessageReceived += midiIn_MessageReceived;
         midiIn.ErrorReceived   += midiIn_ErrorReceived;
     }
     midiIn.Start();
     monitoring                    = true;
     buttonMonitor.Text            = "Stop";
     comboBoxMidiInDevices.Enabled = false;
 }
Exemplo n.º 9
0
 private MidiInput(int deviceId)
 {
     Items = new NotesCollection();
     Project.live.Add(this);
     midiIn = new MidiIn(deviceId); // default device
     midiIn.MessageReceived += midiIn_MessageReceived;
     midiIn.Start();
 }
Exemplo n.º 10
0
        static void Main()
        {
            MidiIn midiIN = new MidiIn(0);

            midiIN.Start();
            midiIN.MessageReceived += midIn_MessageReceived;    //Start midi and add listener delegate
            new ManualResetEvent(false).WaitOne();              //We make sure the application does not terminate
        }
Exemplo n.º 11
0
 public void Start(StellaServerLib.StellaServer stellaServer)
 {
     _stellaServer            = stellaServer;
     _midiIn                  = new MidiIn(_deviceIndex);
     _midiIn.MessageReceived += MidiInOnMessageReceived;
     _midiIn.ErrorReceived   += MidiInOnErrorReceived;
     _midiIn.Start();
 }
Exemplo n.º 12
0
        public MidiDevice(MidiIn midiInput, OnNoteOn onNoteOnListener, OnNoteOff onNoteOffListener)
        {
            _midiInput         = midiInput;
            _onNoteOnListener  = onNoteOnListener;
            _onNoteOffListener = onNoteOffListener;

            _midiInput.MessageReceived += OnMidiMessage;
            _midiInput.ErrorReceived   += OnMidiError;
            _midiInput.Start();
        }
Exemplo n.º 13
0
        static int Main(string[] args)
        {
            _soundpad = new Soundpad();


            var config = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText("config.json"));

            Console.WriteLine("The config contains the following information:");
            Console.WriteLine(JsonConvert.SerializeObject(config));
            Console.WriteLine("");

            var audioControl = new AudioControl(config, _soundpad);


            MidiIn midiIn = default;

            for (var device = 0; device < MidiIn.NumberOfDevices; device++)
            {
                Console.WriteLine(MidiIn.DeviceInfo(device).ProductName);

                if (MidiIn.DeviceInfo(device).ProductName.Contains(config.KeypadName))
                {
                    midiIn = new MidiIn(device);
                    midiIn.MessageReceived += audioControl.OnButtonPress;
                    midiIn.ErrorReceived   += MidiInErrorReceived;
                    midiIn.Start();

                    break;
                }
            }

            if (midiIn == null)
            {
                Console.Error.WriteLine("Device with name pad not found.");
                return(-1);
            }

            _soundpad.StatusChanged += audioControl.SoundpadOnStatusChanged;
            _soundpad.ConnectAsync();



            //if (OnButtonPress() == 41)

            /*{
             *  Soundpad.PlaySound(index: 6);
             * }*/
            Console.CancelKeyPress += delegate
            {
                midiIn?.Dispose();
            };
            Console.ReadLine();
            midiIn.Dispose();
            return(0);
        }
Exemplo n.º 14
0
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            for (int device = 0; device < MidiIn.NumberOfDevices; device++)
            {
                comboBoxMidiInDevices.Items.Add(MidiIn.DeviceInfo(device).ProductName);
            }
            if (comboBoxMidiInDevices.Items.Count > 0)
            {
                comboBoxMidiInDevices.SelectedIndex = 0;
            }
            for (int device = 0; device < MidiOut.NumberOfDevices; device++)
            {
                comboBoxMidiOutDevices.Items.Add(MidiOut.DeviceInfo(device).ProductName);
            }
            if (comboBoxMidiOutDevices.Items.Count > 0)
            {
                comboBoxMidiOutDevices.SelectedIndex = 0;
            }

            if (comboBoxMidiInDevices.Items.Count == 0)
            {
                MessageBox.Show("No MIDI input devices available");
            }
            else
            {
                if (midiIn == null)
                {
                    midiIn = new MidiIn(comboBoxMidiInDevices.SelectedIndex);
                    midiIn.MessageReceived += new EventHandler <MidiInMessageEventArgs>(midiIn_MessageReceived);
                    midiIn.ErrorReceived   += new EventHandler <MidiInMessageEventArgs>(midiIn_ErrorReceived);
                }
                midiIn.Start();
                comboBoxMidiInDevices.Enabled = false;
            }

            if (comboBoxMidiOutDevices.Items.Count == 0)
            {
                MessageBox.Show("No MIDI output devices available");
            }
            else
            {
                if (midiOut == null)
                {
                    midiOut = new MidiOut(comboBoxMidiOutDevices.SelectedIndex);
                }
            }

            // Add Audio Output Types
            InitialiseAsioControls();
        }
Exemplo n.º 15
0
        private void listenButton_Click(object sender, EventArgs e)
        {
            midiDevicesCB.Enabled     = false;
            listenButton.Enabled      = false;
            refreshMIDIButton.Enabled = false;

            midiInput = new MidiIn(midiDevicesCB.SelectedIndex);
            midiInput.MessageReceived += midiInput_MessageReceived;
            midiInput.ErrorReceived   += midiInput_ErrorReceived;
            midiInput.Start();
        }
        public MidiInViewModel(int deviceNo)
        {
            this.deviceNo = deviceNo;
            device        = new MidiIn(deviceNo);
            capabilities  = MidiIn.DeviceInfo(deviceNo);

            subscribers = new List <Subscriber>();

            device.MessageReceived += Device_MessageReceived;
            device.ErrorReceived   += Device_ErrorReceived;
            device.Start();
        }
Exemplo n.º 17
0
        private void StartMonitoringMidi()
        {
            string[] drivers = AsioOut.GetDriverNames();

            try
            {
                MidiIn midi = new MidiIn(0);
                midi.MessageReceived += Midi_MessageReceived;
                midi.Start();
            }
            catch { }
        }
Exemplo n.º 18
0
        private void MidiDeviceList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (midiIn != default(MidiIn))
            {
                midiIn.Stop();
                midiIn.Dispose();
            }

            midiIn = new MidiIn(((KeyValuePair <int, String>)midiDeviceList.SelectedItem).Key);
            midiIn.MessageReceived += MidiIn_MessageReceived;
            midiIn.Start();
        }
Exemplo n.º 19
0
        public void Start()
        {
            MidiIn.ReceivedMidiEvent        += MidiInOnReceivedMidiEvent;
            MidiIn.ReceivedExclusiveMessage += MidiInOnReceivedExclusiveMessage;
            MidiIn.Start();
            Driver.ResetHardware();
            Driver.ResetSoftware();

            Driver.Section(() => Driver.SetSequencerSetting(SequencerSetting.AllKeyOff | SequencerSetting.AllMute | SequencerSetting.AllEgReset |
                                                            SequencerSetting.R_FIFOR | SequencerSetting.R_SEQ | SequencerSetting.R_FIFO), 1);

            Driver.Section(() => Driver.SetSequencerSetting(SequencerSetting.Reset));
        }
Exemplo n.º 20
0
        public void Start()
        {
            _controllerDef = JsonConvert.DeserializeObject <ControllerDefinition>(
                File.ReadAllText(_definitionPath));
            _userProfile = JsonConvert.DeserializeObject <UserProfile>(
                File.ReadAllText(_profilePath));

            _midiIn  = FindMidiIn(_controllerDef.MidiInName);
            _midiOut = FindMidiOut(_controllerDef.MidiOutName);
            _midiIn.MessageReceived += MidiIn_MessageReceived;
            _midiIn.ErrorReceived   += MidiIn_ErrorReceived;
            _midiIn.Start();
        }
Exemplo n.º 21
0
 private void StartMonitoring()
 {
     if (midiIn == null)
     {
         midiIn = new MidiIn(comboBoxMidiInDevices.SelectedIndex);
         midiIn.MessageReceived += new EventHandler <MidiInMessageEventArgs>(midiIn_MessageReceived);
         midiIn.ErrorReceived   += new EventHandler <MidiInMessageEventArgs>(midiIn_ErrorReceived);
     }
     midiIn.Start();
     monitoring                    = true;
     buttonMonitor.Text            = "Stop";
     comboBoxMidiInDevices.Enabled = false;
 }
Exemplo n.º 22
0
        private void MidiInputListener(bool enableListener)
        {
            if (enableListener)
            {
                _mIn.Start();
            }
            else
            {
                _mIn.Stop();
            }

            _userInputCycle = 0;
        }
Exemplo n.º 23
0
 /// <inheritdoc />
 public override void ConnectToDevice(int deviceId)
 {
     try
     {
         _connection = new MidiIn(deviceId);
         _connection.MessageReceived += Connection_MessageReceived;
         Device = deviceId;
         _connection.Start();
     }
     catch
     {
         Debug.WriteLine(Resources.Cant_connect_to_midi_in_device + deviceId);
     }
 }
Exemplo n.º 24
0
        partial void Execute_MidiOnCommand()
        {
            var selectedMidiDevice = MidiDevices.IndexOf(MidiDevice);

            if (selectedMidiDevice >= 0)
            {
                MidiEnabled             = true;
                midiIn                  = new MidiIn(selectedMidiDevice);
                midiIn.MessageReceived += MidiMessageReceived;
                // midiIn.ErrorReceived += MidiErrorReceived;
                midiIn.Start();
                ResetCanExecute();
            }
        }
Exemplo n.º 25
0
        public void StartMIDIInMonitoring()
        {
            if (setting.midiKbd.MidiInDeviceName == "")
            {
                return;
            }

            if (midiin != null)
            {
                try
                {
                    midiin.Stop();
                    midiin.Dispose();
                    midiin.MessageReceived -= midiIn_MessageReceived;
                    midiin.ErrorReceived   -= midiIn_ErrorReceived;
                    midiin = null;
                }
                catch
                {
                    midiin = null;
                }
            }

            if (midiin == null)
            {
                for (int i = 0; i < MidiIn.NumberOfDevices; i++)
                {
                    if (!setting.midiKbd.UseMIDIKeyboard)
                    {
                        continue;
                    }
                    if (setting.midiKbd.MidiInDeviceName != MidiIn.DeviceInfo(i).ProductName)
                    {
                        continue;
                    }
                    try
                    {
                        midiin = new MidiIn(i);
                        midiin.MessageReceived += midiIn_MessageReceived;
                        midiin.ErrorReceived   += midiIn_ErrorReceived;
                        midiin.Start();
                    }
                    catch
                    {
                        midiin = null;
                    }
                }
            }
        }
Exemplo n.º 26
0
 public void OpenIn(int index)
 {
     CloseIn();
     try
     {
         midiIn             = new MidiIn(index);
         midiIn.OnLongMsg  += OnLongMessage;
         midiIn.OnShortMsg += OnShortMessage;
         midiIn.Start();
     }
     catch (Exception ex)
     {
         Trace.WriteLine("Error occured: " + ex.ToString());
     }
 }
Exemplo n.º 27
0
        public void initializeMidi()
        {
            midiIn = new MidiIn(0);


            midiIn.MessageReceived += midiInReceived;
            midiIn.ErrorReceived   += midiIn_ErrorReceived;



            MidiThread = new Thread(() => {
                midiIn.Start();
            });

            MidiThread.Start();
        }
 public void Init(int inDeviceNo, int outDeviceNo)
 {
     if (_initialized)
     {
         _inDevice.Stop();
         _inDevice.Close();
         _inDevice.Dispose();
         _outDevice.Close();
         _outDevice.Dispose();
     }
     _inDevice  = new MidiIn(inDeviceNo);
     _outDevice = new MidiOut(outDeviceNo);
     _inDevice.MessageReceived += MessageReceived;
     _inDevice.ErrorReceived   += ErrorReceived;
     _inDevice.Start();
     _initialized = true;
 }
Exemplo n.º 29
0
        public Monitor(string processToSendKeyPressesTo)
        {
            _numberOfDevices    = MidiIn.NumberOfDevices;
            _midiInCapabilities = GetMidiInCapabilities();

            MidiIns = new List <MidiIn>();
            for (int i = 0; i < _numberOfDevices; i++)
            {
                var midiIn = new MidiIn(i);
                midiIn.MessageReceived += MidiIn_MessageReceived;
                midiIn.ErrorReceived   += MidiIn_ErrorReceived;
                midiIn.Start();
                MidiIns.Add(midiIn);
            }

            _processes = Process.GetProcessesByName(processToSendKeyPressesTo);
        }
Exemplo n.º 30
0
 public void SetMidiIn(int deviceNo)
 {
     try
     {
         midiIn = new MidiIn(deviceNo);
     }
     catch (NAudio.MmException mme)
     {
         Console.WriteLine(MidiIn.NumberOfDevices);
         Console.WriteLine(MidiIn.DeviceInfo(deviceNo).ProductName);
         Console.WriteLine($"Midi device {deviceNo} not available.");
         throw mme;
     }
     midiIn.MessageReceived += HandleMidiIn;
     midiIn.ErrorReceived   += HandleMidiError;
     midiIn.Start();
 }
Exemplo n.º 31
0
		public MidiInRender()
		{
			midiIn = new MidiIn();
			midiIn.OnMidiMessage += new MidiMessageHandler(OnMidiMessageHandler);
			midiIn.Start();
		}