Load coll MATRIX into C++ to create an external file

    Aug 15 2013 | 7:50 am
    Hello members of this forum,
    I have a coll object in a patcher which is a MATRIX containing values in rows and colums, the information contained in this matrix updates constantly, so this means this coll MATRIX is a dynamic Matrix.
    I would like to send all the MATRIX values to a external object that I have created in the same patcher.
    To achieve this I need to load all the matrix values in a 2D array in C++ code: matrix[rows][columns] . How can I read the values from a coll Object and import them in the c++ code?
    The matrix values are in FLOAT format.
    I know how to introduce a float value directly in the c++ code from one inlet with this command:
    //Incoming FLOAT – - – - – - – - – - – - – - – - – - – - – - – -
    void float_inlet(long inlet, double v) {
    m_gain[inlet] = v; // The float number coming from the inlet (v) will be stored in an internal array in the position of the inlet number.
    I would like to use only one inlet coming from the coll output containing all the values of the matrix, and then, using a c++ command to create an internal matrix and store all the values.
    I hope I have explained well enough
    Thank you very much.

    • Aug 15 2013 | 9:06 am
      the solution involves two steps.
      Firstly, you need to get the coll data into your object. Since you can't directly access a coll from your code, you have (at least) two possible solutions. On the one hand, you can create a method accepting lists and another one accepting bangs (see the relevant parts of the documentation on how to do this). Let's call these process_list and process_bang, respectively. You'll want to connect the coll's first and last outlet to your object so that you'd be able to receive the data resulting form `dump'-ing the coll and the bang at the end. This is a simpler solution, however, in this case your object would require direct patching in Max. On the other hand, you could instantiate a hidden coll within your external; by setting up a scheduled task, you could poll this coll regularly with direct calls to its methods. This solution is much more complex and requires a good understanding of the Max SDK, however, it hides everything from the Max user, which may be convenient if your project is big enough.
      Secondly, you have to create your matrix. Assuming that you implement the first input method from the paragraph above (ie. you don't mess around with hidden colls within your object), the biggest issue would be that you don't know the dimensions of the matrix at the time when you `dump' the coll (coll won't give you this information in advance with a call to `dump'). If your matrix has a fixed size, this wouldn't be a big issue; assuming that the dimensions of the matrix may change by each dump, you have (again) at least two solutions. You could either get the dimensions of the matrix in advance by some Max-patching and then let your external know this information in advance. Although this solution is quite easy, it's not very fool-proof in a multithreaded scenario. The other possibility would be to store the incoming information (temporarily) in a linked list (or an STL container if you prefer to code in C++) within your process_list method, and then build the matrix (and clear the temporal linked list/container) within the process_bang method.
      Therefore, in process_bang, you'll want to
      1. free the old matrix, if it's not empty
      2. reserve new memory for the new matrix (it's dimensions can be computed based on the temporarily stored info)
      3. fill the new matrix with the temporal data
      4. clear your temporal linked list/container.
      Hope this helps,
    • Aug 15 2013 | 9:23 am
      Hi Adam,
      thank you very much for your detailed description. I will start working on it right now and let you know how it works.
      Best regards
    • Aug 15 2013 | 2:38 pm
      Hi Adam,
      I am having some difficulties to implement the process_list method you suggested.
      On the first place, I have no idea how to tell my external object to read a coll Matrix (containing a 2D array of elements) from one unique inlet. (I know it is possible to indicate the type of input A_INT, A_FLOAT, A_GIMME... when creating a method ) but all those are refered to only one element coming into one input, not a list.
      On the second place, the elements need to be stored in the internal memory or just read directly from the matrix?
      In case the elements need to be stored, which kind of Data storage sytem should I use? (the type of data storage modules is in MaxAPI 6.0.4 documentation page 276). In this list I can´t find a suitable module to store elements from a Matrix.
      These are my current problems. Please, ask me for more specific details if needed.
      Thanks a lot.
    • Sep 02 2013 | 1:39 pm
      I solved my issue!! thank u very much for your help :-)
    • Sep 09 2013 | 2:46 pm
      Hi, I've been offline for a while (sorry for that), but I'm happy that you managed to solve it.