INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Expressions in MC12  (Read 1064 times)

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 71469
  • Where did I put my teeth?
Expressions in MC12
« on: August 10, 2008, 04:18:42 pm »

This is a little bit of a mess.  Sorry.  I deleted the thread by mistake when editing it.

I'm going to lock it.  Please start a new thread if you need to.

Jim

----------------
Musichawk started this here:

Author Topic: Possibly more bugs in .529 (sorry)  (Read 172 times)  

MusicHawk
Regular Member
World Citizen

Posts: 240



  Possibly more bugs in .529 (sorry)
« on: Yesterday at 02:58:08 PM » Quote Modify Remove Split Topic  

--------------------------------------------------------------------------------
I'm getting anomalies, trying to apply an expression to a track's Filename via the Rename/Move action. Maybe what I'm trying is beyond what an expression and/or functions can do, but some aspects seem odd enough to be either bugs or needing documenting...

Here's the entire file name expression I'm trying, a seemingly-slight modification of an expression I've used without problem:
FixCase(Mid([Artists],0,20) - [Name]If(IsEmpty([RecVer]),, ~[RecVer]),4)

The new and misbehaving part of the file name expression is this:

If(IsEmpty([RecVer]),, ~[RecVer])

RecVer (recording version) is a custom library field that is either empty or has some text. This help me keep track of certain song-artist combinations that have been recorded multiple times, such as different live performances, or different arrangements, etc., so while they have the same Artist and Name they are different enough to identify separately. There are enough in my library that it can get messy, so I use this custom field to keep things straight in the database.

At the file level, my hope is that when RecVer DOES have text, I want to append it to the Name part of the Filename to make the file name unique. (Otherwise I have to manually edit the file name unless I'm one of the situations where MC assigns (1), (2), etc.)

Possible Bug #1 is that IsEmpty ALWAYS evaluates as if RecVer is NOT empty. So ~ and the value of [RecVer] gets appended to Name, which I only want if RecVer is actual text I typed in.

Possible Bug #2 is that when RecVer is empty, MC gives it a value that only shows up via an expression: "Unknown RecVer". This is probably why IsEmpty([RecVer]) always evalutes as false. When RecVer is empty from my perspective -- nothing in the field -- "Unknown RecVer" gets appended to my file's Name. Not what I want. If MC is always going to assign "Unknown..." to an empty text field, then of what use is IsEmpty?

Possible Bug #3 is that when I put a value into field RecVer in ONE file in the database, then select that ONE file and apply the Rename/Move action, MC tells me "Changes have been made to two files. (modified fields: Filename)". TWO FILES? Hmmm... One of us can't count. MC does this every time if there's a value in RecVer (I can retrigger the behavior by changing or adding/removing the value, so Rename/Move has something to do.) Is there something about the expression that would cause recursion of the Filename change process?


Assuming RecVer can be made to behave, two questions about expression syntax and function behavior where my experiments have not yielded suitable results:

Question #1: I want the expression to output a NULL string when RecVer is empty, tried by specifying ,, with nothing between. Is this the correct syntax, or is there a way to indicate a null string/value?

Question #2: How can I force a blank/space character at the START of a string? In my expression I want ~ to be preceded by a space, but MC by design ignores spaces immediately after the comma in a Function. If I use " " MC turns it into underscore-space-underscore. Why?

Big Question: Is this simply beyond what MC's expressions can do?

 --------------------------------------------------------------------------------
Managing my music with JR since Media Jukebox 7
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 71469
  • Where did I put my teeth?
Re: Expressions in MC12
« Reply #1 on: August 10, 2008, 04:19:16 pm »

 
 
 
Alex B

--------------------------------------------------------------------------------
The following works for me:


Quote from: Alex B on June 09, 2008, 01:32:56 PM
Directories:

Code:
[Album Artist (auto)]\[Album]\
Filename:

Code:
If(IsEmpty([Disc #],1), [track #], CD[Disc #] - [track #]) - If(IsEqual([Album Type], Multiple Artists /(complete/), 1), [Artist] - [Name], [Name])
Some examples of the resulting filenames:

Single Artist, no disc number:
\The Cure\Japanese Whispers\06 - Speak My Language.mp3

Single Artist, disc number:
\Bob Marley & The Wailers\Burnin' (Deluxe Edition)\CD2 - 08 - Kinky Reggae.mp3

Multiple Artists, tagged Album Artist, no disc number:
\Tiësto\Elements Of Life\03 - Tiësto feat. Julie Thompson - Do You Feel Me.mp3

Multiple Artists, automatic Album Artist value, disc number:
\(Multiple Artists)\Champs-Élysées Café\CD2 - 04 - Chateau Flight feat. Beretta 9 - Down At The Rotisserie.mp3

-- The text string "CD" will be added if the "Disc #" field has a value.


As a test, I just tried a shorter version (which worked fine):


Code:
If(IsEmpty([Disc #],1), [track #], CD[Disc #] - [track #])
then I changed the [Disc #] field to a user field:


Code:
If(IsEmpty([Encoder],1), [track #], CD[Encoder] - [track #])
The latter didn't work. MC ignored the Encoder field completely even though it had a value. Apparently there's a bug somewhere.  
 
--------
 
MusicHawk

Thanks for the test.

I don't get my custom field ignored -- if it has a value, the expression uses it (though with other issues related to inserting spaces). The big problem for me is that MC gives the field an "Unknown.." value when I intend it to be truly empty. Interesting that didn't happen to you...  
----------
 
marko
MC13 Beta Team
Citizen of the Universe

Posts: 3122


(Not) Bugs

Quote
Possible Bug #1 is that IsEmpty ALWAYS evaluates as if RecVer is NOT empty. So ~ and the value of [RecVer] gets appended to Name, which I only want if RecVer is actual text I typed in.

Possible Bug #2 is that when RecVer is empty, MC gives it a value that only shows up via an expression: "Unknown RecVer". This is probably why IsEmpty([RecVer]) always evalutes as false. When RecVer is empty from my perspective -- nothing in the field -- "Unknown RecVer" gets appended to my file's Name. Not what I want. If MC is always going to assign "Unknown..." to an empty text field, then of what use is IsEmpty?

This behaviour is 'by design' and only affects the rename, move and copy tool.
If you ask MC to create a folder based on \[artist]\ and the [artist] field is empty, this would be an illegal operation in windows, so, MC automatically substitutes "Unknown [field]" to cover these situations.
What this means is, that by the time the expression evaluator gets a look in, the value is no longer empty. The answer to this is to use IsEqual rather than IsEmpty...

if(isequal([RecVer],unknown,8),, ~[RecVer])

I'll need more time to test Bug #3

Questions

Quote
Question #1: I want the expression to output a NULL string when RecVer is empty, tried by specifying ,, with nothing between. Is this the correct syntax, or is there a way to indicate a null string/value?
You are using the correct method and syntax. Refer to my answer above regarding the 'rename move and copy' tool + empty values.


Quote
Question #2: How can I force a blank/space character at the START of a string? In my expression I want ~ to be preceded by a space, but MC by design ignores spaces immediately after the comma in a Function. If I use " " MC turns it into underscore-space-underscore. Why?
Why?
Because any white space that comes after a comma is ignored.
If you use " ", MC translates this to _ _ because double quotes are not allowed in windows file or folder names, so MC replaces them with underscores.
To force the expression evaluator to insert the space, it needs to be escaped using a forward slash, like so:

if(isequal([RecVer],unknown,8),,/ ~[RecVer])


Quote
Big Question: Is this simply beyond what MC's expressions can do?
No

-marko.  
 
 
 
marko
--------------------------------------------------------------------------------
Quote from: Alex B on Yesterday at 03:57:44 PM
As a test, I just tried a shorter version (which worked fine):


Code:
If(IsEmpty([Disc #],1), [track #], CD[Disc #] - [track #])
Interesting...
Switching the check to a 'number style' compare (ie. a zero = empty) allows this to work, however, switch it back to a string compare, and you will see the same behaviour MusicHawk does. My instinct is that this works here because the [disc #] field will have its 'data type' specifically set to 'integer'


Quote from: Alex B on Yesterday at 03:57:44 PM
then I changed the [Disc #] field to a user field:


Code:
If(IsEmpty([Encoder],1), [track #], CD[Encoder] - [track #])
The latter didn't work. MC ignored the Encoder field completely even though it had a value. Apparently there's a bug somewhere.

The '1' is switching the compare to a 'numerical' style compare. The [encoder] field is set to use the 'string' data type, so I guess, numerical compares will always fail.
If you remove it, it switches to a 'string' compare, and exhibits the by now familiar, "never empty, 'Unknown Encoder' " behaviour.

-marko.
  
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 71469
  • Where did I put my teeth?
Re: Expressions in MC12
« Reply #2 on: August 10, 2008, 04:19:24 pm »

 
MusicHawk

  Re: Possibly more bugs in .529 (sorry)
« Reply #6 on: Today at 11:33:37 AM » Quote Modify Remove Split Topic   

--------------------------------------------------------------------------------
if(isequal([RecVer],unknown,8),,/ ~[RecVer]) does the job.

Thank you very much for clarifying the situation and providing a workaround!

On my soapbox...

I think MC's behavior of sometimes inserting a value of "unknown" should be documented in the Wiki on the Expression Language page, noting that MC does this substitution in one use of IsEmpty but not other uses. I spent hours chasing this "bug" ...

Also, this statement on the Wiki page is not the full explanation of spaces in expressions:
"Spaces are interpreted literally in all areas, except immediately after a comma in a function."

It should say something like this:
"Spaces are interpreted literally in all areas, except immediately after a comma in a function. However, a space can be inserted immediately after a comma by precediing it with a / escape character."

Why do I want a space in this position? It's peculiar to my library's use of custom fields and folder/file naming expressions. It allows me to change how I identify multiple recording versions, by moving that info from the end of the Name value to a separate field, and have it yield exactly the same file names so I end up renaming thousands of them.

Back to MC inserting "unknown", sure, Rename/Move can't result in a folder or file name that is ONLY a space, or starts/ends with a space. BUT a space IS allowed and is common in other character positions in the folder/file name. So ALWAYS adding "unknown" in a folder/file expression is over-doing it a bit. It's frustrating to not have control over the "unknown..." behavior.

Why not insert "unknown" only AFTER the expresssion is evaluated, and only when truly necessary? A function would then work as-documented in all cases, but MC would adjust the result when the evaluation yields an "illegal" Rename/Move value. (In my expression, an empty/null/space in RecVer would not cause any harm because I'm trapping it via a function). I know, building in logic to consider the full resulting string would be extra overhead. Maybe just auto-trim the final folder or file name value so there's no space at either end?

More opinion: Is the word "unknown" the best term? It's stating that MC doesn't know something internally, yet it's being applied to external folder/file names where it seems like a peculiar "statement". A blank value isn't necessarily unknown to the user; often its simply not applicable or relevant to the track.

And adding the field name after "unknown" might seem to be helpful to the user, but is it? It's obvious in the database that a tag field/column is empty; who would look to their folder/file structure to discover that they have "unknown" info?

If MC must sometimes insert a value for "empty" data, it would be terrific to let the user specify via Options the string, and whether the field name gets appended to it. I'd likely use just "none" or "empty" or some other term that is stated from MY perspective.


Re Bug #3, it is confusing but probably just a harmless misstatement by MC. I don't see that is actually changing the file name of two files when I only select one. But it's difficult to be sure, so it likely merits investigation.

 
 

marko

--------------------------------------------------------------------------------
Quote from: MusicHawk on Today at 11:33:37 AM
Also, this statement on the Wiki page is not the full explanation of spaces in expressions:
"Spaces are interpreted literally in all areas, except immediately after a comma in a function."

It should say something like this:
"Spaces are interpreted literally in all areas, except immediately after a comma in a function. However, a space can be inserted immediately after a comma by precediing it with a / escape character."

Done.
I'll try and get around to the IsEmpty vs IsEqual thing soon. I've got some half-finished stack pages laying around here that need to take priority, once I've finished "The Fly"....

Not enough hours in the day!!

-marko. 
 
--------------------------------------------------------------------------------
 
Alex B



  Re: Possibly more bugs in .529 (sorry)
« Reply #8 on: Today at 12:14:52 PM » Quote Modify Remove Split Topic   

--------------------------------------------------------------------------------
Quote from: MusicHawk on Today at 11:33:37 AM
if(isequal([RecVer],unknown,8),,/ ~[RecVer]) does the job.

Out of curiosity, what is your full string now?

I figured out that

Quote
if(isequal([RecVer],unknown,8), FixCase(Mid([Artists],0,20) - [Name],4), FixCase(Mid([Artists],0,20) - [Name]/ ~[RecVer],4))
should work (I tested it with my custom fields).

I tried to simplify it, but I couldn't make it work when "if(isequal" was not in the beginning. Though, it is quite possible that I did a typo when I quickly tested different variations. 

--------------------------------------------------------------------------------
The Cosmic Bird – a triple merger of galaxies: http://www.eso.org/public/outreach/press-rel/pr-2007/pr-55-07.html
 
 
MusicHawk

--------------------------------------------------------------------------------

Here's my complete Rename/Move file name expression:

FixCase(Mid([Artists],0,20) - [Name]if(isequal([RecVer],unknown,8),,/ ~[RecVer]),4)

It works to have FixCase evaluate the overall result, reliably converting the whole thing to lowercase (so my files are compatible with all types of storage systems).

I'd been using a Name suffix of ~SOMETHING to identify song versions, until I added the RecVer field (after reminding myself that smart database design separates logical elements). So I'm now transferring whatever follows ~ into the new field, then deleting it from Name. Because Name has always been part of my file name expression, ~SOMETHING ended up in the filename, as desired.

My goal was to split off the ~SOMETHING text from Name to RecVer, then use both to determine the file name IF RecVer has a value, but not alter existing filenames unnecessarily. For example...

Before:
Name = Lotus Blossom ~1967
Filename = m:\music\jazz\e\ellington, duke - lotus blossom ~1967.mp3

After:
Name = Lotus Blossom
RecVer = 1967
Filename = m:\music\jazz\e\ellington, duke - lotus blossom ~1967.mp3

Before:
Name = Lotus Blossom ~TAKE1
Filename = m:\musicminor\jazz\e\ellington, duke - lotus blossom ~take1.mp3

After:
Name = Lotus Blossom
RecVer = TAKE1
Filename = m:\musicminor\jazz\e\ellington, duke - lotus blossom ~take1.mp3

With the revised expression it renames correctly whether RecVer has a value or not. Thanks again.
 
 
Logged
Pages: [1]   Go Up