embed data in patcher


    Aug 28 2006 | 5:58 pm
    hello all,
    is there a way to embed a complex data structure (ex: Atom[][][] or int[][]...) in the patcher using the save() method? or any alternatives before I start digging in java file IO services...
    thank you for any suggestions.
    pfg

    • Aug 28 2006 | 7:38 pm
      By default the embedMessage/save paradigm expects to be working with
      atom lists.
      The only hack i can think of off the top of my head is to:
      * serialize your complex object to a string stream and store that
      string in a single atom.
      *add a message 'deserializedata' to your object
      *in your embedMessage call use deserializedata as the message to be
      sent to your object
      to decode the data.
      Topher
      On Aug 28, 2006, at 10:58 AM, pedro guerreiro wrote:
      >
      > hello all,
      > is there a way to embed a complex data structure (ex: Atom[][][] or
      > int[][]...) in the patcher using the save() method? or any
      > alternatives before I start digging in java file IO services...
      > thank you for any suggestions.
      >
      > pfg
      >
    • Aug 28 2006 | 8:34 pm
      thank you Topher.
      I'll look into that.
      pfg
      > * serialize your complex object to a string stream and store that
      > string in a single atom.
      > *add a message 'deserializedata' to your object
      > *in your embedMessage call use deserializedata as the message to be
      > sent to your object
      > to decode the data.
      >
      > Topher
      >
    • Aug 29 2006 | 10:45 am
      tried it.
      it works if the Atom[] resulting from serialization is shorter than 256 in length (the max limit).
      with a bigger Atom[] max crashes when attempting to save the patch.
      thanks anyway.
    • Aug 29 2006 | 5:29 pm
      you could break them into multiple 256 size chunks. that might be a
      limitation of the current file format!
      topher
      On Aug 29, 2006, at 03:45 AM, pedro guerreiro wrote:
      >
      > tried it.
      > it works if the Atom[] resulting from serialization is shorter than
      > 256 in length (the max limit).
      > with a bigger Atom[] max crashes when attempting to save the patch.
      > thanks anyway.
    • May 01 2009 | 6:21 pm
      was there ever a solution to this? Example code perhaps? I to am trying to wedge a decent sized object into the embed message function
    • May 03 2009 | 3:47 pm
      Since 5.0.6, you can save list of 4094 atoms. You still have to serialized multidimensional arrays though.
      HTH,
    • May 04 2009 | 12:57 am
      I got it happening. Bleedin' awesome! Honestly it solves a TON of my storage issues in max. THANK YOU to who ever figured it out! It's absolutely amazing. wish it would work for abstractions but I can understand the problem with that. This rocks.
    • May 04 2009 | 1:11 am
      I hacked this together,
      static public Atom[] objectToAtoms(Object saveMe)
      serializes java object into atoms for MaxObject.save()
      static public Object atomsToObject(Atom[] atoms)
      deserializes an atom list into a java object. remember to cast!
      static public void setDivisionLength(int size)
      sets the length of each atom
      Here's the source
      package mat;
      
      import java.io.ByteArrayInputStream;
      import java.io.ByteArrayOutputStream;
      import java.io.IOException;
      import java.io.ObjectInputStream;
      import java.io.ObjectOutputStream;
      
      import sun.misc.BASE64Decoder;
      import sun.misc.BASE64Encoder;
      import markov.doc.v001.DocMarkovAlias;
      import markov.doc.v001.MarkovDocument;
      import markov.newgen.MarkovHouse;
      
      import com.cycling74.max.Atom;
      import com.cycling74.max.MaxObject;
      
      public class ObjAtomConverter extends MaxObject {
      
      	static int divisionLength = 200;
      
      	static public Object atomsToObject(Atom[] atoms)
      	{
      		String stringFromPatcher ="";
      		for(int i = 0 ; i < atoms.length;i++)
      		{
      			stringFromPatcher= stringFromPatcher+atoms[i].getString();
      		}
      		return SToO(stringFromPatcher);
      
      	}
      
      	static public Atom[] objectToAtoms(Object saveMe)
      	{
      
      		try
      		{
      			String a = OToS(saveMe);
      			return   stringToAtomArray(a, divisionLength);
      
      		}
      		catch (Exception a)
      		{
      			post("exception trying to save " + a.getMessage() + " " + a.toString());
      		}
      
      		return null;
      	}
      
      	static public Atom[] stringToAtomArray(String b,int divisionLength)
      	{
      		StringBuffer a = new StringBuffer(b);
      		float numOfSubStrings =  (float)a.length()/(float)divisionLength ;
      		post(numOfSubStrings+"