[JW Lua] flip accidentals in selected regions
Joseph Weidinger
jsphweid at gmail.com
Wed Jul 8 23:40:01 CEST 2015
Thanks. Of course that opened up a bunch of other problems with my script
but I managed to figure them out eventually without asking more questions
(it was tough to restrain myself...). Here's the completed script. I think
it works quite well! Let me know if anyone finds any more bugs. I'm also
trying to find a better name. "Flip accidentals" might imply literally
flipping the sign upside. So now I have "flip accidentals enharmonically"
but I still think it is not ideal. Let me know if you have a better idea
for a name...! Code below, cheers, thanks again Jari.
function plugindef()
finaleplugin.Author = "Joseph Weidinger"
finaleplugin.Version = "1.0"
finaleplugin.Date = "July 08, 2015"
finaleplugin.RequireSelection = true
finaleplugin.CategoryTags = "flip, accidental, enharmonic"
return "Flip Accidentals Enharmonically", "Flip Accidentals
Enharmonically", "Toggles sharps to flats or flats to sharps in selected
region."
end
-- table for checking whether note has accidental
isAccidentalTbl = {'A#', 'B#', 'C#', 'D#', 'E#', 'F#', 'G#', 'Cb', 'Fb',
'Bb', 'Db', 'Eb', 'Gb', 'Ab'}
-- conversion tables
tblOne = {'A#', 'B#', 'C#', 'D#', 'E#', 'F#',
'G#', 'Fb', 'Bb', 'Db', 'Eb', 'Gb',
'Ab', 'E',
'B0', 'B1', 'B2', 'B3', -- to handle the break in octave
tranpositions
'B4', 'B5', 'B6', 'B7', 'B8', 'B9',
'B10', 'B11', 'B12', 'B13', 'Cb1', 'Cb2',
'Cb3', 'Cb4', 'Cb5', 'Cb6', 'Cb7', 'Cb8',
'Cb9', 'Cb10', 'Cb11', 'Cb12', 'Cb13', 'Cb14'}
tblTwo = {'Bb', 'C', 'Db', 'Eb', 'F', 'Gb',
'Ab', 'E', 'A#', 'C#', 'D#', 'F#',
'G#', 'Fb',
'Cb1', 'Cb2', 'Cb3', 'Cb4', -- to handle the break in octave
tranpositions
'Cb5', 'Cb6', 'Cb7', 'Cb8', 'Cb9', 'Cb10',
'Cb11', 'Cb12', 'Cb13', 'Cb14', 'B0', 'B1',
'B2', 'B3', 'B4', 'B5', 'B6', 'B7',
'B8', 'B9', 'B10', 'B11', 'B12', 'B13'}
-- establish the containers
local pitchString = finale.FCString()
local soundingPitchString = finale.FCString()
-- check whether 'display in concert pitch' is checked or not so that
-- one can always flip what they see and not be limited to what it's
written pitch is
local partscopeprefs = finale.FCPartScopePrefs()
partscopeprefs:Load(1)
if partscopeprefs.DisplayInConcertPitch then
for entry in eachentrysaved(finenv.Region()) do
if entry:IsNote() then
for note in each(entry) do
note:GetString(soundingPitchString, nil, false, false)
for k, v in ipairs(isAccidentalTbl) do
if soundingPitchString:ContainsLuaString(v, nil) then
for k1, v1 in ipairs(tblOne) do
if soundingPitchString:ContainsLuaString(v1,
nil) then
soundingPitchString:Replace(tblOne[k1],
tblTwo[k1])
note:SetString(soundingPitchString, nil,
false, false)
entry.CheckAccidentals = true
break
end
end
break
end
end
end
end
end
else
for entry in eachentrysaved(finenv.Region()) do
if entry:IsNote() then
for note in each(entry) do
note:GetString(pitchString, nil, false, true)
note:GetString(soundingPitchString, nil, false, false)
for k, v in ipairs(isAccidentalTbl) do
if pitchString:ContainsLuaString(v, nil) then
for k1, v1 in ipairs(tblOne) do
if soundingPitchString:ContainsLuaString(v1,
nil) then
soundingPitchString:Replace(tblOne[k1],
tblTwo[k1])
note:SetString(soundingPitchString, nil,
false, false)
entry.CheckAccidentals = true
break
end
end
break
end
end
end
end
end
end
On Tue, Jul 7, 2015 at 12:58 PM, Jari Williamsson <
jari.williamsson at mailbox.swipnet.se> wrote:
> Joseph,
>
> Lua is case sensitive. FCNote:SetString() in your sample code returned
> false, since you didn't use the correct name of string variable as the
> first parameter.
>
> Furthermore, you don't need to use the index if you use the iterator
> each(). You can remove any lines reffering to the "i" variable in your
> code. Instead, just reference the note object. So, changing the SetString()
> line to the one below should solve it:
>
> ---
> note:SetString(pitchString, nil, false, true)
> ---
>
>
> Best regards,
>
> Jari Williamsson
>
>
>
> On 2015-05-06 16:46, Joseph Weidinger wrote:
>
>> I threw that in there and it still doesn't work though. (below)
>> Besides not working, it seems to have odd behaviors when run on
>> transposing instrument lines (change enharmonics that obviously aren't
>> in the line and meanwhile missing ones that definitely are) although my
>> forth parameter is "true" in all instances.
>>
>> tblOne = {'A#', 'B#', 'C#', 'D#', 'E#', 'F#', 'G#', 'Cb', 'Fb', 'Bb',
>> 'Db', 'Eb', 'Gb', 'Ab'}
>> tblTwo = {'Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab', 'B', 'E', 'A#', 'C#',
>> 'D#', 'F#', 'G#'}
>>
>> local pitchString = finale.FCString()
>> local originalPitchString = finale.FCString()
>>
>> for entry in eachentrysaved(finenv.Region()) do
>> if entry:IsNote() then
>> i = 0 --to get the correct item of a chord, if there is one
>> for note in each(entry) do
>> note:GetString(pitchString, nil, false, true)
>> note:GetString(originalPitchString, nil, false, true)
>> for k, v in ipairs(tblOne) do
>> if pitchString:ContainsLuaString(v, nil) then
>> pitchString:Replace(tblOne[k], tblTwo[k])
>> entry:GetItemAt(i):SetString(pitchstring, nil,
>> false, true)
>> entry.CheckAccidentals = true
>> print('old was', originalPitchString.LuaString,
>> 'and new is', pitchString.LuaString)
>> break
>> end
>> end
>> i = i + 1
>> end
>> end
>> end
>>
>>
>>
>>
>> On Wed, May 6, 2015 at 8:42 AM, Jan Angermüller <jan at angermueller.com
>> <mailto:jan at angermueller.com>> wrote:
>>
>> You might need note:SetString ?
>>
>>
>> Am 06.05.2015 um 15:34 schrieb Joseph Weidinger:
>>
>>> This almost works... It seems to correctly change the note but it
>>> doesn't stick or save. I'm not sure why it doesn't stick as I do
>>> iterate over it with "eachentrysaved" and even have an
>>> entry.CheckAccidentals = true, if that does anything in this
>>> case... What am I missing?
>>>
>>> Thanks!
>>>
>>> tblOne = {'A#', 'B#', 'C#', 'D#', 'E#', 'F#', 'G#', 'Cb', 'Fb',
>>> 'Bb', 'Db', 'Eb', 'Gb', 'Ab'}
>>> tblTwo = {'Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab', 'B', 'E', 'A#',
>>> 'C#', 'D#', 'F#', 'G#'}
>>>
>>> local pitchString = finale.FCString()
>>> local originalPitchString = finale.FCString()
>>>
>>> for entry in eachentrysaved(finenv.Region()) do
>>> if entry:IsNote() then
>>> for note in each(entry) do
>>> note:GetString(pitchString, nil, false, true)
>>> note:GetString(originalPitchString, nil, false, true)
>>> for k, v in ipairs(tblOne) do
>>> if pitchString:ContainsLuaString(v, nil) then
>>> pitchString:Replace(tblOne[k], tblTwo[k])
>>> print("The pitch",
>>> originalPitchString.LuaString, "was changed to",
>>> pitchString.LuaString)
>>> break
>>> end
>>> end
>>> end
>>> end
>>> entry.CheckAccidentals = true
>>> end
>>>
>>>
>>>
>>> _______________________________________________
>>> JWLua mailing list
>>> JWLua at jwmusic.nu <mailto:JWLua at jwmusic.nu>
>>> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>>>
>>
>>
>> --
>> Jan Angermüller
>> Jevenstedter Str. 80
>> 22547 Hamburg
>> Tel. 040 - 28 94 84 82
>> www.angermueller.com <http://www.angermueller.com>
>>
>>
>> _______________________________________________
>> JWLua mailing list
>> JWLua at jwmusic.nu <mailto:JWLua at jwmusic.nu>
>> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>>
>>
>>
>>
>> _______________________________________________
>> JWLua mailing list
>> JWLua at jwmusic.nu
>> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>>
>>
>
>
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20150708/8b455d03/attachment.htm>
More information about the JWLua
mailing list