forked from finale-lua/lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accidental_simplify.lua
43 lines (37 loc) · 1.84 KB
/
accidental_simplify.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function plugindef()
finaleplugin.RequireSelection = true
finaleplugin.Author = "Nick Mazuk"
finaleplugin.Copyright = "CC0 https://creativecommons.org/publicdomain/zero/1.0/"
finaleplugin.Version = "1.1"
finaleplugin.Date = "January 9, 2024"
finaleplugin.CategoryTags = "Accidental"
finaleplugin.AuthorURL = "https://nickmazuk.com"
return "Simplify accidentals", "Simplify accidentals", "Removes all double sharps and flats by respelling them"
end
local transposition = require("library.transposition")
function accidentals_simplify()
for entry in eachentrysaved(finenv.Region()) do
local measure_number = entry.Measure
local staff_number = entry.Staff
local cell = finale.FCCell(measure_number, staff_number)
local key_signature = cell:GetKeySignature()
for note in transposition.each_to_transpose(entry) do
if note.RaiseLower ~= 0 then
-- Use note_string rather than note.RaiseLower because
-- with key signatures, note.RaiseLower returns the alteration
-- from the key signature, not the actual accidental.
-- For instance, in the key of A, a Gb has a RaiseLower of -2
-- even though Gb is not a double flat.
local fs_note_string = finale.FCString()
note:GetString(fs_note_string, key_signature, false, false)
local note_string = fs_note_string:GetLuaString()
-- checking for 'bb' and '##' will also match triple sharps and flats
if string.match(note_string, "bb") or string.match(note_string, "##") then
transposition.enharmonic_transpose(note, note.RaiseLower)
transposition.simplify_spelling(note)
end
end
end
end
end
accidentals_simplify()