Skip to content

Commit cbd9897

Browse files
authored
🤖 Merge PR DefinitelyTyped#72044 fix(Verovio): Add missing methods by @bbloomf
1 parent 27a4e65 commit cbd9897

File tree

4 files changed

+187
-29
lines changed

4 files changed

+187
-29
lines changed

types/verovio/VerovioOptions.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,13 @@ export interface VerovioOptions {
18701870
*/
18711871
ligatureAsBracket?: boolean;
18721872

1873+
/**
1874+
* Ligature oblique shape
1875+
*
1876+
* default: "auto"
1877+
*/
1878+
ligatureOblique?: "auto" | "straight" | "curved";
1879+
18731880
/**
18741881
* Convert mensural content to a more responsive view reduced to the seleceted markup
18751882
*

types/verovio/index.d.ts

Lines changed: 178 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ export interface GetMeiOptions {
1616
*/
1717
pageNo?: number;
1818
/**
19-
* default true
19+
* Score Based, default true
2020
*/
2121
scoreBased?: boolean;
22+
/**
23+
* Basic, default false
24+
*/
25+
basic?: boolean;
2226
/**
2327
* remove all @xml:id not used in the data; default false
2428
*/
@@ -31,6 +35,50 @@ export interface TimeMapEntry {
3135
off?: string[];
3236
tempo?: number;
3337
}
38+
export interface RedoLayoutOptions {
39+
/**
40+
* true by default
41+
*/
42+
resetCache?: boolean;
43+
}
44+
export interface TimeMapOptions {
45+
/**
46+
* Include measures in the timemap (false by default)
47+
*/
48+
includeMeasures?: boolean;
49+
/**
50+
* Include rests in the timemap (false by default)
51+
*/
52+
includeRests?: boolean;
53+
}
54+
export interface Selection {
55+
measureRange?: string;
56+
start?: string;
57+
end?: string;
58+
}
59+
export interface PAEValidationMessage {
60+
column: number;
61+
row: number;
62+
code: number;
63+
text: string;
64+
type: "error" | "warning";
65+
}
66+
export interface PAEValidation {
67+
clef?: PAEValidationMessage;
68+
data?: PAEValidationMessage[];
69+
}
70+
interface ExpansionMap {
71+
[key: string]: any;
72+
}
73+
export interface DescriptiveFeatures {
74+
intervalsChromatic: string[];
75+
intervalsDiatonic: string[];
76+
intervalsIds: string[];
77+
pitchesChromatic: string[];
78+
pitchesDiatonic: string[];
79+
pitchesIds: string[];
80+
}
81+
type DescriptiveFeaturesOptions = unknown;
3482

3583
export const module: VerovioModule;
3684
export interface VerovioModule {
@@ -48,14 +96,36 @@ export interface VerovioModule {
4896

4997
export class toolkit {
5098
constructor(module?: VerovioModule);
99+
destroy: () => void;
51100

52101
/**
53-
* Edit the MEI data.
102+
* Filter Humdrum data.
103+
* @returns The Humdrum data as a string
104+
*/
105+
convertHumdrumToHumdrum: (humdrumData: string) => string;
106+
107+
/**
108+
* Convert Humdrum data to MIDI.
109+
* @returns The MIDI file as a base64-encoded string
110+
*/
111+
convertHumdrumToMIDI: (humdrumData: string) => string;
112+
113+
/**
114+
* Convert MEI data into Humdrum data.
115+
* @returns The Humdrum data as a string
116+
*/
117+
convertMEIToHumdrum: (mei: string) => string;
118+
119+
/**
120+
* Edit the MEI data - experimental code not to rely on.
121+
* @param editorAction The editor actions as a stringified JSON object
122+
* @returns True if the edit action was successfully applied
54123
*/
55124
edit: (editorAction: EditorAction) => boolean;
56125

57126
/**
58-
* Return the editor status.
127+
* Return the editor status - experimental code not to rely on.
128+
* @returns The editor status as a string
59129
*/
60130
editInfo: () => EditorAction;
61131

@@ -67,79 +137,114 @@ export class toolkit {
67137
getAvailableOptions: () => AvailableOptions;
68138

69139
/**
70-
* Returns array of IDs of elements being currently played.
71-
* @returns A JSON object with the page and notes being played
140+
* Return a dictionary of all the options with their default value.
72141
*/
73-
getElementsAtTime: (millisec: number) => { notes: string[]; page: number };
142+
getDefaultOptions: () => VerovioOptions;
143+
144+
/**
145+
* Return descriptive features as a JSON string.
146+
*
147+
* The features are tailored for implementing incipit search.
148+
* @param jsonOptions A JSON object with the feature extraction options
149+
* @returns A JSON object with the requested features
150+
*/
151+
getDescriptiveFeatures: (jsonOptions: DescriptiveFeaturesOptions) => DescriptiveFeatures;
74152

75153
/**
76154
* Return element attributes as a JSON string.
77155
*
78156
* The attributes returned include the ones not supported by Verovio
157+
* @param xmlId the ID (@xml:id) of the element being looked for
79158
* @returns A JSON object with all attributes
80159
*/
81160
getElementAttr: (xmlId: string) => { [attribute: string]: string };
82161

162+
/**
163+
* Returns array of IDs of elements being currently played.
164+
* @param millisec The time in milliseconds
165+
* @returns A JSON object with the page and notes being played
166+
*/
167+
getElementsAtTime: (millisec: number) => { notes: string[]; page: number };
168+
83169
/**
84170
* Returns a vector of ID strings of all elements (the notated and the expanded) for a given element.
171+
* @param xmlId the ID (@xml:id) of the element being looked for
172+
* @returns A JSON object with all IDs
85173
*/
86174
getExpansionIdsForElement: (xmlId: string) => { [notated: string]: string };
87175

88176
/**
89177
* Get the humdrum buffer.
178+
* @returns The humdrum buffer as a string
90179
*/
91180
getHumdrum: () => string;
92181

93182
/**
94-
* Returns the log message of the last performed operation, for example after having called loadData.
183+
* Get the log content for the latest operation.
184+
* @returns The log content as a string
95185
*/
96186
getLog: () => string;
97187

98188
/**
99-
* Returns the MEI data loaded in the toolkit. If a page number is provided (i.e. > 0), then
100-
* only that page is exported. In score-based MEI, then only the section element will be
101-
* output. Set options.scoreBased to true for standard score-based MEI and false for the
102-
* internal page-based MEI.
189+
* Get the MEI as a string.
190+
* @param options A JSON object with the output options; pageNo: integer; (1-based), all pages if none (or 0) specified; scoreBased: true or false; true by default; basic: true or false; false by default; removeIds: true or false; false by default - remove all @xml:id not used in the data;
103191
*/
104192
getMEI: (options?: GetMeiOptions) => string;
105193

106194
/**
107195
* Return MIDI values of the element with the ID (xml:id)
108196
*
109197
* RenderToMIDI() must be called prior to using this method
198+
* @param xmlId the ID (@xml:id) of the element being looked for
199+
* @returns a JSON object with the MIDI values
110200
*/
111201
getMIDIValuesForElement: (xmlId: string) => MIDIValues;
112202

113203
/**
114204
* Returns the ID string of the notated (the original) element.
205+
* @param xmlId the ID (@xml:id) of the element being looked for
206+
* @returns An ID string
115207
*/
116208
getNotatedIdForElement: (xmlId: string) => string;
117209

210+
/**
211+
* Return a dictionary of all the options with their current value.
212+
* @returns A JSON object
213+
*/
214+
getOptions: (defaultValues?: boolean) => VerovioOptions;
215+
118216
/**
119217
* Return the number of pages in the loaded document.
120218
*
121219
* The number of pages depends one the page size and if encoded layout was taken into account or not.
220+
* @returns The number of pages
122221
*/
123222
getPageCount: () => number;
124223

125224
/**
126225
* Return the page on which the element is the ID (xml:id) is rendered.
127226
*
128227
* This takes into account the current layout options.
228+
* @param xmlId the ID (@xml:id) of the element being looked for
229+
* @returns the page number (1-based) where the element is (0 if not found)
129230
*/
130231
getPageWithElement: (xmlId: string) => number;
131232

132233
/**
133234
* Return the time at which the element is the ID (xml:id) is played.
134235
*
135236
* RenderToMIDI() must be called prior to using this method.
237+
* @param xmlId the ID (@xml:id) of the element being looked for
238+
* @returns The time in milliseconds
136239
*/
137240
getTimeForElement: (xmlId: string) => number;
138241

139242
/**
140243
* Return a JSON object string with the following key values for a given note.
141244
*
142245
* Return scoreTimeOnset, scoreTimeOffset, scoreTimeTiedDuration, realTimeOnsetMilliseconds, realTimeOffsetMilliseconds, realTimeTiedDurationMilliseconds.
246+
* @param xmlId the ID (@xml:id) of the element being looked for
247+
* @returns A JSON object with the values
143248
*/
144249
getTimesForElement: (xmlId: string) => {
145250
scoreTimeOnset: number;
@@ -152,25 +257,29 @@ export class toolkit {
152257

153258
/**
154259
* Return the version number.
260+
* @returns the version number as a string
155261
*/
156262
getVersion: () => string;
157263

158264
/**
159265
* Load a string data with the type previously specified in the options.
160266
*
161267
* By default, the methods try to auto-detect the type.
268+
* @param data A string with the data (e.g., MEI data) to be loaded
162269
* @returns True if the data was successfully loaded
163270
*/
164-
loadData: (meiData: string) => boolean;
271+
loadData: (data: string) => boolean;
165272

166273
/**
167274
* Load a MusicXML compressed file passed as base64 encoded string.
275+
* @param zipDataBase64 A ZIP file as a base64 encoded string
168276
* @returns True if the data was successfully loaded
169277
*/
170278
loadZipDataBase64: (zipDataBase64: string) => boolean;
171279

172280
/**
173281
* Load a MusicXML compressed file passed as a buffer of bytes.
282+
* @param zipDataBuffer A ZIP file as a buffer of bytes
174283
* @returns True if the data was successfully loaded
175284
*/
176285
loadZipDataBuffer: (zipDataBuffer: ArrayBuffer) => boolean;
@@ -179,8 +288,9 @@ export class toolkit {
179288
* Redo the layout of the loaded data.
180289
*
181290
* This can be called once the rendering option were changed, for example with a new page (sceen) height or a new zoom level.
291+
* @param options A JSON object with the action options resetCache: true or false; true by default;
182292
*/
183-
redoLayout: () => void;
293+
redoLayout: (options?: RedoLayoutOptions) => void;
184294

185295
/**
186296
* Redo the layout of the pitch postitions of the current drawing page.
@@ -190,12 +300,20 @@ export class toolkit {
190300
redoPagePitchPosLayout: () => void;
191301

192302
/**
193-
* Loads and the data with the options passed as JSON object and renders the first page. This
194-
* methods is a shortcut for loadData and then renderPage and is appropriate for rendering small
195-
* data snippets. The data does stay in memory once loaded. Also, up to version 0.9.12, the JSON
196-
* object had to be stringified.
303+
* Render the first page of the data to SVG.
304+
*
305+
* This method is a wrapper for setting options, loading data and rendering the first page. It will return an empty string if the options cannot be set or the data cannot be loaded.
306+
* @param data A string with the data (e.g., MEI data) to be loaded
307+
* @param options A JSON object with the output options
308+
* @returns The SVG first page as a string
309+
*/
310+
renderData: (data: string, options: VerovioOptions) => string;
311+
312+
/**
313+
* Render a document’s expansionMap, if existing.
314+
* @returns The expansion map as a JSON object
197315
*/
198-
renderData: (meiData: string, options: VerovioOptions) => string;
316+
renderToExpansionMap: () => ExpansionMap;
199317

200318
/**
201319
* Render the document to MIDI.
@@ -204,33 +322,65 @@ export class toolkit {
204322
renderToMIDI: () => string;
205323

206324
/**
207-
* Render a document to Plaine and Easie.
325+
* Render a document to Plaine and Easie code.
208326
*
209327
* Only the top staff / layer is exported.
210328
* @returns The PAE as a string
211329
*/
212330
renderToPAE: () => string;
213331

214332
/**
215-
* Renders a page for the data loaded in the toolkit and returns it in SVG. The page numbering
216-
* is 1-based.
333+
* Render a page to SVG.
334+
* @param pageNumber The page to render (1-based), default 1
335+
* @param xmlDeclaration True for including the xml declaration in the SVG output, default false
217336
* @returns The SVG page as a string
218337
*/
219-
renderToSVG: (pageNumber: number) => string;
338+
renderToSVG: (pageNumber?: number, xmlDeclaration?: boolean) => string;
220339

221340
/**
222341
* Render a document to a timemap.
342+
* @param options A stringified JSON objects with the timemap options
343+
* @returns The timemap as a JSON object
223344
*/
224-
renderToTimemap: () => TimeMapEntry[];
345+
renderToTimemap: (options?: TimeMapOptions) => TimeMapEntry[];
346+
225347
/**
226-
* Sets the options as JSON for the toolkit instance. Up to version 0.9.12, the JSON object had to be stringified.
348+
* Reset all options to default values.
227349
*/
228-
setOptions: (options: VerovioOptions) => void;
350+
resetOptions: () => void;
229351

230352
/**
231-
* Return a dictionary of all the options.
353+
* Reset the seed used to generate MEI @xml:id attribute values.
232354
*
233-
* @param defaultValues True for getting the default values and false for the current values
355+
* Passing 0 will seed the @xml:id generator with a random (time-based) seed value. This method will have no effect if the xml-id-checksum option is set.
356+
* @param seed The seed value for generating the @xml:id values (0 for a time-based random seed)
234357
*/
235-
getOptions: (defaultValues?: boolean) => VerovioOptions;
358+
resetXmlIdSeed: (seed: number) => void;
359+
360+
/**
361+
* Set the value for a selection.
362+
*
363+
* The selection will be applied only when some data is loaded or the layout is redone. The selection can be reset (cancelled) by passing an empty string or an empty JSON object. A selection across multiple mdivs is not possible.
364+
* @param selection The selection as a stringified object
365+
* @returns True if the selection was successfully parsed or reset
366+
*/
367+
select: (selection: Selection) => boolean;
368+
369+
/**
370+
* Set option values.
371+
*
372+
* The name of each option to be set is to be given as JSON key.
373+
* @param options A JSON object with the output options
374+
* @returns True if the options were successfully set
375+
*/
376+
setOptions: (options: VerovioOptions) => boolean;
377+
378+
/**
379+
* Validate the Plaine & Easie code passed in the string data.
380+
*
381+
* A single JSON object is returned when there is a global input error. When reading the input succeeds, validation is grouped by input keys. The methods always returns errors in PAE pedantic mode. No data remains loaded after the validation.
382+
* @param data A string with the data in JSON or with PAE @ keys
383+
* @returns A JSON object with the validation warnings or errors
384+
*/
385+
validatePAE: (data: string | { [key: string]: string }) => PAEValidation;
236386
}

types/verovio/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/verovio",
4-
"version": "5.0.9999",
4+
"version": "5.1.9999",
55
"exports": {
66
".": "./index.d.ts",
77
"./esm": {

0 commit comments

Comments
 (0)