INTERACT FORUM

Please login or register.

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

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

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Expression functions [HELP WANTED]
« Reply #250 on: June 15, 2020, 06:30:16 pm »

No. TV is its own [Media Type], for entries in the TV Program Listings.

Well, not exactly. In the "Television Guide" database program listings have a [Media Type] of "TV", and [Media Sub Type] of "TV Show" or "Movie". I guess if a View or Search in which this function was used included the "Television Guide" database then a [Media Type] of "TV" makes sense.

However in the "Main" and "Playing Now" databases a [Media Type] of "TV" is just TV channel information, and not program information. A [Media Type] of TV isn't valid for the other databases. As searching TV channel information with this new function didn't make much sense, I thought Wer meant the "TV Show" [Media Sub Type] and just wrote that shorthand.

But I guess searching TV program listings using a function like this makes sense, so if the View wasn't restricted in which databases it showed, then yes, including a [Media Type] of "TV" makes sense.

I should note, though, that I’m not sure why such a function would need a scope like that at all. That seems like a redundant, and oddball, addition to the Expression Language in a single function.

Why wouldn’t you just limit the scope on the input side with the much more capable Search Language?

This is I agree with. I didn't like the way Scope was proposed in the function, so I thought it needed more thought.

The function might need some more examples of just how it would be applied as well. I could see a View showing people also listing the Movies and TV Shows they have appeared in, via a delimited list, but I'm not entirely convinced. What issue is the function addressing Wer?
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #251 on: June 15, 2020, 06:53:56 pm »

I don't want to argue about the scope at this point.  It is obviously redundant with what could be done by including a tag like Media Type in the search, I knew that. The reason I suggested it in the form I did was in the hopes it would speed up the search: depending on the scope parameter, the search would be run against a much smaller subset of files, instead of against all files all the time, which would be necessary if you're explicitly scanning a tag value. I guessed that MC might have internal shortcuts to limit scope to certain types of files in this way.  If Matt says it does not, then clearly the scope variable would be pointless.

The goal of the function is to be able to retrieve and display data about related files, in places where such things are not currently possible, like in theater view.

GroupSummaryQuery and GroupCountQuery summarize and count data for related files, respectively.  This function would enumerate data, instead of counting or summarizing.
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #252 on: June 19, 2020, 02:07:24 am »

Matt, what do you think of FieldQuery?  Are you game to give it a try?

Ok Matt, since you've been making short work of these simple ones we've been giving you, how about a complicated one?  ;D

FieldQuery: Return a list of matches based on a list of fields to search, from a selected scope of files.

Syntax:
FieldQuery(fieldlist,valuelist,return,mode,scope)

Fieldlist: list of fields to search, e.g. Director;Studio

Valuelist: a value to search for each field in fieldlist (could be an expression)

Return: The single field that is returned when a match is found, values from files returned as a ; delimited list

Mode: 0=contains
     1=exact match

Scope: Audio=1/Video=2/TV=4/Image=8  OR'd together  (searches globally)


Examples:

FieldQuery(Director,Ridley Scott,Name,1,2) returns
Alien;Blade Runner;Gladiator

FieldQuery(Actors,Al Pacino,Name,0,2) returns
The Godfather;Heat;Scarface

FieldQuery(Actors;Director,Al Pacino;Michael Mann,Name,0,2) returns
Heat

If you think we should, we could add a final option, context 0=global, 1=current file scope in view)
Logged

Hendrik

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 10939
Re: Expression functions [HELP WANTED]
« Reply #253 on: June 19, 2020, 03:22:23 am »

If Matt says it does not, then clearly the scope variable would be pointless.

I'm not Matt, but there are no magic shortcuts. We internally just use search expressions as well.
Logged
~ nevcairiel
~ Author of LAV Filters

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #254 on: June 19, 2020, 12:02:59 pm »

Ok then...  So this would make more sense:

FieldQuery: Return a list of matches based on a list of fields to search, from a selected scope of files.

Syntax:
FieldQuery(fieldlist,valuelist,return,mode,scope)

Fieldlist: list of fields to search, e.g. Director;Studio

Valuelist: a value to search for each field in fieldlist (could be an expression)

Return: The single field that is returned when a match is found, values from files returned as a ; delimited list

Mode: 0=contains
     1=exact match

Scope: 0=global (searches all files), 1=current view scope (just search the files in the current view, for speed)


Examples:

FieldQuery(Director,Ridley Scott,Name,1,0) returns
Alien;Blade Runner;Gladiator

FieldQuery(Actors,Al Pacino,Name,0,0) returns
The Godfather;Heat;Scarface

FieldQuery(Actors;Director,Al Pacino;Michael Mann,Name,0,0) returns
Heat
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9140
Re: Expression functions [HELP WANTED]
« Reply #255 on: June 20, 2020, 02:14:13 am »

ListRemove() does not perform on a substring level, is that by design?

listremove(my;test;expression string,/ string) removes nothing
listremove(my;test;expression string,expression string) removes that last item

Maybe there should be a substring mode 2, so...
listremove(my;test;expression string;this string;that string,/ string) would return:
my;test;expression;this;that

-marko

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Expression functions [HELP WANTED]
« Reply #256 on: June 20, 2020, 06:15:16 pm »

I tried to do what you are trying with all of the other List Manipulation functions Marko, and couldn't find a way.

The ListFind(...) function includes sub-string matching, such that;
ListFind(my;test;expression string;this string;that string,string)

returns the first match, "expression string".

ListGrep(...) also includes sub-string matching, such that;
ListGrep(my;test;expression string;this string;that string,string)

returns "expression string;this string;that string".

If ListGrep supported a NOT operator, then it could perform the function. i.e.;
ListGrep(my;test;expression string;this string;that string,-"string")
or
ListGrep(my;test;expression string;this string;that string,!string)
or similar, but it doesn't support NOT matching.


So I would think ListRemove(...) should also include sub-string matching.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9140
Re: Expression functions [HELP WANTED]
« Reply #257 on: June 21, 2020, 02:19:18 am »

I have run into a brick wall over And() and Or()

I cannot get them to do anything meaningful. The tooltips say "Tests a list of values and outputs 1 if all/some of them are true"

Tests a list of values for what?
As examples,
And(1,1,1)
Or(1,0,1)
are really not very helpful.

And(2,7,10) returns "1"
And(2,7,Yes) returns "0"
And([Artist],[Album Artist]) returns zero (Here, I was expecting maybe a "1" if both were populated, or perhaps "1" if they were the same, but regardless of variations, it always returns zero.

What am I not understanding?

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Expression functions [HELP WANTED]
« Reply #258 on: June 21, 2020, 02:41:35 am »

This works:

Code: [Select]
AND(IsEqual([Artist], Leonard Cohen, 8), IsEqual([Album], Leonard Cohen, 8))
See image.

Also this:

Code: [Select]
AND(IsEqual([Artist], Leonard Cohen, 0), IsEqual([Album Artist (auto)], Leonard Cohen, 0))
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #259 on: June 21, 2020, 02:47:51 am »

Exactly.  It's meant to be used in an If, so that you don't have to string lots of ifs together.

Code: [Select]
If(AND(IsEqual([Artist], Leonard Cohen, 8), IsEqual([Album], Leonard Cohen, 8)),All True, Something's false)
It's essentially a convenience function, to make complicated expressions much shorter. IfCase is another example of that.
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Expression functions [HELP WANTED]
« Reply #260 on: June 21, 2020, 02:56:17 am »

Also

Code: [Select]
AND(IsEqual([Artist], Leonard Cohen, 8), IsEqual([Album Artist], Leonard Cohen, 8))
Returns 0, because the [Album Artist] is empty.

But

Code: [Select]
OR(IsEqual([Artist], Leonard Cohen, 8), IsEqual([Album Artist], Leonard Cohen, 8))
Returns 1, because while [Album Artist] is empty, [Artist] contains "Leonard Cohen".
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #261 on: June 21, 2020, 04:10:16 am »

ListRemove() does not perform on a substring level, is that by design?

listremove(my;test;expression string,/ string) removes nothing
listremove(my;test;expression string,expression string) removes that last item

Maybe there should be a substring mode 2, so...
listremove(my;test;expression string;this string;that string,/ string) would return:
my;test;expression;this;that

-marko
Can be done with Replace(mylist,/ string,,) (Not a List function but anyway...)

BUT what I think could be useful would be mode 2 which removes ALL the items which contains the search query
listremove(my;test;expression string;this string;that string,/ string,2) would return:
my;test
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #262 on: June 21, 2020, 04:34:43 am »

Workaround to remove list items which contain X:
Code: [Select]
listclean(listmix(/#if(isequal([L1],moon,8), , [L1])#/, 0, yellow sun;blue moon;green tree),3)

ListGrep() could take 2 extra modes for a negative search (2=does not contain, 3=does not contain insensitive).
I think changing ListRemove() is not needed, as a simple Replace() works for what Marko wants, as Lepa pointed out.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9140
Re: Expression functions [HELP WANTED]
« Reply #263 on: June 21, 2020, 06:49:17 am »

Exactly.  It's meant to be used in an If, so that you don't have to string lots of ifs together.

Code: [Select]
If(AND(IsEqual([Artist], Leonard Cohen, 8), IsEqual([Album], Leonard Cohen, 8)),All True, Something's false)
It's essentially a convenience function, to make complicated expressions much shorter. IfCase is another example of that.
Also

Code: [Select]
AND(IsEqual([Artist], Leonard Cohen, 8), IsEqual([Album Artist], Leonard Cohen, 8))
Returns 0, because the [Album Artist] is empty.

But

Code: [Select]
OR(IsEqual([Artist], Leonard Cohen, 8), IsEqual([Album Artist], Leonard Cohen, 8))
Returns 1, because while [Album Artist] is empty, [Artist] contains "Leonard Cohen".

Yep, OK, thank you. Foggy head this morning, which isn't getting any better...

jherbert

  • World Citizen
  • ***
  • Posts: 120
Re: Expression functions [HELP WANTED]
« Reply #264 on: July 02, 2020, 11:07:09 am »

I have loads of files that have name of the track completely or partly repeated up to three times, like the following sample:

1. Allegretto, con grazia - Sinfonie Nr. 1 (1947) (New Version For Chamber Orchestra, 1963) - 1. Allegretto, con grazia - Sinfonie Nr. 1 (1947) (New Version For Chamber Orchestra, 1963) - 1. Allegretto, con grazia - Sinfonie


or

1. Etwas lebhaft und mit der innigsten Empfindung (Allegretto ma non troppo) - Piano Sonata No.28 in A, Op.101 - 1. Etwas lebhaft und mit der innigsten Empfindung (Allegretto ma non troppo)



Apart from being wrong and not nice to look at, this is a real problem as filenames and path lengths get out of Windows limits quite easily. Rename and move generates errors, tags are not written properly etc.

My brute force solution is to replace [Name] with a custom field [Save Name] that trims the content of [Name] to say 72 characters, allowing error free saving most of the time.

[Name] still contains lots of garbage, though.

An expression would be handy that does the follwing:

take the leftmost n characters from [Name]
search [name] for that string, starting at n+1
return the string from leftmost position to the start of the match -1
write new [Name] to custom field [Clean Name]

Unfortunately I have no idea how to implement that, nor do I know if there would be a better solution.

I would really appreciate your help on this. Thank you in advance.
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72443
  • Where did I put my teeth?
Re: Expression functions [HELP WANTED]
« Reply #265 on: July 02, 2020, 11:30:11 am »

If your files are named correctly and the error is only in the tag, you could use the Library Tool to fill properties from filename.  Try a few before you do very many.
Logged

jherbert

  • World Citizen
  • ***
  • Posts: 120
Re: Expression functions [HELP WANTED]
« Reply #266 on: July 02, 2020, 01:00:15 pm »

If your files are named correctly and the error is only in the tag, you could use the Library Tool to fill properties from filename. 

They are not, unfortunately. I generate filenames and directories from tags (lossy/lossless for drive, artist/album for directory, disc/track/name for filename), which works well for 99,99 percent. So this is not an option.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #267 on: July 02, 2020, 02:23:32 pm »

Zelda to the rescue :)
This finds the position where the first 20 chars start repeating and then truncates the string there. If there's no repetition, it keeps the first 200 chars - replace the 20 and 200 as desired:

Code: [Select]
clean(left([name], replace(find([name], left([name],20), 20), -1, 200)))
You can use this to generate your [Clean Name], but you will need to rename the actual files to fix your problem.
Logged

jherbert

  • World Citizen
  • ***
  • Posts: 120
Re: Expression functions [HELP WANTED]
« Reply #268 on: July 03, 2020, 02:50:54 am »

Zelda to the rescue :)
This finds the position where the first 20 chars start repeating and then truncates the string there. If there's no repetition, it keeps the first 200 chars - replace the 20 and 200 as desired:

Awesome. Found 3003 files with repetitive patterns.

Changed 200 to 0, so I could easily find those tracks, used move/copy to replace content of [Name] with [Clean name] for these and finally did a rename based on /artist/album/name.

Thank you so much.

(Though there was quite an amount of data mediacenter proved to be rock solid during the operation)
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9140
Re: Expression functions [HELP WANTED]
« Reply #269 on: July 11, 2020, 11:30:18 am »

Still taking requests? If so, if there isn't already a way, I'd love to be able to read environment variables into a couple of my expressions.
Quick question regarding this...

Is this a "Windows only" thing, or do all operating systems have "System Variables", and if the latter, does this expression work on all operating systems MC runs on?

-marko

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #270 on: July 11, 2020, 12:15:44 pm »

Is this a "Windows only" thing, or do all operating systems have "System Variables"

I couldn't say about "all" (which would encompass things like the operating systems for embedded devices) but Windows, MacOS, and Unix/Linux certainly do have environment variables. It's not Windows only.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9140
Re: Expression functions [HELP WANTED]
« Reply #271 on: July 12, 2020, 04:33:05 am »

Thanks wer.

Here's a thing I uncovered regarding GroupCountQuery() (cool function btw) today...

I couldn't figure out why "[artist, 1] (groupcountquery(artist,album,1) albums)" returned "Chris Rea (14 Albums)" but when selected, only 12 albums were listed...
It's because, under my "User" settings, I have an exclusion of -g=Christmas, and "Driving Home For Christmas" is included on two albums, so, although these two Christmas albums are not listed, they are still counted...

Should they be?

I'm happy because I now know what's going on, so I don't really mind either way... incidentally, ~dup also includes items excluded under user settings, but does not display them, which can be potentially, rather confusing.

If pressed to get off the fence, I would side with user settings should be the top level filter and exclusions there should not be considered when performing calculations.

-marko

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #272 on: July 12, 2020, 12:11:30 pm »

GroupCountQuery counts globally, regardless of anything selected or excluded in the view.

It has to work that way, otherwise it would be non-functional in Theater View.  This is because in theater view, when the file info panel is displayed, the current working set is always exactly one file, so the function would always return 1 regardless of circumstances, if it didn't count globally.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9140
Re: Expression functions [HELP WANTED]
« Reply #273 on: July 12, 2020, 12:21:19 pm »

Absolutely, understood, of course, I followed the work you did with Matt closely...

I would still say it should really operate immediately after the user filters. To be clear, I'm talking about filters applied under "View > User > Edit Current User"

As I said before though, it's not a big deal to me either way, just thinking out loud.

-marko

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #274 on: July 12, 2020, 01:06:35 pm »

I think I recall there was some talk about adding an option to make the search global vs the current working set (0/default=global, 1=current set) (which would then do as you describe) so it could be used more flexibly in Standard View, but I don't think it was implemented.  Without such an option I don't see how the expression could tell the difference between "user filters" as you describe vs any other working set limitation, like in theater view or drilling down into a standard view.

Matt would have to comment.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9140
Re: Expression functions [HELP WANTED]
« Reply #275 on: July 12, 2020, 01:18:12 pm »

I wouldn't want current set, I would want global, for theater view...

Thing is, all other Theater View users are oblivious to the fact that there are user exclusions in force, meaning that the results have the potential to confuse and disorientate them.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #276 on: July 13, 2020, 07:34:52 am »

ListRemove() does not perform on a substring level, is that by design?

listremove(my;test;expression string,/ string) removes nothing
listremove(my;test;expression string,expression string) removes that last item

Maybe there should be a substring mode 2, so...
listremove(my;test;expression string;this string;that string,/ string) would return:
my;test;expression;this;that

-marko

I'll add a mode 2 coming later to substring match.  Thanks.
Logged
Matt Ashland, JRiver Media Center

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #277 on: August 17, 2020, 06:26:03 pm »

Is there going to be any more with this thread Matt, or are you all done?

Thanks...

Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #278 on: August 17, 2020, 07:47:41 pm »

I'm still open to good ideas 😀
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #279 on: August 18, 2020, 03:17:41 am »

Here's one that definitely takes more than 5 minutes of your time: user defined functions and function libraries ;D
It sounds complex but it's actually simple, it's mostly string handling/replacement:

function(fname, /#definition#/) - register a function definition (code) for a new function (just saves the definition as a string, no parsing)
call(fname, arg1, arg2, ...) - call a used-defined function (just replaced by the definition on first-pass parsing)
using(fieldName) - load [fieldName] field which would contain a set of function definitions (save() variables could also be there)

The end goal would be to have libraries of user-defined functions that could be developed, maintained and shared by the community.

examples:
Simple example with min/max functions (I know they exist in Math(), this is just an example):
Code: [Select]
function(max, /#if(isequal([P1],[P2],5),[P1],[P2])#/)
function(min, /#if(isequal([P1],[P2],5),[P2],[P1])#/)
Where [P1],[P2]...[Pn] are the function parameters that will be replaced when the function is called (simple string replace)

Usage:
call(max, 10, 15)                 => returns 15
call(min, \[last played\], 1)   => this replaces [P1] with [Last Played], which is then interpreted as the actual field. Should be the same as "call(min, [last played], 1)"

Alternatively (better), you could get rid of Call() by just detecting that this is a known/defined function:
max(10, 15)                        => returns 15, same as call(max, 10, 15)

Function library:
We could store a bunch of function definitions in a Field, for instance in [Functions]. To use this function library in other places we would just import the field at the top of our code:
Code: [Select]
using(functions)/
min(100,10)

Simply doing "[functions] min(100,10)" could also work, but it would produce a few newline chars on the output. Importing with Using() would load the definitions while suppressing all output, avoiding that problem.

The [functions] field could actually be a predefined field for this, and it would be automatically imported if it exists. The user could still import other fields with Using(). This would make all this much easier to use in any place where Expressions can be used, such as for sorting, filtering, etc, without having to explicitly type "using(functions)"

Notes and caveats:
- recursive functions probably cannot be allowed
- functions calling other functions should however work, as long as the call stack doesn't result in a loop
- function definition order should not matter, but the case where F1() calls F2(), but F2() is defined after F1() needs to be handled.
- since this is simple string replacement, arguments can be simple values, lists, fields, expressions, etc.
- performance should not be affected by having large function libraries, as, again, all this would just (mostly) work via string replacement
- redefining a user-function should replace the definition, but redefining a system function should probably not be allowed
- the predefined [functions] fields could be loaded once, systemwide, at MC startup (and reloaded when it's saved/changed) (this would work for function definitions but not for save() calls which require the current context to be a File)
- a library field such as [functions] can also include other using() calls. This way the [functions] would be a global auto-loading field for all user code.

...Too complex?

Thanks!
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #280 on: August 20, 2020, 01:28:42 pm »

Thanks for the idea.  I wonder if functions could just be stored as part of the expression editor (popup dialog).

Making a working min and max sounds fun 😀
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #281 on: August 20, 2020, 01:44:08 pm »

As long as they're available globally, where they're stored is secondary (to the users). I think it would be useful to load them from Field(s), so that users could maintain different function libs: [FunctionsMoe], [FunctionsMarko], [DateFunctions], etc. Sort of separate modules that could be updated just by pasting a new version into the computed field.

Another option is for MC to load all *.elm files from some folder at startup (elm = expression language module). This file could then have some header for version number, module name, etc (optional).

Addenda: Function() could take a 3rd argument for the tooltip text - Function(name, definition, tooltip)

Now go enjoy your vacation :)
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Expression functions [HELP WANTED]
« Reply #282 on: August 20, 2020, 03:52:13 pm »

I'm still open to good ideas 😀

I'd still encourage on FieldQuery.  It would enable returning related files, which would be especially neat in Theater View...  Do you think it's a good idea?  ;D

FieldQuery: Return a list of matches based on a list of fields to search, from a selected scope of files.

Syntax:
FieldQuery(fieldlist,valuelist,return,mode,scope)

Fieldlist: list of fields to search, e.g. Director;Studio

Valuelist: a value to search for each field in fieldlist (could be an expression)

Return: The single field that is returned when a match is found, values from files returned as a ; delimited list

Mode: 0=contains
     1=exact match

Scope: 0=global (searches all files), 1=current view scope (just search the files in the current view, for speed)


Examples:

FieldQuery(Director,Ridley Scott,Name,1,0) returns
Alien;Blade Runner;Gladiator

FieldQuery(Actors,Al Pacino,Name,0,0) returns
The Godfather;Heat;Scarface

FieldQuery(Actors;Director,Al Pacino;Michael Mann,Name,0,0) returns
Heat
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #283 on: August 24, 2020, 10:17:29 am »

Thanks for the idea.  I wonder if functions could just be stored as part of the expression editor (popup dialog).

Making a working min and max sounds fun 😀

I just added the functions min and max.  If there are other simple ones, just let me know.

I'm not sure we'll add the ability to add user defined functions.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #284 on: August 24, 2020, 10:35:09 am »

Thanks.
There was already a Math(min(x,y)) and Math(max(x,y)), though I do prefer them outside Math().
Rand() is another function that exists both as standalone and in Math(). Randn() OTH, only exists in Math().
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #285 on: August 24, 2020, 10:40:24 am »

Thanks.
There was already a Math(min(x,y)) and Math(max(x,y)), though I do prefer them outside Math().
Rand() is another function that exists both as standalone and in Math(). Randn() OTH, only exists in Math().

Do you think randn is needed?  You can already specify Rand(-5, 5) and get the range.  Thanks.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #286 on: August 24, 2020, 10:42:20 am »

You may want to consider more than 2 args for min/max:
min(a,b,c, ... N)    (more than 2 args)
max(a,b,c, ... N)

You can also add other aggregator functions in the same way: Avg(...) and Sum(...) come to mind.

Additionally, what about this one:
ListMath(list, mode)
mode 0 = min of all list elements
mode 1 = max
mode 2 = sum
mode 3 = avg

Non-numeric list items are valued as zero, or as Number(item)
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #287 on: August 24, 2020, 10:43:26 am »

You may want to consider more than 2 args for min/max:
min(a,b,c, ... N)    (more than 2 args)
max(a,b,c, ... N)

I had already thought about this.  They both accept any number of parameters.

Quote
You can also add other aggregator functions in the same way: Avg(...) and Sum(...) come to mind.

Additionally, what about this one:
ListMath(list, mode)
mode 0 = min of all list elements
mode 1 = max
mode 2 = sum
mode 3 = avg

Non-numeric list items are valued as zero, or as Number(item)

I'll think on these.  Thanks.
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #288 on: August 24, 2020, 10:44:16 am »

Do you think randn is needed?  You can already specify Rand(-5, 5) and get the range.  Thanks.

No, I'm just saying that one exists as standalone and the other doesn't.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #289 on: August 24, 2020, 10:55:09 am »

I'm not sure we'll add the ability to add user defined functions.

Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Expression functions [HELP WANTED]
« Reply #290 on: August 25, 2020, 08:14:24 am »

I'd still encourage on FieldQuery.  It would enable returning related files, which would be especially neat in Theater View...  Do you think it's a good idea?  ;D

Yes, I like it.  I'll try to add it to the coming MC27.  Thanks!
Logged
Matt Ashland, JRiver Media Center

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #291 on: September 07, 2020, 04:21:30 am »

Here's one I'd like:

Repeat(string, count) - repeats the string count times (count >= 0)

Repeat(- , 20) = "- - - - - - - - - - - - - - - - - - - - "
Repeat(★,7)Repeat(☆,3) = ★★★★★★★☆☆☆
Repeat(☆,0) = <blank>
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #292 on: September 07, 2020, 04:21:51 am »

And a couple others:

PadLeft(string, length, char) - pad the string on the left
PadRight(string, length, char) - pad the string on the right
string: string to pad
length: desired string length
char: optional, default is space; char to pad the string with
Logged

mvandyke

  • World Citizen
  • ***
  • Posts: 159
Re: Expression functions [HELP WANTED]
« Reply #293 on: September 07, 2020, 07:32:20 am »

I'm not sure which expression (or the exact syntax) to use to get the follow:

Compare the artist field to artist biography field and return a 1 (or 0) if the artist biography field does not contain any text that matches from the artist field.

example
artist field=John Legend
Artist Biography field does not contain a text string = "John Legend" then return a 1 , If it does contain the artist field then return a 0.

I've looked at the search tags expression and many others and can't quite figure out how to do this.

Thanks in advance for any potential help!
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Expression functions [HELP WANTED]
« Reply #294 on: September 07, 2020, 07:40:08 am »

Compare(Find([Artist Biography],[Artist]),>=,0)     = returns 1 if [Artist Biography] contains [Artist]
Compare(Find([Artist Biography],[Artist]),<,0)       = returns 1 if [Artist Biography] does not contain [Artist]
Logged

mvandyke

  • World Citizen
  • ***
  • Posts: 159
Re: Expression functions [HELP WANTED]
« Reply #295 on: September 07, 2020, 11:10:40 am »

Compare(Find([Artist Biography],[Artist]),>=,0)     = returns 1 if [Artist Biography] contains [Artist]
Compare(Find([Artist Biography],[Artist]),<,0)       = returns 1 if [Artist Biography] does not contain [Artist]

Thanks that worked perfect - appreciate your help.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #296 on: September 12, 2020, 03:42:29 am »

Would it be possible to implement function which returns smartlists where file belongs at the time? Like FilePlaylists() but for smarlists.
It would allow access to some statistical information like "most played songs" etc.
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Expression functions [HELP WANTED]
« Reply #297 on: September 12, 2020, 04:17:00 pm »

Smartlists are re-evaluated every time they are opened, or accessed. So I don't think you could get that data, and if you could it wouldn't be useful as it wouldn't indicate a file has been played.

Use the [Number Plays] field and a new View to work out the most played tracks. Or just sort any View by [Number Plays].
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2033
Re: Expression functions [HELP WANTED]
« Reply #298 on: September 12, 2020, 05:05:18 pm »

Thanks for suggestion but that doesn't work at all for what I had in mind. I'm not after making Views.
What I was thinking e.g. that I would have smartlist of say 50 most played songs. Now I if could determine with expression that does a song in question currently belong to that smart list, I could print it in tooltip/theaterview as "TOP50 songs".
Merely using [number plays] doesn't tell anything about popularity against others songs.

Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Expression functions [HELP WANTED]
« Reply #299 on: September 12, 2020, 05:51:57 pm »

Hmmm, whether the solution you described could be provided is definitely a question for Matt.

But I think you could do what you want with an expression. I would have to think about that. I'm a bit busy right now, but the expression would do something like the Smartlist, and return a 1 or 0 based on the Limit function, ~n.

Wrap something around this:
[Media Type]=[audio] ~sort=[Number Plays]-d ~n=50
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner
Pages: 1 2 3 4 5 [6] 7 8 9   Go Up