lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Colored box behind a single note


From: Werner LEMBERG
Subject: Re: Colored box behind a single note
Date: Thu, 25 Jul 2019 07:33:04 +0200 (CEST)

> Using
> 
>   http://lsr.di.unimi.it/LSR/Item?id=1000
> 
> I wonder how to get the effect for a single note.  Ideally, I would
> like to write
> 
>   \genericSpan <...parameters ...>
>   e\startGroup\stopGroup

With the attached patch (for git master) I get exactly that :-)

Not sure whether the coding fits lilypond's C++ style, however.  If I
get an OK I will expand this with documentation and an extended
regression test.


    Werner
diff --git a/lily/horizontal-bracket-engraver.cc 
b/lily/horizontal-bracket-engraver.cc
index 608af35965..94b230989a 100644
--- a/lily/horizontal-bracket-engraver.cc
+++ b/lily/horizontal-bracket-engraver.cc
@@ -56,10 +56,23 @@ Horizontal_bracket_engraver::listen_note_grouping 
(Stream_event *ev)
 {
   Direction d = to_dir (ev->get_property ("span-direction"));
 
+  // One single-moment bracket is allowed.  Abbreviating a horizontal
+  // bracket's `START' span-direction with `L' and `STOP' with `R', this
+  // means that we can have
+  //
+  //   LLL...LLR
+  //
+  // or
+  //
+  //   LRRR...RR
+  //
+  // events attached to a single moment (we don't take care of the order of
+  // `L' and `R' events).
+
   if (d == STOP)
     {
       pop_count_++;
-      if (pop_count_ > bracket_stack_.size ())
+      if (pop_count_ > bracket_stack_.size () + 1)
         ev->origin ()->warning (_ ("do not have that many brackets"));
     }
   else
@@ -68,15 +81,18 @@ Horizontal_bracket_engraver::listen_note_grouping 
(Stream_event *ev)
       events_.push_back (ev);
     }
 
-  if (pop_count_ && push_count_)
+  if (pop_count_ >= 2 && push_count_ >= 2)
     ev->origin ()->warning (_ ("conflicting note group events"));
 }
 
 void
 Horizontal_bracket_engraver::acknowledge_note_column (Grob_info gi)
 {
+  bool process_single_moment_bracket = pop_count_ && push_count_;
+
   for (vsize i = 0; i < bracket_stack_.size (); i++)
     {
+    again:
       Side_position_interface::add_support (bracket_stack_[i], gi.grob ());
       Pointer_group_interface::add_grob (bracket_stack_[i],
                                          ly_symbol2scm ("columns"), gi.grob 
());
@@ -84,6 +100,14 @@ Horizontal_bracket_engraver::acknowledge_note_column 
(Grob_info gi)
                       gi.grob ());
       add_bound_item (text_stack_[i],
                       gi.grob ());
+
+      if (process_single_moment_bracket && i + 1 == bracket_stack_.size ())
+        {
+          // For a single-moment horizontal bracket, use the same note
+          // column again for the right part of the bracket.
+          process_single_moment_bracket = false;
+          goto again;
+        }
     }
 }
 
\include "ColorSpanDef.ily"

\new Staff {
  \override HorizontalBracket.line-thickness = #0
  \genericSpan #-4 #-2 #-4 #-2
    \colDarkRed \colLightRed #0 #0 ##f ##f
  <c' d'>2\startGroup\stopGroup

  c'4\startGroup\startGroup\stopGroup
  c'4\startGroup\stopGroup\stopGroup
}

\layout {
  \context {
    \Voice
    \consists "Horizontal_bracket_engraver"
  }
}

PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]