File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ def __str__(self) -> str:
79
79
class Beat :
80
80
"""A beat in a composition, containing one or more elements"""
81
81
elements : List [Element ] = field (default_factory = list )
82
+ bracketed : bool = False # Track if this beat was originally in brackets
82
83
83
84
def __str__ (self ) -> str :
84
85
"""Format the beat for display"""
@@ -89,13 +90,11 @@ def __str__(self) -> str:
89
90
if len (self .elements ) == 1 :
90
91
return str (self .elements [0 ])
91
92
92
- # If all elements are just notes (no lyrics), compact them
93
- if all (not e .lyrics and e .note for e in self .elements ):
94
- return "" .join (str (e ) for e in self .elements )
93
+ # Format the elements - use spaces only if bracketed
94
+ formatted = (" " .join if self .bracketed else "" .join )(str (e ) for e in self .elements if str (e ))
95
95
96
- # Multiple elements with at least one lyrics - use brackets
97
- formatted = " " .join (str (e ) for e in self .elements if str (e ))
98
- return f"[{ formatted } ]" if formatted else ""
96
+ # Add brackets only if this was originally bracketed
97
+ return f"[{ formatted } ]" if self .bracketed else formatted
99
98
100
99
@dataclass
101
100
class Section :
Original file line number Diff line number Diff line change @@ -106,9 +106,12 @@ def _elements_to_beats(self, elements: List[Element]) -> List[Beat]:
106
106
in_bracket = False
107
107
last_was_separator = True # Start true to handle first element
108
108
109
- def create_beat (elems ):
109
+ def create_beat (elems , bracketed = False ):
110
110
if elems :
111
- beats .append (Beat (elements = [e for e in elems if e .type == ElementType .NORMAL ]))
111
+ beats .append (Beat (
112
+ elements = [e for e in elems if e .type == ElementType .NORMAL ],
113
+ bracketed = bracketed
114
+ ))
112
115
113
116
for element in elements :
114
117
if element .type == ElementType .SEPARATOR :
@@ -127,7 +130,7 @@ def create_beat(elems):
127
130
in_bracket = False
128
131
# Create beat from bracketed elements
129
132
if bracket_elements :
130
- beats . append ( Beat ( elements = [ e for e in bracket_elements if e . type == ElementType . NORMAL ]) )
133
+ create_beat ( bracket_elements , bracketed = True )
131
134
bracket_elements = []
132
135
last_was_separator = True
133
136
else : # Normal element
You can’t perform that action at this time.
0 commit comments