a630422bb95ab0f052d175b0911abd54d3e7b816
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
;
44 if ( filename
[0] == '!' )
50 if ( filename
[0] == '/' )
53 snprintf( fullname
, 1023, "%s%s", cmd_arg
->root_dir
, filename
);
56 return RESPONSE_INVALID_UNIT
;
59 double in
= -1, out
= -1;
60 if ( valerie_tokeniser_count( cmd_arg
->tokeniser
) == 5 )
62 in
= atof( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 3 ) );
63 out
= atof( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 4 ) );
65 if ( miracle_unit_load( unit
, fullname
, in
, out
, flush
) != valerie_ok
)
66 return RESPONSE_BAD_FILE
;
68 return RESPONSE_SUCCESS
;
71 int miracle_list( command_argument cmd_arg
)
73 miracle_unit unit
= miracle_get_unit( cmd_arg
->unit
);
77 miracle_unit_report_list( unit
, cmd_arg
->response
);
78 return RESPONSE_SUCCESS
;
81 return RESPONSE_INVALID_UNIT
;
84 static int parse_clip( command_argument cmd_arg, int arg )
86 dv_unit unit = miracle_get_unit(cmd_arg->unit);
87 int clip = dv_unit_get_current_clip( unit );
89 if ( dv_tokeniser_count( cmd_arg->tokeniser ) > arg )
91 dv_player player = dv_unit_get_dv_player( unit );
92 char *token = dv_tokeniser_get_string( cmd_arg->tokeniser, arg );
93 if ( token[ 0 ] == '+' )
94 clip += atoi( token + 1 );
95 else if ( token[ 0 ] == '-' )
96 clip -= atoi( token + 1 );
101 if ( clip >= player->size )
102 clip = player->size - 1;
109 int miracle_insert( command_argument cmd_arg
)
112 dv_unit unit = miracle_get_unit(cmd_arg->unit);
113 char *filename = (char*) cmd_arg->argument;
116 if ( filename[0] == '/' )
119 snprintf( fullname, 1023, "%s%s", cmd_arg->root_dir, filename );
122 return RESPONSE_INVALID_UNIT;
125 long in = -1, out = -1;
126 int index = parse_clip( cmd_arg, 3 );
128 if ( dv_tokeniser_count( cmd_arg->tokeniser ) == 6 )
130 in = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 4 ) );
131 out = atoi( dv_tokeniser_get_string( cmd_arg->tokeniser, 5 ) );
134 switch( dv_unit_insert( unit, fullname, index, in, out ) )
137 return RESPONSE_SUCCESS;
138 case dv_pump_too_many_files_open:
139 return RESPONSE_TOO_MANY_FILES;
141 return RESPONSE_BAD_FILE;
145 return RESPONSE_SUCCESS
;
148 int miracle_remove( command_argument cmd_arg
)
151 dv_unit unit = miracle_get_unit(cmd_arg->unit);
154 return RESPONSE_INVALID_UNIT;
157 int index = parse_clip( cmd_arg, 2 );
159 if ( dv_unit_remove( unit, index ) != dv_pump_ok )
160 return RESPONSE_BAD_FILE;
163 return RESPONSE_SUCCESS
;
166 int miracle_clean( command_argument cmd_arg
)
169 dv_unit unit = miracle_get_unit(cmd_arg->unit);
172 return RESPONSE_INVALID_UNIT;
175 if ( dv_unit_clean( unit ) != dv_pump_ok )
176 return RESPONSE_BAD_FILE;
179 return RESPONSE_SUCCESS
;
182 int miracle_move( command_argument cmd_arg
)
185 dv_unit unit = miracle_get_unit(cmd_arg->unit);
189 if ( dv_tokeniser_count( cmd_arg->tokeniser ) > 2 )
191 int src = parse_clip( cmd_arg, 2 );
192 int dest = parse_clip( cmd_arg, 3 );
194 if ( dv_unit_move( unit, src, dest ) != dv_pump_ok )
195 return RESPONSE_BAD_FILE;
199 return RESPONSE_MISSING_ARG;
204 return RESPONSE_INVALID_UNIT;
208 return RESPONSE_SUCCESS
;
211 int miracle_append( command_argument cmd_arg
)
213 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
214 char *filename
= (char*) cmd_arg
->argument
;
217 if ( filename
[0] == '/' )
220 snprintf( fullname
, 1023, "%s%s", cmd_arg
->root_dir
, filename
);
223 return RESPONSE_INVALID_UNIT
;
226 double in
= -1, out
= -1;
227 if ( valerie_tokeniser_count( cmd_arg
->tokeniser
) == 5 )
229 in
= atof( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 3 ) );
230 out
= atof( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 4 ) );
232 switch ( miracle_unit_append( unit
, fullname
, in
, out
) )
235 return RESPONSE_SUCCESS
;
237 return RESPONSE_BAD_FILE
;
240 return RESPONSE_SUCCESS
;
243 int miracle_play( command_argument cmd_arg
)
245 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
249 return RESPONSE_INVALID_UNIT
;
254 if ( valerie_tokeniser_count( cmd_arg
->tokeniser
) == 3 )
255 speed
= atoi( valerie_tokeniser_get_string( cmd_arg
->tokeniser
, 2 ) );
256 miracle_unit_play( unit
, speed
);
259 return RESPONSE_SUCCESS
;
262 int miracle_stop( command_argument cmd_arg
)
264 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
266 return RESPONSE_INVALID_UNIT
;
268 miracle_unit_play( unit
, 0 );
269 return RESPONSE_SUCCESS
;
272 int miracle_pause( command_argument cmd_arg
)
274 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
276 return RESPONSE_INVALID_UNIT
;
278 miracle_unit_play( unit
, 0 );
279 return RESPONSE_SUCCESS
;
282 int miracle_rewind( command_argument cmd_arg
)
284 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
286 return RESPONSE_INVALID_UNIT
;
288 miracle_unit_play( unit
, -2000 );
289 return RESPONSE_SUCCESS
;
292 int miracle_step( command_argument cmd_arg
)
295 dv_unit unit = miracle_get_unit(cmd_arg->unit);
297 if (unit == NULL || dv_unit_is_offline(unit))
298 return RESPONSE_INVALID_UNIT;
301 dv_unit_play( unit, 0 );
302 dv_unit_step( unit, *(int*) cmd_arg->argument );
305 return RESPONSE_SUCCESS
;
308 int miracle_goto( command_argument cmd_arg
)
311 dv_unit unit = miracle_get_unit(cmd_arg->unit);
312 int clip = parse_clip( cmd_arg, 3 );
314 if (unit == NULL || dv_unit_is_offline(unit))
315 return RESPONSE_INVALID_UNIT;
317 dv_unit_change_position( unit, clip, *(int*) cmd_arg->argument );
319 return RESPONSE_SUCCESS
;
322 int miracle_ff( command_argument cmd_arg
)
324 miracle_unit unit
= miracle_get_unit(cmd_arg
->unit
);
326 return RESPONSE_INVALID_UNIT
;
328 miracle_unit_play( unit
, 2000 );
329 return RESPONSE_SUCCESS
;
332 int miracle_set_in_point( command_argument cmd_arg
)
335 dv_unit unit = miracle_get_unit(cmd_arg->unit);
336 int clip = parse_clip( cmd_arg, 3 );
338 if (unit == NULL || dv_unit_is_offline(unit))
339 return RESPONSE_INVALID_UNIT;
342 int position = *(int *) cmd_arg->argument;
344 switch( dv_unit_set_clip_in( unit, clip, position ) )
347 return RESPONSE_BAD_FILE;
349 return RESPONSE_OUT_OF_RANGE;
353 return RESPONSE_SUCCESS
;
356 int miracle_set_out_point( command_argument cmd_arg
)
359 dv_unit unit = miracle_get_unit(cmd_arg->unit);
360 int clip = parse_clip( cmd_arg, 3 );
362 if (unit == NULL || dv_unit_is_offline(unit))
363 return RESPONSE_INVALID_UNIT;
366 int position = *(int *) cmd_arg->argument;
368 switch( dv_unit_set_clip_out( unit, clip, position ) )
371 return RESPONSE_BAD_FILE;
373 return RESPONSE_OUT_OF_RANGE;
377 return RESPONSE_SUCCESS
;
380 int miracle_get_unit_status( command_argument cmd_arg
)
382 valerie_status_t status
;
383 int error
= miracle_unit_get_status( miracle_get_unit( cmd_arg
->unit
), &status
);
386 return RESPONSE_INVALID_UNIT
;
390 valerie_response_printf( cmd_arg
->response
, sizeof( text
), valerie_status_serialise( &status
, text
, sizeof( text
) ) );
391 return RESPONSE_SUCCESS_1
;
397 int miracle_set_unit_property( command_argument cmd_arg
)
400 dv_unit unit = miracle_get_unit(cmd_arg->unit);
403 return RESPONSE_INVALID_UNIT;
406 char *key = (char*) cmd_arg->argument;
409 value = strchr( key, '=' );
411 return RESPONSE_OUT_OF_RANGE;
414 miracle_log( LOG_DEBUG, "USET %s = %s", key, value );
415 if ( strncasecmp( key, "eof", 1024) == 0 )
417 if ( strncasecmp( value, "pause", 1024) == 0)
418 dv_unit_set_eof_action( unit, dv_player_pause );
419 else if ( strncasecmp( value, "loop", 1024) == 0)
420 dv_unit_set_eof_action( unit, dv_player_loop );
421 else if ( strncasecmp( value, "stop", 1024) == 0)
422 dv_unit_set_eof_action( unit, dv_player_terminate );
423 else if ( strncasecmp( value, "clean", 1024) == 0)
424 dv_unit_set_eof_action( unit, dv_player_clean_loop );
426 return RESPONSE_OUT_OF_RANGE;
428 else if ( strncasecmp( key, "points", 1024) == 0 )
430 if ( strncasecmp( value, "use", 1024) == 0)
431 dv_unit_set_mode( unit, dv_clip_mode_restricted );
432 else if ( strncasecmp( value, "ignore", 1024) == 0)
433 dv_unit_set_mode( unit, dv_clip_mode_unrestricted );
435 return RESPONSE_OUT_OF_RANGE;
437 else if ( strncasecmp( key, "syt_offset", 1024) == 0 )
439 dv_unit_set_syt_offset( unit, atoi( value ) );
441 else if ( strncasecmp( key, "cip_n", 1024) == 0 )
443 dv_unit_set_cip_n( unit, atoi( value ) );
445 else if ( strncasecmp( key, "cip_d", 1024) == 0 )
447 dv_unit_set_cip_d( unit, atoi( value ) );
449 else if ( strncasecmp( key, "size", 1024) == 0 )
451 dv_unit_set_buffer_size( unit, atoi( value ) );
453 else if ( strncasecmp( key, "n_frames", 1024) == 0 )
455 dv_unit_set_n_frames( unit, atoi( value ) );
457 else if ( strncasecmp( key, "n_fill", 1024) == 0 )
459 dv_unit_set_n_fill( unit, atoi( value ) );
462 return RESPONSE_OUT_OF_RANGE;
465 return RESPONSE_SUCCESS
;
468 int miracle_get_unit_property( command_argument cmd_arg
)
471 dv_unit unit = miracle_get_unit(cmd_arg->unit);
474 return RESPONSE_INVALID_UNIT;
477 char *key = (char*) cmd_arg->argument;
479 if ( strncasecmp( key, "eof", 1024) == 0 )
481 switch ( dv_unit_get_eof_action( unit ) )
483 case dv_player_pause:
484 dv_response_write( cmd_arg->response, "pause", strlen("pause") );
487 dv_response_write( cmd_arg->response, "loop", strlen("loop") );
489 case dv_player_terminate:
490 dv_response_write( cmd_arg->response, "stop", strlen("stop") );
492 case dv_player_clean_loop:
493 dv_response_write( cmd_arg->response, "clean", strlen("clean") );
496 return RESPONSE_SUCCESS_1;
498 else if ( strncasecmp( key, "points", 1024) == 0 )
500 if ( dv_unit_get_mode( unit ) == dv_clip_mode_restricted )
501 dv_response_write( cmd_arg->response, "use", strlen("use") );
503 dv_response_write( cmd_arg->response, "ignore", strlen("ignore") );
504 return RESPONSE_SUCCESS_1;
506 else if ( strncasecmp( key, "syt_offset", 1024) == 0 )
508 dv_response_printf( cmd_arg->response, 1024, "%d\n",
509 dv_unit_get_syt_offset( unit ) );
510 return RESPONSE_SUCCESS_1;
512 else if ( strncasecmp( key, "cip_n", 1024) == 0 )
514 dv_response_printf( cmd_arg->response, 1024, "%d\n",
515 dv_unit_get_cip_n( unit ) );
516 return RESPONSE_SUCCESS_1;
518 else if ( strncasecmp( key, "cip_d", 1024) == 0 )
520 dv_response_printf( cmd_arg->response, 1024, "%d\n",
521 dv_unit_get_cip_d( unit ) );
522 return RESPONSE_SUCCESS_1;
524 else if ( strncasecmp( key, "size", 1024) == 0 )
526 dv_response_printf( cmd_arg->response, 1024, "%d\n",
527 dv_unit_get_buffer_size( unit ) );
528 return RESPONSE_SUCCESS_1;
530 else if ( strncasecmp( key, "n_frames", 1024) == 0 )
532 dv_response_printf( cmd_arg->response, 1024, "%d\n",
533 dv_unit_get_n_frames( unit ) );
534 return RESPONSE_SUCCESS_1;
536 else if ( strncasecmp( key, "n_fill", 1024) == 0 )
538 dv_response_printf( cmd_arg->response, 1024, "%d\n",
539 dv_unit_get_n_fill( unit ) );
540 return RESPONSE_SUCCESS_1;
542 else if ( strncasecmp( key, "all", 1024 ) == 0 )
544 switch ( dv_unit_get_eof_action( unit ) )
546 case dv_player_pause:
547 dv_response_write( cmd_arg->response, "eof=pause\n", strlen("pause") );
550 dv_response_write( cmd_arg->response, "eof=loop\n", strlen("loop") );
552 case dv_player_terminate:
553 dv_response_write( cmd_arg->response, "eof=stop\n", strlen("stop") );
555 case dv_player_clean_loop:
556 dv_response_write( cmd_arg->response, "eof=clean\n", strlen("clean") );
559 if ( dv_unit_get_mode( unit ) == dv_clip_mode_restricted )
560 dv_response_write( cmd_arg->response, "points=use\n", strlen("use") );
562 dv_response_write( cmd_arg->response, "points=ignore\n", strlen("ignore") );
563 dv_response_printf( cmd_arg->response, 1024, "syt_offset=%d\n", dv_unit_get_syt_offset( unit ) );
564 dv_response_printf( cmd_arg->response, 1024, "cip_n=%d\n", dv_unit_get_cip_n( unit ) );
565 dv_response_printf( cmd_arg->response, 1024, "cip_d=%d\n", dv_unit_get_cip_d( unit ) );
566 dv_response_printf( cmd_arg->response, 1024, "size=%d\n", dv_unit_get_buffer_size( unit ) );
567 dv_response_printf( cmd_arg->response, 1024, "n_frames=%d\n", dv_unit_get_n_frames( unit ) );
568 dv_response_printf( cmd_arg->response, 1024, "n_fill=%d\n", dv_unit_get_n_fill( unit ) );
572 return RESPONSE_SUCCESS
;
576 int miracle_transfer( command_argument cmd_arg
)
579 dv_unit src_unit = miracle_get_unit(cmd_arg->unit);
580 int dest_unit_id = -1;
581 char *string = (char*) cmd_arg->argument;
582 if ( string != NULL && ( string[ 0 ] == 'U' || string[ 0 ] == 'u' ) && strlen( string ) > 1 )
583 dest_unit_id = atoi( string + 1 );
585 if ( src_unit != NULL && dest_unit_id != -1 )
587 dv_unit dest_unit = miracle_get_unit( dest_unit_id );
588 if ( dest_unit != NULL && !dv_unit_is_offline(dest_unit) && dest_unit != src_unit )
590 dv_unit_transfer( dest_unit, src_unit );
591 return RESPONSE_SUCCESS;
595 return RESPONSE_INVALID_UNIT
;