Hello Everyone.
When I started producing my own modules, Python was new to me. So, I did what I figured was the best method to get me going - copy source from other modules and begin. This method has served me well for many things, but beware, when copying someone else's source code, you are also copying their errors.
After much pain and late nights, I have discovered the following.
NAMING YOUR MODULE
This is critical. When a project is saved, it saves the module data according to the Name of each module. So if you update the name of your mod (eg. with a new version number in it), when you open a project file, Modul8 won't be able to find your module.
(I have just renamed all my modules in the online library, if you use any I suggest you update.)
HOW PYTHON STORES DATA
In Python, a statement like:
x = 1
print x
'1'
will create an integer holder and add the value of one into that holder.
if you then do this:
y = x
print y
'1'
what you are effectively saying is that y = the memory address of x
so,
x = 2
print y
'2'
but on the other hand if you do this:
x = 1
y = int(x)
x = 2
print y
'1'
with the above we have copied the value of x into a new integer holder y, so when we change the value of x, y remains unaffected.
HOW THIS APPLIES TO SAVING
The standard method of:
outDict['X'] = x
appears to work fine for single values, but when we get into more complex data holders like lists and dictionaries, it falls flat on its face.
Yes, if you have a enough memory on your machine you may be able to save and reload, and M8 will recover your data. But if you save, shutdown then restart, all your work will be lost.
Has anybody ever wondered what happened to all those lovely filters they set up in the Filter module, as you open up your project in front of a large audience? This is the reason.
DEEPCOPY
There is a python module called Copy, and it contains a function called deepcopy.
This function creates a deep copy of all the nested data. (a shallow copy being just the memory address)
to access this in your scripts:
Init Script:
import copy
from copy import deepcopy
exampleDict = {a:1, b:2, c:[1,2,3,4]}
------------------------
Serialize Script:
outDict['EXAMPLE_DICT'] = copy.deepcopy(exampleDict)
---------------------------
Deserialize Script:
exampleDict = copy.deepcopy(inDict['EXAMPLE_DICT'])
_____________________________________________________
I hope this is some help to everyone.
There is plenty of stuff written online about how to correctly assign data in python. Here I was hoping to give a brief explaination and show how it relates to Modul8.
I think all of my online modules where guilty of these errors in some way or another. Please upgrade as I have fixed them all.
Mods I have updated today and uploaded to the online library:
(at) BPM (global)
(at) Layer Sequencer 10x16
(at) Sound Router (layer)
(at) Sound Router (master)
(at) Filter (layer)
(at) LFO (global)
(at) LFO Router (layer)
(at) LFO Router (master)