|
| 1 | +function plugindef() |
| 2 | + finaleplugin.RequireSelection = true |
| 3 | + finaleplugin.Author = "Carl Vine" |
| 4 | + finaleplugin.AuthorURL = "https://carlvine.com/lua/" |
| 5 | + finaleplugin.Copyright = "https://creativecommons.org/licenses/by/4.0/" |
| 6 | + finaleplugin.Version = "0.62" |
| 7 | + finaleplugin.Date = "2024/06/02" |
| 8 | + finaleplugin.Notes = [[ |
| 9 | + Create diamond noteheads on the top note of dyads identified as viable string harmonics. |
| 10 | + Note that this uses MIDI note values to identify acceptable intervals to |
| 11 | + avoid the complications of key signatures and transposing instruments. |
| 12 | + This is inelegant but simple and should work in most situations! |
| 13 | + ]] |
| 14 | + return "String Harmonics", "String Harmonics", |
| 15 | + "Create diamond noteheads on the top note of dyads identified as viable string harmonics" |
| 16 | +end |
| 17 | + |
| 18 | +local notehead = require("library.notehead") |
| 19 | + |
| 20 | +function string_harmonics() |
| 21 | + -- allowable intervals for string harmonics, measured in interval STEPS |
| 22 | + local allowed = { 3, 4, 5, 7, 9, 12, 16, 19, 24, 28, 31 } |
| 23 | + local allowable = {} |
| 24 | + for _, v in ipairs(allowed) do allowable[v] = true end |
| 25 | + |
| 26 | + for entry in eachentrysaved(finenv.Region()) do |
| 27 | + if entry:IsNote() and (entry.Count == 2) then -- only treat 2-note chords |
| 28 | + local highest = entry:CalcHighestNote(nil) |
| 29 | + local lowest = entry:CalcLowestNote(nil) |
| 30 | + local midi_diff = highest:CalcMIDIKey() - lowest:CalcMIDIKey() |
| 31 | + |
| 32 | + if allowable[midi_diff] then -- only permissible intervals |
| 33 | + finale.FCNoteheadMod():EraseAt(lowest) |
| 34 | + notehead.change_shape(highest, "diamond") |
| 35 | + end |
| 36 | + end |
| 37 | + end |
| 38 | +end |
| 39 | + |
| 40 | +string_harmonics() |
0 commit comments