OSDN Git Service

f6e99e6698a749af3b934e7c972a9ac33e1e7de5
[winaudioj/async.git] / async / application.h
1 #pragma once
2 /*
3   ==============================================================================
4
5    This file is part of the async
6    Copyright 2005-10 by Satoshi Fujiwara.
7
8    async can be redistributed and/or modified under the terms of the
9    GNU General Public License, as published by the Free Software Foundation;
10    either version 2 of the License, or (at your option) any later version.
11
12    async is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with async; if not, visit www.gnu.org/licenses or write to the
19    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
20    Boston, MA 02111-1307 USA
21
22   ==============================================================================
23 */
24 #include "singleton.h"
25 #include "exception.h"
26 #include "ring_buffer.h"
27 #include "wasapi.h"
28 #include "async_reader.h"
29 #include "sf_memory.h"
30 #include "toplevel_window.h"
31
32 namespace sf {
33 class application : public singleton<application>
34 {
35 public:
36   struct exception
37     : public sf::win32_error_exception 
38   {
39     exception(uint32_t hr) : win32_error_exception(hr) {};
40     exception() : win32_error_exception() {} ;
41   };
42
43   application();
44   ~application();
45   
46   int execute(HINSTANCE hInstance,
47                      HINSTANCE hPrevInstance,
48                      LPTSTR    lpCmdLine,
49                      int       nCmdShow);
50   
51
52   std::wstring& app_id(){return app_id_;};
53   HINSTANCE instance_handle() {return instance_handle_;};
54   enum player_status 
55   {
56     player_ready,
57     player_stop,
58     player_play,
59     player_end,
60     player_pause,
61     player_prep_seek,
62     player_seek,
63     player_rew,
64     player_ff,
65     player_exit
66   };
67
68   void reader_thread_main();
69   void output_thread_main();
70
71   void change_status(uint32_t v,boost::memory_order o = boost::memory_order_seq_cst);
72   uint32_t get_status(boost::memory_order o = boost::memory_order_seq_cst);
73   
74   void setup(const std::wstring& file_path);
75   
76   void play();
77   void pause();
78   void stop();
79
80   uint64_t get_play_position() { return output_counter_;};
81   void set_play_position(uint64_t pos);
82   uint64_t get_data_size() { return reader_->total_data_bytes(); };
83   void repeat_mode(bool v) { repeat_mode_ = v ;reader_->repeat_mode(v);}
84 private:
85   HINSTANCE instance_handle_;
86   int return_code_;
87
88   
89   boost::thread reader_thread_;
90   handle_holder event_reader_;
91   std::wstring source_file_path_;
92   std::unique_ptr<async_reader> reader_;
93   sf::buffer_t read_buffer_;
94   uint32_t read_index_;
95   uint64_t read_position_;
96
97   handle_holder event_output_;
98   boost::thread output_thread_;
99   std::unique_ptr<sf::wasapi_shared_timer> wasapi_;
100   uint64_t output_counter_;
101   bool repeat_mode_;
102
103   boost::atomic<uint32_t> status_;
104   uint32_t status_backup_;
105   sf::ringbuffer_t ringbuffer_;
106   bool not_enqueue_;
107
108   sf::toplevel_window_ptr window_;
109   static std::wstring app_id_;
110
111 };
112 }
113