Compare commits
402 Commits
Author | SHA1 | Date |
---|---|---|
|
80abaf60ac | |
|
650eec2247 | |
|
2bbadb8796 | |
|
39a4ddb233 | |
|
bd685131e8 | |
|
b8298a0592 | |
|
78c0f642e2 | |
|
7f4f042121 | |
|
c93295ff81 | |
|
05643abb7d | |
|
3944e31d3a | |
|
fc930a41d8 | |
|
364a5d4fe4 | |
|
205540a91b | |
|
0b4d4ee30d | |
|
b967f00c29 | |
|
a86ec43f23 | |
|
7a04b7ed41 | |
|
5cface0af3 | |
|
9a32641a99 | |
|
ed9a3ab957 | |
|
c4317245b1 | |
|
77588fb40e | |
|
3c0befa070 | |
|
5f293cdd33 | |
|
33c542f2e8 | |
|
3599eb35c1 | |
|
71ec4dca3f | |
|
7ff2d0be6b | |
|
8a94fb7db0 | |
|
74822c4a84 | |
|
2b9d305ea1 | |
|
d6fad367fc | |
|
dda889d6ed | |
|
1a0c2535b2 | |
|
a5ebd593d4 | |
|
b7da2cfd5c | |
|
5a6e8346a3 | |
|
2f6e8bc549 | |
|
df8fd3c1fe | |
|
e57fc97811 | |
|
5fcc8816f4 | |
|
01d37d110a | |
|
3f55afa9a8 | |
|
b012c4f7f2 | |
|
d803140e68 | |
|
b9a75662db | |
|
460378bf50 | |
|
c7925d69f0 | |
|
fef283de43 | |
|
6f0e3ef50b | |
|
a29c1795da | |
|
e3dff54b78 | |
|
8da9219e82 | |
|
2218d9c69b | |
|
18f829d03d | |
|
80e04b36ab | |
|
f3b9017a2c | |
|
6c62318816 | |
|
5c428793c9 | |
|
f55bcebf73 | |
|
8d958d09fb | |
|
06b4855d6d | |
|
c821788569 | |
|
21392d32cc | |
|
f3d4cfbb31 | |
|
357cb0b65e | |
|
c68c12c865 | |
|
e5066b549f | |
|
9ba5fc9653 | |
|
d52bec8e55 | |
|
2bbad258c0 | |
|
a723942f22 | |
|
10632576bd | |
|
1393534624 | |
|
494b1ebebd | |
|
59f2993174 | |
|
367c645bb3 | |
|
238687e33b | |
|
cdc9c5b1c4 | |
|
f4418ff25a | |
|
1d04b01654 | |
|
e87ccc8816 | |
|
3189fc8976 | |
|
e325917abe | |
|
d0c9a294e9 | |
|
11a29ddef6 | |
|
44d6cb83de | |
|
c078e6186e | |
|
d029458c70 | |
|
bfc98a1c81 | |
|
3bf7a00d42 | |
|
7ebe9b53e8 | |
|
610f490046 | |
|
3ed38ada2f | |
|
55a099ddc6 | |
|
bf044ca127 | |
|
c93da48c77 | |
|
ce02a3a003 | |
|
49097b00d7 | |
|
8648ed5640 | |
|
c22550f7f8 | |
|
5e7e6f5f87 | |
|
e13c222e28 | |
|
1625de64e2 | |
|
d077aae74c | |
|
b4a2a295d1 | |
|
e02de085bb | |
|
a446209c31 | |
|
5a6630f4b2 | |
|
ec698be116 | |
|
8f2cc2c5e6 | |
|
1784458931 | |
|
7a70ab32c9 | |
|
f7cca4c789 | |
|
eee8e5d5e5 | |
|
8131cecff0 | |
|
46b146a11a | |
|
8527c1577a | |
|
a3a64d8b5d | |
|
e4a661513e | |
|
f39f9c71d9 | |
|
b94d894c36 | |
|
5169e3e46e | |
|
1a2c77ac5b | |
|
5fe835bde5 | |
|
484fd5bd1c | |
|
33dbf6c579 | |
|
64bdf78b85 | |
|
eb2a6a3264 | |
|
19f6772c30 | |
|
8b06f60746 | |
|
19a6b77529 | |
|
b75a3ca1d9 | |
|
a9de5a0a71 | |
|
5db03da56f | |
|
ce54ba60a7 | |
|
7fcaa2ddf7 | |
|
8f1056dc5f | |
|
f3de163d72 | |
|
dd1884432c | |
|
389fd0480b | |
|
0cb82f3e4e | |
|
ecc8efc565 | |
|
d9d0f37b5a | |
|
6e5af62be7 | |
|
34610d0572 | |
|
19a3144572 | |
|
61731441b3 | |
|
db3615b3c3 | |
|
7bb1bec975 | |
|
4d9ddf334f | |
|
82c0a1531e | |
|
d46e574b8e | |
|
a3252359fb | |
|
df783f9afa | |
|
7e7acb8068 | |
|
1c85dbfc3a | |
|
c3602ef23b | |
|
4b016efae7 | |
|
e5c39efeeb | |
|
ee83c79511 | |
|
138f7dfc4a | |
|
bfafac735e | |
|
e90f559a10 | |
|
04595a0441 | |
|
6da2ca1b2f | |
|
22d8dbee64 | |
|
b2f52824b3 | |
|
ef245ce4ff | |
|
223244ed8c | |
|
f0d3364213 | |
|
1511f0a9e0 | |
|
360f85df42 | |
|
97a6c74c3c | |
|
72d020286f | |
|
55cf80e40b | |
|
4c0d706857 | |
|
24e8da4474 | |
|
d705a0c0ee | |
|
4de8f3d18e | |
|
1fb2eb9024 | |
|
5f451feb00 | |
|
7789d43e47 | |
|
e5c7215cc5 | |
|
dd1108b6cd | |
|
f17cb0cc54 | |
|
908d64d01b | |
|
98fb5e7521 | |
|
1fa8e316a0 | |
|
477a9a77ae | |
|
d0c2174404 | |
|
2a1692c270 | |
|
5166f21524 | |
|
745f601ef4 | |
|
ff5c05d054 | |
|
2b44268d60 | |
|
2f1586624a | |
|
8093258e76 | |
|
9fe37dfbb3 | |
|
c6ce5fa8b8 | |
|
5c308b5adf | |
|
35d70b5f3f | |
|
e06124b5c6 | |
|
14eeebfa80 | |
|
76deebdf6a | |
|
308ee7202e | |
|
a7858252f7 | |
|
7330003f24 | |
|
77d8f2b866 | |
|
53c26c9687 | |
|
5983d2fd65 | |
|
bd5a80e7fd | |
|
9bbdf4ffdf | |
|
93327ff646 | |
|
662fa9c7a2 | |
|
909ed57eda | |
|
d1485d45d4 | |
|
fb02a30b82 | |
|
2b3d38f72c | |
|
a3866486ba | |
|
50a27e7da0 | |
|
e94f7b9aeb | |
|
05abfbc687 | |
|
1c72009019 | |
|
3f40ac0aa2 | |
|
c410c00214 | |
|
8f3cad9510 | |
|
def82a0ee6 | |
|
78ed1c7815 | |
|
b987071009 | |
|
05a0050d52 | |
|
cbf5c53c32 | |
|
d3cf642a43 | |
|
da11232c31 | |
|
3bc4384b44 | |
|
4dc9d4253e | |
|
9c9d79c54d | |
|
b02f37e961 | |
|
876fa024ad | |
|
27965ce208 | |
|
a4231b9783 | |
|
e14f736f41 | |
|
a8df4ac4f5 | |
|
9712483a75 | |
|
62b6394bdf | |
|
d777f760d5 | |
|
14969afab7 | |
|
fa0aff0012 | |
|
faea06933b | |
|
07fe549f42 | |
|
e415d59c16 | |
|
2cce8eebd9 | |
|
4af606ae89 | |
|
bdfd77bc4a | |
|
c86512f73e | |
|
43cf341586 | |
|
651521a8c1 | |
|
3c134bbafe | |
|
0cf5f7f365 | |
|
21bea661c1 | |
|
a24fe8874c | |
|
2eb0948c49 | |
|
727b1d1261 | |
|
3cdc78e889 | |
|
1e5a21dbfb | |
|
6d67f77f62 | |
|
db368b4311 | |
|
f7d4a70d3d | |
|
4614939183 | |
|
4e9a588c66 | |
|
82a76c9971 | |
|
a913fa113b | |
|
6a16a706c9 | |
|
1526ee69ef | |
|
8e1d1fbdd3 | |
|
3b599cc751 | |
|
289b7ba56e | |
|
3e34425c11 | |
|
c19ad1c8d0 | |
|
9cfe577612 | |
|
ea3e88fd62 | |
|
529a32e1b2 | |
|
503ba9104a | |
|
1f6f6d6175 | |
|
f5b7971f52 | |
|
b35e05fe7c | |
|
f44baaa05f | |
|
760f6c2ce6 | |
|
750078618c | |
|
de05f69507 | |
|
2fdd98f5b3 | |
|
18aa0f9e20 | |
|
938079a75f | |
|
600b3429a7 | |
|
eea1eb381c | |
|
d97c880754 | |
|
f4f9ffe883 | |
|
cf13499158 | |
|
0ab009e17a | |
|
2607b9a12b | |
|
c06cfd1389 | |
|
46d0c72601 | |
|
12e7a10ab5 | |
|
5222df725b | |
|
111e40238d | |
|
c679b8fb71 | |
|
261a768e0d | |
|
d4b86357cf | |
|
d98de34b98 | |
|
6d321d2428 | |
|
e81c9da999 | |
|
d732859554 | |
|
2aef178eb0 | |
|
b95a3f621c | |
|
ccbd3ed107 | |
|
4403835268 | |
|
056da65d03 | |
|
e304a741ee | |
|
8fd78d63cf | |
|
a632e7a3b3 | |
|
81111ef96a | |
|
78027ea63c | |
|
206cde4658 | |
|
bd1f8226ec | |
|
734d06ad38 | |
|
a851a76ce5 | |
|
8b025a3522 | |
|
16892ae991 | |
|
ce11e59c04 | |
|
b22378221f | |
|
c65c8b4eb3 | |
|
1c50ece142 | |
|
b62fe8af98 | |
|
c566ac56cc | |
|
229105a965 | |
|
6888dadd04 | |
|
1cb41b8309 | |
|
0a577d1947 | |
|
f356855bbd | |
|
95d46ef0b7 | |
|
26cae93478 | |
|
799f334fa7 | |
|
b3b2366468 | |
|
5198ee9230 | |
|
17b43ad205 | |
|
ddcadad710 | |
|
0447cbb4ff | |
|
8fa494fb77 | |
|
6de7ba020a | |
|
ed27b8470c | |
|
2c0471e79f | |
|
2d314f4bc7 | |
|
f13449f810 | |
|
75407dab54 | |
|
2a5ed95698 | |
|
8c9466bcf3 | |
|
9bf8355742 | |
|
3a0a38575f | |
|
84097756c8 | |
|
0aeb35c42e | |
|
96b0ad9b1d | |
|
da78375a10 | |
|
c9b17e1937 | |
|
8502256241 | |
|
f275267ac7 | |
|
faa3f2b4bb | |
|
c6c31a831c | |
|
aec3dbae01 | |
|
97f172282d | |
|
0e00e58d91 | |
|
944c374415 | |
|
478766ff6e | |
|
b2f702c8f4 | |
|
6c9612d2c3 | |
|
4346552312 | |
|
c4b054176c | |
|
522f6c2019 | |
|
d1bbe8538e | |
|
542a5ee3d8 | |
|
1e29151974 | |
|
5cc13cb16f | |
|
0d488e8de2 | |
|
4ed5908627 | |
|
7a763e8755 | |
|
bf19d267ee | |
|
8be6485685 | |
|
4d45bf7c89 | |
|
4d95b4c2c5 | |
|
8d1c618cec | |
|
942cabd773 | |
|
9f4ebd23e3 | |
|
d4b9a8e0c6 | |
|
f1563919e1 | |
|
c67e916185 | |
|
bbc933a821 | |
|
2f31c5aa61 | |
|
9eef09145e | |
|
baf2423b27 | |
|
895b942df3 | |
|
ce204c68de | |
|
c14fb1c7b2 |
|
@ -0,0 +1,15 @@
|
|||
# Config file for generic text editors.
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
|
@ -0,0 +1,5 @@
|
|||
# Use Git LFS for binary files
|
||||
*.wav filter=lfs diff=lfs merge=lfs -text
|
||||
*.flac filter=lfs diff=lfs merge=lfs -text
|
||||
*.ogg filter=lfs diff=lfs merge=lfs -text
|
||||
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
|
@ -0,0 +1,87 @@
|
|||
name: Build
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- description: Windows - Visual Studio
|
||||
os: windows-2019
|
||||
cmakeOptions: '-G "Visual Studio 16 2019" -A x64'
|
||||
publish: true
|
||||
- description: macOS - Xcode
|
||||
os: macos-13
|
||||
cmakeOptions: ""
|
||||
publish: true
|
||||
- description: Linux - GCC
|
||||
os: ubuntu-20.04
|
||||
cmakeOptions: "-D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10"
|
||||
publish: true
|
||||
- description: Linux - Clang
|
||||
os: ubuntu-20.04
|
||||
cmakeOptions: "-D CMAKE_C_COMPILER=clang-12 -D CMAKE_CXX_COMPILER=clang++-12"
|
||||
publish: false
|
||||
env:
|
||||
BOOST_ROOT: ${{ github.workspace }}/lib/boost
|
||||
BOOST_URL: https://sourceforge.net/projects/boost/files/boost/1.86.0/boost_1_86_0.tar.bz2/download
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
- name: Restore Boost from cache
|
||||
uses: actions/cache@v4
|
||||
id: cache-boost
|
||||
with:
|
||||
path: ${{ env.BOOST_ROOT }}
|
||||
key: ${{ env.BOOST_URL }}
|
||||
- name: Download Boost
|
||||
if: steps.cache-boost.outputs.cache-hit != 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "$RUNNER_OS" == "Windows" ]; then
|
||||
# use forward slashes only
|
||||
BOOST_ROOT=$(echo $BOOST_ROOT | sed 's/\\/\//g')
|
||||
fi
|
||||
mkdir -p $BOOST_ROOT
|
||||
curl --insecure -L $BOOST_URL | tar -xj --strip-components=1 -C $BOOST_ROOT
|
||||
- name: Build Rhubarb
|
||||
shell: bash
|
||||
run: |
|
||||
JAVA_HOME=$JAVA_HOME_11_X64
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ${{ matrix.cmakeOptions }} ..
|
||||
cmake --build . --config Release --target package
|
||||
- name: Run tests
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "$RUNNER_OS" == "Windows" ]; then
|
||||
./build/rhubarb/Release/runTests.exe
|
||||
else
|
||||
./build/rhubarb/runTests
|
||||
fi
|
||||
- name: Upload artifacts
|
||||
if: ${{ matrix.publish }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ matrix.description }}
|
||||
path: build/*.zip
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
- name: Create GitHub release draft
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
draft: true
|
||||
files: "*.zip"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@ -1,3 +1,3 @@
|
|||
/.idea
|
||||
/.vs
|
||||
/build
|
||||
.vs/
|
||||
build/
|
||||
*.user
|
|
@ -0,0 +1,181 @@
|
|||
# Version history
|
||||
|
||||
## Version 1.13.0
|
||||
|
||||
* **Improved** animation rules for "F" sound when using just the basic mouth shapes.
|
||||
|
||||
## Version 1.12.0
|
||||
|
||||
* **Added** support for skinning in Rhubarb for Spine ([issue #108](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/108))
|
||||
|
||||
## Version 1.11.0
|
||||
|
||||
* **Added** support for more WAVE file features ([issue #101](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/101))
|
||||
* **Changed** Rhubarb Lip Sync for Spine so that it works with any modern JRE ([issue #97](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/97))
|
||||
* **Changed** Windows build from 32 bit to 64 bit ([issue #98](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/98))
|
||||
|
||||
## Version 1.10.0
|
||||
|
||||
* **Added** switch data file exporter for Moho (formerly Anime Studio) and OpenToonz ([issue #69](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/69))
|
||||
* **Added** support for Spine 3.8 beta ([issue #74](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/74))
|
||||
* **Improved** animation rule for OW sound: animating it as E-F rather than F.
|
||||
|
||||
## Version 1.9.1
|
||||
|
||||
* **Fixed** segmentation fault on OS X ([issue #65](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/65)).
|
||||
|
||||
## Version 1.9.0
|
||||
|
||||
* **Added** basic support for non-English recordings through phonetic recognition ([issue #45](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/45)).
|
||||
* **Improved** processing speed for WAVE files ([issue #58](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/58)).
|
||||
* **Fixed** a bug that resulted in unwanted mouth movement at beginning of a recording ([issue #53](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/53)).
|
||||
* **Fixed** a bug that garbled special characters in the output file path ([issue #54](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/54)).
|
||||
* **Fixed** a bug that prevented the progress bar from reaching 100% ([issue #48](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/48)).
|
||||
* **Fixed** file paths in exported XML and JSON files ([issue #59](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/59)).
|
||||
|
||||
## Version 1.8.0
|
||||
|
||||
* **Added** support for Ogg Vorbis (.ogg) file format ([issue #40](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/40)).
|
||||
* **Fixed** build error with some versions of Boost ([issue #41](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/41)).
|
||||
|
||||
## Version 1.7.2
|
||||
|
||||
* **Fixed** bug in Rhubarb for Spine where processing failed depending on the number of existing animations ([issue #34](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/34#issuecomment-378198776)).
|
||||
|
||||
## Version 1.7.1
|
||||
|
||||
* **Added** more helpful error dialogs for internal errors in Rhubarb Lip Sync for Spine.
|
||||
* **Added**: Internal errors in Rhubarb Lip Sync for Spine are logged to the console (`stderr`).
|
||||
* **Fixed** generic error message in Rhubarb for Spine ([issue #34](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/34)).
|
||||
|
||||
## Version 1.7.0
|
||||
|
||||
* **Added** integration with Spine animation software (Rhubarb Lip Sync for Spine).
|
||||
* **Added** full Unicode support: File names, dialog files, strings in exported files etc. should now be fully Unicode-compatible.
|
||||
* **Added** `--machineReadable` command-line option to allow for better integration with other applications.
|
||||
* **Added** `--consoleLevel` command-line option to control how much detail to log to the console (`stderr`).
|
||||
* **Changed** message output to the console: Unless specified using `--consoleLevel`, only errors and fatal errors are printed to the console. Previously, warnings were also printed.
|
||||
* **Fixed** segfault with WAVE file containing some initial music before spoken words ([issue #25](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/25))
|
||||
|
||||
## Version 1.6.0
|
||||
|
||||
* **Added** a script for lip-syncing in Adobe After Effects.
|
||||
* **Added** `--output` command-line option.
|
||||
* **Changed** the official spelling of the project: Rhubarb Lip-Sync is now Rhubarb Lip Sync (without the hyphen).
|
||||
|
||||
## Version 1.5.0
|
||||
|
||||
* **Added** animation code optimizing animation for words containing "to".
|
||||
* **Improved** animation rules: better animation of ER and AW sounds.
|
||||
* **Fixed** compilation with Boost 1.56.0+ ([issue #9](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/9)).
|
||||
|
||||
## Version 1.4.2
|
||||
|
||||
* **Fixed** incorrect animation before some pauses ([issue #7](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/7)).
|
||||
|
||||
## Version 1.4.1
|
||||
|
||||
* **Fixed** crash with message "Time range start must not be less than end." ([issue #6](https://github.com/DanielSWolf/rhubarb-lip-sync/issues/6))
|
||||
|
||||
## Version 1.4.0
|
||||
|
||||
* **Added** animation code preventing long static segments.
|
||||
|
||||
Watch yourself in a mirror saying "He seized his keys." Your lips barely moved, right? That's exactly what would happen in previous versions of Rhubarb Lip Sync. Only worse: Because there is only one "clenched teeth" mouth shape, the mouth would stay completely static during phrases like this. Rhubarb Lip Sync 1.4.0 now does what [a professional animator would do](http://animateducated.blogspot.de/2016/10/lip-sync-animation-2.html?showComment=1478861729702#c2940729096183546458): It opens the mouth a bit wider for some syllables, keeping the lips moving. This may be cheating, but it looks much better!
|
||||
|
||||
* **Improved** animation rules to use wide-open mouth shape more often.
|
||||
|
||||
Previous versions used mouth shape D (the wide-open mouth) very sparingly. This release uses it more often, which makes the resulting animation more lively and interesting.
|
||||
|
||||
## Version 1.3.0
|
||||
|
||||
* **Improved** animation algorithm: Implemented new, bidirectional animation algorithm.
|
||||
|
||||
Since version 1.0.0, Rhubarb Lip Sync has used a predictive animation algorithm. That means that in many situations (usually before a vowel), the mouth *anticipates* the upcoming sound. It moves *ahead of time*, resulting in more natural animation.
|
||||
|
||||
For version 1.3.0, this core animation algorithm has been re-written from scratch. The new algorithm still anticipates the *next* vowel, but now also considers the *previous* vowel. The resulting animation is even closer to human speech.
|
||||
|
||||
* **Added** artistic timing.
|
||||
|
||||
Previous versions of Rhubarb Lip Sync have tried to reproduce the timing of the recording as precisely as possible. For rapid speech, this often resulted in jittery animation that didn't look good: It tried to fit too much information into the available time. Traditional animators have known this problem since the 1930s. Instead of slavishly following the timing of the recording, they focus on important sounds and mouth shapes, showing them earlier (and thus longer) than would be realistic. On the other hand, they often skip unimportant sounds and mouth shapes altogether.
|
||||
|
||||
Rhubarb Lip Sync 1.3.0 adds a new step in the animation pipeline that emulates this artistic approach. The resulting animation looks much cleaner and smoother. Ironically, it also looks more in-sync than the precise animation created by earlier versions.
|
||||
|
||||
* **Added** `--extendedShapes` command-line option.
|
||||
|
||||
Previous versions of Rhubarb Lip Sync used a fixed set of eight or nine mouth shapes for animation. If users wanted to use fewer mouth shapes, they had to modify the output, for instance by replacing every "X" shape with an "A". This version of Rhubarb Lip Sync introduces the `--extendedShapes` command-line option that allows the user to specify which mouth shapes should be used. This is not only more convenient; knowing which mouth shapes are actually available also allows Rhubarb Lip Sync to create better animation.
|
||||
|
||||
* **Added** `--quiet` mode.
|
||||
|
||||
A "quiet" mode has been added. In that mode, Rhubarb Lip Sync doesn't create any output except for animation data and error messages. This is helpful when using Rhubarb Lip Sync as part of an automated process.
|
||||
|
||||
* **Improved** animation rules and tweening for better animation.
|
||||
|
||||
Animation rules define which mouth shapes can be used to represent a specific sound. For this release, there have been many tweaks to the animation rules, making some sounds look much more convincing. In addition, the rules for inbetweens ("tweening") have been improved. As in traditional animation, the mouth now "pops" open without inbetweens, then closes smoothly.
|
||||
|
||||
* **Improved** pause animations.
|
||||
|
||||
Pauses in speech are tricky to animate. Early version of Rhubarb Lip Sync always closed the mouth, which looks strange for very short pauses. Later versions kept the mouth open for short pauses, which can also look weird if the first mouth shape *after* the pause is identical to the mouth shape *during* the pause: It looks as if somebody just forgot to animate that part.
|
||||
|
||||
This version of Rhubarb Lip Sync uses three different strategies for animating pauses, depending on the duration of the pause and the mouth shapes before and after it.
|
||||
|
||||
* **Fixed** bugs in the grapheme-to-phoneme algorithm.
|
||||
|
||||
Rhubarb Lip Sync comes with a huge dictionary containing pronunciations for more than 100,000 English words. If the dialog text contains words not found in this dictionary, Rhubarb Lip Sync will try to guess the correct pronunciation. I've fixed several bugs in the G2P algorithm that does this. As a result, using the `--dialogFile` option now results in even better animation.
|
||||
|
||||
## Version 1.2.0
|
||||
|
||||
* **Improved** dialog handling to allow for incorrect input dialog.
|
||||
|
||||
Since version 1.0.0, Rhubarb Lip Sync can handle situations where the dialog text is specified (using the `-dialogFile` option), but the actual recording omits some words. For instance, the specified dialog text can be "That's all gobbledygook to me," but the recording only says "That's gobbledygook to me," dropping the word "all."
|
||||
|
||||
Until now, however, Rhubarb Lip Sync couldn't handle *changed* or *inserted* words, such as a recording saying "That's *just* gobbledygook to me." This restriction has been removed. As of version 1.2.0, the actual recording may freely deviate from the specified dialog text. Rhubarb Lip Sync will ignore the dialog file where it audibly differs from the recording, and benefit from it where it matches.
|
||||
|
||||
## Version 1.1.0
|
||||
|
||||
* **Improved** speech recognition to be more reliable.
|
||||
|
||||
The first step in automatic lip sync is speech recognition.
|
||||
Rhubarb Lip Sync 1.1.0 recognizes spoken dialog more accurately, especially at the beginning of recordings.
|
||||
This improves the overall quality of the resulting animation.
|
||||
|
||||
* **Improved** breath detection to be more accurate.
|
||||
|
||||
Rhubarb Lip Sync animates not only dialog, but also noises such as taking a breath.
|
||||
For this version, the accuracy of breath detection has been improved.
|
||||
You shouldn't see actors opening their mouth for no reason any more.
|
||||
|
||||
* **Improved** animation of short pauses.
|
||||
|
||||
During short pauses between words or sentences (up to 0.35s), the mouth is kept open.
|
||||
Now, this open mouth shape is chosen based on the previous and following mouth shapes.
|
||||
This gives pauses in speech a more natural, less mechanical look.
|
||||
|
||||
* **Added** capability to build on Linux
|
||||
|
||||
In addition to Windows and OS X, Rhubarb Lip Sync can now be built on Linux systems.
|
||||
I'm not offering binary distributions for Linux at this time.
|
||||
To build the application yourself, you need CMake, Boost, and a C++14-compatible compiler.
|
||||
|
||||
## Version 1.0.0
|
||||
|
||||
* **Improved** animation algorithm: More realistic animation using new, predictive algorithm.
|
||||
* **Added** tweening for smoother animation.
|
||||
* **Added** support for non-dialog noises (breathing, smacking, etc.)
|
||||
* **Improved** processing speed substantially through multithreading.
|
||||
* **Improved** reliability of voice recognition.
|
||||
* **Added** support for long recordings (I've tested a 30-minute file).
|
||||
* **Added** capability to handle recording that deviate from the specified dialog text.
|
||||
* **Added** capability to handle unknown words as well as numbers, abbreviations, etc. in the specified dialog text.
|
||||
|
||||
## Version 0.2.0
|
||||
|
||||
* **Added** multiple output formats: TSV, XML, JSON.
|
||||
* **Added** experimental option to supply dialog text.
|
||||
* **Improved** error handling and error messages.
|
||||
|
||||
## Version 0.1.0
|
||||
|
||||
* **Added** two-pass phone detection using [CMU PocketSphinx](http://cmusphinx.sourceforge.net/).
|
||||
* **Added** fixed set of eight mouth shapes, based on the Hanna-Barbera shapes.
|
||||
* **Added** naive (but well-tuned) mapping from phones to mouth shapes.
|
171
CMakeLists.txt
|
@ -1,166 +1,41 @@
|
|||
cmake_minimum_required(VERSION 3.3)
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
# Support legacy OS X versions
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.7" CACHE STRING "Minimum OS X deployment version")
|
||||
|
||||
set(appName "Rhubarb Lip Sync")
|
||||
set(appVersionMajor 0)
|
||||
set(appVersionMinor 2)
|
||||
set(appVersionPatch 0)
|
||||
set(appVersionSuffix "")
|
||||
set(appVersion "${appVersionMajor}.${appVersionMinor}.${appVersionPatch}${appVersionSuffix}")
|
||||
include(appInfo.cmake)
|
||||
|
||||
project(${appName})
|
||||
|
||||
# Enable C++14
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
|
||||
endif()
|
||||
# Build and install main executable
|
||||
add_subdirectory(rhubarb)
|
||||
|
||||
# Make sure Xcode uses libc++ instead of libstdc++, allowing us to use the C++14 standard library prior to OS X 10.9
|
||||
if("${CMAKE_GENERATOR}" STREQUAL "Xcode")
|
||||
add_compile_options(-stdlib=libc++)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
|
||||
endif()
|
||||
# Build and install extras
|
||||
add_subdirectory("extras/AdobeAfterEffects")
|
||||
add_subdirectory("extras/MagixVegas")
|
||||
add_subdirectory("extras/EsotericSoftwareSpine")
|
||||
|
||||
# Use static run-time
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
add_compile_options(/MT$<$<CONFIG:Debug>:d>)
|
||||
endif()
|
||||
|
||||
# Set global flags and define flags variables for later use
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
set(enableWarningsFlags "-Wall;-Wextra")
|
||||
set(disableWarningsFlags "-w")
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
set(enableWarningsFlags "/W4")
|
||||
set(disableWarningsFlags "/W0")
|
||||
|
||||
# Disable warning C4456: declaration of '...' hides previous local declaration
|
||||
# I'm doing that on purpose.
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4458")
|
||||
endif()
|
||||
|
||||
# Enable project folders
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
# Define libraries
|
||||
|
||||
# ... Boost
|
||||
set(Boost_USE_STATIC_LIBS ON) # Use static libs
|
||||
set(Boost_USE_MULTITHREADED ON) # Enable multithreading support
|
||||
set(Boost_USE_STATIC_RUNTIME ON) # Use static C++ runtime
|
||||
find_package(Boost REQUIRED COMPONENTS filesystem locale system)
|
||||
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
|
||||
|
||||
# ... C++ Format
|
||||
include_directories(SYSTEM "lib/cppformat")
|
||||
FILE(GLOB cppFormatFiles "lib/cppformat/*.cc")
|
||||
add_library(cppFormat ${cppFormatFiles})
|
||||
target_compile_options(cppFormat PRIVATE ${disableWarningsFlags})
|
||||
set_target_properties(cppFormat PROPERTIES FOLDER lib)
|
||||
|
||||
# ... sphinxbase
|
||||
include_directories(SYSTEM "lib/sphinxbase-5prealpha-2015-08-05/include")
|
||||
FILE(GLOB_RECURSE sphinxbaseFiles "lib/sphinxbase-5prealpha-2015-08-05/src/libsphinxbase/*.c")
|
||||
add_library(sphinxbase ${sphinxbaseFiles})
|
||||
target_compile_options(sphinxbase PRIVATE ${disableWarningsFlags})
|
||||
set_target_properties(sphinxbase PROPERTIES FOLDER lib)
|
||||
|
||||
# ... PocketSphinx
|
||||
include_directories(SYSTEM "lib/pocketsphinx-5prealpha-2015-08-05/include" "lib/pocketsphinx-5prealpha-2015-08-05/src/libpocketsphinx")
|
||||
FILE(GLOB pocketSphinxFiles "lib/pocketsphinx-5prealpha-2015-08-05/src/libpocketsphinx/*.c")
|
||||
add_library(pocketSphinx ${pocketSphinxFiles})
|
||||
target_link_libraries(pocketSphinx sphinxbase)
|
||||
target_compile_options(pocketSphinx PRIVATE ${disableWarningsFlags})
|
||||
set_target_properties(pocketSphinx PROPERTIES FOLDER lib)
|
||||
|
||||
# ... TCLAP
|
||||
include_directories(SYSTEM "lib/tclap-1.2.1/include")
|
||||
|
||||
# ... Google Test
|
||||
add_subdirectory("lib/googletest")
|
||||
set_target_properties(gmock PROPERTIES FOLDER lib)
|
||||
set_target_properties(gmock_main PROPERTIES FOLDER lib)
|
||||
set_target_properties(gtest PROPERTIES FOLDER lib)
|
||||
set_target_properties(gtest_main PROPERTIES FOLDER lib)
|
||||
|
||||
# ... GSL
|
||||
include_directories(SYSTEM "lib/gsl/include")
|
||||
|
||||
# Define executable
|
||||
include_directories("src" "src/audio_input")
|
||||
configure_file(src/appInfo.cpp.in src/appInfo.cpp ESCAPE_QUOTES)
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/appInfo.cpp
|
||||
src/main.cpp
|
||||
src/Phone.cpp src/Phone.h
|
||||
src/Shape.cpp src/Shape.h
|
||||
src/centiseconds.cpp src/centiseconds.h
|
||||
src/EnumConverter.h
|
||||
src/mouthAnimation.cpp src/mouthAnimation.h
|
||||
src/phoneExtraction.cpp src/phoneExtraction.h
|
||||
src/platformTools.cpp src/platformTools.h
|
||||
src/tools.cpp src/tools.h
|
||||
src/audio/AudioStream.cpp src/audio/AudioStream.h
|
||||
src/audio/DCOffset.cpp src/audio/DCOffset.h
|
||||
src/audio/SampleRateConverter.cpp src/audio/SampleRateConverter.h
|
||||
src/audio/UnboundedStream.cpp src/audio/UnboundedStream.h
|
||||
src/audio/voiceActivityDetection.cpp src/audio/voiceActivityDetection.h
|
||||
src/audio/WaveFileReader.cpp src/audio/WaveFileReader.h
|
||||
src/audio/waveFileWriting.cpp src/audio/waveFileWriting.h
|
||||
src/stringTools.cpp src/stringTools.h
|
||||
src/NiceCmdLineOutput.cpp src/NiceCmdLineOutput.h
|
||||
src/TablePrinter.cpp src/TablePrinter.h
|
||||
src/ProgressBar.cpp src/ProgressBar.h
|
||||
src/logging.cpp src/logging.h
|
||||
src/Timed.h
|
||||
src/TimeRange.cpp src/TimeRange.h
|
||||
src/Timeline.h
|
||||
src/Exporter.cpp src/Exporter.h
|
||||
# Install misc. files
|
||||
install(
|
||||
FILES README.adoc LICENSE.md CHANGELOG.md
|
||||
DESTINATION .
|
||||
)
|
||||
add_executable(rhubarb ${SOURCE_FILES})
|
||||
target_link_libraries(rhubarb ${Boost_LIBRARIES} cppFormat sphinxbase pocketSphinx)
|
||||
target_compile_options(rhubarb PUBLIC ${enableWarningsFlags})
|
||||
|
||||
# Define test project
|
||||
#include_directories("${gtest_SOURCE_DIR}/include")
|
||||
set(TEST_FILES
|
||||
tests/stringToolsTests.cpp
|
||||
tests/TimelineTests.cpp
|
||||
src/stringTools.cpp src/stringTools.h
|
||||
src/Timeline.h
|
||||
src/TimeRange.cpp src/TimeRange.h
|
||||
src/centiseconds.cpp src/centiseconds.h
|
||||
)
|
||||
add_executable(runTests ${TEST_FILES})
|
||||
target_link_libraries(runTests gtest gmock gmock_main)
|
||||
# Configure CPack
|
||||
function(get_short_system_name variable)
|
||||
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
|
||||
set(${variable} "macOS" PARENT_SCOPE)
|
||||
else()
|
||||
set(${variable} "${CMAKE_SYSTEM_NAME}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
set(CPACK_PACKAGE_NAME ${appName})
|
||||
string(REPLACE " " "-" CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
|
||||
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
|
||||
set(CPACK_SYSTEM_NAME "OSX")
|
||||
endif()
|
||||
get_short_system_name(CPACK_SYSTEM_NAME)
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR ${appVersionMajor})
|
||||
set(CPACK_PACKAGE_VERSION_MINOR ${appVersionMinor})
|
||||
set(CPACK_PACKAGE_VERSION_PATCH ${appVersionPatch})
|
||||
set(CPACK_PACKAGE_VERSION ${appVersion})
|
||||
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
|
||||
set(CPACK_GENERATOR ZIP)
|
||||
|
||||
# Copy resource files at build time; install them at package time
|
||||
include(tools.cmake)
|
||||
set(modelDir "${CMAKE_SOURCE_DIR}/lib/pocketsphinx-5prealpha-2015-08-05/model")
|
||||
copy_and_install("${modelDir}/en-us/*" "res/sphinx")
|
||||
copy_and_install("${modelDir}/en-us/en-us/*" "res/sphinx/acoustic-model")
|
||||
|
||||
install(
|
||||
TARGETS rhubarb
|
||||
RUNTIME
|
||||
DESTINATION .
|
||||
)
|
||||
install(
|
||||
FILES README.md LICENSE.md VERSION.md
|
||||
DESTINATION .
|
||||
)
|
||||
|
||||
# Run CPack
|
||||
include(CPack)
|
||||
|
|
272
LICENSE.md
|
@ -2,133 +2,271 @@
|
|||
|
||||
## Summary
|
||||
|
||||
This summary is only meant to give you a quick overview. It is not legally binding. The actual license terms are defined by the quoted license texts below.
|
||||
This summary is not legally binding. The actual license terms are defined by the license texts below.
|
||||
|
||||
* Rhubarb Lip Sync and all of its components (libraries, resources, etc.) are under the MIT license or a similar permissive license. This means that you can use Rhubarb Lip Sync in almost any way you want. You may even create commercial software based on it.
|
||||
* When you run Rhubarb Lip Sync on an audio file, the resulting lip-sync data belongs to you alone. This means that if you use Rhubarb Lip Sync in the production process of a video game, an animated cartoon, or a similar product *that doesn't ship with lip-sync functionality*, you don't even have to care about the MIT license.
|
||||
* Rhubarb Lip Sync is released under the MIT license. All its third-party dependencies (libraries, resources, etc.) are released under the MIT license, a BSD license, or a similar permissive license. This means that you can use Rhubarb Lip Sync in almost any way you want, including the creation of commercial software based on it.
|
||||
* When you run Rhubarb Lip Sync on an audio file, the resulting lip sync data belongs to you alone. This means that if you use Rhubarb Lip Sync in the production process of a video game, an animated cartoon, or a similar product *that doesn't ship with lip sync functionality*, you don't even have to care about the MIT license.
|
||||
|
||||
## Individual Licenses
|
||||
## Rhubarb Lip Sync
|
||||
|
||||
### Rhubarb Lip Sync
|
||||
[Rhubarb Lip Sync](https://github.com/DanielSWolf/rhubarb-lip-sync) is released under the **MIT License (MIT)**.
|
||||
|
||||
All parts of [Rhubarb Lip Sync](https://github.com/DanielSWolf/rhubarb-lip-sync) that are not listed with their own license below are released under the **MIT License (MIT)**.
|
||||
|
||||
> Copyright (c) 2015 Daniel Wolf
|
||||
>
|
||||
> Copyright (c) 2015-2016 Daniel Wolf
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
### Boost
|
||||
## Third-party dependencies
|
||||
|
||||
### `[boost]` Boost
|
||||
|
||||
The [Boost](http://www.boost.org/) libraries are released under the **Boost Software License**.
|
||||
|
||||
> Boost Software License - Version 1.0 - August 17th, 2003
|
||||
>
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following:
|
||||
>
|
||||
>
|
||||
> The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
### C++ Format
|
||||
### `[cmusphinx-en-us]` CMU Sphinx US English acoustic model
|
||||
|
||||
The [CMU Sphinx US English acoustic model](https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/US%20English/) is released under a variation of the **2-clause BSD License**.
|
||||
|
||||
> Copyright (c) 2015 Alpha Cephei Inc. All rights reserved.
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
>
|
||||
> 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
> 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY ALPHA CEPHEI INC. ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALPHA CEPHEI INC. NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
### `[cppformat]` C++ Format
|
||||
|
||||
The [C++ Format](https://github.com/cppformat/cppformat) library is released under the **2-clause BSD License**.
|
||||
|
||||
> Copyright (c) 2012 - 2015, Victor Zverovich
|
||||
>
|
||||
>
|
||||
> All rights reserved.
|
||||
>
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
>
|
||||
>
|
||||
> 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
> 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
>
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
### CMU Sphinx common libraries (sphinxbase)
|
||||
### `[flite]` Flite
|
||||
|
||||
The [sphinxbase](https://github.com/cmusphinx/sphinxbase) library is released under a variation of the **2-clause BSD License**.
|
||||
The [CMU Flite](http://www.festvox.org/flite/) engine is released under a **BSD**-like license. For details see the license file in the Flite directory.
|
||||
|
||||
> Copyright (c) 1999-2015 Carnegie Mellon University. All rights reserved.
|
||||
>
|
||||
> Language Technologies Institute
|
||||
> Carnegie Mellon University
|
||||
> Copyright (c) 1999-2008
|
||||
> All Rights Reserved.
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to use and distribute this software and its documentation without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of this work, and to permit persons to whom this work is furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> 1. The code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
> 2. Any modifications must be clearly marked as such.
|
||||
> 3. Original authors' names are not deleted.
|
||||
> 4. The authors' names are not used to endorse or promote products derived from this software without specific prior written permission.
|
||||
>
|
||||
> CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
### `[gsl]` Guidelines Support Library
|
||||
|
||||
The [Guidelines Support Library](https://github.com/Microsoft/GSL) is released under the **MIT License (MIT)**.
|
||||
|
||||
> Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||
>
|
||||
> This code is licensed under the MIT License (MIT).
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
### `[ogg]` libogg
|
||||
|
||||
libogg is released under the **3-clause BSD license**.
|
||||
|
||||
> Copyright (c) 2002, Xiph.org Foundation
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
>
|
||||
> 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
> 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
>
|
||||
> This work was supported in part by funding from the Defense Advanced Research Projects Agency and the National Science Foundation of the United States of America, and the CMU Sphinx Speech Consortium.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
>
|
||||
> - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
>
|
||||
> - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
>
|
||||
> - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
### PocketSphinx
|
||||
### `[pocketsphinx]` PocketSphinx
|
||||
|
||||
The [PocketSphinx](https://github.com/cmusphinx/pocketsphinx) library is released under a variation of the **2-clause BSD License**.
|
||||
|
||||
> Copyright (c) 1999-2015 Carnegie Mellon University. All rights reserved.
|
||||
>
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
>
|
||||
>
|
||||
> 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
> 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
>
|
||||
>
|
||||
> This work was supported in part by funding from the Defense Advanced Research Projects Agency and the National Science Foundation of the United States of America, and the CMU Sphinx Speech Consortium.
|
||||
>
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
### US english acoustic model
|
||||
### `[soundchange]` Sound Change Applier
|
||||
|
||||
The US english acoustic model that is distributed along with the [PocketSphinx](https://github.com/cmusphinx/pocketsphinx) library is released under a variation of the **2-clause BSD License**.
|
||||
The [Sound Change Applier](http://www.zompist.com/sounds.htm) and its [rule set for American English](http://www.zompist.com/spell.html) are released under the **MIT License (MIT)**.
|
||||
|
||||
> Copyright (c) 2015 Alpha Cephei Inc. All rights reserved.
|
||||
>
|
||||
> **The MIT License (MIT)**
|
||||
>
|
||||
> Copyright (c) 2000 Mark Rosenfelder
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
### `[sphinxbase]` CMU Sphinx common libraries
|
||||
|
||||
The [sphinxbase](https://github.com/cmusphinx/sphinxbase) library is released under a variation of the **2-clause BSD License**.
|
||||
|
||||
> Copyright (c) 1999-2015 Carnegie Mellon University. All rights reserved.
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
>
|
||||
>
|
||||
> 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
> 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY ALPHA CEPHEI INC. ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALPHA CEPHEI INC. NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
>
|
||||
> This work was supported in part by funding from the Defense Advanced Research Projects Agency and the National Science Foundation of the United States of America, and the CMU Sphinx Speech Consortium.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
### Templatized C++ Command Line Parser Library (TCLAP)
|
||||
### `[tclap]` Templatized C++ Command Line Parser Library
|
||||
|
||||
The [TCLAP](http://tclap.sourceforge.net/) library is released under the **MIT License (MIT)**.
|
||||
|
||||
> Copyright (c) 2003 Michael E. Smoot
|
||||
>
|
||||
> Copyright (c) 2003 Michael E. Smoot
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
>
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
>
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
### Google Test
|
||||
### `[utfcpp]` UTF8-CPP
|
||||
|
||||
The [Google Test](https://github.com/google/googletest) framework is released under the **3-clause BSD License**.
|
||||
The [UTF8-CPP](https://github.com/nemtrif/utfcpp) library is released under the **Boost Software License**.
|
||||
|
||||
> Copyright 2008, Google Inc.
|
||||
> All rights reserved.
|
||||
>
|
||||
> Copyright 2006 Nemanja Trifunovic
|
||||
>
|
||||
>Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following:
|
||||
>
|
||||
> The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
### `[utf8proc]` utf8proc
|
||||
|
||||
The [utf8proc](https://github.com/JuliaLang/utf8proc) library is released under the **MIT License (MIT)**, while some of its data is released under the **UNICODE License**.
|
||||
|
||||
#### utf8proc license
|
||||
|
||||
> **utf8proc** is a software package originally developed by Jan Behrens and the rest of the Public Software Group, who deserve nearly all of the credit for this library, that is now maintained by the Julia-language developers. Like the original utf8proc, whose copyright and license statements are reproduced below, all new work on the utf8proc library is licensed under the [MIT "expat" license](http://opensource.org/licenses/MIT):
|
||||
>
|
||||
> *Copyright © 2014-2015 by Steven G. Johnson, Jiahao Chen, Tony Kelman, Jonas Fonseca, and other contributors listed in the git history.*
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#### Original utf8proc license
|
||||
|
||||
> *Copyright (c) 2009, 2013 Public Software Group e. V., Berlin, Germany*
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#### Unicode data license
|
||||
|
||||
> This software distribution contains derived data from a modified version of the Unicode data files. The following license applies to that data:
|
||||
>
|
||||
> **COPYRIGHT AND PERMISSION NOTICE**
|
||||
>
|
||||
> *Copyright (c) 1991-2007 Unicode, Inc. All rights reserved. Distributed under the Terms of Use in http://www.unicode.org/copyright.html.*
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy of the Unicode data files and any associated documentation (the "Data Files") or Unicode software and any associated documentation (the "Software") to deal in the Data Files or Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Data Files or Software, and to permit persons to whom the Data Files or Software are furnished to do so, provided that (a) the above copyright notice(s) and this permission notice appear with all copies of the Data Files or Software, (b) both the above copyright notice(s) and this permission notice appear in associated documentation, and (c) there is clear notice in each modified Data File or in the Software as well as in the documentation associated with the Data File(s) or Software that the data or software has been modified.
|
||||
>
|
||||
> THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA FILES OR SOFTWARE.
|
||||
>
|
||||
> Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in these Data Files or Software without prior written authorization of the copyright holder.
|
||||
>
|
||||
> Unicode and the Unicode logo are trademarks of Unicode, Inc., and may be registered in some jurisdictions. All other trademarks and registered trademarks mentioned herein are the property of their respective owners.
|
||||
|
||||
### `[vorbis]` libvorbis
|
||||
|
||||
libvorbis is released under the **3-clause BSD license**.
|
||||
|
||||
> Copyright (c) 2002-2018 Xiph.org Foundation
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
>
|
||||
>* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
>
|
||||
> - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
>
|
||||
> - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
>
|
||||
> - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
### `[webrtc]` WebRTC
|
||||
|
||||
The [WebRTC](https://chromium.googlesource.com/external/webrtc) library is released under the **3-clause BSD License**.
|
||||
|
||||
> Copyright (c) 2011, The WebRTC project authors. All rights reserved.
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
>
|
||||
> * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
> * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
> * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
> * Neither the name of Google nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
### Guidelines Support Library (GSL)
|
||||
### `[whereami]` Where Am I?
|
||||
|
||||
The [Guidelines Support Library](https://github.com/Microsoft/GSL) is released under the **MIT License (MIT)**.
|
||||
The [Where Am I?](https://github.com/gpakosz/whereami) library is released under the **DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE**.
|
||||
|
||||
> DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
> Version 2, December 2004
|
||||
>
|
||||
> Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
>
|
||||
> Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
|
||||
>
|
||||
> DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
>
|
||||
> 0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
> 1. Bla bla bla
|
||||
> 2. Montesqieu et camembert, vive la France, zut alors!
|
||||
>
|
||||
> WTFPLv2 is very permissive, see http://www.wtfpl.net/faq/
|
||||
>
|
||||
> However, if this WTFPLV2 is REALLY a blocker and is the reason you can't use this project, contact me and I'll dual license it.
|
||||
|
||||
> Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||
>
|
||||
> This code is licensed under the MIT License (MIT).
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
>
|
|
@ -0,0 +1,408 @@
|
|||
= Rhubarb Lip Sync
|
||||
:toc:
|
||||
:icons: font
|
||||
|
||||
:A: Ⓐ
|
||||
:B: Ⓑ
|
||||
:C: Ⓒ
|
||||
:D: Ⓓ
|
||||
:E: Ⓔ
|
||||
:F: Ⓕ
|
||||
:G: Ⓖ
|
||||
:H: Ⓗ
|
||||
:X: Ⓧ
|
||||
|
||||
image:https://img.shields.io/twitter/follow/RhubarbLipSync.svg?style=social&label=Follow["Twitter", link="https://twitter.com/RhubarbLipSync"]
|
||||
image:https://github.com/DanielSWolf/rhubarb-lip-sync/actions/workflows/ci.yml/badge.svg["Build status", link="https://github.com/DanielSWolf/rhubarb-lip-sync/actions/workflows/ci.yml"]
|
||||
|
||||
---
|
||||
|
||||
image:img/logo.png[align="center"]
|
||||
|
||||
---
|
||||
|
||||
Rhubarb Lip Sync allows you to quickly create 2D mouth animation from voice recordings. It analyzes your audio files, recognizes what is being said, then automatically generates lip sync information. You can use it for animating speech in computer games, animated cartoons, or any similar project.
|
||||
|
||||
Rhubarb Lip Sync integrates with the following applications:
|
||||
|
||||
* *Adobe After Effects* (see <<afterEffects,below>>)
|
||||
* *Moho* and *OpenToonz* (see <<moho,below>>)
|
||||
* *Spine* by Esoteric Software (see <<spine,below>>)
|
||||
* *Vegas Pro* by Magix (see <<vegas,below>>)
|
||||
* *Visionaire Studio* (see https://www.visionaire-studio.net/forum/thread/mouth-animation-using-rhubarb-lip-sync[external link])
|
||||
|
||||
In addition, you can use Rhubarb Lip Sync's command line interface (*CLI*) to generate files in various <<outputFormats,output formats>> (<<tsv,TSV>>/<<xml,XML>>/<<json,JSON>>).
|
||||
|
||||
== Demo video
|
||||
|
||||
Click the image for a demo video.
|
||||
|
||||
https://www.youtube.com/watch?v=zzdPSFJRlEo[image:http://img.youtube.com/vi/zzdPSFJRlEo/0.jpg[]]
|
||||
|
||||
== Integrations
|
||||
|
||||
[[afterEffects]]
|
||||
=== Adobe After Effects
|
||||
|
||||
You can use Rhubarb Lip Sync to animate dialog right from Adobe After Effects. For more information, <<extras/AdobeAfterEffects/README.adoc#,follow this link>> or see the directory `extras/AdobeAfterEffects`.
|
||||
|
||||
image:img/after-effects.png[]
|
||||
|
||||
[[moho]]
|
||||
=== Moho and OpenToonz
|
||||
|
||||
Rhubarb Lip Sync can create .dat switch data files, which are understood by Moho and OpenToonz. You can set the frame rate using the `--datFrameRate` option; to control the shape names, use the `--datUsePrestonBlair` flag. For more details, see <<options>>.
|
||||
|
||||
image:img/moho.png[]
|
||||
|
||||
[[spine]]
|
||||
=== Spine by Esoteric Software
|
||||
|
||||
Rhubarb Lip Sync for Spine is a graphical tool that allows you to import a Spine project, perform automatic lip sync, then re-import the result into Spine. For more information, <<extras/EsotericSoftwareSpine/README.adoc#,follow this link>> or see the directory `extras/EsotericSoftwareSpine` of the download.
|
||||
|
||||
image:img/spine.png[]
|
||||
|
||||
[[vegas]]
|
||||
=== Vegas Pro by Magix
|
||||
|
||||
Rhubarb Lip Sync also comes with two plugin scripts for Vegas Pro (previously Sony Vegas). For more information, <<extras/MagixVegas/README.adoc#,follow this link>> or see the directory `extras/MagixVegas` of the download.
|
||||
|
||||
image:img/vegas.png[]
|
||||
|
||||
[[mouth-shapes]]
|
||||
== Mouth shapes
|
||||
|
||||
Rhubarb Lip Sync can use between six and nine different mouth positions. The first six mouth shapes ({A}-{F}) are the _basic mouth shapes_ and the absolute minimum you have to draw for your character. These six mouth shapes were invented at the Hanna-Barbera studios for shows such as Scooby-Doo and The Flintstones. Since then, they have evolved into a _de-facto_ standard for 2D animation, and have been widely used by studios like Disney and Warner Bros.
|
||||
|
||||
In addition to the six basic mouth shapes, there are three _extended mouth shapes_: {G}, {H}, and {X}. These are optional. You may choose to draw all three of them, pick just one or two, or leave them out entirely.
|
||||
|
||||
[cols="1h,2,6"]
|
||||
|===
|
||||
|
||||
| {A} | image:img/lisa-A.png[]
|
||||
| Closed mouth for the "`P`", "`B`", and "`M`" sounds. This is almost identical to the {X} shape, but there is ever-so-slight pressure between the lips.
|
||||
|
||||
| {B} | image:img/lisa-B.png[]
|
||||
| Slightly open mouth with clenched teeth. This mouth shape is used for most consonants ("`K`", "`S`", "`T`", etc.). It's also used for some vowels such as the "`EE`" sound in b**ee**.
|
||||
|
||||
| {C} | image:img/lisa-C.png[]
|
||||
| Open mouth. This mouth shape is used for vowels like "`EH`" as in m**e**n and "`AE`" as in b**a**t. It's also used for some consonants, depending on context.
|
||||
|
||||
This shape is also used as an in-between when animating from {A} or {B} to {D}. So make sure the animations {A}{C}{D} and {B}{C}{D} look smooth!
|
||||
|
||||
| {D} | image:img/lisa-D.png[]
|
||||
| Wide open mouth. This mouth shapes is used for vowels like "`AA`" as in f**a**ther.
|
||||
|
||||
| {E} | image:img/lisa-E.png[]
|
||||
| Slightly rounded mouth. This mouth shape is used for vowels like "`AO`" as in **o**ff and "`ER`" as in b**ir**d.
|
||||
|
||||
This shape is also used as an in-between when animating from {C} or {D} to {F}. Make sure the mouth isn't wider open than for {C}. Both {C}{E}{F} and {D}{E}{F} should result in smooth animation.
|
||||
|
||||
| {F} | image:img/lisa-F.png[]
|
||||
| Puckered lips. This mouth shape is used for "`UW`" as in y**ou**, "`OW`" as in sh**ow**, and "`W`" as in **w**ay.
|
||||
|
||||
| {G} | image:img/lisa-G.png[]
|
||||
| Upper teeth touching the lower lip for "`F`" as in **f**or and "`V`" as in **v**ery.
|
||||
|
||||
*This extended mouth shape is optional.* If your art style is detailed enough, it greatly improves the overall look of the animation. If you decide not to use it, you can specify so using the <<extendedShapes,`extendedShapes`>> option.
|
||||
|
||||
| {H} | image:img/lisa-H.png[]
|
||||
| This shape is used for long "`L`" sounds, with the tongue raised behind the upper teeth. The mouth should be at least far open as in {C}, but not quite as far as in {D}.
|
||||
|
||||
*This extended mouth shape is optional.* Depending on your art style and the angle of the head, the tongue may not be visible at all. In this case, there is no point in drawing this extra shape. If you decide not to use it, you can specify so using the <<extendedShapes,`extendedShapes`>> option.
|
||||
|
||||
| {X} | image:img/lisa-X.png[]
|
||||
| Idle position. This mouth shape is used for pauses in speech. This should be the same mouth drawing you use when your character is walking around without talking. It is almost identical to {A}, but with slightly less pressure between the lips: For {X}, the lips should be closed but relaxed.
|
||||
|
||||
*This extended mouth shape is optional.* Whether there should be any visible difference between the rest position {X} and the closed talking mouth {A} depends on your art style and personal taste. If you decide not to use it, you can specify so using the <<extendedShapes,`extendedShapes`>> option.
|
||||
|===
|
||||
|
||||
== How to run Rhubarb Lip Sync
|
||||
|
||||
=== General usage ===
|
||||
|
||||
Rhubarb Lip Sync is a command-line tool that is currently available for Windows, macOS, and Linux.
|
||||
|
||||
* Download the https://github.com/DanielSWolf/rhubarb-lip-sync/releases[latest release] for your operating system and unpack the file anywhere on your computer.
|
||||
* On the command-line, call `rhubarb`, passing it an audio file as argument and telling it where to create the output file. In its simplest form, this might look like this: `rhubarb -o output.txt my-recording.wav`. There are additional <<options,command-line options>> you can specify in order to get better results.
|
||||
* Rhubarb Lip Sync will analyze the sound file, animate it, and create an output file containing the animation. If an error occurs, it will instead print an error message to `stderr` and exit with a non-zero exit code.
|
||||
|
||||
[[options]]
|
||||
=== Command-line options ===
|
||||
|
||||
==== Basic command-line options ====
|
||||
|
||||
The following command-line options are the most common:
|
||||
|
||||
[cols="2,5a"]
|
||||
|===
|
||||
| Option | Description
|
||||
|
||||
| _<input file>_
|
||||
| The audio file to be analyzed. This must be the last command-line argument. Supported file formats are WAVE (.wav) and Ogg Vorbis (.ogg).
|
||||
|
||||
| `-r` _<recognizer>_, `--recognizer` _<recognizer>_
|
||||
| Specifies how Rhubarb Lip Sync recognizes speech within the recording. Options: `pocketSphinx` (use for English recordings), `phonetic` (use for non-English recordings). For details, see <<recognizers>>.
|
||||
|
||||
_Default value: ``pocketSphinx``_
|
||||
|
||||
| `-f` _<format>_, `--exportFormat` _<format>_
|
||||
| The export format. Options: `tsv` (tab-separated values, see <<tsv,details>>), `xml` (see <<xml,details>>), `json` (see <<json,details>>), `dat` (see <<moho>>).
|
||||
|
||||
_Default value: ``tsv``_
|
||||
|
||||
| `-d` _<path>_, `--dialogFile` _<path>_
|
||||
| With this option, you can provide Rhubarb Lip Sync with the dialog text to get more reliable results. Specify the path to a plain-text file (in ASCII or UTF-8 format) containing the dialog contained in the audio file. Rhubarb Lip Sync will still perform word recognition internally, but it will prefer words and phrases that occur in the dialog file. This leads to better recognition results and thus more reliable animation.
|
||||
|
||||
For instance, let's say you're recording dialog for a computer game. The script says: "`That's all gobbledygook to me.`" But actually, the voice artist ends up saying "`That's _just_ gobbledygook to me,`" deviating from the dialog. If you specify a dialog file with the original line ("`That's all gobbledygook to me`"), this will still allow Rhubarb Lip Sync to produce better results, because it will watch out for the uncommon word "`gobbledygook`". Rhubarb Lip Sync will ignore the dialog file where it audibly differs from the recording, and benefit from it where it matches.
|
||||
|
||||
_It is always a good idea to specify the dialog text. This will usually lead to more reliable mouth animation, even if the text is not completely accurate._
|
||||
|
||||
[[extendedShapes]]
|
||||
| `--extendedShapes` _<string>_
|
||||
| As described in <<mouth-shapes>>, Rhubarb Lip Sync uses six basic mouth shapes and up to three _extended mouth shapes_, which are optional. Use this option to specify which extended mouth shapes should be used. For example, to use only the {G} and {X} extended mouth shapes, specify `GX`; to use only the six basic mouth shapes, specify an empty string: `""`.
|
||||
|
||||
_Default value: ``GHX``_
|
||||
|
||||
| `-o`, `--output` _<output file>_
|
||||
| The name of the output file to create. If the file already exists, it will be overwritten. If you don't specify an output file, the result will be written to `stdout`.
|
||||
|
||||
| `--version`
|
||||
| Displays version information and exits.
|
||||
|
||||
| `-h`, `--help`
|
||||
| Displays usage information and exits.
|
||||
|
||||
| `--datFrameRate` _number_
|
||||
| Only valid when using the `dat` export format. Controls the frame rate for the output file.
|
||||
|
||||
_Default value: 24_
|
||||
|
||||
| `--datUsePrestonBlair`
|
||||
| Only valid when using the `dat` export format. Uses Preston Blair mouth shapes names instead of the default alphabetical ones. This applies the following mapping:
|
||||
|
||||
!===
|
||||
! Alphabetic name ! Preston Blair name
|
||||
|
||||
! A ! MBP
|
||||
! B ! etc
|
||||
! C ! E
|
||||
! D ! AI
|
||||
! E ! O
|
||||
! F ! U
|
||||
! G ! FV
|
||||
! H ! L
|
||||
! X ! rest
|
||||
!===
|
||||
|
||||
*Caution:* This mapping is only applied when exporting, _after_ the recording has been animated. To control which mouth shapes to use, use the <<extendedShapes,`extendedShapes`>> option _with the alphabetic names_.
|
||||
|
||||
*Tip:* For optimal results, make sure your mouth drawings follow the guidelines in the <<mouth-shapes>> section. This is easier if you stick to the alphabetic names instead of the Preston Blair names. The only situation where you _need_ to use the Preston Blair names is when you're using OpenToonz, because OpenToonz only supports the Preston Blair names.
|
||||
|
||||
|===
|
||||
|
||||
==== Advanced command-line options ====
|
||||
|
||||
The following command-line options can be helpful in special situations, especially when automating Rhubarb Lip Sync.
|
||||
|
||||
[cols="2,5"]
|
||||
|===
|
||||
| Option | Description
|
||||
|
||||
[[quiet]]
|
||||
| `-q`, `--quiet`
|
||||
| By default, Rhubarb Lip Sync writes a number of progress messages to `stderr`. If you're using it as part of a batch process, this may clutter your console. If you specify the `--quiet` flag, there won't be any output to `stderr` unless an error occurred.
|
||||
|
||||
You can combine this option with the <<consoleLevel,`consoleLevel`>> option to change the minimum event level that is printed to `stderr`.
|
||||
|
||||
| `--machineReadable`
|
||||
a| This option is useful if you want to integrate Rhubarb Lip Sync with another (possibly graphical) application. All status messages to `stderr` will be in structured JSON format, allowing your program to parse them and display a graphical progress bar or something similar. For details, see <<machineReadable,Machine-readable status messages>>.
|
||||
|
||||
[[consoleLevel]]
|
||||
| `--consoleLevel` _<level>_
|
||||
| Sets the log level for reporting to the console (`stderr`). Options: `trace`, `debug`, `info`, `warning`, `error`, `fatal`.
|
||||
|
||||
If <<quiet,`--quiet`>> is also specified, only events with the specified level or higher will be printed. Otherwise, a small number of essential events (startup, progress, etc.) will be printed even if their levels are below the specified value.
|
||||
|
||||
_Default value: ``error``_
|
||||
|
||||
| `--logFile` _<path>_
|
||||
| Creates a log file with diagnostic information at the specified path.
|
||||
|
||||
|`--logLevel` _<level>_
|
||||
| Sets the log level for the log file. Only events with the specified level or higher will be logged. Options: `trace`, `debug`, `info`, `warning`, `error`, `fatal`.
|
||||
|
||||
_Default value: ``debug``_
|
||||
|
||||
| `--threads` _<number>_
|
||||
| Rhubarb Lip Sync uses multithreading to speed up processing. By default, it creates as many worker threads as there are cores on your CPU, which results in optimal processing speed. You may choose to specify a lower number if you feel that Rhubarb Lip Sync is slowing down other applications. Specifying a higher number is not recommended, as it won't result in any additional speed-up.
|
||||
|
||||
Note that for short audio files, Rhubarb Lip Sync may choose to use fewer threads than specified.
|
||||
|
||||
_Default value: as many threads as your CPU has cores_
|
||||
|===
|
||||
|
||||
[[recognizers]]
|
||||
== Recognizers
|
||||
|
||||
The first step in processing an audio file is determining what is being said. More specifically, Rhubarb Lip Sync uses speech recognition to figure out what sound is being said at what point in time. You can choose between two recognizers:
|
||||
|
||||
=== PocketSphinx
|
||||
|
||||
PocketSphinx is an open-source speech recognition library that generally gives good results. This is the default recognizer. The downside is that PocketSphinx only recognizes English dialog. So if your recordings are in a language other than English, this is not a good choice.
|
||||
|
||||
=== Phonetic
|
||||
|
||||
Rhubarb Lip Sync also comes with a phonetic recognizer. _Phonetic_ means that this recognizer won't try to understand entire (English) words and phrases. Instead, it will recognize individual sounds and syllables. The results are usually less precise than those from the PocketSphinx recognizer. The advantage is that this recognizer is language-independent. Use it if your recordings are not in English.
|
||||
|
||||
[[outputFormats]]
|
||||
== Output formats
|
||||
|
||||
The output of Rhubarb Lip Sync is a file that tells you which mouth shape to display at what time within the recording. You can choose between three file formats -- TSV, XML, and JSON. The following paragraphs show you what each of these formats looks like.
|
||||
|
||||
[[tsv]]
|
||||
=== Tab-separated values (`tsv`)
|
||||
|
||||
TSV is the simplest and most compact export format supported by Rhubarb Lip Sync. Each line starts with a timestamp (in seconds), followed by a tab, followed by the name of the mouth shape. The following is the output for a recording of a person saying 'Hi.'
|
||||
|
||||
[source]
|
||||
----
|
||||
0.00 X
|
||||
0.05 D
|
||||
0.27 C
|
||||
0.31 B
|
||||
0.43 X
|
||||
0.47 X
|
||||
----
|
||||
|
||||
Here's how to read it:
|
||||
|
||||
* At the beginning of the recording (0.00s), the mouth is closed (shape {X}). The very first output will always have the timestamp 0.00s.
|
||||
* 0.05s into the recording, the mouth opens wide (shape {D}) for the "`HH`" sound, anticipating the "`AY`" sound that will follow.
|
||||
* The second half of the "`AY`" diphtong (0.31s into the recording) requires clenched teeth (shape {B}). Before that, shape {C} is inserted as an in-between at 0.27s. This allows for a smoother animation from {D} to {B}.
|
||||
* 0.43s into the recording, the dialog is finished and the mouth closes again (shape {X}).
|
||||
* The last output line in TSV format is special: Its timestamp is always the very end of the recording (truncated to a multiple of 0.01s) and its value is always a closed mouth (shape {X} or {A}, depending on your <<extendedShapes,`extendedShapes`>> settings).
|
||||
|
||||
[[xml]]
|
||||
=== XML format (`xml`)
|
||||
|
||||
XML format is rather verbose. The following is the output for a person saying 'Hi,' the same recording as above.
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rhubarbResult>
|
||||
<metadata>
|
||||
<soundFile>C:\Users\Daniel\Desktop\av\hi\hi.wav</soundFile>
|
||||
<duration>0.47</duration>
|
||||
</metadata>
|
||||
<mouthCues>
|
||||
<mouthCue start="0.00" end="0.05">X</mouthCue>
|
||||
<mouthCue start="0.05" end="0.27">D</mouthCue>
|
||||
<mouthCue start="0.27" end="0.31">C</mouthCue>
|
||||
<mouthCue start="0.31" end="0.43">B</mouthCue>
|
||||
<mouthCue start="0.43" end="0.47">X</mouthCue>
|
||||
</mouthCues>
|
||||
</rhubarbResult>
|
||||
----
|
||||
|
||||
The file starts with a `metadata` block containing the full path of the original recording and its duration (truncated to a multiple of 0.01s). After that, each `mouthCue` element indicates the start and end of a certain mouth shape, as explained for <<tsv,TSV format>>. Note that the end of each mouth cue is identical with the start of the following one. This is a bit redundant, but it means that we don't need a special final element like in TSV format.
|
||||
|
||||
[[json]]
|
||||
=== JSON format (`json`)
|
||||
|
||||
JSON format is very similar to <<xml,XML format>>. The choice mainly depends on the programming language you use, which may have built-in support for one format but not the other. The following is the output for a person saying 'Hi,' the same recording as above.
|
||||
|
||||
[source,json]
|
||||
----
|
||||
{
|
||||
"metadata": {
|
||||
"soundFile": "C:\\Users\\Daniel\\Desktop\\av\\hi\\hi.wav",
|
||||
"duration": 0.47
|
||||
},
|
||||
"mouthCues": [
|
||||
{ "start": 0.00, "end": 0.05, "value": "X" },
|
||||
{ "start": 0.05, "end": 0.27, "value": "D" },
|
||||
{ "start": 0.27, "end": 0.31, "value": "C" },
|
||||
{ "start": 0.31, "end": 0.43, "value": "B" },
|
||||
{ "start": 0.43, "end": 0.47, "value": "X" }
|
||||
]
|
||||
}
|
||||
----
|
||||
|
||||
There is nothing surprising here; everything said about XML format applies to JSON, too.
|
||||
|
||||
[[machineReadable]]
|
||||
== Machine-readable status messages
|
||||
|
||||
Use the `--machineReadable` command-line option to enable machine-readable status messages. In this mode, each line printed to `stderr` will be an object in JSON format. Every object contains the following:
|
||||
|
||||
* Property `type`: The type of the event. Currently, one of `"start"` (application start), `"progress"` (numeric progress), `"success"` (successful termination), `"failure"` (unsuccessful termination), and `"log"` (a log message without structured information).
|
||||
* Event-specific structured data. For instance, a `"progress"` event contains the property `value` with a numeric value between 0.0 and 1.0.
|
||||
* Property `log`: A log message describing the event, plus severity information. If you aren't interested in the structured data, you can display this as a fallback. For instance, a `"progress"` event with the structured information `"value": 0.69` may contain the following redundant log message: `"Progress: 69%"`.
|
||||
|
||||
You can combine this option with the <<consoleLevel,`consoleLevel`>> option. Note, however, that this only affects unstructured events of type `"log"` (not to be confused with the `log` property each event contains).
|
||||
|
||||
The following is an example output to `stderr` from a _successful_ run:
|
||||
|
||||
[source,json]
|
||||
----
|
||||
{ "type": "start", "file": "hi.wav", "log": { "level": "Info", "message": "Application startup. Input file: \"hi.wav\"." } }
|
||||
{ "type": "progress", "value": 0.00, "log": { "level": "Trace", "message": "Progress: 0%" } }
|
||||
{ "type": "progress", "value": 0.01, "log": { "level": "Trace", "message": "Progress: 1%" } }
|
||||
{ "type": "progress", "value": 0.03, "log": { "level": "Trace", "message": "Progress: 3%" } }
|
||||
{ "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...
|
||||
{ "type": "success", "log": { "level": "Info", "message": "Application terminating normally." } }
|
||||
----
|
||||
|
||||
The following is an example output to `stderr` from a _failed_ run:
|
||||
|
||||
[source,json]
|
||||
----
|
||||
{ "type": "start", "file": "no-such-file.wav", "log": { "level": "Info", "message": "Application startup. Input file: \"no-such-file.wav\"." } }
|
||||
{ "type": "failure", "reason": "Error processing file \"no-such-file.wav\".\nCould not open sound file \"no-such-file.wav\".\nNo such file or directory", "log": { "level": "Fatal", "message": "Application terminating with error: Error processing file \"no-such-file.wav\".\nCould not open sound file \"no-such-file.wav\".\nNo such file or directory" } }
|
||||
----
|
||||
|
||||
Note that the output format <<Versioning,adheres to SemVer>>. That means that the JSON output created after a minor upgrade will still be compatible. Note, however, that the following kinds of changes may occur at any time, because I consider them non-breaking:
|
||||
|
||||
* Additional types of progress events. Just ignore those events whose types you do not know or use their unstructured `log` property.
|
||||
* Additional properties in any object. Just ignore properties you aren't interested in.
|
||||
* Changes in JSON formatting, such as a re-ordering of properties or changes in whitespaces (except for line breaks -- every event will remain on a singe line)
|
||||
* Fewer or more events of type `"log"` or changes in the wording of log messages
|
||||
|
||||
[[versioning]]
|
||||
== Versioning (SemVer)
|
||||
|
||||
Rhubarb Lip Sync uses Semantic Versioning (SemVer) for its command-line interface. For general information on Semantic Versioning, have a look at the http://semver.org/[official SemVer website].
|
||||
|
||||
As a rule of thumb, everything you can use through the command-line interface adheres to SemVer. Everything else (i.e., the source code, integrations with third-party software, etc.) does not.
|
||||
|
||||
[[building-from-source]]
|
||||
== Building from source
|
||||
|
||||
To use Rhubarb Lip Sync on Windows, macOS, or Linux, you can just download the binary release for your operating system. If you want to modify the code or use Rhubarb on a less-common operating system, this section describes how to build it yourself.
|
||||
|
||||
You'll need the following software installed:
|
||||
|
||||
* CMake 3.10+
|
||||
* A C{plus}{plus} compiler that supports C{plus}{plus}17 +
|
||||
(Rhubarb Lip Sync is regularly built using Visual Studio 2019, Xcode 14, GCC 10, and Clang 12.)
|
||||
* A current version of Boost
|
||||
* JDK 8.x (for building Rhubarb for Spine)
|
||||
|
||||
Then, follow these steps:
|
||||
|
||||
. Create an empty directory `/build` within the Rhubarb repository
|
||||
. Move to the new `/build` directory
|
||||
. Configure CMake by running `cmake ..` +
|
||||
Optionally, pass flags for setting the generator, compiler etc.. For working examples, see `.github\workflows\ci.yml`.
|
||||
. Build Rhubarb Lip Sync by running `cmake --build . --config Release`
|
||||
|
||||
== I'd love to hear from you!
|
||||
|
||||
Have you created something great using Rhubarb Lip Sync? -- *https://twitter.com/RhubarbLipSync[Let me know on Twitter]* or *send me an email* at +++dwolf@dannad.de+++!
|
||||
|
||||
Do you need help? Have you spotted a bug? Do you have a suggestion? -- *https://github.com/DanielSWolf/rhubarb-lip-sync/issues[Create an issue!]*
|
119
README.md
|
@ -1,119 +0,0 @@
|
|||
# Rhubarb Lip-Sync
|
||||
|
||||
[Rhubarb Lip-Sync](https://github.com/DanielSWolf/rhubarb-lip-sync) is a command-line tool that automatically creates mouth animation from voice recordings. You can use it for characters in computer games, in animated cartoons, or in any other project that requires animating mouths based on existing recordings.
|
||||
|
||||
Rhubarb Lip-Sync produces output files in various text formats (TSV/XML/JSON). If you're a programmer, this makes it easy for you to use the output in whatever way you like. If you're not a programmer, there is currently no direct way to import the result into your favorite animation tool. If this is what you need, feel free to [create an issue](https://github.com/DanielSWolf/rhubarb-lip-sync/issues) telling me what tool you're using. I might add support for a few popular animation tools in the future.
|
||||
|
||||
## Mouth shapes
|
||||
|
||||
Rhubarb Lip-Sync uses a fixed set of eight mouth shapes, named from A-H. These mouth shapes are based on the six mouth shapes (A-F) originally developed at the Hanna-Barbera animation studios for classic shows such as Scooby-Doo and The Flintstones.
|
||||
|
||||
| Name | Image | Description |
|
||||
| ---- | ----- | ----------- |
|
||||
| A |  | Closed mouth for rest position and the *P*, *B*, and *M* sounds. |
|
||||
| B |  | Slightly open mouth with clenched teeth. Used for most consonants as well as the *EE* sound in b**ee** or sh**e**. |
|
||||
| C |  | Open mouth for the vowels *EH* as in r**e**d, m**e**n; *IH* as in b**i**g, w**i**n; *AH* as in b**u**t, s**u**n, **a**lone; and *EY* as in s**a**y, **e**ight. |
|
||||
| D |  | Wide open mouth for the vowels *AA* as in f**a**ther; *AE* as in **a**t, b**a**t; *AY* as in m**y**, wh**y**, r**i**de; and *AW* as in h**o**w, n**o**w. |
|
||||
| E |  | Slightly rounded mouth for the vowels *AO* as in **o**ff, f**a**ll; *UH* as in sh**ou**ld, c**ou**ld; *OW* as in sh**o**w, c**o**at; and *ER* as in h**er**, b**ir**d. |
|
||||
| F |  | Small rounded mouth for *UW* as in y**ou**, n**ew**; *OY* as in b**o**y, t**o**y; and *W* as in **w**ay. |
|
||||
| G |  | Biting the lower lip for the *F* and *V* sounds. |
|
||||
| H |  | The *L* sound with the tongue slightly visible. |
|
||||
|
||||
## How to run Rhubarb Lip-Sync
|
||||
|
||||
Rhubarb Lip-Sync is a command-line tool that is currently available for Windows and OS X.
|
||||
|
||||
* Download the [latest release](https://github.com/DanielSWolf/rhubarb-lip-sync/releases) and unzip the file anywhere on your computer.
|
||||
* Call `rhubarb`, passing it a WAVE file as argument, and redirecting the output to a file. This might look like this: `rhubarb my-recording.wav > output.txt`.
|
||||
* Rhubarb Lip-Sync will analyze the sound file and print the result to `stdout`. If you've redirected `stdout` to a file like above, you will now have an XML file containing the lip-sync data.
|
||||
|
||||
The following is a complete list of available command-line options.
|
||||
|
||||
| Option | Description |
|
||||
| ------ | ----------- |
|
||||
| `-f` *format*,<br/>`--exportFormat` *format* | The export format. Options: `tsv` (tab-separated values), `xml`, `json`. Default value: `tsv` |
|
||||
| `-d` *text*,<br/>`--dialog` *text* | Allows you to explicitly specify the text of the dialog rather than relying on Rhubarb Lip-Sync's automatic recognition. This is an experimental feature. Currently, the main limitation is that each word must be contained in Rhubarb Lip-Sync's internal dictionary, or the program will fail. |
|
||||
| `--logFile` *path* | Creates a log file with diagnostic information at the specified path. |
|
||||
| `--logLevel` *level* | Sets the log level for the log file. Options: `trace`, `debug`, `info`, `warning`, `error`, `fatal`. Default value: `debug` |
|
||||
| `--version` | Displays version information and exits. |
|
||||
| `-h`,<br/>`--help` | Displays usage information and exits. |
|
||||
| *input file* | The input file to be analyzed. Must be an sound file in WAVE format. ||
|
||||
|
||||
## How to use the output
|
||||
|
||||
The output of Rhubarb Lip-Sync is a file that tells you which mouth shape to display at what time within the recording. You can choose between three file formats -- TSV, XML, and JSON. The following paragraphs show you what each of these formats looks like.
|
||||
|
||||
### Tab-separated values (`tsv`)
|
||||
|
||||
TSV is the simplest and most compact export format supported by Rhubarb Lip-Sync. Each line starts with a timestamp (in seconds), followed by a tab, followed by the name of the mouth shape. The following is the output for a recording of a person saying 'Hi.'
|
||||
|
||||
```
|
||||
0.00 A
|
||||
0.09 C
|
||||
0.17 D
|
||||
0.38 A
|
||||
0.47 A
|
||||
```
|
||||
|
||||
You see that at the beginning of the recording, the mouth is closed (shape A). 0.09s into the recording, the mouth opens (shape C); a little later, it opens even wider (shape D). 0.38s into the recording, it closes again (shape A).
|
||||
|
||||
The last output line in TSV format is special: Its timestamp is always the very end of the recording (truncated to a multiple of 0.01s) and its value is always a closed mouth (shape A).
|
||||
|
||||
### XML format (`xml`)
|
||||
|
||||
XML format is rather verbose. The following is the output for a person saying 'Hi,' the same recording as above.
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rhubarbResult>
|
||||
<metadata>
|
||||
<soundFile>C:\Users\Daniel\Desktop\audio-test\hi.wav</soundFile>
|
||||
<duration>0.47</duration>
|
||||
</metadata>
|
||||
<mouthCues>
|
||||
<mouthCue start="0.00" end="0.09">A</mouthCue>
|
||||
<mouthCue start="0.09" end="0.17">C</mouthCue>
|
||||
<mouthCue start="0.17" end="0.38">D</mouthCue>
|
||||
<mouthCue start="0.38" end="0.47">A</mouthCue>
|
||||
</mouthCues>
|
||||
</rhubarbResult>
|
||||
```
|
||||
|
||||
The file starts with a `metadata` block containing the full path of the original recording and its duration (truncated to a multiple of 0.01s). After that, each `mouthCue` element indicates the start and end of a certain mouth shape, as explained for TSV format. Note that the end of each mouth cue is identical with the start of the following one. This is a bit redundant, but it means that we don't need a special final element like in TSV format.
|
||||
|
||||
### JSON format (`json`)
|
||||
|
||||
JSON format is very similar to XML format -- the choice mainly depends on which is better supported by your programming language. The following is the output for a person saying 'Hi,' the same recording as above.
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"soundFile": "C:\\Users\\Daniel\\Desktop\\audio-test\\hi.wav",
|
||||
"duration": 0.47
|
||||
},
|
||||
"mouthCues": [
|
||||
{ "start": 0.00, "end": 0.09, "value": "A" },
|
||||
{ "start": 0.09, "end": 0.17, "value": "C" },
|
||||
{ "start": 0.17, "end": 0.38, "value": "D" },
|
||||
{ "start": 0.38, "end": 0.47, "value": "A" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
There is nothing surprising here; everything said about XML format applies to JSON, too.
|
||||
|
||||
## Limitations
|
||||
|
||||
Rhubarb Lip-Sync has some limitations you should be aware of.
|
||||
|
||||
### English only
|
||||
|
||||
Rhubarb Lip-Sync only produces good results when you give it recordings in English. You'll get best results with American English.
|
||||
|
||||
### Fixed set of mouth shapes
|
||||
|
||||
Rhubarb Lip-Sync uses a fixed set of eight mouth shapes, as shown above. If you want to use fewer shapes, you can apply a custom mapping in your own code.
|
||||
|
||||
## Tell me what you think!
|
||||
|
||||
Right now, Rhubarb Lip-Sync is very much work in progress. If you need help or have any suggestions, feel free to [create an issue](https://github.com/DanielSWolf/rhubarb-lip-sync/issues).
|
13
VERSION.md
|
@ -1,13 +0,0 @@
|
|||
# Version history
|
||||
|
||||
## Version 0.2
|
||||
|
||||
* Multiple output formats: TSV, XML, JSON
|
||||
* Experimental option to supply dialog text
|
||||
* Improved error handling and error messages
|
||||
|
||||
## Version 0.1
|
||||
|
||||
* Two-pass phone detection using [CMU PocketSphinx](http://cmusphinx.sourceforge.net/)
|
||||
* Fixed set of eight mouth shapes, based on the Hanna-Barbera shapes
|
||||
* Naive (but well-tuned) mapping from phones to mouth shapes
|
|
@ -0,0 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
set(appName "Rhubarb Lip Sync")
|
||||
set(appVersionMajor 1)
|
||||
set(appVersionMinor 13)
|
||||
set(appVersionPatch 0)
|
||||
set(appVersionSuffix "")
|
||||
set(appVersion "${appVersionMajor}.${appVersionMinor}.${appVersionPatch}${appVersionSuffix}")
|
|
@ -0,0 +1,11 @@
|
|||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
set(afterEffectsFiles
|
||||
"Rhubarb Lip Sync.jsx"
|
||||
"README.adoc"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${afterEffectsFiles}
|
||||
DESTINATION "extras/AdobeAfterEffects"
|
||||
)
|
|
@ -0,0 +1,29 @@
|
|||
= Animation script for Adobe After Effects
|
||||
|
||||
The script in this directory generates After Effects compositions with mouth animation.
|
||||
|
||||
== How to install
|
||||
|
||||
=== 1. Download and extract
|
||||
|
||||
Download the archive file containing Rhubarb Lip Sync, then extract in a directory on your computer.
|
||||
|
||||
=== 2. Make Rhubarb available to After Effects
|
||||
|
||||
On *Windows*, add the Rhubarb directory (the directory containing `rhubarb.exe`) to your `PATH` environment variable.
|
||||
|
||||
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).
|
||||
|
||||
=== 3. Install After Effects script
|
||||
|
||||
Copy (or symlink) the script file `Rhubarb Lip Sync.jsx` into your After Effects scripts directory.
|
||||
|
||||
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.
|
|
@ -0,0 +1,758 @@
|
|||
// Polyfill for Object.assign
|
||||
"function"!=typeof Object.assign&&(Object.assign=function(a,b){"use strict";if(null==a)throw new TypeError("Cannot convert undefined or null to object");for(var c=Object(a),d=1;d<arguments.length;d++){var e=arguments[d];if(null!=e)for(var f in e)Object.prototype.hasOwnProperty.call(e,f)&&(c[f]=e[f])}return c});
|
||||
|
||||
// Polyfill for Array.isArray
|
||||
Array.isArray||(Array.isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)});
|
||||
|
||||
// Polyfill for Array.prototype.map
|
||||
Array.prototype.map||(Array.prototype.map=function(r){var t,n,o;if(null==this)throw new TypeError("this is null or not defined");var e=Object(this),i=e.length>>>0;if("function"!=typeof r)throw new TypeError(r+" is not a function");for(arguments.length>1&&(t=arguments[1]),n=new Array(i),o=0;o<i;){var a,p;o in e&&(a=e[o],p=r.call(t,a,o,e),n[o]=p),o++}return n});
|
||||
|
||||
// Polyfill for Array.prototype.every
|
||||
Array.prototype.every||(Array.prototype.every=function(r,t){"use strict";var e,n;if(null==this)throw new TypeError("this is null or not defined");var o=Object(this),i=o.length>>>0;if("function"!=typeof r)throw new TypeError;for(arguments.length>1&&(e=t),n=0;n<i;){var y;if(n in o&&(y=o[n],!r.call(e,y,n,o)))return!1;n++}return!0});
|
||||
|
||||
// Polyfill for Array.prototype.find
|
||||
Array.prototype.find||(Array.prototype.find=function(r){if(null===this)throw new TypeError("Array.prototype.find called on null or undefined");if("function"!=typeof r)throw new TypeError("callback must be a function");for(var n=Object(this),t=n.length>>>0,o=arguments[1],e=0;e<t;e++){var f=n[e];if(r.call(o,f,e,n))return f}});
|
||||
|
||||
// Polyfill for Array.prototype.filter
|
||||
Array.prototype.filter||(Array.prototype.filter=function(r){"use strict";if(void 0===this||null===this)throw new TypeError;var t=Object(this),e=t.length>>>0;if("function"!=typeof r)throw new TypeError;for(var i=[],o=arguments.length>=2?arguments[1]:void 0,n=0;n<e;n++)if(n in t){var f=t[n];r.call(o,f,n,t)&&i.push(f)}return i});
|
||||
|
||||
// Polyfill for Array.prototype.forEach
|
||||
Array.prototype.forEach||(Array.prototype.forEach=function(a,b){var c,d;if(null===this)throw new TypeError(" this is null or not defined");var e=Object(this),f=e.length>>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=0;d<f;){var g;d in e&&(g=e[d],a.call(c,g,d,e)),d++}});
|
||||
|
||||
// Polyfill for Array.prototype.includes
|
||||
Array.prototype.includes||(Array.prototype.includes=function(r,t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),n=e.length>>>0;if(0===n)return!1;for(var i=0|t,o=Math.max(i>=0?i:n-Math.abs(i),0);o<n;){if(function(r,t){return r===t||"number"==typeof r&&"number"==typeof t&&isNaN(r)&&isNaN(t)}(e[o],r))return!0;o++}return!1});
|
||||
|
||||
// Polyfill for Array.prototype.indexOf
|
||||
Array.prototype.indexOf||(Array.prototype.indexOf=function(r,t){var n;if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if(0===i)return-1;var o=0|t;if(o>=i)return-1;for(n=Math.max(o>=0?o:i-Math.abs(o),0);n<i;){if(n in e&&e[n]===r)return n;n++}return-1});
|
||||
|
||||
// Polyfill for Array.prototype.some
|
||||
Array.prototype.some||(Array.prototype.some=function(r){"use strict";if(null==this)throw new TypeError("Array.prototype.some called on null or undefined");if("function"!=typeof r)throw new TypeError;for(var e=Object(this),o=e.length>>>0,t=arguments.length>=2?arguments[1]:void 0,n=0;n<o;n++)if(n in e&&r.call(t,e[n],n,e))return!0;return!1});
|
||||
|
||||
// Polyfill for String.prototype.trim
|
||||
String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")});
|
||||
|
||||
// Polyfill for JSON
|
||||
"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(a){return a<10?"0"+a:a}function this_value(){return this.valueOf()}function quote(a){return rx_escapable.lastIndex=0,rx_escapable.test(a)?'"'+a.replace(rx_escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,h,g=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,h=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;c<f;c+=1)h[c]=str(c,i)||"null";return e=0===h.length?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]",gap=g,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;c<f;c+=1)"string"==typeof rep[c]&&(d=rep[c],(e=str(d,i))&&h.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i))&&h.push(quote(d)+(gap?": ":":")+e);return e=0===h.length?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}",gap=g,e}}var rx_one=/^[\],:{}\s]*$/,rx_two=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,rx_three=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,rx_four=/(?:^|:|,)(?:\s*\[)+/g,rx_escapable=/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,rx_dangerous=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},Boolean.prototype.toJSON=this_value,Number.prototype.toJSON=this_value,String.prototype.toJSON=this_value);var gap,indent,meta,rep;"function"!=typeof JSON.stringify&&(meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;d<c;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})}),"function"!=typeof JSON.parse&&(JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),rx_dangerous.lastIndex=0,rx_dangerous.test(text)&&(text=text.replace(rx_dangerous,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),rx_one.test(text.replace(rx_two,"@").replace(rx_three,"]").replace(rx_four,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}();
|
||||
|
||||
function last(array) {
|
||||
return array[array.length - 1];
|
||||
}
|
||||
|
||||
function createGuid() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0;
|
||||
var v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
function toArray(list) {
|
||||
var result = [];
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
result.push(list[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function toArrayBase1(list) {
|
||||
var result = [];
|
||||
for (var i = 1; i <= list.length; i++) {
|
||||
result.push(list[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function pad(n, width, z) {
|
||||
z = z || '0';
|
||||
n = String(n);
|
||||
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
||||
}
|
||||
|
||||
// Checks whether scripts are allowed to write files by creating and deleting a dummy file
|
||||
function canWriteFiles() {
|
||||
try {
|
||||
var file = new File();
|
||||
file.open('w');
|
||||
file.writeln('');
|
||||
file.close();
|
||||
file.remove();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function frameToTime(frameNumber, compItem) {
|
||||
return frameNumber * compItem.frameDuration;
|
||||
}
|
||||
|
||||
function timeToFrame(time, compItem) {
|
||||
return time * compItem.frameRate;
|
||||
}
|
||||
|
||||
// To prevent rounding errors
|
||||
var epsilon = 0.001;
|
||||
|
||||
function isFrameVisible(compItem, frameNumber) {
|
||||
if (!compItem) return false;
|
||||
|
||||
var time = frameToTime(frameNumber + epsilon, compItem);
|
||||
var videoLayers = toArrayBase1(compItem.layers).filter(function(layer) {
|
||||
return layer.hasVideo;
|
||||
});
|
||||
var result = videoLayers.find(function(layer) {
|
||||
return layer.activeAtTime(time);
|
||||
});
|
||||
return Boolean(result);
|
||||
}
|
||||
|
||||
var appName = 'Rhubarb Lip Sync';
|
||||
|
||||
var settingsFilePath = Folder.userData.fullName + '/rhubarb-ae-settings.json';
|
||||
|
||||
function readTextFile(fileOrPath) {
|
||||
var filePath = fileOrPath.fsName || fileOrPath;
|
||||
var file = new File(filePath);
|
||||
function check() {
|
||||
if (file.error) throw new Error('Error reading file "' + filePath + '": ' + file.error);
|
||||
}
|
||||
try {
|
||||
file.open('r'); check();
|
||||
file.encoding = 'UTF-8'; check();
|
||||
var result = file.read(); check();
|
||||
return result;
|
||||
} finally {
|
||||
file.close(); check();
|
||||
}
|
||||
}
|
||||
|
||||
function writeTextFile(fileOrPath, text) {
|
||||
var filePath = fileOrPath.fsName || fileOrPath;
|
||||
var file = new File(filePath);
|
||||
function check() {
|
||||
if (file.error) throw new Error('Error writing file "' + filePath + '": ' + file.error);
|
||||
}
|
||||
try {
|
||||
file.open('w'); check();
|
||||
file.encoding = 'UTF-8'; check();
|
||||
file.write(text); check();
|
||||
} finally {
|
||||
file.close(); check();
|
||||
}
|
||||
}
|
||||
|
||||
function readSettingsFile() {
|
||||
try {
|
||||
return JSON.parse(readTextFile(settingsFilePath));
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function writeSettingsFile(settings) {
|
||||
try {
|
||||
writeTextFile(settingsFilePath, JSON.stringify(settings, null, 2));
|
||||
} catch (e) {
|
||||
alert('Error persisting settings. ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
var osIsWindows = (system.osName || $.os).match(/windows/i);
|
||||
|
||||
// Depending on the operating system, the syntax for escaping command-line arguments differs.
|
||||
function cliEscape(argument) {
|
||||
return osIsWindows
|
||||
? '"' + argument + '"'
|
||||
: "'" + argument.replace(/'/g, "'\\''") + "'";
|
||||
}
|
||||
|
||||
function exec(command) {
|
||||
return system.callSystem(command);
|
||||
}
|
||||
|
||||
function execInWindow(command) {
|
||||
if (osIsWindows) {
|
||||
system.callSystem('cmd /C "' + command + '"');
|
||||
} else {
|
||||
// I didn't think it could be so complicated on OS X to open a new Terminal window,
|
||||
// execute a command, then close the Terminal window.
|
||||
// If you know a better solution, let me know!
|
||||
var escapedCommand = command.replace(/"/g, '\\"');
|
||||
var appleScript = '\
|
||||
tell application "Terminal" \
|
||||
-- Quit terminal \
|
||||
-- Yes, that\'s undesirable if there was an open window before. \
|
||||
-- But all solutions I could find were at least as hacky. \
|
||||
quit \
|
||||
-- Open terminal \
|
||||
activate \
|
||||
-- Run command in new tab \
|
||||
set newTab to do script ("' + escapedCommand + '") \
|
||||
-- Wait until command is done \
|
||||
tell newTab \
|
||||
repeat while busy \
|
||||
delay 0.1 \
|
||||
end repeat \
|
||||
end tell \
|
||||
quit \
|
||||
end tell';
|
||||
exec('osascript -e ' + cliEscape(appleScript));
|
||||
}
|
||||
}
|
||||
|
||||
var rhubarbPath = osIsWindows ? 'rhubarb.exe' : '/usr/local/bin/rhubarb';
|
||||
|
||||
// ExtendScript's resource strings are a pain to write.
|
||||
// This function allows them to be written in JSON notation, then converts them into the required
|
||||
// format.
|
||||
// For instance, this string: '{ "__type__": "StaticText", "text": "Hello world" }'
|
||||
// is converted to this: 'StaticText { "text": "Hello world" }'.
|
||||
// This code relies on the fact that, contrary to the language specification, all major JavaScript
|
||||
// implementations keep object properties in insertion order.
|
||||
function createResourceString(tree) {
|
||||
var result = JSON.stringify(tree, null, 2);
|
||||
result = result.replace(/(\{\s*)"__type__":\s*"(\w+)",?\s*/g, '$2 $1');
|
||||
return result;
|
||||
}
|
||||
|
||||
// Object containing functions to create control description trees.
|
||||
// For instance, `controls.StaticText({ text: 'Hello world' })`
|
||||
// returns `{ __type__: StaticText, text: 'Hello world' }`.
|
||||
var controlFunctions = (function() {
|
||||
var controlTypes = [
|
||||
// Strangely, 'dialog' and 'palette' need to start with a lower-case character
|
||||
['Dialog', 'dialog'], ['Palette', 'palette'],
|
||||
'Panel', 'Group', 'TabbedPanel', 'Tab', 'Button', 'IconButton', 'Image', 'StaticText',
|
||||
'EditText', 'Checkbox', 'RadioButton', 'Progressbar', 'Slider', 'Scrollbar', 'ListBox',
|
||||
'DropDownList', 'TreeView', 'ListItem', 'FlashPlayer'
|
||||
];
|
||||
var result = {};
|
||||
controlTypes.forEach(function(type){
|
||||
var isArray = Array.isArray(type);
|
||||
var key = isArray ? type[0] : type;
|
||||
var value = isArray ? type[1] : type;
|
||||
result[key] = function(options) {
|
||||
return Object.assign({ __type__: value }, options);
|
||||
};
|
||||
});
|
||||
return result;
|
||||
})();
|
||||
|
||||
// Returns the path of a project item within the project
|
||||
function getItemPath(item) {
|
||||
if (item === app.project.rootFolder) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
var result = item.name;
|
||||
while (item.parentFolder !== app.project.rootFolder) {
|
||||
result = item.parentFolder.name + ' / ' + result;
|
||||
item = item.parentFolder;
|
||||
}
|
||||
return '/ ' + result;
|
||||
}
|
||||
|
||||
// Selects the item within an item control whose text matches the specified text.
|
||||
// If no such item exists, selects the first item, if present.
|
||||
function selectByTextOrFirst(itemControl, text) {
|
||||
var targetItem = toArray(itemControl.items).find(function(item) {
|
||||
return item.text === text;
|
||||
});
|
||||
if (!targetItem && itemControl.items.length) {
|
||||
targetItem = itemControl.items[0];
|
||||
}
|
||||
if (targetItem) {
|
||||
itemControl.selection = targetItem;
|
||||
}
|
||||
}
|
||||
|
||||
function getAudioFileProjectItems() {
|
||||
var result = toArrayBase1(app.project.items).filter(function(item) {
|
||||
var isAudioFootage = item instanceof FootageItem && item.hasAudio && !item.hasVideo;
|
||||
return isAudioFootage;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
var mouthShapeNames = 'ABCDEFGHX'.split('');
|
||||
var basicMouthShapeCount = 6;
|
||||
var mouthShapeCount = mouthShapeNames.length;
|
||||
var basicMouthShapeNames = mouthShapeNames.slice(0, basicMouthShapeCount);
|
||||
var extendedMouthShapeNames = mouthShapeNames.slice(basicMouthShapeCount);
|
||||
|
||||
function getMouthCompHelpTip() {
|
||||
var result = 'A composition containing the mouth shapes, one drawing per frame. They must be '
|
||||
+ 'arranged as follows:\n';
|
||||
mouthShapeNames.forEach(function(mouthShapeName, i) {
|
||||
var isOptional = i >= basicMouthShapeCount;
|
||||
result += '\n00:' + pad(i, 2) + '\t' + mouthShapeName + (isOptional ? ' (optional)' : '');
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function createExtendedShapeCheckboxes() {
|
||||
var result = {};
|
||||
extendedMouthShapeNames.forEach(function(shapeName) {
|
||||
result[shapeName.toLowerCase()] = controlFunctions.Checkbox({
|
||||
text: shapeName,
|
||||
helpTip: 'Controls whether to use the optional ' + shapeName + ' shape.'
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function createDialogWindow() {
|
||||
var resourceString;
|
||||
with (controlFunctions) {
|
||||
resourceString = createResourceString(
|
||||
Dialog({
|
||||
text: appName,
|
||||
settings: Group({
|
||||
orientation: 'column',
|
||||
alignChildren: ['left', 'top'],
|
||||
audioFile: Group({
|
||||
label: StaticText({
|
||||
text: 'Audio file:',
|
||||
// If I don't explicitly activate a control, After Effects has trouble
|
||||
// with keyboard focus, so I can't type in the text edit field below.
|
||||
active: true
|
||||
}),
|
||||
value: DropDownList({
|
||||
helpTip: 'An audio file containing recorded dialog.\n'
|
||||
+ 'This field shows all audio files that exist in '
|
||||
+ 'your After Effects project.'
|
||||
})
|
||||
}),
|
||||
recognizer: Group({
|
||||
label: StaticText({ text: 'Recognizer:' }),
|
||||
value: DropDownList({
|
||||
helpTip: 'The dialog recognizer.'
|
||||
})
|
||||
}),
|
||||
dialogText: Group({
|
||||
label: StaticText({ text: 'Dialog text (optional):' }),
|
||||
value: EditText({
|
||||
properties: { multiline: true },
|
||||
characters: 60,
|
||||
minimumSize: [0, 100],
|
||||
helpTip: 'For better animation results, you can specify the text of '
|
||||
+ 'the recording here. This field is optional.'
|
||||
})
|
||||
}),
|
||||
mouthComp: Group({
|
||||
label: StaticText({ text: 'Mouth composition:' }),
|
||||
value: DropDownList({ helpTip: getMouthCompHelpTip() })
|
||||
}),
|
||||
extendedMouthShapes: Group(
|
||||
Object.assign(
|
||||
{ label: StaticText({ text: 'Extended mouth shapes:' }) },
|
||||
createExtendedShapeCheckboxes()
|
||||
)
|
||||
),
|
||||
targetFolder: Group({
|
||||
label: StaticText({ text: 'Target folder:' }),
|
||||
value: DropDownList({
|
||||
helpTip: 'The project folder in which to create the animation '
|
||||
+ 'composition. The composition will be named like the audio file.'
|
||||
})
|
||||
}),
|
||||
frameRate: Group({
|
||||
label: StaticText({ text: 'Frame rate:' }),
|
||||
value: EditText({
|
||||
characters: 8,
|
||||
helpTip: 'The frame rate for the animation.'
|
||||
}),
|
||||
auto: Checkbox({
|
||||
text: 'From mouth composition',
|
||||
helpTip: 'If checked, the animation will use the same frame rate as '
|
||||
+ 'the mouth composition.'
|
||||
})
|
||||
})
|
||||
}),
|
||||
separator: Group({ preferredSize: ['', 3] }),
|
||||
buttons: Group({
|
||||
alignment: 'right',
|
||||
animate: Button({
|
||||
properties: { name: 'ok' },
|
||||
text: 'Animate'
|
||||
}),
|
||||
cancel: Button({
|
||||
properties: { name: 'cancel' },
|
||||
text: 'Cancel'
|
||||
})
|
||||
})
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Create window and child controls
|
||||
var window = new Window(resourceString);
|
||||
var controls = {
|
||||
audioFile: window.settings.audioFile.value,
|
||||
dialogText: window.settings.dialogText.value,
|
||||
recognizer: window.settings.recognizer.value,
|
||||
mouthComp: window.settings.mouthComp.value,
|
||||
targetFolder: window.settings.targetFolder.value,
|
||||
frameRate: window.settings.frameRate.value,
|
||||
autoFrameRate: window.settings.frameRate.auto,
|
||||
animateButton: window.buttons.animate,
|
||||
cancelButton: window.buttons.cancel
|
||||
};
|
||||
extendedMouthShapeNames.forEach(function(shapeName) {
|
||||
controls['mouthShape' + shapeName] =
|
||||
window.settings.extendedMouthShapes[shapeName.toLowerCase()];
|
||||
});
|
||||
|
||||
// Add audio file options
|
||||
getAudioFileProjectItems().forEach(function(projectItem) {
|
||||
var listItem = controls.audioFile.add('item', getItemPath(projectItem));
|
||||
listItem.projectItem = projectItem;
|
||||
});
|
||||
|
||||
// Add recognizer options
|
||||
const recognizerOptions = [
|
||||
{ text: 'PocketSphinx (use for English recordings)', value: 'pocketSphinx' },
|
||||
{ text: 'Phonetic (use for non-English recordings)', value: 'phonetic' }
|
||||
];
|
||||
recognizerOptions.forEach(function(option) {
|
||||
var listItem = controls.recognizer.add('item', option.text);
|
||||
listItem.value = option.value;
|
||||
});
|
||||
|
||||
// Add mouth composition options
|
||||
var comps = toArrayBase1(app.project.items).filter(function (item) {
|
||||
return item instanceof CompItem;
|
||||
});
|
||||
comps.forEach(function(projectItem) {
|
||||
var listItem = controls.mouthComp.add('item', getItemPath(projectItem));
|
||||
listItem.projectItem = projectItem;
|
||||
});
|
||||
|
||||
// Add target folder options
|
||||
var projectFolders = toArrayBase1(app.project.items).filter(function (item) {
|
||||
return item instanceof FolderItem;
|
||||
});
|
||||
projectFolders.unshift(app.project.rootFolder);
|
||||
projectFolders.forEach(function(projectFolder) {
|
||||
var listItem = controls.targetFolder.add('item', getItemPath(projectFolder));
|
||||
listItem.projectItem = projectFolder;
|
||||
});
|
||||
|
||||
// Load persisted settings
|
||||
var settings = readSettingsFile();
|
||||
selectByTextOrFirst(controls.audioFile, settings.audioFile);
|
||||
controls.dialogText.text = settings.dialogText || '';
|
||||
selectByTextOrFirst(controls.recognizer, settings.recognizer);
|
||||
selectByTextOrFirst(controls.mouthComp, settings.mouthComp);
|
||||
extendedMouthShapeNames.forEach(function(shapeName) {
|
||||
controls['mouthShape' + shapeName].value =
|
||||
(settings.extendedMouthShapes || {})[shapeName.toLowerCase()];
|
||||
});
|
||||
selectByTextOrFirst(controls.targetFolder, settings.targetFolder);
|
||||
controls.frameRate.text = settings.frameRate || '';
|
||||
controls.autoFrameRate.value = settings.autoFrameRate;
|
||||
|
||||
// Align controls
|
||||
window.onShow = function() {
|
||||
// Give uniform width to all labels
|
||||
var groups = toArray(window.settings.children);
|
||||
var labelWidths = groups.map(function(group) { return group.children[0].size.width; });
|
||||
var maxLabelWidth = Math.max.apply(Math, labelWidths);
|
||||
groups.forEach(function (group) {
|
||||
group.children[0].size.width = maxLabelWidth;
|
||||
});
|
||||
|
||||
// Give uniform width to inputs
|
||||
var valueWidths = groups.map(function(group) {
|
||||
return last(group.children).bounds.right - group.children[1].bounds.left;
|
||||
});
|
||||
var maxValueWidth = Math.max.apply(Math, valueWidths);
|
||||
groups.forEach(function (group) {
|
||||
var multipleControls = group.children.length > 2;
|
||||
if (!multipleControls) {
|
||||
group.children[1].size.width = maxValueWidth;
|
||||
}
|
||||
});
|
||||
|
||||
window.layout.layout(true);
|
||||
};
|
||||
|
||||
var updating = false;
|
||||
|
||||
function update() {
|
||||
if (updating) return;
|
||||
|
||||
updating = true;
|
||||
try {
|
||||
// Handle auto frame rate
|
||||
var autoFrameRate = controls.autoFrameRate.value;
|
||||
controls.frameRate.enabled = !autoFrameRate;
|
||||
if (autoFrameRate) {
|
||||
// Take frame rate from mouth comp
|
||||
var mouthComp = (controls.mouthComp.selection || {}).projectItem;
|
||||
controls.frameRate.text = mouthComp ? mouthComp.frameRate : '';
|
||||
} else {
|
||||
// Sanitize frame rate
|
||||
var sanitizedFrameRate = controls.frameRate.text.match(/\d*\.?\d*/)[0];
|
||||
if (sanitizedFrameRate !== controls.frameRate.text) {
|
||||
controls.frameRate.text = sanitizedFrameRate;
|
||||
}
|
||||
}
|
||||
|
||||
// Store settings
|
||||
var settings = {
|
||||
audioFile: (controls.audioFile.selection || {}).text,
|
||||
recognizer: (controls.recognizer.selection || {}).text,
|
||||
dialogText: controls.dialogText.text,
|
||||
mouthComp: (controls.mouthComp.selection || {}).text,
|
||||
extendedMouthShapes: {},
|
||||
targetFolder: (controls.targetFolder.selection || {}).text,
|
||||
frameRate: Number(controls.frameRate.text),
|
||||
autoFrameRate: controls.autoFrameRate.value
|
||||
};
|
||||
extendedMouthShapeNames.forEach(function(shapeName) {
|
||||
settings.extendedMouthShapes[shapeName.toLowerCase()] =
|
||||
controls['mouthShape' + shapeName].value;
|
||||
});
|
||||
writeSettingsFile(settings);
|
||||
} finally {
|
||||
updating = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate user input. Possible return values:
|
||||
// * Non-empty string: Validation failed. Show error message.
|
||||
// * Empty string: Validation failed. Don't show error message.
|
||||
// * Undefined: Validation succeeded.
|
||||
function validate() {
|
||||
// Check input values
|
||||
if (!controls.audioFile.selection) return 'Please select an audio file.';
|
||||
if (!controls.mouthComp.selection) return 'Please select a mouth composition.';
|
||||
if (!controls.targetFolder.selection) return 'Please select a target folder.';
|
||||
if (Number(controls.frameRate.text) < 12) {
|
||||
return 'Please enter a frame rate of at least 12 fps.';
|
||||
}
|
||||
|
||||
// Check mouth shape visibility
|
||||
var comp = controls.mouthComp.selection.projectItem;
|
||||
for (var i = 0; i < mouthShapeCount; i++) {
|
||||
var shapeName = mouthShapeNames[i];
|
||||
var required = i < basicMouthShapeCount || controls['mouthShape' + shapeName].value;
|
||||
if (required && !isFrameVisible(comp, i)) {
|
||||
return 'The mouth comp does not seem to contain an image for shape '
|
||||
+ shapeName + ' at frame ' + i + '.';
|
||||
}
|
||||
}
|
||||
|
||||
if (!comp.preserveNestedFrameRate) {
|
||||
var fix = Window.confirm(
|
||||
'The setting "Preserve frame rate when nested or in render queue" is not active '
|
||||
+ 'for the mouth composition. This can result in incorrect animation.\n\n'
|
||||
+ 'Activate this setting now?',
|
||||
false,
|
||||
'Fix composition setting?');
|
||||
if (fix) {
|
||||
app.beginUndoGroup(appName + ': Mouth composition setting');
|
||||
comp.preserveNestedFrameRate = true;
|
||||
app.endUndoGroup();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// Check for correct Rhubarb version
|
||||
var version = exec(rhubarbPath + ' --version') || '';
|
||||
var match = version.match(/Rhubarb Lip Sync version ((\d+)\.(\d+).(\d+)(-[0-9A-Za-z-.]+)?)/);
|
||||
if (!match) {
|
||||
var instructions = osIsWindows
|
||||
? 'Make sure your PATH environment variable contains the ' + appName + ' '
|
||||
+ 'application directory.'
|
||||
: 'Make sure you have created this file as a symbolic link to the ' + appName + ' '
|
||||
+ 'executable (rhubarb).';
|
||||
return 'Cannot find executable file "' + rhubarbPath + '". \n' + instructions;
|
||||
}
|
||||
var versionString = match[1];
|
||||
var major = Number(match[2]);
|
||||
var minor = Number(match[3]);
|
||||
var requiredMajor = 1;
|
||||
var minRequiredMinor = 9;
|
||||
if (major != requiredMajor || minor < minRequiredMinor) {
|
||||
return 'This script requires ' + appName + ' ' + requiredMajor + '.' + minRequiredMinor
|
||||
+ '.0 or a later ' + requiredMajor + '.x version. '
|
||||
+ 'Your installed version is ' + versionString + ', which is not compatible.';
|
||||
}
|
||||
}
|
||||
|
||||
function generateMouthCues(audioFileFootage, recognizer, dialogText, mouthComp, extendedMouthShapeNames,
|
||||
targetProjectFolder, frameRate)
|
||||
{
|
||||
var basePath = Folder.temp.fsName + '/' + createGuid();
|
||||
var dialogFile = new File(basePath + '.txt');
|
||||
var logFile = new File(basePath + '.log');
|
||||
var jsonFile = new File(basePath + '.json');
|
||||
try {
|
||||
// Create text file containing dialog
|
||||
writeTextFile(dialogFile, dialogText);
|
||||
|
||||
// Create command line
|
||||
var commandLine = rhubarbPath
|
||||
+ ' --dialogFile ' + cliEscape(dialogFile.fsName)
|
||||
+ ' --recognizer ' + recognizer
|
||||
+ ' --exportFormat json'
|
||||
+ ' --extendedShapes ' + cliEscape(extendedMouthShapeNames.join(''))
|
||||
+ ' --logFile ' + cliEscape(logFile.fsName)
|
||||
+ ' --logLevel fatal'
|
||||
+ ' --output ' + cliEscape(jsonFile.fsName)
|
||||
+ ' ' + cliEscape(audioFileFootage.file.fsName);
|
||||
|
||||
// Run Rhubarb
|
||||
execInWindow(commandLine);
|
||||
|
||||
// Check log for fatal errors
|
||||
if (logFile.exists) {
|
||||
var fatalLog = readTextFile(logFile).trim();
|
||||
if (fatalLog) {
|
||||
// Try to extract only the actual error message
|
||||
var match = fatalLog.match(/\[Fatal\] ([\s\S]*)/);
|
||||
var message = match ? match[1] : fatalLog;
|
||||
throw new Error('Error running ' + appName + '.\n' + message);
|
||||
}
|
||||
}
|
||||
|
||||
var result;
|
||||
try {
|
||||
result = JSON.parse(readTextFile(jsonFile));
|
||||
} catch (e) {
|
||||
throw new Error('No animation result. Animation was probably canceled.');
|
||||
}
|
||||
return result;
|
||||
} finally {
|
||||
dialogFile.remove();
|
||||
logFile.remove();
|
||||
jsonFile.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function animateMouthCues(mouthCues, audioFileFootage, mouthComp, targetProjectFolder,
|
||||
frameRate)
|
||||
{
|
||||
// Find an unconflicting comp name
|
||||
// ... strip extension, if present
|
||||
var baseName = audioFileFootage.name.match(/^(.*?)(\..*)?$/i)[1];
|
||||
var compName = baseName;
|
||||
// ... add numeric suffix, if needed
|
||||
var existingItems = toArrayBase1(targetProjectFolder.items);
|
||||
var counter = 1;
|
||||
while (existingItems.some(function(item) { return item.name === compName; })) {
|
||||
counter++;
|
||||
compName = baseName + ' ' + counter;
|
||||
}
|
||||
|
||||
// Create new comp
|
||||
var comp = targetProjectFolder.items.addComp(compName, mouthComp.width, mouthComp.height,
|
||||
mouthComp.pixelAspect, audioFileFootage.duration, frameRate);
|
||||
|
||||
// Show new comp
|
||||
comp.openInViewer();
|
||||
|
||||
// Add audio layer
|
||||
comp.layers.add(audioFileFootage);
|
||||
|
||||
// Add mouth layer
|
||||
var mouthLayer = comp.layers.add(mouthComp);
|
||||
mouthLayer.timeRemapEnabled = true;
|
||||
mouthLayer.outPoint = comp.duration;
|
||||
|
||||
// Animate mouth layer
|
||||
var timeRemap = mouthLayer['Time Remap'];
|
||||
// Enabling time remapping automatically adds two keys. Remove the second.
|
||||
timeRemap.removeKey(2);
|
||||
mouthCues.mouthCues.forEach(function(mouthCue) {
|
||||
// Round down keyframe time. In animation, earlier is better than later.
|
||||
// Set keyframe time to *just before* the exact frame to prevent rounding errors
|
||||
var frame = Math.floor(timeToFrame(mouthCue.start, comp));
|
||||
var time = frame !== 0 ? frameToTime(frame - epsilon, comp) : 0;
|
||||
// Set remapped time to *just after* the exact frame to prevent rounding errors
|
||||
var mouthCompFrame = mouthShapeNames.indexOf(mouthCue.value);
|
||||
var remappedTime = frameToTime(mouthCompFrame + epsilon, mouthComp);
|
||||
timeRemap.setValueAtTime(time, remappedTime);
|
||||
});
|
||||
for (var i = 1; i <= timeRemap.numKeys; i++) {
|
||||
timeRemap.setInterpolationTypeAtKey(i, KeyframeInterpolationType.HOLD);
|
||||
}
|
||||
}
|
||||
|
||||
function animate(audioFileFootage, recognizer, dialogText, mouthComp, extendedMouthShapeNames,
|
||||
targetProjectFolder, frameRate)
|
||||
{
|
||||
try {
|
||||
var mouthCues = generateMouthCues(audioFileFootage, recognizer, dialogText, mouthComp,
|
||||
extendedMouthShapeNames, targetProjectFolder, frameRate);
|
||||
|
||||
app.beginUndoGroup(appName + ': Animation');
|
||||
animateMouthCues(mouthCues, audioFileFootage, mouthComp, targetProjectFolder,
|
||||
frameRate);
|
||||
app.endUndoGroup();
|
||||
} catch (e) {
|
||||
Window.alert(e.message, appName, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle changes
|
||||
update();
|
||||
controls.audioFile.onChange = update;
|
||||
controls.recognizer.onChange = update;
|
||||
controls.dialogText.onChanging = update;
|
||||
controls.mouthComp.onChange = update;
|
||||
extendedMouthShapeNames.forEach(function(shapeName) {
|
||||
controls['mouthShape' + shapeName].onClick = update;
|
||||
});
|
||||
controls.targetFolder.onChange = update;
|
||||
controls.frameRate.onChanging = update;
|
||||
controls.autoFrameRate.onClick = update;
|
||||
|
||||
// Handle animation
|
||||
controls.animateButton.onClick = function() {
|
||||
var validationError = validate();
|
||||
if (typeof validationError === 'string') {
|
||||
if (validationError) {
|
||||
Window.alert(validationError, appName, true);
|
||||
}
|
||||
} else {
|
||||
window.close();
|
||||
animate(
|
||||
controls.audioFile.selection.projectItem,
|
||||
controls.recognizer.selection.value,
|
||||
controls.dialogText.text || '',
|
||||
controls.mouthComp.selection.projectItem,
|
||||
extendedMouthShapeNames.filter(function(shapeName) {
|
||||
return controls['mouthShape' + shapeName].value;
|
||||
}),
|
||||
controls.targetFolder.selection.projectItem,
|
||||
Number(controls.frameRate.text)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Handle cancelation
|
||||
controls.cancelButton.onClick = function() {
|
||||
window.close();
|
||||
};
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
function checkPreconditions() {
|
||||
if (!canWriteFiles()) {
|
||||
Window.alert('This script requires file system access.\n\n'
|
||||
+ 'Please enable Preferences > General > Allow Scripts to Write Files and Access Network.',
|
||||
appName, true);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (checkPreconditions()) {
|
||||
createDialogWindow().show();
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
# Directory is generated when importing Gradle project
|
||||
/.idea/
|
||||
|
||||
*.iml
|
||||
/.gradle/
|
||||
/build/
|
||||
/out/
|
||||
/tmp/
|
|
@ -0,0 +1,18 @@
|
|||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
add_custom_target(
|
||||
rhubarbForSpine ALL
|
||||
"./gradlew" "build"
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
COMMENT "Building Rhubarb for Spine through Gradle."
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY "build/libs/"
|
||||
DESTINATION "extras/EsotericSoftwareSpine"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES README.adoc
|
||||
DESTINATION "extras/EsotericSoftwareSpine"
|
||||
)
|
|
@ -0,0 +1,51 @@
|
|||
= Rhubarb Lip Sync for Spine
|
||||
|
||||
Rhubarb Lip Sync for Spine is a graphical tool that allows you to import a Spine project, perform automatic lip sync, then re-import the result into Spine.
|
||||
|
||||
image:../../img/spine.png[image]
|
||||
|
||||
== Installation
|
||||
|
||||
https://github.com/DanielSWolf/rhubarb-lip-sync/releases[Download Rhubarb Lip Sync] for your platform, then extract the archive file in a directory on your computer. You’ll find Rhubarb Lip Sync for Spine in the directory `extras/EsotericSoftwareSpine`.
|
||||
|
||||
To create lip sync animation, you’ll need Spine 3.7 or better.
|
||||
|
||||
== Preparing your Spine project
|
||||
|
||||
You can add lip-sync’ed dialog to any Spine skeleton. First, make sure it has a dedicated slot for its mouth. I’m naming the slot `mouth`, but you can choose any name you like.
|
||||
|
||||
Next, add image attachments to the mouth slot, one attachment per mouth shape. For details about the expected mouth shapes, https://github.com/DanielSWolf/rhubarb-lip-sync#user-content-mouth-shapes[refer to the Rhubarb Lip Sync documentation]. You’ll need at least the six basic mouth shapes A-F. If you add any of the extended mouth shapes, Rhubarb will automatically use them to create better-looking animation. I’m naming the attachments `mouth_a`, `mouth_b`, `mouth_c`, etc. You can choose any naming scheme you like and Rhubarb will detect it, as long as it’s consistent (including upper and lower case). For instance, `A-Lips`, `B-Lips`, `C-Lips`, … is fine; `mouth a`, `mouth B`, `Mouth-C`, … isn’t.
|
||||
|
||||
Finally, you need to add some audio events, that is, events with associated audio path. These audio events will be the basis for animation.
|
||||
|
||||
_Optionally_, you can enter the dialog text into each event’s string property. If you do, this will help Rhubarb to create more reliable animation. But don’t worry: If you don’t enter the dialog text or if you already use the string property for something else, the results will normally still be good. For more information, see the https://github.com/DanielSWolf/rhubarb-lip-sync#user-content-options[documentation on the `--dialogFile` option].
|
||||
|
||||
== Exporting a JSON file
|
||||
|
||||
Export the skeleton(s) by selecting _Spine_ | _Export…_.
|
||||
|
||||
Choose JSON format. Make sure the output folder is the same folder that contains your `.spine` file, or Rhubarb won’t be able to locate your audio files. Also, make sure to check the _Nonessential data_ checkbox. Despite the name, Rhubarb needs this information. Finally, click _Export_. This will create a file with the same name as your skeleton and the extension `.json`.
|
||||
|
||||
== Performing lip sync
|
||||
|
||||
Open Rhubarb Lip Sync for Spine by double-clicking `rhubarb-for-spine.jar` in the Windows Explorer (Windows) or Finder (OS X). Specify the input settings as follows:
|
||||
|
||||
* *Spine JSON file:* This is the file you just exported. The most convenient way to fill this field is to drag-and-drop the JSON file anywhere onto the application window. Alternatively, you can use the `…' button or manually enter the file path.
|
||||
* *Mouth slot:* This tells Rhubarb which of your Spine slots represents the mouth. The dropdown shows all the slots on your skeleton. If your mouth slot contains the word `mouth', Rhubarb will automatically select it for you. Otherwise, select it manually.
|
||||
* *Mouth naming:* Rhubarb will automatically detect the naming scheme you used for your mouth attachments and display it here. This is for your information only.
|
||||
* *Mouth shapes:* This group of checkboxes tells you which mouth shapes were found. At least the basic mouth shapes A-F need to be present. This, too, is informational only.
|
||||
* *Animation naming:* When animating, Rhubarb will create new Spine animations based on your existing audio events. The two text fields allow you to fine-tune the animation naming.
|
||||
|
||||
At the bottom of the window, there is a grid with one row per audio event. To animate any audio event, click the corresponding _Animate_ button. Animation jobs are queued, so the next animation job starts once the previous one has finished.
|
||||
|
||||
Each time an animation job finishes, the JSON file is updated with the new animation. When you are done animating, you can close Rhubarb Lip Sync for Spine.
|
||||
|
||||
== Importing the animated results
|
||||
|
||||
Rhubarb Lip Sync for Spine has only changed the exported `.json` file, not your original `.spine` project file. To do that, switch back to Spine.
|
||||
|
||||
Delete your skeleton by selecting it in the hierarchy tree and clicking the _Delete_ button. If you don’t, Spine will complain in the next step that a skeleton with this name already exists.
|
||||
|
||||
Select _Spine_ | _Import Data…_. Make sure the JSON file path is correct. Also make sure the checkbox _New project_ is *not checked*, or else Spine will start confusing paths. Click OK to re-import the skeleton from the JSON file.
|
||||
|
||||
If everything went well, you will now have a number of new, lip-sync’ed animations on your skeleton!
|
|
@ -0,0 +1,57 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.io.File
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.6.0"
|
||||
id("org.openjfx.javafxplugin") version "0.0.10"
|
||||
}
|
||||
|
||||
fun getVersion(): String {
|
||||
// Dynamically read version from CMake file
|
||||
val file = File(rootDir.parentFile.parentFile, "appInfo.cmake")
|
||||
val text = file.readText()
|
||||
val major = Regex("""appVersionMajor\s+(\d+)""").find(text)!!.groupValues[1]
|
||||
val minor = Regex("""appVersionMinor\s+(\d+)""").find(text)!!.groupValues[1]
|
||||
val patch = Regex("""appVersionPatch\s+(\d+)""").find(text)!!.groupValues[1]
|
||||
val suffix = Regex("""appVersionSuffix\s+"(.*?)"""").find(text)!!.groupValues[1]
|
||||
return "$major.$minor.$patch$suffix"
|
||||
}
|
||||
|
||||
group = "com.rhubarb_lip_sync"
|
||||
version = getVersion()
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0")
|
||||
implementation("com.beust:klaxon:5.5")
|
||||
implementation("org.apache.commons:commons-lang3:3.12.0")
|
||||
implementation("no.tornado:tornadofx:2.0.0-SNAPSHOT")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
|
||||
testImplementation("org.assertj:assertj-core:3.21.0")
|
||||
}
|
||||
|
||||
javafx {
|
||||
version = "15.0.1"
|
||||
modules("javafx.controls")
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.withType<Jar> {
|
||||
manifest {
|
||||
attributes("Main-Class" to "com.rhubarb_lip_sync.rhubarb_for_spine.MainKt")
|
||||
}
|
||||
|
||||
from(configurations.compileClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
|
@ -0,0 +1,172 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
|
@ -0,0 +1,84 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
|
@ -0,0 +1 @@
|
|||
rootProject.name = "rhubarb-for-spine"
|
|
@ -0,0 +1,125 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import javafx.beans.binding.BooleanBinding
|
||||
import javafx.beans.property.SimpleBooleanProperty
|
||||
import javafx.beans.property.SimpleListProperty
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.collections.ObservableList
|
||||
import tornadofx.asObservable
|
||||
import java.nio.file.Path
|
||||
import tornadofx.getValue
|
||||
import tornadofx.observable
|
||||
import tornadofx.setValue
|
||||
import java.util.concurrent.ExecutorService
|
||||
|
||||
class AnimationFileModel(val parentModel: MainModel, animationFilePath: Path, private val executor: ExecutorService) {
|
||||
val spineJson = SpineJson(animationFilePath)
|
||||
|
||||
val slotsProperty = SimpleObjectProperty<ObservableList<String>>()
|
||||
private var slots: ObservableList<String> by slotsProperty
|
||||
|
||||
val mouthSlotProperty: SimpleStringProperty = SimpleStringProperty().alsoListen {
|
||||
val mouthSlot = this.mouthSlot
|
||||
val mouthNaming = if (mouthSlot != null)
|
||||
MouthNaming.guess(spineJson.getSlotAttachmentNames(mouthSlot))
|
||||
else null
|
||||
this.mouthNaming = mouthNaming
|
||||
|
||||
mouthShapes = if (mouthSlot != null && mouthNaming != null) {
|
||||
val mouthNames = spineJson.getSlotAttachmentNames(mouthSlot)
|
||||
MouthShape.values().filter { mouthNames.contains(mouthNaming.getName(it)) }
|
||||
} else listOf()
|
||||
|
||||
mouthSlotError = if (mouthSlot != null)
|
||||
null
|
||||
else
|
||||
"No slot with mouth drawings specified."
|
||||
}
|
||||
private var mouthSlot: String? by mouthSlotProperty
|
||||
|
||||
val mouthSlotErrorProperty = SimpleStringProperty()
|
||||
private var mouthSlotError: String? by mouthSlotErrorProperty
|
||||
|
||||
val mouthNamingProperty = SimpleObjectProperty<MouthNaming>()
|
||||
private var mouthNaming: MouthNaming? by mouthNamingProperty
|
||||
|
||||
val mouthShapesProperty = SimpleObjectProperty<List<MouthShape>>().alsoListen {
|
||||
mouthShapesError = getMouthShapesErrorString()
|
||||
}
|
||||
var mouthShapes: List<MouthShape> by mouthShapesProperty
|
||||
private set
|
||||
|
||||
val mouthShapesErrorProperty = SimpleStringProperty()
|
||||
private var mouthShapesError: String? by mouthShapesErrorProperty
|
||||
|
||||
val audioFileModelsProperty = SimpleListProperty<AudioFileModel>(
|
||||
spineJson.audioEvents
|
||||
.map { event ->
|
||||
var audioFileModel: AudioFileModel? = null
|
||||
val reportResult: (List<MouthCue>) -> Unit =
|
||||
{ result -> saveAnimation(audioFileModel!!.animationName, event.name, result) }
|
||||
audioFileModel = AudioFileModel(event, this, executor, reportResult)
|
||||
return@map audioFileModel
|
||||
}
|
||||
.asObservable()
|
||||
)
|
||||
val audioFileModels: ObservableList<AudioFileModel> by audioFileModelsProperty
|
||||
|
||||
val busyProperty = SimpleBooleanProperty().apply {
|
||||
bind(object : BooleanBinding() {
|
||||
init {
|
||||
for (audioFileModel in audioFileModels) {
|
||||
super.bind(audioFileModel.busyProperty)
|
||||
}
|
||||
}
|
||||
override fun computeValue(): Boolean {
|
||||
return audioFileModels.any { it.busy }
|
||||
}
|
||||
})
|
||||
}
|
||||
val busy by busyProperty
|
||||
|
||||
val validProperty = SimpleBooleanProperty().apply {
|
||||
val errorProperties = arrayOf(mouthSlotErrorProperty, mouthShapesErrorProperty)
|
||||
bind(object : BooleanBinding() {
|
||||
init {
|
||||
super.bind(*errorProperties)
|
||||
}
|
||||
override fun computeValue(): Boolean {
|
||||
return errorProperties.all { it.value == null }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun saveAnimation(animationName: String, audioEventName: String, mouthCues: List<MouthCue>) {
|
||||
spineJson.createOrUpdateAnimation(mouthCues, audioEventName, animationName, mouthSlot!!, mouthNaming!!)
|
||||
spineJson.save()
|
||||
}
|
||||
|
||||
init {
|
||||
slots = spineJson.slots.asObservable()
|
||||
mouthSlot = spineJson.guessMouthSlot()
|
||||
}
|
||||
|
||||
private fun getMouthShapesErrorString(): String? {
|
||||
val missingBasicShapes = MouthShape.basicShapes
|
||||
.filter{ !mouthShapes.contains(it) }
|
||||
if (missingBasicShapes.isEmpty()) return null
|
||||
|
||||
val result = StringBuilder()
|
||||
val missingShapesString = missingBasicShapes.joinToString()
|
||||
result.appendln(
|
||||
if (missingBasicShapes.count() > 1)
|
||||
"Mouth shapes $missingShapesString are missing."
|
||||
else
|
||||
"Mouth shape $missingShapesString is missing."
|
||||
)
|
||||
|
||||
val first = MouthShape.basicShapes.first()
|
||||
val last = MouthShape.basicShapes.last()
|
||||
result.append("At least the basic mouth shapes $first-$last need corresponding image attachments.")
|
||||
return result.toString()
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import javafx.application.Platform
|
||||
import javafx.beans.binding.BooleanBinding
|
||||
import javafx.beans.binding.ObjectBinding
|
||||
import javafx.beans.binding.StringBinding
|
||||
import javafx.beans.property.SimpleBooleanProperty
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.scene.control.Alert
|
||||
import javafx.scene.control.ButtonType
|
||||
import tornadofx.getValue
|
||||
import tornadofx.setValue
|
||||
import java.nio.file.Path
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Future
|
||||
|
||||
class AudioFileModel(
|
||||
audioEvent: SpineJson.AudioEvent,
|
||||
private val parentModel: AnimationFileModel,
|
||||
private val executor: ExecutorService,
|
||||
private val reportResult: (List<MouthCue>) -> Unit
|
||||
) {
|
||||
private val spineJson = parentModel.spineJson
|
||||
|
||||
private val audioFilePath: Path = spineJson.audioDirectoryPath.resolve(audioEvent.relativeAudioFilePath)
|
||||
|
||||
val eventNameProperty = SimpleStringProperty(audioEvent.name)
|
||||
val eventName: String by eventNameProperty
|
||||
|
||||
val displayFilePathProperty = SimpleStringProperty(audioEvent.relativeAudioFilePath)
|
||||
|
||||
val animationNameProperty = SimpleStringProperty().apply {
|
||||
val mainModel = parentModel.parentModel
|
||||
bind(object : ObjectBinding<String>() {
|
||||
init {
|
||||
super.bind(
|
||||
mainModel.animationPrefixProperty,
|
||||
eventNameProperty,
|
||||
mainModel.animationSuffixProperty
|
||||
)
|
||||
}
|
||||
override fun computeValue(): String {
|
||||
return mainModel.animationPrefix + eventName + mainModel.animationSuffix
|
||||
}
|
||||
})
|
||||
}
|
||||
val animationName: String by animationNameProperty
|
||||
|
||||
val dialogProperty = SimpleStringProperty(audioEvent.dialog)
|
||||
private val dialog: String? by dialogProperty
|
||||
|
||||
val animationProgressProperty = SimpleObjectProperty<Double?>(null)
|
||||
var animationProgress: Double? by animationProgressProperty
|
||||
private set
|
||||
|
||||
private val animatedProperty = SimpleBooleanProperty().apply {
|
||||
bind(object : ObjectBinding<Boolean>() {
|
||||
init {
|
||||
super.bind(animationNameProperty, parentModel.spineJson.animationNames)
|
||||
}
|
||||
override fun computeValue(): Boolean {
|
||||
return parentModel.spineJson.animationNames.contains(animationName)
|
||||
}
|
||||
})
|
||||
}
|
||||
private var animated by animatedProperty
|
||||
|
||||
private val futureProperty = SimpleObjectProperty<Future<*>?>()
|
||||
private var future by futureProperty
|
||||
|
||||
val audioFileStateProperty = SimpleObjectProperty<AudioFileState>().apply {
|
||||
bind(object : ObjectBinding<AudioFileState>() {
|
||||
init {
|
||||
super.bind(animatedProperty, futureProperty, animationProgressProperty)
|
||||
}
|
||||
override fun computeValue(): AudioFileState {
|
||||
return if (future != null) {
|
||||
if (animationProgress != null)
|
||||
if (future!!.isCancelled)
|
||||
AudioFileState(AudioFileStatus.Canceling)
|
||||
else
|
||||
AudioFileState(AudioFileStatus.Animating, animationProgress)
|
||||
else
|
||||
AudioFileState(AudioFileStatus.Pending)
|
||||
} else {
|
||||
if (animated)
|
||||
AudioFileState(AudioFileStatus.Done)
|
||||
else
|
||||
AudioFileState(AudioFileStatus.NotAnimated)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
val busyProperty = SimpleBooleanProperty().apply {
|
||||
bind(object : BooleanBinding() {
|
||||
init {
|
||||
super.bind(futureProperty)
|
||||
}
|
||||
override fun computeValue(): Boolean {
|
||||
return future != null
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
val busy by busyProperty
|
||||
|
||||
val actionLabelProperty = SimpleStringProperty().apply {
|
||||
bind(object : StringBinding() {
|
||||
init {
|
||||
super.bind(futureProperty)
|
||||
}
|
||||
override fun computeValue(): String {
|
||||
return if (future != null)
|
||||
"Cancel"
|
||||
else
|
||||
"Animate"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun performAction() {
|
||||
if (future == null) {
|
||||
if (animated) {
|
||||
Alert(Alert.AlertType.CONFIRMATION).apply {
|
||||
headerText = "Animation '$animationName' already exists."
|
||||
contentText = "Do you want to replace the existing animation?"
|
||||
val result = showAndWait()
|
||||
if (result.get() != ButtonType.OK) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startAnimation()
|
||||
} else {
|
||||
cancelAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
private fun startAnimation() {
|
||||
val wrapperTask = Runnable {
|
||||
val recognizer = parentModel.parentModel.recognizer.value
|
||||
val extendedMouthShapes = parentModel.mouthShapes.filter { it.isExtended }.toSet()
|
||||
val reportProgress: (Double?) -> Unit = {
|
||||
progress -> runAndWait { this@AudioFileModel.animationProgress = progress }
|
||||
}
|
||||
val rhubarbTask = RhubarbTask(audioFilePath, recognizer, dialog, extendedMouthShapes, reportProgress)
|
||||
try {
|
||||
try {
|
||||
val result = rhubarbTask.call()
|
||||
runAndWait {
|
||||
reportResult(result)
|
||||
}
|
||||
} finally {
|
||||
runAndWait {
|
||||
animationProgress = null
|
||||
future = null
|
||||
}
|
||||
}
|
||||
} catch (e: InterruptedException) {
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace(System.err)
|
||||
|
||||
Platform.runLater {
|
||||
Alert(Alert.AlertType.ERROR).apply {
|
||||
headerText = "Error performing lip sync for event '$eventName'."
|
||||
contentText = if (e is EndUserException)
|
||||
e.message
|
||||
else
|
||||
("An internal error occurred.\n"
|
||||
+ "Please report an issue, including the following information.\n"
|
||||
+ getStackTrace(e))
|
||||
show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
future = executor.submit(wrapperTask)
|
||||
}
|
||||
|
||||
private fun cancelAnimation() {
|
||||
future?.cancel(true)
|
||||
}
|
||||
}
|
||||
|
||||
enum class AudioFileStatus {
|
||||
NotAnimated,
|
||||
Pending,
|
||||
Animating,
|
||||
Canceling,
|
||||
Done
|
||||
}
|
||||
|
||||
data class AudioFileState(val status: AudioFileStatus, val progress: Double? = null)
|
|
@ -0,0 +1,4 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
// An exception with a human-readable message that can be shown to the end user
|
||||
class EndUserException(message: String): Exception(message)
|
|
@ -0,0 +1,80 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.beans.property.StringProperty
|
||||
import javafx.beans.value.ObservableValue
|
||||
import javafx.scene.Group
|
||||
import javafx.scene.Node
|
||||
import javafx.scene.Parent
|
||||
import javafx.scene.control.Tooltip
|
||||
import javafx.scene.paint.Color
|
||||
import tornadofx.addChildIfPossible
|
||||
import tornadofx.circle
|
||||
import tornadofx.rectangle
|
||||
import tornadofx.removeFromParent
|
||||
|
||||
fun renderErrorIndicator(): Node {
|
||||
return Group().apply {
|
||||
isManaged = false
|
||||
circle {
|
||||
radius = 7.0
|
||||
fill = Color.ORANGERED
|
||||
}
|
||||
rectangle {
|
||||
x = -1.0
|
||||
y = -5.0
|
||||
width = 2.0
|
||||
height = 7.0
|
||||
fill = Color.WHITE
|
||||
}
|
||||
rectangle {
|
||||
x = -1.0
|
||||
y = 3.0
|
||||
width = 2.0
|
||||
height = 2.0
|
||||
fill = Color.WHITE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Parent.errorProperty() : StringProperty {
|
||||
return properties.getOrPut("rhubarb.errorProperty", {
|
||||
val errorIndicator: Node = renderErrorIndicator()
|
||||
val tooltip = Tooltip()
|
||||
val property = SimpleStringProperty()
|
||||
|
||||
fun updateTooltipVisibility() {
|
||||
if (tooltip.text.isNotEmpty() && isFocused) {
|
||||
val bounds = localToScreen(boundsInLocal)
|
||||
tooltip.show(scene.window, bounds.minX + 5, bounds.maxY + 2)
|
||||
} else {
|
||||
tooltip.hide()
|
||||
}
|
||||
}
|
||||
|
||||
focusedProperty().addListener({
|
||||
_: ObservableValue<out Boolean>, _: Boolean, _: Boolean ->
|
||||
updateTooltipVisibility()
|
||||
})
|
||||
|
||||
property.addListener({
|
||||
_: ObservableValue<out String?>, _: String?, newValue: String? ->
|
||||
|
||||
if (newValue != null) {
|
||||
this.addChildIfPossible(errorIndicator)
|
||||
|
||||
tooltip.text = newValue
|
||||
Tooltip.install(this, tooltip)
|
||||
updateTooltipVisibility()
|
||||
} else {
|
||||
errorIndicator.removeFromParent()
|
||||
|
||||
tooltip.text = ""
|
||||
tooltip.hide()
|
||||
Tooltip.uninstall(this, tooltip)
|
||||
updateTooltipVisibility()
|
||||
}
|
||||
})
|
||||
return@getOrPut property
|
||||
}) as StringProperty
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import javafx.scene.image.Image
|
||||
import javafx.stage.Stage
|
||||
import tornadofx.App
|
||||
import tornadofx.addStageIcon
|
||||
import java.lang.reflect.Method
|
||||
import javax.swing.ImageIcon
|
||||
|
||||
class MainApp : App(MainView::class) {
|
||||
override fun start(stage: Stage) {
|
||||
super.start(stage)
|
||||
setIcon()
|
||||
}
|
||||
|
||||
private fun setIcon() {
|
||||
// Set icon for windows
|
||||
for (iconSize in listOf(16, 20, 24, 32, 48, 64, 256)) {
|
||||
addStageIcon(Image(this.javaClass.getResourceAsStream("/icon-$iconSize.png")))
|
||||
}
|
||||
|
||||
// OS X requires the dock icon to be changed separately.
|
||||
// Not all JDKs contain the class com.apple.eawt.Application, so we have to use reflection.
|
||||
val classLoader = this.javaClass.classLoader
|
||||
try {
|
||||
val iconURL = this.javaClass.getResource("/icon-256.png")
|
||||
val image: java.awt.Image = ImageIcon(iconURL).image
|
||||
|
||||
// The following is reflection code for the line
|
||||
// Application.getApplication().setDockIconImage(image)
|
||||
val applicationClass: Class<*> = classLoader.loadClass("com.apple.eawt.Application")
|
||||
val getApplicationMethod: Method = applicationClass.getMethod("getApplication")
|
||||
val application: Any = getApplicationMethod.invoke(null)
|
||||
val setDockIconImageMethod: Method =
|
||||
applicationClass.getMethod("setDockIconImage", java.awt.Image::class.java)
|
||||
setDockIconImageMethod.invoke(application, image);
|
||||
} catch (e: Exception) {
|
||||
// Works only on OS X
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.collections.ObservableList
|
||||
import tornadofx.FX
|
||||
import tornadofx.getValue
|
||||
import tornadofx.setValue
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.InvalidPathException
|
||||
import java.nio.file.Paths
|
||||
import java.util.concurrent.ExecutorService
|
||||
|
||||
class MainModel(private val executor: ExecutorService) {
|
||||
val filePathStringProperty = SimpleStringProperty(getDefaultPathString()).alsoListen { value ->
|
||||
filePathError = getExceptionMessage {
|
||||
animationFileModel = null
|
||||
if (value.isNullOrBlank()) {
|
||||
throw EndUserException("No input file specified.")
|
||||
}
|
||||
|
||||
val path = try {
|
||||
val trimmed = value.removeSurrounding("\"")
|
||||
Paths.get(trimmed)
|
||||
} catch (e: InvalidPathException) {
|
||||
throw EndUserException("Not a valid file path.")
|
||||
}
|
||||
|
||||
if (!Files.exists(path)) {
|
||||
throw EndUserException("File does not exist.")
|
||||
}
|
||||
|
||||
animationFileModel = AnimationFileModel(this, path, executor)
|
||||
}
|
||||
}
|
||||
|
||||
val filePathErrorProperty = SimpleStringProperty()
|
||||
private var filePathError: String? by filePathErrorProperty
|
||||
|
||||
val animationFileModelProperty = SimpleObjectProperty<AnimationFileModel?>()
|
||||
var animationFileModel by animationFileModelProperty
|
||||
private set
|
||||
|
||||
val recognizersProperty = SimpleObjectProperty<ObservableList<Recognizer>>(FXCollections.observableArrayList(
|
||||
Recognizer("pocketSphinx", "PocketSphinx (use for English recordings)"),
|
||||
Recognizer("phonetic", "Phonetic (use for non-English recordings)")
|
||||
))
|
||||
private var recognizers: ObservableList<Recognizer> by recognizersProperty
|
||||
|
||||
val recognizerProperty = SimpleObjectProperty<Recognizer>(recognizers[0])
|
||||
var recognizer: Recognizer by recognizerProperty
|
||||
|
||||
val animationPrefixProperty = SimpleStringProperty("say_")
|
||||
var animationPrefix: String by animationPrefixProperty
|
||||
|
||||
val animationSuffixProperty = SimpleStringProperty("")
|
||||
var animationSuffix: String by animationSuffixProperty
|
||||
|
||||
private fun getDefaultPathString() = FX.application.parameters.raw.firstOrNull()
|
||||
}
|
||||
|
||||
class Recognizer(val value: String, val description: String)
|
|
@ -0,0 +1,257 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import javafx.beans.property.Property
|
||||
import javafx.beans.property.SimpleBooleanProperty
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.event.ActionEvent
|
||||
import javafx.event.EventHandler
|
||||
import javafx.event.EventTarget
|
||||
import javafx.geometry.Pos
|
||||
import javafx.scene.control.*
|
||||
import javafx.scene.input.DragEvent
|
||||
import javafx.scene.input.TransferMode
|
||||
import javafx.scene.layout.*
|
||||
import javafx.scene.paint.Color
|
||||
import javafx.scene.text.Font
|
||||
import javafx.scene.text.FontWeight
|
||||
import javafx.scene.text.Text
|
||||
import javafx.stage.FileChooser
|
||||
import javafx.util.StringConverter
|
||||
import tornadofx.*
|
||||
import java.io.File
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class MainView : View() {
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
private val mainModel = MainModel(executor)
|
||||
|
||||
init {
|
||||
title = "Rhubarb Lip Sync for Spine"
|
||||
}
|
||||
|
||||
override val root = form {
|
||||
var filePathTextField: TextField? = null
|
||||
var filePathButton: Button? = null
|
||||
|
||||
val fileModelProperty = mainModel.animationFileModelProperty
|
||||
|
||||
minWidth = 800.0
|
||||
prefWidth = 1000.0
|
||||
fieldset("Settings") {
|
||||
disableProperty().bind(fileModelProperty.select { it!!.busyProperty })
|
||||
field("Spine JSON file") {
|
||||
filePathTextField = textfield {
|
||||
textProperty().bindBidirectional(mainModel.filePathStringProperty)
|
||||
errorProperty().bind(mainModel.filePathErrorProperty)
|
||||
}
|
||||
filePathButton = button("...")
|
||||
}
|
||||
field("Mouth slot") {
|
||||
combobox<String> {
|
||||
itemsProperty().bind(fileModelProperty.select { it!!.slotsProperty })
|
||||
valueProperty().bindBidirectional(fileModelProperty.select { it!!.mouthSlotProperty })
|
||||
errorProperty().bind(fileModelProperty.select { it!!.mouthSlotErrorProperty })
|
||||
}
|
||||
}
|
||||
field("Mouth naming") {
|
||||
label {
|
||||
textProperty().bind(
|
||||
fileModelProperty
|
||||
.select { it!!.mouthNamingProperty }
|
||||
.select { SimpleStringProperty(it.displayString) }
|
||||
)
|
||||
}
|
||||
}
|
||||
field("Mouth shapes") {
|
||||
hbox {
|
||||
errorProperty().bind(fileModelProperty.select { it!!.mouthShapesErrorProperty })
|
||||
gridpane {
|
||||
hgap = 10.0
|
||||
vgap = 3.0
|
||||
row {
|
||||
label("Basic:")
|
||||
for (shape in MouthShape.basicShapes) {
|
||||
renderShapeCheckbox(shape, fileModelProperty, this)
|
||||
}
|
||||
}
|
||||
row {
|
||||
label("Extended:")
|
||||
for (shape in MouthShape.extendedShapes) {
|
||||
renderShapeCheckbox(shape, fileModelProperty, this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
field("Dialog recognizer") {
|
||||
combobox<Recognizer> {
|
||||
itemsProperty().bind(mainModel.recognizersProperty)
|
||||
this.converter = object : StringConverter<Recognizer>() {
|
||||
override fun toString(recognizer: Recognizer?): String {
|
||||
return recognizer?.description ?: ""
|
||||
}
|
||||
override fun fromString(string: String?): Recognizer {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
}
|
||||
valueProperty().bindBidirectional(mainModel.recognizerProperty)
|
||||
}
|
||||
}
|
||||
field("Animation naming") {
|
||||
textfield {
|
||||
maxWidth = 100.0
|
||||
textProperty().bindBidirectional(mainModel.animationPrefixProperty)
|
||||
}
|
||||
label("<audio event name>")
|
||||
textfield {
|
||||
maxWidth = 100.0
|
||||
textProperty().bindBidirectional(mainModel.animationSuffixProperty)
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldset("Audio events") {
|
||||
tableview<AudioFileModel> {
|
||||
placeholder = Label("There are no events with associated audio files.")
|
||||
columnResizePolicy = SmartResize.POLICY
|
||||
column("Event", AudioFileModel::eventNameProperty)
|
||||
.weightedWidth(1.0)
|
||||
column("Animation name", AudioFileModel::animationNameProperty)
|
||||
.weightedWidth(1.0)
|
||||
column("Audio file", AudioFileModel::displayFilePathProperty)
|
||||
.weightedWidth(1.0)
|
||||
column("Dialog", AudioFileModel::dialogProperty).apply {
|
||||
weightedWidth(3.0)
|
||||
// Make dialog column wrap
|
||||
setCellFactory { tableColumn ->
|
||||
return@setCellFactory TableCell<AudioFileModel, String>().also { cell ->
|
||||
cell.graphic = Text().apply {
|
||||
textProperty().bind(cell.itemProperty())
|
||||
fillProperty().bind(cell.textFillProperty())
|
||||
val widthProperty = tableColumn.widthProperty()
|
||||
.minus(cell.paddingLeftProperty)
|
||||
.minus(cell.paddingRightProperty)
|
||||
wrappingWidthProperty().bind(widthProperty)
|
||||
}
|
||||
cell.prefHeight = Control.USE_COMPUTED_SIZE
|
||||
}
|
||||
}
|
||||
}
|
||||
column("Status", AudioFileModel::audioFileStateProperty).apply {
|
||||
weightedWidth(1.0)
|
||||
setCellFactory {
|
||||
return@setCellFactory object : TableCell<AudioFileModel, AudioFileState>() {
|
||||
override fun updateItem(state: AudioFileState?, empty: Boolean) {
|
||||
super.updateItem(state, empty)
|
||||
graphic = if (state != null) {
|
||||
when (state.status) {
|
||||
AudioFileStatus.NotAnimated -> Text("Not animated").apply {
|
||||
fill = Color.GRAY
|
||||
}
|
||||
AudioFileStatus.Pending,
|
||||
AudioFileStatus.Animating -> HBox().apply {
|
||||
val progress: Double? = state.progress
|
||||
val indeterminate = -1.0
|
||||
val bar = progressbar(progress ?: indeterminate) {
|
||||
maxWidth = Double.MAX_VALUE
|
||||
}
|
||||
HBox.setHgrow(bar, Priority.ALWAYS)
|
||||
hbox {
|
||||
minWidth = 30.0
|
||||
if (progress != null) {
|
||||
text("${(progress * 100).toInt()}%") {
|
||||
alignment = Pos.BASELINE_RIGHT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
AudioFileStatus.Canceling -> Text("Canceling")
|
||||
AudioFileStatus.Done -> Text("Done").apply {
|
||||
font = Font.font(font.family, FontWeight.BOLD, font.size)
|
||||
}
|
||||
}
|
||||
} else null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
column("", AudioFileModel::actionLabelProperty).apply {
|
||||
weightedWidth(1.0)
|
||||
// Show button
|
||||
setCellFactory {
|
||||
return@setCellFactory object : TableCell<AudioFileModel, String>() {
|
||||
override fun updateItem(item: String?, empty: Boolean) {
|
||||
super.updateItem(item, empty)
|
||||
graphic = if (!empty)
|
||||
Button(item).apply {
|
||||
this.maxWidth = Double.MAX_VALUE
|
||||
setOnAction {
|
||||
val audioFileModel = this@tableview.items[index]
|
||||
audioFileModel.performAction()
|
||||
}
|
||||
val invalidProperty: Property<Boolean> = fileModelProperty
|
||||
.select { it!!.validProperty }
|
||||
.select { SimpleBooleanProperty(!it) }
|
||||
disableProperty().bind(invalidProperty)
|
||||
}
|
||||
else
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
itemsProperty().bind(fileModelProperty.select { it!!.audioFileModelsProperty })
|
||||
}
|
||||
}
|
||||
|
||||
onDragOver = EventHandler<DragEvent> { event ->
|
||||
if (event.dragboard.hasFiles() && mainModel.animationFileModel?.busy != true) {
|
||||
event.acceptTransferModes(TransferMode.COPY)
|
||||
event.consume()
|
||||
}
|
||||
}
|
||||
onDragDropped = EventHandler<DragEvent> { event ->
|
||||
if (event.dragboard.hasFiles() && mainModel.animationFileModel?.busy != true) {
|
||||
filePathTextField!!.text = event.dragboard.files.firstOrNull()?.path
|
||||
event.isDropCompleted = true
|
||||
event.consume()
|
||||
}
|
||||
}
|
||||
|
||||
whenUndocked {
|
||||
executor.shutdownNow()
|
||||
}
|
||||
|
||||
filePathButton!!.onAction = EventHandler<ActionEvent> {
|
||||
val fileChooser = FileChooser().apply {
|
||||
title = "Open Spine JSON file"
|
||||
extensionFilters.addAll(
|
||||
FileChooser.ExtensionFilter("Spine JSON file (*.json)", "*.json"),
|
||||
FileChooser.ExtensionFilter("All files (*.*)", "*.*")
|
||||
)
|
||||
val lastDirectory = filePathTextField!!.text?.let { File(it).parentFile }
|
||||
if (lastDirectory != null && lastDirectory.isDirectory) {
|
||||
initialDirectory = lastDirectory
|
||||
}
|
||||
}
|
||||
val file = fileChooser.showOpenDialog(this@MainView.primaryStage)
|
||||
if (file != null) {
|
||||
filePathTextField!!.text = file.path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderShapeCheckbox(shape: MouthShape, fileModelProperty: SimpleObjectProperty<AnimationFileModel?>, parent: EventTarget) {
|
||||
parent.label {
|
||||
textProperty().bind(
|
||||
fileModelProperty
|
||||
.select { it!!.mouthShapesProperty }
|
||||
.select { mouthShapes ->
|
||||
val hairSpace = "\u200A"
|
||||
val result = shape.toString() + hairSpace + if (mouthShapes.contains(shape)) "☑" else "☐"
|
||||
return@select SimpleStringProperty(result)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
data class MouthCue(val time: Double, val mouthShape: MouthShape)
|
|
@ -0,0 +1,55 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import java.util.*
|
||||
|
||||
class MouthNaming(private val prefix: String, private val suffix: String, private val mouthShapeCasing: MouthShapeCasing) {
|
||||
|
||||
companion object {
|
||||
fun guess(mouthNames: List<String>): MouthNaming {
|
||||
if (mouthNames.isEmpty()) {
|
||||
return MouthNaming("", "", guessMouthShapeCasing(""))
|
||||
}
|
||||
|
||||
val commonPrefix = mouthNames.commonPrefix
|
||||
val commonSuffix = mouthNames.commonSuffix
|
||||
val firstMouthName = mouthNames.first()
|
||||
if (commonPrefix.length + commonSuffix.length >= firstMouthName.length) {
|
||||
return MouthNaming(commonPrefix, "", guessMouthShapeCasing(""))
|
||||
}
|
||||
|
||||
val shapeName = firstMouthName.substring(
|
||||
commonPrefix.length,
|
||||
firstMouthName.length - commonSuffix.length)
|
||||
val mouthShapeCasing = guessMouthShapeCasing(shapeName)
|
||||
return MouthNaming(commonPrefix, commonSuffix, mouthShapeCasing)
|
||||
}
|
||||
|
||||
private fun guessMouthShapeCasing(shapeName: String): MouthShapeCasing {
|
||||
return if (shapeName.isBlank() || shapeName[0].isLowerCase())
|
||||
MouthShapeCasing.Lower
|
||||
else
|
||||
MouthShapeCasing.Upper
|
||||
}
|
||||
}
|
||||
|
||||
fun getName(mouthShape: MouthShape): String {
|
||||
val name = if (mouthShapeCasing == MouthShapeCasing.Upper)
|
||||
mouthShape.toString()
|
||||
else
|
||||
mouthShape.toString().toLowerCase(Locale.ROOT)
|
||||
return "$prefix$name$suffix"
|
||||
}
|
||||
|
||||
val displayString: String get() {
|
||||
val casing = if (mouthShapeCasing == MouthShapeCasing.Upper)
|
||||
"<UPPER-CASE SHAPE NAME>"
|
||||
else
|
||||
"<lower-case shape name>"
|
||||
return "\"$prefix$casing$suffix\""
|
||||
}
|
||||
}
|
||||
|
||||
enum class MouthShapeCasing {
|
||||
Upper,
|
||||
Lower
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
enum class MouthShape {
|
||||
A, B, C, D, E, F, G, H, X;
|
||||
|
||||
val isBasic: Boolean
|
||||
get() = this.ordinal < basicShapeCount
|
||||
|
||||
val isExtended: Boolean
|
||||
get() = !this.isBasic
|
||||
|
||||
companion object {
|
||||
const val basicShapeCount = 6
|
||||
|
||||
val basicShapes = MouthShape.values().take(basicShapeCount)
|
||||
|
||||
val extendedShapes = MouthShape.values().drop(basicShapeCount)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import com.beust.klaxon.JsonObject
|
||||
import com.beust.klaxon.Parser as JsonParser
|
||||
import org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS
|
||||
import java.io.*
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.util.concurrent.Callable
|
||||
|
||||
class RhubarbTask(
|
||||
val audioFilePath: Path,
|
||||
val recognizer: String,
|
||||
val dialog: String?,
|
||||
val extendedMouthShapes: Set<MouthShape>,
|
||||
val reportProgress: (Double?) -> Unit
|
||||
) : Callable<List<MouthCue>> {
|
||||
|
||||
override fun call(): List<MouthCue> {
|
||||
if (Thread.currentThread().isInterrupted) {
|
||||
throw InterruptedException()
|
||||
}
|
||||
if (!Files.exists(audioFilePath)) {
|
||||
throw EndUserException("File '$audioFilePath' does not exist.")
|
||||
}
|
||||
|
||||
val dialogFile = if (dialog != null) TemporaryTextFile(dialog) else null
|
||||
val outputFile = TemporaryTextFile()
|
||||
dialogFile.use { outputFile.use {
|
||||
val processBuilder = ProcessBuilder(createProcessBuilderArgs(dialogFile?.filePath)).apply {
|
||||
// See http://java-monitor.com/forum/showthread.php?t=4067
|
||||
redirectOutput(outputFile.filePath.toFile())
|
||||
}
|
||||
val process: Process = processBuilder.start()
|
||||
val stderr = BufferedReader(InputStreamReader(process.errorStream, StandardCharsets.UTF_8))
|
||||
try {
|
||||
while (true) {
|
||||
val line = stderr.interruptibleReadLine()
|
||||
val message = parseJsonObject(line)
|
||||
when (message.string("type")!!) {
|
||||
"progress" -> {
|
||||
reportProgress(message.double("value")!!)
|
||||
}
|
||||
"success" -> {
|
||||
reportProgress(1.0)
|
||||
val resultString = String(Files.readAllBytes(outputFile.filePath), StandardCharsets.UTF_8)
|
||||
return parseRhubarbResult(resultString)
|
||||
}
|
||||
"failure" -> {
|
||||
throw EndUserException(message.string("reason") ?: "Rhubarb failed without reason.")
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: InterruptedException) {
|
||||
process.destroyForcibly()
|
||||
throw e
|
||||
} catch (e: EOFException) {
|
||||
throw EndUserException("Rhubarb terminated unexpectedly.")
|
||||
} finally {
|
||||
process.waitFor()
|
||||
}
|
||||
}}
|
||||
|
||||
throw EndUserException("Audio file processing terminated in an unexpected way.")
|
||||
}
|
||||
|
||||
private fun parseRhubarbResult(jsonString: String): List<MouthCue> {
|
||||
val json = parseJsonObject(jsonString)
|
||||
val mouthCues = json.array<JsonObject>("mouthCues")!!
|
||||
return mouthCues.map { mouthCue ->
|
||||
val time = mouthCue.double("start")!!
|
||||
val mouthShape = MouthShape.valueOf(mouthCue.string("value")!!)
|
||||
return@map MouthCue(time, mouthShape)
|
||||
}
|
||||
}
|
||||
|
||||
private val jsonParser = JsonParser.default()
|
||||
private fun parseJsonObject(jsonString: String): JsonObject {
|
||||
return jsonParser.parse(StringReader(jsonString)) as JsonObject
|
||||
}
|
||||
|
||||
private fun createProcessBuilderArgs(dialogFilePath: Path?): List<String> {
|
||||
val extendedMouthShapesString =
|
||||
if (extendedMouthShapes.any()) extendedMouthShapes.joinToString(separator = "")
|
||||
else "\"\""
|
||||
return mutableListOf(
|
||||
rhubarbBinFilePath.toString(),
|
||||
"--machineReadable",
|
||||
"--recognizer", recognizer,
|
||||
"--exportFormat", "json",
|
||||
"--extendedShapes", extendedMouthShapesString
|
||||
).apply {
|
||||
if (dialogFilePath != null) {
|
||||
addAll(listOf(
|
||||
"--dialogFile", dialogFilePath.toString()
|
||||
))
|
||||
}
|
||||
}.apply {
|
||||
add(audioFilePath.toString())
|
||||
}
|
||||
}
|
||||
|
||||
private val guiBinDirectory: Path by lazy {
|
||||
val path = urlToPath(getLocation(RhubarbTask::class.java))
|
||||
return@lazy if (Files.isDirectory(path)) path.parent else path
|
||||
}
|
||||
|
||||
private val rhubarbBinFilePath: Path by lazy {
|
||||
val rhubarbBinName = if (IS_OS_WINDOWS) "rhubarb.exe" else "rhubarb"
|
||||
var currentDirectory: Path? = guiBinDirectory
|
||||
while (currentDirectory != null) {
|
||||
val candidate: Path = currentDirectory.resolve(rhubarbBinName)
|
||||
if (Files.exists(candidate)) {
|
||||
return@lazy candidate
|
||||
}
|
||||
currentDirectory = currentDirectory.parent
|
||||
}
|
||||
throw EndUserException("Could not find Rhubarb Lip Sync executable '$rhubarbBinName'."
|
||||
+ " Expected to find it in '$guiBinDirectory' or any directory above.")
|
||||
}
|
||||
|
||||
private class TemporaryTextFile(text: String = "") : AutoCloseable {
|
||||
val filePath: Path = Files.createTempFile(null, null).also {
|
||||
Files.write(it, text.toByteArray(StandardCharsets.UTF_8))
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
Files.delete(filePath)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Same as readLine, but can be interrupted.
|
||||
// Note that this function handles linebreak characters differently from readLine.
|
||||
// It only consumes the first linebreak character before returning and swallows any leading
|
||||
// linebreak characters.
|
||||
// This behavior is much easier to implement and doesn't make any difference for our purposes.
|
||||
private fun BufferedReader.interruptibleReadLine(): String {
|
||||
val result = StringBuilder()
|
||||
while (true) {
|
||||
val char = interruptibleReadChar()
|
||||
if (char == '\r' || char == '\n') {
|
||||
if (result.isNotEmpty()) return result.toString()
|
||||
} else {
|
||||
result.append(char)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun BufferedReader.interruptibleReadChar(): Char {
|
||||
while (true) {
|
||||
if (Thread.currentThread().isInterrupted) {
|
||||
throw InterruptedException()
|
||||
}
|
||||
if (ready()) {
|
||||
val result: Int = read()
|
||||
if (result == -1) {
|
||||
throw EOFException()
|
||||
}
|
||||
return result.toChar()
|
||||
}
|
||||
Thread.yield()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import com.beust.klaxon.*
|
||||
import javafx.collections.FXCollections.observableSet
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
|
||||
class SpineJson(private val filePath: Path) {
|
||||
private val fileDirectoryPath: Path = filePath.parent
|
||||
private val json: JsonObject
|
||||
private val skeleton: JsonObject
|
||||
|
||||
init {
|
||||
if (!Files.exists(filePath)) {
|
||||
throw EndUserException("File '$filePath' does not exist.")
|
||||
}
|
||||
try {
|
||||
json = Parser.default().parse(filePath.toString()) as JsonObject
|
||||
} catch (e: Exception) {
|
||||
throw EndUserException("Wrong file format. This is not a valid JSON file.")
|
||||
}
|
||||
skeleton = json.obj("skeleton") ?: throw EndUserException("JSON file is corrupted.")
|
||||
|
||||
validateProperties()
|
||||
}
|
||||
|
||||
private fun validateProperties() {
|
||||
imagesDirectoryPath
|
||||
audioDirectoryPath
|
||||
}
|
||||
|
||||
private val imagesDirectoryPath: Path get() {
|
||||
val relativeImagesDirectory = skeleton.string("images")
|
||||
?: throw EndUserException("JSON file is incomplete: Images path is missing."
|
||||
+ " Make sure to check 'Nonessential data' when exporting.")
|
||||
|
||||
val imagesDirectoryPath = fileDirectoryPath.resolve(relativeImagesDirectory).normalize()
|
||||
if (!Files.exists(imagesDirectoryPath)) {
|
||||
throw EndUserException("Could not find images directory relative to the JSON file."
|
||||
+ " Make sure the JSON file is in the same directory as the original Spine file.")
|
||||
}
|
||||
|
||||
return imagesDirectoryPath
|
||||
}
|
||||
|
||||
val audioDirectoryPath: Path get() {
|
||||
val relativeAudioDirectory = skeleton.string("audio")
|
||||
?: throw EndUserException("JSON file is incomplete: Audio path is missing."
|
||||
+ " Make sure to check 'Nonessential data' when exporting.")
|
||||
|
||||
val audioDirectoryPath = fileDirectoryPath.resolve(relativeAudioDirectory).normalize()
|
||||
if (!Files.exists(audioDirectoryPath)) {
|
||||
throw EndUserException("Could not find audio directory relative to the JSON file."
|
||||
+ " Make sure the JSON file is in the same directory as the original Spine file.")
|
||||
}
|
||||
|
||||
return audioDirectoryPath
|
||||
}
|
||||
|
||||
val frameRate: Double get() {
|
||||
return skeleton.double("fps") ?: 30.0
|
||||
}
|
||||
|
||||
val slots: List<String> get() {
|
||||
val slots = json.array("slots") ?: listOf<JsonObject>()
|
||||
return slots.mapNotNull { it.string("name") }
|
||||
}
|
||||
|
||||
fun guessMouthSlot(): String? {
|
||||
return slots.firstOrNull { it.contains("mouth", ignoreCase = true) }
|
||||
?: slots.firstOrNull()
|
||||
}
|
||||
|
||||
data class AudioEvent(val name: String, val relativeAudioFilePath: String, val dialog: String?)
|
||||
|
||||
val audioEvents: List<AudioEvent> get() {
|
||||
val events = json.obj("events") ?: JsonObject()
|
||||
val result = mutableListOf<AudioEvent>()
|
||||
for ((name, value) in events) {
|
||||
if (value !is JsonObject) throw EndUserException("Invalid event found.")
|
||||
|
||||
val relativeAudioFilePath = value.string("audio") ?: continue
|
||||
|
||||
val dialog = value.string("string")
|
||||
result.add(AudioEvent(name, relativeAudioFilePath, dialog))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun getSlotAttachmentNames(slotName: String): List<String> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val skins: Collection<JsonObject> = when (val skinsObject = json["skins"]) {
|
||||
is JsonObject -> skinsObject.values as Collection<JsonObject>
|
||||
is JsonArray<*> -> skinsObject as Collection<JsonObject>
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
// Get attachment names for all skins
|
||||
return skins
|
||||
.flatMap { skin ->
|
||||
skin.obj(slotName)?.keys?.toList()
|
||||
?: skin.obj("attachments")?.obj(slotName)?.keys?.toList()
|
||||
?: emptyList<String>()
|
||||
}
|
||||
.distinct()
|
||||
}
|
||||
|
||||
val animationNames = observableSet<String>(
|
||||
json.obj("animations")?.map{ it.key }?.toMutableSet() ?: mutableSetOf()
|
||||
)
|
||||
|
||||
fun createOrUpdateAnimation(mouthCues: List<MouthCue>, eventName: String, animationName: String,
|
||||
mouthSlot: String, mouthNaming: MouthNaming
|
||||
) {
|
||||
if (!json.containsKey("animations")) {
|
||||
json["animations"] = JsonObject()
|
||||
}
|
||||
val animations: JsonObject = json.obj("animations")!!
|
||||
|
||||
// Round times to full frames. Always round down.
|
||||
// If events coincide, prefer the latest one.
|
||||
val keyframes = mutableMapOf<Int, MouthShape>()
|
||||
for (mouthCue in mouthCues) {
|
||||
val frameNumber = (mouthCue.time * frameRate).toInt()
|
||||
keyframes[frameNumber] = mouthCue.mouthShape
|
||||
}
|
||||
|
||||
animations[animationName] = JsonObject().apply {
|
||||
this["slots"] = JsonObject().apply {
|
||||
this[mouthSlot] = JsonObject().apply {
|
||||
this["attachment"] = JsonArray(
|
||||
keyframes
|
||||
.toSortedMap()
|
||||
.map { (frameNumber, mouthShape) ->
|
||||
JsonObject().apply {
|
||||
this["time"] = frameNumber / frameRate
|
||||
this["name"] = mouthNaming.getName(mouthShape)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
this["events"] = JsonArray(
|
||||
JsonObject().apply {
|
||||
this["time"] = 0.0
|
||||
this["name"] = eventName
|
||||
this["string"] = ""
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
animationNames.add(animationName)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return json.toJsonString(prettyPrint = true)
|
||||
}
|
||||
|
||||
fun save() {
|
||||
Files.write(filePath, listOf(toString()), StandardCharsets.UTF_8)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import java.io.FileInputStream
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URISyntaxException
|
||||
import java.net.URL
|
||||
import org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
// The following code is adapted from https://stackoverflow.com/a/12733172/52041
|
||||
|
||||
/**
|
||||
* Gets the base location of the given class.
|
||||
*
|
||||
* If the class is directly on the file system (e.g.,
|
||||
* "/path/to/my/package/MyClass.class") then it will return the base directory
|
||||
* (e.g., "file:/path/to").
|
||||
*
|
||||
* If the class is within a JAR file (e.g.,
|
||||
* "/path/to/my-jar.jar!/my/package/MyClass.class") then it will return the
|
||||
* path to the JAR (e.g., "file:/path/to/my-jar.jar").
|
||||
*
|
||||
* @param c The class whose location is desired.
|
||||
*/
|
||||
fun getLocation(c: Class<*>): URL {
|
||||
// Try the easy way first
|
||||
try {
|
||||
val codeSourceLocation = c.protectionDomain.codeSource.location
|
||||
if (codeSourceLocation != null) return codeSourceLocation
|
||||
} catch (e: SecurityException) {
|
||||
// Cannot access protection domain
|
||||
} catch (e: NullPointerException) {
|
||||
// Protection domain or code source is null
|
||||
}
|
||||
|
||||
// The easy way failed, so we try the hard way. We ask for the class
|
||||
// itself as a resource, then strip the class's path from the URL string,
|
||||
// leaving the base path.
|
||||
|
||||
// Get the class's raw resource path
|
||||
val classResource = c.getResource(c.simpleName + ".class")
|
||||
?: throw Exception("Cannot find class resource.")
|
||||
|
||||
val url = classResource.toString()
|
||||
val suffix = c.canonicalName.replace('.', '/') + ".class"
|
||||
if (!url.endsWith(suffix)) throw Exception("Malformed URL.")
|
||||
|
||||
// strip the class's path from the URL string
|
||||
val base = url.substring(0, url.length - suffix.length)
|
||||
|
||||
var path = base
|
||||
|
||||
// remove the "jar:" prefix and "!/" suffix, if present
|
||||
if (path.startsWith("jar:")) path = path.substring(4, path.length - 2)
|
||||
|
||||
return URL(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given URL to its corresponding [Path].
|
||||
*
|
||||
* @param url The URL to convert.
|
||||
* @return A file path suitable for use with e.g. [FileInputStream]
|
||||
*/
|
||||
fun urlToPath(url: URL): Path {
|
||||
var pathString = url.toString()
|
||||
|
||||
if (pathString.startsWith("jar:")) {
|
||||
// Remove "jar:" prefix and "!/" suffix
|
||||
val index = pathString.indexOf("!/")
|
||||
pathString = pathString.substring(4, index)
|
||||
}
|
||||
|
||||
try {
|
||||
if (IS_OS_WINDOWS && pathString.matches("file:[A-Za-z]:.*".toRegex())) {
|
||||
pathString = "file:/" + pathString.substring(5)
|
||||
}
|
||||
return Paths.get(URL(pathString).toURI())
|
||||
} catch (e: MalformedURLException) {
|
||||
// URL is not completely well-formed.
|
||||
} catch (e: URISyntaxException) {
|
||||
// URL is not completely well-formed.
|
||||
}
|
||||
|
||||
if (pathString.startsWith("file:")) {
|
||||
// Pass through the URL as-is, minus "file:" prefix
|
||||
pathString = pathString.substring(5)
|
||||
return Paths.get(pathString)
|
||||
}
|
||||
throw IllegalArgumentException("Invalid URL: $url")
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import javafx.application.Application
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Application.launch(MainApp::class.java, *args)
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import javafx.application.Platform
|
||||
import javafx.beans.property.Property
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.concurrent.withLock
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
|
||||
val List<String>.commonPrefix: String get() {
|
||||
return if (isEmpty()) "" else this.reduce { result, string -> result.commonPrefixWith(string) }
|
||||
}
|
||||
|
||||
val List<String>.commonSuffix: String get() {
|
||||
return if (isEmpty()) "" else this.reduce { result, string -> result.commonSuffixWith(string) }
|
||||
}
|
||||
|
||||
fun <TValue, TProperty : Property<TValue>> TProperty.alsoListen(listener: (TValue) -> Unit) : TProperty {
|
||||
// Notify the listener of the initial value.
|
||||
// If we did this synchronously, the listener's state would have to be fully initialized the
|
||||
// moment this function is called. So calling this function during object initialization might
|
||||
// result in access to uninitialized state.
|
||||
Platform.runLater { listener(this.value) }
|
||||
|
||||
addListener({ _, _, newValue -> listener(newValue)})
|
||||
return this
|
||||
}
|
||||
|
||||
fun getExceptionMessage(action: () -> Unit): String? {
|
||||
try {
|
||||
action()
|
||||
} catch (e: Exception) {
|
||||
return e.message
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a Runnable on the JFX thread and waits until it's finished.
|
||||
* Similar to SwingUtilities.invokeAndWait.
|
||||
* Based on http://www.guigarage.com/2013/01/invokeandwait-for-javafx/
|
||||
*
|
||||
* @throws InterruptedException Execution was interrupted
|
||||
* @throws Throwable An exception occurred in the run method of the Runnable
|
||||
*/
|
||||
fun runAndWait(action: () -> Unit) {
|
||||
if (Platform.isFxApplicationThread()) {
|
||||
action()
|
||||
} else {
|
||||
val lock = ReentrantLock()
|
||||
lock.withLock {
|
||||
val doneCondition = lock.newCondition()
|
||||
var throwable: Throwable? = null
|
||||
Platform.runLater {
|
||||
lock.withLock {
|
||||
try {
|
||||
action()
|
||||
} catch (e: Throwable) {
|
||||
throwable = e
|
||||
} finally {
|
||||
doneCondition.signal()
|
||||
}
|
||||
}
|
||||
}
|
||||
doneCondition.await()
|
||||
throwable?.let { throw it }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getStackTrace(e: Exception): String {
|
||||
val stringWriter = StringWriter()
|
||||
e.printStackTrace(PrintWriter(stringWriter))
|
||||
return stringWriter.toString()
|
||||
}
|
After ![]() (image error) Size: 742 B |
After ![]() (image error) Size: 847 B |
After ![]() (image error) Size: 1.0 KiB |
After ![]() (image error) Size: 12 KiB |
After ![]() (image error) Size: 1.4 KiB |
After ![]() (image error) Size: 2.1 KiB |
After ![]() (image error) Size: 2.9 KiB |
|
@ -0,0 +1,121 @@
|
|||
{
|
||||
"skeleton": { "hash": "voNIQumqp3+UQAl32SwHzLMEDaI", "spine": "3.7.04-beta", "width": 795, "height": 1249.62 },
|
||||
"bones": [
|
||||
{ "name": "root" },
|
||||
{ "name": "torso", "parent": "root", "length": 394.49, "rotation": 90, "y": 100 },
|
||||
{ "name": "head", "parent": "torso", "length": 515.83, "x": 390 },
|
||||
{ "name": "legs", "parent": "torso", "length": 79.85, "rotation": 180, "x": -6 }
|
||||
],
|
||||
"slots": [
|
||||
{ "name": "legs", "bone": "legs", "attachment": "legs" },
|
||||
{ "name": "torso", "bone": "torso", "attachment": "torso" },
|
||||
{ "name": "head", "bone": "head", "attachment": "head" },
|
||||
{ "name": "mouth", "bone": "head", "attachment": "mouth_d" }
|
||||
],
|
||||
"skins": {
|
||||
"default": {
|
||||
"head": {
|
||||
"head": { "x": 305.19, "y": -3.37, "rotation": -90, "width": 795, "height": 908 }
|
||||
},
|
||||
"legs": {
|
||||
"legs": { "x": 20.93, "y": 9.45, "rotation": 90, "width": 602, "height": 147 }
|
||||
},
|
||||
"mouth": {
|
||||
"mouth_a": { "x": -53.21, "y": -2.6, "rotation": -90, "width": 118, "height": 27 },
|
||||
"mouth_b": { "x": -38.68, "y": -0.88, "rotation": -90, "width": 170, "height": 59 },
|
||||
"mouth_c": { "x": -45.57, "y": -2.21, "rotation": -90, "width": 145, "height": 71 },
|
||||
"mouth_d": { "x": -50.58, "y": -16.55, "rotation": -90, "width": 122, "height": 91 },
|
||||
"mouth_e": { "x": -47.51, "y": 1.69, "rotation": -90, "width": 105, "height": 73 },
|
||||
"mouth_f": { "x": -42.7, "y": -1.9, "rotation": -90, "width": 55, "height": 54 },
|
||||
"mouth_g": { "x": -42.77, "y": 2.56, "rotation": -90, "width": 141, "height": 37 },
|
||||
"mouth_h": { "x": -44.53, "y": 1.07, "rotation": -90, "width": 141, "height": 71 }
|
||||
},
|
||||
"torso": {
|
||||
"torso": { "x": 185.9, "y": 0.39, "rotation": -90, "width": 741, "height": 449 }
|
||||
}
|
||||
}
|
||||
},
|
||||
"events": {
|
||||
"doornail": {
|
||||
"string": "Marley was dead: to begin with. There is no doubt whatever about that. The register of his burial was signed by the clergyman, the clerk, the undertaker, and the chief mourner. Scrooge signed it: and Scrooge's name was good upon 'Change, for anything he chose to put his hand to. Old Marley was as dead as a door-nail.Mind! I don't mean to say that I know, of my own knowledge, what there is particularly dead about a door-nail. I might have been inclined, myself, to regard a coffin-nail as the deadest piece of ironmongery in the trade. But the wisdom of our ancestors is in the simile; and my unhallowed hands shall not disturb it, or the Country's done for. You will therefore permit me to repeat, emphatically, that Marley was as dead as a door-nail.",
|
||||
"audio": "doornail.wav"
|
||||
},
|
||||
"hi": { "audio": "hi.wav" }
|
||||
},
|
||||
"animations": {
|
||||
"say_test": {
|
||||
"slots": {
|
||||
"mouth": {
|
||||
"attachment": [
|
||||
{ "time": 0, "name": "mouth_a" },
|
||||
{ "time": 0.1, "name": "mouth_b" },
|
||||
{ "time": 0.2, "name": "mouth_c" },
|
||||
{ "time": 0.2667, "name": "mouth_d" },
|
||||
{ "time": 0.3667, "name": "mouth_c" },
|
||||
{ "time": 0.4333, "name": "mouth_a" },
|
||||
{ "time": 0.5333, "name": "mouth_e" },
|
||||
{ "time": 0.6, "name": "mouth_f" },
|
||||
{ "time": 0.7, "name": "mouth_e" },
|
||||
{ "time": 0.8, "name": "mouth_g" },
|
||||
{ "time": 0.8667, "name": "mouth_c" },
|
||||
{ "time": 0.9667, "name": "mouth_h" },
|
||||
{ "time": 1.0667, "name": "mouth_a" }
|
||||
]
|
||||
}
|
||||
},
|
||||
"events": [
|
||||
{ "time": 0.8667, "name": "doornail", "string": "" }
|
||||
]
|
||||
},
|
||||
"shake_head": {
|
||||
"bones": {
|
||||
"head": {
|
||||
"rotate": [
|
||||
{
|
||||
"time": 0,
|
||||
"angle": 0,
|
||||
"curve": [ 0.25, 0, 0.75, 1 ]
|
||||
},
|
||||
{
|
||||
"time": 0.1667,
|
||||
"angle": 10.02,
|
||||
"curve": [ 0.25, 0, 0.75, 1 ]
|
||||
},
|
||||
{
|
||||
"time": 0.5,
|
||||
"angle": -9.37,
|
||||
"curve": [ 0.25, 0, 0.75, 1 ]
|
||||
},
|
||||
{
|
||||
"time": 0.8333,
|
||||
"angle": 10.39,
|
||||
"curve": [ 0.574, 0, 0.666, 1 ]
|
||||
},
|
||||
{ "time": 1.5, "angle": 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"walk": {
|
||||
"bones": {
|
||||
"torso": {
|
||||
"translate": [
|
||||
{
|
||||
"time": 0,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"curve": [ 0, 0.5, 0.75, 1 ]
|
||||
},
|
||||
{
|
||||
"time": 0.1333,
|
||||
"x": 0,
|
||||
"y": 30,
|
||||
"curve": [ 0.25, 0, 1, 0.49 ]
|
||||
},
|
||||
{ "time": 0.2667, "x": 0, "y": 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
{
|
||||
"skeleton": { "hash": "nWA5IiZBBeDJ6tKyTnjtIfu1GXE", "spine": "3.7.94", "width": 795, "height": 1249.62, "images": "./images/", "audio": "./audio/" },
|
||||
"bones": [
|
||||
{ "name": "root" },
|
||||
{ "name": "torso", "parent": "root", "length": 394.49, "rotation": 90, "y": 100 },
|
||||
{ "name": "head", "parent": "torso", "length": 515.83, "x": 390 },
|
||||
{ "name": "legs", "parent": "torso", "length": 79.85, "rotation": 180, "x": -6 }
|
||||
],
|
||||
"slots": [
|
||||
{ "name": "legs", "bone": "legs", "attachment": "legs" },
|
||||
{ "name": "torso", "bone": "torso", "attachment": "torso" },
|
||||
{ "name": "head", "bone": "head", "attachment": "head" },
|
||||
{ "name": "mouth", "bone": "head", "attachment": "mouth_c" }
|
||||
],
|
||||
"skins": {
|
||||
"default": {
|
||||
"head": {
|
||||
"head": { "x": 305.19, "y": -3.37, "rotation": -90, "width": 795, "height": 908 }
|
||||
},
|
||||
"legs": {
|
||||
"legs": { "x": 20.93, "y": 9.45, "rotation": 90, "width": 602, "height": 147 }
|
||||
},
|
||||
"mouth": {
|
||||
"mouth_a": { "x": -53.21, "y": -2.6, "rotation": -90, "width": 118, "height": 27 },
|
||||
"mouth_b": { "x": -38.68, "y": -0.88, "rotation": -90, "width": 170, "height": 59 },
|
||||
"mouth_c": { "x": -45.57, "y": -2.21, "rotation": -90, "width": 145, "height": 71 },
|
||||
"mouth_d": { "x": -50.58, "y": -16.55, "rotation": -90, "width": 122, "height": 91 },
|
||||
"mouth_e": { "x": -47.51, "y": 1.69, "rotation": -90, "width": 105, "height": 73 },
|
||||
"mouth_f": { "x": -42.7, "y": -1.9, "rotation": -90, "width": 55, "height": 54 },
|
||||
"mouth_g": { "x": -42.77, "y": 2.56, "rotation": -90, "width": 141, "height": 37 },
|
||||
"mouth_h": { "x": -44.53, "y": 1.07, "rotation": -90, "width": 141, "height": 71 }
|
||||
},
|
||||
"torso": {
|
||||
"torso": { "x": 185.9, "y": 0.39, "rotation": -90, "width": 741, "height": 449 }
|
||||
}
|
||||
}
|
||||
},
|
||||
"events": {
|
||||
"1-have-you-heard": { "audio": "1-have-you-heard.wav" },
|
||||
"2-it's-a-tool": { "audio": "2-it's-a-tool.wav" },
|
||||
"3-and-now-you-can": { "audio": "3-and-now-you-can.wav" }
|
||||
},
|
||||
"animations": {
|
||||
"shake_head": {
|
||||
"bones": {
|
||||
"head": {
|
||||
"rotate": [
|
||||
{
|
||||
"time": 0,
|
||||
"angle": 0,
|
||||
"curve": [ 0.25, 0, 0.75, 1 ]
|
||||
},
|
||||
{
|
||||
"time": 0.1667,
|
||||
"angle": 10.02,
|
||||
"curve": [ 0.25, 0, 0.75, 1 ]
|
||||
},
|
||||
{
|
||||
"time": 0.5,
|
||||
"angle": -9.37,
|
||||
"curve": [ 0.25, 0, 0.75, 1 ]
|
||||
},
|
||||
{
|
||||
"time": 0.8333,
|
||||
"angle": 10.39,
|
||||
"curve": [ 0.574, 0, 0.666, 1 ]
|
||||
},
|
||||
{ "time": 1.5, "angle": 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"walk": {
|
||||
"bones": {
|
||||
"torso": {
|
||||
"translate": [
|
||||
{
|
||||
"time": 0,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"curve": [ 0, 0.5, 0.75, 1 ]
|
||||
},
|
||||
{
|
||||
"time": 0.1333,
|
||||
"x": 0,
|
||||
"y": 30,
|
||||
"curve": [ 0.25, 0, 1, 0.49 ]
|
||||
},
|
||||
{ "time": 0.2667, "x": 0, "y": 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
{
|
||||
"skeleton": { "hash": "rSEJPpMBeapC2jv56cUew+IkQd0", "spine": "3.8.42-beta", "x": -394.13, "y": -0.43, "width": 795, "height": 1249.62 },
|
||||
"bones": [
|
||||
{ "name": "root" },
|
||||
{ "name": "torso", "parent": "root", "length": 394.49, "rotation": 90, "y": 100 },
|
||||
{ "name": "head", "parent": "torso", "length": 515.83, "x": 390 },
|
||||
{ "name": "legs", "parent": "torso", "length": 79.85, "rotation": 180, "x": -6 }
|
||||
],
|
||||
"slots": [
|
||||
{ "name": "legs", "bone": "legs", "attachment": "legs" },
|
||||
{ "name": "torso", "bone": "torso", "attachment": "torso" },
|
||||
{ "name": "head", "bone": "head", "attachment": "head" },
|
||||
{ "name": "mouth", "bone": "head", "attachment": "mouth_c" }
|
||||
],
|
||||
"skins": [
|
||||
{
|
||||
"name": "default",
|
||||
"attachments": {
|
||||
"mouth": {
|
||||
"mouth_a": { "x": -53.21, "y": -2.6, "rotation": -90, "width": 118, "height": 27 },
|
||||
"mouth_b": { "x": -38.68, "y": -0.88, "rotation": -90, "width": 170, "height": 59 },
|
||||
"mouth_c": { "x": -45.57, "y": -2.21, "rotation": -90, "width": 145, "height": 71 },
|
||||
"mouth_d": { "x": -50.58, "y": -16.55, "rotation": -90, "width": 122, "height": 91 },
|
||||
"mouth_e": { "x": -47.51, "y": 1.69, "rotation": -90, "width": 105, "height": 73 },
|
||||
"mouth_f": { "x": -42.7, "y": -1.9, "rotation": -90, "width": 55, "height": 54 },
|
||||
"mouth_g": { "x": -42.77, "y": 2.56, "rotation": -90, "width": 141, "height": 37 },
|
||||
"mouth_h": { "x": -44.53, "y": 1.07, "rotation": -90, "width": 141, "height": 71 }
|
||||
},
|
||||
"head": {
|
||||
"head": { "x": 305.19, "y": -3.37, "rotation": -90, "width": 795, "height": 908 }
|
||||
},
|
||||
"legs": {
|
||||
"legs": { "x": 20.93, "y": 9.45, "rotation": 90, "width": 602, "height": 147 }
|
||||
},
|
||||
"torso": {
|
||||
"torso": { "x": 185.9, "y": 0.39, "rotation": -90, "width": 741, "height": 449 }
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"events": {
|
||||
"1-have-you-heard": { "audio": "1-have-you-heard.wav" },
|
||||
"2-it's-a-tool": { "audio": "2-it's-a-tool.wav" },
|
||||
"3-and-now-you-can": { "audio": "3-and-now-you-can.wav" }
|
||||
},
|
||||
"animations": {
|
||||
"shake_head": {
|
||||
"bones": {
|
||||
"head": {
|
||||
"rotate": [
|
||||
{ "curve": 0.25, "c3": 0.75 },
|
||||
{ "time": 0.1667, "angle": 10.02, "curve": 0.25, "c3": 0.75 },
|
||||
{ "time": 0.5, "angle": -9.37, "curve": 0.25, "c3": 0.75 },
|
||||
{ "time": 0.8333, "angle": 10.39, "curve": 0.574, "c3": 0.666 },
|
||||
{ "time": 1.5 }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"walk": {
|
||||
"bones": {
|
||||
"torso": {
|
||||
"translate": [
|
||||
{ "curve": 0, "c2": 0.5, "c3": 0.75 },
|
||||
{ "time": 0.1333, "y": 30, "curve": 0.25, "c4": 0.49 },
|
||||
{ "time": 0.2667 }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
{
|
||||
"skeleton": {
|
||||
"hash": "sH1atSHvppLIr/A6E6H7PXWiU4s",
|
||||
"spine": "3.8.42-beta",
|
||||
"x": -394.13,
|
||||
"y": -0.43,
|
||||
"width": 795,
|
||||
"height": 1249.62,
|
||||
"images": "./images/",
|
||||
"audio": "./audio/"
|
||||
},
|
||||
"bones": [
|
||||
{ "name": "root" },
|
||||
{ "name": "torso", "parent": "root", "length": 394.49, "rotation": 90, "y": 100 },
|
||||
{ "name": "head", "parent": "torso", "length": 515.83, "x": 390 },
|
||||
{ "name": "legs", "parent": "torso", "length": 79.85, "rotation": 180, "x": -6 }
|
||||
],
|
||||
"slots": [
|
||||
{ "name": "legs", "bone": "legs", "attachment": "legs" },
|
||||
{ "name": "torso", "bone": "torso", "attachment": "torso" },
|
||||
{ "name": "head", "bone": "head", "attachment": "head" },
|
||||
{ "name": "mouth", "bone": "head", "attachment": "mouth_c" }
|
||||
],
|
||||
"skins": [
|
||||
{
|
||||
"name": "default",
|
||||
"attachments": {
|
||||
"mouth": {
|
||||
"mouth_a": { "x": -53.21, "y": -2.6, "rotation": -90, "width": 118, "height": 27 },
|
||||
"mouth_b": { "x": -38.68, "y": -0.88, "rotation": -90, "width": 170, "height": 59 },
|
||||
"mouth_c": { "x": -45.57, "y": -2.21, "rotation": -90, "width": 145, "height": 71 },
|
||||
"mouth_d": { "x": -50.58, "y": -16.55, "rotation": -90, "width": 122, "height": 91 },
|
||||
"mouth_e": { "x": -47.51, "y": 1.69, "rotation": -90, "width": 105, "height": 73 },
|
||||
"mouth_f": { "x": -42.7, "y": -1.9, "rotation": -90, "width": 55, "height": 54 },
|
||||
"mouth_g": { "x": -42.77, "y": 2.56, "rotation": -90, "width": 141, "height": 37 },
|
||||
"mouth_h": { "x": -44.53, "y": 1.07, "rotation": -90, "width": 141, "height": 71 }
|
||||
},
|
||||
"head": {
|
||||
"head": { "x": 305.19, "y": -3.37, "rotation": -90, "width": 795, "height": 908 }
|
||||
},
|
||||
"legs": {
|
||||
"legs": { "x": 20.93, "y": 9.45, "rotation": 90, "width": 602, "height": 147 }
|
||||
},
|
||||
"torso": {
|
||||
"torso": { "x": 185.9, "y": 0.39, "rotation": -90, "width": 741, "height": 449 }
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"events": {
|
||||
"1-have-you-heard": { "audio": "1-have-you-heard.wav" },
|
||||
"2-it's-a-tool": { "audio": "2-it's-a-tool.wav" },
|
||||
"3-and-now-you-can": { "audio": "3-and-now-you-can.wav" }
|
||||
},
|
||||
"animations": {
|
||||
"shake_head": {
|
||||
"bones": {
|
||||
"head": {
|
||||
"rotate": [
|
||||
{ "curve": 0.25, "c3": 0.75 },
|
||||
{ "time": 0.1667, "angle": 10.02, "curve": 0.25, "c3": 0.75 },
|
||||
{ "time": 0.5, "angle": -9.37, "curve": 0.25, "c3": 0.75 },
|
||||
{ "time": 0.8333, "angle": 10.39, "curve": 0.574, "c3": 0.666 },
|
||||
{ "time": 1.5 }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"walk": {
|
||||
"bones": {
|
||||
"torso": {
|
||||
"translate": [
|
||||
{ "curve": 0, "c2": 0.5, "c3": 0.75 },
|
||||
{ "time": 0.1333, "y": 30, "curve": 0.25, "c4": 0.49 },
|
||||
{ "time": 0.2667 }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.rhubarb_lip_sync.rhubarb_for_spine
|
||||
|
||||
import org.junit.jupiter.api.Nested
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.nio.file.Paths
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.catchThrowable
|
||||
|
||||
class SpineJsonTest {
|
||||
@Nested
|
||||
inner class `file format 3_7` {
|
||||
@Test
|
||||
fun `correctly reads valid file`() {
|
||||
val path = Paths.get("src/test/data/jsonFiles/matt-3.7.json").toAbsolutePath()
|
||||
val spine = SpineJson(path)
|
||||
|
||||
assertThat(spine.audioDirectoryPath)
|
||||
.isEqualTo(Paths.get("src/test/data/jsonFiles/audio").toAbsolutePath())
|
||||
assertThat(spine.frameRate).isEqualTo(30.0)
|
||||
assertThat(spine.slots).containsExactly("legs", "torso", "head", "mouth")
|
||||
assertThat(spine.guessMouthSlot()).isEqualTo("mouth")
|
||||
assertThat(spine.audioEvents).containsExactly(
|
||||
SpineJson.AudioEvent("1-have-you-heard", "1-have-you-heard.wav", null),
|
||||
SpineJson.AudioEvent("2-it's-a-tool", "2-it's-a-tool.wav", null),
|
||||
SpineJson.AudioEvent("3-and-now-you-can", "3-and-now-you-can.wav", null)
|
||||
)
|
||||
assertThat(spine.getSlotAttachmentNames("mouth")).isEqualTo(('a'..'h').map{ "mouth_$it" })
|
||||
assertThat(spine.animationNames).containsExactly("shake_head", "walk")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `throws on file without nonessential data`() {
|
||||
val path = Paths.get("src/test/data/jsonFiles/matt-3.7-essential.json").toAbsolutePath()
|
||||
val throwable = catchThrowable { SpineJson(path) }
|
||||
assertThat(throwable)
|
||||
.hasMessage("JSON file is incomplete: Images path is missing. Make sure to check 'Nonessential data' when exporting.")
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
inner class `file format 3_8` {
|
||||
@Test
|
||||
fun `correctly reads valid file`() {
|
||||
val path = Paths.get("src/test/data/jsonFiles/matt-3.8.json").toAbsolutePath()
|
||||
val spine = SpineJson(path)
|
||||
|
||||
assertThat(spine.audioDirectoryPath)
|
||||
.isEqualTo(Paths.get("src/test/data/jsonFiles/audio").toAbsolutePath())
|
||||
assertThat(spine.frameRate).isEqualTo(30.0)
|
||||
assertThat(spine.slots).containsExactly("legs", "torso", "head", "mouth")
|
||||
assertThat(spine.guessMouthSlot()).isEqualTo("mouth")
|
||||
assertThat(spine.audioEvents).containsExactly(
|
||||
SpineJson.AudioEvent("1-have-you-heard", "1-have-you-heard.wav", null),
|
||||
SpineJson.AudioEvent("2-it's-a-tool", "2-it's-a-tool.wav", null),
|
||||
SpineJson.AudioEvent("3-and-now-you-can", "3-and-now-you-can.wav", null)
|
||||
)
|
||||
assertThat(spine.getSlotAttachmentNames("mouth")).isEqualTo(('a'..'h').map{ "mouth_$it" })
|
||||
assertThat(spine.animationNames).containsExactly("shake_head", "walk")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `throws on file without nonessential data`() {
|
||||
val path = Paths.get("src/test/data/jsonFiles/matt-3.8-essential.json").toAbsolutePath()
|
||||
val throwable = catchThrowable { SpineJson(path) }
|
||||
assertThat(throwable)
|
||||
.hasMessage("JSON file is incomplete: Images path is missing. Make sure to check 'Nonessential data' when exporting.")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
junit.jupiter.testinstance.lifecycle.default = per_class
|
|
@ -0,0 +1,14 @@
|
|||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
set(vegasFiles
|
||||
"Debug Rhubarb.cs"
|
||||
"Debug Rhubarb.cs.config"
|
||||
"Import Rhubarb.cs"
|
||||
"Import Rhubarb.cs.config"
|
||||
"README.adoc"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${vegasFiles}
|
||||
DESTINATION "extras/MagixVegas"
|
||||
)
|
|
@ -13,8 +13,8 @@ using System.Windows.Forms;
|
|||
using System.Windows.Forms.Design;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using Sony.Vegas;
|
||||
using Region = Sony.Vegas.Region;
|
||||
using ScriptPortal.Vegas; // For older versions, this should say Sony.Vegas
|
||||
using Region = ScriptPortal.Vegas.Region; // For older versions, this should say Sony.Vegas.Region
|
||||
|
||||
public class EntryPoint {
|
||||
public void FromVegas(Vegas vegas) {
|
||||
|
@ -49,7 +49,15 @@ public class EntryPoint {
|
|||
List<TimedEvent> filteredEvents = FilterEvents(timedEvents[eventType], visualization.Regex);
|
||||
foreach (TimedEvent timedEvent in filteredEvents) {
|
||||
Timecode start = Timecode.FromSeconds(timedEvent.Start);
|
||||
Timecode length = Timecode.FromSeconds(timedEvent.End) - start;
|
||||
Timecode end = Timecode.FromSeconds(timedEvent.End);
|
||||
Timecode length = end - start;
|
||||
if (config.LoopRegionOnly) {
|
||||
Timecode loopRegionStart = vegas.Transport.LoopRegionStart;
|
||||
Timecode loopRegionEnd = loopRegionStart + vegas.Transport.LoopRegionLength;
|
||||
if (start < loopRegionStart || start > loopRegionEnd || end < loopRegionStart || end > loopRegionEnd) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
switch (visualization.VisualizationType) {
|
||||
case VisualizationType.Marker:
|
||||
project.Markers.Add(new Marker(start, timedEvent.Value));
|
||||
|
@ -149,6 +157,7 @@ public class Config {
|
|||
private string logFile;
|
||||
private bool clearMarkers;
|
||||
private bool clearRegions;
|
||||
private bool loopRegionOnly;
|
||||
private List<Visualization> visualizations = new List<Visualization>();
|
||||
|
||||
[DisplayName("Log File")]
|
||||
|
@ -173,6 +182,13 @@ public class Config {
|
|||
set { clearRegions = value; }
|
||||
}
|
||||
|
||||
[DisplayName("Loop region only")]
|
||||
[Description("Adds regions or markers to the loop region only.")]
|
||||
public bool LoopRegionOnly {
|
||||
get { return loopRegionOnly; }
|
||||
set { loopRegionOnly = value; }
|
||||
}
|
||||
|
||||
[DisplayName("Visualization rules")]
|
||||
[Description("Specify how to visualize various log events.")]
|
||||
[Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
|
||||
|
@ -258,8 +274,10 @@ public class Visualization {
|
|||
public enum EventType {
|
||||
Utterance,
|
||||
Word,
|
||||
RawPhone,
|
||||
Phone,
|
||||
Shape
|
||||
Shape,
|
||||
Segment
|
||||
}
|
||||
|
||||
public enum VisualizationType {
|
|
@ -11,7 +11,7 @@ using System.Windows.Forms;
|
|||
using System.Windows.Forms.Design;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using Sony.Vegas;
|
||||
using ScriptPortal.Vegas; // For older versions, this should say Sony.Vegas
|
||||
|
||||
public class EntryPoint {
|
||||
public void FromVegas(Vegas vegas) {
|
|
@ -0,0 +1,23 @@
|
|||
= Scripts for Magix Vegas
|
||||
|
||||
If you own a copy of http://www.vegascreativesoftware.com/[Magix Vegas] (previously Sony Vegas), you can use this script to visualize Rhubarb Lip Sync’s output on the timeline. This can be useful for creating lip-synced videos or for debugging.
|
||||
|
||||
== Installation
|
||||
|
||||
Copy (or symlink) the files in this directory to `<Vegas installation directory>\Script Menu`. When you restart Vegas, you’ll find two new menu items:
|
||||
|
||||
* _Tools > Scripting > Import Rhubarb:_ This will create a new Vegas project and add two tracks: a video track with a visualization of Rhubarb Lip Sync’s output and an audio track with the original recording.
|
||||
* _Tools > Scripting > Debug Rhubarb:_ This will create markers or regions on the timeline visualizing Rhubarb Lip Sync’s internal data from a log file. You can obtain a log file by redirecting `+stdout+`. I’ve written this script mainly as a debugging aid for myself; feel free to contact me if you’re interested and need a more thorough explanation.
|
||||
|
||||
== How to perform lip sync
|
||||
|
||||
You cannot perform lip sync directly from the Vegas scripts. Instead, run Rhubarb Lip Sync from the command line, specifying the XML output format.
|
||||
|
||||
== How to create an animation
|
||||
|
||||
Select _Tools > Scripting > Import Rhubarb_. Fill in at least the following fields:
|
||||
|
||||
* One image file: You need a set of image files, one for each mouth shapes. All image files should have the same size and should end with "`-<mouth shape>`", for instance _alison-a.png_, _alison-b.png_, and so on. Click the "`...`" button at the right of this field and select one of these image files. The script will automatically find the other image files.
|
||||
* XML file: Click the "`...`" button at the right of this field and select the XML file created by Rhubarb Lip Sync.
|
||||
|
||||
Click _OK_ to create the animation.
|
|
@ -1,8 +0,0 @@
|
|||
# Scripts for Sony Vegas
|
||||
|
||||
If you own a copy of [Sony Vegas](http://www.sonycreativesoftware.com/vegassoftware), you can use this script to visualize Rhubarb Lip Sync's output on the timeline. This can be useful for creating lip-synced videos or for debugging.
|
||||
|
||||
Copy (or symlink) the files in this directory to `<Vegas installation directory>\Script Menu`. When you restart Vegas, you'll find two new menu items:
|
||||
|
||||
* *Tools > Scripting > Import Rhubarb:* This will create a new Vegas project and add two tracks: a video track with a visualization of Rhubarb Lip-Sync's output and an audio track with the original recording.
|
||||
* *Tools > Scripting > Debug Rhubarb:* This will create markers or regions on the timeline visualizing Rhubarb Lip-Sync's internal data from a log file. You can obtain a log file by redirecting `stdout`. I've written this script mainly as a debugging aid for myself; feel free to contact me if you're interested and need a more thorough explanation.
|
After ![]() (image error) Size: 48 KiB |
BIN
img/ken-A.png
Before ![]() (image error) Size: 1023 B |
BIN
img/ken-B.png
Before ![]() (image error) Size: 1.0 KiB |
BIN
img/ken-C.png
Before ![]() (image error) Size: 1.1 KiB |
BIN
img/ken-D.png
Before ![]() (image error) Size: 1.1 KiB |
BIN
img/ken-E.png
Before ![]() (image error) Size: 1.0 KiB |
BIN
img/ken-F.png
Before ![]() (image error) Size: 1.0 KiB |
BIN
img/ken-G.png
Before ![]() (image error) Size: 981 B |
BIN
img/ken-H.png
Before ![]() (image error) Size: 1.1 KiB |
After ![]() (image error) Size: 6.5 KiB |
After ![]() (image error) Size: 10 KiB |
After ![]() (image error) Size: 12 KiB |
After ![]() (image error) Size: 14 KiB |
After ![]() (image error) Size: 9.3 KiB |
After ![]() (image error) Size: 7.0 KiB |
After ![]() (image error) Size: 5.9 KiB |
After ![]() (image error) Size: 13 KiB |
After ![]() (image error) Size: 7.2 KiB |
After ![]() (image error) Size: 4.1 KiB |
After ![]() (image error) Size: 106 KiB |
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="70px" height="70px" viewBox="0 0 70 70" style="enable-background:new 0 0 70 70;" xml:space="preserve">
|
||||
<g>
|
||||
<g>
|
||||
<g>
|
||||
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="8.0628" y1="16.1412" x2="29.2598" y2="69.7572">
|
||||
<stop offset="0.2204" style="stop-color:#C40B55"/>
|
||||
<stop offset="0.6828" style="stop-color:#E343E6"/>
|
||||
<stop offset="0.9247" style="stop-color:#F59252"/>
|
||||
</linearGradient>
|
||||
<polygon style="fill:url(#SVGID_1_);" points="20.2,15.2 34,36.7 11.6,70 0,23.1 "/>
|
||||
|
||||
<linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="875.7187" y1="73.2924" x2="927.5556" y2="18.1521" gradientTransform="matrix(-1 0 0 1 928 -2.064169e-004)">
|
||||
<stop offset="0.1129" style="stop-color:#FFBD00"/>
|
||||
<stop offset="0.586" style="stop-color:#E343E6"/>
|
||||
<stop offset="0.8172" style="stop-color:#EC841B"/>
|
||||
<stop offset="0.9355" style="stop-color:#FFBD00"/>
|
||||
</linearGradient>
|
||||
<polygon style="fill:url(#SVGID_2_);" points="18.9,15.7 21,0 51.2,33.6 42.4,42.3 49.2,70 11.6,70 "/>
|
||||
</g>
|
||||
<linearGradient id="SVGID_3_" gradientUnits="userSpaceOnUse" x1="25.5002" y1="-1.9302" x2="69.9604" y2="51.1679">
|
||||
<stop offset="0.129" style="stop-color:#FFBD00"/>
|
||||
<stop offset="0.6398" style="stop-color:#E343E6"/>
|
||||
<stop offset="0.9086" style="stop-color:#C40B55"/>
|
||||
</linearGradient>
|
||||
<polygon style="fill:url(#SVGID_3_);" points="35.3,47.1 70,47.1 58.4,0 21,0 "/>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<rect x="13.4" y="13.4" style="fill:#000000;" width="43.2" height="43.2"/>
|
||||
<path style="fill:#FFFFFF;" d="M17.4,19h8.2c2.3,0,4,0.6,5.2,1.8c1,1,1.5,2.4,1.5,4.1V25c0,1.5-0.4,2.6-1.1,3.5
|
||||
c-0.7,0.9-1.6,1.6-2.8,2l4.4,6.4h-4.6l-3.7-5.5h-3.3l0,5.5h-3.9V19z M25.4,27.7c1,0,1.7-0.2,2.2-0.7c0.5-0.5,0.8-1.1,0.8-1.8
|
||||
v-0.1c0-0.9-0.3-1.5-0.8-1.9c-0.5-0.4-1.3-0.6-2.3-0.6h-3.9v5.1H25.4z"/>
|
||||
<rect x="17.4" y="48.5" style="fill:#FFFFFF;" width="16.2" height="2.7"/>
|
||||
</g>
|
||||
<g>
|
||||
<path style="fill:#FFFFFF;" d="M43.7,24.4h-4v-3.6h4v-4h3.7v4h4v3.6h-4v4h-3.7V24.4z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path style="fill:#FFFFFF;" d="M37.1,34.6h-4V31h4v-4h3.7v4h4v3.6h-4v4h-3.7V34.6z"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After (image error) Size: 2.4 KiB |
After ![]() (image error) Size: 52 KiB |
After ![]() (image error) Size: 31 KiB |
|
@ -1,46 +0,0 @@
|
|||
# Build matrix / environment variable are explained on:
|
||||
# http://about.travis-ci.org/docs/user/build-configuration/
|
||||
# This file can be validated on:
|
||||
# http://lint.travis-ci.org/
|
||||
|
||||
install:
|
||||
# /usr/bin/gcc is 4.6 always, but gcc-X.Y is available.
|
||||
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.9" CC="gcc-4.9"; fi
|
||||
# /usr/bin/clang is 3.4, lets override with modern one.
|
||||
- if [ "$CXX" = "clang++" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then export CXX="clang++-3.7" CC="clang-3.7"; fi
|
||||
- echo ${PATH}
|
||||
- echo ${CXX}
|
||||
- ${CXX} --version
|
||||
- ${CXX} -v
|
||||
addons:
|
||||
apt:
|
||||
# List of whitelisted in travis packages for ubuntu-precise can be found here:
|
||||
# https://github.com/travis-ci/apt-package-whitelist/blob/master/ubuntu-precise
|
||||
# List of whitelisted in travis apt-sources:
|
||||
# https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
packages:
|
||||
- gcc-4.9
|
||||
- g++-4.9
|
||||
- clang-3.7
|
||||
- valgrind
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
script: ./travis.sh
|
||||
env:
|
||||
matrix:
|
||||
- GTEST_TARGET=googletest SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE
|
||||
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE
|
||||
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug CXX_FLAGS=-std=c++11 VERBOSE_MAKE=true VERBOSE
|
||||
# - GTEST_TARGET=googletest SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false
|
||||
# - GTEST_TARGET=googlemock SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false
|
||||
notifications:
|
||||
email: false
|
||||
sudo: false
|
|
@ -1,16 +0,0 @@
|
|||
cmake_minimum_required(VERSION 2.6.2)
|
||||
|
||||
project( googletest-distribution )
|
||||
|
||||
enable_testing()
|
||||
|
||||
option(BUILD_GTEST "Builds the googletest subproject" OFF)
|
||||
|
||||
#Note that googlemock target already builds googletest
|
||||
option(BUILD_GMOCK "Builds the googlemock subproject" ON)
|
||||
|
||||
if(BUILD_GMOCK)
|
||||
add_subdirectory( googlemock )
|
||||
elseif(BUILD_GTEST)
|
||||
add_subdirectory( googletest )
|
||||
endif()
|
|
@ -1,138 +0,0 @@
|
|||
|
||||
# Google Test #
|
||||
|
||||
[](https://travis-ci.org/google/googletest)
|
||||
|
||||
Welcome to **Google Test**, Google's C++ test framework!
|
||||
|
||||
This repository is a merger of the formerly separate GoogleTest and
|
||||
GoogleMock projects. These were so closely related that it makes sense to
|
||||
maintain and release them together.
|
||||
|
||||
Please see the project page above for more information as well as the
|
||||
mailing list for questions, discussions, and development. There is
|
||||
also an IRC channel on OFTC (irc.oftc.net) #gtest available. Please
|
||||
join us!
|
||||
|
||||
**Google Mock** is an extension to Google Test for writing and using C++ mock
|
||||
classes. See the separate [Google Mock documentation](googlemock/README.md).
|
||||
|
||||
More detailed documentation for googletest (including build instructions) are
|
||||
in its interior [googletest/README.md](googletest/README.md) file.
|
||||
|
||||
## Features ##
|
||||
|
||||
* An [XUnit](https://en.wikipedia.org/wiki/XUnit) test framework.
|
||||
* Test discovery.
|
||||
* A rich set of assertions.
|
||||
* User-defined assertions.
|
||||
* Death tests.
|
||||
* Fatal and non-fatal failures.
|
||||
* Value-parameterized tests.
|
||||
* Type-parameterized tests.
|
||||
* Various options for running the tests.
|
||||
* XML test report generation.
|
||||
|
||||
## Platforms ##
|
||||
|
||||
Google test has been used on a variety of platforms:
|
||||
|
||||
* Linux
|
||||
* Mac OS X
|
||||
* Windows
|
||||
* Cygwin
|
||||
* MinGW
|
||||
* Windows Mobile
|
||||
* Symbian
|
||||
|
||||
## Who Is Using Google Test? ##
|
||||
|
||||
In addition to many internal projects at Google, Google Test is also used by
|
||||
the following notable projects:
|
||||
|
||||
* The [Chromium projects](http://www.chromium.org/) (behind the Chrome
|
||||
browser and Chrome OS).
|
||||
* The [LLVM](http://llvm.org/) compiler.
|
||||
* [Protocol Buffers](https://github.com/google/protobuf), Google's data
|
||||
interchange format.
|
||||
* The [OpenCV](http://opencv.org/) computer vision library.
|
||||
|
||||
## Related Open Source Projects ##
|
||||
|
||||
[Google Test UI](https://github.com/ospector/gtest-gbar) is test runner that runs
|
||||
your test binary, allows you to track its progress via a progress bar, and
|
||||
displays a list of test failures. Clicking on one shows failure text. Google
|
||||
Test UI is written in C#.
|
||||
|
||||
[GTest TAP Listener](https://github.com/kinow/gtest-tap-listener) is an event
|
||||
listener for Google Test that implements the
|
||||
[TAP protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol) for test
|
||||
result output. If your test runner understands TAP, you may find it useful.
|
||||
|
||||
## Requirements ##
|
||||
|
||||
Google Test is designed to have fairly minimal requirements to build
|
||||
and use with your projects, but there are some. Currently, we support
|
||||
Linux, Windows, Mac OS X, and Cygwin. We will also make our best
|
||||
effort to support other platforms (e.g. Solaris, AIX, and z/OS).
|
||||
However, since core members of the Google Test project have no access
|
||||
to these platforms, Google Test may have outstanding issues there. If
|
||||
you notice any problems on your platform, please notify
|
||||
<googletestframework@googlegroups.com>. Patches for fixing them are
|
||||
even more welcome!
|
||||
|
||||
### Linux Requirements ###
|
||||
|
||||
These are the base requirements to build and use Google Test from a source
|
||||
package (as described below):
|
||||
|
||||
* GNU-compatible Make or gmake
|
||||
* POSIX-standard shell
|
||||
* POSIX(-2) Regular Expressions (regex.h)
|
||||
* A C++98-standard-compliant compiler
|
||||
|
||||
### Windows Requirements ###
|
||||
|
||||
* Microsoft Visual C++ v7.1 or newer
|
||||
|
||||
### Cygwin Requirements ###
|
||||
|
||||
* Cygwin v1.5.25-14 or newer
|
||||
|
||||
### Mac OS X Requirements ###
|
||||
|
||||
* Mac OS X v10.4 Tiger or newer
|
||||
* XCode Developer Tools
|
||||
|
||||
### Requirements for Contributors ###
|
||||
|
||||
We welcome patches. If you plan to contribute a patch, you need to
|
||||
build Google Test and its own tests from a git checkout (described
|
||||
below), which has further requirements:
|
||||
|
||||
* [Python](https://www.python.org/) v2.3 or newer (for running some of
|
||||
the tests and re-generating certain source files from templates)
|
||||
* [CMake](https://cmake.org/) v2.6.4 or newer
|
||||
|
||||
## Regenerating Source Files ##
|
||||
|
||||
Some of Google Test's source files are generated from templates (not
|
||||
in the C++ sense) using a script.
|
||||
For example, the
|
||||
file include/gtest/internal/gtest-type-util.h.pump is used to generate
|
||||
gtest-type-util.h in the same directory.
|
||||
|
||||
You don't need to worry about regenerating the source files
|
||||
unless you need to modify them. You would then modify the
|
||||
corresponding `.pump` files and run the '[pump.py](googletest/scripts/pump.py)'
|
||||
generator script. See the [Pump Manual](googletest/docs/PumpManual.md).
|
||||
|
||||
### Contributing Code ###
|
||||
|
||||
We welcome patches. Please read the
|
||||
[Developer's Guide](googletest/docs/DevGuide.md)
|
||||
for how you can contribute. In particular, make sure you have signed
|
||||
the Contributor License Agreement, or we won't be able to accept the
|
||||
patch.
|
||||
|
||||
Happy testing!
|
|
@ -1,126 +0,0 @@
|
|||
Changes for 1.7.0:
|
||||
|
||||
* All new improvements in Google Test 1.7.0.
|
||||
* New feature: matchers DoubleNear(), FloatNear(),
|
||||
NanSensitiveDoubleNear(), NanSensitiveFloatNear(),
|
||||
UnorderedElementsAre(), UnorderedElementsAreArray(), WhenSorted(),
|
||||
WhenSortedBy(), IsEmpty(), and SizeIs().
|
||||
* Improvement: Google Mock can now be built as a DLL.
|
||||
* Improvement: when compiled by a C++11 compiler, matchers AllOf()
|
||||
and AnyOf() can accept an arbitrary number of matchers.
|
||||
* Improvement: when compiled by a C++11 compiler, matchers
|
||||
ElementsAreArray() can accept an initializer list.
|
||||
* Improvement: when exceptions are enabled, a mock method with no
|
||||
default action now throws instead crashing the test.
|
||||
* Improvement: added class testing::StringMatchResultListener to aid
|
||||
definition of composite matchers.
|
||||
* Improvement: function return types used in MOCK_METHOD*() macros can
|
||||
now contain unprotected commas.
|
||||
* Improvement (potentially breaking): EXPECT_THAT() and ASSERT_THAT()
|
||||
are now more strict in ensuring that the value type and the matcher
|
||||
type are compatible, catching potential bugs in tests.
|
||||
* Improvement: Pointee() now works on an optional<T>.
|
||||
* Improvement: the ElementsAreArray() matcher can now take a vector or
|
||||
iterator range as input, and makes a copy of its input elements
|
||||
before the conversion to a Matcher.
|
||||
* Improvement: the Google Mock Generator can now generate mocks for
|
||||
some class templates.
|
||||
* Bug fix: mock object destruction triggerred by another mock object's
|
||||
destruction no longer hangs.
|
||||
* Improvement: Google Mock Doctor works better with newer Clang and
|
||||
GCC now.
|
||||
* Compatibility fixes.
|
||||
* Bug/warning fixes.
|
||||
|
||||
Changes for 1.6.0:
|
||||
|
||||
* Compilation is much faster and uses much less memory, especially
|
||||
when the constructor and destructor of a mock class are moved out of
|
||||
the class body.
|
||||
* New matchers: Pointwise(), Each().
|
||||
* New actions: ReturnPointee() and ReturnRefOfCopy().
|
||||
* CMake support.
|
||||
* Project files for Visual Studio 2010.
|
||||
* AllOf() and AnyOf() can handle up-to 10 arguments now.
|
||||
* Google Mock doctor understands Clang error messages now.
|
||||
* SetArgPointee<> now accepts string literals.
|
||||
* gmock_gen.py handles storage specifier macros and template return
|
||||
types now.
|
||||
* Compatibility fixes.
|
||||
* Bug fixes and implementation clean-ups.
|
||||
* Potentially incompatible changes: disables the harmful 'make install'
|
||||
command in autotools.
|
||||
|
||||
Potentially breaking changes:
|
||||
|
||||
* The description string for MATCHER*() changes from Python-style
|
||||
interpolation to an ordinary C++ string expression.
|
||||
* SetArgumentPointee is deprecated in favor of SetArgPointee.
|
||||
* Some non-essential project files for Visual Studio 2005 are removed.
|
||||
|
||||
Changes for 1.5.0:
|
||||
|
||||
* New feature: Google Mock can be safely used in multi-threaded tests
|
||||
on platforms having pthreads.
|
||||
* New feature: function for printing a value of arbitrary type.
|
||||
* New feature: function ExplainMatchResult() for easy definition of
|
||||
composite matchers.
|
||||
* The new matcher API lets user-defined matchers generate custom
|
||||
explanations more directly and efficiently.
|
||||
* Better failure messages all around.
|
||||
* NotNull() and IsNull() now work with smart pointers.
|
||||
* Field() and Property() now work when the matcher argument is a pointer
|
||||
passed by reference.
|
||||
* Regular expression matchers on all platforms.
|
||||
* Added GCC 4.0 support for Google Mock Doctor.
|
||||
* Added gmock_all_test.cc for compiling most Google Mock tests
|
||||
in a single file.
|
||||
* Significantly cleaned up compiler warnings.
|
||||
* Bug fixes, better test coverage, and implementation clean-ups.
|
||||
|
||||
Potentially breaking changes:
|
||||
|
||||
* Custom matchers defined using MatcherInterface or MakePolymorphicMatcher()
|
||||
need to be updated after upgrading to Google Mock 1.5.0; matchers defined
|
||||
using MATCHER or MATCHER_P* aren't affected.
|
||||
* Dropped support for 'make install'.
|
||||
|
||||
Changes for 1.4.0 (we skipped 1.2.* and 1.3.* to match the version of
|
||||
Google Test):
|
||||
|
||||
* Works in more environments: Symbian and minGW, Visual C++ 7.1.
|
||||
* Lighter weight: comes with our own implementation of TR1 tuple (no
|
||||
more dependency on Boost!).
|
||||
* New feature: --gmock_catch_leaked_mocks for detecting leaked mocks.
|
||||
* New feature: ACTION_TEMPLATE for defining templatized actions.
|
||||
* New feature: the .After() clause for specifying expectation order.
|
||||
* New feature: the .With() clause for for specifying inter-argument
|
||||
constraints.
|
||||
* New feature: actions ReturnArg<k>(), ReturnNew<T>(...), and
|
||||
DeleteArg<k>().
|
||||
* New feature: matchers Key(), Pair(), Args<...>(), AllArgs(), IsNull(),
|
||||
and Contains().
|
||||
* New feature: utility class MockFunction<F>, useful for checkpoints, etc.
|
||||
* New feature: functions Value(x, m) and SafeMatcherCast<T>(m).
|
||||
* New feature: copying a mock object is rejected at compile time.
|
||||
* New feature: a script for fusing all Google Mock and Google Test
|
||||
source files for easy deployment.
|
||||
* Improved the Google Mock doctor to diagnose more diseases.
|
||||
* Improved the Google Mock generator script.
|
||||
* Compatibility fixes for Mac OS X and gcc.
|
||||
* Bug fixes and implementation clean-ups.
|
||||
|
||||
Changes for 1.1.0:
|
||||
|
||||
* New feature: ability to use Google Mock with any testing framework.
|
||||
* New feature: macros for easily defining new matchers
|
||||
* New feature: macros for easily defining new actions.
|
||||
* New feature: more container matchers.
|
||||
* New feature: actions for accessing function arguments and throwing
|
||||
exceptions.
|
||||
* Improved the Google Mock doctor script for diagnosing compiler errors.
|
||||
* Bug fixes and implementation clean-ups.
|
||||
|
||||
Changes for 1.0.0:
|
||||
|
||||
* Initial Open Source release of Google Mock
|
|
@ -1,194 +0,0 @@
|
|||
########################################################################
|
||||
# CMake build script for Google Mock.
|
||||
#
|
||||
# To run the tests for Google Mock itself on Linux, use 'make test' or
|
||||
# ctest. You can select which tests to run using 'ctest -R regex'.
|
||||
# For more options, run 'ctest --help'.
|
||||
|
||||
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
|
||||
# make it prominent in the GUI.
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
|
||||
|
||||
option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
|
||||
|
||||
# A directory to find Google Test sources.
|
||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
|
||||
set(gtest_dir gtest)
|
||||
else()
|
||||
set(gtest_dir ../googletest)
|
||||
endif()
|
||||
|
||||
# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
|
||||
include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL)
|
||||
|
||||
if (COMMAND pre_project_set_up_hermetic_build)
|
||||
# Google Test also calls hermetic setup functions from add_subdirectory,
|
||||
# although its changes will not affect things at the current scope.
|
||||
pre_project_set_up_hermetic_build()
|
||||
endif()
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Project-wide settings
|
||||
|
||||
# Name of the project.
|
||||
#
|
||||
# CMake files in this project can refer to the root source directory
|
||||
# as ${gmock_SOURCE_DIR} and to the root binary directory as
|
||||
# ${gmock_BINARY_DIR}.
|
||||
# Language "C" is required for find_package(Threads).
|
||||
project(gmock CXX C)
|
||||
cmake_minimum_required(VERSION 2.6.2)
|
||||
|
||||
if (COMMAND set_up_hermetic_build)
|
||||
set_up_hermetic_build()
|
||||
endif()
|
||||
|
||||
# Instructs CMake to process Google Test's CMakeLists.txt and add its
|
||||
# targets to the current scope. We are placing Google Test's binary
|
||||
# directory in a subdirectory of our own as VC compilation may break
|
||||
# if they are the same (the default).
|
||||
add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest")
|
||||
|
||||
# Although Google Test's CMakeLists.txt calls this function, the
|
||||
# changes there don't affect the current scope. Therefore we have to
|
||||
# call it again here.
|
||||
config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake
|
||||
|
||||
# Adds Google Mock's and Google Test's header directories to the search path.
|
||||
include_directories("${gmock_SOURCE_DIR}/include"
|
||||
"${gmock_SOURCE_DIR}"
|
||||
"${gtest_SOURCE_DIR}/include"
|
||||
# This directory is needed to build directly from Google
|
||||
# Test sources.
|
||||
"${gtest_SOURCE_DIR}")
|
||||
|
||||
# Summary of tuple support for Microsoft Visual Studio:
|
||||
# Compiler version(MS) version(cmake) Support
|
||||
# ---------- ----------- -------------- -----------------------------
|
||||
# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
|
||||
# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
|
||||
# VS 2013 12 1800 std::tr1::tuple
|
||||
if (MSVC AND MSVC_VERSION EQUAL 1700)
|
||||
add_definitions(/D _VARIADIC_MAX=10)
|
||||
endif()
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Defines the gmock & gmock_main libraries. User tests should link
|
||||
# with one of them.
|
||||
|
||||
# Google Mock libraries. We build them using more strict warnings than what
|
||||
# are used for other targets, to ensure that Google Mock can be compiled by
|
||||
# a user aggressive about warnings.
|
||||
cxx_library(gmock
|
||||
"${cxx_strict}"
|
||||
"${gtest_dir}/src/gtest-all.cc"
|
||||
src/gmock-all.cc)
|
||||
|
||||
cxx_library(gmock_main
|
||||
"${cxx_strict}"
|
||||
"${gtest_dir}/src/gtest-all.cc"
|
||||
src/gmock-all.cc
|
||||
src/gmock_main.cc)
|
||||
|
||||
# If the CMake version supports it, attach header directory information
|
||||
# to the targets for when we are part of a parent build (ie being pulled
|
||||
# in via add_subdirectory() rather than being a standalone build).
|
||||
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
|
||||
target_include_directories(gmock INTERFACE "${gmock_SOURCE_DIR}/include")
|
||||
target_include_directories(gmock_main INTERFACE "${gmock_SOURCE_DIR}/include")
|
||||
endif()
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Google Mock's own tests.
|
||||
#
|
||||
# You can skip this section if you aren't interested in testing
|
||||
# Google Mock itself.
|
||||
#
|
||||
# The tests are not built by default. To build them, set the
|
||||
# gmock_build_tests option to ON. You can do it by running ccmake
|
||||
# or specifying the -Dgmock_build_tests=ON flag when running cmake.
|
||||
|
||||
if (gmock_build_tests)
|
||||
# This must be set in the root directory for the tests to be run by
|
||||
# 'make test' or ctest.
|
||||
enable_testing()
|
||||
|
||||
############################################################
|
||||
# C++ tests built with standard compiler flags.
|
||||
|
||||
cxx_test(gmock-actions_test gmock_main)
|
||||
cxx_test(gmock-cardinalities_test gmock_main)
|
||||
cxx_test(gmock_ex_test gmock_main)
|
||||
cxx_test(gmock-generated-actions_test gmock_main)
|
||||
cxx_test(gmock-generated-function-mockers_test gmock_main)
|
||||
cxx_test(gmock-generated-internal-utils_test gmock_main)
|
||||
cxx_test(gmock-generated-matchers_test gmock_main)
|
||||
cxx_test(gmock-internal-utils_test gmock_main)
|
||||
cxx_test(gmock-matchers_test gmock_main)
|
||||
cxx_test(gmock-more-actions_test gmock_main)
|
||||
cxx_test(gmock-nice-strict_test gmock_main)
|
||||
cxx_test(gmock-port_test gmock_main)
|
||||
cxx_test(gmock-spec-builders_test gmock_main)
|
||||
cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
|
||||
cxx_test(gmock_test gmock_main)
|
||||
|
||||
if (CMAKE_USE_PTHREADS_INIT)
|
||||
cxx_test(gmock_stress_test gmock)
|
||||
endif()
|
||||
|
||||
# gmock_all_test is commented to save time building and running tests.
|
||||
# Uncomment if necessary.
|
||||
# cxx_test(gmock_all_test gmock_main)
|
||||
|
||||
############################################################
|
||||
# C++ tests built with non-standard compiler flags.
|
||||
|
||||
cxx_library(gmock_main_no_exception "${cxx_no_exception}"
|
||||
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
|
||||
|
||||
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
|
||||
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
|
||||
|
||||
if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010.
|
||||
# Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
|
||||
# conflict with our own definitions. Therefore using our own tuple does not
|
||||
# work on those compilers.
|
||||
cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
|
||||
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
|
||||
|
||||
cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
|
||||
gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
|
||||
endif()
|
||||
|
||||
cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
|
||||
gmock_main_no_exception test/gmock-more-actions_test.cc)
|
||||
|
||||
cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}"
|
||||
gmock_main_no_rtti test/gmock-spec-builders_test.cc)
|
||||
|
||||
cxx_shared_library(shared_gmock_main "${cxx_default}"
|
||||
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
|
||||
|
||||
# Tests that a binary can be built with Google Mock as a shared library. On
|
||||
# some system configurations, it may not possible to run the binary without
|
||||
# knowing more details about the system configurations. We do not try to run
|
||||
# this binary. To get a more robust shared library coverage, configure with
|
||||
# -DBUILD_SHARED_LIBS=ON.
|
||||
cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}"
|
||||
shared_gmock_main test/gmock-spec-builders_test.cc)
|
||||
set_target_properties(shared_gmock_test_
|
||||
PROPERTIES
|
||||
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
|
||||
|
||||
############################################################
|
||||
# Python tests.
|
||||
|
||||
cxx_executable(gmock_leak_test_ test gmock_main)
|
||||
py_test(gmock_leak_test)
|
||||
|
||||
cxx_executable(gmock_output_test_ test gmock)
|
||||
py_test(gmock_output_test)
|
||||
endif()
|
|
@ -1,40 +0,0 @@
|
|||
# This file contains a list of people who've made non-trivial
|
||||
# contribution to the Google C++ Mocking Framework project. People
|
||||
# who commit code to the project are encouraged to add their names
|
||||
# here. Please keep the list sorted by first names.
|
||||
|
||||
Benoit Sigoure <tsuna@google.com>
|
||||
Bogdan Piloca <boo@google.com>
|
||||
Chandler Carruth <chandlerc@google.com>
|
||||
Dave MacLachlan <dmaclach@gmail.com>
|
||||
David Anderson <danderson@google.com>
|
||||
Dean Sturtevant
|
||||
Gene Volovich <gv@cite.com>
|
||||
Hal Burch <gmock@hburch.com>
|
||||
Jeffrey Yasskin <jyasskin@google.com>
|
||||
Jim Keller <jimkeller@google.com>
|
||||
Joe Walnes <joe@truemesh.com>
|
||||
Jon Wray <jwray@google.com>
|
||||
Keir Mierle <mierle@gmail.com>
|
||||
Keith Ray <keith.ray@gmail.com>
|
||||
Kostya Serebryany <kcc@google.com>
|
||||
Lev Makhlis
|
||||
Manuel Klimek <klimek@google.com>
|
||||
Mario Tanev <radix@google.com>
|
||||
Mark Paskin
|
||||
Markus Heule <markus.heule@gmail.com>
|
||||
Matthew Simmons <simmonmt@acm.org>
|
||||
Mike Bland <mbland@google.com>
|
||||
Neal Norwitz <nnorwitz@gmail.com>
|
||||
Nermin Ozkiranartli <nermin@google.com>
|
||||
Owen Carlsen <ocarlsen@google.com>
|
||||
Paneendra Ba <paneendra@google.com>
|
||||
Paul Menage <menage@google.com>
|
||||
Piotr Kaminski <piotrk@google.com>
|
||||
Russ Rufer <russ@pentad.com>
|
||||
Sverre Sundsdal <sundsdal@gmail.com>
|
||||
Takeshi Yoshino <tyoshino@google.com>
|
||||
Vadim Berman <vadimb@google.com>
|
||||
Vlad Losev <vladl@google.com>
|
||||
Wolfgang Klier <wklier@google.com>
|
||||
Zhanyong Wan <wan@google.com>
|
|
@ -1,28 +0,0 @@
|
|||
Copyright 2008, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,224 +0,0 @@
|
|||
# Automake file
|
||||
|
||||
# Nonstandard package files for distribution.
|
||||
EXTRA_DIST = LICENSE
|
||||
|
||||
# We may need to build our internally packaged gtest. If so, it will be
|
||||
# included in the 'subdirs' variable.
|
||||
SUBDIRS = $(subdirs)
|
||||
|
||||
# This is generated by the configure script, so clean it for distribution.
|
||||
DISTCLEANFILES = scripts/gmock-config
|
||||
|
||||
# We define the global AM_CPPFLAGS as everything we compile includes from these
|
||||
# directories.
|
||||
AM_CPPFLAGS = $(GTEST_CPPFLAGS) -I$(srcdir)/include
|
||||
|
||||
# Modifies compiler and linker flags for pthreads compatibility.
|
||||
if HAVE_PTHREADS
|
||||
AM_CXXFLAGS = @PTHREAD_CFLAGS@ -DGTEST_HAS_PTHREAD=1
|
||||
AM_LIBS = @PTHREAD_LIBS@
|
||||
endif
|
||||
|
||||
# Build rules for libraries.
|
||||
lib_LTLIBRARIES = lib/libgmock.la lib/libgmock_main.la
|
||||
|
||||
lib_libgmock_la_SOURCES = src/gmock-all.cc
|
||||
|
||||
pkginclude_HEADERS = \
|
||||
include/gmock/gmock-actions.h \
|
||||
include/gmock/gmock-cardinalities.h \
|
||||
include/gmock/gmock-generated-actions.h \
|
||||
include/gmock/gmock-generated-function-mockers.h \
|
||||
include/gmock/gmock-generated-matchers.h \
|
||||
include/gmock/gmock-generated-nice-strict.h \
|
||||
include/gmock/gmock-matchers.h \
|
||||
include/gmock/gmock-more-actions.h \
|
||||
include/gmock/gmock-more-matchers.h \
|
||||
include/gmock/gmock-spec-builders.h \
|
||||
include/gmock/gmock.h
|
||||
|
||||
pkginclude_internaldir = $(pkgincludedir)/internal
|
||||
pkginclude_internal_HEADERS = \
|
||||
include/gmock/internal/gmock-generated-internal-utils.h \
|
||||
include/gmock/internal/gmock-internal-utils.h \
|
||||
include/gmock/internal/gmock-port.h \
|
||||
include/gmock/internal/custom/gmock-generated-actions.h \
|
||||
include/gmock/internal/custom/gmock-matchers.h \
|
||||
include/gmock/internal/custom/gmock-port.h
|
||||
|
||||
lib_libgmock_main_la_SOURCES = src/gmock_main.cc
|
||||
lib_libgmock_main_la_LIBADD = lib/libgmock.la
|
||||
|
||||
# Build rules for tests. Automake's naming for some of these variables isn't
|
||||
# terribly obvious, so this is a brief reference:
|
||||
#
|
||||
# TESTS -- Programs run automatically by "make check"
|
||||
# check_PROGRAMS -- Programs built by "make check" but not necessarily run
|
||||
|
||||
TESTS=
|
||||
check_PROGRAMS=
|
||||
AM_LDFLAGS = $(GTEST_LDFLAGS)
|
||||
|
||||
# This exercises all major components of Google Mock. It also
|
||||
# verifies that libgmock works.
|
||||
TESTS += test/gmock-spec-builders_test
|
||||
check_PROGRAMS += test/gmock-spec-builders_test
|
||||
test_gmock_spec_builders_test_SOURCES = test/gmock-spec-builders_test.cc
|
||||
test_gmock_spec_builders_test_LDADD = $(GTEST_LIBS) lib/libgmock.la
|
||||
|
||||
# This tests using Google Mock in multiple translation units. It also
|
||||
# verifies that libgmock_main and libgmock work.
|
||||
TESTS += test/gmock_link_test
|
||||
check_PROGRAMS += test/gmock_link_test
|
||||
test_gmock_link_test_SOURCES = \
|
||||
test/gmock_link2_test.cc \
|
||||
test/gmock_link_test.cc \
|
||||
test/gmock_link_test.h
|
||||
test_gmock_link_test_LDADD = $(GTEST_LIBS) lib/libgmock_main.la lib/libgmock.la
|
||||
|
||||
if HAVE_PYTHON
|
||||
# Tests that fused gmock files compile and work.
|
||||
TESTS += test/gmock_fused_test
|
||||
check_PROGRAMS += test/gmock_fused_test
|
||||
test_gmock_fused_test_SOURCES = \
|
||||
fused-src/gmock-gtest-all.cc \
|
||||
fused-src/gmock/gmock.h \
|
||||
fused-src/gmock_main.cc \
|
||||
fused-src/gtest/gtest.h \
|
||||
test/gmock_test.cc
|
||||
test_gmock_fused_test_CPPFLAGS = -I"$(srcdir)/fused-src"
|
||||
endif
|
||||
|
||||
# Google Mock source files that we don't compile directly.
|
||||
GMOCK_SOURCE_INGLUDES = \
|
||||
src/gmock-cardinalities.cc \
|
||||
src/gmock-internal-utils.cc \
|
||||
src/gmock-matchers.cc \
|
||||
src/gmock-spec-builders.cc \
|
||||
src/gmock.cc
|
||||
|
||||
EXTRA_DIST += $(GMOCK_SOURCE_INGLUDES)
|
||||
|
||||
# C++ tests that we don't compile using autotools.
|
||||
EXTRA_DIST += \
|
||||
test/gmock-actions_test.cc \
|
||||
test/gmock_all_test.cc \
|
||||
test/gmock-cardinalities_test.cc \
|
||||
test/gmock_ex_test.cc \
|
||||
test/gmock-generated-actions_test.cc \
|
||||
test/gmock-generated-function-mockers_test.cc \
|
||||
test/gmock-generated-internal-utils_test.cc \
|
||||
test/gmock-generated-matchers_test.cc \
|
||||
test/gmock-internal-utils_test.cc \
|
||||
test/gmock-matchers_test.cc \
|
||||
test/gmock-more-actions_test.cc \
|
||||
test/gmock-nice-strict_test.cc \
|
||||
test/gmock-port_test.cc \
|
||||
test/gmock_stress_test.cc
|
||||
|
||||
# Python tests, which we don't run using autotools.
|
||||
EXTRA_DIST += \
|
||||
test/gmock_leak_test.py \
|
||||
test/gmock_leak_test_.cc \
|
||||
test/gmock_output_test.py \
|
||||
test/gmock_output_test_.cc \
|
||||
test/gmock_output_test_golden.txt \
|
||||
test/gmock_test_utils.py
|
||||
|
||||
# Nonstandard package files for distribution.
|
||||
EXTRA_DIST += \
|
||||
CHANGES \
|
||||
CONTRIBUTORS \
|
||||
make/Makefile
|
||||
|
||||
# Pump scripts for generating Google Mock headers.
|
||||
# TODO(chandlerc@google.com): automate the generation of *.h from *.h.pump.
|
||||
EXTRA_DIST += \
|
||||
include/gmock/gmock-generated-actions.h.pump \
|
||||
include/gmock/gmock-generated-function-mockers.h.pump \
|
||||
include/gmock/gmock-generated-matchers.h.pump \
|
||||
include/gmock/gmock-generated-nice-strict.h.pump \
|
||||
include/gmock/internal/gmock-generated-internal-utils.h.pump \
|
||||
include/gmock/internal/custom/gmock-generated-actions.h.pump
|
||||
|
||||
# Script for fusing Google Mock and Google Test source files.
|
||||
EXTRA_DIST += scripts/fuse_gmock_files.py
|
||||
|
||||
# The Google Mock Generator tool from the cppclean project.
|
||||
EXTRA_DIST += \
|
||||
scripts/generator/LICENSE \
|
||||
scripts/generator/README \
|
||||
scripts/generator/README.cppclean \
|
||||
scripts/generator/cpp/__init__.py \
|
||||
scripts/generator/cpp/ast.py \
|
||||
scripts/generator/cpp/gmock_class.py \
|
||||
scripts/generator/cpp/keywords.py \
|
||||
scripts/generator/cpp/tokenize.py \
|
||||
scripts/generator/cpp/utils.py \
|
||||
scripts/generator/gmock_gen.py
|
||||
|
||||
# Script for diagnosing compiler errors in programs that use Google
|
||||
# Mock.
|
||||
EXTRA_DIST += scripts/gmock_doctor.py
|
||||
|
||||
# CMake scripts.
|
||||
EXTRA_DIST += \
|
||||
CMakeLists.txt
|
||||
|
||||
# Microsoft Visual Studio 2005 projects.
|
||||
EXTRA_DIST += \
|
||||
msvc/2005/gmock.sln \
|
||||
msvc/2005/gmock.vcproj \
|
||||
msvc/2005/gmock_config.vsprops \
|
||||
msvc/2005/gmock_main.vcproj \
|
||||
msvc/2005/gmock_test.vcproj
|
||||
|
||||
# Microsoft Visual Studio 2010 projects.
|
||||
EXTRA_DIST += \
|
||||
msvc/2010/gmock.sln \
|
||||
msvc/2010/gmock.vcxproj \
|
||||
msvc/2010/gmock_config.props \
|
||||
msvc/2010/gmock_main.vcxproj \
|
||||
msvc/2010/gmock_test.vcxproj
|
||||
|
||||
if HAVE_PYTHON
|
||||
# gmock_test.cc does not really depend on files generated by the
|
||||
# fused-gmock-internal rule. However, gmock_test.o does, and it is
|
||||
# important to include test/gmock_test.cc as part of this rule in order to
|
||||
# prevent compiling gmock_test.o until all dependent files have been
|
||||
# generated.
|
||||
$(test_gmock_fused_test_SOURCES): fused-gmock-internal
|
||||
|
||||
# TODO(vladl@google.com): Find a way to add Google Tests's sources here.
|
||||
fused-gmock-internal: $(pkginclude_HEADERS) $(pkginclude_internal_HEADERS) \
|
||||
$(lib_libgmock_la_SOURCES) $(GMOCK_SOURCE_INGLUDES) \
|
||||
$(lib_libgmock_main_la_SOURCES) \
|
||||
scripts/fuse_gmock_files.py
|
||||
mkdir -p "$(srcdir)/fused-src"
|
||||
chmod -R u+w "$(srcdir)/fused-src"
|
||||
rm -f "$(srcdir)/fused-src/gtest/gtest.h"
|
||||
rm -f "$(srcdir)/fused-src/gmock/gmock.h"
|
||||
rm -f "$(srcdir)/fused-src/gmock-gtest-all.cc"
|
||||
"$(srcdir)/scripts/fuse_gmock_files.py" "$(srcdir)/fused-src"
|
||||
cp -f "$(srcdir)/src/gmock_main.cc" "$(srcdir)/fused-src"
|
||||
|
||||
maintainer-clean-local:
|
||||
rm -rf "$(srcdir)/fused-src"
|
||||
endif
|
||||
|
||||
# Death tests may produce core dumps in the build directory. In case
|
||||
# this happens, clean them to keep distcleancheck happy.
|
||||
CLEANFILES = core
|
||||
|
||||
# Disables 'make install' as installing a compiled version of Google
|
||||
# Mock can lead to undefined behavior due to violation of the
|
||||
# One-Definition Rule.
|
||||
|
||||
install-exec-local:
|
||||
echo "'make install' is dangerous and not supported. Instead, see README for how to integrate Google Mock into your build system."
|
||||
false
|
||||
|
||||
install-data-local:
|
||||
echo "'make install' is dangerous and not supported. Instead, see README for how to integrate Google Mock into your build system."
|
||||
false
|
|
@ -1,333 +0,0 @@
|
|||
## Google Mock ##
|
||||
|
||||
The Google C++ mocking framework.
|
||||
|
||||
### Overview ###
|
||||
|
||||
Google's framework for writing and using C++ mock classes.
|
||||
It can help you derive better designs of your system and write better tests.
|
||||
|
||||
It is inspired by:
|
||||
|
||||
* [jMock](http://www.jmock.org/),
|
||||
* [EasyMock](http://www.easymock.org/), and
|
||||
* [Hamcrest](http://code.google.com/p/hamcrest/),
|
||||
|
||||
and designed with C++'s specifics in mind.
|
||||
|
||||
Google mock:
|
||||
|
||||
* lets you create mock classes trivially using simple macros.
|
||||
* supports a rich set of matchers and actions.
|
||||
* handles unordered, partially ordered, or completely ordered expectations.
|
||||
* is extensible by users.
|
||||
|
||||
We hope you find it useful!
|
||||
|
||||
### Features ###
|
||||
|
||||
* Provides a declarative syntax for defining mocks.
|
||||
* Can easily define partial (hybrid) mocks, which are a cross of real
|
||||
and mock objects.
|
||||
* Handles functions of arbitrary types and overloaded functions.
|
||||
* Comes with a rich set of matchers for validating function arguments.
|
||||
* Uses an intuitive syntax for controlling the behavior of a mock.
|
||||
* Does automatic verification of expectations (no record-and-replay needed).
|
||||
* Allows arbitrary (partial) ordering constraints on
|
||||
function calls to be expressed,.
|
||||
* Lets a user extend it by defining new matchers and actions.
|
||||
* Does not use exceptions.
|
||||
* Is easy to learn and use.
|
||||
|
||||
Please see the project page above for more information as well as the
|
||||
mailing list for questions, discussions, and development. There is
|
||||
also an IRC channel on OFTC (irc.oftc.net) #gtest available. Please
|
||||
join us!
|
||||
|
||||
Please note that code under [scripts/generator](scripts/generator/) is
|
||||
from [cppclean](http://code.google.com/p/cppclean/) and released under
|
||||
the Apache License, which is different from Google Mock's license.
|
||||
|
||||
## Getting Started ##
|
||||
|
||||
If you are new to the project, we suggest that you read the user
|
||||
documentation in the following order:
|
||||
|
||||
* Learn the [basics](../googletest/docs/Primer.md) of
|
||||
Google Test, if you choose to use Google Mock with it (recommended).
|
||||
* Read [Google Mock for Dummies](docs/ForDummies.md).
|
||||
* Read the instructions below on how to build Google Mock.
|
||||
|
||||
You can also watch Zhanyong's [talk](http://www.youtube.com/watch?v=sYpCyLI47rM) on Google Mock's usage and implementation.
|
||||
|
||||
Once you understand the basics, check out the rest of the docs:
|
||||
|
||||
* [CheatSheet](docs/CheatSheet.md) - all the commonly used stuff
|
||||
at a glance.
|
||||
* [CookBook](docs/CookBook.md) - recipes for getting things done,
|
||||
including advanced techniques.
|
||||
|
||||
If you need help, please check the
|
||||
[KnownIssues](docs/KnownIssues.md) and
|
||||
[FrequentlyAskedQuestions](docs/FrequentlyAskedQuestions.md) before
|
||||
posting a question on the
|
||||
[discussion group](http://groups.google.com/group/googlemock).
|
||||
|
||||
|
||||
### Using Google Mock Without Google Test ###
|
||||
|
||||
Google Mock is not a testing framework itself. Instead, it needs a
|
||||
testing framework for writing tests. Google Mock works seamlessly
|
||||
with [Google Test](http://code.google.com/p/googletest/), but
|
||||
you can also use it with [any C++ testing framework](googlemock/ForDummies.md#Using_Google_Mock_with_Any_Testing_Framework).
|
||||
|
||||
### Requirements for End Users ###
|
||||
|
||||
Google Mock is implemented on top of [Google Test](
|
||||
http://github.com/google/googletest/), and depends on it.
|
||||
You must use the bundled version of Google Test when using Google Mock.
|
||||
|
||||
You can also easily configure Google Mock to work with another testing
|
||||
framework, although it will still need Google Test. Please read
|
||||
["Using_Google_Mock_with_Any_Testing_Framework"](
|
||||
docs/ForDummies.md#Using_Google_Mock_with_Any_Testing_Framework)
|
||||
for instructions.
|
||||
|
||||
Google Mock depends on advanced C++ features and thus requires a more
|
||||
modern compiler. The following are needed to use Google Mock:
|
||||
|
||||
#### Linux Requirements ####
|
||||
|
||||
* GNU-compatible Make or "gmake"
|
||||
* POSIX-standard shell
|
||||
* POSIX(-2) Regular Expressions (regex.h)
|
||||
* C++98-standard-compliant compiler (e.g. GCC 3.4 or newer)
|
||||
|
||||
#### Windows Requirements ####
|
||||
|
||||
* Microsoft Visual C++ 8.0 SP1 or newer
|
||||
|
||||
#### Mac OS X Requirements ####
|
||||
|
||||
* Mac OS X 10.4 Tiger or newer
|
||||
* Developer Tools Installed
|
||||
|
||||
### Requirements for Contributors ###
|
||||
|
||||
We welcome patches. If you plan to contribute a patch, you need to
|
||||
build Google Mock and its tests, which has further requirements:
|
||||
|
||||
* Automake version 1.9 or newer
|
||||
* Autoconf version 2.59 or newer
|
||||
* Libtool / Libtoolize
|
||||
* Python version 2.3 or newer (for running some of the tests and
|
||||
re-generating certain source files from templates)
|
||||
|
||||
### Building Google Mock ###
|
||||
|
||||
#### Preparing to Build (Unix only) ####
|
||||
|
||||
If you are using a Unix system and plan to use the GNU Autotools build
|
||||
system to build Google Mock (described below), you'll need to
|
||||
configure it now.
|
||||
|
||||
To prepare the Autotools build system:
|
||||
|
||||
cd googlemock
|
||||
autoreconf -fvi
|
||||
|
||||
To build Google Mock and your tests that use it, you need to tell your
|
||||
build system where to find its headers and source files. The exact
|
||||
way to do it depends on which build system you use, and is usually
|
||||
straightforward.
|
||||
|
||||
This section shows how you can integrate Google Mock into your
|
||||
existing build system.
|
||||
|
||||
Suppose you put Google Mock in directory `${GMOCK_DIR}` and Google Test
|
||||
in `${GTEST_DIR}` (the latter is `${GMOCK_DIR}/gtest` by default). To
|
||||
build Google Mock, create a library build target (or a project as
|
||||
called by Visual Studio and Xcode) to compile
|
||||
|
||||
${GTEST_DIR}/src/gtest-all.cc and ${GMOCK_DIR}/src/gmock-all.cc
|
||||
|
||||
with
|
||||
|
||||
${GTEST_DIR}/include and ${GMOCK_DIR}/include
|
||||
|
||||
in the system header search path, and
|
||||
|
||||
${GTEST_DIR} and ${GMOCK_DIR}
|
||||
|
||||
in the normal header search path. Assuming a Linux-like system and gcc,
|
||||
something like the following will do:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
|
||||
-isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \
|
||||
-pthread -c ${GTEST_DIR}/src/gtest-all.cc
|
||||
g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
|
||||
-isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \
|
||||
-pthread -c ${GMOCK_DIR}/src/gmock-all.cc
|
||||
ar -rv libgmock.a gtest-all.o gmock-all.o
|
||||
|
||||
(We need -pthread as Google Test and Google Mock use threads.)
|
||||
|
||||
Next, you should compile your test source file with
|
||||
${GTEST\_DIR}/include and ${GMOCK\_DIR}/include in the header search
|
||||
path, and link it with gmock and any other necessary libraries:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -isystem ${GMOCK_DIR}/include \
|
||||
-pthread path/to/your_test.cc libgmock.a -o your_test
|
||||
|
||||
As an example, the make/ directory contains a Makefile that you can
|
||||
use to build Google Mock on systems where GNU make is available
|
||||
(e.g. Linux, Mac OS X, and Cygwin). It doesn't try to build Google
|
||||
Mock's own tests. Instead, it just builds the Google Mock library and
|
||||
a sample test. You can use it as a starting point for your own build
|
||||
script.
|
||||
|
||||
If the default settings are correct for your environment, the
|
||||
following commands should succeed:
|
||||
|
||||
cd ${GMOCK_DIR}/make
|
||||
make
|
||||
./gmock_test
|
||||
|
||||
If you see errors, try to tweak the contents of
|
||||
[make/Makefile](make/Makefile) to make them go away.
|
||||
|
||||
### Windows ###
|
||||
|
||||
The msvc/2005 directory contains VC++ 2005 projects and the msvc/2010
|
||||
directory contains VC++ 2010 projects for building Google Mock and
|
||||
selected tests.
|
||||
|
||||
Change to the appropriate directory and run "msbuild gmock.sln" to
|
||||
build the library and tests (or open the gmock.sln in the MSVC IDE).
|
||||
If you want to create your own project to use with Google Mock, you'll
|
||||
have to configure it to use the `gmock_config` propety sheet. For that:
|
||||
|
||||
* Open the Property Manager window (View | Other Windows | Property Manager)
|
||||
* Right-click on your project and select "Add Existing Property Sheet..."
|
||||
* Navigate to `gmock_config.vsprops` or `gmock_config.props` and select it.
|
||||
* In Project Properties | Configuration Properties | General | Additional
|
||||
Include Directories, type <path to Google Mock>/include.
|
||||
|
||||
### Tweaking Google Mock ###
|
||||
|
||||
Google Mock can be used in diverse environments. The default
|
||||
configuration may not work (or may not work well) out of the box in
|
||||
some environments. However, you can easily tweak Google Mock by
|
||||
defining control macros on the compiler command line. Generally,
|
||||
these macros are named like `GTEST_XYZ` and you define them to either 1
|
||||
or 0 to enable or disable a certain feature.
|
||||
|
||||
We list the most frequently used macros below. For a complete list,
|
||||
see file [${GTEST\_DIR}/include/gtest/internal/gtest-port.h](
|
||||
../googletest/include/gtest/internal/gtest-port.h).
|
||||
|
||||
### Choosing a TR1 Tuple Library ###
|
||||
|
||||
Google Mock uses the C++ Technical Report 1 (TR1) tuple library
|
||||
heavily. Unfortunately TR1 tuple is not yet widely available with all
|
||||
compilers. The good news is that Google Test 1.4.0+ implements a
|
||||
subset of TR1 tuple that's enough for Google Mock's need. Google Mock
|
||||
will automatically use that implementation when the compiler doesn't
|
||||
provide TR1 tuple.
|
||||
|
||||
Usually you don't need to care about which tuple library Google Test
|
||||
and Google Mock use. However, if your project already uses TR1 tuple,
|
||||
you need to tell Google Test and Google Mock to use the same TR1 tuple
|
||||
library the rest of your project uses, or the two tuple
|
||||
implementations will clash. To do that, add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=0
|
||||
|
||||
to the compiler flags while compiling Google Test, Google Mock, and
|
||||
your tests. If you want to force Google Test and Google Mock to use
|
||||
their own tuple library, just add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=1
|
||||
|
||||
to the compiler flags instead.
|
||||
|
||||
If you want to use Boost's TR1 tuple library with Google Mock, please
|
||||
refer to the Boost website (http://www.boost.org/) for how to obtain
|
||||
it and set it up.
|
||||
|
||||
### As a Shared Library (DLL) ###
|
||||
|
||||
Google Mock is compact, so most users can build and link it as a static
|
||||
library for the simplicity. Google Mock can be used as a DLL, but the
|
||||
same DLL must contain Google Test as well. See
|
||||
[Google Test's README][gtest_readme]
|
||||
for instructions on how to set up necessary compiler settings.
|
||||
|
||||
### Tweaking Google Mock ###
|
||||
|
||||
Most of Google Test's control macros apply to Google Mock as well.
|
||||
Please see [Google Test's README][gtest_readme] for how to tweak them.
|
||||
|
||||
### Upgrading from an Earlier Version ###
|
||||
|
||||
We strive to keep Google Mock releases backward compatible.
|
||||
Sometimes, though, we have to make some breaking changes for the
|
||||
users' long-term benefits. This section describes what you'll need to
|
||||
do if you are upgrading from an earlier version of Google Mock.
|
||||
|
||||
#### Upgrading from 1.1.0 or Earlier ####
|
||||
|
||||
You may need to explicitly enable or disable Google Test's own TR1
|
||||
tuple library. See the instructions in section "[Choosing a TR1 Tuple
|
||||
Library](../googletest/#choosing-a-tr1-tuple-library)".
|
||||
|
||||
#### Upgrading from 1.4.0 or Earlier ####
|
||||
|
||||
On platforms where the pthread library is available, Google Test and
|
||||
Google Mock use it in order to be thread-safe. For this to work, you
|
||||
may need to tweak your compiler and/or linker flags. Please see the
|
||||
"[Multi-threaded Tests](../googletest#multi-threaded-tests
|
||||
)" section in file Google Test's README for what you may need to do.
|
||||
|
||||
If you have custom matchers defined using `MatcherInterface` or
|
||||
`MakePolymorphicMatcher()`, you'll need to update their definitions to
|
||||
use the new matcher API (
|
||||
[monomorphic](http://code.google.com/p/googlemock/wiki/CookBook#Writing_New_Monomorphic_Matchers),
|
||||
[polymorphic](http://code.google.com/p/googlemock/wiki/CookBook#Writing_New_Polymorphic_Matchers)).
|
||||
Matchers defined using `MATCHER()` or `MATCHER_P*()` aren't affected.
|
||||
|
||||
### Developing Google Mock ###
|
||||
|
||||
This section discusses how to make your own changes to Google Mock.
|
||||
|
||||
#### Testing Google Mock Itself ####
|
||||
|
||||
To make sure your changes work as intended and don't break existing
|
||||
functionality, you'll want to compile and run Google Test's own tests.
|
||||
For that you'll need Autotools. First, make sure you have followed
|
||||
the instructions above to configure Google Mock.
|
||||
Then, create a build output directory and enter it. Next,
|
||||
|
||||
${GMOCK_DIR}/configure # try --help for more info
|
||||
|
||||
Once you have successfully configured Google Mock, the build steps are
|
||||
standard for GNU-style OSS packages.
|
||||
|
||||
make # Standard makefile following GNU conventions
|
||||
make check # Builds and runs all tests - all should pass.
|
||||
|
||||
Note that when building your project against Google Mock, you are building
|
||||
against Google Test as well. There is no need to configure Google Test
|
||||
separately.
|
||||
|
||||
#### Contributing a Patch ####
|
||||
|
||||
We welcome patches.
|
||||
Please read the [Developer's Guide](docs/DevGuide.md)
|
||||
for how you can contribute. In particular, make sure you have signed
|
||||
the Contributor License Agreement, or we won't be able to accept the
|
||||
patch.
|
||||
|
||||
Happy testing!
|
||||
|
||||
[gtest_readme]: ../googletest/README.md "googletest"
|
|
@ -1,146 +0,0 @@
|
|||
m4_include(../googletest/m4/acx_pthread.m4)
|
||||
|
||||
AC_INIT([Google C++ Mocking Framework],
|
||||
[1.7.0],
|
||||
[googlemock@googlegroups.com],
|
||||
[gmock])
|
||||
|
||||
# Provide various options to initialize the Autoconf and configure processes.
|
||||
AC_PREREQ([2.59])
|
||||
AC_CONFIG_SRCDIR([./LICENSE])
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AC_CONFIG_HEADERS([build-aux/config.h])
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_CONFIG_FILES([scripts/gmock-config], [chmod +x scripts/gmock-config])
|
||||
|
||||
# Initialize Automake with various options. We require at least v1.9, prevent
|
||||
# pedantic complaints about package files, and enable various distribution
|
||||
# targets.
|
||||
AM_INIT_AUTOMAKE([1.9 dist-bzip2 dist-zip foreign subdir-objects])
|
||||
|
||||
# Check for programs used in building Google Test.
|
||||
AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
AC_LANG([C++])
|
||||
AC_PROG_LIBTOOL
|
||||
|
||||
# TODO(chandlerc@google.com): Currently we aren't running the Python tests
|
||||
# against the interpreter detected by AM_PATH_PYTHON, and so we condition
|
||||
# HAVE_PYTHON by requiring "python" to be in the PATH, and that interpreter's
|
||||
# version to be >= 2.3. This will allow the scripts to use a "/usr/bin/env"
|
||||
# hashbang.
|
||||
PYTHON= # We *do not* allow the user to specify a python interpreter
|
||||
AC_PATH_PROG([PYTHON],[python],[:])
|
||||
AS_IF([test "$PYTHON" != ":"],
|
||||
[AM_PYTHON_CHECK_VERSION([$PYTHON],[2.3],[:],[PYTHON=":"])])
|
||||
AM_CONDITIONAL([HAVE_PYTHON],[test "$PYTHON" != ":"])
|
||||
|
||||
# TODO(chandlerc@google.com) Check for the necessary system headers.
|
||||
|
||||
# Configure pthreads.
|
||||
AC_ARG_WITH([pthreads],
|
||||
[AS_HELP_STRING([--with-pthreads],
|
||||
[use pthreads (default is yes)])],
|
||||
[with_pthreads=$withval],
|
||||
[with_pthreads=check])
|
||||
|
||||
have_pthreads=no
|
||||
AS_IF([test "x$with_pthreads" != "xno"],
|
||||
[ACX_PTHREAD(
|
||||
[],
|
||||
[AS_IF([test "x$with_pthreads" != "xcheck"],
|
||||
[AC_MSG_FAILURE(
|
||||
[--with-pthreads was specified, but unable to be used])])])
|
||||
have_pthreads="$acx_pthread_ok"])
|
||||
AM_CONDITIONAL([HAVE_PTHREADS],[test "x$have_pthreads" == "xyes"])
|
||||
AC_SUBST(PTHREAD_CFLAGS)
|
||||
AC_SUBST(PTHREAD_LIBS)
|
||||
|
||||
# GoogleMock currently has hard dependencies upon GoogleTest above and beyond
|
||||
# running its own test suite, so we both provide our own version in
|
||||
# a subdirectory and provide some logic to use a custom version or a system
|
||||
# installed version.
|
||||
AC_ARG_WITH([gtest],
|
||||
[AS_HELP_STRING([--with-gtest],
|
||||
[Specifies how to find the gtest package. If no
|
||||
arguments are given, the default behavior, a
|
||||
system installed gtest will be used if present,
|
||||
and an internal version built otherwise. If a
|
||||
path is provided, the gtest built or installed at
|
||||
that prefix will be used.])],
|
||||
[],
|
||||
[with_gtest=yes])
|
||||
AC_ARG_ENABLE([external-gtest],
|
||||
[AS_HELP_STRING([--disable-external-gtest],
|
||||
[Disables any detection or use of a system
|
||||
installed or user provided gtest. Any option to
|
||||
'--with-gtest' is ignored. (Default is enabled.)])
|
||||
], [], [enable_external_gtest=yes])
|
||||
AS_IF([test "x$with_gtest" == "xno"],
|
||||
[AC_MSG_ERROR([dnl
|
||||
Support for GoogleTest was explicitly disabled. Currently GoogleMock has a hard
|
||||
dependency upon GoogleTest to build, please provide a version, or allow
|
||||
GoogleMock to use any installed version and fall back upon its internal
|
||||
version.])])
|
||||
|
||||
# Setup various GTEST variables. TODO(chandlerc@google.com): When these are
|
||||
# used below, they should be used such that any pre-existing values always
|
||||
# trump values we set them to, so that they can be used to selectively override
|
||||
# details of the detection process.
|
||||
AC_ARG_VAR([GTEST_CONFIG],
|
||||
[The exact path of Google Test's 'gtest-config' script.])
|
||||
AC_ARG_VAR([GTEST_CPPFLAGS],
|
||||
[C-like preprocessor flags for Google Test.])
|
||||
AC_ARG_VAR([GTEST_CXXFLAGS],
|
||||
[C++ compile flags for Google Test.])
|
||||
AC_ARG_VAR([GTEST_LDFLAGS],
|
||||
[Linker path and option flags for Google Test.])
|
||||
AC_ARG_VAR([GTEST_LIBS],
|
||||
[Library linking flags for Google Test.])
|
||||
AC_ARG_VAR([GTEST_VERSION],
|
||||
[The version of Google Test available.])
|
||||
HAVE_BUILT_GTEST="no"
|
||||
|
||||
GTEST_MIN_VERSION="1.7.0"
|
||||
|
||||
AS_IF([test "x${enable_external_gtest}" = "xyes"],
|
||||
[# Begin filling in variables as we are able.
|
||||
AS_IF([test "x${with_gtest}" != "xyes"],
|
||||
[AS_IF([test -x "${with_gtest}/scripts/gtest-config"],
|
||||
[GTEST_CONFIG="${with_gtest}/scripts/gtest-config"],
|
||||
[GTEST_CONFIG="${with_gtest}/bin/gtest-config"])
|
||||
AS_IF([test -x "${GTEST_CONFIG}"], [],
|
||||
[AC_MSG_ERROR([dnl
|
||||
Unable to locate either a built or installed Google Test at '${with_gtest}'.])
|
||||
])])
|
||||
|
||||
AS_IF([test -x "${GTEST_CONFIG}"], [],
|
||||
[AC_PATH_PROG([GTEST_CONFIG], [gtest-config])])
|
||||
AS_IF([test -x "${GTEST_CONFIG}"],
|
||||
[AC_MSG_CHECKING([for Google Test version >= ${GTEST_MIN_VERSION}])
|
||||
AS_IF([${GTEST_CONFIG} --min-version=${GTEST_MIN_VERSION}],
|
||||
[AC_MSG_RESULT([yes])
|
||||
HAVE_BUILT_GTEST="yes"],
|
||||
[AC_MSG_RESULT([no])])])])
|
||||
|
||||
AS_IF([test "x${HAVE_BUILT_GTEST}" = "xyes"],
|
||||
[GTEST_CPPFLAGS=`${GTEST_CONFIG} --cppflags`
|
||||
GTEST_CXXFLAGS=`${GTEST_CONFIG} --cxxflags`
|
||||
GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags`
|
||||
GTEST_LIBS=`${GTEST_CONFIG} --libs`
|
||||
GTEST_VERSION=`${GTEST_CONFIG} --version`],
|
||||
[AC_CONFIG_SUBDIRS([../googletest])
|
||||
# GTEST_CONFIG needs to be executable both in a Makefile environmont and
|
||||
# in a shell script environment, so resolve an absolute path for it here.
|
||||
GTEST_CONFIG="`pwd -P`/../googletest/scripts/gtest-config"
|
||||
GTEST_CPPFLAGS='-I$(top_srcdir)/../googletest/include'
|
||||
GTEST_CXXFLAGS='-g'
|
||||
GTEST_LDFLAGS=''
|
||||
GTEST_LIBS='$(top_builddir)/../googletest/lib/libgtest.la'
|
||||
GTEST_VERSION="${GTEST_MIN_VERSION}"])
|
||||
|
||||
# TODO(chandlerc@google.com) Check the types, structures, and other compiler
|
||||
# and architecture characteristics.
|
||||
|
||||
# Output the generated files. No further autoconf macros may be used.
|
||||
AC_OUTPUT
|
|
@ -1,562 +0,0 @@
|
|||
|
||||
|
||||
# Defining a Mock Class #
|
||||
|
||||
## Mocking a Normal Class ##
|
||||
|
||||
Given
|
||||
```
|
||||
class Foo {
|
||||
...
|
||||
virtual ~Foo();
|
||||
virtual int GetSize() const = 0;
|
||||
virtual string Describe(const char* name) = 0;
|
||||
virtual string Describe(int type) = 0;
|
||||
virtual bool Process(Bar elem, int count) = 0;
|
||||
};
|
||||
```
|
||||
(note that `~Foo()` **must** be virtual) we can define its mock as
|
||||
```
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
class MockFoo : public Foo {
|
||||
MOCK_CONST_METHOD0(GetSize, int());
|
||||
MOCK_METHOD1(Describe, string(const char* name));
|
||||
MOCK_METHOD1(Describe, string(int type));
|
||||
MOCK_METHOD2(Process, bool(Bar elem, int count));
|
||||
};
|
||||
```
|
||||
|
||||
To create a "nice" mock object which ignores all uninteresting calls,
|
||||
or a "strict" mock object, which treats them as failures:
|
||||
```
|
||||
NiceMock<MockFoo> nice_foo; // The type is a subclass of MockFoo.
|
||||
StrictMock<MockFoo> strict_foo; // The type is a subclass of MockFoo.
|
||||
```
|
||||
|
||||
## Mocking a Class Template ##
|
||||
|
||||
To mock
|
||||
```
|
||||
template <typename Elem>
|
||||
class StackInterface {
|
||||
public:
|
||||
...
|
||||
virtual ~StackInterface();
|
||||
virtual int GetSize() const = 0;
|
||||
virtual void Push(const Elem& x) = 0;
|
||||
};
|
||||
```
|
||||
(note that `~StackInterface()` **must** be virtual) just append `_T` to the `MOCK_*` macros:
|
||||
```
|
||||
template <typename Elem>
|
||||
class MockStack : public StackInterface<Elem> {
|
||||
public:
|
||||
...
|
||||
MOCK_CONST_METHOD0_T(GetSize, int());
|
||||
MOCK_METHOD1_T(Push, void(const Elem& x));
|
||||
};
|
||||
```
|
||||
|
||||
## Specifying Calling Conventions for Mock Functions ##
|
||||
|
||||
If your mock function doesn't use the default calling convention, you
|
||||
can specify it by appending `_WITH_CALLTYPE` to any of the macros
|
||||
described in the previous two sections and supplying the calling
|
||||
convention as the first argument to the macro. For example,
|
||||
```
|
||||
MOCK_METHOD_1_WITH_CALLTYPE(STDMETHODCALLTYPE, Foo, bool(int n));
|
||||
MOCK_CONST_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, Bar, int(double x, double y));
|
||||
```
|
||||
where `STDMETHODCALLTYPE` is defined by `<objbase.h>` on Windows.
|
||||
|
||||
# Using Mocks in Tests #
|
||||
|
||||
The typical flow is:
|
||||
1. Import the Google Mock names you need to use. All Google Mock names are in the `testing` namespace unless they are macros or otherwise noted.
|
||||
1. Create the mock objects.
|
||||
1. Optionally, set the default actions of the mock objects.
|
||||
1. Set your expectations on the mock objects (How will they be called? What wil they do?).
|
||||
1. Exercise code that uses the mock objects; if necessary, check the result using [Google Test](../../googletest/) assertions.
|
||||
1. When a mock objects is destructed, Google Mock automatically verifies that all expectations on it have been satisfied.
|
||||
|
||||
Here is an example:
|
||||
```
|
||||
using ::testing::Return; // #1
|
||||
|
||||
TEST(BarTest, DoesThis) {
|
||||
MockFoo foo; // #2
|
||||
|
||||
ON_CALL(foo, GetSize()) // #3
|
||||
.WillByDefault(Return(1));
|
||||
// ... other default actions ...
|
||||
|
||||
EXPECT_CALL(foo, Describe(5)) // #4
|
||||
.Times(3)
|
||||
.WillRepeatedly(Return("Category 5"));
|
||||
// ... other expectations ...
|
||||
|
||||
EXPECT_EQ("good", MyProductionFunction(&foo)); // #5
|
||||
} // #6
|
||||
```
|
||||
|
||||
# Setting Default Actions #
|
||||
|
||||
Google Mock has a **built-in default action** for any function that
|
||||
returns `void`, `bool`, a numeric value, or a pointer.
|
||||
|
||||
To customize the default action for functions with return type `T` globally:
|
||||
```
|
||||
using ::testing::DefaultValue;
|
||||
|
||||
// Sets the default value to be returned. T must be CopyConstructible.
|
||||
DefaultValue<T>::Set(value);
|
||||
// Sets a factory. Will be invoked on demand. T must be MoveConstructible.
|
||||
// T MakeT();
|
||||
DefaultValue<T>::SetFactory(&MakeT);
|
||||
// ... use the mocks ...
|
||||
// Resets the default value.
|
||||
DefaultValue<T>::Clear();
|
||||
```
|
||||
|
||||
To customize the default action for a particular method, use `ON_CALL()`:
|
||||
```
|
||||
ON_CALL(mock_object, method(matchers))
|
||||
.With(multi_argument_matcher) ?
|
||||
.WillByDefault(action);
|
||||
```
|
||||
|
||||
# Setting Expectations #
|
||||
|
||||
`EXPECT_CALL()` sets **expectations** on a mock method (How will it be
|
||||
called? What will it do?):
|
||||
```
|
||||
EXPECT_CALL(mock_object, method(matchers))
|
||||
.With(multi_argument_matcher) ?
|
||||
.Times(cardinality) ?
|
||||
.InSequence(sequences) *
|
||||
.After(expectations) *
|
||||
.WillOnce(action) *
|
||||
.WillRepeatedly(action) ?
|
||||
.RetiresOnSaturation(); ?
|
||||
```
|
||||
|
||||
If `Times()` is omitted, the cardinality is assumed to be:
|
||||
|
||||
* `Times(1)` when there is neither `WillOnce()` nor `WillRepeatedly()`;
|
||||
* `Times(n)` when there are `n WillOnce()`s but no `WillRepeatedly()`, where `n` >= 1; or
|
||||
* `Times(AtLeast(n))` when there are `n WillOnce()`s and a `WillRepeatedly()`, where `n` >= 0.
|
||||
|
||||
A method with no `EXPECT_CALL()` is free to be invoked _any number of times_, and the default action will be taken each time.
|
||||
|
||||
# Matchers #
|
||||
|
||||
A **matcher** matches a _single_ argument. You can use it inside
|
||||
`ON_CALL()` or `EXPECT_CALL()`, or use it to validate a value
|
||||
directly:
|
||||
|
||||
| `EXPECT_THAT(value, matcher)` | Asserts that `value` matches `matcher`. |
|
||||
|:------------------------------|:----------------------------------------|
|
||||
| `ASSERT_THAT(value, matcher)` | The same as `EXPECT_THAT(value, matcher)`, except that it generates a **fatal** failure. |
|
||||
|
||||
Built-in matchers (where `argument` is the function argument) are
|
||||
divided into several categories:
|
||||
|
||||
## Wildcard ##
|
||||
|`_`|`argument` can be any value of the correct type.|
|
||||
|:--|:-----------------------------------------------|
|
||||
|`A<type>()` or `An<type>()`|`argument` can be any value of type `type`. |
|
||||
|
||||
## Generic Comparison ##
|
||||
|
||||
|`Eq(value)` or `value`|`argument == value`|
|
||||
|:---------------------|:------------------|
|
||||
|`Ge(value)` |`argument >= value`|
|
||||
|`Gt(value)` |`argument > value` |
|
||||
|`Le(value)` |`argument <= value`|
|
||||
|`Lt(value)` |`argument < value` |
|
||||
|`Ne(value)` |`argument != value`|
|
||||
|`IsNull()` |`argument` is a `NULL` pointer (raw or smart).|
|
||||
|`NotNull()` |`argument` is a non-null pointer (raw or smart).|
|
||||
|`Ref(variable)` |`argument` is a reference to `variable`.|
|
||||
|`TypedEq<type>(value)`|`argument` has type `type` and is equal to `value`. You may need to use this instead of `Eq(value)` when the mock function is overloaded.|
|
||||
|
||||
Except `Ref()`, these matchers make a _copy_ of `value` in case it's
|
||||
modified or destructed later. If the compiler complains that `value`
|
||||
doesn't have a public copy constructor, try wrap it in `ByRef()`,
|
||||
e.g. `Eq(ByRef(non_copyable_value))`. If you do that, make sure
|
||||
`non_copyable_value` is not changed afterwards, or the meaning of your
|
||||
matcher will be changed.
|
||||
|
||||
## Floating-Point Matchers ##
|
||||
|
||||
|`DoubleEq(a_double)`|`argument` is a `double` value approximately equal to `a_double`, treating two NaNs as unequal.|
|
||||
|:-------------------|:----------------------------------------------------------------------------------------------|
|
||||
|`FloatEq(a_float)` |`argument` is a `float` value approximately equal to `a_float`, treating two NaNs as unequal. |
|
||||
|`NanSensitiveDoubleEq(a_double)`|`argument` is a `double` value approximately equal to `a_double`, treating two NaNs as equal. |
|
||||
|`NanSensitiveFloatEq(a_float)`|`argument` is a `float` value approximately equal to `a_float`, treating two NaNs as equal. |
|
||||
|
||||
The above matchers use ULP-based comparison (the same as used in
|
||||
[Google Test](../../googletest/)). They
|
||||
automatically pick a reasonable error bound based on the absolute
|
||||
value of the expected value. `DoubleEq()` and `FloatEq()` conform to
|
||||
the IEEE standard, which requires comparing two NaNs for equality to
|
||||
return false. The `NanSensitive*` version instead treats two NaNs as
|
||||
equal, which is often what a user wants.
|
||||
|
||||
|`DoubleNear(a_double, max_abs_error)`|`argument` is a `double` value close to `a_double` (absolute error <= `max_abs_error`), treating two NaNs as unequal.|
|
||||
|:------------------------------------|:--------------------------------------------------------------------------------------------------------------------|
|
||||
|`FloatNear(a_float, max_abs_error)` |`argument` is a `float` value close to `a_float` (absolute error <= `max_abs_error`), treating two NaNs as unequal. |
|
||||
|`NanSensitiveDoubleNear(a_double, max_abs_error)`|`argument` is a `double` value close to `a_double` (absolute error <= `max_abs_error`), treating two NaNs as equal. |
|
||||
|`NanSensitiveFloatNear(a_float, max_abs_error)`|`argument` is a `float` value close to `a_float` (absolute error <= `max_abs_error`), treating two NaNs as equal. |
|
||||
|
||||
## String Matchers ##
|
||||
|
||||
The `argument` can be either a C string or a C++ string object:
|
||||
|
||||
|`ContainsRegex(string)`|`argument` matches the given regular expression.|
|
||||
|:----------------------|:-----------------------------------------------|
|
||||
|`EndsWith(suffix)` |`argument` ends with string `suffix`. |
|
||||
|`HasSubstr(string)` |`argument` contains `string` as a sub-string. |
|
||||
|`MatchesRegex(string)` |`argument` matches the given regular expression with the match starting at the first character and ending at the last character.|
|
||||
|`StartsWith(prefix)` |`argument` starts with string `prefix`. |
|
||||
|`StrCaseEq(string)` |`argument` is equal to `string`, ignoring case. |
|
||||
|`StrCaseNe(string)` |`argument` is not equal to `string`, ignoring case.|
|
||||
|`StrEq(string)` |`argument` is equal to `string`. |
|
||||
|`StrNe(string)` |`argument` is not equal to `string`. |
|
||||
|
||||
`ContainsRegex()` and `MatchesRegex()` use the regular expression
|
||||
syntax defined
|
||||
[here](../../googletest/docs/AdvancedGuide.md#regular-expression-syntax).
|
||||
`StrCaseEq()`, `StrCaseNe()`, `StrEq()`, and `StrNe()` work for wide
|
||||
strings as well.
|
||||
|
||||
## Container Matchers ##
|
||||
|
||||
Most STL-style containers support `==`, so you can use
|
||||
`Eq(expected_container)` or simply `expected_container` to match a
|
||||
container exactly. If you want to write the elements in-line,
|
||||
match them more flexibly, or get more informative messages, you can use:
|
||||
|
||||
| `ContainerEq(container)` | The same as `Eq(container)` except that the failure message also includes which elements are in one container but not the other. |
|
||||
|:-------------------------|:---------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `Contains(e)` | `argument` contains an element that matches `e`, which can be either a value or a matcher. |
|
||||
| `Each(e)` | `argument` is a container where _every_ element matches `e`, which can be either a value or a matcher. |
|
||||
| `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, where the i-th element matches `ei`, which can be a value or a matcher. 0 to 10 arguments are allowed. |
|
||||
| `ElementsAreArray({ e0, e1, ..., en })`, `ElementsAreArray(array)`, or `ElementsAreArray(array, count)` | The same as `ElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, or C-style array. |
|
||||
| `IsEmpty()` | `argument` is an empty container (`container.empty()`). |
|
||||
| `Pointwise(m, container)` | `argument` contains the same number of elements as in `container`, and for all i, (the i-th element in `argument`, the i-th element in `container`) match `m`, which is a matcher on 2-tuples. E.g. `Pointwise(Le(), upper_bounds)` verifies that each element in `argument` doesn't exceed the corresponding element in `upper_bounds`. See more detail below. |
|
||||
| `SizeIs(m)` | `argument` is a container whose size matches `m`. E.g. `SizeIs(2)` or `SizeIs(Lt(2))`. |
|
||||
| `UnorderedElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, and under some permutation each element matches an `ei` (for a different `i`), which can be a value or a matcher. 0 to 10 arguments are allowed. |
|
||||
| `UnorderedElementsAreArray({ e0, e1, ..., en })`, `UnorderedElementsAreArray(array)`, or `UnorderedElementsAreArray(array, count)` | The same as `UnorderedElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, or C-style array. |
|
||||
| `WhenSorted(m)` | When `argument` is sorted using the `<` operator, it matches container matcher `m`. E.g. `WhenSorted(UnorderedElementsAre(1, 2, 3))` verifies that `argument` contains elements `1`, `2`, and `3`, ignoring order. |
|
||||
| `WhenSortedBy(comparator, m)` | The same as `WhenSorted(m)`, except that the given comparator instead of `<` is used to sort `argument`. E.g. `WhenSortedBy(std::greater<int>(), ElementsAre(3, 2, 1))`. |
|
||||
|
||||
Notes:
|
||||
|
||||
* These matchers can also match:
|
||||
1. a native array passed by reference (e.g. in `Foo(const int (&a)[5])`), and
|
||||
1. an array passed as a pointer and a count (e.g. in `Bar(const T* buffer, int len)` -- see [Multi-argument Matchers](#Multiargument_Matchers.md)).
|
||||
* The array being matched may be multi-dimensional (i.e. its elements can be arrays).
|
||||
* `m` in `Pointwise(m, ...)` should be a matcher for `::testing::tuple<T, U>` where `T` and `U` are the element type of the actual container and the expected container, respectively. For example, to compare two `Foo` containers where `Foo` doesn't support `operator==` but has an `Equals()` method, one might write:
|
||||
|
||||
```
|
||||
using ::testing::get;
|
||||
MATCHER(FooEq, "") {
|
||||
return get<0>(arg).Equals(get<1>(arg));
|
||||
}
|
||||
...
|
||||
EXPECT_THAT(actual_foos, Pointwise(FooEq(), expected_foos));
|
||||
```
|
||||
|
||||
## Member Matchers ##
|
||||
|
||||
|`Field(&class::field, m)`|`argument.field` (or `argument->field` when `argument` is a plain pointer) matches matcher `m`, where `argument` is an object of type _class_.|
|
||||
|:------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
|`Key(e)` |`argument.first` matches `e`, which can be either a value or a matcher. E.g. `Contains(Key(Le(5)))` can verify that a `map` contains a key `<= 5`.|
|
||||
|`Pair(m1, m2)` |`argument` is an `std::pair` whose `first` field matches `m1` and `second` field matches `m2`. |
|
||||
|`Property(&class::property, m)`|`argument.property()` (or `argument->property()` when `argument` is a plain pointer) matches matcher `m`, where `argument` is an object of type _class_.|
|
||||
|
||||
## Matching the Result of a Function or Functor ##
|
||||
|
||||
|`ResultOf(f, m)`|`f(argument)` matches matcher `m`, where `f` is a function or functor.|
|
||||
|:---------------|:---------------------------------------------------------------------|
|
||||
|
||||
## Pointer Matchers ##
|
||||
|
||||
|`Pointee(m)`|`argument` (either a smart pointer or a raw pointer) points to a value that matches matcher `m`.|
|
||||
|:-----------|:-----------------------------------------------------------------------------------------------|
|
||||
|`WhenDynamicCastTo<T>(m)`| when `argument` is passed through `dynamic_cast<T>()`, it matches matcher `m`. |
|
||||
|
||||
## Multiargument Matchers ##
|
||||
|
||||
Technically, all matchers match a _single_ value. A "multi-argument"
|
||||
matcher is just one that matches a _tuple_. The following matchers can
|
||||
be used to match a tuple `(x, y)`:
|
||||
|
||||
|`Eq()`|`x == y`|
|
||||
|:-----|:-------|
|
||||
|`Ge()`|`x >= y`|
|
||||
|`Gt()`|`x > y` |
|
||||
|`Le()`|`x <= y`|
|
||||
|`Lt()`|`x < y` |
|
||||
|`Ne()`|`x != y`|
|
||||
|
||||
You can use the following selectors to pick a subset of the arguments
|
||||
(or reorder them) to participate in the matching:
|
||||
|
||||
|`AllArgs(m)`|Equivalent to `m`. Useful as syntactic sugar in `.With(AllArgs(m))`.|
|
||||
|:-----------|:-------------------------------------------------------------------|
|
||||
|`Args<N1, N2, ..., Nk>(m)`|The tuple of the `k` selected (using 0-based indices) arguments matches `m`, e.g. `Args<1, 2>(Eq())`.|
|
||||
|
||||
## Composite Matchers ##
|
||||
|
||||
You can make a matcher from one or more other matchers:
|
||||
|
||||
|`AllOf(m1, m2, ..., mn)`|`argument` matches all of the matchers `m1` to `mn`.|
|
||||
|:-----------------------|:---------------------------------------------------|
|
||||
|`AnyOf(m1, m2, ..., mn)`|`argument` matches at least one of the matchers `m1` to `mn`.|
|
||||
|`Not(m)` |`argument` doesn't match matcher `m`. |
|
||||
|
||||
## Adapters for Matchers ##
|
||||
|
||||
|`MatcherCast<T>(m)`|casts matcher `m` to type `Matcher<T>`.|
|
||||
|:------------------|:--------------------------------------|
|
||||
|`SafeMatcherCast<T>(m)`| [safely casts](CookBook.md#casting-matchers) matcher `m` to type `Matcher<T>`. |
|
||||
|`Truly(predicate)` |`predicate(argument)` returns something considered by C++ to be true, where `predicate` is a function or functor.|
|
||||
|
||||
## Matchers as Predicates ##
|
||||
|
||||
|`Matches(m)(value)`|evaluates to `true` if `value` matches `m`. You can use `Matches(m)` alone as a unary functor.|
|
||||
|:------------------|:---------------------------------------------------------------------------------------------|
|
||||
|`ExplainMatchResult(m, value, result_listener)`|evaluates to `true` if `value` matches `m`, explaining the result to `result_listener`. |
|
||||
|`Value(value, m)` |evaluates to `true` if `value` matches `m`. |
|
||||
|
||||
## Defining Matchers ##
|
||||
|
||||
| `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. |
|
||||
|:-------------------------------------------------|:------------------------------------------------------|
|
||||
| `MATCHER_P(IsDivisibleBy, n, "") { *result_listener << "where the remainder is " << (arg % n); return (arg % n) == 0; }` | Defines a macher `IsDivisibleBy(n)` to match a number divisible by `n`. |
|
||||
| `MATCHER_P2(IsBetween, a, b, std::string(negation ? "isn't" : "is") + " between " + PrintToString(a) + " and " + PrintToString(b)) { return a <= arg && arg <= b; }` | Defines a matcher `IsBetween(a, b)` to match a value in the range [`a`, `b`]. |
|
||||
|
||||
**Notes:**
|
||||
|
||||
1. The `MATCHER*` macros cannot be used inside a function or class.
|
||||
1. The matcher body must be _purely functional_ (i.e. it cannot have any side effect, and the result must not depend on anything other than the value being matched and the matcher parameters).
|
||||
1. You can use `PrintToString(x)` to convert a value `x` of any type to a string.
|
||||
|
||||
## Matchers as Test Assertions ##
|
||||
|
||||
|`ASSERT_THAT(expression, m)`|Generates a [fatal failure](../../googletest/docs/Primer.md#assertions) if the value of `expression` doesn't match matcher `m`.|
|
||||
|:---------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
|`EXPECT_THAT(expression, m)`|Generates a non-fatal failure if the value of `expression` doesn't match matcher `m`. |
|
||||
|
||||
# Actions #
|
||||
|
||||
**Actions** specify what a mock function should do when invoked.
|
||||
|
||||
## Returning a Value ##
|
||||
|
||||
|`Return()`|Return from a `void` mock function.|
|
||||
|:---------|:----------------------------------|
|
||||
|`Return(value)`|Return `value`. If the type of `value` is different to the mock function's return type, `value` is converted to the latter type <i>at the time the expectation is set</i>, not when the action is executed.|
|
||||
|`ReturnArg<N>()`|Return the `N`-th (0-based) argument.|
|
||||
|`ReturnNew<T>(a1, ..., ak)`|Return `new T(a1, ..., ak)`; a different object is created each time.|
|
||||
|`ReturnNull()`|Return a null pointer. |
|
||||
|`ReturnPointee(ptr)`|Return the value pointed to by `ptr`.|
|
||||
|`ReturnRef(variable)`|Return a reference to `variable`. |
|
||||
|`ReturnRefOfCopy(value)`|Return a reference to a copy of `value`; the copy lives as long as the action.|
|
||||
|
||||
## Side Effects ##
|
||||
|
||||
|`Assign(&variable, value)`|Assign `value` to variable.|
|
||||
|:-------------------------|:--------------------------|
|
||||
| `DeleteArg<N>()` | Delete the `N`-th (0-based) argument, which must be a pointer. |
|
||||
| `SaveArg<N>(pointer)` | Save the `N`-th (0-based) argument to `*pointer`. |
|
||||
| `SaveArgPointee<N>(pointer)` | Save the value pointed to by the `N`-th (0-based) argument to `*pointer`. |
|
||||
| `SetArgReferee<N>(value)` | Assign value to the variable referenced by the `N`-th (0-based) argument. |
|
||||
|`SetArgPointee<N>(value)` |Assign `value` to the variable pointed by the `N`-th (0-based) argument.|
|
||||
|`SetArgumentPointee<N>(value)`|Same as `SetArgPointee<N>(value)`. Deprecated. Will be removed in v1.7.0.|
|
||||
|`SetArrayArgument<N>(first, last)`|Copies the elements in source range [`first`, `last`) to the array pointed to by the `N`-th (0-based) argument, which can be either a pointer or an iterator. The action does not take ownership of the elements in the source range.|
|
||||
|`SetErrnoAndReturn(error, value)`|Set `errno` to `error` and return `value`.|
|
||||
|`Throw(exception)` |Throws the given exception, which can be any copyable value. Available since v1.1.0.|
|
||||
|
||||
## Using a Function or a Functor as an Action ##
|
||||
|
||||
|`Invoke(f)`|Invoke `f` with the arguments passed to the mock function, where `f` can be a global/static function or a functor.|
|
||||
|:----------|:-----------------------------------------------------------------------------------------------------------------|
|
||||
|`Invoke(object_pointer, &class::method)`|Invoke the {method on the object with the arguments passed to the mock function. |
|
||||
|`InvokeWithoutArgs(f)`|Invoke `f`, which can be a global/static function or a functor. `f` must take no arguments. |
|
||||
|`InvokeWithoutArgs(object_pointer, &class::method)`|Invoke the method on the object, which takes no arguments. |
|
||||
|`InvokeArgument<N>(arg1, arg2, ..., argk)`|Invoke the mock function's `N`-th (0-based) argument, which must be a function or a functor, with the `k` arguments.|
|
||||
|
||||
The return value of the invoked function is used as the return value
|
||||
of the action.
|
||||
|
||||
When defining a function or functor to be used with `Invoke*()`, you can declare any unused parameters as `Unused`:
|
||||
```
|
||||
double Distance(Unused, double x, double y) { return sqrt(x*x + y*y); }
|
||||
...
|
||||
EXPECT_CALL(mock, Foo("Hi", _, _)).WillOnce(Invoke(Distance));
|
||||
```
|
||||
|
||||
In `InvokeArgument<N>(...)`, if an argument needs to be passed by reference, wrap it inside `ByRef()`. For example,
|
||||
```
|
||||
InvokeArgument<2>(5, string("Hi"), ByRef(foo))
|
||||
```
|
||||
calls the mock function's #2 argument, passing to it `5` and `string("Hi")` by value, and `foo` by reference.
|
||||
|
||||
## Default Action ##
|
||||
|
||||
|`DoDefault()`|Do the default action (specified by `ON_CALL()` or the built-in one).|
|
||||
|:------------|:--------------------------------------------------------------------|
|
||||
|
||||
**Note:** due to technical reasons, `DoDefault()` cannot be used inside a composite action - trying to do so will result in a run-time error.
|
||||
|
||||
## Composite Actions ##
|
||||
|
||||
|`DoAll(a1, a2, ..., an)`|Do all actions `a1` to `an` and return the result of `an` in each invocation. The first `n - 1` sub-actions must return void. |
|
||||
|:-----------------------|:-----------------------------------------------------------------------------------------------------------------------------|
|
||||
|`IgnoreResult(a)` |Perform action `a` and ignore its result. `a` must not return void. |
|
||||
|`WithArg<N>(a)` |Pass the `N`-th (0-based) argument of the mock function to action `a` and perform it. |
|
||||
|`WithArgs<N1, N2, ..., Nk>(a)`|Pass the selected (0-based) arguments of the mock function to action `a` and perform it. |
|
||||
|`WithoutArgs(a)` |Perform action `a` without any arguments. |
|
||||
|
||||
## Defining Actions ##
|
||||
|
||||
| `ACTION(Sum) { return arg0 + arg1; }` | Defines an action `Sum()` to return the sum of the mock function's argument #0 and #1. |
|
||||
|:--------------------------------------|:---------------------------------------------------------------------------------------|
|
||||
| `ACTION_P(Plus, n) { return arg0 + n; }` | Defines an action `Plus(n)` to return the sum of the mock function's argument #0 and `n`. |
|
||||
| `ACTION_Pk(Foo, p1, ..., pk) { statements; }` | Defines a parameterized action `Foo(p1, ..., pk)` to execute the given `statements`. |
|
||||
|
||||
The `ACTION*` macros cannot be used inside a function or class.
|
||||
|
||||
# Cardinalities #
|
||||
|
||||
These are used in `Times()` to specify how many times a mock function will be called:
|
||||
|
||||
|`AnyNumber()`|The function can be called any number of times.|
|
||||
|:------------|:----------------------------------------------|
|
||||
|`AtLeast(n)` |The call is expected at least `n` times. |
|
||||
|`AtMost(n)` |The call is expected at most `n` times. |
|
||||
|`Between(m, n)`|The call is expected between `m` and `n` (inclusive) times.|
|
||||
|`Exactly(n) or n`|The call is expected exactly `n` times. In particular, the call should never happen when `n` is 0.|
|
||||
|
||||
# Expectation Order #
|
||||
|
||||
By default, the expectations can be matched in _any_ order. If some
|
||||
or all expectations must be matched in a given order, there are two
|
||||
ways to specify it. They can be used either independently or
|
||||
together.
|
||||
|
||||
## The After Clause ##
|
||||
|
||||
```
|
||||
using ::testing::Expectation;
|
||||
...
|
||||
Expectation init_x = EXPECT_CALL(foo, InitX());
|
||||
Expectation init_y = EXPECT_CALL(foo, InitY());
|
||||
EXPECT_CALL(foo, Bar())
|
||||
.After(init_x, init_y);
|
||||
```
|
||||
says that `Bar()` can be called only after both `InitX()` and
|
||||
`InitY()` have been called.
|
||||
|
||||
If you don't know how many pre-requisites an expectation has when you
|
||||
write it, you can use an `ExpectationSet` to collect them:
|
||||
|
||||
```
|
||||
using ::testing::ExpectationSet;
|
||||
...
|
||||
ExpectationSet all_inits;
|
||||
for (int i = 0; i < element_count; i++) {
|
||||
all_inits += EXPECT_CALL(foo, InitElement(i));
|
||||
}
|
||||
EXPECT_CALL(foo, Bar())
|
||||
.After(all_inits);
|
||||
```
|
||||
says that `Bar()` can be called only after all elements have been
|
||||
initialized (but we don't care about which elements get initialized
|
||||
before the others).
|
||||
|
||||
Modifying an `ExpectationSet` after using it in an `.After()` doesn't
|
||||
affect the meaning of the `.After()`.
|
||||
|
||||
## Sequences ##
|
||||
|
||||
When you have a long chain of sequential expectations, it's easier to
|
||||
specify the order using **sequences**, which don't require you to given
|
||||
each expectation in the chain a different name. <i>All expected<br>
|
||||
calls</i> in the same sequence must occur in the order they are
|
||||
specified.
|
||||
|
||||
```
|
||||
using ::testing::Sequence;
|
||||
Sequence s1, s2;
|
||||
...
|
||||
EXPECT_CALL(foo, Reset())
|
||||
.InSequence(s1, s2)
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(foo, GetSize())
|
||||
.InSequence(s1)
|
||||
.WillOnce(Return(1));
|
||||
EXPECT_CALL(foo, Describe(A<const char*>()))
|
||||
.InSequence(s2)
|
||||
.WillOnce(Return("dummy"));
|
||||
```
|
||||
says that `Reset()` must be called before _both_ `GetSize()` _and_
|
||||
`Describe()`, and the latter two can occur in any order.
|
||||
|
||||
To put many expectations in a sequence conveniently:
|
||||
```
|
||||
using ::testing::InSequence;
|
||||
{
|
||||
InSequence dummy;
|
||||
|
||||
EXPECT_CALL(...)...;
|
||||
EXPECT_CALL(...)...;
|
||||
...
|
||||
EXPECT_CALL(...)...;
|
||||
}
|
||||
```
|
||||
says that all expected calls in the scope of `dummy` must occur in
|
||||
strict order. The name `dummy` is irrelevant.)
|
||||
|
||||
# Verifying and Resetting a Mock #
|
||||
|
||||
Google Mock will verify the expectations on a mock object when it is destructed, or you can do it earlier:
|
||||
```
|
||||
using ::testing::Mock;
|
||||
...
|
||||
// Verifies and removes the expectations on mock_obj;
|
||||
// returns true iff successful.
|
||||
Mock::VerifyAndClearExpectations(&mock_obj);
|
||||
...
|
||||
// Verifies and removes the expectations on mock_obj;
|
||||
// also removes the default actions set by ON_CALL();
|
||||
// returns true iff successful.
|
||||
Mock::VerifyAndClear(&mock_obj);
|
||||
```
|
||||
|
||||
You can also tell Google Mock that a mock object can be leaked and doesn't
|
||||
need to be verified:
|
||||
```
|
||||
Mock::AllowLeak(&mock_obj);
|
||||
```
|
||||
|
||||
# Mock Classes #
|
||||
|
||||
Google Mock defines a convenient mock class template
|
||||
```
|
||||
class MockFunction<R(A1, ..., An)> {
|
||||
public:
|
||||
MOCK_METHODn(Call, R(A1, ..., An));
|
||||
};
|
||||
```
|
||||
See this [recipe](CookBook.md#using-check-points) for one application of it.
|
||||
|
||||
# Flags #
|
||||
|
||||
| `--gmock_catch_leaked_mocks=0` | Don't report leaked mock objects as failures. |
|
||||
|:-------------------------------|:----------------------------------------------|
|
||||
| `--gmock_verbose=LEVEL` | Sets the default verbosity level (`info`, `warning`, or `error`) of Google Mock messages. |
|
|
@ -1,280 +0,0 @@
|
|||
This page discusses the design of new Google Mock features.
|
||||
|
||||
|
||||
|
||||
# Macros for Defining Actions #
|
||||
|
||||
## Problem ##
|
||||
|
||||
Due to the lack of closures in C++, it currently requires some
|
||||
non-trivial effort to define a custom action in Google Mock. For
|
||||
example, suppose you want to "increment the value pointed to by the
|
||||
second argument of the mock function and return it", you could write:
|
||||
|
||||
```
|
||||
int IncrementArg1(Unused, int* p, Unused) {
|
||||
return ++(*p);
|
||||
}
|
||||
|
||||
... WillOnce(Invoke(IncrementArg1));
|
||||
```
|
||||
|
||||
There are several things unsatisfactory about this approach:
|
||||
|
||||
* Even though the action only cares about the second argument of the mock function, its definition needs to list other arguments as dummies. This is tedious.
|
||||
* The defined action is usable only in mock functions that takes exactly 3 arguments - an unnecessary restriction.
|
||||
* To use the action, one has to say `Invoke(IncrementArg1)`, which isn't as nice as `IncrementArg1()`.
|
||||
|
||||
The latter two problems can be overcome using `MakePolymorphicAction()`,
|
||||
but it requires much more boilerplate code:
|
||||
|
||||
```
|
||||
class IncrementArg1Action {
|
||||
public:
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
Result Perform(const ArgumentTuple& args) const {
|
||||
return ++(*tr1::get<1>(args));
|
||||
}
|
||||
};
|
||||
|
||||
PolymorphicAction<IncrementArg1Action> IncrementArg1() {
|
||||
return MakePolymorphicAction(IncrementArg1Action());
|
||||
}
|
||||
|
||||
... WillOnce(IncrementArg1());
|
||||
```
|
||||
|
||||
Our goal is to allow defining custom actions with the least amount of
|
||||
boiler-plate C++ requires.
|
||||
|
||||
## Solution ##
|
||||
|
||||
We propose to introduce a new macro:
|
||||
```
|
||||
ACTION(name) { statements; }
|
||||
```
|
||||
|
||||
Using this in a namespace scope will define an action with the given
|
||||
name that executes the statements. Inside the statements, you can
|
||||
refer to the K-th (0-based) argument of the mock function as `argK`.
|
||||
For example:
|
||||
```
|
||||
ACTION(IncrementArg1) { return ++(*arg1); }
|
||||
```
|
||||
allows you to write
|
||||
```
|
||||
... WillOnce(IncrementArg1());
|
||||
```
|
||||
|
||||
Note that you don't need to specify the types of the mock function
|
||||
arguments, as brevity is a top design goal here. Rest assured that
|
||||
your code is still type-safe though: you'll get a compiler error if
|
||||
`*arg1` doesn't support the `++` operator, or if the type of
|
||||
`++(*arg1)` isn't compatible with the mock function's return type.
|
||||
|
||||
Another example:
|
||||
```
|
||||
ACTION(Foo) {
|
||||
(*arg2)(5);
|
||||
Blah();
|
||||
*arg1 = 0;
|
||||
return arg0;
|
||||
}
|
||||
```
|
||||
defines an action `Foo()` that invokes argument #2 (a function pointer)
|
||||
with 5, calls function `Blah()`, sets the value pointed to by argument
|
||||
#1 to 0, and returns argument #0.
|
||||
|
||||
For more convenience and flexibility, you can also use the following
|
||||
pre-defined symbols in the body of `ACTION`:
|
||||
|
||||
| `argK_type` | The type of the K-th (0-based) argument of the mock function |
|
||||
|:------------|:-------------------------------------------------------------|
|
||||
| `args` | All arguments of the mock function as a tuple |
|
||||
| `args_type` | The type of all arguments of the mock function as a tuple |
|
||||
| `return_type` | The return type of the mock function |
|
||||
| `function_type` | The type of the mock function |
|
||||
|
||||
For example, when using an `ACTION` as a stub action for mock function:
|
||||
```
|
||||
int DoSomething(bool flag, int* ptr);
|
||||
```
|
||||
we have:
|
||||
| **Pre-defined Symbol** | **Is Bound To** |
|
||||
|:-----------------------|:----------------|
|
||||
| `arg0` | the value of `flag` |
|
||||
| `arg0_type` | the type `bool` |
|
||||
| `arg1` | the value of `ptr` |
|
||||
| `arg1_type` | the type `int*` |
|
||||
| `args` | the tuple `(flag, ptr)` |
|
||||
| `args_type` | the type `std::tr1::tuple<bool, int*>` |
|
||||
| `return_type` | the type `int` |
|
||||
| `function_type` | the type `int(bool, int*)` |
|
||||
|
||||
## Parameterized actions ##
|
||||
|
||||
Sometimes you'll want to parameterize the action. For that we propose
|
||||
another macro
|
||||
```
|
||||
ACTION_P(name, param) { statements; }
|
||||
```
|
||||
|
||||
For example,
|
||||
```
|
||||
ACTION_P(Add, n) { return arg0 + n; }
|
||||
```
|
||||
will allow you to write
|
||||
```
|
||||
// Returns argument #0 + 5.
|
||||
... WillOnce(Add(5));
|
||||
```
|
||||
|
||||
For convenience, we use the term _arguments_ for the values used to
|
||||
invoke the mock function, and the term _parameters_ for the values
|
||||
used to instantiate an action.
|
||||
|
||||
Note that you don't need to provide the type of the parameter either.
|
||||
Suppose the parameter is named `param`, you can also use the
|
||||
Google-Mock-defined symbol `param_type` to refer to the type of the
|
||||
parameter as inferred by the compiler.
|
||||
|
||||
We will also provide `ACTION_P2`, `ACTION_P3`, and etc to support
|
||||
multi-parameter actions. For example,
|
||||
```
|
||||
ACTION_P2(ReturnDistanceTo, x, y) {
|
||||
double dx = arg0 - x;
|
||||
double dy = arg1 - y;
|
||||
return sqrt(dx*dx + dy*dy);
|
||||
}
|
||||
```
|
||||
lets you write
|
||||
```
|
||||
... WillOnce(ReturnDistanceTo(5.0, 26.5));
|
||||
```
|
||||
|
||||
You can view `ACTION` as a degenerated parameterized action where the
|
||||
number of parameters is 0.
|
||||
|
||||
## Advanced Usages ##
|
||||
|
||||
### Overloading Actions ###
|
||||
|
||||
You can easily define actions overloaded on the number of parameters:
|
||||
```
|
||||
ACTION_P(Plus, a) { ... }
|
||||
ACTION_P2(Plus, a, b) { ... }
|
||||
```
|
||||
|
||||
### Restricting the Type of an Argument or Parameter ###
|
||||
|
||||
For maximum brevity and reusability, the `ACTION*` macros don't let
|
||||
you specify the types of the mock function arguments and the action
|
||||
parameters. Instead, we let the compiler infer the types for us.
|
||||
|
||||
Sometimes, however, we may want to be more explicit about the types.
|
||||
There are several tricks to do that. For example:
|
||||
```
|
||||
ACTION(Foo) {
|
||||
// Makes sure arg0 can be converted to int.
|
||||
int n = arg0;
|
||||
... use n instead of arg0 here ...
|
||||
}
|
||||
|
||||
ACTION_P(Bar, param) {
|
||||
// Makes sure the type of arg1 is const char*.
|
||||
::testing::StaticAssertTypeEq<const char*, arg1_type>();
|
||||
|
||||
// Makes sure param can be converted to bool.
|
||||
bool flag = param;
|
||||
}
|
||||
```
|
||||
where `StaticAssertTypeEq` is a compile-time assertion we plan to add to
|
||||
Google Test (the name is chosen to match `static_assert` in C++0x).
|
||||
|
||||
### Using the ACTION Object's Type ###
|
||||
|
||||
If you are writing a function that returns an `ACTION` object, you'll
|
||||
need to know its type. The type depends on the macro used to define
|
||||
the action and the parameter types. The rule is relatively simple:
|
||||
| **Given Definition** | **Expression** | **Has Type** |
|
||||
|:---------------------|:---------------|:-------------|
|
||||
| `ACTION(Foo)` | `Foo()` | `FooAction` |
|
||||
| `ACTION_P(Bar, param)` | `Bar(int_value)` | `BarActionP<int>` |
|
||||
| `ACTION_P2(Baz, p1, p2)` | `Baz(bool_value, int_value)` | `BazActionP2<bool, int>` |
|
||||
| ... | ... | ... |
|
||||
|
||||
Note that we have to pick different suffixes (`Action`, `ActionP`,
|
||||
`ActionP2`, and etc) for actions with different numbers of parameters,
|
||||
or the action definitions cannot be overloaded on the number of
|
||||
parameters.
|
||||
|
||||
## When to Use ##
|
||||
|
||||
While the new macros are very convenient, please also consider other
|
||||
means of implementing actions (e.g. via `ActionInterface` or
|
||||
`MakePolymorphicAction()`), especially if you need to use the defined
|
||||
action a lot. While the other approaches require more work, they give
|
||||
you more control on the types of the mock function arguments and the
|
||||
action parameters, which in general leads to better compiler error
|
||||
messages that pay off in the long run. They also allow overloading
|
||||
actions based on parameter types, as opposed to just the number of
|
||||
parameters.
|
||||
|
||||
## Related Work ##
|
||||
|
||||
As you may have realized, the `ACTION*` macros resemble closures (also
|
||||
known as lambda expressions or anonymous functions). Indeed, both of
|
||||
them seek to lower the syntactic overhead for defining a function.
|
||||
|
||||
C++0x will support lambdas, but they are not part of C++ right now.
|
||||
Some non-standard libraries (most notably BLL or Boost Lambda Library)
|
||||
try to alleviate this problem. However, they are not a good choice
|
||||
for defining actions as:
|
||||
|
||||
* They are non-standard and not widely installed. Google Mock only depends on standard libraries and `tr1::tuple`, which is part of the new C++ standard and comes with gcc 4+. We want to keep it that way.
|
||||
* They are not trivial to learn.
|
||||
* They will become obsolete when C++0x's lambda feature is widely supported. We don't want to make our users use a dying library.
|
||||
* Since they are based on operators, they are rather ad hoc: you cannot use statements, and you cannot pass the lambda arguments to a function, for example.
|
||||
* They have subtle semantics that easily confuses new users. For example, in expression `_1++ + foo++`, `foo` will be incremented only once where the expression is evaluated, while `_1` will be incremented every time the unnamed function is invoked. This is far from intuitive.
|
||||
|
||||
`ACTION*` avoid all these problems.
|
||||
|
||||
## Future Improvements ##
|
||||
|
||||
There may be a need for composing `ACTION*` definitions (i.e. invoking
|
||||
another `ACTION` inside the definition of one `ACTION*`). We are not
|
||||
sure we want it yet, as one can get a similar effect by putting
|
||||
`ACTION` definitions in function templates and composing the function
|
||||
templates. We'll revisit this based on user feedback.
|
||||
|
||||
The reason we don't allow `ACTION*()` inside a function body is that
|
||||
the current C++ standard doesn't allow function-local types to be used
|
||||
to instantiate templates. The upcoming C++0x standard will lift this
|
||||
restriction. Once this feature is widely supported by compilers, we
|
||||
can revisit the implementation and add support for using `ACTION*()`
|
||||
inside a function.
|
||||
|
||||
C++0x will also support lambda expressions. When they become
|
||||
available, we may want to support using lambdas as actions.
|
||||
|
||||
# Macros for Defining Matchers #
|
||||
|
||||
Once the macros for defining actions are implemented, we plan to do
|
||||
the same for matchers:
|
||||
|
||||
```
|
||||
MATCHER(name) { statements; }
|
||||
```
|
||||
|
||||
where you can refer to the value being matched as `arg`. For example,
|
||||
given:
|
||||
|
||||
```
|
||||
MATCHER(IsPositive) { return arg > 0; }
|
||||
```
|
||||
|
||||
you can use `IsPositive()` as a matcher that matches a value iff it is
|
||||
greater than 0.
|
||||
|
||||
We will also add `MATCHER_P`, `MATCHER_P2`, and etc for parameterized
|
||||
matchers.
|
|
@ -1,132 +0,0 @@
|
|||
|
||||
|
||||
If you are interested in understanding the internals of Google Mock,
|
||||
building from source, or contributing ideas or modifications to the
|
||||
project, then this document is for you.
|
||||
|
||||
# Introduction #
|
||||
|
||||
First, let's give you some background of the project.
|
||||
|
||||
## Licensing ##
|
||||
|
||||
All Google Mock source and pre-built packages are provided under the [New BSD License](http://www.opensource.org/licenses/bsd-license.php).
|
||||
|
||||
## The Google Mock Community ##
|
||||
|
||||
The Google Mock community exists primarily through the [discussion group](http://groups.google.com/group/googlemock), the
|
||||
[issue tracker](https://github.com/google/googletest/issues) and, to a lesser extent, the [source control repository](../). You are definitely encouraged to contribute to the
|
||||
discussion and you can also help us to keep the effectiveness of the
|
||||
group high by following and promoting the guidelines listed here.
|
||||
|
||||
### Please Be Friendly ###
|
||||
|
||||
Showing courtesy and respect to others is a vital part of the Google
|
||||
culture, and we strongly encourage everyone participating in Google
|
||||
Mock development to join us in accepting nothing less. Of course,
|
||||
being courteous is not the same as failing to constructively disagree
|
||||
with each other, but it does mean that we should be respectful of each
|
||||
other when enumerating the 42 technical reasons that a particular
|
||||
proposal may not be the best choice. There's never a reason to be
|
||||
antagonistic or dismissive toward anyone who is sincerely trying to
|
||||
contribute to a discussion.
|
||||
|
||||
Sure, C++ testing is serious business and all that, but it's also
|
||||
a lot of fun. Let's keep it that way. Let's strive to be one of the
|
||||
friendliest communities in all of open source.
|
||||
|
||||
### Where to Discuss Google Mock ###
|
||||
|
||||
As always, discuss Google Mock in the official [Google C++ Mocking Framework discussion group](http://groups.google.com/group/googlemock). You don't have to actually submit
|
||||
code in order to sign up. Your participation itself is a valuable
|
||||
contribution.
|
||||
|
||||
# Working with the Code #
|
||||
|
||||
If you want to get your hands dirty with the code inside Google Mock,
|
||||
this is the section for you.
|
||||
|
||||
## Checking Out the Source from Subversion ##
|
||||
|
||||
Checking out the Google Mock source is most useful if you plan to
|
||||
tweak it yourself. You check out the source for Google Mock using a
|
||||
[Subversion](http://subversion.tigris.org/) client as you would for any
|
||||
other project hosted on Google Code. Please see the instruction on
|
||||
the [source code access page](../) for how to do it.
|
||||
|
||||
## Compiling from Source ##
|
||||
|
||||
Once you check out the code, you can find instructions on how to
|
||||
compile it in the [README](../README.md) file.
|
||||
|
||||
## Testing ##
|
||||
|
||||
A mocking framework is of no good if itself is not thoroughly tested.
|
||||
Tests should be written for any new code, and changes should be
|
||||
verified to not break existing tests before they are submitted for
|
||||
review. To perform the tests, follow the instructions in [README](http://code.google.com/p/googlemock/source/browse/trunk/README) and
|
||||
verify that there are no failures.
|
||||
|
||||
# Contributing Code #
|
||||
|
||||
We are excited that Google Mock is now open source, and hope to get
|
||||
great patches from the community. Before you fire up your favorite IDE
|
||||
and begin hammering away at that new feature, though, please take the
|
||||
time to read this section and understand the process. While it seems
|
||||
rigorous, we want to keep a high standard of quality in the code
|
||||
base.
|
||||
|
||||
## Contributor License Agreements ##
|
||||
|
||||
You must sign a Contributor License Agreement (CLA) before we can
|
||||
accept any code. The CLA protects you and us.
|
||||
|
||||
* If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html).
|
||||
* If you work for a company that wants to allow you to contribute your work to Google Mock, then you'll need to sign a [corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html).
|
||||
|
||||
Follow either of the two links above to access the appropriate CLA and
|
||||
instructions for how to sign and return it.
|
||||
|
||||
## Coding Style ##
|
||||
|
||||
To keep the source consistent, readable, diffable and easy to merge,
|
||||
we use a fairly rigid coding style, as defined by the [google-styleguide](https://github.com/google/styleguide) project. All patches will be expected
|
||||
to conform to the style outlined [here](https://github.com/google/styleguide/blob/gh-pages/cppguide.xml).
|
||||
|
||||
## Submitting Patches ##
|
||||
|
||||
Please do submit code. Here's what you need to do:
|
||||
|
||||
1. Normally you should make your change against the SVN trunk instead of a branch or a tag, as the latter two are for release control and should be treated mostly as read-only.
|
||||
1. Decide which code you want to submit. A submission should be a set of changes that addresses one issue in the [Google Mock issue tracker](http://code.google.com/p/googlemock/issues/list). Please don't mix more than one logical change per submittal, because it makes the history hard to follow. If you want to make a change that doesn't have a corresponding issue in the issue tracker, please create one.
|
||||
1. Also, coordinate with team members that are listed on the issue in question. This ensures that work isn't being duplicated and communicating your plan early also generally leads to better patches.
|
||||
1. Ensure that your code adheres to the [Google Mock source code style](#Coding_Style.md).
|
||||
1. Ensure that there are unit tests for your code.
|
||||
1. Sign a Contributor License Agreement.
|
||||
1. Create a patch file using `svn diff`.
|
||||
1. We use [Rietveld](http://codereview.appspot.com/) to do web-based code reviews. You can read about the tool [here](https://github.com/rietveld-codereview/rietveld/wiki). When you are ready, upload your patch via Rietveld and notify `googlemock@googlegroups.com` to review it. There are several ways to upload the patch. We recommend using the [upload\_gmock.py](../scripts/upload_gmock.py) script, which you can find in the `scripts/` folder in the SVN trunk.
|
||||
|
||||
## Google Mock Committers ##
|
||||
|
||||
The current members of the Google Mock engineering team are the only
|
||||
committers at present. In the great tradition of eating one's own
|
||||
dogfood, we will be requiring each new Google Mock engineering team
|
||||
member to earn the right to become a committer by following the
|
||||
procedures in this document, writing consistently great code, and
|
||||
demonstrating repeatedly that he or she truly gets the zen of Google
|
||||
Mock.
|
||||
|
||||
# Release Process #
|
||||
|
||||
We follow the typical release process for Subversion-based projects:
|
||||
|
||||
1. A release branch named `release-X.Y` is created.
|
||||
1. Bugs are fixed and features are added in trunk; those individual patches are merged into the release branch until it's stable.
|
||||
1. An individual point release (the `Z` in `X.Y.Z`) is made by creating a tag from the branch.
|
||||
1. Repeat steps 2 and 3 throughout one release cycle (as determined by features or time).
|
||||
1. Go back to step 1 to create another release branch and so on.
|
||||
|
||||
|
||||
---
|
||||
|
||||
This page is based on the [Making GWT Better](http://code.google.com/webtoolkit/makinggwtbetter.html) guide from the [Google Web Toolkit](http://code.google.com/webtoolkit/) project. Except as otherwise [noted](http://code.google.com/policies.html#restrictions), the content of this page is licensed under the [Creative Commons Attribution 2.5 License](http://creativecommons.org/licenses/by/2.5/).
|
|
@ -1,12 +0,0 @@
|
|||
This page lists all documentation wiki pages for Google Mock **(the SVN trunk version)**
|
||||
- **if you use a released version of Google Mock, please read the documentation for that specific version instead.**
|
||||
|
||||
* [ForDummies](ForDummies.md) -- start here if you are new to Google Mock.
|
||||
* [CheatSheet](CheatSheet.md) -- a quick reference.
|
||||
* [CookBook](CookBook.md) -- recipes for doing various tasks using Google Mock.
|
||||
* [FrequentlyAskedQuestions](FrequentlyAskedQuestions.md) -- check here before asking a question on the mailing list.
|
||||
|
||||
To contribute code to Google Mock, read:
|
||||
|
||||
* [DevGuide](DevGuide.md) -- read this _before_ writing your first patch.
|
||||
* [Pump Manual](../googletest/docs/PumpManual.md) -- how we generate some of Google Mock's source files.
|
|
@ -1,439 +0,0 @@
|
|||
|
||||
|
||||
(**Note:** If you get compiler errors that you don't understand, be sure to consult [Google Mock Doctor](FrequentlyAskedQuestions.md#how-am-i-supposed-to-make-sense-of-these-horrible-template-errors).)
|
||||
|
||||
# What Is Google C++ Mocking Framework? #
|
||||
When you write a prototype or test, often it's not feasible or wise to rely on real objects entirely. A **mock object** implements the same interface as a real object (so it can be used as one), but lets you specify at run time how it will be used and what it should do (which methods will be called? in which order? how many times? with what arguments? what will they return? etc).
|
||||
|
||||
**Note:** It is easy to confuse the term _fake objects_ with mock objects. Fakes and mocks actually mean very different things in the Test-Driven Development (TDD) community:
|
||||
|
||||
* **Fake** objects have working implementations, but usually take some shortcut (perhaps to make the operations less expensive), which makes them not suitable for production. An in-memory file system would be an example of a fake.
|
||||
* **Mocks** are objects pre-programmed with _expectations_, which form a specification of the calls they are expected to receive.
|
||||
|
||||
If all this seems too abstract for you, don't worry - the most important thing to remember is that a mock allows you to check the _interaction_ between itself and code that uses it. The difference between fakes and mocks will become much clearer once you start to use mocks.
|
||||
|
||||
**Google C++ Mocking Framework** (or **Google Mock** for short) is a library (sometimes we also call it a "framework" to make it sound cool) for creating mock classes and using them. It does to C++ what [jMock](http://www.jmock.org/) and [EasyMock](http://www.easymock.org/) do to Java.
|
||||
|
||||
Using Google Mock involves three basic steps:
|
||||
|
||||
1. Use some simple macros to describe the interface you want to mock, and they will expand to the implementation of your mock class;
|
||||
1. Create some mock objects and specify its expectations and behavior using an intuitive syntax;
|
||||
1. Exercise code that uses the mock objects. Google Mock will catch any violation of the expectations as soon as it arises.
|
||||
|
||||
# Why Google Mock? #
|
||||
While mock objects help you remove unnecessary dependencies in tests and make them fast and reliable, using mocks manually in C++ is _hard_:
|
||||
|
||||
* Someone has to implement the mocks. The job is usually tedious and error-prone. No wonder people go great distance to avoid it.
|
||||
* The quality of those manually written mocks is a bit, uh, unpredictable. You may see some really polished ones, but you may also see some that were hacked up in a hurry and have all sorts of ad hoc restrictions.
|
||||
* The knowledge you gained from using one mock doesn't transfer to the next.
|
||||
|
||||
In contrast, Java and Python programmers have some fine mock frameworks, which automate the creation of mocks. As a result, mocking is a proven effective technique and widely adopted practice in those communities. Having the right tool absolutely makes the difference.
|
||||
|
||||
Google Mock was built to help C++ programmers. It was inspired by [jMock](http://www.jmock.org/) and [EasyMock](http://www.easymock.org/), but designed with C++'s specifics in mind. It is your friend if any of the following problems is bothering you:
|
||||
|
||||
* You are stuck with a sub-optimal design and wish you had done more prototyping before it was too late, but prototyping in C++ is by no means "rapid".
|
||||
* Your tests are slow as they depend on too many libraries or use expensive resources (e.g. a database).
|
||||
* Your tests are brittle as some resources they use are unreliable (e.g. the network).
|
||||
* You want to test how your code handles a failure (e.g. a file checksum error), but it's not easy to cause one.
|
||||
* You need to make sure that your module interacts with other modules in the right way, but it's hard to observe the interaction; therefore you resort to observing the side effects at the end of the action, which is awkward at best.
|
||||
* You want to "mock out" your dependencies, except that they don't have mock implementations yet; and, frankly, you aren't thrilled by some of those hand-written mocks.
|
||||
|
||||
We encourage you to use Google Mock as:
|
||||
|
||||
* a _design_ tool, for it lets you experiment with your interface design early and often. More iterations lead to better designs!
|
||||
* a _testing_ tool to cut your tests' outbound dependencies and probe the interaction between your module and its collaborators.
|
||||
|
||||
# Getting Started #
|
||||
Using Google Mock is easy! Inside your C++ source file, just #include `"gtest/gtest.h"` and `"gmock/gmock.h"`, and you are ready to go.
|
||||
|
||||
# A Case for Mock Turtles #
|
||||
Let's look at an example. Suppose you are developing a graphics program that relies on a LOGO-like API for drawing. How would you test that it does the right thing? Well, you can run it and compare the screen with a golden screen snapshot, but let's admit it: tests like this are expensive to run and fragile (What if you just upgraded to a shiny new graphics card that has better anti-aliasing? Suddenly you have to update all your golden images.). It would be too painful if all your tests are like this. Fortunately, you learned about Dependency Injection and know the right thing to do: instead of having your application talk to the drawing API directly, wrap the API in an interface (say, `Turtle`) and code to that interface:
|
||||
|
||||
```
|
||||
class Turtle {
|
||||
...
|
||||
virtual ~Turtle() {}
|
||||
virtual void PenUp() = 0;
|
||||
virtual void PenDown() = 0;
|
||||
virtual void Forward(int distance) = 0;
|
||||
virtual void Turn(int degrees) = 0;
|
||||
virtual void GoTo(int x, int y) = 0;
|
||||
virtual int GetX() const = 0;
|
||||
virtual int GetY() const = 0;
|
||||
};
|
||||
```
|
||||
|
||||
(Note that the destructor of `Turtle` **must** be virtual, as is the case for **all** classes you intend to inherit from - otherwise the destructor of the derived class will not be called when you delete an object through a base pointer, and you'll get corrupted program states like memory leaks.)
|
||||
|
||||
You can control whether the turtle's movement will leave a trace using `PenUp()` and `PenDown()`, and control its movement using `Forward()`, `Turn()`, and `GoTo()`. Finally, `GetX()` and `GetY()` tell you the current position of the turtle.
|
||||
|
||||
Your program will normally use a real implementation of this interface. In tests, you can use a mock implementation instead. This allows you to easily check what drawing primitives your program is calling, with what arguments, and in which order. Tests written this way are much more robust (they won't break because your new machine does anti-aliasing differently), easier to read and maintain (the intent of a test is expressed in the code, not in some binary images), and run _much, much faster_.
|
||||
|
||||
# Writing the Mock Class #
|
||||
If you are lucky, the mocks you need to use have already been implemented by some nice people. If, however, you find yourself in the position to write a mock class, relax - Google Mock turns this task into a fun game! (Well, almost.)
|
||||
|
||||
## How to Define It ##
|
||||
Using the `Turtle` interface as example, here are the simple steps you need to follow:
|
||||
|
||||
1. Derive a class `MockTurtle` from `Turtle`.
|
||||
1. Take a _virtual_ function of `Turtle` (while it's possible to [mock non-virtual methods using templates](CookBook.md#mocking-nonvirtual-methods), it's much more involved). Count how many arguments it has.
|
||||
1. In the `public:` section of the child class, write `MOCK_METHODn();` (or `MOCK_CONST_METHODn();` if you are mocking a `const` method), where `n` is the number of the arguments; if you counted wrong, shame on you, and a compiler error will tell you so.
|
||||
1. Now comes the fun part: you take the function signature, cut-and-paste the _function name_ as the _first_ argument to the macro, and leave what's left as the _second_ argument (in case you're curious, this is the _type of the function_).
|
||||
1. Repeat until all virtual functions you want to mock are done.
|
||||
|
||||
After the process, you should have something like:
|
||||
|
||||
```
|
||||
#include "gmock/gmock.h" // Brings in Google Mock.
|
||||
class MockTurtle : public Turtle {
|
||||
public:
|
||||
...
|
||||
MOCK_METHOD0(PenUp, void());
|
||||
MOCK_METHOD0(PenDown, void());
|
||||
MOCK_METHOD1(Forward, void(int distance));
|
||||
MOCK_METHOD1(Turn, void(int degrees));
|
||||
MOCK_METHOD2(GoTo, void(int x, int y));
|
||||
MOCK_CONST_METHOD0(GetX, int());
|
||||
MOCK_CONST_METHOD0(GetY, int());
|
||||
};
|
||||
```
|
||||
|
||||
You don't need to define these mock methods somewhere else - the `MOCK_METHOD*` macros will generate the definitions for you. It's that simple! Once you get the hang of it, you can pump out mock classes faster than your source-control system can handle your check-ins.
|
||||
|
||||
**Tip:** If even this is too much work for you, you'll find the
|
||||
`gmock_gen.py` tool in Google Mock's `scripts/generator/` directory (courtesy of the [cppclean](http://code.google.com/p/cppclean/) project) useful. This command-line
|
||||
tool requires that you have Python 2.4 installed. You give it a C++ file and the name of an abstract class defined in it,
|
||||
and it will print the definition of the mock class for you. Due to the
|
||||
complexity of the C++ language, this script may not always work, but
|
||||
it can be quite handy when it does. For more details, read the [user documentation](../scripts/generator/README).
|
||||
|
||||
## Where to Put It ##
|
||||
When you define a mock class, you need to decide where to put its definition. Some people put it in a `*_test.cc`. This is fine when the interface being mocked (say, `Foo`) is owned by the same person or team. Otherwise, when the owner of `Foo` changes it, your test could break. (You can't really expect `Foo`'s maintainer to fix every test that uses `Foo`, can you?)
|
||||
|
||||
So, the rule of thumb is: if you need to mock `Foo` and it's owned by others, define the mock class in `Foo`'s package (better, in a `testing` sub-package such that you can clearly separate production code and testing utilities), and put it in a `mock_foo.h`. Then everyone can reference `mock_foo.h` from their tests. If `Foo` ever changes, there is only one copy of `MockFoo` to change, and only tests that depend on the changed methods need to be fixed.
|
||||
|
||||
Another way to do it: you can introduce a thin layer `FooAdaptor` on top of `Foo` and code to this new interface. Since you own `FooAdaptor`, you can absorb changes in `Foo` much more easily. While this is more work initially, carefully choosing the adaptor interface can make your code easier to write and more readable (a net win in the long run), as you can choose `FooAdaptor` to fit your specific domain much better than `Foo` does.
|
||||
|
||||
# Using Mocks in Tests #
|
||||
Once you have a mock class, using it is easy. The typical work flow is:
|
||||
|
||||
1. Import the Google Mock names from the `testing` namespace such that you can use them unqualified (You only have to do it once per file. Remember that namespaces are a good idea and good for your health.).
|
||||
1. Create some mock objects.
|
||||
1. Specify your expectations on them (How many times will a method be called? With what arguments? What should it do? etc.).
|
||||
1. Exercise some code that uses the mocks; optionally, check the result using Google Test assertions. If a mock method is called more than expected or with wrong arguments, you'll get an error immediately.
|
||||
1. When a mock is destructed, Google Mock will automatically check whether all expectations on it have been satisfied.
|
||||
|
||||
Here's an example:
|
||||
|
||||
```
|
||||
#include "path/to/mock-turtle.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
using ::testing::AtLeast; // #1
|
||||
|
||||
TEST(PainterTest, CanDrawSomething) {
|
||||
MockTurtle turtle; // #2
|
||||
EXPECT_CALL(turtle, PenDown()) // #3
|
||||
.Times(AtLeast(1));
|
||||
|
||||
Painter painter(&turtle); // #4
|
||||
|
||||
EXPECT_TRUE(painter.DrawCircle(0, 0, 10));
|
||||
} // #5
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// The following line must be executed to initialize Google Mock
|
||||
// (and Google Test) before running the tests.
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
```
|
||||
|
||||
As you might have guessed, this test checks that `PenDown()` is called at least once. If the `painter` object didn't call this method, your test will fail with a message like this:
|
||||
|
||||
```
|
||||
path/to/my_test.cc:119: Failure
|
||||
Actual function call count doesn't match this expectation:
|
||||
Actually: never called;
|
||||
Expected: called at least once.
|
||||
```
|
||||
|
||||
**Tip 1:** If you run the test from an Emacs buffer, you can hit `<Enter>` on the line number displayed in the error message to jump right to the failed expectation.
|
||||
|
||||
**Tip 2:** If your mock objects are never deleted, the final verification won't happen. Therefore it's a good idea to use a heap leak checker in your tests when you allocate mocks on the heap.
|
||||
|
||||
**Important note:** Google Mock requires expectations to be set **before** the mock functions are called, otherwise the behavior is **undefined**. In particular, you mustn't interleave `EXPECT_CALL()`s and calls to the mock functions.
|
||||
|
||||
This means `EXPECT_CALL()` should be read as expecting that a call will occur _in the future_, not that a call has occurred. Why does Google Mock work like that? Well, specifying the expectation beforehand allows Google Mock to report a violation as soon as it arises, when the context (stack trace, etc) is still available. This makes debugging much easier.
|
||||
|
||||
Admittedly, this test is contrived and doesn't do much. You can easily achieve the same effect without using Google Mock. However, as we shall reveal soon, Google Mock allows you to do _much more_ with the mocks.
|
||||
|
||||
## Using Google Mock with Any Testing Framework ##
|
||||
If you want to use something other than Google Test (e.g. [CppUnit](http://sourceforge.net/projects/cppunit/) or
|
||||
[CxxTest](http://cxxtest.tigris.org/)) as your testing framework, just change the `main()` function in the previous section to:
|
||||
```
|
||||
int main(int argc, char** argv) {
|
||||
// The following line causes Google Mock to throw an exception on failure,
|
||||
// which will be interpreted by your testing framework as a test failure.
|
||||
::testing::GTEST_FLAG(throw_on_failure) = true;
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
... whatever your testing framework requires ...
|
||||
}
|
||||
```
|
||||
|
||||
This approach has a catch: it makes Google Mock throw an exception
|
||||
from a mock object's destructor sometimes. With some compilers, this
|
||||
sometimes causes the test program to crash. You'll still be able to
|
||||
notice that the test has failed, but it's not a graceful failure.
|
||||
|
||||
A better solution is to use Google Test's
|
||||
[event listener API](../../googletest/docs/AdvancedGuide.md#extending-google-test-by-handling-test-events)
|
||||
to report a test failure to your testing framework properly. You'll need to
|
||||
implement the `OnTestPartResult()` method of the event listener interface, but it
|
||||
should be straightforward.
|
||||
|
||||
If this turns out to be too much work, we suggest that you stick with
|
||||
Google Test, which works with Google Mock seamlessly (in fact, it is
|
||||
technically part of Google Mock.). If there is a reason that you
|
||||
cannot use Google Test, please let us know.
|
||||
|
||||
# Setting Expectations #
|
||||
The key to using a mock object successfully is to set the _right expectations_ on it. If you set the expectations too strict, your test will fail as the result of unrelated changes. If you set them too loose, bugs can slip through. You want to do it just right such that your test can catch exactly the kind of bugs you intend it to catch. Google Mock provides the necessary means for you to do it "just right."
|
||||
|
||||
## General Syntax ##
|
||||
In Google Mock we use the `EXPECT_CALL()` macro to set an expectation on a mock method. The general syntax is:
|
||||
|
||||
```
|
||||
EXPECT_CALL(mock_object, method(matchers))
|
||||
.Times(cardinality)
|
||||
.WillOnce(action)
|
||||
.WillRepeatedly(action);
|
||||
```
|
||||
|
||||
The macro has two arguments: first the mock object, and then the method and its arguments. Note that the two are separated by a comma (`,`), not a period (`.`). (Why using a comma? The answer is that it was necessary for technical reasons.)
|
||||
|
||||
The macro can be followed by some optional _clauses_ that provide more information about the expectation. We'll discuss how each clause works in the coming sections.
|
||||
|
||||
This syntax is designed to make an expectation read like English. For example, you can probably guess that
|
||||
|
||||
```
|
||||
using ::testing::Return;...
|
||||
EXPECT_CALL(turtle, GetX())
|
||||
.Times(5)
|
||||
.WillOnce(Return(100))
|
||||
.WillOnce(Return(150))
|
||||
.WillRepeatedly(Return(200));
|
||||
```
|
||||
|
||||
says that the `turtle` object's `GetX()` method will be called five times, it will return 100 the first time, 150 the second time, and then 200 every time. Some people like to call this style of syntax a Domain-Specific Language (DSL).
|
||||
|
||||
**Note:** Why do we use a macro to do this? It serves two purposes: first it makes expectations easily identifiable (either by `grep` or by a human reader), and second it allows Google Mock to include the source file location of a failed expectation in messages, making debugging easier.
|
||||
|
||||
## Matchers: What Arguments Do We Expect? ##
|
||||
When a mock function takes arguments, we must specify what arguments we are expecting; for example:
|
||||
|
||||
```
|
||||
// Expects the turtle to move forward by 100 units.
|
||||
EXPECT_CALL(turtle, Forward(100));
|
||||
```
|
||||
|
||||
Sometimes you may not want to be too specific (Remember that talk about tests being too rigid? Over specification leads to brittle tests and obscures the intent of tests. Therefore we encourage you to specify only what's necessary - no more, no less.). If you care to check that `Forward()` will be called but aren't interested in its actual argument, write `_` as the argument, which means "anything goes":
|
||||
|
||||
```
|
||||
using ::testing::_;
|
||||
...
|
||||
// Expects the turtle to move forward.
|
||||
EXPECT_CALL(turtle, Forward(_));
|
||||
```
|
||||
|
||||
`_` is an instance of what we call **matchers**. A matcher is like a predicate and can test whether an argument is what we'd expect. You can use a matcher inside `EXPECT_CALL()` wherever a function argument is expected.
|
||||
|
||||
A list of built-in matchers can be found in the [CheatSheet](CheatSheet.md). For example, here's the `Ge` (greater than or equal) matcher:
|
||||
|
||||
```
|
||||
using ::testing::Ge;...
|
||||
EXPECT_CALL(turtle, Forward(Ge(100)));
|
||||
```
|
||||
|
||||
This checks that the turtle will be told to go forward by at least 100 units.
|
||||
|
||||
## Cardinalities: How Many Times Will It Be Called? ##
|
||||
The first clause we can specify following an `EXPECT_CALL()` is `Times()`. We call its argument a **cardinality** as it tells _how many times_ the call should occur. It allows us to repeat an expectation many times without actually writing it as many times. More importantly, a cardinality can be "fuzzy", just like a matcher can be. This allows a user to express the intent of a test exactly.
|
||||
|
||||
An interesting special case is when we say `Times(0)`. You may have guessed - it means that the function shouldn't be called with the given arguments at all, and Google Mock will report a Google Test failure whenever the function is (wrongfully) called.
|
||||
|
||||
We've seen `AtLeast(n)` as an example of fuzzy cardinalities earlier. For the list of built-in cardinalities you can use, see the [CheatSheet](CheatSheet.md).
|
||||
|
||||
The `Times()` clause can be omitted. **If you omit `Times()`, Google Mock will infer the cardinality for you.** The rules are easy to remember:
|
||||
|
||||
* If **neither** `WillOnce()` **nor** `WillRepeatedly()` is in the `EXPECT_CALL()`, the inferred cardinality is `Times(1)`.
|
||||
* If there are `n WillOnce()`'s but **no** `WillRepeatedly()`, where `n` >= 1, the cardinality is `Times(n)`.
|
||||
* If there are `n WillOnce()`'s and **one** `WillRepeatedly()`, where `n` >= 0, the cardinality is `Times(AtLeast(n))`.
|
||||
|
||||
**Quick quiz:** what do you think will happen if a function is expected to be called twice but actually called four times?
|
||||
|
||||
## Actions: What Should It Do? ##
|
||||
Remember that a mock object doesn't really have a working implementation? We as users have to tell it what to do when a method is invoked. This is easy in Google Mock.
|
||||
|
||||
First, if the return type of a mock function is a built-in type or a pointer, the function has a **default action** (a `void` function will just return, a `bool` function will return `false`, and other functions will return 0). In addition, in C++ 11 and above, a mock function whose return type is default-constructible (i.e. has a default constructor) has a default action of returning a default-constructed value. If you don't say anything, this behavior will be used.
|
||||
|
||||
Second, if a mock function doesn't have a default action, or the default action doesn't suit you, you can specify the action to be taken each time the expectation matches using a series of `WillOnce()` clauses followed by an optional `WillRepeatedly()`. For example,
|
||||
|
||||
```
|
||||
using ::testing::Return;...
|
||||
EXPECT_CALL(turtle, GetX())
|
||||
.WillOnce(Return(100))
|
||||
.WillOnce(Return(200))
|
||||
.WillOnce(Return(300));
|
||||
```
|
||||
|
||||
This says that `turtle.GetX()` will be called _exactly three times_ (Google Mock inferred this from how many `WillOnce()` clauses we've written, since we didn't explicitly write `Times()`), and will return 100, 200, and 300 respectively.
|
||||
|
||||
```
|
||||
using ::testing::Return;...
|
||||
EXPECT_CALL(turtle, GetY())
|
||||
.WillOnce(Return(100))
|
||||
.WillOnce(Return(200))
|
||||
.WillRepeatedly(Return(300));
|
||||
```
|
||||
|
||||
says that `turtle.GetY()` will be called _at least twice_ (Google Mock knows this as we've written two `WillOnce()` clauses and a `WillRepeatedly()` while having no explicit `Times()`), will return 100 the first time, 200 the second time, and 300 from the third time on.
|
||||
|
||||
Of course, if you explicitly write a `Times()`, Google Mock will not try to infer the cardinality itself. What if the number you specified is larger than there are `WillOnce()` clauses? Well, after all `WillOnce()`s are used up, Google Mock will do the _default_ action for the function every time (unless, of course, you have a `WillRepeatedly()`.).
|
||||
|
||||
What can we do inside `WillOnce()` besides `Return()`? You can return a reference using `ReturnRef(variable)`, or invoke a pre-defined function, among [others](CheatSheet.md#actions).
|
||||
|
||||
**Important note:** The `EXPECT_CALL()` statement evaluates the action clause only once, even though the action may be performed many times. Therefore you must be careful about side effects. The following may not do what you want:
|
||||
|
||||
```
|
||||
int n = 100;
|
||||
EXPECT_CALL(turtle, GetX())
|
||||
.Times(4)
|
||||
.WillRepeatedly(Return(n++));
|
||||
```
|
||||
|
||||
Instead of returning 100, 101, 102, ..., consecutively, this mock function will always return 100 as `n++` is only evaluated once. Similarly, `Return(new Foo)` will create a new `Foo` object when the `EXPECT_CALL()` is executed, and will return the same pointer every time. If you want the side effect to happen every time, you need to define a custom action, which we'll teach in the [CookBook](CookBook.md).
|
||||
|
||||
Time for another quiz! What do you think the following means?
|
||||
|
||||
```
|
||||
using ::testing::Return;...
|
||||
EXPECT_CALL(turtle, GetY())
|
||||
.Times(4)
|
||||
.WillOnce(Return(100));
|
||||
```
|
||||
|
||||
Obviously `turtle.GetY()` is expected to be called four times. But if you think it will return 100 every time, think twice! Remember that one `WillOnce()` clause will be consumed each time the function is invoked and the default action will be taken afterwards. So the right answer is that `turtle.GetY()` will return 100 the first time, but **return 0 from the second time on**, as returning 0 is the default action for `int` functions.
|
||||
|
||||
## Using Multiple Expectations ##
|
||||
So far we've only shown examples where you have a single expectation. More realistically, you're going to specify expectations on multiple mock methods, which may be from multiple mock objects.
|
||||
|
||||
By default, when a mock method is invoked, Google Mock will search the expectations in the **reverse order** they are defined, and stop when an active expectation that matches the arguments is found (you can think of it as "newer rules override older ones."). If the matching expectation cannot take any more calls, you will get an upper-bound-violated failure. Here's an example:
|
||||
|
||||
```
|
||||
using ::testing::_;...
|
||||
EXPECT_CALL(turtle, Forward(_)); // #1
|
||||
EXPECT_CALL(turtle, Forward(10)) // #2
|
||||
.Times(2);
|
||||
```
|
||||
|
||||
If `Forward(10)` is called three times in a row, the third time it will be an error, as the last matching expectation (#2) has been saturated. If, however, the third `Forward(10)` call is replaced by `Forward(20)`, then it would be OK, as now #1 will be the matching expectation.
|
||||
|
||||
**Side note:** Why does Google Mock search for a match in the _reverse_ order of the expectations? The reason is that this allows a user to set up the default expectations in a mock object's constructor or the test fixture's set-up phase and then customize the mock by writing more specific expectations in the test body. So, if you have two expectations on the same method, you want to put the one with more specific matchers **after** the other, or the more specific rule would be shadowed by the more general one that comes after it.
|
||||
|
||||
## Ordered vs Unordered Calls ##
|
||||
By default, an expectation can match a call even though an earlier expectation hasn't been satisfied. In other words, the calls don't have to occur in the order the expectations are specified.
|
||||
|
||||
Sometimes, you may want all the expected calls to occur in a strict order. To say this in Google Mock is easy:
|
||||
|
||||
```
|
||||
using ::testing::InSequence;...
|
||||
TEST(FooTest, DrawsLineSegment) {
|
||||
...
|
||||
{
|
||||
InSequence dummy;
|
||||
|
||||
EXPECT_CALL(turtle, PenDown());
|
||||
EXPECT_CALL(turtle, Forward(100));
|
||||
EXPECT_CALL(turtle, PenUp());
|
||||
}
|
||||
Foo();
|
||||
}
|
||||
```
|
||||
|
||||
By creating an object of type `InSequence`, all expectations in its scope are put into a _sequence_ and have to occur _sequentially_. Since we are just relying on the constructor and destructor of this object to do the actual work, its name is really irrelevant.
|
||||
|
||||
In this example, we test that `Foo()` calls the three expected functions in the order as written. If a call is made out-of-order, it will be an error.
|
||||
|
||||
(What if you care about the relative order of some of the calls, but not all of them? Can you specify an arbitrary partial order? The answer is ... yes! If you are impatient, the details can be found in the [CookBook](CookBook#Expecting_Partially_Ordered_Calls.md).)
|
||||
|
||||
## All Expectations Are Sticky (Unless Said Otherwise) ##
|
||||
Now let's do a quick quiz to see how well you can use this mock stuff already. How would you test that the turtle is asked to go to the origin _exactly twice_ (you want to ignore any other instructions it receives)?
|
||||
|
||||
After you've come up with your answer, take a look at ours and compare notes (solve it yourself first - don't cheat!):
|
||||
|
||||
```
|
||||
using ::testing::_;...
|
||||
EXPECT_CALL(turtle, GoTo(_, _)) // #1
|
||||
.Times(AnyNumber());
|
||||
EXPECT_CALL(turtle, GoTo(0, 0)) // #2
|
||||
.Times(2);
|
||||
```
|
||||
|
||||
Suppose `turtle.GoTo(0, 0)` is called three times. In the third time, Google Mock will see that the arguments match expectation #2 (remember that we always pick the last matching expectation). Now, since we said that there should be only two such calls, Google Mock will report an error immediately. This is basically what we've told you in the "Using Multiple Expectations" section above.
|
||||
|
||||
This example shows that **expectations in Google Mock are "sticky" by default**, in the sense that they remain active even after we have reached their invocation upper bounds. This is an important rule to remember, as it affects the meaning of the spec, and is **different** to how it's done in many other mocking frameworks (Why'd we do that? Because we think our rule makes the common cases easier to express and understand.).
|
||||
|
||||
Simple? Let's see if you've really understood it: what does the following code say?
|
||||
|
||||
```
|
||||
using ::testing::Return;
|
||||
...
|
||||
for (int i = n; i > 0; i--) {
|
||||
EXPECT_CALL(turtle, GetX())
|
||||
.WillOnce(Return(10*i));
|
||||
}
|
||||
```
|
||||
|
||||
If you think it says that `turtle.GetX()` will be called `n` times and will return 10, 20, 30, ..., consecutively, think twice! The problem is that, as we said, expectations are sticky. So, the second time `turtle.GetX()` is called, the last (latest) `EXPECT_CALL()` statement will match, and will immediately lead to an "upper bound exceeded" error - this piece of code is not very useful!
|
||||
|
||||
One correct way of saying that `turtle.GetX()` will return 10, 20, 30, ..., is to explicitly say that the expectations are _not_ sticky. In other words, they should _retire_ as soon as they are saturated:
|
||||
|
||||
```
|
||||
using ::testing::Return;
|
||||
...
|
||||
for (int i = n; i > 0; i--) {
|
||||
EXPECT_CALL(turtle, GetX())
|
||||
.WillOnce(Return(10*i))
|
||||
.RetiresOnSaturation();
|
||||
}
|
||||
```
|
||||
|
||||
And, there's a better way to do it: in this case, we expect the calls to occur in a specific order, and we line up the actions to match the order. Since the order is important here, we should make it explicit using a sequence:
|
||||
|
||||
```
|
||||
using ::testing::InSequence;
|
||||
using ::testing::Return;
|
||||
...
|
||||
{
|
||||
InSequence s;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
EXPECT_CALL(turtle, GetX())
|
||||
.WillOnce(Return(10*i))
|
||||
.RetiresOnSaturation();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
By the way, the other situation where an expectation may _not_ be sticky is when it's in a sequence - as soon as another expectation that comes after it in the sequence has been used, it automatically retires (and will never be used to match any call).
|
||||
|
||||
## Uninteresting Calls ##
|
||||
A mock object may have many methods, and not all of them are that interesting. For example, in some tests we may not care about how many times `GetX()` and `GetY()` get called.
|
||||
|
||||
In Google Mock, if you are not interested in a method, just don't say anything about it. If a call to this method occurs, you'll see a warning in the test output, but it won't be a failure.
|
||||
|
||||
# What Now? #
|
||||
Congratulations! You've learned enough about Google Mock to start using it. Now, you might want to join the [googlemock](http://groups.google.com/group/googlemock) discussion group and actually write some tests using Google Mock - it will be fun. Hey, it may even be addictive - you've been warned.
|
||||
|
||||
Then, if you feel like increasing your mock quotient, you should move on to the [CookBook](CookBook.md). You can learn many advanced features of Google Mock there -- and advance your level of enjoyment and testing bliss.
|