[JW Lua] flip accidentals in selected regions

Jari Williamsson jari.williamsson at mailbox.swipnet.se
Tue Jul 7 19:58:42 CEST 2015


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
>






More information about the JWLua mailing list