INTERACT FORUM

Please login or register.

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

Author Topic: Numbers formatted as Roman Numerals?  (Read 3141 times)

6233638

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 5353
Numbers formatted as Roman Numerals?
« on: March 24, 2013, 12:29:01 pm »

Is there any way to have a custom field formatted as Roman Numerals rather than regular numbers?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Numbers formatted as Roman Numerals?
« Reply #1 on: March 24, 2013, 12:40:32 pm »

Sure.  What is the largest value?  Dates?  Or will the range of numbers be arbitrary?
Logged
The opinions I express represent my own folly.

6233638

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 5353
Re: Numbers formatted as Roman Numerals?
« Reply #2 on: March 24, 2013, 01:06:32 pm »

In all likelihood, it's going to be contained to 1-10. I'm not looking to convert dates or anything like that.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Numbers formatted as Roman Numerals?
« Reply #3 on: March 24, 2013, 01:21:37 pm »

Great, here's an easy way then.  I think you'll see the pattern.  I've used [track #] to supply the number.

   listitem(0;I;II;III;IV;V;VI;VII;VIII;IX;X, [track #], ;)
Logged
The opinions I express represent my own folly.

6233638

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 5353
Re: Numbers formatted as Roman Numerals?
« Reply #4 on: March 24, 2013, 02:22:02 pm »

Well that was easier than I expected, thanks. I have been spending some time this weekend working on implementing custom tags (specifically for classical music) and trying to learn how the expressions work, but that had stumped me. (I was looking for some way to manually change the format to roman numerals, rather than simply replace the values)

I have a question about that though: if I go over 10 in your example, the field is displayed as being empty. Is there a way to have it displayed normally if it goes outside that range? (e.g. XIII, IX, X, 11, 12)

What I'm thinking is that in addition to that expression, which I am using to convert [Movement] (a custom tag) to Roman Numerals, I could use one to add a space before 1-9 in the [Track #] field, to be displayed as:
Code: [Select]
8
 9
10
11

Rather than
Code: [Select]
8
9
10
11
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Numbers formatted as Roman Numerals?
« Reply #5 on: March 24, 2013, 06:21:55 pm »

You can add more values after the X to increase the roman numerals supported.  Just follow the pattern of roman followed by a semicolon (the last one doesn't matter).

The following compares track # against 10 - when great, digits are output.  When under, roman numerals.

   if(compare([track #], >, 10), [track #], listitem(0;I;II;III;IV;V;VI;VII;VIII;IX;X, [track #], ;))

You can pseudo-right align by padding.  Below adds up to 4 spaces (actually, En-Quad (Unicode U+2000) characters), depending upon length.  Add more characters to increase the pad.

   mid(/ / / / , length([track #]), -1)[track #]

If you have an expensive calculated fied, you can save it to a temporary variable, and use that variable:

    save([track #],tmp)mid(/ / / / , length([tmp]), -1)[tmp]

Padding breaks down with variable-width fonts (X is much wider than even two I characters).
Logged
The opinions I express represent my own folly.

6233638

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 5353
Re: Numbers formatted as Roman Numerals?
« Reply #6 on: March 25, 2013, 08:01:20 am »

Perfect, thanks again for your help. I'm actually using the Unicode characters for Roman Numerals, so spacing is not a concern with them. (they go up to XII, which is why I then wanted to display regular numbers after that)

What I think I've settled on (so far) with my tagging/display for classical music is:

[Composer], [Composition], [Opus #] - [Movement]. [Name]

Which results in: Ludwig van Beethoven, Symphony № 1 in C major, Op.21 - Ⅰ. Adagio molto - Allegro con brio for example.

I have been trying to implement this "dynamically" though, so that when normal tracks are playing, the information is displayed as:

[Track #] - [Name] ([Album Artist (Auto)] - [Album])



I don't currently have an [Opus #] tag (for now, that's listed at the end of [Composition] ) because I want to figure out how to get it formatted correctly first. Typically it would be "Op.##" but there are exceptions to that rule based on the composer. (e.g. Mozart should be "KV ###") But I think I have an idea of how to do that using Delimit() and then figuring out the prefix based on the composer.


So far, what I have though is:
Code: [Select]
if(isempty([Composition]),Delimit(mid(/ / , length([track #]), -1)[track #],/ -/ ,),Delimit([Composer],/,/ ,)Delimit([Composition],/ -/ ,)Delimit(if(compare([Movement], >, 12), [Movement],listitem(/;Ⅰ;Ⅱ;Ⅲ;Ⅳ;Ⅴ;Ⅵ;Ⅶ;Ⅷ;Ⅸ;Ⅹ;Ⅺ;Ⅻ, [Movement], ;) ),./ ,))[Name]if(isempty([Composition]),Delimit([Artist],/ -,/ /() Delimit([Album],/),),)
Aside from not having [Opus #] in there yet, this seems to be doing what I want. But as I'm fairly new to all this, am I going about it the wrong way, or do I really need an expression that long?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Numbers formatted as Roman Numerals?
« Reply #7 on: March 25, 2013, 06:48:30 pm »

Clever way to create a dynamic pop vs. classical title.

Here's a little cleanup, formatted for readability (which you can enter into the Expression Editor):

if(isempty([Composition]),
   mid(/ / , length([track #]), -1)[track #] - [Name] /([Artist] - [Album]/),
   Delimit([Composer], /,/ )/
   Delimit([Composition], / -/ )/
   Delimit(
         if(compare([Movement], >, 12),
             [Movement],
             listitem(/;Ⅰ;Ⅱ;Ⅲ;Ⅳ;Ⅴ;Ⅵ;Ⅶ;Ⅷ;Ⅸ;Ⅹ;Ⅺ;Ⅻ, [Movement], ;)
          ),
      ./ )
)

There's no need to use Delimit() unless you're trying to omit the output when the first parameter is empty.  Instead, just combine fields and strings as I've done in the second line.

If you need to join a bunch of data with a common separator, omitting empty values, use ListBuild().  That might come in handy when you're building your [Composer], [Composition], [Opus #]    since they are all separated by comma: eg. ListBuild(1, /,, [Composer], [Composition], [Opus #]).

It would be great if you can include a screenshot showing the output of various titles so others can quickly see how your formatting works.
Logged
The opinions I express represent my own folly.

6233638

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 5353
Re: Numbers formatted as Roman Numerals?
« Reply #8 on: April 28, 2013, 02:28:21 pm »

[ Tangent alert - we can follow-up in your referenced thread if you want ]

What's missing / not working?
The Roman numerals are working fine, but I'm still trying to figure out things like how to handle Opus Number correctly.

Right now what's being used (I think this is the latest version of the expression) is a hacky way that only covers Mozart where the Opus numbers are formatted as K.###.
Code: [Select]
if(isempty([Composition]),Delimit(mid(/ / , length([track #]), -1)[track #],/ ‒/ ,),Delimit([Composer],/,/ ,)Delimit([Composition],,)Delimit(if(isequal([Composer],Wolfgang Amadeus Mozart,1),Delimit([Opus #],,K),Delimit([Opus #],,Op./ )),,/,/ )Delimit(if(compare([Movement], >, 12),[Movement],listitem(/;Ⅰ;Ⅱ;Ⅲ;Ⅳ;Ⅴ;Ⅵ;Ⅶ;Ⅷ;Ⅸ;Ⅹ;Ⅺ;Ⅻ, [Movement], ;) ),.,/ ‒/ ))/ [Name]if(isempty([Composition]),Delimit([Artist],/ ‒,/ /() Delimit([Album],/),),)But that was probably written about a month ago before I had done much reading into the expression language, and I haven't given it any thought since - there are too many toys to play with in Media Center and I keep jumping between other projects (skinning can't be that hard… :-\) all while still trying to actually use it for watching/listening to content. It's something that I intend to get working at some point, but is not really a priority for now.

That expression works even though it's not optimal, but only because I have imported and tagged a small selection of my library rather than everything, and only have a small number of classical music fully tagged right now.
As you can see from the Wikipedia page, different composers have different catalogues, and there's even an extended list here: http://en.wikipedia.org/wiki/Catalogues_of_classical_compositions#List_of_catalogues

But I don't need everything - I don't have that extensive a library of classical music. (yet) However I will need something better than isequal([Composer],Wolfgang Amadeus Mozart,1) to handle that.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Numbers formatted as Roman Numerals?
« Reply #9 on: April 28, 2013, 06:25:36 pm »

For your Opus Numbers, you can invert a Regex() to act as a table lookup.  Define a user field such as [Opus Lookups]:

   [Opus Lookups]: Mozart=K[Opus #]|Bach=BVM [Opus #]|Chopin=KK [Opus #]|Debussy=L [Opus #]

and now do the lookup and output:

   regex([Opus Lookups], [Composer]=/([^|]+/), 1)

Extend as desired.  See attached.  Note: I don't have an [Opus #] field, but you can see that its value would be output when it exists.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up