INTERACT FORUM

Please login or register.

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

Author Topic: Editing Expressions - 2 utilities  (Read 2494 times)

EpF

  • Citizen of the Universe
  • *****
  • Posts: 649
Editing Expressions - 2 utilities
« on: April 13, 2006, 05:39:04 pm »

I use Notepad++ and NoteTab Light, (both free), to edit advanced expressions for MC, and I've written 2 utilities, one for each, which I find useful.

The first, for Notepad++, is a user-defined language which displays all the different elements of an expression using a colour and font-weight scheme.

To install it:

If you have not created any user-defined languages already, go to "Documents and Settings\Application Data\<username>\Notepad++" and create a new file called 'userDefineLang.xml' and copy the following code into it:

Code: [Select]
<NotepadPlus>
    <UserLang name="JRMCExpressions" ext="jrx">
        <Settings>
            <Global caseIgnored="yes" />
            <TreatAsSymbol comment="yes" commentLine="no" />
            <Prefix words1="yes" words2="no" words3="no" words4="no" />
        </Settings>
        <KeywordLists>
            <Keywords name="Delimiters">[{0]}0</Keywords>
            <Keywords name="Folder+">Xstart</Keywords>
            <Keywords name="Folder-">Xend</Keywords>
            <Keywords name="Operators">- ( ) , / { } ~ &lt; = &gt;</Keywords>
            <Keywords name="Comment">1#!! 2!!# 0##</Keywords>
            <Keywords name="Words1">If IsMissing IsRemovable IsEqual IsEmpty IsRange FilePath FileName FileVolume FormatNumber FormatDate FormatDuration FormatBoolean FormatFileSize FormatRange AlbumArtist AlbumType Size CustomData Clean FixCase Mid</Keywords>
            <Keywords name="Words2">&amp;DataType</Keywords>
            <Keywords name="Words3">[String] [List] [Number] [Path] [Month]</Keywords>
            <Keywords name="Words4">or</Keywords>
        </KeywordLists>
        <Styles>
            <WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="FOLDEROPEN" styleID="12" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="FOLDERCLOSE" styleID="13" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="KEYWORD1" styleID="5" fgColor="0000FF" bgColor="FFFFFF" fontName="Verdana" fontStyle="0" />
            <WordsStyle name="KEYWORD2" styleID="6" fgColor="8000FF" bgColor="FFFFFF" fontName="Verdana" fontStyle="0" />
            <WordsStyle name="KEYWORD3" styleID="7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="KEYWORD4" styleID="8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="3" />
            <WordsStyle name="COMMENT" styleID="1" fgColor="C0C0C0" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="COMMENT LINE" styleID="2" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="NUMBER" styleID="4" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="10" />
            <WordsStyle name="OPERATOR" styleID="10" fgColor="FF00FF" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="DELIMINER1" styleID="14" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="DELIMINER2" styleID="15" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="DELIMINER3" styleID="16" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
        </Styles>
    </UserLang>
</NotepadPlus>

If you do have other user-defined languages, the file will already exist, so open it for editing and copy the above code without the opening "<NotepadPlus>" and closing "</NotepadPlus>" tags and paste it into the file, making sure not to overwrite any of the opening or closing tags of the overall xml file or other languages in there.

Note that files using this language must be saved with a .jrx extension, which can be done in the save dialog in Notepad++. You can also edit the language scheme within Notepad++ if you don't like the colours I've chosen. The program also allows text folding to reduce clutter as you work. To enable this for .jrx files, start each expression with the text: Xstart (case is important), end it with: Xend. You must put a space or a return after these opening statements. If you use a space and then a title, the title will remain visible when the expression is closed. (See screen shot below for example).



The second is a clip library for NoteTab Light, with which you can simply double-click the name of an expression function or a field and it will be written into the current document with the cursor in the appropriate place. Right click and download this file: MC Expressions & Smartlists.clb, and copy it as a file into the Libraries folder of NoteTab Light in the '"Program Files" folder in Windows. Then it is available as a clip library along with all the others. You can add your own fields to the list by editing the library.

The reason I use two is because you can't colorize the text in NoteTab Light, and I find that very useful in Notepad++ to read what's going on in an expression.

darichman

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1350
Re: Editing Expressions - 2 utilities
« Reply #1 on: April 14, 2006, 06:58:17 pm »

Awesome :)

Will have a look tonight.
Logged

hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Re: Editing Expressions - 2 utilities
« Reply #2 on: November 07, 2006, 07:50:24 am »

Got lost after i pulled your JRX.txt file.

Where do i save it and how do i configure Notepad++ to use it ?
Logged

EpF

  • Citizen of the Universe
  • *****
  • Posts: 649
Re: Editing Expressions - 2 utilities
« Reply #3 on: November 07, 2006, 02:04:56 pm »

Got lost after i pulled your JRX.txt file.
Yeah, not surprised. I made a mess of the original first post. I've edited it now; hopefully it's much clearer.

Quote
Where do i save it and how do i configure Notepad++ to use it ?
Any files saved with a ".jrx" extension should use the language automatically when you open them. When you're starting a file from scratch, just go to the Language menu and choose 'JRMCExpressions' from the list (should be at the bottom).

Let me know if that clears things up for you.

hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Re: Editing Expressions - 2 utilities
« Reply #4 on: November 07, 2006, 02:28:36 pm »



Much better now thanks.

if(isequal([Track#],99,5),[Track#],if(isequal([CUETrack],source,8),if(isempty([Disc#],1),100,[Disc#]00),if(isempty([Disc#],1),if(isempty([Track#],1),[Track#],if(isequal([Track#],10,3),0[Track#],[Track#])),if(isequal([Disc#],1,6),if(isequal([Track#],10,3),[Disc#]0[Track#],[Disc #][Track #]),))))

This expression should fix up the [Track #] in Playing now, but trying to figure why it won't work in MC, i've messed up the parentheses with a comma somwhere  ?


When nesting expressions, those commas make my eyes go blank after a while, so much easier to do this with then & elseif instead of commas.

Any tips to workaround this ?
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8952
Re: Editing Expressions - 2 utilities
« Reply #5 on: November 07, 2006, 08:00:29 pm »

[disc#] & [track#]....

if they're not custom fields or typos, they should be [disc #] & [track #]....

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8952
Re: Editing Expressions - 2 utilities
« Reply #6 on: November 07, 2006, 08:08:06 pm »

assuming they're custom fields, I'm not sure, some of the logic doesn't feel right... brb...

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8952
Re: Editing Expressions - 2 utilities
« Reply #7 on: November 07, 2006, 08:41:02 pm »

if(isequal([Track#],99,5),[Track#], - if track# is greater than 99, then use[track#]

if(isequal([CUETrack],source,8), - if [track#] is less than or equal to 99, does [cuetrack] contain source?

if(isempty([Disc#],1),100,[Disc#]00), - if [track#] <= 99 and [cuetrack] contains source, is [disc#] empty? if so, use 100, else use [disc#]00 <-- you sure? we've just established that [disc#] is empty?

if(isempty([Disc#],1), - if [cuetrack] does not contain source, is [disc#] empty?

if(isempty([Track#],1),[Track#], - if [cuetrack] does not contain source, and [disc#] & [track#] are both empty, then use [track#] <--again, you sure?

if(isequal([Track#],10,3),0[Track#],[Track#])), - if [cuetrack] does not contain source, [disc#] is empty, and [track#] is less than 10, use a preceding zero, otherwise, just use [track#]

if(isequal([Disc#],1,6), - if [cuetrack] does not contain source, and [disc#] is not empty, is [disc#] greater than or equal to 1?

if(isequal([Track#],10,3),[Disc#]0[Track#],[Disc #][Track #]),) - if [disc#] is greater than or equal to 1, is [track#] less than 10? if so use [disc#]0[track#], otherwise, use [disc #][track #] <-- this is the 1st time you've used the standard MC fields? This at the end, ",)" says, if [disc#] is less than 1, then do nothing.

))) - closes the branches: if(isempty([Disc#],1), ; if(isequal([CUETrack],source,8), ; if(isequal([Track#],99,5),[Track#],

-------------------------------------------

It looks OK on paper, though some of the statements don't feel quite right, for example, you ask if the [disc#] is empty, and if it is not empty, you ask if its value is greater than or equal to 1, which it must be, otherwise, it would be empty.

I can't test it because of the custom fields etc. but, when building these things, I find the order in which you ask the questions can help greatly.
I try to imagine a main line from start to end, if the answer is yes, then I leave the main line and follow this branch to it's conclusion, and having dealt with that scenario, go back to the main line and ask the next question, "if it's not that, is it this then?"
It can also help if you break long complex expressions into little bits. If each of the little bits work, but the whole doesn't, it just means you put it together wrong. Use temporary stoppers if you need them to make the snippets work:

if(isequal([Track#],99,5),[Track#],if(isequal([CUETrack],source,8),source,no source))

kind of thing.
Finally, how are you putting the expression to use? as a custom library field?

-marko.





hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Re: Editing Expressions - 2 utilities
« Reply #8 on: November 08, 2006, 08:11:35 am »

[disc#] & [track#]....

if they're not custom fields or typos, they should be [disc #] & [track #]....
..and that was the problem, must have been too tired to see it.

I indented it on several lines to make sure i got the parentheses right, then used a tool in my editor (Ultraedit) to collapse into one line, it must have removed the spaces between Disc/Track & # and MC got confused.

This got me thinking how best to nest several if(_,_,_) expressions and be sure i did not leave out any commas or closing brackets. After playing around a bit came up with this



Note how the commas are aligned with the closing brackets, this way, the hard-to-find missing commas or brackets are avoided. (Thanks EpF).

Convention i used is
- stick to the same line and tab forward if a then or else is just one statement
- indent on next line if more tests are required.

Code: [Select]
if(isequal([Track #],99,5)
, [Track #]
,
if(isempty([Disc #],1)
,
if(isempty([CUE Track],0)
, [Track #]
,
if(isequal([CUE Track],y,1)
,
if(isequal([Track #],10,3)
, 10[Track #]
, 1[Track #]
)
,
if(isequal([CUE Track],source,8)
, 100
, [Track #]
)
)
)
,
if(isequal([CUE Track],source,8)
, [Disc #]00
,
if(isequal([Track #],10,3)
, [Disc #]0[Track #]
, [Disc #][Track #]
)
)
)
)

I have different [Track #] conventions depending on whether an album is seperate tracks or CUE, then if its single or multi-cd compilation.

If [Track #] is greater than 99 then use as is, to ignore albums where i had done this manually earlier.

If its a single CD album, then presumably [Disc #] is not defined, then use [Track #] as is, however if its a cue album , then [Track #] is set to 100 for the big source track and the cue tracks are set to 101, 102, ..etc. This way the big file is always at the top when displayed via Locate or inside MC.

If its a multi-CD album, check if the [Track #] is less than 10 then append [Disc #]0[Track #], do the same for multi-cd cue tracks as well. If its the big file then [Disc #]00

The expression is saved as a custom field [Track # (expr)] and replaces the [Track #] column in PN.  So when i add new stuff to PN, Tracks get displayed automatically as defined in the expression. It's dependent on [Disc #] being filled to work properly but that's easy to do.

I don't want to use expressions in columns anywhere else as it slows down display times. So i have a smartlist that finds files whose [Track #] is different to that obtained from [Track # (expr)], then i Move/Copy from [Track # (expr)] --> [Track #] for those files. Just have to run the smartlist every now & then to be uptodate. This way all processing is done ocassionaly and the displays are quick.

Some thoughts on the expression editor. It would be nice if it knew all the fields defined in the library that way it could flag a field typo in red. Also if it could detect whether a comma or closing bracket was missing by highlighting the appropriate command.
Logged
Pages: [1]   Go Up