1 /***************************************************************************************
2 Analyze - Sample 1
3 Copyright (C) 2000-2001 by Matthew T. Ashland   All Rights Reserved.
4 Feel free to use this code in any way that you like.
5 
6 This example opens an APE file and displays some basic information about it. To use it,
7 just type Sample 1.exe followed by a file name and it'll display information about that
8 file.
9 
10 Notes for use in a new project:
11 	-you need to include "MACLib.lib" in the included libraries list
12 	-life will be easier if you set the [MAC SDK]\\Shared directory as an include
13 	directory and an additional library input path in the project settings
14 	-set the runtime library to "Mutlithreaded"
15 
16 WARNING:
17 	-This class driven system for using Monkey's Audio is still in development, so
18 	I can't make any guarantees that the classes and libraries won't change before
19 	everything gets finalized.  Use them at your own risk.
20 ***************************************************************************************/
21 
22 // includes
23 #include <stdio.h>
24 
25 #include "All.h"
26 #include "GlobalFunctions.h"
27 #include "MACLib.h"
28 #include "CharacterHelper.h"
29 #include "APETag.h"
30 
main(int argc,char * argv[])31 int main(int argc, char* argv[])
32 {
33 	///////////////////////////////////////////////////////////////////////////////
34 	// error check the command line parameters
35 	///////////////////////////////////////////////////////////////////////////////
36 	if (argc != 2)
37 	{
38 		printf("~~~Improper Usage~~~\r\n\r\n");
39 		printf("Usage Example: Sample 1.exe 'c:\\1.ape'\r\n\r\n");
40 		return 0;
41 	}
42 
43 	///////////////////////////////////////////////////////////////////////////////
44 	// variable declares
45 	///////////////////////////////////////////////////////////////////////////////
46 	int					nRetVal = 0;										// generic holder for return values
47 	char				cTempBuffer[256]; ZeroMemory(&cTempBuffer[0], 256);	// generic buffer for string stuff
48 	char *				pFilename = argv[1];								// the file to open
49 	IAPEDecompress *	pAPEDecompress = NULL;								// APE interface
50 	CSmartPtr<wchar_t> spInput;
51 
52 	spInput.Assign(GetUTF16FromANSI(argv[1]), TRUE);
53 
54 //*
55 	///////////////////////////////////////////////////////////////////////////////
56 	// open the file and error check
57 	///////////////////////////////////////////////////////////////////////////////
58 	pAPEDecompress = CreateIAPEDecompress(spInput, &nRetVal);
59 	if (pAPEDecompress == NULL)
60 	{
61 		printf("Error opening APE file. (error code %d)\r\n\r\n", nRetVal);
62 		return 0;
63 	}
64 
65 
66 	///////////////////////////////////////////////////////////////////////////////
67 	// display some information about the file
68 	///////////////////////////////////////////////////////////////////////////////
69 	printf("Displaying information about '%s':\r\n\r\n", pFilename);
70 
71 	// file format information
72 	printf("File Format:\r\n");
73 	printf("\tVersion: %.2f\r\n", float(pAPEDecompress->GetInfo(APE_INFO_FILE_VERSION)) / float(1000));
74 	switch (pAPEDecompress->GetInfo(APE_INFO_COMPRESSION_LEVEL))
75 	{
76 		case COMPRESSION_LEVEL_FAST: printf("\tCompression level: Fast\r\n\r\n"); break;
77 		case COMPRESSION_LEVEL_NORMAL: printf("\tCompression level: Normal\r\n\r\n"); break;
78 		case COMPRESSION_LEVEL_HIGH: printf("\tCompression level: High\r\n\r\n"); break;
79 		case COMPRESSION_LEVEL_EXTRA_HIGH: printf("\tCompression level: Extra High\r\n\r\n"); break;
80 	}
81 
82 	// audio format information
83 	printf("Audio Format:\r\n");
84 	printf("\tSamples per second: %d\r\n", pAPEDecompress->GetInfo(APE_INFO_SAMPLE_RATE));
85 	printf("\tBits per sample: %d\r\n", pAPEDecompress->GetInfo(APE_INFO_BITS_PER_SAMPLE));
86 	printf("\tNumber of channels: %d\r\n", pAPEDecompress->GetInfo(APE_INFO_CHANNELS));
87 	printf("\tPeak level: %d\r\n\r\n", pAPEDecompress->GetInfo(APE_INFO_PEAK_LEVEL));
88 
89 	// size and duration information
90 	printf("Size and Duration:\r\n");
91 	printf("\tLength of file (s): %d\r\n", pAPEDecompress->GetInfo(APE_INFO_LENGTH_MS) / 1000);
92 	printf("\tFile Size (kb): %d\r\n\r\n", pAPEDecompress->GetInfo(APE_INFO_APE_TOTAL_BYTES) / 1024);
93 
94 	// tag information
95 	printf("Tag Information:\r\n");
96 
97 	CAPETag * pAPETag = (CAPETag *) pAPEDecompress->GetInfo(APE_INFO_TAG);
98 	BOOL bHasID3Tag = pAPETag->GetHasID3Tag();
99 	BOOL bHasAPETag = pAPETag->GetHasAPETag();
100 
101 
102 	if (bHasID3Tag || bHasAPETag)
103 	{
104 	    printf("\tID3 Tag: %s, APE Tag: %s", bHasID3Tag ? "Yes" : "No", bHasAPETag ? "" : "No");
105 	    if (bHasAPETag)
106 	    {
107 		printf("%d", pAPETag->GetAPETagVersion() / 1000);
108 	    }
109 	    printf("\n\n");
110 		// iterate through all the tag fields
111 		BOOL bFirst = TRUE;
112 		CAPETagField * pTagField;
113 //		while (pAPETag->GetNextTagField(bFirst, &pTagField))
114 		int index = 0;
115 		while ((pTagField = pAPETag->GetTagField(index)) != NULL)
116 		{
117 			bFirst = FALSE;
118 			index ++;
119 
120 			// output the tag field properties (don't output huge fields like images, etc.)
121 			if (pTagField->GetFieldValueSize() > 128)
122 			{
123 				printf("\t%s: --- too much data to display ---\r\n", GetANSIFromUTF16(pTagField->GetFieldName()));
124 			}
125 			else
126 			{
127 /*
128 			    const wchar_t *fieldName;
129 			    char *name;
130 			    wchar_t fieldValue[255];
131 			    char *value;
132 
133 			    fieldName = pTagField->GetFieldName();
134 			    name = GetANSIFromUTF16(fieldName);
135 
136 			    memset(fieldValue, 0, 255 * sizeof(wchar_t));
137 			    int len;
138 			    pAPETag->GetFieldString(fieldName, fieldValue, &len);
139 
140 			    value = GetANSIFromUTF16(fieldValue);
141 */
142 			    const wchar_t *fieldName;
143 			    char *name;
144 			    const char *fieldValue;
145 			    char *value;
146 
147 			    fieldName = pTagField->GetFieldName();
148 			    name = GetANSIFromUTF16(fieldName);
149 
150 			    fieldValue = pTagField->GetFieldValue();
151 			    if (pAPETag->GetAPETagVersion() == CURRENT_APE_TAG_VERSION)
152 			    {
153 				value = GetANSIFromUTF8((unsigned char *)fieldValue);
154 			    }
155 			    else
156 			    {
157 				value = (char *)fieldValue;
158 			    }
159 			    printf("\t%s : %s\n", name, value);
160 			}
161 		}
162 	}
163 	else
164 	{
165 		printf("\tNot tagged\r\n\r\n");
166 	}
167 
168 	///////////////////////////////////////////////////////////////////////////////
169 	// cleanup (just delete the object
170 	///////////////////////////////////////////////////////////////////////////////
171 	delete pAPEDecompress;
172 
173 	///////////////////////////////////////////////////////////////////////////////
174 	// quit
175 	///////////////////////////////////////////////////////////////////////////////
176 	return 0;
177 }
178