INTERACT FORUM

Please login or register.

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

Author Topic: Expression for cases  (Read 534 times)

Vadomar

  • Recent member
  • *
  • Posts: 17
Expression for cases
« on: February 19, 2024, 03:22:24 am »

Hello dear community,

unfortunately I am a coding beginner and need your help. I can't get it to work myself. I am trying to display the artists of a classical music album in a calculated field. I have:

[soloist] = Anne-Sophie Mutter
[conductor] = Herbert von Karajan
[orchestra] = Berlin Philharmonic Orchestra

I am now looking for a formula that shows me the above information in a separate field [artistcalculated]. It should have the following format:

[artistcalculated] = [soloist], [conductor]: [orchestra]

I can get it to work with this special example, but what if there is no soloist? What if there are soloist and orchestra but no conductor (which can happen especially in old chamber music)? How can I make sure the punctuation is right?
Do I have to use the ifelse-function for this or is there another way?

Thank you very much in advance!
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2345
Re: Expression for cases
« Reply #1 on: February 19, 2024, 04:46:00 am »

There's likely a simpler solution, but here's an ugly one that just checks for all 8 combinations:

Code: [Select]
ifelse(isempty([soloist][conductor][orchestra]),,
isempty([soloist][_conductor]),[orchestra],
isempty([soloist][_orchestra]),[conductor],
isempty([conductor][orchestra]),[soloist],
isempty([soloist]),[conductor]: [orchestra],
isempty([conductor]),[soloist]: [orchestra],
isempty([orchestra]),[soloist]/, [conductor],
1, [soloist]/, [conductor]: [orchestra])
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1962
Re: Expression for cases
« Reply #2 on: February 19, 2024, 04:48:26 am »

zybex beats me to it but here is couple of solutions anyway

It depends what you want end result to be

Assuming here that there is always orchestra

e.g. if you want always have same kind of structure where you know which parts exist and which not:
Code: [Select]
FirstNotEmpty([soloist],NA), FirstNotEmpty([conductor],NA): [orchestra]So it would return e.g.
NA, NA: Berlin Philharmonic Orchestra
Anne-Sophie Mutter, NA: Berlin Philharmonic Orchestra
NA, Herbert von Karajan: Berlin Philharmonic Orchestra
Anne-Sophie Mutter, Herbert von Karajan: Berlin Philharmonic Orchestra

Or you could just return if there is a value (untested expression, might not work but to get you an idea at least):
Code: [Select]
If(!IsEmpty([soloist]),[soloist]If(!IsEmpty([conductor]),/,/ [conductor],): [orchestra],If(!IsEmpty([conductor]),[conductor]: [orchestra],[orchestra]))e.g.
Berlin Philharmonic Orchestra
Anne-Sophie Mutter: Berlin Philharmonic Orchestra
Herbert von Karajan: Berlin Philharmonic Orchestra
Anne-Sophie Mutter, Herbert von Karajan: Berlin Philharmonic Orchestra

Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2345
Re: Expression for cases
« Reply #3 on: February 19, 2024, 05:16:30 am »

Here's a nicer one:
Code: [Select]
listbuild(1,/:/ ,listbuild(1,/,/ ,[soloist], [conductor]), [orchestra])
Lepa's first one with the NA makes sense.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1962
Re: Expression for cases
« Reply #4 on: February 19, 2024, 05:33:04 am »

Here's a nicer one:
Code: [Select]
listbuild(1,/:/ ,listbuild(1,/,/ ,[soloist], [conductor]), [orchestra])
indeed  8)
Logged

Vadomar

  • Recent member
  • *
  • Posts: 17
Re: Expression for cases
« Reply #5 on: February 19, 2024, 05:45:58 am »

Thank you both for your answers and good solutions, all work! I am trying to understand now this one:

Code: [Select]
listbuild(1,/:/ ,listbuild(1,/,/ ,[soloist], [conductor]), [orchestra])
I do have after soloist always a comma. With this, if there is no conductor, it will show a ":". Can this be implemented in this formula or is it better to go with the first long one zybex mentioned?

Thanks again in advance!
Logged

EnglishTiger

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 952
Re: Expression for cases
« Reply #6 on: February 19, 2024, 05:51:41 am »

@zybex and lepa :-
As a rule for creating [artistcalculated] lepa's NA solution is OK if it is only used for tracks that normally have a combination of Soloist, Orchestra and Conductor - but "NA, Herbert von Karajan: Berlin Philharmonic Orchestra" is going to look very wrong for most of the movements from Ludwig Van Beethoven's Symphonies.
Logged
Win NUC - VENOEN 11Th NUC Mini PC Core i7 1165G7,Dual HDMI 2.0+Mini DP,Windows 11 Mini Desktop Computer,Thunderbolt 4.0,1 Lan, USB-C,Wifi,Bluetooth 5.0,32GB RAM Toshiba MQ04ABF100 ‎500Gb 5400 RPM ‎eSATA HD, Gigabyte GP-GSM2NE3512GNTD 1Tb NVMe SSD, Samsung 870 QVO 8 TB SATA 2.5 Inch SSD (MZ-77Q8T0) in Sabrent Ultra Slim USB 3.0 to 2.5-Inch SATA External Aluminium Hard Drive Enclosure (EC-UK30)

Apple 2020 Mac mini M1 Chip (8GB RAM, 512GB SSD)
Sabrent Thunderbolt 3 to Dual NVMe M.2 SSD Tool-Free Enclosure with Sabrent 2TB Rocket NVMe PCIe M.2 2280 High Performance SSD + Crucial P3 Plus 4TB M.2 PCIe

ET Skins & TrackInfo Plugins - https://englishtiger.uk/index.html

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2345
Re: Expression for cases
« Reply #7 on: February 19, 2024, 05:54:42 am »

Thank you both for your answers and good solutions, all work! I am trying to understand now this one:

Code: [Select]
listbuild(1,/:/ ,listbuild(1,/,/ ,[soloist], [conductor]), [orchestra])
I do have after soloist always a comma. With this, if there is no conductor, it will show a ":". Can this be implemented in this formula or is it better to go with the first long one zybex mentioned?

Thanks again in advance!

Why not try it? It does exactly what you requested :)
The comma in "[soloist], [conductor]" is a function separator, not a literal comma. This "/," is a literal comma in an expression.

ListBuild(1,/,/ ,[soloist], [conductor]) - builds a list (joins) of those 2 items using ", " as a separator ("/,/ "). Mode 1 means that empty items will not be in the list, so if there's only one value there's no separator. If both values are missing then the function returns an empty string.
The second ListBuild (first in the expression) then does the same between this result and the [orchestra], but using ": " as the separator.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1962
Re: Expression for cases
« Reply #8 on: February 19, 2024, 05:55:50 am »

If you want to have those placeholder (NA = Not Available/Applicable etc) then use my first one with FirstNotEmpty
If you wan to show only what exist then use zybex's last one. ": " is not shown if there is only orchestra available as there is then only on item so delimiter ": " is not needed and thus not inserted
Logged

Vadomar

  • Recent member
  • *
  • Posts: 17
Re: Expression for cases
« Reply #9 on: February 19, 2024, 07:55:16 am »

Thanks, this is great help! I now brought it down to this for two different interpunctuations (after soloist there is always a "•", never a ":"):

Code: [Select]
IfElse(
    [conductor],
        listbuild(1,/:/ ,
            listbuild(1,/ •/ ,[soloist],[conductor]),
        [orchestra]),
    isempty([conductor]),
        listbuild(1,/ •/ /
            ,listbuild(1,/ •/ ,[soloist],[conductor]),
        [orchestra]/
        )
)

Now help me understand also as an example for some other fields I have, how do I add more conditions? Because I have also a custom field [choir]. So now what if the following fields are given but no soloist:

[conductor] = Herbert von Karajan
[orchestra] = Berlin Philharmonic
[choir] = Thomanerchor Leipzig

The [choir] should be added after the [orchestra] separated by a comma, like this:

Herbert von Karajan: Berlin Philharmonic, Thomanerchoir Leipzig

Or different case, let’s say, there is a cappella with only a soloist and a choir but no conductor or orchestra:

[soloist] = Kurt Moll
[choir] = Leipziger Gewandhauschor

How do I get this to work properly to look like – is it still right with using ifelse or is there an easier solution? It should then look like:

Kurt Moll • Leipziger Gewandhauschor

You don’t need to decline it through for me, it only would be helpful to give me an idea of the correct syntax.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1962
Re: Expression for cases
« Reply #10 on: February 19, 2024, 09:23:46 am »

I think you should first think ALL the rules you want to apply and after that start to think how to achieve that because solution probably will be different depending on what the rules are
Current dilemma probably something like this could do it:
Code: [Select]
listbuild(1,if(isempty([conductor][orchestra]),/ •/ ,/:/ ),listbuild(1,/,/ ,[soloist], [conductor]), listbuild(1,/,/ ,[orchestra],[choir]))
one new nested listbuild to handle right side: orchestra & choir
and then if statement to choose correct delimiter depending on conductor & orchestra: colon or ball
Logged

EnglishTiger

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 952
Re: Expression for cases
« Reply #11 on: February 20, 2024, 11:11:49 am »

I think you should first think ALL the rules you want to apply and after that start to think how to achieve that because solution probably will be different depending on what the rules are

The OP shouldn't just "think ALL the Rules he wants to apply" he needs to switch from Reactive mode into Proactive mode by sitting down with pencil, paper and everything he knows, or has available, about his Classical Music Collection because before too long he may well find the ideas/rules outlined above will constantly need rewriting as they only cover a few of the possible combinations of:
Conductor, Orchestra; Soloist and Chorus/Choir; although I have used the term "choir" it doesn't take too much lateral thinking to realise the existing MC "Chorus" Tag can be used to hold the name of a "Choir".  Plus he needs to deveop a rule that ensures that any manipulation of existing tags is restricted to only happening with tracks that are recognizable as "Classical Music".

While trawling thru the almost 15,400 classical music tracks in my own collection I encountered multiple instances of:-
Orchestra/Ensemble only
Conductor + Orchestra
Conductor + Orchestra + 1 or more Instrumental Soloist
Conductor + Orchestra + 1 or more Vocal Soloist
Conductor + Orchestra + 1 or more Choir/Chorus
Conductor + Orchestra + 1 or more Instrumental Soloist + 1 or more Vocal Soloist
Conductor + Orchestra + 1 or more Instrumental Soloist + 1 or more Choir/Chorus
Conductor + Orchestra + 1 or more Vocal Soloist + 1 or more Choir/Chorus
Conductor + Orchestra + 1 or more Instrumental Soloist + 1 or more Vocal Soloist + 1 or more Choir/Chorus
1 or more Instrumental Soloist
1 or more Instrumental Soloist + 1 or more Vocal Soloist
1 or more Instrumental Soloist + 1 or more Choir/Chorus
1 or more Instrumental Soloist + 1 or more Vocal Soloist + 1 or more Choir/Chorus.
Logged
Win NUC - VENOEN 11Th NUC Mini PC Core i7 1165G7,Dual HDMI 2.0+Mini DP,Windows 11 Mini Desktop Computer,Thunderbolt 4.0,1 Lan, USB-C,Wifi,Bluetooth 5.0,32GB RAM Toshiba MQ04ABF100 ‎500Gb 5400 RPM ‎eSATA HD, Gigabyte GP-GSM2NE3512GNTD 1Tb NVMe SSD, Samsung 870 QVO 8 TB SATA 2.5 Inch SSD (MZ-77Q8T0) in Sabrent Ultra Slim USB 3.0 to 2.5-Inch SATA External Aluminium Hard Drive Enclosure (EC-UK30)

Apple 2020 Mac mini M1 Chip (8GB RAM, 512GB SSD)
Sabrent Thunderbolt 3 to Dual NVMe M.2 SSD Tool-Free Enclosure with Sabrent 2TB Rocket NVMe PCIe M.2 2280 High Performance SSD + Crucial P3 Plus 4TB M.2 PCIe

ET Skins & TrackInfo Plugins - https://englishtiger.uk/index.html

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2345
Re: Expression for cases
« Reply #12 on: February 20, 2024, 11:39:34 am »

What about just color coding?  ;D

Code: [Select]
listbuild(1,/ •/ ,
  if([soloist],<font color=#FF0000>[Soloist]<//font>,),
  if([conductor],<font color=#00FF00>[conductor]<//font>,),
  if([orchestra],<font color="#0000FF">[orchestra]<//font>,),
  if([choir],<font color=#FF00FF>[choir]<//font>,),
  if([cleaning lady],<font color="#FF8040">[cleaning lady]<//font>,)
)

Anne-Sophie Mutter • Herbert von Karajan • Berlin Philharmonic • Thomanerchor Leipzig • Consuela De La Morrela
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1962
Re: Expression for cases
« Reply #13 on: February 20, 2024, 11:43:08 am »

I would just give up classical  ;D ::) :P
Logged

EnglishTiger

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 952
Re: Expression for cases
« Reply #14 on: February 20, 2024, 12:41:33 pm »

What about just color coding?  ;D

I would just give up classical  ;D ::) :P

I just stuck to making better use of the existing tags/fields and then with the help of Wer creating MC's 1st TrackInfo Plugin that was designed to handle Classical music in a better way.  ;D

Logged
Win NUC - VENOEN 11Th NUC Mini PC Core i7 1165G7,Dual HDMI 2.0+Mini DP,Windows 11 Mini Desktop Computer,Thunderbolt 4.0,1 Lan, USB-C,Wifi,Bluetooth 5.0,32GB RAM Toshiba MQ04ABF100 ‎500Gb 5400 RPM ‎eSATA HD, Gigabyte GP-GSM2NE3512GNTD 1Tb NVMe SSD, Samsung 870 QVO 8 TB SATA 2.5 Inch SSD (MZ-77Q8T0) in Sabrent Ultra Slim USB 3.0 to 2.5-Inch SATA External Aluminium Hard Drive Enclosure (EC-UK30)

Apple 2020 Mac mini M1 Chip (8GB RAM, 512GB SSD)
Sabrent Thunderbolt 3 to Dual NVMe M.2 SSD Tool-Free Enclosure with Sabrent 2TB Rocket NVMe PCIe M.2 2280 High Performance SSD + Crucial P3 Plus 4TB M.2 PCIe

ET Skins & TrackInfo Plugins - https://englishtiger.uk/index.html

EnglishTiger

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 952
Re: Expression for cases
« Reply #15 on: March 28, 2024, 04:47:04 am »

While tagging my classical music collection I worked out that by making better/fuller use of the existing MC Fields/Tags and modifying the MC Ultra TrackInfo Plugins i could come up with  way of handling most of the "Exceptions" Vadomar has already encountered  along with most, probably all, of the ones I predicted he could encounter and the linked Pix01 Gallery reveals what I've achieved.

Images 1 & 2 show what the new "MCUltra "Track + Album Info Panel" can display, I had 2 use 2 images as the "Potential Track Info Panel" was too long to fit on one screen, the rest of the images reveals that the new "Track + Album Info Panel" only displays the fields, and their content, that are actually being used for a selection of exceptions/oddities I encountered in my classical music collection.

Oh and the only  field that is populated using an expression is the "Artist" one.

Link to Pixo1 Gallery   https://pix01.jriver.com/lM1%40rohp 

Logged
Win NUC - VENOEN 11Th NUC Mini PC Core i7 1165G7,Dual HDMI 2.0+Mini DP,Windows 11 Mini Desktop Computer,Thunderbolt 4.0,1 Lan, USB-C,Wifi,Bluetooth 5.0,32GB RAM Toshiba MQ04ABF100 ‎500Gb 5400 RPM ‎eSATA HD, Gigabyte GP-GSM2NE3512GNTD 1Tb NVMe SSD, Samsung 870 QVO 8 TB SATA 2.5 Inch SSD (MZ-77Q8T0) in Sabrent Ultra Slim USB 3.0 to 2.5-Inch SATA External Aluminium Hard Drive Enclosure (EC-UK30)

Apple 2020 Mac mini M1 Chip (8GB RAM, 512GB SSD)
Sabrent Thunderbolt 3 to Dual NVMe M.2 SSD Tool-Free Enclosure with Sabrent 2TB Rocket NVMe PCIe M.2 2280 High Performance SSD + Crucial P3 Plus 4TB M.2 PCIe

ET Skins & TrackInfo Plugins - https://englishtiger.uk/index.html
Pages: [1]   Go Up