Author Topic: Split the content of a field to multiple virtual fields  (Read 7838 times)

redwing

  • Guest
Originated from this thread: http://getmusicbee.com/forum/index.php?topic=6719.0

MB's virtual tags offer powerful assistance to managing music library, fulfilling various kinds of needs from users. But it would be nicer if we can do the current "infer and update tags from filename (+ other tags)" function with virtual tags. In other words, that would let users split the content of a field to multiple virtual fields and use them for managing library. For instance, it would instantly address the request of classical music fans to split "work" and "movement" part from title field.

That function would be similar to "guess values" action of MP3tag, but with virtual tags users wouldn't have to constantly update tags manually. Currently additional tagging tools plugin supports a similar function, but it only accepts regular expression which is far from easy for an average user. If this is implemented, MB alone could handle that kind of tagging needs without the assistance of the plugin.

In the thread linked above, I saw a proposed "Split" function for virtual tags. Not sure how it saves the indexed parts of string in other tags, but, for one thing, the function would accept only one delimiter, which is inferior to the current "infer and update tags from filename" function. Probably Steven knows it much better from technical aspect.

Thanks in advance!

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34363
i've done a Split function
$Split(<field>,"search for text",index)

so a field with a value of: "the : smart : fox"
$Split(<field>,":",1) -> the
$Split(<field>,":",2) -> smart
$Split(<field>,":",3) -> fox



redwing

  • Guest
i've done a Split function
$Split(<field>,"search for text",index)

so a field with a value of: "the : smart : fox"
$Split(<field>,":",1) -> the
$Split(<field>,":",2) -> smart
$Split(<field>,":",3) -> fox




Thanks a lot!

Two questions:

1. How to deal with (no) space before and after the delimiter?

2. If a field has a value of "the : smart & fox"

Then,

$Split(<field>,":",1) -> the
$Split(<field>,"&",2) -> fox

But, how can I split "smart"? Do I have to replace "&" with ":" before?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34363
the function trims all leading and trailing spaces in each split.
the scenario i have in mind with this function is for somewho who has formatted a field a particular way where the field could be split into sub-fields using this function.
I cant imagine a realistic scenario where you would use a mixture of delimiters and be able to reliably parse it into a particlar sub-field consistently, but if someone who would use this function can give an example i will reconsider

redwing

  • Guest
the function trims all leading and trailing spaces in each split.
the scenario i have in mind with this function is for somewho who has formatted a field a particular way where the field could be split into sub-fields using this function.
I cant imagine a realistic scenario where you would use a mixture of delimiters and be able to reliably parse it into a particlar sub-field consistently, but if someone who would use this function can give an example i will reconsider

Here is an example from my own collection.
The title has a value of "Violin Sonata No. 09 in A, Op. 47 No. 3 'Kreutzer'-mov2a. Andante"
What I liked to do is to split it to "Violin Sonata No. 09,"  "A, Op. 47 No. 3 'Kreutzer,'" and "mov2a. Andante."
So there are two delimiters, "in" and "-."
How do I achieve this without consuming additional number of virtual tags?

redwing

  • Guest
How about supporting something like this?

$Split(<Title>,("in",2)("-",1))

for "A, Op. 47 No. 3 'Kreutzer,'" part with the example above?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34363
if you are using a virtual field then in normal circumstances eg. if a display field, then its going to apply to every file - you could of course put in extra conditions in the virtual field definition like testing for a particular genre so the split function is applied to only say your classical music.
So given that, will all your classical music files have that field formatted consistently that way with "in" and "-"?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34363
How about supporting something like this?

$Split(<Title>,("in",2)("-",1))

for "A, Op. 47 No. 3 'Kreutzer,'" part with the example above?
the function can only output 1 value - i dont see how this suggestion would work

redwing

  • Guest
will all your classical music files have that field formatted consistently that way with "in" and "-"?

Currently about a half. But that's because their titles were already too long. If this is implemented, I will add additional info to the title field of those tracks. Then it will amount to about 80-90% of my classical music collection. I think an average classical music fan listening to the standard repertoire would have a similar ratio about this if they keep those info in title field though, of course, they might use "," or "." instead of "in."  

redwing

  • Guest
i've done a Split function
$Split(<field>,"search for text",index)

so a field with a value of: "the : smart : fox"
$Split(<field>,":",1) -> the
$Split(<field>,":",2) -> smart
$Split(<field>,":",3) -> fox

Oh, now I got it. It's already implemented in my MB. When was this included?

redwing

  • Guest
Never mind. I can afford to use one more virtual tag. I ended up creating "Work," "Key," "Long Work (work+key)," "Movement," and "Short Title" field.

Short Title = $If(<Genre>="Classical",<Work>,<Title>)

It works perfectly. Thanks!

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2462
I can't believe how many classical music composers name their compositions with little to no consideration for people who have to tag them. Someone should send an email to Messrs Beethoven and Chopin et al. and complain!
Bee excellent to each other...

redwing

  • Guest
I can't believe how many classical music composers name their compositions with little to no consideration for people who have to tag them. Someone should send an email to Messrs Beethoven and Chopin et al. and complain!

They would, in the first place, abhor the idea that we're listening to the recorded music instead of going to concert halls. Actually some classical musicians refuse to record their performance for the same reason.

redwing

  • Guest
What if the delimiter is a comma ","? MB doesn't seem to allow it.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34363