2008-03-08 04:08:50 +01:00
|
|
|
// Copyright (c) 2008, Rodrigo Braz Monteiro
|
|
|
|
// 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/AEGILIB
|
|
|
|
//
|
|
|
|
// Website: http://www.aegisub.net
|
|
|
|
// Contact: mailto:amz@aegisub.net
|
|
|
|
//
|
|
|
|
|
2008-09-20 03:46:24 +02:00
|
|
|
//#define ATHENA_DLL
|
2008-03-08 08:14:14 +01:00
|
|
|
#include <wx/wfstream.h>
|
2008-11-11 04:54:20 +01:00
|
|
|
#include <athenasub/athenasub.h>
|
2008-03-08 04:08:50 +01:00
|
|
|
#include <iostream>
|
2008-03-14 07:10:54 +01:00
|
|
|
#include <wx/stopwatch.h>
|
2008-03-08 04:08:50 +01:00
|
|
|
#include "text_file_reader.h"
|
|
|
|
#include "text_file_writer.h"
|
|
|
|
|
2008-03-16 01:32:42 +01:00
|
|
|
int main()
|
|
|
|
{
|
2008-03-08 04:08:50 +01:00
|
|
|
using namespace std;
|
2008-03-18 04:44:00 +01:00
|
|
|
using namespace Athenasub;
|
2008-03-08 04:08:50 +01:00
|
|
|
|
2008-03-18 04:44:00 +01:00
|
|
|
cout << "Athenasub test program by amz.\n\n";
|
2008-03-08 04:08:50 +01:00
|
|
|
|
2008-03-08 08:14:14 +01:00
|
|
|
try {
|
|
|
|
// Set up the lib
|
2008-11-08 23:07:23 +01:00
|
|
|
cout << "Loading library... ";
|
|
|
|
/*
|
|
|
|
#ifdef WXDEBUG
|
|
|
|
HMODULE module = LoadLibrary(_T("athenasub_d.dll"));
|
|
|
|
#else
|
|
|
|
HMODULE module = LoadLibrary(_T("athenasub.dll"));
|
|
|
|
#endif
|
|
|
|
if (!module) {
|
|
|
|
cout << "Failed to load library, aborting.\n";
|
|
|
|
system("pause");
|
|
|
|
return 1;
|
2008-08-03 18:17:35 +02:00
|
|
|
}
|
2008-11-08 23:07:23 +01:00
|
|
|
*/
|
|
|
|
cout << "Done.\nCreating library...";
|
2008-09-19 05:11:23 +02:00
|
|
|
|
|
|
|
LibAthenaSub lib = Athenasub::Create("Aegilib test program");
|
2008-11-08 23:07:23 +01:00
|
|
|
//LibAthenaSub lib = Athenasub::Create(module,"Aegilib test program");
|
2008-08-09 22:43:27 +02:00
|
|
|
cout << "Done.\n";
|
2008-03-08 04:08:50 +01:00
|
|
|
|
2008-03-08 08:14:14 +01:00
|
|
|
// Subtitles model
|
2008-08-09 22:43:27 +02:00
|
|
|
cout << "Creating model... ";
|
2008-08-03 18:17:35 +02:00
|
|
|
Model subs = lib->CreateModel();
|
2008-08-09 22:43:27 +02:00
|
|
|
cout << "Creating controller...\n";
|
2008-08-03 18:17:35 +02:00
|
|
|
Controller control = subs->CreateController();
|
2008-03-14 07:10:54 +01:00
|
|
|
wxStopWatch timer;
|
2008-03-08 04:08:50 +01:00
|
|
|
|
2008-03-08 08:14:14 +01:00
|
|
|
// Load subtitles
|
|
|
|
cout << "Loading file... ";
|
2008-03-14 07:10:54 +01:00
|
|
|
timer.Start();
|
2008-11-08 23:07:23 +01:00
|
|
|
control->LoadFile("subs_in.ass","UTF-8");
|
2008-03-14 07:10:54 +01:00
|
|
|
timer.Pause();
|
2008-03-15 09:36:52 +01:00
|
|
|
cout << "Done in " << timer.Time() << " ms.\n";
|
|
|
|
|
|
|
|
// Save subtitles
|
|
|
|
cout << "Saving file... ";
|
|
|
|
timer.Start();
|
2008-11-10 00:08:22 +01:00
|
|
|
control->SaveFile("subs_out.ass","UTF-8");
|
2008-03-15 09:36:52 +01:00
|
|
|
timer.Pause();
|
|
|
|
cout << "Done in " << timer.Time() << " ms.\n";
|
2008-03-14 03:02:48 +01:00
|
|
|
|
2008-03-17 02:32:26 +01:00
|
|
|
// Issue an action
|
2008-03-18 03:09:33 +01:00
|
|
|
#ifdef WXDEBUG
|
2008-11-10 00:08:22 +01:00
|
|
|
int n = 1;
|
2008-11-16 01:58:08 +01:00
|
|
|
#else
|
2008-11-21 03:14:15 +01:00
|
|
|
int n = 100;
|
2008-03-18 03:09:33 +01:00
|
|
|
#endif
|
|
|
|
cout << "Executing action " << n << " times... ";
|
2008-03-17 08:19:33 +01:00
|
|
|
timer.Start();
|
2008-09-20 03:46:24 +02:00
|
|
|
for (int i=0;i<n;i++) {
|
2008-11-15 04:55:58 +01:00
|
|
|
ActionList actions = control->CreateActionList("Test");
|
2008-08-03 18:17:35 +02:00
|
|
|
Selection selection = control->CreateSelection();
|
|
|
|
selection->AddRange(Range(0,5000));
|
|
|
|
selection->AddRange(Range(4500,5500));
|
|
|
|
selection->AddRange(Range(9000,9100));
|
2008-11-08 23:07:23 +01:00
|
|
|
std::vector<Entry> entries = actions->ModifyLines(selection,"Events");
|
2008-03-17 08:19:33 +01:00
|
|
|
size_t len = entries.size();
|
|
|
|
for (size_t i=0;i<len;i++) {
|
2008-08-03 18:17:35 +02:00
|
|
|
Dialogue diag = dynamic_pointer_cast<IDialogue> (entries[i]);
|
2008-09-20 05:04:21 +02:00
|
|
|
diag->SetStartTime(diag->GetStartTime() - 55555);
|
|
|
|
diag->SetEndTime(diag->GetEndTime() + 5555);
|
2008-03-17 08:19:33 +01:00
|
|
|
}
|
|
|
|
actions->Finish();
|
|
|
|
}
|
|
|
|
timer.Pause();
|
|
|
|
cout << "Done in " << timer.Time() << " ms.\n";
|
|
|
|
|
|
|
|
// Rollback
|
2008-09-20 03:46:24 +02:00
|
|
|
cout << "Undoing " << n-1 << " times... ";
|
|
|
|
timer.Start();
|
|
|
|
for (int i=0;i<n-1;i++) {
|
2008-07-27 20:26:36 +02:00
|
|
|
control->Undo();
|
2008-03-17 08:19:33 +01:00
|
|
|
}
|
2008-09-20 03:46:24 +02:00
|
|
|
timer.Pause();
|
|
|
|
cout << "Done in " << timer.Time() << " ms.\n";
|
2008-03-14 04:33:27 +01:00
|
|
|
|
|
|
|
// Undo
|
2008-11-16 01:58:08 +01:00
|
|
|
n = 10;
|
2008-09-20 03:46:24 +02:00
|
|
|
cout << "Undoing and redoing " << n << " times... ";
|
2008-03-14 07:10:54 +01:00
|
|
|
timer.Start();
|
2008-09-20 03:46:24 +02:00
|
|
|
for (int i=0;i<n;i++) {
|
2008-07-27 20:26:36 +02:00
|
|
|
control->Undo();
|
|
|
|
control->Redo();
|
2008-03-15 09:36:52 +01:00
|
|
|
}
|
2008-03-14 07:10:54 +01:00
|
|
|
timer.Pause();
|
2008-03-15 09:36:52 +01:00
|
|
|
cout << "Done in " << timer.Time() << " ms.\n";
|
2008-03-18 03:09:33 +01:00
|
|
|
|
|
|
|
// Get style test
|
2008-11-08 23:07:23 +01:00
|
|
|
ConstStyle style = control->GetStyle("japro1_star");
|
2008-11-10 00:08:22 +01:00
|
|
|
cout << "Style " << style->GetName() << " font is " << style->GetFontName() << " " << style->GetFontSize() << ".\n";
|
2008-03-18 03:09:33 +01:00
|
|
|
|
|
|
|
// Save a few more
|
2008-11-08 23:07:23 +01:00
|
|
|
control->SaveFile("subs_out2.ass","UTF-8");
|
2008-07-27 20:26:36 +02:00
|
|
|
control->Undo();
|
2008-11-08 23:07:23 +01:00
|
|
|
control->SaveFile("subs_out3.ass","UTF-8");
|
2008-03-08 08:14:14 +01:00
|
|
|
}
|
|
|
|
|
2008-03-13 08:28:30 +01:00
|
|
|
catch (std::exception &e) {
|
|
|
|
cout << "\n\nException: " << e.what() << endl << endl;
|
2008-03-08 08:14:14 +01:00
|
|
|
}
|
2008-03-15 01:29:17 +01:00
|
|
|
|
|
|
|
return true;
|
2008-03-08 04:08:50 +01:00
|
|
|
}
|