Skip to main content
Topic: Audit Bar Lines tool (Read 9721 times) previous topic - next topic

Audit Bar Lines tool

The Audit Bar Lines tool that NWC provides assumes the note lengths are correct and it will move the bar lines if necessary.
This tool assumes the bar lines are correct and will point out the measures that are short or long in beats defined by the most recent Time Signature.

After downloading this file, please remove the .txt from the end of the file name.

I'll submit it to Scriptorium in a few weeks after I can check feedback.

*** Attachment replaced 12/21/2023. ***
Latest changes: Does not count bar lines excluded from count or empty measures.
*** Attachment replaced 12/22/2023. ***
*** Attachment replaced 12/24/2023. ***
Multi measure rests, Whole rest by itself works for any time signature.
*** Attachment replaced 01/01/2024 ***
Better documentation--cleaned up potential bug.
*** Attachment replaced 01/22/2024 ***
Selecting part of staff just before a bar line could throw the measure count off.
*** Attachment replaced 01/30/2024 ***
Line 96, changing "whole note" to "whole rest"
*** Attachment replaced 03/31/2024 ***
Since 1998

Re: Audit Bar Lines tool

Reply #1
Hi Warren, I like.

The only change I can think of that might be helpful is a negative result alert...

I.E. when you run the tool and there are no problems, you just get the dialogue with no content.  It would add confidence to the result if there was a line that said something like "No problems were detected", or something like that.
I plays 'Bones, crumpets, coronets, floosgals, youfonymums 'n tubies.

Re: Audit Bar Lines tool

Reply #2
Maybe an option to change the color of the misplaced bar lines?
Probably not particularly visible, but easily searchable.

Re: Audit Bar Lines tool

Reply #3
The comments in the tool say that it does not modify the staff, so I would think that changing color of the bar lines (or something like that) would be a significant design change.

Re: Audit Bar Lines tool

Reply #4
There is an expression "I do my best proofreading right after I hit SEND".  I had a variable "foundError" maintained for that but forget to use it at the end. It also doesn't handle Common or Cut time yet. If it is in 9/8 time, should it report the difference in 8ths or dotted quarters?

It could report the result with a red text message that could be easily be deleted when that measure is corrected. This is in the new version.

Feedback welcome.

Put the following just before "return lines":
Code: [Select · Download]
  if (!foundError)
  errMsg="No errors found!";
Since 1998


Re: Audit Bar Lines tool

Reply #6
I have replaced the attachment in the initial post. There is also a prompt--Please edit the end of the command line for this tool to end in "  <PROMPT:Summarize?:=|Y|N>" after you replace the original script.   It will follow "auditBar.js".
Since 1998

Re: Audit Bar Lines tool

Reply #7
The comments in the tool say that it does not modify the staff, so I would think that changing color of the bar lines (or something like that) would be a significant design change.
Rick G pointed me in the right direction about a framework for JavaScript scripts. My scripts start near the bottom (line 103 in this script) with NWC giving the script the nwctxt version of the staff or selected part of it. In the calculate() function, the nwctxt is broken down into an array named lines which is usually modified in some way. The variables rc and errMsg are global so any function can read or modify them. If the Return Code is zero, lines will replace what was passed to the script while any other value else will pass the contents of errMsg to NWC where it will be displayed to the user.

I have had my share of projects where a seemingly trivial change turned into a major undertaking, but fortunately this wasn't one of them . . . . .yet.
Since 1998

Re: Audit Bar Lines tool

Reply #8
Hi Warren,
have a snippet from a staff that gives some errors...
Code: (nwc) [Select · Download]
!NoteWorthyComposerClip(2.751,Single)
|TimeSig|Signature:4/4
|Note|Dur:4th|Pos:1
|Rest|Dur:4th
|Note|Dur:4th|Pos:-2
|Rest|Dur:4th
|Bar
|Note|Dur:Half|Pos:-9
|Note|Dur:4th|Pos:-6
|Rest|Dur:4th
|Bar
|Note|Dur:4th|Pos:-6
|Note|Dur:4th|Pos:-2
|Note|Dur:8th|Pos:-2|Opts:Stem=Up,Beam=First
|Note|Dur:8th|Pos:-6^|Opts:Stem=Up,Beam=End
|Note|Dur:4th|Pos:-6
|Bar
|TimeSig|Signature:2/4
|Note|Dur:Half|Pos:-9
|Bar|Style:MasterRepeatClose
|TimeSig|Signature:4/4
|Note|Dur:4th|Pos:-6
|Rest|Dur:4th
|Rest|Dur:Half
|Bar|Style:SectionClose|SysBreak:Y
!NoteWorthyComposerClip-End

If you run the tool over the whole staff, you get a "too few" in the last bar.
If you run the tool over the 2/4 bar you get:
No errors if you don't include the closing barline
If you DO include the barline you get:"Measure 1 too few: 2 beats
If you have an empty bar prior to the repeat barline (I was testing stuff and this happened) you get both bar 4 and 6 with a too few error.  NB the empty bar 5 would not be counted by NWC, I recommend your tool do the same or the bar numbering will get out of step.

I also suggest bars that are empty or have no durational objects in them be excluded a la the way barlines explicitly excluded from numbering are handled.  E.G. I often use a construct like this (the section immediately following the system break):
Code: (nwc) [Select · Download]
!NoteWorthyComposerClip(2.751,Single)
|Text|Text:"Bm7"|Font:User6|Pos:12
|Note|Dur:8th|Pos:-3|Opts:Stem=Up,Beam=First
|Note|Dur:8th|Pos:#-4|Opts:Stem=Up,Beam=End
|Note|Dur:4th|Pos:-3
|Text|Text:"E7"|Font:User6|Pos:12
|Note|Dur:4th|Pos:-2
|Note|Dur:4th|Pos:-2
|Bar
|Text|Text:"Bm7"|Font:User6|Pos:12
|Note|Dur:8th|Pos:-3
|Note|Dur:4th|Pos:-3
|Note|Dur:8th|Pos:-2^
|Text|Text:"E7"|Font:User6|Pos:12
|Note|Dur:8th|Pos:-2
|Note|Dur:4th|Pos:-3
|Note|Dur:8th|Pos:-3
|Flow|Style:ToCoda|Pos:16|Justify:Right|Placement:AtNextNote
|Bar|Style:Double
|Text|Text:"Bm7"|Font:User6|Pos:12
|Note|Dur:4th|Pos:-4
|Note|Dur:4th|Pos:#-4
|Text|Text:"E7"|Font:User6|Pos:12
|Note|Dur:4th|Pos:-3
|Note|Dur:8th|Pos:-9|Opts:Stem=Up,Beam=First
|Note|Dur:8th|Pos:-8^|Opts:Stem=Up,Beam=End
|Bar
|Text|Text:"A6"|Font:User6|Pos:12
|Note|Dur:Half|Pos:-8
|Text|Text:"E7"|Font:User6|Pos:12
|Rest|Dur:Half
|Flow|Style:DSalCoda|Pos:16.5|Justify:Right|Placement:AtNextNote
|Clef|Type:Treble|AutoSys:N|Visibility:Never
|Key|Signature:F#,C#,G#|Tonic:A|HideCancels:Y|AutoSys:N|Visibility:Never
|Bar|Style:Double|SysBreak:Y
|Boundary|Style:Gap|Width:200|SystemConnections:N
|Flow|Style:Coda|Pos:-2.5|Visibility:Always
|Boundary|Style:Gap|Width:600|SystemConnections:N
|Clef|Type:Treble
|Key|Signature:F#,C#,G#|Tonic:A
|Text|Text:"Bm7"|Font:User6|Pos:12
|Note|Dur:4th|Pos:-4
|Rest|Dur:4th
|Note|Dur:4th|Pos:#-4
|Rest|Dur:4th
|Bar
|Text|Text:"E7"|Font:User6|Pos:12
|Note|Dur:4th|Pos:-3
|Rest|Dur:4th
|Note|Dur:4th|Pos:-2
|Rest|Dur:8th
|Note|Dur:8th,Slur|Pos:0^
|Bar
|Text|Text:"A6"|Font:User6|Pos:12
|Note|Dur:4th,Slur|Pos:0
|Note|Dur:Half,Dotted|Pos:-1^
|Bar|SysBreak:Y
|Text|Text:"F#m"|Font:User6|Pos:12
|Marker|Pos:6.5
|Note|Dur:Whole|Pos:-1^
|Bar
|Text|Text:"D"|Font:User6|Pos:12
|Marker|Pos:0.5
|RestChord|Dur:Half|Opts:Stem=Down,ArticulationsOnStem,HideRest|Dur2:Whole|Pos2:-1^
|Text|Text:"Bm"|Font:User6|Pos:12
|Marker|Pos:0
|Rest|Dur:Half|Opts:VertOffset=-2000
|Bar
|Text|Text:"E7"|Font:User6|Pos:12
|Marker|Pos:0.5
|Note|Dur:4th,Dotted|Pos:-1^
|Text|Text:"A"|Font:User6|Pos:11.5
|Marker|Pos:4
|Note|Dur:8th|Pos:-1
|Rest|Dur:Half
!NoteWorthyComposerClip-End

I also use transparent bars to aid object placement and force system breaks with an open staff:
Code: (nwc) [Select · Download]
!NoteWorthyComposerClip(2.751,Single)
|TimeSig|Signature:4/4
|Note|Dur:4th|Pos:1
|Rest|Dur:4th
|Note|Dur:4th|Pos:-2
|Rest|Dur:4th
|Bar
|Note|Dur:Half|Pos:-9
|Note|Dur:4th|Pos:-6
|Rest|Dur:4th
|Bar
|Note|Dur:4th|Pos:-6
|Note|Dur:4th|Pos:-2
|Note|Dur:8th|Pos:-2|Opts:Stem=Up,Beam=First
|Note|Dur:8th|Pos:-6^|Opts:Stem=Up,Beam=End
|Note|Dur:4th|Pos:-6
|Bar
|TimeSig|Signature:2/4
|Bar|Style:Transparent|SysBreak:Y
|TimeSig|Signature:2/4
|Note|Dur:Half|Pos:-9
|Bar|Style:MasterRepeatClose
|TimeSig|Signature:4/4
|Note|Dur:4th|Pos:-6
|Rest|Dur:4th
|Rest|Dur:Half
!NoteWorthyComposerClip-End
I plays 'Bones, crumpets, coronets, floosgals, youfonymums 'n tubies.

Re: Audit Bar Lines tool

Reply #9
Thank you for looking at it.
 I am changing line 86 to the following:
Code: [Select · Download]
		if (diff != 0 && sumNotes !=0) {    // Change 1 since 1st replacement script 
The variable sumNotes will be zero for an empty measure.

Also on line 43, I am changing the default value of num and denom to 4 each for a default 4/4 time signature.

When I ran the script with the above changes against each of your snippets, it did not find any errors.

On line 68, please change \n+ to \d+

To not count bars excluded from line count, these next three lines replace line 92:
Code: [Select · Download]
		sumNotes=0;                                 // Change 2 since 1st replacement script 
if (lines[i].indexOf("XBarCnt:Y") == -1)    // Change 2 since 1st replacement script
barNum++;                             // Change 2 since 1st replacement script
Since 1998

Re: Audit Bar Lines tool

Reply #10
Hi Warren,
I've applied the changes you specified.  At least, I think I got them right... and things are better, but I still found a problem:
Code: (nwc) [Select · Download]
!NoteWorthyComposerClip(2.751,Single)
|TimeSig|Signature:4/4
|Note|Dur:4th|Pos:1
|Rest|Dur:4th
|Note|Dur:4th|Pos:-2
|Rest|Dur:4th
|Bar
|Note|Dur:Half|Pos:-9
|Note|Dur:4th|Pos:-6
|Rest|Dur:4th
|Bar
|Note|Dur:4th|Pos:-6
|Note|Dur:4th|Pos:-2
|Note|Dur:8th|Pos:-2|Opts:Stem=Up,Beam=First
|Note|Dur:8th|Pos:-6^|Opts:Stem=Up,Beam=End
|Note|Dur:4th|Pos:-6
|Bar
|TimeSig|Signature:2/4
|Note|Dur:Half|Pos:-9
|Bar
|Bar|Style:MasterRepeatClose
|TimeSig|Signature:4/4
|Note|Dur:4th|Pos:-6
|Rest|Dur:Half
|Bar|Style:SectionClose|SysBreak:Y
!NoteWorthyComposerClip-End

The second last bar has 2* "closing" barlines - a normal one and a master repeat close, effectively creating an empty bar between them.  This bar is still being counted.  To prove this I deliberately removed a crotchet rest from the last bar and the report is telling me the faulty bar is bar 6, but it should be reported as bar 5 because the empty bar should not be counted, all same as NWC
I plays 'Bones, crumpets, coronets, floosgals, youfonymums 'n tubies.

Re: Audit Bar Lines tool

Reply #11
This should fix that problem. sumNotes would be zero for an empty measure so I am checking it as well as Exclude from Bar Count before incrementing the bar number. Also postponed the zeroing of sumNotes for the next bar.

This replaces lines 92-94:
Code: [Select · Download]
		if (lines[i].indexOf("XBarCnt:Y") == -1 && sumNotes > 0)    // Change 3 since 1st replacement script 
barNum++;                                             // Change 3 since 1st replacement script
sumNotes=0;                                                 // Change 3 since 1st replacement script
Since 1998

Re: Audit Bar Lines tool

Reply #12
That looks like it's worked just fine, thanks Warren.
I plays 'Bones, crumpets, coronets, floosgals, youfonymums 'n tubies.

Re: Audit Bar Lines tool

Reply #13
Attached file in first post replaced 12/22/2023 0956 CST.
Since 1998

Re: Audit Bar Lines tool

Reply #14
Hi Warren,

I really like this tool. I can see how useful it could be. However, I ran into a situation.

In the attached clip I'm using a whole rest for one of the measure after the 3/4 time signature change.  The tool is returning a value that there is an extra beat (8th measure). It doesn't have the same behavior when the whole rest is after the 4/4 time signature. Is there a way to code the tool to recognize that the use of a whole rest in any time signature represents a rest for the entire measure?

 

Re: Audit Bar Lines tool

Reply #15
Good point! I think it can be corrected by adding the following after line 81:
Code: [Select · Download]
		if (durLen == 768 && lines[i].substr(0,5) == "|Rest" && lines[i-1].substr(0,4) == "|Bar" && lines[i+1].substr(0,4) == "|Bar") // Find only whole rest in bar?
durLen = targetMeasure; // Found | wh rest |

Am trying to implement multi-measure rests, but will have to tackle that next year.

** I replaced the script in the first post. Will check it out further after New Year's Day. MC & HNY **
Since 1998

Re: Audit Bar Lines tool

Reply #16
I think I can put this script to bed. The attachment in the top post is replaced, but needs this line after 104:
Code: [Select · Download]
               foundWhole = false; // Reset for next measure.
This is near the end of the loop that finds a bar line and gets ready for the next measure.
Since 1998

Re: Audit Bar Lines tool

Reply #17
Just a minor tweak in the code. If you run the script on a selected part of the staff, just before a bar line, the measure number may be off by 1. Lines containing contextOn are the only changes since the last version.

To see what this script sees, run it with Y on the prompt, then choose STDIN.
Since 1998

Re: Audit Bar Lines tool

Reply #18
On line 96, please change "whole note" to "whole rest". Lines 89-91 as well as 96-97 are there to allow a whole rest in a measure with nothing else with a duration in it to correctly fill the measure using the current time signature.

This change has been made in the attachment to the top message.
Since 1998