@@ -2,6 +2,35 @@ import { uuidv4 } from './random';
2
2
import * as vkbeautify from 'vkbeautify' ;
3
3
import * as Notification from '../utils/Notification' ;
4
4
5
+ // Note:
6
+ // The file sent to Verovio has the following structure (ConvertToVerovio()):
7
+ // <section>
8
+ // <pb/>
9
+ // <section type="neon-neume-line">
10
+ // <staff/>
11
+ // <layer/>
12
+ // content
13
+ // </section>
14
+ // <section type="neon-neume-line">
15
+ // <staff/>
16
+ // <layer/>
17
+ // content
18
+ // </section>
19
+ // ...
20
+ // </section>
21
+ //
22
+ // The file received needs to be converted back to the following structure (ConvertToNeon()):
23
+ // <section>
24
+ // <staff/>
25
+ // <layer/>
26
+ // <pb/>
27
+ // <sb/>
28
+ // staff content <syllable> etc.
29
+ // <sb/>
30
+ // staff content <syllable> etc.
31
+ // ...
32
+ // </section>
33
+
5
34
export function zip < T > ( array1 : Array < T > , array2 : Array < T > ) : Array < T > {
6
35
const result = [ ] ;
7
36
for ( let i = 0 ; i < ( array1 . length > array2 . length ? array2 . length : array1 . length ) ; i ++ ) {
@@ -24,6 +53,10 @@ export function convertToNeon(staffBasedMei: string): string {
24
53
let nCol = 0 ;
25
54
26
55
for ( const section of mei . querySelectorAll ( 'section:not([type="neon-neume-line"])' ) ) {
56
+ // Remove direct children pb elements within section
57
+ const pbs = section . querySelectorAll ( 'pb' ) ;
58
+ pbs . forEach ( pb => pb . remove ( ) ) ;
59
+
27
60
const newStaff = meiDoc . createElementNS ( 'http://www.music-encoding.org/ns/mei' , 'staff' ) ;
28
61
const newLayer = meiDoc . createElementNS ( 'http://www.music-encoding.org/ns/mei' , 'layer' ) ;
29
62
newStaff . setAttribute ( 'n' , '1' ) ;
@@ -226,12 +259,6 @@ export function convertToVerovio(sbBasedMei: string): string {
226
259
colLayout . parentNode . removeChild ( colLayout ) ;
227
260
}
228
261
229
- // Check if there are <pb> elements and remove them
230
- const pageBegins = Array . from ( mei . getElementsByTagName ( 'pb' ) ) ;
231
- for ( const pb of pageBegins ) {
232
- pb . parentNode . removeChild ( pb ) ;
233
- }
234
-
235
262
// Check syllable without neume
236
263
const syllables = Array . from ( mei . getElementsByTagName ( 'syllable' ) ) ;
237
264
let hasEmptySyllable = false ;
@@ -279,6 +306,11 @@ export function convertToVerovio(sbBasedMei: string): string {
279
306
// A separate array is necessary as the HTMLCollection will update!
280
307
const originalStaves = Array . from ( section . getElementsByTagName ( 'staff' ) ) ;
281
308
for ( const staff of originalStaves ) {
309
+ // Add a pb with a facs pointing to the surface
310
+ const newPb = meiDoc . createElementNS ( 'http://www.music-encoding.org/ns/mei' , 'pb' ) ;
311
+ newPb . setAttribute ( 'facs' , '#' + surface . getAttribute ( 'xml:id' ) ) ;
312
+ section . insertBefore ( newPb , staff ) ;
313
+
282
314
const layer = staff . querySelector ( 'layer' ) ;
283
315
// First pass: get all sb elements as direct children of layer
284
316
const sbArray = Array . from ( layer . getElementsByTagName ( 'sb' ) ) ;
0 commit comments