Conditionals with MIDI Chords

rarar's icon

Hi All,

Very new to max and trying to make a video art project of sorts using a simple piano prelude and some video clips. I'm wanting to get some input on how to get conditionals (i.e, if/else statements) in max to trigger various video clips to play based on specific chords.

The particular part I'm stuck on is trying to structure the correct conditional or switch statement. This is basically going to be a pretty hefty switch in a traditional programming sense with a variety of chords to listen to. Any tips or suggestions would be great. I've attached the patch in progress.

2380.ChopinChords.maxpat
Max Patch
Roman Thilenius's icon

to switch statements there are at least two ways, you can use scripting to re-create
a new [if] object, or you can use [gate 1 2 3 4 5 6 7 8 9 10].

rarar's icon

What about determining the type of chords that were played? For example, if someone played C2-E2-G2, how could I recognize that?

broc's icon

This patch recognizes C major and C minor triads. It can easily be extended.

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

(note: save and close the patch once to cause initialization)

Luke Hall's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Maybe reduce the note names to number values and pop some common chords into a [coll] to get you started, here's a little example that I had floating around.

Roman Thilenius's icon

it is quite some work to determine certain chords, given the number of possible
different chords.

when i remember right my patch for finding C-minor were using something like this:

if ($i1%12)==(0) && ($i2%12)==(4) && ($i3%12)==(7) then 1 else 0

you could use variables for the matches:

if ($i1%12)==($i4) && ($i2%12)==($i5) && ($i3%12)==($i6) then 1 else 0

this way it is still limited to chords of exactly 3 notes of 3 different keys.

the more extras you want, the more mindfuck is involved.

-110

rarar's icon

Thanks for the help everyone. I will have a predefined set of chords to listen to as triggers for other actions. I've already started by packing a list of 4 numbers from the chord values (e.g., C2-E2-G2-C3 would create a list of 48 52 55 60). At this point, I would need to create a filtering mechanism to basically check if a list matches a predefined list. Luke, your patch looks the closest to what I'm trying to achieve, however I couldn't get it to work. Could anyone point me in the right direction as to how I could create a handful of comparisons to check if the values in a MIDI-generated list match that of a predefined set?

broc's icon

Do the predefined chords have the same number of notes?

rarar's icon

Yes, they will all have 4 note chords—I'm using a poly 4 to listen and compile a list. Seems like I will need to use some combination of zl compare and a collection object as a repository of pre-defined chords. The issue I have with the collection is that defining an index value of a root note of a chord will be difficult since the order of the notes in the list will change depending on how the chord is played...

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.
broc's icon

So I think Chris provided a great general solution.

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

Alternatively, here is a simple solution that should also work in your case.
Just fill the [coll] with your specific chords.

Luke Hall's icon

Try patching a [notein] in place of the "keys" subpatch right at the very beginning. That's just a stand in to turn my laptop keyboard keys into a pretend midi instrument for convenience. It should work OK-ish then, but it is just a sketch and could do with some expansion (inversions definitely need some work!)

rarar's icon

Guys, thanks so much—I've been able to piece together what I needed for this project (and what I didn't need serves as a great proof of concept for some other ideas I have in mind!)

Thanks again!