+2002-11-08 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ * lily/lookup.cc (triangle): new function.
+
+ * input/regression/measure-grouping.ly (texidoc): new file: show
+ triangles and brackets for beat groups of 3 and 2.
+
+ * lily/include/measure-grouping-spanner.hh (class
+ Measure_grouping): new file.
+
+ * lily/measure-grouping-spanner.cc (brew_molecule): new file
+
+ * lily/measure-grouping-engraver.cc (class
+ Measure_grouping_engraver): new file.
+
2002-11-06 Jan Nieuwenhuizen <janneke@gnu.org>
* Merge from stable:
2002-11-04 Jan Nieuwenhuizen <janneke@gnu.org>
- * scripts/lilypond-book.py:
- * scripts/ly2dvi.py: Fix: redirect latex progress/error output to
- stderr (by default this goes to stdout). Show lilypond progress,
- even when not verbose.
+ * scripts/lilypond-book.py: * scripts/ly2dvi.py: Fix: redirect
+ latex progress/error output to stderr (by default this goes to
+ stdout). Show lilypond progress, even when not verbose.
* python/lilylib.py (system): New optional parameter to control
showing of progress.
--- /dev/null
+\header
+{
+texidoc = "The Measure_grouping_engraver adds triangles and brackets above beats
+when you set beatGrouping.
+
+(unfinished.)
+"
+}
+\score { \notes
+\context Staff
+ {
+ \time 8/4
+ \property Staff.beatGrouping = #'(3 3)
+ c4 c c c
+ c4
+ \property Staff.beatGrouping = #'()
+ c c c
+
+ }
+ \paper {
+ \translator { \StaffContext
+ \consists "Measure_grouping_engraver"
+ }
+ }
+ }
static Molecule roundfilledbox (Box b, Real blotdiameter);
static Molecule repeat_slash (Real w, Real slope, Real th);
static Molecule line (Real th, Offset from, Offset to);
+ static Molecule triangle (Interval, Real, Real);
};
#endif // LOOKUP_HH
--- /dev/null
+/*
+measure-grouping-spanner.hh -- declare
+
+source file of the GNU LilyPond music typesetter
+
+(c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ */
+
+#ifndef MEASURE_GROUPING_SPANNER_HH
+#define MEASURE_GROUPING_SPANNER_HH
+
+#include "grob.hh"
+
+class Measure_grouping
+{
+public:
+ DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM ));
+
+ static bool has_interface (Grob*);
+};
+
+
+#endif /* MEASURE_GROUPING_SPANNER_HH */
+
return m;
}
+Molecule
+Lookup::triangle (Interval iv, Real thick, Real protude)
+{
+ Box b ;
+ b[X_AXIS] =iv;
+ b[Y_AXIS] = Interval (0, protude);
+
+ SCM s = scm_list_n (ly_symbol2scm ("symmetric-x-triangle"),
+ gh_double2scm (thick),
+ gh_double2scm (iv.length()),
+ gh_double2scm (protude), SCM_UNDEFINED);
+
+ return Molecule (b, s);
+}
+
+
/*
TODO: use rounded boxes.
*/
LY_DEFINE(ly_bracket ,"ly:bracket",
4, 0, 0,
(SCM a, SCM iv, SCM t, SCM p),
- "Make a bracket in direction @var{a}. The extent of the bracket is
-given by @var{iv}. The wings protude by an amount of @var{p}, which
-may be negative. The thickness is given by @var{t}.")
+ "Make a bracket in direction @var{a}. The extent of the bracket is "
+ "given by @var{iv}. The wings protude by an amount of @var{p}, which "
+ "may be negative. The thickness is given by @var{t}.")
{
SCM_ASSERT_TYPE(ly_axis_p (a), a, SCM_ARG1, __FUNCTION__, "axis") ;
SCM_ASSERT_TYPE(ly_number_pair_p (iv), iv, SCM_ARG2, __FUNCTION__, "number pair") ;
--- /dev/null
+/*
+ measure-grouping-engraver.cc -- implement Measure_grouping_engraver
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ */
+
+#include "score-engraver.hh"
+#include "spanner.hh"
+#include "warn.hh"
+#include "side-position-interface.hh"
+
+class Measure_grouping_engraver : public Engraver
+{
+public:
+ TRANSLATOR_DECLARATIONS(Measure_grouping_engraver);
+
+protected:
+ Spanner * grouping_;
+ Rational stop_grouping_mom_;
+
+ virtual void start_translation_timestep ();
+ virtual void finalize ();
+ virtual void acknowledge_grob (Grob_info);
+};
+
+void
+Measure_grouping_engraver::finalize()
+{
+ if (grouping_)
+ {
+ grouping_->set_bound (RIGHT,
+ unsmob_grob (get_property ("currentCommandColumn")));
+ typeset_grob (grouping_);
+ grouping_= 0;
+ }
+}
+
+
+void
+Measure_grouping_engraver::acknowledge_grob (Grob_info gi)
+{
+ if (grouping_)
+ {
+ Side_position_interface::add_support (grouping_, gi.grob_);
+ }
+}
+
+void
+Measure_grouping_engraver::start_translation_timestep ()
+{
+ Moment now = now_mom();
+ if (grouping_ && now.main_part_ >= stop_grouping_mom_ && !now.grace_part_)
+ {
+ Side_position_interface::add_staff_support (grouping_);
+ grouping_->set_bound (RIGHT,
+ unsmob_grob (get_property ("currentMusicalColumn")));
+ typeset_grob (grouping_);
+ grouping_ = 0;
+ }
+
+ if (now.grace_part_)
+ return;
+
+ SCM grouping = get_property ("beatGrouping");
+ if (gh_pair_p (grouping))
+ {
+ Moment *measpos = unsmob_moment (get_property ("measurePosition"));
+ Rational mp = measpos->main_part_;
+
+ Moment * beatlen = unsmob_moment (get_property ("beatLength"));
+ Rational bl = beatlen->main_part_;
+
+ Rational where (0);
+ for (SCM s = grouping; gh_pair_p (s);
+ where += Rational (gh_scm2int (gh_car (s))) * bl,
+ s = gh_cdr (s)
+ )
+ {
+ int grouplen = gh_scm2int (gh_car(s));
+ if (where == mp)
+ {
+ if (grouping_)
+ {
+ programming_error ("Huh, last grouping not finished yet.");
+ continue;
+ }
+
+ grouping_ = new Spanner (get_property ("MeasureGrouping"));
+ grouping_->set_bound (LEFT, unsmob_grob (get_property ("currentMusicalColumn")));
+ announce_grob (grouping_, SCM_EOL);
+
+
+ stop_grouping_mom_ = now.main_part_ + Rational(grouplen - 1) * bl ;
+ top_engraver ()->add_moment_to_process (Moment (stop_grouping_mom_));
+
+ if (grouplen == 3)
+ grouping_->set_grob_property ("type", ly_symbol2scm ("triangle"));
+ else
+ grouping_->set_grob_property ("type", ly_symbol2scm ("bracket"));
+
+ break ;
+ }
+ }
+ }
+}
+Measure_grouping_engraver::Measure_grouping_engraver()
+{
+ grouping_ = 0;
+}
+
+ENTER_DESCRIPTION(Measure_grouping_engraver,
+/* descr */ "Creates Measure_grouping objects using beatGrouping property",
+/* creats*/ "MeasureGrouping",
+/* accepts */ "",
+/* acks */ "note-column-interface",
+/* reads */ "beatGrouping beatLength measurePosition currentMusicalColumn",
+/* write */ "");
--- /dev/null
+/*
+measure-grouping-spanner.cc -- implement Measure_grouping
+
+source file of the GNU LilyPond music typesetter
+
+(c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ */
+#include "paper-def.hh"
+#include "spanner.hh"
+#include "measure-grouping-spanner.hh"
+#include "lookup.hh"
+#include "item.hh"
+
+MAKE_SCHEME_CALLBACK (Measure_grouping, brew_molecule, 1);
+SCM
+Measure_grouping::brew_molecule (SCM grob)
+{
+ Spanner * me = dynamic_cast<Spanner*> (unsmob_grob (grob));
+
+ /*
+ TODO: robustify.
+ */
+ SCM which = me->get_grob_property ("type");
+ SCM thick = me->get_grob_property ("thickness");
+ SCM height = me->get_grob_property ("height");
+
+ Real t = me->get_paper ()->get_var ("linethickness") * gh_scm2double (thick);
+ Grob *common = me->get_bound(LEFT)->common_refpoint (me->get_bound (RIGHT),
+ X_AXIS);
+ Real w = me->get_bound (LEFT)->relative_coordinate (common, X_AXIS)
+ - me->get_bound (RIGHT)->relative_coordinate (common, X_AXIS);
+
+ Interval iv (0,w);
+
+ Molecule m;
+ if (which == ly_symbol2scm ("bracket"))
+ {
+ m = Lookup::bracket (X_AXIS, iv,t, gh_scm2double (height));
+ }
+ else if (which == ly_symbol2scm ("triangle"))
+ {
+ m = Lookup::triangle (iv, t, gh_scm2double (height));
+ }
+
+ return m.smobbed_copy();
+}
+
+ADD_INTERFACE (Measure_grouping,"measure-grouping-interface",
+ "indicate groups of beats. Valid choices for 'type are 'bracket and 'triangle.",
+ "thickness height");
+
+
} ifelse
} bind def
+
+/draw_symmetric_x_triangle % th w h
+{
+ setlinewidth
+ 0 0 moveto
+ dup
+ 0 rlineto
+ 2 div
+ exch rlineto
+ 0 0 lineto
+ stroke
+} bind def
+
/draw_round_box % breapth width depth height blot
{
/blot exch def
(padding . 0.8)
(meta . ((interfaces . (text-interface side-position-interface font-interface mark-interface self-alignment-interface item-interface ))))
))
-
+
+ (MeasureGrouping
+ . (
+ (Y-offset-callbacks . (,Side_position_interface::aligned_side))
+ (molecule-callback . ,Measure_grouping::brew_molecule)
+ (meta . ((interfaces . (spanner-interface measure-grouping-interface))))
+ (padding . 2)
+ (direction . 1)
+ (thickness . 1)
+ (height . 2.0)
+ ))
(MultiMeasureRest
. (
(spacing-procedure . ,Multi_measure_rest::set_spacing_rods)
(list arch_angle arch_width arch_height height arch_thick thick))
" draw_bracket"))
+(define (symmetric-x-triangle thick w h)
+ (string-append
+ (numbers->string (list thick w h ))
+ " draw_symmetric_x_triangle"))
+
+
(define (char i)
(string-append
"(\\" (inexact->string i 8) ") show " ))
+
(define (comment s)
(string-append "% " s "\n"))
+
(define (dashed-line thick on off dx dy)
(string-append
(ly:number->string dx)
(define (zigzag-line centre? zzw zzh thick dx dy)
(embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
+(define (symmetric-x-triangle t w h)
+ (embedded-ps (list 'symmetric-x-triangle t w h)))
+
(define (font-load-command name-mag command)
(string-append
"\\font\\" command "="
(translator-property-description 'barNumberVisibility procedure? "Procedure that takes an int and returns whether the corresponding bar number should be printed")
(translator-property-description 'beamMelismaBusy boolean? "Signal if a beam is set when automaticMelismata is set")
(translator-property-description 'beatLength ly:moment? "The length of one beat in this time signature.")
+(translator-property-description 'beatGrouping list?
+ "List of beatgroups. Eg. in 5/8 time #(list 2 3).")
(translator-property-description 'breakAlignOrder list? "Defines the order in which
prefatory matter (clefs, key signatures) appears, eg. this puts the
key signatures after the bar lines: