2007-01-10 02:36:05 +01:00
|
|
|
// Copyright (c) 2005, 2006, 2007, Rodrigo Braz Monteiro, Niels Martin Hansen
|
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.
|
|
|
|
//
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// AEGISUB
|
|
|
|
//
|
|
|
|
// Website: http://aegisub.cellosoft.com
|
|
|
|
// Contact: mailto:zeratul@cellosoft.com
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "audio_karaoke.h"
|
|
|
|
#include "audio_display.h"
|
|
|
|
#include "audio_box.h"
|
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_override.h"
|
2007-09-12 01:22:26 +02:00
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/log.h>
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
#include <wx/settings.h>
|
2006-01-27 01:48:59 +01:00
|
|
|
#include <algorithm>
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
|
2007-06-23 02:21:20 +02:00
|
|
|
/////////////////////
|
|
|
|
// Empty constructor
|
|
|
|
AudioKaraokeSyllable::AudioKaraokeSyllable()
|
|
|
|
: AssKaraokeSyllable()
|
|
|
|
, start_time(0), selected(false)
|
|
|
|
, display_w(0), display_x(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////
|
|
|
|
// Copy-from-base constructor
|
|
|
|
AudioKaraokeSyllable::AudioKaraokeSyllable(const AssKaraokeSyllable &base)
|
|
|
|
: AssKaraokeSyllable(base)
|
|
|
|
, start_time(0), selected(false)
|
|
|
|
, display_w(0), display_x(0)
|
|
|
|
{
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-23 02:21:20 +02:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
///////////////
|
|
|
|
// Constructor
|
|
|
|
AudioKaraoke::AudioKaraoke(wxWindow *parent)
|
|
|
|
: wxWindow (parent,-1,wxDefaultPosition,wxSize(10,5),wxTAB_TRAVERSAL|wxBORDER_SUNKEN)
|
|
|
|
{
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke constructor"));
|
2006-01-16 22:02:54 +01:00
|
|
|
enabled = false;
|
2006-01-27 01:48:59 +01:00
|
|
|
splitting = false;
|
|
|
|
split_cursor_syl = -1;
|
2006-01-16 22:02:54 +01:00
|
|
|
curSyllable = 0;
|
2006-02-23 22:56:46 +01:00
|
|
|
diag = 0;
|
|
|
|
workDiag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
// Destructor
|
|
|
|
AudioKaraoke::~AudioKaraoke() {
|
|
|
|
delete workDiag;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
// Load from dialogue
|
|
|
|
bool AudioKaraoke::LoadFromDialogue(AssDialogue *_diag) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::LoadFromDialogue(diag=%p)"), _diag);
|
2006-01-27 01:48:59 +01:00
|
|
|
// Make sure we're not in splitting-mode
|
|
|
|
if (splitting) {
|
2007-06-23 01:28:28 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::LoadFromDialogue: is splitting, discarding splits"));
|
|
|
|
// Discard any splits and leave split-mode
|
|
|
|
EndSplit(false);
|
2006-01-27 01:48:59 +01:00
|
|
|
}
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Set dialogue
|
2006-02-23 22:56:46 +01:00
|
|
|
delete workDiag;
|
2006-01-16 22:02:54 +01:00
|
|
|
diag = _diag;
|
|
|
|
if (!diag) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::LoadFromDialogue: no diag, refreshing and returning false"));
|
2006-01-16 22:02:54 +01:00
|
|
|
Refresh(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::LoadFromDialogue: split"));
|
2006-02-27 03:23:50 +01:00
|
|
|
workDiag = new AssDialogue(diag->GetEntryData(), false);
|
2006-02-23 22:56:46 +01:00
|
|
|
workDiag->ParseASSTags();
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
must_rebuild = false;
|
2006-02-23 22:56:46 +01:00
|
|
|
bool hasKar = ParseDialogue(workDiag);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// No karaoke, autosplit
|
|
|
|
if (!hasKar) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::LoadFromDialogue: no existing karaoke, auto-splitting"));
|
2006-01-16 22:02:54 +01:00
|
|
|
AutoSplit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done
|
2006-02-20 08:12:01 +01:00
|
|
|
//if (curSyllable < 0) curSyllable = syllables.size()-1;
|
|
|
|
//if (curSyllable >= (signed) syllables.size()) curSyllable = 0;
|
|
|
|
//SetSelection(curSyllable);
|
|
|
|
//Refresh(false);
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::LoadFromDialogue: returning %d"), hasKar?0:1);
|
2006-01-16 22:02:54 +01:00
|
|
|
return !hasKar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////
|
|
|
|
// Writes line back
|
|
|
|
void AudioKaraoke::Commit() {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Commit"));
|
2006-01-27 01:48:59 +01:00
|
|
|
if (splitting) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Commit: splitting, ending split"));
|
2006-01-27 01:48:59 +01:00
|
|
|
EndSplit(true);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
wxString finalText = _T("");
|
2007-06-23 02:21:20 +02:00
|
|
|
AudioKaraokeSyllable *syl;
|
2006-01-16 22:02:54 +01:00
|
|
|
size_t n = syllables.size();
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Commit: syllables.size() = %u"), n);
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
if (must_rebuild) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Commit: must_rebuild"));
|
2006-02-23 22:56:46 +01:00
|
|
|
workDiag->ClearBlocks();
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
for (size_t i=0;i<n;i++) {
|
|
|
|
syl = &syllables.at(i);
|
2007-06-23 02:21:20 +02:00
|
|
|
finalText += wxString::Format(_T("{%s%i}"), syl->type.c_str(), syl->duration) + syl->text;
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
}
|
2006-02-23 22:56:46 +01:00
|
|
|
workDiag->Text = finalText;
|
|
|
|
workDiag->ParseASSTags();
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
diag->Text = finalText;
|
|
|
|
} else {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Commit: Updating karaoke without rebuild"));
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
for (size_t i = 0; i < n; i++) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Commit: Updating syllable %d"), i);
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
syl = &syllables.at(i);
|
2007-06-23 02:21:20 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Commit: Syllable pointer: %p; tagdata pointer: %p; length: %d"), syl, syl->tag, syl->duration);
|
2007-05-28 13:24:37 +02:00
|
|
|
// Some weird people have text before the first karaoke tag on a line.
|
|
|
|
// Check that a karaoke tag actually exists for the (non-)syllable to avoid a crash.
|
2007-06-23 02:21:20 +02:00
|
|
|
if (syl->tag && syl->tag->Params.size()>0)
|
|
|
|
syl->tag->Params[0]->SetInt(syl->duration);
|
2007-05-28 13:24:37 +02:00
|
|
|
// Of course, if the user changed the duration of such a non-syllable, its timing can't be updated and will stay zero.
|
|
|
|
// There is no way to check for that right now, and I can't bother to fix it.
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
}
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Commit: Done updating syllables"));
|
2006-02-23 22:56:46 +01:00
|
|
|
workDiag->UpdateText();
|
|
|
|
workDiag->ClearBlocks();
|
|
|
|
workDiag->ParseASSTags();
|
|
|
|
diag->Text = workDiag->Text;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Commit: returning"));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Autosplit line
|
|
|
|
void AudioKaraoke::AutoSplit() {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::AutoSplit"));
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Get lengths
|
2008-01-19 01:48:47 +01:00
|
|
|
int timeLen = (diag->End.GetMS() - diag->Start.GetMS())/10;
|
2006-01-16 22:02:54 +01:00
|
|
|
int letterlen = diag->Text.Length();
|
|
|
|
int round = letterlen / 2;
|
|
|
|
int curlen;
|
|
|
|
int acumLen = 0;
|
|
|
|
wxString newText;
|
|
|
|
|
|
|
|
// Parse words
|
|
|
|
wxStringTokenizer tkz(diag->Text,_T(" "),wxTOKEN_RET_DELIMS);
|
2008-01-19 01:48:47 +01:00
|
|
|
wxArrayString words;
|
2006-01-16 22:02:54 +01:00
|
|
|
while (tkz.HasMoreTokens()) {
|
2008-01-19 01:48:47 +01:00
|
|
|
words.Add(tkz.GetNextToken());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process words
|
|
|
|
for (size_t i=0;i<words.Count();i++) {
|
|
|
|
curlen = (words[i].Length() * timeLen + round) / letterlen;
|
2006-01-16 22:02:54 +01:00
|
|
|
acumLen += curlen;
|
2008-01-19 01:48:47 +01:00
|
|
|
|
|
|
|
// Don't let it accumulate over total length
|
|
|
|
if (acumLen > timeLen) {
|
|
|
|
curlen -= acumLen - timeLen;
|
|
|
|
acumLen = timeLen;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2008-01-19 01:48:47 +01:00
|
|
|
|
|
|
|
// Ensure that it accumulates all of it
|
|
|
|
if (i == words.Count()-1 && acumLen < timeLen) {
|
|
|
|
curlen += timeLen - acumLen;
|
|
|
|
acumLen = timeLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
newText += wxString::Format(_T("{\\k%i}"),curlen) + words[i];
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2007-08-15 22:41:57 +02:00
|
|
|
// Workaround for bug #503
|
|
|
|
// Make the line one blank syllable if it's completely blank
|
2008-01-19 01:48:47 +01:00
|
|
|
if (newText == _T("")) newText = wxString::Format(_T("{\\k%d}"), timeLen);
|
2007-08-15 22:41:57 +02:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Load
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
must_rebuild = true;
|
2006-02-27 03:23:50 +01:00
|
|
|
AssDialogue newDiag(diag->GetEntryData());
|
2006-01-16 22:02:54 +01:00
|
|
|
newDiag.Text = newText;
|
2007-06-23 02:21:20 +02:00
|
|
|
newDiag.ParseASSTags();
|
2006-01-16 22:02:54 +01:00
|
|
|
ParseDialogue(&newDiag);
|
2007-06-20 00:37:25 +02:00
|
|
|
|
|
|
|
wxLogDebug(_T("AudioKaraoke::AutoSplit: returning"));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
// Parses text to extract karaoke
|
|
|
|
bool AudioKaraoke::ParseDialogue(AssDialogue *curDiag) {
|
2007-06-23 02:21:20 +02:00
|
|
|
// parse the tagdata
|
|
|
|
AssKaraokeVector tempsyls;
|
|
|
|
ParseAssKaraokeTags(curDiag, tempsyls);
|
2007-06-20 00:37:25 +02:00
|
|
|
|
2007-06-23 02:21:20 +02:00
|
|
|
bool found_kara = tempsyls.size() > 1;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2007-06-23 02:21:20 +02:00
|
|
|
// copy base syllables to real
|
|
|
|
syllables.clear();
|
|
|
|
syllables.reserve(tempsyls.size());
|
|
|
|
int cur_time = 0;
|
|
|
|
for (AssKaraokeVector::iterator base = tempsyls.begin(); base != tempsyls.end(); ++base) {
|
|
|
|
AudioKaraokeSyllable fullsyl(*base);
|
|
|
|
fullsyl.start_time = cur_time;
|
|
|
|
cur_time += fullsyl.duration;
|
|
|
|
syllables.push_back(fullsyl);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2007-06-23 02:21:20 +02:00
|
|
|
// if first syllable is empty, remove it
|
|
|
|
if (!syllables[0].unstripped_text) {
|
|
|
|
syllables.erase(syllables.begin());
|
|
|
|
found_kara = syllables.size() > 0;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2007-06-23 02:21:20 +02:00
|
|
|
// if there's more than one syllable in the list, at least one karaoke tag was found
|
|
|
|
return found_kara;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// Set syllable
|
|
|
|
void AudioKaraoke::SetSyllable(int n) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::SetSyllable(n=%d)"), n);
|
2006-02-20 08:12:01 +01:00
|
|
|
if (n == -1) n = syllables.size()-1;
|
2006-02-20 22:32:58 +01:00
|
|
|
if (n >= (signed) syllables.size()) n = 0;
|
2006-01-16 22:02:54 +01:00
|
|
|
curSyllable = n;
|
|
|
|
startClickSyl = n;
|
|
|
|
SetSelection(n);
|
|
|
|
Refresh(false);
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::SetSyllable: returning"));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Event table
|
|
|
|
BEGIN_EVENT_TABLE(AudioKaraoke,wxWindow)
|
|
|
|
EVT_PAINT(AudioKaraoke::OnPaint)
|
|
|
|
EVT_SIZE(AudioKaraoke::OnSize)
|
|
|
|
EVT_MOUSE_EVENTS(AudioKaraoke::OnMouse)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Paint event
|
|
|
|
void AudioKaraoke::OnPaint(wxPaintEvent &event) {
|
|
|
|
// Get dimensions
|
|
|
|
int w,h;
|
|
|
|
GetClientSize(&w,&h);
|
|
|
|
|
|
|
|
// Start Paint
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
|
|
|
|
// Draw background
|
|
|
|
dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
dc.DrawRectangle(0,0,w,h);
|
|
|
|
|
|
|
|
// Set syllable font
|
2007-01-10 02:36:05 +01:00
|
|
|
wxFont curFont(9,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL,false,_T("Verdana"),wxFONTENCODING_SYSTEM); // FIXME, hardcoded font
|
2006-01-16 22:02:54 +01:00
|
|
|
dc.SetFont(curFont);
|
|
|
|
|
|
|
|
// Draw syllables
|
|
|
|
if (enabled) {
|
|
|
|
wxString temptext;
|
|
|
|
size_t syln = syllables.size();
|
|
|
|
int dx = 0;
|
|
|
|
int tw,th;
|
|
|
|
int delta;
|
|
|
|
int dlen;
|
|
|
|
for (size_t i=0;i<syln;i++) {
|
2007-06-23 02:21:20 +02:00
|
|
|
AudioKaraokeSyllable &syl = syllables.at(i);
|
2006-01-16 22:02:54 +01:00
|
|
|
// Calculate text length
|
2007-06-23 02:21:20 +02:00
|
|
|
temptext = syl.text;
|
2006-01-27 01:48:59 +01:00
|
|
|
// If we're splitting, every character must be drawn
|
|
|
|
if (!splitting) {
|
|
|
|
temptext.Trim(true);
|
|
|
|
temptext.Trim(false);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
GetTextExtent(temptext,&tw,&th,NULL,NULL,&curFont);
|
|
|
|
delta = 0;
|
|
|
|
if (tw < 10) delta = 10 - tw;
|
|
|
|
dlen = tw + 8 + delta;
|
|
|
|
|
|
|
|
// Draw border
|
2007-01-10 02:36:05 +01:00
|
|
|
//dc.SetPen(wxPen(wxColour(0,0,0)));
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2006-01-27 01:48:59 +01:00
|
|
|
if (syl.selected && !splitting) {
|
2006-01-16 22:02:54 +01:00
|
|
|
dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)));
|
|
|
|
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT)));
|
|
|
|
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
|
|
|
|
}
|
|
|
|
dc.DrawRectangle(dx,0,dlen,h);
|
|
|
|
|
2007-01-10 02:36:05 +01:00
|
|
|
// Put syllable-end-marker after text
|
|
|
|
dc.SetPen(*wxBLACK_PEN);
|
|
|
|
//dc.DrawLine(dx, 0, dx, h);
|
|
|
|
dc.DrawLine(dx, 0, dx+1, 0);
|
|
|
|
dc.DrawLine(dx, h-1, dx+1, h-1);
|
|
|
|
dc.DrawLine(dx+dlen-1, 0, dx+dlen-1, h);
|
|
|
|
dc.DrawLine(dx+dlen-2, 0, dx+dlen-1, 0);
|
|
|
|
dc.DrawLine(dx+dlen-2, h-1, dx+dlen-1, h-1);
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Draw text
|
2006-01-27 01:48:59 +01:00
|
|
|
if (splitting) {
|
|
|
|
// Make sure the text position is more predictable in case of splitting
|
|
|
|
dc.DrawText(temptext,dx+4,(h-th)/2);
|
|
|
|
} else {
|
|
|
|
dc.DrawText(temptext,dx+(delta/2)+4,(h-th)/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw pending splits
|
|
|
|
if (syl.pending_splits.size() > 0) {
|
|
|
|
wxArrayInt widths;
|
|
|
|
if (dc.GetPartialTextExtents(temptext, widths)) {
|
2008-01-22 21:36:07 +01:00
|
|
|
for (unsigned int j = 0; j < syl.pending_splits.size(); j++) {
|
2006-02-21 07:52:21 +01:00
|
|
|
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
|
2006-06-27 05:02:28 +02:00
|
|
|
int splitxpos = dx + 4;
|
|
|
|
// Handle splitters placed before first char in syllable; these are represented as -1
|
2008-01-22 21:36:07 +01:00
|
|
|
if (syl.pending_splits[j] >= 0) {
|
|
|
|
splitxpos += widths[syl.pending_splits[j]];
|
2006-06-27 05:02:28 +02:00
|
|
|
} else {
|
|
|
|
splitxpos += 0;
|
|
|
|
}
|
|
|
|
dc.DrawLine(splitxpos, 0, splitxpos, h);
|
2006-01-27 01:48:59 +01:00
|
|
|
}
|
|
|
|
} else {
|
2007-07-18 15:46:38 +02:00
|
|
|
wxLogError(_T("Karaoke syllable display: Failed to GetPartialTextExtents. This should never happen, except on severely overloaded systems."));
|
2006-01-27 01:48:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-24 04:54:32 +01:00
|
|
|
if (splitting && split_cursor_syl == (signed)i /*&& split_cursor_x > 0*/) {
|
2006-01-27 01:48:59 +01:00
|
|
|
dc.SetPen(*wxRED);
|
|
|
|
dc.DrawLine(dx+4+split_cursor_x, 0, dx+4+split_cursor_x, h);
|
|
|
|
dc.SetPen(wxPen(wxColour(0,0,0)));
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Set syllable data
|
2006-01-27 01:48:59 +01:00
|
|
|
syl.display_x = dx;
|
|
|
|
syl.display_w = dlen;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Increment dx
|
|
|
|
dx += dlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
// Size event
|
|
|
|
void AudioKaraoke::OnSize(wxSizeEvent &event) {
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Mouse event
|
|
|
|
void AudioKaraoke::OnMouse(wxMouseEvent &event) {
|
|
|
|
// Get coordinates
|
|
|
|
int x = event.GetX();
|
2007-01-24 04:54:32 +01:00
|
|
|
//int y = event.GetY();
|
2006-01-16 22:02:54 +01:00
|
|
|
bool shift = event.m_shiftDown;
|
|
|
|
|
2006-02-21 07:24:23 +01:00
|
|
|
// Syllable selection mode
|
2006-01-27 01:48:59 +01:00
|
|
|
if (!splitting) {
|
2006-06-27 06:04:40 +02:00
|
|
|
int syl = GetSylAtX(x);
|
2006-01-27 01:48:59 +01:00
|
|
|
|
2006-06-27 06:04:40 +02:00
|
|
|
// Button pressed
|
|
|
|
if (event.LeftDown() || event.RightDown()) {
|
2006-01-27 01:48:59 +01:00
|
|
|
if (syl != -1) {
|
|
|
|
if (shift) {
|
|
|
|
SetSelection(syl,startClickSyl);
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
SetSelection(syl);
|
|
|
|
startClickSyl = syl;
|
|
|
|
curSyllable = syl;
|
|
|
|
Refresh(false);
|
|
|
|
display->Update();
|
2006-06-27 06:04:40 +02:00
|
|
|
CaptureMouse();
|
2006-01-27 01:48:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-06-27 06:04:40 +02:00
|
|
|
// Dragging to make a selection
|
|
|
|
else if (event.Dragging() && (event.LeftIsDown() || event.RightIsDown())) {
|
|
|
|
if (syl < 0) syl = 0;
|
|
|
|
SetSelection(syl, startClickSyl);
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
// Released left button
|
2007-01-17 06:22:21 +01:00
|
|
|
else if (event.LeftUp() && HasCapture()) {
|
2006-07-08 00:47:36 +02:00
|
|
|
ReleaseMouse();
|
2006-06-27 06:04:40 +02:00
|
|
|
}
|
|
|
|
// Released right button; make a menu for selecting \k type
|
2007-01-17 06:13:02 +01:00
|
|
|
else if (event.RightUp()) {
|
2007-01-17 06:22:21 +01:00
|
|
|
if (HasCapture())
|
|
|
|
ReleaseMouse();
|
2006-06-27 06:04:40 +02:00
|
|
|
|
|
|
|
AudioKaraokeTagMenu menu(this);
|
|
|
|
PopupMenu(&menu);
|
|
|
|
}
|
2006-02-21 07:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Karaoke syllable splitting mode
|
|
|
|
else {
|
2006-01-27 01:48:59 +01:00
|
|
|
int syli = GetSylAtX(x);
|
|
|
|
|
2006-02-21 07:24:23 +01:00
|
|
|
// Valid syllable
|
2006-01-27 01:48:59 +01:00
|
|
|
if (syli != -1) {
|
2007-06-23 02:21:20 +02:00
|
|
|
AudioKaraokeSyllable &syl = syllables.at(syli);
|
2006-01-27 01:48:59 +01:00
|
|
|
|
|
|
|
// Get the widths after each character in the text
|
|
|
|
wxClientDC dc(this);
|
|
|
|
wxFont curFont(9,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL,false,_T("Verdana"),wxFONTENCODING_SYSTEM);
|
|
|
|
dc.SetFont(curFont);
|
|
|
|
wxArrayInt widths;
|
2007-06-23 02:21:20 +02:00
|
|
|
dc.GetPartialTextExtents(syl.text, widths);
|
2006-01-27 01:48:59 +01:00
|
|
|
|
|
|
|
// Find the character closest to the mouse
|
|
|
|
int rx = x - syl.display_x - 4;
|
2006-06-27 05:02:28 +02:00
|
|
|
int split_cursor_char = -2;
|
2006-01-27 01:48:59 +01:00
|
|
|
split_cursor_syl = -1;
|
|
|
|
split_cursor_x = -1;
|
2007-06-23 02:21:20 +02:00
|
|
|
if (syl.text.Len() > 0) {
|
2006-06-27 05:02:28 +02:00
|
|
|
int lastx = 0;
|
2006-01-27 01:48:59 +01:00
|
|
|
split_cursor_syl = syli;
|
2006-06-27 05:02:28 +02:00
|
|
|
for (unsigned int i = 0; i < widths.size(); i++) {
|
2007-06-20 00:37:25 +02:00
|
|
|
//wxLogDebug(_T("rx=%d, lastx=%d, widths[i]=%d, i=%d, widths.size()=%d, syli=%d"), rx, lastx, widths[i], i, widths.size(), syli);
|
2006-01-27 01:48:59 +01:00
|
|
|
if (lastx - rx < widths[i] - rx) {
|
|
|
|
if (rx - lastx < widths[i] - rx) {
|
|
|
|
//wxLogDebug(_T("Found at PREV!"));
|
|
|
|
split_cursor_x = lastx;
|
|
|
|
split_cursor_char = i - 1;
|
|
|
|
break;
|
|
|
|
} else if (rx < widths[i]) {
|
|
|
|
//wxLogDebug(_T("Found at CURRENT!"));
|
|
|
|
split_cursor_x = widths[i];
|
|
|
|
split_cursor_char = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastx = widths[i];
|
|
|
|
}
|
|
|
|
// If no split-point was caught by the for-loop, it must be over the last character,
|
|
|
|
// ie. split at next-to-last position
|
|
|
|
if (split_cursor_x < 0) {
|
|
|
|
//wxLogDebug(_T("Emergency picking LAST!"));
|
2006-06-27 05:02:28 +02:00
|
|
|
split_cursor_x = widths[widths.size()-1];
|
|
|
|
split_cursor_char = widths.size() - 1;
|
2006-01-27 01:48:59 +01:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2006-01-27 01:48:59 +01:00
|
|
|
// Do something if there was a click and we're at a valid position
|
2006-06-27 05:02:28 +02:00
|
|
|
if (event.LeftDown() && split_cursor_char >= -1) {
|
2006-01-27 01:48:59 +01:00
|
|
|
//wxLogDebug(_T("A click!"));
|
|
|
|
int num_removed = 0;
|
|
|
|
std::vector<int>::iterator i = syl.pending_splits.begin();
|
|
|
|
while (i != syl.pending_splits.end()) {
|
|
|
|
if (split_cursor_char == *i) {
|
|
|
|
//wxLogDebug(_T("Erasing entry"));
|
|
|
|
num_removed++;
|
|
|
|
syl.pending_splits.erase(i);
|
2006-02-21 07:52:21 +01:00
|
|
|
break;
|
2006-01-27 01:48:59 +01:00
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num_removed == 0) {
|
|
|
|
syl.pending_splits.push_back(split_cursor_char);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2006-01-27 01:48:59 +01:00
|
|
|
|
2006-02-21 07:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid syllable (int syli = GetSylAtX(x); returned -1)
|
|
|
|
else {
|
2006-01-27 01:48:59 +01:00
|
|
|
split_cursor_syl = -1;
|
|
|
|
split_cursor_x = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (split_cursor_syl >= 0) {
|
|
|
|
Refresh(false);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////
|
|
|
|
// Get Syllable at position X
|
|
|
|
int AudioKaraoke::GetSylAtX(int x) {
|
|
|
|
int dx,dw;
|
|
|
|
size_t syln = syllables.size();
|
|
|
|
for (size_t i=0;i<syln;i++) {
|
|
|
|
dx = syllables.at(i).display_x;
|
|
|
|
dw = syllables.at(i).display_w;
|
|
|
|
if (x >= dx && x < dx+dw) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////
|
|
|
|
// Set selection
|
|
|
|
void AudioKaraoke::SetSelection(int start,int end) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::SetSelection(start=%d, end=%d)"), start, end);
|
2006-01-16 22:02:54 +01:00
|
|
|
// Default end
|
|
|
|
if (end == -1) end = start;
|
|
|
|
|
|
|
|
// Get min/max range
|
|
|
|
size_t min = start;
|
|
|
|
size_t max = end;
|
|
|
|
if (max < min) {
|
|
|
|
size_t temp = max;
|
|
|
|
max = min;
|
|
|
|
min = temp;
|
|
|
|
}
|
2007-06-23 01:28:28 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::SetSelection: min=%d, max=%d"), min, max);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Set values
|
|
|
|
bool state;
|
|
|
|
size_t syls = syllables.size();
|
|
|
|
int sels = 0;
|
|
|
|
for (size_t i=0;i<syls;i++) {
|
|
|
|
state = (i >= min && i <= max);
|
|
|
|
syllables.at(i).selected = state;
|
|
|
|
if (state) sels++;
|
|
|
|
}
|
2007-06-23 00:50:02 +02:00
|
|
|
curSyllable = min;
|
2007-06-23 01:28:28 +02:00
|
|
|
selectionCount = max-min+1;
|
|
|
|
wxLogDebug(_T("AudioKaraoke::SetSelection: new curSyllable=%d, selectionCount=%d"), curSyllable, selectionCount);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Set box buttons
|
2007-06-23 01:28:28 +02:00
|
|
|
box->SetKaraokeButtons();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Join syllables
|
|
|
|
void AudioKaraoke::Join() {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Join"));
|
2006-01-16 22:02:54 +01:00
|
|
|
// Variables
|
|
|
|
bool gotOne = false;
|
|
|
|
size_t syls = syllables.size();
|
2007-06-23 02:21:20 +02:00
|
|
|
AudioKaraokeSyllable *curSyl;
|
2006-01-16 22:02:54 +01:00
|
|
|
int first = 0;
|
|
|
|
|
|
|
|
// Loop
|
|
|
|
for (size_t i=0;i<syls;i++) {
|
|
|
|
curSyl = &syllables.at(i);
|
2007-06-30 02:00:44 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::Join: syllable %d, text='%s', unstripped_text='%s', duration=%d"), i, curSyl->text.c_str(), curSyl->unstripped_text.c_str(), curSyl->duration);
|
2006-01-16 22:02:54 +01:00
|
|
|
if (curSyl->selected) {
|
|
|
|
if (!gotOne) {
|
|
|
|
gotOne = true;
|
|
|
|
first = i;
|
|
|
|
}
|
|
|
|
else {
|
2007-06-30 02:00:44 +02:00
|
|
|
AudioKaraokeSyllable &work = syllables.at(first);
|
|
|
|
wxLogDebug(_T("AudioKaraoke::Join: worksyl %d, text='%s', unstripped_text='%s', duration=%d"), i, work.text.c_str(), work.unstripped_text.c_str(), work.duration);
|
|
|
|
work.duration += curSyl->duration;
|
|
|
|
work.text += curSyl->text;
|
|
|
|
work.unstripped_text += curSyl->unstripped_text;
|
2006-01-16 22:02:54 +01:00
|
|
|
syllables.erase(syllables.begin()+i);
|
|
|
|
i--;
|
|
|
|
syls--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set selection
|
2007-06-23 01:28:28 +02:00
|
|
|
SetSelection(first);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Update
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
must_rebuild = true;
|
2006-01-16 22:02:54 +01:00
|
|
|
display->NeedCommit = true;
|
|
|
|
display->Update();
|
|
|
|
Refresh(false);
|
2007-06-30 02:00:44 +02:00
|
|
|
|
|
|
|
wxLogDebug(_T("AudioKaraoke::Join: returning"));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-27 01:48:59 +01:00
|
|
|
////////////////////////
|
|
|
|
// Enter splitting-mode
|
|
|
|
void AudioKaraoke::BeginSplit() {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::BeginSplit"));
|
2006-01-27 01:48:59 +01:00
|
|
|
splitting = true;
|
|
|
|
split_cursor_syl = -1;
|
|
|
|
split_cursor_x = -1;
|
2007-06-23 01:28:28 +02:00
|
|
|
box->SetKaraokeButtons();
|
2006-01-27 01:48:59 +01:00
|
|
|
Refresh(false);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2006-01-27 01:48:59 +01:00
|
|
|
|
|
|
|
////////////////////////////////////////////
|
|
|
|
// Leave splitting-mode, committing changes
|
|
|
|
void AudioKaraoke::EndSplit(bool commit) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::EndSplit(commit=%d)"), commit?1:0);
|
2006-01-27 01:48:59 +01:00
|
|
|
splitting = false;
|
|
|
|
bool hasSplit = false;
|
2008-03-13 20:12:55 +01:00
|
|
|
size_t first_sel = ~0U;
|
2007-06-30 03:27:00 +02:00
|
|
|
for (size_t i = 0; i < syllables.size(); i ++) {
|
2006-01-27 01:48:59 +01:00
|
|
|
if (syllables[i].pending_splits.size() > 0) {
|
|
|
|
if (commit) {
|
2007-06-30 03:27:00 +02:00
|
|
|
if (syllables[i].selected && i < first_sel)
|
|
|
|
first_sel = i;
|
2006-01-27 01:48:59 +01:00
|
|
|
SplitSyl(i);
|
2006-01-16 22:02:54 +01:00
|
|
|
hasSplit = true;
|
2006-01-27 01:48:59 +01:00
|
|
|
} else {
|
|
|
|
syllables[i].pending_splits.clear();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update
|
|
|
|
if (hasSplit) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::EndSplit: hasSplit"));
|
From changelog:
o The correct \k tag (\k, \kf, \ko, \K) is now kept when splitting/joining
o When editing karaoke-timing for a line and not splitting/joining, all tags are kept intact, so only the \k tag timings are changed (BROKEN WITH \t TAGS ATM!)
Reason for breakage with \t seems to be the override tag parser killing all the actual style overrides in the \t tag. Example: \t(100,200,\fscx200) -> \t(100,200,) All other tags seem unaffected, but not intensively tested.
Originally committed to SVN as r31.
2006-01-27 23:22:31 +01:00
|
|
|
must_rebuild = true;
|
2006-01-16 22:02:54 +01:00
|
|
|
display->NeedCommit = true;
|
2007-06-30 03:27:00 +02:00
|
|
|
SetSelection(first_sel);
|
2006-01-16 22:02:54 +01:00
|
|
|
display->Update();
|
|
|
|
}
|
2006-01-27 01:48:59 +01:00
|
|
|
// Always redraw, since the display is different in splitting mode
|
2007-06-23 01:28:28 +02:00
|
|
|
box->SetKaraokeButtons();
|
2006-01-27 01:48:59 +01:00
|
|
|
Refresh(false);
|
2007-06-20 00:37:25 +02:00
|
|
|
|
|
|
|
wxLogDebug(_T("AudioKaraoke::EndSplit: returning"));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-27 01:48:59 +01:00
|
|
|
/////////////////////////////////////////////////
|
|
|
|
// Split a syllable using the pending_slits data
|
2006-01-28 16:11:59 +01:00
|
|
|
int AudioKaraoke::SplitSyl (unsigned int n) {
|
2007-06-20 00:37:25 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::SplitSyl(n=%u)"), n);
|
2007-06-23 00:50:02 +02:00
|
|
|
|
|
|
|
// Avoid multiple vector resizes (this must be first)
|
2006-01-27 01:48:59 +01:00
|
|
|
syllables.reserve(syllables.size() + syllables[n].pending_splits.size());
|
|
|
|
|
2007-06-23 00:50:02 +02:00
|
|
|
// The syllable we're splitting
|
2007-06-23 02:21:20 +02:00
|
|
|
AudioKaraokeSyllable &basesyl = syllables[n];
|
|
|
|
wxLogDebug(_T("AudioKaraoke::SplitSyl: basesyl. contents='%s' selected=%d"), basesyl.unstripped_text.c_str(), basesyl.selected?1:0);
|
2007-06-23 00:50:02 +02:00
|
|
|
|
2006-01-27 01:48:59 +01:00
|
|
|
// Start by sorting the split points
|
2007-06-23 00:50:02 +02:00
|
|
|
std::sort(basesyl.pending_splits.begin(), basesyl.pending_splits.end());
|
2006-01-27 01:48:59 +01:00
|
|
|
|
2007-06-23 02:21:20 +02:00
|
|
|
wxString originalText = basesyl.text;
|
|
|
|
int originalDuration = basesyl.duration;
|
2006-01-27 01:48:59 +01:00
|
|
|
|
|
|
|
// Fixup the first syllable
|
2007-06-23 02:21:20 +02:00
|
|
|
basesyl.text = originalText.Mid(0, basesyl.pending_splits[0] + 1);
|
|
|
|
basesyl.unstripped_text = basesyl.text;
|
2007-06-30 03:27:00 +02:00
|
|
|
basesyl.selected = false;
|
|
|
|
basesyl.duration = originalDuration * basesyl.text.Length() / originalText.Length();
|
2007-06-23 02:21:20 +02:00
|
|
|
int curpos = basesyl.start_time + basesyl.duration;
|
2006-01-27 01:48:59 +01:00
|
|
|
|
|
|
|
// For each split, make a new syllable
|
2007-06-23 00:50:02 +02:00
|
|
|
for (unsigned int i = 0; i < basesyl.pending_splits.size(); i++) {
|
2007-06-23 02:21:20 +02:00
|
|
|
AudioKaraokeSyllable newsyl;
|
2007-06-23 00:50:02 +02:00
|
|
|
if (i < basesyl.pending_splits.size()-1) {
|
2006-01-27 01:48:59 +01:00
|
|
|
// in the middle
|
2007-06-23 02:21:20 +02:00
|
|
|
newsyl.text = originalText.Mid(basesyl.pending_splits[i]+1, basesyl.pending_splits[i+1] - basesyl.pending_splits[i]);
|
2006-01-27 01:48:59 +01:00
|
|
|
} else {
|
|
|
|
// the last one (take the rest)
|
2007-06-23 02:21:20 +02:00
|
|
|
newsyl.text = originalText.Mid(basesyl.pending_splits[i]+1);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2007-06-23 02:21:20 +02:00
|
|
|
newsyl.unstripped_text = newsyl.text;
|
|
|
|
newsyl.duration = originalDuration * newsyl.text.Length() / originalText.Length();
|
|
|
|
newsyl.start_time = curpos;
|
|
|
|
newsyl.type = basesyl.type;
|
2007-06-30 03:27:00 +02:00
|
|
|
newsyl.selected = false;//basesyl.selected;
|
2007-06-23 02:21:20 +02:00
|
|
|
wxLogDebug(_T("AudioKaraoke::SplitSyl: newsyl. contents='%s' selected=%d"), newsyl.text.c_str(), newsyl.selected?1:0);
|
|
|
|
curpos += newsyl.duration;
|
2007-06-23 00:50:02 +02:00
|
|
|
syllables.insert(syllables.begin()+n+i+1, newsyl);
|
2006-01-27 01:48:59 +01:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2006-01-27 01:48:59 +01:00
|
|
|
// The total duration of the new syllables will be equal to or less than the original duration
|
|
|
|
// Fix this, so they'll always add up
|
|
|
|
// Use an unfair method, just adding 1 to each syllable one after another, until it's correct
|
|
|
|
int newDuration = 0;
|
2007-06-23 00:50:02 +02:00
|
|
|
for (unsigned int j = n; j < basesyl.pending_splits.size()+n+1; j++) {
|
2007-06-23 02:21:20 +02:00
|
|
|
newDuration += syllables[j].duration;
|
2006-01-27 01:48:59 +01:00
|
|
|
}
|
2006-01-28 16:11:59 +01:00
|
|
|
unsigned int k = n;
|
2006-01-27 01:48:59 +01:00
|
|
|
while (newDuration < originalDuration) {
|
2007-06-23 02:21:20 +02:00
|
|
|
syllables[k].duration++;
|
2006-01-27 01:48:59 +01:00
|
|
|
k++;
|
|
|
|
if (k >= syllables.size()) {
|
|
|
|
k = n;
|
|
|
|
}
|
|
|
|
newDuration++;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2006-01-27 01:48:59 +01:00
|
|
|
// Prepare for return and clear pending splits
|
2007-06-23 00:50:02 +02:00
|
|
|
int numsplits = basesyl.pending_splits.size();
|
|
|
|
basesyl.pending_splits.clear();
|
2006-01-27 01:48:59 +01:00
|
|
|
return numsplits;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-27 06:04:40 +02:00
|
|
|
////////////////////////////////
|
|
|
|
// Karaoke tag menu constructor
|
|
|
|
AudioKaraokeTagMenu::AudioKaraokeTagMenu(AudioKaraoke *_kara)
|
|
|
|
: wxMenu(_("Karaoke tag"))
|
|
|
|
, kara(_kara)
|
|
|
|
{
|
|
|
|
// Create menu items
|
|
|
|
AppendCheckItem(10001, _T("\\k"), _("Change karaoke tag to \\k"));
|
|
|
|
AppendCheckItem(10002, _T("\\kf / \\K"), _("Change karaoke tag to \\kf"));
|
|
|
|
AppendCheckItem(10003, _T("\\ko"), _("Change karaoke tag to \\ko"));
|
|
|
|
|
|
|
|
// Find out what kinds of tags are in use atm
|
2006-06-30 22:56:16 +02:00
|
|
|
for (size_t i = 0; i < kara->syllables.size(); i++) {
|
2007-06-23 02:21:20 +02:00
|
|
|
AudioKaraokeSyllable &syl = kara->syllables[i];
|
2006-06-27 06:04:40 +02:00
|
|
|
if (syl.selected) {
|
2007-06-23 02:21:20 +02:00
|
|
|
if (syl.type == _T("\\k")) {
|
2006-06-27 06:04:40 +02:00
|
|
|
Check(10001, true);
|
2007-06-23 02:21:20 +02:00
|
|
|
} else if (syl.type == _T("\\kf") || syl.type == _T("\\K")) {
|
2006-06-27 06:04:40 +02:00
|
|
|
Check(10002, true);
|
2007-06-23 02:21:20 +02:00
|
|
|
} else if (syl.type == _T("\\ko")) {
|
2006-06-27 06:04:40 +02:00
|
|
|
Check(10003, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////
|
|
|
|
// Karaoke tag menu destructor
|
|
|
|
AudioKaraokeTagMenu::~AudioKaraokeTagMenu() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Event table
|
|
|
|
BEGIN_EVENT_TABLE(AudioKaraokeTagMenu,wxMenu)
|
|
|
|
EVT_MENU_RANGE(10001, 10003, AudioKaraokeTagMenu::OnSelectItem)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
// Karaoke tag menu event handler
|
|
|
|
void AudioKaraokeTagMenu::OnSelectItem(wxCommandEvent &event) {
|
|
|
|
// Select the new tag for the syllables
|
|
|
|
wxString newtag;
|
|
|
|
switch (event.GetId()) {
|
|
|
|
case 10001: newtag = _T("\\k"); break;
|
|
|
|
case 10002: newtag = _T("\\kf"); break;
|
|
|
|
case 10003: newtag = _T("\\ko"); break;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply it
|
2006-06-30 22:56:16 +02:00
|
|
|
size_t firstsel = kara->syllables.size();
|
|
|
|
int lastsel = -1;
|
|
|
|
for (size_t i = 0; i < kara->syllables.size(); i++) {
|
2007-06-23 02:21:20 +02:00
|
|
|
AudioKaraokeSyllable &syl = kara->syllables[i];
|
2006-06-27 06:04:40 +02:00
|
|
|
if (syl.selected) {
|
|
|
|
if (firstsel > i) firstsel = i;
|
|
|
|
lastsel = i;
|
2007-06-23 02:21:20 +02:00
|
|
|
syl.type = newtag;
|
2006-06-27 06:04:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update display
|
|
|
|
kara->must_rebuild = true;
|
|
|
|
//kara->Commit();
|
|
|
|
kara->display->NeedCommit = true;
|
|
|
|
kara->display->CommitChanges();
|
|
|
|
//kara->display->Update();
|
|
|
|
kara->SetSelection(firstsel, lastsel);
|
|
|
|
}
|
|
|
|
|
2007-09-12 01:22:26 +02:00
|
|
|
|