Ejemplo n.º 1
0
        public void Dispose(bool disposeManagedObjects)
        {
            if (!this.bDisposed済み)
            {
                if (disposeManagedObjects)
                {
                    foreach (IInputDevice device in this.list入力デバイス)
                    {
                        CInputMIDI tmidi = device as CInputMIDI;
                        if (tmidi != null)
                        {
                            CWin32.midiInStop(tmidi.hMidiIn);
                            CWin32.midiInReset(tmidi.hMidiIn);
                            CWin32.midiInClose(tmidi.hMidiIn);
                            Trace.TraceInformation("MIDI In: [{0}] を停止しました。", new object[] { tmidi.ID });
                        }
                    }
                    foreach (IInputDevice device2 in this.list入力デバイス)
                    {
                        device2.Dispose();
                    }
                    lock (this.objMidiIn排他用)
                    {
                        this.list入力デバイス.Clear();
                    }

                    //if( this.timer != null )
                    //{
                    //    this.timer.Dispose();
                    //    this.timer = null;
                    //}
                }
                this.bDisposed済み = true;
            }
        }
Ejemplo n.º 2
0
            public static void t復元する()
            {
                int    cb  = Marshal.SizeOf(stored);
                IntPtr ptr = Marshal.AllocCoTaskMem(cb);

                Marshal.StructureToPtr(stored, ptr, false);
                CWin32.SystemParametersInfo(0x3b, (uint)cb, ptr, 0);
                Marshal.FreeCoTaskMem(ptr);
            }
Ejemplo n.º 3
0
            //-----------------
            static Cトグルキー機能()
            {
                int    cb  = Marshal.SizeOf(stored);
                IntPtr ptr = Marshal.AllocCoTaskMem(cb);

                Marshal.StructureToPtr(stored, ptr, false);
                CWin32.SystemParametersInfo(0x34, (uint)cb, ptr, 0);
                stored = (CWin32.TOGGLEKEYS)Marshal.PtrToStructure(ptr, typeof(CWin32.TOGGLEKEYS));
                Marshal.FreeCoTaskMem(ptr);
            }
Ejemplo n.º 4
0
            //-----------------
            static C固定キー機能()
            {
                stored.cbSize  = 0;
                stored.dwFlags = 0;
                int    cb  = Marshal.SizeOf(stored);
                IntPtr ptr = Marshal.AllocCoTaskMem(cb);

                Marshal.StructureToPtr(stored, ptr, false);
                CWin32.SystemParametersInfo(0x3a, (uint)cb, ptr, 0);
                stored = (CWin32.STICKYKEYS)Marshal.PtrToStructure(ptr, typeof(CWin32.STICKYKEYS));
                Marshal.FreeCoTaskMem(ptr);
            }
Ejemplo n.º 5
0
 public static void t無効化する()
 {
     if ((stored.dwFlags & 1L) == 0L)
     {
         CWin32.STICKYKEYS structure = new CWin32.STICKYKEYS();
         structure.dwFlags  = stored.dwFlags;
         structure.cbSize   = stored.cbSize;
         structure.dwFlags &= -5;
         structure.dwFlags &= -9;
         int    cb  = Marshal.SizeOf(structure);
         IntPtr ptr = Marshal.AllocCoTaskMem(cb);
         Marshal.StructureToPtr(structure, ptr, false);
         CWin32.SystemParametersInfo(0x3b, (uint)cb, ptr, 0);
         Marshal.FreeCoTaskMem(ptr);
     }
 }
Ejemplo n.º 6
0
        private unsafe void tライン描画XRGB32(int n)
        {
            // Snap は RGB32、Textureは X8R8G8B8

            UInt32 *ptrTexture = this.ptrTexture[n];

            for (int y = n; y < this.n高さpx; y += CDirectShow.n並列度)
            {
                byte *ptrPixel = ptrSnap + (((this.n高さpx - y) - 1) * this.nスキャンライン幅byte);

                // アルファ無視なので一括コピー。CopyMemory() は自前でループ展開するよりも速い。
                CWin32.CopyMemory((void *)ptrTexture, (void *)ptrPixel, (uint)(this.n幅px * 4));

                ptrTexture += this.n幅px * CDirectShow.n並列度;
            }
        }
Ejemplo n.º 7
0
        public void CInput管理初期化(IntPtr hWnd, bool bUseMidiIn)
        {
            this.directInput = new DirectInput();
            // this.timer = new CTimer( CTimer.E種別.MultiMedia );

            this.list入力デバイス = new List <IInputDevice>(10);
            this.list入力デバイス.Add(new CInputKeyboard(hWnd, directInput));
            this.list入力デバイス.Add(new CInputMouse(hWnd, directInput));
            foreach (DeviceInstance instance in this.directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                this.list入力デバイス.Add(new CInputJoystick(hWnd, instance, directInput));
            }

            if (bUseMidiIn)
            {
                this.proc = new CWin32.MidiInProc(this.MidiInCallback);
                uint nMidiDevices = CWin32.midiInGetNumDevs();
                Trace.TraceInformation("MIDI入力デバイス数: {0}", nMidiDevices);
                for (uint i = 0; i < nMidiDevices; i++)
                {
                    CInputMIDI item = new CInputMIDI(i);
                    this.list入力デバイス.Add(item);
                    CWin32.MIDIINCAPS lpMidiInCaps = new CWin32.MIDIINCAPS();
                    uint num3 = CWin32.midiInGetDevCaps(i, ref lpMidiInCaps, (uint)Marshal.SizeOf(lpMidiInCaps));
                    if (num3 != 0)
                    {
                        Trace.TraceError("MIDI In: Device{0}: midiInDevCaps(): {1:X2}: ", i, num3);
                    }
                    else if ((CWin32.midiInOpen(ref item.hMidiIn, i, this.proc, 0, 0x30000) == 0) && (item.hMidiIn != 0))
                    {
                        CWin32.midiInStart(item.hMidiIn);
                        Trace.TraceInformation("MIDI In: [{0}] \"{1}\" の入力受付を開始しました。", i, lpMidiInCaps.szPname);
                    }
                    else
                    {
                        Trace.TraceError("MIDI In: [{0}] \"{1}\" の入力受付の開始に失敗しました。", i, lpMidiInCaps.szPname);
                    }
                }
            }
            else
            {
                Trace.TraceInformation("DTXVモードのため、MIDI入力は使用しません。");
            }
        }
Ejemplo n.º 8
0
        // コンストラクタ
        public CInput管理()
        {
            // this.timer = new CTimer( CTimer.E種別.MultiMedia );

            this.list入力デバイス = new List <IInputDevice>(10);
            #region [ Enumerate keyboard/mouse: exception is masked if keyboard/mouse is not connected ]
            CInputKeyboard cinputkeyboard = null;
            CInputMouse    cinputmouse    = null;
            try
            {
                cinputkeyboard = new CInputKeyboard();
                cinputmouse    = new CInputMouse();
            }
            catch
            {
            }
            if (cinputkeyboard != null)
            {
                this.list入力デバイス.Add(cinputkeyboard);
            }
            if (cinputmouse != null)
            {
                this.list入力デバイス.Add(cinputmouse);
            }
            #endregion
            #region [ Enumerate joypad ]
            try
            {
                for (int joynum = 0; joynum < 8; joynum++)                //2020.06.28 Mr-Ojii joystickの検出数を返す関数が見つからないので適当に8個で
                {
                    if (OpenTK.Input.Joystick.GetState(joynum).IsConnected)
                    {
                        this.list入力デバイス.Add(new CInputJoystick(joynum));
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
            #endregion
            this.proc = new CWin32.MidiInProc(this.MidiInCallback);
            uint nMidiDevices = CWin32.midiInGetNumDevs();
            Trace.TraceInformation("MIDI入力デバイス数: {0}", nMidiDevices);
            for (uint i = 0; i < nMidiDevices; i++)
            {
                CInputMIDI        item         = new CInputMIDI(i);
                CWin32.MIDIINCAPS lpMidiInCaps = new CWin32.MIDIINCAPS();
                uint num3 = CWin32.midiInGetDevCaps(i, ref lpMidiInCaps, (uint)Marshal.SizeOf(lpMidiInCaps));
                if (num3 != 0)
                {
                    Trace.TraceError("MIDI In: Device{0}: midiInDevCaps(): {1:X2}: ", i, num3);
                }
                else
                {
                    uint ret = CWin32.midiInOpen(ref item.hMidiIn, i, this.proc, IntPtr.Zero, 0x30000);
                    Trace.TraceInformation("midiInOpen()==" + ret);
                    Trace.TraceInformation("item.hMidiIn==" + item.hMidiIn.ToString());
                    if ((ret == 0) && (item.hMidiIn != IntPtr.Zero))
                    {
                        CWin32.midiInStart(item.hMidiIn);
                        Trace.TraceInformation("MIDI In: [{0}] \"{1}\" の入力受付を開始しました。", i, lpMidiInCaps.szPname);
                        item.strDeviceName = lpMidiInCaps.szPname;
                        this.list入力デバイス.Add(item);
                        continue;
                    }
                }
                Trace.TraceError("MIDI In: [{0}] \"{1}\" の入力受付の開始に失敗しました。", i, lpMidiInCaps.szPname);
            }
        }
        // コンストラクタ
        public CInput管理(IntPtr hWnd)
        {
            this.directInput = new DirectInput();
            // this.timer = new CTimer( CTimer.E種別.MultiMedia );

            this.list入力デバイス = new List <IInputDevice>(10);
            #region [ Enumerate keyboard/mouse: exception is masked if keyboard/mouse is not connected ]
            CInputKeyboard cinputkeyboard = null;
            CInputMouse    cinputmouse    = null;
            try
            {
                cinputkeyboard = new CInputKeyboard(hWnd, directInput);
                cinputmouse    = new CInputMouse(hWnd, directInput);
            }
            catch
            {
            }
            if (cinputkeyboard != null)
            {
                this.list入力デバイス.Add(cinputkeyboard);
            }
            if (cinputmouse != null)
            {
                this.list入力デバイス.Add(cinputmouse);
            }
            #endregion
            #region [ Enumerate joypad ]
            foreach (DeviceInstance instance in this.directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly))
            {
                this.list入力デバイス.Add(new CInputJoystick(hWnd, instance, directInput));
            }
            #endregion
            this.proc = new CWin32.MidiInProc(this.MidiInCallback);
            uint nMidiDevices = CWin32.midiInGetNumDevs();
            Trace.TraceInformation("MIDI入力デバイス数: {0}", nMidiDevices);
            for (uint i = 0; i < nMidiDevices; i++)
            {
                CInputMIDI        item         = new CInputMIDI(i);
                CWin32.MIDIINCAPS lpMidiInCaps = new CWin32.MIDIINCAPS();
                uint num3 = CWin32.midiInGetDevCaps(i, ref lpMidiInCaps, (uint)Marshal.SizeOf(lpMidiInCaps));
                if (num3 != 0)
                {
                    Trace.TraceError("MIDI In: Device{0}: midiInDevCaps(): {1:X2}: ", i, num3);
                }
                else
                {
                    uint ret = CWin32.midiInOpen(ref item.hMidiIn, i, this.proc, IntPtr.Zero, 0x30000);
                    Trace.TraceInformation("midiInOpen()==" + ret);
                    Trace.TraceInformation("item.hMidiIn==" + item.hMidiIn.ToString());
                    if ((ret == 0) && (item.hMidiIn != IntPtr.Zero))
                    {
                        CWin32.midiInStart(item.hMidiIn);
                        Trace.TraceInformation("MIDI In: [{0}] \"{1}\" の入力受付を開始しました。", i, lpMidiInCaps.szPname);
                        item.strDeviceName = lpMidiInCaps.szPname;
                        this.list入力デバイス.Add(item);
                        continue;
                    }
                }
                Trace.TraceError("MIDI In: [{0}] \"{1}\" の入力受付の開始に失敗しました。", i, lpMidiInCaps.szPname);
            }
        }
 /// <summary>
 /// 本体/モニタの省電力モード移行抑制を解除する
 /// </summary>
 public static void tEnableMonitorSuspend()
 {
     CWin32.SetThreadExecutionState(CWin32.ExecutionState.Continuous);                           // スリープ抑止状態を解除
 }
 /// <summary>
 /// 本体/モニタの省電力モード移行を抑止する
 /// </summary>
 public static void tDisableMonitorSuspend()
 {
     CWin32.SetThreadExecutionState(CWin32.ExecutionState.SystemRequired | CWin32.ExecutionState.DisplayRequired);
 }
Ejemplo n.º 12
0
        public static void tオーディオレンダラをNullレンダラに変えてフォーマットを取得する(IGraphBuilder graphBuilder, out WaveFormat wfx, out byte[] wfx拡張データ)
        {
            int hr = 0;

            IBaseFilter audioRenderer              = null;
            IPin        rendererInputPin           = null;
            IPin        rendererConnectedOutputPin = null;
            IBaseFilter nullRenderer         = null;
            IPin        nullRendererInputPin = null;

            wfx      = null;
            wfx拡張データ = new byte[0];

            try
            {
                // audioRenderer を探す。

                audioRenderer = CDirectShow.tオーディオレンダラを探して返す(graphBuilder);
                if (audioRenderer == null)
                {
                    return;                             // なかった
                }
                #region [ 音量ゼロで一度再生する。(オーディオレンダラの入力ピンMediaTypeが、接続時とは異なる「正しいもの」に変わる可能性があるため。)]
                //-----------------
                {
                    // ここに来た時点で、グラフのビデオレンダラは無効化(NullRendererへの置換や除去など)しておくこと。
                    // さもないと、StopWhenReady() 時に一瞬だけ Activeウィンドウが表示されてしまう。

                    var mediaCtrl  = (IMediaControl)graphBuilder;
                    var basicAudio = (IBasicAudio)graphBuilder;

                    basicAudio.put_Volume(-10000);                              // 最小音量


                    // グラフを再生してすぐ止める。(Paused → Stopped へ遷移する)

                    mediaCtrl.StopWhenReady();


                    // グラフが Stopped に遷移完了するまで待つ。(StopWhenReady() はグラフが Stopped になるのを待たずに帰ってくる。)

                    FilterState fs = FilterState.Paused;
                    hr = CWin32.S_FALSE;
                    while (fs != FilterState.Stopped || hr != CWin32.S_OK)
                    {
                        hr = mediaCtrl.GetState(10, out fs);
                    }


                    // 終了処理。

                    basicAudio.put_Volume(0);                                           // 最大音量

                    basicAudio = null;
                    mediaCtrl  = null;
                }
                //-----------------
                #endregion

                // audioRenderer の入力ピンを探す。

                rendererInputPin = t最初の入力ピンを探して返す(audioRenderer);
                if (rendererInputPin == null)
                {
                    return;
                }


                // WAVEフォーマットを取得し、wfx 引数へ格納する。

                var type = new AMMediaType();
                hr = rendererInputPin.ConnectionMediaType(type);
                DsError.ThrowExceptionForHR(hr);
                try
                {
                    wfx = new WaveFormat();

                    #region [ type.formatPtr から wfx に、拡張領域を除くデータをコピーする。]
                    //-----------------
                    var wfxTemp = new WaveFormatEx();                           // SharpDX.Multimedia.WaveFormat は Marshal.PtrToStructure() で使えないので、それが使える DirectShowLib.WaveFormatEx を介して取得する。(面倒…)
                    Marshal.PtrToStructure(type.formatPtr, (object)wfxTemp);

                    wfx = WaveFormat.CreateCustomFormat((WaveFormatEncoding)wfxTemp.wFormatTag, wfxTemp.nSamplesPerSec, wfxTemp.nChannels, wfxTemp.nAvgBytesPerSec, wfxTemp.nBlockAlign, wfxTemp.wBitsPerSample);
                    //-----------------
                    #endregion
                    #region [ 拡張領域が存在するならそれを wfx拡張データ に格納する。 ]
                    //-----------------
                    int nWaveFormatEx本体サイズ = 16 + 2;                     // sizeof( WAVEFORMAT ) + sizof( WAVEFORMATEX.cbSize )
                    int nはみ出しサイズbyte       = type.formatSize - nWaveFormatEx本体サイズ;

                    if (nはみ出しサイズbyte > 0)
                    {
                        wfx拡張データ = new byte[nはみ出しサイズbyte];
                        var hGC = GCHandle.Alloc(wfx拡張データ, GCHandleType.Pinned);                                // 動くなよー
                        unsafe
                        {
                            byte *src = (byte *)type.formatPtr.ToPointer();
                            byte *dst = (byte *)hGC.AddrOfPinnedObject().ToPointer();
                            CWin32.CopyMemory(dst, src + nWaveFormatEx本体サイズ, (uint)nはみ出しサイズbyte);
                        }
                        hGC.Free();
                    }
                    //-----------------
                    #endregion
                }
                finally
                {
                    if (type != null)
                    {
                        DsUtils.FreeAMMediaType(type);
                    }
                }


                // audioRenderer につながる出力ピンを探す。

                hr = rendererInputPin.ConnectedTo(out rendererConnectedOutputPin);
                DsError.ThrowExceptionForHR(hr);


                // audioRenderer をグラフから切断する。

                rendererInputPin.Disconnect();
                rendererConnectedOutputPin.Disconnect();


                // audioRenderer をグラフから除去する。

                hr = graphBuilder.RemoveFilter(audioRenderer);
                DsError.ThrowExceptionForHR(hr);


                // nullRenderer を作成し、グラフに追加する。

                nullRenderer = (IBaseFilter) new NullRenderer();
                hr           = graphBuilder.AddFilter(nullRenderer, "Audio Null Renderer");
                DsError.ThrowExceptionForHR(hr);


                // nullRenderer の入力ピンを探す。

                hr = nullRenderer.FindPin("In", out nullRendererInputPin);
                DsError.ThrowExceptionForHR(hr);


                // nullRenderer をグラフに接続する。

                hr = rendererConnectedOutputPin.Connect(nullRendererInputPin, null);
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                CCommon.tReleaseComObject(ref nullRendererInputPin);
                CCommon.tReleaseComObject(ref nullRenderer);
                CCommon.tReleaseComObject(ref rendererConnectedOutputPin);
                CCommon.tReleaseComObject(ref rendererInputPin);
                CCommon.tReleaseComObject(ref audioRenderer);
            }
        }