00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023
00024 #include <iostream>
00025 using std::cerr;
00026 using std::endl;
00027
00028 #include <gtk/gtk.h>
00029 #include <sys/time.h>
00030
00031 #include "page_export.h"
00032 #include "page_export_1394.h"
00033 #include "page_export_avi.h"
00034 #include "page_export_stills.h"
00035 #include "page_export_audio.h"
00036 #include "page_export_mjpeg.h"
00037 #include "page_export_pipe.h"
00038 #include "page_editor.h"
00039 #include "filehandler.h"
00040
00041 extern "C"
00042 {
00043 #include "support.h"
00044 #include "callbacks.h"
00045 #include "commands.h"
00046
00047 extern KinoCommon * common;
00048 extern struct navigate_control g_nav_ctl;
00049 extern char cmd[];
00050 static char lastcmd[ 16 ];
00051 }
00052
00058 PageExport::PageExport( KinoCommon *common )
00059 : currentMode( -1 ), isExporting( false ), isPausing( false ), exportMutex( false )
00060 {
00061 cerr << "> Creating Export Page" << endl;
00062 this->common = common;
00063 this->notebook = GTK_NOTEBOOK( lookup_widget( common->getWidget(), "notebook_export" ) );
00064 this->progressBar = GTK_PROGRESS_BAR( lookup_widget( common->getWidget(), "progressbar" ) );
00065 gtk_progress_bar_set_pulse_step( this->progressBar, 0.05 );
00066
00067
00068 this->export1394 = new Export1394( this, common );
00069 this->exportAVI = new ExportAVI( this, common );
00070 this->exportStills = new ExportStills( this, common );
00071 this->exportAudio = new ExportAudio( this, common );
00072 this->exportMJPEG = new ExportMJPEG( this, common );
00073 this->exportPipe = new ExportPipe( this, common );
00074
00075
00076 this->currentMode = EXPORT_MODE_1394;
00077
00078 }
00079
00083 PageExport::~PageExport()
00084 {
00085 cerr << "> Destroying Export Page" << endl;
00086 }
00087
00091 void PageExport::start()
00092 {
00093 cerr << ">> Starting Export" << endl;
00094 gtk_notebook_set_page( GTK_NOTEBOOK( lookup_widget( common->getWidget(), "notebook_keyhelp" ) ), 3 );
00095 this->getCurrentPage() ->start();
00096 if ( !isExporting )
00097 {
00098 resetProgress();
00099 }
00100
00101
00102 FileTracker::GetInstance().SetMode( CAPTURE_IGNORE );
00103 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( lookup_widget( common->getWidget(), "menuitem_export" ) ), TRUE );
00104 }
00105
00109 gulong PageExport::activate()
00110 {
00111 return this->getCurrentPage() ->activate();
00112 }
00113
00117 void PageExport::clean()
00118 {
00119 cerr << ">> Leaving Export" << endl;
00120 this->getCurrentPage() ->clean();
00121
00122 FileTracker::GetInstance().SetMode( CAPTURE_MOVIE_APPEND );
00123 }
00124
00125
00130 GtkWidget *PageExport::getWidget()
00131 {
00132 return common->getWidget();
00133 }
00134
00135
00141 void PageExport::changeModeRequest( int mode )
00142 {
00143 gtk_notebook_set_page( notebook, mode );
00144 }
00145
00151 void PageExport::setCurrentMode( int mode )
00152 {
00153 if ( currentMode != mode )
00154 {
00155 if ( currentMode != -1 )
00156 this->clean();
00157 currentMode = mode;
00158 this->start();
00159
00160
00161
00162
00163 common->activateWidgets();
00164 }
00165 }
00166
00167
00174 Export *PageExport::getPage( int mode )
00175 {
00176 Export * ret = NULL;
00177
00178 switch ( mode )
00179 {
00180 case EXPORT_MODE_1394:
00181 ret = export1394;
00182 break;
00183 case EXPORT_MODE_AVI:
00184 ret = exportAVI;
00185 break;
00186 case EXPORT_MODE_STILLS:
00187 ret = exportStills;
00188 break;
00189 case EXPORT_MODE_AUDIO:
00190 ret = exportAudio;
00191 break;
00192 case EXPORT_MODE_MJPEG:
00193 ret = exportMJPEG;
00194 break;
00195 case EXPORT_MODE_PIPE:
00196 ret = exportPipe;
00197 break;
00198 }
00199
00200 return ret;
00201 }
00202
00208 Export *PageExport::getCurrentPage( )
00209 {
00210 Export * ret = getPage( this->currentMode );
00211 return ret;
00212 }
00213
00216 void PageExport::previewExport()
00217 {
00218 if ( !exportMutex && !isExporting )
00219 {
00220 exportMutex = true;
00221
00222 isExporting = true;
00223
00224 getCurrentPage() ->startExport( true );
00225 isExporting = false;
00226 exportMutex = false;
00227 }
00228 }
00229
00232 void PageExport::startExport()
00233 {
00234 if ( !exportMutex && !isExporting )
00235 {
00236 exportMutex = true;
00237 isExporting = true;
00238
00239 getCurrentPage() ->startExport();
00240
00241 exportMutex = false;
00242 }
00243 }
00244
00245
00248 void PageExport::stopExport()
00249 {
00250 if ( !exportMutex && isExporting )
00251 {
00252 exportMutex = true;
00253
00254 getCurrentPage() ->stopExport();
00255
00256 isExporting = false;
00257
00258 isPausing = false;
00259 exportMutex = false;
00260 }
00261 }
00262
00263
00264
00265 void PageExport::pauseExport()
00266 {
00267 cerr << ">>> PageExport::pauseExport()" << endl;
00268 if ( !exportMutex && isExporting )
00269 {
00270 exportMutex = true;
00271 isPausing = !isPausing;
00272 getCurrentPage() ->pauseExport();
00273 exportMutex = false;
00274 }
00275 }
00276
00282 void PageExport::selectScene( int scene )
00283 {
00284 getCurrentPage() ->selectScene( scene );
00285 }
00286
00287
00293 gboolean PageExport::processKeyboard( GdkEventKey *event )
00294 {
00295 gboolean ret = FALSE;
00296
00297 #if 0
00298 printf( "send_event: %2.2x\n", event->send_event );
00299 printf( "time : %8.8x\n", event->time );
00300 printf( "state : %8.8x\n", event->state );
00301 printf( "keyval: %8.8x\n", event->keyval );
00302 printf( "length: %8.8x\n", event->length );
00303 printf( "group : %8.8x\n", event->group );
00304 printf( "string: %s\n", event->string );
00305 printf( "(hex) : %2.2x\n", event->string[ 0 ] );
00306 printf( "cmd : %s\n", cmd );
00307 printf( "(hex) : %8.8x\n", cmd[ 0 ] );
00308 #endif
00309
00310
00311 if ( g_nav_ctl.escaped == FALSE )
00312 {
00313 if ( strcmp( lastcmd, "alt" ) == 0 )
00314 {
00315 strcpy( lastcmd, "" );
00316 return ret;
00317 }
00318
00319 switch ( event->keyval )
00320 {
00321
00322 case GDK_Return:
00323 common->keyboardFeedback( cmd, _( "Start Export" ) );
00324 startExport();
00325 return TRUE;
00326 case GDK_Escape:
00327 if ( this->isExporting )
00328 {
00329 common->keyboardFeedback( cmd, _( "Stop Export" ) );
00330 stopExport( );
00331 }
00332 else
00333 {
00334 common->changePageRequest( PAGE_EDITOR );
00335 }
00336 cmd[ 0 ] = 0;
00337 return TRUE;
00338 case GDK_Alt_L:
00339 case GDK_Alt_R:
00340 strcpy( lastcmd, "alt" );
00341 return FALSE;
00342 default:
00343 strcat( cmd, event->string );
00344 break;
00345 }
00346
00347 if ( !strcmp( cmd, "." ) )
00348 strcpy( cmd, lastcmd );
00349
00350 ret = processCommand( cmd );
00351
00352 }
00353 else if ( event->keyval == GDK_Return || event->keyval == GDK_Escape )
00354 {
00355 g_nav_ctl.escaped = FALSE;
00356 gtk_widget_grab_focus( GTK_WIDGET( notebook ) );
00357 }
00358
00359 return ret;
00360 }
00361
00362
00368 gboolean PageExport::processCommand( char *command )
00369 {
00370 int count = 1;
00371 char real[ 256 ] = "";
00372
00373 strcpy( cmd, command );
00374
00375 switch ( sscanf( cmd, "%d%s", &count, real ) )
00376 {
00377 case 1:
00378
00379 if ( strcmp( cmd, "0" ) )
00380 {
00381 common->keyboardFeedback( cmd, "" );
00382 return FALSE;
00383 }
00384 break;
00385 case 0:
00386 sscanf( cmd, "%s", real );
00387 count = 1;
00388 break;
00389 }
00390
00391 strcpy( lastcmd, cmd );
00392
00393
00394
00395 if ( strcmp( cmd, ":w" ) == 0 )
00396 {
00397 common->keyboardFeedback( cmd, _( "Write playlist" ) );
00398 common->savePlayList( );
00399 cmd[ 0 ] = 0;
00400 }
00401
00402 else if ( strcmp( cmd, "Enter" ) == 0 )
00403 {
00404 common->keyboardFeedback( cmd, _( "Start Export" ) );
00405 GdkEvent ev;
00406 ev.key.type = GDK_KEY_PRESS;
00407 ev.key.window = common->getWidget()->window;
00408 ev.key.send_event = TRUE;
00409 ev.key.state = 0;
00410 ev.key.length = 0;
00411 ev.key.string = "";
00412 ev.key.keyval = GDK_Return;
00413 ev.key.group = 0;
00414 gdk_event_put( &ev );
00415 cmd[ 0 ] = 0;
00416 }
00417
00418 else if ( strcmp( cmd, "Esc" ) == 0 && isExporting )
00419 {
00420 common->keyboardFeedback( cmd, _( "Stop Export" ) );
00421 stopExport();
00422 cmd[ 0 ] = 0;
00423 }
00424
00425 else if ( strcmp( cmd, "F2" ) == 0 )
00426 {
00427 common->keyboardFeedback( cmd, _( "Edit" ) );
00428 common->changePageRequest( PAGE_EDITOR );
00429 cmd[ 0 ] = 0;
00430 }
00431
00432 else if ( strcmp( cmd, "A" ) == 0 )
00433 {
00434 common->keyboardFeedback( cmd, _( "Capture, append to movie" ) );
00435 common->changePageRequest( PAGE_EDITOR );
00436 cmd[ 0 ] = 0;
00437 }
00438
00439 else if ( strcmp( cmd, "v" ) == 0 )
00440 {
00441 common->keyboardFeedback( cmd, _( "Timeline" ) );
00442 common->changePageRequest( PAGE_TIMELINE );
00443 cmd[ 0 ] = 0;
00444 }
00445
00446 else if ( strcmp( cmd, "t" ) == 0 )
00447 {
00448 common->keyboardFeedback( cmd, _( "Trim" ) );
00449 common->changePageRequest( PAGE_TRIM );
00450 cmd[ 0 ] = 0;
00451 }
00452
00453 else if ( strcmp( cmd, "C" ) == 0 )
00454 {
00455 common->keyboardFeedback( cmd, _( "FX" ) );
00456 common->changePageRequest( PAGE_TIMELINE );
00457 cmd[ 0 ] = 0;
00458 }
00459
00460
00461
00462 else if ( strcmp( cmd, ":q" ) == 0 )
00463 {
00464 common->keyboardFeedback( cmd, _( "quit" ) );
00465 kinoDeactivate();
00466 cmd[ 0 ] = 0;
00467 }
00468
00469 else
00470 {
00471
00472 if ( strlen( real ) > 3 )
00473 cmd[ 0 ] = 0;
00474 else if ( strchr( "dgy ", real[ strlen( real ) - 1 ] ) == NULL )
00475 cmd[ 0 ] = 0;
00476
00477 common->keyboardFeedback( cmd, "" );
00478 }
00479
00480 return FALSE;
00481 }
00482
00486 void PageExport::updateProgress( gfloat val )
00487 {
00488 struct timeval tv;
00489 long long now;
00490 static long long lastUpdateTime = 0;
00491
00492 gettimeofday( &tv, 0 );
00493 now = 1000000 * ( long long ) tv.tv_sec + ( long long ) tv.tv_usec;
00494
00495
00496
00497 if ( val > 1.0 )
00498 val = 1.0;
00499
00500 if ( now > lastUpdateTime + 300000 || val == 1.0 )
00501 {
00502 if ( val < 0.0 )
00503 gtk_progress_bar_pulse( progressBar );
00504 else
00505 gtk_progress_bar_set_fraction( progressBar, val );
00506 lastUpdateTime = now;
00507 }
00508
00509 while ( gtk_events_pending() )
00510 {
00511 gtk_main_iteration();
00512 }
00513 }
00514
00515 void PageExport::resetProgress()
00516 {
00517 gtk_progress_bar_update( progressBar, 0.0 );
00518 }
00519
00520 void PageExport::timeFormatChanged()
00521 {
00522 on_spinbutton_export_range_start_value_changed( GTK_SPIN_BUTTON( lookup_widget( common->getWidget(), "spinbutton_export_range_start" ) ), NULL );
00523 on_spinbutton_export_range_end_value_changed( GTK_SPIN_BUTTON( lookup_widget( common->getWidget(), "spinbutton_export_range_end" ) ), NULL );
00524 }
00525
00526
00527 extern "C"
00528 {
00529
00530 gchar avi_entry_text[ 1024 ];
00531 gchar stills_entry_text[ 1024 ];
00532 gchar audio_entry_text[ 1024 ];
00533 gchar mjpeg_entry_text[ 1024 ];
00534
00535 void
00536 on_notebook_export_switch_page ( GtkNotebook * notebook,
00537 GtkNotebookPage * page,
00538 gint page_num,
00539 gpointer user_data )
00540 {
00541 setExportMode( page_num );
00542
00543 }
00544
00545
00546 void
00547 on_togglebutton_export_preview_toggled ( GtkToggleButton * togglebutton,
00548 gpointer user_data )
00549 {
00550 previewExport();
00551 }
00552
00553
00554 void
00555 on_togglebutton_export_record_toggled ( GtkToggleButton * togglebutton,
00556 gpointer user_data )
00557 {
00558 startExport();
00559 }
00560
00561
00562 void
00563 on_togglebutton_export_stop_toggled ( GtkToggleButton * togglebutton,
00564 gpointer user_data )
00565 {
00566 stopExport();
00567 }
00568
00569
00570 void
00571 on_togglebutton_export_pause_toggled ( GtkToggleButton * togglebutton,
00572 gpointer user_data )
00573 {
00574 pauseExport();
00575 }
00576
00577
00578
00579 void
00580 on_spinbutton_export_range_start_end_changed
00581 ( GtkEditable * editable,
00582 gpointer user_data )
00583 {
00584 common->getPageExport() ->getCurrentPage() ->onRangeChange( GTK_SPIN_BUTTON( editable ) );
00585 }
00586
00587 void
00588 on_spinbutton_export_range_start_value_changed
00589 (GtkSpinButton *spinbutton,
00590 gpointer user_data)
00591 {
00592 gtk_entry_set_text( GTK_ENTRY( lookup_widget( GTK_WIDGET( spinbutton ), "entry_export_start" ) ),
00593 common->getTime().parseFramesToString( ( int )gtk_spin_button_get_value( spinbutton ),
00594 common->getTimeFormat() ).c_str() );
00595 }
00596
00597
00598 void
00599 on_spinbutton_export_range_end_value_changed
00600 (GtkSpinButton *spinbutton,
00601 gpointer user_data)
00602 {
00603 gtk_entry_set_text( GTK_ENTRY( lookup_widget( GTK_WIDGET( spinbutton ), "entry_export_end" ) ),
00604 common->getTime().parseFramesToString( ( int )gtk_spin_button_get_value( spinbutton ),
00605 common->getTimeFormat() ).c_str() );
00606 }
00607
00608 void
00609 on_entry_export_start_activate (GtkEntry *entry,
00610 gpointer user_data)
00611 {
00612 common->getTime().parseValueToString( gtk_entry_get_text( entry ), common->getTimeFormat() );
00613 GtkSpinButton *spinbutton = GTK_SPIN_BUTTON( lookup_widget( GTK_WIDGET( entry ), "spinbutton_export_range_start" ) );
00614 gtk_spin_button_set_value( spinbutton, common->getTime().getFrames() );
00615 on_spinbutton_export_range_start_value_changed( spinbutton, NULL );
00616 }
00617
00618 gboolean
00619 on_entry_export_start_focus_out_event (GtkWidget *widget,
00620 GdkEventFocus *event,
00621 gpointer user_data)
00622 {
00623 on_entry_export_start_activate( GTK_ENTRY( widget ), NULL );
00624 g_nav_ctl.escaped = FALSE;
00625 return FALSE;
00626 }
00627
00628 void
00629 on_entry_export_end_activate (GtkEntry *entry,
00630 gpointer user_data)
00631 {
00632 common->getTime().parseValueToString( gtk_entry_get_text( entry ), common->getTimeFormat() );
00633 GtkSpinButton *spinbutton = GTK_SPIN_BUTTON( lookup_widget( GTK_WIDGET( entry ), "spinbutton_export_range_end" ) );
00634 gtk_spin_button_set_value( spinbutton, common->getTime().getFrames() );
00635 on_spinbutton_export_range_end_value_changed( spinbutton, NULL );
00636 }
00637
00638 gboolean
00639 on_entry_export_end_focus_out_event (GtkWidget *widget,
00640 GdkEventFocus *event,
00641 gpointer user_data)
00642 {
00643 on_entry_export_end_activate( GTK_ENTRY( widget ), NULL );
00644 g_nav_ctl.escaped = FALSE;
00645 return FALSE;
00646 }
00647 }