Page 1 of 1

Modifying existing modules to add save feature

Posted: Wed May 04, 2011 3:40 am
by d3v1an7
Hey all,

I'm using (vs) Media Sequencer 1.0, in which the author has saving on the to do list. It hasn't been updated since 2008, so I'm doubting it'll happen any time soon.

With no knowledge of module coding, how easy would it be for me to add the ability to save the module presets to the project save file?

Is there some kind of documentation on implementing features like this?

Thanks heaps.

Posted: Wed May 04, 2011 4:01 am
by lotech
It would be easy for some of the more advanced module makers as there is support for saving states but a little beyond me.

To be honest you should look into (at) Layer Sequencer 10x16 v2.0 as its a more complete version of the same idea. It may include saving but I'm not too sure as I've only just seen the use of a bpm sync'd layer changer (going for a piss/drink/dance).

Posted: Wed May 04, 2011 4:24 am
by d3v1an7
Thanks lotech - I actually need to run both :)

I'm already running the layer sequencer for BPM sync, but I would like some of the layers themselves to switch media over time as well.

I've come across setDefaults / getDefaults in the manual and will give it a shot. Looks like that'll actually save into the module, but I'm not too bothered about that.
Hopefully it saves the different module states for each layer - we'll see.

Posted: Wed May 04, 2011 4:50 am
by d3v1an7
Hm, well I've tried that, along with setting 'Auto-Serialize' for each of the visual elements.
It saves the last instance of the module, but not for each layer.

I've had a peek at other modules and it looks like it'll be a bit more complex unfortunately.

Posted: Wed May 04, 2011 9:34 am
by Lupin
use the InDict /outDict blocks
the outDIct block is the place where you save your data with your project when you close it
if you want to save a variable like

Code: Select all

test="text string"

write:

Code: Select all

outDict['test'] = 'text string'

or to save the variable

Code: Select all

outDict['test'] = test


to recall this saved variable when you open your project, go to the inDict block and ask the script if the data was saved with the project, if so, then recall it and apply it to the test varable.
write:

Code: Select all

if 'test' in inDict:
   test=inDict['test']


you can save numbers, strings, lists, dictionaries with the outDict dictionary.

Posted: Wed May 04, 2011 9:42 am
by lotech
Wow that straight forward explanation just answered all my questions about saving things in modules. Thanks Lupin!

Posted: Wed May 04, 2011 10:18 am
by Lupin
you are welcome i added something to the script.
but i guess you already got the idea of how it works

Posted: Wed May 04, 2011 1:37 pm
by d3v1an7
Hey Lupin, thanks for the clear explanation :)
I understand that concept, but I'm not sure how to save arrays of data for each specific layer.

I'll keep at it, but I'll post parts of the original code - the parts I'm pretty sure need changing.
if anyone has any ideas, I'd really appreciate it!
All of this code is in init()

The save function is called whenever the user edits the sequence

Code: Select all

def saveSequence():
   module.setDefaults ( {'seq1': sequence} )


And here is the load...

Code: Select all

sequence=[]
prefs = module.getDefaults()


I'm pretty sure this is the setup...

Code: Select all

if prefs == {}:
#   sequence =[1,2,3,4,5,6,7,8,9,2,10,11,12]
   module.setDefaults ( {'seq1': [1,2,3,4,5,6,7,8,9,2,10,11,12]} )      
else:
   sequence = prefs['seq1']
   print  sequence

Posted: Wed May 04, 2011 2:32 pm
by Lupin
Hi d3v1an7
your strategy is the worst when it comes to save datas for each layer.
you'd rather use a contextual layer module and use the inDict / outDict blocs to save it.
this dictionaries save datas from each layer as long as you checked the contextual layer checkbox within your module.
otherwise it becomes a real nightmare if you wanna deal with arrays and dictionaries to save each layer's properties.

Posted: Thu May 05, 2011 4:40 am
by d3v1an7
Cool - makes sense.
I'm having trouble getting the script to output saved variables though.

I've done the following:
Serialize(outDict)

Code: Select all

outDict['test'] = 'text string'

Deserialize(inDict)

Code: Select all

if 'test' in inDict:
   test=inDict['test']

Init()

Code: Select all

print (test)

This gives me a runtime error

Code: Select all

NameError: name 'test' is not defined


Any ideas?

Posted: Thu May 05, 2011 9:09 am
by Lupin
you did not declare the test variable previously.
you can't create a gloabal variable within a script aside of the init bloc.

by the way i'm the author of the media sequencer ;) visionsonore was my former company
i did not updated the media sequencer module coz it's really time consuming and since it's impossible to publish,update or delete modules from the public library if the module was created on another computer - that's was my case unfortunatly - i couldn't even update it today.

Wait for the online module manual, you'll find the answers to start to modify and build your own modules. it will be released soon.

Posted: Thu May 05, 2011 9:27 am
by d3v1an7
Haha rookie error, my bad - I've clearly got a long way to go :)

Proper documentation would be amazing - I'm used to looking up functions and having in depth explanations and examples when working with jQuery/Wordpress etc - spoilt really.
I feel quite blind starting out in Modul8, everything is trial and error at the moment.

Thanks for your amazing work on the module in the past, it's exactly what I need. If I can manage to get it to save, I will let you know :D

Posted: Fri May 06, 2011 2:01 am
by d3v1an7
Sorry to keep bumping, but I'm going around in circles at the moment.
Is there some way for me to declare a variable without assigning it a value?

Atm, I'm doing the following
Init()

Code: Select all

testVar = 123
print testVar

MessageEvent(msg,param)

Code: Select all

(On button press...)testVar = 456

Serialize(outDict)

Code: Select all

outDict['STORE_TEST'] = testVar

Deserialize(inDict)

Code: Select all

if 'STORE_TEST' in inDict:
   testVar= inDict['STORE_TEST']

Finish()

Code: Select all

print testVar


When resetting the script, the val 123 is returned for both finish and start prints.
I know why it returns 123 on init (it has only just been declared), but can't figure out why it returns the same value on finish, as it should have changed on button press.

When does the variable get stored? When the button is pressed? Or when the document is saved?

I feel like I'm missing something fundamental here :p

Any help is appreciated :)

Posted: Fri May 06, 2011 10:48 am
by Lupin
the variable is saved in the the outDict when you close your project
the inDict is called when you open a project