From 210397d5e1d8a0b560bac8e683c8be957035b5b4 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 8 May 2005 23:17:49 +0000 Subject: [PATCH] * input/regression/alignment-order.ly: new file. * lily/vertical-align-engraver.cc (acknowledge_grob): read alignAboveContext and alignBelowContext --- ChangeLog | 7 +++ Documentation/topdocs/NEWS.tely | 9 ++++ THANKS | 1 + input/regression/alignment-order.ly | 27 ++++++++++ lily/accidental-engraver.cc | 4 +- lily/align-interface.cc | 6 +-- lily/context.cc | 10 ++-- lily/engraver-group-engraver.cc | 2 +- lily/font-size-engraver.cc | 2 +- lily/function-documentation.cc | 2 +- lily/grob-info.cc | 15 +++++- lily/include/grob-info.hh | 8 +-- lily/output-property-engraver.cc | 7 +-- lily/score-engraver.cc | 10 +--- lily/vertical-align-engraver.cc | 80 +++++++++++++++++++++++++---- scm/define-context-properties.scm | 2 + scm/lily.scm | 2 - 17 files changed, 151 insertions(+), 43 deletions(-) create mode 100644 input/regression/alignment-order.ly diff --git a/ChangeLog b/ChangeLog index 62d5a164af..141a16a40f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-05-09 Han-Wen Nienhuys + + * input/regression/alignment-order.ly: new file. + + * lily/vertical-align-engraver.cc (acknowledge_grob): read + alignAboveContext and alignBelowContext + 2005-05-08 Han-Wen Nienhuys * lily/pfb.cc (LY_DEFINE): add cast. diff --git a/Documentation/topdocs/NEWS.tely b/Documentation/topdocs/NEWS.tely index 27e3a70d9d..50d507eb7a 100644 --- a/Documentation/topdocs/NEWS.tely +++ b/Documentation/topdocs/NEWS.tely @@ -33,6 +33,15 @@ See user manual, \NAME\ @itemize @bullet +@item +Newly created staves and lyric lines, can be put in any vertical order, +by setting @code{alignBelowContext} or @code{alignAboveContext} +properties in the newly created context. An example of the use of this +is in @inputfileref{input/regression,alignment-order.ly}. + +This feature has been sponsored by Bertalan Fodor. + + @item Staves may be stopped and started halfway a line, e.g. diff --git a/THANKS b/THANKS index 597afcc9d4..2cf6a346cc 100644 --- a/THANKS +++ b/THANKS @@ -36,6 +36,7 @@ Yuval Harel SPONSORS +Bertalan Fodor Jonathan Walther Steve Doonan Marcus Macauley diff --git a/input/regression/alignment-order.ly b/input/regression/alignment-order.ly new file mode 100644 index 0000000000..3291b018c5 --- /dev/null +++ b/input/regression/alignment-order.ly @@ -0,0 +1,27 @@ +\header { + texidoc = "Newly created contexts can be inserted +anywhere in the vertical alignment. " +} + +\version "2.5.23" + +\paper { + raggedright = ##t +} + +\relative << + \context Staff = "1" { c4 c s2 } + \context Staff = "2" { c c s2 } + \context Staff = "3" { c c s2 } + { \skip 2 + << + \lyrics { + \set alignBelowContext = #"1" + below8 first staff + } + \lyrics { + \set alignAboveContext = #"3" + above8 last staff + } + >> } +>> diff --git a/lily/accidental-engraver.cc b/lily/accidental-engraver.cc index 1dc9395057..8a47a9cae1 100644 --- a/lily/accidental-engraver.cc +++ b/lily/accidental-engraver.cc @@ -492,8 +492,8 @@ Accidental_engraver::acknowledge_grob (Grob_info info) Accidental_entry entry; entry.head_ = info.grob_; - entry.origin_trans_ = dynamic_cast (info.origin_trans_); - entry.origin_ = info.origin_trans_->context (); + entry.origin_trans_ = dynamic_cast (info.origin_translator ()); + entry.origin_ = entry.origin_trans_->context (); entry.melodic_ = note; accidentals_.push (entry); diff --git a/lily/align-interface.cc b/lily/align-interface.cc index 3e4b9c5ca8..5ae726676f 100644 --- a/lily/align-interface.cc +++ b/lily/align-interface.cc @@ -225,10 +225,10 @@ Align_interface::axis (Grob *me) } void -Align_interface::add_element (Grob *me, Grob *s, SCM cb) +Align_interface::add_element (Grob *me, Grob *element, SCM call_back) { - s->add_offset_callback (cb, Align_interface::axis (me)); - Axis_group_interface::add_element (me, s); + element->add_offset_callback (call_back, Align_interface::axis (me)); + Axis_group_interface::add_element (me, element); } void diff --git a/lily/context.cc b/lily/context.cc index dc38796158..b6ded9ec05 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -221,14 +221,14 @@ Context::create_context (Context_def *cdef, { String type = ly_symbol2string (cdef->get_context_name ()); Object_key const *key = get_context_key (type, id); - Context *new_group + Context *new_context = cdef->instantiate (ops, key); - new_group->id_string_ = id; - add_context (new_group); - apply_property_operations (new_group, ops); + new_context->id_string_ = id; + add_context (new_context); + apply_property_operations (new_context, ops); - return new_group; + return new_context; } Object_key const * diff --git a/lily/engraver-group-engraver.cc b/lily/engraver-group-engraver.cc index 37811f925b..5270d7121c 100644 --- a/lily/engraver-group-engraver.cc +++ b/lily/engraver-group-engraver.cc @@ -67,7 +67,7 @@ Engraver_group_engraver::acknowledge_grobs () { Translator *t = unsmob_translator (scm_car (p)); Engraver *eng = dynamic_cast (t); - if (eng && eng != info.origin_trans_) + if (eng && eng != info.origin_translator ()) eng->acknowledge_grob (info); } } diff --git a/lily/font-size-engraver.cc b/lily/font-size-engraver.cc index a5f7848c7f..bc372a6a43 100644 --- a/lily/font-size-engraver.cc +++ b/lily/font-size-engraver.cc @@ -30,7 +30,7 @@ Font_size_engraver::acknowledge_grob (Grob_info gi) /* We only want to process a grob once. */ - if (gi.origin_trans_->context () != context ()) + if (gi.context () != context ()) return; if (scm_is_number (sz) && scm_to_double (sz)) diff --git a/lily/function-documentation.cc b/lily/function-documentation.cc index 8daf4baf0c..bfa68ec546 100644 --- a/lily/function-documentation.cc +++ b/lily/function-documentation.cc @@ -22,7 +22,7 @@ void ly_add_function_documentation (SCM func, return; if (!scm_is_vector (doc_hash_table)) - doc_hash_table = scm_make_vector (scm_int2num (59), SCM_EOL); + doc_hash_table = scm_c_make_hash_table (59); String s = String (" - ") + "LilyPond procedure: " + fname + " " + varlist + "\n" + doc; diff --git a/lily/grob-info.cc b/lily/grob-info.cc index 38d074dde6..6b69bfeab6 100644 --- a/lily/grob-info.cc +++ b/lily/grob-info.cc @@ -7,12 +7,18 @@ */ #include "grob-info.hh" - #include "grob.hh" #include "music.hh" #include "translator-group.hh" #include "context.hh" + +Grob_info::Grob_info (Translator *t, Grob *g) +{ + origin_trans_ = t; + grob_ = g; +} + Grob_info::Grob_info () { grob_ = 0; @@ -41,3 +47,10 @@ Grob_info::origin_contexts (Translator *end) const return r; } + +Context* +Grob_info::context () const +{ + return origin_trans_->context (); +} + diff --git a/lily/include/grob-info.hh b/lily/include/grob-info.hh index 4ebc0b2999..06b48ab89b 100644 --- a/lily/include/grob-info.hh +++ b/lily/include/grob-info.hh @@ -16,16 +16,18 @@ /* Data container for broadcasts. */ -struct Grob_info +class Grob_info { Translator *origin_trans_; friend class Engraver; - Grob *grob_; - public: + Grob *grob_; + Context *context () const; + Translator *origin_translator () const { return origin_trans_; } Music *music_cause (); Link_array origin_contexts (Translator *) const; + Grob_info (Translator *, Grob *); Grob_info (); }; diff --git a/lily/output-property-engraver.cc b/lily/output-property-engraver.cc index b8cc5d2879..dc7207a3ed 100644 --- a/lily/output-property-engraver.cc +++ b/lily/output-property-engraver.cc @@ -59,12 +59,7 @@ Output_property_engraver::acknowledge_grob (Grob_info inf) } else { - Context * d = - dynamic_cast (inf.origin_trans_); - - if (!d) - d = dynamic_cast (inf.origin_trans_->context ()); - + Context * d = inf.context (); SCM proc = o->get_property ("procedure"); scm_call_3 (proc, inf.grob_->self_scm (), diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 4425741254..0f01110780 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -53,16 +53,10 @@ Score_engraver::make_columns () Object_key const *key2 = context ()->get_grob_key ("PaperColumn"); set_columns (new Paper_column (nmp, key1), new Paper_column (pc, key2)); - Grob_info i1; - i1.grob_ = command_column_; - i1.origin_trans_ = this; - + Grob_info i1 (this, command_column_); announce_grob (i1); - Grob_info i2; - i2.grob_ = musical_column_; - i2.origin_trans_ = this; - + Grob_info i2 (this, musical_column_); announce_grob (i2); } } diff --git a/lily/vertical-align-engraver.cc b/lily/vertical-align-engraver.cc index 20c3ac53e4..3e1838ae1f 100644 --- a/lily/vertical-align-engraver.cc +++ b/lily/vertical-align-engraver.cc @@ -18,21 +18,49 @@ class Vertical_align_engraver : public Engraver { Spanner *valign_; bool qualifies (Grob_info) const; - + SCM id_to_group_hashtab_; + public: TRANSLATOR_DECLARATIONS (Vertical_align_engraver); protected: + virtual void derived_mark () const; virtual void acknowledge_grob (Grob_info); virtual void process_music (); virtual void finalize (); + virtual void initialize (); }; + +ADD_TRANSLATOR (Vertical_align_engraver, + "Catch groups (staffs, lyrics lines, etc.) and stack " + "them vertically.", + /* creats*/ "VerticalAlignment", + /* accepts */ "", + /* acks */ "axis-group-interface", + /* reads */ "", + /* write */ ""); + + Vertical_align_engraver::Vertical_align_engraver () { valign_ = 0; + id_to_group_hashtab_ = SCM_EOL; +} + +void +Vertical_align_engraver::derived_mark () const +{ + scm_gc_mark (id_to_group_hashtab_); } +void +Vertical_align_engraver::initialize () +{ + id_to_group_hashtab_ = scm_c_make_hash_table (11); +} + + void Vertical_align_engraver::process_music () { @@ -67,14 +95,46 @@ Vertical_align_engraver::acknowledge_grob (Grob_info i) { if (qualifies (i)) { - Align_interface::add_element (valign_, i.grob_, get_property ("verticalAlignmentChildCallback")); + String id = i.context ()->id_string (); + + scm_hash_set_x (id_to_group_hashtab_, scm_makfrom0str (id.to_str0 ()), + i.grob_->self_scm ()); + + + SCM before_id = i.context ()->get_property ("alignAboveContext"); + SCM after_id = i.context ()->get_property ("alignBelowContext"); + + SCM before = scm_hash_ref (id_to_group_hashtab_, before_id, SCM_BOOL_F); + SCM after = scm_hash_ref (id_to_group_hashtab_, after_id, SCM_BOOL_F); + + + Align_interface::add_element (valign_, i.grob_, + get_property ("verticalAlignmentChildCallback")); + + if (unsmob_grob (before) || unsmob_grob (after)) + { + SCM elts = valign_->get_property ("elements"); + SCM new_order = scm_cdr (elts); + SCM *current = &new_order; + + for (SCM s = new_order; scm_is_pair (s); s = scm_cdr (s)) + { + if (scm_car (s) == after) + { + *current = scm_cons (i.grob_->self_scm(), s); + break; + } + else if (scm_car (s) == before) + { + scm_set_cdr_x (s, scm_cons (i.grob_->self_scm (), + scm_cdr (s))); + break; + } + + current = SCM_CDRLOC (s); + } + + valign_->set_property ("elements", new_order); + } } } - -ADD_TRANSLATOR (Vertical_align_engraver, - /* descr */ "Catch Vertical axis groups and stack them.", - /* creats*/ "VerticalAlignment", - /* accepts */ "", - /* acks */ "axis-group-interface", - /* reads */ "", - /* write */ ""); diff --git a/scm/define-context-properties.scm b/scm/define-context-properties.scm index 5583927759..d15ed9b303 100644 --- a/scm/define-context-properties.scm +++ b/scm/define-context-properties.scm @@ -23,6 +23,8 @@ (apply translator-property-description x)) `( (aDueText ,string? "Text to print at a unisono passage.") + (alignBelowContext ,string? "Where to insert newly created context in vertiical alignment.") + (alignAboveContext ,string? "Where to insert newly created context in vertiical alignment.") (alignBassFigureAccidentals ,boolean? "If true, then the accidentals are aligned in bass figure context.") diff --git a/scm/lily.scm b/scm/lily.scm index 79f88d2af6..4c0f0abc94 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -36,8 +36,6 @@ (debug-enable 'backtrace) (read-enable 'positions))) - - ;; initialize defaults. (ly:set-option 'command-line-settings '((resolution . 90) -- 2.39.5