From 3e7295940d65e6b71a7351604c490d17bc082a24 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 19:46:37 +0000 Subject: [PATCH] lilypond-0.0.71pre --- lily/global-acceptor.cc | 69 +++++++++++++++++++++++++++++++++ lily/include/global-acceptor.hh | 38 ++++++++++++++++++ lily/include/score-reg.hh | 25 ++++++------ lily/main.cc | 18 ++++++--- lily/register-group.cc | 32 +++++++++------ lily/score-reg.cc | 51 +++++++++++++++--------- lily/score.cc | 58 +++++++++------------------ 7 files changed, 203 insertions(+), 88 deletions(-) create mode 100644 lily/global-acceptor.cc create mode 100644 lily/include/global-acceptor.hh diff --git a/lily/global-acceptor.cc b/lily/global-acceptor.cc new file mode 100644 index 0000000000..057881adc7 --- /dev/null +++ b/lily/global-acceptor.cc @@ -0,0 +1,69 @@ +/* + global-acceptor.cc -- implement + + source file of the GNU LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + +#include "music.hh" +#include "global-acceptor.hh" +#include "score.hh" +#include "score-column.hh" + +Global_acceptor::Global_acceptor() +{ + score_l_ = 0; + last_mom_ = 0; +} + +Acceptor* +Global_acceptor::ancestor_l(int) +{ + return this; +} + +void +Global_acceptor::add_moment_to_process(Moment m) +{ + if (m > last_mom_) + return; + + for (int i=0; i < extra_mom_pq_.size(); i++) + if (extra_mom_pq_[i] == m) + return; + extra_mom_pq_.insert(m); +} + +int +Global_acceptor::depth_i()const +{ + return 0; +} + +void +Global_acceptor::set_score(Score *s) +{ + score_l_ = s; + last_mom_ = score_l_->music_p_->time_int().max(); +} + +void +Global_acceptor::modify_next(Moment &w) +{ + while (extra_mom_pq_.size() && + extra_mom_pq_.front() <= w) + + w =extra_mom_pq_.get(); +} + +int +Global_acceptor::moments_left_i()const +{ + return extra_mom_pq_.size(); +} + +void +Global_acceptor::prepare(Moment) +{ +} diff --git a/lily/include/global-acceptor.hh b/lily/include/global-acceptor.hh new file mode 100644 index 0000000000..6d18720298 --- /dev/null +++ b/lily/include/global-acceptor.hh @@ -0,0 +1,38 @@ +/* + global-acceptor.hh -- declare Global_acceptor + + source file of the GNU LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + + +#ifndef GLOBAL_ACCEPTOR_HH +#define GLOBAL_ACCEPTOR_HH + +#include "acceptor.hh" +#include "pqueue.hh" + +class Global_acceptor : public virtual Acceptor { + PQueue extra_mom_pq_; + Moment last_mom_; +public: + Score *score_l_; + Global_acceptor(); + int moments_left_i()const; + void modify_next(Moment&); + void add_moment_to_process(Moment); + + virtual void set_score(Score*); + virtual void prepare(Moment); + virtual void process() {} + virtual void finish() {} + +protected: + virtual int depth_i() const; + virtual Acceptor *ancestor_l(int); +}; + + + +#endif // GLOBAL_ACCEPTOR_HH diff --git a/lily/include/score-reg.hh b/lily/include/score-reg.hh index 569ddb7ac2..3c4c668ea6 100644 --- a/lily/include/score-reg.hh +++ b/lily/include/score-reg.hh @@ -11,11 +11,11 @@ #define SCORE_REG_HH #include "register-group.hh" -#include "pqueue.hh" +#include "global-acceptor.hh" -class Score_register : public Register_group_register { +class Score_register : public Register_group_register, public Global_acceptor { Line_of_score * scoreline_l_; - Score * score_l_; + Array nobreak_item_p_arr_; Link_array musical_item_p_arr_; @@ -27,18 +27,22 @@ class Score_register : public Register_group_register { void set_cols(Score_column*,Score_column*); void typeset_all(); - PQueue extra_mom_pq_; - Moment last_mom_; public: NAME_MEMBERS(); - void add_moment_to_process(Moment); Score_register(); - int depth_i() const; -protected: - void set_score(Score * score_l); - +protected: + /* Global_acceptor interface */ + virtual void set_score(Score * score_l); + virtual void prepare(Moment); + virtual void finish(); + virtual void process(); + virtual int depth_i() const { return Global_acceptor::depth_i();} + virtual Acceptor* ancestor_l(int l) { return Global_acceptor::ancestor_l(l);} + +protected: + /* Register_group_register interface */ virtual Staff_info get_staff_info()const; virtual bool do_try_request(Request*); virtual void do_creation_processing(); @@ -49,7 +53,6 @@ protected: virtual void typeset_element(Score_elem*elem_p); virtual Paper_def * paper() const; virtual void do_pre_move_processing(); - }; #endif // SCORE_REG_HH diff --git a/lily/main.cc b/lily/main.cc index 7fbaf0c24f..22f226d182 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -17,6 +17,7 @@ #include "path.hh" #include "config.hh" #include "source.hh" +#include "debug.hh" #include "my-lily-parser.hh" Sources* source_l_g = 0; @@ -98,14 +99,22 @@ notice() "USA.\n"; } -static File_path * path_l =0; + +static File_path path; void do_one_file(String init_str, String file_str) { + if ( "" == path.find( init_str ) ) + error ( "Can not find `" + init_str +"'"); + + if ( path.find( file_str ) == "" ) + error ( "Can not find `" + file_str + "'"); + + Sources sources; source_l_g = &sources; - source_l_g->set_path(path_l); + source_l_g->set_path(&path); { My_lily_parser parser(source_l_g); parser.set_version_check(version_ignore_b_); @@ -121,8 +130,6 @@ main (int argc, char **argv) debug_init(); // should be first - File_path path; - // must override (come before) "/usr/local/share/lilypond"! char const * env_l=getenv("LILYINCLUDE"); if (env_l) { @@ -131,8 +138,7 @@ main (int argc, char **argv) path.add( "" ); path.add( String( DIR_DATADIR ) + "/init/" ); - path_l = & path; - path_l->push(DIR_DATADIR ); + path.push(DIR_DATADIR ); Getopt_long oparser(argc, argv,theopts); cout << get_version_str() << endl; diff --git a/lily/register-group.cc b/lily/register-group.cc index 4d60d50fb5..5812b2fb04 100644 --- a/lily/register-group.cc +++ b/lily/register-group.cc @@ -42,7 +42,6 @@ Register_group_register::removable_b()const Register_group_register::Register_group_register() { ireg_l_ =0; - iterator_count_ =0; } void @@ -162,7 +161,7 @@ Register_group_register::terminate_register(Request_register*r_l) delete reg_p; } -IMPLEMENT_IS_TYPE_B1(Register_group_register,Request_register); +IMPLEMENT_IS_TYPE_B2(Register_group_register,Request_register, Acceptor); IMPLEMENT_STATIC_NAME(Register_group_register); ADD_THIS_REGISTER(Register_group_register); @@ -190,19 +189,28 @@ Register_group_register::find_register_l(String n, String id) return r; } -Register_group_register* -Register_group_register::find_get_reg_l(String n,String id) +Acceptor* +Register_group_register::find_get_acceptor_l(String n,String id) { - Register_group_register * ret=0; - if (ireg_l_-> find_ireg_l( n )) { + Acceptor * ret=0; + Input_register * ireg_l= ireg_l_-> recursive_find ( n ); + if (ireg_l ) { ret = find_register_l(n,id); if (!ret) { - ret = ireg_l_-> find_ireg_l(n) -> get_group_register_p(); - add ( ret ); - ret ->id_str_ = id; + Register_group_register * group = + ireg_l-> get_group_register_p(); + + add(group); + ret = group; + + if (group->ireg_l_->is_name_b( n ) ) + ret ->id_str_ = id; + else + return ret->find_get_acceptor_l(n,id); + } } else if (daddy_reg_l_) - ret =daddy_reg_l_->find_get_reg_l(n,id); + ret =daddy_reg_l_->find_get_acceptor_l(n,id); else { warning("Can't find or create `" + n + "' called `" + id + "'\n"); ret =0; @@ -216,7 +224,7 @@ Register_group_register::depth_i()const return daddy_reg_l_->depth_i() + 1; } -Register_group_register* +Acceptor* Register_group_register::ancestor_l(int l) { if (!l || !daddy_reg_l_) @@ -273,7 +281,7 @@ Register_group_register::get_staff_info()const return inf; } -Register_group_register* +Acceptor* Register_group_register::get_default_interpreter() { if ( interpreter_l() ) diff --git a/lily/score-reg.cc b/lily/score-reg.cc index b83c1e3872..35de3a344d 100644 --- a/lily/score-reg.cc +++ b/lily/score-reg.cc @@ -18,29 +18,44 @@ #include "musical-request.hh" #include "score-column.hh" -int -Score_register::depth_i()const -{ - return 0; -} void Score_register::set_score(Score *s) { - score_l_ = s; + Global_acceptor::set_score(s); scoreline_l_ = s->pscore_p_->super_elem_l_->line_of_score_l_; - last_mom_ = score_l_->music_p_->time_int().max(); } Score_register::Score_register() { - score_l_ = 0; scoreline_l_ =0; command_column_l_ =0; musical_column_l_ =0; } +void +Score_register::prepare(Moment w) +{ + Score_column* c1 = new Score_column(w); + Score_column* c2 = new Score_column(w); + + c1->musical_b_ = false; + c2->musical_b_ = true; + + score_l_->cols_.bottom().add(c1); + score_l_->cols_.bottom().add(c2); + set_cols(c1,c2); + + + post_move_processing(); +} +void +Score_register::finish() +{ + check_removal(); + do_removal_processing(); +} void Score_register::do_creation_processing() @@ -66,6 +81,14 @@ Score_register::do_removal_processing() typeset_all(); } +void +Score_register::process() +{ + process_requests(); + do_announces(); + pre_move_processing(); + check_removal(); +} void Score_register::announce_element(Score_elem_info info) @@ -120,6 +143,7 @@ Score_register::typeset_breakable_item(Item * nobreak_p) nobreak_item_p_arr_.push(nobreak_p); } } + void Score_register::typeset_all() { @@ -190,14 +214,3 @@ IMPLEMENT_IS_TYPE_B1(Score_register,Register_group_register); IMPLEMENT_STATIC_NAME(Score_register); ADD_THIS_REGISTER(Score_register); -void -Score_register::add_moment_to_process(Moment m) -{ - if (m > last_mom_) - return; - - for (int i=0; i < extra_mom_pq_.size(); i++) - if (extra_mom_pq_[i] == m) - return; - extra_mom_pq_.insert(m); -} diff --git a/lily/score.cc b/lily/score.cc index 3d7ad33de0..f2899451e7 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -34,55 +34,29 @@ Score::Score(Score const &s) } void -Score::setup_music() +Score::run_acceptor(Global_acceptor * acc_l) { - *mlog << "\nSetting up requests..." << flush; - - Score_register * score_reg = - (Score_register*)lookup_reg("Score_register")->get_group_register_p(); - - score_reg->set_score (this); + acc_l->set_score (this); Music_iterator * iter = Music_iterator::static_get_iterator_p(music_p_, - score_reg); + acc_l); iter->construct_children(); - while ( iter->ok() || score_reg->extra_mom_pq_.size() ) { + while ( iter->ok() || acc_l->moments_left_i() ) { Moment w = INFTY; if (iter->ok() ) { w = iter->next_moment(); iter->print(); } - if (score_reg->extra_mom_pq_.size() && - score_reg->extra_mom_pq_.front() <= w) - - w = score_reg->extra_mom_pq_.get(); - - mtor << "processing moment " << w << "\n"; - - Score_column* c1 = new Score_column(w); - Score_column* c2 = new Score_column(w); - - c1->musical_b_ = false; - c2->musical_b_ = true; - - cols_.bottom().add(c1); - cols_.bottom().add(c2); - score_reg->set_cols(c1,c2); - - score_reg->post_move_processing(); + acc_l->modify_next( w ); + acc_l->prepare(w); iter->next( w ); - - score_reg->process_requests(); - score_reg->do_announces(); - score_reg->pre_move_processing(); - score_reg->check_removal(); + acc_l->process(); } delete iter; - score_reg->check_removal(); - score_reg->do_removal_processing(); - delete score_reg; + acc_l->finish(); } + void Score::process() { @@ -94,14 +68,20 @@ Score::paper() { if (!paper_p_) return; - + + *mlog << "\nCreating elements ..." << flush; + pscore_p_ = new PScore(paper_p_); + + Score_register * score_reg = + (Score_register*)lookup_reg("Score_register")->get_group_register_p(); + run_acceptor( score_reg ); + delete score_reg; + if( errorlevel_i_){ // should we? hampers debugging. warning("Errors found, /*not processing score*/"); // return; } - pscore_p_ = new PScore(paper_p_); - setup_music(); do_cols(); clean_cols(); // can't move clean_cols() farther up. @@ -124,7 +104,6 @@ Score::paper() void Score::clean_cols() { -#if 1 for (iter_top(cols_,c); c.ok(); ) { if (!c->pcol_l_->used_b()) { delete c.remove_p(); @@ -133,7 +112,6 @@ Score::clean_cols() c++; } } -#endif } PCursor -- 2.39.5