11from collections import namedtuple
2+ from typing import Any
23
34import abjad
45
56from ..utils import load_config
67
78
9+ def _nullify_list (property : list [Any ], default_value : Any = None ) -> list [Any ]:
10+ r"""
11+ Creates list with the same structure as an input list. Used to take the staff_names property
12+ from config.toml and create a similar structure with default_values for missing properties.
13+
14+ Args:
15+ property (list[Any]): Reference list to be nullified.
16+ default_value (Any): Default value in the output list, defaults to ``None``.
17+
18+ Returns:
19+ list[Any]: Output list with identical structure to input ``property`` but with nullified
20+ values.
21+
22+ Example:
23+ >>> staff_names = [
24+ ... "Flute",
25+ ... ["Piano_Upper", "Piano_Middle", "Piano_Lower"],
26+ ... ["Harp_Upper", "Harp_Lower"],
27+ ... "Cello",
28+ ... ]
29+ >>> _nullify_list(staff_names)
30+ [
31+ None,
32+ [None, None, None],
33+ [None, None],
34+ None,
35+ ]
36+ """
37+ output_list = []
38+ for value in property :
39+ output_list .append (default_value if not isinstance (value , list ) else _nullify_list (value ))
40+ return output_list
41+
42+
843def create_staves () -> tuple [list [abjad .Staff ], list [namedtuple ]]:
944 r"""
1045 Creates list of staves and list of instrument properties (staves, instrument names, clefs,
@@ -25,7 +60,10 @@ def create_staves() -> tuple[list[abjad.Staff], list[namedtuple]]:
2560 CONTEXTS = config_dict ["instrumentation" ]["contexts" ]
2661 INSTRUMENT_NAMES = config_dict ["instrumentation" ]["instrument_names" ]
2762 SHORT_INSTRUMENT_NAMES = config_dict ["instrumentation" ]["short_instrument_names" ]
28- INITIAL_CLEFS = config_dict ["instrumentation" ]["initial_clefs" ]
63+ try :
64+ INITIAL_CLEFS = config_dict ["instrumentation" ]["initial_clefs" ]
65+ except KeyError :
66+ INITIAL_CLEFS = _nullify_list (STAFF_NAMES , None )
2967
3068 # Defining named tuple
3169 InstrumentProperties = namedtuple (
0 commit comments