Skip to content

Commit

Permalink
first try on accidentals
Browse files Browse the repository at this point in the history
  • Loading branch information
kepper committed Nov 14, 2024
1 parent 1e605c0 commit 441e3a3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/fluidTranscripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ const generateAnimation = (name, ftSvgNode, dtSvgNode, positions) => {
} else if (name === 'beamSpan' || name === 'beam') {
// chords actually can use the same animation as notes
generateAnimation_beam(ftSvgNode, dtSvgNode, positions)
} else if (name === 'accid') {
// chords actually can use the same animation as notes
generateAnimation_accid(ftSvgNode, dtSvgNode, positions)
} else {
console.warn('Unable to animate element ' + name)
}
Expand Down Expand Up @@ -396,6 +399,32 @@ const generateAnimation_beam = (atSvgNode, dtSvgNode, positions) => {
})
}

const generateAnimation_accid = (atSvgNode, dtSvgNode, positions) => {
try {
const atUse = atSvgNode.querySelector('use')
const atX = parseFloat(atUse.getAttribute('x'))
const atY = parseFloat(atUse.getAttribute('y'))
const dtUse = dtSvgNode.querySelector('use')
const dtX = parseFloat(dtUse.getAttribute('x'))
const dtY = parseFloat(dtUse.getAttribute('y'))

const atOffX = positions.atCenter.x - atX
const atOffY = positions.atCenter.y - atY
const dtOffX = positions.dtCenter.x - dtX
const dtOffY = positions.dtCenter.y - dtY

const diffX = atOffX - dtOffX
const diffY = atOffY - dtOffY

const dtPos = diffX + ' ' + diffY
const atPos = '0 0'

addTransformTranslate(atSvgNode, [dtPos, atPos, atPos, atPos])
} catch(err) {
console.warn('Error in generateAnimation_accid: ' + err, err)
}
}

const addTransformTranslate = (node, values = []) => {
const anim = appendNewElement(node, 'animateTransform', 'http://www.w3.org/2000/svg')
anim.setAttribute('attributeName', 'transform')
Expand Down

0 comments on commit 441e3a3

Please sign in to comment.