INTERACT FORUM

More => Old Versions => Media Center 17 => Topic started by: Otello on January 24, 2012, 09:49:35 am

Title: Help with expression
Post by: Otello on January 24, 2012, 09:49:35 am
Can somebody help me writing an expression?

I made a "static" expression for the titles of classical music view:

[Composer] - [Album] By [Conductor], [Artist], [Orchestra] - [Date]

It works with a piano concerto, where all the fields are filled, but for instance with a Piano Sonata without Date I get something like:

Beethoven - Piano Sonata No.29 Op.106 By  , Pollini, -

(please note the unwanted commas and "-" at the end.)

I'd like to have listed, comma separated, the not empty [Conductor], [Artist] and [Orchestra] fields and avoid the endind "-" in case the Date is empty.

I imagine it's quite trivial, but I'm always been thick in scripting.  ;)

Thanks.

Title: Re: Help with expression
Post by: wig on January 24, 2012, 10:54:13 am
You could use If expressions.

http://wiki.jriver.com/index.php/Media_Center_expression_language#If.28....29:_Conditional_If.2FThen.2FElse_evaluator.

Shouldn't be an issue if you have some scripting experience.



Title: Re: Help with expression
Post by: Otello on January 24, 2012, 10:59:53 am
Shouldn't be an issue if you have some scripting experience.


Ehm...  ;D

Quote from: Otello
I'm always been thick in scripting. 
Title: Re: Help with expression
Post by: lepa on January 24, 2012, 11:05:37 am
Does this work?
[Composer] - [Album] By [Conductor], [Artist], [Orchestra] If(IsEmpty([Date]),,- [Date])
Title: Re: Help with expression
Post by: Otello on January 24, 2012, 11:26:37 am
It works 50%.

i.e.: it cured the "-" but not the unwanted commas.

Thanks for the help, anyway.

Title: Re: Help with expression
Post by: lepa on January 24, 2012, 11:31:59 am
Ok, then you need to make similar checking for every field (or maybe use that IfElse structure). I need to go now so I can't make the expression for you right now but I can help later if someone else hasn't by the time I available again.
Title: Re: Help with expression
Post by: wig on January 24, 2012, 11:34:40 am
lepa has it right.

Artist, for example, might look like this.

If(IsEmpty([Artist]),, , [Artist])
Title: Re: Help with expression
Post by: Otello on January 24, 2012, 11:41:49 am
Ok, then you need to make similar checking for every field (or maybe use that IfElse structure). I need to go now so I can't make the expression for you right now but I can help later if someone else hasn't by the time I available again.

OK, thanks. ;)

I tried to extend the "If(IsEmpty" to the other fields, but I suspect I need something different; as depending of which fields are empy I still get an unwanted comma somewhere.
Title: Re: Help with expression
Post by: MrC on January 24, 2012, 11:59:45 am
Try this:

listbuild(1, /,/ , [Composer] - [Album] By [Conductor], [Artist], [Orchestra])IfElse(!IsEmpty([Date]), / - [Date])

It doesn't handle and empty Conductor.  If you need to handle empty Composer, Album, and Conductor, this can be accomplished using a sequence of If(!isempty()) statements.
Title: Re: Help with expression
Post by: Otello on January 24, 2012, 12:09:18 pm
Try this:

listbuild(1, /,, [Composer] - [Album] By [Conductor], [Artist], [Orchestra])IfElse(!IsEmpty([Date]), / - [Date])

This works only if I have a Conductor; if the conductor field is empy I get a comma before the artist:

Beethoven - Piano Sonata No.29 Op.106 by ,Pollini


Puff, I couldn't imagine it was so complicated...  ;)
Title: Re: Help with expression
Post by: MrC on January 24, 2012, 12:13:37 pm
Can you live with <unknown> for an empty value?

The reason it is complicated is that before outputting any given value's separator, you have to consider the value and the next value down the line.
Title: Re: Help with expression
Post by: Otello on January 24, 2012, 12:24:37 pm
Can you live with <unknown> for an empty value?

Well, maybe it's better I do not use commas and put only a <space> between fields; take in mind only a minority of records have all the 3 fields filled: I'd say Concertos and Operas; in a Symphony you miss the Artist, in a Piano Sonata you miss Conductor and Orchestra, etc.



Title: Re: Help with expression
Post by: MrC on January 24, 2012, 12:27:33 pm
Let's use listbuild 3 times to add the different separators.  This should do it.

listbuild(1, /,/ ,
   listbuild(1, / -/ , [Composer],
      listbuild(1, / By/ , [Album], [Conductor])), [Artist], [Orchestra])IfElse(!IsEmpty([Date]), / - [Date])

Copy/Paste using the Expression Editor (via the pulldown triangle when you enter the value for the expression).
Title: Re: Help with expression
Post by: MrC on January 24, 2012, 12:46:45 pm
Finally, with listbuild, we can now get rid of the if() test:

listbuild(1, / -/ , [Composer],
   listbuild(1, / By/ , [Album], listbuild(1, /,/  , [Conductor], [Artist], [Orchestra])), [Date])
Title: Re: Help with expression
Post by: Otello on January 24, 2012, 01:06:31 pm
Finally, with listbuild, we can now get rid of the if() test:

listbuild(1, / -/ , [Composer],
   listbuild(1, / By/ , [Album], listbuild(1, /,/  , [Conductor], [Artist], [Orchestra])), [Date])


Yes, this one worked.

Thank you very much, I really appreciated.

Title: Re: Help with expression
Post by: MrC on January 24, 2012, 01:10:22 pm
You're welcome.  Once I stood back to re-examine the problem, the solution became clear.

Glad it works for you.
Cheers.
Title: Re: Help with expression
Post by: Otello on February 11, 2012, 07:47:52 am
I recicle my old thread for another expression help. ;)

I wrote an expression for the title of not-classical music view, to have the albums sorted by date (if present) and not alphabetically:

[Artist] If(IsEmpty([Date]),, ([Date])) - [Album]

this way I get, for instance:

King Crimson (1973) - Larks' Tongues in Aspic

BUT, if the date field is empty I get this:

King Crimson ) - Larks' Tongues in Aspic

I don't understand why I get this closed parenthesis...

Thanks


P.S. Maybe I'm making complicated a simple thing, i.e.: there's a better way to get the same result?
Title: Re: Help with expression
Post by: marko on February 11, 2012, 09:36:13 am
You need to escape the parenthesis that are not part of the expression:

[Artist] If(IsEmpty([Date]),, /([Date]/)) - [Album]

Try that, it should work now. :)
Title: Re: Help with expression
Post by: Otello on February 11, 2012, 10:00:35 am
Yes!

Thank you.  ;)