2006-02-21 19:49:57 +01:00
|
|
|
// Copyright (c) 2005-2006, Rodrigo Braz Monteiro, Fredrik Mellbin
|
2006-01-16 22:02:54 +01:00
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file vfr.cpp
|
|
|
|
/// @brief Handle variable frame rate files
|
|
|
|
/// @ingroup video_input
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2006-03-14 01:08:56 +01:00
|
|
|
#include <wx/filename.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
|
|
|
#include "main.h"
|
2006-07-01 07:34:39 +02:00
|
|
|
#include "options.h"
|
2006-03-14 01:08:56 +01:00
|
|
|
#include "text_file_reader.h"
|
2008-01-16 03:31:37 +01:00
|
|
|
#include "text_file_writer.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "utils.h"
|
|
|
|
#include "vfr.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief V2 Clear function
|
2006-02-21 19:49:57 +01:00
|
|
|
void FrameRate::Clear () {
|
2006-01-16 22:02:54 +01:00
|
|
|
Frame.clear();
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief V2 Add frame
|
|
|
|
/// @param ms
|
2006-02-21 19:49:57 +01:00
|
|
|
void FrameRate::AddFrame(int ms) {
|
|
|
|
Frame.push_back(ms);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief V2 Get Average
|
2006-02-21 19:49:57 +01:00
|
|
|
void FrameRate::CalcAverage() {
|
2006-02-24 00:24:35 +01:00
|
|
|
if (Frame.size() <= 1)
|
2006-02-24 00:13:56 +01:00
|
|
|
throw _("No timecodes to average");
|
|
|
|
|
2006-02-24 00:24:35 +01:00
|
|
|
AverageFrameRate = double(Frame.back()) / (Frame.size()-1);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:26 +02:00
|
|
|
/// @brief Constructor
|
2006-01-16 22:02:54 +01:00
|
|
|
FrameRate::FrameRate() {
|
2006-02-21 19:49:57 +01:00
|
|
|
Unload();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Destructor
|
2006-01-16 22:02:54 +01:00
|
|
|
FrameRate::~FrameRate() {
|
2006-02-24 17:45:10 +01:00
|
|
|
Unload();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Loads VFR file
|
|
|
|
/// @param filename
|
2006-01-16 22:02:54 +01:00
|
|
|
void FrameRate::Load(wxString filename) {
|
|
|
|
using namespace std;
|
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
Unload();
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Check if file exists
|
|
|
|
wxFileName filetest(filename);
|
|
|
|
if (!filetest.FileExists()) throw _T("File not found.");
|
|
|
|
|
|
|
|
// Open file
|
2006-03-14 01:08:56 +01:00
|
|
|
TextFileReader file(filename);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
try {
|
|
|
|
// Read header
|
2006-03-14 01:08:56 +01:00
|
|
|
wxString curLine;
|
|
|
|
curLine = file.ReadLineFromFile();
|
|
|
|
wxString header = curLine;
|
2006-03-14 01:33:31 +01:00
|
|
|
bool first = (header.Left(7).Lower() == _T("assume "));
|
2006-02-24 17:45:10 +01:00
|
|
|
|
|
|
|
// V1, code converted from avcvfr9
|
2006-03-14 01:33:31 +01:00
|
|
|
if (header == _T("# timecode format v1") || first) {
|
2006-03-14 01:08:56 +01:00
|
|
|
// Locate the default fps line
|
|
|
|
do {
|
2006-03-14 01:33:31 +01:00
|
|
|
// Get next line
|
|
|
|
if (!first) curLine = file.ReadLineFromFile();
|
|
|
|
first = false;
|
|
|
|
|
2006-03-14 01:08:56 +01:00
|
|
|
// Skip empty lines and comments
|
|
|
|
if (curLine == _T("") || curLine.Left(1) == _T("#")) continue;
|
2006-02-24 17:45:10 +01:00
|
|
|
|
2006-03-14 01:08:56 +01:00
|
|
|
else if (curLine.Left(7).Lower() != _T("assume ")) throw _T("Encountered data before 'Assume <fps>' line");
|
2006-02-24 17:45:10 +01:00
|
|
|
else {
|
2006-03-14 01:08:56 +01:00
|
|
|
if (!curLine.Mid(6).ToDouble(&AverageFrameRate) || AverageFrameRate <= 0) throw _T("Invalid 'Assume <fps>' line");
|
2006-02-24 17:45:10 +01:00
|
|
|
break;
|
|
|
|
}
|
2006-03-14 01:08:56 +01:00
|
|
|
} while (file.HasMoreLines());
|
|
|
|
|
|
|
|
// Read and expand all timecodes to v2
|
2006-02-24 17:45:10 +01:00
|
|
|
wxString curline;
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
double currenttime = 0;
|
|
|
|
int lposition = -1;
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
long lstart;
|
|
|
|
long lend;
|
|
|
|
double lfps;
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-03-14 01:08:56 +01:00
|
|
|
while (file.HasMoreLines()) {
|
|
|
|
curLine = file.ReadLineFromFile();
|
2006-02-24 17:45:10 +01:00
|
|
|
|
2006-03-14 01:08:56 +01:00
|
|
|
// Skip empty lines and comments
|
2006-02-24 17:45:10 +01:00
|
|
|
if (curLine == _T("") || curLine.Left(1) == _T("#"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString tmp = curLine.AfterFirst(_T(','));
|
|
|
|
wxString temp = curLine.BeforeFirst(_T(','));
|
|
|
|
if (!temp.ToLong(&lstart) || lstart < 0)
|
|
|
|
throw _T("Timecode parsing error, invalid start format found");
|
|
|
|
temp = tmp.BeforeLast(_T(','));
|
|
|
|
if (!temp.ToLong(&lend) || lend < 0)
|
|
|
|
throw _T("Timecode parsing error, invalid end format found");
|
|
|
|
temp = tmp.AfterLast(_T(','));
|
|
|
|
if (!temp.ToDouble(&lfps) || lfps <= 0)
|
|
|
|
throw _T("Timecode parsing error, invalid fps format found");
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2008-09-10 22:52:51 +02:00
|
|
|
if (lstart <= lposition)
|
|
|
|
throw _T("Timecode parsing error, out of order or overlapping timecode range found");
|
|
|
|
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
for (int i = 0; i <= lstart - lposition - 2; i++)
|
2007-01-11 04:18:14 +01:00
|
|
|
AddFrame((int)(floor(currenttime+(i*1000) / AverageFrameRate)));
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
currenttime += ((lstart - lposition - 1)*1000) / AverageFrameRate;
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
for (int i = 0; i <= lend - lstart; i++)
|
2007-01-11 04:18:14 +01:00
|
|
|
AddFrame((int)(floor(currenttime+(i*1000) / lfps)));
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
currenttime += ((lend - lstart + 1)*1000) / lfps;
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
lposition = lend;
|
|
|
|
}
|
|
|
|
|
2009-02-05 00:11:56 +01:00
|
|
|
AddFrame(currenttime);
|
2006-02-24 17:45:10 +01:00
|
|
|
last_time = currenttime;
|
2009-02-05 00:11:56 +01:00
|
|
|
last_frame = (int)Frame.size() - 1;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
// V2
|
|
|
|
else if (header == _T("# timecode format v2")) {
|
|
|
|
// Assigns new VFR file
|
|
|
|
FrameRateType = VFR;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
long lftime = -1;
|
|
|
|
long cftime = 0;
|
|
|
|
last_frame = 0;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
// Reads body
|
2006-03-14 01:08:56 +01:00
|
|
|
while (file.HasMoreLines()) {
|
|
|
|
curLine = file.ReadLineFromFile();
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
//skip empty lines and comments
|
|
|
|
if (curLine == _T("") || curLine.Left(1) == _T("#"))
|
|
|
|
continue;
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
wxString tmp = curLine.BeforeFirst(_T('.'));
|
|
|
|
tmp.ToLong(&cftime);
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
if (lftime >= cftime)
|
|
|
|
throw _T("Out of order/too close timecodes found");
|
2006-02-24 00:13:56 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
AddFrame(cftime);
|
|
|
|
lftime = cftime;
|
2006-02-24 00:13:56 +01:00
|
|
|
}
|
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
last_time = cftime;
|
2009-02-05 00:11:56 +01:00
|
|
|
last_frame = (int)Frame.size() - 1;
|
2006-02-21 19:49:57 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
CalcAverage();
|
2006-02-24 00:13:56 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2006-02-24 17:45:10 +01:00
|
|
|
// Unknown
|
2006-03-14 01:08:56 +01:00
|
|
|
else {
|
2007-07-18 15:46:38 +02:00
|
|
|
throw _T("Unknown time code file format.");
|
2006-03-14 01:08:56 +01:00
|
|
|
}
|
2006-02-24 17:45:10 +01:00
|
|
|
|
2006-03-14 01:08:56 +01:00
|
|
|
}
|
|
|
|
catch (...) {
|
2006-02-21 19:49:57 +01:00
|
|
|
Unload();
|
2006-02-24 17:45:10 +01:00
|
|
|
throw;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close file
|
|
|
|
loaded = true;
|
|
|
|
vfrFile = filename;
|
2006-06-27 21:11:41 +02:00
|
|
|
FrameRateType = VFR;
|
2006-07-01 07:34:39 +02:00
|
|
|
|
|
|
|
// Add to recent
|
2010-06-18 04:23:27 +02:00
|
|
|
config::mru->Add("Timecodes", STD_STR(filename));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Save
|
|
|
|
/// @param filename
|
2008-01-16 03:31:37 +01:00
|
|
|
void FrameRate::Save(wxString filename) {
|
|
|
|
TextFileWriter file(filename,_T("ASCII"));
|
|
|
|
file.WriteLineToFile(_T("# timecode format v2"));
|
|
|
|
for (size_t i=0;i<Frame.size();i++) {
|
|
|
|
file.WriteLineToFile(wxString::Format(_T("%f"),(float)Frame[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Unload
|
2006-01-16 22:02:54 +01:00
|
|
|
void FrameRate::Unload () {
|
|
|
|
FrameRateType = NONE;
|
|
|
|
AverageFrameRate = 0;
|
2006-02-21 19:49:57 +01:00
|
|
|
last_time = 0;
|
|
|
|
last_frame = 0;
|
|
|
|
Clear();
|
2006-01-16 22:02:54 +01:00
|
|
|
loaded = false;
|
|
|
|
vfrFile = _T("");
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Sets to CFR
|
|
|
|
/// @param fps
|
2006-02-24 17:45:10 +01:00
|
|
|
void FrameRate::SetCFR(double fps) {
|
2006-02-21 19:49:57 +01:00
|
|
|
Unload();
|
2006-06-27 21:11:41 +02:00
|
|
|
loaded = true;
|
2006-01-16 22:02:54 +01:00
|
|
|
FrameRateType = CFR;
|
|
|
|
AverageFrameRate = fps;
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Sets to VFR
|
|
|
|
/// @param newTimes
|
2006-02-23 02:44:48 +01:00
|
|
|
void FrameRate::SetVFR(std::vector<int> newTimes) {
|
|
|
|
Unload();
|
2006-02-24 00:13:56 +01:00
|
|
|
|
2006-06-27 21:11:41 +02:00
|
|
|
loaded = true;
|
2006-02-23 02:44:48 +01:00
|
|
|
FrameRateType = VFR;
|
|
|
|
|
2006-02-24 00:13:56 +01:00
|
|
|
// Set new VFR;
|
2006-02-23 02:44:48 +01:00
|
|
|
Frame = newTimes;
|
2006-02-24 00:13:56 +01:00
|
|
|
CalcAverage();
|
2006-02-23 02:44:48 +01:00
|
|
|
last_time = newTimes.back();
|
2006-10-20 00:53:06 +02:00
|
|
|
last_frame = (int)newTimes.size();
|
2006-02-23 02:44:48 +01:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Gets frame number at time
|
|
|
|
/// @param ms
|
|
|
|
/// @param useceil
|
|
|
|
/// @return
|
2010-06-24 03:24:26 +02:00
|
|
|
int FrameRate::PFrameAtTime(int ms,bool useceil) const {
|
2006-02-25 00:16:20 +01:00
|
|
|
// Check if it's loaded
|
2006-06-27 21:11:41 +02:00
|
|
|
if (!loaded) return -1;
|
2006-02-24 23:46:21 +01:00
|
|
|
|
2006-02-25 00:16:20 +01:00
|
|
|
// Get for constant frame rate
|
2010-06-24 03:24:26 +02:00
|
|
|
if (FrameRateType == CFR || Frame.size() == 0 || ms < 0) {
|
2006-06-21 23:58:23 +02:00
|
|
|
double value = double(ms) * AverageFrameRate / 1000.0;
|
2007-01-11 04:18:14 +01:00
|
|
|
if (useceil) return (int)ceil(value);
|
|
|
|
else return (int)floor(value);
|
2006-02-24 23:46:21 +01:00
|
|
|
}
|
2006-02-25 00:16:20 +01:00
|
|
|
|
|
|
|
// Get for variable frame rate
|
2006-02-24 23:46:21 +01:00
|
|
|
else if (FrameRateType == VFR) {
|
2006-04-04 13:37:27 +02:00
|
|
|
// Get last
|
|
|
|
double trueLast;
|
2006-04-04 15:22:45 +02:00
|
|
|
//if (useceil) trueLast = ceil(last_time);
|
|
|
|
//else trueLast = floor(last_time);
|
|
|
|
trueLast = Frame[Frame.size()-1];
|
2006-04-04 13:37:27 +02:00
|
|
|
|
2006-02-25 00:16:20 +01:00
|
|
|
// Inside VFR range
|
2009-02-05 00:11:56 +01:00
|
|
|
if (ms <= trueLast) {
|
2006-02-25 00:16:20 +01:00
|
|
|
// Prepare binary search
|
2006-02-24 23:46:21 +01:00
|
|
|
size_t start = 0;
|
|
|
|
size_t end = last_frame;
|
|
|
|
size_t cur;
|
|
|
|
bool largerEqual;
|
2006-02-25 00:16:20 +01:00
|
|
|
|
|
|
|
// Do binary search
|
2006-02-24 23:46:21 +01:00
|
|
|
while (start <= end) {
|
2006-02-25 00:16:20 +01:00
|
|
|
// Current frame being checked
|
2006-02-24 23:46:21 +01:00
|
|
|
cur = (start+end)>>1;
|
2006-02-25 00:16:20 +01:00
|
|
|
|
|
|
|
// Is it larger or equal to searched time?
|
2006-02-24 23:46:21 +01:00
|
|
|
largerEqual = Frame[cur] >= ms;
|
|
|
|
|
2006-02-25 00:16:20 +01:00
|
|
|
// If it is, is the previous smaller?
|
|
|
|
// If so, this is the frame we're looking for
|
2006-02-25 00:26:24 +01:00
|
|
|
if (largerEqual && (cur == 0 || Frame[cur-1] < ms)) {
|
2006-10-20 00:53:06 +02:00
|
|
|
if (useceil) return (int)cur;
|
|
|
|
return (int)(cur)-1;
|
2006-02-25 00:26:24 +01:00
|
|
|
}
|
2006-02-24 23:46:21 +01:00
|
|
|
|
2006-02-25 00:16:20 +01:00
|
|
|
// Not found, continue search
|
2006-02-24 23:46:21 +01:00
|
|
|
if (largerEqual) end = cur-1;
|
|
|
|
else start = cur+1;
|
|
|
|
}
|
2006-02-25 00:16:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// After VFR range
|
|
|
|
else {
|
2007-01-11 04:18:14 +01:00
|
|
|
if (useceil) return (int)(last_frame + ceil((ms-last_time) * AverageFrameRate / 1000));
|
|
|
|
else return (int)(last_frame + floor((ms-last_time) * AverageFrameRate / 1000));
|
2006-02-24 23:46:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Gets time at frame
|
|
|
|
/// @param frame
|
|
|
|
/// @return
|
2010-06-24 03:24:26 +02:00
|
|
|
int FrameRate::PTimeAtFrame(int frame) const {
|
2006-02-25 00:16:20 +01:00
|
|
|
// Not loaded
|
2006-06-27 21:11:41 +02:00
|
|
|
if (!loaded) return -1;
|
2006-02-25 00:16:20 +01:00
|
|
|
|
|
|
|
// For negative/zero times, fallback to zero
|
2006-02-24 23:46:21 +01:00
|
|
|
if (frame <= 0) return 0;
|
|
|
|
|
2006-02-25 00:16:20 +01:00
|
|
|
// Constant frame rate
|
2006-06-27 21:11:41 +02:00
|
|
|
if (FrameRateType == CFR || Frame.size() == 0) {
|
2007-01-11 04:18:14 +01:00
|
|
|
return (int)floor(double(frame) / AverageFrameRate * 1000.0);
|
2006-02-24 23:46:21 +01:00
|
|
|
}
|
2006-02-25 00:16:20 +01:00
|
|
|
|
|
|
|
// Variable frame rate
|
|
|
|
else if (FrameRateType == VFR) {
|
|
|
|
// Is it inside frame rate range? If so, just get the value from timecodes table
|
2006-03-14 01:33:31 +01:00
|
|
|
if (frame < (signed) Frame.size()) return Frame.at(frame);
|
2006-02-25 00:16:20 +01:00
|
|
|
|
|
|
|
// Otherwise, calculate it
|
2007-01-11 04:18:14 +01:00
|
|
|
else return (int)floor(Frame.back() + double(frame-Frame.size()+1) / AverageFrameRate * 1000.0);
|
2006-02-25 00:16:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown frame rate type
|
2006-02-24 23:46:21 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief otherwise for start frames returns the adjusted time for end frames when start=false Get correct frame at time
|
|
|
|
/// @param ms
|
|
|
|
/// @param start
|
|
|
|
/// @return
|
2010-06-24 03:24:26 +02:00
|
|
|
int FrameRate::GetFrameAtTime(int ms,bool start) const {
|
2006-02-24 23:57:24 +01:00
|
|
|
return PFrameAtTime(ms,start);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief compensates and returns an end time when start=false Get correct time at frame
|
2010-06-24 03:24:26 +02:00
|
|
|
/// @param frame Frame number
|
|
|
|
/// @param start Adjust for start time
|
|
|
|
/// @param exact Don't do awful things to avoid rounding errors
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @return
|
2010-06-24 03:24:26 +02:00
|
|
|
int FrameRate::GetTimeAtFrame(int frame,bool start,bool exact) const {
|
2006-02-24 23:14:37 +01:00
|
|
|
int finalTime;
|
2006-02-25 00:07:30 +01:00
|
|
|
|
|
|
|
// Exact, for display
|
|
|
|
if (exact) {
|
|
|
|
finalTime = PTimeAtFrame(frame);
|
2006-02-24 23:14:37 +01:00
|
|
|
}
|
2006-02-25 00:07:30 +01:00
|
|
|
|
|
|
|
// Adjusted, for subs sync
|
2006-02-24 23:14:37 +01:00
|
|
|
else {
|
2006-02-25 00:07:30 +01:00
|
|
|
if (start) {
|
|
|
|
finalTime = (PTimeAtFrame(frame-1) + PTimeAtFrame(frame))/2;
|
|
|
|
}
|
|
|
|
else {
|
2006-02-25 00:26:24 +01:00
|
|
|
//if (FrameRateType == VFR) finalTime = PTimeAtFrame(frame);
|
|
|
|
//else finalTime = (PTimeAtFrame(frame) + PTimeAtFrame(frame+1))/2;
|
|
|
|
finalTime = (PTimeAtFrame(frame) + PTimeAtFrame(frame+1))/2;
|
2006-02-25 00:07:30 +01:00
|
|
|
}
|
2006-02-24 23:14:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return finalTime;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Get the current list of frames/times
|
|
|
|
/// @return
|
2010-06-24 03:24:26 +02:00
|
|
|
std::vector<int> FrameRate::GetFrameTimeList() const {
|
2008-03-07 22:24:14 +01:00
|
|
|
return Frame;
|
2007-01-01 04:29:20 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:26 +02:00
|
|
|
bool FrameRate::operator==(FrameRate const& rgt) {
|
|
|
|
if (FrameRateType != rgt.FrameRateType) return false;
|
|
|
|
if (FrameRateType == NONE) return true;
|
|
|
|
if (FrameRateType == CFR) return AverageFrameRate == rgt.AverageFrameRate;
|
|
|
|
return Frame == rgt.Frame;
|
2007-01-01 04:29:20 +01:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// DOCME
|
2006-01-16 22:02:54 +01:00
|
|
|
FrameRate VFR_Output;
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2006-01-16 22:02:54 +01:00
|
|
|
FrameRate VFR_Input;
|