INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 3 4 5 6 [7] 8 9   Go Down

Author Topic: Expression functions [HELP WANTED]  (Read 63236 times)

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #300 on: January 02, 2021, 07:51:19 pm »

Hey Matt, are you up for another one?

ListMatch(): Returns elements of list1 that partial-match list2.

ListMatch is basically a multi-item version of ListFind.

Syntax: ListMatch(list1,list2,mode,delimiter)

    Mode: (optional)
     0: Case-insensitive (default)
     1: Case Sensitive

    Delimiter: Optional, defaults to ;

Example:
ListMatch(Harrison Ford [Rick Deckard];Rutger Hauer [Roy Batty];Sean Young [Rachael];Edward James Olmos [Gaff];M. Emmet Walsh [Bryant],Rick;Sean)
    Returns: Harrison Ford [Rick Deckard];Sean Young [Rachael]

Alternatively, I think ListFind could be expanded to support this functionality, without affecting existing syntax.  The last two arguments are optional, but it would change the behavior if ListFind was given something that looked like a list for list2 as currently it would only find multiple elements if they were complete and contiguous.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #301 on: January 03, 2021, 03:46:41 am »

Seconded, this is useful.
This can be done by simply treating the second argument of ListGrep() as a list - no new function or modes required.
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #302 on: January 03, 2021, 04:24:56 am »

Indeed, I hadn't noticed how close it was to ListGrep as well.

For the sake of simplicity and minimizing future maintenance efforts, I would be in favor of incorporating this functionality and arguments into ListFind, and dropping ListGrep and ListMatch entirely.  Only one function is needed, and I think ListFind is the best name. And while the name ListGrep makes perfect sense to me, to non-Unix people it's Greek.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #303 on: January 03, 2021, 04:41:15 am »

Note that ListFind only returns the first match. It would need additional modes to incorporate ListGrep functionality without breaking existing code (return first vs. return all).
Removing existing functions also breaks existing code.
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #304 on: March 06, 2021, 12:22:51 am »

Matt, are you still interested in doing expression language enhancements?

ListFind() could definitely use some improvements, like eliminating this limitation:
Quote
"Default" specifies what the output should be if Search is not found. This is ignored if using Mode 1 to retrieve the list index #, where all 'not found' items return "-1".


Also, I was thinking it would be very helpful to have a roman numeral converter:

Roman(21) returns XXI
Roman(VII) returns 7

The two are actually related, because I wrote a Roman Numeral converter using ListFind, but it's cumbersome to use with the limitation mentioned above, or for larger numbers.

ListItem could be improved by taking a -1 to retrieve the last item, so that we don't have to resort to ListCount() plus Math().

It would be nice if ListLimit() would accept a delimiter.


Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #305 on: March 09, 2021, 01:09:41 pm »

Coming next build:

NEW: The ListItem(...) expression functions optionally takes a negative number to mean from the end of the list (-1 is last, -2 is second to last, etc.).
NEW: Added a Roman(...) expression function to convert to and from roman numerals.
Changed: The ListLimit(...) expression function takes a delimiter (optional and defaults to semi-colon).
NEW: Added a Repeat(...) expression function to output a string over and over a given number of times.
NEW: Added the expression functions PadLeft(...) and PadRight(...) to pad a string.

Thanks for the suggestions!
Logged
Matt Ashland, JRiver Media Center

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #306 on: March 09, 2021, 01:21:10 pm »

Awesome Matt, thanks a lot!

What about removing that limitation on ListFind, so that we can specify the output for "not found" in mode 1? It's necessary for use as a lookup table.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #307 on: March 09, 2021, 01:38:33 pm »

Awesome Matt, thanks a lot!

What about removing that limitation on ListFind, so that we can specify the output for "not found" in mode 1? It's necessary for use as a lookup table.

Sure!

Next build:
Changed: Made the ListFind(...) expression function support outputting a custom not found string when searching on index (keep blank to output -1).
Logged
Matt Ashland, JRiver Media Center

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #308 on: March 14, 2021, 04:40:13 pm »

Here's one that would be a big time saver and save people a lot of complicated combinations of Find/Left/Right/Mid/Length/Math...

Extract(): Returns a portion of a string bounded by another substring

Extract allows the user to easily extract a portion of a SourceString based on surrounding strings.

Syntax:  Extract(mode,SourceString,string1,string2)

Mode is required and is one of the following:
   1: Everything up to and including string1
   2: Everything up to not including string1
   3: Everything after and including string1
   4: Everything after not including string1
   5: Everything between and including string1 and string2
   6: Everything between not including string1 and string2
   
   Modes 1-6 are case insensitive. Adding 10, for modes 11-16, makes it case sensitive.
   
Examples:

[Name]=Orchestral Suite No. 3 in D major, BWV 1068: 1. Ouverture

Extract(2,[Name], in)
Returns: Orchestral Suite No. 3

[Name]=String Quartet No. 11 in F minor Op. 95 -==Serioso==- I. Allegro con brio

Extract(6,[Name],-==,==-)
Returns: Serioso

[Filename]=\\NAS\Share1\Music\CD\Bach\Flac\Concertos for Orchestra\Concerto for 2 Harpsichords - BWV 1062: I. Vivace
Extract(3,[Filename],[Composer])
Returns: \Flac\Concertos for Orchestra\Concerto for 2 Harpsichords - BWV 1062: I. Vivace

Extract(14,Nocturne OP9 NO2,NO)
Returns: 2


These could of course be done with Regex(), but since many find that too intimidating or difficult, this will make it much more approachable.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #309 on: March 14, 2021, 04:49:45 pm »

Thanks for the suggestion!
Logged
Matt Ashland, JRiver Media Center

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Expression functions [HELP WANTED]
« Reply #310 on: March 14, 2021, 08:42:06 pm »

Preface to say, I love wer's suggestion for Extract(). That would make many of my uses of ListItem() much more clear, and require less regex for a relatively simple operation. The expression language can already effectively do the reverse, but can't do Extract between two different delimiters like this simply. However...

Question on the modes for this: Why do you need versions that include string1 and/or string2 in the output?

By definition, in order to use the Extract() function, you'd have to already have those in order to include them as arguments (or at least you'd have them as the output of an expression). So, if you want to include the opening/closing delimiters, you could just re-add them after the "extraction". So all the odd modes are somewhat superfluous. And you don't need both strings at all if you are searching from the beginning or to the end of the Source String (you only need one, like using ListItem() for the same task).

I'm just thinking it would be simpler to use if it was more like this:
Extract(SourceString,String1,String2,CaseSensitivity)

CaseSensitivity:
0: Case in-sensitive (default)
1: Case sensitive

If String1 or String2 are omitted, then the search happens from the beginning or end of the string relatively (and the substrings are never included).

If you want everything between String1 and String2 (case in-sensitive, probably the most common use-case, and equivalent to your mode 6) then:
Extract(SourceString,String1,String2)

If you want everything from the beginning of SourceString up to String2 (case in-sensitive, mode 2), then you do:
Extract(SourceString,,String2)

If you want everything from String1 to the end of SourceString (case sensitive, mode 14) then:
Extract(SourceString,String1,,1)

And, as I noted above, you have String1 and/or String2 by definition in order to use the function. So, if you want the same thing as above but you want to include String1 (case sensitive, mode 13), then you just do:
String1Extract(SourceString,String1,,1)

Then you don't need all the complicated modes, it allows you to default things not needed, and you can still accomplish all the same things, right?
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #311 on: March 14, 2021, 09:50:28 pm »

Thanks for the thumbs up, Glynor.  I was of course aware of what you're describing. I proposed it the way I did for the reasons of ease and aesthetics. And ease and aesthetics (as in readability) are the reasons for this function to exist at all, since it can be done with regex anyway. I'll make my case/share my thinking with you and we'll see if you buy it.  ;)

The options of omitting one of the boundary strings I don't favor because although shorter, it is harder for people to understand and remember; it's less intuitive.  If you provide string1 and string2, then string2 represents a terminal boundary, but if you only provide string2, then string2 represents an initial boundary.  That can be confusing for people: that the meaning of the argument changes based on the presence or absence of arguments.  Likewise, I think the ,, notation where arguments are omitted is something that often catches people in mistakes: it's a hard error to spot.

The options for including or omitting the string1 & string2 in output is just to make the function shorter and visually simpler.  Because what if string1 and string2 are not short simple strings, but actually long complex functions or chains of functions?  You'd have to type them over again to repeat them in the output.  I think there's enough of that in the expression language already.  It's a major drag when they're long. Not to mention that if you want to edit the expression afterwards, in your syntax you would have to edit it in the output string as well, whereas in mine you just edit it once.  So my way is I think potentially a huge step forward for ease debugging.  I think it would be a shame to not have it.

I could actually make an argument for a different syntax that makes even more sense than yours:
Extract(mode,string1,SourceString,string2)
And incorporating the idea of omitting string1 or string2. But again, it relies on ,, for omitted arguments, so I won't argue in favor of it, other than to say it is more linguistically consistent than yours: is there a leading boundary, or a trailing boundary, or both. Get it?

Then you don't need all the complicated modes, it allows you to default things not needed, and you can still accomplish all the same things, right?

So remember, since everything this function does can be done by other functions anyway, I think any "you can still accomplish the same thing without it" argument is only valid when viewed in the context of ease of use and "straightforwardness". 

What you describe of course could work, but I think the syntax of what I described is more straightforward, and it unquestionably results in shorter, easier-to-read expressions.

Arguably having a separate option for case-sensitivity is more straightforward than my "add 10" idea. But I liked the add 10 idea; it's like the old days of setting a bit in an options flag byte, except we're doing it in base 10 instead of base 2. :)

So I prefer my original syntax to yours, as I think it will be easier for users. But users will be glad if anything is implemented at all.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Expression functions [HELP WANTED]
« Reply #312 on: March 14, 2021, 11:26:43 pm »

Yeah. I just look at it differently. To me, it helps with the overall expression readability to avoid the use of "modes" when possible, and to limit the options in them when needed. I'll always have to look those up and can't "intuit" how they'll function. And, relating to the "empty argument" issue, with your method you wouldn't avoid the omitted arguments, you'll just be pushing it to String2, since there will be many modes where String2's value is ignored I guess? And I feel like that ambiguity is a bit clumsy too (is an empty String2 required even when it is ignored, is it an error if you do include it when you "shouldn't" or is it silently ignored, etc) and it is solved by avoiding the modes.

As far as readability, since the delimiters you're looking for would be right in the overall expression (and would almost always be things like parenthesis, brackets, and dashes) when you want them included, I think it would look reasonably clear when you want them included, as in:
{Extract([Album],{,})}
vs not:
Extract([Album],{,})

To me, that's more obvious and elegant than having to remember one of 12 mode numbers. At a glance, what is the output from this:
Extract(5,[Album],{,})
Versus this (which is kind of an error):
Extract(2,[Album],{,})

But, I can see what you mean from your perspective. I just didn't know if I was missing something and wanted to know why you proposed it that way. I agree that either method would work, but I still like mine better. ;)

Matt will probably pick a third way, but I'm not bothered!
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #313 on: March 15, 2021, 12:33:16 am »

Doesn't the editor show you the modes in the tooltip anyway?

I understand where you're coming from.  But I like things that stay simple, even when the search gets more complicated.

Because:

Extract(5,[Name],ListItem([Name],2,-),ListItem([Name],5,/ ))

is a lot simpler than:

ListItem([Name],2,-)Extract([Name],ListItem([Name],2,-),ListItem([Name],5,/ ))ListItem([Name],5,/ )

My syntax (above) and yours (below) are equivalent. Personally, I'd rather debug mine.  ;D

Anyway like you said, we'll see what Matt does...
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #314 on: March 21, 2021, 11:58:43 am »

Matt, I think you may want to add a sanity limit to Repeat() ... I was testing some expression and ended up with Repeat(test, 100000000) ... 100% CPU for a while :)
Better limit the output buffer size, not just the repeat count.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #315 on: March 23, 2021, 08:03:51 am »

Matt, I think you may want to add a sanity limit to Repeat() ... I was testing some expression and ended up with Repeat(test, 100000000) ... 100% CPU for a while :)
Better limit the output buffer size, not just the repeat count.

Oh boy!  Next build:
Changed: Added a sanity check to the Repeat(...) expression so it will only repeat 100 times then output "... (x more)".
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #316 on: March 23, 2021, 11:33:16 am »

Maybe 1000? Or count=Min(count, 1000/len(value))   (careful with div/0)
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #317 on: March 23, 2021, 01:29:20 pm »

Maybe 1000? Or count=Min(count, 1000/len(value))   (careful with div/0)

Even one letter 100 times makes a huge string.  So I think that's a fine cap.  It outputs that there is more.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #318 on: March 23, 2021, 02:47:08 pm »

The point was more about the total output size.
Repeat(-,100)                  -> 100 chars
Repeat([Filename],100)    -> 10 or 20KB

Yes, I know, just don't do that...  ;D
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #319 on: May 06, 2021, 02:21:07 pm »

Just moved this to the v28 board and would welcome any more ideas.  Thanks :)
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #320 on: May 07, 2021, 05:41:44 am »

Thanks for keeping this up :)

Are you willing to take on this one?

TreeNode(mode) - Basically, a function to return the name of the currently selected tree node, or the current node being built/enumerated for a View. This would provide context to the expression to allow customization of Views such as what that thread describes.

- When used in a GroupBy/Display expression of a View, returns the tree node currently being created
- When used elsewhere, returns the currently selected tree node

mode=0 : name of current node (eg, "Action")
mode=1 : name of parent node (eg, "Movies")
mode=2 : full path of current node (eg, "Video\Movies\Action")
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #321 on: May 07, 2021, 08:19:28 am »

Thanks for the suggestion!  I'll work on it today.

Please keep them coming :)
Logged
Matt Ashland, JRiver Media Center

DrKNo

  • World Citizen
  • ***
  • Posts: 201
Re: Expression functions [HELP WANTED]
« Reply #322 on: May 08, 2021, 12:46:47 am »

I would really appreciate a slice-like  expression for Strings. Mid() takes an index and a number of characters, but find() returns indices. If I need to extract based on indizes I always need to invoke additional math().It would be really neat to have an expression that takes to indices and returns the string between them, very much like the Python String[begin:end]. Could look like Slice(String, begin, end). Thank you!
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #323 on: May 08, 2021, 03:13:46 am »

DrKno, check the new Extract() function a few posts above, it may do what you want since it combines Find and Mid/Left/Right.
https://yabb.jriver.com/interact/index.php/topic,124543.msg894801.html#msg894801
Logged

DrKNo

  • World Citizen
  • ***
  • Posts: 201
Re: Expression functions [HELP WANTED]
« Reply #324 on: May 09, 2021, 01:20:33 am »

Thank you Zybrex! Extract is very useful, thanks for pointing it out. However, it just moves the math problem, as I would still need to convert the index to a string length to use with right(), so it doesn't really affect this use case.

I guess it's not that important in the end since it can be done by subtracting the last index from the length of the string. I'm just lazy :)
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #325 on: May 11, 2021, 07:25:46 am »

I would really appreciate a slice-like  expression for Strings. Mid() takes an index and a number of characters, but find() returns indices. If I need to extract based on indizes I always need to invoke additional math().It would be really neat to have an expression that takes to indices and returns the string between them, very much like the Python String[begin:end]. Could look like Slice(String, begin, end). Thank you!

I'll try to add this:
NEW: The Mid(...) expression function takes a mode so that you can pass the end as an index instead of a count of characters.

Thanks for the suggestion.
Logged
Matt Ashland, JRiver Media Center

EnglishTiger

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 1084
Re: Expression functions [HELP WANTED]
« Reply #326 on: May 12, 2021, 05:40:07 am »

Hope fully I'm asking this in the right thread.

As a Classical Music fan I've started using Neo's Auto Parsing methods - https://yabb.jriver.com/interact/index.php/topic,128884.0.html

Using this expression to extract the Composition from the track Name
Code: [Select]
If(IsEqual([Genre],Classical,1),ListItem([Name],0,:),)
and this one to extract the Movement Name
Code: [Select]
If(IsEqual([Genre],Classical,1),ListItem([Name],1,:),)
Which usually does what I wanted to happen - The part of the track Name before the : is placed in the Composition field/tag and everything after the colon is placed in the Movement Name field/tag if present.

However what I've noticed is that if there is a : inside the Movement Name area that expression is truncating the movement name at the :
For this track - "Piano Sonata No. 2 In A minor; Op. 2/2: 4. Rondo: Grazioso"
the Composition field/tag ends up as " Piano Sonata No. 2 In A minor; Op. 2/2"
BUT the Movement Name ends up as "4. Rondo:" - NOT "4. Rondo: Grazioso"


Have I go the expression wrong; have I come across an undocumented constraint/restriction with regard to ListItem, or have I somehow fallen foul of a mistake/error in the coding of the routines ListItem uses?
Logged
Apple Mac Mini Desktop Computer with M4 Pro chip with 12 core CPU and 16 core GPU: 24GB Unified Memory, 512GB SSD Storage, Gigabit Ethernet, 3 Thunderbolt5 + 2USBC ports.

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #327 on: May 12, 2021, 06:19:52 am »

Wrong thread, this one is for new feature requests - the thread you linked would be better.

ListItem([name], item#, divider) - this splits the [name] on all occurrences of the divider (colon, in your case) and returns the part number 'item#'.
If the name has 1 colon, there will be 2 items; if it has 3 colons, it will have 4 items. So what you're seeing is normal - it's getting the part between the 1st and 2nd colons.

You can change the Movement Name expression to get everything after the first colon using Regex:
Code: [Select]
If(IsEqual([Genre],Classical,1),trim(Regex([temp],/#:(.+)#/,1)),)
Or using the new Extract() function:
Code: [Select]
If(IsEqual([Genre],Classical,1),trim(Extract(4,[Name],:)),)
The extra Trim() gets rid of leading/trailing spaces.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #328 on: May 18, 2021, 09:47:41 am »

This has been a long thread (thanks!) so maybe bump the thread if there's a request you're still hoping to see happen.  We've covered a lot of ground and made great progress because of all your help.  Thank you!
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #329 on: May 18, 2021, 01:28:00 pm »

This one would allow people to build and share function libraries:
https://yabb.jriver.com/interact/index.php/topic,124543.msg877195.html#msg877195
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #330 on: June 02, 2021, 03:45:09 am »

Hi Matt,
Regarding FieldQuery (already implemented), would it be possible to add a couple of modes to make it do AND-matching instead of OR?

The current implementation returns matches in ANY of the given fields (OR). For instance, this returns all files where Sean Penn OR Nicole Kidman is in the Director OR Actors field:
Code: [Select]
fieldquery(Director;Actors, Sean Penn;Nicole Kidman, Name, 1, 0)
The 2 extra modes would make it match the argument lists, returning files where Director=Sean Penn AND Actors=Nicole Kidman (this one)

Modes:
0=contains any/OR
1=exact match any/OR
2=contains each/AND *new*
3=exact match each/AND *new*

Modes 2/3 require that both list arguments are of the same size - if they're not, then just ignore the extra items on the larger list (user error).

Source problem: https://yabb.jriver.com/interact/index.php/topic,129618.msg899282.html#msg899282
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #331 on: June 03, 2021, 01:18:15 pm »

Strings that look like a field and have a comma inside are being truncated by MC when used in an Expression. For instance, if the [Actors] field contains "Hugh Jackman [Logan, Wolverine]", it gets truncated to "Hugh Jackman [Logan]" when used in an Expression.

I understand why it does that, but it should return the whole string when it doesn't recognize the field name. Can you please fix it?
Thanks!

Ref: https://yabb.jriver.com/interact/index.php/topic,119385.msg899365.html#msg899365
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #332 on: June 03, 2021, 02:11:41 pm »

Strings that look like a field and have a comma inside are being truncated by MC when used in an Expression. For instance, if the [Actors] field contains "Hugh Jackman [Logan, Wolverine]", it gets truncated to "Hugh Jackman [Logan]" when used in an Expression.

I understand why it does that, but it should return the whole string when it doesn't recognize the field name. Can you please fix it?
Thanks!

Ref: https://yabb.jriver.com/interact/index.php/topic,119385.msg899365.html#msg899365

You're right.  It's thinking it's a parameter after the field.  Maybe if it's not a number we can let it pass?
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #333 on: June 03, 2021, 02:16:22 pm »

I think it should keep the whole thing if it doesn't recognize a valid field, regardless of it being a number or not. If it's a mistake it's up to the user to correct it.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #334 on: July 13, 2021, 08:07:39 am »

Just bringing this to the top in case anyone has more ideas.  Thanks for all the help so far :)
Logged
Matt Ashland, JRiver Media Center

EnglishTiger

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 1084
Re: Expression functions [HELP WANTED]
« Reply #335 on: July 27, 2021, 07:40:47 am »

A Trim Option that replaces multiple empty lines with a single empty line, mainly for use when editing Lyrics.
Logged
Apple Mac Mini Desktop Computer with M4 Pro chip with 12 core CPU and 16 core GPU: 24GB Unified Memory, 512GB SSD Storage, Gigabit Ethernet, 3 Thunderbolt5 + 2USBC ports.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #336 on: July 27, 2021, 08:00:04 am »

A Trim Option that replaces multiple empty lines with a single empty line, mainly for use when editing Lyrics.

Look at TrimLines(...):
https://wiki.jriver.com/index.php/String_Manipulation_Functions#TrimLines.28.E2.80.A6.29
Logged
Matt Ashland, JRiver Media Center

EnglishTiger

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 1084
Re: Expression functions [HELP WANTED]
« Reply #337 on: July 27, 2021, 09:31:02 am »

Look at TrimLines(...):
https://wiki.jriver.com/index.php/String_Manipulation_Functions#TrimLines.28.E2.80.A6.29

I did and when I tried TrimLines([Lyrics],1) on these lyrics:-

Time is a wicked master
Put your life into its hand
Close your eyes and it will crush you
Fate only spins you faster
It's a curse born unto man
Turns your dreams into disaster

[Chorus]
Save me because the world's going to stop
And baby, 3, 2, 1, are you ready to rock?
Come on and wake me, the final curtain will drop
And baby, 3, 2, 1
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock tonight?


Lies, it's the truth I'm after
Let me find it in your eyes
Quick before the moment dies
Cries in a sea of laughter
Weeping gently in my soul
Love's the only thing that matters

[Chorus]
Save me because the world's going to stop
And baby, 3, 2, 1, are you ready to rock?
Come on and wake me, the final curtain will drop
And baby, 3, 2, 1
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock tonight?


(10, 9, 8, 7, 6, 5, 4) 3, 2, 1!

[Chorus]
Come on and save me 'cause the world's gonna stop
And baby, 3, 2, 1, are you ready to rock?
Come on and wake me, the final curtain will drop
And baby, 3, 2, 1, are you ready to rock?

[Chorus]
Come on and shake me 'cause we're in for a shock
And baby, 3, 2, 1, we're fallin' down from the top
Come on and take me, we're goin straight to the top
And baby, 3, 2, 1
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock tonight?

I ended up with this:-

Time is a wicked master
Put your life into its hand
Close your eyes and it will crush you
Fate only spins you faster
It's a curse born unto man
Turns your dreams into disaster
[Chorus]
Save me because the world's going to stop
And baby, 3, 2, 1, are you ready to rock?
Come on and wake me, the final curtain will drop
And baby, 3, 2, 1
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock tonight?
Lies, it's the truth I'm after
Let me find it in your eyes
Quick before the moment dies
Cries in a sea of laughter
Weeping gently in my soul
Love's the only thing that matters
[Chorus]
Save me because the world's going to stop
And baby, 3, 2, 1, are you ready to rock?
Come on and wake me, the final curtain will drop
And baby, 3, 2, 1
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock tonight?
(10, 9, 8, 7, 6, 5, 4) 3, 2, 1!
[Chorus]
Come on and save me 'cause the world's gonna stop
And baby, 3, 2, 1, are you ready to rock?
Come on and wake me, the final curtain will drop
And baby, 3, 2, 1, are you ready to rock?
[Chorus]
Come on and shake me 'cause we're in for a shock
And baby, 3, 2, 1, we're fallin' down from the top
Come on and take me, we're goin straight to the top
And baby, 3, 2, 1
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock?
Are you ready to rock tonight?

The only "empty line" it didn't remove was the one at the top of the lyrics tag/field but despite being told to only "Trim double new lines" it also removed the single empty lines, that I didn't want removed, as well. Also if you go back and read my OP again I was asking for an option that replaced multiple empty lines with a singe empty line.
Logged
Apple Mac Mini Desktop Computer with M4 Pro chip with 12 core CPU and 16 core GPU: 24GB Unified Memory, 512GB SSD Storage, Gigabit Ethernet, 3 Thunderbolt5 + 2USBC ports.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #338 on: July 27, 2021, 10:11:56 am »

I think what you're looking for is a new mode to convert triple newlines into double.

So next build of MC28:
NEW: Added the number 4 to the TrimLines expression function to replace triple new lines with double.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #339 on: July 27, 2021, 10:33:12 am »

Maybe make it replace 3+ newlines with 2? So it would work with larger gaps too.
Ie, "replace 3 or more newlines with 2 newlines"
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #340 on: July 27, 2021, 10:36:52 am »

Maybe make it replace 3+ newlines with 2? So it would work with larger gaps too.
Ie, "replace 3 or more newlines with 2 newlines"

That's how it will work.  As long as it finds three it will keep replacing.
Logged
Matt Ashland, JRiver Media Center

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression functions [HELP WANTED]
« Reply #341 on: July 27, 2021, 10:59:45 am »

I don't think its currently possible to have an expression manipulate data in another field.

I think I would like it if its possible to have an expression that is able to set a value in a field based on a condition.

Code: [Select]
SetField(condition,field,newvalue,mode)

Mode:
0: trigger SetField to set a new value when the condition does not match
1: trigger SetField to set a new value when the condition matches

I could do something like this:
Code: [Select]
SetField(Find([Album],[MyCustomField],0,0),[Album],[MyCustomAlbum] [[MyCustomField]],0)
Mode is set to 0 so the function works when condition fails.

Album: Best Album Ever! [A67890]
MyCustomField: C12345
MyCustomAlbum: Best Album Ever!
MyCustomAlbum is a calculated data field which strips suffices between () and [] from the album field:
Code: [Select]
Regex([Album], /#^(.+?)((\s*\[[^\]]*\])|(\s*\([^)]*\)))*$#/, 1)

So, SetField in the example above would search the [Album] field for the value in [MyCustomField] and if it doesn't find it, sets [Album] to [MyCustomAlbum] plus [[MyCustomField]].

New Album value: Best Album Ever! [C12345]
MyCustomAlbum: Best Album Ever!

In practise, I would use it update the album field when I change custom fields for Catalog Number and Discogs ID. This would ensure the Album field is always unique, but MyCustomAlbum will always remain the base album title without a suffix.

I suppose this could lead to endless loops and other evil stuff if you're not careful though :P. Some checking should be done to prevent that.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #342 on: July 27, 2021, 11:10:19 am »

Where would you type this SetField() expression?
You can do the same by typing an expression like the following in the Album tag:
Code: [Select]
=if(Find([Album],[MyCustomField],0,0),[Album],[MyCustomAlbum] [[MyCustomField]])
I too would like a way to set field values, but the way MC expression language works, it's not simple. There's already a save() function that stores a value on a named variable, so it could just be extended to allow existing field names... but I can see the problems in doing that.
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression functions [HELP WANTED]
« Reply #343 on: July 27, 2021, 11:15:29 am »

Where would you type this SetField() expression?
You can do the same by typing an expression like the following in the Album tag:
Code: [Select]
=if(Find([Album],[MyCustomField],0,0),[Album],[MyCustomAlbum] [[MyCustomField]])
I too would like a way to set field values, but the way MC expression language works, it's not simple. There's already a save() function that stores a value on a named variable, so it could just be extended to allow existing field names... but I can see the problems in doing that.

Thats what Im doing now, or something similar at least but its a manual action for each change I make in one of the custom fields, is manually update the album field with an expression. Its tedious.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #344 on: July 27, 2021, 11:19:08 am »

So I ask again, where would you type the SetField() expression? How would it change the workflow?
Note that you can select all files and type that expression on the Album tag to update all of them simultaneously.
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression functions [HELP WANTED]
« Reply #345 on: July 27, 2021, 11:22:20 am »

Ah yeh, that. Or create one for it and move it out of view.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #346 on: July 27, 2021, 11:23:14 am »

An out-of-view calculated field is never executed, AFAIK.
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression functions [HELP WANTED]
« Reply #347 on: July 27, 2021, 11:28:53 am »

Then don't but make it really small ;D

I don't know, I admit its not ideal.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2616
Re: Expression functions [HELP WANTED]
« Reply #348 on: July 27, 2021, 11:46:06 am »

I can tell you the feature I'd like to see and that would also fill your requirement... I've been thinking about this for a while. It could be an MC29 major feature :)

Action Triggers:
- User-defined expressions that get executed when MC does some action on a file
- The expressions could be defined in a XML file, or a specific UI could be added to MC to manage them
- Triggers: BeforePlay, AfterPlay, AfterImport, AfterFieldUpdate, OnViewChange, AfterStartup, BeforeExit, ... (more triggers could be added over time)
- multiple expressions could be defined for same trigger
- A SetField() function would be available on these triggers; this would allow changing fields when the trigger event occurred
- An Exec() function would also be nice to start some external process on these triggers (including MCC commands)
- "AfterFieldUpdate" would take an arg to specify which field would trigger it; user could define triggers for different fields
- Some special vars could provide the [PreviousValue], [NewValue] and [FieldName] on the AfterFieldUpdate trigger
- Using a SetField() on an AfterFieldUpdate event could trigger another expression on a different field... so MC would need to prevent update loops.

Any comment Matt?  :)
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression functions [HELP WANTED]
« Reply #349 on: July 27, 2021, 12:21:15 pm »

It could be an MC29 MC28 feature in the next update  ;D

Corrected that for you  8) ::) ;D

On a more serious note, I thought about suggesting macro's that could run with a hotkey or on a schedule or something. Your action triggers are much better though!

Its a really cool idea!
Logged
Pages: 1 ... 3 4 5 6 [7] 8 9   Go Up