public static unsafe string GetDeviceName(int idx) { MIDIINCAPS caps = new MIDIINCAPS(); midiInGetDevCaps((uint)idx, new IntPtr(&caps), (uint)Marshal.SizeOf <MIDIINCAPS>()); return(new string(caps.szPname)); }
public MIDI入力デバイス() { using (Log.Block(FDKUtilities.現在のメソッド名)) { // 初期化する。 this._MIDI入力デバイスハンドルリスト = new List <MIDIINHANDLE>(5); // 5個もあれば十分? this._蓄積用入力イベントリスト = new List <InputEvent>(32); // 適当 this.入力イベントリスト = new List <InputEvent>(); // コールバックをデリゲートとして生成し、そのデリゲートをGCの対象から外す。 this._midiInProc = new MidiInProc(this.MIDI入力コールバック); this._midiInProcGCh = GCHandle.Alloc(this._midiInProc); // デバイス数を取得。 uint MIDI入力デバイス数 = midiInGetNumDevs(); Log.Info($"MIDI入力デバイス数 = {MIDI入力デバイス数}"); // すべてのMIDI入力デバイスについて... for (uint id = 0; id < MIDI入力デバイス数; id++) { // デバイス名を取得。 var caps = new MIDIINCAPS(); midiInGetDevCaps(id, ref caps, Marshal.SizeOf(caps)); this.DeviceName.Add(caps.szPname); Log.Info($"MidiIn[{id}]: {caps.szPname}"); // MIDI入力デバイスを開く。コールバックは全デバイスで共通。 MIDIINHANDLE hMidiIn = default; if (((uint)CSCore.MmResult.NoError == midiInOpen(ref hMidiIn, id, this._midiInProc, default, CALLBACK_FUNCTION)) && (default != hMidiIn))
// 生成と終了 public MidiIns() { using var _ = new LogBlock(Log.現在のメソッド名); // コールバックをデリゲートとして生成し、そのデリゲートをGCの対象から外す。 this._midiInProc = new MidiInProc(this.MIDI入力コールバック); this._midiInProcGCh = GCHandle.Alloc(this._midiInProc); // デバイス数を取得。 uint MIDI入力デバイス数 = midiInGetNumDevs(); Log.Info($"MIDI入力デバイス数 = {MIDI入力デバイス数}"); // すべてのMIDI入力デバイスについて... for (uint id = 0; id < MIDI入力デバイス数; id++) { // デバイス名を取得。 var caps = new MIDIINCAPS(); midiInGetDevCaps(id, ref caps, Marshal.SizeOf(caps)); this.DeviceName.Add(caps.szPname); Log.Info($"MidiIn[{id}]: {caps.szPname}"); // MIDI入力デバイスを開く。コールバックは全デバイスで共通。 IntPtr hMidiIn = default; if (((uint)CSCore.MmResult.NoError == midiInOpen(ref hMidiIn, id, this._midiInProc, default, CALLBACK_FUNCTION)) && (default != hMidiIn))
/// <summary> /// Internal Constructor, only called by the getter for the InstalledDevices property. /// </summary> /// <param name="deviceId">Position of this device in the list of all devices.</param> /// <param name="caps">Win32 Struct with device metadata</param> internal InputDevice(UIntPtr deviceId, MIDIINCAPS caps) : base(caps.szPname) { _deviceId = deviceId; _caps = caps; _inputCallbackDelegate = InputCallback; _isOpen = false; _clock = null; _nrpnWatcher = new NrpnWatcher(this); }
private void Dummy() { //* never called - only here to stop compiler warnings!!! MIDIINCAPS m = new MIDIINCAPS(); m.wMid = 0; m.wPid = 0; m.vDriverVersion = 0; m.szPname = ""; m.dwSupport = 0; }
internal static MIDIINCAPS midiInGetDevCaps(int uDeviceID) { MIDIINCAPS res = new MIDIINCAPS(); MMRESULT err = midiInGetDevCaps(uDeviceID, ref res, (uint)Marshal.SizeOf(typeof(MIDIINCAPS))); if (err != MMRESULT.MMSYSERR_NOERROR) { throw new Exception("err: " + err.ToString()); } return(res); }
public void Start() { uint DeviceCount = GetDeviceCount(); Log.Info($"There {(DeviceCount != 1 ? "are" : "is")} {DeviceCount} MIDI input {(DeviceCount != 1 ? "devices" : "device")} connected."); if (DeviceCount == 0) { Log.Error("No MIDI devices were found. No audio will be received by ColorChord.NET!"); return; } uint DeviceToUse = 0; string DeviceToUseName = "N/A"; for (uint i = 0; i < DeviceCount; i++) { MIDIINCAPS?DeviceInfoPerhaps = GetDeviceInfo(i); if (DeviceInfoPerhaps == null) { Log.Info($" [{i}] Could not get info."); } else { MIDIINCAPS DeviceInfo = DeviceInfoPerhaps.Value; if (this.ShowDeviceInfo) { Log.Info($" [{i}] \"{DeviceInfo.ProductName}\" Manufacturer {DeviceInfo.ManufacturerID:X2}, Product {DeviceInfo.ProductID:X2}, Driver {DeviceInfo.DriverVersion}"); } if (this.DeviceName != "default" && this.DeviceName == DeviceInfo.ProductName) { DeviceToUse = i; DeviceToUseName = DeviceInfo.ProductName; } if (this.DeviceName == "default" && i == 0) { DeviceToUseName = DeviceInfo.ProductName; } } } Log.Info($"Using device ID {DeviceToUse}, \"{DeviceToUseName}\"."); bool Opened = OpenDevice(DeviceToUse, this.Callback); if (!Opened) { return; } bool Started = StartReceiver(this.DeviceHandle); Log.Info(Started ? "Started MIDI receiver." : "Failed to start MIDI receiver."); }
public static string MidiInGetName(int index) { MIDIINCAPS caps = new MIDIINCAPS(); int error = MidiInGetDevCaps(index, ref caps, 44); if (error == 0) { return(caps.szPname); } else { return(""); } }
//***************************** Информация об устройстве ********************* public int InGetCaps(uint dev) { uInDeviceID = dev; // Можно сделать выбор! midiInCaps = new MIDIINCAPS(); uint res = MIDIInGetDevCaps(uInDeviceID, out midiInCaps, (uint)Marshal.SizeOf(midiInCaps)); if (res != MMSYSERR_NOERROR) { string str = ""; MIDIInGetErrorText(res, str, 255); MessageBox.Show("Error = " + str); return(-1); } return(0); }
public static uint?FindInputIdByName(string name) { uint midiDevNum = NativeImports.midiInGetNumDevs(); for (uint i = 0; i < midiDevNum; i++) { MIDIINCAPS capsResult = default; NativeImports.ThrowOnError(NativeImports.midiInGetDevCaps(i, ref capsResult)); if (capsResult.szPname == name) { return(i); } } return(null); }
internal string[] _GetDevs() { string[] devs = new string[GetNumDevs()]; MIDIINCAPS midiincaps = new MIDIINCAPS(); for (int d = 0; d < devs.Length; d++) { int ret = GetDevCaps(d, ref midiincaps, Marshal.SizeOf(midiincaps)); if (ret != 0) { throw new MidiIOException(ret, d.ToString()); } devs[d] = midiincaps.szPname; } return(devs); }
/// <summary> /// Loads/reloads the MIDI input devices /// </summary> public static void LoadInputDevices() { inputDevices = null; List<InputDevice> devices = new List<InputDevice>(); UInt32 numberOfInDevices = Functions.midiInGetNumDevs(); if(numberOfInDevices > 0) { for(Int32 i = 0 ; i < numberOfInDevices ; i++) { MIDIINCAPS caps = new MIDIINCAPS(); if(Functions.midiInGetDevCaps(i, ref caps, (UInt32) Marshal.SizeOf(caps)) == Constants.MMSYSERR_NOERROR) { devices.Add(new InputDevice(i, caps)); } } } inputDevices = devices.AsReadOnly(); }
private static List <MidiDeviceInfoImpl> getMidiIn() { if (mMidiIn == null) { mMidiIn = new List <MidiDeviceInfoImpl>(); int num = 0; try { num = (int)win32.midiInGetNumDevs(); } catch { num = 0; } for (int i = 0; i < num; i++) { MIDIINCAPS m = new MIDIINCAPS(); uint r = win32.midiInGetDevCaps((uint)i, ref m, (uint)System.Runtime.InteropServices.Marshal.SizeOf(m)); MidiDeviceInfoImpl impl = new MidiDeviceInfoImpl(m.szPname, "", "", m.vDriverVersion + "", true, i); mMidiIn.Add(impl); } } return(mMidiIn); }
/// <summary> /// Fills in the capabilities struct for a specific input device. /// </summary> /// NOTE: This is adapted from the original Win32 function in order to make it typesafe. /// /// Win32 docs: http://msdn.microsoft.com/en-us/library/ms711604(VS.85).aspx public static MMRESULT midiInGetDevCaps(UIntPtr uDeviceID, out MIDIINCAPS caps) { return(midiInGetDevCaps(uDeviceID, out caps, (UInt32)Marshal.SizeOf(typeof(MIDIINCAPS)))); }
internal static extern uint midiInGetDevCaps(UIntPtr uDeviceID, out MIDIINCAPS caps, uint cbMidiInCaps);
public static extern int midiInGetDevCaps(int uDeviceID, ref MIDIINCAPS lpCaps, int uSize);
public static extern uint midiInGetDevCaps(uint uDeviceID, ref MIDIINCAPS lpMidiInCaps, uint cbMidiInCaps);
static extern int midiInGetDevCaps(int deviceIndex, ref MIDIINCAPS caps, int sizeOfMidiInCaps);
/// <summary> /// Fills in the capabilities struct for a specific input device. /// </summary> /// NOTE: This is adapted from the original Win32 function in order to make it typesafe. /// /// Win32 docs: http://msdn.microsoft.com/en-us/library/ms711604(VS.85).aspx public static MMRESULT midiInGetDevCaps(UIntPtr uDeviceID, out MIDIINCAPS caps) { return midiInGetDevCaps(uDeviceID, out caps, (UInt32)Marshal.SizeOf(typeof(MIDIINCAPS))); }
public static extern int MidiInGetDevCaps(int uDeviceID, ref MIDIINCAPS caps, int cbMidiInCaps);
private static List<MidiDeviceInfoImpl> getMidiIn() { if( mMidiIn == null ){ mMidiIn = new List<MidiDeviceInfoImpl>(); int num = 0; try { num = (int)win32.midiInGetNumDevs(); } catch { num = 0; } for ( int i = 0; i < num; i++ ) { MIDIINCAPS m = new MIDIINCAPS(); uint r = win32.midiInGetDevCaps( (uint)i, ref m, (uint)System.Runtime.InteropServices.Marshal.SizeOf( m ) ); MidiDeviceInfoImpl impl = new MidiDeviceInfoImpl( m.szPname, "", "", m.vDriverVersion + "", true, i ); mMidiIn.Add( impl ); } } return mMidiIn; }
private uint MIDIInGetDevCaps(uint uDeviceID, out MIDIINCAPS lpCaps, uint uSize) { return(midiInGetDevCaps(uDeviceID, out lpCaps, uSize)); }
public static string MidiInGetName(int index) { MIDIINCAPS caps = new MIDIINCAPS(); int error = MidiInGetDevCaps(index, ref caps, 44); if(error == 0) return caps.szPname; else return ""; }
internal static extern EMMError midiInGetDevCaps(IntPtr uDeviceId, [In, Out] MIDIINCAPS lpMidiInCaps, uint cbMidiInCaps);
private static extern MMRESULT midiInGetDevCaps(UIntPtr uDeviceID, out MIDIINCAPS caps, UInt32 cbMidiInCaps);
internal static extern int midiOutGetDevCaps( IntPtr uDeviceID, out MIDIINCAPS caps, uint cbMidiInCaps);
internal static MMRESULT midiInGetDevCaps(int uDeviceID, ref MIDIINCAPS caps) { return(midiInGetDevCaps(uDeviceID, ref caps, (uint)Marshal.SizeOf(typeof(MIDIINCAPS)))); }
private static extern uint midiInGetDevCaps(uint deviceID, ref MIDIINCAPS caps, uint numBytesToFill);
public static extern uint midiInGetDevCaps(IntPtr uDeviceID, ref MIDIINCAPS caps, uint cbMidiInCaps);
public static uint midiInGetDevCaps(IntPtr uDeviceID, ref MIDIINCAPS caps, uint cbMidiInCaps) { return(MidiWinApi.MMSYSERR_NOERROR); }
internal static extern MMRESULT midiInGetDevCaps(UIntPtr uDeviceID, ref MIDIINCAPS caps, uint cbMidiInCaps);
internal static extern uint midiInGetDevCaps(uint uDeviceID, ref MIDIINCAPS lpCaps, uint uSize);
[DllImport("winmm.dll")] private static extern int midiOutGetDevCaps(int uDeviceID, ref MIDIINCAPS lpMidiInCaps, int cbMidiOutCaps);
internal static extern UInt32 midiInGetDevCaps(Int32 uDeviceID, ref MIDIINCAPS lpMidiInCaps, UInt32 cbMidiInCaps);
private static extern uint midiInGetDevCaps(uint uDeviceID, out MIDIINCAPS caps, uint cbMidiInCaps);
/// <summary> /// Creates a new MIDI input device instance. /// </summary> /// <param name="id">The device's ID.</param> /// <param name="caps">The device's capabilities.</param> internal InputDevice(Int32 id, MIDIINCAPS caps) { ID = id; Name = caps.szPname; }