-- Use sounding pitch local written_pitch = false -- Table with highest/lowest MIDI notes for each staff local lowestnotes = {} local highestnotes = {} -- Tables with the pitch strings for highest/lowest notes local lowestnotestrings = {} local highestnotestrings = {} local region = finenv.Region() -- Use a single object for the string pitch result (=faster) local pitchstring = finale.FCString() for entry in eachentry(region) do if entry:IsNote() then -- Get the staff number where the entry is placed local staffnumber = entry.Staff -- Parse through all notes in the note entry (=chord) for note in each(entry) do -- Use the enharmonic MIDI note to check the pitch local midikeynumber = note:CalcMIDIKey() -- Fill the FCString object that represent the pitch string note:GetString (pitchstring, nil, false, written_pitch) -- See if the note is lowest on the staff if not lowestnotes[staffnumber] or lowestnotes[staffnumber] > midikeynumber then lowestnotes[staffnumber] = midikeynumber lowestnotestrings[staffnumber] = pitchstring.LuaString end -- See if the note is the highest on the staff if not highestnotes[staffnumber] or highestnotes[staffnumber] < midikeynumber then highestnotes[staffnumber] = midikeynumber highestnotestrings[staffnumber] = pitchstring.LuaString end end end end -- Statistics output for k, v in pairs(lowestnotes) do -- Construct a staff name to display local staff = finale.FCStaff() staff:Load(k) local namestr = staff:CreateDisplayFullNameString() local fullstaffname = namestr.LuaString if fullstaffname == "" then fullstaffname = "#" .. k end -- Display the statistics for a staff print (fullstaffname, "- lowest note", lowestnotestrings[k], " highest note", highestnotestrings[k]) end