|
libpsynth 0.2.1
|
00001 /*************************************************************************** 00002 * * 00003 * PSYCHOSYNTH * 00004 * =========== * 00005 * * 00006 * Copyright (C) Juan Pedro Bolivar Puente 2007, 2008 * 00007 * * 00008 * This program is free software: you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation, either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00020 * * 00021 ***************************************************************************/ 00022 00023 #ifndef PSYNTH_OUTPUT_DIRECTOR_JACK_H 00024 #define PSYNTH_OUTPUT_DIRECTOR_JACK_H 00025 00026 #include <psynth/app/defaults_jack.hpp> 00027 #include <psynth/app/output_director.hpp> 00028 #include <psynth/io/jack_output.hpp> 00029 00030 namespace psynth 00031 { 00032 00033 class output_director_jack : public output_director 00034 { 00035 boost::signals::connection m_on_server_change_slot; 00036 00037 ~output_director_jack() 00038 { 00039 if (m_output) 00040 stop(); 00041 } 00042 00043 void on_server_change (base::conf_node& conf) 00044 { 00045 auto old_state = m_output->state (); 00046 build_output (*conf.parent ()); 00047 if (old_state == io::async_state::running) 00048 m_output->start (); 00049 } 00050 00051 virtual graph::audio_async_output_ptr 00052 do_start (base::conf_node& conf) 00053 { 00054 m_on_server_change_slot = 00055 conf.child ("server").on_change.connect 00056 (boost::bind (&output_director_jack::on_server_change, this, _1)); 00057 00058 return build_output (conf); 00059 }; 00060 00061 virtual graph::audio_async_output_ptr 00062 build_output (base::conf_node& conf) 00063 { 00064 auto server = conf.child ("server").get<std::string> (); 00065 m_output = io::new_jack_output<graph::audio_const_range>(server, 44100); 00066 return m_output; 00067 } 00068 00069 virtual void do_stop (base::conf_node& conf) 00070 { 00071 m_on_server_change_slot.disconnect (); 00072 00073 if (m_output) 00074 m_output.reset (); 00075 } 00076 00077 public: 00078 void defaults (base::conf_node& conf) 00079 { 00080 conf.child ("server").def ( 00081 std::string (PSYNTH_DEFAULT_JACK_SERVER)); 00082 } 00083 }; 00084 00085 class output_director_jack_factory : public output_director_factory 00086 { 00087 public: 00088 virtual const char* get_name () { 00089 return PSYNTH_DEFAULT_JACK_NAME; 00090 } 00091 00092 virtual output_director* create_output_director () { 00093 return new output_director_jack; 00094 } 00095 }; 00096 00097 } /* namespace psynth */ 00098 00099 #endif /* PSYNTH_OUTPUT_DIRECTOR_JACK_H */
1.7.4