[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Proposal: Automatically adjusting indents for instrument names
From: |
Johannes Feulner |
Subject: |
Re: Proposal: Automatically adjusting indents for instrument names |
Date: |
Sun, 14 Feb 2021 12:31:46 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 |
Hi Lukas,
thanks for your hint. Some padding was added to an indent, even when no
instrument (short) name was defined. I fixed it in score.cc, see below.
Cheers,
Johannes
Am 14.02.2021 um 00:19 schrieb Lukas-Fabian Moser:
Hi Johannes,
I 'd like to propose the enhancement below to LilyPond. It will
increase the indent and short-indent of a score to fit all of its
instrument names and instrument short names.
This is a great idea (and a feature I've been missing for quite some
time).
In the current version, subsequent systems get a positive short-indent
even if there is no shortInstrumentName given. Is that on purpose? I
would have expected a minimal
\version "2.22.0"
\new Staff { \repeat unfold 64 c'4 }
to yield the same result before and after your patch.
Lukas
diff --git a/lily/score.cc b/lily/score.cc
index 140db0e..a3c24e9 100644
--- a/lily/score.cc
+++ b/lily/score.cc
@@ -32,6 +32,7 @@
#include "paper-book.hh"
#include "paper-score.hh"
#include "warn.hh"
+#include "system.hh" // <SCORIO JF20210212/>
Input *
Score::origin () const
@@ -99,6 +100,43 @@ Score::Score (Score const &s)
ly_module_copy (header_, s.header_);
}
+// <SCORIO JF20210212>
+/*
+ Set indent and short-indent to cover the width of
+ of the longest instrument name and the longest instrument short name
resp.
+ but only in case they are longer than indent or short-indent resp.
+ Otherwise, do not change the values of indent or short-indent.
+*/
+void
+sc_adjust_indents(SCM context, Output_def *def, Real scale) {
+
+ Global_context *g = unsmob<Global_context> (context);
+ LY_ASSERT_SMOB (Global_context, context, 1);
+ SCM output = g->get_output ();
+
+ if (Paper_score *od = unsmob<Paper_score> (output)) {
+ Interval instrumentNamesWidth =
od->root_system()->scGetInstrumentNamesWidth ();
+ Real padding = 1.5 * scale;
+
+ Real indent = def->get_dimension (ly_symbol2scm ("indent"));
+ Real long_width = instrumentNamesWidth[LEFT];
+ if (0 < long_width) {
+ long_width += padding;
+ }
+ def->set_variable(ly_symbol2scm( "indent"),
+ scm_from_double (std::max (indent, long_width)));
+
+ Real short_indent = def->get_dimension (ly_symbol2scm
("short-indent"));
+ Real short_width = instrumentNamesWidth[RIGHT];
+ if (0 < short_width) {
+ short_width += padding;
+ }
+ def->set_variable (ly_symbol2scm ("short-indent"),
+ scm_from_double (std::max (short_indent,
short_width)));
+ }
+}
+// </SCORIO JF20210212>
+
/*
Format score, return list of Music_output objects.
@@ -139,6 +177,8 @@ Score::book_rendering (Output_def *layoutbook,
{
SCM s = ly_format_output (context);
+ sc_adjust_indents(context, def, scale); // <SCORIO JF20210212/>
+
outputs = scm_cons (s, outputs);
}
--
Johannes Feulner
Tel: +49 721 33500158 johannes.feulner@scorio.com
scorio GmbH Bonhoefferweg 3 76327 Pfinztal
Geschäftsführer Johannes Feulner
Sitz der Gesellschaft Karlsruhe
Amtsgericht Mannheim HRB 713486