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.
This commit is contained in:
Amar Takhar 2009-07-29 22:59:22 +00:00
parent d6fbe6fc8e
commit 6ee2f98349
324 changed files with 16843 additions and 3876 deletions

View file

@ -36,6 +36,8 @@
#pragma once
#ifndef _AEGISUB_ENDIAN_H
/// DOCME
#define _AEGISUB_ENDIAN_H
@ -48,15 +50,23 @@
// But this is an OS X system building a universal binary
// Apple's GCC defines _BIG_ENDIAN when building for PPC
# ifdef _BIG_ENDIAN
/// DOCME
# define HAVE_BIG_ENDIAN
# else
/// DOCME
# define HAVE_LITTLE_ENDIAN
# endif
/// DOCME
# undef HAVE_DYNAMIC_ENDIAN
# else // !HAVE_UNIVERSAL_ENDIAN
// We aren't building an OS X universal binary
// Use the dynamic endian code
# ifndef HAVE_DYNAMIC_ENDIAN
/// DOCME
# define HAVE_DYNAMIC_ENDIAN
# endif
# endif //HAVE_UNIVERSAL_ENDIAN
@ -73,6 +83,8 @@
#include <stdint.h>
/// DOCME
namespace Endian {
// Unconditionally reverse endianness
@ -80,6 +92,11 @@ namespace Endian {
// These are only defined for unsigned ints,
// Use reinterpret_cast on the values if you need signed values.
/// @brief DOCME
/// @param val
/// @return
///
inline uint16_t Reverse(uint16_t val)
{
return
@ -87,6 +104,11 @@ namespace Endian {
((val & 0xFF00) >> 8);
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint32_t Reverse(uint32_t val)
{
return
@ -96,6 +118,11 @@ namespace Endian {
((val & 0xFF000000) >> 24);
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint64_t Reverse(uint64_t val)
{
return
@ -116,6 +143,11 @@ namespace Endian {
// Regular, fast, templatized conditional reversing
template <class T>
/// @brief DOCME
/// @param val
/// @return
///
inline T LittleToMachine(T val)
{
#ifdef HAVE_BIG_ENDIAN
@ -128,6 +160,11 @@ namespace Endian {
}
template <class T>
/// @brief DOCME
/// @param val
/// @return
///
inline T BigToMachine(T val)
{
#ifdef HAVE_LITTLE_ENDIAN
@ -140,6 +177,11 @@ namespace Endian {
}
template <class T>
/// @brief DOCME
/// @param val
/// @return
///
inline T MachineToLittle(T val)
{
#ifdef HAVE_BIG_ENDIAN
@ -152,6 +194,11 @@ namespace Endian {
}
template <class T>
/// @brief DOCME
/// @param val
/// @return
///
inline T MachineToBig(T val)
{
#ifdef HAVE_LITTLE_ENDIAN
@ -179,22 +226,45 @@ namespace Endian {
// Unions to pack together ints and get their physical bytes
/// DOCME
union bytes16 {
/// DOCME
uint8_t byte[2];
/// DOCME
uint16_t word;
};
/// DOCME
union bytes32 {
/// DOCME
uint8_t byte[4];
/// DOCME
uint32_t word;
};
/// DOCME
union bytes64 {
/// DOCME
uint8_t byte[8];
/// DOCME
uint64_t word;
};
// 16 bit words
/// @brief DOCME
/// @param val
/// @return
///
inline uint16_t MachineToBig(uint16_t val)
{
bytes16 pack;
@ -205,6 +275,11 @@ namespace Endian {
return pack.word;
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint16_t MachineToLittle(uint16_t val)
{
bytes16 pack;
@ -215,6 +290,11 @@ namespace Endian {
return pack.word;
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint16_t BigToMachine(uint16_t val)
{
bytes16 pack;
@ -224,6 +304,11 @@ namespace Endian {
return uint16_t(pack.byte[1]) | (uint16_t(pack.byte[0]) << 8);
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint16_t LittleToMachine(uint16_t val)
{
bytes16 pack;
@ -236,6 +321,11 @@ namespace Endian {
// 32 bit words
/// @brief DOCME
/// @param val
/// @return
///
inline uint32_t MachineToBig(uint32_t val)
{
bytes32 pack;
@ -246,6 +336,11 @@ namespace Endian {
return pack.word;
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint32_t MachineToLittle(uint32_t val)
{
bytes32 pack;
@ -256,6 +351,11 @@ namespace Endian {
return pack.word;
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint32_t BigToMachine(uint32_t val)
{
bytes32 pack;
@ -267,6 +367,11 @@ namespace Endian {
uint32_t(pack.byte[3]);
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint32_t LittleToMachine(uint32_t val)
{
bytes32 pack;
@ -281,6 +386,11 @@ namespace Endian {
// 64 bit words
/// @brief DOCME
/// @param val
/// @return
///
inline uint64_t MachineToBig(uint64_t val)
{
bytes64 pack;
@ -295,6 +405,11 @@ namespace Endian {
return pack.word;
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint64_t MachineToLittle(uint64_t val)
{
bytes64 pack;
@ -309,6 +424,11 @@ namespace Endian {
return pack.word;
}
/// @brief DOCME
/// @param val
/// @return
///
inline uint64_t BigToMachine(uint64_t val)
{
bytes64 pack;
@ -324,6 +444,10 @@ namespace Endian {
uint64_t(pack.byte[7]);
}
/// @brief DOCME
/// @param val
///
inline uint64_t LittleToMachine(uint64_t val)
{
bytes64 pack;
@ -346,3 +470,4 @@ namespace Endian {
#endif

View file

@ -49,19 +49,25 @@
#include "standard_paths.h"
#include <wx/stdpaths.h>
///////////////
// Constructor
/// @brief Constructor
///
AegisubLocale::AegisubLocale () {
locale = NULL;
curCode = -1;
}
/// @brief DOCME
///
AegisubLocale::~AegisubLocale() {
delete locale;
}
//////////////
// Initialize
/// @brief Initialize
/// @param language
///
void AegisubLocale::Init(int language) {
if (language == -1) language = wxLANGUAGE_ENGLISH;
if (locale) delete locale;
@ -86,8 +92,10 @@ void AegisubLocale::Init(int language) {
}
///////////////////
// Pick a language
/// @brief Pick a language
/// @return
///
int AegisubLocale::PickLanguage() {
// Get list
wxArrayInt langs = GetAvailableLanguages();
@ -120,8 +128,9 @@ int AegisubLocale::PickLanguage() {
}
///////////////////////////////////
// Get list of available languages
/// @brief Get list of available languages
///
wxArrayInt AegisubLocale::GetAvailableLanguages() {
wxArrayInt final;
@ -177,3 +186,4 @@ wxArrayInt AegisubLocale::GetAvailableLanguages() {
return final;
}

View file

@ -35,6 +35,8 @@
///
#ifndef LOCALE_H
/// DOCME
#define LOCALE_H
@ -43,14 +45,22 @@
class wxLocale;
////////////////////////
// Aegisub locale class
/// DOCME
/// @class AegisubLocale
/// @brief DOCME
///
/// DOCME
class AegisubLocale {
private:
/// DOCME
wxLocale *locale;
wxArrayInt GetAvailableLanguages();
public:
/// DOCME
int curCode;
AegisubLocale();
@ -62,3 +72,4 @@ public:
#endif

View file

@ -44,8 +44,10 @@
#include "ass_attachment.h"
///////////////
// Constructor
/// @brief Constructor
/// @param _name
///
AssAttachment::AssAttachment(wxString _name) {
// Parse name
filename = _name;
@ -63,14 +65,17 @@ AssAttachment::AssAttachment(wxString _name) {
}
//////////////
// Destructor
/// @brief Destructor
///
AssAttachment::~AssAttachment() {
}
/////////
// Clone
/// @brief Clone
/// @return
///
AssEntry *AssAttachment::Clone() {
// New object
AssAttachment *clone = new AssAttachment(filename);
@ -83,29 +88,36 @@ AssEntry *AssAttachment::Clone() {
}
////////////
// Get data
/// @brief Get data
/// @return
///
const DataVec &AssAttachment::GetData() {
return data->GetData();
}
/////////////////
// Add more data
/// @brief Add more data
/// @param _data
///
void AssAttachment::AddData(wxString _data) {
data->AddData(_data);
}
//////////////////////
// Finish adding data
/// @brief Finish adding data
///
void AssAttachment::Finish() {
data->Finish();
}
/////////////////////////////////////
// Get encoded data to write on file
/// @brief Get encoded data to write on file
/// @return
///
const wxString AssAttachment::GetEntryData() {
// Get data
const DataVec &dat = data->GetData();
@ -162,8 +174,11 @@ const wxString AssAttachment::GetEntryData() {
}
/////////////////////
// Extract as a file
/// @brief Extract as a file
/// @param filename
/// @return
///
void AssAttachment::Extract(wxString filename) {
// Open file
wxFileOutputStream fp(filename);
@ -172,8 +187,10 @@ void AssAttachment::Extract(wxString filename) {
}
/////////////////////////////
// Read a file as attachment
/// @brief Read a file as attachment
/// @param filename
///
void AssAttachment::Import(wxString filename) {
// Data
DataVec &datavec = data->GetData();
@ -190,8 +207,11 @@ void AssAttachment::Import(wxString filename) {
}
////////////////
// Get filename
/// @brief Get filename
/// @param raw
/// @return
///
wxString AssAttachment::GetFileName(bool raw) {
// Raw
if (raw || filename.Right(4).Lower() != _T(".ttf")) return filename;
@ -212,35 +232,41 @@ wxString AssAttachment::GetFileName(bool raw) {
/////////////////// Attachment //////////////////
///////////////
// Constructor
/// @brief Constructor Attachment //////////////////
///
AttachData::AttachData() {
}
//////////////
// Destructor
/// @brief Destructor
///
AttachData::~AttachData() {
}
////////////
// Get data
/// @brief Get data
/// @return
///
DataVec &AttachData::GetData() {
return data;
}
////////////
// Add data
/// @brief Add data
/// @param data
///
void AttachData::AddData(wxString data) {
buffer += data;
}
//////////
// Finish
/// @brief Finish
///
void AttachData::Finish() {
// Source and dest buffers
unsigned char src[4];
@ -289,3 +315,4 @@ void AttachData::Finish() {
buffer.Shrink();
}

View file

@ -45,16 +45,24 @@
#include <vector>
///////////
// Typedef
/// DOCME
typedef std::vector<unsigned char> DataVec;
///////////////////
// Attachment data
/// DOCME
/// @class AttachData
/// @brief DOCME
///
/// DOCME
class AttachData {
private:
/// DOCME
DataVec data;
/// DOCME
wxString buffer;
public:
@ -67,11 +75,19 @@ public:
};
//////////////////////////////
// Class to store attachments
/// DOCME
/// @class AssAttachment
/// @brief DOCME
///
/// DOCME
class AssAttachment : public AssEntry {
private:
/// DOCME
boost::shared_ptr<AttachData> data;
/// DOCME
wxString filename;
public:
@ -85,6 +101,9 @@ public:
wxString GetFileName(bool raw=false);
const wxString GetEntryData();
/// @brief DOCME
///
ASS_EntryType GetType() { return ENTRY_ATTACHMENT; }
AssEntry *Clone();
@ -92,3 +111,4 @@ public:
~AssAttachment();
};

View file

@ -48,8 +48,9 @@
#include "utils.h"
////////////////////// AssDialogue //////////////////////
// Constructs AssDialogue
/// @brief Constructs AssDialogue AssDialogue //////////////////////
///
AssDialogue::AssDialogue() {
group = _T("[Events]");
@ -68,6 +69,11 @@ AssDialogue::AssDialogue() {
}
/// @brief DOCME
/// @param _data
/// @param version
///
AssDialogue::AssDialogue(wxString _data,int version) {
// Set group
group = _T("[Events]");
@ -92,22 +98,25 @@ AssDialogue::AssDialogue(wxString _data,int version) {
}
//////////////
// Destructor
/// @brief Destructor
///
AssDialogue::~AssDialogue () {
Clear();
}
/////////
// Clear
/// @brief Clear
///
void AssDialogue::Clear () {
ClearBlocks();
}
////////////////
// Clear blocks
/// @brief Clear blocks
///
void AssDialogue::ClearBlocks() {
using std::vector;
for (vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) {
@ -117,8 +126,12 @@ void AssDialogue::ClearBlocks() {
}
//////////////////
// Parse ASS Data
/// @brief Parse ASS Data
/// @param rawData
/// @param version
/// @return
///
bool AssDialogue::Parse(wxString rawData, int version) {
size_t pos = 0;
wxString temp;
@ -213,8 +226,10 @@ bool AssDialogue::Parse(wxString rawData, int version) {
}
/////////////
// Make data
/// @brief Make data
/// @return
///
wxString AssDialogue::MakeData() {
// Prepare
static wxString final = _T("");
@ -254,27 +269,34 @@ wxString AssDialogue::MakeData() {
}
//////////////////////////////////
// Update AssDialogue's data line
/// @brief Update AssDialogue's data line
///
void AssDialogue::UpdateData () {
}
//////////////////
// Get entry data
/// @brief Get entry data
/// @return
///
const wxString AssDialogue::GetEntryData() {
return MakeData();
}
//////////////////
// Set entry data
/// @brief Set entry data
/// @param newData
///
void AssDialogue::SetEntryData(wxString newData) {
}
///////////////////////////////
// Get SSA version of Dialogue
/// @brief Get SSA version of Dialogue
/// @return
///
wxString AssDialogue::GetSSAText () {
// Prepare
wxString work = _T("");
@ -308,10 +330,9 @@ wxString AssDialogue::GetSSAText () {
}
//////////////////
// Parse SRT tags
// --------------
// Yea, I convert to ASS tags, then parse that. So sue me.
/// @brief Yea, I convert to ASS tags, then parse that. So sue me. -------------- Parse SRT tags
///
void AssDialogue::ParseSRTTags () {
// Search and replace
size_t total = 0;
@ -448,8 +469,9 @@ void AssDialogue::ParseSRTTags () {
}
//////////////////
// Parse ASS tags
/// @brief Parse ASS tags
///
void AssDialogue::ParseASSTags () {
// Clear blocks
ClearBlocks();
@ -544,16 +566,19 @@ void AssDialogue::ParseASSTags () {
}
//////////////
// Strip tags
/// @brief Strip tags
///
void AssDialogue::StripTags () {
static wxRegEx reg(_T("\\{[^\\{]*\\}"),wxRE_ADVANCED);
reg.Replace(&Text,_T(""));
}
////////////////////////
// Strip a specific tag
/// @brief Strip a specific tag
/// @param tagName
///
void AssDialogue::StripTag (wxString tagName) {
// Parse
using std::list;
@ -583,11 +608,9 @@ void AssDialogue::StripTag (wxString tagName) {
}
///////////////////////
// Convert tags to SRT
// -------------------
// TODO: Improve this code
//
/// @brief TODO: Improve this code ------------------- Convert tags to SRT
///
void AssDialogue::ConvertTagsToSRT () {
// Setup
using std::list;
@ -688,8 +711,9 @@ void AssDialogue::ConvertTagsToSRT () {
}
//////////////////////////
// Updates text from tags
/// @brief Updates text from tags
///
void AssDialogue::UpdateText () {
using std::vector;
Text = _T("");
@ -704,8 +728,11 @@ void AssDialogue::UpdateText () {
}
/////////////////////////////
// Sets margin from a string
/// @brief Sets margin from a string
/// @param origvalue
/// @param which
///
void AssDialogue::SetMarginString(const wxString origvalue,int which) {
// Make it numeric
wxString strvalue = origvalue;
@ -732,8 +759,12 @@ void AssDialogue::SetMarginString(const wxString origvalue,int which) {
}
//////////////////////////
// Gets string for margin
/// @brief Gets string for margin
/// @param which
/// @param pad
/// @return
///
wxString AssDialogue::GetMarginString(int which,bool pad) {
if (which < 0 || which >= 4) throw new Aegisub::InvalidMarginIdError;
int value = Margin[which];
@ -742,8 +773,14 @@ wxString AssDialogue::GetMarginString(int which,bool pad) {
}
///////////////////////////////////
// Process parameters via callback
/// @brief Process parameters via callback
/// @param tagName
/// @param par_n
/// @param param
/// @param userData)
/// @param userData
///
void AssDialogue::ProcessParameters(void (*callback)(wxString tagName,int par_n,AssOverrideParameter *param,void *userData),void *userData) {
// Apply for all override blocks
AssDialogueBlockOverride *curBlock;
@ -758,8 +795,11 @@ void AssDialogue::ProcessParameters(void (*callback)(wxString tagName,int par_n,
}
///////////////////////////////
// Checks if two lines collide
/// @brief Checks if two lines collide
/// @param target
/// @return
///
bool AssDialogue::CollidesWith(AssDialogue *target) {
if (!target) return false;
int a = Start.GetMS();
@ -770,8 +810,10 @@ bool AssDialogue::CollidesWith(AssDialogue *target) {
}
////////////////////////
// Return just the text without any overrides
/// @brief Return just the text without any overrides
/// @return
///
wxString AssDialogue::GetStrippedText() const {
wxString justtext = wxString(_T(""));
bool inCode = false;
@ -783,8 +825,10 @@ wxString AssDialogue::GetStrippedText() const {
}
return justtext;
}
/////////
// Clone
/// @brief Clone
/// @return
///
AssEntry *AssDialogue::Clone() const {
// Create clone
AssDialogue *final = new AssDialogue();
@ -808,23 +852,26 @@ AssEntry *AssDialogue::Clone() const {
}
////////////////////// AssDialogueBlock //////////////////////
///////////////
// Constructor
/// @brief Constructor AssDialogueBlock //////////////////////
///
AssDialogueBlock::AssDialogueBlock () {
}
//////////////
// Destructor
/// @brief Destructor
/// @return
///
AssDialogueBlock::~AssDialogueBlock () {
}
////////////////////////////
// Returns as a plain block
// ----------------------
// If it isn't a plain block, returns NULL
/// @brief If it isn't a plain block, returns NULL ---------------------- Returns as a plain block
/// @param base
/// @return
///
AssDialogueBlockPlain *AssDialogueBlock::GetAsPlain(AssDialogueBlock *base) {
if (!base) return NULL;
if (base->GetType() == BLOCK_PLAIN) {
@ -834,10 +881,11 @@ AssDialogueBlockPlain *AssDialogueBlock::GetAsPlain(AssDialogueBlock *base) {
}
////////////////////////////////
// Returns as an override block
// ----------------------------
// If it isn't an override block, returns NULL
/// @brief If it isn't an override block, returns NULL ---------------------------- Returns as an override block
/// @param base
/// @return
///
AssDialogueBlockOverride *AssDialogueBlock::GetAsOverride(AssDialogueBlock *base) {
if (!base) return NULL;
if (base->GetType() == BLOCK_OVERRIDE) {
@ -847,10 +895,11 @@ AssDialogueBlockOverride *AssDialogueBlock::GetAsOverride(AssDialogueBlock *base
}
//////////////////////////////
// Returns as a drawing block
// ----------------------------
// If it isn't an drawing block, returns NULL
/// @brief If it isn't an drawing block, returns NULL ---------------------------- Returns as a drawing block
/// @param base
/// @return
///
AssDialogueBlockDrawing *AssDialogueBlock::GetAsDrawing(AssDialogueBlock *base) {
if (!base) return NULL;
if (base->GetType() == BLOCK_DRAWING) {
@ -860,22 +909,27 @@ AssDialogueBlockDrawing *AssDialogueBlock::GetAsDrawing(AssDialogueBlock *base)
}
////////////////////// AssDialogueBlockPlain //////////////////////
///////////////
// Constructor
/// @brief Constructor AssDialogueBlockPlain //////////////////////
///
AssDialogueBlockPlain::AssDialogueBlockPlain () {
}
////////////////////// AssDialogueBlockDrawing //////////////////////
///////////////
// Constructor
/// @brief Constructor AssDialogueBlockDrawing //////////////////////
///
AssDialogueBlockDrawing::AssDialogueBlockDrawing () {
}
////////////////////////
// Multiply coordinates
/// @brief Multiply coordinates
/// @param mx
/// @param my
/// @param x
/// @param y
///
void AssDialogueBlockDrawing::TransformCoords(int mx,int my,double x,double y) {
// HACK: Implement a proper parser ffs!!
wxStringTokenizer tkn(GetText(),_T(" "),wxTOKEN_DEFAULT);
@ -917,3 +971,4 @@ void AssDialogueBlockDrawing::TransformCoords(int mx,int my,double x,double y) {

View file

@ -54,45 +54,63 @@ class AssDialogueBlockOverride;
class AssDialogueBlockDrawing;
///////////////////
// Block type enum
/// DOCME
enum ASS_BlockType {
/// DOCME
BLOCK_BASE,
/// DOCME
BLOCK_PLAIN,
/// DOCME
BLOCK_OVERRIDE,
/// DOCME
BLOCK_DRAWING
};
//////////////////////
// AssDialogue Blocks
// ------------------
// A block is each group in the text field of an AssDialogue
// For example:
// Yes, I {\i1}am{\i0} here.
//
// Gets split in five blocks:
// "Yes, I " (Plain)
// "\i1" (Override)
// "am" (Plain)
// "\i0" (Override)
// " here." (Plain)
//
// Also note how {}s are discarded.
// Override blocks are further divided in AssOverrideTag's.
//
// The GetText() method generates a new value for the "text" field from
// the other fields in the specific class, and returns the new value.
//
/// DOCME
/// @class AssDialogueBlock
/// @brief AssDialogue Blocks
///
/// A block is each group in the text field of an AssDialogue
/// @verbatium
/// Yes, I {\i1}am{\i0} here.
///
/// Gets split in five blocks:
/// "Yes, I " (Plain)
/// "\i1" (Override)
/// "am" (Plain)
/// "\i0" (Override)
/// " here." (Plain)
///
/// Also note how {}s are discarded.
/// Override blocks are further divided in AssOverrideTag's.
///
/// The GetText() method generates a new value for the "text" field from
/// the other fields in the specific class, and returns the new value.
/// @endverbatium
class AssDialogueBlock {
public:
/// DOCME
wxString text;
/// DOCME
AssDialogue *parent;
AssDialogueBlock();
virtual ~AssDialogueBlock();
virtual ASS_BlockType GetType() = 0;
/// @brief DOCME
/// @return
///
virtual wxString GetText() { return text; }
static AssDialogueBlockPlain *GetAsPlain(AssDialogueBlock *base); // Returns a block base as a plain block if it is valid, null otherwise
static AssDialogueBlockOverride *GetAsOverride(AssDialogueBlock *base); // Returns a block base as an override block if it is valid, null otherwise
@ -100,47 +118,64 @@ public:
};
/////////////////////////////
// Plain dialogue block text
// -------------------------
// This is used for standard text
// type = BLOCK_PLAIN
//
/// DOCME
/// @class AssDialogueBlockPlain
/// @brief DOCME
///
/// DOCME
class AssDialogueBlockPlain : public AssDialogueBlock {
public:
/// @brief DOCME
/// @return
///
ASS_BlockType GetType() { return BLOCK_PLAIN; }
AssDialogueBlockPlain();
};
/////////////////////////////
// Plain dialogue block text
// -------------------------
// This is used for drawing commands
// type = BLOCK_DRAWING
//
/// DOCME
/// @class AssDialogueBlockDrawing
/// @brief DOCME
///
/// DOCME
class AssDialogueBlockDrawing : public AssDialogueBlock {
public:
/// DOCME
int Scale;
/// @brief DOCME
/// @return
///
ASS_BlockType GetType() { return BLOCK_DRAWING; }
AssDialogueBlockDrawing();
void TransformCoords(int trans_x,int trans_y,double mult_x,double mult_y);
};
//////////////////////
// Override tag block
// ------------------
// Used to store ASS overrides
// Type = BLOCK_OVERRIDE
//
/// DOCME
/// @class AssDialogueBlockOverride
/// @brief DOCME
///
/// DOCME
class AssDialogueBlockOverride : public AssDialogueBlock {
public:
AssDialogueBlockOverride();
~AssDialogueBlockOverride();
/// DOCME
std::vector<AssOverrideTag*> Tags;
/// @brief DOCME
/// @return
///
ASS_BlockType GetType() { return BLOCK_OVERRIDE; }
wxString GetText();
void ParseTags(); // Parses tags
@ -148,25 +183,53 @@ public:
};
////////////////////////////////////////
// Class for Dialogue and Comment lines
/// DOCME
/// @class AssDialogue
/// @brief DOCME
///
/// DOCME
class AssDialogue : public AssEntry {
private:
wxString MakeData();
public:
/// DOCME
std::vector<AssDialogueBlock*> Blocks; // Contains information about each block of text
/// DOCME
bool Comment; // Is this a comment line?
/// DOCME
int Layer; // Layer number
/// DOCME
int Margin[4]; // Margins: 0 = Left, 1 = Right, 2 = Top (Vertical), 3 = Bottom
/// DOCME
AssTime Start; // Starting time
/// DOCME
AssTime End; // Ending time
/// DOCME
wxString Style; // Style name
/// DOCME
wxString Actor; // Actor name
/// DOCME
wxString Effect; // Effect name
/// DOCME
wxString Text; // Raw text data
/// @brief DOCME
/// @return
///
ASS_EntryType GetType() { return ENTRY_DIALOGUE; }
bool Parse(wxString data,int version=1); // Parses raw ASS data into everything else
@ -186,10 +249,29 @@ public:
void SetEntryData(wxString newData);
void Clear(); // Wipes all data
/// @brief DOCME
/// @return
///
virtual int GetStartMS() const { return Start.GetMS(); }
/// @brief DOCME
/// @return
///
virtual int GetEndMS() const { return End.GetMS(); }
/// @brief DOCME
/// @param newStart
///
virtual void SetStartMS(const int newStart) { AssEntry::SetStartMS(newStart); Start.SetMS(newStart); }
/// @brief DOCME
/// @param newEnd
///
virtual void SetEndMS(const int newEnd) { End.SetMS(newEnd); }
/// @brief DOCME
///
void FixStartMS() { AssEntry::SetStartMS(Start.GetMS()); } // Update StartMS in AssEntry from the Start value here
void SetMarginString(const wxString value,int which); // Set string to a margin value (0 = left, 1 = right, 2 = vertical/top, 3 = bottom)
@ -204,3 +286,4 @@ public:
~AssDialogue();
};

View file

@ -45,34 +45,46 @@
#include "ass_entry.h"
////////////////////// AssEntry //////////////////////
///////////////////////
// Constructs AssEntry
/// @brief Constructs AssEntry AssEntry //////////////////////
///
AssEntry::AssEntry() {
Valid = true;
}
/// @brief DOCME
/// @param _data
///
AssEntry::AssEntry(wxString _data) {
data = _data;
Valid = true;
}
///////////////////////////
// Destructor for AssEntry
/// @brief Destructor for AssEntry
///
AssEntry::~AssEntry() {
}
///////////////////////////
// Comparison for STL Sort
/// @brief Comparison for STL Sort
/// @param t1
/// @param t2
/// @return
///
bool operator < (const AssEntry &t1, const AssEntry &t2) {
return (t1.GetStartMS() < t2.GetStartMS());
}
////////////////////////////////////////////////////////////////
// Returns an entry as dialogue if possible, else, returns NULL
/// @brief Returns an entry as dialogue if possible, else, returns NULL
/// @param base
/// @return
///
AssDialogue *AssEntry::GetAsDialogue(AssEntry *base) {
if (!base) return NULL;
if (base->GetType() == ENTRY_DIALOGUE) {
@ -82,8 +94,11 @@ AssDialogue *AssEntry::GetAsDialogue(AssEntry *base) {
}
/////////////////////////////////////////////////////////////
// Returns an entry as style if possible, else, returns NULL
/// @brief Returns an entry as style if possible, else, returns NULL
/// @param base
/// @return
///
AssStyle *AssEntry::GetAsStyle(AssEntry *base) {
if (!base) return NULL;
if (base->GetType() == ENTRY_STYLE) {
@ -93,8 +108,11 @@ AssStyle *AssEntry::GetAsStyle(AssEntry *base) {
}
///////////////////////////////////////////////////////////////////
// Returns an entry as attachment if possible, else, returns NULL
/// @brief Returns an entry as attachment if possible, else, returns NULL
/// @param base
/// @return
///
AssAttachment *AssEntry::GetAsAttachment(AssEntry *base) {
if (!base) return NULL;
if (base->GetType() == ENTRY_ATTACHMENT) {
@ -104,8 +122,10 @@ AssAttachment *AssEntry::GetAsAttachment(AssEntry *base) {
}
//////////////////////
// Get SSA conversion
/// @brief Get SSA conversion
/// @return
///
wxString AssEntry::GetSSAText() {
// Special cases
if (data.Lower() == _T("[v4+ styles]")) return wxString(_T("[V4 Styles]"));
@ -118,8 +138,9 @@ wxString AssEntry::GetSSAText() {
}
/////////
// Clone
/// @brief Clone
///
AssEntry *AssEntry::Clone() const {
// Create clone
AssEntry *final = new AssEntry();
@ -134,3 +155,4 @@ AssEntry *AssEntry::Clone() const {
return final;
}

View file

@ -52,36 +52,70 @@ class AssStyle;
class AssAttachment;
///////////////////
// Entry type enum
/// DOCME
enum ASS_EntryType {
/// DOCME
ENTRY_BASE,
/// DOCME
ENTRY_DIALOGUE,
/// DOCME
ENTRY_STYLE,
/// DOCME
ENTRY_ATTACHMENT
};
/// DOCME
namespace Aegisub {
// Thrown when someone supplies an invalid margin ID to a function expecting one
// (Usually limited to range 0..3.)
/// DOCME
/// @class InvalidMarginIdError
/// @brief DOCME
///
/// DOCME
class InvalidMarginIdError : public InternalError {
public:
/// @brief DOCME
/// @return
///
InvalidMarginIdError() : InternalError(_T("Invalid margin id"), 0) { }
/// @brief DOCME
/// @return
///
const wxChar *GetName() { return _T("internal_error/invalid_margin_id"); }
};
};
////////////////////////////////////
// Base class for each line in file
/// DOCME
/// @class AssEntry
/// @brief DOCME
///
/// DOCME
class AssEntry {
private:
/// DOCME
wxString data; // Raw data, exactly the same line that appears on the .ass (note that this will be in ass even if source wasn't)
/// DOCME
int StartMS; // This is only stored for sorting issues, in order to keep non-dialogue lines aligned
public:
/// DOCME
bool Valid; // Flags as valid or not
/// DOCME
wxString group; // Group it belongs to, e.g. "[Events]"
AssEntry();
@ -90,13 +124,42 @@ public:
virtual AssEntry *Clone() const;
/// @brief DOCME
/// @return
///
virtual int GetStartMS() const { return StartMS; }
/// @brief DOCME
/// @return
///
virtual int GetEndMS() const { return StartMS; }
/// @brief DOCME
/// @param newStart
///
virtual void SetStartMS(const int newStart) { StartMS = newStart; }
/// @brief DOCME
/// @param newEnd
/// @return
///
virtual void SetEndMS(const int newEnd) { /* do nothing */ (void)newEnd; }
/// @brief DOCME
/// @return
///
virtual ASS_EntryType GetType() { return ENTRY_BASE; }
/// @brief DOCME
/// @return
///
virtual const wxString GetEntryData() { return data; }
/// @brief DOCME
/// @param newData
///
virtual void SetEntryData(wxString newData) { if (newData.IsEmpty()) data.Clear(); else data = newData; }
virtual wxString GetSSAText();
@ -108,3 +171,4 @@ public:
// This operator is for sorting
bool operator < (const AssEntry &t1, const AssEntry &t2);

View file

@ -43,8 +43,9 @@
#include "ass_file.h"
///////////////
// Constructor
/// @brief Constructor
///
AssExportFilter::AssExportFilter() {
hidden = false;
autoExporter = false;
@ -54,8 +55,9 @@ AssExportFilter::AssExportFilter() {
}
//////////////
// Destructor
/// @brief Destructor
///
AssExportFilter::~AssExportFilter() {
try {
Unregister();
@ -66,8 +68,11 @@ AssExportFilter::~AssExportFilter() {
}
////////////
// Register
/// @brief Register
/// @param name
/// @param priority
///
void AssExportFilter::Register (wxString name,int priority) {
// Check if it's registered
// Changed this to an assert, since this kind of error should really only happen during dev. -jfs
@ -114,8 +119,9 @@ try_new_name:
}
//////////////
// Unregister
/// @brief Unregister
///
void AssExportFilter::Unregister () {
// Check if it's registered
if (!IsRegistered()) throw wxString::Format(_T("Unregister export filter: name \"%s\" is not registered."), RegisterName.c_str());
@ -126,8 +132,10 @@ void AssExportFilter::Unregister () {
}
/////////////////////////////
// Checks if it's registered
/// @brief Checks if it's registered
/// @return
///
bool AssExportFilter::IsRegistered() {
// Check name
if (RegisterName.IsEmpty()) {
@ -148,49 +156,61 @@ bool AssExportFilter::IsRegistered() {
}
/////////////
// Get sizer
/// @brief Get sizer
/// @param parent
/// @return
///
wxWindow *AssExportFilter::GetConfigDialogWindow(wxWindow *parent) {
return NULL;
}
////////////////////
// Config dialog OK
/// @brief Config dialog OK
/// @param IsDefault
///
void AssExportFilter::LoadSettings(bool IsDefault) {
}
//////////////////////
// Description reader
/// @brief Description reader
/// @return
///
const wxString& AssExportFilter::GetDescription() const {
return description;
}
///////////////
// Static list
/// DOCME
AssExportFilterChain *AssExportFilterChain::instance=NULL;
////////////
// Get list
/// @brief Get list
/// @return
///
FilterList *AssExportFilterChain::GetFilterList() {
if (instance == NULL) instance = new AssExportFilterChain();
return &(instance->Filters);
}
///////////////////////
// Get unprepared list
/// @brief Get unprepared list
/// @return
///
FilterList *AssExportFilterChain::GetUnpreparedFilterList() {
if (instance == NULL) instance = new AssExportFilterChain();
return &(instance->Unprepared);
}
///////////////////
// Prepare filters
/// @brief Prepare filters
///
void AssExportFilterChain::PrepareFilters() {
for (FilterList::iterator cur=instance->Unprepared.begin();cur!=instance->Unprepared.end();cur++) {
(*cur)->Init();
@ -198,3 +218,4 @@ void AssExportFilterChain::PrepareFilters() {
instance->Unprepared.clear();
}

View file

@ -54,21 +54,31 @@ class DialogExport;
class AssExporter;
////////////
// Typedefs
/// DOCME
typedef std::list<AssExportFilter*> FilterList;
//////////////////////////////////////
// Singleton for storing filter chain
/// DOCME
/// @class AssExportFilterChain
/// @brief DOCME
///
/// DOCME
class AssExportFilterChain {
friend class AssExportFilter;
friend class AssExporter;
private:
/// DOCME
FilterList Filters;
/// DOCME
FilterList Unprepared;
/// DOCME
static AssExportFilterChain *instance;
static FilterList *GetFilterList();
static FilterList *GetUnpreparedFilterList();
@ -78,20 +88,36 @@ public:
};
////////////////////////////
// Base export filter class
/// DOCME
/// @class AssExportFilter
/// @brief DOCME
///
/// DOCME
class AssExportFilter {
friend class AssExporter;
friend class AssExportFilterChain;
private:
/// DOCME
wxString RegisterName;
/// DOCME
int Priority;
protected:
/// DOCME
bool autoExporter;
/// DOCME
bool hidden;
/// DOCME
bool initialized;
/// DOCME
wxString description;
void Register(wxString name,int priority=0); // Register the filter with specific name. Higher priority filters get the file to process first.
@ -110,3 +136,4 @@ public:
virtual void LoadSettings(bool IsDefault); // Config dialog is done - extract data now.
};

View file

@ -45,22 +45,28 @@
#include "frame_main.h"
///////////////
// Constructor
/// @brief Constructor
/// @param subs
///
AssExporter::AssExporter (AssFile *subs) {
OriginalSubs = subs;
IsDefault = true;
}
//////////////
// Destructor
/// @brief Destructor
///
AssExporter::~AssExporter () {
}
/////////////////////////
// Draw control settings
/// @brief Draw control settings
/// @param parent
/// @param AddTo
///
void AssExporter::DrawSettings(wxWindow *parent,wxSizer *AddTo) {
IsDefault = false;
wxWindow *window;
@ -85,8 +91,10 @@ void AssExporter::DrawSettings(wxWindow *parent,wxSizer *AddTo) {
}
///////////////////////
// Add filter to chain
/// @brief Add filter to chain
/// @param name
///
void AssExporter::AddFilter(wxString name) {
// Get filter
AssExportFilter *filter = NULL;
@ -106,8 +114,9 @@ void AssExporter::AddFilter(wxString name) {
}
///////////////////////////////////////////
// Adds all autoexporting filters to chain
/// @brief Adds all autoexporting filters to chain
///
void AssExporter::AddAutoFilters() {
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
@ -119,8 +128,10 @@ void AssExporter::AddAutoFilters() {
}
///////////////////////////
// Get name of all filters
/// @brief Get name of all filters
/// @return
///
wxArrayString AssExporter::GetAllFilterNames() {
wxArrayString names;
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
@ -132,8 +143,11 @@ wxArrayString AssExporter::GetAllFilterNames() {
}
////////////////////////
// Transform for export
/// @brief Transform for export
/// @param export_dialog
/// @return
///
AssFile *AssExporter::ExportTransform(wxWindow *export_dialog) {
// Copy
AssFile *Subs = new AssFile(*OriginalSubs);
@ -149,8 +163,12 @@ AssFile *AssExporter::ExportTransform(wxWindow *export_dialog) {
}
//////////
// Export
/// @brief Export
/// @param filename
/// @param charset
/// @param export_dialog
///
void AssExporter::Export(wxString filename, wxString charset, wxWindow *export_dialog) {
// Get transformation
AssFile *Subs = ExportTransform(export_dialog);
@ -161,8 +179,11 @@ void AssExporter::Export(wxString filename, wxString charset, wxWindow *export_d
}
///////////////////////////////////
// Get window associated with name
/// @brief Get window associated with name
/// @param name
/// @return
///
wxSizer *AssExporter::GetSettingsSizer(wxString name) {
SizerMap::iterator pos = Sizers.find(name);
if (pos == Sizers.end()) return NULL;
@ -170,8 +191,10 @@ wxSizer *AssExporter::GetSettingsSizer(wxString name) {
}
/////////////////////////////
// Get description of filter
/// @brief Get description of filter
/// @param name
///
wxString AssExporter::GetDescription(wxString name) {
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
@ -183,3 +206,4 @@ wxString AssExporter::GetDescription(wxString name) {
throw wxString::Format(_T("Filter not found: %s"), name.c_str());
}

View file

@ -54,19 +54,33 @@ class AssExportFilter;
class AssFile;
////////////
// Typedefs
/// DOCME
typedef std::list<AssExportFilter*> FilterList;
/// DOCME
typedef std::map<wxString,wxSizer*> SizerMap;
//////////////////
// Exporter class
/// DOCME
/// @class AssExporter
/// @brief DOCME
///
/// DOCME
class AssExporter {
private:
/// DOCME
SizerMap Sizers;
/// DOCME
FilterList Filters;
/// DOCME
AssFile *OriginalSubs;
/// DOCME
bool IsDefault;
public:
@ -80,7 +94,11 @@ public:
void Export(wxString file, wxString charset, wxWindow *export_dialog=NULL);
AssFile *ExportTransform(wxWindow *export_dialog=NULL);
wxSizer *GetSettingsSizer(wxString name);
/// @brief DOCME
///
AssFile *GetOriginalSubs() { return OriginalSubs; }
wxString GetDescription(wxString name);
};

View file

@ -58,24 +58,29 @@
#include "subtitle_format.h"
////////////////////// AssFile //////////////////////
///////////////////////
// AssFile constructor
/// @brief AssFile constructor AssFile //////////////////////
///
AssFile::AssFile () {
AssOverrideTagProto::LoadProtos();
Clear();
}
//////////////////////
// AssFile destructor
/// @brief AssFile destructor
///
AssFile::~AssFile() {
Clear();
}
/////////////////////
// Load generic subs
/// @brief Load generic subs
/// @param _filename
/// @param charset
/// @param addToRecent
///
void AssFile::Load (const wxString _filename,const wxString charset,bool addToRecent) {
bool ok = true;
@ -148,8 +153,13 @@ void AssFile::Load (const wxString _filename,const wxString charset,bool addToRe
}
////////////////////////////
// Save a file to Hard Disk
/// @brief Save a file to Hard Disk
/// @param _filename
/// @param setfilename
/// @param addToRecent
/// @param encoding
///
void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wxString encoding) {
// Finds last dot
int i = 0;
@ -182,8 +192,11 @@ void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wx
}
////////////////////////////////
// Saves a file to a ram vector
/// @brief Saves a file to a ram vector
/// @param dst
/// @param encoding
///
void AssFile::SaveMemory(std::vector<char> &dst,const wxString encoding) {
// Set encoding
wxString enc = encoding;
@ -227,8 +240,10 @@ void AssFile::SaveMemory(std::vector<char> &dst,const wxString encoding) {
}
////////////////////////////////////////////
// Exports file with proper transformations
/// @brief Exports file with proper transformations
/// @param _filename
///
void AssFile::Export(wxString _filename) {
AssExporter exporter(this);
exporter.AddAutoFilters();
@ -236,8 +251,10 @@ void AssFile::Export(wxString _filename) {
}
//////////////////
// Can save file?
/// @brief Can save file?
/// @return
///
bool AssFile::CanSave() {
// ASS format?
wxString ext = filename.Lower().Right(4);
@ -307,12 +324,15 @@ bool AssFile::CanSave() {
//}
///////////////////////
// Appends line to Ass
// -------------------
// I strongly advice you against touching this function unless you know what you're doing;
// even moving things out of order might break ASS parsing - AMZ.
//
/// @brief even moving things out of order might break ASS parsing - AMZ. I strongly advice you against touching this function unless you know what you're doing; ------------------- Appends line to Ass
/// @param data
/// @param group
/// @param lasttime
/// @param version
/// @param outGroup
/// @return
///
int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxString *outGroup) {
// Group
AssEntry *entry = NULL;
@ -456,8 +476,9 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,int &version,wxS
}
//////////////////////////////
// Clears contents of assfile
/// @brief Clears contents of assfile
///
void AssFile::Clear () {
for (std::list<AssEntry*>::iterator cur=Line.begin();cur != Line.end();cur++) {
if (*cur) delete *cur;
@ -470,8 +491,10 @@ void AssFile::Clear () {
}
//////////////////////
// Loads default subs
/// @brief Loads default subs
/// @param defline
///
void AssFile::LoadDefault (bool defline) {
// Clear first
Clear();
@ -503,8 +526,10 @@ void AssFile::LoadDefault (bool defline) {
}
////////////////////
// Copy constructor
/// @brief Copy constructor
/// @param from
///
AssFile::AssFile (AssFile &from) {
using std::list;
@ -520,8 +545,10 @@ AssFile::AssFile (AssFile &from) {
}
//////////////////////
// Insert a new style
/// @brief Insert a new style
/// @param style
///
void AssFile::InsertStyle (AssStyle *style) {
// Variables
using std::list;
@ -577,8 +604,10 @@ void AssFile::InsertStyle (AssStyle *style) {
}
////////////////////
// Insert attachment
/// @brief Insert attachment
/// @param attach
///
void AssFile::InsertAttachment (AssAttachment *attach) {
// Search for insertion point
std::list<AssEntry*>::iterator insPoint=Line.end(),cur;
@ -616,8 +645,10 @@ void AssFile::InsertAttachment (AssAttachment *attach) {
}
///////////////////////////////
// Insert attachment from file
/// @brief Insert attachment from file
/// @param filename
///
void AssFile::InsertAttachment (wxString filename) {
// Get name
wxFileName fname(filename);
@ -642,8 +673,11 @@ void AssFile::InsertAttachment (wxString filename) {
}
////////////////////
// Gets script info
/// @brief Gets script info
/// @param _key
/// @return
///
wxString AssFile::GetScriptInfo(const wxString _key) {
// Prepare
wxString key = _key;;
@ -675,8 +709,11 @@ wxString AssFile::GetScriptInfo(const wxString _key) {
}
//////////////////////////
// Get script info as int
/// @brief Get script info as int
/// @param key
/// @return
///
int AssFile::GetScriptInfoAsInt(const wxString key) {
long temp = 0;
try {
@ -689,8 +726,12 @@ int AssFile::GetScriptInfoAsInt(const wxString key) {
}
//////////////////////////
// Set a script info line
/// @brief Set a script info line
/// @param _key
/// @param value
/// @return
///
void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
// Prepare
wxString key = _key;;
@ -745,8 +786,11 @@ void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
}
//////////////////
// Get resolution
/// @brief Get resolution
/// @param sw
/// @param sh
///
void AssFile::GetResolution(int &sw,int &sh) {
// Height
wxString temp = GetScriptInfo(_T("PlayResY"));
@ -788,8 +832,10 @@ void AssFile::GetResolution(int &sw,int &sh) {
}
///////////////////////////////////
// Adds a comment to [Script Info]
/// @brief Adds a comment to [Script Info]
/// @param _comment
///
void AssFile::AddComment(const wxString _comment) {
wxString comment = _T("; ");
comment += _comment;
@ -814,8 +860,10 @@ void AssFile::AddComment(const wxString _comment) {
}
//////////////////////
// Get list of styles
/// @brief Get list of styles
/// @return
///
wxArrayString AssFile::GetStyles() {
wxArrayString styles;
AssStyle *curstyle;
@ -829,8 +877,11 @@ wxArrayString AssFile::GetStyles() {
}
///////////////////////////////
// Gets style of specific name
/// @brief Gets style of specific name
/// @param name
/// @return
///
AssStyle *AssFile::GetStyle(wxString name) {
AssStyle *curstyle;
for (entryIter cur=Line.begin();cur!=Line.end();cur++) {
@ -843,15 +894,20 @@ AssStyle *AssFile::GetStyle(wxString name) {
}
////////////////////////////////////
// Adds file name to list of recent
/// @brief Adds file name to list of recent
/// @param file
///
void AssFile::AddToRecent(wxString file) {
Options.AddToRecentList(file,_T("Recent sub"));
}
///////////////////////////////
// List of supported wildcards
/// @brief List of supported wildcards
/// @param mode
/// @return
///
wxString AssFile::GetWildcardList(int mode) {
//if (mode == 0) return _T("All Supported Types (*.ass,*.ssa,*.srt,*.txt,*.mkv,*.mks,*.mka)|*.ass;*.ssa;*.srt;*.txt;*.mkv;*.mks;*.mka|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Plain-text (*.txt)|*.txt|Matroska (*.mkv,*.mks,*.mka)|*.mkv;*.mks;*.mka");
//else if (mode == 1) return _T("Advanced Substation Alpha (*.ass)|*.ass");
@ -865,8 +921,10 @@ wxString AssFile::GetWildcardList(int mode) {
}
////////////////////////////////////////////
// Compress/decompress for storage on stack
/// @brief Compress/decompress for storage on stack
/// @param compress
///
void AssFile::CompressForStack(bool compress) {
AssDialogue *diag;
for (entryIter cur=Line.begin();cur!=Line.end();cur++) {
@ -882,15 +940,19 @@ void AssFile::CompressForStack(bool compress) {
}
//////////////////////////////
// Checks if file is modified
/// @brief Checks if file is modified
/// @return
///
bool AssFile::IsModified() {
return Modified;
}
/////////////////////////
// Flag file as modified
/// @brief Flag file as modified
/// @param desc
///
void AssFile::FlagAsModified(wxString desc) {
// Clear redo
if (!RedoStack.empty()) {
@ -907,8 +969,10 @@ void AssFile::FlagAsModified(wxString desc) {
}
//////////////
// Stack push
/// @brief Stack push
/// @param desc
///
void AssFile::StackPush(wxString desc) {
// Places copy on stack
AssFile *curcopy = new AssFile(*top);
@ -931,8 +995,9 @@ void AssFile::StackPush(wxString desc) {
}
/////////////
// Stack pop
/// @brief Stack pop
///
void AssFile::StackPop() {
bool addcopy = false;
wxString undodesc=_T("");
@ -964,8 +1029,9 @@ void AssFile::StackPop() {
}
//////////////
// Stack redo
/// @brief Stack redo
///
void AssFile::StackRedo() {
bool addcopy = false;
@ -992,8 +1058,9 @@ void AssFile::StackRedo() {
}
///////////////
// Stack clear
/// @brief Stack clear
///
void AssFile::StackClear() {
// Clear undo
for (std::list<AssFile*>::iterator cur=UndoStack.begin();cur!=UndoStack.end();cur++) {
@ -1011,8 +1078,10 @@ void AssFile::StackClear() {
}
///////////////
// Stack reset
/// @brief Stack reset
/// @return
///
void AssFile::StackReset() {
StackClear();
delete top;
@ -1021,38 +1090,59 @@ void AssFile::StackReset() {
}
//////////////////////////////////
// Returns if undo stack is empty
/// @brief Returns if undo stack is empty
/// @return
///
bool AssFile::IsUndoStackEmpty() {
if (StackModified) return (UndoStack.size() <= 1);
else return UndoStack.empty();
}
//////////////////////////////////
// Returns if redo stack is empty
/// @brief Returns if redo stack is empty
/// @return
///
bool AssFile::IsRedoStackEmpty() {
return RedoStack.empty();
}
/// @brief DOCME
/// @return
///
wxString AssFile::GetUndoDescription() {
return (IsUndoStackEmpty())?_T(""):(UndoStack.back())->undodescription;
}
/// @brief DOCME
/// @return
///
wxString AssFile::GetRedoDescription() {
return (IsRedoStackEmpty())?_T(""):(RedoStack.back())->undodescription;
}
//////////
// Global
/// DOCME
AssFile *AssFile::top;
/// DOCME
std::list<AssFile*> AssFile::UndoStack;
/// DOCME
std::list<AssFile*> AssFile::RedoStack;
/// DOCME
bool AssFile::Popping;
/// DOCME
bool AssFile::StackModified;

View file

@ -58,23 +58,42 @@ class AssDialogueBlockPlain;
class AssEntry;
//////////////////////////////////////
// Class to store the actual ass file
/// DOCME
/// @class AssFile
/// @brief DOCME
///
/// DOCME
class AssFile {
private:
/// DOCME
bool Modified;
// Stack operations
/// DOCME
static std::list<AssFile*> UndoStack;
/// DOCME
static std::list<AssFile*> RedoStack;
/// DOCME
static bool StackModified;
static void StackClear();
public:
/// DOCME
std::list<AssEntry*> Line;
/// DOCME
wxString filename;
/// DOCME
wxString undodescription;
/// DOCME
bool loaded;
AssFile();
@ -116,23 +135,39 @@ public:
static bool IsRedoStackEmpty(); // Checks if undo stack is empty
static wxString GetUndoDescription(); // Gets field undodescription from back of UndoStack
static wxString GetRedoDescription(); // Gets field undodescription from back of RedoStack
/// DOCME
static bool Popping; // Flags the stack as popping. You must unset this after popping
/// DOCME
static AssFile *top; // Current script file. It is "above" the stack.
};
////////////
// Typedefs
/// DOCME
typedef std::list<AssEntry*>::iterator entryIter;
//////////////////////////////////////////////////////
// Hack to get STL sort to work on a list of pointers
template <typename T>
/// DOCME
/// @class LessByPointedToValue
/// @brief DOCME
///
/// DOCME
class LessByPointedToValue : std::binary_function<T const *, T const *, bool> {
public:
/// @brief DOCME
/// @param x
/// @param y
///
bool operator()(T const * x, T const * y) const {
return std::less<T>()(*x, *y);
}
};

View file

@ -40,6 +40,9 @@
#include "ass_karaoke.h"
#include "ass_override.h"
/// @brief DOCME
///
AssKaraokeSyllable::AssKaraokeSyllable()
{
duration = 0;
@ -49,6 +52,11 @@ AssKaraokeSyllable::AssKaraokeSyllable()
tag = 0;
}
/// @brief DOCME
/// @param line
/// @param syls
///
void ParseAssKaraokeTags(const AssDialogue *line, AssKaraokeVector &syls)
{
// Assume line already has tags parsed
@ -120,3 +128,4 @@ void ParseAssKaraokeTags(const AssDialogue *line, AssKaraokeVector &syls)
}

View file

@ -39,17 +39,32 @@
#include "ass_dialogue.h"
#include <vector>
/// DOCME
struct AssKaraokeSyllable {
/// DOCME
int duration; // centiseconds
/// DOCME
wxString text; // stripped text of syllable
/// DOCME
wxString unstripped_text; // including misc. tags
/// DOCME
wxString type; // highlight type, \k \K \kf \ko (backslash included)
/// DOCME
AssOverrideTag *tag; // parsed override tag for direct modification
AssKaraokeSyllable();
};
/// DOCME
typedef std::vector<AssKaraokeSyllable> AssKaraokeVector;
void ParseAssKaraokeTags(const AssDialogue *line, AssKaraokeVector &syls);

View file

@ -45,24 +45,27 @@
#include <wx/log.h>
////////////////////// AssOverrideParameter //////////////////////
///////////////
// Constructor
/// @brief Constructor AssOverrideParameter //////////////////////
///
AssOverrideParameter::AssOverrideParameter () {
classification = PARCLASS_NORMAL;
ommited = false;
}
//////////////
// Destructor
/// @brief Destructor
///
AssOverrideParameter::~AssOverrideParameter () {
DeleteValue();
}
////////
// Copy
/// @brief Copy
/// @param param
///
void AssOverrideParameter::CopyFrom (const AssOverrideParameter &param) {
switch(param.GetType()) {
case VARDATA_INT: SetInt(param.AsInt()); break;
@ -77,20 +80,25 @@ void AssOverrideParameter::CopyFrom (const AssOverrideParameter &param) {
ommited = param.ommited;
}
/// @brief DOCME
/// @param param
///
void AssOverrideParameter::operator= (const AssOverrideParameter &param) {
CopyFrom(param);
}
////////////////////// AssDialogueBlockOverride //////////////////////
///////////////
// Constructor
/// @brief Constructor AssDialogueBlockOverride //////////////////////
///
AssDialogueBlockOverride::AssDialogueBlockOverride () {
}
//////////////
// Destructor
/// @brief Destructor
///
AssDialogueBlockOverride::~AssDialogueBlockOverride () {
for (size_t i=0;i<Tags.size();i++) {
delete Tags[i];
@ -99,8 +107,9 @@ AssDialogueBlockOverride::~AssDialogueBlockOverride () {
}
/////////////
// Read tags
/// @brief Read tags
///
void AssDialogueBlockOverride::ParseTags () {
// Clear current vector
for (size_t i=0;i<Tags.size();i++) {
@ -141,8 +150,10 @@ void AssDialogueBlockOverride::ParseTags () {
}
///////////////////////////
// Get Text representation
/// @brief Get Text representation
/// @return
///
wxString AssDialogueBlockOverride::GetText () {
text = _T("");
for (std::vector<AssOverrideTag*>::iterator cur=Tags.begin();cur!=Tags.end();cur++) {
@ -152,8 +163,13 @@ wxString AssDialogueBlockOverride::GetText () {
}
///////////////////////////////////
// Process parameters via callback
/// @brief Process parameters via callback
/// @param (callback)(wxString
/// @param int
/// @param )
/// @param userData
///
void AssDialogueBlockOverride::ProcessParameters(void (*callback)(wxString,int,AssOverrideParameter *,void *),void *userData) {
AssOverrideTag *curTag;
AssOverrideParameter *curPar;
@ -184,9 +200,12 @@ void AssDialogueBlockOverride::ProcessParameters(void (*callback)(wxString,int,A
}
///////////////////////// AssOverrideParamProto //////////////////////////
///////////////
// Constructor
/// @brief Constructor AssOverrideParamProto //////////////////////////
/// @param _type
/// @param opt
/// @param classi
///
AssOverrideParamProto::AssOverrideParamProto (VariableDataType _type,int opt,ASS_ParameterClass classi) {
type = _type;
optional = opt;
@ -194,33 +213,39 @@ AssOverrideParamProto::AssOverrideParamProto (VariableDataType _type,int opt,ASS
}
//////////////
// Destructor
/// @brief Destructor
///
AssOverrideParamProto::~AssOverrideParamProto() {
}
///////////////////////// AssOverrideTagProto //////////////////////////
///////////////
// Static vars
/// DOCME
std::list<AssOverrideTagProto> AssOverrideTagProto::proto;
/// DOCME
bool AssOverrideTagProto::loaded = false;
///////////////
// Constructor
/// @brief Constructor
///
AssOverrideTagProto::AssOverrideTagProto() {
}
//////////////
// Destructor
/// @brief Destructor
///
AssOverrideTagProto::~AssOverrideTagProto() {
}
///////////////////
// Load prototypes
/// @brief Load prototypes
/// @return
///
void AssOverrideTagProto::LoadProtos () {
if (loaded) return;
loaded = true;
@ -526,23 +551,25 @@ void AssOverrideTagProto::LoadProtos () {
}
//////////////////////// AssOverrideTag //////////////////////////
///////////////
// Constructor
/// @brief Constructor AssOverrideTag //////////////////////////
///
AssOverrideTag::AssOverrideTag () {
valid = false;
}
//////////////
// Destructor
/// @brief Destructor
///
AssOverrideTag::~AssOverrideTag () {
Clear();
}
/////////
// Clear
/// @brief Clear
///
void AssOverrideTag::Clear() {
for (std::vector<AssOverrideParameter*>::iterator cur=Params.begin();cur!=Params.end();cur++) {
delete *cur;
@ -552,8 +579,10 @@ void AssOverrideTag::Clear() {
}
////////////////////////////
// Parses text and sets tag
/// @brief Parses text and sets tag
/// @param text
///
void AssOverrideTag::SetText (const wxString &text) {
// Determine name
Name = _T("");
@ -580,15 +609,19 @@ void AssOverrideTag::SetText (const wxString &text) {
}
/////////////////////////
// Checks if it is valid
/// @brief Checks if it is valid
/// @return
///
bool AssOverrideTag::IsValid() {
return valid;
}
/////////////////////
// Parses parameters
/// @brief Parses parameters
/// @param text
///
void AssOverrideTag::ParseParameters(const wxString &text) {
// Clear first
Clear();
@ -780,8 +813,9 @@ end_tokenizing:
}
//////////////
// Get string
/// @brief Get string
///
wxString AssOverrideTag::ToString() {
// Start with name
wxString result = Name;
@ -814,3 +848,4 @@ wxString AssOverrideTag::ToString() {
return result;
}

View file

@ -50,27 +50,54 @@
class AssDialogueBlockOverride;
// Enum of parameter classification
// This is used for things like checking which tags VFR needs to update
/// DOCME
enum ASS_ParameterClass {
/// DOCME
PARCLASS_NORMAL,
/// DOCME
PARCLASS_ABSOLUTE_SIZE,
/// DOCME
PARCLASS_ABSOLUTE_POS_X,
/// DOCME
PARCLASS_ABSOLUTE_POS_Y,
/// DOCME
PARCLASS_RELATIVE_SIZE_X,
/// DOCME
PARCLASS_RELATIVE_SIZE_Y,
/// DOCME
PARCLASS_RELATIVE_TIME_START,
/// DOCME
PARCLASS_RELATIVE_TIME_END,
//PARCLASS_RELATIVE_TIME_START_CENTI,
//PARCLASS_RELATIVE_TIME_END_CENTI,
/// DOCME
PARCLASS_KARAOKE,
/// DOCME
PARCLASS_DRAWING
};
// Actual class
/// DOCME
/// @class AssOverrideParameter
/// @brief DOCME
///
/// DOCME
class AssOverrideParameter : public VariableData {
public:
/// DOCME
ASS_ParameterClass classification;
/// DOCME
bool ommited;
AssOverrideParameter();
@ -81,18 +108,24 @@ public:
};
///////////////////////////
// Class for override tags
// -----------------------
//
// GetText() returns the text representation of the tag
//
/// DOCME
/// @class AssOverrideTag
/// @brief DOCME
///
/// DOCME
class AssOverrideTag {
private:
/// DOCME
bool valid;
public:
/// DOCME
wxString Name;
/// DOCME
std::vector <AssOverrideParameter*> Params;
AssOverrideTag();
@ -106,36 +139,82 @@ public:
};
///////////////////////////
// Override tags prototype
/// DOCME
enum ASS_ParameterOptional {
/// DOCME
NOT_OPTIONAL = 0xFF,
/// DOCME
OPTIONAL_0 = 0x00,
/// DOCME
OPTIONAL_1 = 0x01,
/// DOCME
OPTIONAL_2 = 0x02,
/// DOCME
OPTIONAL_3 = 0x04,
/// DOCME
OPTIONAL_4 = 0x08,
/// DOCME
OPTIONAL_5 = 0x10,
/// DOCME
OPTIONAL_6 = 0x20,
/// DOCME
OPTIONAL_7 = 0x40
};
/// DOCME
/// @class AssOverrideParamProto
/// @brief DOCME
///
/// DOCME
class AssOverrideParamProto {
public:
/// DOCME
int optional;
/// DOCME
VariableDataType type;
/// DOCME
AssOverrideParameter defaultValue;
/// DOCME
ASS_ParameterClass classification;
AssOverrideParamProto (VariableDataType _type,int opt=NOT_OPTIONAL,ASS_ParameterClass classi=PARCLASS_NORMAL);
~AssOverrideParamProto();
};
/// DOCME
/// @class AssOverrideTagProto
/// @brief DOCME
///
/// DOCME
class AssOverrideTagProto {
public:
/// DOCME
wxString name;
/// DOCME
std::vector<AssOverrideParamProto> params;
/// DOCME
static std::list<AssOverrideTagProto> proto;
/// DOCME
static bool loaded;
static void LoadProtos();
@ -143,3 +222,4 @@ public:
~AssOverrideTagProto();
};

View file

@ -44,20 +44,27 @@
#include "utils.h"
#include <ctype.h>
///////////////////////// AssColor //////////////////////////
////////////////
// Constructors
/// @brief Constructors AssColor //////////////////////////
///
AssColor::AssColor () {
r=g=b=a=0;
}
/// @brief DOCME
/// @param color
///
AssColor::AssColor (wxColour &color) {
SetWXColor(color);
}
//////////////////
// Parse from SSA/ASS
/// @brief Parse from SSA/ASS
/// @param value
/// @return
///
void AssColor::Parse(const wxString value) {
if (value.Len() > 0 && value[0] == _T('#')) {
// HTML colour
@ -91,15 +98,19 @@ void AssColor::Parse(const wxString value) {
}
///////////////////
// Gets a wxColour
/// @brief Gets a wxColour
/// @return
///
wxColour AssColor::GetWXColor() {
return wxColour(r,g,b,255-a);
}
//////////////////////
// Sets color from wx
/// @brief Sets color from wx
/// @param color
///
void AssColor::SetWXColor(const wxColor &color) {
r = color.Red();
g = color.Green();
@ -108,8 +119,13 @@ void AssColor::SetWXColor(const wxColor &color) {
}
///////////////////////////////
// Get formatted in ASS format
/// @brief Get formatted in ASS format
/// @param alpha
/// @param stripped
/// @param isStyle
/// @return
///
wxString AssColor::GetASSFormatted (bool alpha,bool stripped,bool isStyle) {
wxString work;
if (!stripped) work += _T("&H");
@ -120,8 +136,10 @@ wxString AssColor::GetASSFormatted (bool alpha,bool stripped,bool isStyle) {
}
/////////////////////////
// Get decimal formatted
/// @brief Get decimal formatted
/// @return
///
wxString AssColor::GetSSAFormatted () {
long color = (a<<24)+(b<<16)+(g<<8)+r;
wxString output=wxString::Format(_T("%i"),(long)color);
@ -129,20 +147,28 @@ wxString AssColor::GetSSAFormatted () {
}
/////////////
// Operators
/// @brief Operators
/// @param col
/// @return
///
bool AssColor::operator==(AssColor &col) const {
return r==col.r && g==col.g && b==col.b && a==col.a;
}
/// @brief DOCME
/// @param col
/// @return
///
bool AssColor::operator!=(AssColor &col) const {
return r!=col.r || g!=col.g || b!=col.b || a!=col.a;
}
///////////////////////// AssStyle /////////////////////////
///////////////////////
// Default Constructor
/// @brief Default Constructor AssStyle /////////////////////////
///
AssStyle::AssStyle() {
group = _T("[V4+ Styles]");
@ -191,8 +217,11 @@ AssStyle::AssStyle() {
}
///////////////
// Constructor
/// @brief Constructor
/// @param _data
/// @param version
///
AssStyle::AssStyle(wxString _data,int version) {
Valid = Parse(_data,version);
if (!Valid) {
@ -202,14 +231,19 @@ AssStyle::AssStyle(wxString _data,int version) {
}
//////////////
// Destructor
/// @brief Destructor
///
AssStyle::~AssStyle() {
}
//////////////////////////////
// Parses value from ASS data
/// @brief Parses value from ASS data
/// @param rawData
/// @param version
/// @return
///
bool AssStyle::Parse(wxString rawData,int version) {
// Tokenize
wxString temp;
@ -412,8 +446,9 @@ bool AssStyle::Parse(wxString rawData,int version) {
}
///////////////////////////////////////
// Writes data back to ASS (v4+) format
/// @brief Writes data back to ASS (v4+) format
///
void AssStyle::UpdateData() {
wxString final;
@ -437,8 +472,11 @@ void AssStyle::UpdateData() {
}
/////////////////////////////
// Sets margin from a string
/// @brief Sets margin from a string
/// @param str
/// @param which
///
void AssStyle::SetMarginString(const wxString str,int which) {
if (which < 0 || which >= 4) throw new Aegisub::InvalidMarginIdError;
if (!str.IsNumber()) throw _T("Invalid margin value");
@ -451,8 +489,11 @@ void AssStyle::SetMarginString(const wxString str,int which) {
}
//////////////////////////
// Gets string for margin
/// @brief Gets string for margin
/// @param which
/// @return
///
wxString AssStyle::GetMarginString(int which) {
if (which < 0 || which >= 4) throw new Aegisub::InvalidMarginIdError;
wxString result = wxString::Format(_T("%04i"),Margin[which]);
@ -460,8 +501,10 @@ wxString AssStyle::GetMarginString(int which) {
}
///////////////////////////////
// Convert style to SSA string
/// @brief Convert style to SSA string
/// @return
///
wxString AssStyle::GetSSAText() {
wxString output;
int align = 0;
@ -492,8 +535,10 @@ wxString AssStyle::GetSSAText() {
}
/////////
// Clone
/// @brief Clone
/// @return
///
AssEntry *AssStyle::Clone() const {
// Create clone
AssStyle *final = new AssStyle();
@ -534,8 +579,11 @@ AssEntry *AssStyle::Clone() const {
}
///////////////////////////
// Equal to another style?
/// @brief Equal to another style?
/// @param style
/// @return
///
bool AssStyle::IsEqualTo(AssStyle *style) {
// memcmp won't work because strings won't match
if (style->alignment != alignment ||
@ -569,8 +617,10 @@ bool AssStyle::IsEqualTo(AssStyle *style) {
}
/////////////////////////////////////
// Get a list of valid ASS encodings
/// @brief Get a list of valid ASS encodings
/// @param encodingStrings
///
void AssStyle::GetEncodings(wxArrayString &encodingStrings) {
encodingStrings.Clear();
encodingStrings.Add(wxString(_T("0 - ")) + _("ANSI"));
@ -594,3 +644,4 @@ void AssStyle::GetEncodings(wxArrayString &encodingStrings) {
encodingStrings.Add(wxString(_T("255 - ")) + _("OEM"));
}

View file

@ -43,13 +43,25 @@
#include "ass_entry.h"
/////////////////////////
// Class to store colors
/// DOCME
/// @class AssColor
/// @brief DOCME
///
/// DOCME
class AssColor {
public:
/// DOCME
int r; // Red component
/// DOCME
int g; // Green component
/// DOCME
int b; // Blue component
/// DOCME
int a; // Alpha component
AssColor();
@ -66,36 +78,87 @@ public:
};
/////////////////////////
// Class to store styles
/// DOCME
/// @class AssStyle
/// @brief DOCME
///
/// DOCME
class AssStyle : public AssEntry {
public:
/// DOCME
wxString name;
/// DOCME
wxString font;
/// DOCME
double fontsize;
/// DOCME
AssColor primary;
/// DOCME
AssColor secondary;
/// DOCME
AssColor outline;
/// DOCME
AssColor shadow;
/// DOCME
bool bold;
/// DOCME
bool italic;
/// DOCME
bool underline;
/// DOCME
bool strikeout;
/// DOCME
double scalex;
/// DOCME
double scaley;
/// DOCME
double spacing;
/// DOCME
double angle;
/// DOCME
int borderstyle;
/// DOCME
double outline_w;
/// DOCME
double shadow_w;
/// DOCME
int alignment;
/// DOCME
int Margin[4];
/// DOCME
int encoding;
/// DOCME
int relativeTo;
/// @brief DOCME
///
ASS_EntryType GetType() { return ENTRY_STYLE; }
bool Parse(wxString data,int version=1); // Parses raw ASS/SSA data into everything else
@ -114,3 +177,4 @@ public:
~AssStyle();
};

View file

@ -48,8 +48,11 @@
#include "standard_paths.h"
///////////////////////
// Save styles to disk
/// @brief Save styles to disk
/// @param name
/// @return
///
void AssStyleStorage::Save(wxString name) {
if (name.IsEmpty()) return;
@ -61,8 +64,11 @@ void AssStyleStorage::Save(wxString name) {
}
/////////////////////////
// Load styles from disk
/// @brief Load styles from disk
/// @param name
/// @return
///
void AssStyleStorage::Load(wxString name) {
if (name.IsEmpty()) return;
Clear();
@ -84,8 +90,9 @@ void AssStyleStorage::Load(wxString name) {
}
/////////
// Clear
/// @brief Clear
///
void AssStyleStorage::Clear () {
using std::list;
for (list<AssStyle*>::iterator cur=style.begin();cur!=style.end();cur++) {
@ -95,8 +102,10 @@ void AssStyleStorage::Clear () {
}
/////////////
// Get names
/// @brief Get names
/// @return
///
wxArrayString AssStyleStorage::GetNames() {
wxArrayString names;
for (std::list<AssStyle*>::iterator cur=style.begin();cur!=style.end();cur++) {
@ -106,8 +115,10 @@ wxArrayString AssStyleStorage::GetNames() {
}
///////////////////////
// Get a style by name
/// @brief Get a style by name
/// @param name
///
AssStyle *AssStyleStorage::GetStyle(wxString name) {
for (std::list<AssStyle*>::iterator cur=style.begin();cur!=style.end();cur++) {
if ((*cur)->name == name) return *cur;
@ -115,3 +126,4 @@ AssStyle *AssStyleStorage::GetStyle(wxString name) {
return NULL;
}

View file

@ -36,6 +36,8 @@
#ifndef ASS_STYLE_STORAGE_H
/// DOCME
#define ASS_STYLE_STORAGE_H
@ -51,10 +53,16 @@
class AssStyle;
/////////////////
// Storage class
/// DOCME
/// @class AssStyleStorage
/// @brief DOCME
///
/// DOCME
class AssStyleStorage {
public:
/// DOCME
std::list<AssStyle*> style;
wxArrayString GetNames();
@ -67,3 +75,4 @@ public:
#endif

View file

@ -49,17 +49,19 @@
////////////////////// AssTime //////////////////////
// AssTime constructors
/// @brief AssTime constructors AssTime //////////////////////
///
AssTime::AssTime () {
time = 0;
}
////////////////////
// Parses from ASS
// ---------------
// Note that this function is atomic, it won't touch the values if it's invalid.
/// @brief Note that this function is atomic, it won't touch the values if it's invalid. --------------- Parses from ASS
/// @param text
/// @return
///
void AssTime::ParseASS (const wxString text) {
// Prepare
size_t pos = 0;
@ -114,8 +116,10 @@ void AssTime::ParseASS (const wxString text) {
}
///////////////////
// Parses from SRT
/// @brief Parses from SRT
/// @param _text
///
void AssTime::ParseSRT (const wxString _text) {
// Prepare
wxString text = _text;
@ -144,20 +148,29 @@ void AssTime::ParseSRT (const wxString _text) {
}
//////////////////////////////////////////
// AssTime conversion to/from miliseconds
/// @brief AssTime conversion to/from miliseconds
/// @return
///
int AssTime::GetMS () const {
if (!UseMSPrecision) return time/10*10;
else return time;
}
/// @brief DOCME
/// @param _ms
///
void AssTime::SetMS (int _ms) {
time = _ms;
}
////////////////
// ASS Formated
/// @brief ASS Formated
/// @param msPrecision
/// @return
///
wxString AssTime::GetASSFormated (bool msPrecision) {
int h,m,s,ms;
int _ms = time;
@ -202,8 +215,10 @@ wxString AssTime::GetASSFormated (bool msPrecision) {
}
////////////////
// SRT Formated
/// @brief SRT Formated
/// @return
///
wxString AssTime::GetSRTFormated () {
int h,m,s,ms;
int _ms = time;
@ -247,51 +262,108 @@ wxString AssTime::GetSRTFormated () {
}
//////////////////////
// AssTime comparison
/// @brief AssTime comparison
/// @param t1
/// @param t2
/// @return
///
bool operator < (AssTime &t1, AssTime &t2) {
return (t1.GetMS() < t2.GetMS());
}
/// @brief DOCME
/// @param t1
/// @param t2
/// @return
///
bool operator > (AssTime &t1, AssTime &t2) {
return (t1.GetMS() > t2.GetMS());
}
/// @brief DOCME
/// @param t1
/// @param t2
/// @return
///
bool operator <= (AssTime &t1, AssTime &t2) {
return (t1.GetMS() <= t2.GetMS());
}
/// @brief DOCME
/// @param t1
/// @param t2
/// @return
///
bool operator >= (AssTime &t1, AssTime &t2) {
return (t1.GetMS() >= t2.GetMS());
}
/// @brief DOCME
/// @param t1
/// @param t2
/// @return
///
bool operator == (AssTime &t1, AssTime &t2) {
return (t1.GetMS() == t2.GetMS());
}
/// @brief DOCME
/// @param t1
/// @param t2
/// @return
///
bool operator != (AssTime &t1, AssTime &t2) {
return (t1.GetMS() != t2.GetMS());
}
/////////////////
// Static option
/// DOCME
bool AssTime::UseMSPrecision = false;
///////
// Get
/// @brief Get
/// @return
///
int AssTime::GetTimeHours() { return time / 3600000; }
/// @brief DOCME
/// @return
///
int AssTime::GetTimeMinutes() { return (time % 3600000)/60000; }
/// @brief DOCME
/// @return
///
int AssTime::GetTimeSeconds() { return (time % 60000)/1000; }
/// @brief DOCME
/// @return
///
int AssTime::GetTimeMiliseconds() { return (time % 1000); }
/// @brief DOCME
/// @return
///
int AssTime::GetTimeCentiseconds() { return (time % 1000)/10; }
///////
// Constructor
/// @brief Constructor
/// @param separator
/// @param numerator
/// @param denominator
/// @param dropframe
///
FractionalTime::FractionalTime (wxString separator, int numerator, int denominator, bool dropframe) {
drop = dropframe;
if (drop) {
@ -311,14 +383,18 @@ FractionalTime::FractionalTime (wxString separator, int numerator, int denominat
throw _T("FractionalTime: no separator specified");
}
///////
// Destructor
/// @brief Destructor
///
FractionalTime::~FractionalTime () {
sep.Clear();
}
///////
// SMPTE text string to milliseconds conversion
/// @brief SMPTE text string to milliseconds conversion
/// @param _text
/// @return
///
int FractionalTime::ToMillisecs (wxString _text) {
wxString text = _text;
wxString re_str = _T("");
@ -376,22 +452,30 @@ int FractionalTime::ToMillisecs (wxString _text) {
return msecs_f;
}
///////
// SMPTE text string to AssTime conversion
/// @brief SMPTE text string to AssTime conversion
/// @param _text
/// @return
///
AssTime FractionalTime::ToAssTime (wxString _text) {
AssTime time;
time.SetMS((int)ToMillisecs(_text));
return time;
}
///////
// AssTime to SMPTE text string conversion
/// @brief AssTime to SMPTE text string conversion
/// @param time
/// @return
///
wxString FractionalTime::FromAssTime(AssTime time) {
return FromMillisecs(time.GetMS());
}
///////
// Milliseconds to SMPTE text string conversion
/// @brief Milliseconds to SMPTE text string conversion
/// @param msec
///
wxString FractionalTime::FromMillisecs(int64_t msec) {
int h=0, m=0, s=0, f=0; // hours, minutes, seconds, fractions
int fn = (msec*(int64_t)num) / (1000*den); // frame number
@ -444,3 +528,4 @@ RETURN:
return wxString::Format(_T("%02i") + sep + _T("%02i") + sep + _T("%02i") + sep + _T("%02i"),h,m,s,f);
}

View file

@ -45,13 +45,21 @@
#include <stdint.h>
/////////////////////////////
// Class for Ass format time
/// DOCME
/// @class AssTime
/// @brief DOCME
///
/// DOCME
class AssTime {
private:
/// DOCME
int time; // Miliseconds
public:
/// DOCME
static bool UseMSPrecision;
AssTime();
@ -80,17 +88,31 @@ bool operator >= (AssTime &t1, AssTime &t2);
/////////////////////////////
// Class for that annoying SMPTE format timecodes stuff
/// DOCME
/// @class FractionalTime
/// @brief DOCME
///
/// DOCME
class FractionalTime {
private:
/// DOCME
int time; // milliseconds, like in AssTime
/// DOCME
/// DOCME
int num, den; // numerator/denominator
/// DOCME
bool drop; // EVIL
/// DOCME
wxString sep; // separator; someone might have separators of more than one character :V
// A period is roughly 10 minutes and is used for the dropframe stuff;
// SMPTE dropframe timecodes drops 18 timestamps per 18000, hence the number 17982.
/// DOCME
static const int frames_per_period = 17982;
public:
@ -106,3 +128,4 @@ public:
wxString FromMillisecs(int64_t msec);
};

View file

@ -60,8 +60,10 @@
//#include "bevelButton.h"
//#endif
///////////////
// Constructor
/// @brief Constructor
/// @param parent
///
AudioBox::AudioBox(wxWindow *parent) :
wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL|wxBORDER_RAISED)
{
@ -229,8 +231,9 @@ wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL|wxBORDER_RAISE
}
//////////////
// Destructor
/// @brief Destructor
///
AudioBox::~AudioBox() {
audioScroll->PopEventHandler(true);
HorizontalZoom->PopEventHandler(true);
@ -239,8 +242,12 @@ AudioBox::~AudioBox() {
}
////////////
// Set file
/// @brief Set file
/// @param file
/// @param FromVideo
/// @return
///
void AudioBox::SetFile(wxString file,bool FromVideo) {
wxLogDebug(_T("AudioBox::SetFile(file=%s, FromVideo=%d)"), file.c_str(), FromVideo?1:0);
loaded = false;
@ -299,22 +306,28 @@ BEGIN_EVENT_TABLE(AudioBox,wxPanel)
END_EVENT_TABLE()
/////////////////////
// Scrollbar changed
/// @brief Scrollbar changed
/// @param event
///
void AudioBox::OnScrollbar(wxScrollEvent &event) {
audioDisplay->SetPosition(event.GetPosition()*12);
}
///////////////////////////////
// Horizontal zoom bar changed
/// @brief Horizontal zoom bar changed
/// @param event
///
void AudioBox::OnHorizontalZoom(wxScrollEvent &event) {
audioDisplay->SetSamplesPercent(event.GetPosition());
}
/////////////////////////////
// Vertical zoom bar changed
/// @brief Vertical zoom bar changed
/// @param event
///
void AudioBox::OnVerticalZoom(wxScrollEvent &event) {
int pos = event.GetPosition();
if (pos < 1) pos = 1;
@ -328,8 +341,10 @@ void AudioBox::OnVerticalZoom(wxScrollEvent &event) {
}
//////////////////////
// Volume bar changed
/// @brief Volume bar changed
/// @param event
///
void AudioBox::OnVolume(wxScrollEvent &event) {
if (!VerticalLink->GetValue()) {
int pos = event.GetPosition();
@ -340,8 +355,10 @@ void AudioBox::OnVolume(wxScrollEvent &event) {
}
////////////////////////
// Bars linked/unlinked
/// @brief Bars linked/unlinked
/// @param event
///
void AudioBox::OnVerticalLink(wxCommandEvent &event) {
int pos = VerticalZoom->GetValue();
if (pos < 1) pos = 1;
@ -358,8 +375,11 @@ void AudioBox::OnVerticalLink(wxCommandEvent &event) {
}
////////
// Sash
/// @brief Sash
/// @param event
/// @return
///
void AudioBox::OnSash(wxSashEvent& event) {
// OK?
if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE) return;
@ -405,8 +425,10 @@ void AudioBox::OnSash(wxSashEvent& event) {
}
//////////////////
// Play selection
/// @brief Play selection
/// @param event
///
void AudioBox::OnPlaySelection(wxCommandEvent &event) {
int start=0,end=0;
audioDisplay->SetFocus();
@ -415,8 +437,10 @@ void AudioBox::OnPlaySelection(wxCommandEvent &event) {
}
/////////////////
// Play dialogue
/// @brief Play dialogue
/// @param event
///
void AudioBox::OnPlayDialogue(wxCommandEvent &event) {
int start=0,end=0;
audioDisplay->SetFocus();
@ -426,16 +450,20 @@ void AudioBox::OnPlayDialogue(wxCommandEvent &event) {
}
////////////////
// Stop Playing
/// @brief Stop Playing
/// @param event
///
void AudioBox::OnStop(wxCommandEvent &event) {
audioDisplay->SetFocus();
audioDisplay->Stop();
}
////////
// Next
/// @brief Next
/// @param event
///
void AudioBox::OnNext(wxCommandEvent &event) {
audioDisplay->SetFocus();
audioDisplay->Stop();
@ -443,8 +471,10 @@ void AudioBox::OnNext(wxCommandEvent &event) {
}
////////////
// Previous
/// @brief Previous
/// @param event
///
void AudioBox::OnPrev(wxCommandEvent &event) {
audioDisplay->SetFocus();
audioDisplay->Stop();
@ -452,8 +482,10 @@ void AudioBox::OnPrev(wxCommandEvent &event) {
}
/////////////////
// 500 ms before
/// @brief 500 ms before
/// @param event
///
void AudioBox::OnPlay500Before(wxCommandEvent &event) {
int start=0,end=0;
audioDisplay->SetFocus();
@ -462,8 +494,10 @@ void AudioBox::OnPlay500Before(wxCommandEvent &event) {
}
////////////////
// 500 ms after
/// @brief 500 ms after
/// @param event
///
void AudioBox::OnPlay500After(wxCommandEvent &event) {
int start=0,end=0;
audioDisplay->SetFocus();
@ -472,8 +506,10 @@ void AudioBox::OnPlay500After(wxCommandEvent &event) {
}
////////////////
// First 500 ms
/// @brief First 500 ms
/// @param event
///
void AudioBox::OnPlay500First(wxCommandEvent &event) {
int start=0,end=0;
audioDisplay->SetFocus();
@ -484,8 +520,10 @@ void AudioBox::OnPlay500First(wxCommandEvent &event) {
}
///////////////
// Last 500 ms
/// @brief Last 500 ms
/// @param event
///
void AudioBox::OnPlay500Last(wxCommandEvent &event) {
int start=0,end=0;
audioDisplay->SetFocus();
@ -496,8 +534,10 @@ void AudioBox::OnPlay500Last(wxCommandEvent &event) {
}
////////////////////////
// Start to end of file
/// @brief Start to end of file
/// @param event
///
void AudioBox::OnPlayToEnd(wxCommandEvent &event) {
int start=0,end=0;
audioDisplay->SetFocus();
@ -506,8 +546,11 @@ void AudioBox::OnPlayToEnd(wxCommandEvent &event) {
}
//////////////////
// Commit changes
/// @brief Commit changes
/// @param event
/// @return
///
void AudioBox::OnCommit(wxCommandEvent &event) {
wxLogDebug(_T("AudioBox::OnCommit"));
audioDisplay->SetFocus();
@ -517,8 +560,11 @@ void AudioBox::OnCommit(wxCommandEvent &event) {
}
//////////////////
// Toggle karaoke
/// @brief Toggle karaoke
/// @param event
/// @return
///
void AudioBox::OnKaraoke(wxCommandEvent &event) {
wxLogDebug(_T("AudioBox::OnKaraoke"));
audioDisplay->SetFocus();
@ -545,8 +591,9 @@ void AudioBox::OnKaraoke(wxCommandEvent &event) {
}
////////////////////////
// Sets karaoke buttons
/// @brief Sets karaoke buttons
///
void AudioBox::SetKaraokeButtons() {
// What to enable
bool join,split;
@ -573,8 +620,10 @@ void AudioBox::SetKaraokeButtons() {
}
///////////////
// Join button
/// @brief Join button
/// @param event
///
void AudioBox::OnJoin(wxCommandEvent &event) {
wxLogDebug(_T("AudioBox::OnJoin"));
audioDisplay->SetFocus();
@ -586,8 +635,10 @@ void AudioBox::OnJoin(wxCommandEvent &event) {
}
////////////////
// Split button
/// @brief Split button
/// @param event
///
void AudioBox::OnSplit(wxCommandEvent &event) {
wxLogDebug(_T("AudioBox::OnSplit"));
audioDisplay->SetFocus();
@ -599,16 +650,20 @@ void AudioBox::OnSplit(wxCommandEvent &event) {
}
///////////////
// Goto button
/// @brief Goto button
/// @param event
///
void AudioBox::OnGoto(wxCommandEvent &event) {
audioDisplay->SetFocus();
audioDisplay->MakeDialogueVisible(true);
}
/////////////
// Auto Goto
/// @brief Auto Goto
/// @param event
///
void AudioBox::OnAutoGoto(wxCommandEvent &event) {
audioDisplay->SetFocus();
Options.SetBool(_T("Audio Autoscroll"),AutoScroll->GetValue());
@ -616,8 +671,10 @@ void AudioBox::OnAutoGoto(wxCommandEvent &event) {
}
///////////////
// Auto Commit
/// @brief Auto Commit
/// @param event
///
void AudioBox::OnAutoCommit(wxCommandEvent &event) {
audioDisplay->SetFocus();
Options.SetBool(_T("Audio Autocommit"),AutoCommit->GetValue());
@ -625,8 +682,10 @@ void AudioBox::OnAutoCommit(wxCommandEvent &event) {
}
//////////////////////
// Next line on Commit
/// @brief Next line on Commit
/// @param event
///
void AudioBox::OnNextLineCommit(wxCommandEvent &event) {
audioDisplay->SetFocus();
Options.SetBool(_T("Audio Next Line on Commit"),NextCommit->GetValue());
@ -634,8 +693,10 @@ void AudioBox::OnNextLineCommit(wxCommandEvent &event) {
}
///////////////
// Medusa Mode
/// @brief Medusa Mode
/// @param event
///
void AudioBox::OnMedusaMode(wxCommandEvent &event) {
audioDisplay->SetFocus();
Options.SetBool(_T("Audio Medusa Timing Hotkeys"),MedusaMode->GetValue());
@ -644,8 +705,10 @@ void AudioBox::OnMedusaMode(wxCommandEvent &event) {
}
//////////////////////////
// Spectrum Analyzer Mode
/// @brief Spectrum Analyzer Mode
/// @param event
///
void AudioBox::OnSpectrumMode(wxCommandEvent &event) {
Options.SetBool(_T("Audio Spectrum"),SpectrumMode->GetValue());
Options.Save();
@ -655,13 +718,19 @@ void AudioBox::OnSpectrumMode(wxCommandEvent &event) {
}
///////////////
// Lead in/out
/// @brief Lead in/out
/// @param event
///
void AudioBox::OnLeadIn(wxCommandEvent &event) {
audioDisplay->SetFocus();
audioDisplay->AddLead(true,false);
}
/// @brief DOCME
/// @param event
///
void AudioBox::OnLeadOut(wxCommandEvent &event) {
audioDisplay->SetFocus();
audioDisplay->AddLead(false,true);
@ -674,6 +743,10 @@ BEGIN_EVENT_TABLE(FocusEvent,wxEvtHandler)
EVT_SET_FOCUS(FocusEvent::OnSetFocus)
END_EVENT_TABLE()
/// @brief DOCME
/// @param event
///
void FocusEvent::OnSetFocus(wxFocusEvent &event) {
wxWindow *previous = event.GetWindow();
if (previous) previous->SetFocus();
@ -681,3 +754,4 @@ void FocusEvent::OnSetFocus(wxFocusEvent &event) {

View file

@ -36,6 +36,8 @@
#ifndef AUDIO_BOX_H
/// DOCME
#define AUDIO_BOX_H
@ -63,29 +65,67 @@ class wxToggleButton;
class ToggleBitmap;
///////////////////
// Audio box class
/// DOCME
/// @class AudioBox
/// @brief DOCME
///
/// DOCME
class AudioBox : public wxPanel {
friend class AudioDisplay;
private:
/// DOCME
wxScrollBar *audioScroll;
/// DOCME
wxSlider *HorizontalZoom;
/// DOCME
wxSlider *VerticalZoom;
/// DOCME
wxSlider *VolumeBar;
/// DOCME
wxSizer *MainSizer;
/// DOCME
wxSizer *TopSizer;
/// DOCME
wxSizer *sashSizer;
/// DOCME
wxSizer *DisplaySizer;
/// DOCME
wxSashWindow *Sash;
/// DOCME
ToggleBitmap *VerticalLink;
/// DOCME
wxButton *SplitButton;
/// DOCME
wxButton *JoinButton;
/// DOCME
ToggleBitmap *AutoScroll;
/// DOCME
ToggleBitmap *NextCommit;
/// DOCME
ToggleBitmap *MedusaMode;
/// DOCME
ToggleBitmap *AutoCommit;
/// DOCME
ToggleBitmap *SpectrumMode;
void OnScrollbar(wxScrollEvent &event);
@ -120,12 +160,26 @@ private:
void OnNextLineCommit(wxCommandEvent &event);
public:
/// DOCME
AudioDisplay *audioDisplay;
/// DOCME
AudioKaraoke *audioKaraoke;
/// DOCME
wxToggleButton *KaraokeButton;
/// DOCME
FrameMain *frameMain;
/// DOCME
wxString audioName;
/// DOCME
bool loaded;
/// DOCME
bool karaokeMode;
AudioBox(wxWindow *parent);
@ -138,6 +192,12 @@ public:
};
/// DOCME
/// @class FocusEvent
/// @brief DOCME
///
/// DOCME
class FocusEvent : public wxEvtHandler {
private:
@ -149,38 +209,95 @@ private:
///////
// IDs
enum {
/// DOCME
Audio_Scrollbar = 1600,
/// DOCME
Audio_Horizontal_Zoom,
/// DOCME
Audio_Vertical_Zoom,
/// DOCME
Audio_Volume,
/// DOCME
Audio_Sash,
/// DOCME
Audio_Vertical_Link,
/// DOCME
Audio_Button_Play,
/// DOCME
Audio_Button_Stop,
/// DOCME
Audio_Button_Prev,
/// DOCME
Audio_Button_Next,
/// DOCME
Audio_Button_Play_500ms_Before,
/// DOCME
Audio_Button_Play_500ms_After,
/// DOCME
Audio_Button_Play_500ms_First,
/// DOCME
Audio_Button_Play_500ms_Last,
/// DOCME
Audio_Button_Play_Row,
/// DOCME
Audio_Button_Play_To_End,
/// DOCME
Audio_Button_Commit,
/// DOCME
Audio_Button_Karaoke,
/// DOCME
Audio_Button_Goto,
/// DOCME
Audio_Button_Join,
/// DOCME
Audio_Button_Split,
/// DOCME
Audio_Button_Leadin,
/// DOCME
Audio_Button_Leadout,
/// DOCME
Audio_Check_AutoCommit,
/// DOCME
Audio_Check_NextCommit,
/// DOCME
Audio_Check_AutoGoto,
/// DOCME
Audio_Check_Medusa,
/// DOCME
Audio_Check_Spectrum
};
#endif

View file

@ -67,13 +67,19 @@
#ifdef __WXMAC__
/// DOCME
# define AudioDisplayWindowStyle wxWANTS_CHARS
#else
/// DOCME
# define AudioDisplayWindowStyle wxSUNKEN_BORDER | wxWANTS_CHARS
#endif
///////////////
// Constructor
/// @brief Constructor
/// @param parent
///
AudioDisplay::AudioDisplay(wxWindow *parent)
: wxWindow (parent, -1, wxDefaultPosition, wxSize(200,Options.AsInt(_T("Audio Display Height"))), AudioDisplayWindowStyle , _T("Audio Display"))
{
@ -125,8 +131,9 @@ AudioDisplay::AudioDisplay(wxWindow *parent)
}
//////////////
// Destructor
/// @brief Destructor
///
AudioDisplay::~AudioDisplay() {
if (player) player->CloseStream();
delete provider;
@ -148,8 +155,9 @@ AudioDisplay::~AudioDisplay() {
}
/////////
// Reset
/// @brief Reset
///
void AudioDisplay::Reset() {
wxLogDebug(_T("AudioDisplay::Reset"));
hasSel = false;
@ -163,8 +171,10 @@ void AudioDisplay::Reset() {
}
////////////////
// Update image
/// @brief Update image
/// @param weak
///
void AudioDisplay::UpdateImage(bool weak) {
// Update samples
UpdateSamples();
@ -177,6 +187,10 @@ void AudioDisplay::UpdateImage(bool weak) {
Refresh(false);
}
/// @brief DOCME
/// @return
///
void AudioDisplay::DoUpdateImage() {
// Loaded?
if (!loaded || !provider) return;
@ -397,8 +411,11 @@ void AudioDisplay::DoUpdateImage() {
}
///////////////////////
// Draw Inactive Lines
/// @brief Draw Inactive Lines
/// @param dc
/// @return
///
void AudioDisplay::DrawInactiveLines(wxDC &dc) {
// Check if there is anything to do
int shadeType = Options.AsInt(_T("Audio Inactive Lines Display Mode"));
@ -471,8 +488,10 @@ void AudioDisplay::DrawInactiveLines(wxDC &dc) {
}
//////////////////
// Draw keyframes
/// @brief Draw keyframes
/// @param dc
///
void AudioDisplay::DrawKeyframes(wxDC &dc) {
wxArrayInt KeyFrames = VideoContext::Get()->GetKeyFrames();
int nKeys = (int)KeyFrames.Count();
@ -494,8 +513,10 @@ void AudioDisplay::DrawKeyframes(wxDC &dc) {
}
//////////////////
// Draw timescale
/// @brief Draw timescale
/// @param dc
///
void AudioDisplay::DrawTimescale(wxDC &dc) {
// Set size
int timelineHeight = Options.AsBool(_T("Audio Draw Timeline")) ? 20 : 0;
@ -559,8 +580,11 @@ void AudioDisplay::DrawTimescale(wxDC &dc) {
}
////////////
// Waveform
/// @brief Waveform
/// @param dc
/// @param weak
///
void AudioDisplay::DrawWaveform(wxDC &dc,bool weak) {
// Prepare Waveform
if (!weak || peak == NULL || min == NULL) {
@ -601,8 +625,11 @@ void AudioDisplay::DrawWaveform(wxDC &dc,bool weak) {
}
//////////////////////////
// Draw spectrum analyzer
/// @brief Draw spectrum analyzer
/// @param finaldc
/// @param weak
///
void AudioDisplay::DrawSpectrum(wxDC &finaldc,bool weak) {
if (!weak || !spectrumDisplay || spectrumDisplay->GetWidth() != w || spectrumDisplay->GetHeight() != h) {
if (spectrumDisplay) {
@ -653,8 +680,12 @@ void AudioDisplay::DrawSpectrum(wxDC &finaldc,bool weak) {
}
}
//////////////////////////
// Get selection position
/// @brief Get selection position
/// @param selStart
/// @param selEnd
/// @param cap
///
void AudioDisplay::GetDialoguePos(int64_t &selStart,int64_t &selEnd, bool cap) {
selStart = GetXAtMS(curStartMS);
selEnd = GetXAtMS(curEndMS);
@ -668,8 +699,12 @@ void AudioDisplay::GetDialoguePos(int64_t &selStart,int64_t &selEnd, bool cap) {
}
////////////////////////
// Get karaoke position
/// @brief Get karaoke position
/// @param karStart
/// @param karEnd
/// @param cap
///
void AudioDisplay::GetKaraokePos(int64_t &karStart,int64_t &karEnd, bool cap) {
try {
// Wrap around
@ -698,8 +733,10 @@ void AudioDisplay::GetKaraokePos(int64_t &karStart,int64_t &karEnd, bool cap) {
}
//////////
// Update
/// @brief Update
/// @return
///
void AudioDisplay::Update() {
if (blockUpdate) return;
if (loaded) {
@ -711,8 +748,9 @@ void AudioDisplay::Update() {
}
//////////////////////
// Recreate the image
/// @brief Recreate the image
///
void AudioDisplay::RecreateImage() {
GetClientSize(&w,&h);
h -= Options.AsBool(_T("Audio Draw Timeline")) ? 20 : 0;
@ -722,8 +760,10 @@ void AudioDisplay::RecreateImage() {
}
/////////////////////////
// Make dialogue visible
/// @brief Make dialogue visible
/// @param force
///
void AudioDisplay::MakeDialogueVisible(bool force) {
wxLogDebug(_T("AudioDisplay::MakeDialogueVisible(force=%d)"), force?1:0);
// Variables
@ -756,8 +796,10 @@ void AudioDisplay::MakeDialogueVisible(bool force) {
}
////////////////
// Set position
/// @brief Set position
/// @param pos
///
void AudioDisplay::SetPosition(int pos) {
wxLogDebug(_T("AudioDisplay::SetPosition(pos=%d)"), pos);
Position = pos;
@ -766,8 +808,12 @@ void AudioDisplay::SetPosition(int pos) {
}
///////////////////
// Update position
/// @brief Update position
/// @param pos
/// @param IsSample
/// @return
///
void AudioDisplay::UpdatePosition (int pos,bool IsSample) {
// Safeguards
if (!provider) return;
@ -783,9 +829,13 @@ void AudioDisplay::UpdatePosition (int pos,bool IsSample) {
}
/////////////////////////////
// Set samples in percentage
// Note: aka Horizontal Zoom
/// @brief Note: aka Horizontal Zoom Set samples in percentage
/// @param percent
/// @param update
/// @param pivot
/// @return
///
void AudioDisplay::SetSamplesPercent(int percent,bool update,float pivot) {
// Calculate
if (percent < 1) percent = 1;
@ -810,8 +860,10 @@ void AudioDisplay::SetSamplesPercent(int percent,bool update,float pivot) {
}
//////////////////
// Update samples
/// @brief Update samples
/// @return
///
void AudioDisplay::UpdateSamples() {
// Set samples
if (!provider) return;
@ -836,8 +888,11 @@ void AudioDisplay::UpdateSamples() {
}
/////////////
// Set scale
/// @brief Set scale
/// @param _scale
/// @return
///
void AudioDisplay::SetScale(float _scale) {
if (scale == _scale) return;
scale = _scale;
@ -845,8 +900,11 @@ void AudioDisplay::SetScale(float _scale) {
}
//////////////////
// Load from file
/// @brief Load from file
/// @param file
/// @return
///
void AudioDisplay::SetFile(wxString file) {
wxLogDebug(_T("AudioDisplay::SetFile(file=%s)"), file.c_str());
// Unload
@ -956,8 +1014,9 @@ void AudioDisplay::SetFile(wxString file) {
}
///////////////////
// Load from video
/// @brief Load from video
///
void AudioDisplay::SetFromVideo() {
wxLogDebug(_T("AudioDisplay::SetFromVideo"));
if (VideoContext::Get()->IsLoaded()) {
@ -969,16 +1028,19 @@ void AudioDisplay::SetFromVideo() {
}
////////////////
// Reload audio
/// @brief Reload audio
///
void AudioDisplay::Reload() {
wxLogDebug(_T("AudioDisplay::Reload"));
if (provider) SetFile(provider->GetFilename());
}
////////////////////
// Update scrollbar
/// @brief Update scrollbar
/// @return
///
void AudioDisplay::UpdateScrollbar() {
if (!provider) return;
int page = w/12;
@ -988,50 +1050,72 @@ void AudioDisplay::UpdateScrollbar() {
}
//////////////////////////////////////////////
// Gets the sample number at the x coordinate
/// @brief Gets the sample number at the x coordinate
/// @param x
/// @return
///
int64_t AudioDisplay::GetSampleAtX(int x) {
return (x+Position)*samples;
}
/////////////////////////////////////////////////
// Gets the x coordinate corresponding to sample
/// @brief Gets the x coordinate corresponding to sample
/// @param n
/// @return
///
int AudioDisplay::GetXAtSample(int64_t n) {
return samples ? (n/samples)-Position : 0;
}
/////////////////
// Get MS from X
/// @brief Get MS from X
/// @param x
/// @return
///
int AudioDisplay::GetMSAtX(int64_t x) {
return (PositionSample+(x*samples)) * 1000 / provider->GetSampleRate();
}
/////////////////
// Get X from MS
/// @brief Get X from MS
/// @param ms
/// @return
///
int AudioDisplay::GetXAtMS(int64_t ms) {
return ((ms * provider->GetSampleRate() / 1000)-PositionSample)/samples;
}
////////////////////
// Get MS At sample
/// @brief Get MS At sample
/// @param x
/// @return
///
int AudioDisplay::GetMSAtSample(int64_t x) {
return x * 1000 / provider->GetSampleRate();
}
////////////////////
// Get Sample at MS
/// @brief Get Sample at MS
/// @param ms
/// @return
///
int64_t AudioDisplay::GetSampleAtMS(int64_t ms) {
return ms * provider->GetSampleRate() / 1000;
}
////////
// Play
/// @brief Play
/// @param start
/// @param end
/// @return
///
void AudioDisplay::Play(int start,int end) {
wxLogDebug(_T("AudioDisplay::Play"));
Stop();
@ -1092,8 +1176,9 @@ void AudioDisplay::Play(int start,int end) {
}
////////
// Stop
/// @brief Stop
///
void AudioDisplay::Stop() {
wxLogDebug(_T("AudioDisplay::Stop"));
if (VideoContext::Get()->IsPlaying()) VideoContext::Get()->Stop();
@ -1101,8 +1186,12 @@ void AudioDisplay::Stop() {
}
///////////////////////////
// Get samples of dialogue
/// @brief Get samples of dialogue
/// @param start
/// @param end
/// @return
///
void AudioDisplay::GetTimesDialogue(int &start,int &end) {
wxLogDebug(_T("AudioDisplay::GetTimesDialogue"));
if (!dialogue) {
@ -1116,8 +1205,12 @@ void AudioDisplay::GetTimesDialogue(int &start,int &end) {
}
////////////////////////////
// Get samples of selection
/// @brief Get samples of selection
/// @param start
/// @param end
/// @return
///
void AudioDisplay::GetTimesSelection(int &start,int &end) {
wxLogDebug(_T("AudioDisplay::GetTimesSelection"));
start = 0;
@ -1140,8 +1233,11 @@ void AudioDisplay::GetTimesSelection(int &start,int &end) {
}
/////////////////////////////
// Set the current selection
/// @brief Set the current selection
/// @param start
/// @param end
///
void AudioDisplay::SetSelection(int start, int end) {
wxLogDebug(_T("AudioDisplay::SetSelection(start=%d, end=%d)"), start, end);
curStartMS = start;
@ -1150,8 +1246,13 @@ void AudioDisplay::SetSelection(int start, int end) {
}
////////////////
// Set dialogue
/// @brief Set dialogue
/// @param _grid
/// @param diag
/// @param n
/// @return
///
void AudioDisplay::SetDialogue(SubtitlesGrid *_grid,AssDialogue *diag,int n) {
wxLogDebug(_T("AudioDisplay::SetDialogue"));
// Actual parameters
@ -1197,8 +1298,11 @@ void AudioDisplay::SetDialogue(SubtitlesGrid *_grid,AssDialogue *diag,int n) {
}
//////////////////
// Commit changes
/// @brief Commit changes
/// @param nextLine
/// @return
///
void AudioDisplay::CommitChanges (bool nextLine) {
wxLogDebug(_T("AudioDisplay::CommitChanges(nextLine=%d)"), nextLine?1:0);
// Loaded?
@ -1311,8 +1415,11 @@ void AudioDisplay::CommitChanges (bool nextLine) {
}
////////////
// Add lead
/// @brief Add lead
/// @param in
/// @param out
///
void AudioDisplay::AddLead(bool in,bool out) {
// Lead in
if (in) {
@ -1346,8 +1453,11 @@ BEGIN_EVENT_TABLE(AudioDisplay, wxWindow)
END_EVENT_TABLE()
/////////
// Paint
/// @brief Paint
/// @param event
/// @return
///
void AudioDisplay::OnPaint(wxPaintEvent& event) {
if (w == 0 || h == 0) return;
DoUpdateImage();
@ -1357,8 +1467,11 @@ void AudioDisplay::OnPaint(wxPaintEvent& event) {
}
///////////////
// Mouse event
/// @brief Mouse event
/// @param event
/// @return
///
void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
// Get x,y
int64_t x = event.GetX();
@ -1764,8 +1877,14 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
}
////////////////////////
// Get snap to boundary
/// @brief Get snap to boundary
/// @param ms
/// @param rangeX
/// @param shiftHeld
/// @param start
/// @return
///
int AudioDisplay::GetBoundarySnap(int ms,int rangeX,bool shiftHeld,bool start) {
// Range?
if (rangeX <= 0) return ms;
@ -1954,8 +2073,10 @@ int AudioDisplay::GetBoundarySnap(int ms,int rangeX,bool shiftHeld,bool start) {
*/
//////////////
// Size event
/// @brief Size event
/// @param event
///
void AudioDisplay::OnSize(wxSizeEvent &event) {
// Set size
GetClientSize(&w,&h);
@ -1973,8 +2094,11 @@ void AudioDisplay::OnSize(wxSizeEvent &event) {
}
///////////////
// Timer event
/// @brief Timer event
/// @param event
/// @return
///
void AudioDisplay::OnUpdateTimer(wxTimerEvent &event) {
if (!origImage)
return;
@ -2060,8 +2184,10 @@ void AudioDisplay::OnUpdateTimer(wxTimerEvent &event) {
}
////////////
// Key down
/// @brief Key down
/// @param event
///
void AudioDisplay::OnKeyDown(wxKeyEvent &event) {
int key = event.GetKeyCode();
#ifdef __APPLE__
@ -2229,8 +2355,12 @@ void AudioDisplay::OnKeyDown(wxKeyEvent &event) {
}
///////////////
// Change line
/// @brief Change line
/// @param delta
/// @param block
/// @return
///
void AudioDisplay::ChangeLine(int delta, bool block) {
wxLogDebug(_T("AudioDisplay::ChangeLine(delta=%d)"), delta);
if (dialogue) {
@ -2258,8 +2388,11 @@ void AudioDisplay::ChangeLine(int delta, bool block) {
}
////////
// Next
/// @brief Next
/// @param play
/// @return
///
void AudioDisplay::Next(bool play) {
wxLogDebug(_T("AudioDisplay::Next"));
// Karaoke
@ -2313,8 +2446,11 @@ void AudioDisplay::Next(bool play) {
}
////////////
// Previous
/// @brief Previous
/// @param play
/// @return
///
void AudioDisplay::Prev(bool play) {
wxLogDebug(_T("AudioDisplay::Prev"));
// Karaoke
@ -2366,8 +2502,11 @@ void AudioDisplay::Prev(bool play) {
}
///////////////////////////////
// Gets syllable at x position
/// @brief Gets syllable at x position
/// @param x
/// @return
///
int AudioDisplay::GetSyllableAtX(int x) {
if (!karaoke->enabled) return -1;
int ms = GetMSAtX(x);
@ -2386,8 +2525,10 @@ int AudioDisplay::GetSyllableAtX(int x) {
}
////////////////
// Focus events
/// @brief Focus events
/// @param event
///
void AudioDisplay::OnGetFocus(wxFocusEvent &event) {
if (!hasFocus) {
hasFocus = true;
@ -2395,6 +2536,10 @@ void AudioDisplay::OnGetFocus(wxFocusEvent &event) {
}
}
/// @brief DOCME
/// @param event
///
void AudioDisplay::OnLoseFocus(wxFocusEvent &event) {
if (hasFocus && loaded) {
hasFocus = false;
@ -2404,11 +2549,13 @@ void AudioDisplay::OnLoseFocus(wxFocusEvent &event) {
}
//////////////////////////////
// Update time edit controls
/// @brief Update time edit controls
///
void AudioDisplay::UpdateTimeEditCtrls() {
grid->editBox->StartTime->SetTime(curStartMS,true);
grid->editBox->EndTime->SetTime(curEndMS,true);
grid->editBox->Duration->SetTime(curEndMS-curStartMS,true);
}

View file

@ -36,6 +36,8 @@
#ifndef AUDIO_DISPLAY_H
/// DOCME
#define AUDIO_DISPLAY_H
@ -61,58 +63,146 @@ class VideoProvider;
class FrameMain;
/////////////////
// Display class
/// DOCME
/// @class AudioDisplay
/// @brief DOCME
///
/// DOCME
class AudioDisplay: public wxWindow {
friend class FrameMain;
private:
/// DOCME
SubtitlesGrid *grid;
/// DOCME
int line_n;
/// DOCME
AssDialogue *dialogue;
/// DOCME
AudioSpectrum *spectrumRenderer;
/// DOCME
wxBitmap *origImage;
/// DOCME
wxBitmap *spectrumDisplay;
/// DOCME
wxBitmap *spectrumDisplaySelected;
/// DOCME
int64_t PositionSample;
/// DOCME
float scale;
/// DOCME
int samples;
/// DOCME
int64_t Position;
/// DOCME
int samplesPercent;
/// DOCME
int oldCurPos;
/// DOCME
bool hasFocus;
/// DOCME
bool blockUpdate;
/// DOCME
bool dontReadTimes;
/// DOCME
bool playingToEnd;
/// DOCME
bool needImageUpdate;
/// DOCME
bool needImageUpdateWeak;
/// DOCME
bool hasSel;
/// DOCME
bool hasKaraoke;
/// DOCME
bool diagUpdated;
/// DOCME
bool holding;
/// DOCME
bool draggingScale;
/// DOCME
int64_t selStart;
/// DOCME
int64_t selEnd;
/// DOCME
int64_t lineStart;
/// DOCME
int64_t lineEnd;
/// DOCME
int64_t selStartCap;
/// DOCME
int64_t selEndCap;
/// DOCME
int hold;
/// DOCME
int lastX;
/// DOCME
int lastDragX;
/// DOCME
int curStartMS;
/// DOCME
int curEndMS;
/// DOCME
int holdSyl;
/// DOCME
int *peak;
/// DOCME
int *min;
/// DOCME
int scrubTime;
/// DOCME
int64_t scrubLastPos;
/// DOCME
bool scrubbing;
/// DOCME
int scrubLastRate;
void OnPaint(wxPaintEvent &event);
@ -138,17 +228,41 @@ private:
void DoUpdateImage();
public:
/// DOCME
AudioProvider *provider;
/// DOCME
StreamAudioProvider *scrubProvider;
/// DOCME
AudioPlayer *player;
/// DOCME
bool NeedCommit;
/// DOCME
bool loaded;
/// DOCME
bool temporary;
/// DOCME
/// DOCME
int w,h;
/// DOCME
AudioBox *box;
/// DOCME
AudioKaraoke *karaoke;
/// DOCME
wxScrollBar *ScrollBar;
/// DOCME
wxTimer UpdateTimer;
AudioDisplay(wxWindow *parent);
@ -197,9 +311,12 @@ public:
///////
// IDs
enum {
/// DOCME
Audio_Update_Timer = 1700
};
#endif

View file

@ -52,8 +52,9 @@
#include <algorithm>
/////////////////////
// Empty constructor
/// @brief Empty constructor
///
AudioKaraokeSyllable::AudioKaraokeSyllable()
: AssKaraokeSyllable()
, start_time(0), selected(false)
@ -61,8 +62,10 @@ AudioKaraokeSyllable::AudioKaraokeSyllable()
{
}
//////////////////////////////
// Copy-from-base constructor
/// @brief Copy-from-base constructor
/// @param base
///
AudioKaraokeSyllable::AudioKaraokeSyllable(const AssKaraokeSyllable &base)
: AssKaraokeSyllable(base)
, start_time(0), selected(false)
@ -72,8 +75,10 @@ AudioKaraokeSyllable::AudioKaraokeSyllable(const AssKaraokeSyllable &base)
///////////////
// Constructor
/// @brief Constructor
/// @param parent
///
AudioKaraoke::AudioKaraoke(wxWindow *parent)
: wxWindow (parent,-1,wxDefaultPosition,wxSize(10,5),wxTAB_TRAVERSAL|wxBORDER_SUNKEN)
{
@ -87,15 +92,19 @@ AudioKaraoke::AudioKaraoke(wxWindow *parent)
}
//////////////
// Destructor
/// @brief Destructor
///
AudioKaraoke::~AudioKaraoke() {
delete workDiag;
}
//////////////////////
// Load from dialogue
/// @brief Load from dialogue
/// @param _diag
/// @return
///
bool AudioKaraoke::LoadFromDialogue(AssDialogue *_diag) {
wxLogDebug(_T("AudioKaraoke::LoadFromDialogue(diag=%p)"), _diag);
// Make sure we're not in splitting-mode
@ -137,8 +146,10 @@ bool AudioKaraoke::LoadFromDialogue(AssDialogue *_diag) {
}
////////////////////
// Writes line back
/// @brief Writes line back
/// @return
///
void AudioKaraoke::Commit() {
wxLogDebug(_T("AudioKaraoke::Commit"));
if (splitting) {
@ -182,8 +193,10 @@ void AudioKaraoke::Commit() {
}
//////////////////
// Autosplit line
/// @brief Autosplit line
/// @return
///
void AudioKaraoke::AutoSplit() {
wxLogDebug(_T("AudioKaraoke::AutoSplit"));
@ -237,8 +250,11 @@ void AudioKaraoke::AutoSplit() {
}
//////////////////////////////////
// Parses text to extract karaoke
/// @brief Parses text to extract karaoke
/// @param curDiag
/// @return
///
bool AudioKaraoke::ParseDialogue(AssDialogue *curDiag) {
// parse the tagdata
AssKaraokeVector tempsyls;
@ -268,8 +284,11 @@ bool AudioKaraoke::ParseDialogue(AssDialogue *curDiag) {
}
////////////////
// Set syllable
/// @brief Set syllable
/// @param n
/// @return
///
void AudioKaraoke::SetSyllable(int n) {
wxLogDebug(_T("AudioKaraoke::SetSyllable(n=%d)"), n);
if (n == -1) n = syllables.size()-1;
@ -291,8 +310,10 @@ BEGIN_EVENT_TABLE(AudioKaraoke,wxWindow)
END_EVENT_TABLE()
///////////////
// Paint event
/// @brief Paint event
/// @param event
///
void AudioKaraoke::OnPaint(wxPaintEvent &event) {
// Get dimensions
int w,h;
@ -401,15 +422,20 @@ void AudioKaraoke::OnPaint(wxPaintEvent &event) {
}
//////////////
// Size event
/// @brief Size event
/// @param event
///
void AudioKaraoke::OnSize(wxSizeEvent &event) {
Refresh(false);
}
///////////////
// Mouse event
/// @brief Mouse event
/// @param event
/// @return
///
void AudioKaraoke::OnMouse(wxMouseEvent &event) {
// Get coordinates
int x = event.GetX();
@ -542,8 +568,11 @@ void AudioKaraoke::OnMouse(wxMouseEvent &event) {
}
//////////////////////////////
// Get Syllable at position X
/// @brief Get Syllable at position X
/// @param x
/// @return
///
int AudioKaraoke::GetSylAtX(int x) {
int dx,dw;
size_t syln = syllables.size();
@ -558,8 +587,11 @@ int AudioKaraoke::GetSylAtX(int x) {
}
/////////////////
// Set selection
/// @brief Set selection
/// @param start
/// @param end
///
void AudioKaraoke::SetSelection(int start,int end) {
wxLogDebug(_T("AudioKaraoke::SetSelection(start=%d, end=%d)"), start, end);
// Default end
@ -593,8 +625,10 @@ void AudioKaraoke::SetSelection(int start,int end) {
}
//////////////////
// Join syllables
/// @brief Join syllables
/// @return
///
void AudioKaraoke::Join() {
wxLogDebug(_T("AudioKaraoke::Join"));
// Variables
@ -638,8 +672,9 @@ void AudioKaraoke::Join() {
}
////////////////////////
// Enter splitting-mode
/// @brief Enter splitting-mode
///
void AudioKaraoke::BeginSplit() {
wxLogDebug(_T("AudioKaraoke::BeginSplit"));
splitting = true;
@ -650,8 +685,11 @@ void AudioKaraoke::BeginSplit() {
}
////////////////////////////////////////////
// Leave splitting-mode, committing changes
/// @brief Leave splitting-mode, committing changes
/// @param commit
/// @return
///
void AudioKaraoke::EndSplit(bool commit) {
wxLogDebug(_T("AudioKaraoke::EndSplit(commit=%d)"), commit?1:0);
splitting = false;
@ -686,8 +724,11 @@ void AudioKaraoke::EndSplit(bool commit) {
}
/////////////////////////////////////////////////
// Split a syllable using the pending_slits data
/// @brief Split a syllable using the pending_slits data
/// @param n
/// @return
///
int AudioKaraoke::SplitSyl (unsigned int n) {
wxLogDebug(_T("AudioKaraoke::SplitSyl(n=%u)"), n);
@ -755,8 +796,13 @@ int AudioKaraoke::SplitSyl (unsigned int n) {
}
//////////////////////////////////
// Apply delta length to syllable
/// @brief Apply delta length to syllable
/// @param n
/// @param delta
/// @param mode
/// @return
///
bool AudioKaraoke::SyllableDelta(int n,int delta,int mode) {
wxLogDebug(_T("AudioKaraoke::SyllableDelta(n=%d, delta=%d, mode=%d)"), n, delta, mode);
// Get syllable and next
@ -806,8 +852,10 @@ bool AudioKaraoke::SyllableDelta(int n,int delta,int mode) {
}
////////////////////////////////
// Karaoke tag menu constructor
/// @brief Karaoke tag menu constructor
/// @param _kara
///
AudioKaraokeTagMenu::AudioKaraokeTagMenu(AudioKaraoke *_kara)
: wxMenu(_("Karaoke tag"))
, kara(_kara)
@ -833,8 +881,9 @@ AudioKaraokeTagMenu::AudioKaraokeTagMenu(AudioKaraoke *_kara)
}
///////////////////////////////
// Karaoke tag menu destructor
/// @brief Karaoke tag menu destructor
///
AudioKaraokeTagMenu::~AudioKaraokeTagMenu() {
}
@ -846,8 +895,10 @@ BEGIN_EVENT_TABLE(AudioKaraokeTagMenu,wxMenu)
END_EVENT_TABLE()
//////////////////////////////////
// Karaoke tag menu event handler
/// @brief Karaoke tag menu event handler
/// @param event
///
void AudioKaraokeTagMenu::OnSelectItem(wxCommandEvent &event) {
// Select the new tag for the syllables
wxString newtag;
@ -881,3 +932,4 @@ void AudioKaraokeTagMenu::OnSelectItem(wxCommandEvent &event) {

View file

@ -36,6 +36,8 @@
#ifndef AUDIO_KARAOKE_H
/// DOCME
#define AUDIO_KARAOKE_H
@ -59,32 +61,60 @@ class AudioDisplay;
class AudioBox;
class AudioKaraokeTagMenu;
///////////////////////////////////
// Karaoke syllable with more info
/// DOCME
struct AudioKaraokeSyllable : AssKaraokeSyllable {
/// DOCME
int start_time; // centiseconds
/// DOCME
bool selected;
/// DOCME
std::vector<int> pending_splits;
/// DOCME
int display_w;
/// DOCME
int display_x;
AudioKaraokeSyllable();
AudioKaraokeSyllable(const AssKaraokeSyllable &base);
};
/// DOCME
typedef std::vector<AudioKaraokeSyllable> AudioKaraokeVector;
/////////
// Class
/// DOCME
/// @class AudioKaraoke
/// @brief DOCME
///
/// DOCME
class AudioKaraoke : public wxWindow {
friend class AudioKaraokeTagMenu;
private:
/// DOCME
AssDialogue *diag;
/// DOCME
AssDialogue *workDiag;
/// DOCME
int startClickSyl;
/// DOCME
bool must_rebuild;
/// DOCME
int split_cursor_syl;
/// DOCME
int split_cursor_x;
void AutoSplit();
@ -98,13 +128,27 @@ private:
void OnMouse(wxMouseEvent &event);
public:
/// DOCME
AudioDisplay *display;
/// DOCME
AudioBox *box;
/// DOCME
int curSyllable;
/// DOCME
int selectionCount;
/// DOCME
bool enabled;
/// DOCME
bool splitting;
/// DOCME
AudioKaraokeVector syllables;
AudioKaraoke(wxWindow *parent);
@ -124,10 +168,16 @@ public:
};
///////////////
// Helper menu
/// DOCME
/// @class AudioKaraokeTagMenu
/// @brief DOCME
///
/// DOCME
class AudioKaraokeTagMenu : public wxMenu {
private:
/// DOCME
AudioKaraoke *kara;
void OnSelectItem(wxCommandEvent &event);
@ -141,3 +191,4 @@ public:
#endif

View file

@ -60,16 +60,18 @@
#endif
///////////////
// Constructor
/// @brief Constructor
///
AudioPlayer::AudioPlayer() {
provider = NULL;
displayTimer = NULL;
}
//////////////
// Destructor
/// @brief Destructor
///
AudioPlayer::~AudioPlayer() {
if (displayTimer) {
displayTimer->Stop();
@ -78,36 +80,45 @@ AudioPlayer::~AudioPlayer() {
}
////////////////
// Set provider
/// @brief Set provider
/// @param _provider
///
void AudioPlayer::SetProvider(AudioProvider *_provider) {
provider = _provider;
}
////////////////
// Get provider
/// @brief Get provider
/// @return
///
AudioProvider *AudioPlayer::GetProvider() {
return provider;
}
/////////////
// Get mutex
/// @brief Get mutex
/// @return
///
wxMutex *AudioPlayer::GetMutex() {
return NULL;
}
/////////////
// Set timer
/// @brief Set timer
/// @param timer
///
void AudioPlayer::SetDisplayTimer(wxTimer *timer) {
displayTimer = timer;
}
/////////////////////
// Ask to stop later
/// @brief Ask to stop later
///
void AudioPlayer::RequestStop() {
wxCommandEvent event(wxEVT_STOP_AUDIO, 1000);
event.SetEventObject(this);
@ -123,13 +134,19 @@ BEGIN_EVENT_TABLE(AudioPlayer, wxEvtHandler)
EVT_COMMAND (1000, wxEVT_STOP_AUDIO, AudioPlayer::OnStopAudio)
END_EVENT_TABLE()
/// @brief DOCME
/// @param event
///
void AudioPlayer::OnStopAudio(wxCommandEvent &event) {
Stop(false);
}
//////////////
// Get player
/// @brief Get player
/// @return
///
AudioPlayer* AudioPlayerFactoryManager::GetAudioPlayer() {
// List of providers
wxArrayString list = GetFactoryList(Options.AsText(_T("Audio player")));
@ -154,8 +171,9 @@ AudioPlayer* AudioPlayerFactoryManager::GetAudioPlayer() {
}
//////////////////////////
// Register all factories
/// @brief Register all factories
///
void AudioPlayerFactoryManager::RegisterProviders() {
#ifdef WITH_ALSA
RegisterFactory(new AlsaPlayerFactory(),_T("ALSA"));
@ -176,15 +194,17 @@ void AudioPlayerFactoryManager::RegisterProviders() {
}
///////////////////////
// Clear all factories
/// @brief Clear all factories
///
void AudioPlayerFactoryManager::ClearProviders() {
ClearFactories();
}
//////////
// Static
/// DOCME
template <class AudioPlayerFactory> std::map<wxString,AudioPlayerFactory*>* FactoryManager<AudioPlayerFactory>::factories=NULL;

View file

@ -52,8 +52,9 @@
#include "options.h"
///////////////
// Constructor
/// @brief Constructor
///
AlsaPlayer::AlsaPlayer()
{
volume = 1.0f;
@ -64,16 +65,18 @@ AlsaPlayer::AlsaPlayer()
}
//////////////
// Destructor
/// @brief Destructor
///
AlsaPlayer::~AlsaPlayer()
{
CloseStream();
}
///////////////
// Open stream
/// @brief Open stream
///
void AlsaPlayer::OpenStream()
{
CloseStream();
@ -102,6 +105,9 @@ void AlsaPlayer::OpenStream()
}
/// @brief DOCME
///
void AlsaPlayer::SetUpHardware()
{
int dir;
@ -195,6 +201,9 @@ void AlsaPlayer::SetUpHardware()
}
/// @brief DOCME
///
void AlsaPlayer::SetUpAsync()
{
// Prepare software params struct
@ -231,8 +240,10 @@ void AlsaPlayer::SetUpAsync()
}
////////////////
// Close stream
/// @brief Close stream
/// @return
///
void AlsaPlayer::CloseStream()
{
if (!open) return;
@ -250,8 +261,11 @@ void AlsaPlayer::CloseStream()
}
////////
// Play
/// @brief Play
/// @param start
/// @param count
///
void AlsaPlayer::Play(int64_t start,int64_t count)
{
if (playing) {
@ -278,8 +292,11 @@ void AlsaPlayer::Play(int64_t start,int64_t count)
}
////////
// Stop
/// @brief Stop
/// @param timerToo
/// @return
///
void AlsaPlayer::Stop(bool timerToo)
{
if (!open) return;
@ -300,42 +317,60 @@ void AlsaPlayer::Stop(bool timerToo)
}
/// @brief DOCME
/// @return
///
bool AlsaPlayer::IsPlaying()
{
return playing;
}
///////////
// Set end
/// @brief Set end
/// @param pos
///
void AlsaPlayer::SetEndPosition(int64_t pos)
{
end_frame = pos;
}
////////////////////////
// Set current position
/// @brief Set current position
/// @param pos
///
void AlsaPlayer::SetCurrentPosition(int64_t pos)
{
cur_frame = pos;
}
/// @brief DOCME
/// @return
///
int64_t AlsaPlayer::GetStartPosition()
{
return start_frame;
}
/// @brief DOCME
/// @return
///
int64_t AlsaPlayer::GetEndPosition()
{
return end_frame;
}
////////////////////////
// Get current position
/// @brief Get current position
/// @return
///
int64_t AlsaPlayer::GetCurrentPosition()
{
// FIXME: this should be based on not duration played but actual sample being heard
@ -346,6 +381,10 @@ int64_t AlsaPlayer::GetCurrentPosition()
}
/// @brief DOCME
/// @param pcm_callback
///
void AlsaPlayer::async_write_handler(snd_async_handler_t *pcm_callback)
{
// TODO: check for broken pipes in here and restore as needed
@ -393,3 +432,4 @@ void AlsaPlayer::async_write_handler(snd_async_handler_t *pcm_callback)
#endif // WITH_ALSA

View file

@ -50,30 +50,70 @@
#include "options.h"
///////////////
// Alsa player
/// DOCME
/// @class AlsaPlayer
/// @brief DOCME
///
/// DOCME
class AlsaPlayer : public AudioPlayer {
private:
/// DOCME
bool open;
/// DOCME
volatile bool playing;
/// DOCME
volatile float volume;
/// DOCME
volatile unsigned long start_frame; // first frame of playback
/// DOCME
volatile unsigned long cur_frame; // last written frame + 1
/// DOCME
volatile unsigned long end_frame; // last frame to play
/// DOCME
unsigned long bpf; // bytes per frame
/// DOCME
AudioProvider *provider;
/// DOCME
snd_pcm_t *pcm_handle; // device handle
/// DOCME
snd_pcm_stream_t stream; // stream direction
/// DOCME
snd_async_handler_t *pcm_callback;
/// DOCME
snd_pcm_format_t sample_format;
/// DOCME
unsigned int rate; // sample rate of audio
/// DOCME
unsigned int real_rate; // actual sample rate played back
/// DOCME
unsigned int period_len; // length of period in microseconds
/// DOCME
unsigned int buflen; // length of buffer in microseconds
/// DOCME
snd_pcm_uframes_t period; // size of period in frames
/// DOCME
snd_pcm_uframes_t bufsize; // size of buffer in frames
void SetUpHardware();
@ -98,18 +138,35 @@ public:
void SetEndPosition(int64_t pos);
void SetCurrentPosition(int64_t pos);
/// @brief DOCME
/// @param vol
/// @return
///
void SetVolume(double vol) { volume = vol; }
/// @brief DOCME
/// @return
///
double GetVolume() { return volume; }
};
///////////
// Factory
/// DOCME
/// @class AlsaPlayerFactory
/// @brief DOCME
///
/// DOCME
class AlsaPlayerFactory : public AudioPlayerFactory {
public:
/// @brief DOCME
///
AudioPlayer *CreatePlayer() { return new AlsaPlayer(); }
};
#endif

View file

@ -48,8 +48,9 @@
#include "audio_player_dsound.h"
///////////////
// Constructor
/// @brief Constructor
///
DirectSoundPlayer::DirectSoundPlayer() {
playing = false;
volume = 1.0f;
@ -64,15 +65,17 @@ DirectSoundPlayer::DirectSoundPlayer() {
}
//////////////
// Destructor
/// @brief Destructor
///
DirectSoundPlayer::~DirectSoundPlayer() {
CloseStream();
}
///////////////
// Open stream
/// @brief Open stream
///
void DirectSoundPlayer::OpenStream() {
// Get provider
AudioProvider *provider = GetProvider();
@ -123,8 +126,9 @@ void DirectSoundPlayer::OpenStream() {
}
////////////////
// Close stream
/// @brief Close stream
///
void DirectSoundPlayer::CloseStream() {
// Stop it
Stop();
@ -143,8 +147,11 @@ void DirectSoundPlayer::CloseStream() {
}
///////////////
// Fill buffer
/// @brief Fill buffer
/// @param fill
/// @return
///
bool DirectSoundPlayer::FillBuffer(bool fill) {
if (playPos >= endPos) return false;
@ -231,8 +238,11 @@ RetryLock:
}
////////
// Play
/// @brief Play
/// @param start
/// @param count
///
void DirectSoundPlayer::Play(int64_t start,int64_t count) {
// Make sure that it's stopped
Stop();
@ -272,8 +282,10 @@ void DirectSoundPlayer::Play(int64_t start,int64_t count) {
}
////////
// Stop
/// @brief Stop
/// @param timerToo
///
void DirectSoundPlayer::Stop(bool timerToo) {
// Stop the thread
if (thread) {
@ -302,23 +314,29 @@ void DirectSoundPlayer::Stop(bool timerToo) {
}
///////////
// Set end
/// @brief Set end
/// @param pos
///
void DirectSoundPlayer::SetEndPosition(int64_t pos) {
if (playing) endPos = pos;
}
////////////////////////
// Set current position
/// @brief Set current position
/// @param pos
///
void DirectSoundPlayer::SetCurrentPosition(int64_t pos) {
startPos = playPos = pos;
startTime = GetTickCount();
}
////////////////////////
// Get current position
/// @brief Get current position
/// @return
///
int64_t DirectSoundPlayer::GetCurrentPosition() {
// Check if buffer is loaded
if (!buffer || !playing) return 0;
@ -331,23 +349,28 @@ int64_t DirectSoundPlayer::GetCurrentPosition() {
}
//////////////////////
// Thread constructor
/// @brief Thread constructor
/// @param par
///
DirectSoundPlayerThread::DirectSoundPlayerThread(DirectSoundPlayer *par) : wxThread(wxTHREAD_JOINABLE) {
parent = par;
stopnotify = CreateEvent(NULL, true, false, NULL);
}
/////////////////////
// Thread destructor
/// @brief Thread destructor
///
DirectSoundPlayerThread::~DirectSoundPlayerThread() {
CloseHandle(stopnotify);
}
//////////////////////
// Thread entry point
/// @brief Thread entry point
/// @return
///
wxThread::ExitCode DirectSoundPlayerThread::Entry() {
CoInitialize(0);
@ -396,8 +419,9 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() {
}
////////////////////////
// Stop playback thread
/// @brief Stop playback thread
///
void DirectSoundPlayerThread::Stop() {
// Increase the stopnotify by one, causing a wait for it to succeed
SetEvent(stopnotify);
@ -405,3 +429,4 @@ void DirectSoundPlayerThread::Stop() {
#endif // WITH_DIRECTSOUND

View file

@ -54,11 +54,19 @@
class DirectSoundPlayer;
//////////
// Thread
/// DOCME
/// @class DirectSoundPlayerThread
/// @brief DOCME
///
/// DOCME
class DirectSoundPlayerThread : public wxThread {
private:
/// DOCME
DirectSoundPlayer *parent;
/// DOCME
HANDLE stopnotify;
public:
@ -85,27 +93,53 @@ All but GetPosition() set appropriate fields and then raise the parameters chang
*/
////////////////////
// Portaudio player
/// DOCME
/// @class DirectSoundPlayer
/// @brief DOCME
///
/// DOCME
class DirectSoundPlayer : public AudioPlayer {
friend class DirectSoundPlayerThread;
private:
/// DOCME
volatile bool playing;
/// DOCME
float volume;
/// DOCME
int offset;
/// DOCME
DWORD bufSize;
/// DOCME
volatile int64_t playPos;
/// DOCME
int64_t startPos;
/// DOCME
volatile int64_t endPos;
/// DOCME
DWORD startTime;
/// DOCME
IDirectSound8 *directSound;
/// DOCME
IDirectSoundBuffer8 *buffer;
bool FillBuffer(bool fill);
/// DOCME
DirectSoundPlayerThread *thread;
public:
@ -117,27 +151,56 @@ public:
void Play(int64_t start,int64_t count);
void Stop(bool timerToo=true);
/// @brief DOCME
/// @return
///
bool IsPlaying() { return playing; }
/// @brief DOCME
/// @return
///
int64_t GetStartPosition() { return startPos; }
/// @brief DOCME
/// @return
///
int64_t GetEndPosition() { return endPos; }
int64_t GetCurrentPosition();
void SetEndPosition(int64_t pos);
void SetCurrentPosition(int64_t pos);
/// @brief DOCME
/// @param vol
/// @return
///
void SetVolume(double vol) { volume = vol; }
/// @brief DOCME
/// @return
///
double GetVolume() { return volume; }
//wxMutex *GetMutex() { return &DSMutex; }
};
///////////
// Factory
/// DOCME
/// @class DirectSoundPlayerFactory
/// @brief DOCME
///
/// DOCME
class DirectSoundPlayerFactory : public AudioPlayerFactory {
public:
/// @brief DOCME
///
AudioPlayer *CreatePlayer() { return new DirectSoundPlayer(); }
};
#endif

View file

@ -53,19 +53,32 @@
#include "audio_player_dsound2.h"
/// DOCME
struct COMInitialization {
/// DOCME
bool inited;
/// @brief DOCME
///
COMInitialization()
{
inited = false;
}
/// @brief DOCME
///
~COMInitialization()
{
if (inited) CoUninitialize();
}
/// @brief DOCME
///
void Init()
{
if (!inited)
@ -79,24 +92,42 @@ struct COMInitialization {
template<class T>
/// DOCME
struct COMObjectRetainer {
/// DOCME
T *obj;
/// @brief DOCME
///
COMObjectRetainer()
{
obj = 0;
}
/// @brief DOCME
/// @param _obj
///
COMObjectRetainer(T *_obj)
{
obj = _obj;
}
/// @brief DOCME
///
~COMObjectRetainer()
{
if (obj) obj->Release();
}
/// @brief DOCME
/// @return
///
T * operator -> ()
{
return obj;
@ -104,6 +135,12 @@ struct COMObjectRetainer {
};
/// DOCME
/// @class DirectSoundPlayer2Thread
/// @brief DOCME
///
/// DOCME
class DirectSoundPlayer2Thread {
static unsigned int __stdcall ThreadProc(void *parameter);
void Run();
@ -112,32 +149,66 @@ class DirectSoundPlayer2Thread {
void CheckError();
/// DOCME
HANDLE thread_handle;
// Used to signal state-changes to thread
HANDLE
/// DOCME
event_start_playback,
/// DOCME
event_stop_playback,
/// DOCME
event_update_end_time,
/// DOCME
event_set_volume,
/// DOCME
event_kill_self;
// Thread communicating back
HANDLE
/// DOCME
thread_running,
/// DOCME
is_playing,
/// DOCME
error_happened;
/// DOCME
wxChar *error_message;
/// DOCME
double volume;
/// DOCME
int64_t start_frame;
/// DOCME
int64_t end_frame;
/// DOCME
int wanted_latency;
/// DOCME
int buffer_length;
/// DOCME
DWORD last_playback_restart;
/// DOCME
AudioProvider *provider;
public:
@ -158,6 +229,11 @@ public:
};
/// @brief DOCME
/// @param parameter
/// @return
///
unsigned int __stdcall DirectSoundPlayer2Thread::ThreadProc(void *parameter)
{
static_cast<DirectSoundPlayer2Thread*>(parameter)->Run();
@ -165,8 +241,14 @@ unsigned int __stdcall DirectSoundPlayer2Thread::ThreadProc(void *parameter)
}
/// @brief DOCME
/// @return
///
void DirectSoundPlayer2Thread::Run()
{
/// DOCME
#define REPORT_ERROR(msg) { error_message = _T("DirectSoundPlayer2Thread: ") _T(msg); SetEvent(error_happened); return; }
COMInitialization COM_library;
@ -433,10 +515,22 @@ void DirectSoundPlayer2Thread::Run()
}
}
/// DOCME
#undef REPORT_ERROR
}
/// @brief DOCME
/// @param buf1
/// @param buf1sz
/// @param buf2
/// @param buf2sz
/// @param input_frame
/// @param bfr
/// @return
///
DWORD DirectSoundPlayer2Thread::FillAndUnlockBuffers(void *buf1, DWORD buf1sz, void *buf2, DWORD buf2sz, int64_t &input_frame, IDirectSoundBuffer8 *bfr)
{
// Assume buffers have been locked and are ready to be filled
@ -496,6 +590,10 @@ DWORD DirectSoundPlayer2Thread::FillAndUnlockBuffers(void *buf1, DWORD buf1sz, v
}
/// @brief DOCME
/// @return
///
void DirectSoundPlayer2Thread::CheckError()
{
try
@ -525,6 +623,12 @@ void DirectSoundPlayer2Thread::CheckError()
}
/// @brief DOCME
/// @param provider
/// @param _WantedLatency
/// @param _BufferLength
///
DirectSoundPlayer2Thread::DirectSoundPlayer2Thread(AudioProvider *provider, int _WantedLatency, int _BufferLength)
{
event_start_playback = CreateEvent(0, FALSE, FALSE, 0);
@ -558,6 +662,9 @@ DirectSoundPlayer2Thread::DirectSoundPlayer2Thread(AudioProvider *provider, int
}
/// @brief DOCME
///
DirectSoundPlayer2Thread::~DirectSoundPlayer2Thread()
{
SetEvent(event_kill_self);
@ -565,6 +672,11 @@ DirectSoundPlayer2Thread::~DirectSoundPlayer2Thread()
}
/// @brief DOCME
/// @param start
/// @param count
///
void DirectSoundPlayer2Thread::Play(int64_t start, int64_t count)
{
CheckError();
@ -577,6 +689,9 @@ void DirectSoundPlayer2Thread::Play(int64_t start, int64_t count)
}
/// @brief DOCME
///
void DirectSoundPlayer2Thread::Stop()
{
CheckError();
@ -585,6 +700,10 @@ void DirectSoundPlayer2Thread::Stop()
}
/// @brief DOCME
/// @param new_end_frame
///
void DirectSoundPlayer2Thread::SetEndFrame(int64_t new_end_frame)
{
CheckError();
@ -594,6 +713,10 @@ void DirectSoundPlayer2Thread::SetEndFrame(int64_t new_end_frame)
}
/// @brief DOCME
/// @param new_volume
///
void DirectSoundPlayer2Thread::SetVolume(double new_volume)
{
CheckError();
@ -603,6 +726,10 @@ void DirectSoundPlayer2Thread::SetVolume(double new_volume)
}
/// @brief DOCME
/// @return
///
bool DirectSoundPlayer2Thread::IsPlaying()
{
CheckError();
@ -625,6 +752,10 @@ bool DirectSoundPlayer2Thread::IsPlaying()
}
/// @brief DOCME
/// @return
///
int64_t DirectSoundPlayer2Thread::GetStartFrame()
{
CheckError();
@ -633,6 +764,10 @@ int64_t DirectSoundPlayer2Thread::GetStartFrame()
}
/// @brief DOCME
/// @return
///
int64_t DirectSoundPlayer2Thread::GetCurrentFrame()
{
CheckError();
@ -645,6 +780,10 @@ int64_t DirectSoundPlayer2Thread::GetCurrentFrame()
}
/// @brief DOCME
/// @return
///
int64_t DirectSoundPlayer2Thread::GetEndFrame()
{
CheckError();
@ -653,6 +792,10 @@ int64_t DirectSoundPlayer2Thread::GetEndFrame()
}
/// @brief DOCME
/// @return
///
double DirectSoundPlayer2Thread::GetVolume()
{
CheckError();
@ -661,6 +804,10 @@ double DirectSoundPlayer2Thread::GetVolume()
}
/// @brief DOCME
/// @return
///
bool DirectSoundPlayer2Thread::IsDead()
{
switch (WaitForSingleObject(thread_running, 0))
@ -676,6 +823,9 @@ bool DirectSoundPlayer2Thread::IsDead()
/// @brief DOCME
///
DirectSoundPlayer2::DirectSoundPlayer2()
{
thread = 0;
@ -692,12 +842,19 @@ DirectSoundPlayer2::DirectSoundPlayer2()
}
/// @brief DOCME
///
DirectSoundPlayer2::~DirectSoundPlayer2()
{
CloseStream();
}
/// @brief DOCME
/// @return
///
bool DirectSoundPlayer2::IsThreadAlive()
{
if (!thread) return false;
@ -713,6 +870,10 @@ bool DirectSoundPlayer2::IsThreadAlive()
}
/// @brief DOCME
/// @return
///
void DirectSoundPlayer2::OpenStream()
{
if (IsThreadAlive()) return;
@ -729,6 +890,10 @@ void DirectSoundPlayer2::OpenStream()
}
/// @brief DOCME
/// @return
///
void DirectSoundPlayer2::CloseStream()
{
if (!IsThreadAlive()) return;
@ -745,6 +910,10 @@ void DirectSoundPlayer2::CloseStream()
}
/// @brief DOCME
/// @param provider
///
void DirectSoundPlayer2::SetProvider(AudioProvider *provider)
{
try
@ -764,6 +933,11 @@ void DirectSoundPlayer2::SetProvider(AudioProvider *provider)
}
/// @brief DOCME
/// @param start
/// @param count
///
void DirectSoundPlayer2::Play(int64_t start,int64_t count)
{
try
@ -780,6 +954,10 @@ void DirectSoundPlayer2::Play(int64_t start,int64_t count)
}
/// @brief DOCME
/// @param timerToo
///
void DirectSoundPlayer2::Stop(bool timerToo)
{
try
@ -797,6 +975,10 @@ void DirectSoundPlayer2::Stop(bool timerToo)
}
/// @brief DOCME
/// @return
///
bool DirectSoundPlayer2::IsPlaying()
{
try
@ -812,6 +994,10 @@ bool DirectSoundPlayer2::IsPlaying()
}
/// @brief DOCME
/// @return
///
int64_t DirectSoundPlayer2::GetStartPosition()
{
try
@ -827,6 +1013,10 @@ int64_t DirectSoundPlayer2::GetStartPosition()
}
/// @brief DOCME
/// @return
///
int64_t DirectSoundPlayer2::GetEndPosition()
{
try
@ -842,6 +1032,10 @@ int64_t DirectSoundPlayer2::GetEndPosition()
}
/// @brief DOCME
/// @return
///
int64_t DirectSoundPlayer2::GetCurrentPosition()
{
try
@ -857,6 +1051,10 @@ int64_t DirectSoundPlayer2::GetCurrentPosition()
}
/// @brief DOCME
/// @param pos
///
void DirectSoundPlayer2::SetEndPosition(int64_t pos)
{
try
@ -870,6 +1068,10 @@ void DirectSoundPlayer2::SetEndPosition(int64_t pos)
}
/// @brief DOCME
/// @param pos
///
void DirectSoundPlayer2::SetCurrentPosition(int64_t pos)
{
try
@ -883,6 +1085,10 @@ void DirectSoundPlayer2::SetCurrentPosition(int64_t pos)
}
/// @brief DOCME
/// @param vol
///
void DirectSoundPlayer2::SetVolume(double vol)
{
try
@ -896,6 +1102,9 @@ void DirectSoundPlayer2::SetVolume(double vol)
}
/// @brief DOCME
///
double DirectSoundPlayer2::GetVolume()
{
try
@ -913,3 +1122,4 @@ double DirectSoundPlayer2::GetVolume()
#endif // WITH_DIRECTSOUND

View file

@ -43,11 +43,23 @@
class DirectSoundPlayer2Thread;
/// DOCME
/// @class DirectSoundPlayer2
/// @brief DOCME
///
/// DOCME
class DirectSoundPlayer2 : public AudioPlayer {
/// DOCME
DirectSoundPlayer2Thread *thread;
protected:
/// DOCME
int WantedLatency;
/// DOCME
int BufferLength;
bool IsThreadAlive();
@ -76,10 +88,20 @@ public:
};
/// DOCME
/// @class DirectSoundPlayer2Factory
/// @brief DOCME
///
/// DOCME
class DirectSoundPlayer2Factory : public AudioPlayerFactory {
public:
/// @brief DOCME
///
AudioPlayer *CreatePlayer() { return new DirectSoundPlayer2(); }
};
#endif

View file

@ -54,8 +54,12 @@
class AudioProvider;
///////////////////
// Factory Manager
/// DOCME
/// @class AudioPlayerFactoryManager
/// @brief DOCME
///
/// DOCME
class AudioPlayerFactoryManager : public FactoryManager<AudioPlayerFactory> {
public:
static AudioPlayer *GetAudioPlayer();
@ -71,3 +75,4 @@ DECLARE_EVENT_TYPE(wxEVT_STOP_AUDIO, -1)

View file

@ -69,8 +69,9 @@
#endif
///////////////
// Constructor
/// @brief Constructor
///
OpenALPlayer::OpenALPlayer()
{
volume = 1.0f;
@ -81,16 +82,18 @@ OpenALPlayer::OpenALPlayer()
}
//////////////
// Destructor
/// @brief Destructor
///
OpenALPlayer::~OpenALPlayer()
{
CloseStream();
}
///////////////
// Open stream
/// @brief Open stream
///
void OpenALPlayer::OpenStream()
{
CloseStream();
@ -145,8 +148,10 @@ void OpenALPlayer::OpenStream()
}
////////////////
// Close stream
/// @brief Close stream
/// @return
///
void OpenALPlayer::CloseStream()
{
if (!open) return;
@ -163,8 +168,11 @@ void OpenALPlayer::CloseStream()
}
////////
// Play
/// @brief Play
/// @param start
/// @param count
///
void OpenALPlayer::Play(int64_t start,int64_t count)
{
if (playing) {
@ -197,8 +205,11 @@ void OpenALPlayer::Play(int64_t start,int64_t count)
}
////////
// Stop
/// @brief Stop
/// @param timerToo
/// @return
///
void OpenALPlayer::Stop(bool timerToo)
{
if (!open) return;
@ -221,6 +232,10 @@ void OpenALPlayer::Stop(bool timerToo)
}
/// @brief DOCME
/// @param count
///
void OpenALPlayer::FillBuffers(ALsizei count)
{
wxLogDebug(_T("FillBuffers: count=%d, buffers_free=%d"), count, buffers_free);
@ -259,6 +274,9 @@ void OpenALPlayer::FillBuffers(ALsizei count)
}
/// @brief DOCME
///
void OpenALPlayer::Notify()
{
ALsizei newplayed;
@ -295,42 +313,59 @@ void OpenALPlayer::Notify()
}
/// @brief DOCME
/// @return
///
bool OpenALPlayer::IsPlaying()
{
return playing;
}
///////////
// Set end
/// @brief Set end
/// @param pos
///
void OpenALPlayer::SetEndPosition(int64_t pos)
{
end_frame = pos;
}
////////////////////////
// Set current position
/// @brief Set current position
/// @param pos
///
void OpenALPlayer::SetCurrentPosition(int64_t pos)
{
cur_frame = pos;
}
/// @brief DOCME
/// @return
///
int64_t OpenALPlayer::GetStartPosition()
{
return start_frame;
}
/// @brief DOCME
/// @return
///
int64_t OpenALPlayer::GetEndPosition()
{
return end_frame;
}
////////////////////////
// Get current position
/// @brief Get current position
///
int64_t OpenALPlayer::GetCurrentPosition()
{
// FIXME: this should be based on not duration played but actual sample being heard
@ -343,3 +378,4 @@ int64_t OpenALPlayer::GetCurrentPosition()
#endif // WITH_OPENAL

View file

@ -61,33 +61,77 @@
#endif
/////////////////
// OpenAL player
/// DOCME
/// @class OpenALPlayer
/// @brief DOCME
///
/// DOCME
class OpenALPlayer : public AudioPlayer, wxTimer {
private:
/// DOCME
bool open;
/// DOCME
volatile bool playing;
/// DOCME
volatile float volume;
/// DOCME
static const ALsizei num_buffers = 8;
/// DOCME
ALsizei buffer_length;
/// DOCME
ALsizei samplerate;
/// DOCME
volatile unsigned long start_frame; // first frame of playback
/// DOCME
volatile unsigned long cur_frame; // last written frame + 1
/// DOCME
volatile unsigned long end_frame; // last frame to play
/// DOCME
unsigned long bpf; // bytes per frame
/// DOCME
AudioProvider *provider;
/// DOCME
ALCdevice *device; // device handle
/// DOCME
ALCcontext *context; // sound context
/// DOCME
ALuint buffers[num_buffers]; // sound buffers
/// DOCME
ALuint source; // playback source
/// DOCME
ALsizei buf_first_free; // index into buffers, first free (unqueued) buffer
/// DOCME
ALsizei buf_first_queued; // index into buffers, first queued (non-free) buffer
/// DOCME
ALsizei buffers_free; // number of free buffers
/// DOCME
ALsizei buffers_played;
/// DOCME
wxStopWatch playback_segment_timer;
void FillBuffers(ALsizei count);
@ -112,18 +156,35 @@ public:
void SetEndPosition(int64_t pos);
void SetCurrentPosition(int64_t pos);
/// @brief DOCME
/// @param vol
/// @return
///
void SetVolume(double vol) { volume = vol; }
/// @brief DOCME
/// @return
///
double GetVolume() { return volume; }
};
///////////
// Factory
/// DOCME
/// @class OpenALPlayerFactory
/// @brief DOCME
///
/// DOCME
class OpenALPlayerFactory : public AudioPlayerFactory {
public:
/// @brief DOCME
///
AudioPlayer *CreatePlayer() { return new OpenALPlayer(); }
};
#endif

View file

@ -51,13 +51,14 @@
// Uncomment to enable debug features.
//#define PORTAUDIO_DEBUG
/////////////////////
// Reference counter
/// DOCME
int PortAudioPlayer::pa_refcount = 0;
///////////////
// Constructor
/// @brief Constructor
///
PortAudioPlayer::PortAudioPlayer() {
// Initialize portaudio
if (!pa_refcount) {
@ -80,16 +81,18 @@ PortAudioPlayer::PortAudioPlayer() {
}
//////////////
// Destructor
/// @brief Destructor
///
PortAudioPlayer::~PortAudioPlayer() {
// Deinit portaudio
if (!--pa_refcount) Pa_Terminate();
}
///////////////
// Open stream
/// @brief Open stream
///
void PortAudioPlayer::OpenStream() {
// Open stream
PaStreamParameters pa_output_p;
@ -127,8 +130,9 @@ void PortAudioPlayer::OpenStream() {
}
///////////////
// Close stream
/// @brief Close stream
///
void PortAudioPlayer::CloseStream() {
try {
Stop(false);
@ -136,7 +140,10 @@ void PortAudioPlayer::CloseStream() {
} catch (...) {}
}
// Called when the callback has finished.
/// @brief Called when the callback has finished.
/// @param userData
///
void PortAudioPlayer::paStreamFinishedCallback(void *userData) {
PortAudioPlayer *player = (PortAudioPlayer *) userData;
@ -150,8 +157,12 @@ void PortAudioPlayer::paStreamFinishedCallback(void *userData) {
}
////////
// Play
/// @brief Play
/// @param start
/// @param count
/// @return
///
void PortAudioPlayer::Play(int64_t start,int64_t count) {
PaError err;
@ -187,8 +198,10 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) {
}
////////
// Stop
/// @brief Stop
/// @param timerToo
///
void PortAudioPlayer::Stop(bool timerToo) {
//wxMutexLocker locker(PAMutex);
//softStop = false;
@ -204,8 +217,16 @@ void PortAudioPlayer::Stop(bool timerToo) {
}
//////////////////////
/// PortAudio callback
/// @brief PortAudio callback
/// @param inputBuffer
/// @param outputBuffer
/// @param framesPerBuffer
/// @param timeInfo
/// @param statusFlags
/// @param userData
/// @return
///
int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData) {
// Get provider
@ -238,8 +259,10 @@ int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, uns
}
////////////////////////
/// Get current stream position.
/// @brief Get current stream position.
/// @return
///
int64_t PortAudioPlayer::GetCurrentPosition()
{
@ -261,9 +284,10 @@ int64_t PortAudioPlayer::GetCurrentPosition()
}
///////////////
/// Return a list of available output devices.
/// @param Setting from config file.
/// @brief @param Setting from config file. Return a list of available output devices.
/// @param favorite
///
wxArrayString PortAudioPlayer::GetOutputDevices(wxString favorite) {
wxArrayString list;
int devices = Pa_GetDeviceCount();
@ -284,3 +308,4 @@ wxArrayString PortAudioPlayer::GetOutputDevices(wxString favorite) {
#endif // WITH_PORTAUDIO

View file

@ -49,21 +49,44 @@ extern "C" {
////////////////////
// Portaudio player
/// DOCME
/// @class PortAudioPlayer
/// @brief DOCME
///
/// DOCME
class PortAudioPlayer : public AudioPlayer {
private:
/// DOCME
static int pa_refcount;
/// DOCME
wxMutex PAMutex;
/// DOCME
volatile bool stopping;
//bool softStop;
/// DOCME
bool playing;
/// DOCME
float volume;
/// DOCME
volatile int64_t playPos;
/// DOCME
volatile int64_t startPos;
/// DOCME
volatile int64_t endPos;
/// DOCME
void *stream;
/// DOCME
PaTime paStart;
static int paCallback(
@ -87,28 +110,69 @@ public:
void Play(int64_t start,int64_t count);
void Stop(bool timerToo=true);
/// @brief DOCME
/// @return
///
bool IsPlaying() { return playing; }
/// @brief DOCME
/// @return
///
int64_t GetStartPosition() { return startPos; }
/// @brief DOCME
/// @return
///
int64_t GetEndPosition() { return endPos; }
int64_t GetCurrentPosition();
/// @brief DOCME
/// @param pos
///
void SetEndPosition(int64_t pos) { endPos = pos; }
/// @brief DOCME
/// @param pos
///
void SetCurrentPosition(int64_t pos) { playPos = pos; }
/// @brief DOCME
/// @param vol
/// @return
///
void SetVolume(double vol) { volume = vol; }
/// @brief DOCME
/// @return
///
double GetVolume() { return volume; }
wxArrayString GetOutputDevices(wxString favorite);
/// @brief DOCME
/// @return
///
wxMutex *GetMutex() { return &PAMutex; }
};
///////////
// Factory
/// DOCME
/// @class PortAudioPlayerFactory
/// @brief DOCME
///
/// DOCME
class PortAudioPlayerFactory : public AudioPlayerFactory {
public:
/// @brief DOCME
///
AudioPlayer *CreatePlayer() { return new PortAudioPlayer(); }
};
#endif //ifdef WITH_PORTAUDIO

View file

@ -50,8 +50,9 @@
#include "options.h"
///////////////
// Constructor
/// @brief Constructor
///
PulseAudioPlayer::PulseAudioPlayer()
: context_notify(0, 1)
, context_success(0, 1)
@ -65,16 +66,18 @@ PulseAudioPlayer::PulseAudioPlayer()
}
//////////////
// Destructor
/// @brief Destructor
///
PulseAudioPlayer::~PulseAudioPlayer()
{
if (open) CloseStream();
}
///////////////
// Open stream
/// @brief Open stream
///
void PulseAudioPlayer::OpenStream()
{
//printf("Opening PulseAudio stream\n");
@ -171,8 +174,10 @@ void PulseAudioPlayer::OpenStream()
}
////////////////
// Close stream
/// @brief Close stream
/// @return
///
void PulseAudioPlayer::CloseStream()
{
if (!open) return;
@ -193,8 +198,11 @@ void PulseAudioPlayer::CloseStream()
}
////////
// Play
/// @brief Play
/// @param start
/// @param count
///
void PulseAudioPlayer::Play(int64_t start,int64_t count)
{
//printf("Starting PulseAudio playback\n");
@ -247,8 +255,11 @@ void PulseAudioPlayer::Play(int64_t start,int64_t count)
}
////////
// Stop
/// @brief Stop
/// @param timerToo
/// @return
///
void PulseAudioPlayer::Stop(bool timerToo)
{
if (!is_playing) return;
@ -281,42 +292,60 @@ void PulseAudioPlayer::Stop(bool timerToo)
}
/// @brief DOCME
/// @return
///
bool PulseAudioPlayer::IsPlaying()
{
return is_playing;
}
///////////
// Set end
/// @brief Set end
/// @param pos
///
void PulseAudioPlayer::SetEndPosition(int64_t pos)
{
end_frame = pos;
}
////////////////////////
// Set current position
/// @brief Set current position
/// @param pos
///
void PulseAudioPlayer::SetCurrentPosition(int64_t pos)
{
cur_frame = pos;
}
/// @brief DOCME
/// @return
///
int64_t PulseAudioPlayer::GetStartPosition()
{
return start_frame;
}
/// @brief DOCME
/// @return
///
int64_t PulseAudioPlayer::GetEndPosition()
{
return end_frame;
}
////////////////////////
// Get current position
/// @brief Get current position
/// @return
///
int64_t PulseAudioPlayer::GetCurrentPosition()
{
if (!is_playing) return 0;
@ -333,7 +362,12 @@ int64_t PulseAudioPlayer::GetCurrentPosition()
}
// Called by PA to notify about contetxt operation completion
/// @brief Called by PA to notify about contetxt operation completion
/// @param c
/// @param success
/// @param thread
///
void PulseAudioPlayer::pa_context_success(pa_context *c, int success, PulseAudioPlayer *thread)
{
thread->context_success_val = success;
@ -341,7 +375,11 @@ void PulseAudioPlayer::pa_context_success(pa_context *c, int success, PulseAudio
}
// Called by PA to notify about other context-related stuff
/// @brief Called by PA to notify about other context-related stuff
/// @param c
/// @param thread
///
void PulseAudioPlayer::pa_context_notify(pa_context *c, PulseAudioPlayer *thread)
{
thread->cstate = pa_context_get_state(thread->context);
@ -349,7 +387,12 @@ void PulseAudioPlayer::pa_context_notify(pa_context *c, PulseAudioPlayer *thread
}
// Called by PA when an operation completes
/// @brief Called by PA when an operation completes
/// @param p
/// @param success
/// @param thread
///
void PulseAudioPlayer::pa_stream_success(pa_stream *p, int success, PulseAudioPlayer *thread)
{
thread->stream_success_val = success;
@ -357,7 +400,13 @@ void PulseAudioPlayer::pa_stream_success(pa_stream *p, int success, PulseAudioPl
}
// Called by PA to request more data (and other things?)
/// @brief Called by PA to request more data (and other things?)
/// @param p
/// @param length
/// @param thread
/// @return
///
void PulseAudioPlayer::pa_stream_write(pa_stream *p, size_t length, PulseAudioPlayer *thread)
{
if (!thread->is_playing) return;
@ -391,7 +440,11 @@ void PulseAudioPlayer::pa_stream_write(pa_stream *p, size_t length, PulseAudioPl
}
// Called by PA to notify about other stuff
/// @brief Called by PA to notify about other stuff
/// @param p
/// @param thread
///
void PulseAudioPlayer::pa_stream_notify(pa_stream *p, PulseAudioPlayer *thread)
{
thread->sstate = pa_stream_get_state(thread->stream);
@ -401,3 +454,4 @@ void PulseAudioPlayer::pa_stream_notify(pa_stream *p, PulseAudioPlayer *thread)
#endif // WITH_PULSEAUDIO

View file

@ -55,35 +55,76 @@ class PulseAudioPlayer;
//////////////////////
// Pulse Audio player
/// DOCME
/// @class PulseAudioPlayer
/// @brief DOCME
///
/// DOCME
class PulseAudioPlayer : public AudioPlayer {
private:
/// DOCME
float volume;
/// DOCME
bool open;
/// DOCME
bool is_playing;
// Audio data info
/// DOCME
volatile unsigned long start_frame;
/// DOCME
volatile unsigned long cur_frame;
/// DOCME
volatile unsigned long end_frame;
/// DOCME
unsigned long bpf; // bytes per frame
// Used for synchronising with async events
/// DOCME
wxSemaphore context_notify;
/// DOCME
wxSemaphore context_success;
/// DOCME
volatile int context_success_val;
/// DOCME
wxSemaphore stream_notify;
/// DOCME
wxSemaphore stream_success;
/// DOCME
volatile int stream_success_val;
// PulseAudio data
/// DOCME
pa_threaded_mainloop *mainloop; // pulseaudio mainloop handle
/// DOCME
pa_context *context; // connection context
/// DOCME
volatile pa_context_state_t cstate;
/// DOCME
pa_stream *stream;
/// DOCME
volatile pa_stream_state_t sstate;
/// DOCME
volatile pa_usec_t play_start_time; // timestamp when playback was started
/// DOCME
int paerror;
// Called by PA to notify about contetxt operation completion
@ -114,18 +155,35 @@ public:
void SetEndPosition(int64_t pos);
void SetCurrentPosition(int64_t pos);
/// @brief DOCME
/// @param vol
/// @return
///
void SetVolume(double vol) { volume = vol; }
/// @brief DOCME
/// @return
///
double GetVolume() { return volume; }
};
///////////
// Factory
/// DOCME
/// @class PulseAudioPlayerFactory
/// @brief DOCME
///
/// DOCME
class PulseAudioPlayerFactory : public AudioPlayerFactory {
public:
/// @brief DOCME
///
AudioPlayer *CreatePlayer() { return new PulseAudioPlayer(); }
};
#endif

View file

@ -58,58 +58,78 @@
#include "audio_display.h"
///////////////
// Constructor
/// @brief Constructor
///
AudioProvider::AudioProvider() {
raw = NULL;
}
//////////////
// Destructor
/// @brief Destructor
///
AudioProvider::~AudioProvider() {
// Clear buffers
delete[] raw;
}
//////////////////////////
// Get number of channels
/// @brief Get number of channels
/// @return
///
int AudioProvider::GetChannels() {
return channels;
}
//////////////////////////
// Get number of samples
/// @brief Get number of samples
/// @return
///
int64_t AudioProvider::GetNumSamples() {
return num_samples;
}
///////////////////
// Get sample rate
/// @brief Get sample rate
/// @return
///
int AudioProvider::GetSampleRate() {
return sample_rate;
}
////////////////////////
// Get bytes per sample
/// @brief Get bytes per sample
/// @return
///
int AudioProvider::GetBytesPerSample() {
return bytes_per_sample;
}
////////////////
// Get filename
/// @brief Get filename
/// @return
///
wxString AudioProvider::GetFilename() {
return filename;
}
////////////////
// Get waveform
/// @brief Get waveform
/// @param min
/// @param peak
/// @param start
/// @param w
/// @param h
/// @param samples
/// @param scale
///
void AudioProvider::GetWaveForm(int *min,int *peak,int64_t start,int w,int h,int samples,float scale) {
// Setup
int channels = GetChannels();
@ -173,8 +193,14 @@ void AudioProvider::GetWaveForm(int *min,int *peak,int64_t start,int w,int h,int
}
/////////////////////////
// Get audio with volume
/// @brief Get audio with volume
/// @param buf
/// @param start
/// @param count
/// @param volume
/// @return
///
void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count, double volume) {
try {
GetAudio(buf,start,count);
@ -204,8 +230,12 @@ void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count,
}
////////////////
// Get provider
/// @brief Get provider
/// @param filename
/// @param cache
/// @return
///
AudioProvider *AudioProviderFactoryManager::GetAudioProvider(wxString filename, int cache) {
// Prepare provider
AudioProvider *provider = NULL;
@ -274,8 +304,9 @@ AudioProvider *AudioProviderFactoryManager::GetAudioProvider(wxString filename,
}
///////////////////////////
// Register all providers
/// @brief Register all providers
///
void AudioProviderFactoryManager::RegisterProviders() {
#ifdef WITH_AVISYNTH
RegisterFactory(new AvisynthAudioProviderFactory(),_T("Avisynth"));
@ -289,14 +320,16 @@ void AudioProviderFactoryManager::RegisterProviders() {
}
///////////////////////
// Clear all providers
/// @brief Clear all providers
///
void AudioProviderFactoryManager::ClearProviders() {
ClearFactories();
}
//////////
// Static
/// DOCME
template <class AudioProviderFactory> std::map<wxString,AudioProviderFactory*>* FactoryManager<AudioProviderFactory>::factories=NULL;

View file

@ -51,8 +51,10 @@
#include "charset_conv.h"
//////////////
// Constructor
/// @brief Constructor
/// @param _filename
///
AvisynthAudioProvider::AvisynthAudioProvider(wxString _filename) {
filename = _filename;
@ -66,23 +68,26 @@ AvisynthAudioProvider::AvisynthAudioProvider(wxString _filename) {
}
//////////////
// Destructor
/// @brief Destructor
///
AvisynthAudioProvider::~AvisynthAudioProvider() {
Unload();
}
////////////////
// Unload audio
/// @brief Unload audio
///
void AvisynthAudioProvider::Unload() {
// Clean up avisynth
clip = NULL;
}
////////////////////////////
// Load audio from avisynth
/// @brief Load audio from avisynth
///
void AvisynthAudioProvider::OpenAVSAudio() {
// Set variables
AVSValue script;
@ -129,8 +134,10 @@ void AvisynthAudioProvider::OpenAVSAudio() {
}
/////////////////////////
// Read from environment
/// @brief Read from environment
/// @param _clip
///
void AvisynthAudioProvider::LoadFromClip(AVSValue _clip) {
// Prepare avisynth
AVSValue script;
@ -171,14 +178,20 @@ void AvisynthAudioProvider::LoadFromClip(AVSValue _clip) {
}
////////////////
// Get filename
/// @brief Get filename
/// @return
///
wxString AvisynthAudioProvider::GetFilename() {
return filename;
}
/////////////
// Get audio
/// @brief Get audio
/// @param buf
/// @param start
/// @param count
///
void AvisynthAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
// Requested beyond the length of audio
if (start+count > num_samples) {
@ -208,3 +221,4 @@ void AvisynthAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
#endif

View file

@ -44,11 +44,19 @@
#include "avisynth_wrap.h"
////////////////////////
// Audio provider class
/// DOCME
/// @class AvisynthAudioProvider
/// @brief DOCME
///
/// DOCME
class AvisynthAudioProvider : public AudioProvider, public AviSynthWrapper {
private:
/// DOCME
wxString filename;
/// DOCME
PClip clip;
void LoadFromClip(AVSValue clip);
@ -62,7 +70,10 @@ public:
wxString GetFilename();
// Only exists for x86 Windows, always delivers machine (little) endian
/// @brief // Only exists for x86 Windows, always delivers machine (little) endian
/// @return
///
bool AreSamplesNativeEndian() { return true; }
void GetAudio(void *buf, int64_t start, int64_t count);
@ -70,12 +81,21 @@ public:
};
///////////
// Factory
/// DOCME
/// @class AvisynthAudioProviderFactory
/// @brief DOCME
///
/// DOCME
class AvisynthAudioProviderFactory : public AudioProviderFactory {
public:
/// @brief DOCME
/// @param file
///
AudioProvider *CreateProvider(wxString file) { return new AvisynthAudioProvider(file); }
};
#endif

View file

@ -44,8 +44,10 @@
#include "aegisub_endian.h"
///////////////
// Constructor
/// @brief Constructor
/// @param src
///
ConvertAudioProvider::ConvertAudioProvider(AudioProvider *src) {
source = src;
channels = source->GetChannels();
@ -61,15 +63,20 @@ ConvertAudioProvider::ConvertAudioProvider(AudioProvider *src) {
}
//////////////
// Destructor
/// @brief Destructor
///
ConvertAudioProvider::~ConvertAudioProvider() {
delete source;
}
/////////////////////
// Convert to 16-bit
/// @brief Convert to 16-bit
/// @param src
/// @param dst
/// @param count
///
void ConvertAudioProvider::Make16Bit(const char *src, short *dst, int64_t count) {
for (int64_t i=0;i<count;i++) {
dst[i] = (short(src[i])-128)*255;
@ -82,6 +89,13 @@ void ConvertAudioProvider::Make16Bit(const char *src, short *dst, int64_t count)
// This requres 16-bit input
// The SampleConverter is a class overloading operator() with a function from short to short
template<class SampleConverter>
/// @brief DOCME
/// @param src
/// @param dst
/// @param count
/// @param converter
///
void ConvertAudioProvider::ChangeSampleRate(const short *src, short *dst, int64_t count, const SampleConverter &converter) {
// Upsample by 2
if (sampleMult == 2) {
@ -122,23 +136,39 @@ void ConvertAudioProvider::ChangeSampleRate(const short *src, short *dst, int64_
}
// Do-nothing sample converter for ChangeSampleRate
/// DOCME
struct NullSampleConverter {
/// @brief DOCME
/// @param val
/// @return
///
inline short operator()(const short val) const {
return val;
}
};
// Endian-swapping sample converter for ChangeSampleRate
/// DOCME
struct EndianSwapSampleConverter {
/// @brief DOCME
/// @param val
/// @return
///
inline short operator()(const short val) const {
return (short)Endian::Reverse((uint16_t)val);
};
};
/////////////
// Get audio
/// @brief Get audio
/// @param destination
/// @param start
/// @param count
///
void ConvertAudioProvider::GetAudio(void *destination, int64_t start, int64_t count) {
// Bits per sample
int srcBps = source->GetBytesPerSample();
@ -189,7 +219,10 @@ void ConvertAudioProvider::GetAudio(void *destination, int64_t start, int64_t co
}
}
// See if we need to downmix the number of channels
/// @brief See if we need to downmix the number of channels
/// @param source_provider
///
AudioProvider *CreateConvertAudioProvider(AudioProvider *source_provider) {
AudioProvider *provider = source_provider;
@ -212,3 +245,4 @@ AudioProvider *CreateConvertAudioProvider(AudioProvider *source_provider) {
return provider;
}

View file

@ -43,12 +43,20 @@
#include "include/aegisub/audio_provider.h"
////////////////////////
// Audio provider class
/// DOCME
/// @class ConvertAudioProvider
/// @brief DOCME
///
/// DOCME
class ConvertAudioProvider : public AudioProvider {
private:
/// DOCME
int sampleMult;
/// DOCME
AudioProvider *source;
void Make16Bit(const char *src, short *dst, int64_t count);
template<class SampleConverter>
@ -58,14 +66,20 @@ public:
ConvertAudioProvider(AudioProvider *source);
~ConvertAudioProvider();
// By its nature, the ConvertAudioProvider always delivers machine endian:
// That's one of the points of it!
/// @brief // That's one of the points of it! // By its nature, the ConvertAudioProvider always delivers machine endian:
/// @return
///
bool AreSamplesNativeEndian() { return true; }
void GetAudio(void *buf, int64_t start, int64_t count);
/// @brief DOCME
///
wxString GetFilename() { return source->GetFilename(); }
};
AudioProvider *CreateConvertAudioProvider(AudioProvider *source_provider);

View file

@ -42,8 +42,10 @@
#include "audio_provider_downmix.h"
//////////////////
// Constructor
/// @brief Constructor
/// @param source
///
DownmixingAudioProvider::DownmixingAudioProvider(AudioProvider *source) {
filename = source->GetFilename();
channels = 1; // target
@ -61,14 +63,19 @@ DownmixingAudioProvider::DownmixingAudioProvider(AudioProvider *source) {
throw _T("Downmixing Audio Provider: Source must have machine endian samples");
}
/////////////////
// Destructor
/// @brief Destructor
///
DownmixingAudioProvider::~DownmixingAudioProvider() {
delete provider;
}
////////////////
// Actual work happens here
/// @brief Actual work happens here
/// @param buf
/// @param start
/// @param count
///
void DownmixingAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
if (count == 0) return;
@ -123,3 +130,4 @@ void DownmixingAudioProvider::GetAudio(void *buf, int64_t start, int64_t count)
delete[] tmp;
}

View file

@ -36,16 +36,28 @@
#include "include/aegisub/audio_provider.h"
/// DOCME
/// @class DownmixingAudioProvider
/// @brief DOCME
///
/// DOCME
class DownmixingAudioProvider : public AudioProvider {
private:
/// DOCME
AudioProvider *provider;
/// DOCME
int src_channels;
public:
DownmixingAudioProvider(AudioProvider *source);
~DownmixingAudioProvider();
// Downmixing requires samples to be native endian beforehand
/// @brief // Downmixing requires samples to be native endian beforehand
///
bool AreSamplesNativeEndian() { return true; }
void GetAudio(void *buf, int64_t start, int64_t count);
@ -53,3 +65,4 @@ public:
};

View file

@ -43,8 +43,11 @@
#include "utils.h"
///////////////
// Constructor
/// @brief Constructor
/// @param dur_ms
/// @param _noise
///
DummyAudioProvider::DummyAudioProvider(unsigned long dur_ms, bool _noise) {
noise = _noise;
channels = 1;
@ -54,14 +57,19 @@ DummyAudioProvider::DummyAudioProvider(unsigned long dur_ms, bool _noise) {
}
//////////////
// Destructor
/// @brief Destructor
///
DummyAudioProvider::~DummyAudioProvider() {
}
/////////////
// Get audio
/// @brief Get audio
/// @param buf
/// @param start
/// @param count
///
void DummyAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
short *workbuf = (short*)buf;
@ -75,3 +83,4 @@ void DummyAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
}
}

View file

@ -43,18 +43,28 @@
#include "include/aegisub/audio_provider.h"
////////////////////////
// Audio provider class
/// DOCME
/// @class DummyAudioProvider
/// @brief DOCME
///
/// DOCME
class DummyAudioProvider : public AudioProvider {
private:
/// DOCME
bool noise;
public:
DummyAudioProvider(unsigned long dur_ms, bool _noise);
~DummyAudioProvider();
/// @brief DOCME
///
bool AreSamplesNativeEndian() { return true; }
void GetAudio(void *buf, int64_t start, int64_t count);
};

View file

@ -49,8 +49,10 @@
#endif
///////////
// Constructor
/// @brief Constructor
/// @param filename
///
FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(wxString filename) {
COMInited = false;
#ifdef WIN32
@ -79,8 +81,10 @@ FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(wxString filename) {
}
///////////
// Load audio file
/// @brief Load audio file
/// @param filename
///
void FFmpegSourceAudioProvider::LoadAudio(wxString filename) {
// clean up
Close();
@ -198,8 +202,9 @@ void FFmpegSourceAudioProvider::LoadAudio(wxString filename) {
}
///////////
// Destructor
/// @brief Destructor
///
FFmpegSourceAudioProvider::~FFmpegSourceAudioProvider() {
Close();
#ifdef WIN32
@ -209,16 +214,21 @@ FFmpegSourceAudioProvider::~FFmpegSourceAudioProvider() {
}
///////////
// Clean up
/// @brief Clean up
///
void FFmpegSourceAudioProvider::Close() {
FFMS_DestroyAudioSource(AudioSource);
AudioSource = NULL;
}
///////////
// Get audio
/// @brief Get audio
/// @param Buf
/// @param Start
/// @param Count
///
void FFmpegSourceAudioProvider::GetAudio(void *Buf, int64_t Start, int64_t Count) {
if (FFMS_GetAudio(AudioSource, Buf, Start, Count, FFMSErrMsg, MsgSize)) {
ErrorMsg.Append(wxString::Format(_T("Failed to get audio samples: %s"), FFMSErrMsg));
@ -229,3 +239,4 @@ void FFmpegSourceAudioProvider::GetAudio(void *Buf, int64_t Start, int64_t Count
#endif /* WITH_FFMPEGSOURCE */

View file

@ -42,16 +42,30 @@
#include "ffmpegsource_common.h"
///////////////////////
// FFmpegSource audio provider
/// DOCME
/// @class FFmpegSourceAudioProvider
/// @brief DOCME
///
/// DOCME
class FFmpegSourceAudioProvider : public AudioProvider, FFmpegSourceProvider {
private:
/// DOCME
FFAudio *AudioSource;
/// DOCME
char FFMSErrMsg[1024];
/// DOCME
unsigned MsgSize;
/// DOCME
wxString ErrorMsg;
/// DOCME
bool COMInited;
void Close();
@ -61,7 +75,10 @@ public:
FFmpegSourceAudioProvider(wxString filename);
virtual ~FFmpegSourceAudioProvider();
// FFMS always delivers samples in machine endian
/// @brief // FFMS always delivers samples in machine endian
/// @return
///
bool AreSamplesNativeEndian() { return true; }
virtual void GetAudio(void *buf, int64_t start, int64_t count);
@ -69,13 +86,22 @@ public:
};
///////////////////////
// Factory
/// DOCME
/// @class FFmpegSourceAudioProviderFactory
/// @brief DOCME
///
/// DOCME
class FFmpegSourceAudioProviderFactory : public AudioProviderFactory {
public:
/// @brief DOCME
/// @param file
///
AudioProvider *CreateProvider(wxString file) { return new FFmpegSourceAudioProvider(file); }
};
#endif /* WITH_FFMPEGSOURCE */

View file

@ -51,8 +51,10 @@
#include "main.h"
///////////////
// Constructor
/// @brief Constructor
/// @param source
///
HDAudioProvider::HDAudioProvider(AudioProvider *source) {
// Copy parameters
bytes_per_sample = source->GetBytesPerSample();
@ -104,8 +106,9 @@ HDAudioProvider::HDAudioProvider(AudioProvider *source) {
}
//////////////
// Destructor
/// @brief Destructor
///
HDAudioProvider::~HDAudioProvider() {
file_cache.Close();
wxRemoveFile(diskCacheFilename);
@ -113,8 +116,12 @@ HDAudioProvider::~HDAudioProvider() {
}
/////////////
// Get audio
/// @brief Get audio
/// @param buf
/// @param start
/// @param count
///
void HDAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
// Requested beyond the length of audio
if (start+count > num_samples) {
@ -145,8 +152,10 @@ void HDAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
}
///////////////////////////
// Get disk cache path
/// @brief Get disk cache path
/// @return
///
wxString HDAudioProvider::DiskCachePath() {
// Default
wxString path = Options.AsText(_T("Audio HD Cache Location"));
@ -157,8 +166,9 @@ wxString HDAudioProvider::DiskCachePath() {
}
///////////////////////////
// Get disk cache filename
/// @brief Get disk cache filename
///
wxString HDAudioProvider::DiskCacheName() {
// Get pattern
wxString pattern = Options.AsText(_T("Audio HD Cache Name"));
@ -182,3 +192,4 @@ wxString HDAudioProvider::DiskCacheName() {
return _T("");
}

View file

@ -44,14 +44,28 @@
#include <wx/file.h>
////////////////////////
// Audio provider class
/// DOCME
/// @class HDAudioProvider
/// @brief DOCME
///
/// DOCME
class HDAudioProvider : public AudioProvider {
private:
/// DOCME
wxMutex diskmutex;
/// DOCME
wxFile file_cache;
/// DOCME
wxString diskCacheFilename;
/// DOCME
bool samples_native_endian;
/// DOCME
char *data;
static wxString DiskCachePath();
@ -61,8 +75,12 @@ public:
HDAudioProvider(AudioProvider *source);
~HDAudioProvider();
/// @brief DOCME
///
bool AreSamplesNativeEndian() { return samples_native_endian; }
void GetAudio(void *buf, int64_t start, int64_t count);
};

View file

@ -46,8 +46,12 @@
#include "include/aegisub/audio_provider.h"
///////////////////
// Factory Manager
/// DOCME
/// @class AudioProviderFactoryManager
/// @brief DOCME
///
/// DOCME
class AudioProviderFactoryManager : public FactoryManager<AudioProviderFactory> {
public:
static void RegisterProviders();
@ -55,3 +59,4 @@ public:
static void ClearProviders();
};

View file

@ -53,6 +53,10 @@
/// @brief DOCME
/// @param filename
///
PCMAudioProvider::PCMAudioProvider(const wxString &filename)
{
#ifdef _WINDOWS
@ -114,6 +118,9 @@ PCMAudioProvider::PCMAudioProvider(const wxString &filename)
}
/// @brief DOCME
///
PCMAudioProvider::~PCMAudioProvider()
{
#ifdef _WINDOWS
@ -137,6 +144,12 @@ PCMAudioProvider::~PCMAudioProvider()
}
/// @brief DOCME
/// @param range_start
/// @param range_length
/// @return
///
char * PCMAudioProvider::EnsureRangeAccessible(int64_t range_start, int64_t range_length)
{
if (range_start + range_length > file_size) {
@ -210,6 +223,12 @@ char * PCMAudioProvider::EnsureRangeAccessible(int64_t range_start, int64_t rang
}
/// @brief DOCME
/// @param buf
/// @param start
/// @param count
///
void PCMAudioProvider::GetAudio(void *buf, int64_t start, int64_t count)
{
// Read blocks from the file
@ -254,29 +273,66 @@ void PCMAudioProvider::GetAudio(void *buf, int64_t start, int64_t count)
// RIFF WAV PCM provider
// Overview of RIFF WAV: <http://www.sonicspot.com/guide/wavefiles.html>
/// DOCME
/// @class RiffWavPCMAudioProvider
/// @brief DOCME
///
/// DOCME
class RiffWavPCMAudioProvider : public PCMAudioProvider {
private:
/// DOCME
struct ChunkHeader {
/// DOCME
char type[4];
/// DOCME
uint32_t size;
};
/// DOCME
struct RIFFChunk {
/// DOCME
ChunkHeader ch;
/// DOCME
char format[4];
};
/// DOCME
struct fmtChunk {
// Skip the chunk header here, it's processed separately
/// DOCME
uint16_t compression; // compression format used -- 0x0001 = PCM
/// DOCME
uint16_t channels;
/// DOCME
uint32_t samplerate;
/// DOCME
uint32_t avg_bytes_sec; // can't always be trusted
/// DOCME
uint16_t block_align;
/// DOCME
uint16_t significant_bits_sample;
// Here was supposed to be some more fields but we don't need them
// and just skipping by the size of the struct wouldn't be safe
// either way, as the fields can depend on the compression.
};
/// @brief DOCME
/// @param str1[]
/// @param str2[]
/// @return
///
static bool CheckFourcc(const char str1[], const char str2[])
{
assert(str1);
@ -289,6 +345,10 @@ private:
}
public:
/// @brief DOCME
/// @param _filename
///
RiffWavPCMAudioProvider(const wxString &_filename)
: PCMAudioProvider(_filename)
{
@ -368,6 +428,10 @@ public:
}
/// @brief DOCME
/// @return
///
bool AreSamplesNativeEndian()
{
// 8 bit samples don't consider endianness
@ -383,64 +447,128 @@ public:
// Sony Wave64 audio provider
// Specs obtained at: <http://www.vcs.de/fileadmin/user_upload/MBS/PDF/Whitepaper/Informations_about_Sony_Wave64.pdf>
/// DOCME
static const uint8_t w64GuidRIFF[16] = {
// {66666972-912E-11CF-A5D6-28DB04C10000}
0x72, 0x69, 0x66, 0x66, 0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
};
/// DOCME
static const uint8_t w64GuidWAVE[16] = {
// {65766177-ACF3-11D3-8CD1-00C04F8EDB8A}
0x77, 0x61, 0x76, 0x65, 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A
};
/// DOCME
static const uint8_t w64Guidfmt[16] = {
// {20746D66-ACF3-11D3-8CD1-00C04F8EDB8A}
0x66, 0x6D, 0x74, 0x20, 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A
};
/// DOCME
static const uint8_t w64Guiddata[16] = {
// {61746164-ACF3-11D3-8CD1-00C04F8EDB8A}
0x64, 0x61, 0x74, 0x61, 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A
};
/// DOCME
/// @class Wave64AudioProvider
/// @brief DOCME
///
/// DOCME
class Wave64AudioProvider : public PCMAudioProvider {
private:
// Here's some copy-paste from the FFmpegSource2 code
/// DOCME
struct WaveFormatEx {
/// DOCME
uint16_t wFormatTag;
/// DOCME
uint16_t nChannels;
/// DOCME
uint32_t nSamplesPerSec;
/// DOCME
uint32_t nAvgBytesPerSec;
/// DOCME
uint16_t nBlockAlign;
/// DOCME
uint16_t wBitsPerSample;
/// DOCME
uint16_t cbSize;
};
/// DOCME
struct RiffChunk {
/// DOCME
uint8_t riff_guid[16];
/// DOCME
uint64_t file_size;
/// DOCME
uint8_t format_guid[16];
};
/// DOCME
struct FormatChunk {
/// DOCME
uint8_t chunk_guid[16];
/// DOCME
uint64_t chunk_size;
/// DOCME
WaveFormatEx format;
/// DOCME
uint8_t padding[6];
};
/// DOCME
struct DataChunk {
/// DOCME
uint8_t chunk_guid[16];
/// DOCME
uint64_t chunk_size;
};
/// @brief DOCME
/// @param guid1
/// @param guid2
/// @return
///
inline bool CheckGuid(const uint8_t *guid1, const uint8_t *guid2)
{
return memcmp(guid1, guid2, 16) == 0;
}
public:
/// @brief DOCME
/// @param _filename
///
Wave64AudioProvider(const wxString &_filename)
: PCMAudioProvider(_filename)
{
@ -521,6 +649,10 @@ public:
}
/// @brief DOCME
/// @return
///
bool AreSamplesNativeEndian()
{
// 8 bit samples don't consider endianness
@ -532,6 +664,10 @@ public:
};
/// @brief DOCME
/// @param filename
///
AudioProvider *CreatePCMAudioProvider(const wxString &filename)
{
AudioProvider *provider = 0;
@ -561,3 +697,4 @@ AudioProvider *CreatePCMAudioProvider(const wxString &filename)
return NULL;
}

View file

@ -50,18 +50,29 @@
#endif
/////////////////////////////
// Audio provider base class
/// DOCME
/// @class PCMAudioProvider
/// @brief DOCME
///
/// DOCME
class PCMAudioProvider : public AudioProvider {
private:
#ifdef _WINDOWS
// File handle and file mapping handle from Win32
/// DOCME
HANDLE file_handle;
/// DOCME
HANDLE file_mapping;
// Pointer to current area mapped into memory
/// DOCME
void *current_mapping;
// Byte indices in the file that the current mapping covers
/// DOCME
int64_t mapping_start;
/// DOCME
size_t mapping_length;
#else
int file_handle;
@ -75,19 +86,28 @@ protected:
virtual ~PCMAudioProvider(); // Closes the file mapping
char * EnsureRangeAccessible(int64_t range_start, int64_t range_length); // Ensure that the given range of bytes are accessible in the file mapping and return a pointer to the first byte of the requested range
/// DOCME
int64_t file_size; // Size of the opened file
// Hold data for an index point,
// to support files where audio data are
// split into multiple blocks.
// Using int64_t's should be safe on most compilers,
// wx defines wxFileOffset as int64 when possible
/// DOCME
struct IndexPoint {
/// DOCME
int64_t start_byte;
/// DOCME
int64_t start_sample;
/// DOCME
int64_t num_samples;
};
/// DOCME
typedef std::vector<IndexPoint> IndexVector;
/// DOCME
IndexVector index_points;
public:
@ -99,3 +119,4 @@ AudioProvider *CreatePCMAudioProvider(const wxString &filename);

View file

@ -39,6 +39,10 @@
#ifdef WITH_QUICKTIME
/// @brief DOCME
/// @param filename
///
QuickTimeAudioProvider::QuickTimeAudioProvider(wxString filename) {
movie = NULL;
in_dataref = NULL;
@ -74,12 +78,18 @@ QuickTimeAudioProvider::QuickTimeAudioProvider(wxString filename) {
}
/// @brief DOCME
///
QuickTimeAudioProvider::~QuickTimeAudioProvider() {
Close();
DeInitQuickTime();
}
/// @brief DOCME
///
void QuickTimeAudioProvider::Close() {
if (movie)
DisposeMovie(movie);
@ -93,6 +103,10 @@ void QuickTimeAudioProvider::Close() {
}
/// @brief DOCME
/// @param filename
///
void QuickTimeAudioProvider::LoadAudio(wxString filename) {
OSType in_dataref_type;
wxStringToDataRef(filename, &in_dataref, &in_dataref_type);
@ -148,6 +162,12 @@ void QuickTimeAudioProvider::LoadAudio(wxString filename) {
}
/// @brief DOCME
/// @param buf
/// @param start
/// @param count
///
void QuickTimeAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
TimeRecord trec;
trec.scale = GetMovieTimeScale(movie);
@ -180,3 +200,4 @@ void QuickTimeAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
#endif /* WITH_QUICKTIME */

View file

@ -45,16 +45,36 @@
#include "include/aegisub/audio_provider.h"
/// DOCME
/// @class QuickTimeAudioProvider
/// @brief DOCME
///
/// DOCME
class QuickTimeAudioProvider : public AudioProvider, QuickTimeProvider {
private:
/// DOCME
Movie movie; // input file
/// DOCME
Handle in_dataref; // input file handle
/// DOCME
MovieAudioExtractionRef extract_ref; // extraction session object
/// DOCME
bool inited;
/// DOCME
OSErr qt_err; // quicktime error code
/// DOCME
OSStatus qt_status; // another quicktime error code
/// DOCME
wxString errmsg; // aegisub error messages
void Close();
@ -64,17 +84,32 @@ public:
QuickTimeAudioProvider(wxString filename);
virtual ~QuickTimeAudioProvider();
/// @brief DOCME
/// @return
///
bool AreSamplesNativeEndian() { return true; }
virtual void GetAudio(void *buf, int64_t start, int64_t count);
};
/// DOCME
/// @class QuickTimeAudioProviderFactory
/// @brief DOCME
///
/// DOCME
class QuickTimeAudioProviderFactory : public AudioProviderFactory {
public:
/// @brief DOCME
/// @param file
///
AudioProvider *CreateProvider(wxString file) { return new QuickTimeAudioProvider(file); }
};
#endif /* WITH_QUICKTIME */

View file

@ -46,14 +46,18 @@
#include "main.h"
///////////
// Defines
/// DOCME
#define CacheBits ((22))
/// DOCME
#define CacheBlockSize ((1 << CacheBits))
///////////////
// Constructor
/// @brief Constructor
/// @param source
///
RAMAudioProvider::RAMAudioProvider(AudioProvider *source) {
// Init
blockcache = NULL;
@ -109,15 +113,17 @@ RAMAudioProvider::RAMAudioProvider(AudioProvider *source) {
}
//////////////
// Destructor
/// @brief Destructor
///
RAMAudioProvider::~RAMAudioProvider() {
Clear();
}
/////////
// Clear
/// @brief Clear
///
void RAMAudioProvider::Clear() {
// Free ram cache
if (blockcache) {
@ -131,8 +137,12 @@ void RAMAudioProvider::Clear() {
}
/////////////
// Get audio
/// @brief Get audio
/// @param buf
/// @param start
/// @param count
///
void RAMAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
// Requested beyond the length of audio
if (start+count > num_samples) {
@ -177,3 +187,4 @@ void RAMAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
}
}

View file

@ -43,12 +43,22 @@
#include "include/aegisub/audio_provider.h"
////////////////////////
// Audio provider class
/// DOCME
/// @class RAMAudioProvider
/// @brief DOCME
///
/// DOCME
class RAMAudioProvider : public AudioProvider {
private:
/// DOCME
char** blockcache;
/// DOCME
int blockcount;
/// DOCME
bool samples_native_endian;
void Clear();
@ -57,8 +67,12 @@ public:
RAMAudioProvider(AudioProvider *source);
~RAMAudioProvider();
/// @brief DOCME
///
bool AreSamplesNativeEndian() { return samples_native_endian; }
void GetAudio(void *buf, int64_t start, int64_t count);
};

View file

@ -43,11 +43,14 @@
#include "utils.h"
/// DOCME
#define BUFSIZE 65536
///////////////
// Constructor
/// @brief Constructor
///
StreamAudioProvider::StreamAudioProvider() {
bufLen = 8192;
startPos = 0;
@ -58,8 +61,9 @@ StreamAudioProvider::StreamAudioProvider() {
}
//////////////
// Destructor
/// @brief Destructor
///
StreamAudioProvider::~StreamAudioProvider() {
for (std::list<BufferChunk*>::iterator cur=buffer.begin();cur!=buffer.end();cur++) {
delete *cur;
@ -68,8 +72,12 @@ StreamAudioProvider::~StreamAudioProvider() {
}
/////////////
// Get audio
/// @brief Get audio
/// @param buf
/// @param start
/// @param count
///
void StreamAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
// Write
int64_t left = count;
@ -111,8 +119,11 @@ void StreamAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
}
//////////////////////////
// Append audio to stream
/// @brief Append audio to stream
/// @param voidptr
/// @param count
///
void StreamAudioProvider::Append(void *voidptr, int64_t count) {
// Read
int64_t left = count;
@ -140,8 +151,12 @@ void StreamAudioProvider::Append(void *voidptr, int64_t count) {
}
//////////////////
// Set parameters
/// @brief Set parameters
/// @param chan
/// @param rate
/// @param bps
///
void StreamAudioProvider::SetParams(int chan,int rate,int bps) {
channels = chan;
sample_rate = rate;
@ -149,10 +164,12 @@ void StreamAudioProvider::SetParams(int chan,int rate,int bps) {
}
////////////////////////////
// Buffer chunk constructor
/// @brief Buffer chunk constructor
///
StreamAudioProvider::BufferChunk::BufferChunk() {
buf.resize(BUFSIZE);
isFree = true;
}

View file

@ -45,24 +45,49 @@
#include "include/aegisub/audio_provider.h"
////////////////////////
// Audio provider class
/// DOCME
/// @class StreamAudioProvider
/// @brief DOCME
///
/// DOCME
class StreamAudioProvider : public AudioProvider {
private:
// Buffer chunk subclass
/// DOCME
/// @class BufferChunk
/// @brief DOCME
///
/// DOCME
class BufferChunk {
public:
/// DOCME
std::vector<short> buf;
/// DOCME
bool isFree;
BufferChunk();
};
/// DOCME
std::list<BufferChunk*> buffer;
/// DOCME
int startPos;
/// DOCME
int endPos;
/// DOCME
int bufLen;
/// DOCME
int buffered;
/// DOCME
bool hasBuf;
public:
@ -80,3 +105,4 @@ public:
void SetParams(int channels,int rate,int bps);
};

View file

@ -55,21 +55,49 @@
// Audio spectrum FFT data cache
// Spectrum cache basically caches the raw result of FFT
/// DOCME
/// @class AudioSpectrumCache
/// @brief DOCME
///
/// DOCME
class AudioSpectrumCache {
public:
// Type of a single FFT result line
/// DOCME
typedef std::vector<float> CacheLine;
// Types for cache aging
/// DOCME
typedef unsigned int CacheAccessTime;
/// DOCME
struct CacheAgeData {
/// DOCME
CacheAccessTime access_time;
/// DOCME
unsigned long first_line;
/// DOCME
unsigned long num_lines; // includes overlap-lines
/// @brief DOCME
/// @param second
/// @return
///
bool operator< (const CacheAgeData& second) const { return access_time < second.access_time; }
/// @brief DOCME
/// @param t
/// @param first
/// @param num
///
CacheAgeData(CacheAccessTime t, unsigned long first, unsigned long num) : access_time(t), first_line(first), num_lines(num) { }
};
/// DOCME
typedef std::vector<CacheAgeData> CacheAgeList;
// Get the overlap'th overlapping FFT in FFT group i, generating it if needed
@ -85,37 +113,73 @@ public:
// Return true if the object called on is empty and can safely be deleted too
virtual bool KillLine(unsigned long line_id) = 0;
// Set the FFT size used
/// @brief // Set the FFT size used
/// @param new_length
///
static void SetLineLength(unsigned long new_length)
{
line_length = new_length;
null_line.resize(new_length, 0);
}
/// @brief DOCME
///
virtual ~AudioSpectrumCache() {};
protected:
// A cache line containing only zero-values
/// DOCME
static CacheLine null_line;
// The FFT size
/// DOCME
static unsigned long line_length;
};
/// DOCME
AudioSpectrumCache::CacheLine AudioSpectrumCache::null_line;
/// DOCME
unsigned long AudioSpectrumCache::line_length;
// Bottom level FFT cache, holds actual power data itself
/// DOCME
/// @class FinalSpectrumCache
/// @brief DOCME
///
/// DOCME
class FinalSpectrumCache : public AudioSpectrumCache {
private:
/// DOCME
std::vector<CacheLine> data;
/// DOCME
/// DOCME
unsigned long start, length; // start and end of range
/// DOCME
unsigned int overlaps;
/// DOCME
CacheAccessTime last_access;
public:
/// @brief DOCME
/// @param i
/// @param overlap
/// @param created
/// @param access_time
/// @return
///
CacheLine& GetLine(unsigned long i, unsigned int overlap, bool &created, CacheAccessTime access_time)
{
last_access = access_time;
@ -127,21 +191,41 @@ public:
return null_line;
}
/// @brief DOCME
/// @return
///
size_t GetManagedLineCount()
{
return data.size();
}
/// @brief DOCME
/// @param ages
///
void GetLineAccessTimes(CacheAgeList &ages)
{
ages.push_back(CacheAgeData(last_access, start, data.size()));
}
/// @brief DOCME
/// @param line_id
/// @return
///
bool KillLine(unsigned long line_id)
{
return start == line_id;
}
/// @brief DOCME
/// @param provider
/// @param _start
/// @param _length
/// @param _overlaps
///
FinalSpectrumCache(AudioProvider *provider, unsigned long _start, unsigned long _length, unsigned int _overlaps)
{
start = _start;
@ -210,6 +294,9 @@ public:
}
}
/// @brief DOCME
///
virtual ~FinalSpectrumCache()
{
}
@ -219,16 +306,46 @@ public:
// Non-bottom-level cache, refers to other caches to do the work
/// DOCME
/// @class IntermediateSpectrumCache
/// @brief DOCME
///
/// DOCME
class IntermediateSpectrumCache : public AudioSpectrumCache {
private:
/// DOCME
std::vector<AudioSpectrumCache*> sub_caches;
/// DOCME
/// DOCME
/// DOCME
unsigned long start, length, subcache_length;
/// DOCME
unsigned int overlaps;
/// DOCME
bool subcaches_are_final;
/// DOCME
int depth;
/// DOCME
AudioProvider *provider;
public:
/// @brief DOCME
/// @param i
/// @param overlap
/// @param created
/// @param access_time
/// @return
///
CacheLine &GetLine(unsigned long i, unsigned int overlap, bool &created, CacheAccessTime access_time)
{
if (i >= start && i-start <= length) {
@ -251,6 +368,10 @@ public:
}
}
/// @brief DOCME
/// @return
///
size_t GetManagedLineCount()
{
size_t res = 0;
@ -261,6 +382,10 @@ public:
return res;
}
/// @brief DOCME
/// @param ages
///
void GetLineAccessTimes(CacheAgeList &ages)
{
for (size_t i = 0; i < sub_caches.size(); ++i) {
@ -269,6 +394,11 @@ public:
}
}
/// @brief DOCME
/// @param line_id
/// @return
///
bool KillLine(unsigned long line_id)
{
int sub_caches_left = 0;
@ -285,6 +415,14 @@ public:
return sub_caches_left == 0;
}
/// @brief DOCME
/// @param _provider
/// @param _start
/// @param _length
/// @param _overlaps
/// @param _depth
///
IntermediateSpectrumCache(AudioProvider *_provider, unsigned long _start, unsigned long _length, unsigned int _overlaps, int _depth)
{
provider = _provider;
@ -307,6 +445,9 @@ public:
sub_caches.resize(num_subcaches, 0);
}
/// @brief DOCME
///
virtual ~IntermediateSpectrumCache()
{
for (size_t i = 0; i < sub_caches.size(); ++i)
@ -318,15 +459,37 @@ public:
/// DOCME
/// @class AudioSpectrumCacheManager
/// @brief DOCME
///
/// DOCME
class AudioSpectrumCacheManager {
private:
/// DOCME
IntermediateSpectrumCache *cache_root;
/// DOCME
/// DOCME
unsigned long cache_hits, cache_misses;
/// DOCME
AudioSpectrumCache::CacheAccessTime cur_time;
/// DOCME
unsigned long max_lines_cached;
public:
/// @brief DOCME
/// @param i
/// @param overlap
/// @return
///
AudioSpectrumCache::CacheLine &GetLine(unsigned long i, unsigned int overlap)
{
bool created = false;
@ -338,6 +501,10 @@ public:
return res;
}
/// @brief DOCME
/// @return
///
void Age()
{
wxLogDebug(_T("AudioSpectrumCacheManager stats: hits=%u, misses=%u, misses%%=%f, managed lines=%u (max=%u)"), cache_hits, cache_misses, cache_misses/float(cache_hits+cache_misses)*100, cache_root->GetManagedLineCount(), max_lines_cached);
@ -383,6 +550,13 @@ public:
assert(cache_root->GetManagedLineCount() < max_lines_cached);
}
/// @brief DOCME
/// @param provider
/// @param line_length
/// @param num_lines
/// @param num_overlaps
///
AudioSpectrumCacheManager(AudioProvider *provider, unsigned long line_length, unsigned long num_lines, unsigned int num_overlaps)
{
cache_hits = cache_misses = 0;
@ -398,6 +572,9 @@ public:
max_lines_cached = max_cache_size / line_size;
}
/// @brief DOCME
///
~AudioSpectrumCacheManager()
{
delete cache_root;
@ -407,6 +584,10 @@ public:
// AudioSpectrum
/// @brief DOCME
/// @param _provider
///
AudioSpectrum::AudioSpectrum(AudioProvider *_provider)
{
provider = _provider;
@ -496,12 +677,26 @@ AudioSpectrum::AudioSpectrum(AudioProvider *_provider)
}
/// @brief DOCME
///
AudioSpectrum::~AudioSpectrum()
{
delete cache;
}
/// @brief DOCME
/// @param range_start
/// @param range_end
/// @param selected
/// @param img
/// @param imgleft
/// @param imgwidth
/// @param imgpitch
/// @param imgheight
///
void AudioSpectrum::RenderRange(int64_t range_start, int64_t range_end, bool selected, unsigned char *img, int imgleft, int imgwidth, int imgpitch, int imgheight)
{
unsigned long first_line = (unsigned long)(fft_overlaps * range_start / line_length / 2);
@ -551,6 +746,8 @@ void AudioSpectrum::RenderRange(int64_t range_start, int64_t range_end, bool sel
}
}
/// DOCME
#define WRITE_PIXEL \
if (intensity < 0) intensity = 0; \
if (intensity > 255) intensity = 255; \
@ -599,6 +796,8 @@ void AudioSpectrum::RenderRange(int64_t range_start, int64_t range_end, bool sel
}
}
/// DOCME
#undef WRITE_PIXEL
}
@ -609,6 +808,10 @@ void AudioSpectrum::RenderRange(int64_t range_start, int64_t range_end, bool sel
}
/// @brief DOCME
/// @param _power_scale
///
void AudioSpectrum::SetScaling(float _power_scale)
{
power_scale = _power_scale;
@ -616,3 +819,4 @@ void AudioSpectrum::SetScaling(float _power_scale)

View file

@ -36,6 +36,8 @@
///
#ifndef AUDIO_SPECTRUM_H
/// DOCME
#define AUDIO_SPECTRUM_H
#include <wx/wxprec.h>
@ -47,22 +49,46 @@
class AudioSpectrumCacheManager;
/// DOCME
/// @class AudioSpectrum
/// @brief DOCME
///
/// DOCME
class AudioSpectrum {
private:
// Data provider
/// DOCME
AudioSpectrumCacheManager *cache;
// Colour pallettes
/// DOCME
unsigned char colours_normal[256*3];
/// DOCME
unsigned char colours_selected[256*3];
/// DOCME
AudioProvider *provider;
/// DOCME
unsigned long line_length; // number of frequency components per line (half of number of samples)
/// DOCME
unsigned long num_lines; // number of lines needed for the audio
/// DOCME
unsigned int fft_overlaps; // number of overlaps used in FFT
/// DOCME
float power_scale; // amplification of displayed power
/// DOCME
int minband; // smallest frequency band displayed
/// DOCME
int maxband; // largest frequency band displayed
public:
@ -77,3 +103,4 @@ public:
#endif

View file

@ -68,8 +68,20 @@
#include FT_FREETYPE_H
#endif
/// DOCME
namespace Automation4 {
/// @brief DOCME
/// @param style
/// @param text
/// @param width
/// @param height
/// @param descent
/// @param extlead
/// @return
///
bool CalculateTextExtents(AssStyle *style, wxString &text, double &width, double &height, double &descent, double &extlead)
{
width = height = descent = extlead = 0;
@ -183,6 +195,11 @@ namespace Automation4 {
// Feature
/// @brief DOCME
/// @param _featureclass
/// @param _name
///
Feature::Feature(ScriptFeatureClass _featureclass, const wxString &_name)
: featureclass(_featureclass)
, name(_name)
@ -190,11 +207,19 @@ namespace Automation4 {
// nothing to do
}
/// @brief DOCME
/// @return
///
ScriptFeatureClass Feature::GetClass() const
{
return featureclass;
}
/// @brief DOCME
/// @return
///
FeatureMacro* Feature::AsMacro()
{
if (featureclass == SCRIPTFEATURE_MACRO)
@ -203,6 +228,10 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @return
///
FeatureFilter* Feature::AsFilter()
{
if (featureclass == SCRIPTFEATURE_FILTER)
@ -210,6 +239,10 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @return
///
FeatureSubtitleFormat* Feature::AsSubFormat()
{
if (featureclass == SCRIPTFEATURE_SUBFORMAT)
@ -217,6 +250,10 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @return
///
const wxString& Feature::GetName() const
{
return name;
@ -225,6 +262,11 @@ namespace Automation4 {
// FeatureMacro
/// @brief DOCME
/// @param _name
/// @param _description
///
FeatureMacro::FeatureMacro(const wxString &_name, const wxString &_description)
: Feature(SCRIPTFEATURE_MACRO, _name)
, description(_description)
@ -232,6 +274,10 @@ namespace Automation4 {
// nothing to do
}
/// @brief DOCME
/// @return
///
const wxString& FeatureMacro::GetDescription() const
{
return description;
@ -240,6 +286,12 @@ namespace Automation4 {
// FeatureFilter
/// @brief DOCME
/// @param _name
/// @param _description
/// @param _priority
///
FeatureFilter::FeatureFilter(const wxString &_name, const wxString &_description, int _priority)
: Feature(SCRIPTFEATURE_FILTER, _name)
, AssExportFilter()
@ -249,16 +301,28 @@ namespace Automation4 {
Register(_name, _priority);
}
/// @brief DOCME
///
FeatureFilter::~FeatureFilter()
{
Unregister();
}
/// @brief DOCME
/// @return
///
wxString FeatureFilter::GetScriptSettingsIdentifier()
{
return inline_string_encode(wxString::Format(_T("Automation Settings %s"), GetName().c_str()));
}
/// @brief DOCME
/// @param parent
/// @return
///
wxWindow* FeatureFilter::GetConfigDialogWindow(wxWindow *parent) {
if (config_dialog) {
delete config_dialog;
@ -275,6 +339,10 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @param IsDefault
///
void FeatureFilter::LoadSettings(bool IsDefault) {
if (config_dialog) {
config_dialog->ReadBack();
@ -289,6 +357,11 @@ namespace Automation4 {
// FeatureSubtitleFormat
/// @brief DOCME
/// @param _name
/// @param _extension
///
FeatureSubtitleFormat::FeatureSubtitleFormat(const wxString &_name, const wxString &_extension)
: Feature(SCRIPTFEATURE_SUBFORMAT, _name)
, extension(_extension)
@ -296,16 +369,30 @@ namespace Automation4 {
// nothing to do
}
/// @brief DOCME
/// @return
///
const wxString& FeatureSubtitleFormat::GetExtension() const
{
return extension;
}
/// @brief DOCME
/// @param filename
/// @return
///
bool FeatureSubtitleFormat::CanWriteFile(wxString filename)
{
return !filename.Right(extension.Length()).CmpNoCase(extension);
}
/// @brief DOCME
/// @param filename
/// @return
///
bool FeatureSubtitleFormat::CanReadFile(wxString filename)
{
return !filename.Right(extension.Length()).CmpNoCase(extension);
@ -314,23 +401,37 @@ namespace Automation4 {
// ShowConfigDialogEvent
/// DOCME
const wxEventType EVT_SHOW_CONFIG_DIALOG_t = wxNewEventType();
// ScriptConfigDialog
/// @brief DOCME
/// @param parent
/// @return
///
wxWindow* ScriptConfigDialog::GetWindow(wxWindow *parent)
{
if (win) return win;
return win = CreateWindow(parent);
}
/// @brief DOCME
///
void ScriptConfigDialog::DeleteWindow()
{
if (win) delete win;
win = 0;
}
/// @brief DOCME
/// @return
///
wxString ScriptConfigDialog::Serialise()
{
return _T("");
@ -339,6 +440,10 @@ namespace Automation4 {
// ProgressSink
/// @brief DOCME
/// @param parent
///
ProgressSink::ProgressSink(wxWindow *parent)
: wxDialog(parent, -1, _T("Automation"), wxDefaultPosition, wxDefaultSize, wxBORDER_RAISED)
, debug_visible(false)
@ -384,11 +489,18 @@ namespace Automation4 {
trace_level = Options.AsInt(_T("Automation Trace Level"));
}
/// @brief DOCME
///
ProgressSink::~ProgressSink()
{
delete update_timer;
}
/// @brief DOCME
/// @param evt
///
void ProgressSink::OnIdle(wxIdleEvent &evt)
{
// The big glossy "update display" event
@ -406,6 +518,10 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @return
///
void ProgressSink::DoUpdateDisplay()
{
// If debug output isn't handled before the test for script_finished later,
@ -434,6 +550,10 @@ namespace Automation4 {
data_updated = false;
}
/// @brief DOCME
/// @param _progress
///
void ProgressSink::SetProgress(float _progress)
{
wxMutexLocker lock(data_mutex);
@ -441,6 +561,10 @@ namespace Automation4 {
data_updated = true;
}
/// @brief DOCME
/// @param _task
///
void ProgressSink::SetTask(const wxString &_task)
{
wxMutexLocker lock(data_mutex);
@ -448,6 +572,10 @@ namespace Automation4 {
data_updated = true;
}
/// @brief DOCME
/// @param _title
///
void ProgressSink::SetTitle(const wxString &_title)
{
wxMutexLocker lock(data_mutex);
@ -455,6 +583,10 @@ namespace Automation4 {
data_updated = true;
}
/// @brief DOCME
/// @param msg
///
void ProgressSink::AddDebugOutput(const wxString &msg)
{
wxMutexLocker lock(data_mutex);
@ -469,11 +601,19 @@ namespace Automation4 {
EVT_SHOW_CONFIG_DIALOG(ProgressSink::OnConfigDialog)
END_EVENT_TABLE()
/// @brief DOCME
/// @param evt
///
void ProgressSink::OnInit(wxInitDialogEvent &evt)
{
has_inited = true;
}
/// @brief DOCME
/// @param evt
///
void ProgressSink::OnCancel(wxCommandEvent &evt)
{
if (!script_finished) {
@ -484,6 +624,10 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @param evt
///
void ProgressSink::OnConfigDialog(ShowConfigDialogEvent &evt)
{
// assume we're in the GUI thread here
@ -514,6 +658,10 @@ namespace Automation4 {
// Script
/// @brief DOCME
/// @param _filename
///
Script::Script(const wxString &_filename)
: filename(_filename)
, name(_T(""))
@ -536,6 +684,9 @@ namespace Automation4 {
}
}
/// @brief DOCME
///
Script::~Script()
{
for (std::vector<Feature*>::iterator f = features.begin(); f != features.end(); ++f) {
@ -543,42 +694,74 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @return
///
wxString Script::GetPrettyFilename() const
{
wxFileName fn(filename);
return fn.GetFullName();
}
/// @brief DOCME
/// @return
///
const wxString& Script::GetFilename() const
{
return filename;
}
/// @brief DOCME
/// @return
///
const wxString& Script::GetName() const
{
return name;
}
/// @brief DOCME
/// @return
///
const wxString& Script::GetDescription() const
{
return description;
}
/// @brief DOCME
/// @return
///
const wxString& Script::GetAuthor() const
{
return author;
}
/// @brief DOCME
/// @return
///
const wxString& Script::GetVersion() const
{
return version;
}
/// @brief DOCME
/// @return
///
bool Script::GetLoadedState() const
{
return loaded;
}
/// @brief DOCME
/// @return
///
std::vector<Feature*>& Script::GetFeatures()
{
return features;
@ -587,16 +770,27 @@ namespace Automation4 {
// ScriptManager
/// @brief DOCME
///
ScriptManager::ScriptManager()
{
// do nothing...?
}
/// @brief DOCME
///
ScriptManager::~ScriptManager()
{
RemoveAll();
}
/// @brief DOCME
/// @param script
/// @return
///
void ScriptManager::Add(Script *script)
{
for (std::vector<Script*>::iterator i = scripts.begin(); i != scripts.end(); ++i) {
@ -605,6 +799,11 @@ namespace Automation4 {
scripts.push_back(script);
}
/// @brief DOCME
/// @param script
/// @return
///
void ScriptManager::Remove(Script *script)
{
for (std::vector<Script*>::iterator i = scripts.begin(); i != scripts.end(); ++i) {
@ -616,6 +815,9 @@ namespace Automation4 {
}
}
/// @brief DOCME
///
void ScriptManager::RemoveAll()
{
for (std::vector<Script*>::iterator i = scripts.begin(); i != scripts.end(); ++i) {
@ -624,11 +826,19 @@ namespace Automation4 {
scripts.clear();
}
/// @brief DOCME
/// @return
///
const std::vector<Script*>& ScriptManager::GetScripts() const
{
return scripts;
}
/// @brief DOCME
/// @return
///
const std::vector<FeatureMacro*>& ScriptManager::GetMacros()
{
macros.clear();
@ -646,12 +856,19 @@ namespace Automation4 {
// AutoloadScriptManager
/// @brief DOCME
/// @param _path
///
AutoloadScriptManager::AutoloadScriptManager(const wxString &_path)
: path(_path)
{
Reload();
}
/// @brief DOCME
///
void AutoloadScriptManager::Reload()
{
RemoveAll();
@ -704,18 +921,32 @@ namespace Automation4 {
// ScriptFactory
/// DOCME
std::vector<ScriptFactory*> *ScriptFactory::factories = 0;
/// @brief DOCME
/// @return
///
const wxString& ScriptFactory::GetEngineName() const
{
return engine_name;
}
/// @brief DOCME
/// @return
///
const wxString& ScriptFactory::GetFilenamePattern() const
{
return filename_pattern;
}
/// @brief DOCME
/// @param factory
///
void ScriptFactory::Register(ScriptFactory *factory)
{
if (!factories)
@ -729,6 +960,11 @@ namespace Automation4 {
factories->push_back(factory);
}
/// @brief DOCME
/// @param factory
/// @return
///
void ScriptFactory::Unregister(ScriptFactory *factory)
{
if (!factories)
@ -743,6 +979,12 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @param filename
/// @param log_errors
/// @return
///
Script* ScriptFactory::CreateFromFile(const wxString &filename, bool log_errors)
{
if (!factories)
@ -771,6 +1013,11 @@ namespace Automation4 {
return new UnknownScript(filename);
}
/// @brief DOCME
/// @param filename
/// @return
///
bool ScriptFactory::CanHandleScriptFormat(const wxString &filename)
{
// Just make this always return true to bitch about unknown script formats in autoload
@ -786,6 +1033,10 @@ namespace Automation4 {
return false;
}
/// @brief DOCME
/// @return
///
const std::vector<ScriptFactory*>& ScriptFactory::GetFactories()
{
if (!factories)
@ -797,6 +1048,10 @@ namespace Automation4 {
// UnknownScript
/// @brief DOCME
/// @param filename
///
UnknownScript::UnknownScript(const wxString &filename)
: Script(filename)
{
@ -810,3 +1065,4 @@ namespace Automation4 {
#endif // WITH_AUTOMATION

View file

@ -37,6 +37,8 @@
#pragma once
#ifndef _AUTO4_BASE_H
/// DOCME
#define _AUTO4_BASE_H
#include <wx/string.h>
@ -62,18 +64,29 @@ class wxPathList;
DECLARE_EVENT_TYPE(wxEVT_AUTOMATION_SCRIPT_COMPLETED, -1)
/// DOCME
namespace Automation4 {
// Calculate the extents of a text string given a style
bool CalculateTextExtents(AssStyle *style, wxString &text, double &width, double &height, double &descent, double &extlead);
// The class of a Feature...
/// DOCME
enum ScriptFeatureClass {
/// DOCME
SCRIPTFEATURE_MACRO = 0,
/// DOCME
SCRIPTFEATURE_FILTER,
/// DOCME
SCRIPTFEATURE_SUBFORMAT,
/// DOCME
SCRIPTFEATURE_MAX // must be last
};
@ -83,15 +96,28 @@ namespace Automation4 {
class FeatureMacro;
class FeatureFilter;
class FeatureSubtitleFormat;
/// DOCME
/// @class Feature
/// @brief DOCME
///
/// DOCME
class Feature {
private:
/// DOCME
ScriptFeatureClass featureclass;
/// DOCME
wxString name;
protected:
Feature(ScriptFeatureClass _featureclass, const wxString &_name);
public:
/// @brief DOCME
///
virtual ~Feature() { }
ScriptFeatureClass GetClass() const;
@ -103,15 +129,25 @@ namespace Automation4 {
};
// The Macro feature; adds a menu item that runs script code
/// DOCME
/// @class FeatureMacro
/// @brief DOCME
///
/// DOCME
class FeatureMacro : public virtual Feature {
private:
/// DOCME
wxString description;
protected:
FeatureMacro(const wxString &_name, const wxString &_description);
public:
/// @brief DOCME
///
virtual ~FeatureMacro() { }
const wxString& GetDescription() const;
@ -122,9 +158,16 @@ namespace Automation4 {
class ScriptConfigDialog;
// The Export Filter feature; adds a new export filter
/// DOCME
/// @class FeatureFilter
/// @brief DOCME
///
/// DOCME
class FeatureFilter : public virtual Feature, public AssExportFilter {
private:
/// DOCME
ScriptConfigDialog *config_dialog;
protected:
@ -146,15 +189,26 @@ namespace Automation4 {
};
// The Subtitle Format feature; adds new subtitle format readers/writers
/// DOCME
/// @class FeatureSubtitleFormat
/// @brief DOCME
///
/// DOCME
class FeatureSubtitleFormat : public virtual Feature, public SubtitleFormat {
private:
/// DOCME
wxString extension;
protected:
FeatureSubtitleFormat(const wxString &_name, const wxString &_extension);
public:
/// @brief DOCME
/// @return
///
virtual ~FeatureSubtitleFormat() { }
const wxString& GetExtension() const;
@ -169,22 +223,39 @@ namespace Automation4 {
};
// Base class for script-provided config dialogs
/// DOCME
/// @class ScriptConfigDialog
/// @brief DOCME
///
/// DOCME
class ScriptConfigDialog {
private:
/// DOCME
wxWindow *win;
protected:
virtual wxWindow* CreateWindow(wxWindow *parent) = 0;
public:
/// @brief DOCME
///
ScriptConfigDialog() : win(0) { }
/// @brief DOCME
///
virtual ~ScriptConfigDialog() { }
wxWindow* GetWindow(wxWindow *parent);
void DeleteWindow();
virtual void ReadBack() = 0;
virtual wxString Serialise();
/// @brief DOCME
/// @param serialised
///
virtual void Unserialise(const wxString &serialised) { }
};
@ -192,51 +263,99 @@ namespace Automation4 {
// Config dialog event class and related stuff (wx </3)
extern const wxEventType EVT_SHOW_CONFIG_DIALOG_t;
/// DOCME
/// @class ShowConfigDialogEvent
/// @brief DOCME
///
/// DOCME
class ShowConfigDialogEvent : public wxCommandEvent {
public:
/// @brief DOCME
/// @param EVT_SHOW_CONFIG_DIALOG_t
/// @return
///
ShowConfigDialogEvent(const wxEventType &event = EVT_SHOW_CONFIG_DIALOG_t)
: wxCommandEvent(event)
, config_dialog(0)
, sync_sema(0) { };
/// @brief DOCME
/// @return
///
virtual wxEvent *Clone() const { return new ShowConfigDialogEvent(*this); }
/// DOCME
ScriptConfigDialog *config_dialog;
// Synchronisation for config dialog events:
// You don't want the script asynchronically continue executing while the dialog
// is displaying, so a synchronisation mechanism is used.
// The poster of the event should supply a semaphore object with an initial count
// of zero. After posting the event, the poster should wait for the semaphore.
// When the dialog is finished, the semaphore is posted, and the poster can
// continue.
// The poster is responsible for cleaning up the semaphore.
/// DOCME
wxSemaphore *sync_sema;
};
/// DOCME
typedef void (wxEvtHandler::*ShowConfigDialogEventFunction)(ShowConfigDialogEvent&);
/// DOCME
#define EVT_SHOW_CONFIG_DIALOG(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_SHOW_CONFIG_DIALOG_t, -1, -1, (wxObjectEventFunction)(wxEventFunction)(ShowConfigDialogEventFunction)&fn, (wxObject*)0 ),
// Base class for progress reporting/other output
/// DOCME
/// @class ProgressSink
/// @brief DOCME
///
/// DOCME
class ProgressSink : public wxDialog {
private:
/// DOCME
wxBoxSizer *sizer;
/// DOCME
wxGauge *progress_display;
/// DOCME
wxButton *cancel_button;
/// DOCME
wxStaticText *title_display;
/// DOCME
wxStaticText *task_display;
/// DOCME
wxTextCtrl *debug_output;
/// DOCME
volatile bool debug_visible;
/// DOCME
volatile bool data_updated;
/// DOCME
float progress;
/// DOCME
wxString task;
/// DOCME
wxString title;
/// DOCME
wxString pending_debug_output;
/// DOCME
wxMutex data_mutex;
/// DOCME
wxTimer *update_timer;
void OnCancel(wxCommandEvent &evt);
@ -247,7 +366,11 @@ namespace Automation4 {
void DoUpdateDisplay();
protected:
/// DOCME
volatile bool cancelled;
/// DOCME
int trace_level;
ProgressSink(wxWindow *parent);
@ -259,27 +382,52 @@ namespace Automation4 {
void SetTitle(const wxString &_title);
void AddDebugOutput(const wxString &msg);
/// DOCME
volatile bool has_inited;
/// DOCME
volatile bool script_finished;
DECLARE_EVENT_TABLE()
};
// Base class for Scripts
/// DOCME
/// @class Script
/// @brief DOCME
///
/// DOCME
class Script {
private:
/// DOCME
wxString filename;
protected:
/// DOCME
wxString name;
/// DOCME
wxString description;
/// DOCME
wxString author;
/// DOCME
wxString version;
/// DOCME
bool loaded; // is the script properly loaded?
/// DOCME
wxPathList include_path;
/// DOCME
std::vector<Feature*> features;
Script(const wxString &_filename);
@ -301,13 +449,20 @@ namespace Automation4 {
};
// Manages loaded scripts; for whatever reason, multiple managers might be instantiated. In truth, this is more
// like a macro manager at the moment, since Export Filter and Subtitle Format are already managed by other
// classes.
/// DOCME
/// @class ScriptManager
/// @brief DOCME
///
/// DOCME
class ScriptManager {
private:
/// DOCME
std::vector<Script*> scripts;
/// DOCME
std::vector<FeatureMacro*> macros;
public:
@ -325,9 +480,16 @@ namespace Automation4 {
};
// Scans a directory for scripts and attempts to load all of them
/// DOCME
/// @class AutoloadScriptManager
/// @brief DOCME
///
/// DOCME
class AutoloadScriptManager : public ScriptManager {
private:
/// DOCME
wxString path;
public:
AutoloadScriptManager(const wxString &_path);
@ -335,15 +497,31 @@ namespace Automation4 {
};
// Script factory; each scripting engine should create exactly one instance of this object and register it.
// This is used to create Script objects from a file.
/// DOCME
/// @class ScriptFactory
/// @brief DOCME
///
/// DOCME
class ScriptFactory {
private:
/// DOCME
static std::vector<ScriptFactory*> *factories;
protected:
/// @brief DOCME
///
ScriptFactory() { }
/// @brief DOCME
///
virtual ~ScriptFactory() { }
/// DOCME
wxString engine_name;
/// DOCME
wxString filename_pattern;
public:
virtual Script* Produce(const wxString &filename) const = 0;
@ -357,10 +535,18 @@ namespace Automation4 {
static const std::vector<ScriptFactory*>& GetFactories();
};
// Dummy class for scripts that could not be loaded by the ScriptFactory
/// DOCME
/// @class UnknownScript
/// @brief DOCME
///
/// DOCME
class UnknownScript : public Script {
public:
UnknownScript(const wxString &filename);
/// @brief DOCME
///
void Reload() { };
};
@ -368,3 +554,4 @@ namespace Automation4 {
#endif

View file

@ -66,6 +66,8 @@
#include <assert.h>
#include <algorithm>
/// DOCME
namespace Automation4 {
// LuaStackcheck
@ -104,10 +106,26 @@ namespace Automation4 {
~LuaStackcheck() { check_stack(0); }
};
#else
/// DOCME
struct LuaStackcheck {
/// @brief DOCME
/// @param additional
///
void check_stack(int additional) { }
/// @brief DOCME
///
void dump() { }
/// @brief DOCME
/// @param L
///
LuaStackcheck(lua_State *L) { }
/// @brief DOCME
///
~LuaStackcheck() { }
};
#endif
@ -115,6 +133,10 @@ namespace Automation4 {
// LuaScript
/// @brief DOCME
/// @param filename
///
LuaScript::LuaScript(const wxString &filename)
: Script(filename)
, L(0)
@ -122,11 +144,17 @@ namespace Automation4 {
Create();
}
/// @brief DOCME
///
LuaScript::~LuaScript()
{
if (L) Destroy();
}
/// @brief DOCME
///
void LuaScript::Create()
{
Destroy();
@ -265,6 +293,10 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @return
///
void LuaScript::Destroy()
{
// Assume the script object is clean if there's no Lua state
@ -284,12 +316,20 @@ namespace Automation4 {
loaded = false;
}
/// @brief DOCME
///
void LuaScript::Reload()
{
Destroy();
Create();
}
/// @brief DOCME
/// @param L
/// @return
///
LuaScript* LuaScript::GetScriptObject(lua_State *L)
{
lua_getfield(L, LUA_REGISTRYINDEX, "aegisub");
@ -298,6 +338,11 @@ namespace Automation4 {
return (LuaScript*)ptr;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaScript::LuaTextExtents(lua_State *L)
{
if (!lua_istable(L, 1)) {
@ -336,6 +381,11 @@ namespace Automation4 {
return 4;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaScript::LuaInclude(lua_State *L)
{
LuaScript *s = GetScriptObject(L);
@ -374,6 +424,11 @@ namespace Automation4 {
return lua_gettop(L) - pretop;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaScript::LuaFrameFromMs(lua_State *L)
{
int ms = (int)lua_tonumber(L, -1);
@ -387,6 +442,11 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaScript::LuaMsFromFrame(lua_State *L)
{
int frame = (int)lua_tonumber(L, -1);
@ -400,6 +460,11 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaScript::LuaVideoSize(lua_State *L)
{
VideoContext *ctx = VideoContext::Get();
@ -418,6 +483,12 @@ namespace Automation4 {
// LuaThreadedCall
/// @brief DOCME
/// @param _L
/// @param _nargs
/// @param _nresults
///
LuaThreadedCall::LuaThreadedCall(lua_State *_L, int _nargs, int _nresults)
: wxThread(wxTHREAD_JOINABLE)
, L(_L)
@ -434,6 +505,10 @@ namespace Automation4 {
Run();
}
/// @brief DOCME
/// @return
///
wxThread::ExitCode LuaThreadedCall::Entry()
{
int result = lua_pcall(L, nargs, nresults, 0);
@ -466,12 +541,21 @@ namespace Automation4 {
// LuaFeature
/// @brief DOCME
/// @param _L
/// @param _featureclass
/// @param _name
///
LuaFeature::LuaFeature(lua_State *_L, ScriptFeatureClass _featureclass, const wxString &_name)
: Feature(_featureclass, _name)
, L(_L)
{
}
/// @brief DOCME
///
void LuaFeature::RegisterFeature()
{
// get the LuaScript objects
@ -493,6 +577,10 @@ namespace Automation4 {
lua_pop(L, 1);
}
/// @brief DOCME
/// @param functionid
///
void LuaFeature::GetFeatureFunction(int functionid)
{
// get feature table
@ -505,6 +593,10 @@ namespace Automation4 {
lua_remove(L, -2);
}
/// @brief DOCME
/// @param ints
///
void LuaFeature::CreateIntegerArray(const std::vector<int> &ints)
{
// create an array-style table with an integer vector in it
@ -516,6 +608,9 @@ namespace Automation4 {
}
}
/// @brief DOCME
///
void LuaFeature::ThrowError()
{
wxString err(lua_tostring(L, -1), wxConvUTF8);
@ -526,6 +621,11 @@ namespace Automation4 {
// LuaFeatureMacro
/// @brief DOCME
/// @param L
/// @return
///
int LuaFeatureMacro::LuaRegister(lua_State *L)
{
wxString _name(lua_tostring(L, 1), wxConvUTF8);
@ -537,6 +637,12 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param _name
/// @param _description
/// @param _L
///
LuaFeatureMacro::LuaFeatureMacro(const wxString &_name, const wxString &_description, lua_State *_L)
: Feature(SCRIPTFEATURE_MACRO, _name)
, FeatureMacro(_name, _description)
@ -561,6 +667,13 @@ namespace Automation4 {
lua_pop(L, 1);
}
/// @brief DOCME
/// @param subs
/// @param selected
/// @param active
/// @return
///
bool LuaFeatureMacro::Validate(AssFile *subs, const std::vector<int> &selected, int active)
{
if (no_validate)
@ -591,6 +704,14 @@ namespace Automation4 {
return result;
}
/// @brief DOCME
/// @param subs
/// @param selected
/// @param active
/// @param progress_parent
/// @return
///
void LuaFeatureMacro::Process(AssFile *subs, std::vector<int> &selected, int active, wxWindow * const progress_parent)
{
GetFeatureFunction(1); // 1 = processing function
@ -636,6 +757,13 @@ namespace Automation4 {
// LuaFeatureFilter
/// @brief DOCME
/// @param _name
/// @param _description
/// @param merit
/// @param _L
///
LuaFeatureFilter::LuaFeatureFilter(const wxString &_name, const wxString &_description, int merit, lua_State *_L)
: Feature(SCRIPTFEATURE_FILTER, _name)
, FeatureFilter(_name, _description, merit)
@ -656,11 +784,19 @@ namespace Automation4 {
lua_pop(L, 1);
}
/// @brief DOCME
///
void LuaFeatureFilter::Init()
{
// Don't think there's anything to do here... (empty in auto3)
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaFeatureFilter::LuaRegister(lua_State *L)
{
wxString _name(lua_tostring(L, 1), wxConvUTF8);
@ -673,6 +809,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param subs
/// @param export_dialog
///
void LuaFeatureFilter::ProcessSubs(AssFile *subs, wxWindow *export_dialog)
{
LuaStackcheck stackcheck(L);
@ -719,6 +860,11 @@ namespace Automation4 {
delete ps;
}
/// @brief DOCME
/// @param parent
/// @return
///
ScriptConfigDialog* LuaFeatureFilter::GenerateConfigDialog(wxWindow *parent)
{
if (!has_config)
@ -749,6 +895,12 @@ namespace Automation4 {
// LuaProgressSink
/// @brief DOCME
/// @param _L
/// @param parent
/// @param allow_config_dialog
///
LuaProgressSink::LuaProgressSink(lua_State *_L, wxWindow *parent, bool allow_config_dialog)
: ProgressSink(parent)
, L(_L)
@ -802,6 +954,9 @@ namespace Automation4 {
lua_pop(L, 2);
}
/// @brief DOCME
///
LuaProgressSink::~LuaProgressSink()
{
// remove progress reporting stuff
@ -815,6 +970,12 @@ namespace Automation4 {
lua_setfield(L, LUA_REGISTRYINDEX, "progress_sink");
}
/// @brief DOCME
/// @param L
/// @param idx
/// @return
///
LuaProgressSink* LuaProgressSink::GetObjPointer(lua_State *L, int idx)
{
assert(lua_type(L, idx) == LUA_TUSERDATA);
@ -822,6 +983,11 @@ namespace Automation4 {
return *((LuaProgressSink**)ud);
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaProgressSink::LuaSetProgress(lua_State *L)
{
LuaProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1));
@ -830,6 +996,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaProgressSink::LuaSetTask(lua_State *L)
{
LuaProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1));
@ -838,6 +1009,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaProgressSink::LuaSetTitle(lua_State *L)
{
LuaProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1));
@ -846,6 +1022,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaProgressSink::LuaGetCancelled(lua_State *L)
{
LuaProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1));
@ -853,6 +1034,11 @@ namespace Automation4 {
return 1;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaProgressSink::LuaDebugOut(lua_State *L)
{
LuaProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1));
@ -887,6 +1073,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaProgressSink::LuaDisplayDialog(lua_State *L)
{
LuaProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1));
@ -919,10 +1110,18 @@ namespace Automation4 {
return dlg.LuaReadBack(L);
}
// Factory methods
/// @brief // Factory methods
///
LuaScriptFactory::LuaScriptFactory() {}
/// @brief DOCME
///
LuaScriptFactory::~LuaScriptFactory() {}
/// @brief DOCME
///
void LuaScriptFactory::RegisterFactory ()
{
engine_name = _T("Lua");
@ -930,6 +1129,10 @@ namespace Automation4 {
Register(this);
}
/// @brief DOCME
/// @param filename
///
Script* LuaScriptFactory::Produce(const wxString &filename) const
{
// Just check if file extension is .lua
@ -945,3 +1148,4 @@ namespace Automation4 {
#endif // WITH_AUTO4_LUA

View file

@ -37,6 +37,8 @@
#pragma once
#ifndef _AUTO4_LUA_H
/// DOCME
#define _AUTO4_LUA_H
#include "auto4_base.h"
@ -52,20 +54,38 @@
class wxWindow;
/// DOCME
namespace Automation4 {
// Provides access to an AssFile object (and all lines contained) for a Lua script
/// DOCME
/// @class LuaAssFile
/// @brief DOCME
///
/// DOCME
class LuaAssFile {
private:
/// DOCME
AssFile *ass;
/// DOCME
lua_State *L;
/// DOCME
bool can_modify;
/// DOCME
bool can_set_undo;
void CheckAllowModify(); // throws an error if modification is disallowed
// keep a cursor of last accessed item to avoid walking over the entire file on every access
/// DOCME
std::list<AssEntry*>::iterator last_entry_ptr;
/// DOCME
int last_entry_id;
void GetAssEntry(int n); // set last_entry_ptr to point to item n
@ -94,9 +114,16 @@ namespace Automation4 {
};
// Provides progress UI and control functions for a Lua script
/// DOCME
/// @class LuaProgressSink
/// @brief DOCME
///
/// DOCME
class LuaProgressSink : public ProgressSink {
private:
/// DOCME
lua_State *L;
static int LuaSetProgress(lua_State *L);
@ -114,38 +141,96 @@ namespace Automation4 {
};
// Provides Config UI functions for a Lua script
/// DOCME
/// @class LuaConfigDialogControl
/// @brief DOCME
///
/// DOCME
class LuaConfigDialogControl {
public:
/// DOCME
wxControl *cw; // control window
/// DOCME
/// DOCME
wxString name, hint;
/// DOCME
/// DOCME
/// DOCME
/// DOCME
int x, y, width, height;
virtual wxControl *Create(wxWindow *parent) = 0;
virtual void ControlReadBack() = 0;
virtual void LuaReadBack(lua_State *L) = 0;
/// @brief DOCME
/// @return
///
virtual bool CanSerialiseValue() { return false; }
/// @brief DOCME
/// @return
///
virtual wxString SerialiseValue() { return _T(""); }
/// @brief DOCME
/// @param serialised
///
virtual void UnserialiseValue(const wxString &serialised) { }
LuaConfigDialogControl(lua_State *L);
/// @brief DOCME
///
virtual ~LuaConfigDialogControl() { }
};
/// DOCME
/// @class LuaConfigDialog
/// @brief DOCME
///
/// DOCME
class LuaConfigDialog : public ScriptConfigDialog {
private:
/// DOCME
std::vector<LuaConfigDialogControl*> controls;
/// DOCME
std::vector<wxString> buttons;
/// DOCME
bool use_buttons;
/// DOCME
/// @class ButtonEventHandler
/// @brief DOCME
///
/// DOCME
class ButtonEventHandler : public wxEvtHandler {
public:
/// DOCME
int *button_pushed;
void OnButtonPush(wxCommandEvent &evt);
};
/// DOCME
ButtonEventHandler *button_event;
/// DOCME
int button_pushed;
protected:
@ -163,10 +248,19 @@ namespace Automation4 {
};
// Second base-class for Lua implemented Features
/// DOCME
/// @class LuaFeature
/// @brief DOCME
///
/// DOCME
class LuaFeature : public virtual Feature {
protected:
/// DOCME
lua_State *L;
/// DOCME
int myid;
LuaFeature(lua_State *_L, ScriptFeatureClass _featureclass, const wxString &_name);
@ -179,11 +273,18 @@ namespace Automation4 {
};
// Class of Lua scripts
/// DOCME
/// @class LuaScript
/// @brief DOCME
///
/// DOCME
class LuaScript : public Script {
friend class LuaFeature;
private:
/// DOCME
lua_State *L;
void Create(); // load script and create internal structures etc.
@ -205,12 +306,22 @@ namespace Automation4 {
};
// A single call to a Lua function, run inside a separate thread.
// This object should be created on the stack in the function that does the call.
/// DOCME
/// @class LuaThreadedCall
/// @brief DOCME
///
/// DOCME
class LuaThreadedCall : public wxThread {
private:
/// DOCME
lua_State *L;
/// DOCME
int nargs;
/// DOCME
int nresults;
public:
LuaThreadedCall(lua_State *_L, int _nargs, int _nresults);
@ -218,14 +329,24 @@ namespace Automation4 {
};
// Implementation of the Macro Feature for Lua scripts
/// DOCME
/// @class LuaFeatureMacro
/// @brief DOCME
///
/// DOCME
class LuaFeatureMacro : public FeatureMacro, LuaFeature {
private:
/// DOCME
bool no_validate;
protected:
LuaFeatureMacro(const wxString &_name, const wxString &_description, lua_State *_L);
public:
static int LuaRegister(lua_State *L);
/// @brief DOCME
///
virtual ~LuaFeatureMacro() { }
virtual bool Validate(AssFile *subs, const std::vector<int> &selected, int active);
@ -233,10 +354,19 @@ namespace Automation4 {
};
// Implementation of the Export Filter Feature for Lua scripts
/// DOCME
/// @class LuaFeatureFilter
/// @brief DOCME
///
/// DOCME
class LuaFeatureFilter : public FeatureFilter, LuaFeature {
private:
/// DOCME
bool has_config;
/// DOCME
LuaConfigDialog *config_dialog;
protected:
@ -248,6 +378,9 @@ namespace Automation4 {
public:
static int LuaRegister(lua_State *L);
/// @brief DOCME
///
virtual ~LuaFeatureFilter() { }
void ProcessSubs(AssFile *subs, wxWindow *export_dialog);
@ -257,3 +390,4 @@ namespace Automation4 {
#endif

View file

@ -56,10 +56,16 @@
#include <assert.h>
#include <algorithm>
/// DOCME
namespace Automation4 {
// LuaAssFile
/// @brief DOCME
/// @return
///
void LuaAssFile::CheckAllowModify()
{
if (can_modify)
@ -68,6 +74,11 @@ namespace Automation4 {
lua_error(L);
}
/// @brief DOCME
/// @param L
/// @param e
///
void LuaAssFile::AssEntryToLua(lua_State *L, AssEntry *e)
{
lua_newtable(L);
@ -231,6 +242,11 @@ namespace Automation4 {
lua_setfield(L, -2, "class");
}
/// @brief DOCME
/// @param L
/// @return
///
AssEntry *LuaAssFile::LuaToAssEntry(lua_State *L)
{
// assume an assentry table is on the top of the stack
@ -254,6 +270,8 @@ namespace Automation4 {
AssEntry *result;
/// DOCME
#define GETSTRING(varname, fieldname, lineclass) \
lua_getfield(L, -1, fieldname); \
if (!lua_isstring(L, -1)) { \
@ -263,6 +281,8 @@ namespace Automation4 {
} \
wxString varname (lua_tostring(L, -1), wxConvUTF8); \
lua_pop(L, 1);
/// DOCME
#define GETFLOAT(varname, fieldname, lineclass) \
lua_getfield(L, -1, fieldname); \
if (!lua_isnumber(L, -1)) { \
@ -272,6 +292,8 @@ namespace Automation4 {
} \
float varname = lua_tonumber(L, -1); \
lua_pop(L, 1);
/// DOCME
#define GETINT(varname, fieldname, lineclass) \
lua_getfield(L, -1, fieldname); \
if (!lua_isnumber(L, -1)) { \
@ -281,6 +303,8 @@ namespace Automation4 {
} \
int varname = lua_tointeger(L, -1); \
lua_pop(L, 1);
/// DOCME
#define GETBOOL(varname, fieldname, lineclass) \
lua_getfield(L, -1, fieldname); \
if (!lua_isboolean(L, -1)) { \
@ -418,15 +442,27 @@ namespace Automation4 {
return 0;
}
/// DOCME
#undef GETSTRING
/// DOCME
#undef GETFLOAT
/// DOCME
#undef GETINT
/// DOCME
#undef GETBOOL
//lua_pop(L, 1); // the function shouldn't eat the table it converted
return result;
}
/// @brief DOCME
/// @param n
///
void LuaAssFile::GetAssEntry(int n)
{
entryIter e;
@ -460,6 +496,11 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::ObjectIndexRead(lua_State *L)
{
LuaAssFile *laf = GetObjPointer(L, 1);
@ -538,6 +579,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::ObjectIndexWrite(lua_State *L)
{
// instead of implementing everything twice, just call the other modification-functions from here
@ -593,6 +639,11 @@ namespace Automation4 {
}
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::ObjectGetLen(lua_State *L)
{
LuaAssFile *laf = GetObjPointer(L, 1);
@ -600,6 +651,11 @@ namespace Automation4 {
return 1;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::ObjectDelete(lua_State *L)
{
LuaAssFile *laf = GetObjPointer(L, lua_upvalueindex(1));
@ -648,6 +704,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::ObjectDeleteRange(lua_State *L)
{
LuaAssFile *laf = GetObjPointer(L, lua_upvalueindex(1));
@ -687,6 +748,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::ObjectAppend(lua_State *L)
{
LuaAssFile *laf = GetObjPointer(L, lua_upvalueindex(1));
@ -709,6 +775,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::ObjectInsert(lua_State *L)
{
LuaAssFile *laf = GetObjPointer(L, lua_upvalueindex(1));
@ -736,6 +807,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::ObjectGarbageCollect(lua_State *L)
{
LuaAssFile *laf = GetObjPointer(L, 1);
@ -744,6 +820,11 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::LuaParseTagData(lua_State *L)
{
lua_newtable(L);
@ -751,6 +832,11 @@ namespace Automation4 {
return 1;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::LuaUnparseTagData(lua_State *L)
{
lua_pushstring(L, "");
@ -758,6 +844,11 @@ namespace Automation4 {
return 1;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::LuaParseKaraokeData(lua_State *L)
{
AssEntry *e = LuaToAssEntry(L);
@ -887,6 +978,11 @@ namespace Automation4 {
return 1;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaAssFile::LuaSetUndoPoint(lua_State *L)
{
LuaAssFile *laf = GetObjPointer(L, lua_upvalueindex(1));
@ -907,6 +1003,12 @@ namespace Automation4 {
return 0;
}
/// @brief DOCME
/// @param L
/// @param idx
/// @return
///
LuaAssFile *LuaAssFile::GetObjPointer(lua_State *L, int idx)
{
assert(lua_type(L, idx) == LUA_TUSERDATA);
@ -914,10 +1016,20 @@ namespace Automation4 {
return *((LuaAssFile**)ud);
}
/// @brief DOCME
///
LuaAssFile::~LuaAssFile()
{
}
/// @brief DOCME
/// @param _L
/// @param _ass
/// @param _can_modify
/// @param _can_set_undo
///
LuaAssFile::LuaAssFile(lua_State *_L, AssFile *_ass, bool _can_modify, bool _can_set_undo)
: ass(_ass)
, L(_L)
@ -971,3 +1083,4 @@ namespace Automation4 {
#endif // WITH_AUTO4_LUA

View file

@ -61,11 +61,17 @@
#include "colour_button.h"
#include "ass_style.h"
/// DOCME
namespace Automation4 {
// LuaConfigDialogControl
/// @brief DOCME
/// @param L
///
LuaConfigDialogControl::LuaConfigDialogControl(lua_State *L)
{
// Assume top of stack is a control table (don't do checking)
@ -125,14 +131,28 @@ namespace Automation4 {
wxLogDebug(_T("created control: '%s', (%d,%d)(%d,%d), '%s'"), name.c_str(), x, y, width, height, hint.c_str());
}
/// DOCME
namespace LuaControl {
// Label
/// DOCME
/// @class Label
/// @brief DOCME
///
/// DOCME
class Label : public LuaConfigDialogControl {
public:
/// DOCME
wxString label;
/// @brief DOCME
/// @param L
///
Label(lua_State *L)
: LuaConfigDialogControl(L)
{
@ -141,20 +161,35 @@ namespace Automation4 {
lua_pop(L, 1);
}
/// @brief DOCME
///
virtual ~Label() { }
// Doesn't have a serialisable value so don't implement that sub-interface
/// @brief DOCME
/// @param parent
/// @return
///
wxControl *Create(wxWindow *parent)
{
return cw = new wxStaticText(parent, -1, label);
}
/// @brief DOCME
///
void ControlReadBack()
{
// Nothing here
}
/// @brief DOCME
/// @param L
///
void LuaReadBack(lua_State *L)
{
// Label doesn't produce output, so let it be nil
@ -165,10 +200,22 @@ namespace Automation4 {
// Basic edit
/// DOCME
/// @class Edit
/// @brief DOCME
///
/// DOCME
class Edit : public LuaConfigDialogControl {
public:
/// DOCME
wxString text;
/// @brief DOCME
/// @param L
///
Edit(lua_State *L)
: LuaConfigDialogControl(L)
{
@ -185,23 +232,43 @@ namespace Automation4 {
lua_pop(L, 1);
}
/// @brief DOCME
///
virtual ~Edit() { }
/// @brief DOCME
/// @return
///
bool CanSerialiseValue()
{
return true;
}
/// @brief DOCME
/// @return
///
wxString SerialiseValue()
{
return inline_string_encode(text);
}
/// @brief DOCME
/// @param serialised
///
void UnserialiseValue(const wxString &serialised)
{
text = inline_string_decode(serialised);
}
/// @brief DOCME
/// @param parent
/// @return
///
wxControl *Create(wxWindow *parent)
{
cw = new wxTextCtrl(parent, -1, text, wxDefaultPosition, wxDefaultSize, 0);
@ -209,11 +276,18 @@ namespace Automation4 {
return cw;
}
/// @brief DOCME
///
void ControlReadBack()
{
text = ((wxTextCtrl*)cw)->GetValue();
}
/// @brief DOCME
/// @param L
///
void LuaReadBack(lua_State *L)
{
lua_pushstring(L, text.mb_str(wxConvUTF8));
@ -222,10 +296,22 @@ namespace Automation4 {
};
/// DOCME
/// @class Color
/// @brief DOCME
///
/// DOCME
class Color : public LuaConfigDialogControl {
public:
/// DOCME
wxString text;
/// @brief DOCME
/// @param L
///
Color(lua_State *L)
: LuaConfigDialogControl(L)
{
@ -234,23 +320,43 @@ namespace Automation4 {
lua_pop(L, 1);
}
/// @brief DOCME
///
virtual ~Color() { }
/// @brief DOCME
/// @return
///
bool CanSerialiseValue()
{
return true;
}
/// @brief DOCME
/// @return
///
wxString SerialiseValue()
{
return inline_string_encode(text);
}
/// @brief DOCME
/// @param serialised
///
void UnserialiseValue(const wxString &serialised)
{
text = inline_string_decode(serialised);
}
/// @brief DOCME
/// @param parent
/// @return
///
wxControl *Create(wxWindow *parent)
{
AssColor colour;
@ -260,11 +366,18 @@ namespace Automation4 {
return cw;
}
/// @brief DOCME
///
void ControlReadBack()
{
text = ((ColourButton*)cw)->GetColour().GetAsString(wxC2S_HTML_SYNTAX);
}
/// @brief DOCME
/// @param L
///
void LuaReadBack(lua_State *L)
{
lua_pushstring(L, text.mb_str(wxConvUTF8));
@ -276,19 +389,37 @@ namespace Automation4 {
// Multiline edit
/// DOCME
/// @class Textbox
/// @brief DOCME
///
/// DOCME
class Textbox : public Edit {
public:
/// @brief DOCME
/// @param L
///
Textbox(lua_State *L)
: Edit(L)
{
// Nothing more
}
/// @brief DOCME
///
virtual ~Textbox() { }
// Same serialisation interface as single-line edit
/// @brief DOCME
/// @param parent
/// @return
///
wxControl *Create(wxWindow *parent)
{
cw = new wxTextCtrl(parent, -1, text, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
@ -302,12 +433,30 @@ namespace Automation4 {
// Integer only edit
/// DOCME
/// @class IntEdit
/// @brief DOCME
///
/// DOCME
class IntEdit : public Edit {
public:
/// DOCME
int value;
/// DOCME
bool hasspin;
/// DOCME
/// DOCME
int min, max;
/// @brief DOCME
/// @param L
///
IntEdit(lua_State *L)
: Edit(L)
{
@ -341,18 +490,33 @@ nospin:
}
}
/// @brief DOCME
///
virtual ~IntEdit() { }
/// @brief DOCME
/// @return
///
bool CanSerialiseValue()
{
return true;
}
/// @brief DOCME
/// @return
///
wxString SerialiseValue()
{
return wxString::Format(_T("%d"), value);
}
/// @brief DOCME
/// @param serialised
///
void UnserialiseValue(const wxString &serialised)
{
long tmp;
@ -360,6 +524,11 @@ nospin:
value = tmp;
}
/// @brief DOCME
/// @param parent
/// @return
///
wxControl *Create(wxWindow *parent)
{
wxSpinCtrl *scw = new wxSpinCtrl(parent, -1, wxString::Format(_T("%d"), value), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, value);
@ -368,11 +537,18 @@ nospin:
return cw;
}
/// @brief DOCME
///
void ControlReadBack()
{
value = ((wxSpinCtrl*)cw)->GetValue();
}
/// @brief DOCME
/// @param L
///
void LuaReadBack(lua_State *L)
{
lua_pushinteger(L, value);
@ -383,13 +559,31 @@ nospin:
// Float only edit
/// DOCME
/// @class FloatEdit
/// @brief DOCME
///
/// DOCME
class FloatEdit : public Edit {
public:
/// DOCME
float value;
/// DOCME
bool hasspin;
/// DOCME
/// DOCME
float min, max;
// FIXME: Can't support spin button atm
/// @brief DOCME
/// @param L
///
FloatEdit(lua_State *L)
: Edit(L)
{
@ -400,18 +594,33 @@ nospin:
// TODO: spin button support
}
/// @brief DOCME
///
virtual ~FloatEdit() { }
/// @brief DOCME
/// @return
///
bool CanSerialiseValue()
{
return true;
}
/// @brief DOCME
/// @return
///
wxString SerialiseValue()
{
return PrettyFloatF(value);
}
/// @brief DOCME
/// @param serialised
///
void UnserialiseValue(const wxString &serialised)
{
double tmp;
@ -419,7 +628,14 @@ nospin:
value = (float)tmp;
}
/// DOCME
typedef wxValidator FloatTextValidator;
/// @brief DOCME
/// @param parent
/// @return
///
wxControl *Create(wxWindow *parent)
{
cw = new wxTextCtrl(parent, -1, PrettyFloatF(value), wxDefaultPosition, wxDefaultSize, 0); //, FloatTextValidator());
@ -427,6 +643,9 @@ nospin:
return cw;
}
/// @brief DOCME
///
void ControlReadBack()
{
double newval;
@ -436,6 +655,10 @@ nospin:
}
}
/// @brief DOCME
/// @param L
///
void LuaReadBack(lua_State *L)
{
lua_pushnumber(L, value);
@ -446,11 +669,25 @@ nospin:
// Dropdown
/// DOCME
/// @class Dropdown
/// @brief DOCME
///
/// DOCME
class Dropdown : public LuaConfigDialogControl {
public:
/// DOCME
wxArrayString items;
/// DOCME
wxString value;
/// @brief DOCME
/// @param L
///
Dropdown(lua_State *L)
: LuaConfigDialogControl(L)
{
@ -469,23 +706,43 @@ nospin:
lua_pop(L, 1);
}
/// @brief DOCME
///
virtual ~Dropdown() { }
/// @brief DOCME
/// @return
///
bool CanSerialiseValue()
{
return true;
}
/// @brief DOCME
/// @return
///
wxString SerialiseValue()
{
return inline_string_encode(value);
}
/// @brief DOCME
/// @param serialised
///
void UnserialiseValue(const wxString &serialised)
{
value = inline_string_decode(serialised);
}
/// @brief DOCME
/// @param parent
/// @return
///
wxControl *Create(wxWindow *parent)
{
cw = new wxComboBox(parent, -1, value, wxDefaultPosition, wxDefaultSize, items, wxCB_READONLY);
@ -493,11 +750,18 @@ nospin:
return cw;
}
/// @brief DOCME
///
void ControlReadBack()
{
value = ((wxComboBox*)cw)->GetValue();
}
/// @brief DOCME
/// @param L
///
void LuaReadBack(lua_State *L)
{
lua_pushstring(L, value.mb_str(wxConvUTF8));
@ -508,11 +772,25 @@ nospin:
// Checkbox
/// DOCME
/// @class Checkbox
/// @brief DOCME
///
/// DOCME
class Checkbox : public LuaConfigDialogControl {
public:
/// DOCME
wxString label;
/// DOCME
bool value;
/// @brief DOCME
/// @param L
///
Checkbox(lua_State *L)
: LuaConfigDialogControl(L)
{
@ -525,24 +803,44 @@ nospin:
lua_pop(L, 1);
}
/// @brief DOCME
///
virtual ~Checkbox() { }
/// @brief DOCME
/// @return
///
bool CanSerialiseValue()
{
return true;
}
/// @brief DOCME
/// @return
///
wxString SerialiseValue()
{
return value ? _T("1") : _T("0");
}
/// @brief DOCME
/// @param serialised
///
void UnserialiseValue(const wxString &serialised)
{
// fixme? should this allow more different "false" values?
value = (serialised == _T("0")) ? false : true;
}
/// @brief DOCME
/// @param parent
/// @return
///
wxControl *Create(wxWindow *parent)
{
cw = new wxCheckBox(parent, -1, label);
@ -551,11 +849,18 @@ nospin:
return cw;
}
/// @brief DOCME
///
void ControlReadBack()
{
value = ((wxCheckBox*)cw)->GetValue();
}
/// @brief DOCME
/// @param L
///
void LuaReadBack(lua_State *L)
{
lua_pushboolean(L, value);
@ -568,6 +873,11 @@ nospin:
// LuaConfigDialog
/// @brief DOCME
/// @param L
/// @param include_buttons
///
LuaConfigDialog::LuaConfigDialog(lua_State *L, bool include_buttons)
: use_buttons(include_buttons)
{
@ -653,12 +963,20 @@ badcontrol:
}
}
/// @brief DOCME
///
LuaConfigDialog::~LuaConfigDialog()
{
for (size_t i = 0; i < controls.size(); ++i)
delete controls[i];
}
/// @brief DOCME
/// @param parent
/// @return
///
wxWindow* LuaConfigDialog::CreateWindow(wxWindow *parent)
{
wxWindow *w = new wxPanel(parent);
@ -706,6 +1024,11 @@ badcontrol:
return w;
}
/// @brief DOCME
/// @param L
/// @return
///
int LuaConfigDialog::LuaReadBack(lua_State *L)
{
// First read back which button was pressed, if any
@ -740,6 +1063,10 @@ badcontrol:
}
}
/// @brief DOCME
/// @return
///
wxString LuaConfigDialog::Serialise()
{
if (controls.size() == 0)
@ -763,6 +1090,10 @@ badcontrol:
return res;
}
/// @brief DOCME
/// @param serialised
///
void LuaConfigDialog::Unserialise(const wxString &serialised)
{
// Split by pipe
@ -782,6 +1113,9 @@ badcontrol:
}
}
/// @brief DOCME
///
void LuaConfigDialog::ReadBack()
{
for (size_t i = 0; i < controls.size(); ++i) {
@ -789,6 +1123,10 @@ badcontrol:
}
}
/// @brief DOCME
/// @param evt
///
void LuaConfigDialog::ButtonEventHandler::OnButtonPush(wxCommandEvent &evt)
{
// Let button_pushed == 0 mean "cancelled", such that pushing Cancel or closing the dialog
@ -818,3 +1156,4 @@ badcontrol:
#endif // WITH_AUTO4_LUA

View file

@ -37,13 +37,22 @@
#pragma once
#ifndef _AUTO4_LUA_FACTORY_H
/// DOCME
#define _AUTO4_LUA_FACTORY_H
#include "auto4_base.h"
/// DOCME
namespace Automation4 {
// Factory class for Lua scripts
/// DOCME
/// @class LuaScriptFactory
/// @brief DOCME
///
/// DOCME
class LuaScriptFactory : public ScriptFactory {
public:
LuaScriptFactory();
@ -56,3 +65,4 @@ namespace Automation4 {
#endif

View file

@ -40,9 +40,14 @@
#include "auto4_lua_scriptreader.h"
/// DOCME
namespace Automation4 {
// LuaScriptReader
/// @brief // LuaScriptReader
/// @param filename
///
LuaScriptReader::LuaScriptReader(const wxString &filename)
{
#ifdef WIN32
@ -56,6 +61,9 @@ namespace Automation4 {
databuf = new char[bufsize];
}
/// @brief DOCME
///
LuaScriptReader::~LuaScriptReader()
{
if (databuf)
@ -63,6 +71,12 @@ namespace Automation4 {
fclose(f);
}
/// @brief DOCME
/// @param L
/// @param data
/// @param size
///
const char* LuaScriptReader::reader_func(lua_State *L, void *data, size_t *size)
{
LuaScriptReader *self = (LuaScriptReader*)(data);
@ -113,3 +127,4 @@ namespace Automation4 {
#endif // WITH_AUTO4_LUA

View file

@ -43,13 +43,24 @@
#include "lua.hpp"
#endif
/// DOCME
namespace Automation4 {
// Manage reading in a Lua script file
/// DOCME
struct LuaScriptReader {
/// DOCME
FILE *f;
/// DOCME
bool first;
/// DOCME
char *databuf;
/// DOCME
static const size_t bufsize = 512;
LuaScriptReader(const wxString &filename);
~LuaScriptReader();
@ -61,3 +72,4 @@ namespace Automation4 {

View file

@ -47,7 +47,13 @@
#ifdef DEBUG_AVISYNTH_CODE
#include "main.h"
#include "wx/textfile.h"
/// DOCME
wxTextFile avs_trace_file;
/// @brief DOCME
/// @param s
///
void DoAvsTrace(const wxString &s)
{
if (!avs_trace_file.IsOpened()) {
@ -63,16 +69,23 @@ void DoAvsTrace(const wxString &s)
#endif
///////////////////////////////
// Static field initialization
/// DOCME
int AviSynthWrapper::avs_refcount = 0;
/// DOCME
HINSTANCE AviSynthWrapper::hLib = NULL;
/// DOCME
IScriptEnvironment *AviSynthWrapper::env = NULL;
/// DOCME
wxMutex AviSynthWrapper::AviSynthMutex;
////////////////////////
// AviSynth constructor
/// @brief AviSynth constructor
///
AviSynthWrapper::AviSynthWrapper() {
if (!avs_refcount) {
AVSTRACE(_T("Avisynth not loaded, trying to load it now..."));
@ -116,8 +129,9 @@ AviSynthWrapper::AviSynthWrapper() {
}
///////////////////////
// AviSynth destructor
/// @brief AviSynth destructor
///
AviSynthWrapper::~AviSynthWrapper() {
AVSTRACE(_T("Decreasing reference count"));
if (!--avs_refcount) {
@ -130,11 +144,13 @@ AviSynthWrapper::~AviSynthWrapper() {
}
///////////////////
// Get environment
/// @brief Get environment
///
IScriptEnvironment *AviSynthWrapper::GetEnv() {
return env;
}
#endif

View file

@ -36,6 +36,8 @@
#ifndef AVISYNTH_WRAP_H
/// DOCME
#define AVISYNTH_WRAP_H
@ -48,8 +50,8 @@
#include "avisynth.h"
//////////////////////////////////
// Typedef to make my life easier
/// DOCME
typedef IScriptEnvironment* __stdcall FUNC(int);
@ -57,21 +59,37 @@ typedef IScriptEnvironment* __stdcall FUNC(int);
// Avisynth debugging stuff
#ifdef DEBUG_AVISYNTH_CODE
void DoAvsTrace(const wxString &s);
/// DOCME
#define AVSTRACE(s) DoAvsTrace(s)
#else
/// DOCME
#define AVSTRACE(s)
#endif
///////////////////////////
// AviSynth wrapping class
/// DOCME
/// @class AviSynthWrapper
/// @brief DOCME
///
/// DOCME
class AviSynthWrapper {
private:
/// DOCME
static int avs_refcount;
/// DOCME
static HINSTANCE hLib;
protected:
/// DOCME
static IScriptEnvironment *env;
public:
/// DOCME
static wxMutex AviSynthMutex;
IScriptEnvironment *GetEnv();
@ -82,3 +100,4 @@ public:
#endif
#endif

View file

@ -55,8 +55,15 @@
#include "audio_display.h"
///////////////
// Constructor
/// @brief Constructor
/// @param parent
/// @param id
/// @param pos
/// @param size
/// @param style
/// @param name
///
BaseGrid::BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
: wxWindow(parent, id, pos, size, style, name)
{
@ -84,15 +91,17 @@ BaseGrid::BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wx
}
//////////////
// Destructor
/// @brief Destructor
///
BaseGrid::~BaseGrid() {
delete bmp;
}
////////////////
// Update style
/// @brief Update style
///
void BaseGrid::UpdateStyle() {
// Set font
wxString fontname = Options.AsText(_T("Grid Font Face"));
@ -120,8 +129,9 @@ void BaseGrid::UpdateStyle() {
}
///////////////
// Clears grid
/// @brief Clears grid
///
void BaseGrid::Clear () {
diagMap.clear();
diagPtrMap.clear();
@ -131,23 +141,29 @@ void BaseGrid::Clear () {
}
///////////////
// Begin batch
/// @brief Begin batch
///
void BaseGrid::BeginBatch() {
//Freeze();
}
/////////////
// End batch
/// @brief End batch
///
void BaseGrid::EndBatch() {
//Thaw();
AdjustScrollbar();
}
//////////////////////
// Makes cell visible
/// @brief Makes cell visible
/// @param row
/// @param col
/// @param center
///
void BaseGrid::MakeCellVisible(int row, int col,bool center) {
// Update last row selection
lastRow = row;
@ -176,8 +192,12 @@ void BaseGrid::MakeCellVisible(int row, int col,bool center) {
}
////////////////
// Select a row
/// @brief Select a row
/// @param row
/// @param addToSelected
/// @param select
///
void BaseGrid::SelectRow(int row, bool addToSelected, bool select) {
// Sanity checking
if (row >= GetRows()) row = GetRows()-1;
@ -203,8 +223,9 @@ void BaseGrid::SelectRow(int row, bool addToSelected, bool select) {
}
/////////////////////////
// Selects visible lines
/// @brief Selects visible lines
///
void BaseGrid::SelectVisible() {
int rows = GetRows();
bool selectedOne = false;
@ -223,8 +244,9 @@ void BaseGrid::SelectVisible() {
}
///////////////////////
// Unselects all cells
/// @brief Unselects all cells
///
void BaseGrid::ClearSelection() {
int rows = selMap.size();
for (int i=0;i<rows;i++) {
@ -234,8 +256,12 @@ void BaseGrid::ClearSelection() {
}
/////////////////////////
// Is cell in selection?
/// @brief Is cell in selection?
/// @param row
/// @param col
/// @return
///
bool BaseGrid::IsInSelection(int row, int col) const {
if (row >= GetRows() || row < 0) return false;
(void) col;
@ -248,8 +274,10 @@ bool BaseGrid::IsInSelection(int row, int col) const {
}
///////////////////////////
// Number of selected rows
/// @brief Number of selected rows
/// @return
///
int BaseGrid::GetNumberSelection() {
int count = 0;
int rows = selMap.size();
@ -260,8 +288,10 @@ int BaseGrid::GetNumberSelection() {
}
///////////////////////////
// Gets first selected row
/// @brief Gets first selected row
/// @return
///
int BaseGrid::GetFirstSelRow() {
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
@ -273,8 +303,10 @@ int BaseGrid::GetFirstSelRow() {
}
/////////////////////////////////////////////////////
// Gets last selected row from first block selection
/// @brief Gets last selected row from first block selection
/// @return
///
int BaseGrid::GetLastSelRow() {
int frow = GetFirstSelRow();
while (IsInSelection(frow)) {
@ -284,8 +316,11 @@ int BaseGrid::GetLastSelRow() {
}
//////////////////////////
// Gets all selected rows
/// @brief Gets all selected rows
/// @param cont
/// @return
///
wxArrayInt BaseGrid::GetSelection(bool *cont) {
// Prepare
int nrows = GetRows();
@ -308,8 +343,10 @@ wxArrayInt BaseGrid::GetSelection(bool *cont) {
}
//////////////////////
// Get number of rows
/// @brief Get number of rows
/// @return
///
int BaseGrid::GetRows() const {
return diagMap.size();
}
@ -326,8 +363,10 @@ BEGIN_EVENT_TABLE(BaseGrid,wxWindow)
END_EVENT_TABLE()
///////////////
// Paint event
/// @brief Paint event
/// @param event
///
void BaseGrid::OnPaint (wxPaintEvent &event) {
// Prepare
wxPaintDC dc(this);
@ -362,8 +401,10 @@ void BaseGrid::OnPaint (wxPaintEvent &event) {
}
//////////////
// Draw image
/// @brief Draw image
/// @param dc
///
void BaseGrid::DrawImage(wxDC &dc) {
// Get size and pos
int w = 0;
@ -578,8 +619,10 @@ void BaseGrid::DrawImage(wxDC &dc) {
}
///////////
// On size
/// @brief On size
/// @param event
///
void BaseGrid::OnSize(wxSizeEvent &event) {
AdjustScrollbar();
SetColumnWidths();
@ -587,8 +630,10 @@ void BaseGrid::OnSize(wxSizeEvent &event) {
}
/////////////
// On scroll
/// @brief On scroll
/// @param event
///
void BaseGrid::OnScroll(wxScrollEvent &event) {
int newPos = event.GetPosition();
if (yPos != newPos) {
@ -598,8 +643,11 @@ void BaseGrid::OnScroll(wxScrollEvent &event) {
}
////////////////
// Mouse events
/// @brief Mouse events
/// @param event
/// @return
///
void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
// Window size
int w,h;
@ -733,8 +781,10 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
}
/////////////
// Scroll to
/// @brief Scroll to
/// @param y
///
void BaseGrid::ScrollTo(int y) {
int w,h;
GetClientSize(&w,&h);
@ -747,8 +797,9 @@ void BaseGrid::ScrollTo(int y) {
}
////////////////////
// Adjust scrollbar
/// @brief Adjust scrollbar
///
void BaseGrid::AdjustScrollbar() {
// Variables
int w,h,sw,sh;
@ -775,8 +826,10 @@ void BaseGrid::AdjustScrollbar() {
}
/////////////////////
// Set column widths
/// @brief Set column widths
/// @return
///
void BaseGrid::SetColumnWidths() {
if (!IsShownOnScreen()) return;
@ -909,8 +962,11 @@ void BaseGrid::SetColumnWidths() {
}
//////////////////////////
// Gets dialogue from map
/// @brief Gets dialogue from map
/// @param n
/// @return
///
AssDialogue *BaseGrid::GetDialogue(int n) {
try {
if (n < 0) return NULL;
@ -924,8 +980,11 @@ AssDialogue *BaseGrid::GetDialogue(int n) {
}
////////////////////////////////////
// Check if line is being displayed
/// @brief Check if line is being displayed
/// @param line
/// @return
///
bool BaseGrid::IsDisplayed(AssDialogue *line) {
if (!VideoContext::Get()->IsLoaded()) return false;
int f1 = VFR_Output.GetFrameAtTime(line->Start.GetMS(),true);
@ -935,8 +994,9 @@ bool BaseGrid::IsDisplayed(AssDialogue *line) {
}
///////////////
// Update maps
/// @brief Update maps
///
void BaseGrid::UpdateMaps() {
// Store old
int len = diagMap.size();
@ -981,8 +1041,11 @@ void BaseGrid::UpdateMaps() {
}
/////////////
// Key press
/// @brief Key press
/// @param event
/// @return
///
void BaseGrid::OnKeyPress(wxKeyEvent &event) {
// Get size
int w,h;
@ -1099,8 +1162,11 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) {
}
////////////////////////////////
// Sets display by frame or not
/// @brief Sets display by frame or not
/// @param state
/// @return
///
void BaseGrid::SetByFrame (bool state) {
// Check if it's already the same
if (byFrame == state) return;
@ -1110,8 +1176,11 @@ void BaseGrid::SetByFrame (bool state) {
}
///////////////////////////////////////////////
// Generates an array covering inclusive range
/// @brief Generates an array covering inclusive range
/// @param n1
/// @param n2
///
wxArrayInt BaseGrid::GetRangeArray(int n1,int n2) {
// Swap if in wrong order
if (n2 < n1) {
@ -1128,3 +1197,4 @@ wxArrayInt BaseGrid::GetRangeArray(int n1,int n2) {
return target;
}

View file

@ -52,20 +52,42 @@ class AssEntry;
class AssDialogue;
class SubsEditBox;
class FrameMain;
/// DOCME
typedef std::list<AssEntry*>::iterator entryIter;
///////////////////
// Base grid class
/// DOCME
/// @class BaseGrid
/// @brief DOCME
///
/// DOCME
class BaseGrid : public wxWindow {
private:
/// DOCME
int lineHeight;
/// DOCME
int colWidth[16];
/// DOCME
int lastRow;
/// DOCME
int extendRow;
/// DOCME
bool holding;
/// DOCME
wxFont font;
/// DOCME
wxScrollBar *scrollBar;
/// DOCME
wxBitmap *bmp;
void OnPaint(wxPaintEvent &event);
@ -77,19 +99,39 @@ private:
void DrawImage(wxDC &dc);
protected:
/// DOCME
FrameMain *parentFrame;
/// DOCME
bool showCol[16];
/// @brief DOCME
/// @param alternate=false
///
virtual void OnPopupMenu(bool alternate=false) {}
void ScrollTo(int y);
/// DOCME
int yPos;
public:
/// DOCME
SubsEditBox *editBox;
/// DOCME
bool byFrame;
/// DOCME
std::vector<entryIter> diagMap;
/// DOCME
std::vector<AssDialogue *> diagPtrMap;
/// DOCME
std::vector<bool> selMap;
void AdjustScrollbar();
@ -128,6 +170,9 @@ public:
///////
// IDs
enum {
/// DOCME
GRID_SCROLLBAR = 1730
};

View file

@ -47,8 +47,15 @@
#include "standard_paths.h"
///////////////
// Constructor
/// @brief Constructor
/// @param parent
/// @param id
/// @param text
/// @param _type
/// @param position
/// @param size
///
BrowseButton::BrowseButton(wxWindow *parent,int id,wxString text,BrowseType _type,wxPoint position,wxSize size)
: wxButton (parent,id,text == wxString(_T("")) ? wxString(_("Browse...")) : text,position,size)
{
@ -59,15 +66,20 @@ BrowseButton::BrowseButton(wxWindow *parent,int id,wxString text,BrowseType _typ
}
////////
// Bind
/// @brief Bind
/// @param control
/// @param pos
///
void BrowseButton::Bind(wxTextCtrl *control,int pos) {
ctrl[pos] = control;
}
///////////
// Pressed
/// @brief Pressed
/// @param event
///
void BrowseButton::OnPressed(wxCommandEvent &event) {
// Folder
if (type == BROWSE_FOLDER) {
@ -103,3 +115,4 @@ void BrowseButton::OnPressed(wxCommandEvent &event) {

View file

@ -45,20 +45,34 @@
#include <wx/textctrl.h>
///////////////
// Browse type
/// DOCME
enum BrowseType {
/// DOCME
BROWSE_FILE,
/// DOCME
BROWSE_FOLDER,
/// DOCME
BROWSE_FONT
};
///////////////////////
// Browse button class
/// DOCME
/// @class BrowseButton
/// @brief DOCME
///
/// DOCME
class BrowseButton : public wxButton {
private:
/// DOCME
wxTextCtrl *ctrl[2];
/// DOCME
BrowseType type;
void OnPressed(wxCommandEvent &event);
@ -68,3 +82,4 @@ public:
void Bind(wxTextCtrl *control,int pos=0);
};

View file

@ -44,20 +44,39 @@
WX_DECLARE_STRING_HASH_MAP(wxString, PrettyNamesHash);
#if wxUSE_THREADS
/// DOCME
static wxMutex encodingListMutex;
#endif
/// DOCME
static const iconv_t iconv_invalid = (iconv_t)-1;
/// DOCME
static const size_t iconv_failed = (size_t)-1;
/// DOCME
#define ICONV_CONST_CAST(a) const_cast<ICONV_CONST char *>(a)
#ifndef ICONV_POSIX
static int addEncoding(unsigned int namescount, const char * const * names, void* data);
#endif
/// DOCME
static wxArrayString *supportedEncodings = NULL;
/// DOCME
static wxArrayString *prettyEncodingList = NULL;
/// DOCME
static PrettyNamesHash *prettyEncodingHash = NULL;
/// @brief DOCME
/// @param mbEncName
/// @param enableSubst
///
AegisubCSConv::AegisubCSConv(const wxChar *mbEncName, bool enableSubst)
: mbCharsetName(GetRealEncodingName(mbEncName)), mbNulLen(0), enableSubst(enableSubst)
{
@ -85,17 +104,27 @@ AegisubCSConv::AegisubCSConv(const wxChar *mbEncName, bool enableSubst)
#endif
}
}
/// @brief DOCME
///
AegisubCSConv::~AegisubCSConv() {
if (m2w != iconv_invalid) iconv_close(m2w);
if (w2m != iconv_invalid) iconv_close(w2m);
}
/// @brief DOCME
/// @return
///
wxMBConv * AegisubCSConv::Clone() const {
AegisubCSConv *c = new AegisubCSConv(mbCharsetName);
c->mbNulLen = mbNulLen;
return c;
}
// Calculate the size of NUL in the target encoding via iconv
/// @brief Calculate the size of NUL in the target encoding via iconv
/// @return
///
size_t AegisubCSConv::GetMBNulLen() const {
if (mbNulLen == 0) {
const wchar_t nulStr[] = L"";
@ -115,7 +144,11 @@ size_t AegisubCSConv::GetMBNulLen() const {
return mbNulLen;
}
// Calculate the length (in bytes) of a MB string, not including the terminator
/// @brief Calculate the length (in bytes) of a MB string, not including the terminator
/// @param str
/// @return
///
size_t AegisubCSConv::MBBuffLen(const char * str) const {
size_t nulLen = GetMBNulLen();
const char *ptr;
@ -133,6 +166,14 @@ size_t AegisubCSConv::MBBuffLen(const char * str) const {
}
}
/// @brief DOCME
/// @param dst
/// @param dstSize
/// @param src
/// @param srcLen
/// @return
///
size_t AegisubCSConv::ToWChar(wchar_t *dst, size_t dstSize, const char *src, size_t srcLen) const {
return doConversion(
m2w,
@ -143,6 +184,14 @@ size_t AegisubCSConv::ToWChar(wchar_t *dst, size_t dstSize, const char *src, siz
) / sizeof(wchar_t);
}
/// @brief DOCME
/// @param dst
/// @param dstSize
/// @param src
/// @param srcLen
/// @return
///
size_t AegisubCSConv::FromWChar(char *dst, size_t dstSize, const wchar_t *src, size_t srcLen) const {
return doConversion(
w2m,
@ -153,6 +202,15 @@ size_t AegisubCSConv::FromWChar(char *dst, size_t dstSize, const wchar_t *src, s
);
}
/// @brief DOCME
/// @param cd
/// @param dst
/// @param dstSize
/// @param src
/// @param srcSize
/// @return
///
size_t AegisubCSConv::doConversion(iconv_t cd, char *dst, size_t dstSize, char *src, size_t srcSize) const {
if (dstSize > 0) {
return iconvWrapper(cd, &src, &srcSize, &dst, &dstSize);
@ -176,6 +234,15 @@ size_t AegisubCSConv::doConversion(iconv_t cd, char *dst, size_t dstSize, char *
return charsWritten;
}
/// @brief DOCME
/// @param cd
/// @param inbuf
/// @param inbytesleft
/// @param outbuf
/// @param outbytesleft
/// @return
///
size_t AegisubCSConv::iconvWrapper(iconv_t cd, char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft) const {
@ -236,6 +303,16 @@ size_t AegisubCSConv::iconvWrapper(iconv_t cd, char **inbuf, size_t *inbytesleft
#endif
}
/// @brief DOCME
/// @param code
/// @param buf
/// @param buflen
/// @param callback_arg)
/// @param callback_arg
/// @param convPtr
/// @return
///
void AegisubCSConv::ucToMbFallback(
unsigned int code,
void (*callback) (const char *buf, size_t buflen, void* callback_arg),
@ -253,6 +330,13 @@ void AegisubCSConv::ucToMbFallback(
}
#ifndef ICONV_POSIX
/// @brief DOCME
/// @param namescount
/// @param names
/// @param data
/// @return
///
int addEncoding(unsigned int namescount, const char * const * names, void* data) {
for (unsigned int i = 0; i < namescount; i++) {
supportedEncodings->Add(wxString::FromAscii(names[i]));
@ -261,6 +345,10 @@ int addEncoding(unsigned int namescount, const char * const * names, void* data)
}
#endif
/// @brief DOCME
/// @return
///
wxArrayString AegisubCSConv::GetAllSupportedEncodings() {
#if wxUSE_THREADS
wxMutexLocker lock(encodingListMutex);
@ -275,7 +363,11 @@ wxArrayString AegisubCSConv::GetAllSupportedEncodings() {
return *supportedEncodings;
}
// Map pretty names to the real encoding names
/// @brief Map pretty names to the real encoding names
/// @param name
/// @return
///
wxString AegisubCSConv::GetRealEncodingName(wxString name) {
if (name.Lower() == _T("local")) return wxLocale::GetSystemEncodingName();
if (prettyEncodingList == NULL) return name;
@ -287,6 +379,9 @@ wxString AegisubCSConv::GetRealEncodingName(wxString name) {
return name;
}
/// @brief DOCME
///
wxArrayString AegisubCSConv::GetEncodingsList() {
#if wxUSE_THREADS
wxMutexLocker lock(encodingListMutex);
@ -438,3 +533,4 @@ wxArrayString AegisubCSConv::GetEncodingsList() {
static AegisubCSConv localConv(_T("Local"), false);
AegisubCSConv& csConvLocal(localConv);

View file

@ -35,6 +35,8 @@
///
#ifndef AEGISUB_CHARSET_CONV_H
/// DOCME
#define AEGISUB_CHARSET_CONV_H
#include <iconv.h>
@ -47,9 +49,17 @@
#include "aegisub_endian.h"
#if !defined(_LIBICONV_VERSION) || _LIBICONV_VERSION < 0x010A || defined(LIBICONV_PLUG)
/// DOCME
#define ICONV_POSIX
#endif
/// DOCME
/// @class AegisubCSConv
/// @brief DOCME
///
/// DOCME
class AegisubCSConv : public wxMBConv {
public:
// By default, any conversion that would be lossy will fail
@ -76,12 +86,24 @@ public:
static wxString GetRealEncodingName(wxString name);
protected:
/// DOCME
/// DOCME
iconv_t m2w, w2m;
private:
/// DOCME
wxString wcCharsetName;
/// DOCME
wxString mbCharsetName;
/// DOCME
size_t mbNulLen;
/// DOCME
bool enableSubst;
size_t doConversion(iconv_t cd, char *dst, size_t dstSize, char *src, size_t srcSize) const;
@ -92,15 +114,22 @@ private:
void (*callback) (const char *buf, size_t buflen, void* callback_arg),
void *callback_arg,
void *convPtr);
/// DOCME
char invalidRep[8];
/// DOCME
size_t invalidRepSize;
#ifndef ICONV_POSIX
/// DOCME
iconv_fallbacks fallbacks;
#endif
#if wxUSE_THREADS
// While iconv itself is thread-safe, using the same iconv_t on multiple threads is not
/// DOCME
wxMutex iconvMutex;
#endif
};
@ -110,23 +139,36 @@ extern AegisubCSConv& csConvLocal;
#ifdef HAVE_BIG_ENDIAN
# if SIZEOF_WCHAR_T == 4
/// DOCME
# define WCHAR_T_ENCODING "UTF-32BE"
# elif SIZEOF_WCHAR_T == 2
/// DOCME
# define WCHAR_T_ENCODING "UTF-16BE"
# endif
#elif defined(HAVE_LITTLE_ENDIAN)
# if SIZEOF_WCHAR_T == 4
/// DOCME
# define WCHAR_T_ENCODING "UTF-32LE"
# elif SIZEOF_WCHAR_T == 2
/// DOCME
# define WCHAR_T_ENCODING "UTF-16LE"
# endif
#else
# if SIZEOF_WCHAR_T == 4
/// DOCME
# define WCHAR_T_ENCODING ((Endian::MachineToBig((uint32_t)1) == 1) ? "UTF-32BE" : "UTF-32LE")
# elif SIZEOF_WCHAR_T == 2
/// DOCME
# define WCHAR_T_ENCODING ((Endian::MachineToBig((uint32_t)1) == 1) ? "UTF-16BE" : "UTF-16LE")
# endif
#endif
#endif

View file

@ -48,15 +48,29 @@
#include <wx/choicdlg.h>
/// DOCME
struct CharDetResult {
/// DOCME
float confidence;
/// DOCME
wxString name;
/// @brief DOCME
/// @param par
/// @return
///
bool operator < (CharDetResult &par) { return confidence > par.confidence; }
};
////////////////
// Get encoding
/// @brief Get encoding
/// @param filename
/// @return
///
wxString CharSetDetect::GetEncoding(wxString filename) {
std::ifstream file;
#ifdef __WINDOWS__
@ -148,8 +162,10 @@ wxString CharSetDetect::GetEncoding(wxString filename) {
return result;
}
//////////
// Report
/// @brief Report
/// @param aCharset
///
void CharSetDetect::Report(const char* aCharset) {
// Store the result reported
result = wxString(aCharset,wxConvUTF8);
@ -157,3 +173,4 @@ void CharSetDetect::Report(const char* aCharset) {
#endif // WITH_UNIVCHARDET

View file

@ -43,15 +43,25 @@
#include "../universalchardet/nsUniversalDetector.h"
/////////////////////////////////
// Character set detection class
/// DOCME
/// @class CharSetDetect
/// @brief DOCME
///
/// DOCME
class CharSetDetect : public nsUniversalDetector {
private:
/// DOCME
wxString result;
void Report(const char* aCharset);
public:
wxString GetEncoding(wxString filename);
/// @brief DOCME
///
PRBool done() const { return mDone; }
};

View file

@ -40,7 +40,15 @@
#include "utils.h"
// matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
/// @brief matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
/// @param Y
/// @param U
/// @param V
/// @param R
/// @param G
/// @param B
///
void yuv_to_rgb(int Y, int U, int V, unsigned char *R, unsigned char *G, unsigned char *B)
{
U = U - 128;
@ -51,8 +59,16 @@ void yuv_to_rgb(int Y, int U, int V, unsigned char *R, unsigned char *G, unsigne
}
// algorithm from http://130.113.54.154/~monger/hsl-rgb.html
// making every value into 0..255 range though
/// @brief making every value into 0..255 range though algorithm from http://130.113.54.154/~monger/hsl-rgb.html
/// @param H
/// @param S
/// @param L
/// @param R
/// @param G
/// @param B
/// @return
///
void hsl_to_rgb(int H, int S, int L, unsigned char *R, unsigned char *G, unsigned char *B)
{
if (S == 0) {
@ -153,8 +169,16 @@ void hsl_to_rgb(int H, int S, int L, unsigned char *R, unsigned char *G, unsigne
}
// formulas taken from wikipedia: http://en.wikipedia.org/wiki/HSV_color_space
// the range for H is 0..255 instead of 0..359, so 60 degrees has been translated to 256/6 here
/// @brief the range for H is 0..255 instead of 0..359, so 60 degrees has been translated to 256/6 here formulas taken from wikipedia: http://en.wikipedia.org/wiki/HSV_color_space
/// @param H
/// @param S
/// @param V
/// @param R
/// @param G
/// @param B
/// @return
///
void hsv_to_rgb(int H, int S, int V, unsigned char *R, unsigned char *G, unsigned char *B)
{
*R = *G = *B = 0;
@ -257,7 +281,15 @@ void hsv_to_rgb(int H, int S, int V, unsigned char *R, unsigned char *G, unsigne
}
// matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
/// @brief matrix from http://forum.doom9.org/showthread.php?p=684080#post684080
/// @param R
/// @param G
/// @param B
/// @param Y
/// @param U
/// @param V
///
void rgb_to_yuv(int R, int G, int B, unsigned char *Y, unsigned char *U, unsigned char *V)
{
*Y = clip_colorval(( int(0.299*65536) * R + int(0.587*65536) * G + int(0.114*65536) * B) / 65536);
@ -266,8 +298,15 @@ void rgb_to_yuv(int R, int G, int B, unsigned char *Y, unsigned char *U, unsigne
}
// also from http://130.113.54.154/~monger/hsl-rgb.html
// still keeping everything integer
/// @brief still keeping everything integer also from http://130.113.54.154/~monger/hsl-rgb.html
/// @param R
/// @param G
/// @param B
/// @param H
/// @param S
/// @param L
///
void rgb_to_hsl(int R, int G, int B, unsigned char *H, unsigned char *S, unsigned char *L)
{
float r = R/255.f, g = G/255.f, b = B/255.f;
@ -304,7 +343,15 @@ void rgb_to_hsl(int R, int G, int B, unsigned char *H, unsigned char *S, unsigne
}
// formulas from http://en.wikipedia.org/wiki/HSV_color_space
/// @brief formulas from http://en.wikipedia.org/wiki/HSV_color_space
/// @param R
/// @param G
/// @param B
/// @param H
/// @param S
/// @param V
///
void rgb_to_hsv(int R, int G, int B, unsigned char *H, unsigned char *S, unsigned char *V)
{
float r = R/255.f, g = G/255.f, b = B/255.f;
@ -339,6 +386,15 @@ void rgb_to_hsv(int R, int G, int B, unsigned char *H, unsigned char *S, unsigne
}
/// @brief DOCME
/// @param iH
/// @param iS
/// @param iV
/// @param oH
/// @param oS
/// @param oL
///
void hsv_to_hsl(int iH, int iS, int iV, unsigned char *oH, unsigned char *oS, unsigned char *oL)
{
int p = iV * (255 - iS);
@ -354,6 +410,16 @@ void hsv_to_hsl(int iH, int iS, int iV, unsigned char *oH, unsigned char *oS, un
}
/// @brief DOCME
/// @param iH
/// @param iS
/// @param iL
/// @param oH
/// @param oS
/// @param oV
/// @return
///
void hsl_to_hsv(int iH, int iS, int iL, unsigned char *oH, unsigned char *oS, unsigned char *oV)
{
*oH = iH;
@ -374,12 +440,21 @@ void hsl_to_hsv(int iH, int iS, int iL, unsigned char *oH, unsigned char *oS, un
}
/// @brief DOCME
/// @param color
/// @return
///
wxString color_to_html(wxColour color)
{
return wxString::Format(_T("#%02X%02X%02X"), color.Red(), color.Green(), color.Blue());
}
/// @brief DOCME
/// @param html
///
wxColour html_to_color(wxString html)
{
html.Trim(true);
@ -418,3 +493,4 @@ wxColour html_to_color(wxString html)
}

View file

@ -35,6 +35,8 @@
///
#ifndef COLORSPACE_H
/// DOCME
#define COLORSPACE_H
#include <wx/wxprec.h>
@ -42,6 +44,10 @@
#include <wx/string.h>
/// @brief DOCME
/// @param val
///
inline unsigned int clip_colorval(int val)
{
if (val < 0) return 0;
@ -82,3 +88,4 @@ wxColour html_to_color(wxString html);
#endif

View file

@ -44,8 +44,13 @@
#include "dialog_colorpicker.h"
///////////////
// Constructor
/// @brief Constructor
/// @param parent
/// @param id
/// @param size
/// @param col
///
ColourButton::ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col) {
// Variables
linkColour = NULL;
@ -62,14 +67,17 @@ ColourButton::ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size,
}
//////////////
// Destructor
/// @brief Destructor
///
ColourButton::~ColourButton() {
}
//////////////
// Set colour
/// @brief Set colour
/// @param col
///
void ColourButton::SetColour(wxColour col) {
// Set colour
colour = col;
@ -90,15 +98,19 @@ void ColourButton::SetColour(wxColour col) {
}
//////////////
// Get Colour
/// @brief Get Colour
/// @return
///
wxColour ColourButton::GetColour() {
return colour;
}
/////////
// Click
/// @brief Click
/// @param event
///
void ColourButton::OnClick(wxCommandEvent &event) {
DialogColorPicker dlg(GetParent(), colour);
if (dlg.ShowModal() == wxID_OK) {
@ -108,10 +120,13 @@ void ColourButton::OnClick(wxCommandEvent &event) {
}
///////////////////
// Set Link Colour
/// @brief Set Link Colour
/// @param col
///
void ColourButton::SetLinkColour(wxColour *col) {
linkColour = col;
if (linkColour) SetColour(*linkColour);
}

View file

@ -44,12 +44,22 @@
#include <wx/bmpbuttn.h>
///////////////////////
// Colour Button class
/// DOCME
/// @class ColourButton
/// @brief DOCME
///
/// DOCME
class ColourButton: public wxBitmapButton {
private:
/// DOCME
wxBitmap bmp;
/// DOCME
wxColour colour;
/// DOCME
wxColour *linkColour;
void OnClick(wxCommandEvent &event);
@ -63,3 +73,4 @@ public:
void SetLinkColour(wxColour *colour);
};

View file

@ -50,8 +50,10 @@
///////////////
// Constructor
/// @brief Constructor
/// @param parent
///
AboutScreen::AboutScreen(wxWindow *parent)
: wxDialog (parent, -1, _("About Aegisub"), wxDefaultPosition, wxSize(300,240), wxCAPTION | wxCLOSE_BOX , _("About Aegisub"))
{
@ -185,8 +187,10 @@ AboutScreen::AboutScreen(wxWindow *parent)
}
//////////////
// Destructor
/// @brief Destructor
///
AboutScreen::~AboutScreen () {
}

View file

@ -45,11 +45,16 @@
#include "static_bmp.h"
///////////////////////
// Splash screen class
/// DOCME
/// @class AboutScreen
/// @brief DOCME
///
/// DOCME
class AboutScreen: public wxDialog {
public:
AboutScreen(wxWindow *parent);
~AboutScreen();
};

View file

@ -45,8 +45,10 @@
#include "dialog_associations.h"
///////////////
// Constructor
/// @brief Constructor
/// @param parent
///
DialogAssociations::DialogAssociations (wxWindow *parent)
: wxDialog (parent,-1,_("Associate extensions"),wxDefaultPosition,wxDefaultSize)
{
@ -86,14 +88,17 @@ DialogAssociations::DialogAssociations (wxWindow *parent)
}
//////////////
// Destructor
/// @brief Destructor
///
DialogAssociations::~DialogAssociations() {
}
/////////////////////////////////////
// Associates a type with Aegisub
/// @brief Associates a type with Aegisub
/// @param type
///
void DialogAssociations::AssociateType(wxString type) {
type.Lower();
wxRegKey *key = new wxRegKey(_T("HKEY_CURRENT_USER\\Software\\Classes\\.") + type);
@ -103,8 +108,11 @@ void DialogAssociations::AssociateType(wxString type) {
}
//////////////////////////////////////////////////
// Checks if a type is associated with Aegisub
/// @brief Checks if a type is associated with Aegisub
/// @param type
/// @return
///
bool DialogAssociations::CheckAssociation(wxString type) {
type.Lower();
wxRegKey *key = new wxRegKey(_T("HKEY_CURRENT_USER\\Software\\Classes\\.") + type);
@ -128,8 +136,10 @@ BEGIN_EVENT_TABLE(DialogAssociations, wxDialog)
END_EVENT_TABLE()
//////////////
// OK pressed
/// @brief OK pressed
/// @param event
///
void DialogAssociations::OnOK(wxCommandEvent &event) {
if (ListBox->IsChecked(0)) AssociateType(_T("ass"));
if (ListBox->IsChecked(1)) AssociateType(_T("ssa"));
@ -139,3 +149,4 @@ void DialogAssociations::OnOK(wxCommandEvent &event) {
event.Skip();
}

View file

@ -46,10 +46,16 @@
#include <wx/slider.h>
//////////////////////////////////
// File associations dialog class
/// DOCME
/// @class DialogAssociations
/// @brief DOCME
///
/// DOCME
class DialogAssociations : public wxDialog {
private:
/// DOCME
wxCheckListBox *ListBox;
void OnOK(wxCommandEvent &event);
@ -63,3 +69,4 @@ public:
DECLARE_EVENT_TABLE()
};

View file

@ -55,8 +55,10 @@
///////////////
// Constructor
/// @brief Constructor
/// @param parent
///
DialogAttachments::DialogAttachments(wxWindow *parent)
: wxDialog(parent,-1,_("Attachment List"),wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE)
{
@ -92,8 +94,9 @@ DialogAttachments::DialogAttachments(wxWindow *parent)
}
///////////////
// Update list
/// @brief Update list
///
void DialogAttachments::UpdateList() {
// Clear list
listView->ClearAll();
@ -119,8 +122,9 @@ void DialogAttachments::UpdateList() {
}
//////////////
// Destructor
/// @brief Destructor
///
DialogAttachments::~DialogAttachments() {
}
@ -138,8 +142,11 @@ BEGIN_EVENT_TABLE(DialogAttachments,wxDialog)
END_EVENT_TABLE()
///////////////
// Attach font
/// @brief Attach font
/// @param event
/// @return
///
void DialogAttachments::OnAttachFont(wxCommandEvent &event) {
// Pick files
wxArrayString filenames;
@ -171,8 +178,11 @@ void DialogAttachments::OnAttachFont(wxCommandEvent &event) {
}
///////////////////
// Attach graphics
/// @brief Attach graphics
/// @param event
/// @return
///
void DialogAttachments::OnAttachGraphics(wxCommandEvent &event) {
// Pick files
wxArrayString filenames;
@ -204,8 +214,11 @@ void DialogAttachments::OnAttachGraphics(wxCommandEvent &event) {
}
///////////
// Extract
/// @brief Extract
/// @param event
/// @return
///
void DialogAttachments::OnExtract(wxCommandEvent &event) {
// Check if there's a selection
int i = listView->GetFirstSelected();
@ -237,8 +250,10 @@ void DialogAttachments::OnExtract(wxCommandEvent &event) {
}
//////////
// Delete
/// @brief Delete
/// @param event
///
void DialogAttachments::OnDelete(wxCommandEvent &event) {
// Loop through items in list
int i = listView->GetFirstSelected();
@ -252,8 +267,10 @@ void DialogAttachments::OnDelete(wxCommandEvent &event) {
}
//////////////////////////
// List selection changed
/// @brief List selection changed
/// @param event
///
void DialogAttachments::OnListClick(wxListEvent &event) {
// Check if any is selected
bool hasSel = listView->GetFirstSelected() != -1;
@ -263,3 +280,4 @@ void DialogAttachments::OnListClick(wxListEvent &event) {
deleteButton->Enable(hasSel);
}

View file

@ -49,12 +49,22 @@ class wxListView;
class wxListEvent;
//////////////////////
// Attachments window
/// DOCME
/// @class DialogAttachments
/// @brief DOCME
///
/// DOCME
class DialogAttachments : public wxDialog {
private:
/// DOCME
wxListView *listView;
/// DOCME
wxButton *extractButton;
/// DOCME
wxButton *deleteButton;
void OnAttachFont(wxCommandEvent &event);
@ -76,10 +86,21 @@ public:
///////
// IDs
enum {
/// DOCME
BUTTON_ATTACH_FONT = 1300,
/// DOCME
BUTTON_ATTACH_GRAPHICS,
/// DOCME
BUTTON_EXTRACT,
/// DOCME
BUTTON_DELETE,
/// DOCME
ATTACHMENT_LIST
};

View file

@ -53,6 +53,11 @@
/// @brief DOCME
/// @param parent
/// @param _local_manager
///
DialogAutomation::DialogAutomation(wxWindow *parent, Automation4::ScriptManager *_local_manager)
: wxDialog(parent, -1, _("Automation Manager"), wxDefaultPosition, wxDefaultSize)
{
@ -111,6 +116,9 @@ DialogAutomation::DialogAutomation(wxWindow *parent, Automation4::ScriptManager
}
/// @brief DOCME
///
void DialogAutomation::RebuildList()
{
script_info.clear();
@ -135,6 +143,10 @@ void DialogAutomation::RebuildList()
}
/// @brief DOCME
/// @param ei
///
void DialogAutomation::AddScript(ExtraScriptInfo &ei)
{
script_info.push_back(ei);
@ -157,6 +169,9 @@ void DialogAutomation::AddScript(ExtraScriptInfo &ei)
}
/// @brief DOCME
///
void DialogAutomation::UpdateDisplay()
{
int i = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
@ -186,6 +201,10 @@ BEGIN_EVENT_TABLE(DialogAutomation, wxDialog)
END_EVENT_TABLE()
/// @brief DOCME
/// @param evt
///
void DialogAutomation::OnAdd(wxCommandEvent &evt)
{
// build filename filter list
@ -237,6 +256,11 @@ void DialogAutomation::OnAdd(wxCommandEvent &evt)
}
}
/// @brief DOCME
/// @param evt
/// @return
///
void DialogAutomation::OnRemove(wxCommandEvent &evt)
{
int i = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
@ -249,6 +273,11 @@ void DialogAutomation::OnRemove(wxCommandEvent &evt)
list->Select(i);
}
/// @brief DOCME
/// @param evt
/// @return
///
void DialogAutomation::OnReload(wxCommandEvent &evt)
{
int i = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
@ -273,6 +302,10 @@ void DialogAutomation::OnReload(wxCommandEvent &evt)
}
}
/// @brief DOCME
/// @param evt
///
void DialogAutomation::OnInfo(wxCommandEvent &evt)
{
int i = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
@ -318,6 +351,10 @@ void DialogAutomation::OnInfo(wxCommandEvent &evt)
wxMessageBox(info, _("Automation Script Info"));
}
/// @brief DOCME
/// @param evt
///
void DialogAutomation::OnReloadAutoload(wxCommandEvent &evt)
{
global_manager->Reload();
@ -325,6 +362,10 @@ void DialogAutomation::OnReloadAutoload(wxCommandEvent &evt)
UpdateDisplay();
}
/// @brief DOCME
/// @param evt
///
void DialogAutomation::OnSelectionChange(wxListEvent &evt)
{
UpdateDisplay();
@ -332,3 +373,4 @@ void DialogAutomation::OnSelectionChange(wxListEvent &evt)
#endif // WITH_AUTOMATION

View file

@ -37,6 +37,8 @@
#pragma once
#ifndef DIALOG_AUTOMATION_H
/// DOCME
#define DIALOG_AUTOMATION_H
#include <wx/dialog.h>
@ -44,25 +46,59 @@
#include <wx/button.h>
#include <vector>
/// DOCME
namespace Automation4 { class ScriptManager; class Script; };
/// DOCME
/// @class DialogAutomation
/// @brief DOCME
///
/// DOCME
class DialogAutomation : public wxDialog {
private:
/// DOCME
struct ExtraScriptInfo {
/// DOCME
Automation4::Script *script;
/// DOCME
bool is_global;
};
/// DOCME
std::vector<ExtraScriptInfo> script_info;
/// DOCME
Automation4::ScriptManager *local_manager;
/// DOCME
Automation4::AutoloadScriptManager *global_manager;
/// DOCME
wxListView *list;
/// DOCME
wxButton *add_button;
/// DOCME
wxButton *remove_button;
/// DOCME
wxButton *reload_button;
/// DOCME
wxButton *info_button;
/// DOCME
wxButton *reload_autoload_button;
/// DOCME
wxButton *close_button;
void RebuildList();
@ -83,13 +119,26 @@ public:
};
enum {
/// DOCME
Automation_List_Box = 1000,
/// DOCME
Automation_Add_Script,
/// DOCME
Automation_Remove_Script,
/// DOCME
Automation_Reload_Script,
/// DOCME
Automation_Show_Info,
/// DOCME
Automation_Reload_Autoload
};
#endif

Some files were not shown because too many files have changed in this diff Show more