Skip to content

Commit

Permalink
New options: --lyrics-min-distance and --lyrcis-font-size
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Dec 29, 2024
1 parent 3737755 commit 95c65aa
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 6 deletions.
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ CLI Usage
[--footer <left> <center> <right>]
[--footer-odd-even <odd-left> <even-left> <odd-center> <even-center> <odd-right> <even-right>]
[--clear-footer]
[--lyrics-font-size STYLE_LYRICS_FONT_SIZE]
[--lyrics-min-distance STYLE_LYRICS_MIN_DISTANCE]
[<path> ...]

The next generation command line tool to manipulate the XML based "*.mscX" and "*.mscZ" files of the notation software MuseScore.
Expand Down Expand Up @@ -889,6 +891,15 @@ CLI Usage
--clear-footer Clear all footer fields by setting all fields to empty
strings. The footer is hidden.

lyrics (style):
Change the lyrics styles.

--lyrics-font-size STYLE_LYRICS_FONT_SIZE
Set the font size of both even and odd lyrics.
--lyrics-min-distance STYLE_LYRICS_MIN_DISTANCE
Set the minimum gap or minimum distance between syllables or
words.

Configuration file
==================

Expand Down
2 changes: 1 addition & 1 deletion autocomplete.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@



_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-C' '--config-file' '-b' '--backup' '-d' '--dry-run' '--catch-errors' '-m' '--mscore' '--save-in-mscore' '-e' '--executable' '-E' '--export' '--compress' '--remove-origin' '-V' '--version' '-v' '--verbose' '-k' '--color' '--no-color' '--diff' '--print-xml' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--title' '--subtitle' '--composer' '--lyricist' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-t' '--target' '--only-filename' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '--list-fields' '--list-functions' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '--clean' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--reset-small-staffs' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--a4' '--din-a4' '--letter' '--margin' '--show-header' '--no-show-header' '--header-first-page' '--no-header-first-page' '--different-odd-even-header' '--no-different-odd-even-header' '--header' '--header-odd-even' '--clear-header' '--show-footer' '--no-show-footer' '--footer-first-page' '--no-footer-first-page' '--different-odd-even-footer' '--no-different-odd-even-footer' '--footer' '--footer-odd-even' '--clear-footer')
_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-C' '--config-file' '-b' '--backup' '-d' '--dry-run' '--catch-errors' '-m' '--mscore' '--save-in-mscore' '-e' '--executable' '-E' '--export' '--compress' '--remove-origin' '-V' '--version' '-v' '--verbose' '-k' '--color' '--no-color' '--diff' '--print-xml' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--title' '--subtitle' '--composer' '--lyricist' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-t' '--target' '--only-filename' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '--list-fields' '--list-functions' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '--clean' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--reset-small-staffs' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--a4' '--din-a4' '--letter' '--margin' '--show-header' '--no-show-header' '--header-first-page' '--no-header-first-page' '--different-odd-even-header' '--no-different-odd-even-header' '--header' '--header-odd-even' '--clear-header' '--show-footer' '--no-show-footer' '--footer-first-page' '--no-footer-first-page' '--different-odd-even-footer' '--no-different-odd-even-footer' '--footer' '--footer-odd-even' '--clear-footer' '--lyrics-font-size' '--lyrics-min-distance')

_shtab_musescore_manager_pos_0_COMPGEN=_shtab_compgen_files
_shtab_musescore_manager__C_COMPGEN=_shtab_compgen_files
Expand Down
2 changes: 1 addition & 1 deletion autocomplete.tcsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


complete musescore-manager \
'c/--/(a4 alphanum ascii backup catch-errors clean clean-meta clear-footer clear-header color composer compress config-file delete-duplicates diff different-odd-even-footer different-odd-even-header din-a4 distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer footer-first-page footer-odd-even glob header header-first-page header-odd-even help json letter list-fields list-files list-fonts list-functions log lyricist margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-color no-different-odd-even-footer no-different-odd-even-header no-footer-first-page no-header-first-page no-show-footer no-show-header no-whitespace only-filename page-size print-completion print-xml remap remap-lyrics remove-origin rename reset-small-staffs s3 s4 save-in-mscore set-field show-footer show-header skip-if-empty staff-space style style-file styles-v3 styles-v4 subtitle synchronize target text-font title title-font vbox vbox-meta verbose version)/' \
'c/--/(a4 alphanum ascii backup catch-errors clean clean-meta clear-footer clear-header color composer compress config-file delete-duplicates diff different-odd-even-footer different-odd-even-header din-a4 distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer footer-first-page footer-odd-even glob header header-first-page header-odd-even help json letter list-fields list-files list-fonts list-functions log lyricist lyrics-font-size lyrics-min-distance margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-color no-different-odd-even-footer no-different-odd-even-header no-footer-first-page no-header-first-page no-show-footer no-show-header no-whitespace only-filename page-size print-completion print-xml remap remap-lyrics remove-origin rename reset-small-staffs s3 s4 save-in-mscore set-field show-footer show-header skip-if-empty staff-space style style-file styles-v3 styles-v4 subtitle synchronize target text-font title title-font vbox vbox-meta verbose version)/' \
'c/-/(- A C D E F K L S V Y a b c d e g h i j k l m n r s t v x y)/' \
'n/--print-completion/(bash zsh tcsh)/' \
'n/-C/f/' \
Expand Down
2 changes: 2 additions & 0 deletions autocomplete.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ _shtab_musescore_manager_options=(
"--footer[Set the footer for all pages.]:style_footer_all:"
"--footer-odd-even[Set different footers for odd and even pages.]:style_footer_odd_even:"
"--clear-footer[Clear all footer fields by setting all fields to empty strings. The footer is hidden.]"
"--lyrics-font-size[Set the font size of both even and odd lyrics.]:style_lyrics_font_size:"
"--lyrics-min-distance[Set the minimum gap or minimum distance between syllables or words.]:style_lyrics_min_distance:"
"(*)::Path to a \"\*.msc\[zx\]\" file or a folder containing \"\*.msc\[zx\]\" files. can be specified several times.:_files"
)

Expand Down
11 changes: 11 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Comande line interface
[--footer <left> <center> <right>]
[--footer-odd-even <odd-left> <even-left> <odd-center> <even-center> <odd-right> <even-right>]
[--clear-footer]
[--lyrics-font-size STYLE_LYRICS_FONT_SIZE]
[--lyrics-min-distance STYLE_LYRICS_MIN_DISTANCE]
[<path> ...]

The next generation command line tool to manipulate the XML based "*.mscX" and "*.mscZ" files of the notation software MuseScore.
Expand Down Expand Up @@ -266,3 +268,12 @@ Comande line interface
--clear-footer Clear all footer fields by setting all fields to empty
strings. The footer is hidden.

lyrics (style):
Change the lyrics styles.

--lyrics-font-size STYLE_LYRICS_FONT_SIZE
Set the font size of both even and odd lyrics.
--lyrics-min-distance STYLE_LYRICS_MIN_DISTANCE
Set the minimum gap or minimum distance between syllables or
words.

44 changes: 40 additions & 4 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ def setup_parser() -> argparse.ArgumentParser:
help="Reset all small staffs to normal size.",
)

# font (style)

font = parser.add_argument_group(
"font (style)", "Change the font faces of a score."
)
Expand Down Expand Up @@ -601,6 +603,8 @@ def setup_parser() -> argparse.ArgumentParser:
help="Set “musicalTextFont”.",
)

# page (style)

page = parser.add_argument_group("page (style)", "Page settings.")

page.add_argument(
Expand Down Expand Up @@ -642,7 +646,7 @@ def setup_parser() -> argparse.ArgumentParser:
help="Set the top, right, bottom and left margins to the same value.",
)

# header
# header (style)

header = parser.add_argument_group("header (style)", "Change the header.")

Expand Down Expand Up @@ -697,7 +701,7 @@ def setup_parser() -> argparse.ArgumentParser:
help="Clear all header fields by setting all fields to empty strings. The header is hidden.",
)

# footer
# footer (style)

footer = parser.add_argument_group("footer (style)", "Change the footer.")

Expand Down Expand Up @@ -752,6 +756,26 @@ def setup_parser() -> argparse.ArgumentParser:
help="Clear all footer fields by setting all fields to empty strings. The footer is hidden.",
)

# lyrics (style)

lyrics_style = parser.add_argument_group(
"lyrics (style)", "Change the lyrics styles."
)

lyrics_style.add_argument(
"--lyrics-font-size",
type=float,
dest="style_lyrics_font_size",
help="Set the font size of both even and odd lyrics.",
)

lyrics_style.add_argument(
"--lyrics-min-distance",
type=float,
dest="style_lyrics_min_distance",
help="Set the minimum gap or minimum distance between syllables or words.",
)

###############################################################################
# last positional parameter
###############################################################################
Expand Down Expand Up @@ -855,6 +879,8 @@ def list_styles(version: int) -> None:
if args.style_file:
score.style.load_style_file(args.style_file.name)

# font (style)

if args.style_text_font is not None:
score.style.set_text_fonts(args.style_text_font)

Expand All @@ -867,6 +893,8 @@ def list_styles(version: int) -> None:
if args.style_musical_text_font is not None:
score.style.musical_text_font = args.style_musical_text_font

# page (style)

if args.style_staff_space is not None:
score.style.staff_space = args.style_staff_space

Expand All @@ -882,7 +910,7 @@ def list_styles(version: int) -> None:
if args.style_margin is not None:
score.style.margin = inch(args.style_margin)

# header
# header (style)

if args.style_show_header is not None:
score.style.show_header = args.style_show_header
Expand All @@ -902,7 +930,7 @@ def list_styles(version: int) -> None:
if args.style_clear_header:
score.style.clear_header()

# footer
# footer (style)

if args.style_show_footer is not None:
score.style.show_footer = args.style_show_footer
Expand All @@ -922,6 +950,14 @@ def list_styles(version: int) -> None:
if args.style_clear_footer:
score.style.clear_footer()

# lyrics (style)

if args.style_lyrics_font_size is not None:
score.style.lyrics_font_size = args.style_lyrics_font_size

if args.style_lyrics_min_distance is not None:
score.style.lyrics_min_distance = args.style_lyrics_min_distance

# small staffs

if args.style_reset_small_staffs:
Expand Down
3 changes: 3 additions & 0 deletions mscxyz/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class DefaultArguments:
style_footer_all: Optional[tuple[str, str, str]] = None
style_footer_odd_even: Optional[tuple[str, str, str, str, str, str]] = None
style_clear_footer: bool = False
# style: lyrics
style_lyrics_font_size: Optional[float] = None
style_lyrics_min_distance: Optional[float] = None

# positional argument
path: list[PathOrStr] = ["."]
Expand Down
32 changes: 32 additions & 0 deletions mscxyz/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,3 +1420,35 @@ def reset_small_staffs(self) -> None:
for element in self.xml.findall(".//StaffType/small"):
if element.text == "1":
self.xml.remove(element)

# lyrics ###################################################################

@property
def lyrics_font_size(self) -> float:
even = self.__get_float("lyricsEvenFontSize")
odd = self.__get_float("lyricsOddFontSize")
if even is None or odd is None or even != odd:
raise Exception(
f"Lyrics even and odd size differs: even: {even} odd: {odd}"
)
return even

@lyrics_font_size.setter
def lyrics_font_size(self, value: float) -> None:
self.set("lyricsEvenFontSize", value)
self.set("lyricsOddFontSize", value)

@property
def lyrics_min_distance(self) -> Optional[float]:
"""
default: 0.25
https://github.com/musescore/MuseScore/blob/e0f941733ac2c0959203a5e99252eb4c58f67606/src/engraving/style/styledef.cpp#L80
"""
return self.__get_float("lyricsMinDistance")

@lyrics_min_distance.setter
def lyrics_min_distance(self, value: float) -> None:
self.set("lyricsMinDistance", value)
10 changes: 10 additions & 0 deletions tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,16 @@ def test_option_clear_footer(self) -> None:
assert s.style.odd_footer_right is None
assert s.style.even_footer_right is None

def test_option_lyrics_font_size(self) -> None:
c = Cli("--lyrics-font-size", "42").execute()
assert c.pre.style.lyrics_font_size == 11
assert c.post.style.lyrics_font_size == 42

def test_option_lyrics_min_distance(self) -> None:
c = Cli("--lyrics-min-distance", "7").execute()
assert c.pre.style.lyrics_min_distance == 0
assert c.post.style.lyrics_min_distance == 7


class TestProperties:
def test_measure_number_offset(self, score: Score) -> None:
Expand Down

0 comments on commit 95c65aa

Please sign in to comment.