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,198 @@
|
|
|
1
|
+
# Copyright 2026 Luckolite
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""One print-only pair with exact, ordered physical note members."""
|
|
4
|
+
import hashlib
|
|
5
|
+
import math
|
|
6
|
+
import re
|
|
7
|
+
import struct
|
|
8
|
+
import uuid
|
|
9
|
+
from collections import Counter
|
|
10
|
+
from typing import NamedTuple
|
|
11
|
+
|
|
12
|
+
SOURCE = 'printed-parenthesized-note-group'
|
|
13
|
+
TARGET = 'parenthesis-group-v1:'
|
|
14
|
+
PAIR = 'parenthesis-pair-v1:'
|
|
15
|
+
GRACE = 1 << 15
|
|
16
|
+
f32 = lambda v: struct.unpack('>f', struct.pack('>f', v))[0]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def bits(value):
|
|
20
|
+
return struct.pack('>f', value).hex()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def unbits(value):
|
|
24
|
+
if not isinstance(value, str) or re.fullmatch('[0-9a-f]{8}', value) is None:
|
|
25
|
+
raise ValueError('Noncanonical float bits')
|
|
26
|
+
return struct.unpack('>f', bytes.fromhex(value))[0]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def integer(value):
|
|
30
|
+
if type(value) is not int or not -2147483648 <= value <= 2147483647:
|
|
31
|
+
raise ValueError('Invalid member integer')
|
|
32
|
+
return value
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Member(NamedTuple):
|
|
36
|
+
measure: int
|
|
37
|
+
staff: int
|
|
38
|
+
count: int
|
|
39
|
+
x_bits: str
|
|
40
|
+
step: int
|
|
41
|
+
y_bits: str
|
|
42
|
+
|
|
43
|
+
def token(self):
|
|
44
|
+
return f'{self.measure},{self.staff},{self.count},{self.x_bits},{self.step},{self.y_bits}'
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class Pair(NamedTuple):
|
|
48
|
+
members: tuple
|
|
49
|
+
geometry: tuple
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def target(self):
|
|
53
|
+
return TARGET + self.members[0].token()
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def qualifier(self):
|
|
57
|
+
return PAIR + ':'.join(map(bits, self.geometry)) + ':' + '/'.join(m.token() for m in self.members)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def member(token):
|
|
61
|
+
p = token.split(',')
|
|
62
|
+
if len(p) != 6:
|
|
63
|
+
raise ValueError('Invalid member')
|
|
64
|
+
m, staff, count, step = [integer(int(p[i])) for i in (0, 1, 2, 4)]
|
|
65
|
+
x, y = unbits(p[3]), unbits(p[5])
|
|
66
|
+
if m < 0 or not 0 <= staff < count or not all(math.isfinite(v) and 0 <= v <= 1 for v in (x, y)):
|
|
67
|
+
raise ValueError('Invalid physical member')
|
|
68
|
+
result = Member(m, staff, count, p[3], step, p[5])
|
|
69
|
+
if result.token() != token:
|
|
70
|
+
raise ValueError('Noncanonical member')
|
|
71
|
+
return result
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def member_of(note):
|
|
75
|
+
try:
|
|
76
|
+
if note.get('kind', 'PITCHED') != 'PITCHED' or integer(note.get('articulations', 0)) & GRACE:
|
|
77
|
+
return None
|
|
78
|
+
m, staff, count, step = [integer(note[k]) for k in ('measureIndex', 'staffIndex', 'staffCount', 'staffStep')]
|
|
79
|
+
x, y = note['positionInMeasure'], note['pageY']
|
|
80
|
+
if any(type(v) not in (int, float) or not math.isfinite(v) for v in (x, y)):
|
|
81
|
+
return None
|
|
82
|
+
return member(f'{m},{staff},{count},{bits(x)},{step},{bits(y)}')
|
|
83
|
+
except (KeyError, TypeError, ValueError, OverflowError, struct.error):
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def decode(qualifier):
|
|
88
|
+
try:
|
|
89
|
+
if not isinstance(qualifier, str) or len(qualifier) > 4096 or not qualifier.startswith(PAIR):
|
|
90
|
+
return None
|
|
91
|
+
p = qualifier[len(PAIR):].split(':')
|
|
92
|
+
if len(p) != 7:
|
|
93
|
+
return None
|
|
94
|
+
geometry = tuple(unbits(v) for v in p[:6])
|
|
95
|
+
lx, ly, rx, ry, lh, rh = geometry
|
|
96
|
+
if (not all(math.isfinite(v) for v in geometry) or not -2 <= lx <= -f32(.45)
|
|
97
|
+
or not f32(.45) <= rx <= 2 or abs(ly) > f32(.65) or abs(ry) > f32(.65)
|
|
98
|
+
or not f32(1.1) <= lh <= f32(2.6) or not f32(1.1) <= rh <= f32(2.6)):
|
|
99
|
+
return None
|
|
100
|
+
tokens = p[6].split('/')
|
|
101
|
+
if not 2 <= len(tokens) <= 64:
|
|
102
|
+
return None
|
|
103
|
+
members = tuple(member(v) for v in tokens)
|
|
104
|
+
first, previous = members[0], -1
|
|
105
|
+
for m in members:
|
|
106
|
+
x = unbits(m.x_bits)
|
|
107
|
+
if m[:3] != first[:3] or x <= previous:
|
|
108
|
+
return None
|
|
109
|
+
previous = x
|
|
110
|
+
result = Pair(members, geometry)
|
|
111
|
+
return result if result.qualifier == qualifier else None
|
|
112
|
+
except (ValueError, TypeError, OverflowError, struct.error):
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def owners(mark, notes):
|
|
117
|
+
if (mark.get('kind') != 'PARENTHESIZED_NOTE_GROUP' or mark.get('scope') not in ('NOTE', 'UNRESOLVED')
|
|
118
|
+
or mark.get('end') is not None or mark.get('strength') != 'UNSPECIFIED'):
|
|
119
|
+
return None
|
|
120
|
+
pair = decode(mark.get('qualifierText'))
|
|
121
|
+
if pair is None or mark.get('targetEventId') != pair.target:
|
|
122
|
+
return None
|
|
123
|
+
first = pair.members[0]
|
|
124
|
+
if (type(mark.get('staffIndex')) is not int or type(mark.get('staffCount')) is not int
|
|
125
|
+
or (mark['staffIndex'], mark['staffCount']) != (first.staff, first.count)):
|
|
126
|
+
return None
|
|
127
|
+
start = mark.get('start')
|
|
128
|
+
if mark['scope'] == 'UNRESOLVED':
|
|
129
|
+
if start is not None:
|
|
130
|
+
return None
|
|
131
|
+
elif (not isinstance(start, dict) or type(start.get('measureIndex')) is not int
|
|
132
|
+
or start['measureIndex'] != first.measure or type(start.get('quarterBeatOffset')) not in (int, float)
|
|
133
|
+
or not math.isfinite(start['quarterBeatOffset']) or start['quarterBeatOffset'] < 0):
|
|
134
|
+
return None
|
|
135
|
+
evidence = mark.get('evidence')
|
|
136
|
+
if not isinstance(evidence, list) or not any(isinstance(e, dict) and e.get('sourceId') == SOURCE
|
|
137
|
+
and (e.get('staffIndex'), e.get('staffCount')) == (first.staff, first.count) for e in evidence):
|
|
138
|
+
return None
|
|
139
|
+
identities = [member_of(n) for n in notes]
|
|
140
|
+
found = []
|
|
141
|
+
for wanted in pair.members:
|
|
142
|
+
matches = [i for i, m in enumerate(identities) if m == wanted]
|
|
143
|
+
if len(matches) != 1:
|
|
144
|
+
return None
|
|
145
|
+
found.append(matches[0])
|
|
146
|
+
left, right = unbits(first.x_bits), unbits(pair.members[-1].x_bits)
|
|
147
|
+
for i, note in enumerate(notes):
|
|
148
|
+
position = note.get('positionInMeasure')
|
|
149
|
+
if ((note.get('measureIndex'), note.get('staffIndex'), note.get('staffCount')) == first[:3]
|
|
150
|
+
and type(position) in (int, float) and math.isfinite(position) and 0 <= position <= 1
|
|
151
|
+
and left <= f32(position) <= right and identities[i] not in pair.members):
|
|
152
|
+
return None
|
|
153
|
+
return tuple(found)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def group_id(mark, pair):
|
|
157
|
+
digest = hashlib.md5((mark['eventId'] + '|' + pair.target).encode('utf-8')).digest()
|
|
158
|
+
return 'pg-' + str(uuid.UUID(bytes=digest, version=3))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def retained(page):
|
|
162
|
+
"""Validate every member against the final adapter clock before any endpoint escapes."""
|
|
163
|
+
score, events, beats = page.get('score', {}), page.get('events', []), page.get('measureBeats', [])
|
|
164
|
+
notes = score.get('notes', [])
|
|
165
|
+
if len(events) != len(notes) or not beats or any(type(v) not in (int, float) or not math.isfinite(v) or v <= 0 for v in beats):
|
|
166
|
+
return ()
|
|
167
|
+
starts = [0]
|
|
168
|
+
for beat in beats:
|
|
169
|
+
starts.append(starts[-1] + beat)
|
|
170
|
+
marks = score.get('expressiveEvents', [])
|
|
171
|
+
proposed = [(m, owners(m, notes)) for m in marks if m.get('kind') == 'PARENTHESIZED_NOTE_GROUP']
|
|
172
|
+
counts = Counter(i for _, members in proposed if members is not None for i in members)
|
|
173
|
+
ticks = lambda v: math.floor(v * 10080 + .5)
|
|
174
|
+
result = []
|
|
175
|
+
for mark, members in proposed:
|
|
176
|
+
if members is None or any(counts[i] != 1 for i in members):
|
|
177
|
+
continue
|
|
178
|
+
previous_end, valid = -1, True
|
|
179
|
+
for i in members:
|
|
180
|
+
note, event = notes[i], events[i]
|
|
181
|
+
m = note['measureIndex']
|
|
182
|
+
begin, duration = event.get('startBeat'), event.get('durationBeats')
|
|
183
|
+
if (event.get('kind', 'PITCHED') != 'PITCHED' or event.get('durationFallback', False)
|
|
184
|
+
or event.get('grace', False) or type(event.get('sourceNoteIndex')) is not int or event['sourceNoteIndex'] != i
|
|
185
|
+
or any(event.get(k) != note[k] for k in ('measureIndex', 'staffIndex', 'staffCount'))
|
|
186
|
+
or m >= len(beats) or any(type(v) not in (int, float) or not math.isfinite(v) for v in (begin, duration))
|
|
187
|
+
or duration <= 0 or not ticks(starts[m]) <= ticks(begin) < ticks(starts[m + 1])
|
|
188
|
+
or ticks(begin) < previous_end or ticks(begin + duration) > ticks(starts[-1])):
|
|
189
|
+
valid = False
|
|
190
|
+
break
|
|
191
|
+
previous_end = ticks(begin + duration)
|
|
192
|
+
if not valid:
|
|
193
|
+
continue
|
|
194
|
+
if mark['scope'] == 'NOTE' and ticks(starts[notes[members[0]]['measureIndex']] + mark['start']['quarterBeatOffset']) != ticks(events[members[0]]['startBeat']):
|
|
195
|
+
continue
|
|
196
|
+
pair = decode(mark['qualifierText'])
|
|
197
|
+
result.append((mark, pair, members))
|
|
198
|
+
return tuple(sorted(result, key=lambda r: events[r[2][0]]['startBeat']))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright 2026 Luckolite
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Optional native PDF tablature text; geometry and symbol semantics remain in Java."""
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
_TOKEN = re.compile(r"-(?:[12]|(?i:full))|(?i:full|whammy|w/bar|bar|upstroke|downstroke|strum up|strum down)|-?(?:1 1/2|1/4|1/2|3/4|1\u00bd|[\u00bc\u00bd\u00be])|[\uE846\uE847]|<[0-9]{1,2}>|\([0-9]{1,2}\)|(?<![0-9])[0-9]{1,2}[bB][0-9]{1,2}(?:[rR][0-9]{1,2})?~*|(?<![0-9])(?:[0-9]{1,2}|[xX])(?:[/\\hHpP][0-9]{1,2})+~*|(?<![0-9])[0-9]{1,3}(?![0-9])~*|[xXHPT=]|[\uE1E7\uE241\uE243\uE245\uE4E3-\uE4E8\uE4A2\uEAB2\uE080-\uE089\uECA5\uECA6\uECB7]")
|
|
7
|
+
|
|
8
|
+
def tuning_header(page):
|
|
9
|
+
textpage = page.get_textpage()
|
|
10
|
+
try:
|
|
11
|
+
match = re.search(r"(?im)^\s*tuning\s*[:=]?[^\r\n]+", textpage.get_text_range())
|
|
12
|
+
return match.group().strip() if match else ""
|
|
13
|
+
finally:
|
|
14
|
+
textpage.close()
|
|
15
|
+
|
|
16
|
+
def tuning_words(header):
|
|
17
|
+
"""Document tuning is metadata, independent of transformed page coordinates."""
|
|
18
|
+
return [dict(text=header, left=.01, top=.001, right=.9, bottom=.009)] if header else []
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def tab_words(page, header=""):
|
|
22
|
+
textpage = page.get_textpage()
|
|
23
|
+
words = []
|
|
24
|
+
try:
|
|
25
|
+
width, height = page.get_width(), page.get_height()
|
|
26
|
+
text = textpage.get_text_range()
|
|
27
|
+
tokens = set(_TOKEN.findall(text)) | {c for c in text if c in "0123456789"}
|
|
28
|
+
for token in sorted(tokens, key=len, reverse=True):
|
|
29
|
+
search = textpage.search(token)
|
|
30
|
+
try:
|
|
31
|
+
while (match := search.get_next()) is not None:
|
|
32
|
+
index, count = match
|
|
33
|
+
boxes = [textpage.get_charbox(i) for i in range(index, index + count)]
|
|
34
|
+
# PDF text search can concatenate frets on different strings into "55".
|
|
35
|
+
# Such a tall box must not suppress the two valid single-character boxes.
|
|
36
|
+
if len(token) > 1 and token.isdigit():
|
|
37
|
+
visible = [b for b in boxes if b[2] > b[0] and b[3] > b[1]]
|
|
38
|
+
centers = [(b[1]+b[3])/2 for b in visible]
|
|
39
|
+
if centers and max(centers)-min(centers) > max(b[3]-b[1] for b in visible):
|
|
40
|
+
continue
|
|
41
|
+
left = min(b[0] for b in boxes) / width
|
|
42
|
+
right = max(b[2] for b in boxes) / width
|
|
43
|
+
top = 1 - max(b[3] for b in boxes) / height
|
|
44
|
+
bottom = 1 - min(b[1] for b in boxes) / height
|
|
45
|
+
if 0 <= left < right <= 1 and 0 <= top < bottom <= 1:
|
|
46
|
+
words.append(dict(text=token, left=left, top=top, right=right, bottom=bottom))
|
|
47
|
+
finally:
|
|
48
|
+
search.close()
|
|
49
|
+
finally:
|
|
50
|
+
textpage.close()
|
|
51
|
+
words.extend(tuning_words(header))
|
|
52
|
+
return words
|