2006-12-18 17:20:45 +01:00
// Copyright (c) 2006, Rodrigo Braz Monteiro
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 dialog_timing_processor.cpp
/// @brief Timing Post-processor dialogue box and logic
/// @ingroup tools_ui
///
2006-01-16 22:02:54 +01:00
2009-01-04 07:31:48 +01:00
# include "config.h"
2011-01-16 08:17:36 +01:00
# ifndef AGI_PRE
# include <algorithm>
# endif
2009-09-10 15:06:40 +02:00
# include "ass_dialogue.h"
2006-01-16 22:02:54 +01:00
# include "ass_file.h"
2009-09-10 15:06:40 +02:00
# include "ass_time.h"
# include "dialog_timing_processor.h"
# include "help_button.h"
2011-01-16 08:17:36 +01:00
# include "include/aegisub/context.h"
2009-09-10 15:06:40 +02:00
# include "libresrc/libresrc.h"
2010-05-21 03:13:36 +02:00
# include "main.h"
2010-12-08 04:36:10 +01:00
# include "selection_controller.h"
2009-09-10 15:06:40 +02:00
# include "subs_grid.h"
# include "utils.h"
2006-01-16 22:02:54 +01:00
# include "validators.h"
2009-09-10 15:06:40 +02:00
# include "video_box.h"
2009-09-10 03:41:34 +02:00
# include "video_context.h"
2009-09-10 15:06:40 +02:00
# include "video_display.h"
2006-01-16 22:02:54 +01:00
2010-07-08 06:29:04 +02:00
/// Window IDs
enum {
CHECK_ENABLE_LEADIN = 1850 ,
CHECK_ENABLE_LEADOUT ,
CHECK_ENABLE_KEYFRAME ,
CHECK_ENABLE_ADJASCENT ,
BUTTON_SELECT_ALL ,
BUTTON_SELECT_NONE ,
TIMING_STYLE_LIST
} ;
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
2011-01-16 08:17:36 +01:00
DialogTimingProcessor : : DialogTimingProcessor ( agi : : Context * c )
: wxDialog ( c - > parent , - 1 , _ ( " Timing Post-Processor " ) , wxDefaultPosition , wxSize ( 400 , 250 ) , wxDEFAULT_DIALOG_STYLE )
, c ( c )
, leadInTime ( wxString : : Format ( " %d " , OPT_GET ( " Audio/Lead/IN " ) - > GetInt ( ) ) )
, leadOutTime ( wxString : : Format ( " %d " , OPT_GET ( " Audio/Lead/OUT " ) - > GetInt ( ) ) )
, thresStartBefore ( wxString : : Format ( " %d " , OPT_GET ( " Tool/Timing Post Processor/Threshold/Key Start Before " ) - > GetInt ( ) ) )
, thresStartAfter ( wxString : : Format ( " %d " , OPT_GET ( " Tool/Timing Post Processor/Threshold/Key Start After " ) - > GetInt ( ) ) )
, thresEndBefore ( wxString : : Format ( " %d " , OPT_GET ( " Tool/Timing Post Processor/Threshold/Key End Before " ) - > GetInt ( ) ) )
, thresEndAfter ( wxString : : Format ( " %d " , OPT_GET ( " Tool/Timing Post Processor/Threshold/Key End After " ) - > GetInt ( ) ) )
, adjsThresTime ( wxString : : Format ( " %d " , OPT_GET ( " Tool/Timing Post Processor/Threshold/Adjacent " ) - > GetInt ( ) ) )
2006-01-16 22:02:54 +01:00
{
2009-07-25 06:49:59 +02:00
SetIcon ( BitmapToIcon ( GETIMAGE ( timing_processor_toolbutton_24 ) ) ) ;
2007-07-05 01:09:40 +02:00
2006-01-16 22:02:54 +01:00
// Set variables
2010-05-21 03:13:36 +02:00
2007-08-16 01:17:42 +02:00
// Styles box
2007-09-24 19:40:03 +02:00
wxSizer * LeftSizer = new wxStaticBoxSizer ( wxVERTICAL , this , _ ( " Apply to styles " ) ) ;
2011-01-16 08:17:36 +01:00
wxArrayString styles = c - > ass - > GetStyles ( ) ;
2007-08-16 01:17:42 +02:00
StyleList = new wxCheckListBox ( this , TIMING_STYLE_LIST , wxDefaultPosition , wxSize ( 150 , 150 ) , styles ) ;
StyleList - > SetToolTip ( _ ( " Select styles to process. Unchecked ones will be ignored. " ) ) ;
wxButton * all = new wxButton ( this , BUTTON_SELECT_ALL , _ ( " All " ) ) ;
all - > SetToolTip ( _ ( " Select all styles. " ) ) ;
wxButton * none = new wxButton ( this , BUTTON_SELECT_NONE , _ ( " None " ) ) ;
none - > SetToolTip ( _ ( " Deselect all styles. " ) ) ;
2007-01-08 04:27:47 +01:00
// Options box
wxSizer * optionsSizer = new wxStaticBoxSizer ( wxHORIZONTAL , this , _ ( " Options " ) ) ;
onlySelection = new wxCheckBox ( this , - 1 , _ ( " Affect selection only " ) ) ;
2010-05-21 03:13:36 +02:00
onlySelection - > SetValue ( OPT_GET ( " Tool/Timing Post Processor/Only Selection " ) - > GetBool ( ) ) ;
2007-01-08 04:27:47 +01:00
optionsSizer - > Add ( onlySelection , 1 , wxALL , 0 ) ;
2006-01-16 22:02:54 +01:00
// Lead-in/out box
wxSizer * LeadSizer = new wxStaticBoxSizer ( wxHORIZONTAL , this , _ ( " Lead-in/Lead-out " ) ) ;
2006-03-21 10:24:46 +01:00
hasLeadIn = new wxCheckBox ( this , CHECK_ENABLE_LEADIN , _ ( " Add lead in: " ) ) ;
2006-01-16 22:02:54 +01:00
hasLeadIn - > SetToolTip ( _ ( " Enable adding of lead-ins to lines. " ) ) ;
2010-05-21 03:13:36 +02:00
hasLeadIn - > SetValue ( OPT_GET ( " Tool/Timing Post Processor/Enable/Lead/IN " ) - > GetBool ( ) ) ;
2006-01-16 22:02:54 +01:00
leadIn = new wxTextCtrl ( this , - 1 , _T ( " " ) , wxDefaultPosition , wxSize ( 80 , - 1 ) , 0 , NumValidator ( & leadInTime ) ) ;
2008-07-04 05:40:57 +02:00
leadIn - > SetToolTip ( _ ( " Lead in to be added, in milliseconds. " ) ) ;
2006-03-21 10:24:46 +01:00
hasLeadOut = new wxCheckBox ( this , CHECK_ENABLE_LEADOUT , _ ( " Add lead out: " ) ) ;
2006-01-16 22:02:54 +01:00
hasLeadOut - > SetToolTip ( _ ( " Enable adding of lead-outs to lines. " ) ) ;
2010-05-21 03:13:36 +02:00
hasLeadOut - > SetValue ( OPT_GET ( " Tool/Timing Post Processor/Enable/Lead/OUT " ) - > GetBool ( ) ) ;
2006-01-16 22:02:54 +01:00
leadOut = new wxTextCtrl ( this , - 1 , _T ( " " ) , wxDefaultPosition , wxSize ( 80 , - 1 ) , 0 , NumValidator ( & leadOutTime ) ) ;
2008-07-04 05:40:57 +02:00
leadOut - > SetToolTip ( _ ( " Lead out to be added, in milliseconds. " ) ) ;
2006-01-16 22:02:54 +01:00
LeadSizer - > Add ( hasLeadIn , 0 , wxRIGHT | wxEXPAND , 5 ) ;
LeadSizer - > Add ( leadIn , 0 , wxRIGHT | wxEXPAND , 5 ) ;
LeadSizer - > Add ( hasLeadOut , 0 , wxRIGHT | wxEXPAND , 5 ) ;
LeadSizer - > Add ( leadOut , 0 , wxRIGHT | wxEXPAND , 0 ) ;
LeadSizer - > AddStretchSpacer ( 1 ) ;
2008-01-27 23:09:47 +01:00
// Adjacent subs sizer
wxSizer * AdjacentSizer = new wxStaticBoxSizer ( wxHORIZONTAL , this , _ ( " Make adjacent subtitles continuous " ) ) ;
2006-03-17 02:27:30 +01:00
adjsEnable = new wxCheckBox ( this , CHECK_ENABLE_ADJASCENT , _ ( " Enable " ) ) ;
adjsEnable - > SetToolTip ( _ ( " Enable snapping of subtitles together if they are within a certain distance of each other. " ) ) ;
2010-05-21 03:13:36 +02:00
adjsEnable - > SetValue ( OPT_GET ( " Tool/Timing Post Processor/Enable/Adjacent " ) - > GetBool ( ) ) ;
2006-03-17 02:27:30 +01:00
wxStaticText * adjsThresText = new wxStaticText ( this , - 1 , _ ( " Threshold: " ) , wxDefaultPosition , wxDefaultSize , wxALIGN_CENTRE ) ;
2008-01-27 23:09:47 +01:00
adjacentThres = new wxTextCtrl ( this , - 1 , _T ( " " ) , wxDefaultPosition , wxSize ( 60 , - 1 ) , 0 , NumValidator ( & adjsThresTime ) ) ;
2008-07-04 05:40:57 +02:00
adjacentThres - > SetToolTip ( _ ( " Maximum difference between start and end time for two subtitles to be made continuous, in milliseconds. " ) ) ;
2010-12-31 22:03:03 +01:00
adjacentBias = new wxSlider ( this , - 1 , mid ( 0 , int ( OPT_GET ( " Tool/Timing Post Processor/Adjacent Bias " ) - > GetDouble ( ) * 100 ) , 100 ) , 0 , 100 , wxDefaultPosition , wxSize ( - 1 , 20 ) ) ;
2008-01-27 23:09:47 +01:00
adjacentBias - > SetToolTip ( _ ( " Sets how to set the adjoining of lines. If set totally to left, it will extend start time of the second line; if totally to right, it will extend the end time of the first line. " ) ) ;
AdjacentSizer - > Add ( adjsEnable , 0 , wxRIGHT | wxEXPAND , 10 ) ;
AdjacentSizer - > Add ( adjsThresText , 0 , wxRIGHT | wxALIGN_CENTER , 5 ) ;
AdjacentSizer - > Add ( adjacentThres , 0 , wxRIGHT | wxEXPAND , 5 ) ;
AdjacentSizer - > Add ( new wxStaticText ( this , - 1 , _ ( " Bias: Start <- " ) , wxDefaultPosition , wxDefaultSize , wxALIGN_CENTRE ) , 0 , wxALIGN_CENTER , 0 ) ;
AdjacentSizer - > Add ( adjacentBias , 1 , wxEXPAND , 0 ) ;
AdjacentSizer - > Add ( new wxStaticText ( this , - 1 , _ ( " -> End " ) , wxDefaultPosition , wxDefaultSize , wxALIGN_CENTRE ) , 0 , wxALIGN_CENTER , 0 ) ;
2006-03-17 02:27:30 +01:00
2006-01-16 22:02:54 +01:00
// Keyframes sizer
KeyframesSizer = new wxStaticBoxSizer ( wxHORIZONTAL , this , _ ( " Keyframe snapping " ) ) ;
2006-03-21 10:24:46 +01:00
wxSizer * KeyframesFlexSizer = new wxFlexGridSizer ( 2 , 5 , 5 , 0 ) ;
2006-01-16 22:02:54 +01:00
keysEnable = new wxCheckBox ( this , CHECK_ENABLE_KEYFRAME , _ ( " Enable " ) ) ;
keysEnable - > SetToolTip ( _ ( " Enable snapping of subtitles to nearest keyframe, if distance is within threshold. " ) ) ;
2010-05-21 03:13:36 +02:00
keysEnable - > SetValue ( OPT_GET ( " Tool/Timing Post Processor/Enable/Keyframe " ) - > GetBool ( ) ) ;
2006-03-21 10:24:46 +01:00
wxStaticText * textStartBefore = new wxStaticText ( this , - 1 , _ ( " Starts before thres.: " ) , wxDefaultPosition , wxDefaultSize , wxALIGN_CENTRE ) ;
keysStartBefore = new wxTextCtrl ( this , - 1 , _T ( " " ) , wxDefaultPosition , wxSize ( 60 , - 1 ) , 0 , NumValidator ( & thresStartBefore ) ) ;
keysStartBefore - > SetToolTip ( _ ( " Threshold for 'before start' distance, that is, how many frames a subtitle must start before a keyframe to snap to it. " ) ) ;
wxStaticText * textStartAfter = new wxStaticText ( this , - 1 , _ ( " Starts after thres.: " ) , wxDefaultPosition , wxDefaultSize , wxALIGN_CENTRE ) ;
keysStartAfter = new wxTextCtrl ( this , - 1 , _T ( " " ) , wxDefaultPosition , wxSize ( 60 , - 1 ) , 0 , NumValidator ( & thresStartAfter ) ) ;
keysStartAfter - > SetToolTip ( _ ( " Threshold for 'after start' distance, that is, how many frames a subtitle must start after a keyframe to snap to it. " ) ) ;
wxStaticText * textEndBefore = new wxStaticText ( this , - 1 , _ ( " Ends before thres.: " ) , wxDefaultPosition , wxDefaultSize , wxALIGN_CENTRE ) ;
keysEndBefore = new wxTextCtrl ( this , - 1 , _T ( " " ) , wxDefaultPosition , wxSize ( 60 , - 1 ) , 0 , NumValidator ( & thresEndBefore ) ) ;
keysEndBefore - > SetToolTip ( _ ( " Threshold for 'before end' distance, that is, how many frames a subtitle must end before a keyframe to snap to it. " ) ) ;
wxStaticText * textEndAfter = new wxStaticText ( this , - 1 , _ ( " Ends after thres.: " ) , wxDefaultPosition , wxDefaultSize , wxALIGN_CENTRE ) ;
keysEndAfter = new wxTextCtrl ( this , - 1 , _T ( " " ) , wxDefaultPosition , wxSize ( 60 , - 1 ) , 0 , NumValidator ( & thresEndAfter ) ) ;
keysEndAfter - > SetToolTip ( _ ( " Threshold for 'after end' distance, that is, how many frames a subtitle must end after a keyframe to snap to it. " ) ) ;
KeyframesFlexSizer - > Add ( keysEnable , 0 , wxRIGHT | wxEXPAND , 10 ) ;
KeyframesFlexSizer - > Add ( textStartBefore , 0 , wxRIGHT | wxALIGN_CENTER , 5 ) ;
KeyframesFlexSizer - > Add ( keysStartBefore , 0 , wxRIGHT | wxEXPAND , 5 ) ;
KeyframesFlexSizer - > Add ( textStartAfter , 0 , wxRIGHT | wxALIGN_CENTER , 5 ) ;
KeyframesFlexSizer - > Add ( keysStartAfter , 0 , wxRIGHT | wxEXPAND , 0 ) ;
KeyframesFlexSizer - > AddStretchSpacer ( 1 ) ;
KeyframesFlexSizer - > Add ( textEndBefore , 0 , wxRIGHT | wxALIGN_CENTER , 5 ) ;
KeyframesFlexSizer - > Add ( keysEndBefore , 0 , wxRIGHT | wxEXPAND , 5 ) ;
KeyframesFlexSizer - > Add ( textEndAfter , 0 , wxRIGHT | wxALIGN_CENTER , 5 ) ;
KeyframesFlexSizer - > Add ( keysEndAfter , 0 , wxRIGHT | wxEXPAND , 0 ) ;
KeyframesSizer - > Add ( KeyframesFlexSizer , 0 , wxEXPAND ) ;
2006-01-16 22:02:54 +01:00
KeyframesSizer - > AddStretchSpacer ( 1 ) ;
// Button sizer
2007-07-02 06:47:04 +02:00
wxStdDialogButtonSizer * ButtonSizer = new wxStdDialogButtonSizer ( ) ;
ApplyButton = new wxButton ( this , wxID_OK ) ;
ButtonSizer - > AddButton ( ApplyButton ) ;
ButtonSizer - > AddButton ( new wxButton ( this , wxID_CANCEL ) ) ;
2008-01-13 22:27:06 +01:00
ButtonSizer - > AddButton ( new HelpButton ( this , _T ( " Timing Processor " ) ) ) ;
2007-07-02 06:47:04 +02:00
ButtonSizer - > Realize ( ) ;
2006-01-16 22:02:54 +01:00
// Right Sizer
wxSizer * RightSizer = new wxBoxSizer ( wxVERTICAL ) ;
2007-01-08 04:27:47 +01:00
RightSizer - > Add ( optionsSizer , 0 , wxBOTTOM | wxEXPAND , 5 ) ;
2006-01-16 22:02:54 +01:00
RightSizer - > Add ( LeadSizer , 0 , wxBOTTOM | wxEXPAND , 5 ) ;
2008-01-27 23:09:47 +01:00
RightSizer - > Add ( AdjacentSizer , 0 , wxBOTTOM | wxEXPAND , 5 ) ;
2006-03-17 02:27:30 +01:00
RightSizer - > Add ( KeyframesSizer , 0 , wxBOTTOM | wxEXPAND , 5 ) ;
2006-01-16 22:02:54 +01:00
RightSizer - > AddStretchSpacer ( 1 ) ;
RightSizer - > Add ( ButtonSizer , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 0 ) ;
// Style buttons sizer
wxSizer * StyleButtonsSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
StyleButtonsSizer - > Add ( all , 1 , 0 , 0 ) ;
StyleButtonsSizer - > Add ( none , 1 , 0 , 0 ) ;
// Left sizer
size_t len = StyleList - > GetCount ( ) ;
for ( size_t i = 0 ; i < len ; i + + ) {
StyleList - > Check ( i ) ;
}
LeftSizer - > Add ( StyleList , 1 , wxBOTTOM | wxEXPAND , 0 ) ;
LeftSizer - > Add ( StyleButtonsSizer , 0 , wxEXPAND , 0 ) ;
// Top Sizer
wxSizer * TopSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
TopSizer - > Add ( LeftSizer , 0 , wxRIGHT | wxEXPAND , 5 ) ;
TopSizer - > Add ( RightSizer , 1 , wxALL | wxEXPAND , 0 ) ;
// Main Sizer
wxSizer * MainSizer = new wxBoxSizer ( wxVERTICAL ) ;
MainSizer - > Add ( TopSizer , 1 , wxALL | wxEXPAND , 5 ) ;
MainSizer - > SetSizeHints ( this ) ;
SetSizer ( MainSizer ) ;
2006-01-27 01:48:59 +01:00
CenterOnParent ( ) ;
2006-01-16 22:02:54 +01:00
UpdateControls ( ) ;
}
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 Update controls
///
2006-01-16 22:02:54 +01:00
void DialogTimingProcessor : : UpdateControls ( ) {
// Boxes
leadIn - > Enable ( hasLeadIn - > IsChecked ( ) ) ;
leadOut - > Enable ( hasLeadOut - > IsChecked ( ) ) ;
2008-01-27 23:09:47 +01:00
adjacentThres - > Enable ( adjsEnable - > IsChecked ( ) ) ;
adjacentBias - > Enable ( adjsEnable - > IsChecked ( ) ) ;
2006-01-16 22:02:54 +01:00
// Keyframes are only available if timecodes are loaded
2007-01-21 07:30:19 +01:00
bool keysAvailable = VideoContext : : Get ( ) - > KeyFramesLoaded ( ) ;
2006-01-16 22:02:54 +01:00
bool enableKeys = keysEnable - > IsChecked ( ) & & keysAvailable ;
2006-03-21 10:24:46 +01:00
keysStartBefore - > Enable ( enableKeys ) ;
keysStartAfter - > Enable ( enableKeys ) ;
keysEndBefore - > Enable ( enableKeys ) ;
keysEndAfter - > Enable ( enableKeys ) ;
2006-01-16 22:02:54 +01:00
if ( ! keysAvailable ) {
keysEnable - > SetValue ( false ) ;
keysEnable - > Enable ( false ) ;
}
// Apply button
int checked = 0 ;
size_t len = StyleList - > GetCount ( ) ;
for ( size_t i = 0 ; i < len ; i + + ) {
if ( StyleList - > IsChecked ( i ) ) checked + + ;
}
ApplyButton - > Enable ( checked & & ( hasLeadIn - > IsChecked ( ) | hasLeadOut - > IsChecked ( ) | keysEnable - > IsChecked ( ) | adjsEnable - > IsChecked ( ) ) ) ;
}
BEGIN_EVENT_TABLE ( DialogTimingProcessor , wxDialog )
EVT_CHECKBOX ( CHECK_ENABLE_LEADIN , DialogTimingProcessor : : OnCheckBox )
EVT_CHECKBOX ( CHECK_ENABLE_LEADOUT , DialogTimingProcessor : : OnCheckBox )
EVT_CHECKBOX ( CHECK_ENABLE_KEYFRAME , DialogTimingProcessor : : OnCheckBox )
EVT_CHECKBOX ( CHECK_ENABLE_ADJASCENT , DialogTimingProcessor : : OnCheckBox )
EVT_CHECKLISTBOX ( TIMING_STYLE_LIST , DialogTimingProcessor : : OnCheckBox )
2007-07-02 06:47:04 +02:00
EVT_BUTTON ( wxID_OK , DialogTimingProcessor : : OnApply )
2006-01-16 22:02:54 +01:00
EVT_BUTTON ( BUTTON_SELECT_ALL , DialogTimingProcessor : : OnSelectAll )
EVT_BUTTON ( BUTTON_SELECT_NONE , DialogTimingProcessor : : OnSelectNone )
END_EVENT_TABLE ( )
2010-07-08 06:29:04 +02:00
void DialogTimingProcessor : : OnCheckBox ( wxCommandEvent & ) {
2006-01-16 22:02:54 +01:00
UpdateControls ( ) ;
}
2010-07-08 06:29:04 +02:00
void DialogTimingProcessor : : OnSelectAll ( wxCommandEvent & ) {
2006-01-16 22:02:54 +01:00
size_t len = StyleList - > GetCount ( ) ;
for ( size_t i = 0 ; i < len ; i + + ) {
StyleList - > Check ( i ) ;
}
UpdateControls ( ) ;
}
2010-07-08 06:29:04 +02:00
void DialogTimingProcessor : : OnSelectNone ( wxCommandEvent & ) {
2006-01-16 22:02:54 +01:00
size_t len = StyleList - > GetCount ( ) ;
for ( size_t i = 0 ; i < len ; i + + ) {
StyleList - > Check ( i , false ) ;
}
UpdateControls ( ) ;
}
2010-07-08 06:29:04 +02:00
void DialogTimingProcessor : : OnApply ( wxCommandEvent & ) {
2006-01-16 22:02:54 +01:00
// Save settings
long temp = 0 ;
leadIn - > GetValue ( ) . ToLong ( & temp ) ;
2010-05-21 03:13:36 +02:00
OPT_SET ( " Audio/Lead/IN " ) - > SetInt ( temp ) ;
2006-01-16 22:02:54 +01:00
leadOut - > GetValue ( ) . ToLong ( & temp ) ;
2010-05-21 03:13:36 +02:00
OPT_SET ( " Audio/Lead/OUT " ) - > SetInt ( temp ) ;
2006-03-21 10:24:46 +01:00
keysStartBefore - > GetValue ( ) . ToLong ( & temp ) ;
2010-05-21 03:13:36 +02:00
OPT_SET ( " Tool/Timing Post Processor/Threshold/Key Start Before " ) - > SetInt ( temp ) ;
2006-03-21 10:24:46 +01:00
keysStartAfter - > GetValue ( ) . ToLong ( & temp ) ;
2010-05-21 03:13:36 +02:00
OPT_SET ( " Tool/Timing Post Processor/Threshold/Key Start After " ) - > SetInt ( temp ) ;
2006-03-21 10:24:46 +01:00
keysEndBefore - > GetValue ( ) . ToLong ( & temp ) ;
2010-05-21 03:13:36 +02:00
OPT_SET ( " Tool/Timing Post Processor/Threshold/Key End Before " ) - > SetInt ( temp ) ;
2006-03-21 10:24:46 +01:00
keysEndAfter - > GetValue ( ) . ToLong ( & temp ) ;
2010-05-21 03:13:36 +02:00
OPT_SET ( " Tool/Timing Post Processor/Threshold/Key End After " ) - > SetInt ( temp ) ;
2008-01-27 23:09:47 +01:00
adjacentThres - > GetValue ( ) . ToLong ( & temp ) ;
2010-05-21 03:13:36 +02:00
OPT_SET ( " Tool/Timing Post Processor/Threshold/Adjacent " ) - > SetInt ( temp ) ;
OPT_SET ( " Tool/Timing Post Processor/Adjacent Bias " ) - > SetDouble ( adjacentBias - > GetValue ( ) / 100.0 ) ;
OPT_SET ( " Tool/Timing Post Processor/Enable/Lead/IN " ) - > SetBool ( hasLeadIn - > IsChecked ( ) ) ;
OPT_SET ( " Tool/Timing Post Processor/Enable/Lead/OUT " ) - > SetBool ( hasLeadOut - > IsChecked ( ) ) ;
if ( keysEnable - > IsEnabled ( ) ) OPT_SET ( " Tool/Timing Post Processor/Enable/Keyframe " ) - > SetBool ( keysEnable - > IsChecked ( ) ) ;
OPT_SET ( " Tool/Timing Post Processor/Enable/Adjacent " ) - > SetBool ( adjsEnable - > IsChecked ( ) ) ;
OPT_SET ( " Tool/Timing Post Processor/Only Selection " ) - > SetBool ( onlySelection - > IsChecked ( ) ) ;
2006-01-16 22:02:54 +01:00
// Check if rows are valid
2011-01-16 08:17:36 +01:00
for ( entryIter cur = c - > ass - > Line . begin ( ) ; cur ! = c - > ass - > Line . end ( ) ; + + cur ) {
if ( AssDialogue * tempDiag = dynamic_cast < AssDialogue * > ( * cur ) ) {
2006-01-16 22:02:54 +01:00
if ( tempDiag - > Start . GetMS ( ) > tempDiag - > End . GetMS ( ) ) {
2011-01-16 08:17:36 +01:00
wxMessageBox (
wxString : : Format (
_ ( " One of the lines in the file (%i) has negative duration. Aborting. " ) ,
std : : distance ( c - > ass - > Line . begin ( ) , cur ) ) ,
_ ( " Invalid script " ) ,
wxICON_ERROR | wxOK ) ;
EndModal ( 0 ) ;
return ;
2006-01-16 22:02:54 +01:00
}
}
}
2011-01-16 08:17:36 +01:00
Process ( ) ;
2006-01-16 22:02:54 +01:00
EndModal ( 0 ) ;
}
int DialogTimingProcessor : : GetClosestKeyFrame ( int frame ) {
2011-01-16 08:17:36 +01:00
std : : vector < int > : : iterator pos = lower_bound ( KeyFrames . begin ( ) , KeyFrames . end ( ) , frame ) ;
if ( distance ( pos , KeyFrames . end ( ) ) < 2 ) return KeyFrames . back ( ) ;
return frame - * pos < * ( pos + 1 ) - frame ? * pos : * ( pos + 1 ) ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:17:36 +01:00
static bool bad_line ( std : : set < wxString > * styles , AssDialogue * d ) {
return ! d | | d - > Comment | | styles - > find ( d - > Style ) = = styles - > end ( ) ;
2006-01-16 22:02:54 +01:00
}
void DialogTimingProcessor : : SortDialogues ( ) {
2011-01-16 08:17:36 +01:00
std : : set < wxString > styles ;
for ( size_t i = 0 ; i < StyleList - > GetCount ( ) ; + + i ) {
if ( StyleList - > IsChecked ( i ) ) {
styles . insert ( StyleList - > GetString ( i ) ) ;
2006-01-16 22:02:54 +01:00
}
}
2007-01-08 04:27:47 +01:00
Sorted . clear ( ) ;
2011-01-16 08:17:36 +01:00
Sorted . reserve ( c - > ass - > Line . size ( ) ) ;
if ( onlySelection - > IsChecked ( ) ) {
SelectionController < AssDialogue > : : Selection sel = c - > selectionController - > GetSelectedSet ( ) ;
remove_copy_if ( sel . begin ( ) , sel . end ( ) , back_inserter ( Sorted ) ,
bind ( bad_line , & styles , std : : tr1 : : placeholders : : _1 ) ) ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:17:36 +01:00
else {
std : : vector < AssDialogue * > tmp ( c - > ass - > Line . size ( ) ) ;
transform ( c - > ass - > Line . begin ( ) , c - > ass - > Line . end ( ) , back_inserter ( tmp ) , cast < AssDialogue * > ( ) ) ;
remove_copy_if ( tmp . begin ( ) , tmp . end ( ) , back_inserter ( Sorted ) ,
bind ( bad_line , & styles , std : : tr1 : : placeholders : : _1 ) ) ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:17:36 +01:00
sort ( Sorted . begin ( ) , Sorted . end ( ) , AssFile : : CompStart ) ;
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 Actually process subtitles
///
2006-01-16 22:02:54 +01:00
void DialogTimingProcessor : : Process ( ) {
SortDialogues ( ) ;
int rows = Sorted . size ( ) ;
// Options
long inVal = 0 ;
long outVal = 0 ;
leadIn - > GetValue ( ) . ToLong ( & inVal ) ;
leadOut - > GetValue ( ) . ToLong ( & outVal ) ;
bool addIn = hasLeadIn - > IsChecked ( ) & & inVal ;
bool addOut = hasLeadOut - > IsChecked ( ) & & outVal ;
// Add lead-in/out
if ( addIn | | addOut ) {
for ( int i = 0 ; i < rows ; i + + ) {
2011-01-16 08:17:36 +01:00
AssDialogue * cur = Sorted [ i ] ;
2006-01-16 22:02:54 +01:00
// Compare to every previous line (yay for O(n^2)!) to see if it's OK to add lead-in
2011-01-16 08:17:36 +01:00
if ( inVal ) {
int startLead = cur - > Start . GetMS ( ) - inVal ;
2006-01-16 22:02:54 +01:00
for ( int j = 0 ; j < i ; j + + ) {
2011-01-16 08:17:36 +01:00
AssDialogue * comp = Sorted [ j ] ;
2006-01-16 22:02:54 +01:00
// Check if they don't already collide (ignore it in that case)
if ( cur - > CollidesWith ( comp ) ) continue ;
// Get comparison times
2011-01-16 08:17:36 +01:00
startLead = std : : max ( startLead , comp - > End . GetMS ( ) ) ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:17:36 +01:00
cur - > Start . SetMS ( startLead ) ;
2006-01-16 22:02:54 +01:00
}
// Compare to every line to see how far can lead-out be extended
2011-01-16 08:17:36 +01:00
if ( outVal ) {
int endLead = cur - > End . GetMS ( ) + outVal ;
2006-01-16 22:02:54 +01:00
for ( int j = i + 1 ; j < rows ; j + + ) {
2011-01-16 08:17:36 +01:00
AssDialogue * comp = Sorted [ j ] ;
2006-01-16 22:02:54 +01:00
// Check if they don't already collide (ignore it in that case)
if ( cur - > CollidesWith ( comp ) ) continue ;
// Get comparison times
2011-01-16 08:17:36 +01:00
endLead = std : : min ( endLead , comp - > Start . GetMS ( ) ) ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:17:36 +01:00
cur - > End . SetMS ( endLead ) ;
2006-01-16 22:02:54 +01:00
}
}
}
2008-01-27 23:09:47 +01:00
// Make adjacent
2006-01-16 22:02:54 +01:00
if ( adjsEnable - > IsChecked ( ) ) {
2011-01-16 08:17:36 +01:00
AssDialogue * prev = Sorted . front ( ) ;
2006-01-16 22:02:54 +01:00
long adjsThres = 0 ;
2008-01-27 23:09:47 +01:00
adjacentThres - > GetValue ( ) . ToLong ( & adjsThres ) ;
2006-01-16 22:02:54 +01:00
2008-01-27 23:09:47 +01:00
float bias = adjacentBias - > GetValue ( ) / 100.0 ;
2006-03-05 03:25:12 +01:00
2011-01-16 08:17:36 +01:00
for ( int i = 1 ; i < rows ; i + + ) {
AssDialogue * cur = Sorted [ i ] ;
2006-01-16 22:02:54 +01:00
// Check if they don't collide
if ( cur - > CollidesWith ( prev ) ) continue ;
// Compare distance
2011-01-16 08:17:36 +01:00
int curStart = cur - > Start . GetMS ( ) ;
int prevEnd = prev - > End . GetMS ( ) ;
int dist = curStart - prevEnd ;
2006-01-16 22:02:54 +01:00
if ( dist > 0 & & dist < adjsThres ) {
2006-03-05 03:25:12 +01:00
int setPos = prevEnd + int ( dist * bias ) ;
cur - > Start . SetMS ( setPos ) ;
prev - > End . SetMS ( setPos ) ;
2006-01-16 22:02:54 +01:00
}
prev = cur ;
}
}
// Keyframe snapping
if ( keysEnable - > IsChecked ( ) ) {
2011-01-16 08:17:36 +01:00
KeyFrames = c - > videoController - > GetKeyFrames ( ) ;
KeyFrames . push_back ( c - > videoController - > GetLength ( ) - 1 ) ;
2006-01-16 22:02:54 +01:00
2006-03-21 10:24:46 +01:00
long beforeStart = 0 ;
long afterStart = 0 ;
long beforeEnd = 0 ;
long afterEnd = 0 ;
keysStartBefore - > GetValue ( ) . ToLong ( & beforeStart ) ;
keysStartAfter - > GetValue ( ) . ToLong ( & afterStart ) ;
keysEndBefore - > GetValue ( ) . ToLong ( & beforeEnd ) ;
keysEndAfter - > GetValue ( ) . ToLong ( & afterEnd ) ;
2006-01-16 22:02:54 +01:00
for ( int i = 0 ; i < rows ; i + + ) {
2011-01-16 08:17:36 +01:00
AssDialogue * cur = Sorted [ i ] ;
2006-01-16 22:02:54 +01:00
// Get start/end frames
2011-01-16 08:17:36 +01:00
int startF = c - > videoController - > FrameAtTime ( cur - > Start . GetMS ( ) , agi : : vfr : : START ) ;
int endF = c - > videoController - > FrameAtTime ( cur - > End . GetMS ( ) , agi : : vfr : : END ) ;
2006-01-16 22:02:54 +01:00
// Get closest for start
2011-01-16 08:17:36 +01:00
int closest = GetClosestKeyFrame ( startF ) ;
2006-03-21 10:24:46 +01:00
if ( ( closest > startF & & closest - startF < = beforeStart ) | | ( closest < startF & & startF - closest < = afterStart ) ) {
2011-01-16 08:17:36 +01:00
cur - > Start . SetMS ( c - > videoController - > TimeAtFrame ( closest , agi : : vfr : : START ) ) ;
2006-01-16 22:02:54 +01:00
}
// Get closest for end
closest = GetClosestKeyFrame ( endF ) - 1 ;
2006-03-21 10:24:46 +01:00
if ( ( closest > endF & & closest - endF < = beforeEnd ) | | ( closest < endF & & endF - closest < = afterEnd ) ) {
2011-01-16 08:17:36 +01:00
cur - > End . SetMS ( c - > videoController - > TimeAtFrame ( closest , agi : : vfr : : END ) ) ;
2006-01-16 22:02:54 +01:00
}
}
}
// Update grid
2011-01-16 08:17:36 +01:00
c - > ass - > Commit ( _ ( " timing processor " ) , AssFile : : COMMIT_TIMES ) ;
2006-01-16 22:02:54 +01:00
}