Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing #1189 #1195

Merged
merged 6 commits into from
Jul 31, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
As of v3.0.0 this project adheres to [Semantic Versioning](http://semver.org/). It follows [some conventions](http://keepachangelog.com/).

[Unreleased][unreleased]
## Changed
- Notes are now left-aligned as if all clefs had the same width as the largest clef in the score. You can get previous behavior back with `\grebolshiftcleftype{current}`, or temporary force alignment until the end of a score with `\grelocalbolshiftcleftype`. See Documentation of these functions and [#1189](https://github.com/gregorio-project/gregorio/issues/1189).

### Added
- More cavum shapes are now available. To use them, simply add `r` in gabc to any note in a glyph. See [#844](https://github.com/gregorio-project/gregorio/issues/844).
- Square brackets can be placed around notes by using `[[` and `]]` to surround said notes in gabc (see [#844](https://github.com/gregorio-project/gregorio/issues/844)).
Expand Down
20 changes: 20 additions & 0 deletions doc/Command_Index_User.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,26 @@ \subsubsection{End of Line Behavior}
& \texttt{disable} & The shifts are not applied.
\end{argtable}

\macroname{\textbackslash grebolshiftcleftype}{\{\#1\}}{gregoriotex-spaces.tex}
Macro to determine how notes should be left aligned in the case where clefs of different widths appear in the same score.

\begin{argtable}
\#1 & \texttt{largest} & The notes are aligned as if all clefs had the width of the largest clef (default)\\
& \texttt{current} & The notes are aligned on the current clef, which leads to unaligned notes. This was the default of Gregorio < \texttt{5.0}.
\end{argtable}

\macroname{\textbackslash grelocalbolshiftcleftype}{\{\#1\}}{gregoriotex-spaces.tex}
Equivalent of \verb=\grebolshiftcleftype= but valid only until the next end of a score, and with more options. This can be used inside gabc for corner cases like different alignment on a score taking two pages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the user documentation, I would explicitly mention that this should be used in a <v>texverb</v> in gabc.


\begin{argtable}
\#1 & \texttt{largest} & same as in \verb=\grebolshiftcleftype=\\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, as this is user documentation, I would repeat the descriptions here rather then refer to another macro.

& \texttt{current} & idem\\
& \texttt{f} & force left alignment of notes as if all clef were f clef\\
& \texttt{c} & idem with c clef\\
& \texttt{fb} & idem with flatted f clef\\
& \texttt{cb} & idem with flatted c clef\\
\end{argtable}

\macroname{\textbackslash gresetlastline}{\{\#1\}}{gregoriotex-main.tex}
Macro to determine whether the last line of the score should be justified or not.

Expand Down
7 changes: 6 additions & 1 deletion doc/Command_Index_gregorio.tex
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ \section{Gregorio Controls}
\#7 & integer & \texttt{0} if clef and first note are far enough to use a shorter space, 1 otherwise.\\
\end{argtable}

\macroname{\textbackslash GreSetLinesClef}{\#1\#2\#3\#4\#5\#6\#7}{gregoriotex-main.tex}
\macroname{\textbackslash GreSetLinesClef}{\#1\#2\#3\#4\#5\#6\#7}{gregoriotex-signs.tex}
Macro to define the clef that will appear at the beginning of the lines.

\begin{argtable}
Expand All @@ -816,6 +816,11 @@ \section{Gregorio Controls}
\#7 & integer & Height of flat in secondary clef (\texttt{3} for no flat).\\
\end{argtable}

\macroname{\textbackslash GreSetLargestClef}{\#1\#2\#3\#4\#5\#6}{gregoriotex-signs.tex}
Macro defining the largest clef of the score (for notes left alignment).
The arguments are the same as \verb=\GreSetInitialClef= without the \#7th one, which is always considered
to be \texttt{1}.

\macroname{\textbackslash GreSetNabcAboveLines}{\#1}{gregoriotex-main.tex}
Macro to place argument containing Nabc neumes above the lines and empty
\verb=\gre@currenttextabovelines= when done.
Expand Down
85 changes: 85 additions & 0 deletions src/gregoriotex/gregoriotex-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -4110,6 +4110,90 @@ static int first_note_near_clef(const gregorio_score *const score) {
return 1;
}

static int clef_size(const gregorio_clef_info *const clef)
{
/* this is a heuristic clef size approximation:
* C-clef = 1
* F-clef = 2
* flatted = +2
* unstacked double-clef = +1 (plus the clef size)
*/
/* purposely making line signed */
int line_diff = clef->line - clef->secondary_line;
int size;
if (clef->clef == CLEF_F) {
size = 2;
} else {
size = 1;
}
if (clef->flatted) {
size += 2;
}
if (clef->secondary_line) {
if (line_diff < -1 || line_diff > 1) { /* stacked */
int secondary_size;
if (clef->secondary_clef == CLEF_F) {
secondary_size = 2;
} else {
secondary_size = 1;
}
if (clef->secondary_flatted) {
secondary_size += 2;
}
if (secondary_size > size) {
size = secondary_size;
}
} else { /* unstacked */
size += 1;
if (clef->secondary_clef == CLEF_F) {
size += 2;
} else {
size += 1;
}
if (clef->secondary_flatted) {
size += 2;
}
}
}
return size;
}

static void write_largest_clef(FILE *const f, gregorio_score *const score)
{
const gregorio_syllable *syllable;
const gregorio_element *element;
gregorio_clef_info clef = gregorio_default_clef;
int size;

if (score->first_voice_info) {
clef = score->first_voice_info->initial_clef;
}
size = clef_size(&clef);

for (syllable = score->first_syllable; syllable;
syllable = syllable->next_syllable) {
if (syllable->elements) {
for (element = *syllable->elements; element;
element = element->next) {
if (element->type == GRE_CLEF) {
const int this_size = clef_size(&element->u.misc.clef);
if (this_size > size) {
clef = element->u.misc.clef;
size = this_size;
}
}
}
}
}

fprintf(f, "\\GreSetLargestClef{%c}{%d}{%d}{%c}{%d}{%d}%%\n",
gregorio_clef_to_char(clef.clef), clef.line,
clef_flat_height(clef.clef, clef.line, clef.flatted),
gregorio_clef_to_char(clef.secondary_clef), clef.secondary_line,
clef_flat_height(clef.secondary_clef, clef.secondary_line,
clef.secondary_flatted));
}

void gregoriotex_write_score(FILE *const f, gregorio_score *const score,
const char *const point_and_click_filename)
{
Expand Down Expand Up @@ -4192,6 +4276,7 @@ void gregoriotex_write_score(FILE *const f, gregorio_score *const score,
}
/* LCOV_EXCL_STOP */

write_largest_clef(f, score);
fprintf(f, "\\GreScoreOpening{%%\n"); /* GreScoreOpening#1 */
if (score->first_voice_info) {
gregoriotex_write_voice_info(f, score->first_voice_info);
Expand Down
4 changes: 2 additions & 2 deletions src/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ typedef struct gregorio_extra_info {
} gregorio_extra_info;

typedef struct gregorio_clef_info {
unsigned char line;
unsigned char secondary_line;
signed char line;
signed char secondary_line;
ENUM_BITFIELD(gregorio_clef) clef:1;
bool flatted:1;
ENUM_BITFIELD(gregorio_clef) secondary_clef:1;
Expand Down
1 change: 1 addition & 0 deletions tex/gregoriotex-main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@
\unsetluatexattribute{\gre@attr@glyph@top}%
\unsetluatexattribute{\gre@attr@glyph@bottom}%
\unsetluatexattribute{\gre@attr@dash}%
\xdef\gre@bolshiftcleftypelocal{\gre@bolshiftcleftypeglobal}%
\ifgre@justifylastline%
\parfillskip=\gre@save@parfillskip\relax%
\fi %
Expand Down
50 changes: 33 additions & 17 deletions tex/gregoriotex-signs.tex
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@
]%
}%


%% marcro to define the clef that will appear at the beginning of the lines
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're here, you might as well correct the spelling of macro.

% the first argument is the type : f or c, and the second is the height
% the third argument is whether we must type a space after or not (0 if not, 1 if yes)
% if the fourth argument is 3, it means that we must not put a flat after the key, otherwise it's the height of the flat
%% #1 c or f: type of first clef
%% #2 int: line of first clef
%% #3 int: 0 if not space, 1 if normal space, 2 for short space
%% #4 int: height of the flat of first clef, 3 for no flat
%% #5, #6, #7 = #1, #2, #3 for second clef
\def\GreSetLinesClef#1#2#3#4#5#6#7{%
\gre@localleftbox{%
\gre@skip@temp@four = \gre@dimen@additionalleftspace\relax%
Expand All @@ -166,6 +167,15 @@
\relax%
}%

% defines the largest clef of the score
% arguments are the same as \GreSetLinesClef except that the #3 of
% \GreSetLineClef is removed (always 1)
\def\GreSetLargestClef#1#2#3#4#5#6{%
\gre@boxclef{#1}{#2}{0}{1}{#3}{#4}{#5}{#6}%
\gre@update@clefwidth@largest{\wd\gre@box@temp@width}%
\relax%
}%

\def\gre@save@clef#1#2#3#4#5#6{%
\global\let\gre@clef=#1\relax%
\xdef\gre@clefheight{#2}%
Expand All @@ -183,18 +193,10 @@

\newbox\gre@box@temp@clef%
\newbox\gre@box@temp@cleftwo%
% macro that typesets the clef
% arguments are :
%% #1: the type of the clef : c or f
%% #2: the line of the clef (1 is the lowest)
%% #3: if we must use small clef characters (inside a line) or not 0: if not inside, 1 if inside
%% #4: 0: no space after, 1: normal space after, 2: short space after
%% #5: if 3, it means that we must not put a flat after the clef, otherwise it's the height of the flat
%% #6: the type of the secondary clef : c or f
%% #7: the line of the secondary clef (1 is the lowest)
%% #8: if 3, it means that we must not put a flat after the secondary clef, otherwise it's the height of the flat
\def\gre@typeclef#1#2#3#4#5#6#7#8{%
\setbox\gre@box@temp@width=\hbox{%

% sets \gre@box@temp@width with the clef, the arguments are the same as \gre@typeclef
\def\gre@boxclef#1#2#3#4#5#6#7#8{%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This macro needs to be added to Command_Index_internal.tex.

\global\setbox\gre@box@temp@width=\hbox{%
\ifcase#7%
\gre@typesingleclef{#1}{#2}{#3}{#5}%
\else %
Expand All @@ -214,8 +216,22 @@
\fi %
\fi %
}%
}

% macro that typesets the clef
% arguments are :
%% #1: the type of the clef : c or f
%% #2: the line of the clef (1 is the lowest)
%% #3: if we must use small clef characters (inside a line) or not 0: if not inside, 1 if inside
%% #4: 0: no space after, 1: normal space after, 2: short space after
%% #5: if 3, it means that we must not put a flat after the clef, otherwise it's the height of the flat
%% #6: the type of the secondary clef : c or f
%% #7: the line of the secondary clef (1 is the lowest)
%% #8: if 3, it means that we must not put a flat after the secondary clef, otherwise it's the height of the flat
\def\gre@typeclef#1#2#3#4#5#6#7#8{%
\gre@boxclef{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}%
\ifcase#3%
\global\gre@dimen@clefwidth=\wd\gre@box@temp@width %
\gre@update@clefwidth@current{\wd\gre@box@temp@width}%
\fi %
\copy\gre@box@temp@width %
\ifcase#4 %
Expand Down
84 changes: 80 additions & 4 deletions tex/gregoriotex-spaces.tex
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@
\else%
\global\advance\gre@skip@temp@three by \gre@dimen@bolextra\relax%
\fi%
\gre@debugmsg{bolshift}{ clefwidthcurrent = \the\gre@dimen@clefwidth@current}%
\gre@debugmsg{bolshift}{ clefwidthbol = \the\gre@dimen@clefwidth@bol}%
% we ignore the current-bol adjustment if the clef is the first of the score and there is an initial on one line:
\ifnum\gre@initiallines=1\ifgre@beginningofscore\else %
\global\advance\gre@skip@temp@three by \dimexpr(\gre@dimen@clefwidth@current-\gre@dimen@clefwidth@bol)\relax %
\fi\else %
\global\advance\gre@skip@temp@three by \dimexpr(\gre@dimen@clefwidth@current-\gre@dimen@clefwidth@bol)\relax %
\fi %
\ifdim#1>0pt\relax%
% no additional shift is needed if the notes start before the text
\global\gre@dimen@bolshift = \gre@skip@temp@three\relax%
Expand All @@ -407,7 +415,7 @@
% we don't want to kern more than clefwidth + spaceafterlineclef - minimalspaceatlinebeginning
% violating this would mean that either the notes are closer than (clefwidth + spaceafterlineclef)
% or that the lyrics are closer than minimalspaceatlinebeginning
\gre@skip@temp@one = \glueexpr(\gre@dimen@clefwidth %
\gre@skip@temp@one = \glueexpr(\gre@dimen@clefwidth@current %
+ \gre@space@skip@spaceafterlineclef %
- \gre@space@dimen@minimalspaceatlinebeginning)\relax %
\ifdim\gre@skip@temp@three < \gre@skip@temp@one %
Expand All @@ -420,6 +428,77 @@
\relax %
}

% the width of the current
\newdimen\gre@dimen@clefwidth@current\relax%
Copy link
Contributor

@henryso henryso Jul 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new dimensions and macros need to be added to Command_Index_internal.tex.

% the width of the max clef
\newdimen\gre@dimen@clefwidth@largest\relax%
% the width to compute bolshift with
\newdimen\gre@dimen@clefwidth@bol\relax%

\def\gre@update@clefwidth@current#1{%
\gre@debugmsg{bolshift}{ updating clefwidthcurrent to \the\gre@dimen@clefwidth@current}%
\global\gre@dimen@clefwidth@current=#1\relax %
\ifnum\gre@bolshiftcleftypelocal=2\relax %
\global\gre@dimen@clefwidth@bol=#1\relax %
\fi %
\relax %
}

\def\gre@update@clefwidth@largest#1{%
\global\gre@dimen@clefwidth@largest=#1\relax %
\ifnum\gre@bolshiftcleftypelocal=1\relax %
\global\gre@dimen@clefwidth@bol=#1\relax %
\fi %
}

\def\gre@update@clefwidth@forced#1{%
\global\gre@dimen@clefwidth@bol=#1\relax %
}

% 1 for largest, 2 for current and 3 for forced
\xdef\gre@bolshiftcleftypeglobal{1}
\xdef\gre@bolshiftcleftypelocal{1}

\def\grebolshiftcleftype#1{
\IfStrEqCase{#1}{%
{largest}%
{\xdef\gre@bolshiftcleftypeglobal{1}\xdef\gre@bolshiftcleftypelocal{1}}%
{current}%
{\xdef\gre@bolshiftcleftypeglobal{2}\xdef\gre@bolshiftcleftypelocal{2}}%
}[% all other cases
\gre@error{Unrecognized option "#1" for \protect\grebolshiftcleftype\MessageBreak Possible options are: 'largest' and 'current'.}%
]%
}

\def\grelocalbolshiftcleftype#1{
\IfStrEqCase{#1}{%
{largest}%
{\xdef\gre@bolshiftcleftypelocal{1}%
\global\gre@dimen@clefwidth@bol=\gre@dimen@clefwidth@largest\relax }%
{current}%
{\xdef\gre@bolshiftcleftypelocal{2}%
\global\gre@dimen@clefwidth@bol=\gre@dimen@clefwidth@current\relax }%
{c}%
{\gre@boxclef{c}{3}{0}{1}{3}{c}{0}{3}%
\xdef\gre@bolshiftcleftypelocal{3}%
\gre@update@clefwidth@forced{\wd\gre@box@temp@width}}%
{f}%
{\gre@boxclef{f}{3}{0}{1}{3}{c}{0}{3}%
\xdef\gre@bolshiftcleftypelocal{3}%
\gre@update@clefwidth@forced{\wd\gre@box@temp@width}}%
{cb}%
{\gre@boxclef{c}{3}{0}{1}{8}{c}{0}{3}%
\xdef\gre@bolshiftcleftypelocal{3}%
\gre@update@clefwidth@forced{\wd\gre@box@temp@width}}%
{fb}%
{\gre@boxclef{f}{3}{0}{1}{8}{c}{0}{3}%
\xdef\gre@bolshiftcleftypelocal{3}%
\gre@update@clefwidth@forced{\wd\gre@box@temp@width}}%
}[% all other cases
\gre@error{Unrecognized option "#1" for \protect\grelocalbolshiftcleftype\MessageBreak Possible options are: 'largest', 'current', 'c', 'f', 'cb' and 'fb'.}%
]%
}

% dimen keeping the shift computed with next function
\newdimen\gre@dimen@eolshift
\newcount\gre@count@protrusion@hyphen@eol %
Expand Down Expand Up @@ -1212,9 +1291,6 @@
% begindifference is the difference between the beginning of the text and the beginning of the notes. Warning : it can be negative.
\newdimen\gre@dimen@begindifference\relax%

% the width of the clef
\newdimen\gre@dimen@clefwidth\relax%

% the width of the last glyph
\newdimen\gre@dimen@lastglyphwidth\relax%

Expand Down