INTERACT FORUM

Please login or register.

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

Author Topic: Database Expressions... what?  (Read 6776 times)

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9133
Database Expressions... what?
« on: January 25, 2007, 04:22:08 am »

Quote from: park
Finally, I'm sure that expressions must be very powerful, but I still have no idea how to write one, and cant even picture what kind of expression I would need. It would be cool if there were some stock expressions (like the stock smartlists that you can add at any time) as options in some kind of pulldown menu too.

While it is possible to use expressions in the search bar, the need does not arise very often so perhaps we'll go there later.
Expressions can be used in lots of places around MC, for different reasons, with the most common reason being aesthetic, so lets start there.

Say you want a pane to show you the [number plays] field. Add one to a view scheme and you see the values for [number plays], but, all those files that have never been played are listed in the pane under "Unassigned". I don't like unassigned, and now that we have expressions, we can get rid by using one instead of the standard library field. Simply get rid of the standard [number plays] pane, and replace it with an expression that says, show me [number plays], unless it's empty, in which case, show me "Not Played Yet"
if(isempty([number plays],Not Played Yet,[number plays])

I use the formatdate expression quite a lot to get dates shown the way I want them. [date imported] without the time, for example.
formatdate([date imported,0],yyyy - MM -dd)

Where these things really come into their own, is with your picture library. The difference is that with audio, everything is pretty linear, and using a details view, most of the info we want is there to see, easy. With pictures, we really need to be in thubnail view, so detais are hidden, and space beneath the thumbnail for information is tight. Enter expressions...
My image workflow dictates that if a picture does not have a subject tag, then it's not tagged, so, the following expression:
if(isempty([subject],not tagged,)
will place the not tagged text under the thumbnail if it's not tagged, and show nothing if it is tagged, freeing up space for other info I may want on display.

In this post, I describe how creating two new expression based library fields from the [date (filename friendly)] field and then sorting by them, allows you to list photos "Newest first, but sorted oldest first within days" so you see photos taken today at the top of the list, sorted into the order they were actually taken.

When using the "rename from properties" tool, I use strict rules, dictated by media type. I've created rather long expressions for both the file name, and the directory fields which allow me to select a bunch of tagged files, right click, rename from properties and immediately click the OK button. I don't need to worry myself about things like [media type], if the tags are correct, MC will place each file in the correct location.

When playing picture slideshows, MC shows a caption beneath each slide. This is nice, but a pain if pictures don't all contain the tags specified in the caption string. Again, this can be avoided by using expressions to display a different tag if another is not available.

If you use the playingnow plugin, you'll know that it displays tag info in a popup box. For the most part, that info is static, but, you can create expression based fields specifically for playingnow to use. In my signature image, the text in the bottom line, from the number of plays to the end is all generated by a single expression based field.

In summary, expressions are a lot like smartlists in that they are more personal than portable. You would use them to bend MC into a shape that's right for you, for reasons best known to you, therefore, your expressions would likely not make a lot of sense, nor be a lot of use to someone else, hence the reason, IMVHO, that the expression and smartlist sharing threads are not as popular as everyone wishes they were.

When you want MC to do something, best policy so far has been to ask how. If expressions are the answer, take that opportunity to ask why, and so learn a little from the questions. Once you get started, it doesn't take long before you instinctively know what you need, and how to get it. :)

Any questions?

-marko.

dcwebman

  • Citizen of the Universe
  • *****
  • Posts: 2154
Re: Database Expressions... what?
« Reply #1 on: January 25, 2007, 09:06:24 am »

Excellent post marko. If you haven't already, will you be adding it to the Wiki?
Logged
Jeff

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Database Expressions... what?
« Reply #2 on: January 25, 2007, 12:46:00 pm »

Thanks Marko.

I posted a question a while ago in the MC11 form (no answer yet); perhaps there's some expression that can do what I want.

I have a numeric reference id from 1 to n, which I use in a view scheme to list cd's by this reference id, grouped in groups of 160 discs.  Unfortunately, the group by box is 0-based, so cds are listed as reference ids

     0 - 159
 160 - 319
 ...

I'd like

    1 - 160
161 - 320

Is there a way to do this?
Thanks in advance,
MrC
Logged
The opinions I express represent my own folly.

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9133
Re: Database Expressions... what?
« Reply #3 on: January 25, 2007, 01:34:26 pm »

dcwebman, probably, at some point, my playtime is getting a serious squeeze atm.

MrC, 1st thing that springs to mind is to use the new search list option. The only drawback with that approach is that it's not maintainence free like the 'group items' option is...

You would name the search list "Reference ID" and then add searches like so:
1 - 160 [=isrange([reference id],1-160)]=1
161 - 320 [=isrange([reference id],161-320)]=1
321 - 480 [=isrange([reference id],321-480)]=1
481 - 640 [=isrange([reference id],481-640)]=1

and so on. It will work for you, but you'll need to add searches as the ref id list grows outside the highest grouping.

... and that is how you use expressions in searches! [=<EXPRESSION>]=1 (use one for positive results, or zero for negative results)

-marko.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Database Expressions... what?
« Reply #4 on: January 25, 2007, 04:11:57 pm »

Marko - fantastic thanks!  This worked like a charm. 



Adding a new expression every 160 CDs is trivial, so maintainence is not a problem for me.

I suppose it would be a nice feature if the Group By could have a check box which would make numeric groupings 1-based instead of 0-based, or even more general yet, and offset that could be added to numeric Group By's.

Thanks again!
Logged
The opinions I express represent my own folly.

dcwebman

  • Citizen of the Universe
  • *****
  • Posts: 2154
Re: Database Expressions... what?
« Reply #5 on: January 25, 2007, 07:09:00 pm »

dcwebman, probably, at some point, my playtime is getting a serious squeeze atm.

I have the day off tomorrow so I'll have time to add it for you.
Logged
Jeff

park

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2358
  • I wish I had more to say!
Re: Database Expressions... what?
« Reply #6 on: January 28, 2007, 08:59:57 pm »

That sounds great. Thanks for the summary.

Would there be some way to force information into different fields? I can think of several usage scenarios:

1) At work, I have images and music in folders based on the where they were purchased. It would be good if there were an expression to tag the "source" field in those files to the names of the folders.

2) I would prefer my video files to automatically fill the album field with the [Name] or "Volume Name" info depending on whether the file were a DVD or divX file.

3) I'd like some fields to be auto filled upon import. Eg, most of the music I import is full albums, and I have a custom field specifying whether something is an album, ep, or single. It'd be nice if it always imported as "Album" so that I only had to change the odd cd now and then if it were an ep or whatever.

Just some general info on if any of these are possbile or not, and a summary of the logic/process would be great.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9133
Re: Database Expressions... what?
« Reply #7 on: January 29, 2007, 03:19:35 pm »

That sounds great. Thanks for the summary.

Would there be some way to force information into different fields?
No, we can't do that with expressions. The closest we can get is to create calculated, expression based library fields, then use the "move/copy fields" tool to copy the data to the desired fields.

1) At work, I have images and music in folders based on the where they were purchased. It would be good if there were an expression to tag the "source" field in those files to the names of the folders.
If this one is for portability, then again, it's not so straightforward, because we don't have the option of storing calculated field data in file tags.
If it's not for portability, then whether or not expressions would be of any use to you here depends on your workflow. If, for example, you download the files directly into the various source folders and let auto-import deal with them, then an expression could be written to present those files in a pane that offers source filtering.

2) I would prefer my video files to automatically fill the album field with the [Name] or "Volume Name" info depending on whether the file were a DVD or divX file.
Again, we can't automatically fill existing fields in this way, but it should be possible to write an expression for use inside your video library that says if filename contains video_ts then output [volume name] otherwise, output [name]

3) I'd like some fields to be auto filled upon import. Eg, most of the music I import is full albums, and I have a custom field specifying whether something is an album, ep, or single. It'd be nice if it always imported as "Album" so that I only had to change the odd cd now and then if it were an ep or whatever.
How about an expression that displays empty instances of the custom field as "Album"? The expression could also be made to take care of existing "Album" entries if required.

Just some general info on if any of these are possbile or not, and a summary of the logic/process would be great.
Extremely general comments above that hopefully help shed a little light on where the boundaries lie for expressions. If after reading the comments, you think that expressions might be useful, I'd need more detail about workflow and projected usage to be able to offer any example expressions that you might be able to use or tweak. From what we've got so far, it feels as if the most promising area is the custom "Album, EP, Single" field.

-marko.
Pages: [1]   Go Up