Problem with appending COMMENT field with letters

I'm having problems when I have letters in the COMMENT field and I want to append the INITIALKEY field into it. If the COMMENT field contains numbers it works fine but with letters it deletes them. What i have is:

Before (Works fine):
INITIALKEY: 4A
COMMENT: 5

Result:

INITIALKEY: 4A
COMMENT: 4A - 5

Before (Does NOT work):

INITIALKEY: 4A
COMMENT: ANY TEXT HERE

Result:

INITIALKEY: 4A

COMMENT: 4A<!--colorc--></span><!--/colorc--></i><!--coloro:#000000--><span style="color:#000000"><!--/coloro--><i> [<b>Notice it deletes '</b></i><!--colorc--></span><!--/colorc--><i><!--coloro:#000000--><span style="color:#000000"><!--/coloro--><b>ANY TEXT HERE'</b>]<!--colorc--></span><!--/colorc--></i>

Im using the following actions:
Name of action group: For&mat#INITIALKEY Key to Camelot Notation

Action #1:
Action type: Replace
Field: INITIALKEY
Original: B Major
Replace with: 1B

[ ] only as whole word

[ ] case-sensitive comparison

>>>>>>>Action #1 - #24 change keys to Camelot Notation>>>>>>>>

Action #25:
Action type: Format value
Field: COMMENT
Formatstring: %initialkey% - %comment%

Action #26:
Action type: Replace with regular expression
Field: COMMENT
Regular expression: ^\s+-\s+$|\s+-\s+$|\s+-\s+\d{1,2}[A-B]\s+-\s+$|\s+-\s+\d{1,2}[A-B]$|^(\d{1,2}[A-B]\s+-\s+)\d{1,2}[A-B]\s+-\s+(\w+)
Replace matches with: $1$2

[ ] case-sensitive comparison

I've tried using it without action #26 which just cleans up the COMMENT field but it still deletes text and not numbers.

I was just wondering what workaround I could use for action #25?

I just tried it and your action #25 works fine for me. I used the exact same field names and values.

What happens if you execute it alone, without the prior 24 actions in the group?

yes, Sorry I should of mentioned I tested it on its own and it works just fine. I Have also tried separating the actions with no joy.

I have placed the attached format action group above the replace and reg exp action group in the action list tree. (See attached).

I'm not sure if its a bug in the programme or what??

For_mat_INITIALKEY_Key_to_Camelot_Notation__1_.mta (55 Bytes)

For_mat_INITIALKEY_Key_to_Camelot_Notation__2_.mta (2.67 KB)


From a debugging standpoint, if you haven't done it already, see what you have if you end the action group after action #24. Are you certain that the INITIALKEY and COMMENT fields contain the values that you think they do going into action #25? Particularly the COMMENT field, given the behavior that you describe.

If indeed it's a program bug and the execution of the 20+ actions in one action group could have something to do with it, try breaking the group down into several logical parts.

I took your long action group, and replaced the last action with the one that combines the fields.

Action type: Format value
Field: COMMENT
Format string: %initialkey% - %comment%

And it still works as expected on my system. Could it have something to do with the unicode characters? Does it fail when the replaced strings do not contain one of these?

I have found the problem! Silly me. I have the following action which is above my new action which strips the comment field if it doesn't start with a digit as I always format my COMMENT tag like '4A - 5' 4A being the Camelot Notation and the 5 the rating of the track.

Action type: Replace with regular expression
Field: COMMENT
Regular expression: ^[^\d]+.+
Replace matches with:

[ ] case-sensitive comparison

So for anyone out there who wants to change the INITIALKEY tag from F♯ Major to 2B and append it to the start of the COMMENT tag then here is the working action.

Name of action group: For&mat#INITIALKEY Key to Camelot Notation

Action #1:
Action type: Replace
Field: INITIALKEY
Original: B Major
Replace with: 1B

[ ] only as whole word

[ ] case-sensitive comparison

Action #2:
Action type: Replace
Field: INITIALKEY
Original: F♯ Major
Replace with: 2B

[ ] only as whole word

[ ] case-sensitive comparison

Action #3:
Action type: Replace
Field: INITIALKEY
Original: D♭ Major
Replace with: 3B

[ ] only as whole word

[ ] case-sensitive comparison

Action #4:
Action type: Replace
Field: INITIALKEY
Original: A♭ Major
Replace with: 4B

[ ] only as whole word

[ ] case-sensitive comparison

Action #5:
Action type: Replace
Field: INITIALKEY
Original: E♭ Major
Replace with: 5B

[ ] only as whole word

[ ] case-sensitive comparison

Action #6:
Action type: Replace
Field: INITIALKEY
Original: B♭ Major
Replace with: 6B

[ ] only as whole word

[ ] case-sensitive comparison

Action #7:
Action type: Replace
Field: INITIALKEY
Original: F Major
Replace with: 7B

[ ] only as whole word

[ ] case-sensitive comparison

Action #8:
Action type: Replace
Field: INITIALKEY
Original: C Major
Replace with: 8B

[ ] only as whole word

[ ] case-sensitive comparison

Action #9:
Action type: Replace
Field: INITIALKEY
Original: G Major
Replace with: 9B

[ ] only as whole word

[ ] case-sensitive comparison

Action #10:
Action type: Replace
Field: INITIALKEY
Original: D Major
Replace with: 10B

[ ] only as whole word

[ ] case-sensitive comparison

Action #11:
Action type: Replace
Field: INITIALKEY
Original: A Major
Replace with: 11B

[ ] only as whole word

[ ] case-sensitive comparison

Action #12:
Action type: Replace
Field: INITIALKEY
Original: E Major
Replace with: 12B

[ ] only as whole word

[ ] case-sensitive comparison

Action #13:
Action type: Replace
Field: INITIALKEY
Original: A♭ Minor
Replace with: 1A

[ ] only as whole word

[ ] case-sensitive comparison

Action #14:
Action type: Replace
Field: INITIALKEY
Original: E♭ Minor
Replace with: 2A

[ ] only as whole word

[ ] case-sensitive comparison

Action #15:
Action type: Replace
Field: INITIALKEY
Original: B♭ Minor
Replace with: 3A

[ ] only as whole word

[ ] case-sensitive comparison

Action #16:
Action type: Replace
Field: INITIALKEY
Original: F Minor
Replace with: 4A

[ ] only as whole word

[ ] case-sensitive comparison

Action #17:
Action type: Replace
Field: INITIALKEY
Original: C Minor
Replace with: 5A

[ ] only as whole word

[ ] case-sensitive comparison

Action #18:
Action type: Replace
Field: INITIALKEY
Original: G Minor
Replace with: 6A

[ ] only as whole word

[ ] case-sensitive comparison

Action #19:
Action type: Replace
Field: INITIALKEY
Original: D Minor
Replace with: 7A

[ ] only as whole word

[ ] case-sensitive comparison

Action #20:
Action type: Replace
Field: INITIALKEY
Original: A Minor
Replace with: 8A

[ ] only as whole word

[ ] case-sensitive comparison

Action #21:
Action type: Replace
Field: INITIALKEY
Original: E Minor
Replace with: 9A

[ ] only as whole word

[ ] case-sensitive comparison

Action #22:
Action type: Replace
Field: INITIALKEY
Original: B Minor
Replace with: 10A

[ ] only as whole word

[ ] case-sensitive comparison

Action #23:
Action type: Replace
Field: INITIALKEY
Original: F♭ Minor
Replace with: 11A

[ ] only as whole word

[ ] case-sensitive comparison

Action #24:
Action type: Replace
Field: INITIALKEY
Original: D♭ Minor
Replace with: 12A

[ ] only as whole word

[ ] case-sensitive comparison

Action #25:
Action type: Format value
Field: COMMENT
Formatstring: %initialkey% - %comment%

Action #26:
Action type: Replace with regular expression
Field: COMMENT
Regular expression: ^\s+-\s+|^\s+-\s+$|\s+-\s+$|\s+-\s+\d{1,2}[A-B]\s+-\s+$|\s+-\s+\d{1,2}[A-B]$|^(\d{1,2}[A-B]\s+-\s+)\d{1,2}[A-B]\s+-\s+(\w+)
Replace matches with: $1$2

[ ] case-sensitive comparison

Please explain, what is the purpose of Action #26 and how does it work?

If you want to detect a 'Camelot string' then you can use this regular expression:
((?:[1-9]|1[0-2])[AB])

Be aware that you fill the tag-field INITIALKEY with bad data, when filling it with a 'Camelot string'.
The standard rules for ID3v2.3 and ID3v2.4 defines the frame TKEY as:
TKEY
The 'Initial key' frame contains the musical key in which the sound starts. It is represented as a string with a maximum length of three characters. The ground keys are represented with "A","B","C","D","E", "F" and "G" and halfkeys represented with "b" and "#". Minor is represented as "m". Example "Cbm". Off key is represented with an "o" only.

It would be a good practical advice to save already existing 'musical key string' into a user-defined backup tag-field before overwriting the tag-field INITIALKEY with 'bad data'.

DD.20120111.0854.CET

Once the format has been done the following cleans up the COMMENT tag.

^\s+-\s+|^\s+-\s+$|\s+-\s+$|\s+-\s+\d{1,2}[A-B]\s+-\s+$|\s+-\s+\d{1,2}[A-B]$|^(\d{1,2}[A-B]\s+-\s+)\d{1,2}[A-B]\s+-\s+(\w+)

^\s+-\s+ deletes 'startofstring'whitespace'-'whitespace' if only COMMENT is present.

^\s+-\s+$ deletes 'startofstring'whitespace'-'whitespace'endofstring' if both COMMENT and INITIALKEY tag are empty.

\s+-\s+$ deletes 'whitespace'-'whitespace'endofstring' if only INITIALKEY is present.
\s+-\s+\d{1,2}[A-B]\s+-\s+$ removes the extra INITIALKEY and 'whitespace'-'whitespace' after format from end of string.
\s+-\s+\d{1,2}[A-B]$ same sort of thing basically only just the INITIALKEY from end of string.
^(\d{1,2}[A-B]\s+-\s+)\d{1,2}[A-B]\s+-\s+(\w+) captures and sorts the COMMENT tag the way it should be formatted.

How is broken down?

So:
A sharp minor is A#m
A flat offkey is Abo

Correct?

stevehero, thank you for the effort to describe the regular expression so colourful.
Still it is not clear to me how the content of the COMMENT tag-field looks like, i. e. the different variations of text content, what the regexp should handle.
It seems to be a very special case for your own purposes?
Can you provide some samples to let me understand what the big regular expression can resolve?

I understand the term 'off key', stored in tag-field INITIALKEY as the single letter 'o', this way:
The related sound has nothing to do with the musical theory of western music and their melody scales.
The sound is simply off from any key.

DD.20120112.1950.CET

It changes the COMMENT field from:

12A - 12A - Any word character TO (NEED REG EXP TO MATCH THIS)
12A - Any word character (REPLACE WITH '$1$2')

^(\d{1,2}[A-B]\s+-\s+)\d{1,2}[A-B]\s+-\s+(\w+)
Text representation of regular Exp:
^(12A - )12A - (Any word character)


^ Anchors search to start of string.
( Start capture no#1.
\d{1,2}[A-B]\s+-\s+ finds '1A - '
)
End capture no#1.
\d{1,2}[A-B]\s+-\s+ finds '1A - '.
( Start capture no#2.
\w+ Captures word characters.
) End capture no#2.

I know:
A sharp minor is A#m

But how is:
A sharp major represented?