Extracting the key from the file name

Just Evan's icon

Hi, I'm trying to find a way to extract the key from the file name, bypassing all min/maj characters, but allowing # and b.

A couple of file name examples: sample_F#_one_shot.wav of sample_oneshot_F#maj.wav


I came up with a 2 step system using [regexp]. In the first step I find the key with symbols around it, for example: F; .F.; [F]; F#; _F#maj; and so on...


Something like: [regexp (?:[^a-gA-G#b]|^)([A-G](?:#|b)?(?:m(?:in(?:or)?)?|M(?:aj(?:or)?)?))(?:[^a-zA-Z#bd]|$)]


The second step is to simply get rid of all the characters, leaving only # and b in the key using another [regexp].

Problem: In the first step I am unable to achieve high accuracy in isolating the key with symbols.

Question: Perhaps there is an easier way to do this?

Source Audio's icon

don't have max at hand, but

refgexp [A-G] can split keys (capital letters),

regexp [A-G](\\#+|b+) would check if # or b is next to key letter

also atoi - some matching - itoa would do...

Source Audio's icon

.......................

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