OSDN Git Service

リセット
[momiji/momiji_main.git] / Core / Momiji.Core.Wave.Out.h
1 /*
2 [momiji music component library]
3 ---------------------------------------------------------------------
4 Momiji.Core.Wave.Out.h
5         wave output component.
6 ---------------------------------------------------------------------
7 Copyright (C) 2011 tyiki badwell {miria@users.sourceforge.jp}.
8
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program.  If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
21 ---------------------------------------------------------------------
22 */
23 #pragma once
24
25 #using <mscorlib.dll>
26 #include "Momiji.Core.Interface.h"
27 #include "Momiji.Core.Winmm.h"
28 #include "Momiji.Core.Buffer.h"
29
30 using namespace System::Runtime;
31
32 namespace Momiji{
33 namespace Core {
34 namespace Wave {
35 namespace Out {
36
37         public ref class Device
38         {
39         private:
40                 initonly System::UInt32 _deviceID;
41
42                 initonly System::UInt16 _channels;
43                 initonly System::UInt32 _samplesPerSecond;
44                 initonly System::UInt16 _bitsPerSample;
45                 initonly Interop::Winmm::WaveFormatExtensiblePart::SPEAKER      _channelMask;
46                 initonly Interop::Guiddef::Guid _formatSubType;
47                 initonly System::UInt32 _samplesPerBuffer;
48
49                 Interop::Winmm::Function::WaveOut^      _handle;
50                 Core::Winmm::DriverCallBack^            _callBack;
51                 Core::Buffer::BufferPool<Interop::Winmm::WaveHeader^>^ _headerPool;
52
53         public:
54                 ref class UnpreparedEventArgs: System::EventArgs
55                 {
56                 public:
57                         System::IntPtr  bufferPtr;
58                 };
59
60         public:
61                 Device(
62                         System::UInt32 deviceID,
63                         System::UInt16 channels,
64                         System::UInt32 samplesPerSecond,
65                         System::UInt16 bitsPerSample,
66                         Interop::Winmm::WaveFormatExtensiblePart::SPEAKER       channelMask,
67                         Interop::Guiddef::Guid formatSubType,
68                         System::UInt32 samplesPerBuffer
69                 );
70                 virtual ~Device();
71         protected:
72                 !Device();
73
74         private:
75                 System::IntPtr Prepare(System::IntPtr data, System::UInt32 useSize);
76                 System::IntPtr Unprepare(System::IntPtr headerPtr);
77
78                 Interop::Winmm::WaveHeader^ AllocateHeader();
79
80         public:
81                 static System::UInt32 GetNumDevices();
82                 static Interop::Winmm::WaveOutCapabilities^ GetCapabilities(System::UInt32 uDeviceID);
83                 Interop::Winmm::WaveOutCapabilities^ GetCapabilities();
84
85         private:
86                 void Open();
87                 void Close();
88
89         public:
90                 //TODO: これのインタフェースは何かのBuffer情報の塊にしたい
91                 void Send(System::IntPtr data, System::UInt32 useSize);
92                 void Reset();
93
94         public:
95                 event System::EventHandler<System::EventArgs^>^ OnOpen;
96                 event System::EventHandler<System::EventArgs^>^ OnClose;
97                 event System::EventHandler<UnpreparedEventArgs^>^ OnDone;
98
99         private:
100                 void OnEventHandler(System::Object^ sender, Interop::Winmm::DriverCallBack::DriverEventArgs^ args);
101
102                 void DoOpen(System::IntPtr dwParam1, System::IntPtr dwParam2);
103                 void DoClose(System::IntPtr dwParam1, System::IntPtr dwParam2);
104                 void DoDone(System::IntPtr dwParam1, System::IntPtr dwParam2);
105         };
106         
107         public ref class WaveOutException
108                 : public System::Exception
109         {
110         private:
111                 initonly Interop::Winmm::MMRESULT _mmResult;
112                 System::String^ Initialize();
113
114         public:
115                 WaveOutException(Interop::Winmm::MMRESULT v): _mmResult(v), System::Exception(Initialize()){};
116                 WaveOutException(System::String^ v): System::Exception(v){};
117                 virtual ~WaveOutException(void){};
118
119                 property Interop::Winmm::MMRESULT mmResult
120                 {
121                         Interop::Winmm::MMRESULT get(void) {return this->_mmResult;};
122                 }
123         };
124
125 }
126 }
127 }
128 }