2007-01-13 03:42:19 +01:00
|
|
|
// Copyright (c) 2005, Dan Donovan (Dansolo)
|
2009-06-08 04:37:09 +02:00
|
|
|
// Copyright (c) 2009, Niels Martin Hansen
|
2007-01-13 03:22:28 +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.
|
|
|
|
//
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// AEGISUB
|
|
|
|
//
|
|
|
|
// Website: http://aegisub.cellosoft.com
|
|
|
|
// Contact: mailto:zeratul@cellosoft.com
|
2007-01-15 00:34:27 +01:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-06-19 08:04:47 +02:00
|
|
|
#include <vector>
|
2009-06-08 04:37:09 +02:00
|
|
|
#include <deque>
|
2007-01-13 03:22:28 +01:00
|
|
|
#include "dialog_kanji_timer.h"
|
|
|
|
#include "ass_file.h"
|
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_style.h"
|
|
|
|
#include "ass_override.h"
|
|
|
|
#include "subs_grid.h"
|
|
|
|
#include "validators.h"
|
2007-01-21 18:01:22 +01:00
|
|
|
#include "video_context.h"
|
2007-07-05 01:09:40 +02:00
|
|
|
#include "utils.h"
|
2007-10-31 22:52:51 +01:00
|
|
|
#include "help_button.h"
|
2009-06-08 04:37:09 +02:00
|
|
|
#include "ass_karaoke.h"
|
|
|
|
#include <wx/string.h>
|
2009-07-24 02:08:25 +02:00
|
|
|
#include "libresrc/libresrc.h"
|
2009-07-25 18:15:13 +02:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// These are made with #define in the hope gettext can pick it up for translation then
|
|
|
|
#define TEXT_LABEL_SOURCE _("Source: ")
|
|
|
|
#define TEXT_LABEL_DEST _("Dest: ")
|
|
|
|
|
|
|
|
|
|
|
|
class KaraokeLineMatchDisplay : public wxControl {
|
|
|
|
struct MatchSyllable {
|
|
|
|
int dur;
|
|
|
|
wxString text;
|
2009-06-25 00:22:45 +02:00
|
|
|
MatchSyllable(int _dur, const wxString &_text) : dur(_dur), text(_text) { }
|
2009-06-08 04:37:09 +02:00
|
|
|
};
|
|
|
|
struct MatchGroup {
|
2009-06-25 04:31:35 +02:00
|
|
|
std::vector<MatchSyllable> src;
|
|
|
|
typedef std::vector<MatchSyllable>::iterator SrcIterator;
|
2009-06-08 04:37:09 +02:00
|
|
|
wxString dst;
|
|
|
|
int duration;
|
|
|
|
int last_render_width;
|
|
|
|
MatchGroup() : duration(0), last_render_width(0) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Groups matched on current line so far
|
|
|
|
std::vector<MatchGroup> matched_groups;
|
|
|
|
typedef std::vector<MatchGroup>::iterator MatchedGroupIterator;
|
|
|
|
// Unmatched source syllables
|
2009-06-25 04:31:35 +02:00
|
|
|
std::deque<MatchSyllable> unmatched_source;
|
|
|
|
typedef std::deque<MatchSyllable>::iterator UnmatchedSourceIterator;
|
2009-06-08 04:37:09 +02:00
|
|
|
// Unmatched destination text
|
|
|
|
wxString unmatched_destination;
|
|
|
|
|
|
|
|
int last_total_matchgroup_render_width;
|
|
|
|
|
|
|
|
// Length of current selection in the unmatched source and destination
|
|
|
|
int source_sel_length;
|
|
|
|
int destination_sel_length;
|
|
|
|
|
|
|
|
// Whether source and destination lines are set
|
|
|
|
bool has_source, has_destination;
|
|
|
|
|
|
|
|
void OnPaint(wxPaintEvent &event);
|
|
|
|
void OnKeyboard(wxKeyEvent &event);
|
|
|
|
void OnFocusEvent(wxFocusEvent &event);
|
|
|
|
|
|
|
|
const wxString label_source, label_destination;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Start processing a new line pair
|
|
|
|
void SetInputData(const AssDialogue *src, const AssDialogue *dst);
|
|
|
|
// Build and return the output line from the matched syllables
|
|
|
|
wxString GetOutputLine();
|
|
|
|
|
|
|
|
// Number of syllables not yet matched from source
|
|
|
|
int GetRemainingSource();
|
|
|
|
// Number of characters not yet matched from destination
|
|
|
|
int GetRemainingDestination();
|
|
|
|
|
|
|
|
// Adjust source and destination match lengths
|
|
|
|
void IncreaseSourceMatch();
|
|
|
|
void DecreaseSourceMatch();
|
|
|
|
void IncreseDestinationMatch();
|
|
|
|
void DecreaseDestinationMatch();
|
|
|
|
// Attempt to treat source as Japanese romaji, destination as Japanese kana+kanji, and make an automatic match
|
|
|
|
void AutoMatchJapanese();
|
|
|
|
// Accept current selection and save match
|
|
|
|
bool AcceptMatch();
|
|
|
|
// Undo last match, adding it back to the unmatched input
|
|
|
|
bool UndoMatch();
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor and destructor
|
|
|
|
KaraokeLineMatchDisplay(DialogKanjiTimer *parent);
|
|
|
|
~KaraokeLineMatchDisplay();
|
|
|
|
|
|
|
|
wxSize GetBestSize();
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
KaraokeLineMatchDisplay::KaraokeLineMatchDisplay(DialogKanjiTimer *parent)
|
|
|
|
: wxControl(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxWANTS_CHARS)
|
|
|
|
, label_source(TEXT_LABEL_SOURCE)
|
|
|
|
, label_destination(TEXT_LABEL_DEST)
|
|
|
|
{
|
|
|
|
InheritAttributes();
|
|
|
|
SetInputData(0, 0);
|
|
|
|
|
|
|
|
wxSize best_size = GetBestSize();
|
|
|
|
SetMaxSize(wxSize(-1, best_size.GetHeight()));
|
|
|
|
SetMinSize(best_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
KaraokeLineMatchDisplay::~KaraokeLineMatchDisplay()
|
|
|
|
{
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSize KaraokeLineMatchDisplay::GetBestSize()
|
|
|
|
{
|
|
|
|
int w_src, h_src, w_dst, h_dst;
|
|
|
|
GetTextExtent(label_source, &w_src, &h_src);
|
|
|
|
GetTextExtent(label_destination, &w_dst, &h_dst);
|
|
|
|
|
|
|
|
int min_width = (w_dst > w_src) ? w_dst : w_src;
|
|
|
|
|
|
|
|
// Magic number 7:
|
|
|
|
// 1 pixel for top black border, 1 pixel white top border in first row, 1 pixel white bottom padding in first row
|
|
|
|
// 1 pixel middle border, 1 pixel top and 1 pixel bottom padding in second row, 1 pixel bottom border
|
|
|
|
return wxSize(min_width * 2, h_src + h_dst + 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(KaraokeLineMatchDisplay,wxControl)
|
|
|
|
EVT_PAINT(KaraokeLineMatchDisplay::OnPaint)
|
|
|
|
EVT_KEY_DOWN(KaraokeLineMatchDisplay::OnKeyboard)
|
|
|
|
EVT_SET_FOCUS(KaraokeLineMatchDisplay::OnFocusEvent)
|
|
|
|
EVT_KILL_FOCUS(KaraokeLineMatchDisplay::OnFocusEvent)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
int DrawBoxedText(wxDC &dc, const wxString &txt, int x, int y)
|
|
|
|
{
|
|
|
|
int tw, th;
|
|
|
|
// Assume the pen, brush and font properties have already been set in the DC.
|
|
|
|
// Return the advance width, including box margins, borders etc
|
|
|
|
|
|
|
|
if (txt == _T(""))
|
|
|
|
{
|
|
|
|
// Empty string gets special handling:
|
|
|
|
// The box is drawn in shorter width, to emphasize it's empty
|
|
|
|
// GetTextExtent has to be called with a non-empty string, otherwise it returns the wrong height
|
|
|
|
dc.GetTextExtent(_T(" "), &tw, &th);
|
|
|
|
dc.DrawRectangle(x, y-2, 4, th+4);
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dc.GetTextExtent(txt, &tw, &th);
|
|
|
|
dc.DrawRectangle(x, y-2, tw+4, th+4);
|
|
|
|
dc.DrawText(txt, x+2, y);
|
|
|
|
return tw+3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KaraokeLineMatchDisplay::OnPaint(wxPaintEvent &event)
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
|
|
|
|
wxColour outer_text(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
|
|
|
|
wxColour outer_back(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
2009-06-08 05:34:09 +02:00
|
|
|
wxColour outer_frame(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
|
2009-06-08 04:37:09 +02:00
|
|
|
wxColour inner_back(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
|
|
|
wxColour inner_text(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
|
|
|
|
wxColour sel_back(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
|
|
|
|
wxColour sel_text(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
|
|
|
|
|
|
|
|
// Y coordinates of the top and bottom lines
|
|
|
|
int y_line1, y_line2, y_line3;
|
|
|
|
// Next X coordinate to draw a matched syllable at
|
|
|
|
int next_x;
|
|
|
|
|
|
|
|
wxSize client_size = GetClientSize();
|
|
|
|
|
|
|
|
// Calculate the text line positions
|
|
|
|
{
|
|
|
|
int x, y, x2;
|
|
|
|
GetTextExtent(label_source, &x, &y);
|
|
|
|
y_line1 = 2;
|
|
|
|
y_line2 = y_line1 + y + 3;
|
|
|
|
y_line3 = y_line2 + y + 3;
|
|
|
|
GetTextExtent(label_destination, &x2, &y);
|
|
|
|
next_x = (x2 > x) ? x2 : x;
|
|
|
|
next_x += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paint the labels
|
|
|
|
dc.SetTextBackground(outer_back);
|
|
|
|
if (FindFocus() == this)
|
|
|
|
dc.SetTextForeground(outer_text);
|
|
|
|
else
|
|
|
|
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
|
|
|
|
dc.SetFont(GetFont());
|
|
|
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
|
|
|
dc.DrawText(label_source, wxPoint(0, y_line1));
|
|
|
|
dc.DrawText(label_destination, wxPoint(0, y_line2));
|
|
|
|
|
|
|
|
// Horizontal lines through the width of the control
|
|
|
|
dc.SetPen(wxPen(outer_frame));
|
|
|
|
dc.DrawLine(next_x-1, y_line1-2, client_size.GetWidth(), y_line1-2);
|
|
|
|
dc.DrawLine(next_x-1, y_line2-2, client_size.GetWidth(), y_line2-2);
|
|
|
|
dc.DrawLine(next_x-1, y_line3-2, client_size.GetWidth(), y_line3-2);
|
|
|
|
|
|
|
|
// Draw matched groups
|
|
|
|
int this_total_matchgroup_render_width = 0;
|
|
|
|
bool scroll_arrows_drawn = false;
|
|
|
|
for (size_t i = 0; i < matched_groups.size(); ++i)
|
|
|
|
{
|
|
|
|
MatchGroup &grp = matched_groups[i];
|
|
|
|
int prev_x = next_x;
|
|
|
|
|
|
|
|
// Skip groups that would cause the input part to be too far right
|
|
|
|
this_total_matchgroup_render_width += grp.last_render_width;
|
|
|
|
if (last_total_matchgroup_render_width - this_total_matchgroup_render_width > client_size.x / 2)
|
|
|
|
{
|
|
|
|
// If we're skipping some syllables, show an arrow as feedback that something is scrolled off
|
|
|
|
if (!scroll_arrows_drawn)
|
|
|
|
{
|
|
|
|
dc.SetBrush(wxBrush(outer_frame));
|
|
|
|
wxPoint triangle[3];
|
|
|
|
int height = y_line2 - y_line1;
|
|
|
|
triangle[0] = wxPoint(next_x-3, height/2);
|
|
|
|
triangle[1] = wxPoint(next_x-3+height/2, 0);
|
|
|
|
triangle[2] = wxPoint(next_x-3+height/2, height);
|
|
|
|
dc.DrawPolygon(3, triangle, 0, 0);
|
|
|
|
dc.DrawPolygon(3, triangle, 0, height);
|
|
|
|
next_x += height/2 - 4;
|
|
|
|
}
|
|
|
|
scroll_arrows_drawn = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dc.SetPen(wxPen(outer_frame));
|
|
|
|
dc.SetBrush(wxBrush(inner_back));
|
|
|
|
dc.SetTextBackground(inner_back);
|
|
|
|
dc.SetTextForeground(inner_text);
|
|
|
|
|
|
|
|
// Matched source syllables
|
|
|
|
int syl_x = next_x;
|
|
|
|
for (size_t j = 0; j < grp.src.size(); ++j)
|
|
|
|
{
|
|
|
|
syl_x += DrawBoxedText(dc, grp.src[j].text, syl_x, y_line1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Matched destination text
|
|
|
|
{
|
|
|
|
int adv = DrawBoxedText(dc, grp.dst, next_x, y_line2);
|
|
|
|
|
|
|
|
// Adjust next_x here while we have the text_w
|
|
|
|
if (syl_x > next_x + adv)
|
|
|
|
next_x = syl_x;
|
|
|
|
else
|
|
|
|
next_x = next_x + adv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spacing between groups
|
|
|
|
next_x += 3;
|
|
|
|
grp.last_render_width = next_x - prev_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_total_matchgroup_render_width = this_total_matchgroup_render_width;
|
|
|
|
|
|
|
|
// Spacing between grouped and ungrouped parts
|
|
|
|
next_x += 4;
|
|
|
|
|
|
|
|
// Remaining source syllables
|
|
|
|
int syl_x = next_x;
|
|
|
|
// Start out with highlight colours
|
|
|
|
dc.SetTextBackground(sel_back);
|
|
|
|
dc.SetTextForeground(sel_text);
|
|
|
|
dc.SetBrush(wxBrush(sel_back));
|
|
|
|
for (size_t j = 0; j < unmatched_source.size(); ++j)
|
|
|
|
{
|
|
|
|
// Switch to regular colours after all selected syllables
|
|
|
|
if (j == source_sel_length)
|
|
|
|
{
|
|
|
|
dc.SetTextBackground(inner_back);
|
|
|
|
dc.SetTextForeground(inner_text);
|
|
|
|
dc.SetBrush(wxBrush(inner_back));
|
|
|
|
}
|
|
|
|
|
|
|
|
syl_x += DrawBoxedText(dc, unmatched_source[j].text, syl_x, y_line1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remaining destination
|
|
|
|
dc.SetTextBackground(sel_back);
|
|
|
|
dc.SetTextForeground(sel_text);
|
|
|
|
dc.SetBrush(wxBrush(sel_back));
|
|
|
|
wxString txt = unmatched_destination.Left(destination_sel_length);
|
|
|
|
if (txt != _T(""))
|
|
|
|
next_x += DrawBoxedText(dc, txt, next_x, y_line2);
|
|
|
|
|
|
|
|
dc.SetTextBackground(inner_back);
|
|
|
|
dc.SetTextForeground(inner_text);
|
|
|
|
dc.SetBrush(wxBrush(inner_back));
|
|
|
|
txt = unmatched_destination.Mid(destination_sel_length);
|
|
|
|
if (txt != _T(""))
|
|
|
|
DrawBoxedText(dc, txt, next_x, y_line2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KaraokeLineMatchDisplay::OnKeyboard(wxKeyEvent &event)
|
|
|
|
{
|
|
|
|
((DialogKanjiTimer*)GetParent())->OnKeyDown(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KaraokeLineMatchDisplay::OnFocusEvent(wxFocusEvent &event)
|
|
|
|
{
|
|
|
|
Refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KaraokeLineMatchDisplay::SetInputData(const AssDialogue *src, const AssDialogue *dst)
|
|
|
|
{
|
|
|
|
has_source = src != 0;
|
|
|
|
has_destination = dst != 0;
|
|
|
|
|
|
|
|
last_total_matchgroup_render_width = 0;
|
|
|
|
|
|
|
|
matched_groups.clear();
|
|
|
|
|
|
|
|
unmatched_source.clear();
|
|
|
|
source_sel_length = 0;
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
AssDialogue *varsrc = AssEntry::GetAsDialogue(src->Clone());
|
|
|
|
varsrc->ParseASSTags();
|
|
|
|
AssKaraokeVector kara;
|
|
|
|
ParseAssKaraokeTags(varsrc, kara);
|
|
|
|
// Start from 1 instead of 0: The first syllable is actually everything before the first
|
|
|
|
for (size_t i = 1; i < kara.size(); ++i)
|
|
|
|
{
|
2009-06-25 00:22:45 +02:00
|
|
|
unmatched_source.push_back(MatchSyllable(kara[i].duration, kara[i].text));
|
2009-06-08 04:37:09 +02:00
|
|
|
}
|
|
|
|
delete varsrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
unmatched_destination.clear();
|
|
|
|
destination_sel_length = 0;
|
|
|
|
if (dst)
|
|
|
|
{
|
|
|
|
unmatched_destination = dst->GetStrippedText();
|
|
|
|
}
|
|
|
|
|
|
|
|
IncreaseSourceMatch();
|
|
|
|
IncreseDestinationMatch();
|
|
|
|
Refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString KaraokeLineMatchDisplay::GetOutputLine()
|
|
|
|
{
|
|
|
|
wxString res;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < matched_groups.size(); ++i)
|
|
|
|
{
|
|
|
|
MatchGroup &match = matched_groups[i];
|
|
|
|
res = wxString::Format(_T("%s{\\k%d}%s"), res.c_str(), match.duration, match.dst.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int KaraokeLineMatchDisplay::GetRemainingSource()
|
|
|
|
{
|
|
|
|
return unmatched_source.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int KaraokeLineMatchDisplay::GetRemainingDestination()
|
|
|
|
{
|
|
|
|
return unmatched_destination.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KaraokeLineMatchDisplay::IncreaseSourceMatch()
|
|
|
|
{
|
|
|
|
source_sel_length += 1;
|
|
|
|
if (source_sel_length > GetRemainingSource())
|
|
|
|
source_sel_length = GetRemainingSource();
|
|
|
|
Refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KaraokeLineMatchDisplay::DecreaseSourceMatch()
|
|
|
|
{
|
|
|
|
source_sel_length -= 1;
|
|
|
|
if (source_sel_length < 0)
|
|
|
|
source_sel_length = 0;
|
|
|
|
Refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KaraokeLineMatchDisplay::IncreseDestinationMatch()
|
|
|
|
{
|
|
|
|
destination_sel_length += 1;
|
|
|
|
if (destination_sel_length > GetRemainingDestination())
|
|
|
|
destination_sel_length = GetRemainingDestination();
|
|
|
|
Refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KaraokeLineMatchDisplay::DecreaseDestinationMatch()
|
|
|
|
{
|
|
|
|
destination_sel_length -= 1;
|
|
|
|
if (destination_sel_length < 0)
|
|
|
|
destination_sel_length = 0;
|
|
|
|
Refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define KANA_SEARCH_DISTANCE 3 //Kana interpolation, in characters, unset to disable
|
|
|
|
#define ROMAJI_SEARCH_DISTANCE 4 //Romaji interpolation, in karaoke groups, unset to disable
|
|
|
|
|
|
|
|
void KaraokeLineMatchDisplay::AutoMatchJapanese()
|
|
|
|
{
|
|
|
|
if (unmatched_source.size() < 1) return;
|
|
|
|
|
|
|
|
// Quick escape: If there's no destination left, take all remaining source.
|
|
|
|
// (Usually this means the user made a mistake.)
|
|
|
|
if (unmatched_destination.size() == 0)
|
|
|
|
{
|
|
|
|
source_sel_length = unmatched_source.size();
|
|
|
|
destination_sel_length = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KanaTable kt;
|
|
|
|
typedef std::list<KanaEntry>::const_iterator KanaIterator;
|
|
|
|
|
|
|
|
// We'll first see if we can do something with the first unmatched source syllable
|
|
|
|
wxString src(unmatched_source[0].text.Lower());
|
|
|
|
wxString dst(unmatched_destination);
|
|
|
|
source_sel_length = 1; // we're working on the first, assume it was matched
|
|
|
|
destination_sel_length = 0;
|
|
|
|
|
|
|
|
// Quick escape: If the source syllable is empty, return with first source syllable and empty destination
|
|
|
|
if (src.size() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to match the next source syllable against the destination.
|
|
|
|
// Do it "inverted", try all kana from the table and prefix-match them against the destination,
|
|
|
|
// then if it matches a prefix, try to match the hepburn for it agast the source; eat if it matches.
|
|
|
|
// Keep trying to match as long as there's text left in the source syllable or matching fails.
|
|
|
|
while (src.size() > 0)
|
|
|
|
{
|
|
|
|
wxString dst_hira_rest, dst_kata_rest, src_rest;
|
|
|
|
bool matched = false;
|
|
|
|
for (KanaIterator ke = kt.entries.begin(); ke != kt.entries.end(); ++ke)
|
|
|
|
{
|
|
|
|
bool hira_matches = dst.StartsWith(ke->hiragana, &dst_hira_rest) && !ke->hiragana.IsEmpty();
|
|
|
|
bool kata_matches = dst.StartsWith(ke->katakana, &dst_kata_rest);
|
|
|
|
bool roma_matches = src.StartsWith(ke->hepburn, &src_rest);
|
|
|
|
|
|
|
|
if ((hira_matches || kata_matches) && roma_matches)
|
|
|
|
{
|
|
|
|
matched = true;
|
|
|
|
src = src_rest;
|
|
|
|
dst = hira_matches ? dst_hira_rest : dst_kata_rest;
|
|
|
|
destination_sel_length += (hira_matches?ke->hiragana:ke->katakana).size();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!matched) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The source might be empty now: That's good!
|
|
|
|
// That means we managed to match it all against destination text
|
|
|
|
if (src.size() == 0)
|
|
|
|
{
|
|
|
|
// destination_sel_length already has the appropriate value
|
|
|
|
// and source_sel_length was alredy 1
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now the source syllable might consist of just whitespace.
|
|
|
|
// Eat all whitespace at the start of the destination.
|
2009-06-25 00:22:45 +02:00
|
|
|
if (StringEmptyOrWhitespace(src))
|
2009-06-08 04:37:09 +02:00
|
|
|
{
|
|
|
|
trycatchingmorespaces:
|
|
|
|
// ASCII space
|
|
|
|
if (unmatched_destination[destination_sel_length] == L'\x20') { ++destination_sel_length; goto trycatchingmorespaces; }
|
|
|
|
// Japanese fullwidth ('ideographic') space
|
|
|
|
if (unmatched_destination[destination_sel_length] == L'\u3000') { ++destination_sel_length; goto trycatchingmorespaces; }
|
|
|
|
// Now we've eaten all spaces in the destination as well
|
|
|
|
// so the selection lengths should be good
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's just one character left in the destination at this point,
|
|
|
|
// (and the source doesn't begin with space syllables, see test above)
|
|
|
|
// assume it's safe to take all remaining source to match the single
|
|
|
|
// remaining destination.
|
|
|
|
if (unmatched_destination.size() == 1)
|
|
|
|
{
|
|
|
|
source_sel_length = unmatched_source.size();
|
|
|
|
destination_sel_length = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef KANA_SEARCH_DISTANCE
|
|
|
|
// Try to look up to KANA_SEARCH_DISTANCE characters ahead in destination, see if any of those
|
|
|
|
// are recognised kana. If there are any within the range, see if it matches a following syllable,
|
|
|
|
// at most 5 source syllables per character in source we're ahead.
|
|
|
|
// The number 5 comes from the kanji with the longest readings: 'uketamawa.ru' and 'kokorozashi'
|
|
|
|
// which each has a reading consisting of five kana.
|
|
|
|
// Only match the found kana in destination against the beginning of source syllables, not the
|
|
|
|
// middle of them.
|
|
|
|
// If a match is found, make a guess at how much source and destination should be selected based
|
|
|
|
// on the distances it was found at.
|
|
|
|
dst = unmatched_destination;
|
|
|
|
for (size_t lookahead = 0; lookahead < KANA_SEARCH_DISTANCE; ++lookahead)
|
|
|
|
{
|
|
|
|
// Eat dst at the beginning, don't test for the first character being kana
|
|
|
|
dst = dst.Mid(1);
|
|
|
|
// Find a position where hiragana or katakana matches
|
|
|
|
wxString matched_roma;
|
|
|
|
wxString matched_kana;
|
|
|
|
for (KanaIterator ke = kt.entries.begin(); ke != kt.entries.end(); ++ke)
|
|
|
|
{
|
|
|
|
if (!!ke->hiragana && dst.StartsWith(ke->hiragana))
|
|
|
|
{
|
|
|
|
matched_roma = ke->hepburn;
|
|
|
|
matched_kana = ke->hiragana;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!!ke->katakana && dst.StartsWith(ke->katakana))
|
|
|
|
{
|
|
|
|
matched_roma = ke->hepburn;
|
|
|
|
matched_kana = ke->katakana;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we didn't match any kana against dst, move to next char in dst
|
|
|
|
if (!matched_kana)
|
|
|
|
continue;
|
|
|
|
// Otherwise look for a match for the romaji
|
|
|
|
// For the magic number 5, see big comment block above
|
|
|
|
int src_lookahead_max = (lookahead+1)*5;
|
|
|
|
int src_lookahead_pos = 0;
|
|
|
|
for (UnmatchedSourceIterator ss = unmatched_source.begin(); ss != unmatched_source.end(); ++ss)
|
|
|
|
{
|
|
|
|
// Check if we've gone too far ahead in the source
|
|
|
|
if (src_lookahead_pos++ >= src_lookahead_max) break;
|
|
|
|
// Otherwise look for a match
|
|
|
|
if (ss->text.StartsWith(matched_roma))
|
|
|
|
{
|
|
|
|
// Yay! Time to interpolate.
|
|
|
|
// Special case: If the last source syllable before the matching one is
|
|
|
|
// empty or contains just whitespace, don't include that one.
|
2009-06-25 00:22:45 +02:00
|
|
|
if (src_lookahead_pos > 1 && StringEmptyOrWhitespace(unmatched_source[src_lookahead_pos-2].text))
|
2009-06-08 04:37:09 +02:00
|
|
|
src_lookahead_pos -= 1;
|
|
|
|
// Special case: Just one source syllable matching, pick all destination found
|
|
|
|
if (src_lookahead_pos == 2)
|
|
|
|
{
|
|
|
|
source_sel_length = 1;
|
|
|
|
destination_sel_length = lookahead+1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Otherwise try to split the eaten source syllables evenly between the eaten
|
|
|
|
// destination characters, and do a regular rounding.
|
|
|
|
float src_per_dst = (float)(src_lookahead_pos-1)/(float)(lookahead+1);
|
|
|
|
source_sel_length = (int)(src_per_dst + 0.5);
|
|
|
|
destination_sel_length = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ROMAJI_SEARCH_DISTANCE
|
|
|
|
// Not re-implemented (yet?)
|
|
|
|
// So far testing shows that the kana-based interpolation works just fine by itself.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Okay so we didn't match anything. Aww.
|
|
|
|
// Just fail...
|
|
|
|
// We know from earlier that we do have both some source and some destination.
|
|
|
|
source_sel_length = 1;
|
|
|
|
destination_sel_length = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KaraokeLineMatchDisplay::AcceptMatch()
|
|
|
|
{
|
|
|
|
MatchGroup match;
|
|
|
|
|
|
|
|
if (source_sel_length == 0 && destination_sel_length == 0)
|
|
|
|
{
|
|
|
|
// Completely empty match
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(source_sel_length >= 0);
|
|
|
|
assert(source_sel_length <= (int)unmatched_source.size());
|
|
|
|
while (source_sel_length > 0)
|
|
|
|
{
|
|
|
|
match.src.push_back(unmatched_source.front());
|
|
|
|
match.duration += unmatched_source.front().dur;
|
|
|
|
unmatched_source.pop_front();
|
|
|
|
source_sel_length--;
|
|
|
|
}
|
|
|
|
assert(source_sel_length == 0);
|
|
|
|
|
|
|
|
assert(destination_sel_length >= 0);
|
|
|
|
assert(destination_sel_length <= (int)unmatched_destination.size());
|
|
|
|
match.dst = unmatched_destination.Left(destination_sel_length);
|
|
|
|
unmatched_destination = unmatched_destination.Mid(destination_sel_length);
|
|
|
|
destination_sel_length = 0;
|
|
|
|
|
|
|
|
matched_groups.push_back(match);
|
|
|
|
|
|
|
|
IncreaseSourceMatch();
|
|
|
|
IncreseDestinationMatch();
|
|
|
|
Refresh(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KaraokeLineMatchDisplay::UndoMatch()
|
|
|
|
{
|
|
|
|
if (matched_groups.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MatchGroup &group = matched_groups.back();
|
|
|
|
|
|
|
|
source_sel_length = group.src.size();
|
|
|
|
destination_sel_length = group.dst.size();
|
|
|
|
|
|
|
|
while (group.src.size() > 0)
|
|
|
|
{
|
|
|
|
unmatched_source.push_front(group.src.back());
|
|
|
|
group.src.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
unmatched_destination = group.dst + unmatched_destination;
|
|
|
|
|
|
|
|
matched_groups.pop_back();
|
|
|
|
|
|
|
|
Refresh(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Constructor
|
|
|
|
DialogKanjiTimer::DialogKanjiTimer(wxWindow *parent, SubtitlesGrid *_grid)
|
|
|
|
: wxDialog (parent,-1,_("Kanji timing"),wxDefaultPosition)
|
|
|
|
{
|
2007-07-05 01:09:40 +02:00
|
|
|
// Set icon
|
2009-07-25 06:49:59 +02:00
|
|
|
SetIcon(BitmapToIcon(GETIMAGE(kanji_timer_button_24)));
|
2007-07-05 01:09:40 +02:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
// Variables
|
2009-06-08 04:37:09 +02:00
|
|
|
subs = AssFile::top;
|
2007-01-13 03:22:28 +01:00
|
|
|
grid = _grid;
|
|
|
|
|
|
|
|
//Sizers
|
2009-06-08 04:37:09 +02:00
|
|
|
wxSizer *DisplayBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Text"));
|
|
|
|
wxSizer *StylesBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Styles"));
|
|
|
|
wxFlexGridSizer *StylesGridSizer = new wxFlexGridSizer(2, 2, 6, 6);
|
|
|
|
wxSizer *HelpBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Shortcut Keys"));
|
|
|
|
wxSizer *ButtonsBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Commands"));
|
|
|
|
wxSizer *MainStackSizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxSizer *BottomShelfSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
wxSizer *BottomLeftStackSizer = new wxBoxSizer(wxVERTICAL);
|
2007-01-13 03:22:28 +01:00
|
|
|
|
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
display = new KaraokeLineMatchDisplay(this);
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
//Checkbox
|
|
|
|
Interpolate = new wxCheckBox(this,-1,_("Attempt to interpolate kanji."),wxDefaultPosition,wxDefaultSize,wxALIGN_LEFT);
|
|
|
|
Interpolate->SetValue(Options.AsBool(_T("kanji timer interpolation")));
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2007-07-05 17:23:31 +02:00
|
|
|
SourceStyle=new wxComboBox(this,-1,_T(""),wxDefaultPosition,wxSize(160,-1),
|
2007-01-13 03:22:28 +01:00
|
|
|
subs->GetStyles(),wxCB_READONLY,wxDefaultValidator,_("Source Style"));
|
2007-07-05 17:23:31 +02:00
|
|
|
DestStyle = new wxComboBox(this,-1,_T(""),wxDefaultPosition,wxSize(160,-1),
|
2007-01-13 03:22:28 +01:00
|
|
|
subs->GetStyles(),wxCB_READONLY,wxDefaultValidator,_("Dest Style"));
|
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
wxStaticText *ShortcutKeys = new wxStaticText(this,-1,_("When the destination textbox has focus, use the following keys:\n\nRight Arrow: Increase dest. selection length\nLeft Arrow: Decrease dest. selection length\nUp Arrow: Increase source selection length\nDown Arrow: Decrease source selection length\nEnter: Link, accept line when done\nBackspace: Unlink last"));
|
2007-01-13 03:42:19 +01:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
//Buttons
|
2008-01-18 18:07:00 +01:00
|
|
|
wxButton *Start = new wxButton(this,BUTTON_KTSTART,_("Start!"));
|
2007-01-13 03:42:19 +01:00
|
|
|
wxButton *Link = new wxButton(this,BUTTON_KTLINK,_("Link"));
|
|
|
|
wxButton *Unlink = new wxButton(this,BUTTON_KTUNLINK,_("Unlink"));
|
|
|
|
wxButton *SkipSourceLine = new wxButton(this,BUTTON_KTSKIPSOURCE,_("Skip Source Line"));
|
|
|
|
wxButton *SkipDestLine = new wxButton(this,BUTTON_KTSKIPDEST,_("Skip Dest Line"));
|
|
|
|
wxButton *GoBackLine = new wxButton(this,BUTTON_KTGOBACK,_("Go Back a Line"));
|
|
|
|
wxButton *AcceptLine = new wxButton(this,BUTTON_KTACCEPT,_("Accept Line"));
|
2007-08-16 01:17:42 +02:00
|
|
|
wxButton *CloseKT = new wxButton(this,wxID_CLOSE,_("Close"));
|
2007-01-15 00:34:27 +01:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
//Frame: Text
|
2009-06-08 04:37:09 +02:00
|
|
|
DisplayBoxSizer->Add(display, 0, wxEXPAND|wxALL, 6);
|
|
|
|
DisplayBoxSizer->Add(Interpolate, 0, wxEXPAND|wxALL, 6);
|
2007-01-13 03:22:28 +01:00
|
|
|
//Frame: Styles
|
2009-06-08 04:37:09 +02:00
|
|
|
StylesGridSizer->Add(new wxStaticText(this, -1, TEXT_LABEL_SOURCE), 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
|
|
|
|
StylesGridSizer->Add(SourceStyle, 1, wxEXPAND);
|
|
|
|
StylesGridSizer->Add(new wxStaticText(this, -1, TEXT_LABEL_DEST), 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
|
|
|
|
StylesGridSizer->Add(DestStyle, 1, wxEXPAND);
|
|
|
|
StylesBoxSizer->Add(StylesGridSizer, 1, wxEXPAND|wxALL, 6);
|
|
|
|
//Frame: Shortcut Keys
|
|
|
|
HelpBoxSizer->Add(ShortcutKeys, 1, wxALIGN_CENTER_HORIZONTAL|wxRIGHT, 6);
|
2007-01-13 03:22:28 +01:00
|
|
|
//Frame: Commands
|
2009-06-08 04:37:09 +02:00
|
|
|
ButtonsBoxSizer->AddStretchSpacer(1);
|
|
|
|
ButtonsBoxSizer->Add(Start, 0, wxEXPAND|wxALL, 6);
|
|
|
|
ButtonsBoxSizer->Add(Link, 0, wxEXPAND|(wxALL&~wxTOP), 6);
|
|
|
|
ButtonsBoxSizer->Add(Unlink, 0, wxEXPAND|(wxALL&~wxTOP), 6);
|
|
|
|
ButtonsBoxSizer->Add(SkipSourceLine, 0, wxEXPAND|(wxALL&~wxTOP), 6);
|
|
|
|
ButtonsBoxSizer->Add(SkipDestLine, 0, wxEXPAND|(wxALL&~wxTOP), 6);
|
|
|
|
ButtonsBoxSizer->Add(GoBackLine, 0, wxEXPAND|(wxALL&~wxTOP), 6);
|
|
|
|
ButtonsBoxSizer->Add(AcceptLine, 0, wxEXPAND|(wxALL&~wxTOP), 6);
|
|
|
|
ButtonsBoxSizer->AddStretchSpacer(1);
|
2007-10-31 22:52:51 +01:00
|
|
|
|
|
|
|
// Button sizer
|
|
|
|
wxStdDialogButtonSizer *buttonSizer = new wxStdDialogButtonSizer();
|
|
|
|
buttonSizer->AddButton(new HelpButton(this,_T("Kanji Timer")));
|
|
|
|
buttonSizer->SetAffirmativeButton(CloseKT);
|
|
|
|
buttonSizer->Realize();
|
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
// Layout it all
|
|
|
|
BottomLeftStackSizer->Add(StylesBoxSizer, 0, wxEXPAND|wxBOTTOM, 6);
|
|
|
|
BottomLeftStackSizer->Add(HelpBoxSizer, 1, wxEXPAND, 6);
|
|
|
|
BottomShelfSizer->Add(BottomLeftStackSizer, 1, wxEXPAND|wxRIGHT, 6);
|
|
|
|
BottomShelfSizer->Add(ButtonsBoxSizer, 0, wxEXPAND, 6);
|
|
|
|
MainStackSizer->Add(DisplayBoxSizer, 0, wxEXPAND|wxALL, 6);
|
|
|
|
MainStackSizer->Add(BottomShelfSizer, 1, wxEXPAND|wxLEFT|wxRIGHT, 6);
|
|
|
|
MainStackSizer->Add(buttonSizer, 0, wxEXPAND|wxALL, 6);
|
|
|
|
|
|
|
|
SetSizerAndFit(MainStackSizer);
|
2007-01-13 03:22:28 +01:00
|
|
|
CenterOnParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Event table
|
|
|
|
BEGIN_EVENT_TABLE(DialogKanjiTimer,wxDialog)
|
2007-01-15 00:34:27 +01:00
|
|
|
EVT_BUTTON(wxID_CLOSE,DialogKanjiTimer::OnClose)
|
2007-01-13 03:22:28 +01:00
|
|
|
EVT_BUTTON(BUTTON_KTSTART,DialogKanjiTimer::OnStart)
|
|
|
|
EVT_BUTTON(BUTTON_KTLINK,DialogKanjiTimer::OnLink)
|
|
|
|
EVT_BUTTON(BUTTON_KTUNLINK,DialogKanjiTimer::OnUnlink)
|
|
|
|
EVT_BUTTON(BUTTON_KTSKIPSOURCE,DialogKanjiTimer::OnSkipSource)
|
|
|
|
EVT_BUTTON(BUTTON_KTSKIPDEST,DialogKanjiTimer::OnSkipDest)
|
|
|
|
EVT_BUTTON(BUTTON_KTGOBACK,DialogKanjiTimer::OnGoBack)
|
|
|
|
EVT_BUTTON(BUTTON_KTACCEPT,DialogKanjiTimer::OnAccept)
|
|
|
|
EVT_KEY_DOWN(DialogKanjiTimer::OnKeyDown)
|
|
|
|
EVT_TEXT_ENTER(TEXT_SOURCE,DialogKanjiTimer::OnKeyEnter)
|
|
|
|
EVT_TEXT_ENTER(TEXT_DEST,DialogKanjiTimer::OnKeyEnter)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2007-01-15 00:34:27 +01:00
|
|
|
void DialogKanjiTimer::OnClose(wxCommandEvent &event) {
|
2007-01-16 21:55:27 +01:00
|
|
|
Options.SetBool(_T("kanji timer interpolation"),Interpolate->IsChecked());
|
|
|
|
Options.Save();
|
2007-11-01 22:47:37 +01:00
|
|
|
bool modified = !LinesToChange.empty();
|
2007-01-25 23:47:29 +01:00
|
|
|
|
|
|
|
while(LinesToChange.empty()==false) {
|
2009-06-08 04:37:09 +02:00
|
|
|
std::pair<entryIter,wxString> p = LinesToChange.back();
|
2007-01-25 23:47:29 +01:00
|
|
|
LinesToChange.pop_back();
|
2009-06-08 04:37:09 +02:00
|
|
|
AssDialogue *line = AssEntry::GetAsDialogue(*p.first);
|
2007-01-25 23:47:29 +01:00
|
|
|
line->Text = p.second;
|
|
|
|
}
|
2007-03-08 19:57:55 +01:00
|
|
|
if (modified) {
|
|
|
|
grid->ass->FlagAsModified(_("kanji timing"));
|
|
|
|
grid->CommitChanges();
|
2007-11-01 22:47:37 +01:00
|
|
|
grid->UpdateMaps();
|
2007-03-08 19:57:55 +01:00
|
|
|
LinesToChange.clear();
|
|
|
|
}
|
2007-01-15 00:34:27 +01:00
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
void DialogKanjiTimer::OnStart(wxCommandEvent &event) {
|
2007-01-13 08:04:12 +01:00
|
|
|
if (SourceStyle->GetValue().Len() == 0 || DestStyle->GetValue().Len() == 0)
|
|
|
|
wxMessageBox(_("Select source and destination styles first."),_("Error"),wxICON_EXCLAMATION | wxOK);
|
|
|
|
else if (SourceStyle->GetValue() == DestStyle->GetValue())
|
|
|
|
wxMessageBox(_("The source and destination styles must be different."),_("Error"),wxICON_EXCLAMATION | wxOK);
|
|
|
|
else {
|
2009-06-08 04:37:09 +02:00
|
|
|
currentSourceLine = FindNextStyleMatch(subs->Line.begin(), SourceStyle->GetValue());
|
|
|
|
currentDestinationLine = FindNextStyleMatch(subs->Line.begin(), DestStyle->GetValue());
|
|
|
|
ResetForNewLine();
|
2007-01-13 08:04:12 +01:00
|
|
|
}
|
2007-01-25 23:47:29 +01:00
|
|
|
LinesToChange.clear();
|
2007-01-13 03:22:28 +01:00
|
|
|
}
|
2009-06-08 04:37:09 +02:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
void DialogKanjiTimer::OnLink(wxCommandEvent &event) {
|
2009-06-08 04:37:09 +02:00
|
|
|
if (display->AcceptMatch())
|
|
|
|
TryAutoMatch();
|
|
|
|
else
|
|
|
|
wxBell();
|
2007-01-13 03:22:28 +01:00
|
|
|
}
|
2009-06-08 04:37:09 +02:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
void DialogKanjiTimer::OnUnlink(wxCommandEvent &event) {
|
2009-06-08 04:37:09 +02:00
|
|
|
if (!display->UndoMatch())
|
|
|
|
wxBell();
|
|
|
|
// Don't auto-match here, undoing sets the selection to the undone match
|
2007-01-13 03:22:28 +01:00
|
|
|
}
|
2007-01-13 08:04:12 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
void DialogKanjiTimer::OnSkipSource(wxCommandEvent &event) {
|
|
|
|
currentSourceLine = FindNextStyleMatch(currentSourceLine, SourceStyle->GetValue());
|
|
|
|
ResetForNewLine();
|
2007-01-13 03:22:28 +01:00
|
|
|
}
|
2007-01-24 04:54:32 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
void DialogKanjiTimer::OnSkipDest(wxCommandEvent &event) {
|
|
|
|
currentDestinationLine = FindNextStyleMatch(currentDestinationLine, DestStyle->GetValue());
|
|
|
|
ResetForNewLine();
|
2007-01-13 03:22:28 +01:00
|
|
|
}
|
2009-06-08 04:37:09 +02:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
void DialogKanjiTimer::OnGoBack(wxCommandEvent &event) {
|
2007-01-25 23:47:29 +01:00
|
|
|
if (LinesToChange.empty()==false)
|
|
|
|
LinesToChange.pop_back(); //If we go back, then take out the modified line we saved.
|
2009-06-08 04:37:09 +02:00
|
|
|
|
|
|
|
currentSourceLine = FindPrevStyleMatch(currentSourceLine, SourceStyle->GetValue());
|
|
|
|
currentDestinationLine = FindPrevStyleMatch(currentDestinationLine, DestStyle->GetValue());
|
|
|
|
ResetForNewLine();
|
2007-01-13 03:22:28 +01:00
|
|
|
}
|
2009-06-08 04:37:09 +02:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
void DialogKanjiTimer::OnAccept(wxCommandEvent &event) {
|
2009-06-08 04:37:09 +02:00
|
|
|
if (display->GetRemainingSource() > 0)
|
2007-01-13 08:04:12 +01:00
|
|
|
wxMessageBox(_("Group all of the source text."),_("Error"),wxICON_EXCLAMATION | wxOK);
|
|
|
|
else {
|
2009-06-08 04:37:09 +02:00
|
|
|
wxString OutputText = display->GetOutputLine();
|
|
|
|
std::pair<entryIter,wxString> ins(currentDestinationLine, OutputText);
|
2007-01-25 23:47:29 +01:00
|
|
|
LinesToChange.push_back(ins);
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
currentSourceLine = FindNextStyleMatch(currentSourceLine, SourceStyle->GetValue());
|
|
|
|
currentDestinationLine = FindNextStyleMatch(currentDestinationLine, DestStyle->GetValue());
|
|
|
|
ResetForNewLine();
|
2007-01-13 08:04:12 +01:00
|
|
|
}
|
2007-01-13 03:22:28 +01:00
|
|
|
}
|
2009-06-08 04:37:09 +02:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
void DialogKanjiTimer::OnKeyDown(wxKeyEvent &event) {
|
2007-01-24 04:54:32 +01:00
|
|
|
wxCommandEvent evt;
|
2007-01-16 21:55:27 +01:00
|
|
|
switch(event.GetKeyCode()) {
|
2007-01-13 03:22:28 +01:00
|
|
|
case WXK_ESCAPE :
|
2007-01-24 04:54:32 +01:00
|
|
|
OnClose(evt);
|
2007-01-13 03:22:28 +01:00
|
|
|
break;
|
|
|
|
case WXK_BACK :
|
2007-01-24 04:54:32 +01:00
|
|
|
OnUnlink(evt);
|
2007-01-13 03:22:28 +01:00
|
|
|
break;
|
|
|
|
case WXK_RIGHT : //inc dest selection len
|
2009-06-08 04:37:09 +02:00
|
|
|
display->IncreseDestinationMatch();
|
2007-01-13 03:22:28 +01:00
|
|
|
break;
|
|
|
|
case WXK_LEFT : //dec dest selection len
|
2009-06-08 04:37:09 +02:00
|
|
|
display->DecreaseDestinationMatch();
|
2007-01-13 03:22:28 +01:00
|
|
|
break;
|
|
|
|
case WXK_UP : //inc source selection len
|
2009-06-08 04:37:09 +02:00
|
|
|
display->IncreaseSourceMatch();
|
2007-01-13 03:22:28 +01:00
|
|
|
break;
|
|
|
|
case WXK_DOWN : //dec source selection len
|
2009-06-08 04:37:09 +02:00
|
|
|
display->DecreaseSourceMatch();
|
2007-01-13 03:22:28 +01:00
|
|
|
break;
|
|
|
|
case WXK_RETURN :
|
2007-01-24 04:54:32 +01:00
|
|
|
OnKeyEnter(evt);
|
2007-01-13 03:22:28 +01:00
|
|
|
break;
|
|
|
|
default :
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
}
|
2009-06-08 04:37:09 +02:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
void DialogKanjiTimer::OnKeyEnter(wxCommandEvent &event) {
|
2007-01-24 04:54:32 +01:00
|
|
|
wxCommandEvent evt;
|
2007-01-15 00:34:27 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
if (display->GetRemainingSource() == 0 && display->GetRemainingDestination() == 0)
|
|
|
|
{
|
|
|
|
OnAccept(evt);
|
2007-05-12 19:35:54 +02:00
|
|
|
}
|
2009-06-08 04:37:09 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
OnLink(evt);
|
2007-01-15 00:34:27 +01:00
|
|
|
}
|
2007-01-13 08:04:12 +01:00
|
|
|
}
|
2007-01-15 00:34:27 +01:00
|
|
|
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
void DialogKanjiTimer::ResetForNewLine()
|
|
|
|
{
|
|
|
|
AssDialogue *src = 0;
|
|
|
|
AssDialogue *dst = 0;
|
|
|
|
|
|
|
|
if (currentSourceLine != subs->Line.end())
|
|
|
|
src = AssEntry::GetAsDialogue(*currentSourceLine);
|
|
|
|
if (currentDestinationLine != subs->Line.end())
|
|
|
|
dst = AssEntry::GetAsDialogue(*currentDestinationLine);
|
|
|
|
|
|
|
|
if (src == 0 || dst == 0)
|
|
|
|
{
|
|
|
|
src = dst = 0;
|
|
|
|
wxBell();
|
2007-01-13 03:22:28 +01:00
|
|
|
}
|
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
display->SetInputData(src, dst);
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
TryAutoMatch();
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
display->SetFocus();
|
|
|
|
}
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
void DialogKanjiTimer::TryAutoMatch()
|
|
|
|
{
|
|
|
|
if (Interpolate->GetValue())
|
|
|
|
display->AutoMatchJapanese();
|
|
|
|
}
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
entryIter DialogKanjiTimer::FindNextStyleMatch(entryIter search_from, const wxString &search_style)
|
|
|
|
{
|
|
|
|
if (search_from == subs->Line.end()) return search_from;
|
|
|
|
|
|
|
|
while (++search_from != subs->Line.end())
|
|
|
|
{
|
|
|
|
AssDialogue *dlg = AssEntry::GetAsDialogue(*search_from);
|
|
|
|
if (dlg && dlg->Style == search_style)
|
|
|
|
break;
|
|
|
|
}
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
return search_from;
|
2007-01-13 03:22:28 +01:00
|
|
|
}
|
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
entryIter DialogKanjiTimer::FindPrevStyleMatch(entryIter search_from, const wxString &search_style)
|
|
|
|
{
|
|
|
|
if (search_from == subs->Line.begin()) return search_from;
|
2007-01-13 03:22:28 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
while (--search_from != subs->Line.begin())
|
|
|
|
{
|
|
|
|
AssDialogue *dlg = AssEntry::GetAsDialogue(*search_from);
|
|
|
|
if (dlg && dlg->Style == search_style)
|
|
|
|
break;
|
|
|
|
}
|
2007-01-13 08:04:12 +01:00
|
|
|
|
2009-06-08 04:37:09 +02:00
|
|
|
return search_from;
|
2007-01-13 08:04:12 +01:00
|
|
|
}
|
2009-06-08 04:37:09 +02:00
|
|
|
|