Pixels luminance --> MIDI notes

playmodes's icon

Hello Everyone!

I'm working on a patch where i receive a 64*35 syphon texture, then i get the luminance for each of the 2240 pixels (64*35).
I want to generate a MIDI note for each pixel which is lit (not black). Obviously, as i have 2240 pixels and there's just 127 MIDI notes in a channel, i should repeat some notes, maybe creating a map of notes which repeat recursively...

I'm having some problems in transforming the boolean luminance information into midi notes... I used jit.iter and zl group to transform the jitter matrix into a list of numbers, but once i have this list of numbers, when i feed makenote i dont get reliable results.

I'm afraid my approach is wrong from the begining, and i'll be glad to hear some suggestions from you.
I attach a simplified version of the patch, so that you can check it

thank you!

MIDIficator_nosyphon.maxpat
Max Patch
Jean-Francois Charles's icon

A couple of things:
- your "luminance" matrix is likely a one-plane matrix, not 2 planes.
- you are grouping / ungrouping the data: this is unnecessary IMO.
You are on the right track, but I think you need to clearly define your own algorithm first without Max: how do you want to convert the data? Do you want the luminance value (1-255) to have an influence (velocity) or not?
How do you reduce your data to numbers smaller than 127 or not? Or do you play with delays to make rhythms?
How often do you want the new notes to be triggered? Surely not every 30 ms (even if it's what the video might give you).
Once this is clear, it won't be hard to make it happen in Max.

playmodes's icon

Hello Jean-Francois, and thanks for your support.

-Regarding the luminance matrix, you're right... i couldn't get the luminance data just by making a 1 plane matrix, so i used 2 planes. Now i found jit.rgb2luma, which looks like a better solution... thanks for pointing this!
-For the ungrouping/grouping... i do it this way to get an integer list from the jit.matrix, i don't know any other way to do it... well, maybe getcell, but i don't think it's an efficient way to parse that many integers... maybe i'm missing some object which could help in this task!!

Regarding the other questions you make, which i tink are all related:

-I want to trigger a note whenever a pixel changes its state from black to non-black, and the note is held until the pixel goes again back to black; hence the use of zl.change. So no velocity information is needed... at the end of the day, this patch is going to be used to control a pipe organ which has no velocity features.

-Regarding pitch information, i still need to conceptualize which pixels represent which note. It will sure be a constant 64*35 integer list.
Let's think, for example, that all pixels in row 1 will always trigger note 60, and there will be an increment of +1 until row 35.
Maybe i should lace this list with the other velocity list, and then get pairs of note-velocity to feed noteout?

Thanks again for your help!

playmodes's icon

I could make some steps forward... as Jean-Francois suggested, there was no need to ungroup-regroup the matrix.
I found that jit.spill was the way to go to transform a matrix into a list, and after finding how to work with lists larger than 256 elements, i could lace my velocity and pitch lists using zl.lace.

So i have a resulting list of laced pitches and velocities(by the moment just 0 and 1 instead of 0 and 127).
When i ungroup this big list into lists of 2 elements (pitch and velocity), everything is triggered for each frame... but i want the triggers to be done just if the velocity of that pair of values had a state change.
I don't find the way to use zl.change in this situation, and i'm not sure, again, of having a correct approach for the problem...

Find attached the patch as it is at this very moment.
Any thoughts?

thank you very much!

MIDIficator.maxpat
Max Patch
playmodes's icon

I finally could figure out the last part of my patch. Using zl compare was the key for what was left.

I'm attaching the final patch, just in case it could be useful for anyone else in the future.
I guess this could be nice to transform jit.conway into a midi sequencer, a la reaktor-newscool, for example...

MIDIficator2.maxpat
Max Patch
Jean-Francois Charles's icon

Good to know you got it to work!