many fixes and improvements

This commit is contained in:
itsmattkc
2018-07-19 13:02:35 +01:00
parent 33f8d7274a
commit c375cd3ee7
10 changed files with 239 additions and 228 deletions
+50 -42
View File
@@ -24,6 +24,9 @@ Viewer::Viewer(QWidget *parent) :
viewer_widget = ui->openGLWidget;
timecode_view = TIMECODE_DROP;
update_sequence();
update_playhead_timecode(0);
update_end_timecode();
}
Viewer::~Viewer()
@@ -32,8 +35,8 @@ Viewer::~Viewer()
delete ui;
}
QString Viewer::frame_to_timecode(long f) {
if (timecode_view == TIMECODE_FRAMES) {
QString Viewer::frame_to_timecode(long f, int view, double frame_rate) {
if (view == TIMECODE_FRAMES) {
return QString::number(f);
}
@@ -44,49 +47,47 @@ QString Viewer::frame_to_timecode(long f) {
int frames = 0;
QString token = ":";
if (sequence != NULL) {
if (timecode_view == TIMECODE_DROP && frame_rate_is_droppable(sequence->frame_rate)) {
//CONVERT A FRAME NUMBER TO DROP FRAME TIMECODE
//Code by David Heidelberger, adapted from Andrew Duncan, further adapted for Olive by Olive Team
//Given an int called framenumber and a double called framerate
//Framerate should be 29.97, 59.94, or 23.976, otherwise the calculations will be off.
if (view == TIMECODE_DROP && frame_rate_is_droppable(frame_rate)) {
//CONVERT A FRAME NUMBER TO DROP FRAME TIMECODE
//Code by David Heidelberger, adapted from Andrew Duncan, further adapted for Olive by Olive Team
//Given an int called framenumber and a double called framerate
//Framerate should be 29.97, 59.94, or 23.976, otherwise the calculations will be off.
int d;
int m;
int d;
int m;
int dropFrames = round(sequence->frame_rate * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate
int framesPerHour = round(sequence->frame_rate*60*60); //Number of frames in an hour
int framesPer24Hours = framesPerHour*24; //Number of frames in a day - timecode rolls over after 24 hours
int framesPer10Minutes = round(sequence->frame_rate * 60 * 10); //Number of frames per ten minutes
int framesPerMinute = (round(sequence->frame_rate)*60)- dropFrames; //Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames
int dropFrames = round(frame_rate * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate
int framesPerHour = round(frame_rate*60*60); //Number of frames in an hour
int framesPer24Hours = framesPerHour*24; //Number of frames in a day - timecode rolls over after 24 hours
int framesPer10Minutes = round(frame_rate * 60 * 10); //Number of frames per ten minutes
int framesPerMinute = (round(frame_rate)*60)- dropFrames; //Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames
//If framenumber is greater than 24 hrs, next operation will rollover clock
f = f % framesPer24Hours; //% is the modulus operator, which returns a remainder. a % b = the remainder of a/b
//If framenumber is greater than 24 hrs, next operation will rollover clock
f = f % framesPer24Hours; //% is the modulus operator, which returns a remainder. a % b = the remainder of a/b
d = f / framesPer10Minutes; // \ means integer division, which is a/b without a remainder. Some languages you could use floor(a/b)
m = f % framesPer10Minutes;
d = f / framesPer10Minutes; // \ means integer division, which is a/b without a remainder. Some languages you could use floor(a/b)
m = f % framesPer10Minutes;
//In the original post, the next line read m>1, which only worked for 29.97. Jean-Baptiste Mardelle correctly pointed out that m should be compared to dropFrames.
if (m > dropFrames) {
f = f + (dropFrames*9*d) + dropFrames * ((m - dropFrames) / framesPerMinute);
} else {
f = f + dropFrames*9*d;
}
int frRound = round(sequence->frame_rate);
frames = f % frRound;
secs = (f / frRound) % 60;
mins = ((f / frRound) / 60) % 60;
hours = (((f / frRound) / 60) / 60);
token = ";";
//In the original post, the next line read m>1, which only worked for 29.97. Jean-Baptiste Mardelle correctly pointed out that m should be compared to dropFrames.
if (m > dropFrames) {
f = f + (dropFrames*9*d) + dropFrames * ((m - dropFrames) / framesPerMinute);
} else {
int int_fps = qRound(sequence->frame_rate);
hours = f/ (3600 * int_fps);
mins = f / (60*int_fps) % 60;
secs = f/int_fps % 60;
frames = f%int_fps;
f = f + dropFrames*9*d;
}
int frRound = round(frame_rate);
frames = f % frRound;
secs = (f / frRound) % 60;
mins = ((f / frRound) / 60) % 60;
hours = (((f / frRound) / 60) / 60);
token = ";";
} else {
int int_fps = qRound(frame_rate);
hours = f/ (3600 * int_fps);
mins = f / (60*int_fps) % 60;
secs = f/int_fps % 60;
frames = f%int_fps;
}
return QString(QString::number(hours).rightJustified(2, '0') +
":" + QString::number(mins).rightJustified(2, '0') +
@@ -99,12 +100,16 @@ bool frame_rate_is_droppable(float rate) {
return (rate == 23.976f || rate == 29.97f || rate == 59.94f);
}
void Viewer::update_playhead_timecode() {
ui->currentTimecode->setText(frame_to_timecode(panel_timeline->playhead));
void Viewer::update_playhead_timecode(long p) {
ui->currentTimecode->setText(frame_to_timecode(p, timecode_view, (sequence != NULL) ? sequence->frame_rate : 30));
}
void Viewer::update_end_timecode() {
ui->endTimecode->setText(frame_to_timecode(sequence->getEndFrame()));
if (sequence == NULL) {
ui->endTimecode->setText(frame_to_timecode(0, timecode_view, 30));
} else {
ui->endTimecode->setText(frame_to_timecode(sequence->getEndFrame(), timecode_view, sequence->frame_rate));
}
}
void Viewer::update_sequence() {
@@ -127,11 +132,14 @@ void Viewer::update_sequence() {
timecode_view = TIMECODE_NONDROP;
}
update_playhead_timecode();
update_playhead_timecode(panel_timeline->playhead);
update_end_timecode();
ui->glViewerPane->aspect_ratio = (float) sequence->width / (float) sequence->height;
ui->glViewerPane->adjust();
} else {
update_playhead_timecode(0);
update_end_timecode();
}
update();