From: Han-Wen Nienhuys Date: Fri, 8 Nov 2002 01:39:37 +0000 (+0000) Subject: * lily/lookup.cc (triangle): new function. X-Git-Tag: release/1.7.7~14 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=367ed56704b509885a4928003b5aadcd5fa7820a;p=lilypond.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 60ad34f219..35ecb9e217 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2002-11-08 Han-Wen Nienhuys + + * 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 * Merge from stable: @@ -32,10 +47,9 @@ 2002-11-04 Jan Nieuwenhuizen - * 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. diff --git a/input/regression/measure-grouping.ly b/input/regression/measure-grouping.ly new file mode 100644 index 0000000000..2eca7d467f --- /dev/null +++ b/input/regression/measure-grouping.ly @@ -0,0 +1,25 @@ +\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" + } + } + } diff --git a/lily/include/lookup.hh b/lily/include/lookup.hh index b81c610f31..e4ffb541b7 100644 --- a/lily/include/lookup.hh +++ b/lily/include/lookup.hh @@ -31,6 +31,7 @@ struct Lookup 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 diff --git a/lily/include/measure-grouping-spanner.hh b/lily/include/measure-grouping-spanner.hh new file mode 100644 index 0000000000..afba2bf9e7 --- /dev/null +++ b/lily/include/measure-grouping-spanner.hh @@ -0,0 +1,25 @@ +/* +measure-grouping-spanner.hh -- declare + +source file of the GNU LilyPond music typesetter + +(c) 2002 Han-Wen Nienhuys + + */ + +#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 */ + diff --git a/lily/lookup.cc b/lily/lookup.cc index e12dd064ff..67022a606e 100644 --- a/lily/lookup.cc +++ b/lily/lookup.cc @@ -551,15 +551,31 @@ Lookup::bracket (Axis a, Interval iv, Real thick, Real protude) 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") ; diff --git a/lily/measure-grouping-engraver.cc b/lily/measure-grouping-engraver.cc new file mode 100644 index 0000000000..bbeab81854 --- /dev/null +++ b/lily/measure-grouping-engraver.cc @@ -0,0 +1,119 @@ +/* + measure-grouping-engraver.cc -- implement Measure_grouping_engraver + + source file of the GNU LilyPond music typesetter + + (c) 2002 Han-Wen Nienhuys + */ + +#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 */ ""); diff --git a/lily/measure-grouping-spanner.cc b/lily/measure-grouping-spanner.cc new file mode 100644 index 0000000000..55c76ae277 --- /dev/null +++ b/lily/measure-grouping-spanner.cc @@ -0,0 +1,53 @@ +/* +measure-grouping-spanner.cc -- implement Measure_grouping + +source file of the GNU LilyPond music typesetter + +(c) 2002 Han-Wen Nienhuys + + */ +#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 (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"); + + diff --git a/ps/music-drawing-routines.ps b/ps/music-drawing-routines.ps index 114669bbb6..338272affd 100644 --- a/ps/music-drawing-routines.ps +++ b/ps/music-drawing-routines.ps @@ -47,6 +47,19 @@ } 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 diff --git a/scm/grob-description.scm b/scm/grob-description.scm index 3302ffba54..2b5e39b0f4 100644 --- a/scm/grob-description.scm +++ b/scm/grob-description.scm @@ -530,7 +530,17 @@ (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) diff --git a/scm/ps.scm b/scm/ps.scm index f6f20fe814..3d1e99034f 100644 --- a/scm/ps.scm +++ b/scm/ps.scm @@ -75,13 +75,21 @@ (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) diff --git a/scm/tex.scm b/scm/tex.scm index 4026ec1789..41b43d2d68 100644 --- a/scm/tex.scm +++ b/scm/tex.scm @@ -99,6 +99,9 @@ (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 "=" diff --git a/scm/translator-property-description.scm b/scm/translator-property-description.scm index 3d9982067c..a560876d72 100644 --- a/scm/translator-property-description.scm +++ b/scm/translator-property-description.scm @@ -132,6 +132,8 @@ using barchecks in polyphonic music.") (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: