Building GSA Names on the Fly

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

Building GSA Names on the Fly

Martin Marris

I need to create some Global Sparse Arrays but the number of these arrays changes from one plugin run to the next.

 

Sometimes there will be 3 of them, sometimes 15.....

 

So the names of the arrays are generated on the fly, with the numeric index being the last portion of the array’s name.

 

I tried something like this. For the sake of the example, let us postulate that the value of "foo" is 3.

 

name = "gsa_myGSA" & foo

creationstring = "Self._property:" & name

@creationstring = CreateSparseArray();

 

but when I later tried to access the array with an argument something like

 

x = @name[0]

 

I got an error message saying that “field gsa_myGSA3 not found.”

 

I usually try to avoid using indirection but I couldn’t see how else to handle this one.

 

Any suggestions?

 

Tnx.

 

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: Building GSA Names on the Fly

Bob Zawalich

Are you trying to have values in the global sparse arrays accessible after the plugin stops execution, as you can do with “normal” global arrays?

 

I don’t know if you can do that, and there is probably no one in development to ask about that. I have never attempted to do that. I have used global sparse arrays and global Dictionaries many times, but I have only accessed them while the plugin is running.

 

I would be surprised if it would actually work, and more surprised if you could set values in a global sparse array, then edit the plugin and hope that the arrays would retain their values in the plugin file, the way that normal global arrays do.

 

Sparse arrays are allocated with Create Sparse Array, and I believe they disappear when the plugin terminates.  If one holds non-string objects, they surely will not endure across a Sibelius session. There is some possibility that they retain the storage when they plugin stops running but is still in memory, but I would suspect that this would not be the case – it would be a bad idea to have every plugin that had run lock up the memory held in its sparse arrays and dictionaries across the execution.

 

To access them across the runs, you would probably have to have the name stored as a global variable and hope that it remained across sessions, but I *really* doubt that happens.

 

Normal global arrays can endure across runs and across sessions because they hold only strings and are stored as text in the Tree Structure that makes up a plugin. They are just more text. Sparse arrays are not like that. They are allocated data structures that were bolted onto the plugin architecture in Sib 6, and I totally doubt that they can be reduced to text. You could of course try creating a sparse array, assigning it to a global variable, filling the array, then editing the plugin, saving it, and closing Sib and looking in the plugin text file. I doubt you will see anything there, but I could be wrong.

 

I typically use global “normal” arrays, which only contain strings, to hold values across a run, and the Preferences database to hold string values across sessions without needed to edit the plugin file.

 

So I suppose the first thing I would test is whether you can set up a global sparse array, set some values into it, and then access the set values the next time the plugin is run. I would think that at absolute best you might be able to access that data during the same Sibelius session. And really, I strongly doubt that would work.

 

So I would say, figure out if you can do that first, without worrying about the indirection, and then if you can do that, let’s discuss the indirection issues.

 

Actually, the MS reference says

 

User properties assigned to the plug-in are persistent between invocations

 

In this block:

 

Using user properties as global variables

You can store SparseArray and Dictionary objects, and indeed any other object, as user properties of the Plugin object

itself. In the example below, Self is the object that corresponds to the running plug-in, and a user property globalData is

assigned to the plug-in, containing a Dictionary:

Self._property:globalData = CreateDictionary(1,2,3,4);

// globalData and Self.globalData can be used interchangeably

trace(globalData);

trace(Self.globalData);

User properties assigned to the plug-in are persistent between invocations. Take care to ensure that these user properties are

created before you attempt to use them, otherwise your plug-in will abort with a run-time error. Using the

_property:property_name syntax never causes run-time errors, but direct references to property_name force a runtime error

if property_name hasn't been created yet.

 

 

So it might be possible that it will work if you use the _property:property_name syntax to reference the data.

 

Personally, I would not attempt indirection of user property names unless I really needed to . If you are only dealing with strings, you can use normal global arrays to get data across invocations. I doubt anyone really considered this being done when they added Sparse Arrays and Dictionaries (which were added to Sib 6 at really the last minute before it shipped) and no one had really done even normal testing on it.

 

At any rate, the indirection you are using appears syntactically correct, and even the error message indicates that @name is properly set up.

 

CreateSparseArray, though, is returning an object, whereas CreateArray returns a pointer to an array, and that may be the source of the problem. I don’t think you can use indirection like this on an object.

 

Getting pointers to arrays is why you always have to do something like

 

string = “” & arr[3];

 

It allows you to have arrays of arrays, but it is one of the largest sources of plugin programming errors.

 

Maybe what you could do is create another Sparse Array, and for each Sparse Array you create, push the result of CreateSparseArray into your other sparse array. Then when you need the 3rd one you created (index = 2), you can say

 

ars = arsOfArs[2];

 

x = ars[0];

 

and I would expect it to work. Then you just need to keep track of the indexes.

 

Good luck with this one.

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Martin Marris
Sent: Tuesday, September 29, 2015 12:46 PM
To: 'A mailing list for Sibelius plug-in developers'
Subject: [Plugin-dev] Building GSA Names on the Fly

 

I need to create some Global Sparse Arrays but the number of these arrays changes from one plugin run to the next.

 

Sometimes there will be 3 of them, sometimes 15.....

 

So the names of the arrays are generated on the fly, with the numeric index being the last portion of the array’s name.

 

I tried something like this. For the sake of the example, let us postulate that the value of "foo" is 3.

 

name = "gsa_myGSA" & foo

creationstring = "Self._property:" & name

@creationstring = CreateSparseArray();

 

but when I later tried to access the array with an argument something like

 

x = @name[0]

 

I got an error message saying that “field gsa_myGSA3 not found.”

 

I usually try to avoid using indirection but I couldn’t see how else to handle this one.

 

Any suggestions?

 

Tnx.

 

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: Building GSA Names on the Fly

Bob Zawalich

Page numbers are not remotely straightforward. For one big thing, page number changes are not bar objects, so you cannot filter them in the usual way.

 

I have published a plugin called Page Numbers (category Engravers’ Tools) that will hide and show page numbers. That might well be the best documentation around for showing how to work with page numbers, unfortunately.

 

I suggest you look at the code there that hides page numbers.

 

In the Sibelius blog, the plugin is discussed in

 

http://www.sibeliusblog.com/tips/new-plug-in-page-numbers/

 

and you might also find this useful:

 

http://www.sibeliusblog.com/tutorials/working-with-page-numbers-in-sibelius/

 

Good luck!

 

bob

 

From: Martin Marris [mailto:[hidden email]]
Sent: Saturday, October 03, 2015 11:45 AM
To: [hidden email]
Subject: RE: [Plugin-dev] Building GSA Names on the Fly

 

I've been trying to hide *all* the page numbers in a score. I thought this should work but it doesn't:

 

foo = bar.AddPageNumber();      //where "bar" is any bar on the first page

foo.SetFormatChangeOnly(True);

foo.SetHideOrShow = 2;

 

Years ago someone, probably BobZ, explained to me how page-number objects work and IIRC it's not as straightforward as one might think.

 


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