📄 timelines.cpp
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA/* * @$Id: timelines.cpp,v 1.15 2007/02/12 14:15:06 jackjansen Exp $ */#include "ambulant/mms/timelines.h"#ifndef AM_DBG#define AM_DBG if(0)#endifnamespace ambulant {namespace mms {class dead_playable_class : public common::playable { public: dead_playable_class() : common::playable() {} void stop() {} void start(double t) {}; void pause(common::pause_display d=common::display_show) {}; void resume() {}; void seek(double t) {}; void wantclicks(bool want) {}; void preroll(double t1, double t2, double t3) {}; common::duration get_dur() { return common::duration(false, 0.0); } virtual int get_cookie() const { static int zero=0; return zero; } long add_ref() {return 1;}; long release() {return 1;}; long get_ref_count() const { return 1;}};dead_playable_class dead_playable;namespace detail {/* ---------------- */// The active_int_action subclass stores an internal timeline action.// Firing such an action has no side effects, it only triggers a timeline// dependency, possibly after a timeout.class active_int_action : public active_action { public: active_int_action(int dependency) : m_dependency(dependency), m_timeout(0) {}; active_int_action(int dependency, const timeline_delay& delay) : m_dependency(dependency), m_timeout(delay.timeout()) {}; void fire(active_timeline * const parent) const; void delayed_fire(active_timeline * const parent) const;#ifndef AMBULANT_NO_IOSTREAMS void to_stream(std::ostream& os) const;#endif private: const int m_dependency; const int m_timeout;};voidactive_int_action::delayed_fire(active_timeline * const parent) const{ lib::logger::get_logger()->error("Internal error: timelines.active_int_action::delayed_fire called!");#ifndef AMBULANT_NO_ABORT abort();#endif}voidactive_int_action::fire(active_timeline * const parent) const{#ifndef AMBULANT_NO_IOSTREAMS AM_DBG std::cout << "fire_int " << m_dependency << " timeout=" << m_timeout << std::endl;#endif typedef lib::scalar_arg_callback<active_timeline, detail::dependency_callback_arg> mycallback; lib::event *e = new mycallback(parent, &active_timeline::dependency_callback, m_dependency); parent->m_event_processor->add_event(e, m_timeout, lib::ep_high);}#ifndef AMBULANT_NO_IOSTREAMSvoidactive_int_action::to_stream(std::ostream& os) const{ os << "active_int_action(" << m_dependency << ", delay=" << m_timeout << ")";}#endif/* ---------------- */// The active_ext_action class stores an external timeline action,// an action that only causes a side-effect and has no direct// influence on the timeline scheduler.class active_ext_action : public detail::active_action { public: active_ext_action(int action_index, timeline_event_class cls, int node_index) : m_action_index(action_index), m_cls(cls), m_node_index(node_index) {}; void fire(active_timeline * const parent) const;#ifndef AMBULANT_NO_IOSTREAMS void to_stream(std::ostream& os) const;#endif protected: const int m_action_index; const timeline_event_class m_cls; const int m_node_index; };voidactive_ext_action::fire(active_timeline * const parent) const{#ifndef AMBULANT_NO_IOSTREAMS AM_DBG std::cout << "fire_ext " << m_action_index << std::endl;#endif typedef lib::scalar_arg_callback<active_timeline, detail::dependency_callback_arg> mycallback; lib::event *e = new mycallback(parent, &active_timeline::ext_dependency_callback, m_action_index); parent->m_event_processor->add_event(e, 0, lib::ep_low);}#ifndef AMBULANT_NO_IOSTREAMSvoidactive_ext_action::to_stream(std::ostream& os) const{ os << "active_ext_action(" << m_cls << ", node_index=" << m_node_index << ")";}#endif// Three classes that subclass active_ext_action to provide the// correct side-effects on fire()class active_preroll_action : public detail::active_ext_action { public: active_preroll_action(int action_index, timeline_event_class cls, int node_index) : active_ext_action(action_index, cls, node_index) {}; void delayed_fire(active_timeline * const parent) const {#ifndef AMBULANT_NO_IOSTREAMS AM_DBG std::cout << "delayed_fire_ext_preroll " << m_cls << ", node index=" << m_node_index << std::endl;#endif parent->ext_preroll(m_node_index); };}; class active_startplay_action : public detail::active_ext_action { public: active_startplay_action(int action_index, timeline_event_class cls, int node_index) : active_ext_action(action_index, cls, node_index) {}; void delayed_fire(active_timeline * const parent) const {#ifndef AMBULANT_NO_IOSTREAMS AM_DBG std::cout << "delayed_fire_ext_startplay " << m_cls << ", node index=" << m_node_index << std::endl;#endif parent->ext_play(m_node_index); };}; class active_stopplay_action : public detail::active_ext_action { public: active_stopplay_action(int action_index, timeline_event_class cls, int node_index) : active_ext_action(action_index, cls, node_index) {}; void delayed_fire(active_timeline * const parent) const {#ifndef AMBULANT_NO_IOSTREAMS AM_DBG std::cout << "delayed_fire_ext_stopplay " << m_cls << ", node index=" << m_node_index << std::endl;#endif parent->ext_stop(m_node_index); };}; } // namespace detail/* ---------------- */voiddetail::timeline_rhs_event::build_action(detail::active_action_vector& actions, detail::dependency_index_generator& indexer, int node_index){ // First handle the special cases for external events int asize = int(actions.size()); if ( m_what == START_PREROLL_RENDERER ) { detail::active_ext_action *act = new active_preroll_action(asize, m_what, node_index); actions.push_back(act); } else if ( m_what == START_PLAY_RENDERER ) { detail::active_ext_action *act = new active_startplay_action(asize, m_what, node_index); actions.push_back(act); } else if ( m_what == STOP_PLAY_RENDERER ) { detail::active_ext_action *act = new active_stopplay_action(asize, m_what, node_index); actions.push_back(act); } else if ( m_what == DELAY) { int index = indexer.get_index(*this); detail::active_int_action *act = new active_int_action(index, *m_delay); actions.push_back(act); } else { int index = indexer.get_index(*this); detail::active_int_action *act = new active_int_action(index); actions.push_back(act); } }/* ---------------- */intdetail::dependency_index_generator::set_index(detail::timeline_event_vector &evv){ detail::timeline_event_vector::iterator i; for(i=evv.begin(); i<evv.end(); i++) { if (m_index.find(*i) != m_index.end()) {#ifndef AMBULANT_NO_IOSTREAMS std::cout << "dependency_index_generator: duplicate: " << *i << std::endl; // XXXX#endif#ifndef AMBULANT_NO_ABORT abort();#endif } m_index[*i] = m_cur_end_pos;#ifndef AMBULANT_NO_IOSTREAMS AM_DBG std::cout << "Inserted dependency " << *i << " at " << m_cur_end_pos << std::endl;#endif } return m_cur_end_pos++;}intdetail::dependency_index_generator::get_index(detail::timeline_event &ev){ std::map<timeline_event, int>::iterator i; i = m_index.find(ev); if (i == m_index.end()) { return -1; } return m_index[ev];}/* ---------------- */void timeline_node_transition::add_lhs(timeline_event_class what){ m_lhs.push_back(detail::timeline_event(what, (lib::node *)NULL));}void timeline_node_transition::add_lhs(timeline_event_class what, const lib::node *direct_object){ m_lhs.push_back(detail::timeline_event(what, direct_object));}void timeline_node_transition::add_lhs(timeline_event_class what, const timeline_delay *direct_object){ m_lhs.push_back(detail::timeline_event(what, direct_object));}void timeline_node_transition::add_rhs(timeline_event_class what, const lib::node *direct_object){ m_rhs.push_back(detail::timeline_rhs_event(what, direct_object));}void timeline_node_transition::add_rhs(timeline_event_class what, const timeline_delay *direct_object){ m_rhs.push_back(detail::timeline_rhs_event(what, direct_object));}voidtimeline_node_transition::build_index(detail::dependency_index_generator& indexer){ m_event_index = indexer.set_index(m_lhs);}void timeline_node_transition::build_actions(detail::active_action_vector& actions, detail::dependency_index_generator& indexer, int node_index){ detail::timeline_rhs_event_vector::iterator i; #ifndef AMBULANT_NO_IOSTREAMS AM_DBG std::cout << "build actions for " << this << std::endl;#endif m_action_begin = int(actions.size()); for(i=m_rhs.begin(); i<m_rhs.end(); i++) i->build_action(actions, indexer, node_index); m_action_end = int(actions.size());}void timeline_node_transition::build_dependencies(detail::active_dependency_vector& dependencies){#ifndef AMBULANT_NO_IOSTREAMS AM_DBG std::cout << "build dependencies for " << this << std::endl;#endif detail::active_dependency act = detail::active_dependency(int(m_lhs.size()), m_action_begin, m_action_end); dependencies.push_back(act);}#ifndef AMBULANT_NO_IOSTREAMSvoid timeline_node_transition::dump(std::ostream& os){ detail::timeline_event_vector::iterator i; detail::timeline_rhs_event_vector::iterator j; bool first = true; for (i=m_lhs.begin(); i<m_lhs.end(); i++) { if (!first) os << " && "; first = false; os << (*i); } os << ":" << std::endl; first = true; for (j=m_rhs.begin(); j<m_rhs.end(); j++) { if (!first) os << "," << std::endl; first = false; os << "\t\t" << (*j); } os << std::endl;}#endif /* ---------------- */timeline_node_transition *timeline_node::add_transition(){ timeline_node_transition *rv = new timeline_node_transition(); m_transitions.push_back(rv); return rv;}#ifndef AMBULANT_NO_IOSTREAMSvoid timeline_node::dump(std::ostream& os, int &num){ std::vector<timeline_node_transition*>::iterator i; for (i=m_transitions.begin(); i<m_transitions.end(); i++) { os << num++ << "\t"; (**i).dump(os); } os << std::endl;}#endif#ifndef AMBULANT_NO_IOSTREAMSvoid timeline_node::dump(std::ostream& os){ std::vector<timeline_node_transition*>::iterator i; for (i=m_transitions.begin(); i<m_transitions.end(); i++) { (**i).dump(os); } os << std::endl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -