From 8cd8cd8852eb0cec8ff09dc40217ab2625cfb346 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 20:12:54 +0000 Subject: [PATCH] lilypond-1.0.1 --- lily/align-element.cc | 187 +++++++++++++++++++++++++++++++ lily/include/score-element.hh | 128 +++++++++++++++++++++ lily/include/super-element.hh | 40 +++++++ lily/span-bar.cc | 69 +++++++----- lily/vertical-group-elem.cc | 22 +--- stepmake/stepmake/C++_rules.make | 27 +++++ stepmake/stepmake/C_rules.make | 26 +++++ 7 files changed, 457 insertions(+), 42 deletions(-) create mode 100644 lily/align-element.cc create mode 100644 lily/include/score-element.hh create mode 100644 lily/include/super-element.hh create mode 100644 stepmake/stepmake/C++_rules.make create mode 100644 stepmake/stepmake/C_rules.make diff --git a/lily/align-element.cc b/lily/align-element.cc new file mode 100644 index 0000000000..4f80841a66 --- /dev/null +++ b/lily/align-element.cc @@ -0,0 +1,187 @@ +/* + align-elem.cc -- implement Align_elem + + source file of the GNU LilyPond music typesetter + + (c) 1997--1998 Han-Wen Nienhuys +*/ + +#include "align-element.hh" +#include "interval.hh" +#include "direction.hh" + + +struct Align_element_content { + Score_element * elem_l_; + int priority_i_; + + static int compare (Align_element_content const &h1, + Align_element_content const &h2) + { + return h1.priority_i_ - h2.priority_i_; + } + Align_element_content (Score_element *elem_l, int p) + { + priority_i_ = p; + elem_l_ = elem_l; + } + Align_element_content () { + elem_l_ = 0; + priority_i_ = 0; + } +}; + + + +void +Align_element::add_element (Score_element*el_l) +{ + int p = priority_i_arr_.size (); + add_element_priority (el_l, p); +} + +void +Align_element::add_element_priority (Score_element *el, int p) +{ + assert (! contains_b (el)); + elem_l_arr_.push (el); + priority_i_arr_.push (p); + add_dependency (el); +} + +void +Align_element::do_substitute_dependency (Score_element*o, + Score_element*n) +{ + int i; + while ((i = elem_l_arr_.find_i (o))>=0) + if (n) + elem_l_arr_[i] = n; + else + elem_l_arr_.del (i); + + if (o == center_l_) + { + center_l_ = n; + } +} + +/** + Align elements top to bottom. + The first element has its top at y = 0.0 afterwards + + TODO configurable, like Horizontal_align_item + + TODO should parametrise in direction and coordinate. + */ +void +Align_element::do_post_processing() +{ + if (axis_ == Y_AXIS) + do_side_processing (); +} + +void +Align_element::do_pre_processing () +{ + if (axis_ == X_AXIS) + do_side_processing (); +} + +void +Align_element::do_side_processing () +{ + sort_elements (); + Array dims; + + for (int i=0; i < elem_l_arr_.size(); i++) + { + Interval y = elem_l_arr_[i]->extent(axis_) ; + if (y.empty_b()) + y = Interval (0,0); + + dims.push (y); + } + + Real where_f=0; + Real center_f = 0.0; + for (int i=0 ; i < elem_l_arr_.size(); i++) + { + Real dy = - stacking_dir_ * dims[i][-stacking_dir_]; + if (i) + dy += stacking_dir_ * dims[i-1][stacking_dir_]; + + if (i) + { + dy = (dy >? threshold_interval_[SMALLER] ) + translate_axis (where_f, axis_); + } + + if (align_dir_ == RIGHT) + center_f = where_f; + + if (center_f) + for (int i=0 ; i < elem_l_arr_.size(); i++) + elem_l_arr_[i]->translate_axis (- center_f, axis_); +} + +Align_element::Align_element() +{ + threshold_interval_ = Interval (0, Interval::infinity ()); + transparent_b_ = true; + set_empty (true); + stacking_dir_ = DOWN; + align_dir_ = LEFT; + axis_ = X_AXIS; + center_l_ =0; +} + + +bool +Align_element::contains_b (Score_element const *e) const +{ + return elem_l_arr_.find_l (e); +} + + +IMPLEMENT_IS_TYPE_B1(Align_element, Score_element); + +void +Align_element::sort_elements () +{ + Array content; + for (int i =0; i < elem_l_arr_.size(); i++) + content.push (Align_element_content (elem_l_arr_[i], priority_i_arr_[i])); + content.sort (Align_element_content::compare); + + elem_l_arr_.clear(); + priority_i_arr_.clear(); + + for (int i =0; i < content.size(); i++) + { + elem_l_arr_.push (content[i].elem_l_); + priority_i_arr_.push (content[i].priority_i_); + } +} + +void +Align_element::do_print () const +{ +#if 0 + DOUT << "contains: "; + for (int i=0 ; i < item_l_arr_.size(); i++) + DOUT << item_l_arr_[i]->name () << ", "; +#endif +} diff --git a/lily/include/score-element.hh b/lily/include/score-element.hh new file mode 100644 index 0000000000..7a3211b234 --- /dev/null +++ b/lily/include/score-element.hh @@ -0,0 +1,128 @@ +/* + score-element.hh -- part of GNU LilyPond + + (c) 1996,97 Han-Wen Nienhuys +*/ + +#ifndef STAFFELEM_HH +#define STAFFELEM_HH + +#include "parray.hh" +#include "virtual-methods.hh" +#include "directed-graph.hh" +#include "graphical-element.hh" + +#define SCORE_ELEMENT_CLONE(T) VIRTUAL_COPY_CONS (T, Score_element) + + +typedef void (Score_element::*Score_element_method_pointer) (void); + +/** Both Spanner and Item are Score_element's. Most Score_element's depend + on other Score_element's, eg, Beam needs to know and set direction of + Stem. So the Beam has to be calculated *before* Stem. This is + accomplished with the dependencies fields of struct Score_element, + which are implemented in the Directed_graph_node class: all elements + form an acyclic graph. + + (elem) */ +class Score_element : private Directed_graph_node, public virtual Graphical_element { +public: + Paper_score *pscore_l_; + + Score_element (); + Score_element (Score_element const&); + virtual void print () const; + + Paper_def *paper () const; + Lookup * lookup_l () const; + + virtual ~Score_element (); + DECLARE_MY_RUNTIME_TYPEINFO; + + void add_processing (); + + /** + Remove all links (dependencies, dependents, Axis_group_elements. + */ + void unlink (); + void substitute_dependency (Score_element*,Score_element*); + void remove_dependency (Score_element*); + /** + add a dependency. It may be the 0 pointer, in which case, it is ignored. + */ + void add_dependency (Score_element*); + + /* + virtual accessors + */ + + virtual Spanner* access_Spanner () { return 0; } + virtual Span_bar* access_Span_bar () { return 0; } + virtual Axis_group_element * access_Axis_group_element () { return 0; } + virtual Score_element* access_Score_element () { return this; } + + virtual Item * access_Item () { return 0; } + virtual Line_of_score * line_l () const; + virtual bool linked_b () const; + SCORE_ELEMENT_CLONE (Score_element); + + /// do not print anything black + bool transparent_b_; + + int size_i_; + + // ugh: no protection. Denk na, Vrij Veilig + void calcalute_dependencies (int final, int busy, Score_element_method_pointer funcptr); + +protected: + /** + Administration: Where are we?. This is mainly used by Super_elem and + Score_element::calcalute_dependencies () + + 0 means ORPHAN, + -1 means deleted + + */ +public: + int status_i_; +protected: + Score_element* dependency (int) const; + Score_element* dependent (int) const; + int dependent_size () const; + int dependency_size () const; + + virtual void do_brew_molecule (); + void junk_links (); + virtual Interval do_height () const; + virtual Interval do_width () const; + + /// do printing of derived info. + virtual void do_print () const {} + /// generate the molecule + virtual Molecule* brew_molecule_p () const; + ///executed directly after the item is added to the Paper_score + virtual void do_add_processing (); + /// do calculations before determining horizontal spacing + virtual void do_pre_processing (); + + /// generate rods & springs + virtual void do_space_processing (); + + virtual void do_breakable_col_processing (); + /// do calculations after determining horizontal spacing + virtual void do_post_processing (); + + virtual void do_substitute_dependency (Score_element * , Score_element *); + virtual void do_substitute_dependent (Score_element *, Score_element *); + virtual void do_break_processing (); + virtual void handle_broken_dependencies (); + virtual void handle_prebroken_dependencies (); + virtual Link_array get_extra_dependencies () const; + virtual void do_unlink (); + virtual void do_junk_links (); + +}; + + +#endif // STAFFELEM_HH + diff --git a/lily/include/super-element.hh b/lily/include/super-element.hh new file mode 100644 index 0000000000..a625b850ec --- /dev/null +++ b/lily/include/super-element.hh @@ -0,0 +1,40 @@ +/* + super-element.hh -- declare Super_elem + + source file of the LilyPond music typesetter + + (c) 1997--1998 Han-Wen Nienhuys +*/ + + +#ifndef SUPER_ELEM_HH +#define SUPER_ELEM_HH + +#include "score-element.hh" +/** The toplevel element. The Paper_score contains this element, and any + element shoud be a dependency for the super element. + */ +class Super_elem : public Score_element { +public: + Link_array lines_arr_; + Line_of_score * line_of_score_l_; + void add_broken_line (Line_of_score*); + Super_elem(); + + void space_processing (); + void pre_processing(); + void breakable_col_processing(); + void break_processing(); + void post_processing(); + void output_all (); + void unlink_all (); + +protected: + virtual void do_substitute_dependency (Score_element*,Score_element*); + virtual void handle_broken_dependencies(); + + virtual void do_add_processing(); + DECLARE_MY_RUNTIME_TYPEINFO; +}; + +#endif // SUPER_ELEM_HH diff --git a/lily/span-bar.cc b/lily/span-bar.cc index e89b05352f..678853185b 100644 --- a/lily/span-bar.cc +++ b/lily/span-bar.cc @@ -3,52 +3,60 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1998 Han-Wen Nienhuys + (c) 1997--1998 Han-Wen Nienhuys */ -#include "dimen.hh" +#include "dimension.hh" #include "span-bar.hh" #include "lookup.hh" #include "atom.hh" #include "paper-def.hh" #include "molecule.hh" -#include "vertical-align-elem.hh" +#include "align-element.hh" void -Span_bar::add (Bar*b) +Span_bar::add_bar (Bar*b) { spanning_l_arr_.push (b); add_dependency (b); } - - void -Span_bar::do_substitute_dependency (Score_elem*o, Score_elem*n) +Span_bar::do_substitute_dependency (Score_element*o, Score_element*n) { spanning_l_arr_.unordered_substitute (o, n); } - void -Span_bar::set (Vertical_align_element *a) +Span_bar::set_align (Align_element *a) { add_dependency (a); } - Interval -Span_bar::do_width() const +Span_bar::do_width () const { - return paper()->lookup_l ()->bar (type_str_, 40 PT).dim_.x (); // ugh + return lookup_l ()->bar (type_str_, 40 PT).dim_.x (); // ugh } void -Span_bar::do_pre_processing() +Span_bar::do_pre_processing () { Bar::do_pre_processing (); - if (spanning_l_arr_.size() < 1) + evaluate_empty (); +} + +void +Span_bar::do_post_processing () +{ + Bar::do_post_processing (); +} + +void +Span_bar::evaluate_empty () +{ + if (spanning_l_arr_.size () < 1) { transparent_b_ = true; set_empty (true); @@ -66,40 +74,51 @@ Span_bar::do_pre_processing() { type_str_ = "|."; } + else if (type_str_ == ":|:") + { + type_str_ = ".|."; + } } Atom Span_bar::get_bar_sym (Real dy) const { - return paper()->lookup_l ()->bar (type_str_, dy); + if (dy < paper ()->staffheight_f () / 2) + return Atom (); + + return lookup_l ()->bar (type_str_, dy); } - Molecule* -Span_bar::brew_molecule_p() const +Span_bar::brew_molecule_p () const { Interval y_int; - for (int i=0; i < spanning_l_arr_.size(); i++) + for (int i=0; i < spanning_l_arr_.size (); i++) { - Axis_group_element *common = + Graphical_axis_group *common = common_group (spanning_l_arr_[i], Y_AXIS); Real y = spanning_l_arr_[i]->relative_coordinate (common, Y_AXIS) -relative_coordinate (common,Y_AXIS); - y_int.unite (y + spanning_l_arr_[i]->height()); + y_int.unite (y + spanning_l_arr_[i]->height ()); } - Atom s = get_bar_sym (y_int.length()); + Atom s = get_bar_sym (y_int.length ()); Molecule*output = new Molecule (Atom (s)); - output->translate_axis (y_int.center(), Y_AXIS); + output->translate_axis (y_int.center (), Y_AXIS); return output; } +IMPLEMENT_IS_TYPE_B1 (Span_bar,Bar); -IMPLEMENT_IS_TYPE_B1(Span_bar,Bar); - -Span_bar::Span_bar() +Span_bar::Span_bar () { type_str_ = ""; } + +Span_bar* +Span_bar::access_Span_bar () +{ + return this; +} diff --git a/lily/vertical-group-elem.cc b/lily/vertical-group-elem.cc index 79e22317e0..61c644676c 100644 --- a/lily/vertical-group-elem.cc +++ b/lily/vertical-group-elem.cc @@ -3,36 +3,24 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1998 Han-Wen Nienhuys + (c) 1997--1998 Han-Wen Nienhuys */ -#include "vertical-group-elem.hh" +#include "vertical-group-element.hh" #include "interval.hh" #include "item.hh" #include "debug.hh" -void -Vertical_group_element::add_element (Graphical_element*e) -{ - axis_admin_.add_element (e, this, Y_AXIS, Y_AXIS); -} -void -Vertical_group_element::remove_element (Graphical_element*e) +Vertical_group_element::Vertical_group_element() + : Axis_group_element (Y_AXIS,Y_AXIS) { - axis_admin_.remove_element (e, Y_AXIS, Y_AXIS); } - Interval Vertical_group_element::do_height() const { - return axis_admin_.extent (Y_AXIS); -} -void -Vertical_group_element::remove_all() -{ - axis_admin_.remove_all (Y_AXIS,Y_AXIS); + return Graphical_axis_group::extent (Y_AXIS); } IMPLEMENT_IS_TYPE_B1(Vertical_group_element, Axis_group_element); diff --git a/stepmake/stepmake/C++_rules.make b/stepmake/stepmake/C++_rules.make new file mode 100644 index 0000000000..df26b06ced --- /dev/null +++ b/stepmake/stepmake/C++_rules.make @@ -0,0 +1,27 @@ +# title C++ rules +# file make/C++_rules.make + +.SUFFIXES: .cc .o .hh .yy .ll .dep + +# compile rules: +# +$(outdir)/%.o: %.cc + $(DO_CXX_COMPILE) + +$(outdir)/%.o: $(outdir)/%.cc + $(DO_CXX_COMPILE) + +$(outdir)/%.cc: %.yy + $(BISON) $< + mv $<.tab.c $@ + +$(outdir)/%.hh: %.yy + $(BISON) -d $< + mv $<.tab.h $@ + mv $<.tab.c $(basename $@).cc + +$(outdir)/%.cc: %.ll + $(FLEX) -Cfe -p -p -t $< > $@ +# could be faster: +# $(FLEX) -8 -Cf -t $< > $@ + diff --git a/stepmake/stepmake/C_rules.make b/stepmake/stepmake/C_rules.make new file mode 100644 index 0000000000..a2bf496187 --- /dev/null +++ b/stepmake/stepmake/C_rules.make @@ -0,0 +1,26 @@ +# stepmake/C_rules.make + +.SUFFIXES: .c .o .h .y .l .dep + +$(outdir)/%.o: %.c + $(DO_C_COMPILE) + +$(outdir)/%.o: $(outdir)/%.c + $(DO_C_COMPILE) + +$(outdir)/%.c: %.y + $(BISON) $< +# mv $<.tab.c $@ + mv parser.tab.c $@ + +$(outdir)/%.h: %.y + $(BISON) -d $< +# mv $<.tab.h $@ + mv parser.tab.h $@ + mv parser.tab.c $(basename $@).c + +$(outdir)/%.c: %.l + $(FLEX) -Cfe -p -p -t $< > $@ +# could be faster: +# $(FLEX) -8 -Cf -t $< > $@ + -- 2.39.5