Browse Source

Fix bad include, missing static declaration, SRT path directory, and formatting

working_subtitles
ZarothYe 3 years ago committed by rarified
parent
commit
f4b1de5826
  1. 1
      Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.h
  2. 23
      Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.cpp

1
Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.h

@ -260,6 +260,7 @@ private:
static hsBool fInit; static hsBool fInit;
static hsBool fActive; static hsBool fActive;
static hsBool fMuted; static hsBool fMuted;
static bool fEnableSubtitles;
static hsWindowHndl fWnd; static hsWindowHndl fWnd;
static hsBool fUseHardware; static hsBool fUseHardware;
static hsBool fDelayedActivate; static hsBool fDelayedActivate;

23
Sources/Plasma/PubUtilLib/plAudioCore/plSrtFileReader.cpp

@ -45,8 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsStream.h" #include "hsStream.h"
#include "../plStatusLog/plStatusLog.h" #include "../plStatusLog/plStatusLog.h"
#include "../pnUtils/Private/pnUtPath.h" #include "../pnUtils/pnUtils.h"
#include "../pnUtils/Private/pnUtStr.h"
#include <regex> #include <regex>
@ -55,8 +54,15 @@ static const std::regex timingsRegex("^(\\d{2}):(\\d{2}):(\\d{2}),(\\d{3}) --> (
bool plSrtFileReader::ReadFile() bool plSrtFileReader::ReadFile()
{ {
char path[MAX_PATH];
if (strchr(fAudioFileName, '\\') != nil)
strcpy(path, fAudioFileName);
else
sprintf(path, "sfx\\%s", fAudioFileName);
wchar srtPathUnicode[MAX_PATH]; wchar srtPathUnicode[MAX_PATH];
StrToUnicode(srtPathUnicode, fAudioFileName, arrsize(srtPathUnicode)); StrToUnicode(srtPathUnicode, path, arrsize(srtPathUnicode));
PathSetExtension(srtPathUnicode, srtPathUnicode, L".sub", arrsize(srtPathUnicode)); PathSetExtension(srtPathUnicode, srtPathUnicode, L".sub", arrsize(srtPathUnicode));
if (PathDoesFileExist(srtPathUnicode)) { if (PathDoesFileExist(srtPathUnicode)) {
@ -70,7 +76,7 @@ bool plSrtFileReader::ReadFile()
uint32_t subtitleNumber = 0; uint32_t subtitleNumber = 0;
uint32_t subtitleStartTimeMs = 0; uint32_t subtitleStartTimeMs = 0;
uint32_t subtitleEndTimeMs = 0; uint32_t subtitleEndTimeMs = 0;
char* line; char line[4096];
std::string speakerName; std::string speakerName;
std::string subtitleText; std::string subtitleText;
std::cmatch matches; std::cmatch matches;
@ -78,8 +84,7 @@ bool plSrtFileReader::ReadFile()
for (unsigned int lnCounter = 0; !srtFileStream.AtEnd(); lnCounter++) { for (unsigned int lnCounter = 0; !srtFileStream.AtEnd(); lnCounter++) {
if (lnCounter % 4 == 0 && srtFileStream.ReadLn(line)) { if (lnCounter % 4 == 0 && srtFileStream.ReadLn(line)) {
subtitleNumber = std::stoul(line); subtitleNumber = std::stoul(line);
} } else if (lnCounter % 4 == 1 && srtFileStream.ReadLn(line)) {
else if (lnCounter % 4 == 1 && srtFileStream.ReadLn(line)) {
if (std::regex_match(line, matches, timingsRegex)) { if (std::regex_match(line, matches, timingsRegex)) {
if (matches.size() < 9) { if (matches.size() < 9) {
// add error message and ensure this subtitle line won't be added to the entries // add error message and ensure this subtitle line won't be added to the entries
@ -107,8 +112,7 @@ bool plSrtFileReader::ReadFile()
subtitleEndTimeMs += std::stoul(matches[8].str()); subtitleEndTimeMs += std::stoul(matches[8].str());
} }
} }
} } else if (lnCounter % 4 == 2 && srtFileStream.ReadLn(line)) {
else if (lnCounter % 4 == 2 && srtFileStream.ReadLn(line)) {
if (std::regex_match(line, matches, speakerTextRegex)) { if (std::regex_match(line, matches, speakerTextRegex)) {
if (matches.size() < 5) { if (matches.size() < 5) {
// add error message and ensure this subtitle line won't be added to the entries // add error message and ensure this subtitle line won't be added to the entries
@ -124,8 +128,7 @@ bool plSrtFileReader::ReadFile()
subtitleText = matches[5]; subtitleText = matches[5];
} }
} }
} } else if (lnCounter % 4 == 3 && subtitleNumber > 0 && subtitleStartTimeMs >= 0 && subtitleEndTimeMs >= 0 && !subtitleText.empty()) {
else if (lnCounter % 4 == 3 && subtitleNumber > 0 && subtitleStartTimeMs >= 0 && subtitleEndTimeMs >= 0 && !subtitleText.empty()) {
// entry is complete, add to the queue and reset our temp variables // entry is complete, add to the queue and reset our temp variables
if (!speakerName.empty()) if (!speakerName.empty())
fEntries.emplace_back(plSrtEntry(subtitleNumber, subtitleStartTimeMs, subtitleEndTimeMs, std::move(subtitleText), std::move(speakerName))); fEntries.emplace_back(plSrtEntry(subtitleNumber, subtitleStartTimeMs, subtitleEndTimeMs, std::move(subtitleText), std::move(speakerName)));

Loading…
Cancel
Save