Dealing with selections consisting only of default barlines

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Dealing with selections consisting only of default barlines

Bob Zawalich-3
Occasionally I try to deal with selections that only have default barlines
in them. If you select a non-special barline and then run code like this

for each obj in sel
{
        trace(obj.Type);
}

The plugin will crash, telling you that obj is null. What is curious is that
something is returned, but it is a null object.

I usually avoid this by doing something like the following, which rejects
the null object and possibly other weird stuff:

for each obj in sel
{
        if (IsObject(obj))
        {
                trace(obj.Type);
        }
}

Recently I wanted to actually handle such barlines, and figure out which bar
they were associated with. But I could get nothing from the code above.

However, I found I could do this and end up with a bar object if only a
default barline was selected.:

for each Bar b in sel
{
        trace('no object. bar, staff = ' & b.BarNumber & ', ' &
b.ParentStaff.StaffNum);
}

It turns out that it returns a bar in the system staff. So I could do 2
passes. First look for a valid object in the selection, and if it found
something, return.  The second pass looked for bars in the selection.

In my case I just wanted the barnumber of the first selected bar or object.

So I did the first pass. If it did not find anything, I tried looking for
bars in the selection. If I found one I assume that meant the selection was
one or more barlines. The code below is what I eventually used.

A couple of issues:

1. If I got a barline or special barline, I wanted  the bar number that
treated the barline as if it were at the start of the bar.

For special barlines, only Start Repeat barlines are at the start, so for
any other special barline, I add 1 to make it look like it is at the start
of the following bar.
Default barlines are also at the end of a bar so I add 1 to get to the start
of the next bar. Unfortunately, if a bar is the first bar in a system, you
get the same bar if you select the barline at the start of the bar or at the
end of the bar.
I could figure out no way to find which barline it was, so if I had a bar at
the start of a system, I put up a message box and asked the user to tell me
which one it was.


Other than that, it seems to work pretty well. Try out the downloadable
plugin Add Rehearsal Mark Plus Double Barline in category Other for a demo.


bob




************** This routine is part of the downloadable plugin  Add
Rehearsal Mark Plus Double Barline**********************************

        GetFirstSelectedBarNumber "(score, sel) {
// special code to handle barline-only selection. First check for a selected
object
// and if found return the bar number of its parent.

for each obj in sel
{
        if (IsObject(obj))
        {
                barnum =  obj.ParentBar.BarNumber;
                if (obj.Type = 'SpecialBarline')  // might be funky for
mid-bar barline
                {
                        if (obj.BarlineInternalType !=
SpecialBarlineStartRepeat)
                        {
                                barnum = barnum + 1;
                        }
                }

                if (barnum > score.SystemStaff.BarCount)
                {
                        barnum = score.SystemStaff.BarCount;
                }
                //trace('object found: type = ' & obj.Type);
                return barnum;
        }
}

// no object found. Look for selected bars. If found, it should be a
selected barline.
// The bar will be the bar for which the barline is the end. We actually
want to
// treat the barline as the start of a bar, so add 1 to the barnumber
// unless it is the last bar in the score, in which case
// just leave it alone and the rm/bl will go to the previous bar.

// we get the same bar if either barline is selected for the first bar in a
system.
// if that happens I put up a messagebox to ask if they go at the start of
the system or in the following bar.

for each Bar b in sel
{
        //trace('no object. bar, staff = ' & b.BarNumber & ', ' &
b.ParentStaff.StaffNum);
        barnum = b.BarNumber;
        if (barnum != score.SystemStaff.BarCount)
        {
                barnum = barnum + 1;
        }

        if (b.NthBarInSystem = 0)  // can't tell if leading or trailing
barline was selected
        {
                ok = MyYesNoMessageBox(_msgLeadingOrTrailingBarline);
                if (ok and (barnum > 1)) // treat as leading barline
                {
                        barnum = barnum - 1;
                }
        }

        return barnum;
}


return -1;  // only if nothing in selection
}"
        _msgLeadingOrTrailingBarline "The first bar in a system confuses me.
  Choose Yes to put the objects at the start of the system.
  Choose No to put them in the next bar."

_______________________________________________
Plugin-dev mailing list
[hidden email]
https://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev