<div dir="ltr">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.<div><br></div><div><div>function plugindef()</div><div> finaleplugin.Author = "Joseph Weidinger"</div><div> finaleplugin.Version = "1.0"</div><div> finaleplugin.Date = "July 08, 2015"</div><div> finaleplugin.RequireSelection = true</div><div> finaleplugin.CategoryTags = "flip, accidental, enharmonic"</div><div> return "Flip Accidentals Enharmonically", "Flip Accidentals Enharmonically", "Toggles sharps to flats or flats to sharps in selected region."</div><div>end</div><div><br></div><div>-- table for checking whether note has accidental</div><div>isAccidentalTbl = {'A#', 'B#', 'C#', 'D#', 'E#', 'F#', 'G#', 'Cb', 'Fb', 'Bb', 'Db', 'Eb', 'Gb', 'Ab'}</div><div><br></div><div>-- conversion tables</div><div>tblOne = {'A#', 'B#', 'C#', 'D#', 'E#', 'F#',</div><div> 'G#', 'Fb', 'Bb', 'Db', 'Eb', 'Gb',</div><div> 'Ab', 'E',</div><div> 'B0', 'B1', 'B2', 'B3', -- to handle the break in octave tranpositions</div><div> 'B4', 'B5', 'B6', 'B7', 'B8', 'B9',</div><div> 'B10', 'B11', 'B12', 'B13', 'Cb1', 'Cb2',</div><div> 'Cb3', 'Cb4', 'Cb5', 'Cb6', 'Cb7', 'Cb8',</div><div> 'Cb9', 'Cb10', 'Cb11', 'Cb12', 'Cb13', 'Cb14'}</div><div>tblTwo = {'Bb', 'C', 'Db', 'Eb', 'F', 'Gb',</div><div> 'Ab', 'E', 'A#', 'C#', 'D#', 'F#',</div><div> 'G#', 'Fb',</div><div> 'Cb1', 'Cb2', 'Cb3', 'Cb4', -- to handle the break in octave tranpositions</div><div> 'Cb5', 'Cb6', 'Cb7', 'Cb8', 'Cb9', 'Cb10',</div><div> 'Cb11', 'Cb12', 'Cb13', 'Cb14', 'B0', 'B1',</div><div> 'B2', 'B3', 'B4', 'B5', 'B6', 'B7',</div><div> 'B8', 'B9', 'B10', 'B11', 'B12', 'B13'}</div><div><br></div><div>-- establish the containers</div><div>local pitchString = finale.FCString()</div><div>local soundingPitchString = finale.FCString()</div><div><br></div><div>-- check whether 'display in concert pitch' is checked or not so that </div><div>-- one can always flip what they see and not be limited to what it's written pitch is</div><div>local partscopeprefs = finale.FCPartScopePrefs()</div><div>partscopeprefs:Load(1)</div><div><br></div><div>if partscopeprefs.DisplayInConcertPitch then</div><div> for entry in eachentrysaved(finenv.Region()) do</div><div> if entry:IsNote() then</div><div> for note in each(entry) do</div><div> note:GetString(soundingPitchString, nil, false, false)</div><div> for k, v in ipairs(isAccidentalTbl) do</div><div> if soundingPitchString:ContainsLuaString(v, nil) then</div><div> for k1, v1 in ipairs(tblOne) do</div><div> if soundingPitchString:ContainsLuaString(v1, nil) then</div><div> soundingPitchString:Replace(tblOne[k1], tblTwo[k1])</div><div> note:SetString(soundingPitchString, nil, false, false)</div><div> entry.CheckAccidentals = true</div><div> break</div><div> end</div><div> end</div><div> break</div><div> end</div><div> end</div><div> end</div><div> end</div><div> end</div><div>else</div><div> for entry in eachentrysaved(finenv.Region()) do</div><div> if entry:IsNote() then</div><div> for note in each(entry) do</div><div> note:GetString(pitchString, nil, false, true)</div><div> note:GetString(soundingPitchString, nil, false, false)</div><div> for k, v in ipairs(isAccidentalTbl) do</div><div> if pitchString:ContainsLuaString(v, nil) then</div><div> for k1, v1 in ipairs(tblOne) do</div><div> if soundingPitchString:ContainsLuaString(v1, nil) then</div><div> soundingPitchString:Replace(tblOne[k1], tblTwo[k1])</div><div> note:SetString(soundingPitchString, nil, false, false)</div><div> entry.CheckAccidentals = true</div><div> break</div><div> end</div><div> end</div><div> break</div><div> end</div><div> end</div><div> end</div><div> end</div><div> end</div><div>end</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 7, 2015 at 12:58 PM, Jari Williamsson <span dir="ltr"><<a href="mailto:jari.williamsson@mailbox.swipnet.se" target="_blank">jari.williamsson@mailbox.swipnet.se</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Joseph,<br>
<br>
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.<br>
<br>
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:<br>
<br>
---<br>
note:SetString(pitchString, nil, false, true)<br>
---<br>
<br>
<br>
Best regards,<br>
<br>
Jari Williamsson<div><div class="h5"><br>
<br>
<br>
On 2015-05-06 16:46, Joseph Weidinger wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
I threw that in there and it still doesn't work though. (below)<br>
Besides not working, it seems to have odd behaviors when run on<br>
transposing instrument lines (change enharmonics that obviously aren't<br>
in the line and meanwhile missing ones that definitely are) although my<br>
forth parameter is "true" in all instances.<br>
<br>
tblOne = {'A#', 'B#', 'C#', 'D#', 'E#', 'F#', 'G#', 'Cb', 'Fb', 'Bb',<br>
'Db', 'Eb', 'Gb', 'Ab'}<br>
tblTwo = {'Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab', 'B', 'E', 'A#', 'C#',<br>
'D#', 'F#', 'G#'}<br>
<br>
local pitchString = finale.FCString()<br>
local originalPitchString = finale.FCString()<br>
<br>
for entry in eachentrysaved(finenv.Region()) do<br>
if entry:IsNote() then<br>
i = 0 --to get the correct item of a chord, if there is one<br>
for note in each(entry) do<br>
note:GetString(pitchString, nil, false, true)<br>
note:GetString(originalPitchString, nil, false, true)<br>
for k, v in ipairs(tblOne) do<br>
if pitchString:ContainsLuaString(v, nil) then<br>
pitchString:Replace(tblOne[k], tblTwo[k])<br>
entry:GetItemAt(i):SetString(pitchstring, nil,<br>
false, true)<br>
entry.CheckAccidentals = true<br>
print('old was', originalPitchString.LuaString,<br>
'and new is', pitchString.LuaString)<br>
break<br>
end<br>
end<br>
i = i + 1<br>
end<br>
end<br>
end<br>
<br>
<br>
<br>
<br>
On Wed, May 6, 2015 at 8:42 AM, Jan Angermüller <<a href="mailto:jan@angermueller.com" target="_blank">jan@angermueller.com</a><br></div></div><div><div class="h5">
<mailto:<a href="mailto:jan@angermueller.com" target="_blank">jan@angermueller.com</a>>> wrote:<br>
<br>
You might need note:SetString ?<br>
<br>
<br>
Am 06.05.2015 um 15:34 schrieb Joseph Weidinger:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
This almost works... It seems to correctly change the note but it<br>
doesn't stick or save. I'm not sure why it doesn't stick as I do<br>
iterate over it with "eachentrysaved" and even have an<br>
entry.CheckAccidentals = true, if that does anything in this<br>
case... What am I missing?<br>
<br>
Thanks!<br>
<br>
tblOne = {'A#', 'B#', 'C#', 'D#', 'E#', 'F#', 'G#', 'Cb', 'Fb',<br>
'Bb', 'Db', 'Eb', 'Gb', 'Ab'}<br>
tblTwo = {'Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab', 'B', 'E', 'A#',<br>
'C#', 'D#', 'F#', 'G#'}<br>
<br>
local pitchString = finale.FCString()<br>
local originalPitchString = finale.FCString()<br>
<br>
for entry in eachentrysaved(finenv.Region()) do<br>
if entry:IsNote() then<br>
for note in each(entry) do<br>
note:GetString(pitchString, nil, false, true)<br>
note:GetString(originalPitchString, nil, false, true)<br>
for k, v in ipairs(tblOne) do<br>
if pitchString:ContainsLuaString(v, nil) then<br>
pitchString:Replace(tblOne[k], tblTwo[k])<br>
print("The pitch",<br>
originalPitchString.LuaString, "was changed to",<br>
pitchString.LuaString)<br>
break<br>
end<br>
end<br>
end<br>
end<br>
entry.CheckAccidentals = true<br>
end<br>
<br>
<br>
<br>
_______________________________________________<br>
JWLua mailing list<br></div></div>
<a href="mailto:JWLua@jwmusic.nu" target="_blank">JWLua@jwmusic.nu</a> <mailto:<a href="mailto:JWLua@jwmusic.nu" target="_blank">JWLua@jwmusic.nu</a>><br>
<a href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu" rel="noreferrer" target="_blank">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a><br>
</blockquote><span class="">
<br>
<br>
--<br>
Jan Angermüller<br>
Jevenstedter Str. 80<br>
22547 Hamburg<br>
Tel. 040 - 28 94 84 82<br></span>
<a href="http://www.angermueller.com" rel="noreferrer" target="_blank">www.angermueller.com</a> <<a href="http://www.angermueller.com" rel="noreferrer" target="_blank">http://www.angermueller.com</a>><br>
<br>
<br>
_______________________________________________<br>
JWLua mailing list<br>
<a href="mailto:JWLua@jwmusic.nu" target="_blank">JWLua@jwmusic.nu</a> <mailto:<a href="mailto:JWLua@jwmusic.nu" target="_blank">JWLua@jwmusic.nu</a>><br>
<a href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu" rel="noreferrer" target="_blank">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a><span class=""><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
JWLua mailing list<br>
<a href="mailto:JWLua@jwmusic.nu" target="_blank">JWLua@jwmusic.nu</a><br>
<a href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu" rel="noreferrer" target="_blank">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a><br>
<br>
</span></blockquote><div class="HOEnZb"><div class="h5">
<br>
<br>
<br>
_______________________________________________<br>
JWLua mailing list<br>
<a href="mailto:JWLua@jwmusic.nu" target="_blank">JWLua@jwmusic.nu</a><br>
<a href="http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu" rel="noreferrer" target="_blank">http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu</a><br>
</div></div></blockquote></div><br></div>