INTERACT FORUM

Please login or register.

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

Author Topic: Generating the opus number  (Read 1259 times)

Vincent Kars

  • Citizen of the Universe
  • *****
  • Posts: 1154
Generating the opus number
« on: January 05, 2011, 03:15:05 pm »

In case of classical music, all my 'albums' are compositions.
It would be nice to have a list of all works by opus number.

Expressions can be used to parse the album title and extract the opus number.
Most albums have a title like:

Bach: Cello Sonata No. 2 in D-dur, BWV 1028

You can use a MID function to retrieve a part of a string
MID([Album],start,length) would do the job.

How to find the starting position of BWV?
Normally you have 'find' function returning the position e.g. Find([Album],'BWV') but this is not available in MC.
Now way to combine the MID with a lookup function.

ListItem
This function makes a list of a string given a delimiting character.
Each item of this list has an index starting at 0
           
ListItem([Album],0,BWV)=Bach: Cello Sonata No. 2 in D-dur,
ListItem([Album],1,BWV)=1028

Obvious the delimiter is not part of the list.

I want to have the BWV in front
BWV ListItem([Album],1,BWV)=BWV 1028

However when the BWV is not available the column is filled with BWV only.
A test is needed.

If(
IsEmpty(ListItem([Album],1,BWV)),
,
BWV ListItem([Album],1,BWV)
)

If list item[1] is empty, BWV is not in the album so do nothing, otherwise get the BWV.

As you might have guessed BWV (Bach-Werke-Verzeichnis) applies to the works of JS Bach only.
We can simply repeat the expression above for other composers

Beethoven: Piano Sonata No. 26 in E flat major ('Les Adieux') Op. 81a
Schumann: Waldszenen op. 82


If(
IsEmpty(ListItem([Album],1,op.)),
,
Op. ListItem([Album],1,op.)
)

This works for all works with op. in it, Op. doesn't work. Obvious the use of the delimiter is case sensitive. To avoid repeating everything for each variation is case, a conversion to lower case is needed.

If(
IsEmpty(ListItem(FixCase([Album],4),1,op.)),
,
Op. ListItem(FixCase([Album],4),1,op.)
)

FixCase converts to lower (4) and must be done two times.

Up to now, the opus numbers are at the end of the work.
What to do if this is not the case.

Brahms: Sonata for Violin & Piano no. 2 in A major Op. 100 (Thun)
Brahms: Intermezzo Op.117 – Lupu


The trick is to make a list of a list

If(
IsEmpty(ListItem(FixCase([Album],4),1,op.)),
,
Op. ListItem(ListItem(FixCase([Album],4),1,op.),0,-)
)

ListItem(FixCase([Album],4),1,op.)) gives us everything after op.
Wrap a second ListItem around using – as a delimiter.
This gives us all characters up to the – so this time we need the first ListItem.

To avoid repeating this for every possible delimiter, use the replace function.

If(
IsEmpty(ListItem(FixCase([Album],4),1,op.)),
,
Op. ListItem(ListItem(Replace(Replace(FixCase([Album],4),/(,;),-,;),1,op.),0)
)

Before building the second list, replace ( and – by ;
; is the default delimiter used in building lists.

I do have BWV, KV, D, WoO and Op.
For you barbarians out there Bach-Werke-Verzeichnis, Köchel-Verzeichnis, Deutsch, Werke ohne Opus Nummer and opus.
Simple combine them.

Schubert: Sonatina for violin & piano in A minor D. 385 (Op. posth. 137/2)

As we have both D. and Op. start with Schubert to extract the D.

If(IsEmpty(ListItem(FixCase([Album],4),1,d.)),
 If(IsEmpty(ListItem(FixCase([Album],4),1,bwv)),
  If(IsEmpty(ListItem(FixCase([Album],4),1,op.)),
   If(IsEmpty(ListItem(FixCase([Album],4),1,woo)),
    If(IsEmpty(ListItem(FixCase([Album],4),1,kv)),
     ,
     KV ListItem(FixCase([Album],4),1,kv)
     ),
     WoO ListItem(FixCase([Album],4),1,woo)
     ),
    Op. ListItem(ListItem(Replace(Replace(FixCase([Album],4),/(,;),-,;),1,op.),0)
    ),
  BWV ListItem(FixCase([Album],4),1,bwv)
  ),
D. ListItem(ListItem(Replace(Replace(FixCase([Album],4),/(,;),/,,;),1,d.),0)

)

Sigh...

 
A bit more detail can be found here: http://thewelltemperedcomputer.com/SW/Players/MC14/MC_Expression.htm
Logged
Pages: [1]   Go Up