Ejemplo n.º 1
0
        // Get the specific list based on the property name.
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            List <string>?rec = null;

            switch (context.PropertyDescriptor.Name)
            {
            case "MidiInDevice":
                rec = new List <string>();
                for (int devindex = 0; devindex < MidiIn.NumberOfDevices; devindex++)
                {
                    rec.Add(MidiIn.DeviceInfo(devindex).ProductName);
                }
                break;

            case "MidiOutDevice":
                rec = new List <string>();
                for (int devindex = 0; devindex < MidiOut.NumberOfDevices; devindex++)
                {
                    rec.Add(MidiOut.DeviceInfo(devindex).ProductName);
                }
                break;
            }

            return(new StandardValuesCollection(rec));
        }
Ejemplo n.º 2
0
        public MIDIControlWizardViewModel(string title, HardwareSettingsViewModel hardwareSettings)
        {
            _hardwareSettings = hardwareSettings;

            Title = title;

            SaveMidiControlCommand = new RelayCommand(SaveMidiControl);
            SetMinValueCommand     = new RelayCommand(SetMinValue);
            SetMaxValueCommand     = new RelayCommand(SetMaxValue);

            _availableMidiInDevices = MidiIn.GetAllDevices();

            _dispatcher = System.Windows.Threading.Dispatcher.FromThread(System.Threading.Thread.CurrentThread);

            // Default scaling maximum is 1 .
            ScalingMaximum = 1;

            // Default scaling tick frequency is 0.01 .
            ScalingTickFrequency = 0.01F;

            // Scaling value slider has a default value of 1.0 .
            ScalingValue = 1.0F;

            // Set default control type selection.
            ControlTypeSelected = _controlTypeSelected;
        }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
        public void RefreshConnectedDevices()
        {
            _connectedInputDevices = new ConcurrentDictionary <string, List <int> >();
            for (var i = 0; i < MidiIn.NumberOfDevices; i++)
            {
                var infoIn = MidiIn.DeviceInfo(i);
                if (!_connectedInputDevices.ContainsKey(infoIn.ProductName))
                {
                    _connectedInputDevices.TryAdd(infoIn.ProductName, new List <int>());
                }
                _connectedInputDevices[infoIn.ProductName].Add(i);
            }

            _connectedOutputDevices = new ConcurrentDictionary <string, List <int> >();
            for (int i = 0; i < MidiOut.NumberOfDevices; i++)
            {
                var infoOut = MidiOut.DeviceInfo(i);
                if (!_connectedOutputDevices.ContainsKey(infoOut.ProductName))
                {
                    _connectedOutputDevices.TryAdd(infoOut.ProductName, new List <int>());
                }
                _connectedOutputDevices[infoOut.ProductName].Add(i);
            }
            BuildInputDeviceList();
            BuildOutputDeviceList();
        }
Ejemplo n.º 5
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            f2 = new FormSettings();
            cm = new ChooseModule();
            int k = 0;

            k = MidiOut.NumberOfDevices;
            for (int i = 0; i < k; i++)
            {
                f2.comboBox1.Items.Add(MidiOut.DeviceInfo(i).ProductName.ToString());
            }
            if (k > 0)
            {
                f2.comboBox1.SelectedIndex = 0;
            }
            k = 0;
            k = MidiIn.NumberOfDevices;
            for (int i = 0; i < k; i++)
            {
                f2.comboBox3.Items.Add(MidiIn.DeviceInfo(i).ProductName.ToString());
            }
            if (k > 0)
            {
                f2.comboBox3.SelectedIndex = 0;
            }
            f2.comboBox2.SelectedIndex = 0;
            f2.StartPosition           = FormStartPosition.CenterParent;
            f2.FormClosing            += SettingsClose;
            f2.ShowDialog();
            cm.StartPosition = FormStartPosition.CenterScreen;
            cm.FormClosing  += ChooseModuleClose;
        }
 public static IEnumerable <MidiInCapabilities> GetConnectedInputDevices()
 {
     for (var i = 0; i < MidiIn.NumberOfDevices; ++i)
     {
         yield return(MidiIn.DeviceInfo(i));
     }
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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;
            }
        }
Ejemplo n.º 9
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;
     }
 }
Ejemplo n.º 10
0
 private void handleMidiMessages()
 {
     midiIn = new MidiIn(selectedDevice);
     midiIn.MessageReceived += midiIn_MessageReceived;
     midiIn.ErrorReceived   += midiIn_ErrorReceived;
     midiIn.Start();
 }
Ejemplo n.º 11
0
        public MidiDriver(IList <ToneItem> toneItems, IList <EqualizerItem> equalizerItems, MidiIn midiIn, Ymf825Driver driver)
        {
            ToneItems      = toneItems;
            EqualizerItems = equalizerItems;
            MidiIn         = midiIn;
            Driver         = driver;
            Driver.EnableSectionMode();

            for (var i = 0; i < 16; i++)
            {
                noteOnKeys[i]  = -1;
                pitchBends[i]  = 1.0;
                corrections[i] = 1.0;

                volumes[i]     = 100.0 / 127.0;
                toneVolumes[i] = 1.0;
                lchVolumes[i]  = 1.0;
                rchVolumes[i]  = 1.0;
                expressions[i] = 1.0;

                rpnMsb[i]         = 127;
                rpnLsb[i]         = 127;
                fineTune[i]       = 1.0;
                pitchBendWidth[i] = 2.0;
            }
        }
Ejemplo n.º 12
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);
            }
        }
        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)
            {
            }
        }
Ejemplo n.º 14
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;
 }
Ejemplo n.º 15
0
 public Controller(string inputDeviceName, string outputDeviceName)
 {
     this.midiIn = MidiInformation.GetInputDeviceWithName(inputDeviceName);
     this.midiIn.Start();
     this.midiIn.MessageReceived += MessageReceived;
     this.midiOut = MidiInformation.GetOutputDeviceWithName(outputDeviceName);
 }
Ejemplo n.º 16
0
        //[TestMethod()]
        public void GetMessageTest()
        {
            int cnt = MidiIn.GetDeviceCount();

            Assert.IsFalse(cnt == 0);
            for (int i = 0; i < cnt; i++)
            {
                Console.WriteLine(MidiIn.GetDeviceName(i));
            }
            MidiIn        mi      = MidiIn.Create(MidiIn.GetDeviceName(0));
            List <object> message = new List <object>();
            Stopwatch     s       = new Stopwatch();

            s.Start();
            while (s.ElapsedMilliseconds < 2500)
            {
                ;
            }
            do
            {
                List <object> ret = mi.GetMessage();
                if (ret != null)
                {
                    message.AddRange(ret);
                }
            } while (s.ElapsedMilliseconds < 5000);
            Assert.Fail();
        }
Ejemplo n.º 17
0
    private void frmConfig_Load(object sender, EventArgs e)
    {
        List <float> flist = new List <float>();

        flist.Add(0);
        flist.Add(2);
        flist.Add(4);
        flist.Add(6);
        flist.Add(8);
        flist.Add(10);
        DiscDraw.Draw(pictureBox1, flist);
        DiscDraw.Draw(pictureBox2, flist);

        _config = Config.ReadXML(configFilename);

        lstMIDIEvent.Items.Clear();
        //ASIOドライバー一覧取得
        foreach (string device in AsioOut.GetDriverNames())
        {
            cboAsioDriver.Items.Add(device);
        }
        if (cboAsioDriver.Items.Count > 0)
        {
            cboAsioDriver.SelectedIndex = 0;
        }
        //MIDI入力デバイス一覧取得
        for (int device = 0; device < MidiIn.NumberOfDevices; device++)
        {
            cboMIDIINDEVICE.Items.Add(MidiIn.DeviceInfo(device).ProductName);
        }
        if (cboMIDIINDEVICE.Items.Count > 0)
        {
            cboMIDIINDEVICE.SelectedIndex = 0;
        }
    }
Ejemplo n.º 18
0
 private MidiInput(int deviceId)
 {
     Items = new NotesCollection();
     Project.live.Add(this);
     midiIn = new MidiIn(deviceId); // default device
     midiIn.MessageReceived += midiIn_MessageReceived;
     midiIn.Start();
 }
Ejemplo n.º 19
0
 public Midi(int ticksPerQuarterNote)
 {
     this.ticksPerQuarterNote = ticksPerQuarterNote;
     currentNoteNumbers       = new List <int>();
     CurrentNoteNumbers       = currentNoteNumbers;
     midiIn = null;
     microsecondsPerQuarterNote = 2000000; // 120 Bpm = 2 Bps
 }
Ejemplo n.º 20
0
 public void Start(StellaServerLib.StellaServer stellaServer)
 {
     _stellaServer            = stellaServer;
     _midiIn                  = new MidiIn(_deviceIndex);
     _midiIn.MessageReceived += MidiInOnMessageReceived;
     _midiIn.ErrorReceived   += MidiInOnErrorReceived;
     _midiIn.Start();
 }
Ejemplo n.º 21
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
        }
Ejemplo n.º 22
0
 public MidiInput(int devId)
 {
     base.DeviceID    = new DeviceId();
     base.DeviceID.id = devId;
     base.DeviceID.t  = EDeviceType.In;
     base.DeviceName  = MidiIn.DeviceInfo(devId).ProductName;
     this.InputDevice = new MidiIn(devId);
     this.InputDevice.MessageReceived += new EventHandler <MidiInMessageEventArgs>(this.HandleMsgReceived);
 }
Ejemplo n.º 23
0
 public static string[] GetInputDevices()
 {
     string[] names = new string[MidiIn.NumberOfDevices];
     for (int i = 0; i < MidiIn.NumberOfDevices; i++)
     {
         names[i] = MidiIn.DeviceInfo(i).ProductName;
     }
     return(names);
 }
Ejemplo n.º 24
0
 public void fillDevicesList()
 {
     devices = new List <string>();
     devices.Add("[NONE]");
     for (int i = 0; i < MidiIn.NumberOfDevices; i++)
     {
         devices.Add(String.Format("{0}", MidiIn.DeviceInfo(i).ProductName));
     }
 }
Ejemplo n.º 25
0
 public void Dispose()
 {
     if (Disposed)
     {
         return;
     }
     MidiIn.Stop();
     MidiIn.Dispose();
     MidiIn = null;
 }
Ejemplo n.º 26
0
        public MidiDevice(MidiIn midiInput, OnNoteOn onNoteOnListener, OnNoteOff onNoteOffListener)
        {
            _midiInput         = midiInput;
            _onNoteOnListener  = onNoteOnListener;
            _onNoteOffListener = onNoteOffListener;

            _midiInput.MessageReceived += OnMidiMessage;
            _midiInput.ErrorReceived   += OnMidiError;
            _midiInput.Start();
        }
Ejemplo n.º 27
0
 private void comboBoxMidiInSelect_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (Device != null)
     {
         Trace.WriteLine("Opening MIDI-IN: " + comboBoxMidiInSelect.Items[comboBoxMidiInSelect.SelectedIndex]);
         Device.OpenIn(comboBoxMidiInSelect.SelectedIndex);
         try { Config.lastSelectedMidiIn = MidiIn.GetDeviceNames()[comboBoxMidiInSelect.SelectedIndex]; }
         catch { }
     }
 }
Ejemplo n.º 28
0
        private List <MidiInCapabilities> GetMidiInCapabilities()
        {
            var devices = new List <MidiInCapabilities>();

            for (int i = 0; i < _numberOfDevices; i++)
            {
                devices.Add(MidiIn.DeviceInfo(i));
            }
            return(devices);
        }
Ejemplo n.º 29
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);
        }
Ejemplo n.º 30
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();
        }
Ejemplo n.º 31
0
		public MidiInRender()
		{
			midiIn = new MidiIn();
			midiIn.OnMidiMessage += new MidiMessageHandler(OnMidiMessageHandler);
			midiIn.Start();
		}