INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Expression question  (Read 7285 times)

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Expression question
« on: October 28, 2012, 07:48:02 am »

Is it be possible to check if the average bitrate of an album is below a certain value?
Logged

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: Expression question
« Reply #1 on: October 28, 2012, 08:15:49 am »

From my understanding of global variables you should be able to do it

Maybe something along the lines to this. It quite hard to wrap your head around global variables. I was hoping to use global variables to create a tagging system but I don't know if it is possible. Do you know if the output of global variables can be outputted in a pane?

http://yabb.jriver.com/interact/index.php?topic=72049.0
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #2 on: October 28, 2012, 08:18:07 am »

Thanks Brian, I'll have a look at that link later.

I have no idea about global variables, I've only recently started actually using expressions to help me do stuff.
Logged

Lasse_Lus

  • Citizen of the Universe
  • *****
  • Posts: 999
Re: Expression question
« Reply #3 on: October 28, 2012, 08:26:05 am »

you can try out categories,detailed view and add bitrate as a column, you will then see the avg bitrate per grouping
Logged
MT5FR

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression question
« Reply #4 on: October 28, 2012, 01:44:24 pm »

Expanding on Lasse_Lus' good idea, add also an expression column, for example:

   if(compare([bitrate], <, 200), LESS, MORE)
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression question
« Reply #5 on: October 28, 2012, 01:51:17 pm »

Do you know if the output of global variables can be outputted in a pane?

Yes.  The Load() function is just an expression like all others, whose value can be output in an expression column.

   load(var)

where the global var was previously set.  A trick to set var's value per view is to create a custom search, such as this in the Set rules for file display... :

  [=save(1,var)1]=1
 
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #6 on: October 28, 2012, 02:29:28 pm »

you can try out categories,detailed view and add bitrate as a column, you will then see the avg bitrate per grouping

Expanding on Lasse_Lus' good idea, add also an expression column, for example:

   if(compare([bitrate], <, 200), LESS, MORE)

But that doesn't give a list of albums for which the average bitrate is below a given value, does it?

I'll play around with it, thanks guys!
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression question
« Reply #7 on: October 28, 2012, 02:41:48 pm »

Not directly.  But you can select the MORE entries on then the file list will show the albums.

Or, you can use the same technique as in this thread:

  http://yabb.jriver.com/interact/index.php?topic=72049.0

but instead you'll store / increment a variable, something like, var_bitrate_[Album]_[Album Artist (auto)].

I'm headed out now; if you'd like some help, bump this thread, and I'll post a solution when i return.
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #8 on: October 28, 2012, 02:42:42 pm »

I'll fiddle around some, thanks!
Logged

Lasse_Lus

  • Citizen of the Universe
  • *****
  • Posts: 999
Re: Expression question
« Reply #9 on: October 29, 2012, 06:05:13 am »

But that doesn't give a list of albums for which the average bitrate is below a given value, does it?

True Mouse, but you can sort to see what albums has low avg..

another option would be to copy data to excel and build a nice pivot table
Logged
MT5FR

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #10 on: October 29, 2012, 01:10:13 pm »

The problem with the above is that albums are not kept together.

It should be relatively simple using listbuild() and math(). Relatively because so far I've been unable to whip up a working expression :P.
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #11 on: October 29, 2012, 01:24:22 pm »

I was thinking

listbuild(1,;,[bitrate]) --> builds the list of bitrates

listcount(listbuild(1,;,[bitrate]),;) --> should give the amount of values in the list (doesn't work, returns 1)

math((listbuild(1,;,[bitrate])) / listcount((listbuild(1,;,[bitrate]),;)) --> divide total by count.
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #12 on: October 29, 2012, 01:38:42 pm »

Hm ... I see how that's not gonna work  :-\
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression question
« Reply #13 on: October 29, 2012, 01:45:08 pm »

You'll want:

 - a bitrate_sum variable per album / album artist (auto), that sums the bitrates
 - a track count variable per album / album artist (auto), that counts the tracks

Your output will be the division of bitrate_sum / track count for each of the album / album artist (auto) variables.

Example variables:

   v_bitrate_sum_[album]_[album artist (auto)
   v_trackcount_[album]_[album artist (auto)
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #14 on: October 29, 2012, 03:37:00 pm »

I can't get that to work I'm afraid  :-[

I need to look at that album rating expression more carefully but its not something I can easily wrap my head around without frying my brain.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression question
« Reply #15 on: October 29, 2012, 09:20:39 pm »

Ok, maybe this will help:

Paste this into the Set rules for file display in the view, via the Import/Export button:

[Media Type]=[Audio] [=save(0,v_tracks[album artist (auto)][album])1]=1 [=save(math(1+load(v_tracks[album artist (auto)][album])),v_tracks[album artist (auto)][album])1]=1 [=save(0,v_brsum[album artist (auto)][album])1]=1 [=if(compare([bitrate],=,0),save(-1,v_brsum[album artist (auto)][album]),)1]=1 [=if(compare(load(v_brsum[album artist (auto)][album]),>,-1),save(math([bitrate]+load(v_brsum[album artist (auto)][album])),v_brsum[album artist (auto)][album]),)1]=1 ~sort=[Album Artist (auto)],[Album],[Track #],[Media Type],[Disc #],[Name]

Paste this into an expression column either in a pane or file list column depending upon your needs:

if(compare(load(v_brsum[album artist (auto)][album]), >, 0),
   formatnumber(
      math( load(v_brsum[album artist (auto)][album]) / load(v_tracks[album artist (auto)][album]) ),
      2
   ),
0)

You should now have an expression column that shows average bit rate per-album.

Let's break the first expression down, piece by piece:

[Media Type]=[Audio]

We want audio files only.

[=save(0, v_tracks[album artist (auto)][album])1]=1

This saves the value 0 into a global variable, whose name is the concatenation of "v_tracks" and the value of [album artist (auto)] and [album].  In otherwords, there is one variable created per unique album.  The extra [= ]=1 syntax around the outside is required since the custom rule needs to look like an MC search expression of the form [=expr]=1.  That extra 1 just inside is the sneaky trick to ensure that the expr portion outputs a 1, since the save() function generates no output.  So, save() executes and the ultimate output of the expression is [=1]=1, thus being true for ALL FiLES MC examines.  This causes the variable to be set for each album (yes, multiple times, but that's OK).

[=save(math(1+load(v_tracks[album artist (auto)][album])),
     v_tracks[album artist (auto)][album])1]=1


This loads the value of the per-album number of tracks global variable, so that math() can add 1 to it, and then saves it back into the per-album number of tracks global variable.  The previous search rule already initialized the variable with 0.  As MC operates on each track (by determining if the rule would select a track for inclusion), the per-album tracks global variable is incremented.

[=save(0, v_brsum[album artist (auto)][album])1]=1

This initializes the per-album bitrate sum global variable with 0, just like above.

[=if(compare([bitrate],=,0),
   save(-1, v_brsum[album artist (auto)][album]),
)1]=1


This tests the tracks bitrate for 0, and saves -1 into the per-album bitrate if the bitrate is 0.  The If() does nothing if bitrate is not 0.

[=if(compare(load(v_brsum[album artist (auto)][album]),>,-1),
   save(math([bitrate]+load(v_brsum[album artist (auto)][album])),
       v_brsum[album artist (auto)][album]),
)1]=1


This compares the per-album bitrate sum against -1; i.e. is it initialized?.  If initializesd, then load the current per-album bitrate sum and add it to the track's bitrate, and then re-save that into the per-album bitrate sum.  Nothing is done if the per-album bitrate sum is -1.

~sort=[Album Artist (auto)],[Album],[Track #],[Media Type],[Disc #],[Name]

Gratuitous sorting

I think at this point the expression column expression should be pretty clear.
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #16 on: October 30, 2012, 01:48:37 am »

Many thanks MrC,appreciate you taking the time to work that out.

Early morning here gotta run for work I'll have a go at it when I get back.
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #17 on: October 30, 2012, 12:58:37 pm »

This is beautiful ...  :-*

4 panes: Artist, this expr, Album, your expr.

Code: [Select]
if(isequal(if(compare(load(v_brsum[album artist (auto)][album]), >, 0),
   formatnumber(
      math( load(v_brsum[album artist (auto)][album]) / load(v_tracks[album artist (auto)][album]) ),
      2
   ),
0),200,3),< 200,> 200)

It's going to take some time to wrap my head around the rules for display. I appreciate you taking the time to spell it all out, thanks!

I just have one more question: how do you know all that? I mean, I can't find any info in the wiki about those variables and the syntax used (starts with [=... ?).
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: Expression question
« Reply #18 on: October 30, 2012, 01:06:47 pm »

And btw, I can't believe how fast this is, its instant.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression question
« Reply #19 on: October 30, 2012, 01:10:52 pm »

Beautiful is good.

There's nothing intuitive about how we've had to trick Set rules for file display, but it works.  I got the idea when global vars were introduced, and it was obvious there needed to be a way to force an evaluation *before* pane content and the file list was produced.

The [= expr ]=1 syntax is described here.

The Load() and Save() functions have not been documented on the expressions wiki page yet.

The (global) variable names themselves are just made up names, supported by Load() and Save().

The real answer to your question "how do you know all that?" is that I waste way too much time discovering the inner workings of Matt's mind and his pet Expression Language idiosyncrasies.    :D
Logged
The opinions I express represent my own folly.

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72534
  • Where did I put my teeth?
Re: Expression question
« Reply #20 on: October 30, 2012, 01:18:01 pm »

The real answer to your question "how do you know all that?" is that I waste way too much time discovering the inner workings of Matt's mind and his pet Expression Language idiosyncrasies. 
Matt has a curious mind.

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression question
« Reply #21 on: October 30, 2012, 01:36:22 pm »

Matt has a curious mind.

A Beautiful Mind.
Logged
The opinions I express represent my own folly.

struct

  • Galactic Citizen
  • ****
  • Posts: 380
Re: Expression question
« Reply #22 on: October 30, 2012, 03:52:06 pm »



Very cool outcome, very impressed.

Got me thinking, is there set of variables (e.g. average bitrate) that we could reasonably agree to have automatically populated in the long bar at the bottom of the screen to save the development of some "common" expressions.  Values would be determined on the current selection only.  At the moment when we have a selection of files we get the file count, cummulative file size, and duration of play but there is whole lot of wasted space down there.

Could this information be expanded and selectable by a right click, similar to what MS Excel does at its bottom bar (i.e. you have the choice of displaying, max, min, average, count etc and you simply right click to get the ones you want normally displayed.)

This is assuming that there is a reasonable set of summary information.  Here is a starting guess...

Average bit rate
Average files per Album
Average song rating
Average album rating
Average year of production


Are there others??

Craig
Logged
Pages: [1]   Go Up