The original version of this page can be found at : http://forum.makemusic.com/default.aspx?f=11&m=450816
Posted By : Motet - 3/26/2015 5:27 PM
I'm writing my first JW Lua script, to put double barlines at key- and time-signature changes.

allmeasures = finale.FCMeasures()
allmeasures:LoadAll()
lastmeasure = finale.FCMeasure()
for measure in each(allmeasures) do
    if measure.ItemNo > 1 then
        if not measure.TimeSignature:IsIdentical(lastmeasure.TimeSignature)
        or not measure.KeySignature:IsIdentical(lastmeasure.KeySignature)
        then
            lastmeasure.Barline = finale.BARLINE_DOUBLE
            lastmeasure:Save()
        end
    end
    lastmeasure = measure
end


It's getting the error

[string "allmeasures = finale.FCMeasures() ..."]:6: attempt to index field 'TimeSignature' (a userdata value)

What am I doing wrong?


Finale 2011b, 2005, TGTools
Windows 7, MIDI input
Finale Transposition Chart

Post Edited (Motet) : 3/26/2015 5:59:32 PM (GMT-5)


Posted By : Motet - 3/26/2015 6:08 PM
If I try this instead

if not measure.GetTimeSignature():IsIdentical(lastmeasure.TimeSignature)


I get "[string "allmeasures = finale.FCMeasures() ..."]:6: bad argument #1 to 'GetTimeSignature' (FCMeasure expected, got table)"

Does "each()" produce a table rather than a FCMeasure?


Finale 2011b, 2005, TGTools
Windows 7, MIDI input
Finale Transposition Chart


Posted By : Jari Williamsson - 3/27/2015 3:31 AM
Your script was almost correct. each() indeed produces FCMeasure objects in your script.

TimeSignature is a property and should be preceeded with a '.'

GetTimeSignature() and IsIdentical() are method calls and should be preceeded with a ':'

This version should work:

local allmeasures = finale.FCMeasures()
allmeasures:LoadAll()
lastmeasure = finale.FCMeasure()
for measure in each(allmeasures) do
    if measure.ItemNo > 1 then
        if not measure.TimeSignature:IsIdentical(lastmeasure.TimeSignature)
        or not measure.KeySignature:IsIdentical(lastmeasure.KeySignature)
        then
            lastmeasure.Barline = finale.BARLINE_DOUBLE
            lastmeasure:Save()
        end
    end
    lastmeasure = measure
end


Jari Williamsson

Windows XP, Pentium 4
2.40 GHz, 4 GB RAM

www.finaletips.nu - The Finale Productivity Tips site

Post Edited (Jari Williamsson) : 3/27/2015 3:34:36 AM (GMT-5)


Posted By : Motet - 3/27/2015 10:55 AM
Except for the "local", that's what I had in my original posting, and I still get

[string "local allmeasures = finale.FCMeasures() ..."]:6: attempt to index field 'TimeSignature' (a userdata value).

I suspect I don't have the latest versions of everything. Will investigate.


Finale 2011b, 2005, TGTools
Windows 7, MIDI input
Finale Transposition Chart

Post Edited (Motet) : 3/27/2015 11:00:49 AM (GMT-5)


Posted By : Motet - 3/27/2015 12:00 PM
D-oh! I just needed the latest JW Lua. Since JW Plug-in Manager doesn't manage it I had never updated it. Thanks for your help and sorry for the false alarm. I am excited to be learning this and predict great things to be gained.

Is there access to the displayed time signature, by the way? Since I rarely use that, it's no big deal if not, but ideally these double barlines are based on what the player sees, not the underlying Finale time signatures. Conceivably, one could have a split measure or something.


Finale 2011b, 2005, TGTools
Windows 7, MIDI input
Finale Transposition Chart

Post Edited (Motet) : 3/27/2015 12:04:04 PM (GMT-5)


Posted By : Jari Williamsson - 3/27/2015 5:48 PM
Motet said...
Is there access to the displayed time signature, by the way? Since I rarely use that, it's no big deal if not, but ideally these double barlines are based on what the player sees, not the underlying Finale time signatures. Conceivably, one could have a split measure or something.


These FCMeasure properties should work:
FCMeasure.UseTimeSigForDisplay (boolean)
FCMeasure.TimeSignatureForDisplay (FCTimeSignature object)


Jari Williamsson

Windows XP, Pentium 4
2.40 GHz, 4 GB RAM

www.finaletips.nu - The Finale Productivity Tips site


Posted By : Motet - 3/27/2015 8:07 PM
Thanks, Jari!


Finale 2011b, 2005, TGTools
Windows 7, MIDI input
Finale Transposition Chart


Posted By : Motet - 3/29/2015 4:33 PM
Jari,

Looks like FCNote:GetString() doesn't observe "simplify key" in the transposition. For example, in the concert key of F# major, the Bb Clarinet's key signature would be Ab major, and GetString() returns "E#" for a written F. Any work-around?

(If you would prefer I take my questions to the mailing list, I'm happy to do so.)


Finale 2011b, 2005, TGTools
Windows 7, MIDI input
Finale Transposition Chart


Posted By : Charles Lawrence - 3/30/2015 10:05 AM
Motet said...

(If you would prefer I take my questions to the mailing list, I'm happy to do so.)

That would be better, as it is the de facto clearing house for all things JW Lua related, not this forum.  Besides, there are list members who do not look at this forum.


"Anything is possible if you don't know what you are talking about!"

 

Intel(R) Core(TM) i7-5930K CPU with 6 dual core processors @ 3.50 GHz (12 threads)

Realtek High Definition on board audio
NVIDIA GeForce GTX 980 GPU with 4GB ram

512 GB SSD

Four 4TB and one 1TB internal SATA HD's
Microsoft Windows 8.1 Professional with Media Center x64 Edition, (06.03.9600.00)
Finale versions: 2011b.r2, 2012c.r13, 2014d.v5030

GPO4.02

 

Cakewalk SONAR X3

 

"There is a world of difference between a person who has a big problem and a person who makes a problem big." – John Maxwell


Posted By : Motet - 3/30/2015 12:17 PM
I have done so.


Finale 2011b, 2005, TGTools
Windows 7, MIDI input
Finale Transposition Chart