From b08872aadfedee2ef8a8f52565fe58166416f328 Mon Sep 17 00:00:00 2001 From: Neil Puttock Date: Sat, 15 Nov 2008 16:00:39 +0000 Subject: [PATCH] Set percent counter visibility using repeatCountVisibility. --- .../repeat-percent-count-visibility.ly | 15 ++++++++++++ lily/percent-repeat-engraver.cc | 23 ++++++++++++++----- ly/engraver-init.ly | 2 ++ scm/define-context-properties.scm | 4 ++++ scm/output-lib.scm | 7 ++++++ 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 input/regression/repeat-percent-count-visibility.ly diff --git a/input/regression/repeat-percent-count-visibility.ly b/input/regression/repeat-percent-count-visibility.ly new file mode 100644 index 0000000000..39e3fddb40 --- /dev/null +++ b/input/regression/repeat-percent-count-visibility.ly @@ -0,0 +1,15 @@ +\version "2.11.64" +\header { + texidoc = " +Percent repeat counters can be shown at regular +intervals by setting @code{repeatCountVisibility}. +" +} + +\relative c'' { + \set countPercentRepeats = ##t + \set repeatCountVisibility = #(every-nth-repeat-count-visible 5) + \repeat percent 10 { c1 } \break + \set repeatCountVisibility = #(every-nth-repeat-count-visible 2) + \repeat percent 6 { c1 d1 } +} diff --git a/lily/percent-repeat-engraver.cc b/lily/percent-repeat-engraver.cc index fc3d2a727a..b00eac52f6 100644 --- a/lily/percent-repeat-engraver.cc +++ b/lily/percent-repeat-engraver.cc @@ -1,5 +1,5 @@ /* - new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver + percent-repeat-engraver.cc -- implement Percent_repeat_engraver source file of the GNU LilyPond music typesetter @@ -30,6 +30,7 @@ class Percent_repeat_engraver : public Engraver { void typeset_perc (); + bool check_count_visibility (SCM count); public: TRANSLATOR_DECLARATIONS (Percent_repeat_engraver); @@ -120,7 +121,7 @@ Percent_repeat_engraver::listen_percent (Stream_event *ev) /* don't warn about percent repeats: slash repeats are not exactly 1 or 2 measures long. - */ + */ return; } percent_event_ = ev; @@ -147,7 +148,8 @@ Percent_repeat_engraver::process_music () percent_->set_bound (LEFT, col); SCM count = percent_event_->get_property ("repeat-count"); - if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats"))) + if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats")) + && check_count_visibility (count)) { percent_counter_ = make_spanner ("PercentRepeatCounter", percent_event_->self_scm ()); @@ -167,8 +169,8 @@ Percent_repeat_engraver::process_music () Item *double_percent = make_item ("DoublePercentRepeat", percent_event_->self_scm ()); SCM count = percent_event_->get_property ("repeat-count"); - if (count != SCM_EOL - && to_boolean (get_property ("countPercentRepeats"))) + if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats")) + && check_count_visibility (count)) { Item *double_percent_counter = make_item ("DoublePercentRepeatCounter", percent_event_->self_scm ()); @@ -219,6 +221,14 @@ Percent_repeat_engraver::typeset_perc () } } +bool +Percent_repeat_engraver::check_count_visibility (SCM count) +{ + SCM proc = get_property ("repeatCountVisibility"); + return (ly_is_procedure (proc) && to_boolean (scm_call_2 (proc, + count, + context ()->self_scm ()))); +} void @@ -239,7 +249,8 @@ ADD_TRANSLATOR (Percent_repeat_engraver, /* read */ "countPercentRepeats " "currentCommandColumn " - "measureLength ", + "measureLength " + "repeatCountVisibility ", /* write */ "forbidBreak " diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index 49f22c1b3d..b1be75d1cb 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -522,6 +522,8 @@ automatically when an output definition (a @code{\score} or explicitKeySignatureVisibility = #all-visible implicitTimeSignatureVisibility = #end-of-line-invisible + repeatCountVisibility = #all-repeat-counts-visible + autoBeamSettings = #default-auto-beam-settings autoBeaming = ##t autoBeamCheck = #default-auto-beam-check diff --git a/scm/define-context-properties.scm b/scm/define-context-properties.scm index e3245477ee..29a633ef3c 100644 --- a/scm/define-context-properties.scm +++ b/scm/define-context-properties.scm @@ -374,6 +374,10 @@ context.") (repeatCommands ,list? "This property is a list of commands of the form @code{(list 'volta @var{x})}, where @var{x} is a string or @code{#f}. @code{'end-repeat} is also accepted as a command.") + (repeatCountVisibility ,procedure? "A procedure taking as +arguments an integer and context, returning whether the corresponding +percent repeat number should be printed when @code{countPercentRepeats} +is set.") (restNumberThreshold ,number? "If a multimeasure rest has more measures than this, a number is printed.") diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 22e4377046..dcb1129004 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -202,6 +202,13 @@ centered, X==1 is at the right, X == -1 is at the left." (define-public (first-bar-number-invisible barnum) (> barnum 1)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; percent repeat counters + +(define-public ((every-nth-repeat-count-visible n) count context) (= 0 (modulo count n))) + +(define-public (all-repeat-counts-visible count context) #t) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; break visibility -- 2.39.5