libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/io/file_common.hpp
Go to the documentation of this file.
00001 
00014 /*
00015  *  Copyright (C) 2011 Juan Pedro BolĂ­var Puente
00016  *
00017  *  This file is part of Psyhcosynth.
00018  *   
00019  *  Psyhcosynth is free software: you can redistribute it and/or modify
00020  *  it under the terms of the GNU General Public License as published by
00021  *  the Free Software Foundation, either version 3 of the License, or
00022  *  (at your option) any later version.
00023  *
00024  *  Psyhcosynth is distributed in the hope that it will be useful,
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027  *  GNU General Public License for more details.
00028  *
00029  *  You should have received a copy of the GNU General Public License
00030  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00031  *
00032  */
00033 
00034 #ifndef PSYNTH_IO_FILE_COMMON_H_
00035 #define PSYNTH_IO_FILE_COMMON_H_
00036 
00037 #include <psynth/io/output.hpp>
00038 #include <psynth/io/input.hpp>
00039 
00040 namespace psynth
00041 {
00042 namespace io
00043 {
00044 
00045 PSYNTH_DECLARE_ERROR (error, file_error);
00046 PSYNTH_DECLARE_ERROR (file_error, file_open_error);
00047 PSYNTH_DECLARE_ERROR (file_error, file_param_error);
00048 PSYNTH_DECLARE_ERROR (file_error, file_seek_error);
00049 
00050 template <class Range>
00051 class file_support;
00052 
00053 template <class Range>
00054 struct file_is_supported
00055 {
00056     typedef typename file_support<Range>::is_supported type;
00057 };
00058 
00059 
00066 enum class file_fmt
00067 {
00068     wav = 0,
00069     aiff,
00070     au,
00071     ogg,
00072     flac,
00073     num_formats
00074 };
00075 
00079 enum class seek_dir
00080 {
00081     beg = 0,
00082     cur,
00083     end
00084 };
00085 
00086 template <typename Range>
00087 class file_output_base : public output<Range>
00088 {
00089 public:
00090     virtual std::size_t seek (std::ptrdiff_t offset,
00091                               seek_dir dir = seek_dir::beg) = 0;
00092 };
00093 
00094 
00095 template <typename Range>
00096 class file_input_base : public input<Range>
00097 {
00098 public:
00099     virtual std::size_t frame_rate () const = 0;
00100     
00101     virtual std::size_t seek (std::ptrdiff_t offset,
00102                               seek_dir dir = seek_dir::beg) = 0;
00103 
00104     virtual std::size_t length () const = 0;
00105 };
00106 
00107 template <typename Range>
00108 class dummy_file_input : public file_input_base<Range>
00109 {
00110 public:
00111     typedef Range range;
00112     
00113     std::size_t frame_rate () const
00114     { return 44100; }
00115 
00116     std::size_t length () const
00117     { return 0; }
00118     
00119     std::size_t seek (std::ptrdiff_t offset,
00120                       seek_dir dir = seek_dir::beg)
00121     { return 0; }
00122     
00123     virtual std::size_t take (const range& data)
00124     {
00125         detail::dummy_input_take_impl ();
00126         typename range::value_type zero (
00127             sound::sample_traits<
00128                 typename sound::sample_type<range>::type
00129                 >::zero_value ());
00130         fill_frames (data, zero);
00131         return data.size ();
00132     }
00133 };
00134 
00135 } /* namespace io */
00136 } /* namespace psynth */
00137 
00138 #include <psynth/io/file_common.tpp>
00139 
00140 #endif /* PSYNTH_IO_FILE_COMMON_H_ */
00141