< Back to IRCAM Forum

Musical Analysis - Note color change systemically based on position or pitch

Hello everyone, in OM7.6, it is possible to change the color of notes in all classes/score objects. I need (for the purposes of musical analysis using OM) a function that allows me to change the color of selected notes systemically based on a) specifying the position (posn-match) or b) specifying the pitch in MIDI cents. At the same time, I need to be able to mark one note or group of notes with one color, another group with another color, etc. The ideal solution would be something like posn-match, where I enter the pitch or position in one slot and the color in another slot, all in a tree list structure. Can you think of a solution?

CODE_color-note.txt (670 Bytes)

I used AI to create the attached code, but it doesn’t work.
Does anyone have any ideas?

Dear Petrh,

Hopefully, AI didn’t yet replace humans :slight_smile:
Here is a solution:

The patch:
Patch 12.omp (8.6 KB)

Best
K

Here a version which automatically include tied notes:
notecolors.zip (3.3 KB)

(unzip then import the folder in the workspace)

Best
K

Thank you very much, Karim! We have met here many times before. I have a question: are the parameters in the Lisp function “om-make-color” in the form of “0.1,” “0.5,” etc. color parameters? Is there some kind of reference colorimetric scale? RGB? But maybe it’s simpler than it looks (sorry, I got up at 5 a.m. today :)). P-

Dear Petr,

The arguments are for RGB colors (Red Green Blue) and values are floats.
where
(om-make-color 1 1 1) is white
and
(om-make-color 0 0 0) is black

all in between is a mix of the three RGB colors

You can look them up in this file:
code/kernel/graphics/graphictools.lisp

Where the code folder is inside the OM app folder (depends if you are on mac, windows or linux). Let me know.

Best
K

Dear Karim, thank you very much for your willingness and help, it works great, have a nice day, P.

Dear Karim, I have a tool from you for coloring notes in the Voice object based on their positions. Now I’d like to ask about one more detail. I tried using the “om-make-color” function in omloop so that I could color different notes in different positions with different colors (I use OM for analysis and need to mark parts of compositions with different colors). The entire algorithm you gave me works in lambda mode, and I’m unable to integrate it into omloop so that it works (i.e., a different RGB color for each position list) Can you please advise me? Thank you, have a nice evening, Petr

Dear Petr,

No problem. Just to know, you want the same thing, but with a different color for each position? Is it so?

Best
K

Dear Karim, I apologize; I didn’t describe the problem clearly enough. Let me clarify: each position list should have its own color. The function you sent me (the internal patch: set-chord-color), which handles the color change, should take as input a treelist of positions and the corresponding treelist of RGB colors. To be precise, for example, the position treelist: ((0 1 3 4 6) (7 8 9) (8 9 10 13)) and the corresponding RGB treelist: ((1 0 1) (0 1 0) (1 1 0)).
Finally, one more question: in the example given, the second and third list in the position treelist overlap (both contain positions 8 and 9). Would it be possible to modify the color-changing algorithm so that, in such a case, the notes at these positions (8 9) are automatically colored gray (0.5 0.5 0.5)?
Thanks again and best regards, PetrH

Oh this is completely different. Can you:

  • provide a tree example
  • do you consider a position to be of also a position of a continuous chord or rest?

Best
K

Dear Karim,

yes, you’re right, I’m not using conventional terminology in this communication; my apologies. In this context, a “note” simply refers to any symbol that indicates pitch or duration, including rests. A melody is simply a sequence of “notes” in a given position.

A chord, e.g., (6000 6300 6700), played harmonically consists of three different notes in the same position. To be more specific, let’s consider a piece composed, for example, of just five chords, each with only three notes. All chords are played harmonically. A list of positions that would mark all the “notes” in the given composition should look like this: (0 0 0 1 1 1 2 2 2 3 3 3 4 4 4).

If the first three chords were to be green and the next two red, then the position list would be a treelist and would look like this: ((0 0 0 1 1 1 2 2 2) (3 3 3 4 4 4)). The RGB color treelist would then also contain two lists ((1 0 0) (1 1 0))

The algorithm you sent me can color notes that are in a given positions. Let me give another example. Notes in positions (1 3 4 5) should be red. If I want to color other notes at different positions, e.g., the notes at positions (2 3 5 6) green, I’ll enter the RGB parameters for the green color. After the iteration, the notes at positions (2 3 5 6) will be green, but the red color of the notes at positions (1 3 4 5) will disappear.

That is why I wanted to put the algorithm in an OMLOOP and specify as inputs a treelist of positions, e.g., ((1 3 4 5) (2 3 5 6)), and a treelist of RGB colors, e.g., ((1 0 0) (0 1 0)). However, I was unable to create such an OMLOOP. I wanted to ask for such an OMLOOP or another solution.

At the same time, I took the liberty of asking for one improvement. In the given situation, the notes at positions (1 3 4 5) are red and at positions (2 3 5 6) are green. Both lists have an intersection (3 5). Would it be possible to automatically color the notes in the overlap area gray using the RGB values (0.5 0.5 0.5)? The result would then be that only the notes at positions (1 4) would be red, the notes at positions (2 6) would be green, and the notes at position (3 5) would be gray.

Thank you once again for your willingness and kindness, PetrH

Thank you for the precision.
However, please let me know if you need to color a NOTE object or a CHORD object, which is different in OM. Your explanation above seems different of what you have asked.
So for me it is not really clear. Sorry.
Can you send me a voice to start with It is much easier for me than to start from scratch. or a graphical explanation of what you want to achieve using your input parameters.

Best
K

best
K

Dear Karim, I apologize for the complications. Thank you very much for taking the time to address my issue.

I am attaching a patch that contains the algorithm you created for me. The patch also includes two “voice” objects. One is the subject of the analysis (Varese - density), and the other is for illustration (voice-position). The algorithm you provided colors the notes according to their positions. There are two types of input data: input 1: a list of positions; input 2: a list of RGB color identificators. This is how the algorithm currently works—it colors the notes at the given positions with a single color; for example, notes at positions (0 3 5 4) are colored green with RGB: (0 1 0).

Now I’m trying to make two improvements. The first improvement is this. I need it to be possible to color different parts of the composition with different numbers of colors. For example, color the notes at positions (0 3 5 4) green (RGB: (0 1 0)) and at the same time color the notes at positions (4 5 6 9) red (RGB: (1 0 0)).

Ideally, the input data could take the form of a treelist (just like in omloop). Input 1: treelist of positions ((0 3 4 5) (4 5 6 9)) and Input 2: treelist of RGB colors ((0 1 0) (1 0 0)).

The second improvement should be as follows. The position lists in the treelist ((0 3 4 5) (4 5 6 9)) form an intersection. In the first list, which specifies the notes to be colored green, the positions (4 5) are included, among others. In the second list, which marks the notes to be colored red, the positions are also (4 5). The algorithm with the second improvement should be able to automatically color such an intersection (4 5) as gray RGB: (0.5 0.5 0.5)

Now, a clarification of what I mean when I say “note” and “position” and where I work with “position” and “note.” I work in the voice object. That is where I have the transcribed compositions for analysis. A “note” is, of course, a symbol that indicates the duration or pitch of a tone; a “note” is also a rest. “Position” is the placement of a note within the duration of the composition. In monophonic music, this is straightforward. In polyphonic music, “position” should denote notes according to the logic described in the attached image (the positions are marked with red numbers in the picture),

Thank you, have a nice day, PetrH

patch with voice and algo to karim.omp (97.6 KB)

Thank you Petr,

Now it is clear for me. So it is indeed NOTE objects.
I will see what i can do here.

Will get back to you ASAP.

Best
K

Dear Petr,

So here it is (hoping this is what you want…):

The code is in lisp so you need to load it either by putting the lisp file in the init folder of your OM application to make it available to all workspaces, or put it in the user folder of your workspace:

analysis-color.lisp (2.1 KB)

Note: The NOTEs position depend on the order they are in the CHORD, so not necessarily from bottom to top.
Best
K

,and the patch,

analysis-colors.omp (10.2 KB)

Dear Karim, thank you very much for the solution. I placed analysis-color.lisp in the OM init folder and tested the algorithm on two Voice objects.

For the Voice object with chords, the notes were colored, but in a strange way. The first two were supposed to be red, the next two green, and the following two blue. However, the result is different; see the image voice-position-test.

In the second case, I tested a monophonic Voice, and OM displayed an error message—see the image voice-position-test-2.

Did I make some ( stupid) mistake somewhere?

Have a nice evening, P-


The second issue is my bad, will fix it
the first is that the voice you are using is already colored. I will also fix it.
ASAP

BEst
K

Dear Petr,

this should work.
analysis-color-1.lisp (2.4 KB)

replace the old file by this one.
Keep me informed.

Best
K

Dear Karim, thank you very much. I’ve only tried it once so far, but it works perfectly.
Thanks again, and best regards, P-

1 Like