void HandleAction (Action action) { uint32_t nf = 0; uint32_t old; admScopedMutex autolock(&singleThread); // make sure only one thread at a time calls this ADM_warning("************ %s **************\n",getActionName(action)); // handle out of band actions // independant load not loaded //------------------------------------------------ if(action==ACT_RUN_SCRIPT) { GUI_FileSelRead("Select script/project to run", A_RunScript); return; } if (action >= ACT_SCRIPT_ENGINE_FIRST && action < ACT_SCRIPT_ENGINE_LAST) { int engineIndex = (action - ACT_SCRIPT_ENGINE_FIRST) / 3; int actionId = (action - ACT_SCRIPT_ENGINE_FIRST) % 3; tempEngine = getScriptEngines()[engineIndex]; switch (actionId) { case 0: GUI_FileSelRead("Select script to run", RunScript); break; case 1: GUI_FileSelRead("Select script to debug", DebugScript); break; case 2: GUI_FileSelWrite(QT_TRANSLATE_NOOP("adm","Select script to save"), SaveScript); UI_refreshCustomMenu(); break; } return; } if (action >= ACT_SCRIPT_ENGINE_SHELL_FIRST && action < ACT_SCRIPT_ENGINE_SHELL_LAST) { IScriptEngine *shellEngine = getScriptEngines()[action - ACT_SCRIPT_ENGINE_SHELL_FIRST]; if ((shellEngine->capabilities() & IScriptEngine::DebuggerShell) == IScriptEngine::DebuggerShell) { shellEngine->openDebuggerShell(); } else { interactiveScript(shellEngine); } return; } switch (action) { case ACT_TimeShift: A_TimeShift(); return; case ACT_Goto: brokenAct(); return; case ACT_AVS_PROXY: GUI_avsProxy(); return; case ACT_BUILT_IN: DIA_builtin(); return; case ACT_RECENT0: case ACT_RECENT1: case ACT_RECENT2: case ACT_RECENT3: { const char **name; int rank; name=prefs->get_lastfiles(); rank=(int)action-ACT_RECENT0; ADM_assert(name[rank]); A_openAvi (name[rank]); return; } case ACT_RECENT_PROJECT0: case ACT_RECENT_PROJECT1: case ACT_RECENT_PROJECT2: case ACT_RECENT_PROJECT3: { const char **name = prefs->get_lastprojectfiles(); int rank = (int)action - ACT_RECENT_PROJECT0; ADM_assert(name[rank]); call_scriptEngine(name[rank]); return; } case ACT_VIDEO_CODEC_CONFIGURE: videoEncoder6Configure(); return; case ACT_ContainerConfigure: { int index=UI_GetCurrentFormat(); ADM_mux_configure(index); return; } case ACT_VIDEO_CODEC_CHANGED: { int nw=UI_getCurrentVCodec(); videoEncoder6_SetCurrentEncoder(nw); return; } case ACT_AUDIO_CODEC_CHANGED: { int nw=UI_getCurrentACodec(); audioCodecSetByIndex(0,nw); return; } case ACT_PLUGIN_INFO: DIA_pluginsInfo(); return; case ACT_OPEN_APP_LOG: GUI_OpenApplicationLog(); return; case ACT_OPEN_APP_FOLDER: GUI_OpenApplicationDataFolder(); return; case ACT_ABOUT : DIA_about( ); return; case ACT_AUDIO_CODEC_CONFIGURE: audioCodecConfigure(0); return; case ACT_AUDIO_FILTERS: { EditableAudioTrack *ed=video_body->getDefaultEditableAudioTrack(); if(ed) ed->audioEncodingConfig.audioFilterConfigure(); } return; case ACT_PREFERENCES: if(playing) return; if(DIA_Preferences()) { ADM_info("Saving prefs\n"); prefs->save (); } return; case ACT_SavePref: prefs->save (); return; case ACT_EXIT: if(playing) { ADM_info("Stopping playback...\n"); GUI_PlayAvi(); } ADM_info("Closing ui\n"); UI_closeGui(); return; break; default: break; } if (playing) // only allow some action { switch (action) { case ACT_PlayAvi: case ACT_StopAvi: break; default: return; } } // not playing, // restict disabled uncoded actions if ((int) action >= ACT_DUMMY) { GUI_Error_HIG (QT_TRANSLATE_NOOP("adm","Not coded in this version"), NULL); return; } // allow only if avi loaded if (!avifileinfo) { switch (action) { case ACT_JOG: break; case ACT_OPEN_VIDEO: GUI_FileSelRead (QT_TRANSLATE_NOOP("adm","Select Video File..."), (SELFILE_CB *)A_openAvi); break; default: break; } return; } // Dispatch actions, we have a file loaded if(action>ACT_NAVIGATE_BEGIN && action < ACT_NAVIGATE_END) { return HandleAction_Navigate(action); } if(action>ACT_SAVE_BEGIN && action < ACT_SAVE_END) { return HandleAction_Save(action); } switch (action) { case ACT_SAVE_PY_SCRIPT: { IScriptEngine *engine=getPythonScriptEngine(); if(!engine) { GUI_Error_HIG("No engine","tinyPy script is not enabled in this build"); break; } char fileName[1024]; if(FileSel_SelectWrite("Saving tinypy project",fileName,1000, NULL)) { int l=strlen(fileName); if(l>3) { char *tail=fileName+l-3; if(tail[0]!='.'|| tail[1]!='p'|| tail[2]!='y') strcat(fileName,".py"); } A_saveScript(engine, fileName); } break; } break; case ACT_JOG: A_jog(); break; case ACT_CLOSE: GUI_close(); break; case ACT_ZOOM_1_4: case ACT_ZOOM_1_2: case ACT_ZOOM_1_1: case ACT_ZOOM_2_1: case ACT_ZOOM_4_1: currentZoom=(renderZoom)((action-ACT_ZOOM_1_4)+ZOOM_1_4); changePreviewZoom(currentZoom); admPreview::samePicture(); break; case ACT_AUDIO_SELECT_TRACK: A_audioTrack(); break; case ACT_OPEN_VIDEO: GUI_FileSelRead (QT_TRANSLATE_NOOP("adm","Select Video File..."),(SELFILE_CB *) A_openAvi); break; case ACT_APPEND_VIDEO: GUI_FileSelRead (QT_TRANSLATE_NOOP("adm","Select Video File to Append..."),(SELFILE_CB *) A_appendAvi); break; case ACT_VIDEO_PROPERTIES: DIA_properties (); break; case ACT_PlayAvi: GUI_PlayAvi (); break; #define TOGGLE_PREVIEW ADM_PREVIEW_OUTPUT case ACT_PreviewChanged: { ADM_PREVIEW_MODE oldpreview=getPreviewMode(),newpreview=(ADM_PREVIEW_MODE)UI_getCurrentPreview(); printf("Old preview %d, New preview mode : %d\n",oldpreview,newpreview); if(oldpreview==newpreview) { return; } admPreview::stop(); setPreviewMode(newpreview); admPreview::start(); // admPreview::update(curframe); } break; case ACT_StopAvi: if (playing) GUI_PlayAvi (); break; case ACT_SetPostProcessing: A_setPostproc(); break; case ACT_MarkA: case ACT_MarkB: { bool swapit=0; uint64_t markA,markB; uint64_t pts=admPreview::getCurrentPts(); if( prefs->get(FEATURES_SWAP_IF_A_GREATER_THAN_B, &swapit) != RC_OK ) swapit = 1; markA=video_body->getMarkerAPts(); markB=video_body->getMarkerBPts(); if (action == ACT_MarkA) markA=pts; else markB=pts; if (markA>markB && swapit ) // auto swap { uint64_t y; y = markA; markA=markB; markB=y; } video_body->setMarkerAPts(markA); video_body->setMarkerBPts(markB); UI_setMarkers (markA, markB); break; } case ACT_Copy: { uint64_t markA,markB; markA=video_body->getMarkerAPts(); markB=video_body->getMarkerBPts(); if(markA>markB) { uint64_t p=markA; markA=markB; markB=p; } video_body->copyToClipBoard (markA,markB); break; } case ACT_Paste: { uint64_t currentPts=video_body->getCurrentFramePts(); video_body->pasteFromClipBoard(currentPts); video_body->getVideoInfo (avifileinfo); A_ResetMarkers(); ReSync (); } break; break; case ACT_Undo: if (avifileinfo) { uint64_t currentPts=video_body->getCurrentFramePts(); if(video_body->undo()) { video_body->getVideoInfo(avifileinfo); ReSync(); A_ResetMarkers(); A_Rewind(); if(currentPts<=video_body->getVideoDuration()) GUI_GoToTime(currentPts); } } break; case ACT_ResetSegments: if(avifileinfo) if(GUI_Question(QT_TRANSLATE_NOOP("adm","Are you sure?"))) { video_body->resetSeg(); video_body->getVideoInfo (avifileinfo); A_ResetMarkers(); ReSync (); // forget last project file video_body->setProjectName(""); } break; case ACT_Delete: case ACT_Cut: { uint64_t a=video_body->getMarkerAPts(); uint64_t b=video_body->getMarkerBPts(); if(false==video_body->remove(a,b)) { GUI_Error_HIG("Cutting","Error while cutting out."); } else { A_ResetMarkers(); A_Resync(); // total duration & stuff // Rewind to first frame... //A_Rewind(); GUI_GoToTime(a); } } break; // set decoder option (post processing ...) case ACT_DecoderOption: video_body->setDecodeParam ( admPreview::getCurrentPts()); break; case ACT_VIDEO_FILTERS: GUI_handleVFilter(); break; case ACT_HEX_DUMP: GUI_showCurrentFrameHex(); break; case ACT_SIZE_DUMP: GUI_showSize(); break; case ACT_TimeShift: A_TimeShift(); break; default: printf ("\n unhandled action %d\n", action); ADM_assert (0); return; } }
/** \fn A_openAvi \brief Open (replace mode) a video */ int A_openAvi (const char *name) { uint8_t res; char *longname; uint32_t magic[4]; uint32_t id = 0; if (playing) return 0; /// check if name exists FILE *fd; fd = ADM_fopen(name, "rb"); if (!fd) { if (errno == EACCES) { GUI_Error_HIG(QT_TRANSLATE_NOOP("adm", "Permission error"), QT_TRANSLATE_NOOP("adm", "Cannot open \"%s\"."), name); } if (errno == ENOENT) { GUI_Error_HIG(QT_TRANSLATE_NOOP("adm", "File error"), QT_TRANSLATE_NOOP("adm", "\"%s\" does not exist."), name); } return 0; } if (4 == fread(magic, 4, 4, fd)) id = R32(magic[0]); fclose(fd); GUI_close(); // Cleanup // DIA_StartBusy (); /* ** we may get a relative path by cmdline */ longname = ADM_PathCanonize(name); // check if avisynth input is given if (fourCC::check(id, (uint8_t *) "ADAP")) res = video_body->addFile(AVS_PROXY_DUMMY_FILE); else res = video_body->addFile(longname); // DIA_StopBusy (); // forget last project file video_body->setProjectName(""); if (res != ADM_OK) // an error occured { delete[] longname; if (ADM_IGN == res) { return 0; } if (fourCC::check(id, (uint8_t *) "//AD")) { GUI_Error_HIG(QT_TRANSLATE_NOOP("adm", "Cannot open project using the video loader."), QT_TRANSLATE_NOOP("adm", "Try 'File' -> 'Load/Run Project...'")); } else { GUI_Error_HIG(QT_TRANSLATE_NOOP("adm", "Could not open the file"), NULL); } return 0; } { int i; FILE *fd = NULL; char magic[4]; /* check myself it is a project file (transparent detected and read ** by video_body->addFile (name); */ //#warning FIXME #if 0 if ((fd = ADM_fopen(longname, "rb"))) { if (fread(magic, 4, 1, fd) == 4) { /* remember a workbench file */ if (!strncmp(magic, "ADMW", 4)) { actual_workbench_file = ADM_strdup(longname); } } fclose(fd); } #endif /* remember any video or workbench file to "recent" */ prefs->set_lastfile(longname); UI_updateRecentMenu(); updateLoaded(); if (currentaudiostream) { uint32_t nbAudio; audioInfo *infos = NULL; if (video_body->getAudioStreamsInfo(admPreview::getCurrentPts() + 1, &nbAudio, &infos)) { if (nbAudio > 1) { // Multiple track warn user GUI_Info_HIG(ADM_LOG_INFO, QT_TRANSLATE_NOOP("adm", "Multiple Audio Tracks"), QT_TRANSLATE_NOOP("adm", "The file you just loaded contains several audio tracks.\n" "Go to Audio->MainTrack to select the active one.")); } } if (infos) delete [] infos; // Revert mixer to copy //setCurrentMixerFromString("NONE"); EditableAudioTrack *ed = video_body->getDefaultEditableAudioTrack(); if (ed) ed->audioEncodingConfig.audioFilterSetMixer(CHANNEL_INVALID); } for (i = strlen(longname); i >= 0; i--) { #ifdef _WIN32 if (longname[i] == '\\' || longname[i] == '/') #else if (longname[i] == '/') #endif { i++; break; } } UI_setTitle(longname + i); } delete[] longname; return 1; }
void ADM_Composer::closeFile(void) { GUI_close(); }