98a420d5886044e89113e47436a14e16d5145f04
3 * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
4 * Author: Dan Dennedy <dan@dennedy.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <sys/types.h>
33 #include "miracle_unit.h"
34 #include "miracle_commands.h"
35 #include "miracle_log.h"
37 int miracle_load( command_argument cmd_arg
)
39 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
40 char *filename
= (char*) cmd_arg
->argument
;
45 if ( filename
[0] == '!' )
51 service
= strchr( filename
, ':' );
52 if ( service
!= NULL
)
55 filename
= strchr( service
, ':' );
58 if ( strlen( cmd_arg
->root_dir
) && filename
[0] == '/' )
61 snprintf( fullname
, 1023, "%s:%s%s", service
, cmd_arg
->root_dir
, filename
);
65 if ( strlen( cmd_arg
->root_dir
) && filename
[0] == '/' )
68 snprintf( fullname
, 1023, "%s%s", cmd_arg
->root_dir
, filename
);
72 return RESPONSE_INVALID_UNIT
;
75 int32_t in
= -1, out
= -1;
76 if ( valerie_tokeniser_count( cmd_arg
->tokeniser
) == 5 )
78 in
= atol( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 3 ) );
79 out
= atol( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 4 ) );
81 if ( miracle_unit_load( unit
, fullname
, in
, out
, flush
) != valerie_ok
)
82 return RESPONSE_BAD_FILE
;
84 return RESPONSE_SUCCESS
;
87 int miracle_list( command_argument cmd_arg
)
89 miracle_unit unit
= miracle_get_unit( cmd_arg
->unit
);
93 miracle_unit_report_list( unit
, cmd_arg
->response
);
94 return RESPONSE_SUCCESS
;
97 return RESPONSE_INVALID_UNIT
;
100 static int parse_clip( command_argument cmd_arg
, int arg
)
102 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
103 int clip
= miracle_unit_get_current_clip( unit
);
105 if ( valerie_tokeniser_count( cmd_arg
->tokeniser
) > arg
)
107 char *token
= valerie_tokeniser_get_string( cmd_arg
->tokeniser
, arg
);
108 if ( token
[ 0 ] == '+' )
109 clip
+= atoi( token
+ 1 );
110 else if ( token
[ 0 ] == '-' )
111 clip
-= atoi( token
+ 1 );
113 clip
= atoi( token
);
119 int miracle_insert( command_argument cmd_arg
)
121 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
122 char *filename
= (char*) cmd_arg
->argument
;
125 if ( strlen( cmd_arg
->root_dir
) && filename
[0] == '/' )
128 snprintf( fullname
, 1023, "%s%s", cmd_arg
->root_dir
, filename
);
131 return RESPONSE_INVALID_UNIT
;
134 long in
= -1, out
= -1;
135 int index
= parse_clip( cmd_arg
, 3 );
137 if ( valerie_tokeniser_count( cmd_arg
->tokeniser
) == 6 )
139 in
= atoi( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 4 ) );
140 out
= atoi( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 5 ) );
143 switch( miracle_unit_insert( unit
, fullname
, index
, in
, out
) )
146 return RESPONSE_SUCCESS
;
148 return RESPONSE_BAD_FILE
;
151 return RESPONSE_SUCCESS
;
154 int miracle_remove( command_argument cmd_arg
)
156 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
159 return RESPONSE_INVALID_UNIT
;
162 int index
= parse_clip( cmd_arg
, 2 );
164 if ( miracle_unit_remove( unit
, index
) != valerie_ok
)
165 return RESPONSE_BAD_FILE
;
167 return RESPONSE_SUCCESS
;
170 int miracle_clean( command_argument cmd_arg
)
172 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
175 return RESPONSE_INVALID_UNIT
;
178 if ( miracle_unit_clean( unit
) != valerie_ok
)
179 return RESPONSE_BAD_FILE
;
181 return RESPONSE_SUCCESS
;
184 int miracle_clear( command_argument cmd_arg
)
186 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
189 return RESPONSE_INVALID_UNIT
;
192 if ( miracle_unit_clear( unit
) != valerie_ok
)
193 return RESPONSE_BAD_FILE
;
195 return RESPONSE_SUCCESS
;
198 int miracle_move( command_argument cmd_arg
)
200 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
204 if ( valerie_tokeniser_count( cmd_arg
->tokeniser
) > 2 )
206 int src
= parse_clip( cmd_arg
, 2 );
207 int dest
= parse_clip( cmd_arg
, 3 );
209 if ( miracle_unit_move( unit
, src
, dest
) != valerie_ok
)
210 return RESPONSE_BAD_FILE
;
214 return RESPONSE_MISSING_ARG
;
219 return RESPONSE_INVALID_UNIT
;
222 return RESPONSE_SUCCESS
;
225 int miracle_append( command_argument cmd_arg
)
227 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
228 char *filename
= (char*) cmd_arg
->argument
;
231 if ( strlen( cmd_arg
->root_dir
) && filename
[0] == '/' )
234 snprintf( fullname
, 1023, "%s%s", cmd_arg
->root_dir
, filename
);
237 return RESPONSE_INVALID_UNIT
;
240 int32_t in
= -1, out
= -1;
241 if ( valerie_tokeniser_count( cmd_arg
->tokeniser
) == 5 )
243 in
= atol( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 3 ) );
244 out
= atol( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 4 ) );
246 switch ( miracle_unit_append( unit
, fullname
, in
, out
) )
249 return RESPONSE_SUCCESS
;
251 return RESPONSE_BAD_FILE
;
254 return RESPONSE_SUCCESS
;
257 int miracle_push( command_argument cmd_arg
, mlt_service service
)
259 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
260 if ( unit
!= NULL
&& service
!= NULL
)
261 if ( miracle_unit_append_service( unit
, service
) == valerie_ok
)
262 return RESPONSE_SUCCESS
;
263 return RESPONSE_BAD_FILE
;
266 int miracle_receive( command_argument cmd_arg
, char *doc
)
268 mlt_producer producer
= mlt_factory_producer( "westley-xml", doc
);
269 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
270 if ( unit
!= NULL
&& producer
!= NULL
)
272 if ( miracle_unit_append_service( unit
, MLT_PRODUCER_SERVICE( producer
) ) == valerie_ok
)
274 mlt_producer_close( producer
);
275 return RESPONSE_SUCCESS
;
278 mlt_producer_close( producer
);
279 return RESPONSE_BAD_FILE
;
282 int miracle_play( command_argument cmd_arg
)
284 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
288 return RESPONSE_INVALID_UNIT
;
293 if ( valerie_tokeniser_count( cmd_arg
->tokeniser
) == 3 )
294 speed
= atoi( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 2 ) );
295 miracle_unit_play( unit
, speed
);
298 return RESPONSE_SUCCESS
;
301 int miracle_stop( command_argument cmd_arg
)
303 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
305 return RESPONSE_INVALID_UNIT
;
307 miracle_unit_terminate( unit
);
308 return RESPONSE_SUCCESS
;
311 int miracle_pause( command_argument cmd_arg
)
313 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
315 return RESPONSE_INVALID_UNIT
;
317 miracle_unit_play( unit
, 0 );
318 return RESPONSE_SUCCESS
;
321 int miracle_rewind( command_argument cmd_arg
)
323 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
325 return RESPONSE_INVALID_UNIT
;
327 miracle_unit_play( unit
, -2000 );
328 return RESPONSE_SUCCESS
;
331 int miracle_step( command_argument cmd_arg
)
333 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
336 return RESPONSE_INVALID_UNIT
;
339 miracle_unit_play( unit
, 0 );
340 miracle_unit_step( unit
, *(int*) cmd_arg
->argument
);
342 return RESPONSE_SUCCESS
;
345 int miracle_goto( command_argument cmd_arg
)
347 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
348 int clip
= parse_clip( cmd_arg
, 3 );
350 if (unit
== NULL
|| miracle_unit_is_offline(unit
))
351 return RESPONSE_INVALID_UNIT
;
353 miracle_unit_change_position( unit
, clip
, *(int*) cmd_arg
->argument
);
354 return RESPONSE_SUCCESS
;
357 int miracle_ff( command_argument cmd_arg
)
359 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
361 return RESPONSE_INVALID_UNIT
;
363 miracle_unit_play( unit
, 2000 );
364 return RESPONSE_SUCCESS
;
367 int miracle_set_in_point( command_argument cmd_arg
)
369 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
370 int clip
= parse_clip( cmd_arg
, 3 );
373 return RESPONSE_INVALID_UNIT
;
376 int position
= *(int *) cmd_arg
->argument
;
378 switch( miracle_unit_set_clip_in( unit
, clip
, position
) )
381 return RESPONSE_BAD_FILE
;
383 return RESPONSE_OUT_OF_RANGE
;
386 return RESPONSE_SUCCESS
;
389 int miracle_set_out_point( command_argument cmd_arg
)
391 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
392 int clip
= parse_clip( cmd_arg
, 3 );
395 return RESPONSE_INVALID_UNIT
;
398 int position
= *(int *) cmd_arg
->argument
;
400 switch( miracle_unit_set_clip_out( unit
, clip
, position
) )
403 return RESPONSE_BAD_FILE
;
405 return RESPONSE_OUT_OF_RANGE
;
409 return RESPONSE_SUCCESS
;
412 int miracle_get_unit_status( command_argument cmd_arg
)
414 valerie_status_t status
;
415 int error
= miracle_unit_get_status( miracle_get_unit( cmd_arg
->unit
), &status
);
418 return RESPONSE_INVALID_UNIT
;
422 valerie_response_printf( cmd_arg
->response
, sizeof( text
), valerie_status_serialise( &status
, text
, sizeof( text
) ) );
423 return RESPONSE_SUCCESS_1
;
429 int miracle_set_unit_property( command_argument cmd_arg
)
431 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
432 char *name_value
= (char*) cmd_arg
->argument
;
434 return RESPONSE_INVALID_UNIT
;
436 miracle_unit_set( unit
, name_value
);
437 return RESPONSE_SUCCESS
;
440 int miracle_get_unit_property( command_argument cmd_arg
)
442 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
443 char *name
= (char*) cmd_arg
->argument
;
444 char *value
= miracle_unit_get( unit
, name
);
446 return RESPONSE_INVALID_UNIT
;
447 else if ( value
!= NULL
)
448 valerie_response_printf( cmd_arg
->response
, 1024, "%s\n", value
);
449 return RESPONSE_SUCCESS
;
453 int miracle_transfer( command_argument cmd_arg
)
455 miracle_unit src_unit
= miracle_get_unit(cmd_arg
->unit
);
456 int dest_unit_id
= -1;
457 char *string
= (char*) cmd_arg
->argument
;
458 if ( string
!= NULL
&& ( string
[ 0 ] == 'U' || string
[ 0 ] == 'u' ) && strlen( string
) > 1 )
459 dest_unit_id
= atoi( string
+ 1 );
461 if ( src_unit
!= NULL
&& dest_unit_id
!= -1 )
463 miracle_unit dest_unit
= miracle_get_unit( dest_unit_id
);
464 if ( dest_unit
!= NULL
&& !miracle_unit_is_offline(dest_unit
) && dest_unit
!= src_unit
)
466 miracle_unit_transfer( dest_unit
, src_unit
);
467 return RESPONSE_SUCCESS
;
470 return RESPONSE_INVALID_UNIT
;