libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/io/jack_raw_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_JACK_RAW_OUTPUT_H_
00032 #define PSYNTH_IO_JACK_RAW_OUTPUT_H_
00033 
00034 #include <vector>
00035 #include <jack/jack.h>
00036 
00037 #include <psynth/io/async_base.hpp>
00038 
00039 namespace psynth
00040 {
00041 namespace io
00042 {
00043 
00044 PSYNTH_DECLARE_ERROR (error, jack_error);
00045 PSYNTH_DECLARE_ERROR (jack_error, jack_open_error);
00046 PSYNTH_DECLARE_ERROR (jack_error, jack_param_error);
00047 
00048 class jack_raw_output : public detail::async_base_impl,
00049                         private boost::noncopyable
00050 {
00051 public:
00052     typedef detail::async_base_impl::callback_type callback_type;
00053     
00054     jack_raw_output (const char* client,
00055                      const char* server,
00056                      int         rate,
00057                      int         channels,
00058                      callback_type cb = callback_type ());
00059 
00060     ~jack_raw_output ();
00061 
00062     void start ();
00063     void stop ();
00064     
00065     std::size_t put_i (const void*        data, std::size_t frames);
00066     std::size_t put_n (const void* const* data, std::size_t frames);
00067 
00068     std::size_t buffer_size () const
00069     { return _buffer_size; }
00070     
00071 private:
00072     void connect_ports ();
00073     
00074     void _on_process (jack_nframes_t frames)
00075     { process (frames); }
00076 
00077     void _on_sample_rate (jack_nframes_t newrate) { /* TODO */ }
00078 
00079     void _on_buffer_size (jack_nframes_t newsize)
00080     { _buffer_size = newsize; }
00081     
00082     void _on_shutdown () { /* TODO */ }
00083     
00084     static int _process_cb (jack_nframes_t nframes, void* jack_client);
00085     static int _sample_rate_cb (jack_nframes_t newrate, void* jack_client);
00086     static int _buffer_size_cb (jack_nframes_t newsize, void* jack_client);
00087     static void _shutdown_cb (void* jack_client);
00088     
00089     std::vector<jack_port_t*> _out_ports;
00090     jack_client_t*            _client;
00091     int                       _actual_rate;
00092     std::size_t               _buffer_size;
00093 };
00094 
00095 } /* namespace io */
00096 } /* namespace psynth */
00097 
00098 #endif /* PSYNTH_IO_JACK_RAW_OUTPUT_H_ */
00099