1 //
2 // C++ Implementation: cmdlineextractor
3 //
4 // Description:
5 //
6 //
7 // Author: Yorn <yorn@gmx.net>, (C) 2009
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #include "cmdlineextractor.h"
13
14 #include <iostream>
15 #include <sstream>
16 #include <vector>
17 #include <string>
18 #include <sstream>
19
20 #include "definition.h"
21 #include "oggComment.h"
22 #include "pictureLoader.h"
23 #include "log.h"
24 #include "effectorTypes.h"
25
CmdlineExtractor()26 CmdlineExtractor::CmdlineExtractor()
27 {
28 }
29
~CmdlineExtractor()30 CmdlineExtractor::~CmdlineExtractor()
31 {
32 }
33
extractCommentPairs(std::vector<OggComment> & list,const std::string & _argument,char tokenSeparator,char commentSeparator)34 void CmdlineExtractor::extractCommentPairs(std::vector<OggComment>& list,
35 const std::string& _argument, char tokenSeparator,
36 char commentSeparator)
37 {
38 std::string argument(_argument);
39 std::stringstream str;
40 std::string substr;
41
42 // delete all invalid data
43 std::size_t pos;
44 while ((pos = argument.find_first_not_of(validTextChars))
45 != std::string::npos) {
46 #ifdef DEBUG
47 logger.debug() << "Erasing sign <"<<argument.at(pos) <<"> - it is invalid\n";
48 #endif
49 argument.erase(pos, 1);
50 }
51
52 // if there is no argument given, the first frame will be created as a thumbnail
53 if (argument.empty()) {
54 return;
55 }
56
57 str << argument;
58
59 while (!str.eof()) {
60 getline(str, substr, tokenSeparator);
61
62 std::size_t commentSeparatorPos;
63 if ((commentSeparatorPos = substr.find_first_of(commentSeparator))
64 != std::string::npos) {
65 OggComment comment;
66 comment.tag = substr.substr(0, commentSeparatorPos);
67 comment.value = substr.substr(commentSeparatorPos + 1,
68 std::string::npos);
69 list.push_back(comment);
70 // logger.debug() << "Found pair "<<comment.tag<<" "<<comment.value
71 // <<std::endl;
72 }
73
74 }
75
76 }
77
extractUint32(std::deque<uint32> & list,const std::string & _argument,char seperator)78 void CmdlineExtractor::extractUint32(std::deque<uint32>& list,
79 const std::string& _argument, char seperator)
80 {
81 std::string argument(_argument);
82 std::stringstream str;
83 std::string substr;
84
85 // delete all invalid data
86 std::size_t pos;
87 while ((pos = argument.find_first_not_of(validChars)) != std::string::npos) {
88 #ifdef DEBUG
89 logger.debug() << "erasing <"<<argument.at(pos) <<">\n";
90 #endif
91 argument.erase(pos, 1);
92 }
93
94 // if there is no argument given, the first frame will be created as a thumbnail
95 if (argument.empty()) {
96 list.push_back(0);
97 return;
98 }
99
100 str << argument;
101
102 uint32 value(0);
103 while (!str.eof()) {
104 std::stringstream part;
105 getline(str, substr, seperator);
106 part << substr;
107 part >> value;
108 list.push_back(value);
109 }
110
111 }
112
extractBlend(std::vector<BlendElement> & list,const std::string & _argument,char tokenSeparator,char valueSeparator)113 void CmdlineExtractor::extractBlend(std::vector<BlendElement>& list,
114 const std::string& _argument, char tokenSeparator,
115 char valueSeparator)
116 {
117
118 std::string argument(_argument);
119 std::stringstream str;
120 std::string substr;
121
122 // delete all invalid data
123 std::size_t pos;
124 while ((pos = argument.find_first_not_of(validTextChars))
125 != std::string::npos) {
126 argument.erase(pos, 1);
127 }
128
129 // if there is no argument given, the first frame will be created as a thumbnail
130 if (argument.empty()) {
131 return;
132 }
133
134 str << argument;
135
136 while (!str.eof()) {
137 getline(str, substr, tokenSeparator);
138
139 /* extract picture name */
140 std::size_t valueSeparatorPos = substr.find_first_of(valueSeparator);
141
142 std::string filename = substr.substr(0, valueSeparatorPos);
143
144 /* extract all extra data if some (start time, end time, smoothing)*/
145 double startTime(0);
146 double endTime(-1);
147 bool smooth(false);
148 std::stringstream tmp;
149
150 /* are there any other information given? */
151 if (valueSeparatorPos != std::string::npos) {
152
153 /* analysing start time */
154 substr = substr.substr(valueSeparatorPos + 1);
155
156 valueSeparatorPos = substr.find_first_of(valueSeparator);
157
158 tmp << substr.substr(0, valueSeparatorPos);
159 tmp >> startTime;
160 tmp.clear();
161
162 if (valueSeparatorPos != std::string::npos) {
163
164 /* analysing start time */
165 substr = substr.substr(valueSeparatorPos + 1);
166
167 valueSeparatorPos = substr.find_first_of(valueSeparator);
168
169 tmp << substr.substr(0, valueSeparatorPos);
170 tmp >> endTime;
171
172 if (valueSeparatorPos != std::string::npos) {
173
174 /* analysing start time */
175 substr = substr.substr(valueSeparatorPos + 1);
176
177 if (substr.substr(0, valueSeparator) == "s")
178 smooth = true;
179 }
180 }
181
182 }
183
184 BlendElement elem(filename, startTime, endTime, smooth);
185 // elem.loadPicture();
186 list.push_back(elem);
187
188 }
189
190 #ifdef DEBUG
191 for (uint32 i( 0); i<list.size(); ++i) {
192 logger.debug() << "Info: picture"<<i<<": startTime="<<list[i].startTime
193 <<" endTime="<<list[i].endTime<<" smooth=";
194 if (list[i].smooth == true)
195 logger.debug() << "true\n";
196 else
197 logger.debug() << "false\n";
198
199 }
200 #endif
201 }
202
atoi(const std::string & _argument)203 uint32 CmdlineExtractor::atoi(const std::string& _argument)
204 {
205 std::stringstream stream;
206 uint32 value;
207
208 stream << _argument;
209 stream >> value;
210
211 return (value);
212
213 }
214
atof(const std::string & _argument)215 float CmdlineExtractor::atof(const std::string& _argument)
216 {
217 std::stringstream stream;
218 float value;
219
220 stream << _argument;
221 stream >> value;
222
223 return (value);
224
225 }
226
getNextUint32(std::string & argument,char tokenSeparator)227 uint32 CmdlineExtractor::getNextUint32(std::string& argument,
228 char tokenSeparator)
229 {
230 uint32 retValue(0);
231
232 if (!argument.empty()) {
233
234 std::stringstream tmp;
235
236 std::size_t tokenPosition(argument.find_first_of(tokenSeparator));
237 tmp << argument.substr(0, tokenPosition);
238 tmp >> retValue;
239
240 argument = argument.substr(tokenPosition + 1);
241
242 }
243
244 return (retValue);
245 }
246
getNextFloat(std::string & argument,char tokenSeparator)247 float CmdlineExtractor::getNextFloat(std::string& argument,
248 char tokenSeparator)
249 {
250 float retValue(0.0);
251
252 if (!argument.empty()) {
253
254 std::stringstream tmp;
255
256 std::size_t tokenPosition(argument.find_first_of(tokenSeparator));
257 tmp << argument.substr(0, tokenPosition);
258 tmp >> retValue;
259
260 argument = argument.substr(tokenPosition + 1);
261
262 }
263
264 return (retValue);
265 }
266
getNextString(std::string & argument,char tokenSeparator)267 std::string CmdlineExtractor::getNextString(std::string& argument,
268 char tokenSeparator)
269 {
270 std::string retValue(0);
271
272 if (!argument.empty()) {
273
274 std::stringstream tmp;
275
276 std::size_t tokenPosition(argument.find_first_of(tokenSeparator));
277 tmp << argument.substr(0, tokenPosition);
278 tmp >> retValue;
279
280 argument = argument.substr(tokenPosition + 1);
281
282 }
283
284 return (retValue);
285 }
286
extractSlideshow(const std::string & _argument,char tokenSeparator,SlideshowElement & slideshowElement)287 void CmdlineExtractor::extractSlideshow(const std::string& _argument,
288 char tokenSeparator, SlideshowElement& slideshowElement)
289 {
290 /* A full specified picture would look like this (speparator is ",")
291 * name.jpg:<duration>,<type>,<typeSpecificData>
292 * This should go into a creator factory later:
293 * start and end position is written as <X-Position>,<YPosition>,<Zoom>
294 * The X and Y Position is from the left upper corner. The Zoom is 1 if
295 * the pixel is just copy. In that case, the subframe is as big is the
296 * outgoing frame */
297
298 std::string argument(_argument);
299 std::stringstream tmp;
300
301 // delete all invalid data
302 std::size_t pos;
303 while ((pos = argument.find_first_not_of(validTextChars))
304 != std::string::npos) {
305 argument.erase(pos, 1);
306 }
307
308 // if there is no argument given, the first frame will be created as a thumbnail
309 if (argument.empty()) {
310 return;
311 }
312
313 /* extract picture name */
314 std::size_t tokenPosition(argument.find_first_of(tokenSeparator));
315 slideshowElement.filename = argument.substr(0, tokenPosition);
316
317 std::string substr = argument.substr(tokenPosition + 1);
318
319 /* extract length */
320 // if (tokenPosition != std::string::npos) {
321 // std::string substr = argument.substr(tokenPosition + 1);
322 // tokenPosition = substr.find_first_of(tokenSeparator);
323 // tmp << substr.substr(0, tokenPosition);
324 // tmp >> slideshowElement.duration;
325 // substr = substr.substr(tokenPosition + 1);
326 // std::cout << substr << std::endl;
327
328 // if (tokenPosition != std::string::npos) {
329 // tokenPosition = substr.find_first_of(tokenSeparator);
330 // std::string typeName(substr.substr(0, tokenPosition));
331 // std::cout << substr << std::endl;
332 //
333 // if ((typeName == "kb") || (typeName == "KB")
334 // || (typeName == "KenBurns") || (typeName == "kenburns"))
335 // slideshowElement.type = KenBurns;
336 //
337 // if ((typeName == "p") || (typeName == "pl") || (typeName == "plain")
338 // || (typeName == "Plain"))
339 // slideshowElement.type = Plain;
340 //
341 // if ((typeName == "cf") || (typeName == "crossfade")
342 // || (typeName == "CF") || (typeName == "Crossfade"))
343 // slideshowElement.type = Crossfade;
344 //
345 // if ((typeName == "bl") || (typeName == "b") || (typeName == "B")
346 // || (typeName == "blur") || (typeName == "bluring"))
347 // slideshowElement.type = Blur;
348
349 substr = substr.substr(tokenPosition + 1);
350
351 if (tokenPosition != std::string::npos) {
352 std::cout << "F " << substr << std::endl;
353
354 slideshowElement.startPosX = getNextUint32(substr,
355 tokenSeparator);
356 std::cout << substr << std::endl;
357 slideshowElement.startPosY = getNextUint32(substr,
358 tokenSeparator);
359 std::cout << substr << std::endl;
360 slideshowElement.startZoom = getNextFloat(substr,
361 tokenSeparator);
362 std::cout << substr << std::endl;
363 slideshowElement.endPosX = getNextUint32(substr,
364 tokenSeparator);
365 std::cout << substr << std::endl;
366 slideshowElement.endPosY = getNextUint32(substr,
367 tokenSeparator);
368 std::cout << substr << std::endl;
369 slideshowElement.endZoom = getNextFloat(substr, tokenSeparator);
370 }
371 // }
372 //}
373 }
374
extractCrossSequence(std::vector<std::string> & list,const std::string & _argument,char tokenSeparator)375 void CmdlineExtractor::extractCrossSequence(std::vector<std::string>& list,
376 const std::string& _argument, char tokenSeparator)
377 {
378 std::string argument(_argument);
379
380 // delete all invalid data
381 std::size_t pos;
382 while ((pos = argument.find_first_not_of(validTextChars))
383 != std::string::npos) {
384 argument.erase(pos, 1);
385 }
386
387 while (!argument.empty())
388 list.push_back(getNextString(argument, tokenSeparator));
389
390 return;
391 }
392
393