コード例 #1
0
        private void SetDeviceInformation()
        {
            var caps = default(MidiInWinApi.MIDIINCAPS);

            ProcessMmResult(MidiInWinApi.midiInGetDevCaps(new IntPtr(Id), ref caps, (uint)Marshal.SizeOf(caps)));

            SetBasicDeviceInformation(caps.wMid, caps.wPid, caps.vDriverVersion, caps.szPname);
        }
コード例 #2
0
        public void Start()
        {
            EnsureDeviceIsNotDisposed();
            EnsureHandleIsCreated();

            PrepareSysExBuffer();
            ProcessMmResult(() => MidiInWinApi.midiInStart(_handle));
            _startTime = DateTime.UtcNow;
        }
コード例 #3
0
        private void EnsureHandleIsCreated()
        {
            if (_handle != IntPtr.Zero)
            {
                return;
            }

            _callback = OnMessage;
            ProcessMmResult(MidiInWinApi.midiInOpen(out _handle, Id, _callback, IntPtr.Zero, MidiWinApi.CallbackFunction));
        }
コード例 #4
0
        private void DestroyHandle()
        {
            if (_handle == IntPtr.Zero)
            {
                return;
            }

            MidiInWinApi.midiInReset(_handle);
            MidiInWinApi.midiInClose(_handle);
        }
コード例 #5
0
        /// <summary>
        /// Starts listening for incoming MIDI events on the current input device.
        /// </summary>
        /// <exception cref="ObjectDisposedException">The current <see cref="InputDevice"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public void StartEventsListening()
        {
            EnsureDeviceIsNotDisposed();
            EnsureHandleIsCreated();

            PrepareSysExBuffer();
            ProcessMmResult(MidiInWinApi.midiInStart(_handle));

            IsListeningForEvents = true;
        }
コード例 #6
0
        /// <summary>
        /// Stops listening for incoming MIDI events on the current <see cref="InputDevice"/> and flushes
        /// all pending data.
        /// </summary>
        /// <exception cref="ObjectDisposedException">The current <see cref="InputDevice"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public void Reset()
        {
            EnsureDeviceIsNotDisposed();

            if (_handle == IntPtr.Zero)
            {
                return;
            }

            ProcessMmResult(MidiInWinApi.midiInReset(_handle));
        }
コード例 #7
0
        public void Reset()
        {
            EnsureDeviceIsNotDisposed();

            if (_handle == IntPtr.Zero)
            {
                return;
            }

            ProcessMmResult(() => MidiInWinApi.midiInReset(_handle));
            _startTime = DateTime.UtcNow;
        }
コード例 #8
0
        /// <summary>
        /// Stops listening for incoming MIDI events on the current input device.
        /// </summary>
        /// <exception cref="ObjectDisposedException">The current <see cref="InputDevice"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public void StopEventsListening()
        {
            EnsureDeviceIsNotDisposed();

            if (_handle == IntPtr.Zero)
            {
                return;
            }

            IsListeningForEvents = false;

            ProcessMmResult(MidiInWinApi.midiInStop(_handle));
        }
コード例 #9
0
        private void PrepareSysExBuffer()
        {
            var buffer = new byte[SysExBufferLength];

            _sysExBufferPointer = Marshal.AllocHGlobal(buffer.Length);
            Marshal.Copy(buffer, 0, _sysExBufferPointer, buffer.Length);

            _sysExHeader                = new MidiWinApi.MIDIHDR();
            _sysExHeader.lpData         = _sysExBufferPointer;
            _sysExHeader.dwBufferLength = _sysExHeader.dwBytesRecorded = (uint)buffer.Length;

            ProcessMmResult(() => MidiInWinApi.midiInPrepareHeader(_handle, ref _sysExHeader, Marshal.SizeOf(_sysExHeader)));
            ProcessMmResult(() => MidiInWinApi.midiInAddBuffer(_handle, ref _sysExHeader, Marshal.SizeOf(_sysExHeader)));
        }
コード例 #10
0
        private void UnprepareSysExBuffer(IntPtr headerPointer)
        {
            if (headerPointer == IntPtr.Zero)
            {
                return;
            }

            MidiInWinApi.midiInUnprepareHeader(_handle, headerPointer, MidiWinApi.MidiHeaderSize);

            var header = (MidiWinApi.MIDIHDR)Marshal.PtrToStructure(headerPointer, typeof(MidiWinApi.MIDIHDR));

            Marshal.FreeHGlobal(header.lpData);
            Marshal.FreeHGlobal(headerPointer);
        }
コード例 #11
0
        private void PrepareSysExBuffer()
        {
            var header = new MidiWinApi.MIDIHDR
            {
                lpData          = Marshal.AllocHGlobal(SysExBufferLength),
                dwBufferLength  = SysExBufferLength,
                dwBytesRecorded = SysExBufferLength
            };

            _sysExHeaderPointer = Marshal.AllocHGlobal(MidiWinApi.MidiHeaderSize);
            Marshal.StructureToPtr(header, _sysExHeaderPointer, false);

            ProcessMmResult(MidiInWinApi.midiInPrepareHeader(_handle, _sysExHeaderPointer, MidiWinApi.MidiHeaderSize));
            ProcessMmResult(MidiInWinApi.midiInAddBuffer(_handle, _sysExHeaderPointer, MidiWinApi.MidiHeaderSize));
        }
コード例 #12
0
 public static int GetDevicesCount()
 {
     // TODO: process last error
     // TODO: uint instead of int
     return(MidiInWinApi.midiInGetNumDevs());
 }
コード例 #13
0
 private void UnprepareSysExBuffer()
 {
     ProcessMmResult(() => MidiInWinApi.midiInUnprepareHeader(_handle, ref _sysExHeader, Marshal.SizeOf(_sysExHeader)));
     Marshal.FreeHGlobal(_sysExBufferPointer);
 }
コード例 #14
0
 private void DestroyHandle()
 {
     MidiInWinApi.midiInClose(_handle);
 }
コード例 #15
0
 /// <summary>
 /// Gets error description for the specified MMRESULT which is return value of winmm function.
 /// </summary>
 /// <param name="mmrError">MMRESULT which is return value of winmm function.</param>
 /// <param name="pszText"><see cref="StringBuilder"/> to write error description to.</param>
 /// <param name="cchText">Size of <paramref name="pszText"/> buffer.</param>
 /// <returns>Return value of winmm function which gets error description.</returns>
 protected override uint GetErrorText(uint mmrError, StringBuilder pszText, uint cchText)
 {
     return(MidiInWinApi.midiInGetErrorText(mmrError, pszText, cchText));
 }
コード例 #16
0
 /// <summary>
 /// Retrieves the number of input MIDI devices presented in the system.
 /// </summary>
 /// <returns>Number of input MIDI devices presented in the system.</returns>
 public static int GetDevicesCount()
 {
     return((int)MidiInWinApi.midiInGetNumDevs());
 }
コード例 #17
0
 internal override MMRESULT GetErrorText(MMRESULT mmrError, StringBuilder pszText, uint cchText)
 {
     return(MidiInWinApi.midiInGetErrorText(mmrError, pszText, cchText));
 }
コード例 #18
0
ファイル: InputDevice.cs プロジェクト: jrdndj/drywetmidi
 private uint StopEventsListeningSilently()
 {
     IsListeningForEvents = false;
     return(MidiInWinApi.midiInStop(_handle));
 }