How To Detect Grand Staff?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How To Detect Grand Staff?

Martin Marris
Is there a reliable way to identify an instrument as being a grand staff
instrument?

Counting the number of staves in the instrument is not reliable, because
users sometimes use the "add staff above/below" mechanism incorrectly
(thinking that they are adding a new instrument) -- so they end up creating
a single, multi-staff instrument, unbeknown to them. Checking for the
presence of a brace (rather than a bracket) is not reliable because braces
aren't just used on grand staves.

Perhaps the best way is to check whether the InstrumentType variable
"OtherClefStyleId" is valid?

(I think I asked this question in this space before, but I've forgotten the
answer....)

Martin


_______________________________________________
Plugin-dev mailing list
[hidden email]
http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: How To Detect Grand Staff?

Bob Zawalich
The best thing I came up with is to use OtherClefStyleId

        it = staff.InitialInstrumentType;
        fStaffInGrandStaff = (it.OtherClefStyleId != "");

I think Daniel suggested that at one point. If you have

if ((staff.NumStavesInSameInstrument = 2) and (it.OtherClefStyleId != ""))

true for a staff, then it is a staff in and instrument that was at least
initially a grand staff instrument, and most likely still is.

You can't be sure, though, and especially if you are looking at a score that
have been through a lot, there may have been sdtaves added and deleted and
ossias added and deleted, etc. But this is a good guess.

You are welcome to use any of the code that follows anywhere you might find
it useful.

If I need to analyze multi-staff instruments, I almost always run this
little bit of code early on, and it saves fussing with the staves later. It
sets up an array indexed by staff number, and it has "1" if the staff is a
single staff instrument, and F, M, or L, if it is the First, one of the
Middle, or the Last staff in a multistaff instrument:

(Note this is in "text file format", so the internal double quotes are
single quotes; copy this code into a plugin text file and they will be
converted to double quotes in the editor)

*******************************************************
        GetArrMultiStaves "(score) {
arrMultiStatus = CreateArray();

numRemaining = 0;
for each Staff s in score
{
        if (numRemaining > 0)
        {
                numRemaining = numRemaining - 1;
                if (numRemaining = 0) // last in multi
                {
                        arrMultiStatus[s.StaffNum] = 'L';  // last
                }
                else
                {
                        arrMultiStatus[s.StaffNum] = 'M';  // middle
                }
        }
        else
        {
                if (s.NumStavesInSameInstrument = 1)
                {
                        arrMultiStatus[s.StaffNum] = '1';  // single
instrument
                }
                else
                {
                        arrMultiStatus[s.StaffNum] = 'F';  // first of a
multi
                        numRemaining = s.NumStavesInSameInstrument - 1;
                }
        }
}

//trace('GetArrMultiStaves table = ' & arrMultiStatus.WriteToString());

return arrMultiStatus;}"

***************************************************

So one example of how this might be used is if you have a bar and want to
know if it is in the top staff of a grand staff. You might run this code
after getting the array:

*********************************************************************

        BarInTopStaffOfGrandStaff "(bar, arrMultiStatus) {
staff = bar.ParentStaff;
if (staff.NumStavesInSameInstrument = 2)
{
        if (arrMultiStatus[staff.StaffNum] = 'F')
        {
                return True;
        }
}

return False;}"

*****************************************************

Sometime I need a list of available multi staff instruments; I suppose you
might be able to go through the list of Instrument Types looking for those
where (it.OtherClefStyleId != '')). When I needed some, I just picked some I
wanted and used the itList to get the language-appropriate names

        FillInstrumentList "() {
score = Sibelius.ActiveScore;
itList = score.InstrumentTypes;

arr = CreateArray();
// no easy way to get all the grand staff instruments, so just add a few I
like


strPiano = 'Piano';

for each it in itList
{
        switch (it.StyleId)
        {
                case('instrument.keyboard.piano')
                {
                        arr[arr.NumChildren] = it.DialogName;
                        strPiano = '' & it.DialogName;
                }
                case('instrument.keyboard.harpsichord')
                {
                        arr[arr.NumChildren] = it.DialogName;
                }
                case('instrument.pitchedpercussion.harp')
                {
                        arr[arr.NumChildren] = it.DialogName;
                }
                case('instrument.pitchedpercussion.harp.lever')
                {
                        arr[arr.NumChildren] = it.DialogName;
                }
                case('instrument.pitchedpercussion.marimba')
                {
                        arr[arr.NumChildren] = it.DialogName;
                }
        }
}

dlg_lstInstGrandStaff = arr;
dlg_strInstrumentGrandStaff = strPiano;

}"
        dlg_lstInstGrandStaff
        {
                 "Harpsichord"
                 "Piano"
                 "Harp"
                 "Lever Harp"
                 "Marimba [grand staff]"
        }
        dlg_strInstrumentGrandStaff "Piano"

*********************************************

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Martin Marris
Sent: Friday, September 25, 2015 6:17 AM
To: 'A mailing list for Sibelius plug-in developers'
Subject: [Plugin-dev] How To Detect Grand Staff?

Is there a reliable way to identify an instrument as being a grand staff
instrument?

Counting the number of staves in the instrument is not reliable, because
users sometimes use the "add staff above/below" mechanism incorrectly
(thinking that they are adding a new instrument) -- so they end up creating
a single, multi-staff instrument, unbeknown to them. Checking for the
presence of a brace (rather than a bracket) is not reliable because braces
aren't just used on grand staves.

Perhaps the best way is to check whether the InstrumentType variable
"OtherClefStyleId" is valid?

(I think I asked this question in this space before, but I've forgotten the
answer....)

Martin


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

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