function plugindef() -- This function and the 'finaleplugin' namespace -- are both reserved for the plug-in definition. finaleplugin.RequireSelection = true finaleplugin.Author = "Charles O. Lawrence" return "DelNoteInChord", "DelNoteInChord", "Deletes a selected note from all chords found in the selected region." end -- set up some debug flags local DEBUG0 = false local DEBUG1 = false local DEBUG2 = true -- information alert message local infoString = "This script will delete a selected note from all chords found in the selected region.\n" infoString = infoString.."You may choose any note from A0 to C8. The default is C4, middle C on the piano.\n\n" infoString = infoString.."Do you want to continue?" -- initialize entries for UI local selectNote = { ["C8"] = {108}, ["B7"] = {107}, ["Bb/A# 7"] = {106}, ["A7"] = {105}, ["Ab/G# 7"] = {104}, ["G7"] = {103}, ["Gb/F# 7"] = {102}, ["F7"] = {101}, ["E7"] = {100}, ["Eb/D# 7"] = {99}, ["D7"] = {98}, ["Db/C# 7"] = {97}, ["C7"] = {96}, ["B6"] = {95}, ["Bb/A# 6"] = {94}, ["A6"] = {93}, ["Ab/G# 6"] = {92}, ["G6"] = {91}, ["Gb/F# 6"] = {90}, ["F6"] = {89}, ["E6"] = {88}, ["Eb/D# 6"] = {87}, ["D6"] = {86}, ["Db/C# 6"] = {85}, ["C6"] = {84}, ["B5"] = {83}, ["Bb/A# 5"] = { 82}, ["A5"] = {81}, ["Ab/G# 5"] = {80}, ["G5"] = {79}, ["Gb/F# 5"] = {78}, ["F5"] = {77}, ["E5"] = {76}, ["Eb/D# 5"] = {75}, ["D5"] = {74}, ["Db/C# 5"] = {73}, ["C5"] = {72}, ["B4"] = {71}, ["Bb/A# 4"] = {70}, ["A4"] = {69}, ["Ab/G# 4"] = {68}, ["G4"] = {67}, ["Gb/F# 4"] = {66}, ["F4"] = {65}, ["E4"] = {64}, ["Eb/D# 4"] = {63}, ["D4"] = {62}, ["Db/C# 4"] = {61}, ["C4 >>>>> (middle C) <<<<<"] = {60}, ["B3"] = {59}, ["Bb/A# 3"] = {58}, ["A3"] = {57}, ["Ab/G# 3"] = {56}, ["G3"] = {55}, ["Gb/F# 3"] = {54}, ["F3"] = {53}, ["E3"] = {52}, ["Eb/D# 3"] = {51}, ["D3"] = {50}, ["Db/C# 3"] = {49}, ["C3"] = {48}, ["B2"] = {47}, ["Bb/A# 2"] = {46}, ["A2"] = {45}, ["Ab/G# 2"] = {44}, ["G2"] = {43}, ["Gb/F# 2"] = {42}, ["F2"] = {41}, ["E2"] = {40}, ["Eb/D# 2"] = {39}, ["D2"] = {38}, ["Db/C# 2"] = {37}, ["C2"] = {36}, ["B1"] = {35}, ["Bb/A# 1"] = {34}, ["A1"] = {33}, ["Ab/G# 1"] = {32}, ["G1"] = {31}, ["Gb/F# 1"] = {30}, ["F1"] = {29}, ["E1"] = {28}, ["Eb/D# 1"] = {27}, ["D1"] = {26}, ["Db/C# 1"] = {25}, ["C1"] = {24}, ["B0"] = {23}, ["Bb/A# 0"] = {22}, ["A0"] = {21} } -- initialize a string list for the user input dialog local popuplist = {} for key,value in pairs(selectNote) do table.insert(popuplist,key) -- Using Lua's table library end -- sort the table according to MIDI note number highest to lowest table.sort(popuplist, function(a,b) local sizetable = selectNote[a] local MIDIa = sizetable[1] local sizetable = selectNote[b] local MIDIb = sizetable[1] if DEBUG0 then print (a,MIDIa,"<= =>",b,MIDIb) end return MIDIb>>>> (middle C) <<<<<") -- default to middle C on the piano returnValues = dialog:Execute() -- returns a table (nil if CANCEL is clicked) if not returnValues then return end -- end script if nil -- save the selected MIDI note number local notetable = selectNote[returnValues[1]] -- retrieve the subtable containig the MIDI note number local MIDINote = notetable[1] if DEBUG1 then print ("Delete MIDI note",MIDINote) end local delCount = 0 for noteentry in eachentrysaved(finenv.Region()) do if DEBUG1 then print ("Notes in noteentry",noteentry.Count) end if noteentry.Count >1 then for note in each(noteentry) do if DEBUG1 then print ("Pitch",note:CalcPitchChar(),note:CalcMIDIKey()) end if note:CalcMIDIKey() == MIDINote then noteentry:DeleteNote(note) delCount = delCount+1 end end end end if DEBUG2 then print ("Total notes deleted",delCount) end