Subversion Repositories spk

Rev

Rev 270 | Rev 289 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 270 Rev 287
Line 19... Line 19...
19
 
19
 
20
#include "sndfile.hh"
20
#include "sndfile.hh"
21
 
21
 
22
 
22
 
23
void PrintSyntax (const Utils::WString &cmd)
23
void PrintSyntax (const Utils::WString &cmd)
24
{
24
{	
-
 
25
	wprintf ( L"Syntax: %s </command> [options]\n", cmd.c_str());
-
 
26
	wprintf ( L"\nCommands:\n" );
25
	/*
27
	/*
26
	printf ( "Syntax: %s %s </command> [arguments]\n", cmd.c_str(), FLAGS );
-
 
27
	printf ( "\nCommands:\n" );
-
 
28
	printf ( "   /list\n\t- Lists installed packages\n" );
28
	printf ( "   /list\n\t- Lists installed packages\n" );
29
	printf ( "   /install <file>\n\t- Installs a package file\n" );
29
	printf ( "   /install <file>\n\t- Installs a package file\n" );
30
	printf ( "   /uninstall <package#>\n\t- Uninstalls a package, use id number from list\n" );
30
	printf ( "   /uninstall <package#>\n\t- Uninstalls a package, use id number from list\n" );
31
	printf ( "   /enable <package#>\n\t- Enables an installed package\n" );
31
	printf ( "   /enable <package#>\n\t- Enables an installed package\n" );
32
	printf ( "   /disable <package#>\n\t- Disables an installed package\n" );
32
	printf ( "   /disable <package#>\n\t- Disables an installed package\n" );
Line 37... Line 37...
37
	printf ( "   -v (--verbose)\n\tTurns on verbose mode\n\n" );
37
	printf ( "   -v (--verbose)\n\tTurns on verbose mode\n\n" );
38
	printf ( "   -o (--override)\n\tOverride install warnings\n\tIE. allows you to install older scripts\n\n" );
38
	printf ( "   -o (--override)\n\tOverride install warnings\n\tIE. allows you to install older scripts\n\n" );
39
	printf ( "   -t (--textrename)\n\tForces text file renaming for installed packages\n\n" );
39
	printf ( "   -t (--textrename)\n\tForces text file renaming for installed packages\n\n" );
40
	printf ( "   -l (--language) <language>\n\tSets the language id for text file renaming\n\totheriwse reads game lang.dat\n\n" );
40
	printf ( "   -l (--language) <language>\n\tSets the language id for text file renaming\n\totheriwse reads game lang.dat\n\n" );
41
	printf ( "   -c (--enablechild)\n\tAuto Enabled all children when parent is enabled\n\n" );
41
	printf ( "   -c (--enablechild)\n\tAuto Enabled all children when parent is enabled\n\n" );
42
	printf ( "   -m (--forcemod\n\tForces a mod enabled even if theres one already enabled\n\n" );
42
	printf ( "   -m (--forcemod\n\tForces a mod enabled even if theres one already enabled\n\n" );	
43
	*/
43
	*/
44
}
44
}
45
 
45
 
46
void Pause()
46
void Pause()
47
{
47
{
48
#ifdef _DEBUG
48
#ifdef _DEBUG
49
	char pause;
49
	char pause;
50
	scanf ( "%s", &pause );
50
	scanf ( "%s", &pause );
51
#endif
51
#endif
52
}
52
}
53
 
53
 
54
#define BUFFER_LEN 4096
54
#define BUFFER_LEN 4096
-
 
55
 
-
 
56
 
-
 
57
void DoOffset(const Utils::WString &cmd, const Utils::WStringList &options, const std::vector<Utils::WString> &args)
-
 
58
{
-
 
59
	if (args.size() < 2)
-
 
60
	{
-
 
61
		wprintf(L"Syntax: %s offset [options] <offset> <file> [--out:<file>]\n", cmd.c_str());
-
 
62
		wprintf(L"	<offset>\t\tOffset time to adjust by\n");
-
 
63
		wprintf(L"	<file>\t\tThe file to adjust\n");
-
 
64
		wprintf(L"\nOptions:\n");
-
 
65
		wprintf(L"  --out:<file>\t\tThe output filename, otherwise, will write to the input\n");
-
 
66
		wprintf(L"  --page:<id>\t\tThe page id to read (otherwise will do all of them)\n");
-
 
67
	}
-
 
68
	else
-
 
69
	{
-
 
70
		Utils::WString offsetStr = args[0];
-
 
71
		Utils::WString fileStr = args[1];
-
 
72
		Utils::WString outFileStr = options.contains(L"out") ? options[L"out"]->data : fileStr;
-
 
73
		unsigned int pageID = options.contains(L"page") ? options[L"page"]->data.toInt() : 0;
-
 
74
		long offset = offsetStr.toLong();
-
 
75
 
-
 
76
		CFileIO f;
-
 
77
		if (f.open(fileStr))
-
 
78
		{
-
 
79
			bool inPage = false;
-
 
80
			Utils::WStringList list;
-
 
81
			Utils::WStringList outList;
-
 
82
			if (f.readLines(list))
-
 
83
			{
-
 
84
				for (auto itr = list.begin(); itr != list.end(); itr++)
-
 
85
				{
-
 
86
					Utils::WString line = (*itr)->str;
-
 
87
					if (line.contains(L"<page id=\""))
-
 
88
					{
-
 
89
						long id = line.between(L"<page id=\"", L"\"").toLong();
-
 
90
						if (pageID == 0 || pageID == id)
-
 
91
							inPage = true;
-
 
92
					}
-
 
93
					else if (line.contains(L"</page>"))
-
 
94
						inPage = false;
-
 
95
					else if (inPage)
-
 
96
					{
-
 
97
						long pos = line.findPos(L"s=\"");
-
 
98
						if (pos != -1)
-
 
99
						{
-
 
100
							Utils::WString s = line.substr(pos + 3);
-
 
101
							s = s.token(L"\"", 1);
-
 
102
							long time = s.toLong();
-
 
103
							long toTime = time + offset;
-
 
104
							line = line.findReplace(time, toTime);
-
 
105
						}
-
 
106
					}
-
 
107
					outList.pushBack(line);
-
 
108
				}
-
 
109
				CFileIO outFile(outFileStr);
-
 
110
				outFile.writeFile(&outList);
-
 
111
				outFile.close();
-
 
112
			}
-
 
113
		}
-
 
114
		else
-
 
115
			wprintf(L"Error: Unable to open file, %s\n", fileStr.c_str());
-
 
116
	}
-
 
117
 
-
 
118
}
-
 
119
 
55
/*
120
/*
56
	Main entry point to program
121
	Main entry point to program
57
*/
122
*/
58
int main ( int argc, char **argv )
123
int main ( int argc, char **argv )
59
{
124
{
60
 	// display program header to command prompt
125
 	// display program header to command prompt
61
	printf ( "\nX3 Voice Create V1.00 (SPK Library Version %.2f) 15/12/2023 Created by Cycrow\n\n", GetLibraryVersion() );
126
	printf ( "\nX3 Voice Create V1.00 (SPK Library Version %.2f) 15/12/2023 Created by Cycrow\n\n", GetLibraryVersion() );
62
 
127
 
63
	// parse the cmd name
128
	// parse the cmd name
64
	Utils::WString cmd (argv[0]);
129
	Utils::WString cmd (argv[0]);
-
 
130
	Utils::WString command(argv[1]);
-
 
131
	cmd = cmd.findReplace(L"\\", L"/");
-
 
132
	Utils::WString cmdDir = cmd.tokens(L"/", 1, cmd.countToken(L"/") - 1);
-
 
133
	cmd = cmd.token(L"/", cmd.countToken(L"/"));
65
 
134
 
66
	Utils::String mainFileStr = "d:/x/X3 Terran Conflict - Guilds/addon2/mov/00344.wav";
-
 
67
	Utils::WString dir = L"d:/x/X3 Terran Conflict - Guilds/addon2/mov/working";
135
	Utils::WStringList options;
68
	Utils::String output = "d:/x/X3 Terran Conflict - Guilds/addon2/mov/working/00344.wav";
-
 
69
	Utils::WString outputXML = L"d:/x/X3 Terran Conflict - Guilds/addon2/mov/working/00044.xml";
-
 
70
 
-
 
71
	SF_INFO info;
-
 
72
	SNDFILE* mainFile = sf_open(mainFileStr.c_str(), SFM_READ, &amp;info);
136
	std::vector&lt;Utils::WString> args;
73
	if (mainFile) 
137
	for (int i = 2; i < argc; i++)
74
	{
138
	{
75
		double duration = static_cast<double>(info.frames) / static_cast<double>(info.samplerate);
-
 
76
		size_t currentPos = static_cast<size_t>((duration * 1000.0) + 0.5);
-
 
77
 
-
 
78
		CFileIO(mainFileStr).copy(output);
139
		Utils::WString arg(argv[i]);
79
 
-
 
80
 
-
 
81
		SF_INFO outInfo;
-
 
82
		SNDFILE* outputFile = sf_open(output.c_str(), SFM_RDWR, &outInfo);
-
 
83
		if (outputFile) 
140
		if (arg.startsWith(L"--"))
84
		{
141
		{
85
			double buffer[BUFFER_LEN];
142
			arg = arg.substr(2);
86
 
143
 
-
 
144
			if (arg.contains(L":"))
-
 
145
			{
87
			int check = sf_format_check(&amp;outInfo);
146
				Utils::WString a = arg.token(L&quot;:", 1);
88
			sf_count_t seek = sf_seek(outputFile, 0, SEEK_END);
147
				Utils::WString b = arg.tokens(L":", 2);
-
 
148
				options.pushBack(a, b);
-
 
149
			}
-
 
150
			else
-
 
151
				options.pushBack(arg);
-
 
152
		}
-
 
153
		else
-
 
154
			args.push_back(arg);
-
 
155
	}
89
 
156
 
90
			Utils::WStringList xmlOut;
157
	if (command == L"offset";)
91
			xmlOut.pushBack(L"<?xml version=\"1.0\" ?>");
158
		DoOffset(cmd, options, args);
92
			xmlOut.pushBack(L";<language id=\"44\">");
159
	else if (command == L";help")
-
 
160
	{
-
 
161
		PrintSyntax(cmd);
-
 
162
	}
-
 
163
	else
-
 
164
	{
-
 
165
 
-
 
166
		Utils::String mainFileStr = "d:/x/X3 Terran Conflict - Guilds/addon2/mov/00344.wav";
-
 
167
		Utils::WString dir = L"d:/x/X3 Terran Conflict - Guilds/addon2/mov/working";
-
 
168
		Utils::String output = "d:/x/X3 Terran Conflict - Guilds/addon2/mov/working/00344.wav";
-
 
169
		Utils::WString outputXML = L"d:/x/X3 Terran Conflict - Guilds/addon2/mov/working/00044.xml";
93
 
170
 
94
			CDirIO D(dir);
171
		SF_INFO info;
-
 
172
		SNDFILE* mainFile = sf_open(mainFileStr.c_str(), SFM_READ, &info);
-
 
173
		if (mainFile)
-
 
174
		{
-
 
175
			double duration = static_cast<double>(info.frames) / static_cast<double>(info.samplerate);
-
 
176
			size_t currentPos = static_cast<size_t>((duration * 1000.0) + 0.5);
-
 
177
 
95
			Utils::WStringList list;
178
			CFileIO(mainFileStr).copy(output);
-
 
179
 
-
 
180
 
-
 
181
			SF_INFO outInfo;
-
 
182
			SNDFILE* outputFile = sf_open(output.c_str(), SFM_RDWR, &outInfo);
96
			if (D.dirList(list))
183
			if (outputFile)
97
			{
184
			{
-
 
185
				double buffer[BUFFER_LEN];
-
 
186
 
-
 
187
				int check = sf_format_check(&outInfo);
98
				for (auto itr = list.begin(); itr != list.end(); itr++)
188
				sf_count_t seek = sf_seek(outputFile, 0, SEEK_END);
-
 
189
 
-
 
190
				Utils::WStringList xmlOut;
-
 
191
				xmlOut.pushBack(L"<?xml version=\"1.0\" ?>");
-
 
192
				xmlOut.pushBack(L"<language id=\"44\">");
-
 
193
 
-
 
194
				CDirIO D(dir);
-
 
195
				Utils::WStringList list;
-
 
196
				if (D.dirList(list))
99
				{
197
				{
100
					if (D.isDir((*itr)->str)) 
198
					for (auto itr = list.begin(); itr != list.end(); itr++)
101
					{
199
					{
102
						CDirIO curDir(D.dir((*itr)->str));
200
						if (D.isDir((*itr)->str))
103
						long pageID = (*itr)->str.toInt();
-
 
104
 
-
 
105
						xmlOut.pushBack(Utils::WString(L"<page id=\"") + pageID + L"\" stream=\"3\">");
-
 
106
 
-
 
107
						Utils::WStringList idList;
-
 
108
						if (curDir.dirList(idList)) 
-
 
109
						{
201
						{
-
 
202
							CDirIO curDir(D.dir((*itr)->str));
-
 
203
							long pageID = (*itr)->str.toInt();
-
 
204
 
-
 
205
							xmlOut.pushBack(Utils::WString(L"<page id=\"") + pageID + L"\" stream=\"3\">");
-
 
206
 
-
 
207
							Utils::WStringList idList;
110
							for (auto itr2 = idList.begin(); itr2 != idList.end(); itr2++)
208
							if (curDir.dirList(idList))
111
							{
209
							{
112
								if (curDir.isFile((*itr2)->;str))
210
								for (auto itr2 = idList.begin(); itr2 != idList.end(); itr2++)
113
								{
211
								{
114
									CFileIO F(curDir.file((*itr2)->str));
212
									if (curDir.isFile((*itr2)->str))
115
									long id = F.baseName().toInt();
-
 
116
									size_t len = 0;
-
 
117
 
-
 
118
									SF_INFO inInfo;
-
 
119
									SNDFILE* inputFile = sf_open(F.fullFilename().toString().c_str(), SFM_READ, &inInfo);
-
 
120
									if (inputFile)
-
 
121
									{
213
									{
122
										double duration = static_cast<double>(inInfo.frames) / static_cast<double>(inInfo.samplerate);
214
										CFileIO F(curDir.file((*itr2)->str));
123
										size_t len = static_cast<size_t>((duration * 1000.0) + 0.5);
215
										long id = F.baseName().toInt();
124
 
-
 
-
 
216
										size_t len = 0;
125
 
217
 
-
 
218
										SF_INFO inInfo;
-
 
219
										SNDFILE* inputFile = sf_open(F.fullFilename().toString().c_str(), SFM_READ, &inInfo);
-
 
220
										if (inputFile)
-
 
221
										{
-
 
222
											double duration = static_cast<double>(inInfo.frames) / static_cast<double>(inInfo.samplerate);
-
 
223
											size_t len = static_cast<size_t>((duration * 1000.0) + 0.5);
-
 
224
 
-
 
225
 
126
										sf_count_t readcount;
226
											sf_count_t readcount;
127
										while ((readcount = sf_read_double(inputFile, buffer, BUFFER_LEN)) > 0)
227
											while ((readcount = sf_read_double(inputFile, buffer, BUFFER_LEN)) > 0)
128
											sf_write_double(outputFile, buffer, readcount);
228
												sf_write_double(outputFile, buffer, readcount);
129
										//int* data = new int[inInfo.frames * inInfo.channels];
229
											//int* data = new int[inInfo.frames * inInfo.channels];
130
										//sf_count_t readCount = sf_readf_int(inputFile, data, inInfo.frames);
230
											//sf_count_t readCount = sf_readf_int(inputFile, data, inInfo.frames);
131
										//sf_count_t writeCount = sf_writef_int(outputFile, data, inInfo.frames);
231
											//sf_count_t writeCount = sf_writef_int(outputFile, data, inInfo.frames);
132
 
232
 
133
										xmlOut.pushBack(Utils::WString(L"\t<t id=\"") + id + L"\" s=\"" + (long)currentPos + L"\" l=\"" + (long)len + "\"/>");
233
											xmlOut.pushBack(Utils::WString(L"\t<t id=\"") + id + L"\" s=\"" + (long)currentPos + L"\" l=\"" + (long)len + "\"/>");
134
										currentPos += len;
234
											currentPos += len;
135
										sf_close(inputFile);
235
											sf_close(inputFile);
-
 
236
										}
136
									}
237
									}
137
								}
238
								}
138
							}
239
							}
-
 
240
 
-
 
241
							xmlOut.pushBack(L"</page>");
139
						}
242
						}
140
 
-
 
141
						xmlOut.pushBack(L"</page>");
-
 
142
					}
243
					}
143
				}
244
				}
144
			}
-
 
145
 
-
 
146
			xmlOut.pushBack("</language>");
-
 
147
 
-
 
148
			sf_close(outputFile);
-
 
149
 
245
 
-
 
246
				xmlOut.pushBack("</language>");
-
 
247
 
-
 
248
				sf_close(outputFile);
-
 
249
 
150
			CFileIO xml(outputXML);
250
				CFileIO xml(outputXML);
151
			xml.writeFile(&xmlOut);
251
				xml.writeFile(&xmlOut);
-
 
252
			}
-
 
253
 
-
 
254
			sf_close(mainFile);
152
		}
255
		}
153
 
-
 
154
		sf_close(mainFile);
-
 
155
	}
256
	}
156
	//Pause();
257
	//Pause();
157
 
258
 
158
	return 0;
259
	return 0;
159
}
260
}