libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/io/output.hpp
Go to the documentation of this file.
00001 
00011 /*
00012  *  Copyright (C) 2011 Juan Pedro BolĂ­var Puente
00013  *
00014  *  This file is part of Psychosynth.
00015  *   
00016  *  Psychosynth is free software: you can redistribute it and/or modify
00017  *  it under the terms of the GNU General Public License as published by
00018  *  the Free Software Foundation, either version 3 of the License, or
00019  *  (at your option) any later version.
00020  *
00021  *  Psychosynth is distributed in the hope that it will be useful,
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *  GNU General Public License for more details.
00025  *
00026  *  You should have received a copy of the GNU General Public License
00027  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00028  *
00029  */
00030 
00031 #ifndef PSYNTH_IO_OUTPUT_HPP_
00032 #define PSYNTH_IO_OUTPUT_HPP_
00033 
00034 #include <psynth/sound/forwards.hpp>
00035 
00036 #include <psynth/io/output_fwd.hpp>
00037 #include <psynth/io/async_base.hpp>
00038 #include <psynth/io/output.tpp>
00039 
00040 namespace psynth
00041 {
00042 namespace io
00043 {
00044 
00045 const std::size_t default_output_buffer_size = 1024;
00046 
00051 template <typename Range>
00052 class output
00053 {
00054 public:
00055     typedef Range range;
00056     typedef typename Range::const_type const_range;
00057     
00061     virtual std::size_t put (const const_range& data) = 0;
00062 };
00063 
00067 template <typename Range>
00068 class dummy_output : public output<Range>
00069 {
00070 public:
00071     typedef Range range;
00072     typedef typename Range::const_type const_range;
00073         
00074     virtual std::size_t put (const const_range& data)
00075     {
00076         detail::dummy_output_put_impl ();
00077         return data.size ();
00078     }
00079 };
00080 
00081 
00085 template <typename Range>
00086 class async_output : public output<Range>,
00087                      public virtual async_base
00088 {
00089 public:
00090     virtual std::size_t buffer_size () const = 0;
00091 };
00092 
00096 template <typename Range>
00097 class dummy_async_output : public detail::async_base_impl
00098 {
00099 public:
00100     typedef Range range;
00101     typedef typename Range::const_type const_range;
00102     
00103     dummy_async_output (std::size_t buffer_size)
00104         : _buffer_size (buffer_size)
00105     {}
00106     
00107     std::size_t buffer_size () const
00108     { return _buffer_size; }
00109     
00110     virtual std::size_t put (const range& data)
00111     {
00112         detail::dummy_output_put_impl ();
00113         return data.size ();
00114     }
00115 
00116     void start ()
00117     {
00118         this->check_idle ();
00119         this->set_state (async_state::running);
00120         detail::dummy_output_start_impl ();
00121     }
00122 
00123     void stop ()
00124     {
00125         this->check_running ();
00126         this->set_state (async_state::idle);
00127         detail::dummy_output_stop_impl ();
00128     }
00129     
00130 private:
00131     std::size_t _buffer_size;
00132 };
00133 
00138 template <typename RawOutput, typename Range>
00139 std::size_t put_on_raw (RawOutput& out, const Range& data);
00140 
00141 } /* namespace io */
00142 } /* namespace psynth */
00143 
00144 #endif /* PSYNTH_IO_OUTPUT_H */
00145