mirror of
https://github.com/DanielSWolf/rhubarb-lip-sync.git
synced 2026-11-21 12:25:08 +00:00
Merge pull request #169 from DanielSWolf/feature/#77-after-effects-improvements
Fix After Effects script on macOS and related improvements
This commit is contained in:
@@ -10,6 +10,6 @@ indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{yml,yaml}]
|
||||
[*.{jsx,yml,yaml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
# Version history
|
||||
|
||||
## Unreleased
|
||||
|
||||
* **Fixed** After Effects script on macOS ([issue #77](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/77), [issue #128](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/128))
|
||||
* **Changed** the way you make Rhubarb available to After Effects on macOS. This used to be a `/usr/local/bin/` symlink but is now a `PATH` entry ([issue #143](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/143)). For details, see the README file for Rhubarb for After Effects.
|
||||
|
||||
## Version 1.13.0
|
||||
|
||||
* **Improved** animation rules for "F" sound when using just the basic mouth shapes.
|
||||
|
||||
@@ -354,7 +354,7 @@ The following is an example output to `stderr` from a _successful_ run:
|
||||
{ "type": "progress", "value": 0.06, "log": { "level": "Trace", "message": "Progress: 6%" } }
|
||||
{ "type": "progress", "value": 0.69, "log": { "level": "Trace", "message": "Progress: 68%" } }
|
||||
{ "type": "progress", "value": 1.00, "log": { "level": "Trace", "message": "Progress: 100%" } }
|
||||
// Result data, printed to stdout...
|
||||
# This is the moment that result data is printed to stdout (not stderr)
|
||||
{ "type": "success", "log": { "level": "Info", "message": "Application terminating normally." } }
|
||||
----
|
||||
|
||||
|
||||
8
extras/AdobeAfterEffects/.prettierrc.yml
Normal file
8
extras/AdobeAfterEffects/.prettierrc.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
# Config file for Prettier, a JavaScript/TypeScript code formatter.
|
||||
|
||||
useTabs: false
|
||||
tabWidth: 2
|
||||
printWidth: 100
|
||||
singleQuote: true
|
||||
arrowParens: avoid
|
||||
trailingComma: none
|
||||
@@ -1,11 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
set(afterEffectsFiles
|
||||
"Rhubarb Lip Sync.jsx"
|
||||
"README.adoc"
|
||||
install(
|
||||
FILES
|
||||
"Rhubarb Lip Sync.jsx"
|
||||
"README.adoc"
|
||||
DESTINATION "extras/AdobeAfterEffects"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${afterEffectsFiles}
|
||||
DIRECTORY demo
|
||||
DESTINATION "extras/AdobeAfterEffects"
|
||||
)
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
= Animation script for Adobe After Effects
|
||||
= Rhubarb for After Effects
|
||||
:experimental:
|
||||
:imagesdir: ../../img
|
||||
:A: Ⓐ
|
||||
:B: Ⓑ
|
||||
:C: Ⓒ
|
||||
:D: Ⓓ
|
||||
:E: Ⓔ
|
||||
:F: Ⓕ
|
||||
:G: Ⓖ
|
||||
:H: Ⓗ
|
||||
:X: Ⓧ
|
||||
|
||||
The script in this directory generates After Effects compositions with mouth animation.
|
||||
|
||||
@@ -8,22 +19,69 @@ The script in this directory generates After Effects compositions with mouth ani
|
||||
|
||||
Download the archive file containing Rhubarb Lip Sync, then extract in a directory on your computer.
|
||||
|
||||
=== 2. Make Rhubarb available to After Effects
|
||||
=== 2. Add Rhubarb to the PATH environment variable
|
||||
|
||||
On *Windows*, add the Rhubarb directory (the directory containing `rhubarb.exe`) to your `PATH` environment variable.
|
||||
After Effects needs to know where to find Rhubarb Lip Sync.
|
||||
So you need to add the Rhubarb directory to your computer's PATH environment variable as follows:
|
||||
|
||||
On *OS X*, create a symbolic link to the executable (`rhubarb`) in `/usr/local/bin/`. You can do that by executing `ln -s /rhubarb-directory/rhubarb /usr/local/bin/` (make sure to replace `rhubarb-directory` with the actual directory).
|
||||
*On Windows:*
|
||||
|
||||
. *Copy the full path of the Rhubarb directory:*
|
||||
* In the File Explorer, press and hold the kbd:[Shift] key while right-clicking on the Rhubarb directory (the directory containing `rhubarb`, `README.adoc`, etc.).
|
||||
* In the context menu, select _Copy as path_.
|
||||
|
||||
. *Add the Rhubarb directory to the PATH variable:*
|
||||
* Press kbd:[Start] + kbd:[R] to open the Run dialog.
|
||||
* Type `sysdm.cpl` and press kbd:[Enter] to open the System Properties window.
|
||||
* In the System Properties window, go to the _Advanced_ tab and click the _Environment Variables..._ button.
|
||||
* In the _Environment Variables_ window, under _System variables_, select the _Path_ variable, then click _Edit..._.
|
||||
* In the Edit Environment Variable window, click _New_, then paste the path you copied earlier.
|
||||
* Click _OK_ to close all windows.
|
||||
* To make sure everything is working, open a new Command Prompt window by pressing kbd:[Start] + kbd:[R], typing `cmd`, and pressing kbd:[Enter]. Type `rhubarb --version` and press kbd:[Enter]. You should see the version number of Rhubarb Lip Sync.
|
||||
|
||||
*On macOS:*
|
||||
|
||||
. *Copy the full path of the Rhubarb directory:*
|
||||
* In the Finder app, right-click on the Rhubarb directory (the directory containing `rhubarb`, `README.adoc`, etc.).
|
||||
* While the context menu is open, press and hold the kbd:[Option] key. This will change some of the menu items.
|
||||
* Select _Copy [...] as Pathname_.
|
||||
|
||||
. *Open the Terminal app:*
|
||||
* Click on the Spotlight search icon (the little magnifying glass) at the top-right of your screen.
|
||||
* Into the search bar that opens, type "`terminal`", then press kbd:[Enter].
|
||||
|
||||
. *Add the Rhubarb directory to the PATH variable:*
|
||||
* In the Terminal window, type `touch ~/.zshrc` and confirm with kbd:[Enter].
|
||||
* Next, type `open -e ~/.zshrc` and confirm with kbd:[Enter]. The TextEdit app should open with a file.
|
||||
* If the file already contains text, move to the end of the file and add a new line.
|
||||
* Type `export PATH="`, press kbd:[Cmd] + kbd:[V] to paste the path you copied earlier, then type `:$PATH"`. +
|
||||
The resulting line should look something like `export PATH="/Users/Daniel/Rhubarb-Lip-Sync:$PATH"`.
|
||||
* Save the file and close TextEdit.
|
||||
* To make sure everything is working, close the terminal window, then open it again as described above. Type `rhubarb --version` and confirm with kbd:[Enter]. You should see the version number of Rhubarb Lip Sync.
|
||||
|
||||
=== 3. Install After Effects script
|
||||
|
||||
Copy (or symlink) the script file `Rhubarb Lip Sync.jsx` into your After Effects scripts directory.
|
||||
In After Effects, go to _File_ > _Scripts_ > _Install Script File..._, then select the script file `Rhubarb Lip Sync.jsx` from the `extras/AdobeAfterEffects` subdirectory of Rhubarb Lip Sync.
|
||||
|
||||
On *Windows*, that directory is usually `C:\Program Files\Adobe\Adobe After Effects <version>\Support Files\Scripts`.
|
||||
Older After Effects versions don't have this command, so you'll have to manually copy (or symlink) the script file into your After Effects scripts directory.
|
||||
|
||||
On *OS X*, that directory is usually `Applications/Adobe After Effects <version>/Scripts`.
|
||||
* On *Windows*, that directory is usually `C:\Program Files\Adobe\Adobe After Effects <version>\Support Files\Scripts`.
|
||||
* On *OS X*, that directory is usually `Applications/Adobe After Effects <version>/Scripts`.
|
||||
|
||||
=== 4. (Re-)start After Effects
|
||||
|
||||
== How to use
|
||||
|
||||
In After Effects, select _File > Scripts > Rhubarb Lip Sync.jsx_. That will open a dialog window where you can specify the audio file with the dialog recording and a number of other options. To get information about any input field, just hover above it with your mouse and you’ll see a tooltip.
|
||||
=== Create your mouth composition
|
||||
|
||||
To start, you need a composition containing all your mouth shapes.
|
||||
The first frame (`00:00`) should contain the {A} mouth shape, the second frame (`00:01`) should contain the {B} mouth shape, and so on.
|
||||
The optional mouth shapes {G}, {H}, and {X} belong at `00:06`, `00:07`, and `00:08`, respectively.
|
||||
|
||||
For your first experiments, check out the demo project in the `extras/AdobeAfterEffects/demo` directory.
|
||||
|
||||
image:after-effects-setup.png[]
|
||||
|
||||
=== Run Rhubarb for After Effects
|
||||
|
||||
In After Effects, select _File > Scripts > Rhubarb Lip Sync.jsx_. That will open a dialog window where you can specify the audio file with the dialog recording and a number of other options. To get information about any input field, just hover above it with your mouse and you'll see a tooltip.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
BIN
extras/AdobeAfterEffects/demo/egg.aep
Normal file
BIN
extras/AdobeAfterEffects/demo/egg.aep
Normal file
Binary file not shown.
1337
extras/AdobeAfterEffects/demo/egg.ai
Normal file
1337
extras/AdobeAfterEffects/demo/egg.ai
Normal file
File diff suppressed because one or more lines are too long
BIN
extras/AdobeAfterEffects/demo/riddle.wav
LFS
Normal file
BIN
extras/AdobeAfterEffects/demo/riddle.wav
LFS
Normal file
Binary file not shown.
BIN
img/after-effects-setup.png
Normal file
BIN
img/after-effects-setup.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 215 KiB |
@@ -4,7 +4,7 @@ include(FetchContent)
|
||||
include("../appInfo.cmake")
|
||||
|
||||
# Support legacy OS X versions
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.10" CACHE STRING "Minimum OS X deployment version")
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
|
||||
|
||||
# Enable C++17
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
@@ -94,6 +94,7 @@ set_target_properties(pocketSphinx PROPERTIES FOLDER lib)
|
||||
include_directories(SYSTEM "lib/tclap-1.2.1/include")
|
||||
|
||||
# ... Google Test
|
||||
set(INSTALL_GTEST OFF) # Prevent library files from ending up in our artifacts
|
||||
FetchContent_Declare(googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG v1.16.0
|
||||
@@ -497,6 +498,12 @@ target_link_libraries(rhubarb-tools
|
||||
|
||||
# Define Rhubarb executable
|
||||
add_executable(rhubarb
|
||||
src/rhubarb/sinks/MachineReadableStderrSink.cpp
|
||||
src/rhubarb/sinks/MachineReadableStderrSink.h
|
||||
src/rhubarb/sinks/NiceStderrSink.cpp
|
||||
src/rhubarb/sinks/NiceStderrSink.h
|
||||
src/rhubarb/sinks/QuietStderrSink.cpp
|
||||
src/rhubarb/sinks/QuietStderrSink.h
|
||||
src/rhubarb/main.cpp
|
||||
src/rhubarb/ExportFormat.cpp
|
||||
src/rhubarb/ExportFormat.h
|
||||
@@ -504,8 +511,6 @@ add_executable(rhubarb
|
||||
src/rhubarb/RecognizerType.h
|
||||
src/rhubarb/semanticEntries.cpp
|
||||
src/rhubarb/semanticEntries.h
|
||||
src/rhubarb/sinks.cpp
|
||||
src/rhubarb/sinks.h
|
||||
)
|
||||
target_include_directories(rhubarb PUBLIC "src/rhubarb")
|
||||
target_link_libraries(rhubarb
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
#include "animation/targetShapeSet.h"
|
||||
#include <boost/utility/in_place_factory.hpp>
|
||||
#include "tools/platformTools.h"
|
||||
#include "sinks.h"
|
||||
#include "sinks/MachineReadableStderrSink.h"
|
||||
#include "sinks/NiceStderrSink.h"
|
||||
#include "sinks/QuietStderrSink.h"
|
||||
#include "semanticEntries.h"
|
||||
#include "RecognizerType.h"
|
||||
#include "recognition/PocketSphinxRecognizer.h"
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
#include "sinks.h"
|
||||
#include "logging/sinks.h"
|
||||
#include "logging/formatters.h"
|
||||
#include "semanticEntries.h"
|
||||
#include "tools/stringTools.h"
|
||||
#include "core/appInfo.h"
|
||||
#include <boost/utility/in_place_factory.hpp>
|
||||
|
||||
using std::string;
|
||||
using std::make_shared;
|
||||
using logging::Level;
|
||||
using logging::StdErrSink;
|
||||
using logging::SimpleConsoleFormatter;
|
||||
using boost::optional;
|
||||
|
||||
NiceStderrSink::NiceStderrSink(Level minLevel) :
|
||||
minLevel(minLevel),
|
||||
progress(0.0),
|
||||
innerSink(make_shared<StdErrSink>(make_shared<SimpleConsoleFormatter>()))
|
||||
{}
|
||||
|
||||
void NiceStderrSink::receive(const logging::Entry& entry) {
|
||||
// For selected semantic entries, print a user-friendly message instead of
|
||||
// the technical log message.
|
||||
if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) {
|
||||
std::cerr
|
||||
<< fmt::format("Generating lip sync data for {}.", startEntry->getInputFilePath().u8string())
|
||||
<< std::endl;
|
||||
startProgressIndication();
|
||||
} else if (const auto* progressEntry = dynamic_cast<const ProgressEntry*>(&entry)) {
|
||||
assert(progressBar);
|
||||
progress = progressEntry->getProgress();
|
||||
progressBar->reportProgress(progress);
|
||||
} else if (dynamic_cast<const SuccessEntry*>(&entry)) {
|
||||
interruptProgressIndication();
|
||||
std::cerr << "Done." << std::endl;
|
||||
} else {
|
||||
// Treat the entry as a normal log message
|
||||
if (entry.level >= minLevel) {
|
||||
const bool inProgress = progressBar.is_initialized();
|
||||
if (inProgress) interruptProgressIndication();
|
||||
innerSink->receive(entry);
|
||||
if (inProgress) resumeProgressIndication();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NiceStderrSink::startProgressIndication() {
|
||||
std::cerr << "Progress: ";
|
||||
progressBar = boost::in_place();
|
||||
}
|
||||
|
||||
void NiceStderrSink::interruptProgressIndication() {
|
||||
progressBar.reset();
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
void NiceStderrSink::resumeProgressIndication() {
|
||||
std::cerr << "Progress (cont'd): ";
|
||||
progressBar = boost::in_place(progress);
|
||||
}
|
||||
|
||||
QuietStderrSink::QuietStderrSink(Level minLevel) :
|
||||
minLevel(minLevel),
|
||||
innerSink(make_shared<StdErrSink>(make_shared<SimpleConsoleFormatter>()))
|
||||
{}
|
||||
|
||||
void QuietStderrSink::receive(const logging::Entry& entry) {
|
||||
// Set inputFilePath as soon as we get it
|
||||
if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) {
|
||||
inputFilePath = startEntry->getInputFilePath();
|
||||
}
|
||||
|
||||
if (entry.level >= minLevel) {
|
||||
if (quietSoFar) {
|
||||
// This is the first message we print. Give a bit of context.
|
||||
const string intro = inputFilePath
|
||||
? fmt::format("{} {} processing file {}:", appName, appVersion, inputFilePath->u8string())
|
||||
: fmt::format("{} {}:", appName, appVersion);
|
||||
std::cerr << intro << std::endl;
|
||||
quietSoFar = false;
|
||||
}
|
||||
innerSink->receive(entry);
|
||||
}
|
||||
}
|
||||
|
||||
MachineReadableStderrSink::MachineReadableStderrSink(Level minLevel) :
|
||||
minLevel(minLevel)
|
||||
{}
|
||||
|
||||
string formatLogProperty(const logging::Entry& entry) {
|
||||
return fmt::format(
|
||||
R"("log": {{ "level": "{}", "message": "{}" }})",
|
||||
entry.level,
|
||||
escapeJsonString(entry.message)
|
||||
);
|
||||
}
|
||||
|
||||
void MachineReadableStderrSink::receive(const logging::Entry& entry) {
|
||||
optional<string> line;
|
||||
if (dynamic_cast<const SemanticEntry*>(&entry)) {
|
||||
if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) {
|
||||
const string file = escapeJsonString(startEntry->getInputFilePath().u8string());
|
||||
line = fmt::format(
|
||||
R"({{ "type": "start", "file": "{}", {} }})",
|
||||
file,
|
||||
formatLogProperty(entry)
|
||||
);
|
||||
} else if (const auto* progressEntry = dynamic_cast<const ProgressEntry*>(&entry)) {
|
||||
const int progressPercent = static_cast<int>(progressEntry->getProgress() * 100);
|
||||
if (progressPercent > lastProgressPercent) {
|
||||
line = fmt::format(
|
||||
R"({{ "type": "progress", "value": {:.2f}, {} }})",
|
||||
progressEntry->getProgress(),
|
||||
formatLogProperty(entry)
|
||||
);
|
||||
lastProgressPercent = progressPercent;
|
||||
}
|
||||
} else if (dynamic_cast<const SuccessEntry*>(&entry)) {
|
||||
line = fmt::format(R"({{ "type": "success", {} }})", formatLogProperty(entry));
|
||||
} else if (const auto* failureEntry = dynamic_cast<const FailureEntry*>(&entry)) {
|
||||
const string reason = escapeJsonString(failureEntry->getReason());
|
||||
line = fmt::format(
|
||||
R"({{ "type": "failure", "reason": "{}", {} }})",
|
||||
reason,
|
||||
formatLogProperty(entry)
|
||||
);
|
||||
} else {
|
||||
throw std::runtime_error("Unsupported type of semantic entry.");
|
||||
}
|
||||
} else {
|
||||
if (entry.level >= minLevel) {
|
||||
line = fmt::format(R"({{ "type": "log", {} }})", formatLogProperty(entry));
|
||||
}
|
||||
}
|
||||
|
||||
if (line) {
|
||||
std::cerr << *line << std::endl;
|
||||
// Make sure the stream is flushed so that applications listening to it get the line immediately
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "logging/Entry.h"
|
||||
#include "logging/Sink.h"
|
||||
#include "tools/ProgressBar.h"
|
||||
#include <filesystem>
|
||||
|
||||
// Prints nicely formatted progress to stderr.
|
||||
// Non-semantic entries are only printed if their log level at least matches the specified minimum level.
|
||||
class NiceStderrSink : public logging::Sink {
|
||||
public:
|
||||
NiceStderrSink(logging::Level minLevel);
|
||||
void receive(const logging::Entry& entry) override;
|
||||
private:
|
||||
void startProgressIndication();
|
||||
void interruptProgressIndication();
|
||||
void resumeProgressIndication();
|
||||
|
||||
logging::Level minLevel;
|
||||
double progress;
|
||||
boost::optional<ProgressBar> progressBar;
|
||||
std::shared_ptr<Sink> innerSink;
|
||||
};
|
||||
|
||||
// Mostly quiet output to stderr.
|
||||
// Entries are only printed if their log level at least matches the specified minimum level.
|
||||
class QuietStderrSink : public logging::Sink {
|
||||
public:
|
||||
QuietStderrSink(logging::Level minLevel);
|
||||
void receive(const logging::Entry& entry) override;
|
||||
private:
|
||||
logging::Level minLevel;
|
||||
bool quietSoFar = true;
|
||||
boost::optional<std::filesystem::path> inputFilePath;
|
||||
std::shared_ptr<Sink> innerSink;
|
||||
};
|
||||
|
||||
// Prints machine-readable progress to stderr.
|
||||
// Non-semantic entries are only printed if their log level at least matches the specified minimum level.
|
||||
class MachineReadableStderrSink : public logging::Sink {
|
||||
public:
|
||||
MachineReadableStderrSink(logging::Level minLevel);
|
||||
void receive(const logging::Entry& entry) override;
|
||||
private:
|
||||
logging::Level minLevel;
|
||||
int lastProgressPercent = -1;
|
||||
};
|
||||
71
rhubarb/src/rhubarb/sinks/MachineReadableStderrSink.cpp
Normal file
71
rhubarb/src/rhubarb/sinks/MachineReadableStderrSink.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "MachineReadableStderrSink.h"
|
||||
#include "semanticEntries.h"
|
||||
#include "tools/stringTools.h"
|
||||
#include <iostream>
|
||||
|
||||
using std::string;
|
||||
using logging::Level;
|
||||
using boost::optional;
|
||||
|
||||
MachineReadableStderrSink::MachineReadableStderrSink(Level minLevel) :
|
||||
minLevel(minLevel)
|
||||
{
|
||||
}
|
||||
|
||||
string formatLogProperty(const logging::Entry& entry) {
|
||||
return fmt::format(
|
||||
R"("log": {{ "level": "{}", "message": "{}" }})",
|
||||
entry.level,
|
||||
escapeJsonString(entry.message)
|
||||
);
|
||||
}
|
||||
|
||||
void MachineReadableStderrSink::receive(const logging::Entry& entry) {
|
||||
optional<string> line;
|
||||
if (dynamic_cast<const SemanticEntry*>(&entry)) {
|
||||
if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) {
|
||||
const string file = escapeJsonString(startEntry->getInputFilePath().u8string());
|
||||
line = fmt::format(
|
||||
R"({{ "type": "start", "file": "{}", {} }})",
|
||||
file,
|
||||
formatLogProperty(entry)
|
||||
);
|
||||
}
|
||||
else if (const auto* progressEntry = dynamic_cast<const ProgressEntry*>(&entry)) {
|
||||
const int progressPercent = static_cast<int>(progressEntry->getProgress() * 100);
|
||||
if (progressPercent > lastProgressPercent) {
|
||||
line = fmt::format(
|
||||
R"({{ "type": "progress", "value": {:.2f}, {} }})",
|
||||
progressEntry->getProgress(),
|
||||
formatLogProperty(entry)
|
||||
);
|
||||
lastProgressPercent = progressPercent;
|
||||
}
|
||||
}
|
||||
else if (dynamic_cast<const SuccessEntry*>(&entry)) {
|
||||
line = fmt::format(R"({{ "type": "success", {} }})", formatLogProperty(entry));
|
||||
}
|
||||
else if (const auto* failureEntry = dynamic_cast<const FailureEntry*>(&entry)) {
|
||||
const string reason = escapeJsonString(failureEntry->getReason());
|
||||
line = fmt::format(
|
||||
R"({{ "type": "failure", "reason": "{}", {} }})",
|
||||
reason,
|
||||
formatLogProperty(entry)
|
||||
);
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Unsupported type of semantic entry.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (entry.level >= minLevel) {
|
||||
line = fmt::format(R"({{ "type": "log", {} }})", formatLogProperty(entry));
|
||||
}
|
||||
}
|
||||
|
||||
if (line) {
|
||||
std::cerr << *line << std::endl;
|
||||
// Make sure the stream is flushed so that applications listening to it get the line immediately
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
15
rhubarb/src/rhubarb/sinks/MachineReadableStderrSink.h
Normal file
15
rhubarb/src/rhubarb/sinks/MachineReadableStderrSink.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "logging/Entry.h"
|
||||
#include "logging/Sink.h"
|
||||
|
||||
// Prints machine-readable progress to stderr.
|
||||
// Non-semantic entries are only printed if their log level at least matches the specified minimum level.
|
||||
class MachineReadableStderrSink : public logging::Sink {
|
||||
public:
|
||||
MachineReadableStderrSink(logging::Level minLevel);
|
||||
void receive(const logging::Entry& entry) override;
|
||||
private:
|
||||
logging::Level minLevel;
|
||||
int lastProgressPercent = -1;
|
||||
};
|
||||
61
rhubarb/src/rhubarb/sinks/NiceStderrSink.cpp
Normal file
61
rhubarb/src/rhubarb/sinks/NiceStderrSink.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "NiceStderrSink.h"
|
||||
#include "logging/sinks.h"
|
||||
#include "logging/formatters.h"
|
||||
#include "semanticEntries.h"
|
||||
#include <boost/utility/in_place_factory.hpp>
|
||||
|
||||
using std::make_shared;
|
||||
using logging::Level;
|
||||
using logging::StdErrSink;
|
||||
using logging::SimpleConsoleFormatter;
|
||||
|
||||
NiceStderrSink::NiceStderrSink(Level minLevel) :
|
||||
minLevel(minLevel),
|
||||
progress(0.0),
|
||||
innerSink(make_shared<StdErrSink>(make_shared<SimpleConsoleFormatter>()))
|
||||
{
|
||||
}
|
||||
|
||||
void NiceStderrSink::receive(const logging::Entry& entry) {
|
||||
// For selected semantic entries, print a user-friendly message instead of
|
||||
// the technical log message.
|
||||
if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) {
|
||||
std::cerr
|
||||
<< fmt::format("Generating lip sync data for {}.", startEntry->getInputFilePath().u8string())
|
||||
<< std::endl;
|
||||
startProgressIndication();
|
||||
}
|
||||
else if (const auto* progressEntry = dynamic_cast<const ProgressEntry*>(&entry)) {
|
||||
assert(progressBar);
|
||||
progress = progressEntry->getProgress();
|
||||
progressBar->reportProgress(progress);
|
||||
}
|
||||
else if (dynamic_cast<const SuccessEntry*>(&entry)) {
|
||||
interruptProgressIndication();
|
||||
std::cerr << "Done." << std::endl;
|
||||
}
|
||||
else {
|
||||
// Treat the entry as a normal log message
|
||||
if (entry.level >= minLevel) {
|
||||
const bool inProgress = progressBar.is_initialized();
|
||||
if (inProgress) interruptProgressIndication();
|
||||
innerSink->receive(entry);
|
||||
if (inProgress) resumeProgressIndication();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NiceStderrSink::startProgressIndication() {
|
||||
std::cerr << "Progress: ";
|
||||
progressBar = boost::in_place();
|
||||
}
|
||||
|
||||
void NiceStderrSink::interruptProgressIndication() {
|
||||
progressBar.reset();
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
void NiceStderrSink::resumeProgressIndication() {
|
||||
std::cerr << "Progress (cont'd): ";
|
||||
progressBar = boost::in_place(progress);
|
||||
}
|
||||
22
rhubarb/src/rhubarb/sinks/NiceStderrSink.h
Normal file
22
rhubarb/src/rhubarb/sinks/NiceStderrSink.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "logging/Entry.h"
|
||||
#include "logging/Sink.h"
|
||||
#include "tools/ProgressBar.h"
|
||||
|
||||
// Prints nicely formatted progress to stderr.
|
||||
// Non-semantic entries are only printed if their log level at least matches the specified minimum level.
|
||||
class NiceStderrSink : public logging::Sink {
|
||||
public:
|
||||
NiceStderrSink(logging::Level minLevel);
|
||||
void receive(const logging::Entry& entry) override;
|
||||
private:
|
||||
void startProgressIndication();
|
||||
void interruptProgressIndication();
|
||||
void resumeProgressIndication();
|
||||
|
||||
logging::Level minLevel;
|
||||
double progress;
|
||||
boost::optional<ProgressBar> progressBar;
|
||||
std::shared_ptr<Sink> innerSink;
|
||||
};
|
||||
37
rhubarb/src/rhubarb/sinks/QuietStderrSink.cpp
Normal file
37
rhubarb/src/rhubarb/sinks/QuietStderrSink.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "QuietStderrSink.h"
|
||||
#include "logging/sinks.h"
|
||||
#include "logging/formatters.h"
|
||||
#include "semanticEntries.h"
|
||||
#include "core/appInfo.h"
|
||||
#include <iostream>
|
||||
|
||||
using std::string;
|
||||
using std::make_shared;
|
||||
using logging::Level;
|
||||
using logging::StdErrSink;
|
||||
using logging::SimpleConsoleFormatter;
|
||||
|
||||
QuietStderrSink::QuietStderrSink(Level minLevel) :
|
||||
minLevel(minLevel),
|
||||
innerSink(make_shared<StdErrSink>(make_shared<SimpleConsoleFormatter>()))
|
||||
{
|
||||
}
|
||||
|
||||
void QuietStderrSink::receive(const logging::Entry& entry) {
|
||||
// Set inputFilePath as soon as we get it
|
||||
if (const auto* startEntry = dynamic_cast<const StartEntry*>(&entry)) {
|
||||
inputFilePath = startEntry->getInputFilePath();
|
||||
}
|
||||
|
||||
if (entry.level >= minLevel) {
|
||||
if (quietSoFar) {
|
||||
// This is the first message we print. Give a bit of context.
|
||||
const string intro = inputFilePath
|
||||
? fmt::format("{} {} processing file {}:", appName, appVersion, inputFilePath->u8string())
|
||||
: fmt::format("{} {}:", appName, appVersion);
|
||||
std::cerr << intro << std::endl;
|
||||
quietSoFar = false;
|
||||
}
|
||||
innerSink->receive(entry);
|
||||
}
|
||||
}
|
||||
18
rhubarb/src/rhubarb/sinks/QuietStderrSink.h
Normal file
18
rhubarb/src/rhubarb/sinks/QuietStderrSink.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "logging/Entry.h"
|
||||
#include "logging/Sink.h"
|
||||
#include <filesystem>
|
||||
|
||||
// Mostly quiet output to stderr.
|
||||
// Entries are only printed if their log level at least matches the specified minimum level.
|
||||
class QuietStderrSink : public logging::Sink {
|
||||
public:
|
||||
QuietStderrSink(logging::Level minLevel);
|
||||
void receive(const logging::Entry& entry) override;
|
||||
private:
|
||||
logging::Level minLevel;
|
||||
bool quietSoFar = true;
|
||||
boost::optional<std::filesystem::path> inputFilePath;
|
||||
std::shared_ptr<Sink> innerSink;
|
||||
};
|
||||
@@ -14,43 +14,73 @@
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
#include "fileTools.h"
|
||||
|
||||
using std::filesystem::path;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
path getBinPath() {
|
||||
static const path binPath = [] {
|
||||
try {
|
||||
// Determine path length
|
||||
const int pathLength = wai_getExecutablePath(nullptr, 0, nullptr);
|
||||
if (pathLength == -1) {
|
||||
throw std::runtime_error("Error determining path length.");
|
||||
}
|
||||
|
||||
// Get path
|
||||
// Note: According to documentation, pathLength does *not* include the trailing zero.
|
||||
// Actually, it does.
|
||||
// In case there are situations where it doesn't, we allocate one character more.
|
||||
std::vector<char> buffer(pathLength + 1);
|
||||
if (wai_getExecutablePath(buffer.data(), static_cast<int>(buffer.size()), nullptr) == -1) {
|
||||
throw std::runtime_error("Error reading path.");
|
||||
}
|
||||
buffer[pathLength] = 0;
|
||||
|
||||
// Convert to std::filesystem::path
|
||||
const string pathString(buffer.data());
|
||||
path result(std::filesystem::canonical(pathString).make_preferred());
|
||||
return result;
|
||||
} catch (...) {
|
||||
std::throw_with_nested(std::runtime_error("Could not determine path of bin directory."));
|
||||
path _getBinPath() {
|
||||
try {
|
||||
// Determine path length
|
||||
const int pathLength = wai_getExecutablePath(nullptr, 0, nullptr);
|
||||
if (pathLength == -1) {
|
||||
throw std::runtime_error("Error determining path length.");
|
||||
}
|
||||
}();
|
||||
return binPath;
|
||||
|
||||
// Get path
|
||||
// Note: According to documentation, pathLength does *not* include the trailing zero.
|
||||
// Actually, it does.
|
||||
// In case there are situations where it doesn't, we allocate one character more.
|
||||
std::vector<char> buffer(pathLength + 1);
|
||||
if (wai_getExecutablePath(buffer.data(), static_cast<int>(buffer.size()), nullptr) == -1) {
|
||||
throw std::runtime_error("Error reading path.");
|
||||
}
|
||||
buffer[pathLength] = 0;
|
||||
|
||||
// Convert to std::filesystem::path
|
||||
const string pathString(buffer.data());
|
||||
return path(std::filesystem::canonical(pathString).make_preferred());
|
||||
} catch (...) {
|
||||
std::throw_with_nested(std::runtime_error("Could not determine path of bin directory."));
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the path of the Rhubarb executable binary.
|
||||
path getBinPath() {
|
||||
static const path result = _getBinPath();
|
||||
return result;
|
||||
}
|
||||
|
||||
path _getBinDirectory() {
|
||||
path binPath = getBinPath();
|
||||
path binDirectory = binPath.parent_path();
|
||||
|
||||
// Perform sanity checks on bin directory
|
||||
path testPath = binDirectory / "res" / "sphinx" / "cmudict-en-us.dict";
|
||||
if (!std::filesystem::exists(testPath)) {
|
||||
throw std::runtime_error(fmt::format(
|
||||
"Found Rhubarb executable at {}, but could not find resource file {}.",
|
||||
binPath.u8string(),
|
||||
testPath.u8string()
|
||||
));
|
||||
}
|
||||
try {
|
||||
throwIfNotReadable(testPath);
|
||||
} catch (...) {
|
||||
throw std::runtime_error(fmt::format(
|
||||
"Cannot read resource file {}. Please check file permissions.",
|
||||
testPath.u8string()
|
||||
));
|
||||
}
|
||||
|
||||
return binDirectory;
|
||||
}
|
||||
|
||||
// Returns the directory containing the Rhubarb executable binary.
|
||||
path getBinDirectory() {
|
||||
return getBinPath().parent_path();
|
||||
static const path result = _getBinDirectory();
|
||||
return result;
|
||||
}
|
||||
|
||||
path getTempFilePath() {
|
||||
|
||||
Reference in New Issue
Block a user