Skip to content

Commit

Permalink
cherry pick src/tools/mei.js draft2score
Browse files Browse the repository at this point in the history
  • Loading branch information
jpvoigt committed Aug 21, 2024
1 parent 2c4212f commit c1e42f3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/tools/mei.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ export function sortRastrumsByVerticalPosition (rastrumDesc) {
export function draft2score (meiDom) {
const arr = []
meiDom.querySelectorAll('draft').forEach(draft => {
console.warn('draft:', draft)
const music = document.createElementNS('http://www.music-encoding.org/ns/mei', 'music')
music.setAttribute('meiversion', '5.0.0-dev')
const body = document.createElementNS('http://www.music-encoding.org/ns/mei', 'body')
Expand All @@ -585,6 +586,25 @@ export function draft2score (meiDom) {
})
arr.push(music)
})
// console.log(arr)
if (arr.length === 0) {
console.warn('draft2score: try to add score elements ...')
meiDom.querySelectorAll('score').forEach(score => {
const music = document.createElementNS('http://www.music-encoding.org/ns/mei', 'music')
music.setAttribute('meiversion', '5.0.0-dev')
const body = document.createElementNS('http://www.music-encoding.org/ns/mei', 'body')
const mdiv = document.createElementNS('http://www.music-encoding.org/ns/mei', 'mdiv')

music.append(body)
body.append(mdiv)
mdiv.append(score.cloneNode(true))

arr.push(music)
})
}
if (arr.length === 0) {
console.error('draft2score: no scores!')
}
return arr
}

Expand Down

0 comments on commit c1e42f3

Please sign in to comment.