Skip to content

Commit

Permalink
Better handling of configuration name type
Browse files Browse the repository at this point in the history
A configuration name is actually a symbol, but can be
entered as an implicit string in a \with block.
  • Loading branch information
uliska committed Jul 16, 2020
1 parent 63de78c commit 38025ca
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 54 deletions.
29 changes: 24 additions & 5 deletions internal/properties.ily
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ Trying to define configuration for non-existent propset
Skipping definition."
(os-path-join-dots propset-path)))))

#(define (symbol-list-or-boolean? obj)
(or (symbol-list? obj)
(boolean? obj)))

\definePropertySet OLL.configurations #'()

Expand Down Expand Up @@ -420,6 +417,27 @@ Skipping"
'()))


#(define (configuration-name? obj)
"Predicate for the choice of a configuration name.
It is eventually handled as a symbol, but may also be #f
to indicate 'no configuration'. A string is allowed as a convenience
for entry in a \\with block (the automatic string->symbol-property handler
works only for actual symbol? predicates."
(or (symbol? obj)
(string? obj)
(eq? obj #f)))

#(define (sanitize-configuration-name obj)
"Ensure that a configuration name is either a symbol or #f.
When given in a \\with block the name is typically parsed as a string,
which must converted, while a #f value should be kept as-is."
(cond
((or (symbol? obj) (eq? obj #f)) obj)
((string? obj) (string->symbol obj))
(else
(oll:warn "
Wrong property type: expecting string or symbol, got ~a" obj)
obj)))

#(define (merge-props propset-path props configuration-or-opts)
"Update function properties:
Expand Down Expand Up @@ -447,13 +465,14 @@ Skipping"
(value (cdr prop))
(property
(if (eq? name 'configuration)
(cons boolean-or-symbol? value)
;; ensure that a configuration name is either a symbol or #f
(cons configuration-name? (sanitize-configuration-name value))
(assq-ref propset name)))
)
(if property
(let*
((pred (car property))
(value (string->symbol-property pred value)))
(value (string->symbol-property pred (cdr property))))
(if (pred value)
(cons name value)
(begin
Expand Down
89 changes: 40 additions & 49 deletions usage-examples/presets.ly
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
\version "2.20.0"

% Test file for preset settings
% Test file for configuration filters

\include "oll-core/package.ily"

\definePropertySet test.presets
\definePropertySet test.configurations
#`((color ,color? ,red)
(direction ,ly:dir? ,UP))

test =
#(with-property-set define-music-function (mus)(ly:music?)
`(test presets)
`(test configurations)
(let*
((text (or (property 'preset) 'none))
;; use (use-preset) to determine the "active" state of the function
(color (if (use-preset) (property 'color) black))
((text (or (property 'configuration) 'none))
;; use (use-configuration) to determine the "active" state of the function
(color (if (use-configuration) (property 'color) black))
(direction (property 'direction)))
#{
\once \override Stem.direction = #direction
Expand All @@ -32,7 +32,7 @@ testColor =
#(with-property-set define-music-function (mus)(ly:music?)
`(test colors)
(let*
((use (use-preset))
((use (use-configuration))
(color (if use (property 'color) black)))
#{
\temporary \override NoteHead.color = #color
Expand All @@ -42,96 +42,87 @@ testColor =

% Presets for the text function

\definePreset \with {
\definePropertyConfiguration \with {
color = #green
direction = #DOWN
} test.presets one
} test.configurations one

\definePreset \with {
\definePropertyConfiguration \with {
color = #blue
direction = #UP
} test.presets two
} test.configurations two

\definePreset \with {
\definePropertyConfiguration \with {
color = #magenta
direction = #DOWN
} test.presets three
} test.configurations three

\definePreset \with {
\definePropertyConfiguration \with {
color = #yellow
direction = #UP
} test.presets four
} test.configurations four

\definePreset \with {
\definePropertyConfiguration \with {
color = #darkgreen
direction = #DOWN
} test.presets five
} test.configurations five

% Presets for the inner coloring function

\definePreset \with {
\definePropertyConfiguration \with {
color = #green
} test.colors one

\definePreset \with {
\definePropertyConfiguration \with {
color = #blue
} test.colors two

\definePreset \with {
\definePropertyConfiguration \with {
color = #magenta
} test.colors three

\definePreset \with {
\definePropertyConfiguration \with {
color = #yellow
} test.colors four

\definePreset \with {
\definePropertyConfiguration \with {
color = #darkgreen
} test.colors five


% Test different filter settings
% \setGlobalPresetFilters affects *all* functions with the named preset
% \setGlobalPresetFilters affects *all* functions with the named configuration
% \setPresetFilters affects only the specified property set.


% require-preset
% if ##t only functions with a given preset are used
% require-configuration
% if ##t only functions with a given configuration are used

%\setGlobalPresetFilters require-preset ##t
%\setPresetFilters test.presets require-preset ##t
%\setPresetFilters test.colors require-preset ##t
%\setGlobalPresetFilters require-configuration ##t
%\setPresetFilters test.configurations require-configuration ##t
%\setPresetFilters test.colors require-configuration ##t


% use-only-presets
% only presets given in the lists are used.
% use-only-configurations
% only configurations given in the lists are used.
% global and local filters add up the restrictions, possibly resulting in
% *no* presets being used.
% If require-preset = ##t this amounts to "only use functions
% where this preset has been set".
% *no* configurations being used.
% If require-configuration = ##t this amounts to "only use functions
% where this configuration has been set".

%\setGlobalPresetFilters use-only-presets one.two
%\setPresetFilters test.presets use-only-presets three.four
%\setPresetFilters test.colors use-only-presets two.five


% ignore-presets
% Don't use presets within the list. Functions without preset
% ignore-configurations
% Don't use configurations within the list. Functions without configuration
% are *not* affected by this.
% Global and local lists add up.

%\setGlobalPresetFilters ignore-presets one.two
%\setPresetFilters test.presets ignore-presets three.four
%\setPresetFilters test.colors ignore-presets two.five


content = {
\test \testColor b2
\test \with { preset = one } \testColor \with { preset = one } c'2
\test \with { preset = two } \testColor \with { preset = two } d'
\test \with { preset = three } \testColor \with { preset = three } e'
\test \with { preset = four } \testColor \with { preset = four } f'
\test \with { preset = five } \testColor \with { preset = five } g'
\test \with { configuration = one } \testColor \with { configuration = one } c'2
\test \with { configuration = two } \testColor \with { configuration = two } d'
\test \with { configuration = three } \testColor \with { configuration = three } e'
\test \with { configuration = four } \testColor \with { configuration = four } f'
\test \with { configuration = five } \testColor \with { configuration = five } g'
}

\new Staff \content

0 comments on commit 38025ca

Please sign in to comment.