Author Topic: Cannot figure out how to make a virtual tag with nested if-statements  (Read 1905 times)

SonicRings

  • Sr. Member
  • ****
  • Posts: 277
I have currently made a virtual tag which seems to work that does the following:

Code
$IsNull(<Composer>,$If($IsMatch(<AlbumArtist>,<Artist>"|Various|Various Artists"),,"Album Artist: "<AlbumArtist>),"Composer: "<Composer>" 🎤 "$If($IsMatch(<AlbumArtist>,<Artist>"|Various|Various Artists"),," Album Artist: "<AlbumArtist>))

if composer is null
    check if albumartist = artist
        if it is, don't say anything
        if it isn't, show album artist
if composer isn't null
    check if albumartist = artist
        if it is, show the composer
        if it isn't, show the composer and then the album artist

Now, I want to modify it to do the following:

Code
if composer is null
check if albumartist = artist
if it is, don't say anything
if it isn't, show album artist
if composer isn't null
check if it's the same as artist
if it is, check if albumartist = artist
if it is, don't show anything
if it isn't, show the album artist
if it isn't, check if alumartist = artist
if it is, show the composer
if it isn't, show the composer and then the album artist

This is what I've got, but for some reason, despite always saying "OK", it never displays anything:

Code
$IsNull(<Composer>,$If($IsMatch(<AlbumArtist>,<Artist>"|Various|Various Artists"),,"Album Artist: "<AlbumArtist>),$If($IsMatch(<Composer>,<Artist>),$If($IsMatch(<AlbumArtist>,<Artist>"|Various|Various Artists"),," Album Artist: "<AlbumArtist>),"Composer: "<Composer>" 🎤 "$If($IsMatch(<AlbumArtist>,<Artist>"|Various|Various Artists"),," Album Artist: "<AlbumArtist>)))

I've been scratching my head trying everything I can think of for well over an hour now but can't figure out what's wrong. I've considered maybe it's because I'm not supposed to use tags with $IsMatch, so I tried using $Or, but I just cannot figure out how. Can someone please help me with this?

P.S. On further inspection, the first tag I posted also doesn't work; it never displays the Album Artist tag even when it's different from the Artist tag. I'm guessing it's because $IsMatch only takes regex and not tags.
Last Edit: July 23, 2022, 02:28:10 AM by SonicRings

SonicRings

  • Sr. Member
  • ****
  • Posts: 277
I finally figured it out, only took me 2 hours! (╯°□°)╯︵ ┻━┻

Code
$IsNull(<Composer>,$If($Or($Contains(<AlbumArtist>,<Artist>)=T,$Contains(<AlbumArtist>,"Various")=T,$Contains(<AlbumArtist>,"Various Artists")=T),,"Album Artist: "<AlbumArtist>),$If(<Composer>=<Artist>,$If($Or($Contains(<AlbumArtist>,<Artist>)=T,$Contains(<AlbumArtist>,"Various")=T,$Contains(<AlbumArtist>,"Various Artists")=T),,"Album Artist: "<AlbumArtist>),"Composer: "<Composer>" 🎤 "$If($Or($Contains(<AlbumArtist>,<Artist>)=T,$Contains(<AlbumArtist>,"Various")=T,$Contains(<AlbumArtist>,"Various Artists")=T),,"Album Artist: "<AlbumArtist>)))

Welp, if I could improve this in any way, please let me know. I really don't like how I have to copy paste the same thing in 3 different places.

ⁱ ʳᵉᵃˡˡʸ ʷⁱˢʰ ⁱᵗ ʷᵃˢ ᵉᵃˢⁱᵉʳ ᵗᵒ ˡᵒᵒᵏ ᵃᵗ ᵗʰᵉ ˢʸⁿᵗᵃˣ ᵐᵘˢⁱᶜᵇᵉᵉ ᵘˢᵉˢ ᶠᵒʳ ᵛⁱʳᵗᵘᵃˡ ᵗᵃᵍˢ...

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2459
I finally figured it out, only took me 2 hours!
Been there, done that, and banged my head against that wall many times, as I'm sure other forum members have too.

Without trying to pick apart the whole thing, you might be getting caught out by MusicBee substituting Artist for Album Artist in tracks where it isn't explicity set, even in virtual tags.
So for a track:
Artist = ABC
Album Artist = <blank>

Code
$If(<Artist>=<Album Artist>,True,False)
is always True.

I'm guessing it's because $IsMatch only takes regex and not tags.
Yep, no joy there either.

For a track:
Artist = ABC
Album Artist = XYZ

Code
$IsMatch(<Artist>,<Album Artist>)
is always True. I guess it's just the way it's been implemented.


Code
... $Contains(<AlbumArtist>,"Various")=T,$Contains(<AlbumArtist>,"Various Artists")=T)...
Because these are now checking known values, you could replace these with

Code
$IsMatch(<Album Artist>,"Various|Various Artists")
Which will make it shorter at least, if not easier to read.

Using MusicBee's Detect iTunes compilations setting can also make it easier to detect compilations in virtual tags, because if a track has the compilation tag set:

Code
$If(<Album Artist>="Various Artists")
does correctly return True.
(where Various Artists is the value specified in the preferences)


Quote
ⁱ ʳᵉᵃˡˡʸ ʷⁱˢʰ ⁱᵗ ʷᵃˢ ᵉᵃˢⁱᵉʳ ᵗᵒ ˡᵒᵒᵏ ᵃᵗ ᵗʰᵉ ˢʸⁿᵗᵃˣ ᵐᵘˢⁱᶜᵇᵉᵉ ᵘˢᵉˢ ᶠᵒʳ ᵛⁱʳᵗᵘᵃˡ ᵗᵃᵍˢ...
+1
Bee excellent to each other...

SonicRings

  • Sr. Member
  • ****
  • Posts: 277
I finally figured it out, only took me 2 hours!
Been there, done that, and banged my head against that wall many times, as I'm sure other forum members have too.

Without trying to pick apart the whole thing, you might be getting caught out by MusicBee substituting Artist for Album Artist in tracks where it isn't explicity set, even in virtual tags.
So for a track:
Artist = ABC
Album Artist = <blank>

Code
$If(<Artist>=<Album Artist>,True,False)
is always True.



Good catch, though in my case, that's perfectly fine. My use case is for DiscordBee, specifically to display the album artist and composer among the other elements I'm displaying when one hovers over the play icon in my discord rich presence. I wanted to de-clutter that, so I made it so redundant composer and album artist tags would not show (when they're the same as the artist). So in my case, even if there is no album artist, that's still perfectly fine, as it won't show anything.


For a track:
Artist = ABC
Album Artist = XYZ

Code
$IsMatch(<Artist>,<Album Artist>)
is always True. I guess it's just the way it's been implemented.


Code
... $Contains(<AlbumArtist>,"Various")=T,$Contains(<AlbumArtist>,"Various Artists")=T)...
Because these are now checking known values, you could replace these with

Code
$IsMatch(<Album Artist>,"Various|Various Artists")
Which will make it shorter at least, if not easier to read.

Thank you very much, that's a great change to make the code more concise and easier to read! I just made that change and it works.

Code
$IsNull(<Composer>,$If($Or($Contains(<AlbumArtist>,<Artist>)=T,$Contains(<AlbumArtist>,"Various|Various Artists")),,"🎤 Album Artist: "<AlbumArtist>),$If(<Composer>=<Artist>,$If($Or($Contains(<AlbumArtist>,<Artist>)=T,$IsMatch(<AlbumArtist>,"Various|Various Artists")),,"🎤 Album Artist: "<AlbumArtist>),"🎤 Composer: "<Composer>" "$If($Or($Contains(<AlbumArtist>,<Artist>)=T,$IsMatch(<AlbumArtist>,"Various|Various Artists")),,"🎤 Album Artist: "<AlbumArtist>)))


Using MusicBee's Detect iTunes compilations setting can also make it easier to detect compilations in virtual tags, because if a track has the compilation tag set:

Code
$If(<Album Artist>="Various Artists")
does correctly return True.
(where Various Artists is the value specified in the preferences)

This one won't be as useful for me. I don't explicitly add that tag to my tracks, so for my use case that won't be very helpful. But I really appreciate your insight!

I really wish there was some sort of tool or software that makes writing these a lot easier, with a nice GUI. Something like this, which is for AutoHotKey https://www.macrocreator.com/ where you essentially give it the information you want it to do, and it spits out the code that does it.
Last Edit: July 19, 2022, 05:00:32 AM by SonicRings

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2459
I really wish there was some sort of tool or software that makes writing these a lot easier, with a nice GUI. Something like this, which is for AutoHotKey https://www.macrocreator.com/ where you essentially give it the information you want it to do, and it spits out the code that does it.
That's not going to happen, but you're right that trying to work with complicated, nested virtual tags is becoming a bit of a nightmare. It's Steven's fault for making the virtual tags so useful that some people can't help but make MusicBee do things it doesn't want to.  ;)

There are other - much simpler - changes that could be implemented. I'll write up a new Wishlist request in a few hours.
Bee excellent to each other...

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2459
Thank you very much, that's a great change to make the code more concise and easier to read! I just made that change and it works.
Code
... $Contains(<AlbumArtist>,"Various|Various Artists") ...
Looks like you forgot to change the first formula, which means one of your code paths probably won't give you the result you expect.
Bee excellent to each other...

SonicRings

  • Sr. Member
  • ****
  • Posts: 277
Thank you very much, that's a great change to make the code more concise and easier to read! I just made that change and it works.
Code
... $Contains(<AlbumArtist>,"Various|Various Artists") ...
Looks like you forgot to change the first formula, which means one of your code paths probably won't give you the result you expect.

Ah, good catch! Fixed it now, thank you!

Code
$IsNull(<Composer>,$If($Or($Contains(<AlbumArtist>,<Artist>)=T,$IsMatch(<AlbumArtist>,"Various|Various Artists")),,"🎤 Album Artist: "<AlbumArtist>),$If(<Composer>=<Artist>,$If($Or($Contains(<AlbumArtist>,<Artist>)=T,$IsMatch(<AlbumArtist>,"Various|Various Artists")),,"🎤 Album Artist: "<AlbumArtist>),"🎤 Composer: "<Composer>" "$If($Or($Contains(<AlbumArtist>,<Artist>)=T,$IsMatch(<AlbumArtist>,"Various|Various Artists")),,"🎤 Album Artist: "<AlbumArtist>)))

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2459

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1044
  • Heal The World
Code
$IsMatch(<Album Artist>,"Various|Various Artists")
Which will make it shorter at least, if not easier to read.
I believe it can still be shortened some more.
Unless I'm missing something, I don't think there's a need to include 'Various Artists' in the search criteria as 'Various' alone would make a match on that as well.
I realize Sonic Rings is also equaling the $Contains to 'T' in his $If statements - that's not neccessary either, it will work just the same without the =T.

ⁱ ʳᵉᵃˡˡʸ ʷⁱˢʰ ⁱᵗ ʷᵃˢ ᵉᵃˢⁱᵉʳ ᵗᵒ ˡᵒᵒᵏ ᵃᵗ ᵗʰᵉ ˢʸⁿᵗᵃˣ ᵐᵘˢⁱᶜᵇᵉᵉ ᵘˢᵉˢ ᶠᵒʳ ᵛⁱʳᵗᵘᵃˡ ᵗᵃᵍˢ...
I may be misunderstanding this as well, because in the template editor under 'function selector',
a user can already see all of MusicBee's available functions, as well as the syntax used and type of input required for each function.

Lastly, are you aware that your virtual tag currently displays nothing when composer=artist=album artist ?
In your start post, you said you wanted it to show composer instead when all three were the same...
Last Edit: July 20, 2022, 07:41:39 PM by Mayibongwe
Favourite tune at the moment:   Dearly Beloved by Yoko Shimomura from the Kingdom Hearts soundtrack

SonicRings

  • Sr. Member
  • ****
  • Posts: 277
Code
$IsMatch(<Album Artist>,"Various|Various Artists")
Which will make it shorter at least, if not easier to read.
I believe it can still be shortened some more.
Unless I'm missing something, I don't think there's a need to include 'Various Artists' in the search criteria as 'Various' alone would make a match on that as well.
I realize Sonic Rings is also equaling the $Contains to 'T' in his $If statements - that's not neccessary either, it will work just the same without the =T.

Ah, I actually knew I could shorten it to just "Various Artists", but I don't mind making it redundant since it makes looking at it and understanding what it does easier and more obvious. The =T's don't bother me too much either.




ⁱ ʳᵉᵃˡˡʸ ʷⁱˢʰ ⁱᵗ ʷᵃˢ ᵉᵃˢⁱᵉʳ ᵗᵒ ˡᵒᵒᵏ ᵃᵗ ᵗʰᵉ ˢʸⁿᵗᵃˣ ᵐᵘˢⁱᶜᵇᵉᵉ ᵘˢᵉˢ ᶠᵒʳ ᵛⁱʳᵗᵘᵃˡ ᵗᵃᵍˢ...
I may be misunderstanding this as well, because in the template editor under 'function selector',
a user can already see all of MusicBee's available functions, as well as the syntax used and type of input required for each function.

Lastly, are you aware that your virtual tag currently displays nothing when composer=artist=album artist ?
In your start post, you said you wanted it to show composer instead when all three were the same...

You are misunderstanding. The template editor has nothing to do with making the syntax easy to look at. It doesn't keep line breaks, for example, so it's very hard to follow a ton of brackets to make sure you aren't closing one too late or too early. Some colour coding would be appreciated as well.

As well, yes, I'm aware it shows nothing when composer=artist=album artist. This is what I want. As I explained:
Good catch, though in my case, that's perfectly fine. My use case is for DiscordBee, specifically to display the album artist and composer among the other elements I'm displaying when one hovers over the play icon in my discord rich presence. I wanted to de-clutter that, so I made it so redundant composer and album artist tags would not show (when they're the same as the artist). So in my case, even if there is no album artist, that's still perfectly fine, as it won't show anything.

As well, the description of the virtual tags also reflect this.

Code
if composer is null
check if albumartist = artist
if it is, don't say anything

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1044
  • Heal The World
I missed the mark indeed. I thought that syntax comment was in reference to how you were initially uncertain of what kind of parameters $IsMatch took in.

As well, yes, I'm aware it shows nothing when composer=artist=album artist. This is what I want. As I explained:
Could my interpretation of the quote below have been incorrect? (It's what I had based my assumption on)

Now, I want to modify it to do the following:
Code
if composer isn't null
check if it's the same as artist
if it is, check if albumartist = artist
if it is, show the composer
if it isn't, show the composer and then the album artist
Favourite tune at the moment:   Dearly Beloved by Yoko Shimomura from the Kingdom Hearts soundtrack

SonicRings

  • Sr. Member
  • ****
  • Posts: 277
I missed the mark indeed. I thought that syntax comment was in reference to how you were initially uncertain of what kind of parameters $IsMatch took in.

As well, yes, I'm aware it shows nothing when composer=artist=album artist. This is what I want. As I explained:
Could my interpretation of the quote below have been incorrect? (It's what I had based my assumption on)

Now, I want to modify it to do the following:
Code
if composer isn't null
check if it's the same as artist
if it is, check if albumartist = artist
if it is, show the composer
if it isn't, show the composer and then the album artist
Ah good catch, yeah that's wrong. I wrote that explanation hurriedly after having written the code and explained it poorly. I've updated it in the OP.

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1044
  • Heal The World
Alright it's cool. No worries, just wanted to make sure.
Favourite tune at the moment:   Dearly Beloved by Yoko Shimomura from the Kingdom Hearts soundtrack