separating Sibelius objects from User-created objects

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

separating Sibelius objects from User-created objects

Alexander Plötz
Hello List,
 
can anyone of you think of a clever way to check whether an object is a genuine Sibelius score object (Score, Staff, Bar, NoteRest, Text, etc...) or a user-created "container" object (e. g. a SparseArray, Dictionary, Array...)? I would like to be able to pass in score objects and container objects into a method and process them there according to what they are. I tried separating them by checking appropriate (non-user-created) properties, but since I have to check for both possible cases (for example "Type" and "NumChildren") there will always be one property which will cause a runtime error.
 
Any input is appreciated.
 
Best,
 
Alex

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

Update: separating Sibelius objects from User-created objects

Alexander Plötz
On further attempt, this turned out to be pretty easy to do:
IsSpArrOrDict "(Container) {

    if (IsObject(Container)) {

        if (Length(Container)>0) {

            return true;

        }

    }

    return false;

}"


This seems to reliably recognize SparseArrays and Dictionaries, but not Arrays (but then again, the latter do not hold objects anyway, so it works out well).

 

 

Alex
 
 
 

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

Re: Update: separating Sibelius objects from User-created objects

Bob Zawalich

I really would not trust this. I have found IsObject to be unreliable, in some cases returning True when passed in a null “object”.

 

Also passing an object as a parameter is also fairly unreliable – Sibelius will sometimes lose track of what kind of object it is – you are really passing pointers around and ManuScript is not as  precise as it might be.

 

If I ever have to do anything like this I will always pass in a type identifier of some sort, so I pass both the object and something that tell what type it is.  Set up a sparse array whose first entry is an identifier and the second is the object, for example and pass that around.

 

I will pass around a bar object and expect to be able to tell what it is using IsObject and obj.Type, but if you mix arrays, hashes, Sparse Arrays and Dictionaries, and strings and numbers into the mix, it is almost certain to fail as some very inconvenient point.

 

And you can certainly have a valid Sparse Array or Dictionary with length = 0 when it has no entries.

 

So I would be very cautious about doing what you suggest.

 

Bob

From: [hidden email] [mailto:[hidden email]] On Behalf Of notenlektorat
Sent: Wednesday, December 09, 2015 12:40 PM
To: A mailing list for Sibelius plug-in developers
Subject: [Plugin-dev] Update: separating Sibelius objects from User-created objects

 

On further attempt, this turned out to be pretty easy to do:

IsSpArrOrDict "(Container) {

    if (IsObject(Container)) {

        if (Length(Container)>0) {

            return true;

        }

    }

    return false;

}"


This seems to reliably recognize SparseArrays and Dictionaries, but not Arrays (but then again, the latter do not hold objects anyway, so it works out well).

 

 

Alex

 

 

 


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

Re: Update: separating Sibelius objects fromUser-created objects

Alexander Plötz
Hi Bob,
 
I am aware that you probably do not have a stack of non-working code put away for a rainy day, but just in case, I would be interested in seeing some code that produces the kind of errors that you mention, for better understanding. I don't remember ever running into problems with IsObject(); I have, on the contrary, come to consider it a trustworthy and helpful friend.
 
But I also would like to address an obvious misunderstanding: my code does not check the Length variable of the SparseArray or Dictionary (I don't think the latter has such a variable), but the result of the Length(Expression) method, which means I am asking for the amount of characters as if the object is treated as an expression. For empty SparseArrays and Dictionaries this value seems to be 2, and higher once the object holds any contents.
 
Best,
 
Alex

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

Re: Update: separating Sibelius objects fromUser-created objects

Bob Zawalich

Hi Alex,

 

You are correct that I do not have a lot of examples of code that does now work. But I can tell you that I have had a lot of trouble over the years with methods returning null  then passing that to IsObject and having it not fail. So now most of my code that gets null returns check for null first before checking IsObject.

 

For a while I wrote code that returned -1 instead of null. So it really did happen often enough that I was going out of my way to avoid it.

 

If I write a simple method that just returns null in 7.5 and then call IsObject on the result, if fails as expected. So either it does not happen anymore or the situation that causes the problem is more complex.

 

But at any rate, it might be worth keeping  an eye out for issues that might occur with IsObject and a null return.

 

I am also a bit leery of using Length on objects.  Most object that have a sense of length have a  .Length variable; in  Sparse Arrays there is both .Length and .NumChildren which are equivalent. (though NumChildren is undocumented for this).

 

I note that Length() of a score, staff, or array all return 0. I think Length was really intended for strings, though it does say that Expression is the parameter. To me it does not really make sense for an object. So unless I had access to someone like Daniel who could look at the code and tell me it was OK, I would be careful about relying on something like this.

 

I did a test on a dict and sparse array, though, and I also came up with lengths of 2 for empty dict and ars, and numbers that increased the more I added entries to those containers.

 

So with that amount of experimental data, perhaps what you have will work.

 

Good luck!

 

From: notenlektorat [mailto:[hidden email]]
Sent: Monday, December 14, 2015 1:01 PM
To: [hidden email]; A mailing list for Sibelius plug-in developers
Subject: Re: [Plugin-dev] Update: separating Sibelius objects fromUser-created objects

 

Hi Bob,

 

I am aware that you probably do not have a stack of non-working code put away for a rainy day, but just in case, I would be interested in seeing some code that produces the kind of errors that you mention, for better understanding. I don't remember ever running into problems with IsObject(); I have, on the contrary, come to consider it a trustworthy and helpful friend.

 

But I also would like to address an obvious misunderstanding: my code does not check the Length variable of the SparseArray or Dictionary (I don't think the latter has such a variable), but the result of the Length(Expression) method, which means I am asking for the amount of characters as if the object is treated as an expression. For empty SparseArrays and Dictionaries this value seems to be 2, and higher once the object holds any contents.

 

Best,

 

Alex


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