2011-09-28 21:44:07 +02:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-06-23 02:21:20 +02:00
|
|
|
//
|
2011-09-28 21:44:07 +02:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2007-06-23 02:21:20 +02:00
|
|
|
//
|
2011-09-28 21:44:07 +02:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2007-06-23 02:21:20 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
2011-09-28 21:44:07 +02:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2012-12-30 00:53:56 +01:00
|
|
|
#include <string>
|
2007-06-23 02:21:20 +02:00
|
|
|
#include <vector>
|
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-09-28 21:44:07 +02:00
|
|
|
#include <libaegisub/signal.h>
|
|
|
|
|
|
|
|
namespace agi { struct Context; }
|
|
|
|
class AssDialogue;
|
|
|
|
|
|
|
|
/// @class AssKaraoke
|
|
|
|
/// @brief Karaoke parser and parsed karaoke data model
|
|
|
|
class AssKaraoke {
|
|
|
|
public:
|
|
|
|
/// Parsed syllable data
|
|
|
|
struct Syllable {
|
|
|
|
int start_time; ///< Start time relative to time zero (not line start) in milliseconds
|
|
|
|
int duration; ///< Duration in milliseconds
|
2012-12-30 00:53:56 +01:00
|
|
|
std::string text; ///< Stripped syllable text
|
|
|
|
std::string tag_type; ///< \k, \kf or \ko
|
2011-09-28 21:44:07 +02:00
|
|
|
/// Non-karaoke override tags in this syllable. Key is an index in text
|
|
|
|
/// before which the value should be inserted
|
2012-12-30 00:53:56 +01:00
|
|
|
std::map<size_t, std::string> ovr_tags;
|
2011-09-28 21:44:07 +02:00
|
|
|
|
|
|
|
/// Get the text of this line with override tags and optionally the karaoke tag
|
2012-12-30 00:53:56 +01:00
|
|
|
std::string GetText(bool k_tag) const;
|
2011-09-28 21:44:07 +02:00
|
|
|
};
|
|
|
|
private:
|
|
|
|
std::vector<Syllable> syls;
|
|
|
|
|
2013-12-12 01:29:48 +01:00
|
|
|
bool no_announce = false;
|
2011-09-28 21:44:07 +02:00
|
|
|
|
|
|
|
agi::signal::Signal<> AnnounceSyllablesChanged;
|
2012-12-01 01:40:00 +01:00
|
|
|
void ParseSyllables(AssDialogue *line, Syllable &syl);
|
2011-09-28 21:44:07 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// Constructor
|
|
|
|
/// @param line Initial line
|
|
|
|
/// @param auto_split Should the line automatically be split on spaces if there are no k tags?
|
2012-02-16 06:21:00 +01:00
|
|
|
/// @param normalize Should the total duration of the syllables be forced to equal the line duration?
|
2013-11-21 18:13:36 +01:00
|
|
|
AssKaraoke(AssDialogue *line = nullptr, bool auto_split = false, bool normalize = true);
|
2011-09-28 21:44:07 +02:00
|
|
|
|
|
|
|
/// Parse a dialogue line
|
2012-02-16 06:21:00 +01:00
|
|
|
void SetLine(AssDialogue *line, bool auto_split = false, bool normalize = true);
|
2011-09-28 21:44:07 +02:00
|
|
|
|
|
|
|
/// Add a split before character pos in syllable syl_idx
|
|
|
|
void AddSplit(size_t syl_idx, size_t pos);
|
|
|
|
/// Remove the split at the given index
|
|
|
|
void RemoveSplit(size_t syl_idx);
|
|
|
|
/// Set the start time of a syllable in ms
|
|
|
|
void SetStartTime(size_t syl_idx, int time);
|
2012-02-22 23:00:54 +01:00
|
|
|
/// Adjust the line's start and end times without shifting the syllables
|
|
|
|
void SetLineTimes(int start_time, int end_time);
|
2011-09-28 21:44:07 +02:00
|
|
|
|
|
|
|
typedef std::vector<Syllable>::const_iterator iterator;
|
|
|
|
|
|
|
|
iterator begin() const { return syls.begin(); }
|
|
|
|
iterator end() const { return syls.end(); }
|
|
|
|
size_t size() const { return syls.size(); }
|
|
|
|
|
|
|
|
/// Get the line's text with k tags
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string GetText() const;
|
2011-09-28 21:44:07 +02:00
|
|
|
|
|
|
|
/// Get the karaoke tag type used, with leading slash
|
|
|
|
/// @returns "\k", "\kf", or "\ko"
|
2012-12-30 00:53:56 +01:00
|
|
|
std::string GetTagType() const;
|
2011-09-28 21:44:07 +02:00
|
|
|
/// Set the tag type for all karaoke tags in this line
|
2012-12-30 00:53:56 +01:00
|
|
|
void SetTagType(std::string const& new_type);
|
2011-09-28 21:44:07 +02:00
|
|
|
|
|
|
|
DEFINE_SIGNAL_ADDERS(AnnounceSyllablesChanged, AddSyllablesChangedListener)
|
2007-06-23 02:21:20 +02:00
|
|
|
};
|