INTERACT FORUM

Please login or register.

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

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

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #50 on: March 29, 2020, 11:46:32 am »

Can't believe I missed this one:

ListJoin(list, joiner, separator)
list - list to join
joiner - string with witch to join the list elements
separator - list separator, optional

Example:
ListJoin(SomeList,\ - \ )  - returns a list with elements joined by " - "

This effectively replaces the list separator with something else. A replace() runs the risk of replacing commas/semicolons inside the list elements themselves.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #51 on: March 29, 2020, 11:47:25 am »

Quick one: Is there already an easy way to add a \n (newline) ? I dislike how the literal newline on the expressions disrupt the readability.

EDIT: perhaps different whitespace handling modes could be introduced with a whitespace(expression, mode) function. Mode would be literal/explicit/legacy/etc.
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #52 on: March 29, 2020, 12:31:32 pm »

ListCombine() already exists.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #53 on: March 29, 2020, 01:03:29 pm »

ListCombine() already exists.
Thanks, I didn't know you could specify the output delimiter on that one. It does the trick.
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #54 on: March 29, 2020, 09:46:48 pm »

I tried out the expressions in the new version and they work great, Matt.  Thanks!!

 ;D ;D ;D
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72413
  • Where did I put my teeth?
Re: Expression functions [HELP WANTED]
« Reply #55 on: March 29, 2020, 10:02:05 pm »

Thanks, everyone, for all the ideas and feedback.  Well done, Matt.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #56 on: April 05, 2020, 10:34:57 am »

It is really tedious to do any Math() in country where comma is a decimal point as MC only understand period. If I could just use something like Number([field]) instead of Replace([field],/,,.) it would be really helpful.
Could this be added to Number()?
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #57 on: April 05, 2020, 05:10:45 pm »

It looks like the Math expression function wasn't working with non-US decimals very well.  I'll try to shore it up in a coming build.  Thanks.
Logged
Matt Ashland, JRiver Media Center

timwtheov

  • Galactic Citizen
  • ****
  • Posts: 354
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #59 on: April 10, 2020, 05:19:03 am »

Are these new functions documented somewhere? I at least couldn't find any.

One request would be reverse find, which would start from end and return first found index
Logged

SkGe

  • Galactic Citizen
  • ****
  • Posts: 433
Re: Expression functions [HELP WANTED]
« Reply #60 on: April 12, 2020, 11:35:10 pm »

Hello there. I want to know if it is possible to alter a bit the way length() works because now, it only can read characters and nothing more. Is a way to expand this to include also words in the expression?! Right now I'm using a site that can count words in a text, but it will be better to have this include in JRiver.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #61 on: April 13, 2020, 02:08:39 am »

Hello there. I want to know if it is possible to alter a bit the way length() works because now, it only can read characters and nothing more. Is a way to expand this to include also words in the expression?! Right now I'm using a site that can count words in a text, but it will be better to have this include in JRiver.
Don't know how efficient it is but you could use ListCount(Field],/ ) to count words
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #62 on: April 13, 2020, 02:27:13 am »

Good thinking lepa.
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #63 on: April 13, 2020, 05:49:04 am »

Matt, I have an idea...  But it's a bit harder than the others we've talked about here.

GroupSummary is a great function, but there's a way it could become incredibly more useful.

I propose a related function, let's call it GroupSummaryQuery.

Now currently GroupSummary summarizes a given field for the members of the current context.  If you're looking at an album, GroupSummary(Duration) summarizes the Duration for all the members of that album.

GroupSummaryQuery is related, but slightly abstracted.

GroupSummaryQuery(field1, field2) summarizes a given field2 not for members of the current context, but for files that share a field1 with the current context.


So for example, if you're looking at an individual track in the AC/DC album Back in Black, then:

GroupSummary(Duration) gives you the duration of just that track, because you're not looking at the album level.

GroupSummaryQuery(Album, Duration) would give you the total duration for all tracks in the Back in Black album.

GroupSummaryQuery(Artist, Duration) would give you the total duration of all AC/DC tracks.

The functionality can be extended if the first field can be combined like a string:
GroupSummaryQuery(Artist-Year, Rating) would give you the summarized rating of all the AC/DC tracks released the same year as the current track.

Performing GroupSummaryQuery(Artist, Duration) would report the exact same result if you were looking at ANY AC/DC track, because they all share the same Artist.

This would provide some neat facilities that are currently available only with global variables.  In a sense, it generates on-the-fly relational fields.  By eliminating some of the need for global variables, it would make many constructs much more approachable for people.

The exact same thing could also be done with GroupCount, creating GroupCountQuery.

What do you think?  It seems to me this could probably be easily built off the existing GroupSummary code.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #64 on: April 13, 2020, 08:36:30 am »

Coming next build:
NEW: Added the expression function GroupSummaryQuery to build a summary for files matching the given fields.

Thanks for the suggestion!  Testing appreciated because it was a little complicated.
Logged
Matt Ashland, JRiver Media Center

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #65 on: April 13, 2020, 08:37:50 am »

Coming next build:
NEW: Added the expression function GroupSummaryQuery to build a summary for files matching the given fields.

Thanks for the suggestion!  Testing appreciated because it was a little complicated.
Thanks
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #66 on: April 13, 2020, 12:28:48 pm »

Cool!  Glad to test.  Thanks!
Logged

mvandyke

  • World Citizen
  • ***
  • Posts: 159
Re: Expression functions [HELP WANTED]
« Reply #67 on: April 14, 2020, 09:17:45 am »

Thanks for the information.

Next build will have this:
NEW: Added the expression function TrimLines(...) to standardize and consolidate newlines.

It takes a mode like this:
Mode (or together): 1 trims double newlines, 2: trims starting and ending newlines (optional: defaults to 3)

If there's anything more you're looking for from TrimLines(...), just let me know.  Thanks again.

I have a Field AMG Artist Biography that has many extra lines between paragraphs, sometimes 4 or 5 lines (sometimes the lines contain spaces).  I would like to create an expression to trim the "blank lines" out and leave one or two blank lines between paragraphs.

Could you provide the syntax for this (it's currently not documented in the Expression Language area as it's new?

Thanks
Matt
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #68 on: April 14, 2020, 03:15:00 pm »

Coming next build:
NEW: Added the expression function GroupSummaryQuery to build a summary for files matching the given fields.

Thanks for the suggestion!  Testing appreciated because it was a little complicated.
First tests going on. Could similar mode parameter as it is now in GroupSummary be added to this also to be able to automatically filter out postfix text please?
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #69 on: April 14, 2020, 03:35:04 pm »

Yep, I'd thought of that but thought he might have it in there by default...

Is GroupCountQuery in there too?  That's the other side of the coin.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #70 on: April 15, 2020, 02:55:31 am »

Coming next build:
NEW: Added the expression function GroupSummaryQuery to build a summary for files matching the given fields.

Thanks for the suggestion!  Testing appreciated because it was a little complicated.
Using variables seems to be much more lightweight. GroupSummaryQuery really struggles on scrolling when used like this on biggish views

Code: [Select]
[ArtistAlbum] = [Album Artist (auto)][Album]
Code: [Select]
[=Save(0, v_AlbumDuration[ArtistAlbum])1]=1 [=Save(Math([Duration,0] + Load(v_AlbumDuration[ArtistAlbum])), v_AlbumDuration[ArtistAlbum])1]=1
Create expression column using
Code: [Select]
GroupSummaryQuery(ArtistAlbum, Duration)vs.
Code: [Select]
FormatDuration(Load(v_AlbumDuration[ArtistAlbum]))
Logged

arcspin

  • Galactic Citizen
  • ****
  • Posts: 391
Re: Expression functions [HELP WANTED]
« Reply #71 on: April 15, 2020, 11:07:49 pm »

Coming next build:

Hi Matt
I would like to bring to your attention zybex suggestions and try to find a way for them to be added into future builds.

zybex is doing an incredible job with his MCRatings software that are an tremendous help for me and others in making our Theater view the best it can be and zybex suggestions seems to be of importance in making McRatings even better.



Thank you and stay safe,

//arcspin
Logged
Hardware: Intel Core i5-8600K 16GB RAM, ASUS GeForce RTX 2080 8GB DUAL OC
Software: Windows 10 Home 64-bit, version 2004, JRiver MC 29, MadVr 0.92.17 (Beta 113), NVIDIA driver 457.09
Projector: JVC DLA-I X5500 (RS420, X570R) -
Screen: DNP Supernova 08-85
Processor: Anthem AVM 70
Power amp: XTZ A2-400 for Front & Center - XTZ A2-300 for Surround & Height channels
Speakers: Arendal 1723 S Monitor for Front & Center, Linn Unik for Front Height, Rear Height, Surround & Surround back. Elipson Planet M for Top Middle.
Sub: Arendal 1723 1S

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #72 on: April 16, 2020, 07:49:25 am »

I would like to bring to your attention zybex suggestions and try to find a way for them to be added into future builds.

I've implemented several of his ideas.

If you have a specific one I overlooked, please post it again.

Thanks.
Logged
Matt Ashland, JRiver Media Center

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #73 on: April 16, 2020, 07:55:25 am »

First tests going on. Could similar mode parameter as it is now in GroupSummary be added to this also to be able to automatically filter out postfix text please?

Next build:
Changed: The GroupSummaryQuery function accepts a parameter just like GroupSummary to turn off labeling.

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

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #74 on: April 16, 2020, 08:50:53 am »

I've implemented several of his ideas.
If you have a specific one I overlooked, please post it again.

Thanks Matt, appreciated.
I think he's referring to the transform() function I proposed above which would simplify many long expressions we're currently using.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #75 on: April 16, 2020, 08:55:46 am »

Thanks Matt, appreciated.
I think he's referring to the transform() function I proposed above which would simplify many long expressions we're currently using.

Thanks.

Could you provide a few more examples of how Transform(...) would work?

I'm still trying to figure out if it would be possible in a straight forward way.

Thanks again.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #76 on: April 16, 2020, 10:45:04 am »

Sure, thanks for taking a look!

Syntax: Transform(template, separator, List)

The goal is to transform each element of a list using a given pattern, returning a new list with the same size where each element is transformed.
For instance, this expression can be used to process the [Actors] field to get a series of <img> tags pointing to the Actor profile PNGs (to show Actor pics in theater/thumbnail view):
Code: [Select]
<img src="E:\JRiver\Actors\Left(listitem([Actors],0), 1)\listitem([Actors],0).png" width="130"> <img src="E:\JRiver\Actors\Left(listitem([Actors],1), 1)\listitem([Actors],1).png" width="130"> <img src="E:\JRiver\Actors\Left(listitem([Actors],2), 1)\listitem([Actors],2).png" width="130"> <img src="E:\JRiver\Actors\Left(listitem([Actors],3), 1)\listitem([Actors],3).png" width="130"> <img src="E:\JRiver\Actors\Left(listitem([Actors],4), 1)\listitem([Actors],4).png" width="130"> <img src="E:\JRiver\Actors\Left(listitem([Actors],5), 1)\listitem([Actors],5).png" width="130"> <img src="E:\JRiver\Actors\Left(listitem([Actors],6), 1)\listitem([Actors],6).png" width="130">That's 670 chars just to do that, and it assumes the list always has at least 6 elements.

The same output (better, since it handles any list size) would be accomplished with:
Code: [Select]
ListCombine(Transform(<img src="E:\JRiver\Actors\Left([L],1)\[L].png" width="130">,,[Actors]),,, )(Note: I'm using ListJoin() which does not exist, because I just realized that ListCombine() is meant to join 2 lists into 1 - I think there's nothing like ListJoin yet - to join list elements into a single string - and it would also be useful)

The idea is that each element of [Actors] gets inserted into the template in turn, replacing the placeholder [L]. If a list has 5 elements, this transform is done 5 times, returning a new list where each element is the "template" with the [L] replaced with the original element.

Sample implementation
Here's a naive implementation example in metacode (corner cases not handled):
Code: [Select]
Transform(template, separator, SourceList) {
    var transformed=new List<string>();
    foreach (string item in SourceList.Split(separator))
        string newItem = template.Replace("[L]", item)
        transformed.Add(newItem)
    return transformed.Join(separator);
}

Transforming multiple lists
I placed the List argument in last place because the function can be expanded to take any number of lists:

Transform(template, separator, List1, List2, List3...)

In this case, the template could include placeholders referencing each of the lists - I proposed [L1], [L2], [L3], etc. [L] could be a shorthand for [L1] when there's only one list. We could also have [N] for the current loop index (item position in list).

For instance, assume your have 3 lists:
Code: [Select]
[Tracks] = "Track1; Track2; Track3"
[Durations] = "3:45; 2:50; 4:27"
[Bitrates] = "224; 224; 160"

Code: [Select]
Transform("Song #[N]: [L1] ([L2] @ [L3] Kbps)",, [Tracks], [Durations], [Bitrates])
This would output a list of 3 elements:
Code: [Select]
Song #1: Track1 (3:45 @ 224 Kbps); Song #2: Track2 (2:50 @ 224 Kbps); Song #3: Track3 (4:27 @ 224 Kbps)
Sample implementation for multiple lists:
(needs bounds checks to handle cases where the number of elements on each list is different - just use "" if there's no element for a given index)
Code: [Select]
Transform(template, separator, list<list<string>> Lists) {
    var transformed=new List<string>();
    int max = HighestElementCount(Lists);
    for (int n = 0; n < max; n++) {
       string newItem = template.Replace("[N]", n);
       newItem = newItem.Replace("[L]", Lists[n][0]);
       for (int x = 0; x < Lists.Count(); x++)
           newItem = newItem.Replace("[L{x+1}]", Lists[n][x]);
       transformed.Add(newItem)
    }
    return transformed.Join(separator);
}

I used placeholders like [N], [L], [L1] etc because there are already similar placeholders in regex functions [R1], [R2], etc. Other placeholder format can be used, of course.

OK, I hope this is not too complex for implementation :)
Let me know if some point is not clear.

Zybex

EDIT: fixed 2nd algorithm
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #77 on: April 16, 2020, 10:53:23 am »

ListCombine() already exists.

I just realized that ListCombine() is meant to join 2 lists into a new list, removing duplicate elements.
The ListJoin() I was proposing is meant to join the elements of a List and output a string (basically, replace the list separator with something else).

Code: [Select]
ListJoin(List, joiner, separator)
example:
Code: [Select]
ListJoin(1;2;3;4,/ -/ ,)output:  1 - 2 - 3 - 4
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #78 on: April 16, 2020, 12:28:46 pm »

List combine can do what you're proposing Zybex.  I'm not understanding the difference.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #79 on: April 16, 2020, 12:34:29 pm »

I'm playing with your transform idea.

I have this expression:
Transform(Song #[N]: [L1] /([L2] @ [L3] Kbps/), Track1; Track2; Track3, 3:45; 2:50; 4:27, 124; 224; 160)

And it outputs this:
Song #1: Track1 (3:45 @ 124 Kbps); Song #2: Track2 (2:50 @ 224 Kbps); Song #3: Track3 (4:27 @ 160 Kbps)

Do I have it working right?  Any other angles I need to consider?

Thanks.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #80 on: April 16, 2020, 12:44:52 pm »

Matt, that looks exactly right  ;D

If the template includes functions, does it work as well?
For instance (stupid example):

Transform(Song #[N]: [L1] /([L2] @ Math([L3]/8) KBps/), Track1; Track2; Track3, 3:45; 2:50; 4:27, 128; 224; 160)

should yield:
Song #1: Track1 (3:45 @ 16 KBps); Song #2: Track2 (2:50 @ 28 KBps); Song #3: Track3 (4:27 @ 20 KBps)
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #81 on: April 16, 2020, 12:48:31 pm »

List combine can do what you're proposing Zybex.  I'm not understanding the difference.

Wer,
True, ListCombine(1;2;3;4,,,/ -/ ) also achieves the same.
As MrC pointed out to me, even a simple Replace() can do what I mentioned since a list is, in practice, just a string.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #82 on: April 16, 2020, 01:13:28 pm »

Matt, that looks exactly right  ;D

If the template includes functions, does it work as well?
For instance (stupid example):

Transform(Song #[N]: [L1] /([L2] @ Math([L3]/8) KBps/), Track1; Track2; Track3, 3:45; 2:50; 4:27, 128; 224; 160)

should yield:
Song #1: Track1 (3:45 @ 16 KBps); Song #2: Track2 (2:50 @ 28 KBps); Song #3: Track3 (4:27 @ 20 KBps)

You just love to make it hard on me!

But I'm trying.  If you put the string in a string literal escape, the Math(...) won't get translated as a function.

Then I can parse it in the transform function.

So it takes something like this:
Transform(/*Song #[N]: [L1] /([L2] @ Math([L3]+1) KBps)/*, Track1; Track2; Track3, 3:45; 2:50; 4:27, 128; 224; 160)

Not sure if there could be any way to make that automatic?

Cheers.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #83 on: April 16, 2020, 01:25:42 pm »

Can't you delay the function eval for the template argument?

I suppose that when you are evaluating/executing some function, you first evaluate/execute each of the args:
Function(arg1, arg2, arg3)
=> Function(Evaluate(arg1), Evaluate(arg2), Evaluate(arg3))

What we need in this case is:
Evaluate(Transform(template, Evaluate(arg2), Evaluate(arg3), ...))

That is, the "template" is a special arg that is not evaluated before Transform(), but instead there's an extra call to Evaluate the final output.
Does this make sense to you? Is it possible?

2 other minor things:
- the second arg to Transform() should perhaps be the ListSeparator char, for consistency with other list funcs)
- if later on we think of new functionality, we would need a "mode" arg ... but since the Transform() takes a variable number of List args, then this "mode" would need to come before the Lists. Do you think it should be added now as a placeholder?

Thanks,
zybex
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #84 on: April 16, 2020, 01:27:52 pm »

- the second arg to Transform() should perhaps be the ListSeparator char, for consistency with other list funcs)
- if later on we think of new functionality, we would need a "mode" arg ... but since the Transform() takes a variable number of List args, then this "mode" would need to come before the Lists. Do you think it should be added now as a placeholder?

I was thinking about going without specifying a delimiter.  I just think you should use semi-colon, or your life will be terrible with our expression engine!

If you can think of something to put in mode, I can add it.

Thanks.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #85 on: April 16, 2020, 01:40:03 pm »

I was thinking about going without specifying a delimiter.  I just think you should use semi-colon, or your life will be terrible with our expression engine!
That's fine.

Quote
If you can think of something to put in mode, I can add it.
Mode 0 - what we talked about
Mode 1 - ?? ??
Mode 2 - Profit!  ;D

OK, can't thing of anything right now.

One other detail: it's fine to reference the same [L{n}] multiple times in the template. they should all get processed/replaced.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #86 on: April 16, 2020, 02:03:09 pm »

NEW: Added the expression function Find(...) to search for a substring in a string.
If I have understood correctly Find() behaves like find first.
Could there be a mode to return the last occurrence of the searched char/string Find([Text], searchedString, 2)

Scenario could be e.g. making own line feeds
Code: [Select]
[Text] = "I have many words and I want to cut this text after 20 characters max but want to keep the words as a whole"
So desired result would like this (cut before 20 character as it was in the middle of the word):
Code: [Select]
I have many words
and I want to cut this text after 20 characters max but want to keep the words as a whole

If(Compare(Length([Text]),>,20),Mid([Text], 0, Find(Mid([Text],0,20),/ , 2)), [Text])
2 flag indicates that mode is find last. So above expression would examine if input string is more than 20 char long and if it is, it would find last space before 20th character and output text only to that point.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #87 on: April 16, 2020, 06:17:48 pm »

Can't you delay the function eval for the template argument?

I just figured out how to escape the string as part of the pre-process.  I think that will work.  I was trying to dig into the parsing but not having much luck.  Hopeful for release tomorrow.
Logged
Matt Ashland, JRiver Media Center

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #88 on: April 17, 2020, 07:51:42 am »

Next build:
NEW: Added a Transform(...) expression function (see this thread for details: https://yabb.jriver.com/interact/index.php/topic,124543.0.html)
NEW: Added a mode to the Find(...) expression function "2" to reverse find instead of forward find in the string.

Thanks so much for the suggestions.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #89 on: April 17, 2020, 08:01:49 am »

Yaaaay!



Thanks Matt!
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #90 on: April 17, 2020, 08:07:16 am »

And just for the record, I did add a do-nothing flags field to Transform(...) thinking I better future proof!
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #91 on: April 17, 2020, 08:12:46 am »

Nice. I bet if you didn't we would find a need for it shortly after release... Murphy's law.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #92 on: April 17, 2020, 08:23:23 am »

What about:
mode 0 - default as implemented
mode 1 - return as many elements as the shortest list
mode 2 - return as many elements as the first list

The code I proposed returns as many list elements as the longest list (using "" for the missing elements of other lists)
Mode 1 would stop when it reaches the end of one of the list arguments, preventing results with blanks.
Mode 2 would stop when it reaches the end of the first list

The code change would be:
Code: [Select]
int max = (mode == 2) ? Lists[0].Length : (mode == 1) ? ShortestElementCount(lists) : HighestElementCount(Lists);
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #93 on: April 17, 2020, 08:39:21 am »

What about:
mode 0 - default as implemented
mode 1 - return as many elements as the shortest list
mode 2 - return as many elements as the first list

The code I proposed returns as many list elements as the longest list (using "" for the missing elements of other lists)
Mode 1 would stop when it reaches the end of one of the list arguments, preventing results with blanks.
Mode 2 would stop when it reaches the end of the first list

The code change would be:
Code: [Select]
int max = (mode == 2) ? Lists[0].Length : (mode == 1) ? ShortestElementCount(lists) : HighestElementCount(Lists);

You got it!

From the code:
Flags: flags (0: return # of longest list; 1: returns # of shortest list; 2: return # of first list)
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2591
Re: Expression functions [HELP WANTED]
« Reply #94 on: April 17, 2020, 08:47:35 am »

Great :)
Please consider if it makes sense to switch mode 0 and 2. Should the default be # first list? Your call.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #95 on: April 22, 2020, 08:17:21 am »

Just a thank you to zybex for all his help testing the new feature.  Next build will have a ListMix(...) expression.  It's built around the Transform(...) modeled above.

Thanks again everyone.
Logged
Matt Ashland, JRiver Media Center

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #96 on: April 26, 2020, 09:16:16 pm »

Matt, here's a good one that would simplify things a lot with what we're doing with the custom tooltips/views.

Proposal:
IfCase, which functions as a switch or select case statement.


IfCase performs an IsEqual operation against one primary operand and several secondary operands, with an action for each secondary operand.  IfCase honors the same modes as IsEqual.  IfCase acts on the first match, and if no match occurs returns null.

IfCase(primary, mode, secondary1, action1, secondary2, action2, secondary3, action3..... etc)

Example:

IfCase([bitrate], 2, 64, Low, 128, Standard, 256, Medium, 320, High)
    Converts a numerical bitrate to a descriptive word.
   
IfCase(Length([Name]), 5, 50, Wow this is super long, 30, This is a very long track name, 20, This is not so long)
    Takes various actions based on the length of a field.

IfCase([Oscar Awarded to], 8, Matt, Matt wins on his first acting job, meryl, The Oscar went to Meryl again, carrey, Unbelievable result)
    Multiple actions based on the contents of one string

Something like this would save a lot of typing of nested Compare() or IsEqual() statements when matching things against a possible list of values, and makes for much more readable expressions.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #97 on: April 27, 2020, 06:59:55 am »

+1 for wer's case. I've actually writing it sometimes like that and then realized that I'm missing conditionals for everyone else but the first one. Definitely would use this one.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #98 on: April 27, 2020, 08:17:07 am »

Wer, coming next build:
NEW: Added the IfCase(...) expression function ( details here: https://yabb.jriver.com/interact/index.php/topic,124543.msg866100.html#msg866100 ).

Note that you'll need to reverse the order of your logic so it tests the longest string first, then shorter.  Because we just work down the list and find the first match.  So even really, really long strings are longer than long strings.

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

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42344
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #99 on: April 27, 2020, 08:18:58 am »

Just to expand, your above expression would need to be changed to be like this:
IfCase(Length([Name]), 5, 50, Wow this is super long, 30, This is a very long track name, 20, This is a long track name)
Logged
Matt Ashland, JRiver Media Center
Pages: 1 [2] 3 4 5 6 ... 9   Go Up