score-reader 0.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- score_reader-0.1.5.dist-info/METADATA +154 -0
- score_reader-0.1.5.dist-info/RECORD +64 -0
- score_reader-0.1.5.dist-info/WHEEL +5 -0
- score_reader-0.1.5.dist-info/entry_points.txt +2 -0
- score_reader-0.1.5.dist-info/licenses/LICENSE +202 -0
- score_reader-0.1.5.dist-info/licenses/NOTICE +13 -0
- score_reader-0.1.5.dist-info/top_level.txt +1 -0
- sheet_interpreter/__init__.py +9 -0
- sheet_interpreter/arpeggio_notation.py +111 -0
- sheet_interpreter/articulation_export.py +49 -0
- sheet_interpreter/audio.py +260 -0
- sheet_interpreter/beam_source.py +163 -0
- sheet_interpreter/boundary_ties.py +82 -0
- sheet_interpreter/bow_export.py +35 -0
- sheet_interpreter/clef_export.py +76 -0
- sheet_interpreter/cli.py +142 -0
- sheet_interpreter/clock_context.py +261 -0
- sheet_interpreter/continuous_slide_curve.py +89 -0
- sheet_interpreter/cue_caption.py +54 -0
- sheet_interpreter/data/LICENSE +202 -0
- sheet_interpreter/data/NOTICE +13 -0
- sheet_interpreter/data/music_sheets_v4_float16.tflite +0 -0
- sheet_interpreter/dynamic_export.py +76 -0
- sheet_interpreter/fall_off_notation.py +128 -0
- sheet_interpreter/grace_export.py +83 -0
- sheet_interpreter/guide_writer.py +287 -0
- sheet_interpreter/guitar_effect.py +32 -0
- sheet_interpreter/guitar_export.py +36 -0
- sheet_interpreter/hairpin_export.py +102 -0
- sheet_interpreter/interpreter.jar +0 -0
- sheet_interpreter/midi.py +340 -0
- sheet_interpreter/multi_rest_wire.py +62 -0
- sheet_interpreter/musicxml.py +937 -0
- sheet_interpreter/natural_harmonic_notation.py +125 -0
- sheet_interpreter/navigation.py +186 -0
- sheet_interpreter/neutral_rest_caption.py +58 -0
- sheet_interpreter/ocr.py +103 -0
- sheet_interpreter/octave_shift_export.py +94 -0
- sheet_interpreter/ornament_export.py +53 -0
- sheet_interpreter/page_processing_budget.py +17 -0
- sheet_interpreter/parenthesized_note_group.py +198 -0
- sheet_interpreter/pdf_annotations.py +52 -0
- sheet_interpreter/performance.py +478 -0
- sheet_interpreter/printed_tempo_spans.py +124 -0
- sheet_interpreter/reader.py +204 -0
- sheet_interpreter/rest_kinds.py +33 -0
- sheet_interpreter/runtime.py +17 -0
- sheet_interpreter/semantic_wire.py +321 -0
- sheet_interpreter/slide_numbering.py +43 -0
- sheet_interpreter/slide_performance.py +204 -0
- sheet_interpreter/slur_export.py +124 -0
- sheet_interpreter/slur_wire.py +159 -0
- sheet_interpreter/source_tempo_clock.py +93 -0
- sheet_interpreter/spelling_export.py +48 -0
- sheet_interpreter/straight_slide.py +76 -0
- sheet_interpreter/sudden_dynamic.py +47 -0
- sheet_interpreter/technique_export.py +62 -0
- sheet_interpreter/tie_owners.py +43 -0
- sheet_interpreter/tremolo_export.py +93 -0
- sheet_interpreter/tremolo_performance.py +45 -0
- sheet_interpreter/tremolo_wire.py +138 -0
- sheet_interpreter/typed_events.py +57 -0
- sheet_interpreter/typed_performance.py +44 -0
- sheet_interpreter/visual_size.py +18 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Music Sheets Interpreter
|
|
2
|
+
Copyright 2026 Luckolite
|
|
3
|
+
|
|
4
|
+
The original source code, documentation, generated examples and model weights
|
|
5
|
+
in this repository are offered under the Apache License, Version 2.0.
|
|
6
|
+
|
|
7
|
+
Training font files and the bundled Bravura/Leland recognition glyph rasters,
|
|
8
|
+
with their accompanying notices, retain the SIL Open Font License 1.1.
|
|
9
|
+
External runtime and training dependencies retain
|
|
10
|
+
their own licenses; see THIRD_PARTY_NOTICES.md.
|
|
11
|
+
|
|
12
|
+
This project is not affiliated with or endorsed by HOMR, Andromr, oemer,
|
|
13
|
+
Verovio, or the Apache Software Foundation.
|
|
Binary file
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Copyright 2026 Luckolite
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Absolute dynamics at explicitly owned, exact source note columns."""
|
|
4
|
+
import math
|
|
5
|
+
from .technique_export import position
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def plan(page, rendered, bars, page_identity):
|
|
9
|
+
notes = page.get('score', {}).get('notes', [])
|
|
10
|
+
events = page.get('events', [])
|
|
11
|
+
if len(notes) != len(events) or len(rendered) != len(notes):
|
|
12
|
+
return []
|
|
13
|
+
result, seen = [], set()
|
|
14
|
+
for index, change in enumerate(page.get('score', {}).get('dynamicChanges', [])):
|
|
15
|
+
m, staff, count = (change.get(k) for k in ('measureIndex', 'staffIndex', 'staffCount'))
|
|
16
|
+
p, db = position(change.get('positionInMeasure')), change.get('decibels')
|
|
17
|
+
shared = change.get('sharedStaffs', False)
|
|
18
|
+
timing = change.get('sharedTiming', shared)
|
|
19
|
+
if (type(change.get('direction')) is not int or change['direction'] != 0
|
|
20
|
+
or type(m) is not int or not 0 <= m < len(bars)
|
|
21
|
+
or type(staff) is not int or type(count) is not int or not 0 <= staff < count <= 8
|
|
22
|
+
or p is None or type(db) not in (int, float) or not math.isfinite(db) or not -24 <= db <= 9
|
|
23
|
+
or type(shared) is not bool or type(timing) is not bool):
|
|
24
|
+
continue
|
|
25
|
+
timing |= shared
|
|
26
|
+
owners, malformed = [], False
|
|
27
|
+
for i, note in enumerate(notes):
|
|
28
|
+
if note.get('measureIndex') != m:
|
|
29
|
+
continue
|
|
30
|
+
if timing:
|
|
31
|
+
if note.get('staffCount') != count:
|
|
32
|
+
continue
|
|
33
|
+
elif note.get('staffIndex') != staff:
|
|
34
|
+
continue
|
|
35
|
+
if position(note.get('positionInMeasure')) != p:
|
|
36
|
+
continue
|
|
37
|
+
if (any(type(note.get(k)) is not int for k in ('measureIndex', 'staffIndex', 'staffCount'))
|
|
38
|
+
or note['staffCount'] != count or not 0 <= note['staffIndex'] < count):
|
|
39
|
+
malformed = True
|
|
40
|
+
break
|
|
41
|
+
owners.append(i)
|
|
42
|
+
if malformed or not owners:
|
|
43
|
+
continue
|
|
44
|
+
start, valid = None, True
|
|
45
|
+
for i in owners:
|
|
46
|
+
source, event, row = notes[i], events[i], rendered[i]
|
|
47
|
+
at = row['start']
|
|
48
|
+
if (type(event.get('sourceNoteIndex')) is not int or event['sourceNoteIndex'] != i
|
|
49
|
+
or event.get('durationFallback') is not False
|
|
50
|
+
or any(type(event.get(k)) is not int or event[k] != source.get(k)
|
|
51
|
+
for k in ('measureIndex', 'staffIndex', 'staffCount'))
|
|
52
|
+
or type(at) is not int or not bars[m]['start'] <= at <= bars[m]['start'] + bars[m]['length']
|
|
53
|
+
or at == bars[m]['start'] + bars[m]['length'] and not row.get('grace', False)
|
|
54
|
+
or start is not None and start != at):
|
|
55
|
+
valid = False
|
|
56
|
+
break
|
|
57
|
+
start = at
|
|
58
|
+
if not valid:
|
|
59
|
+
continue
|
|
60
|
+
name = ('ppp' if db <= -18 else 'pp' if db <= -12 else 'p' if db <= -8 else
|
|
61
|
+
'mp' if db <= -4 else 'mf' if db <= 0 else 'f' if db <= 4 else 'ff' if db <= 7 else 'fff')
|
|
62
|
+
targets = sorted({n['staffIndex'] for n in notes
|
|
63
|
+
if type(n.get('staffIndex')) is int and 0 <= n['staffIndex'] < count
|
|
64
|
+
and type(n.get('staffCount')) is int and n['staffCount'] == count
|
|
65
|
+
and n.get('measureIndex') == m}) if shared else [staff]
|
|
66
|
+
for target in targets:
|
|
67
|
+
key = (m, target, count, name, start)
|
|
68
|
+
if key in seen:
|
|
69
|
+
continue
|
|
70
|
+
seen.add(key)
|
|
71
|
+
result.append(dict(identity=f'{page_identity}/absolute-dynamic:{index}:{target}',
|
|
72
|
+
kind='ABSOLUTE_DYNAMIC', scope='PART', staffIndex=target, staffCount=count,
|
|
73
|
+
startTick=start, endTick=None, ownerIds=[rendered[i]['sourceIdentity'] for i in owners if notes[i]['staffIndex']==target], evidence=[],
|
|
74
|
+
_dynamicGroup=f'{page_identity}/absolute-dynamic:{index}',
|
|
75
|
+
_absoluteDynamic=name, _absoluteDynamicBarStart=bars[m]['start']))
|
|
76
|
+
return result
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Copyright 2026 Luckolite
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Exact source-note ownership for printed fall-off notation."""
|
|
4
|
+
import math
|
|
5
|
+
import struct
|
|
6
|
+
|
|
7
|
+
PREFIX = 'fall-off-note-v1:'
|
|
8
|
+
SOURCE = 'printed-fall-off'
|
|
9
|
+
CURVED = 'falloff-v1:curved'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def target(note):
|
|
13
|
+
"""Canonical raw note identity; never a nearest note or chord-wide attachment."""
|
|
14
|
+
try:
|
|
15
|
+
m, staff, count, step = [note[k] for k in
|
|
16
|
+
('measureIndex', 'staffIndex', 'staffCount', 'staffStep')]
|
|
17
|
+
x, y = note['positionInMeasure'], note['pageY']
|
|
18
|
+
if (any(type(v) is not int for v in (m, staff, count, step)) or m < 0
|
|
19
|
+
or not 0 <= staff < count or note.get('kind', 'PITCHED') != 'PITCHED'
|
|
20
|
+
or any(type(v) not in (int, float) or not math.isfinite(v) or not 0 <= v <= 1
|
|
21
|
+
for v in (x, y))):
|
|
22
|
+
return None
|
|
23
|
+
bits = lambda v: struct.pack('>f', v).hex()
|
|
24
|
+
return f'{PREFIX}{m}:{staff}:{count}:{bits(x)}:{step}:{bits(y)}'
|
|
25
|
+
except (KeyError, TypeError, ValueError, OverflowError, struct.error):
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def retained(page):
|
|
30
|
+
notes, events = page.get('score', {}).get('notes', []), page.get('events', [])
|
|
31
|
+
if len(notes) != len(events):
|
|
32
|
+
return frozenset()
|
|
33
|
+
owners = {}
|
|
34
|
+
for i, note in enumerate(notes):
|
|
35
|
+
key = target(note)
|
|
36
|
+
if key is not None:
|
|
37
|
+
owners[key] = i if key not in owners else None
|
|
38
|
+
result = set()
|
|
39
|
+
marks = page.get('score', {}).get('expressiveEvents', [])
|
|
40
|
+
owner_counts = {}
|
|
41
|
+
for mark in marks:
|
|
42
|
+
i = owner_index(mark, notes)
|
|
43
|
+
if i is not None:
|
|
44
|
+
owner_counts[i] = owner_counts.get(i, 0) + 1
|
|
45
|
+
for mark in marks:
|
|
46
|
+
if (mark.get('qualifierText') != CURVED or mark.get('strength') != 'UNSPECIFIED'
|
|
47
|
+
or mark.get('kind') != 'FALL_OFF' or mark.get('scope') not in ('NOTE', 'UNRESOLVED')
|
|
48
|
+
or mark.get('end') is not None or not isinstance(mark.get('targetEventId'), str)):
|
|
49
|
+
continue
|
|
50
|
+
i = owners.get(mark['targetEventId'])
|
|
51
|
+
if i is None or owner_counts.get(i) != 1:
|
|
52
|
+
continue
|
|
53
|
+
note, event, anchor = notes[i], events[i], mark.get('start')
|
|
54
|
+
if (any(mark.get(k) != note[k] for k in ('staffIndex', 'staffCount'))
|
|
55
|
+
or event.get('kind', 'PITCHED') != 'PITCHED'
|
|
56
|
+
or type(event.get('sourceNoteIndex')) is not int or event['sourceNoteIndex'] != i
|
|
57
|
+
or any(event.get(k) != note[k] for k in ('measureIndex', 'staffIndex', 'staffCount'))
|
|
58
|
+
or event.get('durationFallback', False)
|
|
59
|
+
or (mark.get('scope') == 'NOTE' and (not isinstance(anchor, dict)
|
|
60
|
+
or type(anchor.get('measureIndex')) is not int
|
|
61
|
+
or anchor['measureIndex'] != note['measureIndex']))
|
|
62
|
+
or (mark.get('scope') == 'UNRESOLVED' and anchor is not None)
|
|
63
|
+
or not any(e.get('sourceId') == SOURCE
|
|
64
|
+
and all(e.get(k) == note[k] for k in ('staffIndex', 'staffCount'))
|
|
65
|
+
for e in mark.get('evidence', []))):
|
|
66
|
+
continue
|
|
67
|
+
beats, m = page.get('measureBeats', []), note['measureIndex']
|
|
68
|
+
start, duration = event.get('startBeat'), event.get('durationBeats')
|
|
69
|
+
if (m >= len(beats) or any(type(v) not in (int, float) or not math.isfinite(v) or v <= 0 for v in beats[:m+1])
|
|
70
|
+
or any(type(v) not in (int, float) or not math.isfinite(v) for v in (start, duration))
|
|
71
|
+
or duration <= 0):
|
|
72
|
+
continue
|
|
73
|
+
begin = sum(beats[:m])
|
|
74
|
+
if not begin <= start < begin + beats[m]:
|
|
75
|
+
continue
|
|
76
|
+
if mark.get('scope') == 'UNRESOLVED':
|
|
77
|
+
result.add(i)
|
|
78
|
+
continue
|
|
79
|
+
offset = anchor['quarterBeatOffset']
|
|
80
|
+
if not 0 <= offset < beats[m]:
|
|
81
|
+
continue
|
|
82
|
+
# The mark must name the exact final-attack tick used by the Java resolver.
|
|
83
|
+
if round(start * 10080) != round((begin + offset) * 10080):
|
|
84
|
+
continue
|
|
85
|
+
result.add(i)
|
|
86
|
+
return frozenset(result)
|
|
87
|
+
|
|
88
|
+
def owner_index(mark, notes):
|
|
89
|
+
"""Mirror Java physical-owner validation before final-clock validation."""
|
|
90
|
+
if (mark.get('qualifierText') != CURVED or mark.get('strength') != 'UNSPECIFIED'
|
|
91
|
+
or mark.get('kind') != 'FALL_OFF'
|
|
92
|
+
or mark.get('scope') not in ('NOTE', 'UNRESOLVED')
|
|
93
|
+
or mark.get('end') is not None
|
|
94
|
+
or not isinstance(mark.get('targetEventId'), str)):
|
|
95
|
+
return None
|
|
96
|
+
anchor = mark.get('start')
|
|
97
|
+
if mark['scope'] == 'NOTE':
|
|
98
|
+
if (not isinstance(anchor, dict) or type(anchor.get('measureIndex')) is not int
|
|
99
|
+
or type(anchor.get('quarterBeatOffset')) not in (int, float)):
|
|
100
|
+
return None
|
|
101
|
+
try:
|
|
102
|
+
if not math.isfinite(anchor['quarterBeatOffset']):
|
|
103
|
+
return None
|
|
104
|
+
except (OverflowError, TypeError, ValueError):
|
|
105
|
+
return None
|
|
106
|
+
elif anchor is not None:
|
|
107
|
+
return None
|
|
108
|
+
evidence = mark.get('evidence', [])
|
|
109
|
+
if not isinstance(evidence, list) or not any(
|
|
110
|
+
isinstance(e, dict) and e.get('sourceId') == SOURCE
|
|
111
|
+
and e.get('staffIndex') == mark.get('staffIndex')
|
|
112
|
+
and e.get('staffCount') == mark.get('staffCount') for e in evidence):
|
|
113
|
+
return None
|
|
114
|
+
matches = [i for i, note in enumerate(notes) if target(note) == mark['targetEventId']]
|
|
115
|
+
if len(matches) != 1:
|
|
116
|
+
return None
|
|
117
|
+
i = matches[0]
|
|
118
|
+
note = notes[i]
|
|
119
|
+
if (note.get('staffIndex') != mark.get('staffIndex')
|
|
120
|
+
or note.get('staffCount') != mark.get('staffCount')
|
|
121
|
+
or (anchor is not None and anchor['measureIndex'] != note.get('measureIndex'))):
|
|
122
|
+
return None
|
|
123
|
+
return i
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Copyright 2026 Luckolite
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Validate retained written grace ownership separately from playback budgets."""
|
|
4
|
+
from collections import defaultdict
|
|
5
|
+
import math
|
|
6
|
+
from .typed_events import event_kind
|
|
7
|
+
from .articulation_export import source_flags
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def plan(page, ticks):
|
|
11
|
+
notes, events = page.get('score', {}).get('notes', []), page['events']
|
|
12
|
+
if not any(type(n.get('articulations', 0)) is int and n.get('articulations', 0) & (1 << 15) for n in notes):
|
|
13
|
+
return {}
|
|
14
|
+
if len(notes) != len(events):
|
|
15
|
+
raise ValueError('Grace export needs one event per retained source head')
|
|
16
|
+
for i in range(len(events)):
|
|
17
|
+
source_flags(page, i) # Validate signed flags before interpreting the grace bit.
|
|
18
|
+
result, groups, budgets = {}, defaultdict(list), defaultdict(float)
|
|
19
|
+
beat_starts = [0.0]
|
|
20
|
+
for beats in page['measureBeats']:
|
|
21
|
+
beat_starts.append(beat_starts[-1]+beats)
|
|
22
|
+
page_end = ticks(beat_starts[-1])
|
|
23
|
+
for i, (note, event) in enumerate(zip(notes, events)):
|
|
24
|
+
fields = ('measureIndex', 'staffIndex', 'staffCount')
|
|
25
|
+
if (type(event.get('sourceNoteIndex', i)) is not int or event.get('sourceNoteIndex', i) != i
|
|
26
|
+
or any(k not in note or k not in event or note[k] != event[k] for k in fields)):
|
|
27
|
+
raise ValueError('Grace written placement source identity disagrees')
|
|
28
|
+
p = event.get('writtenPlacement')
|
|
29
|
+
if not isinstance(p, dict):
|
|
30
|
+
raise ValueError('Grace export needs retained written placement metadata')
|
|
31
|
+
for key in ('onsetBeats', 'durationBeats', 'stealPercent'):
|
|
32
|
+
if type(p.get(key)) not in (int, float) or not math.isfinite(p[key]) or p[key] < 0:
|
|
33
|
+
raise ValueError('Invalid grace written clock')
|
|
34
|
+
for key in ('principalIndex', 'ordinal'):
|
|
35
|
+
if type(p.get(key)) is not int:
|
|
36
|
+
raise ValueError('Invalid grace written owner')
|
|
37
|
+
if type(p.get('afterGrace')) is not bool or p['durationBeats'] <= 0:
|
|
38
|
+
raise ValueError('Invalid grace written placement')
|
|
39
|
+
m = event['measureIndex']
|
|
40
|
+
if type(m) is not int or not 0 <= m < len(page['measureBeats']):
|
|
41
|
+
raise ValueError('Grace written measure outside page')
|
|
42
|
+
grace = p['principalIndex'] >= 0
|
|
43
|
+
if grace != bool(note.get('articulations', 0) & (1 << 15)):
|
|
44
|
+
raise ValueError('Grace written placement contradicts source mark')
|
|
45
|
+
if grace and event_kind(event) != 'PITCHED':
|
|
46
|
+
raise ValueError('Unpitched grace needs explicit instrument semantics')
|
|
47
|
+
onset, duration = ticks(p['onsetBeats']), ticks(p['durationBeats'])
|
|
48
|
+
absolute = ticks(beat_starts[m]) + onset
|
|
49
|
+
if ((not grace or not p['afterGrace']) and onset > ticks(page['measureBeats'][m])
|
|
50
|
+
or absolute > page_end or not grace and absolute+duration > page_end+2):
|
|
51
|
+
raise ValueError('Grace written clock outside measure')
|
|
52
|
+
if not grace and (p['principalIndex'] != -1 or p['ordinal'] != -1 or p['afterGrace'] or p['stealPercent'] != 0):
|
|
53
|
+
raise ValueError('Metrical note has contradictory grace ownership')
|
|
54
|
+
if grace and (not 0 <= p['principalIndex'] < len(events) or p['principalIndex'] == i
|
|
55
|
+
or p['ordinal'] < 0 or not 0 < p['stealPercent'] <= 100):
|
|
56
|
+
raise ValueError('Invalid grace written principal')
|
|
57
|
+
result[i] = dict(start=absolute,
|
|
58
|
+
duration=duration, grace=grace, principal=p['principalIndex'],
|
|
59
|
+
ordinal=p['ordinal'], after=p['afterGrace'], steal=p['stealPercent'])
|
|
60
|
+
if grace:
|
|
61
|
+
groups[p['principalIndex'], p['afterGrace']].append(i)
|
|
62
|
+
budgets[p['principalIndex']] += p['stealPercent']
|
|
63
|
+
for (principal, after), members in groups.items():
|
|
64
|
+
owner = result[principal]
|
|
65
|
+
if owner['grace'] or event_kind(events[principal]) != 'PITCHED':
|
|
66
|
+
raise ValueError('Grace principal must be a metrical pitched head')
|
|
67
|
+
expected = owner['start'] + (owner['duration'] if after else 0)
|
|
68
|
+
for i in members:
|
|
69
|
+
if (any(events[i][k] != events[principal][k] for k in ('measureIndex', 'staffIndex', 'staffCount'))
|
|
70
|
+
or result[i]['start'] != expected):
|
|
71
|
+
raise ValueError('Grace principal context or written anchor disagrees')
|
|
72
|
+
if sorted(result[i]['ordinal'] for i in members) != list(range(len(members))):
|
|
73
|
+
raise ValueError('Grace group ordinals are incomplete or ambiguous')
|
|
74
|
+
for budget in budgets.values():
|
|
75
|
+
if budget > 100+1e-7:
|
|
76
|
+
raise ValueError('Grace group exceeds principal playback budget')
|
|
77
|
+
return result
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def order(event):
|
|
81
|
+
if not event.get('grace', False):
|
|
82
|
+
return event['start'], 0
|
|
83
|
+
return event['start'], event['graceOrdinal'] - (2000000 if event['afterGrace'] else 1000000)
|