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

Add option to print only the first flat on each line #1607

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3ae07bb
Adds a new option (alteration-scope: line in header, \setalterationsc…
davidweichiang Jan 22, 2025
f16aa96
Adds a new option (alteration-scope: line in header, \setalterationsc…
davidweichiang Jan 22, 2025
a2a2e0c
correctly compute space before suppressed flats
davidweichiang Jan 24, 2025
5ab1c49
resolve conflicts
davidweichiang Jan 24, 2025
7043fdb
fix bug in previous commit
davidweichiang Jan 24, 2025
949b794
with alteration-scope:line, if a natural follows a flat on the same l…
davidweichiang Jan 24, 2025
3eac5d4
fix bug in last commit and clean up
davidweichiang Jan 25, 2025
e2f293b
suppressed flats shouldn't have ledger lines
davidweichiang Jan 25, 2025
1a0b474
rename some local macros with \gre@ prefix
davidweichiang Jan 25, 2025
a0054fd
Add "soft" flat (X), sharp (#*), and natural (Y), which appear only i…
davidweichiang Jan 26, 2025
d28a7e6
a soft natural shouldn't be printed if it's the first on the line
davidweichiang Jan 26, 2025
348de3c
new cases needed for soft flats with ledger lines
davidweichiang Jan 27, 2025
24b60df
Add \gresetalterationeffect option and some documentation
davidweichiang Jan 27, 2025
a35eb55
fix spacing between bar and suppressed flat
davidweichiang Jan 28, 2025
fc38e7a
change soft sharp to ##
davidweichiang Jan 28, 2025
4005bb8
update docs for soft alterations
davidweichiang Jan 29, 2025
88c8928
change many double quotes
davidweichiang Jan 29, 2025
48dce0b
improve "rerun to fix" warning and some comments
davidweichiang Jan 30, 2025
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
22 changes: 22 additions & 0 deletions tex/gregoriotex-main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@
% attribute for syllable tracking
\newluatexattribute\gre@attr@syllable@id %

% attributes for soft alterations
\newluatexattribute\gre@attr@alteration@height %
\edef\gre@attrid@alteration@height{\the\allocationnumber}%
\newluatexattribute\gre@attr@alteration@type % see \gre@alteration for codes
\edef\gre@attrid@alteration@type{\the\allocationnumber}%
\newluatexattribute\gre@attr@alteration@id %

\newluatexcatcodetable\gre@atletter %
\setluatexcatcodetable\gre@atletter{%
\catcode`\@=11 %
Expand Down Expand Up @@ -1276,6 +1283,7 @@
\gre@resetledgerlineheuristics%
\global\setluatexattribute\gre@attr@glyph@id{0}%
\global\setluatexattribute\gre@attr@syllable@id{0}%
\global\setluatexattribute\gre@attr@alteration@id{0}%
\let\gre@pitch@cleftop\gre@pitch@dummy %
\let\gre@pitch@clefbottom\gre@pitch@dummy %
\xdef\gre@gabcname{#6}%
Expand Down Expand Up @@ -2134,4 +2142,18 @@
% We load the default space configuration.
\greloadspaceconf{default}%

\newif\ifgre@alteration@line
\gre@alteration@linefalse
\def\gresetalterationscope#1{%
\IfStrEqCase{#1}{%
{none}%
{\gre@alteration@linefalse}%
{line}%
{\gre@alteration@linetrue}%
}[% all other cases
\gre@error{Unrecognized option "#1" for \protect\gresetalterationscope\MessageBreak Possible options are: 'none' and 'line'}%
]%
}
\gresetheadercapture{alteration-scope}{gresetalterationscope}{}

\input gregoriotex-nabc.tex
87 changes: 66 additions & 21 deletions tex/gregoriotex-signs.tex
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
\gre@debugmsg{custos}{not blocked}%
\gre@calculate@glyphraisevalue{#1}{0}{}%
%here we need some tricks to draw the line before the custos (for the color)
\edef\gre@saved@attr@alteration@id{\number\gre@attr@alteration@id\relax}%
\setbox\gre@box@temp@width=\hbox{%
% we type a hskip and the we type the custos
\gre@hskip\gre@space@skip@spacebeforeeolcustos\relax %
Expand All @@ -547,6 +548,7 @@
\gre@pickcustos{#1}{2}\relax %
}%
}%
\global\gre@attr@alteration@id=\gre@saved@attr@alteration@id\relax %
\gre@dimen@temp@three=\wd\gre@box@temp@width %
% we make \wd\gre@box@temp@sign contain the width of a custos
\setbox\gre@box@temp@sign=\hbox{%
Expand Down Expand Up @@ -2695,16 +2697,59 @@

% the top level macro:
% #1 is the height
% #2 is the char of the alteration
% #3 is the char of the alteration hole
% #4 is 1 if the alteration is the flat in a clef
% #5 are the signs to typeset before the glyph (typically additional bars, as they must be "behind" the glyph)
% #6 are the signs to typeset after the glyph (almost all signs)
% #7 is the line:char:column for a textedit link
\def\gre@alteration#1#2#3#4#5#6#7{%
\gre@trace{gre@alteration{#1}{#2}{#3}{#4}{#5}{#6}{#7}}%
\setbox\gre@box@temp@width=\hbox{\gre@pointandclick{#2}{#7}}%
\ifnum#4=0\relax %
% #2 is the alteration type: 0 = none, 1 = flat, 2 = natural, 3 = sharp,
% 4 = parenthesized flat, 5 = parenthesized natural,
% 6 = parenthesized flat
% #3 is 1 if the alteration is the flat in a clef
% #4 are the signs to typeset before the glyph (typically additional bars, as they must be "behind" the glyph)
% #5 are the signs to typeset after the glyph (almost all signs)
% #6 is the line:char:column for a textedit link
\def\gre@alteration#1#2#3#4#5#6{%
\gre@trace{gre@alteration{#1}{#2}{#3}{#4}{#5}{#6}}%
\global\advance\gre@attr@alteration@id by 1\relax
\gre@alteration@isvisible{0}%
\ifgre@alteration@isvisible
\gre@alteration@visible{#1}{#2}{#3}{#4}{#5}{#6}%
\else
% ignore #4 (ledger line) and #5 (not used anyway?)
\hbox
attr \gre@attrid@alteration@height=#1\relax
attr \gre@attrid@alteration@type=#2\relax
{}%
\fi
}

% Test whether an alteration should be visible.
% #1 = 0 for current alteration, 1 for next alteration.
% Sets \ifgre@alteration@isvisibletrue or \ifgre@alteration@isvisiblefalse.
\newif\ifgre@alteration@isvisible
\def\gre@alteration@isvisible#1{%
\ifgre@alteration@line
\ifcase\directlua{gregoriotex.is_first_alteration(#1)}\relax
\global\gre@alteration@isvisibletrue
\else
\global\gre@alteration@isvisiblefalse
\fi
\else
\global\gre@alteration@isvisibletrue
\fi
}

\def\gre@alteration@visible#1#2#3#4#5#6{%
\gre@trace{gre@alteration@visible{#1}{#2}{#3}{#4}{#5}{#6}}%
\ifcase#2\relax
\or\def\alterationchar{\gre@fontchar@flat}\def\alterationhole{\gre@fontchar@flathole}% flat
Copy link
Contributor

Choose a reason for hiding this comment

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

We try to avoid unprefixed macros in order to prevent name conflicts with other packages (regardless of how unlikely we think they are). Our prefix system is:

  • \gre@: Internal macros that users should never interact with in their documents
  • \Gre: Macros written to the gtex file by the executable. Advanced users might interact with these to do special things in their document
  • \gre: user facing macros. We expect users to make use of these macros regularly.

With that in mind, \alterationchar and \alterationhole should probably be named \gre@alterationchar and \gre@alterationhole.

\or\def\alterationchar{\gre@fontchar@natural}\def\alterationhole{\gre@fontchar@naturalhole}% natural
\or\def\alterationchar{\gre@fontchar@sharp}\def\alterationhole{\gre@fontchar@sharphole}% sharp
\or\def\alterationchar{\gre@fontchar@flatparen}\def\alterationhole{\gre@fontchar@flatparenhole}% parenthesized flat
\or\def\alterationchar{\gre@fontchar@naturalparen}\def\alterationhole{\gre@fontchar@naturalparenhole}% parenthesized natural
\or\def\alterationchar{\gre@fontchar@sharpparen}\def\alterationhole{\gre@fontchar@sharpparenhole}% parenthesized sharp
\fi
\setbox\gre@box@temp@width=\hbox
attr \gre@attrid@alteration@height=#1\relax
attr \gre@attrid@alteration@type=#2\relax
{\gre@pointandclick{\alterationchar}{#6}}%
\ifnum#3=0\relax %
\gre@newglyphcommon %
\fi %
\ifgre@in@custos\else\relax %
Expand All @@ -2713,16 +2758,16 @@
% the three next lines are a trick to get the additional lines below the glyphs
\gre@skip@temp@one = \gre@dimen@lastglyphwidth\relax%
\kern\gre@skip@temp@one %
#5\relax %
#4\relax %
\kern-\gre@skip@temp@one %
\gre@calculate@glyphraisevalue{#1}{0}{}%
\ifgre@hidealtlines %
\gre@fillhole{#3}{0}%
\gre@fillhole{\alterationhole}{0}%
\fi %
\raise \gre@dimen@glyphraisevalue%
\copy\gre@box@temp@width%
#6\relax %
\ifnum#4=0\relax %
#5\relax %
\ifnum#3=0\relax %
% we try to avoid line breaking after a flat or a natural
\GreNoBreak %
\gre@skip@temp@four = \gre@space@dimen@alterationspace\relax%
Expand All @@ -2748,7 +2793,7 @@

\def\GreFlat#1#2#3#4#5{%
\gre@trace{GreFlat{#1}{#2}{#3}{#4}{#5}}%
\gre@alteration{#1}{\gre@fontchar@flat}{\gre@fontchar@flathole}{#2}{#3}{#4}{#5}%
\gre@alteration{#1}{1}{#2}{#3}{#4}{#5}%
\relax%
\gre@trace@end%
}%
Expand All @@ -2757,7 +2802,7 @@

\def\GreFlatParen#1#2#3#4#5{%
\gre@trace{GreFlatParen{#1}{#2}{#3}{#4}{#5}}%
\gre@alteration{#1}{\gre@fontchar@flatparen}{\gre@fontchar@flatparenhole}{#2}{#3}{#4}{#5}%
\gre@alteration{#1}{4}{#2}{#3}{#4}{#5}%
\relax%
\gre@trace@end%
}%
Expand All @@ -2766,7 +2811,7 @@

\def\GreNatural#1#2#3#4#5{%
\gre@trace{GreNatural{#1}{#2}{#3}{#4}{#5}}%
\gre@alteration{#1}{\gre@fontchar@natural}{\gre@fontchar@naturalhole}{#2}{#3}{#4}{#5}%
\gre@alteration{#1}{2}{#2}{#3}{#4}{#5}%
\relax%
\gre@trace@end%
}%
Expand All @@ -2775,7 +2820,7 @@

\def\GreNaturalParen#1#2#3#4#5{%
\gre@trace{GreNaturalParen{#1}{#2}{#3}{#4}{#5}}%
\gre@alteration{#1}{\gre@fontchar@naturalparen}{\gre@fontchar@naturalparenhole}{#2}{#3}{#4}{#5}%
\gre@alteration{#1}{5}{#2}{#3}{#4}{#5}%
\relax%
\gre@trace@end%
}%
Expand All @@ -2784,16 +2829,16 @@

\def\GreSharp#1#2#3#4#5{%
\gre@trace{GreSharp{#1}{#2}{#3}{#4}{#5}}%
\gre@alteration{#1}{\gre@fontchar@sharp}{\gre@fontchar@sharphole}{#2}{#3}{#4}{#5}%
\gre@alteration{#1}{3}{#2}{#3}{#4}{#5}%
\relax%
\gre@trace@end%
}%

% Same as the one before, but for sharps.

\def\GreSharpParen#1#2#3#4#5{%
\gre@trace{GreSharpParem{#1}{#2}{#3}{#4}{#5}}%
\gre@alteration{#1}{\gre@fontchar@sharpparen}{\gre@fontchar@sharpparenhole}{#2}{#3}{#4}{#5}%
\gre@trace{GreSharpParen{#1}{#2}{#3}{#4}{#5}}%
\gre@alteration{#1}{6}{#2}{#3}{#4}{#5}%
\relax%
\gre@trace@end%
}%
Expand Down
2 changes: 1 addition & 1 deletion tex/gregoriotex-spaces.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@
%% 3 : the middle letters of the next syllable
%% 4 : the end letters of the next syllable
%% 5 : the type of notes alignment
%% 6 : alteration type (see gre@calculate@nextnotesaligncenter)
%% 6 : alteration type (see \gre@alteration)
\def\gre@calculate@nextbegindifference#1#2#3#4#5#6{%
\gre@trace{gre@calculate@nextbegindifference{#1}{#2}{#3}{#4}{#5}{#6}}%
\ifnum\gre@lastoflinecount=1\relax %
Expand Down
33 changes: 24 additions & 9 deletions tex/gregoriotex-syllable.tex
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@

% this is the function that we call when we try to determine the next aligncenter of the notes.
% #1 is the note type
% #2 is the alteration style : 0 = none, 1 = flat, 2 = natural, 3 = sharp,
% 4 = parenthesized flat, 5 = parenthesized natural,
% 6 = parenthesized flat
% #2 is the alteration type (see \gre@alteration)
\def\gre@calculate@nextnotesaligncenter#1#2{%
\gre@trace{gre@calculate@nextnotesaligncenter{#1}{#2}}%
\gre@calculate@simplenotesaligncenter{#1}{1}%
Expand Down Expand Up @@ -856,6 +854,10 @@
\gre@firstglyphtrue%
\gre@dimen@bolextra = 0pt\relax%
\gre@calculate@textaligncenter{\gre@saved@syllable@endsyllablepart}{\gre@firstsyllablepart}{\gre@middlesyllablepart}{0}% we first get the width between the alignment point and the end of the syllable
% Before measuring the notes, save the alteration id. We will
% restore it later, so that the measured notes and the actual notes
% have the same alteration ids, if any.
\edef\gre@saved@attr@alteration@id{\number\gre@attr@alteration@id\relax}%
\gre@syllablenotes{#9}% we put the notes in a box, so that we have the width of it
% now we calculate the begin difference, that is to say \gre@dimen@notesaligncenter - \gre@dimen@textaligncenter
\gre@dimen@begindifference=\dimexpr(\gre@dimen@notesaligncenter - \gre@dimen@textaligncenter)\relax %
Expand Down Expand Up @@ -904,7 +906,20 @@
% by default, gre@attr@dash will be 2
\gre@attr@dash=2\relax %
#5%
\gre@calculate@nextbegindifference{\gre@emit@endsyllablepartfornextsyllable}{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart}}{\gre@evaluatenextsyllable{\gre@nextmiddlesyllablepart}}{\gre@evaluatenextsyllable{\gre@nextendsyllablepart}}#7%
% if the next glyph has an alteration, check if it is suppressed;
% if so, pretend there's no alteration
\def\next@alignment{\gre@arg@oftwo@first#7}%
\def\next@alteration{\gre@arg@oftwo@second#7}%
\ifnum\next@alteration>0\relax
\gre@alteration@isvisible{1}% if the notes contain an alteration, the id was incremented, so this checks the alteration after the notes
\ifgre@alteration@isvisible
\else
\def\next@alteration{0}%
\fi
\fi
% now we can restore the alteration id to typeset the notes for real
\global\gre@attr@alteration@id=\gre@saved@attr@alteration@id\relax %
\gre@calculate@nextbegindifference{\gre@emit@endsyllablepartfornextsyllable}{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart}}{\gre@evaluatenextsyllable{\gre@nextmiddlesyllablepart}}{\gre@evaluatenextsyllable{\gre@nextendsyllablepart}}{\next@alignment}{\next@alteration}%
\gre@unsetfixednexttextformat %
\ifgre@showlyrics%
\setbox\gre@box@syllabletext=\hbox{%
Expand All @@ -922,10 +937,10 @@
\setbox\gre@box@syllabletext=\box\voidb@x%
\fi%
\gre@calculate@enddifference{\wd\gre@box@syllablenotes}{\wd\gre@box@syllabletext}{\gre@dimen@textaligncenter}{\gre@dimen@notesaligncenter}{1}%
% gre@count@temp@one holds 0 if next is a not bar, 1 if it is
% gre@count@temp@one holds 1 if next is a bar, 2 if an alteration, else 0
\gre@count@temp@one=0%
\ifnum\gre@arg@oftwo@second#7=0\relax %
\ifnum\gre@arg@oftwo@first#7>9\relax %
\ifnum\next@alteration=0\relax %
\ifnum\next@alignment>9\relax %
\gre@count@temp@one=1\relax %
\fi %
\else %
Expand Down Expand Up @@ -991,7 +1006,7 @@
\fi%
\fi %
% recomputing end difference and final skip with the final hyphen
\gre@calculate@nextbegindifference{\gre@emit@endsyllablepartfornextsyllable}{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart}}{\gre@evaluatenextsyllable{\gre@nextmiddlesyllablepart}}{\gre@evaluatenextsyllable{\gre@nextendsyllablepart}}#7%
\gre@calculate@nextbegindifference{\gre@emit@endsyllablepartfornextsyllable}{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart}}{\gre@evaluatenextsyllable{\gre@nextmiddlesyllablepart}}{\gre@evaluatenextsyllable{\gre@nextendsyllablepart}}{\next@alignment}{\next@alteration}%
\gre@calculate@enddifference{\wd\gre@box@syllablenotes}{\wd\gre@box@syllabletext}{\gre@dimen@textaligncenter}{\gre@dimen@notesaligncenter}{0}%
\gre@calculate@syllablefinalskip{#4}{\gre@count@temp@one}%
\else %
Expand Down Expand Up @@ -1062,7 +1077,7 @@
\GreNoBreak %
\fi%
% we call end of syllable
\gre@syllable@end#7{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart\gre@nextmiddlesyllablepart\gre@nextendsyllablepart}}{#4}%
\gre@syllable@end{\next@alignment}{\next@alteration}{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart\gre@nextmiddlesyllablepart\gre@nextendsyllablepart}}{#4}%
\gre@push@endsyllable{#6}\relax %
\global\gre@dimen@notesaligncenter=0pt\relax% very important, see flat and natural
\gre@unsetfixedtextformat %
Expand Down
Loading