OSDN Git Service

a95c449dbc4de8ecca0dbec7ba3a808332459305
[winaudioj/wasapi2.git] / wasapi2 / application.h
1 #pragma once\r
2 /*\r
3   ==============================================================================\r
4 \r
5    This file is part of the async\r
6    Copyright 2005-10 by Satoshi Fujiwara.\r
7 \r
8    async can be redistributed and/or modified under the terms of the\r
9    GNU General Public License, as published by the Free Software Foundation;\r
10    either version 2 of the License, or (at your option) any later version.\r
11 \r
12    async is distributed in the hope that it will be useful,\r
13    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15    GNU General Public License for more details.\r
16 \r
17    You should have received a copy of the GNU General Public License\r
18    along with async; if not, visit www.gnu.org/licenses or write to the\r
19    Free Software Foundation, Inc., 59 Temple Place, Suite 330, \r
20    Boston, MA 02111-1307 USA\r
21 \r
22   ==============================================================================\r
23 */\r
24 #include "singleton.h"\r
25 #include "exception.h"\r
26 #include "ring_buffer.h"\r
27 #include "wasapi.h"\r
28 #include "async_reader.h"\r
29 #include "sf_memory.h"\r
30 #include "toplevel_window.h"\r
31 #include "reader_agent.h"\r
32 #include "output_agent.h"\r
33 #include "input_agent.h"\r
34 #include "mixer_agent.h"\r
35 #include "sequencer.h"\r
36 \r
37 namespace sf {\r
38 class application : public singleton<application>\r
39 {\r
40   static const size_t Q_SIZE = 8;\r
41 public:\r
42   struct exception\r
43     : public sf::win32_error_exception \r
44   {\r
45     exception(uint32_t hr) : win32_error_exception(hr) {};\r
46     exception() : win32_error_exception() {} ;\r
47   };\r
48 \r
49  \r
50   application();\r
51   ~application();\r
52   \r
53   int execute(HINSTANCE hInstance,\r
54                      HINSTANCE hPrevInstance,\r
55                      LPTSTR    lpCmdLine,\r
56                      int       nCmdShow);\r
57   \r
58 \r
59   std::wstring& app_id(){return app_id_;};\r
60   HINSTANCE instance_handle() {return instance_handle_;};\r
61   \r
62   // アプリケーションのカレントディレクトリを返す\r
63   const std::wstring& base_directory() const { return base_directory_; }\r
64 \r
65  \r
66 // ----------------------------------------\r
67 private:\r
68 // ----------------------------------------\r
69 \r
70   //void wasapi_setup();\r
71   HINSTANCE instance_handle_;\r
72   int return_code_;\r
73   \r
74 //---------------------------------------\r
75 // ファイル読取り関係\r
76 //---------------------------------------\r
77 public:\r
78 \r
79   void reader_setup(const std::wstring& file_path);\r
80   void reader_read_file();\r
81   void reader_pause();\r
82   void reader_stop();\r
83   void reader_end();\r
84   uint64_t reader_position() {return reader_agent_.position();}\r
85   void reader_position(uint64_t pos){reader_agent_.position(pos);}\r
86   uint64_t reader_data_size(){return reader_agent_.size();}\r
87   void reader_repeat_mode(bool v){ reader_agent_.repeat_mode(v);}\r
88   bool reader_repeat_mode(){ return reader_agent_.repeat_mode();}\r
89   int reader_status(std::memory_order o = std::memory_order_seq_cst) {return reader_agent_.status(o);}\r
90   ringbuffer_t& reader_ringbuffer() {return reader_agent_.ringbuffer();}\r
91 private:\r
92   reader_agent_t reader_agent_;\r
93 \r
94 // ----------------------------\r
95 // WASAPI出力関係\r
96 // ----------------------------\r
97 // 出力デバイスの設定・変更\r
98 public:\r
99   void apply_output_device_config(int device_index,wasapi_device_manager::device_info::params_t& params);\r
100   audio_base& output_device() {return output_agent_.device();}\r
101   ringbuffer_t& output_ringbuffer() {return output_agent_.ringbuffer();}\r
102   output_agent_t& output_thread(){return output_agent_;}\r
103 private:\r
104   output_agent_t output_agent_;\r
105 // -----------------------------  \r
106 // WASAPI入力関係\r
107 // -----------------------------  \r
108 public:\r
109   void apply_input_device_config(int device_index,wasapi_device_manager::device_info::params_t& params)\r
110   {\r
111       input_agent_.apply_config(device_index,params);\r
112   };\r
113   audio_base& input_device() {return input_agent_.device();}\r
114   ringbuffer_t& input_ringbuffer() {return input_agent_.ringbuffer();}\r
115   input_agent_t& input_thread(){return input_agent_;}\r
116 private:\r
117   input_agent_t input_agent_;\r
118 \r
119 // -----------------------------  \r
120 // ミキサー関係\r
121 // -----------------------------  \r
122 public:\r
123   ringbuffer_t& mixer_ringbuffer(){return mixer_agent_.ringbuffer();}\r
124   mixer_agent_t& mixer_thread(){return mixer_agent_;}\r
125 private:\r
126   mixer_agent_t mixer_agent_;\r
127 \r
128 // -----------------------------  \r
129 // その他\r
130 // -----------------------------  \r
131 \r
132   std::wstring base_directory_;\r
133   sf::toplevel_window_ptr window_;\r
134 //--------------------------------\r
135 // シーケンサ\r
136 //--------------------------------\r
137 public:\r
138   sf::sequencer & sequencer() {return seq_;}\r
139 private:\r
140   sf::sequencer seq_;\r
141   static std::wstring app_id_;\r
142   static const int WAIT_TIMEOUT_DEFAULT = 100; \r
143 \r
144 };\r
145 }\r
146 \r