INTERACT FORUM

Please login or register.

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

Author Topic: Help with expression  (Read 3538 times)

Otello

  • World Citizen
  • ***
  • Posts: 204
Help with expression
« 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.

Logged

wig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 750
Re: Help with expression
« Reply #1 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.



Logged

Otello

  • World Citizen
  • ***
  • Posts: 204
Re: Help with expression
« Reply #2 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. 
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1971
Re: Help with expression
« Reply #3 on: January 24, 2012, 11:05:37 am »

Does this work?
[Composer] - [Album] By [Conductor], [Artist], [Orchestra] If(IsEmpty([Date]),,- [Date])
Logged

Otello

  • World Citizen
  • ***
  • Posts: 204
Re: Help with expression
« Reply #4 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.

Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1971
Re: Help with expression
« Reply #5 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.
Logged

wig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 750
Re: Help with expression
« Reply #6 on: January 24, 2012, 11:34:40 am »

lepa has it right.

Artist, for example, might look like this.

If(IsEmpty([Artist]),, , [Artist])
Logged

Otello

  • World Citizen
  • ***
  • Posts: 204
Re: Help with expression
« Reply #7 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.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help with expression
« Reply #8 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.
Logged
The opinions I express represent my own folly.

Otello

  • World Citizen
  • ***
  • Posts: 204
Re: Help with expression
« Reply #9 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...  ;)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help with expression
« Reply #10 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.
Logged
The opinions I express represent my own folly.

Otello

  • World Citizen
  • ***
  • Posts: 204
Re: Help with expression
« Reply #11 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.



Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help with expression
« Reply #12 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).
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help with expression
« Reply #13 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])
Logged
The opinions I express represent my own folly.

Otello

  • World Citizen
  • ***
  • Posts: 204
Re: Help with expression
« Reply #14 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.

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Help with expression
« Reply #15 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.
Logged
The opinions I express represent my own folly.

Otello

  • World Citizen
  • ***
  • Posts: 204
Re: Help with expression
« Reply #16 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?
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8959
Re: Help with expression
« Reply #17 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. :)

Otello

  • World Citizen
  • ***
  • Posts: 204
Re: Help with expression
« Reply #18 on: February 11, 2012, 10:00:35 am »

Yes!

Thank you.  ;)
Logged
Pages: [1]   Go Up