Convert Color to Frequency (or MIDI Data)

Sophia's icon

Hello!
Recently, with the help and generosity of these forums, a patch was created that uses a midi keyboard to control a digital LED strip where each LED lit up a specific color based on its corresponding light frequency and in a specific position based on what note was pressed (Link to forum found here). I was wondering if I could actually do the reverse of this and possibly use swatch to choose a color that would then output its corresponding frequency. Hopefully with the final product being able to output chords based what color is input (and actually sound pleasant), but does anyone know if this would be plausible or where to start with the conversion?

Martin Beck's icon

I recommend to have a look at the Bach and Cage packages. There are lots of examples that are dedicated to chords and tone relationships presented with UI elements that also use color panels. Might be a "little" more than the scope of your question but same direction.

Sophia's icon

I looked at the packages but I am not quite sure how I can integrate color into it. So far I just mapped out what colors I want for each note but that is as far as I have gotten. I am still doing more research.

color_to_frequency.maxpat
text/plain 8.33 KB

Sophia's icon

The overall goal is to give the patch a "color score" and have it convert the colors to notes, then export the notes as MIDI data to Logic

Martin Beck's icon

I will have a look for the patch from Cage/Bach...do not remember how it was called. What I have not understood from your question is what is your basic problem?
Are you looking for concepts how to convert a color space triple into the one dimensional property frequency? Or do you regard color as spectral property of light (rather than perceptual property of human color perception) and you are looking just for a somehow meaningfull scaling of light frequency to audible frequency? Or do you have problems with specific Max objects?

Sophia's icon

In theory, yes I am looking for a meaningful way of scaling light frequency to audible frequency. However, seeing as I am on a time crunch as this is for a final project due in 2 weeks, help in converting a color space triple into the one dimensional property frequency would be more practical.

Sophia's icon

My previous patch (linked below) was able to do the opposite, but I am not quite sure how to reverse the process

color_mapping(keys).maxpat
text/plain 31.28 KB

Martin Beck's icon

The reverse process is somehow limited as the %-operator has no inverse.
This here could be done. But you still have to figure out how to set the correct offset of the notes.

Max Patch
Copy patch and select New From Clipboard in Max.

Parmerud's icon

Hello, do I understand it as you want to control pitch with light (emitting different colors)? If so you are in a rather difficult situation since if you want to do this in real time (playing a synth with light as a controller for example) using differently colored LEDs (or by any other source of light) you would need some sensor that would be able to give you the frequency of the emitted light (and maybe intensity to control volume). Basically converting from blue (400nm) to red (700nm) is easy but how would you get that info/analyzed input? There are some analyzers that will output data about LED lights (intensity and frequency) but they can probably only see one LED at the time and for sure there is no interface to get the data into Max for conversion...and they are expensive too.

Sophia's icon

You bring up a very good point. I think I am going about this wrong. But the basic premise of our project idea is to have a "color score" (a video of individual colors that change every second or so) and the max patch analyzes the score and outputs the corresponding note based on its frequency as MIDI data. I am thinking perhaps a conversion from RGB to XYZ, XYZ to wavelength, then wavelength to frequency might work instead. I am starting a new patch and so far it looks like this.

color_to_sound.maxpat
text/plain 45.76 KB