00001 #include "vuKeyFramerDialog.h"
00002 #include <wx/colordlg.h>
00003
00004 #include <fstream.h>
00005 #include <iostream.h>
00006 #include <GL/gl.h>
00007 #include <GL/glu.h>
00008 #include <math.h>
00009 #include <stdio.h>
00010
00011 #include "../vuTransferCanvas.h"
00012
00013 #include "vuColourRGBa.h"
00014
00015 #ifndef DEBUGMSG
00016 #define DEBUGMSG cout << __FILE__ << ":" << __LINE__<<":" << endl
00017 #endif
00018
00019
00020
00021
00022
00023 BEGIN_EVENT_TABLE (vuKeyFramerDialog, wxFrame)
00024 EVT_BUTTON (vuKeyFramerDialog::idAUTOSHOT, vuKeyFramerDialog::OnAutoShot)
00025 EVT_BUTTON (vuKeyFramerDialog::idCLOSE, vuKeyFramerDialog::OnClose)
00026 EVT_BUTTON (vuKeyFramerDialog::idFASTFORWARD, vuKeyFramerDialog::OnFastForward)
00027 EVT_BUTTON (vuKeyFramerDialog::idLOAD, vuKeyFramerDialog::OnLoad)
00028 EVT_BUTTON (vuKeyFramerDialog::idPAUSE, vuKeyFramerDialog::OnPause)
00029 EVT_BUTTON (vuKeyFramerDialog::idPLAY, vuKeyFramerDialog::OnPlay)
00030 EVT_BUTTON (vuKeyFramerDialog::idPLAYFROMIMAGES, vuKeyFramerDialog::OnPlayFromImages)
00031 EVT_BUTTON (vuKeyFramerDialog::idRECORD, vuKeyFramerDialog::OnRecord)
00032 EVT_BUTTON (vuKeyFramerDialog::idREWIND, vuKeyFramerDialog::OnRewind)
00033 EVT_BUTTON (vuKeyFramerDialog::idSAVE, vuKeyFramerDialog::OnSave)
00034 EVT_BUTTON (vuKeyFramerDialog::idSTOP, vuKeyFramerDialog::OnStop)
00035 EVT_BUTTON (vuKeyFramerDialog::idTAKESHOT, vuKeyFramerDialog::OnTakeShot)
00036
00037
00038
00039
00040
00041
00042
00043 EVT_CHECKBOX (vuKeyFramerDialog::idKFBOUNCE, vuKeyFramerDialog::OnKFBounce)
00044 EVT_CHECKBOX (vuKeyFramerDialog::idKFLOOP, vuKeyFramerDialog::OnKFLoop)
00045 EVT_CHECKBOX (vuKeyFramerDialog::idKFSELECT, vuKeyFramerDialog::OnKFSelect)
00046 EVT_CHECKBOX (vuKeyFramerDialog::idVIDSELECT, vuKeyFramerDialog::OnVideoSelect)
00047
00048
00049 END_EVENT_TABLE ()
00050
00051
00052
00053
00054
00055 wxSize defsize (200, 200);
00056
00057 vuKeyFramerDialog::vuKeyFramerDialog (wxWindow *parent, vuCamera *cam, vuBasicUtility *UWin)
00058 : wxFrame (parent, -1, wxString ("Key Frame Editor")),
00059
00060
00061 mb_fast_forward (false),
00062 mb_imgs_loaded (false),
00063 mb_loaded (false),
00064 mb_pause (false),
00065 mb_play (false),
00066 mb_play_from_images (false),
00067 mb_record (false),
00068 mb_rewind (false),
00069 mb_run (false),
00070 mb_stop (false),
00071 mb_video_bounce (false),
00072 mb_video_fast_forward (false),
00073 mb_video_loop (false),
00074 mb_video_pause (false),
00075 mb_video_reverse (false),
00076 mb_video_rewind (false),
00077 m_play_video_buf (NULL),
00078 m_img_fstart (NULL),
00079 m_imgfp (NULL),
00080 m_currentframe (0),
00081 m_play_video_frame (0),
00082 m_Gui (UWin),
00083 m_camera (cam),
00084 m_play_camera_1 (NULL),
00085 m_play_camera_2 (NULL)
00086
00087 {
00088
00089
00090
00091
00092
00093 vuEvtGenerator* t_timer = new vuEvtGenerator [1];
00094
00095 m_play_counter = 0;
00096
00097 t_timer->setKeyFramer (this);
00098
00099 m_PlayTimer = (void *) t_timer;
00100
00101
00102 m_MainSizer = new wxBoxSizer (wxHORIZONTAL);
00103
00104 wxBoxSizer *vlefSizer = new wxBoxSizer (wxVERTICAL);
00105
00106
00107
00108 wxBoxSizer *firstbar = new wxBoxSizer (wxHORIZONTAL);
00109 wxBoxSizer *kfplaybar = new wxBoxSizer (wxHORIZONTAL);
00110
00111 wxBoxSizer *recbar = new wxBoxSizer (wxHORIZONTAL);
00112 wxBoxSizer *loadbar = new wxBoxSizer (wxHORIZONTAL);
00113 wxBoxSizer *infobar = new wxBoxSizer (wxHORIZONTAL);
00114
00115 wxBoxSizer *kfloopbar = new wxBoxSizer (wxHORIZONTAL);
00116
00117 wxBoxSizer *topbar = new wxBoxSizer (wxHORIZONTAL);
00118 wxBoxSizer *openbar = new wxBoxSizer (wxVERTICAL);
00119 wxBoxSizer *statbar = new wxBoxSizer (wxVERTICAL);
00120
00121
00122 wxSize size (80, -1);
00123 wxSize halfsize (40, -1);
00124
00125
00126
00127 m_time_delay = new wxTextCtrl ((wxCHILDWINDOW *) (this), -1, "1.00", wxPoint (235, 70), halfsize, 0,
00128 wxTextValidator (wxFILTER_NUMERIC));
00129
00130 m_fm_rate = new wxStaticText (this ,-1 , wxString (vuKF_default_fm_rate_msg_), wxPoint (195, 70),size, 0);
00131
00132 m_fm_rate_txt = new wxStaticText (this, -1, wxString (vuKF_default_fm_rate_msg_), wxPoint (200, 155), size, 0);
00133
00134 m_frames_played_txt = new wxStaticText (this, -1, wxString (vuKF_frames_played_msg_), wxPoint (200, 170), wxSize (145, -1), 0);
00135
00136 m_kf_status_txt = new wxStaticText (this, -1, wxString (vuKF_status_msg), wxPoint (200, 140), size, 0);
00137
00138 m_loaded_txt = new wxStaticText (this, -1, wxString (vuKF_default_curr_loaded_msg), wxPoint (5, 190), wxSize (200, -1), 0);
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 m_total_time = new wxStaticText (this, -1, wxString (vuKF_render_time_msg), wxPoint (200, 185), size, 0);
00150
00151
00152 m_close = new wxButton (this, idCLOSE, "Close", wxPoint (55, 140), wxSize (45, 20));
00153
00154
00155 m_fastforward = new wxBitmapButton (this, idFASTFORWARD, wxBitmap ("vuGui/wxUIElements/vuKeyFramerDialog/ff.bmp", wxBITMAP_TYPE_BMP), wxPoint (330, 30), wxSize (55, 25));
00156 m_load = new wxButton (this, idLOAD, "Open", wxPoint (5, 140), wxSize (45, 20));
00157 m_play = new wxBitmapButton (this, idPLAY, wxBitmap ("vuGui/wxUIElements/vuKeyFramerDialog/play.bmp", wxBITMAP_TYPE_BMP), wxPoint (70, 30), wxSize (55, 25));
00158 m_pause = new wxBitmapButton (this, idPAUSE, wxBitmap ("vuGui/wxUIElements/vuKeyFramerDialog/pause.bmp", wxBITMAP_TYPE_BMP), wxPoint (135, 30), wxSize (55, 25));
00159 m_record = new wxBitmapButton (this, idRECORD, wxBitmap ("vuGui/wxUIElements/vuKeyFramerDialog/rec.bmp", wxBITMAP_TYPE_BMP), wxPoint (265, 30), wxSize (55, 25));
00160 m_rewind = new wxBitmapButton (this, idREWIND, wxBitmap ("vuGui/wxUIElements/vuKeyFramerDialog/rew.bmp", wxBITMAP_TYPE_BMP), wxPoint (3, 30), wxSize (55, 25));
00161 m_stop = new wxBitmapButton (this, idSTOP, wxBitmap ("vuGui/wxUIElements/vuKeyFramerDialog/stop.bmp", wxBITMAP_TYPE_BMP), wxPoint (200, 30), wxSize (55, 25));
00162 m_takeshot = new wxButton (this, idTAKESHOT, "Take", wxPoint (5, 165), wxSize (45, 20));
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 m_burstplay = new wxCheckBox (this, idBURSTPLAY, "Max Speed/Key Frames Only", wxPoint (5, 90));
00174 m_kf_bounce = new wxCheckBox (this, idKFBOUNCE, wxString (vuKF_bounce_msg), wxPoint (320, 90));
00175 m_kf_loop = new wxCheckBox (this, idKFLOOP, wxString (vuKF_loop_msg), wxPoint (320, 70));
00176 m_kf_txt = new wxCheckBox (this, idKFSELECT, "KeyFrame", wxPoint (5, 5), size, 0);
00177 m_genimages = new wxCheckBox (this, idGENIMAGES, "Save Animation", wxPoint (5, 70));
00178
00179 m_save = new wxButton (this, idSAVE, "Save", wxPoint (105, 140), wxSize (45, 20));
00180
00181
00182 m_vid_txt = new wxCheckBox (this, idVIDSELECT, "Video", wxPoint (320, 5),size, 0);
00183
00184 m_divider = new wxPanel (this, -1, wxPoint (190, 135), wxSize (2, 100), wxSUNKEN_BORDER);
00185 m_divider2 = new wxPanel (this, -1, wxPoint (5, 130), wxSize (400, 2), wxSUNKEN_BORDER);
00186
00187
00188 topbar->Add (m_kf_txt, 0);
00189 topbar->Add (200, 0);
00190 topbar->Add (m_vid_txt, 0);
00191
00192 kfplaybar->Add (m_rewind, 0);
00193 kfplaybar->Add (10, 0);
00194 kfplaybar->Add (m_play, 0);
00195 kfplaybar->Add (10, 0);
00196 kfplaybar->Add (m_pause, 0);
00197 kfplaybar->Add (10, 0);
00198 kfplaybar->Add (m_record, 0);
00199 kfplaybar->Add (10, 0);
00200 kfplaybar->Add (m_stop, 0);
00201 kfplaybar->Add (10, 0);
00202 kfplaybar->Add (m_fastforward, 0);
00203 kfplaybar->Add (10, 0);
00204
00205 firstbar->Add (m_genimages);
00206 firstbar->Add (20, 0);
00207 firstbar->Add (m_fm_rate, 0);
00208 firstbar->Add (m_time_delay, 0);
00209 firstbar->Add (20, 0);
00210 firstbar->Add (m_kf_bounce, 0);
00211
00212 recbar->Add (m_takeshot, 0);
00213
00214
00215
00216 loadbar->Add (m_load, 0);
00217 loadbar->Add (5, 0);
00218 loadbar->Add (m_close, 0);
00219 loadbar->Add (5, 0);
00220 loadbar->Add (m_save, 0);
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 kfloopbar->Add (m_burstplay, 0);
00236 kfloopbar->Add (85, 0);
00237 kfloopbar->Add (m_kf_loop, 0);
00238
00239 vlefSizer->Add (0, 5);
00240 vlefSizer->Add (topbar, 0, wxEXPAND);
00241 vlefSizer->Add (0, 5);
00242 vlefSizer->Add (kfplaybar, 0);
00243 vlefSizer->Add (0, 5);
00244 vlefSizer->Add (firstbar, 0, wxEXPAND);
00245 vlefSizer->Add (0, 5);
00246 vlefSizer->Add (kfloopbar, 0, wxEXPAND);
00247 vlefSizer->Add (0, 5);
00248 vlefSizer->Add (m_divider2, 0);
00249 vlefSizer->Add (0, 5);
00250
00251 openbar->Add (loadbar, 0);
00252 openbar->Add (0, 5);
00253 openbar->Add (m_takeshot, 0);
00254 openbar->Add (0, 5);
00255 openbar->Add (m_loaded_txt, 0);
00256 openbar->Add (0, 5);
00257 openbar->Add (m_kf_status_txt, 0);
00258 openbar->Add (0, 5);
00259
00260 statbar->Add (m_total_time, 0);
00261 statbar->Add (0, 5);
00262 statbar->Add (m_fm_rate_txt, 0);
00263 statbar->Add (0, 5);
00264 statbar->Add (m_frames_played_txt, 0);
00265
00266 infobar->Add (openbar, 0);
00267 infobar->Add (5, 0);
00268 infobar->Add (m_divider, 0);
00269 infobar->Add (5, 0);
00270 infobar->Add (statbar, 0);
00271
00272 vlefSizer->Add (infobar, 0);
00273 vlefSizer->Add (0, 5);
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 m_MainSizer->Add (5, 0);
00306 m_MainSizer->Add (vlefSizer, 1, wxEXPAND);
00307
00308
00309
00310
00311
00312
00313
00314 SetSizer (m_MainSizer);
00315 SetAutoLayout (true);
00316
00317 m_MainSizer->SetSizeHints (this);
00318 m_MainSizer->Fit (this);
00319
00320
00321 m_playwatch.setFastSpeed (vuKF_spd_mul);
00322 m_vid_play_timer.setFastSpeed (vuKF_spd_mul);
00323
00324 m_kf_txt->SetValue (true);
00325 m_vid_txt->SetValue (false);
00326
00327
00328 m_takeshot->Disable ();
00329 m_save->Disable ();
00330 }
00331
00332 vuKeyFramerDialog::~vuKeyFramerDialog ()
00333
00334 {
00335 vuEvtGenerator *temp;
00336 temp = (vuEvtGenerator *) (m_PlayTimer);
00337
00338 delete [] temp;
00339
00340 if (int (m_camera_vector.getLength ()) > 0)
00341
00342 {
00343 for (int i = 0; i < int (m_camera_vector.getLength ()); i++)
00344 delete [] m_camera_vector [i];
00345
00346 m_camera_vector.removeRange (0, m_camera_vector.getLength () - 1);
00347 }
00348
00349 if (int (tfilenamevector.getLength ()) > 0)
00350
00351 {
00352 for (int i = 0; i < int (tfilenamevector.getLength ()); i++)
00353 delete [] tfilenamevector [i];
00354
00355 tfilenamevector.removeRange (0, tfilenamevector.getLength () - 1);
00356 }
00357 }
00358
00359 void vuKeyFramerDialog::setup (vuCamera *cam, vuBasicUtility *UWin)
00360
00361 {
00362 m_camera = cam;
00363 m_Gui = UWin;
00364 }
00365
00366 void vuKeyFramerDialog::Close ()
00367
00368 {
00369 Show (false);
00370 }
00371
00372 bool vuKeyFramerDialog::Destroy ()
00373
00374 {
00375 Show (false);
00376 return true;
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386 bool vuKeyFramerDialog::IsFastForwarding ()
00387
00388 {
00389 return mb_fast_forward;
00390 }
00391
00392 bool vuKeyFramerDialog::IsImgsLoaded ()
00393
00394 {
00395 return mb_imgs_loaded;
00396 }
00397
00398 bool vuKeyFramerDialog::IsKFBouncing ()
00399
00400 {
00401 return m_kf_bounce->GetValue ();
00402 }
00403
00404 bool vuKeyFramerDialog::IsKFLooping ()
00405
00406 {
00407 return m_kf_loop->GetValue ();
00408 }
00409
00410 bool vuKeyFramerDialog::IsKFReversing ()
00411
00412 {
00413 return mb_kf_reverse;
00414 }
00415
00416 bool vuKeyFramerDialog::IsLoaded ()
00417
00418 {
00419 return mb_loaded;
00420 }
00421
00422 bool vuKeyFramerDialog::IsPaused ()
00423
00424 {
00425 return mb_pause;
00426 }
00427
00428 bool vuKeyFramerDialog::IsPlaying ()
00429
00430 {
00431 return mb_play;
00432 }
00433
00434 bool vuKeyFramerDialog::IsPlayingImgs ()
00435
00436 {
00437 return mb_play_from_images;
00438 }
00439
00440 bool vuKeyFramerDialog::IsRecording ()
00441
00442 {
00443 return mb_record;
00444 }
00445
00446 bool vuKeyFramerDialog::IsRewinding ()
00447
00448 {
00449 return mb_rewind;
00450 }
00451
00452 bool vuKeyFramerDialog::IsStopped ()
00453
00454 {
00455 return mb_stop;
00456 }
00457
00458 bool vuKeyFramerDialog::IsVideoFastForwarding ()
00459
00460 {
00461 return mb_video_fast_forward;
00462 }
00463
00464 bool vuKeyFramerDialog::IsVideoPaused ()
00465
00466 {
00467 return mb_video_pause;
00468 }
00469
00470 bool vuKeyFramerDialog::IsVideoPlaying ()
00471
00472 {
00473 return IsPlayingImgs ();
00474 }
00475
00476 bool vuKeyFramerDialog::IsVideoBouncing ()
00477
00478 {
00479
00480
00481
00482 return ((m_kf_bounce->GetValue ()) && (m_vid_txt->GetValue ()));
00483 }
00484
00485 bool vuKeyFramerDialog::IsVideoLooping ()
00486
00487 {
00488
00489
00490
00491 return ((m_kf_loop->GetValue ()) && (m_vid_txt->GetValue ()));
00492 }
00493
00494 bool vuKeyFramerDialog::IsVideoReversing ()
00495
00496 {
00497 return mb_video_reverse;
00498 }
00499
00500 bool vuKeyFramerDialog::IsVideoRewinding ()
00501
00502 {
00503 return mb_video_rewind;
00504 }
00505
00506
00507
00508 void vuKeyFramerDialog::run (int whatsup, void* data)
00509
00510 {
00511 if (mb_run)
00512 return;
00513
00514 mb_run = true;
00515
00516 wxCommandEvent temp;
00517
00518 if (mb_stop)
00519
00520 {
00521 OnStop (temp);
00522 }
00523
00524 if (mb_pause)
00525
00526 {
00527 OnPause (temp);
00528 }
00529
00530 if ((mb_play) && (!mb_pause) && (!mb_stop))
00531
00532 {
00533 cout << "playtime" << endl;
00534
00535 PlayFunc ();
00536 }
00537
00538 if ((mb_record) && (!mb_pause) && (!mb_stop))
00539
00540 {
00541 }
00542
00543 mb_run = false;
00544 }
00545
00546
00547
00548 void vuKeyFramerDialog::setIsFastForwarding (bool isit)
00549
00550 {
00551 mb_fast_forward = isit;
00552
00553 m_playwatch.setIsFastForwarding (isit);
00554
00555 if (isit)
00556
00557 {
00558 setIsRewinding (false);
00559 setIsKFReversing (false);
00560
00561 }
00562 }
00563
00564 void vuKeyFramerDialog::setIsImgsLoaded (bool isit)
00565
00566 {
00567 mb_imgs_loaded = isit;
00568 }
00569
00570 void vuKeyFramerDialog::setIsKFBouncing (bool isit)
00571
00572 {
00573 m_kf_bounce->SetValue (isit);
00574
00575 m_playwatch.setIsBouncing (isit);
00576
00577 if (isit)
00578 m_kf_loop->SetValue (isit);
00579 }
00580
00581 void vuKeyFramerDialog::setIsKFLooping (bool isit)
00582
00583 {
00584 m_kf_loop->SetValue (isit);
00585
00586 m_playwatch.setIsLooping (isit);
00587
00588 if (isit)
00589 m_kf_bounce->SetValue (isit);
00590 }
00591
00592 void vuKeyFramerDialog::setIsKFReversing (bool isit)
00593
00594 {
00595 mb_kf_reverse = isit;
00596
00597 m_playwatch.setIsReversing (true);
00598
00599 if (isit)
00600
00601 {
00602 setIsRewinding (false);
00603 setIsFastForwarding (false);
00604 }
00605 }
00606
00607 void vuKeyFramerDialog::setIsLoaded (bool isit)
00608
00609 {
00610 mb_loaded = isit;
00611 }
00612
00613 void vuKeyFramerDialog::setIsPaused (bool isit)
00614
00615 {
00616 mb_pause = isit;
00617
00618 if (isit)
00619 m_playwatch.Pause ();
00620 else
00621 m_playwatch.Resume ();
00622 }
00623
00624 void vuKeyFramerDialog::setIsPlaying (bool isit)
00625
00626 {
00627 mb_play = isit;
00628
00629 m_playwatch.Resume ();
00630
00631 if (isit)
00632
00633 {
00634 setIsRewinding (false);
00635 setIsKFReversing (false);
00636 setIsFastForwarding (false);
00637 }
00638 }
00639
00640 void vuKeyFramerDialog::setIsPlayingImgs (bool isit)
00641
00642 {
00643 mb_play_from_images = isit;
00644 }
00645
00646 void vuKeyFramerDialog::setIsRecording (bool isit)
00647
00648 {
00649 mb_record = isit;
00650 }
00651
00652 void vuKeyFramerDialog::setIsVideoBouncing (bool isit)
00653
00654 {
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664 m_vid_play_timer.setIsBouncing (isit);
00665 }
00666
00667 void vuKeyFramerDialog::setIsVideoFastForwarding (bool isit)
00668
00669 {
00670 mb_video_fast_forward = isit;
00671 m_vid_play_timer.setIsFastForwarding (isit);
00672
00673 if (isit)
00674
00675 {
00676 setIsVideoRewinding (false);
00677 setIsVideoReversing (false);
00678 }
00679 }
00680
00681 void vuKeyFramerDialog::setIsVideoLooping (bool isit)
00682
00683 {
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693 m_vid_play_timer.setIsLooping (isit);
00694 }
00695
00696 void vuKeyFramerDialog::setIsVideoPaused (bool isit)
00697
00698 {
00699 mb_video_pause = isit;
00700
00701 if (isit)
00702 m_vid_play_timer.Pause ();
00703 else
00704 m_vid_play_timer.Resume ();
00705 }
00706
00707 void vuKeyFramerDialog::setIsVideoPlaying (bool isit)
00708
00709 {
00710 setIsPlayingImgs (isit);
00711
00712 if (isit)
00713
00714 {
00715 setIsVideoRewinding (false);
00716 setIsVideoReversing (false);
00717 setIsVideoFastForwarding (false);
00718 }
00719 }
00720
00721 void vuKeyFramerDialog::setIsVideoRewinding (bool isit)
00722
00723 {
00724 m_vid_play_timer.setIsRewinding (isit);
00725 mb_video_rewind = isit;
00726
00727 if (isit)
00728
00729 {
00730 setIsVideoReversing (false);
00731 setIsVideoFastForwarding (false);
00732 }
00733 }
00734
00735 void vuKeyFramerDialog::setIsVideoReversing (bool isit)
00736
00737 {
00738 mb_video_reverse = isit;
00739
00740 m_vid_play_timer.setIsReversing (isit);
00741
00742 if (isit)
00743
00744 {
00745 setIsVideoRewinding (false);
00746 setIsVideoFastForwarding (false);
00747 }
00748 }
00749
00750 void vuKeyFramerDialog::setIsRewinding (bool isit)
00751
00752 {
00753 mb_rewind = isit;
00754
00755 m_playwatch.setIsRewinding (isit);
00756
00757 if (isit)
00758
00759 {
00760 setIsKFReversing (false);
00761 setIsFastForwarding (false);
00762 }
00763 }
00764
00765 void vuKeyFramerDialog::setIsStopped (bool isit)
00766
00767 {
00768 mb_stop = isit;
00769 }
00770
00771 void vuKeyFramerDialog::OnAutoShot (wxCommandEvent &ev)
00772
00773 {
00774 }
00775
00776 void vuKeyFramerDialog::OnClose (wxCommandEvent &ev)
00777
00778 {
00779 if (m_vid_txt->GetValue ())
00780
00781 {
00782 OnVideoClose (ev);
00783
00784
00785 }
00786
00787 if ((!IsLoaded ()) && (!IsRecording ()))
00788 return;
00789
00790 if (IsPlaying ())
00791
00792 {
00793
00794
00795
00796
00797
00798 OnStop (ev);
00799 }
00800
00801 if (IsRecording ())
00802
00803 {
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817 OnSave (ev);
00818 }
00819
00820 m_camera_vector.removeRange (0, m_camera_vector.getLength ());
00821 m_time_vector.removeRange (0, m_time_vector.getLength ());
00822
00823 setIsLoaded (false);
00824 setIsRecording (false);
00825 setIsPlaying (false);
00826
00827 m_save->Disable ();
00828 m_takeshot->Disable ();
00829
00830 m_loaded_txt->SetLabel (wxString (vuKF_default_curr_loaded_msg));
00831
00832 return;
00833 }
00834
00835 void vuKeyFramerDialog::OnFastForward (wxCommandEvent &ev)
00836
00837 {
00838 if (m_vid_txt->GetValue ())
00839
00840 {
00841 OnVideoFastForward (ev);
00842
00843 return;
00844 }
00845
00846 if (!IsPlaying ())
00847 OnPlay (ev);
00848
00849
00850 if (IsRewinding ())
00851 OnRewind (ev);
00852
00853 if (IsPaused ())
00854 OnPause (ev);
00855
00856 if (IsKFReversing ())
00857 m_playwatch.setIsReversing (false);
00858
00859 if (IsFastForwarding ())
00860 cout << "fastforwarding" << endl;
00861 else
00862 cout << "not fastforwarding" << endl;
00863
00864 setIsFastForwarding (!IsFastForwarding ());
00865
00866 if (IsFastForwarding ())
00867
00868 {
00869 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Fast Forwarding"));
00870
00871
00872 m_playwatch.setIsFastForwarding (true);
00873 }
00874
00875 else
00876
00877 {
00878 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
00879
00880 m_playwatch.setIsFastForwarding (false);
00881 }
00882
00883 cout << "OnFastForward" << endl;
00884 }
00885
00886 void vuKeyFramerDialog::OnKFBounce (wxCommandEvent &ev)
00887
00888 {
00889 if (m_vid_txt->GetValue ())
00890
00891 {
00892 OnVideoBounce (ev);
00893
00894
00895 }
00896
00897 if (m_kf_bounce->GetValue ())
00898 m_kf_loop->SetValue (false);
00899
00900 m_playwatch.setIsBouncing (m_kf_bounce->GetValue ());
00901 m_playwatch.setIsLooping (false);
00902
00903 m_vid_play_timer.setIsBouncing (m_kf_bounce->GetValue ());
00904 m_vid_play_timer.setIsLooping (false);
00905 }
00906
00907 void vuKeyFramerDialog::OnKFLoop (wxCommandEvent &ev)
00908
00909 {
00910 if (m_vid_txt->GetValue ())
00911
00912 {
00913 OnVideoLoop (ev);
00914
00915
00916 }
00917
00918 if (m_kf_loop->GetValue ())
00919 m_kf_bounce->SetValue (false);
00920
00921 m_playwatch.setIsLooping (m_kf_loop->GetValue ());
00922 m_playwatch.setIsBouncing (false);
00923
00924 m_vid_play_timer.setIsLooping (m_kf_loop->GetValue ());
00925 m_vid_play_timer.setIsBouncing (false);
00926 }
00927
00928 void vuKeyFramerDialog::OnKFSelect (wxCommandEvent &ev)
00929
00930 {
00931 if (m_vid_txt->GetValue ())
00932
00933 {
00934 m_vid_txt->SetValue (false);
00935
00936 m_genimages->Enable (true);
00937 m_burstplay->Enable (true);
00938 m_record->Enable (true);
00939
00940 m_kf_bounce->SetValue (false);
00941 m_kf_loop->SetValue (false);
00942
00943
00944
00945
00946 OnVideoStop (ev);
00947 OnVideoClose (ev);
00948 }
00949
00950 else
00951
00952 {
00953 m_vid_txt->SetValue (true);
00954
00955 m_genimages->Disable ();
00956 m_burstplay->Disable ();
00957 m_record->Disable ();
00958 m_takeshot->Disable ();
00959 m_save->Disable ();
00960
00961
00962
00963
00964 OnStop (ev);
00965 OnClose (ev);
00966 }
00967 }
00968
00969 void vuKeyFramerDialog::OnLoad (wxCommandEvent &ev)
00970
00971 {
00972 if (m_vid_txt->GetValue ())
00973
00974 {
00975 OnVideoLoad (ev);
00976
00977 return;
00978 }
00979
00980 if (IsLoaded ())
00981
00982 {
00983
00984
00985
00986
00987
00988 OnClose (ev);
00989 }
00990
00991 if (IsRecording ())
00992
00993 {
00994
00995
00996
00997
00998 OnSave (ev);
00999 }
01000
01001 LoadFunc ();
01002 }
01003
01004 void vuKeyFramerDialog::OnPause (wxCommandEvent &ev)
01005
01006 {
01007 if (m_vid_txt->GetValue ())
01008
01009 {
01010 OnVideoPause (ev);
01011
01012 return;
01013 }
01014
01015 setIsPaused (!IsPaused ());
01016
01017 if (IsPaused ())
01018 m_playwatch.Pause ();
01019 else
01020 m_playwatch.Resume ();
01021 }
01022
01023 void vuKeyFramerDialog::OnPlay (wxCommandEvent &ev)
01024
01025 {
01026 if (m_vid_txt->GetValue ())
01027
01028 {
01029 OnPlayFromImages (ev);
01030
01031 return;
01032 }
01033
01034 if (IsPlaying ())
01035
01036 {
01037 wxCommandEvent ev;
01038
01039 bool retval = false;
01040
01041 if (IsPaused ())
01042
01043 {
01044 OnPause (ev);
01045
01046 retval = true;
01047 }
01048
01049 if (IsRewinding ())
01050
01051 {
01052 OnRewind (ev);
01053
01054 retval = true;
01055 }
01056
01057 if (IsFastForwarding ())
01058
01059 {
01060 OnFastForward (ev);
01061
01062 return;
01063 }
01064
01065 if (IsKFReversing ())
01066
01067 {
01068 setIsKFReversing (false);
01069
01070 return;
01071 }
01072
01073 if (retval)
01074 return;
01075
01076
01077
01078
01079
01080 return;
01081 }
01082
01083 setIsPaused (false);
01084 setIsStopped (false);
01085
01086
01087 if (IsPlaying ())
01088 return;
01089
01090 if (IsRecording ())
01091
01092 {
01093 wxMessageDialog temp (this, "Cannot play a key frame file while another is recording. \n Please stop this file before reocrding to another.", "Play Error!", wxOK);
01094
01095 temp.ShowModal ();
01096
01097 return;
01098 }
01099
01100 if (m_camera == NULL)
01101
01102 {
01103 wxMessageDialog temp (this, "Cannot play a key frame file when the rendering method gives me a NULL pointer to a camera. \n Please fix the return value of this functions before continue.", "Play Error!", wxOK);
01104
01105 temp.ShowModal ();
01106
01107 return;
01108 }
01109
01110 wxCommandEvent ttemp;
01111
01112 if (!IsLoaded ())
01113 OnLoad (ttemp);
01114
01115 if (!IsLoaded ())
01116 return;
01117
01118 mb_play = true;
01119
01120
01121
01122
01123 #ifndef WIN32
01124 if (!XInitThreads ())
01125 cout << "X initialization failed" << endl;
01126 #endif
01127
01128 run (10, NULL);
01129 }
01130
01131 void vuKeyFramerDialog::OnPlayFromImages (wxCommandEvent &ev)
01132
01133 {
01134 cout << "PlayFromImages " << endl;
01135
01136 if (IsVideoPlaying ())
01137
01138 {
01139 cout << "VideoIsPlaying" << endl;
01140 setIsVideoPlaying (true);
01141 return;
01142 }
01143
01144 if (IsVideoFastForwarding ())
01145
01146 {
01147 setIsVideoFastForwarding (false);
01148
01149 return;
01150 }
01151
01152 if (IsVideoRewinding ())
01153
01154 {
01155 setIsVideoRewinding (false);
01156
01157 return;
01158 }
01159
01160 if (IsVideoPaused ())
01161
01162 {
01163 setIsVideoPaused (false);
01164
01165 return;
01166 }
01167
01168 if (IsPlaying ())
01169
01170 {
01171 wxMessageDialog temp (this, "Already Playing a Key Frame animation, \n can't play a prerendered animation as well.", "Load Error!", wxOK);
01172
01173 temp.ShowModal ();
01174
01175 return;
01176 }
01177
01178 if (IsPlayingImgs ())
01179
01180 {
01181
01182
01183
01184
01185
01186 return;
01187 }
01188
01189 if (IsRecording ())
01190
01191 {
01192 wxMessageDialog temp (this, "Already Recording a Key Frame file, \n can't play while this is happening.", "Load Error!", wxOK);
01193
01194 temp.ShowModal ();
01195
01196 return;
01197 }
01198
01199 if (m_Gui->getCurrentImage () == NULL)
01200
01201 {
01202 wxMessageDialog temp (this, "Cannot play a prerendered video without an image buffer to write to. \n Please fix the return value of the rendering method's getCurrentImage () so that this can work.");
01203
01204 temp.ShowModal ();
01205
01206 return;
01207 }
01208
01209 setIsPlayingImgs (true);
01210
01211 PlayFromImages ();
01212 }
01213
01214 void vuKeyFramerDialog::OnRecord(wxCommandEvent &ev)
01215
01216 {
01217 if (IsRecording ())
01218
01219 {
01220 wxMessageDialog temp (this, "Cannot record to a file while another is being recorded to. \n Please save or close the current recording before recording to a new file.", "Load Error!", wxOK);
01221 temp.ShowModal ();
01222
01223 return;
01224 }
01225
01226 if (IsLoaded ())
01227
01228 {
01229 wxMessageDialog temp (this, "Cannot record to a file while another is loaded. \n Please save or close the currently loaded file before recording to a new file.", "Load Error!", wxOK);
01230 temp.ShowModal ();
01231
01232 return;
01233 }
01234
01235 RecordFunc ();
01236
01237 setIsRecording (true);
01238 setIsPaused (false);
01239
01240 m_takeshot->Enable (true);
01241 m_save->Enable (true);
01242 }
01243
01244 void vuKeyFramerDialog::OnRewind (wxCommandEvent &ev)
01245
01246 {
01247 if (m_vid_txt->GetValue ())
01248
01249 {
01250 OnVideoRewind (ev);
01251
01252 return;
01253 }
01254
01255 if (!IsPlaying ())
01256 OnPlay (ev);
01257
01258 if (IsFastForwarding ())
01259 OnFastForward (ev);
01260
01261 if (IsPaused ())
01262 OnPause (ev);
01263
01264 if (IsKFReversing ())
01265 m_playwatch.setIsReversing (false);
01266
01267 setIsRewinding (!IsRewinding ());
01268
01269 if (IsRewinding ())
01270
01271 {
01272 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Rewinding"));
01273
01274
01275 m_playwatch.setIsRewinding (true);
01276 }
01277
01278 else
01279
01280 {
01281 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
01282
01283 m_playwatch.setIsRewinding (false);
01284 }
01285 }
01286
01287 void vuKeyFramerDialog::OnSave (wxCommandEvent &ev)
01288
01289 {
01290 if ((!IsRecording ()) && (!IsLoaded ()))
01291
01292 {
01293 wxMessageDialog temp (this, "No key frame file has been loaded.\n On must be loaded (or recorded to) before save can take effect.", "Load Error!", wxOK);
01294
01295
01296
01297 return;
01298 }
01299
01300 if (IsLoaded ())
01301
01302 {
01303 wxMessageDialog temp (this, "Currently, this can only save modifications to Key frame files that have been recorded to.", "Load Error!", wxOK);
01304
01305 temp.ShowModal ();
01306
01307 return;
01308 }
01309
01310 wxMessageDialog temp (this, "Saving will also remove the currently loaded or recording file from memory. \n Do you wish to continue?", "Load Error!", wxYES_NO);
01311
01312
01313
01314
01315 m_save->Disable ();
01316 m_takeshot->Disable ();
01317
01318 SaveFunc (true);
01319 }
01320
01321 void vuKeyFramerDialog::OnStop(wxCommandEvent &ev)
01322
01323 {
01324
01325
01326
01327 OnVideoStop (ev);
01328
01329
01330
01331
01332 if (m_camera->IsRecording ())
01333
01334 {
01335 wxMessageDialog temp (this, "Stopping without saving could cause loss of data. \n Are you sure you wish to continue?", "Stop Error!", wxYES_NO);
01336
01337 if (temp.ShowModal () == wxID_NO)
01338 return;
01339
01340 SaveFunc (false);
01341
01342 m_camera->stop_recording ();
01343
01344 setIsRecording (false);
01345 }
01346
01347 setIsFastForwarding (false);
01348 setIsPaused (false);
01349 setIsPlaying (false);
01350 setIsRewinding (false);
01351
01352
01353 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg));
01354
01355 m_save->Disable ();
01356 m_takeshot->Disable ();
01357
01358 m_currentframe = 0;
01359 }
01360
01361 void vuKeyFramerDialog::OnTakeShot(wxCommandEvent &ev)
01362
01363 {
01364
01365 if (!IsRecording ())
01366
01367 {
01368 wxMessageDialog temp (this, "No key frame file to record to. \n Please start recording before taking snapshots.", "Snap Shot Error!", wxOK);
01369
01370 temp.ShowModal ();
01371
01372 return;
01373
01374 }
01375
01376 cout << "OnTakeShot:: taking the thing" << endl;
01377
01378
01379 time_t += m_timer.getElapsedTimeFloat ();
01380
01381
01382 m_time_vector.add (time_t);
01383 vuCamera* tcam = m_camera->create_new ();
01384 *tcam = m_camera;
01385 m_camera_vector.add (tcam);
01386 }
01387
01388 void vuKeyFramerDialog::OnVideoBounce (wxCommandEvent &ev)
01389
01390 {
01391
01392
01393
01394
01395
01396
01397
01398 m_vid_play_timer.setIsBouncing (m_kf_bounce->GetValue ());
01399 m_vid_play_timer.setIsLooping (false);
01400 }
01401
01402 void vuKeyFramerDialog::OnVideoClose (wxCommandEvent &ev)
01403
01404 {
01405 if (IsVideoPlaying ())
01406
01407 {
01408
01409
01410
01411
01412
01413 OnVideoStop (ev);
01414 }
01415
01416 if (m_imgfp != NULL)
01417
01418 {
01419 fclose (m_imgfp);
01420
01421 m_imgfp = NULL;
01422 }
01423
01424 for (int i = 0; i < int (tfilenamevector.getLength ()); i++)
01425 delete [] tfilenamevector [i];
01426
01427 tfilenamevector.removeRange (0, tfilenamevector.getLength () - 1);
01428 ttimevector.removeRange (0, ttimevector.getLength () - 1);
01429
01430
01431 m_loaded_txt->SetLabel (wxString (vuKF_default_curr_loaded_msg));
01432
01433 setIsImgsLoaded (false);
01434
01435
01436 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg));
01437 }
01438
01439 void vuKeyFramerDialog::OnVideoFastForward (wxCommandEvent &ev)
01440
01441 {
01442 if (!IsVideoPlaying ())
01443 OnPlayFromImages (ev);
01444
01445
01446 if (IsVideoPaused ())
01447 OnVideoPause (ev);
01448
01449 if (IsVideoRewinding ())
01450 OnVideoRewind (ev);
01451
01452 if (IsVideoReversing ())
01453 OnVideoReverse (ev);
01454
01455 setIsVideoFastForwarding (!IsVideoFastForwarding ());
01456
01457 if (IsVideoFastForwarding ())
01458
01459 {
01460
01461 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Fast Forwarding"));
01462
01463
01464 m_vid_play_timer.setIsFastForwarding (true);
01465 }
01466
01467 else
01468
01469 {
01470
01471 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
01472
01473 m_vid_play_timer.setIsFastForwarding (false);
01474 }
01475 }
01476
01477 void vuKeyFramerDialog::OnVideoLoad (wxCommandEvent &ev)
01478
01479 {
01480 m_imgfp = OpenGIFile ();
01481
01482 setIsImgsLoaded (true);
01483 }
01484
01485 void vuKeyFramerDialog::OnVideoLoop (wxCommandEvent &ev)
01486
01487 {
01488
01489
01490
01491
01492
01493
01494
01495 m_vid_play_timer.setIsLooping (m_kf_loop->GetValue ());
01496 m_vid_play_timer.setIsBouncing (false);
01497 }
01498
01499 void vuKeyFramerDialog::OnVideoPause (wxCommandEvent &ev)
01500
01501 {
01502 if (!IsVideoPlaying ())
01503 return;
01504
01505 setIsVideoPaused (!IsVideoPaused ());
01506
01507 if (!IsVideoPaused ())
01508
01509 {
01510 m_vid_play_timer.Resume ();
01511
01512 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
01513 }
01514
01515 else
01516
01517 {
01518 m_vid_play_timer.Pause ();
01519
01520 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Paused"));
01521 }
01522 }
01523
01524 void vuKeyFramerDialog::OnVideoPlay (wxCommandEvent &ev)
01525
01526 {
01527 if (IsPlaying ())
01528
01529 {
01530 wxMessageDialog temp (this, "Already Playing a Key Frame animation, \n can't play a prerendered animation as well.", "Load Error!", wxOK);
01531
01532 temp.ShowModal ();
01533
01534 return;
01535 }
01536
01537 if (IsPlayingImgs ())
01538
01539 {
01540 bool retnow = false;
01541 wxCommandEvent ev;
01542
01543 if (IsVideoRewinding ())
01544
01545 {
01546 OnVideoRewind (ev);
01547
01548 retnow = true;
01549 }
01550
01551 if (IsVideoFastForwarding ())
01552
01553 {
01554 OnVideoFastForward (ev);
01555
01556 retnow = true;
01557 }
01558
01559 if (IsVideoPaused ())
01560
01561 {
01562 OnVideoPause (ev);
01563
01564 return;
01565 }
01566
01567 if (IsVideoReversing ())
01568
01569 {
01570 OnVideoReverse (ev);
01571
01572 return;
01573 }
01574
01575 if (IsVideoPlaying ())
01576
01577 {
01578 OnVideoPlay (ev);
01579
01580 return;
01581 }
01582
01583 if (retnow)
01584 return;
01585
01586 wxMessageDialog temp (this, "Already Playing an animation, \n can't play another while this is happening.", "Load Error!", wxOK);
01587
01588 temp.ShowModal ();
01589
01590 return;
01591 }
01592
01593 if (IsRecording ())
01594
01595 {
01596 wxMessageDialog temp (this, "Already Recording a Key Frame file, \n can't play while this is happening.", "Load Error!", wxOK);
01597
01598 temp.ShowModal ();
01599
01600 return;
01601 }
01602
01603 setIsPlayingImgs (true);
01604 setIsVideoFastForwarding (false);
01605 setIsVideoRewinding (false);
01606
01607
01608 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
01609
01610 cout << "::PlayFromImages" << endl;
01611
01612 PlayFromImages ();
01613 }
01614
01615 void vuKeyFramerDialog::OnVideoReverse (wxCommandEvent &ev)
01616
01617 {
01618 m_vid_play_timer.setIsReversing (!m_vid_play_timer.IsReversing ());
01619
01620 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Reversing"));
01621 }
01622
01623 void vuKeyFramerDialog::OnVideoRewind (wxCommandEvent &ev)
01624
01625 {
01626 if (!IsVideoPlaying ())
01627 OnPlayFromImages (ev);
01628
01629 if (IsVideoFastForwarding ())
01630 OnVideoFastForward (ev);
01631
01632 if (IsVideoPaused ())
01633 OnVideoPause (ev);
01634
01635 if (IsVideoReversing ())
01636 OnVideoReverse (ev);
01637
01638 setIsVideoRewinding (!IsVideoRewinding ());
01639
01640 if (IsVideoRewinding ())
01641
01642 {
01643
01644 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Rewinding"));
01645
01646
01647 m_vid_play_timer.setIsRewinding (true);
01648 }
01649
01650 else
01651
01652 {
01653
01654 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
01655
01656 m_vid_play_timer.setIsRewinding (false);
01657 }
01658 }
01659
01660 void vuKeyFramerDialog::OnVideoSelect (wxCommandEvent &ev)
01661
01662 {
01663 if (m_kf_txt->GetValue ())
01664
01665 {
01666 m_kf_txt->SetValue (false);
01667
01668 m_genimages->Disable ();
01669 m_burstplay->Disable ();
01670 m_record->Disable ();
01671 m_takeshot->Disable ();
01672 m_save->Disable ();
01673
01674
01675
01676
01677 OnStop (ev);
01678 OnClose (ev);
01679 }
01680
01681 else
01682
01683 {
01684 m_kf_txt->SetValue (true);
01685
01686 m_genimages->Enable (true);
01687 m_burstplay->Enable (true);
01688 m_record->Enable (true);
01689
01690 m_kf_bounce->SetValue (false);
01691 m_kf_loop->SetValue (false);
01692
01693
01694
01695
01696 OnVideoStop (ev);
01697 OnVideoClose (ev);
01698 }
01699 }
01700
01701 void vuKeyFramerDialog::OnVideoStop (wxCommandEvent &ev)
01702
01703 {
01704 setIsPlayingImgs (false);
01705 setIsVideoRewinding (false);
01706 setIsVideoFastForwarding (false);
01707 setIsVideoPaused (false);
01708
01709
01710 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg));
01711 }
01712
01713
01714
01715 void vuKeyFramerDialog::BurstPlay ()
01716
01717 {
01718 wxStopWatch twatch;
01719
01720 twatch.Start (0);
01721
01722 for (unsigned int i = 0; i < m_camera_vector.getLength (); i++)
01723 if ((mb_play) && (!mb_stop) && (!mb_pause))
01724
01725 {
01726 *m_camera = m_camera_vector [i];
01727
01728 m_Gui->DrawAgain ();
01729 }
01730
01731 unsigned int time = twatch.Time ();
01732
01733 char tchar [20];
01734
01735 gcvt (time, 16, tchar);
01736
01737 m_total_time->SetLabel (wxString (vuKF_render_time_msg) + wxString (tchar) + wxString (" ms"));
01738
01739 float temp = float (m_camera_vector.getLength ()) / float (time);
01740
01741 gcvt (temp, vuKF_precision_digits, tchar);
01742
01743
01744
01745 gcvt (m_camera_vector.getLength (), 16, tchar);
01746
01747 m_frames_played_txt->SetLabel (wxString (vuKF_frames_played_msg_) + wxString (tchar));
01748
01749 gcvt (float (m_camera_vector.getLength () / float (time)), vuKF_precision_digits, tchar);
01750
01751 m_fm_rate_txt->SetLabel (wxString (vuKF_default_fm_rate_msg_) + wxString (tchar) + wxString ("/sec"));
01752 }
01753
01754 void vuKeyFramerDialog::BurstPlayGI ()
01755
01756 {
01757 FILE* fp = NULL;
01758 char* line = NULL;
01759 char* num = NULL;
01760
01761 if (IsImgsLoaded ())
01762
01763 {
01764 wxMessageDialog temp (this, "An animation file has already been loaded.\n Please close this file before recording to another", "Load Error!", wxOK);
01765
01766 temp.ShowModal ();
01767
01768 return;
01769 }
01770
01771 if (m_Gui->getCurrentImage () == NULL)
01772
01773 {
01774 wxMessageDialog temp (this, "No image to write to or read from \n (the method needs to tell the Key framer where it's image is, fix getCurrentMethod ()'s return value...).", "Play Error!", wxOK);
01775
01776 temp.ShowModal ();
01777
01778 return;
01779 }
01780
01781 int time = 0;
01782 int time2 = 0;
01783
01784 char time_str [20];
01785
01786
01787 fp = OpenGIFile (true);
01788
01789
01790
01791 if (fp == NULL)
01792
01793 {
01794 cout << "file does not exist " << endl;
01795
01796 return;
01797 }
01798
01799 line = new char [512];
01800 num = new char [15];
01801
01802 char *ttime;
01803
01804 ttime = (char *) (m_time_delay->GetValue ().c_str ());
01805
01806 vuCamera *f_camera_1 = m_camera_vector [0]->create_new ();
01807 vuCamera *f_camera_2 = m_camera_vector [0]->create_new ();
01808
01809 if ((f_camera_1 == NULL) || (f_camera_2 == NULL))
01810 return;
01811
01812 m_camera->set_defaults ();
01813 cout << "set_defaults ():" << endl;
01814
01815 char strinc [8];
01816
01817 strncpy (strinc, m_time_delay->GetValue ().c_str (), 7);
01818
01819 float tinc = atof (strinc);
01820
01821 if (tinc <= 0)
01822
01823 {
01824 wxMessageDialog temp (this, "A video cannot be generated with a non-positive frame rate. \n Please input a valid (positive frame rate) and try again in order to generate your video.", "Pllay Error!", wxOK);
01825
01826 temp.ShowModal ();
01827
01828 return;
01829 }
01830
01831 int fr = 0;
01832
01833 int play_counter = 0;
01834
01835 wxStopWatch totalTimer;
01836
01837 totalTimer.Start (0);
01838
01839 int counter = 0;
01840
01841 float frame = - 1.0 / float (tinc);
01842
01843 cout << int ((m_time_vector.getLength () - 1) * int (tinc) - 1) << endl;
01844
01845 for (counter = 0; counter < int ((m_time_vector.getLength () - 2) * int (tinc)); counter++)
01846 if ((mb_play) && (!mb_stop) && (!mb_pause))
01847
01848 {
01849 play_counter ++;
01850
01851
01852
01853 frame += 1.0 / float (tinc);
01854 fr = int (frame);
01855
01856 float t = (frame - float (fr)) * (m_time_vector [fr + 1] - m_time_vector [fr]) + m_time_vector [fr];
01857
01858 f_camera_1->operator= (m_camera_vector [fr]);
01859 f_camera_2->operator= (m_camera_vector [fr + 1]);
01860
01861 cout << ":t:" << m_time_vector [fr] << ":t:" << m_time_vector [fr + 1] << endl;
01862
01863 m_camera->operator= (interpolate (f_camera_1, f_camera_2, t, m_time_vector [fr], m_time_vector [fr + 1]));
01864
01865 gcvt (t, 10, num);
01866 strcpy (line, num);
01867 strcat (line, ", ");
01868 strcat (line, m_img_fstart);
01869 gcvt (m_currentframe, 10, num);
01870 strcat (line, num);
01871 strcat (line, ".ppm\n");
01872
01873 fputs (line, fp);
01874
01875 strcpy (line, m_img_fstart);
01876 strcat (line, num);
01877 strcat (line, ".ppm");
01878
01879 m_PPMHandler.SaveImage (line, *(m_Gui->getCurrentImage ()));
01880
01881 m_currentframe++;
01882
01883 m_Gui->DrawAgain ();
01884
01885 time2 = int (totalTimer.Time ());
01886 time = int (1000.0 * time2);
01887
01888 gcvt (time, vuKF_precision_digits, time_str);
01889
01890 m_total_time->SetLabel (wxString (vuKF_render_time_msg) + vuString (time_str).c_str () + " ms");
01891 }
01892
01893 if (fp != NULL)
01894 fclose (fp);
01895
01896 unsigned int ttim = totalTimer.Time ();
01897
01898 char tchar [20];
01899
01900 gcvt (ttim, 16, tchar);
01901
01902 m_total_time->SetLabel (wxString (vuKF_render_time_msg) + wxString (tchar) + wxString (" ms"));
01903
01904 gcvt (play_counter, 16, tchar);
01905
01906 m_frames_played_txt->SetLabel (wxString (vuKF_frames_played_msg_) + wxString (tchar));
01907
01908 delete [] f_camera_1;
01909 delete [] f_camera_2;
01910 }
01911
01912 void vuKeyFramerDialog::LoadFunc ()
01913
01914 {
01915 wxString tstring;
01916
01917 wxFileDialog KFfdlg (this, vuKF_default_vuKFFileDlg_msg_, wxString (vuKF_default_keyframe_save_dir_), "", vuKF_default_recorded_ext_);
01918
01919 if (KFfdlg.ShowModal () == wxID_CANCEL)
01920 return;
01921
01922 tstring = KFfdlg.GetPath ();
01923
01924 char* tcstr = (char *) (tstring.c_str ());
01925
01926 ifstream temp (tcstr);
01927
01928 if (!temp.good ())
01929
01930 {
01931
01932 char tstr [100];
01933
01934 strcpy (tstr, "Could not open file: ");
01935 strcat (tstr, tcstr);
01936
01937 wxMessageDialog temp (this, tstr, "Load Error!", wxOK);
01938 temp.ShowModal ();
01939
01940 return;
01941 }
01942
01943 temp.close ();
01944
01945 tstring = vuKF_default_curr_loaded_msg;
01946 tstring += KFfdlg.GetFilename ();
01947
01948 m_loaded_txt->SetLabel (tstring);
01949
01950 m_camera_vector.removeRange (0, m_camera_vector.getLength ());
01951 m_time_vector.removeRange (0, m_time_vector.getLength ());
01952
01953 if (!load_WithTime (tcstr, m_camera, m_camera_vector, m_time_vector))
01954
01955 {
01956 char tstr [100];
01957
01958 strcpy (tstr, "Could not parse file: ");
01959 strcat (tstr, tcstr);
01960 strcat (tstr, ",\n This is not a valid key frame file");
01961
01962 wxMessageDialog temp (this, tstr, "Load Error!", wxOK);
01963 temp.ShowModal ();
01964
01965 return;
01966 }
01967
01968 setIsLoaded (true);
01969 }
01970
01971 void vuKeyFramerDialog::PlayFromImages (bool fromevttimer)
01972
01973 {
01974 if (m_Gui->getCurrentImage () == NULL)
01975
01976 {
01977 wxMessageDialog temp (this, wxString ("This method couldn't find the buffer that was associated with it. \n This will now end."), "Can't find buffer!", wxOK);
01978 temp.ShowModal ();
01979
01980 return;
01981 }
01982
01983 FILE *fp;
01984
01985 if (!IsImgsLoaded ())
01986 fp = OpenGIFile (false);
01987 else
01988 fp = m_imgfp;
01989
01990 if (fp == NULL)
01991
01992 {
01993 cout << "File could not be opened" << endl;
01994
01995 return;
01996 }
01997
01998 fseek (fp, 0, SEEK_SET);
01999
02000 for (int i = 0; i < 5; i++)
02001 m_play_video_times [i] = 0.0;
02002
02003 m_play_video_frame = 0;
02004 m_play_video_size = -1;
02005 m_vid_play_timer.Start (1);
02006
02007 m_vid_play_timer.setMaxTime (int (1000.0 * ttimevector [ttimevector.getLength () - 1]));
02008
02009 m_play_video_ttime = 0.0;
02010
02011
02012 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
02013
02014
02015
02016 PlayNextImage ();
02017 }
02018
02019 void vuKeyFramerDialog::PlayFunc ()
02020
02021 {
02022 wxCommandEvent tmpevent;
02023
02024 if (!IsLoaded ())
02025 OnLoad (tmpevent);
02026
02027
02028 if (m_camera_vector.getLength () == 0)
02029 return;
02030
02031 m_currentframe = 0;
02032
02033 if (m_genimages->GetValue ())
02034
02035 {
02036 BurstPlayGI ();
02037
02038 setIsPlaying (false);
02039
02040 return;
02041 }
02042
02043 if (m_burstplay->GetValue ())
02044
02045 {
02046 BurstPlay ();
02047
02048 setIsPlaying (false);
02049
02050 return;
02051 }
02052
02053 setIsPlaying (true);
02054 setIsPaused (false);
02055 setIsStopped (false);
02056 setIsRecording (false);
02057
02058 m_playwatch.setMaxTime (int (1000.0 * m_time_vector [m_time_vector.getLength () - 1]));
02059
02060 PlayInTime ();
02061 }
02062
02063 void vuKeyFramerDialog::PlayInTime ()
02064
02065 {
02066 if (!IsPlaying ())
02067 return;
02068
02069 m_play_time = 0.0;
02070
02071 m_play_timer.getElapsedTimeFloat ();
02072
02073 if (m_camera_vector.getLength () == 0)
02074 return;
02075
02076 if (m_play_camera_1 != NULL)
02077 delete [] m_play_camera_1;
02078
02079 if (m_play_camera_2 != NULL)
02080 delete [] m_play_camera_2;
02081
02082 m_play_camera_1 = m_camera_vector [0]->create_new ();
02083 m_play_camera_2 = m_camera_vector [0]->create_new ();
02084
02085 for (int i = 0; i < 5; i++)
02086 m_play_times [i] = 0.0;
02087
02088 m_play_counter = 0;
02089
02090 m_playwatch.Start(0);
02091
02092 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
02093
02094 PlayNextFrame ();
02095 }
02096
02097 void vuKeyFramerDialog::PlayNextFrame ()
02098
02099 {
02100 if (!IsPlaying ())
02101 return;
02102
02103 if (IsPaused ())
02104
02105 {
02106 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Paused"));
02107
02108 ((vuEvtGenerator *) (m_PlayTimer))->Start (vuKF_regular_pause_delay, true);
02109
02110 return;
02111 }
02112
02113 if (m_playwatch.IsRewinding ())
02114
02115 {
02116 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Rewinding"));
02117 setIsRewinding (true);
02118 }
02119
02120 if (m_playwatch.IsFastForwarding ())
02121
02122 {
02123 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Fast Forwarding"));
02124 setIsFastForwarding (true);
02125 }
02126
02127 if (m_playwatch.IsReversing ())
02128
02129 {
02130 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Reversing"));
02131 setIsKFReversing (true);
02132 }
02133
02134 if ((!m_playwatch.IsReversing ()) && (!m_playwatch.IsRewinding ()) && (!m_playwatch.IsFastForwarding ()))
02135 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
02136
02137 int ttemp;
02138
02139 int frame;
02140 float fr;
02141 float frate;
02142
02143 ttemp = m_playwatch.Time ();
02144
02145 wxCommandEvent ev;
02146
02147 for (int i = 0; i < 4; i++)
02148 m_play_times [i] = m_play_times [i + 1];
02149
02150 m_play_time = float (ttemp) / 1000.0;
02151
02152 m_play_times [4] = float (m_playwatch.TotalTime ()) / 1000.0;
02153
02154 m_playwatch.setMaxTime (int (1000.0 * m_time_vector [m_time_vector.getLength () - 1]));
02155
02156 if (m_play_time < m_time_vector [m_time_vector.getLength () - 1] && (!IsPaused ()) && (!IsStopped ()))
02157
02158 {
02159 fr = get_frame_number (m_play_time);
02160 frame = int (fr);
02161
02162 cout << "frame = " << frame << endl;
02163
02164 if ((frame > int (m_camera_vector.getLength () - 2)) || (fr < 0))
02165 *m_camera = *(m_camera_vector [frame]);
02166 else
02167
02168 {
02169 m_play_camera_1->operator= (m_camera_vector [frame]);
02170 m_play_camera_2->operator= (m_camera_vector [frame + 1]);
02171
02172 cout << ":t:" << m_time_vector [frame] << ":t:" << m_time_vector [frame + 1] << endl;
02173
02174 *m_camera = interpolate (m_play_camera_1, m_play_camera_2, m_play_time, m_time_vector [frame], m_time_vector [frame + 1]);
02175
02176 }
02177
02178 m_Gui->DrawAgain ();
02179
02180 char time [16];
02181 gcvt (float (m_playwatch.TotalTime ()) / 1000.0, vuKF_precision_digits, time);
02182
02183 wxString timstr = vuKF_render_time_msg;
02184 timstr += time;
02185 timstr += " sec";
02186
02187 m_total_time->SetLabel (timstr);
02188
02189
02190
02191
02192 if (++m_play_counter > 4)
02193 frate = 5.0 / (m_play_times [4] - m_play_times [0]);
02194 else
02195 frate = float (m_play_counter) / (m_play_times [4]);
02196
02197 gcvt (frate, vuKF_precision_digits, time);
02198
02199 timstr = vuKF_frame_rate_msg;
02200 timstr += time;
02201 timstr += "/second";
02202
02203 m_fm_rate_txt->SetLabel (timstr);
02204
02205
02206 gcvt (float (m_play_counter), vuKF_precision_digits, time);
02207 timstr = vuKF_frames_played_msg_;
02208 timstr += time;
02209
02210 m_frames_played_txt->SetLabel (timstr);
02211
02212 ((vuEvtGenerator *) (m_PlayTimer))->Start (vuKF_play_delay, true);
02213
02214 return;
02215 }
02216
02217 else
02218
02219 {
02220 if ((!IsKFBouncing ()) && (!IsKFLooping ()))
02221 setIsPlaying (false);
02222 }
02223
02224 if ((IsKFLooping ()) || (IsKFBouncing ()))
02225
02226 {
02227 ((vuEvtGenerator *) (m_PlayTimer))->Start (vuKF_play_delay, true);
02228
02229 return;
02230 }
02231
02232 cout << "stopping\n";
02233
02234 setIsPlaying (false);
02235
02236 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg));
02237
02238 delete [] m_play_camera_1;
02239 delete [] m_play_camera_2;
02240
02241 m_play_camera_1 = NULL;
02242 m_play_camera_2 = NULL;
02243 }
02244
02245 void vuKeyFramerDialog::PlayNextImage ()
02246
02247 {
02248 if (!mb_play_from_images)
02249 return;
02250
02251 if (IsVideoPaused ())
02252
02253 {
02254
02255 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Paused"));
02256
02257 ((vuEvtGenerator *) (m_PlayTimer))->Start (vuKF_regular_pause_delay, true);
02258
02259 return;
02260 }
02261
02262 if (m_vid_play_timer.IsRewinding ())
02263
02264 {
02265
02266 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Rewinding"));
02267
02268
02269 }
02270
02271 if (m_vid_play_timer.IsReversing ())
02272
02273 {
02274
02275 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Reversing"));
02276
02277 }
02278
02279 if (m_vid_play_timer.IsFastForwarding ())
02280
02281 {
02282
02283 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Fast Forwarding"));
02284
02285 }
02286
02287 if ((!m_vid_play_timer.IsReversing ()) && (!m_vid_play_timer.IsFastForwarding ()) && (!m_vid_play_timer.IsRewinding ()))
02288
02289 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Playing"));
02290
02291 char fm_rate_str [10];
02292 float calc_time;
02293 wxString twxstr;
02294
02295 FILE *currfp;
02296
02297 int k64 = 0x10000;
02298
02299 debugtimer.Start (0);
02300
02301 for (int z = 0; z < 4; z++)
02302 m_play_video_times [z] = m_play_video_times [z + 1];
02303
02304 int ttime = m_vid_play_timer.Time ();
02305
02306
02307
02308
02309
02310
02311 m_play_video_ttime = float (ttime) / 1000.0;
02312
02313 m_play_video_times [4] = float (m_vid_play_timer.TotalTime ()) / 1000.0;
02314
02315 if (m_play_video_frame >= int (ttimevector.getLength ()))
02316 m_play_video_frame = int (ttimevector.getLength ()) - 1;
02317
02318 while ((m_play_video_ttime < ttimevector [m_play_video_frame]) && (m_play_video_frame > 0))
02319 m_play_video_frame--;
02320
02321 while ((m_play_video_ttime > ttimevector [m_play_video_frame]) && (m_play_video_frame < int (ttimevector.getLength () - 1)))
02322 m_play_video_frame++;
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334
02335
02336
02337 if (m_play_video_size == -1)
02338
02339 {
02340 delete [] m_play_video_buf;
02341
02342 (m_Gui->getCurrentImage ())->set_extents (0, 0);
02343 (m_Gui->getCurrentImage ())->elim_data (NULL);
02344
02345 cout << (int ) ((void*) tfilenamevector [m_play_video_frame]) << endl;
02346 m_PPMHandler.ReadImage (tfilenamevector [m_play_video_frame], *(m_Gui->getCurrentImage ()), 1);
02347 cout << tfilenamevector [m_play_video_frame] << endl;
02348
02349 int x, y;
02350
02351 m_Gui->getCurrentImage ()->get_extents (x, y);
02352
02353 m_play_video_size = 18 + 3 * x * y;
02354
02355 m_play_video_buf = new char [m_play_video_size];
02356 }
02357
02358 else
02359
02360 {
02361 int newcount = 0;
02362 currfp = fopen (tfilenamevector [m_play_video_frame], "r");
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378 if (currfp != NULL)
02379
02380 {
02381
02382 while (newcount + k64 < m_play_video_size)
02383
02384 {
02385
02386 fread (m_play_video_buf + newcount, 1, k64, currfp);
02387 newcount += k64;
02388 }
02389
02390
02391 fread (m_play_video_buf + newcount, 1, m_play_video_size - newcount, currfp);
02392
02393 m_PPMHandler.ReadImageFromBuffer (m_play_video_buf, *(m_Gui->getCurrentImage ()), 1);
02394
02395
02396 fclose (currfp);
02397 }
02398 }
02399
02400
02401 debugtimer.Start (0);
02402
02403 float ntime = ttimevector [m_play_video_frame];
02404
02405
02406 m_play_video_ttime = float (ttime) / 1000.0;
02407
02408 m_Gui->DrawFromImage ();
02409
02410
02411 debugtimer.Start (0);
02412
02413 m_play_video_frame++;
02414
02415 if (m_play_video_frame >= int (ttimevector.getLength ()))
02416 m_play_video_frame = ttimevector.getLength () - 1;
02417
02418
02419
02420 if (m_play_video_frame > 4)
02421
02422 {
02423 calc_time = 5 / (m_play_video_times [4] - m_play_video_times [0]);
02424
02425 gcvt (calc_time, vuKF_precision_digits, fm_rate_str);
02426
02427 twxstr = vuKF_frame_rate_msg;
02428 twxstr += fm_rate_str;
02429 twxstr += "/sec";
02430
02431
02432 m_fm_rate_txt->SetLabel (twxstr);
02433
02434
02435 calc_time = m_vid_play_timer.TotalTime ();
02436
02437 gcvt (calc_time, vuKF_precision_digits, fm_rate_str);
02438
02439 twxstr = vuKF_render_time_msg;
02440 twxstr += fm_rate_str;
02441 twxstr += " ms";
02442
02443
02444 m_total_time->SetLabel (twxstr);
02445
02446 gcvt (m_play_video_frame, 16, fm_rate_str);
02447
02448
02449 m_frames_played_txt->SetLabel (wxString (vuKF_frames_played_msg_) + wxString (fm_rate_str));
02450 }
02451
02452 if ((m_play_video_frame < int (ttimevector.getLength () - 1)) || (m_kf_bounce->GetValue ()) || (m_kf_loop->GetValue ()))
02453
02454
02455 {
02456 if ((m_kf_bounce->GetValue ()) || (m_kf_loop->GetValue ()))
02457
02458 {
02459 ((vuEvtGenerator *) (m_PlayTimer))->Start (int ((1.0 / float (vuKF_spd_mul)) * (ntime - m_play_video_ttime - 0.001) * 1000.0), true);
02460
02461 return;
02462 }
02463
02464 if (m_play_video_frame >= int (ttimevector.getLength () - 2))
02465
02466 {
02467 ((vuEvtGenerator *) (m_PlayTimer))->Start (1, true);
02468
02469 return;
02470 }
02471
02472 if ((IsVideoFastForwarding ()) && (m_play_video_frame < int (ttimevector.getLength ())))
02473
02474 {
02475 ((vuEvtGenerator *) (m_PlayTimer))->Start (int ((1.0 / float (vuKF_spd_mul)) * (ntime - m_play_video_ttime - 0.001) * 1000.0), true);
02476
02477 return;
02478 }
02479
02480 if (((IsVideoRewinding ())|| (IsVideoRewinding ())) && (m_play_video_frame > 0))
02481
02482 {
02483 ((vuEvtGenerator *) (m_PlayTimer))->Start (int ((1.0 / float (vuKF_spd_mul)) * (ntime - m_play_video_ttime - 0.001) * 1000.0), true);
02484
02485 return;
02486 }
02487
02488 if ((IsVideoRewinding ()) || (IsVideoFastForwarding ())|| (IsVideoReversing ()))
02489
02490 {
02491 setIsPlayingImgs (false);
02492
02493 return;
02494 }
02495
02496 ((vuEvtGenerator *) (m_PlayTimer))->Start (int ((1.0 / float (vuKF_spd_mul)) * (ntime - m_play_video_ttime - 0.001) * 1000.0), true);
02497
02498 return;
02499 }
02500
02501 setIsPlayingImgs (false);
02502 }
02503
02504 void vuKeyFramerDialog::RecordFunc ()
02505
02506 {
02507 m_camera_vector.removeRange (0, m_camera_vector.getLength());
02508 m_time_vector.removeRange (0, m_time_vector.getLength ());
02509
02510 wxString tstring;
02511 wxFileDialog KFfdlg (this, vuKF_default_vuKFFileDlg_msg_, vuKF_default_keyframe_save_dir_, "", vuKF_default_recorded_ext_);
02512
02513 if (KFfdlg.ShowModal () == wxID_CANCEL)
02514 return;
02515
02516 tstring = KFfdlg.GetPath ();
02517
02518 char* tcstr = (char *) (tstring.c_str ());
02519
02520 cout << "OnRECORD " << tcstr << endl;
02521
02522
02523 setIsRecording (true);
02524
02525 record_with_time (tcstr, (*m_camera));
02526
02527 tstring = vuKF_default_curr_loaded_msg;
02528 tstring += KFfdlg.GetFilename ();
02529
02530 m_loaded_txt->SetLabel (tstring);
02531
02532 m_kf_status_txt->SetLabel (wxString (vuKF_status_msg) + wxString ("Recording"));
02533
02534 m_timer.getElapsedTimeFloat ();
02535 time_t = 0.0;
02536 }
02537
02538 void vuKeyFramerDialog::RecordInTime ()
02539
02540 {
02541 if ((mb_pause) || (!mb_record) || (!m_autoshot->GetValue ()))
02542 return;
02543
02544 wxCommandEvent tempevt;
02545
02546 OnTakeShot (tempevt);
02547 }
02548
02549 void vuKeyFramerDialog::SaveFunc (bool writechanges)
02550
02551 {
02552 if (m_camera->IsRecording ())
02553
02554 {
02555 for (int i = 0; i < int (m_time_vector.getLength ()), i < int (m_camera_vector.getLength ()); i++)
02556
02557 {
02558 if (writechanges)
02559
02560 {
02561 *m_camera = m_camera_vector [i];
02562
02563 TakeSnapShotWithTime (float (i), *m_camera);
02564 }
02565
02566 delete [] m_camera_vector [i];
02567 }
02568
02569 m_time_vector.removeRange (0, m_time_vector.getLength () - 1);
02570 m_camera_vector.removeRange (0, m_camera_vector.getLength () - 1);
02571
02572 m_camera->stop_recording ();
02573 }
02574
02575 setIsRecording (false);
02576 setIsPlaying (false);
02577 setIsLoaded (false);
02578
02579 m_loaded_txt->SetLabel (wxString (vuKF_default_curr_loaded_msg));
02580 }
02581
02582
02583
02584 void vuKeyFramerDialog::rebuildCustomSizer()
02585 {
02586 if(!m_CustomSizer) return;
02587
02588 while(m_CustomSizer->Remove(0)) {};
02589 buildCustomSizer();
02590
02591
02592
02593 m_CustomSizer->Layout();
02594 m_MainSizer->Layout();
02595 m_MainSizer->SetSizeHints(this);
02596 m_MainSizer->Fit(this);
02597
02598
02599 }
02600
02601
02602
02603 int vuKeyFramerDialog::bisect_time_vector_search (float time, int start, int finish)
02604
02605 {
02606 if (start == finish)
02607 return start;
02608 if (start == finish - 1)
02609 return start;
02610
02611 int middle = finish - start;
02612 middle /= 2;
02613 middle += start;
02614
02615 if (m_time_vector [middle] > time)
02616 return bisect_time_vector_search (time, start, middle);
02617
02618 return bisect_time_vector_search (time, middle, finish);
02619 }
02620
02621 void vuKeyFramerDialog::clear_vectors ()
02622
02623 {
02624 for (int i = 0; i < int (m_camera_vector.getLength ()); i++)
02625 delete [] m_camera_vector [i];
02626
02627 m_camera_vector.removeRange (0, m_camera_vector.getLength () - 1);
02628 m_time_vector.removeRange (0, m_time_vector.getLength () - 1);
02629 }
02630
02631 float vuKeyFramerDialog::get_frame_number (float time)
02632
02633 {
02634 int frame = bisect_time_vector_search (time, 0, m_time_vector.getLength () - 1);
02635
02636 if (frame < 0)
02637 return 0;
02638
02639 if (frame > int (m_time_vector.getLength ()) - 2)
02640 return float (frame);
02641
02642 float t0 = m_time_vector [frame];
02643 float t1 = m_time_vector [frame + 1];
02644
02645 float fr = float (frame);
02646
02647 fr += (time - t0) / (t1 - t0);
02648
02649 cout << "time " << time << " frame " << frame << " fr " << fr << endl;
02650
02651 if (fr < 0)
02652 fr = 0.0;
02653
02654 if (fr > float (m_time_vector.getLength () - 1))
02655 fr = float (m_time_vector.getLength () - 1);
02656
02657 return fr;
02658 }
02659
02660 FILE* vuKeyFramerDialog::OpenGIFile (bool write)
02661
02662 {
02663 if (IsImgsLoaded ())
02664
02665 {
02666
02667
02668
02669
02670
02671 wxCommandEvent tev;
02672
02673 OnVideoClose (tev);
02674 }
02675
02676 wxString tstring;
02677
02678 wxFileDialog KFfdlg (this, wxString ("Select where you wish image information to be saved to"), wxString (vuKF_default_keyframe_save_dir_), wxString (""), wxString (vuKF_default_animated_ext_));
02679 if (KFfdlg.ShowModal () == wxID_CANCEL)
02680 return NULL;
02681
02682 tstring = KFfdlg.GetPath ();
02683
02684 char* tcstr = (char *) (tstring.c_str ());
02685
02686 if (m_img_fstart == NULL)
02687 m_img_fstart = new char [256];
02688
02689 strcpy (m_img_fstart, tcstr);
02690
02691 m_img_fstart [strlen (m_img_fstart) - 4] = '\0';
02692
02693 wxString twxstr = vuKF_default_curr_loaded_msg;
02694 twxstr += tcstr;
02695
02696
02697 tstring = KFfdlg.GetDirectory ();
02698 tstring += KFfdlg.GetFilename ();
02699
02700
02701 m_loaded_txt->SetLabel (wxString ("Currently Loaded:") + KFfdlg.GetFilename ());
02702
02703 if (write)
02704
02705 {
02706 m_imgfp = fopen (tcstr, "w");
02707
02708
02709 m_loaded_txt->SetLabel (wxString (vuKF_default_curr_loaded_msg) + KFfdlg.GetFilename ());
02710 return m_imgfp;
02711 }
02712
02713 m_imgfp = fopen (tcstr, "r");
02714
02715 if (m_imgfp == NULL)
02716
02717 {
02718 cout << "Couldn't open the header" << endl;
02719
02720 cout << tstring.c_str () << endl;
02721
02722 return NULL;
02723 }
02724
02725 char cbuf [256];
02726
02727 int position;
02728 int tpos;
02729 char* tbuf;
02730
02731 setIsImgsLoaded (true);
02732
02733 cout << "OpenGIFilea" << endl;
02734
02735 cbuf [0] = 'a';
02736
02737 while ((cbuf [0] != EOF) && (cbuf [0] != '\0'))
02738
02739 {
02740 cbuf [0] = fgetc (m_imgfp);
02741
02742 fgets (cbuf + 1, 255, m_imgfp);
02743
02744 cout << "cbuf:" << cbuf << endl;
02745
02746 if (cbuf [0] != EOF)
02747
02748 {
02749 position = clear_blanks (cbuf);
02750
02751 float ntime = atof (&(cbuf [position]));
02752
02753 ttimevector.add (ntime);
02754
02755 position += get_next_comma (&(cbuf [position])) + 1;
02756
02757 position += clear_blanks (&(cbuf [position]));
02758
02759 tpos = position;
02760
02761 while ((cbuf [tpos] != '\0') && (cbuf [tpos] != '\n'))
02762 tpos++;
02763
02764 cbuf [tpos] = '\0';
02765
02766 tbuf = new char [strlen (&(cbuf [position])) + 1];
02767
02768 cout << "tbuf:" << (unsigned int) ( (void*) (tbuf)) << endl;
02769 strcpy (tbuf, &(cbuf [position]));
02770
02771 tfilenamevector.add (tbuf);
02772 }
02773 }
02774
02775 return m_imgfp;
02776 }
02777
02778
02779
02780 void vuKeyFramerDialog::TimerEvent ()
02781
02782 {
02783 if (mb_play_from_images)
02784 PlayNextImage ();
02785
02786 if (mb_play)
02787 PlayNextFrame ();
02788
02789 if (mb_record)
02790 RecordInTime ();
02791 }
02792
02793
02794
02795
02796
02797
02798
02799
02800
02801