[JW Lua] Vocal compass
Mr.Pat
Mr.Pat at pdreditions.com
Fri May 13 19:34:19 CEST 2016
Here's my first attempt. My work is with choral music so this plugin applies
to choral scores. It scans the selected region to find the highest, lowest,
and mean notes in the selected staves. It then displays them in the first
measure of the staff. It assumes that there is at least one note in the
first measure already. All of my templates are set up like that. The plugin
works as it is, but I think there is a more efficient way to get the notes
placed in the first measure. Suggestions welcomed.
Pat
function plugindef()
-- This function and the 'finaleplugin' namespace
-- are both reserved for the plug-in definition.
finaleplugin.RequireScore = true
finaleplugin.RequireSelection = true
finaleplugin.MinFinaleVersion = "2012"
finaleplugin.MinJWLuaVersion = "0.45"
finaleplugin.Author = "PDR Editions"
finaleplugin.Copyright = "2016"
finaleplugin.Version = "1.0"
finaleplugin.Date = "5/11/2016"
finaleplugin.AuthorURL = "www.pdreditions.com"
finaleplugin.AuthorEmail = "Mr.Pat at pdreditions.com"
finaleplugin.CategoryTags = "Chord, Measure, MIDI, Note, Pitch, Region,
Staff"
return "Find Ranges", "Find Range", "Finds highest, lowest, and median
range"
end
-- Use sounding pitch
local written_pitch = false
-- Table MIDI notes for each staff
local lowestnotes = {}
local highestnotes = {}
local midnotes = {}
local notecount = {}
local staff = {}
local region = finenv.Region()
for slot = region.StartSlot, region.EndSlot do
staff[region:CalcStaffNumber(slot)] = slot
end
for entry in eachentry(region) do
if entry:IsNote() then
-- Get the staff number where the entry is placed
local staffnumber = entry.Staff
-- skip the first measure
if entry.Measure >1 then
-- 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()
-- See if the note is lowest on the staff
if not lowestnotes[staffnumber] or lowestnotes[staffnumber] >
midikeynumber then
lowestnotes[staffnumber] = midikeynumber
end
-- See if the note is the highest on the staff
if not highestnotes[staffnumber] or highestnotes[staffnumber] <
midikeynumber then
highestnotes[staffnumber] = midikeynumber
end
-- Add the note to midnotes
if not midnotes[staffnumber] then
midnotes[staffnumber] = midikeynumber
else
midnotes[staffnumber] = midnotes[staffnumber] + midikeynumber
end
if not notecount[staffnumber] then
notecount[staffnumber] = 1
else
notecount[staffnumber] = notecount[staffnumber] + 1
end
end
end
end
end
-- Add new notes to each staff as needed. Assume at least one existing note
local staffnum
local slotnum
for staffnum, slotnum in pairs(staff) do
noteentrycell = finale.FCNoteEntryCell(region.StartMeasure, staffnum)
noteentrycell:Load()
for noteentry in each(noteentrycell) do
for i = noteentry.Count, 2, 1 do
noteentry:AddNewNote()
end
end
noteentrycell:Save()
end
-- Set the values for each note
for staffnum, slotnum in pairs(staff) do
noteentrycell = finale.FCNoteEntryCell(region.StartMeasure, staffnum)
noteentrycell:Load()
local noteentry = noteentrycell:GetItemAt(0)
local note = noteentry:GetItemAt(0)
note:SetMIDIKey(math.floor(midnotes[staffnum]/notecount[staffnum] + .5))
note.Playback = false
note = noteentry:GetItemAt(1)
note:SetMIDIKey(highestnotes[staffnum])
note.Playback = false
note = noteentry:GetItemAt(2)
note:SetMIDIKey(lowestnotes[staffnum])
note.Playback = false
noteentry.CheckAccidentals = true
noteentrycell:Save()
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20160513/1dd15dab/attachment.htm>
More information about the JWLua
mailing list