
#import "CD_DBase.h"
#import "CD_DBaseSubs.h"

@implementation CD_DBase

    /* I intend to hook up some real database to this, once I
     * figure out how I want that to work.  So far I just tack on
     * info for CD's as I play them, mainly for checking purposes.
     */

#define MOLDFIELD_OMMADAWN     793550963 /* key parts = 2204.23.03.1163 204 */
#define RWAKE_JOURNEY_UDII     865512364 /* key parts = 2404.15.02.1264 1138 */
#define MOLDFIELD_HERGESTRIDGE 871248390 /* key parts = 2420.10.02.1290 1128 */
#define TDREAM_TANGRAM_DE      871762042 /* key parts = 2421.42.02.1192 1227 */
#define VAPO_GRAVITATIONAL     887822707 /* key parts = 2466.13.02.2107 357 */
#define PINKF_WYWH_USA1        955800362 /* key parts = 2655.00.02.1262 1391 */
#define MOLDFIELD_EXPOSED_D2   990720501 /* key parts = 2752.00.03.1701 384 */
#define TDREAM_PERGAMON_REL    996936347 /* key parts = 2769.20.02.1397 1370 */
#define TDREAM_PERGAMON_SEQ    996960350 /* key parts = 2769.25.02.1400 1367 */
#define TDREAM_PERGAMON_CAR    999720353 /* key parts = 2777.00.02.1403 1373 */
#define MOLDFIELD_EXPOSED_D1  1022649986 /* key parts = 2840.52.02.1586 1252 */
#define MOLDFIELD_TUBULARBELL 1057488333 /* key parts = 2937.35.02.1533 1402 */
#define TDREAM_LOGOS_DE       1099113906 /* key parts = 3053.07.02.2706 345 */
#define MOLDFIELD_ORCHTUBELLS 1103640392 /* key parts = 3065.50.02.1592 1471 */
#define TDREAM_LOGOS          1105930093 /* key parts = 3072.02.03.1543 349 */
#define RENAIS_CARNEGIE_D2    1131120410 /* key parts = 3142.00.02.1760 1380 */
#define SOFTW_SYNCODE         1204920476 /* key parts = 3347.00.03.1376 567 */
#define TDREAM_LIVEMILES_SEQ  1233264444 /* key parts = 3425.55.02.1794 1629 */
#define QUEEN_TALKS           1280030839 /* key parts = 3555.48.02.3289 264 */
#define MOLDFIELD_AMAROK      1297665752 /* key parts = 3604.47.01.3602 3602 */
#define RADIOMI_FROZENN_D2    1486651562 /* key parts = 4129.44.02.1712 2415 */
#define KSCH_DRESDEN_D2       1487136410 /* key parts = 4130.70.02.2810 1318 */
#define ELP_ELPKB_D2          1580098028 /* key parts = 4389.12.02.2228 2159 */
#define KSCH_DRESDEN_D1       1585550965 /* key parts = 4404.23.03.2665 1111 */
#define KSCH_DOMEEVENT        1604880362 /* key parts = 4458.00.02.3812 644 */


- fillTocTitles:(struct cd_toc *)tocPtr givenKey:(u_int)cdKey
{
    /* split the records up into subroutines based on the number of
     * songs on the album.  This routine was getting a bit too big...
     */
    if ( tocPtr->lastCDtrack >= 4 ) {
	switch ( tocPtr->lastCDtrack ) {
	case 4:
	    filltoc04(tocPtr, cdKey);
	    break;
	case 5:
	    filltoc05(tocPtr, cdKey);
	    break;
	case 6:
	    filltoc06(tocPtr, cdKey);
	    break;
	case 7:
	    filltoc07(tocPtr, cdKey);
	    break;
	case 8:
	    if ( cdKey > CDKEY_45min )      filltoc08_45(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_40min ) filltoc08_40(tocPtr, cdKey);
	    else                            filltoc08_00(tocPtr, cdKey);
	    break;
	case 9:
	    if ( cdKey > CDKEY_55min )      filltoc09_55(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_45min ) filltoc09_45(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_40min ) filltoc09_40(tocPtr, cdKey);
	    else                            filltoc09_00(tocPtr, cdKey);
	    break;
	case 10:
	    /* There are a lot of CD's with 10 tracks... */
	    if ( cdKey > CDKEY_50min )      filltoc10_50(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_45min ) filltoc10_45(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_43min ) filltoc10_43(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_40min ) filltoc10_40(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_38min ) filltoc10_38(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_35min ) filltoc10_35(tocPtr, cdKey);
	    else                            filltoc10_00(tocPtr, cdKey);
	    break;
	case 11:
	    if ( cdKey > CDKEY_60min )      filltoc11_60(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_50min ) filltoc11_50(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_45min ) filltoc11_45(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_40min ) filltoc11_40(tocPtr, cdKey);
	    else                            filltoc11_00(tocPtr, cdKey);
	    break;
	case 12:
	    if ( cdKey > CDKEY_60min )      filltoc12_60(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_50min ) filltoc12_50(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_45min ) filltoc12_45(tocPtr, cdKey);
	    else                            filltoc12_00(tocPtr, cdKey);
	    break;
	case 13:
	    if ( cdKey > CDKEY_60min )      filltoc13_60(tocPtr, cdKey);
	    else if ( cdKey > CDKEY_50min ) filltoc13_50(tocPtr, cdKey);
	    else                            filltoc13_00(tocPtr, cdKey);
	    break;
	case 14:
	    if ( cdKey > CDKEY_60min )      filltoc14_60(tocPtr, cdKey);
	    else                            filltoc14_00(tocPtr, cdKey);
	    break;
	case 15:
	    filltoc15(tocPtr, cdKey);
	    break;
	case 16:
	    filltoc16(tocPtr, cdKey);
	    break;
	case 17:
	    filltoc17(tocPtr, cdKey);
	    break;
	case 18:
	    filltoc18(tocPtr, cdKey);
	    break;
	case 19:
	    filltoc19(tocPtr, cdKey);
	    break;
	case 20:
	    filltoc20(tocPtr, cdKey);
	    break;
	case 21:
	    filltoc21(tocPtr, cdKey);
	    break;
	case 22: case 23: case 24: case 25:
	    filltoc22(tocPtr, cdKey);
	    break;
	default: /* 26 or more tracks... */
	    if (tocPtr->lastCDtrack < 50)
		  filltoc26(tocPtr, cdKey);
	    else  filltoc50(tocPtr, cdKey);
	    break;
	} /* end switch ( tocPtr->lastCDtrack ) */
	return self;
    } /* end if ( tocPtr->lastCDtrack >= 4 ) */

    /* CD's with less than 4 tracks are checked here... */
    
    if ( cdKey == ELP_ELPKB_D2 ) { /* 1:13:09-12 */
	tocPtr->discPerformer = "Emerson, Lake & Palmer";
	tocPtr->discTitle = "ELP on King Biscuit  [disc 2]";
	SET_CDtt( 1, 37.08, "Karn Evil 9");
	SET_CDtt( 2, 35.59, "[Mac/PC interactive track]");
	}
    if ( cdKey == MOLDFIELD_TUBULARBELL ) { /* 0:48:57-35 */
	tocPtr->discPerformer = "Mike Oldfield";
	tocPtr->discTitle = "Tubular Bells";
#     if !defined(SKIPSONGS_Mike_Oldfield)
	SET_CDtt( 1, 25.33, "Tubular Bells: Part One");
	SET_CDtt( 2, 23.22, "Tubular Bells: Part Two");
#     endif
	}
    if ( cdKey == MOLDFIELD_HERGESTRIDGE ) { /* 0:40:20-10 */
	tocPtr->discPerformer = "Mike Oldfield";
	tocPtr->discTitle = "Hergest Ridge";
#     if !defined(SKIPSONGS_Mike_Oldfield)
	SET_CDtt( 1, 21.30, "Hergest Ridge: Part One");
	SET_CDtt( 2, 18.48, "Hergest Ridge: Part Two");
#     endif
	}
    if ( cdKey == MOLDFIELD_ORCHTUBELLS ) { /* 0:51:05-50 */
	tocPtr->discPerformer = "Mike Oldfield";
	tocPtr->discTitle = "The Orchestral Tubular Bells";
#     if !defined(SKIPSONGS_Mike_Oldfield)
	SET_CDtt( 1, 26.32, "The Orchestral Tubular Bells: Part 1");
	SET_CDtt( 2, 24.31, "The Orchestral Tubular Bells: Part 2");
#     endif
	}
    if ( cdKey == MOLDFIELD_OMMADAWN ) { /* 0:36:44-23 */
	tocPtr->discPerformer = "Mike Oldfield";
	tocPtr->discTitle = "Ommadawn";
#     if !defined(SKIPSONGS_Mike_Oldfield)
	SET_CDtt( 1, 19.23, "Ommadawn: Part One");
	SET_CDtt( 2, 13.55, "Ommadawn: Part Two");
	SET_CDtt( 3, 03.24, "The Horse Song");
#     endif
	}
    if ( cdKey == MOLDFIELD_EXPOSED_D1 ) { /* 0:47:20-52 */
	tocPtr->discPerformer = "Mike Oldfield";
	tocPtr->discTitle = "Exposed  [disc 1]";
#     if !defined(SKIPSONGS_Mike_Oldfield)
	SET_CDtt( 1, 26.26, "Incantations (Parts 1 & 2)");
	SET_CDtt( 2, 20.52, "Incantations (Parts 3 & 4)");
#     endif
	}
    if ( cdKey == MOLDFIELD_EXPOSED_D2 ) { /* 0:45:52-00 */
	tocPtr->discPerformer = "Mike Oldfield";
	tocPtr->discTitle = "Exposed  [disc 2]";
#     if !defined(SKIPSONGS_Mike_Oldfield)
	SET_CDtt( 1, 28.21, "Tubular Bells (Part 1)");
	SET_CDtt( 2, 11.05, "Tubular Bells (Part 2)");
	SET_CDtt( 3, 06.24, "Guilty");
#     endif
	}
    if ( cdKey == MOLDFIELD_AMAROK ) { /* 1:00:04-47 */
	tocPtr->discPerformer = "Mike Oldfield";
	tocPtr->discTitle = "Amarok";
#     if !defined(SKIPSONGS_Mike_Oldfield)
	SET_CDtt( 1, 60.02, "Amarok");
#     endif
	}
    if ( cdKey == PINKF_WYWH_USA1 ) { /* 0:44:15-00 */
	tocPtr->discPerformer = "Pink Floyd";
	tocPtr->discTitle = "Wish You Were Here  [First USA release]";
	/*
	 *	index 1.1 started 0:00:02-04 into CD
	 *	index 1.2 started 0:13:31-12 into CD, 0:13:29 into the song
	 *	index 2.0 started 0:21:02-49 into CD,  -00:02 into the song
	 *	index 2.1 started 0:21:05-11 into CD
	 *	index 2.2 started 0:26:11-48 into CD, 0:05:06 into the song
	 *	index 2.3 started 0:31:48-28 into CD, 0:10:43 into the song
	 */
#     if !defined(SKIPSONGS_Pink_Floyd)
	SET_CDtt( 1, 21.02, "Wish You Were Here; Side 1");	/* index=2 */
	SET_CDtt( 2, 23.11, "Wish You Were Here; Side 2");	/* index=3 */
#     endif
	}
    if ( cdKey == QUEEN_TALKS ) { /* 0:59:15-48 */
	tocPtr->discPerformer = "Queen";
	tocPtr->discTitle = "The Queen Collection: Queen Talks";
#     if !defined(SKIPSONGS_Queen)
	SET_CDtt( 1, 54.49, "BBC Radio One Interview with Mike Read");
	SET_CDtt( 2, 04.24, "Thank God It's Christmas");
#     endif
	}
    if ( cdKey == RADIOMI_FROZENN_D2 ) { /* 1:08:49-44 */
	tocPtr->discPerformer = "Radio Massacre International";
	tocPtr->discTitle = "Frozen North  [disc 2]";
	SET_CDtt( 1, 28.32, "Frozen North: I");
	SET_CDtt( 2, 40.15, "Frozen North: IV");
	}
    if ( cdKey == RENAIS_CARNEGIE_D2 ) { /* 0:52:22-00 */
	tocPtr->discPerformer = "Renaissance";
	tocPtr->discTitle = "Live at Carnegie Hall  [disc 2]";
#     if !defined(SKIPSONGS_Renaissance)
	SET_CDtt( 1, 29.20, "Scheherazade");
	SET_CDtt( 2, 23.00, "Ashes are Burning");
#     endif
	}
    if ( cdKey == KSCH_DOMEEVENT ) { /* 1:14:18-00 */
	tocPtr->discPerformer = "Klaus Schulze";
	tocPtr->discTitle = "The Dome Event";
#     if !defined(SKIPSONGS_Klaus_Schulze)
	SET_CDtt( 1, 63.32, "The Dome Event");
	SET_CDtt( 2, 10.44, "After Eleven");
#     endif
	}
    if ( cdKey == KSCH_DRESDEN_D1 ) { /* 1:13:24-23 */
	tocPtr->discPerformer = "Klaus Schulze";
	tocPtr->discTitle = "The Dresden Performance  [disc 1]";
#     if !defined(SKIPSONGS_Klaus_Schulze)
	SET_CDtt( 1, 44.25, "Dresden One");
	SET_CDtt( 2, 10.26, "Dresden Three");
	SET_CDtt( 3, 18.31, "Dresden Five");
#     endif
	}
    if ( cdKey == KSCH_DRESDEN_D2 ) { /* 1:08:50-70 */
	tocPtr->discPerformer = "Klaus Schulze";
	tocPtr->discTitle = "The Dresden Performance  [disc 2]";
#     if !defined(SKIPSONGS_Klaus_Schulze)
	SET_CDtt( 1, 46.50, "Dresden Two");
	SET_CDtt( 2, 21.58, "Dresden Four");
#     endif
	}
    if ( cdKey == SOFTW_SYNCODE ) { /* 0:55:47-00 */
	tocPtr->discPerformer = "Software";
	tocPtr->discTitle = "Syn-Code";
	/*
	 *	index 1.1 started 0:00:02-04 into CD
	 *	index 1.2 started 0:02:04-08 into CD, 0:02:02 into the song
	 *	index 1.3 started 0:05:46-12 into CD, 0:05:44 into the song
	 *	index 1.4 started 0:12:06-17 into CD, 0:12:04 into the song
	 *	index 1.5 started 0:14:01-18 into CD, 0:13:59 into the song
	 *	index 1.6 started 0:17:00-21 into CD, 0:16:58 into the song
	 *	index 2.1 started 0:22:58-26 into CD
	 *	index 2.2 started 0:29:46-31 into CD, 0:06:48 into the song
	 *	index 2.3 started 0:35:18-36 into CD, 0:12:20 into the song
	 *	index 2.4 started 0:39:31-02 into CD, 0:16:33 into the song
	 *	index 2.5 started 0:42:16-04 into CD, 0:19:18 into the song
	 *	index 3.0 started 0:46:17-07 into CD, -00:02 before the song
	 *	index 3.1 started 0:46:20-07 into CD
	 */
#     if !defined(SKIPSONGS_Software)
	SET_CDtt( 1, 22.56, "Syn-Code-A");		/* index = 6 */
	SET_CDtt( 2, 23.22, "Syn±Code±Z");		/* index = 5 */
	SET_CDtt( 3, 09.27, "Syn±Code±Sunset");
#     endif
	}
    if ( cdKey == TDREAM_TANGRAM_DE ) { /* 0:40:21-42 */
	tocPtr->discPerformer = "Tangerine Dream";
	tocPtr->discTitle = "Tangram  [definitive edition]";
#     if !defined(SKIPSONGS_Tangerine_Dream)
	SET_CDtt( 1, 19.52, "Tangram: Set 1");
	SET_CDtt( 2, 20.27, "Tangram: Set 2");
#     endif
	}
    if ( cdKey == TDREAM_LOGOS ) { /* 0:51:12-02 */
	tocPtr->discPerformer = "Tangerine Dream";
	tocPtr->discTitle = "Logos - Live";
#     if !defined(SKIPSONGS_Tangerine_Dream)
	SET_CDtt( 1, 25.43, "Logos - Part One");
	SET_CDtt( 2, 19.38, "Logos - Part Two");
	SET_CDtt( 3, 05.49, "Dominion");
#     endif
	}
    if ( cdKey == TDREAM_LOGOS_DE ) { /* 0:50:53-07 */
	tocPtr->discPerformer = "Tangerine Dream";
	tocPtr->discTitle = "Logos - Live 1982  [definitive edition]";
#     if !defined(SKIPSONGS_Tangerine_Dream)
	SET_CDtt( 1, 45.06, "Logos");
	SET_CDtt( 2, 05.45, "Dominion");
#     endif
	}
    if ( cdKey == TDREAM_PERGAMON_CAR ) { /* 0:46:17-00 */
	tocPtr->discPerformer = "Tangerine Dream";
	tocPtr->discTitle = "Pergamon: Live at the »Palast Der Republic« GDR";
#     if !defined(SKIPSONGS_Tangerine_Dream)
	SET_CDtt( 1, 23.23, "Quichotte Part I");
	SET_CDtt( 2, 22.53, "Quichotte Part II");
#     endif
	}
    if ( cdKey == TDREAM_PERGAMON_REL ) { /* 0:46:09-20 */
	tocPtr->discPerformer = "Tangerine Dream";
	tocPtr->discTitle = "Pergamon ± Live at the »Palast Der Republic« GDR  [Relativity]";
#     if !defined(SKIPSONGS_Tangerine_Dream)
	SET_CDtt( 1, 23.17, "Quichotte Part I");
	SET_CDtt( 2, 22.50, "Quichotte Part II");
#     endif
	}
    if ( cdKey == TDREAM_PERGAMON_SEQ ) { /* 0:46:09-25 */
	tocPtr->discPerformer = "Tangerine Dream";
	tocPtr->discTitle = "Pergamon ± Live at the »Palast Der Republic« GDR  [sequel]";
#     if !defined(SKIPSONGS_Tangerine_Dream)
	SET_CDtt( 1, 23.20, "Quichotte Part I");
	SET_CDtt( 2, 22.47, "Quichotte Part II");
#     endif
	}
    if ( cdKey == TDREAM_LIVEMILES_SEQ ) { /* 0:57:05-55 */
	tocPtr->discPerformer = "Tangerine Dream";
	tocPtr->discTitle = "Live Miles  [sequel]";
#     if !defined(SKIPSONGS_Tangerine_Dream)
	SET_CDtt( 1, 29.54, "Livemiles I (Albuquerque Concert)");
	SET_CDtt( 2, 27.09, "Livemiles II (Berlin Concert)");
#     endif
	}
    if ( cdKey == VAPO_GRAVITATIONAL ) { /* 0:41:06-13 */
	tocPtr->discPerformer = "Vapourspace";
	tocPtr->discTitle = "Gravitational Arch of 10";
	SET_CDtt( 1, 35.07, "Magnetic Gravity Arc Suite");
	SET_CDtt( 2, 05.57, "Gravitational Arch of 10  [radio/video edit]");
	}
    if ( cdKey == RWAKE_JOURNEY_UDII ) { /* 0:40:04-15 */
	tocPtr->discPerformer = "Rick Wakeman";
	tocPtr->discTitle = "Journey to the Centre of the Earth  [UltraDisc II]";
	SET_CDtt( 1, 21.04, "The Journey/ Recollection");
	SET_CDtt( 2, 18.58, "The Battle/ The Forest");
	}
    return self;
}


- (u_int) indexKey:(struct cd_toc *)tocPtr
{
    /* the objective for the key is to come up with a number that is
       less than a signed integer, and yet is likely to be fairly
       unique over all music CD's (note that alternate pressings of
       the same title make it almost impossible to come up with a
       truly unique key).
       
       key is based on hours, minutes, seconds, frames, the number
       of tracks on the CD, and the elapsed time of the first track
       on the CD.  That shouldn't produce too many duplicates.
    */
    u_int	calculatedKey;

    calculatedKey = tocPtr->info[100].elapsedSec;
    calculatedKey = (calculatedKey * 75) + tocPtr->info[100].frame;
    calculatedKey = (calculatedKey * 32) + (tocPtr->lastCDtrack % 32);
    calculatedKey = (calculatedKey * 150) + (tocPtr->info[1].elapsedSec % 150);

    return calculatedKey;
}


@end
