Skip to content

Commit

Permalink
Remove old annotations when regenerating tabs
Browse files Browse the repository at this point in the history
- Tabs were added every time the plugin was run, resulting in duplicates.
- In cases where the note changes, the glyphs were simply overlaid on one another,
making the result incorrect.
- Fix: while adding annotations, check the segment for those
which have the same offset as the new annotation, and remove them.
  • Loading branch information
uthidata committed Apr 14, 2024
1 parent 29ab4b9 commit 9f996f8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tin_whistle_tablature.qml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ MuseScore {
console.log("^^ -------- " + title + " ---------- ^^")
} // end dumpObjectEntries

function removeDuplicatesInSegment(segment, elementToKeep) {
var removables = [];

for (var i = 0; i < segment.annotations.length; i++) {
var element = segment.annotations[i];
if (element.is(elementToKeep)) {
continue;
}

if (element.offsetX == elementToKeep.offsetX && element.offsetY == elementToKeep.offsetY) {
removables.push(element);
}
}

for (var i = 0; i < removables.length; i++) {
var element = segment.annotations[i];
removeElement(element);
}
}

function renderTinWhistleTablature () {
curScore.startCmd();

Expand Down Expand Up @@ -288,6 +308,8 @@ MuseScore {
// (See the note below about behavior of the text.offsetY property.)
text.offsetY = tabOffsetY // place the tab below the staff

removeDuplicatesInSegment(cursor.segment, text);

// Create new text element for next tab placement
text = newElement(Element.STAFF_TEXT)
}
Expand Down Expand Up @@ -340,6 +362,8 @@ MuseScore {
else
text.offsetX = 0.5

removeDuplicatesInSegment(cursor.segment, text);

// Create new text element for next tab placement
text = newElement(Element.STAFF_TEXT)
} // end if repeated
Expand Down Expand Up @@ -376,6 +400,8 @@ MuseScore {
// (See the note below about behavior of the text.offsetY property.)
text.offsetY = tabOffsetY // place the tab below the staff

removeDuplicatesInSegment(cursor.segment, text);

// Create new text element for next tab placement
text = newElement(Element.STAFF_TEXT)
}
Expand Down

0 comments on commit 9f996f8

Please sign in to comment.