PLUGIN-DEV: Equating notes

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

PLUGIN-DEV: Equating notes

Andrew Moschou
Hi,

Consider the following example:

Staff = Sibelius.ActiveScore.NthStaff(1);
for each BarObject in Staff.NthBar(1)
{
    if(BarObject.Type = "NoteRest")
    {
        if(BarObject.NoteCount > 0)
        {
            A = BarObject[0];
            B = A.ParentNoteRest[0];
            if(A = B)
            {
                trace("yes");
            }
            else
            {
                trace("no");
            }
        }
    }
}

The variables A and B refer to the same note (the first note of the chord), but (A = B) is always false, so "yes" is never traced. This behaviour is justified by thinking that notes are not well-ordered variables so can't be compared with "=", "<" and ">".

I wonder if it is possible to compare equality of notes, or any object in general, consider the simpler example below:

A = Sibelius.ActiveScore.NthStaff(1);
B = Sibelius.ActiveScore.NthStaff(1);
if(A = B)
{
    trace("yes");
}
else
{
    trace("no");
}

Again, "no" is always traced.

Without any other information, all that I can think to do is to test some of the objects' variables. Each staff has a unique StaffNum so if(A.StaffNum = B.StaffNum) will work but for notes, there is no unique variable to exploit in this way.

Am I missing something or is just this all?

Andrew
Reply | Threaded
Open this post in threaded view
|

PLUGIN-DEV: Equating notes

Hans Höglund

There are some errors in your code, but you seem to be right. I tested with the following methods:

s = Sibelius.ActiveScore.NthStaff(1);
b = s.NthBar(1);


prefix0 = "staffNote";
i = 0;

for each NoteRest nr in s {
    for each n in nr {
        var = prefix0 & i;
        @var = n;
        i = i + 1;       
    }
}

prefix1 = "barNote";
i = 0;

for each NoteRest nr in b {
    for each n in nr {
        var = prefix1 & i;
        @var = n;
        i = i + 1;       
    }
}
for j = 0 to i {
    v1 = prefix0 & j;
    v2 = prefix1 & j;
    res = (@v1 = @v2);
    trace(res);
}

and Sibelius 6 version:


s = Sibelius.ActiveScore.NthStaff(1);
b = s.NthBar(1);


staffNotes = CreateSparseArray();
barNotes = CreateSparseArray();

for each NoteRest nr in s {
    for each n in nr {
        staffNotes.Push(n);       
    }
}

for each NoteRest nr in b {
    for each n in nr {
        barNotes.Push(n);       
    }
}

stop = utils.min(staffNotes.Length, barNotes.Length);
for i = 0 to stop {
    res = (staffNotes[i] = barNotes[i]);
    trace(res);
}

They both output false for all notes in the score. Obviously this is bug in manuscript, iterators returning objects that are obviously reffering to the same element should compare as equal. What you can do is, as you said, to implement an own comparison method. How would you define equality? Personally I would use pitch, position of the parent NoteRest in bar and bar number of the parent Bar.

Another simple solution is to never obtain BarObjects from a staff (a good practice anyway), and everything should compare correctly.



Använd nätet för att dela med dig av dina minnen till vem du vill.
Reply | Threaded
Open this post in threaded view
|

RE: PLUGIN-DEV: Equating notes

Bob Zawalich
In reply to this post by Andrew Moschou
I agree with your conclusion. Objects in general cannot be compared. If I
have to compare something (Tuplets turns out fairly often as something to
compare) I always pick a set of properties that I think are adequate to
ensure equality, and compare all the properties. There are various examples
of
“TupletsEqual”  routines in various plugins.

The new Sib 6 SparseArrays claim to allow equality checks:

*********************
You can compare two sparse arrays for equality, e.g.:
if (array = array2) {
// do something
}
********************

Since they can hold objects, one would assume that you might be able to fill
2 arrays with an object each and then compare the arrays.

I have not really investigated this. I tend to doubt it would really work,
but it would be great if it did.

bob

________________________________________
From: Majordomo Pseudo User [mailto:[hidden email]] On Behalf Of
Andrew Moschou
Sent: Sunday, September 06, 2009 5:32 AM
To: [hidden email]
Subject: PLUGIN-DEV: Equating notes

Hi,

Consider the following example:

Staff = Sibelius.ActiveScore.NthStaff(1);
for each BarObject in Staff.NthBar(1)
{
    if(BarObject.Type = "NoteRest")
    {
        if(BarObject.NoteCount > 0)
        {
            A = BarObject[0];
            B = A.ParentNoteRest[0];
            if(A = B)
            {
                trace("yes");
            }
            else
            {
                trace("no");
            }
        }
    }
}

The variables A and B refer to the same note (the first note of the chord),
but (A = B) is always false, so "yes" is never traced. This behaviour is
justified by thinking that notes are not well-ordered variables so can't be
compared with "=", "<" and ">".

I wonder if it is possible to compare equality of notes, or any object in
general, consider the simpler example below:
A = Sibelius.ActiveScore.NthStaff(1);
B = Sibelius.ActiveScore.NthStaff(1);
if(A = B)
{
    trace("yes");
}
else
{
    trace("no");
}

Again, "no" is always traced.

Without any other information, all that I can think to do is to test some of
the objects' variables. Each staff has a unique StaffNum so if(A.StaffNum =
B.StaffNum) will work but for notes, there is no unique variable to exploit
in this way.

Am I missing something or is just this all?

Andrew


Reply | Threaded
Open this post in threaded view
|

Re: PLUGIN-DEV: Equating notes

Andrew Moschou
With notes, the problem is that matching properties (duration, pitch, parent NoteRest's position and voice) does not guarantee we're looking at the same note. It is not uncommon in string music for a chord to have two noteheads on a single pitch, which indicates the same not is played simultaneously on two adjacent strings (e.g. open string and stopped string). And the method of comparing properties will not differentiate between the two.

Now that I think of it, it might not be necessary. If two note(heads) have identical properties, then there's no way to topologically separate them, so for all purposes, they can be treated as identical (That is if I want to look at one note, it's not going to matter if I accidentally look at the other note).

Andrew