// ----------------------------------------------------------------------- void * cchar_term_worker(void *ptr) { struct cchar_unit_proto_t *unit = ptr; char data; int res; static int counter; while (1) { res = term_read(UNIT->term, &data, 1); if (res <= 0) { continue; } if (data == 10) { cchar_term_queue_char(unit, 10); cchar_term_queue_char(unit, 13); counter++; } else if (data == 13) { continue; } else { cchar_term_queue_char(unit, data); } } pthread_exit(NULL); }
void transport( mlt_producer producer ) { mlt_properties properties = mlt_producer_properties( producer ); term_init( ); fprintf( stderr, "Press 'q' to continue\n" ); while( mlt_properties_get_int( properties, "done" ) == 0 ) { int value = term_read( ); if ( value != -1 ) transport_action( producer, ( char * )&value ); } }
char get_keypress( ) { char value = '\0'; int pressed = 0; fflush( stdout ); term_init( ); while ( ( pressed = term_read( ) ) == -1 ) ; term_exit( ); value = (char)pressed; return value; }
// ----------------------------------------------------------------------- void * cchar_term_worker(void *ptr) { struct cchar_unit_proto_t *unit = (struct cchar_unit_proto_t *) ptr; char data; int res; while (1) { res = term_read(UNIT->term, &data, 1); usleep(1000); if ((res <= 0) || (data == 10)) { continue; } cchar_term_queue_char(unit, data); } pthread_exit(NULL); }
static int pollterms(void) { struct pollfd ufds[NTERMS + 1]; int term_idx[NTERMS + 1]; int i; int n = 1; ufds[0].fd = 0; ufds[0].events = POLLIN; for (i = 0; i < NTERMS; i++) { if (TERMOPEN(i)) { ufds[n].fd = terms[i].fd; ufds[n].events = POLLIN; term_idx[n++] = i; } } if (poll(ufds, n, 1000) < 1) return 0; if (ufds[0].revents & (POLLFLAGS & ~POLLIN)) return 1; if (ufds[0].revents & POLLIN) directkey(); for (i = 1; i < n; i++) { if (!(ufds[i].revents & POLLFLAGS)) continue; peepterm(term_idx[i]); if (ufds[i].revents & POLLIN) { term_read(); } else { scr_free(term_idx[i]); term_end(); if (cmdmode) exitit = 1; } peepback(term_idx[i]); } return 0; }
static void transport( mlt_producer producer, mlt_consumer consumer ) { mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer ); int silent = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "silent" ); int progress = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "progress" ); struct timespec tm = { 0, 40000000 }; int total_length = mlt_producer_get_length( producer ); int last_position = 0; if ( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) ) { if ( !silent && !progress ) { term_init( ); fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" ); fprintf( stderr, "|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|\n" ); fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" ); fprintf( stderr, "+---------------------------------------------------------------------+\n" ); fprintf( stderr, "| H = back 1 minute, L = forward 1 minute |\n" ); fprintf( stderr, "| h = previous frame, l = next frame |\n" ); fprintf( stderr, "| g = start of clip, j = next clip, k = previous clip |\n" ); fprintf( stderr, "| 0 = restart, q = quit, space = play |\n" ); fprintf( stderr, "+---------------------------------------------------------------------+\n" ); } while( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) ) { int value = ( silent || progress )? -1 : term_read( ); if ( value != -1 ) { char string[ 2 ] = { value, 0 }; transport_action( producer, string ); } #if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL) event_handling( producer, consumer ); #endif if ( !silent && mlt_properties_get_int( properties, "stats_off" ) == 0 ) { if ( progress ) { int current_position = mlt_producer_position( producer ); if ( current_position > last_position ) { fprintf( stderr, "Current Frame: %10d, percentage: %10d%c", current_position, 100 * current_position / total_length, progress == 2 ? '\n' : '\r' ); last_position = current_position; } } else { fprintf( stderr, "Current Position: %10d\r", (int)mlt_consumer_position( consumer ) ); } fflush( stderr ); } if ( silent || progress ) nanosleep( &tm, NULL ); } if ( !silent ) fprintf( stderr, "\n" ); } }
mvcp_error_code client_transport( client demo ) { mvcp_error_code error = mvcp_ok; int refresh = 1; int terminated = 0; mvcp_status_t status; mvcp_notifier notifier = mvcp_get_notifier( demo->dv ); while ( !terminated ) { if ( refresh ) { printf( " +----+ +------+ +----+ +------+ +---+ +-----+ +------+ +-----+ +---+ \n" ); printf( " |1=-5| |2=-2.5| |3=-1| |4=-0.5| |5=1| |6=0.5| |7=1.25| |8=2.5| |9=5| \n" ); printf( " +----+ +------+ +----+ +------+ +---+ +-----+ +------+ +-----+ +---+ \n" ); printf( "\n" ); printf( "+----------------------------------------------------------------------+\n" ); printf( "| 0 = quit, x = eXecute, 'space' = pause |\n" ); printf( "| g = goto a frame, q = queue maintenance |\n" ); printf( "| h = step -1, j = end of clip, k = start of clip, l = step 1 |\n" ); printf( "| eof handling: p = pause, r = repeat, t = terminate |\n" ); printf( "| i = set in point, o = set out point, c = clear in/out |\n" ); printf( "| u = use point settings, d = don't use point settings |\n" ); printf( "+----------------------------------------------------------------------+\n" ); printf( "\n" ); term_init( ); refresh = 0; } client_change_status( demo, 1 ); switch( term_read( ) ) { case '0': terminated = 1; break; case -1: break; case ' ': error = mvcp_unit_pause( demo->dv, demo->selected_unit ); break; case '1': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, -5000 ); break; case '2': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, -2500 ); break; case '3': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, -1000 ); break; case '4': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, -500 ); break; case '5': error = mvcp_unit_play( demo->dv, demo->selected_unit ); break; case '6': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, 500 ); break; case '7': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, 1250 ); break; case '8': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, 2500 ); break; case '9': error = mvcp_unit_play_at_speed( demo->dv, demo->selected_unit, 5000 ); break; case 's': error = mvcp_unit_goto( demo->dv, demo->selected_unit, 0 ); break; case 'h': error = mvcp_unit_step( demo->dv, demo->selected_unit, -1 ); break; case 'j': mvcp_notifier_get( notifier, &status, demo->selected_unit ); error = mvcp_unit_goto( demo->dv, demo->selected_unit, status.tail_out ); break; case 'k': mvcp_notifier_get( notifier, &status, demo->selected_unit ); error = mvcp_unit_goto( demo->dv, demo->selected_unit, status.in ); break; case 'l': error = mvcp_unit_step( demo->dv, demo->selected_unit, 1 ); break; case 'p': error = mvcp_unit_set( demo->dv, demo->selected_unit, "eof", "pause" ); break; case 'r': error = mvcp_unit_set( demo->dv, demo->selected_unit, "eof", "loop" ); break; case 't': error = mvcp_unit_set( demo->dv, demo->selected_unit, "eof", "stop" ); break; case 'i': error = client_set_in( demo ); break; case 'o': error = client_set_out( demo ); break; case 'g': client_change_status( demo, 0 ); term_exit( ); error = client_goto( demo ); refresh = 1; break; case 'c': error = client_clear_in_out( demo ); break; case 'u': error = mvcp_unit_set( demo->dv, demo->selected_unit, "points", "use" ); break; case 'd': error = mvcp_unit_set( demo->dv, demo->selected_unit, "points", "ignore" ); break; case 'x': client_change_status( demo, 0 ); term_exit( ); client_execute( demo ); refresh = 1; break; case 'q': client_change_status( demo, 0 ); term_exit( ); client_queue_maintenance( demo, &demo->queues[ demo->selected_unit ] ); refresh = 1; break; } client_change_status( demo, 0 ); } term_exit( ); return error; }
mvcp_error_code client_load( client demo ) { mvcp_error_code error = mvcp_ok; int terminated = 0; int refresh = 1; int start = 0; strcpy( demo->current_directory, demo->last_directory ); term_init( ); while ( !terminated ) { mvcp_dir dir = mvcp_dir_init( demo->dv, demo->current_directory ); if ( mvcp_dir_count( dir ) == -1 ) { printf( "Invalid directory - retrying %s\n", demo->last_directory ); mvcp_dir_close( dir ); dir = mvcp_dir_init( demo->dv, demo->last_directory ); if ( mvcp_dir_count( dir ) == -1 ) { printf( "Invalid directory - going back to /\n" ); mvcp_dir_close( dir ); dir = mvcp_dir_init( demo->dv, "/" ); strcpy( demo->current_directory, "/" ); } else { strcpy( demo->current_directory, demo->last_directory ); } } terminated = mvcp_dir_count( dir ) == -1; if ( !terminated ) { int index = 0; int selected = 0; int max = 9; int end = 0; end = mvcp_dir_count( dir ); strcpy( demo->last_directory, demo->current_directory ); while ( !selected && !terminated ) { mvcp_dir_entry_t entry; int pressed; if ( refresh ) { const char *action = "Load & Play"; if ( demo->queues[ demo->selected_unit ].mode ) action = "Queue"; printf( "%s from %s\n\n", action, demo->current_directory ); if ( strcmp( demo->current_directory, "/" ) ) printf( "-: Parent directory\n" ); for ( index = start; index < end && ( index - start ) < max; index ++ ) { mvcp_dir_get( dir, index, &entry ); printf( "%d: %s\n", index - start + 1, entry.name ); } while ( ( index ++ % 9 ) != 0 ) printf( "\n" ); printf( "\n" ); if ( start + max < end ) printf( "space = more files" ); else if ( end > max ) printf( "space = return to start of list" ); if ( start > 0 ) printf( ", b = previous files" ); printf( "\n" ); printf( "0 = abort, t = transport, x = execute command, q = queue maintenance\n\n" ); refresh = 0; } client_change_status( demo, 1 ); pressed = term_read( ); switch( pressed ) { case -1: break; case '0': terminated = 1; break; case 'b': refresh = start - max >= 0; if ( refresh ) start = start - max; break; case ' ': refresh = start + max < end; if ( refresh ) { start = start + max; } else if ( end > max ) { start = 0; refresh = 1; } break; case '-': if ( strcmp( demo->current_directory, "/" ) ) { selected = 1; ( *strrchr( demo->current_directory, '/' ) ) = '\0'; ( *( strrchr( demo->current_directory, '/' ) + 1 ) ) = '\0'; } break; case 't': client_change_status( demo, 0 ); term_exit( ); client_transport( demo ); term_init( ); selected = 1; break; case 'x': client_change_status( demo, 0 ); term_exit( ); client_execute( demo ); term_init( ); selected = 1; break; case 'q': client_change_status( demo, 0 ); term_exit( ); client_queue_maintenance( demo, &demo->queues[ demo->selected_unit ] ); term_init( ); selected = 1; break; default: if ( pressed >= '1' && pressed <= '9' ) { if ( ( start + pressed - '1' ) < end ) { mvcp_dir_get( dir, start + pressed - '1', &entry ); selected = 1; strcat( demo->current_directory, entry.name ); } } break; } client_change_status( demo, 0 ); } mvcp_dir_close( dir ); } if ( !terminated && demo->current_directory[ strlen( demo->current_directory ) - 1 ] != '/' ) { if ( demo->queues[ demo->selected_unit ].mode == 0 ) { error = mvcp_unit_load( demo->dv, demo->selected_unit, demo->current_directory ); mvcp_unit_play( demo->dv, demo->selected_unit ); } else { client_queue_add( demo, &demo->queues[ demo->selected_unit ], demo->current_directory ); printf( "File %s added to queue.\n", demo->current_directory ); } strcpy( demo->current_directory, demo->last_directory ); refresh = 0; } else { refresh = 1; start = 0; } } term_exit( ); return error; }
mvcp_error_code client_queue_maintenance( client demo, client_queue queue ) { printf( "Queue Maintenance for Unit %d\n\n", queue->unit ); if ( !queue->mode ) { char ch; printf( "Activate queueing? [Y] " ); ch = get_keypress( ); if ( ch == 'y' || ch == 'Y' || ch == '\r' ) queue->mode = 1; printf( "\n\n" ); } if ( queue->mode ) { int terminated = 0; int last_position = -2; term_init( ); while ( !terminated ) { int first = ( queue->position + 1 ) % 50; int index = first; if ( first == queue->tail ) index = first = queue->head; if ( queue->head == queue->tail ) { if ( last_position == -2 ) { printf( "Queue is empty\n" ); printf( "\n" ); printf( "0 = exit, t = turn off queueing\n\n" ); last_position = -1; } } else if ( last_position != queue->position ) { printf( "Order of play\n\n" ); do { printf( "%c%02d: %s\n", index == first ? '*' : ' ', index, queue->list[ index ] + 1 ); index = ( index + 1 ) % 50; if ( index == queue->tail ) index = queue->head; } while( index != first ); printf( "\n" ); printf( "0 = exit, t = turn off queueing, c = clear queue\n\n" ); last_position = queue->position; } client_change_status( demo, 1 ); switch( term_read( ) ) { case -1: break; case '0': terminated = 1; break; case 't': terminated = 1; queue->mode = 0; break; case 'c': queue->head = queue->tail = 0; queue->position = -1; last_position = -2; break; } client_change_status( demo, 0 ); } term_exit( ); } return mvcp_ok; }