guitarpro-parser 1.0.0
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.
- package/LICENSE +52 -0
- package/README.md +197 -0
- package/dist/index.cjs +1649 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +222 -0
- package/dist/index.d.ts +222 -0
- package/dist/index.js +1621 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Emilien Bevierre
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Minimal pitch utilities — inlined from GuitarWeaver's pitch.ts to make
|
|
18
|
+
* this package fully self-contained with zero external dependencies.
|
|
19
|
+
*/
|
|
20
|
+
/** Chromatic pitch class: 0 = C, 1 = C#/Db, ..., 11 = B */
|
|
21
|
+
type PitchClass = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
|
|
22
|
+
type Accidental = 'sharp' | 'flat' | 'natural';
|
|
23
|
+
interface Note {
|
|
24
|
+
pitchClass: PitchClass;
|
|
25
|
+
name: string;
|
|
26
|
+
accidental: Accidental;
|
|
27
|
+
octave?: number;
|
|
28
|
+
}
|
|
29
|
+
/** Builds a Note from a pitch class, with optional octave and flat preference. */
|
|
30
|
+
declare function noteFromPitchClass(pc: PitchClass, preferFlats?: boolean, octave?: number): Note;
|
|
31
|
+
/** Converts MIDI note number to PitchClass. */
|
|
32
|
+
declare function midiToPitchClass(midi: number): PitchClass;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Copyright 2026 Emilien Bevierre
|
|
36
|
+
*
|
|
37
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
38
|
+
* you may not use this file except in compliance with the License.
|
|
39
|
+
* You may obtain a copy of the License at
|
|
40
|
+
*
|
|
41
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
42
|
+
*
|
|
43
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
44
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
45
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
46
|
+
* See the License for the specific language governing permissions and
|
|
47
|
+
* limitations under the License.
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Public types for parsed Guitar Pro file structures.
|
|
51
|
+
* These types are format-agnostic — all parsers (GPX, GP5, GP7) produce the same output.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/** Duration values matching Guitar Pro's rhythm notation */
|
|
55
|
+
type Duration = 'whole' | 'half' | 'quarter' | 'eighth' | '16th' | '32nd' | '64th' | '128th';
|
|
56
|
+
/** A single note on a specific string/fret with technique annotations */
|
|
57
|
+
interface TabNote {
|
|
58
|
+
string: number;
|
|
59
|
+
fret: number;
|
|
60
|
+
pitchClass: PitchClass;
|
|
61
|
+
noteName: string;
|
|
62
|
+
slide: number | null;
|
|
63
|
+
harmonic: string | null;
|
|
64
|
+
palmMute: boolean;
|
|
65
|
+
muted: boolean;
|
|
66
|
+
letRing: boolean;
|
|
67
|
+
bend: {
|
|
68
|
+
origin: number;
|
|
69
|
+
destination: number;
|
|
70
|
+
middle: number;
|
|
71
|
+
} | null;
|
|
72
|
+
tie: {
|
|
73
|
+
origin: boolean;
|
|
74
|
+
destination: boolean;
|
|
75
|
+
};
|
|
76
|
+
vibrato: string | null;
|
|
77
|
+
hammerOn: boolean;
|
|
78
|
+
pullOff: boolean;
|
|
79
|
+
tapped: boolean;
|
|
80
|
+
accent: number | null;
|
|
81
|
+
}
|
|
82
|
+
/** A beat = a rhythmic moment containing 0..N simultaneous notes */
|
|
83
|
+
interface TabBeat {
|
|
84
|
+
index: number;
|
|
85
|
+
barIndex: number;
|
|
86
|
+
notes: TabNote[];
|
|
87
|
+
duration: Duration;
|
|
88
|
+
tuplet: {
|
|
89
|
+
num: number;
|
|
90
|
+
den: number;
|
|
91
|
+
} | null;
|
|
92
|
+
dotted: number;
|
|
93
|
+
isRest: boolean;
|
|
94
|
+
dynamic: string | null;
|
|
95
|
+
tempo: number;
|
|
96
|
+
}
|
|
97
|
+
/** A bar with time signature and key info */
|
|
98
|
+
interface TabBar {
|
|
99
|
+
index: number;
|
|
100
|
+
timeSignature: {
|
|
101
|
+
numerator: number;
|
|
102
|
+
denominator: number;
|
|
103
|
+
};
|
|
104
|
+
keySignature: {
|
|
105
|
+
accidentalCount: number;
|
|
106
|
+
mode: 'major' | 'minor';
|
|
107
|
+
} | null;
|
|
108
|
+
section: {
|
|
109
|
+
letter?: string;
|
|
110
|
+
text?: string;
|
|
111
|
+
} | null;
|
|
112
|
+
beats: TabBeat[];
|
|
113
|
+
repeatStart: boolean;
|
|
114
|
+
repeatEnd: boolean;
|
|
115
|
+
repeatCount: number;
|
|
116
|
+
}
|
|
117
|
+
/** A track (instrument) with its tuning and bars */
|
|
118
|
+
interface TabTrack {
|
|
119
|
+
id: string;
|
|
120
|
+
name: string;
|
|
121
|
+
shortName: string;
|
|
122
|
+
instrument: string | null;
|
|
123
|
+
tuning: Note[];
|
|
124
|
+
capoFret: number;
|
|
125
|
+
bars: TabBar[];
|
|
126
|
+
}
|
|
127
|
+
/** Top-level parsed song */
|
|
128
|
+
interface TabSong {
|
|
129
|
+
title: string;
|
|
130
|
+
artist: string;
|
|
131
|
+
album: string;
|
|
132
|
+
tempo: number;
|
|
133
|
+
tracks: TabTrack[];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Copyright 2026 Emilien Bevierre
|
|
138
|
+
*
|
|
139
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
140
|
+
* you may not use this file except in compliance with the License.
|
|
141
|
+
* You may obtain a copy of the License at
|
|
142
|
+
*
|
|
143
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
144
|
+
*
|
|
145
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
146
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
147
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
148
|
+
* See the License for the specific language governing permissions and
|
|
149
|
+
* limitations under the License.
|
|
150
|
+
*/
|
|
151
|
+
/**
|
|
152
|
+
* Unified Guitar Pro file parser — dispatches to format-specific parsers
|
|
153
|
+
* based on file header detection.
|
|
154
|
+
*
|
|
155
|
+
* Supported formats:
|
|
156
|
+
* - .gpx → BCFZ/BCFS container (Guitar Pro 6)
|
|
157
|
+
* - .gp → ZIP container with Content/score.gpif (Guitar Pro 7+)
|
|
158
|
+
* - .gp5 → Legacy sequential binary (Guitar Pro 5)
|
|
159
|
+
*
|
|
160
|
+
* Pure, zero native dependencies.
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
/** Detects file format from header bytes and filename. */
|
|
164
|
+
declare function detectFormat(data: Uint8Array, fileName?: string): 'gpx' | 'gp7' | 'gp5';
|
|
165
|
+
/**
|
|
166
|
+
* Parses any supported Guitar Pro file format into a TabSong.
|
|
167
|
+
* Detects format automatically from file header bytes.
|
|
168
|
+
*
|
|
169
|
+
* Supported: .gpx (GP6), .gp (GP7+), .gp5 (GP5)
|
|
170
|
+
*/
|
|
171
|
+
declare function parseTabFile(data: Uint8Array, fileName?: string): TabSong;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Copyright 2026 Emilien Bevierre
|
|
175
|
+
*
|
|
176
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
177
|
+
* you may not use this file except in compliance with the License.
|
|
178
|
+
* You may obtain a copy of the License at
|
|
179
|
+
*
|
|
180
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
181
|
+
*
|
|
182
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
183
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
184
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
185
|
+
* See the License for the specific language governing permissions and
|
|
186
|
+
* limitations under the License.
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/** Converts a rhythm value to a beat fraction accounting for dots and tuplets. */
|
|
190
|
+
declare function durationToBeats(duration: Duration, dotCount: number, tuplet: {
|
|
191
|
+
num: number;
|
|
192
|
+
den: number;
|
|
193
|
+
} | null): number;
|
|
194
|
+
/** Computes the duration in milliseconds for a beat at its tempo. */
|
|
195
|
+
declare function beatDurationMs(beat: TabBeat): number;
|
|
196
|
+
/** Transforms GPIF XML DOM into a TabSong. Exported for reuse by GP7+ ZIP parser. */
|
|
197
|
+
declare function gpifToTabSong(doc: Document): TabSong;
|
|
198
|
+
/** Parses a Guitar Pro .gpx file from raw bytes into a TabSong.
|
|
199
|
+
* Pipeline: Uint8Array → BCFZ/BCFS decode → extract score.gpif → DOMParser → TabSong
|
|
200
|
+
*/
|
|
201
|
+
declare function parseGpxFile(data: Uint8Array): TabSong;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Copyright 2026 Emilien Bevierre
|
|
205
|
+
*
|
|
206
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
207
|
+
* you may not use this file except in compliance with the License.
|
|
208
|
+
* You may obtain a copy of the License at
|
|
209
|
+
*
|
|
210
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
211
|
+
*
|
|
212
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
213
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
214
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
215
|
+
* See the License for the specific language governing permissions and
|
|
216
|
+
* limitations under the License.
|
|
217
|
+
*/
|
|
218
|
+
|
|
219
|
+
/** Parses a Guitar Pro 5 (.gp5) file from raw bytes into a TabSong. */
|
|
220
|
+
declare function parseGp5File(data: Uint8Array): TabSong;
|
|
221
|
+
|
|
222
|
+
export { type Accidental, type Duration, type Note, type PitchClass, type TabBar, type TabBeat, type TabNote, type TabSong, type TabTrack, beatDurationMs, detectFormat, durationToBeats, gpifToTabSong, midiToPitchClass, noteFromPitchClass, parseGp5File, parseGpxFile, parseTabFile };
|