コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
114bd6e6ee
|
||
|
|
bdb843f2df
|
||
|
|
1941a9c168
|
||
|
|
a55a3849f9
|
||
|
|
3ae158b1a4
|
||
|
|
50e36725a9
|
||
|
|
e6064d3d37
|
||
|
|
8078ca06b1
|
||
|
|
e5188f19c1
|
||
|
|
7d574632f3
|
||
|
|
537c0de969
|
||
|
|
551e8d4620
|
||
|
|
a81e0b94b2
|
||
|
|
92e8aace30
|
||
|
|
767ac2d9de
|
||
|
|
7e6e78cd82
|
||
|
|
66abdacb91
|
||
|
|
779b6b8b0d
|
||
|
|
53461b59f4
|
||
|
|
0fc1456b3e
|
||
|
|
294d3475de
|
||
|
|
3971c60295
|
||
|
|
7e3715d423
|
||
|
|
d7b4bfe431
|
||
|
|
1d7644de97
|
||
|
|
9030fe55a8
|
||
|
|
3fbfeaa514
|
||
|
|
4bea943cf3
|
||
|
|
1824f9faaf
|
||
|
|
41b813e2bb
|
||
|
|
e1fa384f83
|
||
|
|
d455ed4659
|
検索条件に一致するファイルはありません
@@ -0,0 +1,24 @@
|
||||
NAudio
|
||||
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright © Mark Heath & Contributors
|
||||
|
||||
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,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 StAkira
|
||||
|
||||
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.
|
||||
+58
-2
@@ -1,5 +1,5 @@
|
||||
========================================
|
||||
UTAU for YMM4 v1.6.1
|
||||
UTAU for YMM4 v1.7.4
|
||||
========================================
|
||||
YukkuriMovieMaker4(YMM4)上で動作する、UTAU 音源から歌声を合成する
|
||||
音声合成プラグインです。
|
||||
@@ -57,6 +57,19 @@ WorldNet で分析して合成し直します。
|
||||
- アイテムの編集画面の「ノートを編集」から、音程・長さ・ビブラート・
|
||||
ポルタメント・表現曲線を編集できます。
|
||||
|
||||
- ノートエディターでノートを右で押すと品書きが出ます。選んだノートすべての
|
||||
オクターブ上げ下げ、長さを吸着に合わせる操作、音程曲線・ビブラート・
|
||||
発声タイミング・ノート全体を既定へ戻す操作、ノートのコピーと貼り付けを
|
||||
行えます。オクターブの上げ下げでノートどうしの音程差は変わりません。
|
||||
|
||||
- 品書きの「歌詞をまとめて編集」で、選んだノートの歌詞を別の窓で一度に
|
||||
書き換えられます。空白と改行で区切り、漢字とかなは 1 文字ずつ、引用符で
|
||||
囲んだ部分はまとめて 1 つのノートになります。歌詞の数がノートの数より
|
||||
多いときは余りを捨て、少ないときは残りのノートをそのままにします。
|
||||
|
||||
- 品書きの「別ウィンドウで編集」で、編集画面をそのまま別の窓へ移せます。
|
||||
窓を閉じると元の位置へ戻り、編集した内容はそのまま残ります。
|
||||
|
||||
- ノートエディターの工具列に出る文言が幅に収まらないときは、2 秒おいてから
|
||||
端まで送り、2 秒おいて戻ります。収まっているときは動きません。
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -96,6 +109,44 @@ WorldNet で分析して合成し直します。
|
||||
|
||||
- 本プラグインを使用する前に、YMM4 プロジェクトファイルのバックアップを
|
||||
作成することを推奨します。
|
||||
--------------------------------------------------------------------------------
|
||||
■ 不具合の報告
|
||||
--------------------------------------------------------------------------------
|
||||
本プラグインは、想定していない例外が起きたときに、その内容を開発者へ自動で
|
||||
送信します。同意は求めず、常に送信します。
|
||||
|
||||
送信する情報は次のとおりです。
|
||||
例外 : 型の完全名、メッセージ、スタックトレース
|
||||
発生位置 : モジュール名、関数名、ファイル名、行番号
|
||||
プラグイン : アセンブリ名、バージョン
|
||||
実行環境 : OS の名前とバージョン、.NET のバージョン、
|
||||
CPU のアーキテクチャ、論理プロセッサ数
|
||||
識別子 : YMM4 の起動ごとに決まるセッション識別子、報告ごとの識別子
|
||||
|
||||
利用者の名前、プロジェクトの名前、音源の名前、歌詞、音声ファイルの中身は
|
||||
送信しません。継続して個人を追跡する識別子も持ちません。セッション識別子は
|
||||
YMM4 を起動し直すと別の値になります。メッセージとファイル名に含まれる
|
||||
利用者名などの文字列は、送信の前に置き換えます。送信元の IP アドレスは
|
||||
受信側へ渡す手前で取り除いています。
|
||||
|
||||
送信するのは想定していない例外だけです。本プラグインが例外を握り潰す箇所と、
|
||||
YMM4 へ処理を返す境界の両方で報告します。画面の操作やバックグラウンドの
|
||||
処理で未処理になった例外も報告しますが、本プラグインのコードが関わる例外に
|
||||
限ります。YMM4 本体やほかのプラグインで起きた例外は送信しません。
|
||||
|
||||
次の例外は送信しません。
|
||||
利用者へ知らせるための失敗 : エイリアスが見つからない、合成できるノートが
|
||||
ない、セリフが空
|
||||
更新の確認の通信の失敗 : GitHub へ接続できない
|
||||
探索と設定ファイルの読み取りで想定している失敗 : フォルダーを開く権限が
|
||||
ない、文字コードを判別できない、パスが長すぎる
|
||||
|
||||
音源の音声ファイルを読み込めなかった場合は送信します。読み込みの不具合を
|
||||
見つけるためです。
|
||||
|
||||
送信できなかった報告は YMM4 のユーザーフォルダーへ退避し、次回の起動時に
|
||||
送り直します。送信も再送も非同期に行うため、起動と合成が遅くなることは
|
||||
ありません。
|
||||
--------------------------------------------------------------------------------
|
||||
■ 免責事項
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -112,10 +163,15 @@ WorldNet で分析して合成し直します。
|
||||
本プラグインは音声の分析と合成に WorldNet(MIT License)を同梱しています。
|
||||
WorldNet は M. Morise 氏の WORLD(修正 BSD License)を C# へ移植した物で、
|
||||
高速フーリエ変換には Takuya OOURA 氏の FFT パッケージを用いています。
|
||||
ライセンスの全文は同梱の LICENSE フォルダー(WorldNet.txt)に収録しています。
|
||||
音声ファイルの読み書きには NAudio(MIT License)を同梱しています。
|
||||
歌詞をまとめて編集するときの区切り方は OpenUtau(MIT License)の規約に
|
||||
合わせています。
|
||||
ライセンスの全文は同梱の LICENSE フォルダーに収録しています。
|
||||
WorldNet : Copyright (c) 2026 routersys
|
||||
NAudio : Copyright (c) Mark Heath & Contributors
|
||||
WORLD : Copyright (c) 2010 M. Morise
|
||||
Ooura FFT : Copyright Takuya OOURA, 1996-2001
|
||||
OpenUtau : Copyright (c) 2014 StAkira
|
||||
--------------------------------------------------------------------------------
|
||||
■ ライセンス
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
+24
-74
@@ -50,87 +50,37 @@ jobs:
|
||||
echo "TAG=$tag" >> $env:GITHUB_OUTPUT
|
||||
echo "VERSION=$($tag.TrimStart('v'))" >> $env:GITHUB_OUTPUT
|
||||
|
||||
- name: バージョン記載の照合と訂正
|
||||
- name: バージョン記載の照合
|
||||
shell: pwsh
|
||||
run: |
|
||||
function Read-TextKeepingBom {
|
||||
param([string]$Path)
|
||||
$bytes = [System.IO.File]::ReadAllBytes($Path)
|
||||
$hasBom = $bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF
|
||||
$offset = 0
|
||||
if ($hasBom) { $offset = 3 }
|
||||
return @{
|
||||
Text = [System.Text.Encoding]::UTF8.GetString($bytes, $offset, $bytes.Length - $offset)
|
||||
HasBom = $hasBom
|
||||
}
|
||||
}
|
||||
|
||||
function Write-TextKeepingBom {
|
||||
param([string]$Path, [string]$Text, [bool]$HasBom)
|
||||
$body = [System.Text.Encoding]::UTF8.GetBytes($Text)
|
||||
if ($HasBom) { $body = [byte[]](0xEF, 0xBB, 0xBF) + $body }
|
||||
[System.IO.File]::WriteAllBytes($Path, $body)
|
||||
}
|
||||
|
||||
function Repair-VersionFiles {
|
||||
param([string]$Root, [string]$Version, [string]$Tag)
|
||||
$changed = @()
|
||||
|
||||
$csprojPath = Join-Path $Root "UTAU/UTAU.csproj"
|
||||
$csproj = Read-TextKeepingBom -Path $csprojPath
|
||||
$wantedCsproj = "<Version>$Version</Version>"
|
||||
if (-not $csproj.Text.Contains($wantedCsproj)) {
|
||||
$updated = $csproj.Text -replace '<Version>[^<]*</Version>', $wantedCsproj
|
||||
if (-not $updated.Contains($wantedCsproj)) { throw "UTAU.csproj に <Version> が見つかりませんでした" }
|
||||
Write-TextKeepingBom -Path $csprojPath -Text $updated -HasBom $csproj.HasBom
|
||||
$changed += "UTAU/UTAU.csproj"
|
||||
}
|
||||
|
||||
$readmePath = Join-Path $Root ".github/Plugin_Readme.txt"
|
||||
$readme = Read-TextKeepingBom -Path $readmePath
|
||||
$wantedHeading = " UTAU for YMM4 $Tag"
|
||||
if (-not $readme.Text.Contains($wantedHeading)) {
|
||||
$updated = $readme.Text -replace '(?m)^( UTAU for YMM4 )v[0-9][^\r\n]*', "`${1}$Tag"
|
||||
if (-not $updated.Contains($wantedHeading)) { throw "Plugin_Readme.txt の見出しが見つかりませんでした" }
|
||||
Write-TextKeepingBom -Path $readmePath -Text $updated -HasBom $readme.HasBom
|
||||
$changed += ".github/Plugin_Readme.txt"
|
||||
}
|
||||
|
||||
return $changed
|
||||
}
|
||||
|
||||
$tag = "${{ steps.version.outputs.TAG }}"
|
||||
$tag = "${{ steps.version.outputs.TAG }}"
|
||||
$version = "${{ steps.version.outputs.VERSION }}"
|
||||
$changed = Repair-VersionFiles -Root "." -Version $version -Tag $tag
|
||||
$problems = @()
|
||||
|
||||
if ($changed.Count -eq 0) {
|
||||
$csprojPath = "UTAU/UTAU.csproj"
|
||||
$csproj = Get-Content $csprojPath -Raw
|
||||
if (-not $csproj.Contains("<Version>$version</Version>")) {
|
||||
$current = if ($csproj -match '<Version>([^<]*)</Version>') { $Matches[1] } else { "記載なし" }
|
||||
$problems += "$csprojPath の <Version> が $current です。$version にしてください。"
|
||||
}
|
||||
|
||||
$readmePath = ".github/Plugin_Readme.txt"
|
||||
$readme = Get-Content $readmePath -Raw
|
||||
if (-not $readme.Contains(" UTAU for YMM4 $tag")) {
|
||||
$current = if ($readme -match '(?m)^ UTAU for YMM4 (\S+)') { $Matches[1] } else { "記載なし" }
|
||||
$problems += "$readmePath の見出しが $current です。$tag にしてください。"
|
||||
}
|
||||
|
||||
if ($problems.Count -eq 0) {
|
||||
Write-Host "バージョン記載は $tag と一致しています"
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Host "タグと合わない記載を訂正しました: $($changed -join ', ')"
|
||||
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git fetch origin main --quiet
|
||||
|
||||
$sync = Join-Path $env:RUNNER_TEMP "version-sync"
|
||||
git worktree add $sync origin/main --quiet
|
||||
Repair-VersionFiles -Root $sync -Version $version -Tag $tag | Out-Null
|
||||
|
||||
Push-Location $sync
|
||||
git add -A
|
||||
$pending = git diff --cached --name-only
|
||||
if ($pending) {
|
||||
git commit -m "バージョンを${tag}へ合わせる" --quiet
|
||||
git push origin HEAD:main
|
||||
Write-Host "main へ訂正を反映しました"
|
||||
} else {
|
||||
Write-Host "main は既に $tag と一致しています"
|
||||
foreach ($problem in $problems) {
|
||||
Write-Host "::error::$problem"
|
||||
}
|
||||
Pop-Location
|
||||
|
||||
git worktree remove $sync --force
|
||||
Write-Host "::error::リリースの対象は $tag が指すコミットです。タグを付けた後で main へ訂正を積んでも、その訂正はリリースに入りません。タグを削除し、記載を直したコミットを積んでから付け直してください。"
|
||||
exit 1
|
||||
|
||||
- name: resx ファイルの生成(初回ビルド)
|
||||
shell: pwsh
|
||||
@@ -162,8 +112,8 @@ jobs:
|
||||
New-Item -ItemType Directory -Path $stageRoot -Force | Out-Null
|
||||
New-Item -ItemType Directory -Path "$stageRoot/LICENSE" -Force | Out-Null
|
||||
|
||||
foreach ($name in @("UTAU.dll", "WorldNet.dll")) {
|
||||
$path = "$outDir/$name"
|
||||
foreach ($path in @("$outDir/plugin/UTAU.dll", "$outDir/WorldNet.dll")) {
|
||||
$name = Split-Path $path -Leaf
|
||||
if (-not (Test-Path $path)) {
|
||||
Write-Error "ビルド結果に $name が見つかりませんでした: $path"
|
||||
exit 1
|
||||
|
||||
@@ -4,3 +4,6 @@
|
||||
[submodule "YMM4-GitHubUpdateNotifier"]
|
||||
path = YMM4-GitHubUpdateNotifier
|
||||
url = https://github.com/routersys/YMM4-GitHubUpdateNotifier.git
|
||||
[submodule "YMM4-Telemetry"]
|
||||
path = YMM4-Telemetry
|
||||
url = https://github.com/routersys/YMM4-Telemetry.git
|
||||
@@ -34,9 +34,10 @@ YukkuriMovieMaker4(YMM4)上で動作する、UTAU 音源から歌声を合
|
||||
9. [対応フォーマット](#対応フォーマット)
|
||||
10. [制限事項](#制限事項)
|
||||
11. [注意事項](#注意事項)
|
||||
12. [免責事項](#免責事項)
|
||||
13. [サードパーティライセンス](#サードパーティライセンス)
|
||||
14. [ライセンス](#ライセンス)
|
||||
12. [不具合の報告](#不具合の報告)
|
||||
13. [免責事項](#免責事項)
|
||||
14. [サードパーティライセンス](#サードパーティライセンス)
|
||||
15. [ライセンス](#ライセンス)
|
||||
|
||||
---
|
||||
|
||||
@@ -122,6 +123,12 @@ YukkuriMovieMaker4(YMM4)上で動作する、UTAU 音源から歌声を合
|
||||
- ノートを 2 回押すと音程の制御点を追加し、制御点を引くと動かし、右で押すと削除します。制御点の間の曲線は S 字・直線・R 字・J 字から選べます。
|
||||
- 下の帯では、子音速度・音量・モジュレーションをノートごとの棒として、フォルマントと息の量を曲線として引いて編集できます。
|
||||
- 休符の挿入、ノートの削除、すべてのノートの選択、表示範囲に合わせる操作をボタンから行えます。
|
||||
- ノートを右で押すと品書きが出ます。押したノートが選択に入っていないときは、そのノートだけを選び直します。選択の中を押したときは選択をそのまま保ちます。
|
||||
- 品書きからは、選んだノートすべてに対してオクターブ上げとオクターブ下げ、長さを吸着に合わせる操作を行えます。オクターブの上げ下げは、端に当たるノートがあるときは選択全体の移動量を縮めるため、ノートどうしの音程差は変わりません。長さを吸着に合わせる操作は、吸着なしのときは行いません。
|
||||
- 品書きの「戻す」からは、選んだノートすべての音程曲線・ビブラート・発声タイミング・ノート全体を既定へ戻せます。歌詞と音程と長さは残ります。
|
||||
- 品書きからノートをコピーして貼り付けられます。貼り付けたノートは選択の後ろに入り、そのまま選択されます。コピーした内容は別のアイテムの編集画面へも貼り付けられます。
|
||||
- 品書きの「歌詞をまとめて編集」では、選んだノートの歌詞を別の窓で一度に書き換えられます。空白と改行で区切り、漢字とかなは 1 文字ずつ、引用符で囲んだ部分はまとめて 1 つのノートになります。歌詞の数とノートの数を窓に表示し、歌詞の方が多いときは余りを捨て、ノートの方が多いときは残りのノートをそのままにします。
|
||||
- 品書きの「別ウィンドウで編集」では、編集画面をそのまま別の窓へ移せます。窓を閉じると元の位置へ戻り、編集した内容はそのまま残ります。窓を開いている間は「ノートを編集」のボタンを押せません。
|
||||
- ノートは隙間なく並びます。間を空けるときは休符を挿入します。
|
||||
- 原音設定に見つからなかった歌詞があるときは、工具列の右端に警告として並びます。ノートエディターを開いたままでも、合成をやり直すたびに書き換わります。
|
||||
- 工具列の文言が幅に収まらないときは、2 秒おいてから端まで送り、2 秒おいて戻ります。収まっているときは動きません。
|
||||
@@ -263,6 +270,40 @@ YMM4 の設定画面の「音声」に「UTAU」として表示されます。
|
||||
|
||||
---
|
||||
|
||||
## 不具合の報告
|
||||
|
||||
本プラグインは、想定していない例外が起きたときに、その内容を開発者へ自動で送信します。同意は求めず、常に送信します。
|
||||
|
||||
送信する情報は次のとおりです。
|
||||
|
||||
| 種類 | 内容 |
|
||||
|---|---|
|
||||
| 例外 | 型の完全名、メッセージ、スタックトレース |
|
||||
| 発生位置 | モジュール名、関数名、ファイル名、行番号 |
|
||||
| プラグイン | アセンブリ名、バージョン |
|
||||
| 実行環境 | OS の名前とバージョン、.NET のバージョン、CPU のアーキテクチャ、論理プロセッサ数 |
|
||||
| 識別子 | YMM4 の起動ごとに決まるセッション識別子、報告ごとの識別子 |
|
||||
|
||||
利用者の名前、プロジェクトの名前、音源の名前、歌詞、音声ファイルの中身は送信しません。継続して個人を追跡する識別子も持ちません。セッション識別子は YMM4 を起動し直すと別の値になります。メッセージとファイル名に含まれる利用者名などの文字列は、送信の前に置き換えます。送信元の IP アドレスは受信側へ渡す手前で取り除いています。
|
||||
|
||||
送信するのは想定していない例外だけです。本プラグインが例外を握り潰す箇所と、YMM4 へ処理を返す境界の両方で報告します。画面の操作やバックグラウンドの処理で未処理になった例外も報告しますが、本プラグインのコードが関わる例外に限ります。YMM4 本体やほかのプラグインで起きた例外は送信しません。
|
||||
|
||||
次の例外は送信しません。
|
||||
|
||||
| 種類 | 例 |
|
||||
|---|---|
|
||||
| 利用者へ知らせるための失敗 | エイリアスが見つからない、合成できるノートがない、セリフが空 |
|
||||
| 更新の確認の通信の失敗 | GitHub へ接続できない |
|
||||
| 探索と設定ファイルの読み取りで想定している失敗 | フォルダーを開く権限がない、文字コードを判別できない、パスが長すぎる |
|
||||
|
||||
音源の音声ファイルを読み込めなかった場合は送信します。読み込みの不具合を見つけるためです。
|
||||
|
||||
送信できなかった報告は YMM4 のユーザーフォルダーへ退避し、次回の起動時に送り直します。送信も再送も非同期に行うため、起動と合成が遅くなることはありません。
|
||||
|
||||
実装は [YMM4-Telemetry](https://github.com/routersys/YMM4-Telemetry) をサブモジュールとして取り込んでいます。
|
||||
|
||||
---
|
||||
|
||||
## 免責事項
|
||||
|
||||
本プラグインは MIT ライセンスのもとで公開されています。
|
||||
@@ -276,13 +317,15 @@ YMM4 の設定画面の「音声」に「UTAU」として表示されます。
|
||||
|
||||
## サードパーティライセンス
|
||||
|
||||
本プラグインは音声の分析と合成に以下のサードパーティソフトウェアを同梱・使用しています。ライセンスの全文は、リポジトリの [`.github/LICENSE/WorldNet.txt`](.github/LICENSE/WorldNet.txt) と、配布パッケージの `LICENSE` フォルダーに収録しています。
|
||||
本プラグインは以下のサードパーティソフトウェアを同梱・使用しています。ライセンスの全文は、リポジトリの [`.github/LICENSE`](.github/LICENSE) と、配布パッケージの `LICENSE` フォルダーに収録しています。
|
||||
|
||||
| ソフトウェア | 用途 | ライセンス | 著作権表示 |
|
||||
|---|---|---|---|
|
||||
| [WorldNet](https://github.com/routersys/WorldNet) | 音声の分析と合成 | MIT License | Copyright (c) 2026 routersys |
|
||||
| [NAudio](https://github.com/naudio/NAudio) | 音声ファイルの読み書き | MIT License | Copyright (c) Mark Heath & Contributors |
|
||||
| [WORLD](https://github.com/mmorise/World) | WorldNet が移植した音声分析合成システム | 修正 BSD License | Copyright (c) 2010 M. Morise |
|
||||
| [Ooura FFT](https://www.kurims.kyoto-u.ac.jp/~ooura/fft.html) | WORLD が使う高速フーリエ変換 | 作者が定める条件 | Copyright Takuya OOURA, 1996-2001 |
|
||||
| [OpenUtau](https://github.com/stakira/OpenUtau) | 歌詞の区切り方の規約。試験には参照実装として原実装を転写しています | MIT License | Copyright (c) 2014 StAkira |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Windows.Media;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using UTAU.Views;
|
||||
using YukkuriMovieMaker.Controls;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
@@ -37,12 +36,11 @@ public sealed class ExpressionStripAlignmentTests
|
||||
return result;
|
||||
}
|
||||
|
||||
static (NoteEditor Editor, NoteEditorViewModel ViewModel, Border Host) Build(int noteCount)
|
||||
static (NoteEditorSurface Editor, NoteEditorViewModel ViewModel, Border Host) Build(int noteCount)
|
||||
{
|
||||
var editor = new NoteEditor();
|
||||
var button = (PopupButton)editor.Content;
|
||||
var root = (Grid)button.PopupContent!;
|
||||
button.PopupContent = null;
|
||||
var editor = new NoteEditorSurface();
|
||||
var root = (Grid)editor.Content!;
|
||||
editor.Content = null;
|
||||
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
for (var index = 0; index < noteCount; index++)
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UTAU.Notes;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
public sealed class LyricSplitterTests
|
||||
{
|
||||
static class Reference
|
||||
{
|
||||
static readonly Regex whitespace = new(@"\s");
|
||||
static readonly Regex standalone = new(
|
||||
@"\p{IsCJKUnifiedIdeographs}|\p{IsHiragana}|\p{IsKatakana}|\p{IsHangulSyllables}");
|
||||
static readonly Regex contracted = new(@"[ゃゅょぁぃぅぇぉャュョァィゥェォ]");
|
||||
|
||||
public static List<string> Split(string? text)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
var lyrics = new List<string>();
|
||||
var builder = new StringBuilder();
|
||||
var etor = StringInfo.GetTextElementEnumerator(text);
|
||||
while (etor.MoveNext())
|
||||
{
|
||||
string ele = etor.GetTextElement();
|
||||
if (whitespace.IsMatch(ele))
|
||||
{
|
||||
if (builder.Length > 0)
|
||||
{
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
}
|
||||
}
|
||||
else if (contracted.IsMatch(ele))
|
||||
{
|
||||
builder.Append(ele);
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
}
|
||||
else if (standalone.IsMatch(ele))
|
||||
{
|
||||
if (builder.Length > 0)
|
||||
{
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
}
|
||||
builder.Append(ele);
|
||||
}
|
||||
else if (ele == "\"")
|
||||
{
|
||||
while (etor.MoveNext())
|
||||
{
|
||||
string ele1 = etor.GetTextElement();
|
||||
if (ele1 == "\"")
|
||||
{
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append(ele1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (builder.Length > 0 && standalone.IsMatch(builder.ToString()))
|
||||
{
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
}
|
||||
builder.Append(ele);
|
||||
}
|
||||
}
|
||||
if (builder.Length > 0)
|
||||
{
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
}
|
||||
return lyrics;
|
||||
}
|
||||
|
||||
public static string Join(IEnumerable<string> lyrics)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
foreach (string lyric in lyrics)
|
||||
{
|
||||
if (builder.Length != 0)
|
||||
{
|
||||
builder.Append(" ");
|
||||
}
|
||||
if (lyric.Length == 0)
|
||||
{
|
||||
builder.Append("\"\"");
|
||||
}
|
||||
else if (whitespace.IsMatch(lyric))
|
||||
{
|
||||
builder.Append($"\"{lyric}\"");
|
||||
}
|
||||
else if (standalone.IsMatch(lyric))
|
||||
{
|
||||
if (lyric.Length == 1)
|
||||
{
|
||||
builder.Append(lyric);
|
||||
}
|
||||
else if (lyric.Length == 2 && contracted.IsMatch(lyric.Substring(1)))
|
||||
{
|
||||
builder.Append(lyric);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append($"\"{lyric}\"");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append(lyric);
|
||||
}
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
static readonly string[] Alphabet =
|
||||
[
|
||||
"a", "b", "z", "R", "-", "+", "_", "1", "#", "[", "]",
|
||||
" ", "\t", "\n", "\r", " ", "\"",
|
||||
"あ", "か", "し", "ん", "ゃ", "ゅ", "ょ", "ぁ",
|
||||
"ア", "カ", "ャ", "ヴ", "ー",
|
||||
"中", "文", "русский", "가", "각", "𠮷", "é",
|
||||
];
|
||||
|
||||
static string RandomText(Random random)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
var length = random.Next(0, 12);
|
||||
for (var index = 0; index < length; index++)
|
||||
builder.Append(Alphabet[random.Next(Alphabet.Length)]);
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SplittingSeparatesWordsAndStandaloneCharacters()
|
||||
{
|
||||
Assert.Equal(
|
||||
["a", "word", "中", "文", "русский", "가", "각", "갂", "ひ", "ら", "が", "な", "がな", "", "two words"],
|
||||
LyricSplitter.Split("a word中文русский가각갂ひらがな \"がな\" \"\" \"two words\""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JoiningQuotesOnlyWhatSplittingWouldNotRecover()
|
||||
{
|
||||
Assert.Equal(
|
||||
"a word 中 文 русский 가 각 갂 ひ ら が な \"がな\" \"\" \"two words\"",
|
||||
LyricSplitter.Join(["a", "word", "中", "文", "русский", "가", "각", "갂", "ひ", "ら", "が", "な", "がな", "", "two words"]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ASmallKanaStaysWithTheKanaBeforeIt()
|
||||
{
|
||||
Assert.Equal(["きゃ", "ら", "ば", "ん"], LyricSplitter.Split("きゃらばん"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ASmallKanaAfterALatinWordKeepsThatWord()
|
||||
{
|
||||
Assert.Equal(["aゃ"], LyricSplitter.Split("aゃ"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnUnclosedQuoteSwallowsTheRest()
|
||||
{
|
||||
Assert.Equal(["ab"], LyricSplitter.Split("\"ab"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AQuoteAfterLatinCharactersKeepsThemInTheSameLyric()
|
||||
{
|
||||
Assert.Equal(["abcdef"], LyricSplitter.Split("abc\"def\""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EveryKindOfWhitespaceSeparates()
|
||||
{
|
||||
Assert.Equal(["a", "b", "c", "d", "e"], LyricSplitter.Split("a b\tc\nd\re"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SplittingNothingGivesNothing()
|
||||
{
|
||||
Assert.Empty(LyricSplitter.Split(null));
|
||||
Assert.Empty(LyricSplitter.Split(string.Empty));
|
||||
Assert.Empty(LyricSplitter.Split(" "));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JoiningAndSplittingRestoresEveryLyric()
|
||||
{
|
||||
string[] lyrics =
|
||||
[
|
||||
"a", "word", "中", "文", "中文", " ", " ", "-", "12 3# $%^",
|
||||
"中русский", "русский", "ひ", "ら", "が", "な", "がな", "two words", "가", "각", "갂", "갃간",
|
||||
];
|
||||
|
||||
Assert.Equal(lyrics, LyricSplitter.Split(LyricSplitter.Join(lyrics)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SplittingMatchesTheOpenUtauImplementation()
|
||||
{
|
||||
var random = new Random(20260822);
|
||||
var mismatch = 0;
|
||||
var first = string.Empty;
|
||||
for (var trial = 0; trial < 100000; trial++)
|
||||
{
|
||||
var text = RandomText(random);
|
||||
if (LyricSplitter.Split(text).SequenceEqual(Reference.Split(text)))
|
||||
continue;
|
||||
|
||||
if (mismatch == 0)
|
||||
first = text;
|
||||
mismatch++;
|
||||
}
|
||||
|
||||
Assert.True(mismatch == 0, $"mismatch={mismatch} first={first}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JoiningMatchesTheOpenUtauImplementation()
|
||||
{
|
||||
var random = new Random(20260823);
|
||||
var mismatch = 0;
|
||||
var first = string.Empty;
|
||||
for (var trial = 0; trial < 100000; trial++)
|
||||
{
|
||||
var lyrics = Reference.Split(RandomText(random));
|
||||
if (LyricSplitter.Join(lyrics) == Reference.Join(lyrics))
|
||||
continue;
|
||||
|
||||
if (mismatch == 0)
|
||||
first = string.Join("|", lyrics);
|
||||
mismatch++;
|
||||
}
|
||||
|
||||
Assert.True(mismatch == 0, $"mismatch={mismatch} first={first}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using UTAU.ViewModels;
|
||||
using UTAU.Views;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
[Collection("Wpf")]
|
||||
public sealed class LyricsBulkEditLayoutTests
|
||||
{
|
||||
const double RowHeight = 26.0;
|
||||
|
||||
static T RunSta<T>(Func<T> action)
|
||||
{
|
||||
var result = default(T)!;
|
||||
Exception? error = null;
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
result = action();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
error = exception;
|
||||
}
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
if (error is not null)
|
||||
throw new InvalidOperationException(error.Message, error);
|
||||
return result;
|
||||
}
|
||||
|
||||
static IEnumerable<DependencyObject> Descend(DependencyObject root)
|
||||
{
|
||||
var count = VisualTreeHelper.GetChildrenCount(root);
|
||||
for (var index = 0; index < count; index++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(root, index);
|
||||
yield return child;
|
||||
foreach (var descendant in Descend(child))
|
||||
yield return descendant;
|
||||
}
|
||||
}
|
||||
|
||||
sealed record Placed(string Name, double Left, double Top, double Width, double Height)
|
||||
{
|
||||
public double Right => Left + Width;
|
||||
|
||||
public double Bottom => Top + Height;
|
||||
}
|
||||
|
||||
static (Placed[] Buttons, Placed Box, double Width, double Height) Measure(double width, double height)
|
||||
=> RunSta(() =>
|
||||
{
|
||||
var view = new LyricsBulkEditView { DataContext = new LyricsBulkEditViewModel("あ い う", 3) };
|
||||
var host = new Border { Width = width, Height = height, Child = view };
|
||||
for (var pass = 0; pass < 3; pass++)
|
||||
{
|
||||
host.Measure(new Size(width, height));
|
||||
host.Arrange(new Rect(0.0, 0.0, width, height));
|
||||
host.UpdateLayout();
|
||||
}
|
||||
|
||||
Placed Place(FrameworkElement element, string name)
|
||||
{
|
||||
var origin = element.TranslatePoint(new Point(0.0, 0.0), host);
|
||||
return new Placed(name, origin.X, origin.Y, element.ActualWidth, element.ActualHeight);
|
||||
}
|
||||
|
||||
var buttons = Descend(host)
|
||||
.OfType<Button>()
|
||||
.Select(x => Place(x, (string)x.Content))
|
||||
.OrderBy(x => x.Left)
|
||||
.ToArray();
|
||||
var box = Place((TextBox)view.FindName("LyricBox")!, "LyricBox");
|
||||
return (buttons, box, width, height);
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void TheButtonsAreNotCutOffAtTheBottom()
|
||||
{
|
||||
var placed = Measure(560.0, 280.0);
|
||||
|
||||
Assert.NotEmpty(placed.Buttons);
|
||||
foreach (var button in placed.Buttons)
|
||||
Assert.True(button.Bottom <= placed.Height, $"{button.Name} bottom={button.Bottom} host={placed.Height}");
|
||||
|
||||
Assert.Equal(placed.Height, placed.Buttons.Max(x => x.Bottom), 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheButtonsFillTheRowWithoutAGapAboveOrBelow()
|
||||
{
|
||||
var placed = Measure(560.0, 280.0);
|
||||
|
||||
foreach (var button in placed.Buttons)
|
||||
{
|
||||
Assert.Equal(RowHeight, button.Height, 6);
|
||||
Assert.Equal(placed.Height - RowHeight, button.Top, 6);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheButtonsSitAgainstEachOtherWithNoGap()
|
||||
{
|
||||
var placed = Measure(560.0, 280.0);
|
||||
|
||||
for (var index = 1; index < placed.Buttons.Length; index++)
|
||||
Assert.Equal(placed.Buttons[index - 1].Right, placed.Buttons[index].Left, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheLastButtonReachesTheRightEdge()
|
||||
{
|
||||
var placed = Measure(560.0, 280.0);
|
||||
|
||||
Assert.Equal(placed.Width, placed.Buttons[^1].Right, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheTextBoxFillsEverythingAboveTheButtons()
|
||||
{
|
||||
var placed = Measure(560.0, 280.0);
|
||||
|
||||
Assert.Equal(0.0, placed.Box.Left, 6);
|
||||
Assert.Equal(0.0, placed.Box.Top, 6);
|
||||
Assert.Equal(placed.Width, placed.Box.Width, 6);
|
||||
Assert.Equal(placed.Height - RowHeight, placed.Box.Height, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NothingIsCutOffAtTheSmallestAllowedSize()
|
||||
{
|
||||
var placed = Measure(360.0, 220.0);
|
||||
|
||||
foreach (var button in placed.Buttons)
|
||||
{
|
||||
Assert.True(button.Bottom <= placed.Height, $"{button.Name} bottom={button.Bottom}");
|
||||
Assert.Equal(RowHeight, button.Height, 6);
|
||||
}
|
||||
|
||||
Assert.Equal(placed.Width, placed.Buttons[^1].Right, 6);
|
||||
Assert.True(placed.Box.Height > 0.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheHintIsCarriedByTheTextBoxRatherThanTakingUpARow()
|
||||
{
|
||||
var tip = RunSta(() =>
|
||||
{
|
||||
var view = new LyricsBulkEditView { DataContext = new LyricsBulkEditViewModel("あ", 1) };
|
||||
return ((TextBox)view.FindName("LyricBox")!).ToolTip;
|
||||
});
|
||||
|
||||
Assert.Equal(Texts.LyricsBulkEditHint, tip);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using UTAU.Views;
|
||||
using YukkuriMovieMaker.UndoRedo;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
[Collection("Wpf")]
|
||||
public sealed class LyricsBulkEditTests
|
||||
{
|
||||
sealed class Recorder
|
||||
{
|
||||
readonly List<IUndoRedoCommand> commands = [];
|
||||
|
||||
public Recorder(UTAUVoicePronounce pronounce)
|
||||
=> pronounce.UndoRedoCommandCreated += (_, e) =>
|
||||
{
|
||||
if (e.Command is IUndoRedoCommand command)
|
||||
commands.Add(command);
|
||||
};
|
||||
|
||||
public int Recorded => commands.Count(x => !x.IsEmpty);
|
||||
|
||||
public void UndoAll()
|
||||
{
|
||||
for (var index = commands.Count - 1; index >= 0; index--)
|
||||
{
|
||||
if (!commands[index].IsEmpty)
|
||||
commands[index].Undo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static NoteEditorViewModel CreateViewModel(UTAUVoicePronounce pronounce, params string[] lyrics)
|
||||
{
|
||||
foreach (var lyric in lyrics)
|
||||
pronounce.Notes.Add(new UTAUNote { Lyric = lyric, Tone = 60, LengthTicks = UTAUNote.DefaultLengthTicks });
|
||||
return new NoteEditorViewModel(pronounce);
|
||||
}
|
||||
|
||||
static NoteEditorViewModel CreateViewModel(params string[] lyrics)
|
||||
=> CreateViewModel(new UTAUVoicePronounce(), lyrics);
|
||||
|
||||
static T RunSta<T>(Func<T> action)
|
||||
{
|
||||
var result = default(T)!;
|
||||
Exception? error = null;
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
result = action();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
error = exception;
|
||||
}
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
if (error is not null)
|
||||
throw new InvalidOperationException(error.Message, error);
|
||||
return result;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheSelectedLyricsComeOutInNoteOrder()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "り", "が", "と");
|
||||
viewModel.Select(viewModel.Notes[3]);
|
||||
viewModel.ToggleSelection(viewModel.Notes[1]);
|
||||
|
||||
Assert.Equal("り と", viewModel.ReadSelectedLyrics());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ALyricThatWouldNotSurviveSplittingComesOutQuoted()
|
||||
{
|
||||
var viewModel = CreateViewModel("あい", "R");
|
||||
viewModel.SelectAll();
|
||||
|
||||
Assert.Equal("\"あい\" R", viewModel.ReadSelectedLyrics());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyingReplacesTheLyricsOfTheSelectionInOrder()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "あ", "あ");
|
||||
viewModel.SelectAll();
|
||||
|
||||
var applied = viewModel.ApplyLyrics(LyricSplitter.Split("かきく"));
|
||||
|
||||
Assert.Equal(3, applied);
|
||||
Assert.Equal(["か", "き", "く"], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyingFollowsScoreOrderNotTheOrderTheNotesWereClicked()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "い", "う");
|
||||
viewModel.Select(viewModel.Notes[2]);
|
||||
viewModel.ToggleSelection(viewModel.Notes[0]);
|
||||
|
||||
viewModel.ApplyLyrics(LyricSplitter.Split("かき"));
|
||||
|
||||
Assert.Equal(["か", "い", "き"], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadingAndApplyingAgreeOnTheOrderOfAScatteredSelection()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "い", "う", "え");
|
||||
viewModel.Select(viewModel.Notes[3]);
|
||||
viewModel.ToggleSelection(viewModel.Notes[0]);
|
||||
viewModel.ToggleSelection(viewModel.Notes[2]);
|
||||
|
||||
viewModel.ApplyLyrics(LyricSplitter.Split(viewModel.ReadSelectedLyrics()));
|
||||
|
||||
Assert.Equal(["あ", "い", "う", "え"], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyingLeavesTheNotesOutsideTheSelectionAlone()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "い", "う");
|
||||
viewModel.Select(viewModel.Notes[1]);
|
||||
|
||||
viewModel.ApplyLyrics(LyricSplitter.Split("か"));
|
||||
|
||||
Assert.Equal(["あ", "か", "う"], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExtraLyricsBeyondTheSelectionAreDropped()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "い");
|
||||
viewModel.SelectAll();
|
||||
|
||||
var applied = viewModel.ApplyLyrics(LyricSplitter.Split("かきくけこ"));
|
||||
|
||||
Assert.Equal(2, applied);
|
||||
Assert.Equal(["か", "き"], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotesBeyondTheLyricsKeepWhatTheyHad()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "い", "う", "え");
|
||||
viewModel.SelectAll();
|
||||
|
||||
var applied = viewModel.ApplyLyrics(LyricSplitter.Split("かき"));
|
||||
|
||||
Assert.Equal(2, applied);
|
||||
Assert.Equal(["か", "き", "う", "え"], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyingNothingChangesNothing()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "い");
|
||||
viewModel.SelectAll();
|
||||
|
||||
var applied = viewModel.ApplyLyrics(LyricSplitter.Split(" "));
|
||||
|
||||
Assert.Equal(0, applied);
|
||||
Assert.Equal(["あ", "い"], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AQuotedRunBecomesOneLyric()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "い");
|
||||
viewModel.SelectAll();
|
||||
|
||||
viewModel.ApplyLyrics(LyricSplitter.Split("\"a あ\" \"\""));
|
||||
|
||||
Assert.Equal(["a あ", ""], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheLyricsSurviveAReadAndAWriteRoundTrip()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "きゃ", "two words", "", "R", "-", "中");
|
||||
viewModel.SelectAll();
|
||||
var text = viewModel.ReadSelectedLyrics();
|
||||
|
||||
viewModel.ApplyLyrics(LyricSplitter.Split(text));
|
||||
|
||||
Assert.Equal(["あ", "きゃ", "two words", "", "R", "-", "中"], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingBringsEveryLyricBack()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
var viewModel = CreateViewModel(pronounce, "あ", "い", "う");
|
||||
viewModel.SelectAll();
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.ApplyLyrics(LyricSplitter.Split("かきく"));
|
||||
Assert.Equal(3, recorder.Recorded);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal(["あ", "い", "う"], viewModel.Notes.Select(x => x.Note.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnUnchangedLyricIsNotRecorded()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
var viewModel = CreateViewModel(pronounce, "あ", "い", "う");
|
||||
viewModel.SelectAll();
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.ApplyLyrics(LyricSplitter.Split("あ い く"));
|
||||
|
||||
Assert.Equal(1, recorder.Recorded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EditingTheLyricsNeedsASelection()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ");
|
||||
viewModel.Select(null);
|
||||
|
||||
Assert.False(viewModel.EditLyricsCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheCommandAsksTheViewToOpenTheWindow()
|
||||
{
|
||||
var viewModel = CreateViewModel("あ", "い");
|
||||
viewModel.SelectAll();
|
||||
var asked = 0;
|
||||
viewModel.LyricsEditRequested += (_, _) => asked++;
|
||||
|
||||
viewModel.EditLyricsCommand.Execute(null);
|
||||
|
||||
Assert.Equal(1, asked);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheDialogCountsTheLyricsAgainstTheNotes()
|
||||
{
|
||||
var dialog = new LyricsBulkEditViewModel("あ い う", 3);
|
||||
|
||||
Assert.Equal(3, dialog.LyricCount);
|
||||
Assert.Equal(3, dialog.NoteCount);
|
||||
Assert.False(dialog.HasMismatch);
|
||||
Assert.Equal(string.Format(Texts.LyricCountFormat, 3, 3), dialog.CountText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheDialogReportsAMismatchAsTheTextChanges()
|
||||
{
|
||||
var dialog = new LyricsBulkEditViewModel("あ い う", 3);
|
||||
|
||||
dialog.Text = "かき";
|
||||
|
||||
Assert.Equal(2, dialog.LyricCount);
|
||||
Assert.True(dialog.HasMismatch);
|
||||
Assert.Equal(string.Format(Texts.LyricCountFormat, 2, 3), dialog.CountText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheDialogPutsTheTextBackWhenReverted()
|
||||
{
|
||||
var dialog = new LyricsBulkEditViewModel("あ い う", 3);
|
||||
dialog.Text = "かき";
|
||||
|
||||
Assert.True(dialog.ResetCommand.CanExecute(null));
|
||||
dialog.ResetCommand.Execute(null);
|
||||
|
||||
Assert.Equal("あ い う", dialog.Text);
|
||||
Assert.False(dialog.ResetCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheDialogRaisesItsCountAsTheTextChanges()
|
||||
{
|
||||
var dialog = new LyricsBulkEditViewModel("あ", 1);
|
||||
var raised = new List<string>();
|
||||
dialog.PropertyChanged += (_, e) => raised.Add(e.PropertyName ?? string.Empty);
|
||||
|
||||
dialog.Text = "あ い";
|
||||
|
||||
Assert.Contains(nameof(LyricsBulkEditViewModel.Text), raised);
|
||||
Assert.Contains(nameof(LyricsBulkEditViewModel.LyricCount), raised);
|
||||
Assert.Contains(nameof(LyricsBulkEditViewModel.CountText), raised);
|
||||
Assert.Contains(nameof(LyricsBulkEditViewModel.HasMismatch), raised);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheWindowShowsTheViewAndTakesItsViewModel()
|
||||
{
|
||||
var hosted = RunSta(() =>
|
||||
{
|
||||
var dialog = new LyricsBulkEditViewModel("あ い", 2);
|
||||
var window = new LyricsBulkEditWindow(dialog);
|
||||
return (window.Content, ReferenceEquals(window.DataContext, dialog), window.Title);
|
||||
});
|
||||
|
||||
Assert.IsType<LyricsBulkEditView>(hosted.Content);
|
||||
Assert.True(hosted.Item2);
|
||||
Assert.Equal(Texts.EditLyrics, hosted.Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheWindowFollowsTheThemeOfTheHost()
|
||||
{
|
||||
var basedOn = RunSta(() =>
|
||||
{
|
||||
var window = new LyricsBulkEditWindow(new LyricsBulkEditViewModel("あ", 1));
|
||||
return window.Style?.BasedOn?.TargetType;
|
||||
});
|
||||
|
||||
Assert.Equal(typeof(Window), basedOn);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheApplyButtonTellsTheWindowToClose()
|
||||
{
|
||||
var applied = RunSta(() =>
|
||||
{
|
||||
var view = new LyricsBulkEditView { DataContext = new LyricsBulkEditViewModel("あ", 1) };
|
||||
var count = 0;
|
||||
view.Applied += (_, _) => count++;
|
||||
var button = (Button)view.FindName("ApplyButton")!;
|
||||
button.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, button));
|
||||
return count;
|
||||
});
|
||||
|
||||
Assert.Equal(1, applied);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,565 @@
|
||||
using UTAU;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using YukkuriMovieMaker.UndoRedo;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
[Collection("NoteClipboard")]
|
||||
public sealed class NoteBatchEditTests
|
||||
{
|
||||
sealed class Recorder
|
||||
{
|
||||
readonly List<IUndoRedoCommand> commands = [];
|
||||
|
||||
public Recorder(UTAUVoicePronounce pronounce)
|
||||
=> pronounce.UndoRedoCommandCreated += (_, e) =>
|
||||
{
|
||||
if (e.Command is IUndoRedoCommand command)
|
||||
commands.Add(command);
|
||||
};
|
||||
|
||||
public int Recorded => commands.Count(x => !x.IsEmpty);
|
||||
|
||||
public void UndoAll()
|
||||
{
|
||||
for (var index = commands.Count - 1; index >= 0; index--)
|
||||
{
|
||||
if (!commands[index].IsEmpty)
|
||||
commands[index].Undo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static NoteEditorViewModel CreateViewModel(UTAUVoicePronounce pronounce, params int[] tones)
|
||||
{
|
||||
foreach (var tone in tones)
|
||||
pronounce.Notes.Add(new UTAUNote { Lyric = "あ", Tone = tone, LengthTicks = UTAUNote.DefaultLengthTicks });
|
||||
return new NoteEditorViewModel(pronounce);
|
||||
}
|
||||
|
||||
static NoteEditorViewModel CreateViewModel(params int[] tones)
|
||||
=> CreateViewModel(new UTAUVoicePronounce(), tones);
|
||||
|
||||
static void SelectAllOf(NoteEditorViewModel viewModel) => viewModel.SelectAll();
|
||||
|
||||
[Fact]
|
||||
public void RaisingAnOctaveAddsTwelveSemitonesToEverySelectedNote()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62, 64);
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.OctaveUpCommand.Execute(null);
|
||||
|
||||
Assert.Equal([72, 74, 76], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoweringAnOctaveSubtractsTwelveSemitonesFromEverySelectedNote()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62, 64);
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.OctaveDownCommand.Execute(null);
|
||||
|
||||
Assert.Equal([48, 50, 52], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OnlyTheSelectedNotesMove()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62, 64);
|
||||
viewModel.Select(viewModel.Notes[1]);
|
||||
|
||||
viewModel.OctaveUpCommand.Execute(null);
|
||||
|
||||
Assert.Equal([60, 74, 64], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheWholeShiftShrinksSoThatTheIntervalsSurvive()
|
||||
{
|
||||
var viewModel = CreateViewModel(100, 118);
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.OctaveUpCommand.Execute(null);
|
||||
|
||||
Assert.Equal([109, 127], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
Assert.Equal(18, viewModel.Notes[1].Note.Tone - viewModel.Notes[0].Note.Tone);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ANoteAlreadyAtTheTopOfTheRangeStopsTheWholeSelection()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 127);
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.OctaveUpCommand.Execute(null);
|
||||
|
||||
Assert.Equal([60, 127], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheWholeShiftShrinksDownwardsAsWell()
|
||||
{
|
||||
var viewModel = CreateViewModel(9, 27);
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.OctaveDownCommand.Execute(null);
|
||||
|
||||
Assert.Equal([0, 18], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
Assert.Equal(18, viewModel.Notes[1].Note.Tone - viewModel.Notes[0].Note.Tone);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ANoteAlreadyAtTheBottomOfTheRangeStopsTheWholeSelection()
|
||||
{
|
||||
var viewModel = CreateViewModel(0, 60);
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.OctaveDownCommand.Execute(null);
|
||||
|
||||
Assert.Equal([0, 60], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingAnOctaveBringsEveryToneBack()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
var viewModel = CreateViewModel(pronounce, 60, 62, 64);
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.OctaveUpCommand.Execute(null);
|
||||
Assert.Equal(3, recorder.Recorded);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal([60, 62, 64], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QuantizingRoundsEveryLengthToTheSnapDivision()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62, 64);
|
||||
viewModel.SnapDivision = new NoteDivision(16);
|
||||
viewModel.Notes[0].Note.LengthTicks = 130;
|
||||
viewModel.Notes[1].Note.LengthTicks = 180;
|
||||
viewModel.Notes[2].Note.LengthTicks = 470;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.QuantizeLengthCommand.Execute(null);
|
||||
|
||||
Assert.Equal([120, 240, 480], viewModel.Notes.Select(x => x.Note.LengthTicks));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QuantizingNeverProducesANoteShorterThanTheMinimum()
|
||||
{
|
||||
var viewModel = CreateViewModel(60);
|
||||
viewModel.SnapDivision = new NoteDivision(16);
|
||||
viewModel.Notes[0].Note.LengthTicks = 40;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.QuantizeLengthCommand.Execute(null);
|
||||
|
||||
Assert.Equal(UTAUNote.MinimumLengthTicks, viewModel.Notes[0].Note.LengthTicks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QuantizingDoesNothingWhileTheSnapIsFree()
|
||||
{
|
||||
var viewModel = CreateViewModel(60);
|
||||
viewModel.SnapDivision = NoteDivision.Free;
|
||||
viewModel.Notes[0].Note.LengthTicks = 130;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
Assert.False(viewModel.QuantizeLengthCommand.CanExecute(null));
|
||||
viewModel.QuantizeLengthCommand.Execute(null);
|
||||
|
||||
Assert.Equal(130, viewModel.Notes[0].Note.LengthTicks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheFreeSnapLeavesEveryValidLengthWhereItIs()
|
||||
{
|
||||
var viewModel = CreateViewModel(60);
|
||||
viewModel.SnapDivision = NoteDivision.Free;
|
||||
|
||||
foreach (var length in new[]
|
||||
{
|
||||
UTAUNote.MinimumLengthTicks, 16, 47, 130, 479, 480, 481, 1919, UTAUNote.MaximumLengthTicks,
|
||||
})
|
||||
{
|
||||
Assert.Equal(length, viewModel.SnapLength(length));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingAQuantizeBringsEveryLengthBack()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
var viewModel = CreateViewModel(pronounce, 60, 62);
|
||||
viewModel.SnapDivision = new NoteDivision(16);
|
||||
viewModel.Notes[0].Note.LengthTicks = 130;
|
||||
viewModel.Notes[1].Note.LengthTicks = 180;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.QuantizeLengthCommand.Execute(null);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal([130, 180], viewModel.Notes.Select(x => x.Note.LengthTicks));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResettingTheVibratoRestoresEveryField()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62);
|
||||
var vibrato = viewModel.Notes[0].Note.Vibrato;
|
||||
vibrato.LengthPercent = 60.0;
|
||||
vibrato.PeriodMilliseconds = 300.0;
|
||||
vibrato.DepthCents = 90.0;
|
||||
vibrato.FadeInPercent = 40.0;
|
||||
vibrato.FadeOutPercent = 50.0;
|
||||
vibrato.PhasePercent = -30.0;
|
||||
vibrato.OffsetPercent = 20.0;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.ResetVibratoCommand.Execute(null);
|
||||
|
||||
Assert.Equal(0.0, vibrato.LengthPercent);
|
||||
Assert.Equal(175.0, vibrato.PeriodMilliseconds);
|
||||
Assert.Equal(25.0, vibrato.DepthCents);
|
||||
Assert.Equal(20.0, vibrato.FadeInPercent);
|
||||
Assert.Equal(20.0, vibrato.FadeOutPercent);
|
||||
Assert.Equal(0.0, vibrato.PhasePercent);
|
||||
Assert.Equal(0.0, vibrato.OffsetPercent);
|
||||
Assert.False(vibrato.IsEnabled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingAVibratoResetBringsEveryFieldBack()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
var viewModel = CreateViewModel(pronounce, 60);
|
||||
var vibrato = viewModel.Notes[0].Note.Vibrato;
|
||||
vibrato.LengthPercent = 60.0;
|
||||
vibrato.DepthCents = 90.0;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.ResetVibratoCommand.Execute(null);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal(60.0, vibrato.LengthPercent);
|
||||
Assert.Equal(90.0, vibrato.DepthCents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResettingTheTimingRestoresTheOverridesAndTheFades()
|
||||
{
|
||||
var viewModel = CreateViewModel(60);
|
||||
var note = viewModel.Notes[0].Note;
|
||||
note.PreutteranceOverride = 120.0;
|
||||
note.OverlapOverride = 60.0;
|
||||
note.StartPointMilliseconds = 30.0;
|
||||
note.FadeInMilliseconds = 90.0;
|
||||
note.FadeOutMilliseconds = 90.0;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.ResetTimingCommand.Execute(null);
|
||||
|
||||
Assert.Equal(UTAUNote.FollowOtoValue, note.PreutteranceOverride);
|
||||
Assert.Equal(UTAUNote.FollowOtoValue, note.OverlapOverride);
|
||||
Assert.Equal(UTAUNote.DefaultStartPointMilliseconds, note.StartPointMilliseconds);
|
||||
Assert.Equal(UTAUNote.DefaultFadeInMilliseconds, note.FadeInMilliseconds);
|
||||
Assert.Equal(UTAUNote.DefaultFadeOutMilliseconds, note.FadeOutMilliseconds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingATimingResetBringsEveryValueBack()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
var viewModel = CreateViewModel(pronounce, 60);
|
||||
var note = viewModel.Notes[0].Note;
|
||||
note.PreutteranceOverride = 120.0;
|
||||
note.OverlapOverride = 60.0;
|
||||
note.StartPointMilliseconds = 30.0;
|
||||
note.FadeInMilliseconds = 90.0;
|
||||
note.FadeOutMilliseconds = 90.0;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.ResetTimingCommand.Execute(null);
|
||||
Assert.Equal(5, recorder.Recorded);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal(120.0, note.PreutteranceOverride);
|
||||
Assert.Equal(60.0, note.OverlapOverride);
|
||||
Assert.Equal(30.0, note.StartPointMilliseconds);
|
||||
Assert.Equal(90.0, note.FadeInMilliseconds);
|
||||
Assert.Equal(90.0, note.FadeOutMilliseconds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResettingTheTimingLeavesTheLyricAndTheToneAndTheLength()
|
||||
{
|
||||
var viewModel = CreateViewModel(64);
|
||||
var note = viewModel.Notes[0].Note;
|
||||
note.LengthTicks = 321;
|
||||
note.PreutteranceOverride = 120.0;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.ResetTimingCommand.Execute(null);
|
||||
|
||||
Assert.Equal("あ", note.Lyric);
|
||||
Assert.Equal(64, note.Tone);
|
||||
Assert.Equal(321, note.LengthTicks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResettingANoteClearsEveryParameterAndEveryPitchPoint()
|
||||
{
|
||||
var viewModel = CreateViewModel(64);
|
||||
var note = viewModel.Notes[0].Note;
|
||||
note.LengthTicks = 321;
|
||||
note.TempoOverride = 150.0;
|
||||
note.Velocity = 40.0;
|
||||
note.Intensity = 160.0;
|
||||
note.Modulation = -80.0;
|
||||
note.PreutteranceOverride = 120.0;
|
||||
note.Vibrato.LengthPercent = 70.0;
|
||||
note.PitchPoints.Add(new PitchPoint(0, -200.0));
|
||||
note.PitchPoints.Add(new PitchPoint(120, 300.0, PitchPointShape.Linear));
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.ResetNoteCommand.Execute(null);
|
||||
|
||||
Assert.Equal(UTAUNote.FollowScoreValue, note.TempoOverride);
|
||||
Assert.Equal(UTAUNote.DefaultVelocity, note.Velocity);
|
||||
Assert.Equal(UTAUNote.DefaultIntensity, note.Intensity);
|
||||
Assert.Equal(UTAUNote.DefaultModulation, note.Modulation);
|
||||
Assert.Equal(UTAUNote.FollowOtoValue, note.PreutteranceOverride);
|
||||
Assert.Equal(0.0, note.Vibrato.LengthPercent);
|
||||
Assert.Empty(note.PitchPoints);
|
||||
Assert.Equal("あ", note.Lyric);
|
||||
Assert.Equal(64, note.Tone);
|
||||
Assert.Equal(321, note.LengthTicks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingANoteResetBringsThePitchPointsAndTheParametersBack()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
var viewModel = CreateViewModel(pronounce, 60);
|
||||
var note = viewModel.Notes[0].Note;
|
||||
note.Velocity = 40.0;
|
||||
note.PitchPoints.Add(new PitchPoint(0, -200.0));
|
||||
note.PitchPoints.Add(new PitchPoint(120, 300.0, PitchPointShape.Linear));
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.ResetNoteCommand.Execute(null);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal(40.0, note.Velocity);
|
||||
Assert.Equal(2, note.PitchPoints.Count);
|
||||
Assert.Equal([0, 120], note.PitchPoints.Select(x => x.Ticks));
|
||||
Assert.Equal([-200.0, 300.0], note.PitchPoints.Select(x => x.Cents));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PastingPutsTheCopiedNotesAfterTheSelection()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
var viewModel = CreateViewModel(pronounce, 60, 62, 64);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
Assert.Equal([60, 60, 62, 64], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
Assert.Equal([60, 60, 62, 64], pronounce.Notes.Select(x => x.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyingTakesTheNotesInScoreOrderNotInTheOrderTheyWereClicked()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62, 64);
|
||||
viewModel.Select(viewModel.Notes[2]);
|
||||
viewModel.ToggleSelection(viewModel.Notes[0]);
|
||||
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
Assert.Equal([60, 62, 64, 60, 64], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PastingKeepsTheOrderOfTheCopiedNotes()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62, 64);
|
||||
viewModel.SelectAll();
|
||||
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
Assert.Equal([60, 62, 64, 60, 62, 64], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PastingSelectsWhatItPastedAndNothingElse()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
Assert.Equal(1, viewModel.SelectedCount);
|
||||
Assert.Same(viewModel.Notes[1], viewModel.SelectedNote);
|
||||
Assert.True(viewModel.Notes[1].IsSelected);
|
||||
Assert.False(viewModel.Notes[0].IsSelected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ACopiedNoteCarriesItsParametersAndItsPitchPoints()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62);
|
||||
var note = viewModel.Notes[0].Note;
|
||||
note.Lyric = "か";
|
||||
note.LengthTicks = 321;
|
||||
note.Velocity = 40.0;
|
||||
note.Vibrato.LengthPercent = 70.0;
|
||||
note.PitchPoints.Add(new PitchPoint(60, -150.0, PitchPointShape.Linear));
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
var pasted = viewModel.Notes[1].Note;
|
||||
Assert.NotSame(note, pasted);
|
||||
Assert.Equal("か", pasted.Lyric);
|
||||
Assert.Equal(321, pasted.LengthTicks);
|
||||
Assert.Equal(40.0, pasted.Velocity);
|
||||
Assert.Equal(70.0, pasted.Vibrato.LengthPercent);
|
||||
Assert.Equal([60], pasted.PitchPoints.Select(x => x.Ticks));
|
||||
Assert.Equal([-150.0], pasted.PitchPoints.Select(x => x.Cents));
|
||||
Assert.Equal([PitchPointShape.Linear], pasted.PitchPoints.Select(x => x.Shape));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EditingAPastedNoteLeavesTheOriginalAlone()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
viewModel.Notes[1].Note.Lyric = "き";
|
||||
|
||||
Assert.Equal("あ", viewModel.Notes[0].Note.Lyric);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopiedNotesReachAnotherEditor()
|
||||
{
|
||||
var origin = CreateViewModel(60, 62);
|
||||
origin.SelectAll();
|
||||
origin.CopyNotesCommand.Execute(null);
|
||||
|
||||
var other = CreateViewModel(64);
|
||||
other.Select(other.Notes[0]);
|
||||
other.PasteNotesCommand.Execute(null);
|
||||
|
||||
Assert.Equal([64, 60, 62], other.Notes.Select(x => x.Note.Tone));
|
||||
Assert.Equal([60, 62], origin.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PastingTwiceMakesTwoIndependentNotes()
|
||||
{
|
||||
var viewModel = CreateViewModel(60);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
Assert.Equal(3, viewModel.Notes.Count);
|
||||
Assert.NotSame(viewModel.Notes[1].Note, viewModel.Notes[2].Note);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingAPasteTakesTheNotesOutOfTheScore()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
var viewModel = CreateViewModel(pronounce, 60, 62);
|
||||
viewModel.SelectAll();
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
Assert.Equal(4, pronounce.Notes.Count);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal(2, pronounce.Notes.Count);
|
||||
Assert.Equal([60, 62], pronounce.Notes.Select(x => x.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyingNothingLeavesTheClipboardAlone()
|
||||
{
|
||||
var viewModel = CreateViewModel(60);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
viewModel.Select(null);
|
||||
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
Assert.Equal(2, viewModel.Notes.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PastingWithNothingSelectedAppendsToTheEnd()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
viewModel.Select(null);
|
||||
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
Assert.Equal([60, 62, 60], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EveryBatchOperationNeedsASelection()
|
||||
{
|
||||
var viewModel = CreateViewModel(60);
|
||||
viewModel.Select(null);
|
||||
|
||||
Assert.False(viewModel.OctaveUpCommand.CanExecute(null));
|
||||
Assert.False(viewModel.OctaveDownCommand.CanExecute(null));
|
||||
Assert.False(viewModel.QuantizeLengthCommand.CanExecute(null));
|
||||
Assert.False(viewModel.ResetVibratoCommand.CanExecute(null));
|
||||
Assert.False(viewModel.ResetTimingCommand.CanExecute(null));
|
||||
Assert.False(viewModel.ResetNoteCommand.CanExecute(null));
|
||||
Assert.False(viewModel.CopyNotesCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThePositionsFollowTheLengthsAfterAQuantize()
|
||||
{
|
||||
var viewModel = CreateViewModel(60, 62, 64);
|
||||
viewModel.SnapDivision = new NoteDivision(16);
|
||||
viewModel.Notes[0].Note.LengthTicks = 130;
|
||||
viewModel.Notes[1].Note.LengthTicks = 180;
|
||||
SelectAllOf(viewModel);
|
||||
|
||||
viewModel.QuantizeLengthCommand.Execute(null);
|
||||
|
||||
Assert.Equal([0, 120, 360], viewModel.Notes.Select(x => x.StartTicks));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,541 @@
|
||||
using System.Windows.Threading;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using YukkuriMovieMaker.UndoRedo;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
[Collection("NoteClipboard")]
|
||||
public sealed class NoteCollectionSyncTests
|
||||
{
|
||||
sealed class Recorder
|
||||
{
|
||||
readonly List<IUndoRedoCommand> commands = [];
|
||||
bool recording = true;
|
||||
|
||||
public Recorder(UTAUVoicePronounce pronounce)
|
||||
=> pronounce.UndoRedoCommandCreated += (_, e) =>
|
||||
{
|
||||
if (recording && e.Command is IUndoRedoCommand command)
|
||||
commands.Add(command);
|
||||
};
|
||||
|
||||
public int Recorded => commands.Count(x => !x.IsEmpty);
|
||||
|
||||
public void UndoAll()
|
||||
{
|
||||
recording = false;
|
||||
for (var index = commands.Count - 1; index >= 0; index--)
|
||||
{
|
||||
if (!commands[index].IsEmpty)
|
||||
commands[index].Undo();
|
||||
}
|
||||
}
|
||||
|
||||
public void RedoAll()
|
||||
{
|
||||
recording = false;
|
||||
foreach (var command in commands)
|
||||
{
|
||||
if (!command.IsEmpty)
|
||||
command.Redo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static (UTAUVoicePronounce Pronounce, NoteEditorViewModel ViewModel) Create(params int[] tones)
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
foreach (var tone in tones)
|
||||
pronounce.Notes.Add(new UTAUNote { Lyric = "あ", Tone = tone, LengthTicks = UTAUNote.DefaultLengthTicks });
|
||||
return (pronounce, new NoteEditorViewModel(pronounce));
|
||||
}
|
||||
|
||||
static void Pump()
|
||||
{
|
||||
var frame = new DispatcherFrame();
|
||||
Dispatcher.CurrentDispatcher.BeginInvoke(
|
||||
new Action(() => frame.Continue = false),
|
||||
DispatcherPriority.SystemIdle);
|
||||
Dispatcher.PushFrame(frame);
|
||||
}
|
||||
|
||||
static void AssertMirrors(UTAUVoicePronounce pronounce, NoteEditorViewModel viewModel)
|
||||
{
|
||||
Pump();
|
||||
|
||||
Assert.Equal(pronounce.Notes.Count, viewModel.Notes.Count);
|
||||
for (var index = 0; index < pronounce.Notes.Count; index++)
|
||||
Assert.Same(pronounce.Notes[index], viewModel.Notes[index].Note);
|
||||
|
||||
foreach (var note in viewModel.Notes)
|
||||
Assert.Equal(viewModel.SelectedNotes.Contains(note), note.IsSelected);
|
||||
|
||||
Assert.Equal(viewModel.SelectedNote is null ? 0 : 1, viewModel.Notes.Count(x => x.IsPrimary));
|
||||
Assert.Equal(viewModel.SelectedNotes.Count, viewModel.SelectedCount);
|
||||
|
||||
foreach (var selected in viewModel.SelectedNotes)
|
||||
Assert.Contains(selected, viewModel.Notes);
|
||||
|
||||
if (viewModel.SelectedNote is { } primary)
|
||||
{
|
||||
Assert.Contains(primary, viewModel.Notes);
|
||||
Assert.True(primary.IsPrimary);
|
||||
}
|
||||
|
||||
var position = 0;
|
||||
foreach (var note in viewModel.Notes)
|
||||
{
|
||||
Assert.Equal(position, note.StartTicks);
|
||||
position += note.Note.LengthTicks;
|
||||
}
|
||||
|
||||
Assert.Equal(position, viewModel.TotalTicks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingARestInsertTakesItOutOfTheEditor()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.InsertRestCommand.Execute(null);
|
||||
Assert.Equal(3, viewModel.Notes.Count);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal(2, viewModel.Notes.Count);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingARemovalPutsTheNotesBackInTheEditor()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
viewModel.Select(viewModel.Notes[1]);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.RemoveNoteCommand.Execute(null);
|
||||
Assert.Equal(2, viewModel.Notes.Count);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal(3, viewModel.Notes.Count);
|
||||
Assert.Equal([60, 62, 64], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingAPasteTakesTheNotesOutOfTheEditor()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
viewModel.SelectAll();
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
Assert.Equal(4, viewModel.Notes.Count);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal(2, viewModel.Notes.Count);
|
||||
Assert.Equal([60, 62], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedoingAPasteBringsTheNotesBack()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
viewModel.SelectAll();
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
recorder.UndoAll();
|
||||
recorder.RedoAll();
|
||||
|
||||
Assert.Equal(4, viewModel.Notes.Count);
|
||||
Assert.Equal([60, 62, 60, 62], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingAPasteDropsTheSelectionItLeftBehind()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
viewModel.SelectAll();
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
Assert.Equal(2, viewModel.SelectedCount);
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Equal(0, viewModel.SelectedCount);
|
||||
Assert.Null(viewModel.SelectedNote);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UndoingARemovalLeavesTheSurvivingSelectionAlone()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
|
||||
var recorder = new Recorder(pronounce);
|
||||
viewModel.RemoveNoteCommand.Execute(null);
|
||||
var kept = viewModel.SelectedNote;
|
||||
recorder.UndoAll();
|
||||
|
||||
Assert.Same(kept, viewModel.SelectedNote);
|
||||
Assert.Equal(1, viewModel.SelectedCount);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ANoteAddedFromOutsideShowsUpInTheEditor()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
|
||||
pronounce.Notes.Insert(1, new UTAUNote { Lyric = "か", Tone = 64 });
|
||||
|
||||
Assert.Equal(3, viewModel.Notes.Count);
|
||||
Assert.Equal([60, 64, 62], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ANoteRemovedFromOutsideLeavesTheEditor()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
viewModel.SelectAll();
|
||||
|
||||
pronounce.Notes.RemoveAt(1);
|
||||
|
||||
Assert.Equal(2, viewModel.Notes.Count);
|
||||
Assert.Equal(2, viewModel.SelectedCount);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearingTheScoreFromOutsideEmptiesTheEditor()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
viewModel.SelectAll();
|
||||
|
||||
pronounce.Notes.Clear();
|
||||
|
||||
Assert.Empty(viewModel.Notes);
|
||||
Assert.Equal(0, viewModel.SelectedCount);
|
||||
Assert.Null(viewModel.SelectedNote);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheEditorKeepsTheViewModelOfANoteThatStays()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
var kept = viewModel.Notes[2];
|
||||
|
||||
pronounce.Notes.RemoveAt(0);
|
||||
|
||||
Assert.Same(kept, viewModel.Notes[1]);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MovingANoteFromOutsideReordersTheEditor()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
var moved = viewModel.Notes[0];
|
||||
|
||||
pronounce.Notes.Move(0, 2);
|
||||
|
||||
Assert.Equal([62, 64, 60], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
Assert.Same(moved, viewModel.Notes[2]);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheEditorStopsListeningOnceDisposed()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
viewModel.Dispose();
|
||||
|
||||
pronounce.Notes.Add(new UTAUNote { Lyric = "か", Tone = 64 });
|
||||
|
||||
Assert.Empty(viewModel.Notes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADroppedNoteStopsDrivingTheEditor()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
var dropped = pronounce.Notes[1];
|
||||
pronounce.Notes.RemoveAt(1);
|
||||
|
||||
dropped.Tone = 80;
|
||||
|
||||
Assert.Equal([60, 64], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheNoteListMirrorsAtOnceAndThePositionsFollowOnTheDispatcher()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
|
||||
pronounce.Notes.RemoveAt(0);
|
||||
|
||||
Assert.Equal(2, viewModel.Notes.Count);
|
||||
Assert.Equal([62, 64], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
Assert.Equal([UTAUNote.DefaultLengthTicks, UTAUNote.DefaultLengthTicks * 2], viewModel.Notes.Select(x => x.StartTicks));
|
||||
|
||||
Pump();
|
||||
|
||||
Assert.Equal([0, UTAUNote.DefaultLengthTicks], viewModel.Notes.Select(x => x.StartTicks));
|
||||
Assert.Equal(UTAUNote.DefaultLengthTicks * 2, viewModel.TotalTicks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ABurstOfChangesCostsOneLayoutPass()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64, 65, 67);
|
||||
Pump();
|
||||
var passes = 0;
|
||||
viewModel.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(NoteEditorViewModel.TotalTicks))
|
||||
passes++;
|
||||
};
|
||||
|
||||
for (var index = 0; index < 4; index++)
|
||||
pronounce.Notes.RemoveAt(0);
|
||||
Pump();
|
||||
|
||||
Assert.Equal(1, passes);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScrollingCatchesUpAPendingLayout()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
|
||||
pronounce.Notes.RemoveAt(0);
|
||||
viewModel.SetViewport(0.0, 400.0);
|
||||
|
||||
Assert.Equal([0, UTAUNote.DefaultLengthTicks], viewModel.Notes.Select(x => x.StartTicks));
|
||||
Assert.Equal(UTAUNote.DefaultLengthTicks * 2, viewModel.TotalTicks);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OurOwnEditsLeaveNothingPendingForTheDispatcher()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
|
||||
viewModel.SnapDivision = new NoteDivision(16);
|
||||
viewModel.InsertRestCommand.Execute(null);
|
||||
|
||||
Assert.Equal(3, viewModel.Notes.Count);
|
||||
Assert.Equal([240, 120, 240], viewModel.Notes.Select(x => x.Note.LengthTicks));
|
||||
Assert.Equal([0, 240, 360], viewModel.Notes.Select(x => x.StartTicks));
|
||||
Assert.Equal(600, viewModel.TotalTicks);
|
||||
}
|
||||
|
||||
static void AssertSameShapeAsAFreshEditor(UTAUVoicePronounce pronounce, NoteEditorViewModel viewModel)
|
||||
{
|
||||
Pump();
|
||||
using var fresh = new NoteEditorViewModel(pronounce);
|
||||
|
||||
Assert.Equal(fresh.Notes.Select(x => x.Note), viewModel.Notes.Select(x => x.Note));
|
||||
Assert.Equal(fresh.Notes.Select(x => x.StartTicks), viewModel.Notes.Select(x => x.StartTicks));
|
||||
Assert.Equal(fresh.VisibleNotes.Select(x => x.Note), viewModel.VisibleNotes.Select(x => x.Note));
|
||||
Assert.Equal(fresh.TotalTicks, viewModel.TotalTicks);
|
||||
Assert.Equal(fresh.MinimumTone, viewModel.MinimumTone);
|
||||
Assert.Equal(fresh.MaximumTone, viewModel.MaximumTone);
|
||||
Assert.Equal(fresh.CanvasWidth, viewModel.CanvasWidth);
|
||||
Assert.Equal(fresh.CanvasHeight, viewModel.CanvasHeight);
|
||||
Assert.Equal(fresh.Keyboard.Count, viewModel.Keyboard.Count);
|
||||
Assert.Equal(fresh.TimeGridLines.Count, viewModel.TimeGridLines.Count);
|
||||
Assert.Equal(fresh.PitchCurve.Count, viewModel.PitchCurve.Count);
|
||||
Assert.Equal(fresh.ExpressionBars.Count, viewModel.ExpressionBars.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnyRunOfChangesLeavesTheEditorWhereAFreshOneWouldBe()
|
||||
{
|
||||
var random = new Random(20260823);
|
||||
for (var trial = 0; trial < 200; trial++)
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64, 65);
|
||||
var steps = random.Next(1, 9);
|
||||
for (var step = 0; step < steps; step++)
|
||||
{
|
||||
switch (random.Next(6))
|
||||
{
|
||||
case 0:
|
||||
pronounce.Notes.Insert(
|
||||
random.Next(pronounce.Notes.Count + 1),
|
||||
new UTAUNote { Lyric = "か", Tone = 50 + random.Next(30), LengthTicks = 60 + random.Next(400) });
|
||||
break;
|
||||
case 1 when pronounce.Notes.Count > 1:
|
||||
pronounce.Notes.RemoveAt(random.Next(pronounce.Notes.Count));
|
||||
break;
|
||||
case 2 when pronounce.Notes.Count > 1:
|
||||
pronounce.Notes.Move(random.Next(pronounce.Notes.Count), random.Next(pronounce.Notes.Count));
|
||||
break;
|
||||
case 3:
|
||||
pronounce.Notes[random.Next(pronounce.Notes.Count)].LengthTicks = 60 + random.Next(400);
|
||||
break;
|
||||
case 4:
|
||||
viewModel.Select(viewModel.Notes[random.Next(viewModel.Notes.Count)]);
|
||||
viewModel.InsertRestCommand.Execute(null);
|
||||
break;
|
||||
default:
|
||||
if (viewModel.Notes.Count > 1)
|
||||
{
|
||||
viewModel.Select(viewModel.Notes[random.Next(viewModel.Notes.Count)]);
|
||||
viewModel.RemoveNoteCommand.Execute(null);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
AssertSameShapeAsAFreshEditor(pronounce, viewModel);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
viewModel.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheLayoutCatchesUpBeforeAnythingDrawsTheEditor()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
Pump();
|
||||
var order = new List<string>();
|
||||
viewModel.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(NoteEditorViewModel.TotalTicks))
|
||||
order.Add("layout");
|
||||
};
|
||||
|
||||
Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => order.Add("draw")), DispatcherPriority.Render);
|
||||
pronounce.Notes.RemoveAt(0);
|
||||
Pump();
|
||||
|
||||
Assert.Equal(["layout", "draw"], order);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PastingIntoAnEditorThatWasEmptiedFromOutsideWorks()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
viewModel.SelectAll();
|
||||
viewModel.CopyNotesCommand.Execute(null);
|
||||
|
||||
pronounce.Notes.Clear();
|
||||
viewModel.PasteNotesCommand.Execute(null);
|
||||
|
||||
Assert.Equal([60, 62], viewModel.Notes.Select(x => x.Note.Tone));
|
||||
Assert.Equal(2, viewModel.SelectedCount);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADroppedNoteNeverStaysInTheDrawnList()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
Pump();
|
||||
var dropped = viewModel.Notes[1];
|
||||
Assert.Contains(dropped, viewModel.VisibleNotes);
|
||||
|
||||
pronounce.Notes.RemoveAt(1);
|
||||
|
||||
Assert.DoesNotContain(dropped, viewModel.VisibleNotes);
|
||||
Assert.All(viewModel.VisibleNotes, x => Assert.Contains(x, viewModel.Notes));
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AChangeFromAnotherThreadIsBroughtBackToTheEditorThread()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
Pump();
|
||||
|
||||
var thread = new Thread(() => pronounce.Notes.Add(new UTAUNote { Lyric = "か", Tone = 64 }));
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
|
||||
Assert.Equal(2, viewModel.Notes.Count);
|
||||
|
||||
Pump();
|
||||
|
||||
Assert.Equal(3, viewModel.Notes.Count);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AChangeThatArrivesAfterDisposalIsIgnored()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
var thread = new Thread(() => pronounce.Notes.Add(new UTAUNote { Lyric = "か", Tone = 64 }));
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
|
||||
viewModel.Dispose();
|
||||
Pump();
|
||||
|
||||
Assert.Empty(viewModel.Notes);
|
||||
Assert.Equal(3, pronounce.Notes.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DisposingTwiceIsHarmless()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62);
|
||||
|
||||
viewModel.Dispose();
|
||||
viewModel.Dispose();
|
||||
|
||||
Assert.Empty(viewModel.Notes);
|
||||
Assert.Equal(2, pronounce.Notes.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ARedundantChangeCostsNoLayoutPass()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64);
|
||||
Pump();
|
||||
var passes = 0;
|
||||
viewModel.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(NoteEditorViewModel.TotalTicks))
|
||||
passes++;
|
||||
};
|
||||
|
||||
pronounce.Notes.Move(1, 1);
|
||||
Pump();
|
||||
|
||||
Assert.Equal(0, passes);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemovingManySelectedNotesResynchronisesOnlyOnce()
|
||||
{
|
||||
var (pronounce, viewModel) = Create(60, 62, 64, 65, 67, 69);
|
||||
var rebuilds = 0;
|
||||
viewModel.Notes.CollectionChanged += (_, _) => rebuilds++;
|
||||
viewModel.Select(viewModel.Notes[1]);
|
||||
viewModel.ToggleSelection(viewModel.Notes[2]);
|
||||
viewModel.ToggleSelection(viewModel.Notes[3]);
|
||||
|
||||
viewModel.RemoveNoteCommand.Execute(null);
|
||||
|
||||
Assert.Equal(3, viewModel.Notes.Count);
|
||||
Assert.Equal(1 + 3, rebuilds);
|
||||
AssertMirrors(pronounce, viewModel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using UTAU.Views;
|
||||
using YukkuriMovieMaker.Resources.Icons;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
[Collection("Wpf")]
|
||||
public sealed class NoteContextMenuTests
|
||||
{
|
||||
const double PopupWidth = 980.0;
|
||||
const double PopupHeight = 480.0;
|
||||
|
||||
static T RunSta<T>(Func<T> action)
|
||||
{
|
||||
var result = default(T)!;
|
||||
Exception? error = null;
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
result = action();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
error = exception;
|
||||
}
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
if (error is not null)
|
||||
throw new InvalidOperationException(error.Message, error);
|
||||
return result;
|
||||
}
|
||||
|
||||
static (NoteEditorSurface Surface, NoteEditorViewModel ViewModel) Build(params int[] tones)
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
foreach (var tone in tones)
|
||||
pronounce.Notes.Add(new UTAUNote { Lyric = "あ", Tone = tone, LengthTicks = UTAUNote.DefaultLengthTicks });
|
||||
|
||||
var viewModel = new NoteEditorViewModel(pronounce);
|
||||
var surface = new NoteEditorSurface { DataContext = viewModel };
|
||||
var host = new Border { Width = PopupWidth, Height = PopupHeight, Child = surface };
|
||||
for (var pass = 0; pass < 3; pass++)
|
||||
{
|
||||
host.Measure(new Size(PopupWidth, PopupHeight));
|
||||
host.Arrange(new Rect(0.0, 0.0, PopupWidth, PopupHeight));
|
||||
host.UpdateLayout();
|
||||
}
|
||||
|
||||
return (surface, viewModel);
|
||||
}
|
||||
|
||||
static IEnumerable<DependencyObject> Descend(DependencyObject root)
|
||||
{
|
||||
var count = VisualTreeHelper.GetChildrenCount(root);
|
||||
for (var index = 0; index < count; index++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(root, index);
|
||||
yield return child;
|
||||
foreach (var descendant in Descend(child))
|
||||
yield return descendant;
|
||||
}
|
||||
}
|
||||
|
||||
static FrameworkElement NoteBody(NoteEditorSurface surface, NoteViewModel note)
|
||||
=> Descend(surface.RollCanvas)
|
||||
.OfType<Grid>()
|
||||
.First(x => ReferenceEquals(x.DataContext, note));
|
||||
|
||||
[Fact]
|
||||
public void TheRollCanvasCarriesAContextMenu()
|
||||
{
|
||||
var headers = RunSta(() =>
|
||||
{
|
||||
var (surface, _) = Build(60, 62);
|
||||
return surface.RollCanvas.ContextMenu!.Items
|
||||
.OfType<MenuItem>()
|
||||
.Select(x => (string)x.Header)
|
||||
.ToArray();
|
||||
});
|
||||
|
||||
Assert.Equal(
|
||||
[
|
||||
Texts.NoteContextCopy,
|
||||
Texts.NoteContextPaste,
|
||||
Texts.SelectAllNotes,
|
||||
Texts.OctaveUp,
|
||||
Texts.OctaveDown,
|
||||
Texts.QuantizeLength,
|
||||
Texts.ResetGroup,
|
||||
Texts.EditLyrics,
|
||||
Texts.DetachEditor,
|
||||
],
|
||||
headers);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheResetGroupHoldsTheFourResets()
|
||||
{
|
||||
var headers = RunSta(() =>
|
||||
{
|
||||
var (surface, _) = Build(60, 62);
|
||||
var group = surface.RollCanvas.ContextMenu!.Items.OfType<MenuItem>()
|
||||
.First(x => (string)x.Header == Texts.ResetGroup);
|
||||
return group.Items.OfType<MenuItem>().Select(x => (string)x.Header).ToArray();
|
||||
});
|
||||
|
||||
Assert.Equal(
|
||||
[Texts.ResetPitch, Texts.ResetVibrato, Texts.ResetTiming, Texts.ResetNote],
|
||||
headers);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EveryMenuEntryIsBoundToACommand()
|
||||
{
|
||||
var unbound = RunSta(() =>
|
||||
{
|
||||
var (surface, _) = Build(60, 62);
|
||||
var items = surface.RollCanvas.ContextMenu!.Items.OfType<MenuItem>().ToList();
|
||||
var leaves = items.Where(x => x.Items.Count == 0)
|
||||
.Concat(items.SelectMany(x => x.Items.OfType<MenuItem>()))
|
||||
.ToList();
|
||||
return leaves.Where(x => x.Command is null).Select(x => (string)x.Header).ToArray();
|
||||
});
|
||||
|
||||
Assert.Empty(unbound);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheMenuCommandsAreTheOnesOfTheEditor()
|
||||
{
|
||||
var same = RunSta(() =>
|
||||
{
|
||||
var (surface, viewModel) = Build(60, 62);
|
||||
var items = surface.RollCanvas.ContextMenu!.Items.OfType<MenuItem>().ToList();
|
||||
return ReferenceEquals(items[0].Command, viewModel.CopyNotesCommand)
|
||||
&& ReferenceEquals(items[3].Command, viewModel.OctaveUpCommand)
|
||||
&& ReferenceEquals(items[4].Command, viewModel.OctaveDownCommand)
|
||||
&& ReferenceEquals(items[5].Command, viewModel.QuantizeLengthCommand)
|
||||
&& ReferenceEquals(items[6].Items.OfType<MenuItem>().Last().Command, viewModel.ResetNoteCommand)
|
||||
&& ReferenceEquals(items[7].Command, viewModel.EditLyricsCommand)
|
||||
&& ReferenceEquals(items[8].Command, viewModel.DetachCommand);
|
||||
});
|
||||
|
||||
Assert.True(same);
|
||||
}
|
||||
|
||||
static readonly (string Header, string Icon)[] ExpectedIcons =
|
||||
[
|
||||
(Texts.NoteContextCopy, IconKeys.ContentCopy),
|
||||
(Texts.NoteContextPaste, IconKeys.ContentPaste),
|
||||
(Texts.SelectAllNotes, IconKeys.SelectAll),
|
||||
(Texts.OctaveUp, IconKeys.ArrowUp),
|
||||
(Texts.OctaveDown, IconKeys.ArrowDown),
|
||||
(Texts.QuantizeLength, IconKeys.Magnet),
|
||||
(Texts.ResetGroup, IconKeys.Restore),
|
||||
(Texts.ResetPitch, IconKeys.VectorCurve),
|
||||
(Texts.ResetVibrato, IconKeys.SineWave),
|
||||
(Texts.ResetTiming, IconKeys.TimerOutline),
|
||||
(Texts.ResetNote, IconKeys.BackupRestore),
|
||||
(Texts.EditLyrics, IconKeys.TextBoxEdit),
|
||||
(Texts.DetachEditor, IconKeys.OpenInNew),
|
||||
];
|
||||
|
||||
static List<MenuItem> Entries(ItemsControl menu)
|
||||
{
|
||||
var entries = new List<MenuItem>();
|
||||
foreach (var item in menu.Items.OfType<MenuItem>())
|
||||
{
|
||||
entries.Add(item);
|
||||
entries.AddRange(Entries(item));
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EveryMenuEntryAsksForItsOwnIcon()
|
||||
{
|
||||
var asked = RunSta(() =>
|
||||
{
|
||||
var (surface, _) = Build(60, 62);
|
||||
var menu = surface.RollCanvas.ContextMenu!;
|
||||
foreach (var key in ExpectedIcons.Select(x => x.Icon).Distinct())
|
||||
menu.Resources[key] = key;
|
||||
|
||||
return Entries(menu).Select(x => ((string)x.Header, x.Icon as string)).ToArray();
|
||||
});
|
||||
|
||||
Assert.Equal(ExpectedIcons.Length, asked.Length);
|
||||
Assert.Equal(ExpectedIcons, asked.Select(x => (x.Item1, x.Item2 ?? string.Empty)).ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoMenuEntryIsLeftWithoutAnIcon()
|
||||
{
|
||||
var missing = RunSta(() =>
|
||||
{
|
||||
var (surface, _) = Build(60, 62);
|
||||
var menu = surface.RollCanvas.ContextMenu!;
|
||||
foreach (var key in ExpectedIcons.Select(x => x.Icon).Distinct())
|
||||
menu.Resources[key] = key;
|
||||
|
||||
return Entries(menu).Where(x => x.Icon is null).Select(x => (string)x.Header).ToArray();
|
||||
});
|
||||
|
||||
Assert.Empty(missing);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RightClickingAnUnselectedNoteSelectsIt()
|
||||
{
|
||||
var selected = RunSta(() =>
|
||||
{
|
||||
var (surface, viewModel) = Build(60, 62, 64);
|
||||
viewModel.Select(viewModel.Notes[0]);
|
||||
var body = NoteBody(surface, viewModel.Notes[2]);
|
||||
body.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Right)
|
||||
{
|
||||
RoutedEvent = UIElement.MouseRightButtonDownEvent,
|
||||
});
|
||||
return (viewModel.SelectedCount, IsThird: ReferenceEquals(viewModel.SelectedNote, viewModel.Notes[2]));
|
||||
});
|
||||
|
||||
Assert.Equal(1, selected.SelectedCount);
|
||||
Assert.True(selected.IsThird);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RightClickingInsideTheSelectionKeepsIt()
|
||||
{
|
||||
var count = RunSta(() =>
|
||||
{
|
||||
var (surface, viewModel) = Build(60, 62, 64);
|
||||
viewModel.SelectAll();
|
||||
var body = NoteBody(surface, viewModel.Notes[1]);
|
||||
body.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Right)
|
||||
{
|
||||
RoutedEvent = UIElement.MouseRightButtonDownEvent,
|
||||
});
|
||||
return viewModel.SelectedCount;
|
||||
});
|
||||
|
||||
Assert.Equal(3, count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using UTAU.Views;
|
||||
using YukkuriMovieMaker.Controls;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
[Collection("Wpf")]
|
||||
public sealed class NoteEditorDetachTests
|
||||
{
|
||||
static T RunSta<T>(Func<T> action)
|
||||
{
|
||||
var result = default(T)!;
|
||||
Exception? error = null;
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
result = action();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
error = exception;
|
||||
}
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
if (error is not null)
|
||||
throw new InvalidOperationException(error.Message, error);
|
||||
return result;
|
||||
}
|
||||
|
||||
static UTAUVoicePronounce CreatePronounce(params string[] lyrics)
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
foreach (var lyric in lyrics)
|
||||
pronounce.Notes.Add(new UTAUNote { Lyric = lyric, Tone = 60, LengthTicks = UTAUNote.DefaultLengthTicks });
|
||||
return pronounce;
|
||||
}
|
||||
|
||||
static NoteEditor CreateEditor(UTAUVoicePronounce pronounce)
|
||||
{
|
||||
var editor = new NoteEditor();
|
||||
var host = new Border { Width = 200.0, Height = 26.0, Child = editor };
|
||||
host.Measure(new Size(200.0, 26.0));
|
||||
host.Arrange(new Rect(0.0, 0.0, 200.0, 26.0));
|
||||
host.UpdateLayout();
|
||||
editor.Pronounce = pronounce;
|
||||
return editor;
|
||||
}
|
||||
|
||||
static ContentControl PopupHostOf(NoteEditor editor)
|
||||
=> (ContentControl)((PopupButton)editor.Content).PopupContent!;
|
||||
|
||||
static NoteEditorViewModel ViewModelOf(NoteEditorSurface surface)
|
||||
=> (NoteEditorViewModel)surface.DataContext;
|
||||
|
||||
[Fact]
|
||||
public void DetachingTakesTheSurfaceOutOfThePopupAndIntoTheWindow()
|
||||
{
|
||||
var state = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(CreatePronounce("あ", "い"));
|
||||
var before = (NoteEditorSurface)PopupHostOf(editor).Content!;
|
||||
editor.Detach();
|
||||
var moved = ReferenceEquals(editor.DetachedWindow?.Surface, before);
|
||||
var emptied = PopupHostOf(editor).Content is null;
|
||||
editor.CloseDetached();
|
||||
return (moved, emptied);
|
||||
});
|
||||
|
||||
Assert.True(state.moved);
|
||||
Assert.True(state.emptied);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClosingTheWindowPutsTheSameSurfaceBackInThePopup()
|
||||
{
|
||||
var state = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(CreatePronounce("あ", "い"));
|
||||
var before = PopupHostOf(editor).Content;
|
||||
editor.Detach();
|
||||
editor.CloseDetached();
|
||||
return (
|
||||
Same: ReferenceEquals(PopupHostOf(editor).Content, before),
|
||||
Gone: editor.DetachedWindow is null);
|
||||
});
|
||||
|
||||
Assert.True(state.Same);
|
||||
Assert.True(state.Gone);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThePopupButtonIsHeldShutWhileTheWindowIsOpen()
|
||||
{
|
||||
var state = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(CreatePronounce("あ"));
|
||||
var button = (PopupButton)editor.Content;
|
||||
editor.Detach();
|
||||
var whileOpen = button.IsEnabled;
|
||||
editor.CloseDetached();
|
||||
return (whileOpen, AfterClose: button.IsEnabled);
|
||||
});
|
||||
|
||||
Assert.False(state.whileOpen);
|
||||
Assert.True(state.AfterClose);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DetachingBeginsAnEditAndClosingEndsIt()
|
||||
{
|
||||
var state = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(CreatePronounce("あ"));
|
||||
var begun = 0;
|
||||
var ended = 0;
|
||||
editor.BeginEdit += (_, _) => begun++;
|
||||
editor.EndEdit += (_, _) => ended++;
|
||||
|
||||
editor.Detach();
|
||||
var afterDetach = (Begun: begun, Ended: ended);
|
||||
editor.CloseDetached();
|
||||
return (afterDetach, After: (Begun: begun, Ended: ended));
|
||||
});
|
||||
|
||||
Assert.Equal((1, 0), state.afterDetach);
|
||||
Assert.Equal((1, 1), state.After);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheDetachedSurfaceEditsTheSamePronounce()
|
||||
{
|
||||
var pronounce = CreatePronounce("あ", "い", "う");
|
||||
var applied = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(pronounce);
|
||||
editor.Detach();
|
||||
var viewModel = ViewModelOf(editor.DetachedWindow!.Surface!);
|
||||
viewModel.SelectAll();
|
||||
var count = viewModel.ApplyLyrics(LyricSplitter.Split("かきく"));
|
||||
editor.CloseDetached();
|
||||
return count;
|
||||
});
|
||||
|
||||
Assert.Equal(3, applied);
|
||||
Assert.Equal(["か", "き", "く"], pronounce.Notes.Select(x => x.Lyric));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheEditsMadeInTheWindowAreThereWhenItCloses()
|
||||
{
|
||||
var pronounce = CreatePronounce("あ", "い");
|
||||
var inPopup = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(pronounce);
|
||||
editor.Detach();
|
||||
var viewModel = ViewModelOf(editor.DetachedWindow!.Surface!);
|
||||
viewModel.SelectAll();
|
||||
viewModel.OctaveUpCommand.Execute(null);
|
||||
editor.CloseDetached();
|
||||
return ViewModelOf((NoteEditorSurface)PopupHostOf(editor).Content!)
|
||||
.Notes.Select(x => x.Note.Tone).ToArray();
|
||||
});
|
||||
|
||||
Assert.Equal([72, 72], inPopup);
|
||||
Assert.Equal([72, 72], pronounce.Notes.Select(x => x.Tone));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearingThePronounceClosesTheWindow()
|
||||
{
|
||||
var state = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(CreatePronounce("あ"));
|
||||
editor.Detach();
|
||||
var whileOpen = editor.DetachedWindow is not null;
|
||||
editor.Pronounce = null;
|
||||
return (whileOpen, After: editor.DetachedWindow is not null, Back: PopupHostOf(editor).Content is NoteEditorSurface);
|
||||
});
|
||||
|
||||
Assert.True(state.whileOpen);
|
||||
Assert.False(state.After);
|
||||
Assert.True(state.Back);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DetachingTwiceOpensOnlyOneWindow()
|
||||
{
|
||||
var same = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(CreatePronounce("あ"));
|
||||
editor.Detach();
|
||||
var first = editor.DetachedWindow;
|
||||
editor.Detach();
|
||||
var second = editor.DetachedWindow;
|
||||
editor.CloseDetached();
|
||||
return ReferenceEquals(first, second);
|
||||
});
|
||||
|
||||
Assert.True(same);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheCommandAsksTheViewToDetach()
|
||||
{
|
||||
var pronounce = CreatePronounce("あ");
|
||||
var detached = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(pronounce);
|
||||
var viewModel = ViewModelOf((NoteEditorSurface)PopupHostOf(editor).Content!);
|
||||
viewModel.DetachCommand.Execute(null);
|
||||
var open = editor.DetachedWindow is not null;
|
||||
editor.CloseDetached();
|
||||
return open;
|
||||
});
|
||||
|
||||
Assert.True(detached);
|
||||
}
|
||||
|
||||
static MenuItem DetachEntry(NoteEditorSurface surface)
|
||||
=> surface.RollCanvas.ContextMenu!.Items
|
||||
.OfType<MenuItem>()
|
||||
.First(x => (string)x.Header == Texts.DetachEditor);
|
||||
|
||||
[Fact]
|
||||
public void TheWindowDoesNotOfferToOpenAnotherWindow()
|
||||
{
|
||||
var state = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(CreatePronounce("あ"));
|
||||
var surface = (NoteEditorSurface)PopupHostOf(editor).Content!;
|
||||
var before = DetachEntry(surface).Visibility;
|
||||
editor.Detach();
|
||||
var whileOpen = DetachEntry(editor.DetachedWindow!.Surface!).Visibility;
|
||||
editor.CloseDetached();
|
||||
return (before, whileOpen, After: DetachEntry(surface).Visibility);
|
||||
});
|
||||
|
||||
Assert.Equal(Visibility.Visible, state.before);
|
||||
Assert.Equal(Visibility.Collapsed, state.whileOpen);
|
||||
Assert.Equal(Visibility.Visible, state.After);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheDetachCommandTurnsItselfOffWhileTheWindowIsOpen()
|
||||
{
|
||||
var state = RunSta(() =>
|
||||
{
|
||||
var editor = CreateEditor(CreatePronounce("あ"));
|
||||
var viewModel = ViewModelOf((NoteEditorSurface)PopupHostOf(editor).Content!);
|
||||
var before = viewModel.DetachCommand.CanExecute(null);
|
||||
editor.Detach();
|
||||
var whileOpen = (viewModel.DetachCommand.CanExecute(null), viewModel.IsDetached, viewModel.CanDetach);
|
||||
editor.CloseDetached();
|
||||
return (before, whileOpen, After: (viewModel.DetachCommand.CanExecute(null), viewModel.IsDetached, viewModel.CanDetach));
|
||||
});
|
||||
|
||||
Assert.True(state.before);
|
||||
Assert.Equal((false, true, false), state.whileOpen);
|
||||
Assert.Equal((true, false, true), state.After);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheWindowFollowsTheThemeOfTheHost()
|
||||
{
|
||||
var basedOn = RunSta(() =>
|
||||
{
|
||||
var window = new NoteEditorWindow(new NoteEditorSurface());
|
||||
var result = window.Style?.BasedOn?.TargetType;
|
||||
window.Release();
|
||||
return result;
|
||||
});
|
||||
|
||||
Assert.Equal(typeof(Window), basedOn);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheWindowIsTitledLikeTheEditorButton()
|
||||
{
|
||||
var title = RunSta(() =>
|
||||
{
|
||||
var window = new NoteEditorWindow(new NoteEditorSurface());
|
||||
var result = window.Title;
|
||||
window.Release();
|
||||
return result;
|
||||
});
|
||||
|
||||
Assert.Equal(Texts.EditNotes, title);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using System.Windows.Controls;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using UTAU.Views;
|
||||
using YukkuriMovieMaker.Controls;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
[Collection("Wpf")]
|
||||
public sealed class NoteEditorHostTests
|
||||
{
|
||||
static T RunSta<T>(Func<T> action)
|
||||
{
|
||||
var result = default(T)!;
|
||||
Exception? error = null;
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
result = action();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
error = exception;
|
||||
}
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
if (error is not null)
|
||||
throw new InvalidOperationException(error.Message, error);
|
||||
return result;
|
||||
}
|
||||
|
||||
static UTAUVoicePronounce CreatePronounce()
|
||||
{
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
pronounce.Notes.Add(new UTAUNote { Lyric = "あ", Tone = 60 });
|
||||
return pronounce;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThePopupHoldsTheEditingSurface()
|
||||
{
|
||||
var hosted = RunSta(() =>
|
||||
{
|
||||
var editor = new NoteEditor();
|
||||
var button = (PopupButton)editor.Content;
|
||||
var host = (ContentControl)button.PopupContent!;
|
||||
return host.Content;
|
||||
});
|
||||
|
||||
Assert.IsType<NoteEditorSurface>(hosted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheSurfaceGetsTheViewModelOfTheGivenPronounce()
|
||||
{
|
||||
var pronounce = CreatePronounce();
|
||||
var context = RunSta(() =>
|
||||
{
|
||||
var editor = new NoteEditor();
|
||||
editor.Pronounce = pronounce;
|
||||
var button = (PopupButton)editor.Content;
|
||||
var host = (ContentControl)button.PopupContent!;
|
||||
return ((NoteEditorSurface)host.Content!).DataContext;
|
||||
});
|
||||
|
||||
var viewModel = Assert.IsType<NoteEditorViewModel>(context);
|
||||
Assert.Single(viewModel.Notes);
|
||||
Assert.Same(pronounce.Notes[0], viewModel.Notes[0].Note);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearingThePronounceTakesTheViewModelAway()
|
||||
{
|
||||
var pronounce = CreatePronounce();
|
||||
var context = RunSta(() =>
|
||||
{
|
||||
var editor = new NoteEditor();
|
||||
editor.Pronounce = pronounce;
|
||||
editor.Pronounce = null;
|
||||
var button = (PopupButton)editor.Content;
|
||||
var host = (ContentControl)button.PopupContent!;
|
||||
return ((NoteEditorSurface)host.Content!).DataContext;
|
||||
});
|
||||
|
||||
Assert.Null(context);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheEditorAttributeBindsThePronounceToTheSurface()
|
||||
{
|
||||
var pronounce = CreatePronounce();
|
||||
var context = RunSta(() =>
|
||||
{
|
||||
var attribute = new NoteEditorAttribute();
|
||||
var control = attribute.Create();
|
||||
attribute.SetBindings(control, pronounce, pronounce, typeof(UTAUVoicePronounce).GetProperty(nameof(UTAUVoicePronounce.Notes))!);
|
||||
var editor = (NoteEditor)control;
|
||||
var button = (PopupButton)editor.Content;
|
||||
var host = (ContentControl)button.PopupContent!;
|
||||
return ((NoteEditorSurface)host.Content!).DataContext;
|
||||
});
|
||||
|
||||
var viewModel = Assert.IsType<NoteEditorViewModel>(context);
|
||||
Assert.Same(pronounce.Notes[0], viewModel.Notes[0].Note);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using System.Windows.Media;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using UTAU.Views;
|
||||
using YukkuriMovieMaker.Controls;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
@@ -38,12 +37,11 @@ public sealed class NoteEditorMeasuredLayoutTests
|
||||
return result;
|
||||
}
|
||||
|
||||
static (NoteEditor Editor, NoteEditorViewModel ViewModel, Border Host) Build()
|
||||
static (NoteEditorSurface Editor, NoteEditorViewModel ViewModel, Border Host) Build()
|
||||
{
|
||||
var editor = new NoteEditor();
|
||||
var button = (PopupButton)editor.Content;
|
||||
var root = (Grid)button.PopupContent!;
|
||||
button.PopupContent = null;
|
||||
var editor = new NoteEditorSurface();
|
||||
var root = (Grid)editor.Content!;
|
||||
editor.Content = null;
|
||||
|
||||
var pronounce = new UTAUVoicePronounce();
|
||||
for (var index = 0; index < NoteCount; index++)
|
||||
@@ -102,7 +100,7 @@ public sealed class NoteEditorMeasuredLayoutTests
|
||||
return false;
|
||||
}
|
||||
|
||||
static ItemsControl KeyboardColumn(NoteEditor editor, NoteEditorViewModel viewModel)
|
||||
static ItemsControl KeyboardColumn(NoteEditorSurface editor, NoteEditorViewModel viewModel)
|
||||
=> Descend(editor.VerticalScroller)
|
||||
.OfType<ItemsControl>()
|
||||
.First(x => ReferenceEquals(x.ItemsSource, viewModel.Keyboard) && !IsUnder(x, editor.RollCanvas));
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Windows.Threading;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using UTAU.Views;
|
||||
using YukkuriMovieMaker.Controls;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
@@ -55,10 +54,9 @@ public sealed class RenderMessageDisplayTests
|
||||
|
||||
static Border Build(NoteEditorViewModel viewModel)
|
||||
{
|
||||
var editor = new NoteEditor();
|
||||
var button = (PopupButton)editor.Content;
|
||||
var root = (Grid)button.PopupContent!;
|
||||
button.PopupContent = null;
|
||||
var editor = new NoteEditorSurface();
|
||||
var root = (Grid)editor.Content!;
|
||||
editor.Content = null;
|
||||
root.DataContext = viewModel;
|
||||
|
||||
var host = new Border { Width = PopupWidth, Height = PopupHeight, Child = root };
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Windows.Media;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using UTAU.Views;
|
||||
using YukkuriMovieMaker.Controls;
|
||||
|
||||
namespace UTAU.Tests;
|
||||
|
||||
@@ -104,10 +103,9 @@ public sealed class ScrollingTextTests
|
||||
{
|
||||
var found = RunSta(() =>
|
||||
{
|
||||
var editor = new NoteEditor();
|
||||
var button = (PopupButton)editor.Content;
|
||||
var root = (Grid)button.PopupContent!;
|
||||
button.PopupContent = null;
|
||||
var editor = new NoteEditorSurface();
|
||||
var root = (Grid)editor.Content!;
|
||||
editor.Content = null;
|
||||
|
||||
var pronounce = new UTAUVoicePronounce { ImportMessage = Long, RenderMessage = Long };
|
||||
pronounce.Notes.Add(new UTAUNote { Lyric = "あ" });
|
||||
|
||||
@@ -494,3 +494,67 @@ public sealed class AnalysisCacheTests
|
||||
Assert.Equal(0, cache.UsedBytes);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class PitchTrackTests
|
||||
{
|
||||
static PhonemeUnit Unit(double start, double length, int tone, double preutterance, double overlap)
|
||||
=> new(
|
||||
new UTAUNote { Lyric = "a", Tone = tone },
|
||||
new OtoEntry(@"C:ank", "a.wav", "a", 0.0, 0.0, 0.0, preutterance, overlap),
|
||||
"a",
|
||||
start,
|
||||
length,
|
||||
start,
|
||||
length,
|
||||
tone);
|
||||
|
||||
static PitchTrack Track(params PhonemeUnit[] units)
|
||||
=> PitchTrack.Create(UnitTimingBuilder.Build(units), 0.0, 5.0, 80);
|
||||
|
||||
[Fact]
|
||||
public void ThePitchStepsAtTheNoteBoundary()
|
||||
{
|
||||
var track = Track(Unit(0.0, 200.0, 60, 0.0, 0.0), Unit(200.0, 200.0, 72, 80.0, 40.0));
|
||||
|
||||
Assert.Equal(6000.0, track.CentsAt(39), 9);
|
||||
Assert.Equal(7200.0, track.CentsAt(40), 9);
|
||||
for (var frame = 0; frame < 80; frame++)
|
||||
Assert.True(track.CentsAt(frame) is 6000.0 or 7200.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheOverlapKeepsThePitchOfThePreviousNote()
|
||||
{
|
||||
var track = Track(Unit(0.0, 200.0, 60, 0.0, 0.0), Unit(200.0, 200.0, 72, 80.0, 40.0));
|
||||
|
||||
Assert.Equal(6000.0, track.CentsAt(24), 9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void APhraseOpeningNoteExtendsItsFirstPointBackToItsAudioStart()
|
||||
{
|
||||
var second = Unit(300.0, 200.0, 72, 80.0, 40.0);
|
||||
second.Note.LengthTicks = 240;
|
||||
second.Note.PitchPoints.Add(new PitchPoint(-50, 500.0));
|
||||
second.Note.PitchPoints.Add(new PitchPoint(0, 0.0));
|
||||
var track = Track(Unit(0.0, 200.0, 60, 0.0, 0.0), second);
|
||||
|
||||
Assert.Equal(7200.0, track.CentsAt(43), 9);
|
||||
Assert.Equal(7700.0, track.CentsAt(44), 9);
|
||||
Assert.Equal(7200.0, track.CentsAt(60), 9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void APortamentoReachesAcrossThePreviousNote()
|
||||
{
|
||||
var second = Unit(200.0, 200.0, 72, 80.0, 40.0);
|
||||
second.Note.LengthTicks = 240;
|
||||
second.Note.PitchPoints.Add(new PitchPoint(-120, -1200.0));
|
||||
second.Note.PitchPoints.Add(new PitchPoint(0, 0.0));
|
||||
var track = Track(Unit(0.0, 200.0, 60, 0.0, 0.0), second);
|
||||
|
||||
Assert.Equal(6000.0, track.CentsAt(20), 9);
|
||||
Assert.Equal(6600.0, track.CentsAt(30), 9);
|
||||
Assert.Equal(7200.0, track.CentsAt(40), 9);
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="NAudio">
|
||||
<HintPath>$(YMM4DirPath)NAudio.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio.Core">
|
||||
<HintPath>$(YMM4DirPath)NAudio.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>$(YMM4DirPath)Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace UTAU.Notes;
|
||||
|
||||
internal static class LyricSplitter
|
||||
{
|
||||
public const char Quote = '"';
|
||||
public const char Separator = ' ';
|
||||
|
||||
static readonly char[] Contracted =
|
||||
['ゃ', 'ゅ', 'ょ', 'ぁ', 'ぃ', 'ぅ', 'ぇ', 'ぉ', 'ャ', 'ュ', 'ョ', 'ァ', 'ィ', 'ゥ', 'ェ', 'ォ'];
|
||||
|
||||
public static List<string> Split(string? text)
|
||||
{
|
||||
var lyrics = new List<string>();
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return lyrics;
|
||||
|
||||
var builder = new StringBuilder();
|
||||
var rest = text.AsSpan();
|
||||
while (!rest.IsEmpty)
|
||||
{
|
||||
var element = Take(ref rest);
|
||||
if (ContainsWhitespace(element))
|
||||
{
|
||||
Flush(lyrics, builder);
|
||||
}
|
||||
else if (ContainsContracted(element))
|
||||
{
|
||||
builder.Append(element);
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
}
|
||||
else if (ContainsStandalone(element))
|
||||
{
|
||||
Flush(lyrics, builder);
|
||||
builder.Append(element);
|
||||
}
|
||||
else if (IsQuote(element))
|
||||
{
|
||||
TakeQuoted(ref rest, lyrics, builder);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (builder.Length > 0 && ContainsStandalone(builder))
|
||||
{
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
}
|
||||
|
||||
builder.Append(element);
|
||||
}
|
||||
}
|
||||
|
||||
Flush(lyrics, builder);
|
||||
return lyrics;
|
||||
}
|
||||
|
||||
public static string Join(IEnumerable<string> lyrics)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
foreach (var lyric in lyrics)
|
||||
{
|
||||
if (builder.Length != 0)
|
||||
builder.Append(Separator);
|
||||
|
||||
if (lyric.Length == 0)
|
||||
builder.Append(Quote).Append(Quote);
|
||||
else if (ContainsWhitespace(lyric))
|
||||
builder.Append(Quote).Append(lyric).Append(Quote);
|
||||
else if (!ContainsStandalone(lyric))
|
||||
builder.Append(lyric);
|
||||
else if (lyric.Length == 1 || (lyric.Length == 2 && ContainsContracted(lyric.AsSpan(1))))
|
||||
builder.Append(lyric);
|
||||
else
|
||||
builder.Append(Quote).Append(lyric).Append(Quote);
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
static ReadOnlySpan<char> Take(ref ReadOnlySpan<char> rest)
|
||||
{
|
||||
var length = StringInfo.GetNextTextElementLength(rest);
|
||||
var element = rest[..length];
|
||||
rest = rest[length..];
|
||||
return element;
|
||||
}
|
||||
|
||||
static void TakeQuoted(ref ReadOnlySpan<char> rest, List<string> lyrics, StringBuilder builder)
|
||||
{
|
||||
while (!rest.IsEmpty)
|
||||
{
|
||||
var element = Take(ref rest);
|
||||
if (IsQuote(element))
|
||||
{
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
builder.Append(element);
|
||||
}
|
||||
}
|
||||
|
||||
static void Flush(List<string> lyrics, StringBuilder builder)
|
||||
{
|
||||
if (builder.Length == 0)
|
||||
return;
|
||||
|
||||
lyrics.Add(builder.ToString());
|
||||
builder.Clear();
|
||||
}
|
||||
|
||||
static bool IsQuote(ReadOnlySpan<char> element) => element.Length == 1 && element[0] == Quote;
|
||||
|
||||
static bool ContainsWhitespace(ReadOnlySpan<char> element)
|
||||
{
|
||||
foreach (var value in element)
|
||||
{
|
||||
if (char.IsWhiteSpace(value))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ContainsContracted(ReadOnlySpan<char> element) => element.IndexOfAny(Contracted) >= 0;
|
||||
|
||||
static bool ContainsStandalone(ReadOnlySpan<char> element)
|
||||
{
|
||||
foreach (var value in element)
|
||||
{
|
||||
if (IsStandalone(value))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ContainsStandalone(StringBuilder builder)
|
||||
{
|
||||
foreach (var chunk in builder.GetChunks())
|
||||
{
|
||||
if (ContainsStandalone(chunk.Span))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsStandalone(char value)
|
||||
=> value is >= '\u4e00' and <= '\u9fff'
|
||||
or >= '\u3040' and <= '\u309f'
|
||||
or >= '\u30a0' and <= '\u30ff'
|
||||
or >= '\uac00' and <= '\ud7af';
|
||||
}
|
||||
+12
-8
@@ -15,6 +15,10 @@ internal sealed class UTAUNote : UndoRedoable
|
||||
public const int MaximumLengthTicks = TimeBase.TicksPerWholeNote * 16;
|
||||
public const double DefaultFadeInMilliseconds = 5.0;
|
||||
public const double DefaultFadeOutMilliseconds = 35.0;
|
||||
public const double DefaultVelocity = 100.0;
|
||||
public const double DefaultIntensity = 100.0;
|
||||
public const double DefaultModulation = 0.0;
|
||||
public const double DefaultStartPointMilliseconds = 0.0;
|
||||
public const double FollowOtoValue = 0.0;
|
||||
public const double FollowScoreValue = 0.0;
|
||||
public const string RestLyric = "R";
|
||||
@@ -24,10 +28,10 @@ internal sealed class UTAUNote : UndoRedoable
|
||||
bool suppressAutoVcv;
|
||||
int tone = MusicalTone.MiddleC.NoteNumber;
|
||||
int lengthTicks = DefaultLengthTicks;
|
||||
double velocity = 100.0;
|
||||
double intensity = 100.0;
|
||||
double modulation;
|
||||
double startPointMilliseconds;
|
||||
double velocity = DefaultVelocity;
|
||||
double intensity = DefaultIntensity;
|
||||
double modulation = DefaultModulation;
|
||||
double startPointMilliseconds = DefaultStartPointMilliseconds;
|
||||
double tempoOverride;
|
||||
double preutteranceOverride;
|
||||
double overlapOverride;
|
||||
@@ -103,7 +107,7 @@ internal sealed class UTAUNote : UndoRedoable
|
||||
[Display(GroupName = nameof(Texts.NoteGroupExpression), Name = nameof(Texts.NoteVelocity), Description = nameof(Texts.NoteVelocityDescription), ResourceType = typeof(Texts))]
|
||||
[TextBoxSlider("F0", "", 0.0, 200.0, Delay = -1)]
|
||||
[Range(0.0, 200.0)]
|
||||
[DefaultValue(100.0)]
|
||||
[DefaultValue(DefaultVelocity)]
|
||||
public double Velocity
|
||||
{
|
||||
get => velocity;
|
||||
@@ -113,7 +117,7 @@ internal sealed class UTAUNote : UndoRedoable
|
||||
[Display(GroupName = nameof(Texts.NoteGroupExpression), Name = nameof(Texts.NoteIntensity), ResourceType = typeof(Texts))]
|
||||
[TextBoxSlider("F0", "%", 0.0, 200.0, Delay = -1)]
|
||||
[Range(0.0, 200.0)]
|
||||
[DefaultValue(100.0)]
|
||||
[DefaultValue(DefaultIntensity)]
|
||||
public double Intensity
|
||||
{
|
||||
get => intensity;
|
||||
@@ -123,7 +127,7 @@ internal sealed class UTAUNote : UndoRedoable
|
||||
[Display(GroupName = nameof(Texts.NoteGroupExpression), Name = nameof(Texts.NoteModulation), Description = nameof(Texts.ParameterModulationDescription), ResourceType = typeof(Texts))]
|
||||
[TextBoxSlider("F0", "%", -200.0, 200.0, Delay = -1)]
|
||||
[Range(-200.0, 200.0)]
|
||||
[DefaultValue(0.0)]
|
||||
[DefaultValue(DefaultModulation)]
|
||||
public double Modulation
|
||||
{
|
||||
get => modulation;
|
||||
@@ -153,7 +157,7 @@ internal sealed class UTAUNote : UndoRedoable
|
||||
[Display(GroupName = nameof(Texts.NoteGroupTiming), Name = nameof(Texts.NoteStartPoint), Description = nameof(Texts.NoteStartPointDescription), ResourceType = typeof(Texts))]
|
||||
[TextBoxSlider("F0", "ms", 0.0, 500.0, Delay = -1)]
|
||||
[Range(0.0, 5000.0)]
|
||||
[DefaultValue(0.0)]
|
||||
[DefaultValue(DefaultStartPointMilliseconds)]
|
||||
public double StartPointMilliseconds
|
||||
{
|
||||
get => startPointMilliseconds;
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
using UTAU.Notes;
|
||||
|
||||
namespace UTAU.Synthesis;
|
||||
|
||||
internal sealed class PitchTrack
|
||||
{
|
||||
readonly record struct TrackNote(UTAUNote Note, double StartMilliseconds, double LengthMilliseconds, int Tone, double AudioStartMilliseconds)
|
||||
{
|
||||
public double EndMilliseconds => StartMilliseconds + LengthMilliseconds;
|
||||
|
||||
public double Cents => Tone * 100.0;
|
||||
}
|
||||
|
||||
readonly double[] cents;
|
||||
|
||||
PitchTrack(double[] cents) => this.cents = cents;
|
||||
|
||||
public static PitchTrack Create(IReadOnlyList<UnitTiming> timings, double startMilliseconds, double framePeriod, int frameCount)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(timings);
|
||||
|
||||
var cents = new double[Math.Max(frameCount, 0)];
|
||||
var notes = CollectNotes(timings);
|
||||
if (cents.Length == 0 || notes.Count == 0)
|
||||
return new PitchTrack(cents);
|
||||
|
||||
FillTones(cents, notes, startMilliseconds, framePeriod);
|
||||
ApplyVibrato(cents, notes, startMilliseconds, framePeriod);
|
||||
ApplyPortamento(cents, notes, startMilliseconds, framePeriod);
|
||||
return new PitchTrack(cents);
|
||||
}
|
||||
|
||||
public double CentsAt(int frame)
|
||||
=> cents.Length == 0 ? 0.0 : cents[Math.Clamp(frame, 0, cents.Length - 1)];
|
||||
|
||||
static List<TrackNote> CollectNotes(IReadOnlyList<UnitTiming> timings)
|
||||
{
|
||||
var notes = new List<TrackNote>(timings.Count);
|
||||
foreach (var timing in timings)
|
||||
{
|
||||
var unit = timing.Unit;
|
||||
if (unit.Note.IsRest)
|
||||
continue;
|
||||
notes.Add(new TrackNote(unit.Note, unit.NoteStartMilliseconds, unit.NoteLengthMilliseconds, unit.Tone, timing.AudioStartMilliseconds));
|
||||
}
|
||||
|
||||
notes.Sort((left, right) => left.StartMilliseconds.CompareTo(right.StartMilliseconds));
|
||||
|
||||
var distinct = new List<TrackNote>(notes.Count);
|
||||
foreach (var note in notes)
|
||||
{
|
||||
if (distinct.Count > 0 && distinct[^1].StartMilliseconds == note.StartMilliseconds && ReferenceEquals(distinct[^1].Note, note.Note))
|
||||
{
|
||||
distinct[^1] = distinct[^1] with
|
||||
{
|
||||
AudioStartMilliseconds = Math.Min(distinct[^1].AudioStartMilliseconds, note.AudioStartMilliseconds),
|
||||
};
|
||||
continue;
|
||||
}
|
||||
distinct.Add(note);
|
||||
}
|
||||
return distinct;
|
||||
}
|
||||
|
||||
static void FillTones(double[] cents, List<TrackNote> notes, double startMilliseconds, double framePeriod)
|
||||
{
|
||||
var index = 0;
|
||||
foreach (var note in notes)
|
||||
{
|
||||
while (index < cents.Length && startMilliseconds + index * framePeriod < note.EndMilliseconds)
|
||||
{
|
||||
cents[index] = note.Cents;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
Array.Fill(cents, notes[^1].Cents);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = index; i < cents.Length; i++)
|
||||
cents[i] = cents[i - 1];
|
||||
}
|
||||
|
||||
static void ApplyVibrato(double[] cents, List<TrackNote> notes, double startMilliseconds, double framePeriod)
|
||||
{
|
||||
foreach (var note in notes)
|
||||
{
|
||||
if (!note.Note.Vibrato.IsEnabled)
|
||||
continue;
|
||||
|
||||
var from = Math.Max((int)Math.Ceiling((note.StartMilliseconds - startMilliseconds) / framePeriod), 0);
|
||||
var to = Math.Min((int)((note.EndMilliseconds - startMilliseconds) / framePeriod), cents.Length);
|
||||
for (var i = from; i < to; i++)
|
||||
cents[i] = note.Cents + note.Note.Vibrato.Evaluate(startMilliseconds + i * framePeriod - note.StartMilliseconds, note.LengthMilliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
static void ApplyPortamento(double[] cents, List<TrackNote> notes, double startMilliseconds, double framePeriod)
|
||||
{
|
||||
for (var n = 0; n < notes.Count; n++)
|
||||
{
|
||||
var note = notes[n];
|
||||
if (note.Note.PitchPoints.Count == 0 || note.Note.LengthTicks <= 0)
|
||||
continue;
|
||||
|
||||
var scale = note.LengthMilliseconds / note.Note.LengthTicks;
|
||||
var points = new List<(double X, double Y, PitchPointShape Shape)>(note.Note.PitchPoints.Count + 2);
|
||||
foreach (var point in note.Note.PitchPoints)
|
||||
points.Add((note.StartMilliseconds + point.Ticks * scale, note.Cents + point.Cents, point.Shape));
|
||||
|
||||
var opensPhrase = n == 0 || notes[n - 1].EndMilliseconds < note.StartMilliseconds;
|
||||
var lead = opensPhrase
|
||||
? Math.Max(startMilliseconds, note.AudioStartMilliseconds)
|
||||
: note.StartMilliseconds;
|
||||
if (points[0].X > lead)
|
||||
points.Insert(0, (lead, points[0].Y, points[0].Shape));
|
||||
if (points[^1].X < note.EndMilliseconds)
|
||||
points.Add((note.EndMilliseconds, points[^1].Y, points[^1].Shape));
|
||||
|
||||
for (var s = 0; s < points.Count - 1; s++)
|
||||
{
|
||||
var from = points[s];
|
||||
var to = points[s + 1];
|
||||
var first = Math.Max((int)Math.Ceiling((from.X - startMilliseconds) / framePeriod), 0);
|
||||
var last = Math.Min((int)Math.Ceiling((to.X - startMilliseconds) / framePeriod), cents.Length);
|
||||
var span = to.X - from.X;
|
||||
|
||||
for (var i = first; i < last; i++)
|
||||
{
|
||||
var x = startMilliseconds + i * framePeriod;
|
||||
var progress = span <= 0.0 ? 1.0 : (x - from.X) / span;
|
||||
var pitch = PitchPoint.Interpolate(from.Y, to.Y, progress, from.Shape);
|
||||
var basePitch = n > 0 && x < notes[n - 1].EndMilliseconds ? notes[n - 1].Cents : note.Cents;
|
||||
cents[i] += pitch - basePitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,6 +314,12 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
|
||||
Array.Clear(voicedWeight, 0, frameCount);
|
||||
Array.Clear(logF0Sum, 0, frameCount);
|
||||
|
||||
var track = PitchTrack.Create(
|
||||
[.. segment.TimingIndices.Select(x => timings[x])],
|
||||
offset + segment.StartFrame * framePeriod,
|
||||
framePeriod,
|
||||
frameCount);
|
||||
|
||||
foreach (var index in segment.TimingIndices)
|
||||
{
|
||||
var source = BuildSource(requests[index], arena);
|
||||
@@ -323,6 +329,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
|
||||
AccumulateUnit(
|
||||
timings[index],
|
||||
source,
|
||||
track,
|
||||
offset,
|
||||
framePeriod,
|
||||
segment.StartFrame,
|
||||
@@ -359,6 +366,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
|
||||
void AccumulateUnit(
|
||||
UnitTiming timing,
|
||||
UnitSource source,
|
||||
PitchTrack track,
|
||||
double offset,
|
||||
double framePeriod,
|
||||
int segmentStartFrame,
|
||||
@@ -420,11 +428,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
|
||||
if (sourceF0 <= 0.0)
|
||||
continue;
|
||||
|
||||
var progress = unit.NoteLengthMilliseconds > 0.0
|
||||
? (absolute - unit.NoteStartMilliseconds) / unit.NoteLengthMilliseconds
|
||||
: 0.0;
|
||||
var cents = note.EvaluatePitchOffsetCents(progress, unit.NoteLengthMilliseconds);
|
||||
var targetF0 = MusicalTone.FrequencyOf(unit.Tone + cents / 100.0);
|
||||
var targetF0 = MusicalTone.FrequencyOf(track.CentsAt(frame) / 100.0);
|
||||
var ratio = source.MeanF0 > 0.0 ? sourceF0 / source.MeanF0 : 1.0;
|
||||
var value = targetF0 * Math.Pow(ratio, modulation);
|
||||
if (!double.IsFinite(value) || value <= 0.0)
|
||||
@@ -665,6 +669,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
|
||||
}
|
||||
catch (Exception exception) when (exception is IOException or InvalidOperationException or FormatException or NotSupportedException or ArgumentException)
|
||||
{
|
||||
UTAUTelemetry.Report(exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -691,6 +696,7 @@ internal sealed class UtauRenderer(RenderSettings settings, RenderCurves curves,
|
||||
}
|
||||
catch (Exception exception) when (exception is IOException or InvalidOperationException or FormatException or NotSupportedException or ArgumentException)
|
||||
{
|
||||
UTAUTelemetry.Report(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +198,15 @@
|
||||
<data name="PitchPointCentsDescription" xml:space="preserve"><value>الانحراف عن درجة النوتة. 100 سنت تساوي نصف نغمة.</value></data>
|
||||
<data name="SelectAllNotes" xml:space="preserve"><value>تحديد كل النوتات</value></data>
|
||||
<data name="SelectionCountFormat" xml:space="preserve"><value>تم تحديد {0} نوتة</value></data>
|
||||
<data name="NoteContextCopy" xml:space="preserve"><value>نسخ النوتات</value></data>
|
||||
<data name="NoteContextPaste" xml:space="preserve"><value>لصق النوتات</value></data>
|
||||
<data name="OctaveUp" xml:space="preserve"><value>رفع أوكتاف</value></data>
|
||||
<data name="OctaveDown" xml:space="preserve"><value>خفض أوكتاف</value></data>
|
||||
<data name="QuantizeLength" xml:space="preserve"><value>محاذاة الأطوال إلى المحاذاة</value></data>
|
||||
<data name="ResetGroup" xml:space="preserve"><value>إعادة الضبط</value></data>
|
||||
<data name="ResetVibrato" xml:space="preserve"><value>إعادة ضبط الفيبراتو</value></data>
|
||||
<data name="ResetTiming" xml:space="preserve"><value>إعادة ضبط التوقيت</value></data>
|
||||
<data name="ResetNote" xml:space="preserve"><value>إعادة ضبط النوتات إلى الافتراضي</value></data>
|
||||
<data name="UstImportedFormat" xml:space="preserve"><value>تم تحميل {0} نوتة</value></data>
|
||||
<data name="UstImportFailed" xml:space="preserve"><value>تعذّر قراءة ملف UST</value></data>
|
||||
<data name="UstImportEmpty" xml:space="preserve"><value>لا توجد نوتات لتحميلها في الملف</value></data>
|
||||
@@ -208,4 +217,11 @@
|
||||
<data name="UstPhraseOffsetFormat" xml:space="preserve"><value>من التِك {0} في الأصل</value></data>
|
||||
<data name="NoteTempo" xml:space="preserve"><value>الإيقاع</value></data>
|
||||
<data name="NoteTempoDescription" xml:space="preserve"><value>القيمة 0 تتبع إيقاع النوتة الموسيقية. وإدخال قيمة يغيّر الإيقاع بدءاً من هذه النوتة.</value></data>
|
||||
<data name="EditLyrics" xml:space="preserve"><value>تحرير الكلمات دفعة واحدة</value></data>
|
||||
<data name="LyricsBulkEditHint" xml:space="preserve"><value>تُفصل الكلمات بالمسافات وفواصل الأسطر. تُؤخذ الكانجي والكانا حرفاً حرفاً، ويصبح الجزء المحاط بعلامتي اقتباس نوتة واحدة.</value></data>
|
||||
<data name="LyricCountFormat" xml:space="preserve"><value>{0} / {1}</value></data>
|
||||
<data name="ButtonApply" xml:space="preserve"><value>تطبيق</value></data>
|
||||
<data name="ButtonCancel" xml:space="preserve"><value>إلغاء</value></data>
|
||||
<data name="ButtonReset" xml:space="preserve"><value>استرجاع</value></data>
|
||||
<data name="DetachEditor" xml:space="preserve"><value>التحرير في نافذة منفصلة</value></data>
|
||||
</root>
|
||||
@@ -138,6 +138,15 @@ PitchPointTimeDescription,,ノートの先頭からの位置です。480ティ
|
||||
PitchPointCentsDescription,,ノートの音程からのずれです。100セントが半音です。,The offset from the pitch of the note. 100 cents is a semitone.,相对音符音高的偏移。100 音分为半音。,相對音符音高的偏移。100 音分為半音。,노트 음정으로부터의 차이입니다. 100센트가 반음입니다.,El desvío respecto al tono de la nota. 100 centésimas equivalen a un semitono.,الانحراف عن درجة النوتة. 100 سنت تساوي نصف نغمة.,Selisih dari nada not. 100 sen sama dengan satu seminada.
|
||||
SelectAllNotes,,すべてのノートを選択,Select all the notes,选择所有音符,選擇所有音符,모든 노트 선택,Seleccionar todas las notas,تحديد كل النوتات,Pilih semua not
|
||||
SelectionCountFormat,,{0} 個を選択中,{0} notes selected,已选择 {0} 个音符,已選擇 {0} 個音符,{0}개 선택 중,{0} notas seleccionadas,تم تحديد {0} نوتة,{0} not terpilih
|
||||
NoteContextCopy,,ノートをコピー,Copy the notes,复制音符,複製音符,노트 복사,Copiar las notas,نسخ النوتات,Salin not
|
||||
NoteContextPaste,,ノートを貼り付け,Paste the notes,粘贴音符,貼上音符,노트 붙여넣기,Pegar las notas,لصق النوتات,Tempel not
|
||||
OctaveUp,,オクターブ上げる,Move an octave up,升高八度,升高八度,한 옥타브 올리기,Subir una octava,رفع أوكتاف,Naikkan satu oktaf
|
||||
OctaveDown,,オクターブ下げる,Move an octave down,降低八度,降低八度,한 옥타브 내리기,Bajar una octava,خفض أوكتاف,Turunkan satu oktaf
|
||||
QuantizeLength,,長さを吸着に合わせる,Round the lengths to the snap,将长度对齐到吸附,將長度對齊到吸附,길이를 스냅에 맞추기,Ajustar las duraciones al ajuste,محاذاة الأطوال إلى المحاذاة,Bulatkan panjang ke pengancingan
|
||||
ResetGroup,,戻す,Reset,重置,重設,되돌리기,Restablecer,إعادة الضبط,Setel ulang
|
||||
ResetVibrato,,ビブラートを戻す,Reset the vibrato,重置颤音,重設顫音,비브라토 되돌리기,Restablecer el vibrato,إعادة ضبط الفيبراتو,Setel ulang vibrato
|
||||
ResetTiming,,発声タイミングを戻す,Reset the timing,重置发声时间,重設發聲時間,발성 타이밍 되돌리기,Restablecer los tiempos,إعادة ضبط التوقيت,Setel ulang pewaktuan
|
||||
ResetNote,,ノートを既定に戻す,Reset the notes to the defaults,将音符重置为默认值,將音符重設為預設值,노트를 기본값으로 되돌리기,Restablecer las notas a los valores predeterminados,إعادة ضبط النوتات إلى الافتراضي,Setel ulang not ke bawaan
|
||||
UstImportedFormat,,{0} 個のノートを読み込みました,Loaded {0} notes,已载入 {0} 个音符,已載入 {0} 個音符,노트 {0}개를 불러왔습니다,Se cargaron {0} notas,تم تحميل {0} نوتة,Memuat {0} not
|
||||
UstImportFailed,,USTを読み込めませんでした,The UST file could not be read,无法读取 UST 文件,無法讀取 UST 檔案,UST를 읽지 못했습니다,No se pudo leer el archivo UST,تعذّر قراءة ملف UST,Berkas UST tidak dapat dibaca
|
||||
UstImportEmpty,,読み込めるノートがありません,The file has no notes to load,文件中没有可载入的音符,檔案中沒有可載入的音符,불러올 노트가 없습니다,El archivo no tiene notas que cargar,لا توجد نوتات لتحميلها في الملف,Berkas tidak memiliki not untuk dimuat
|
||||
@@ -148,3 +157,10 @@ UstPhraseRangeFormat,,全 {2} フレーズ中 {0} から {1} 個,{1} of {2} phra
|
||||
UstPhraseOffsetFormat,,元の {0} ティック目から,from tick {0} of the original,自原曲第 {0} 刻,自原曲第 {0} 刻,원곡 {0}틱부터,desde el tic {0} del original,من التِك {0} في الأصل,dari tik {0} aslinya
|
||||
NoteTempo,,テンポ,Tempo,速度,速度,템포,Tempo,الإيقاع,Tempo
|
||||
NoteTempoDescription,,0でこの譜面のテンポに従います。値を入れるとこのノートから先のテンポが変わります。,0 follows the tempo of the score. A value changes the tempo from this note onward.,0 表示沿用乐谱的速度。填入数值则从该音符起改变速度。,0 表示沿用樂譜的速度。填入數值則從該音符起改變速度。,0이면 악보의 템포를 따릅니다. 값을 넣으면 이 노트부터 템포가 바뀝니다.,0 sigue el tempo de la partitura. Un valor cambia el tempo a partir de esta nota.,القيمة 0 تتبع إيقاع النوتة الموسيقية. وإدخال قيمة يغيّر الإيقاع بدءاً من هذه النوتة.,0 mengikuti tempo partitur. Sebuah nilai mengubah tempo mulai dari not ini.
|
||||
EditLyrics,,歌詞をまとめて編集,Edit the lyrics together,批量编辑歌词,批次編輯歌詞,가사 일괄 편집,Editar las letras en conjunto,تحرير الكلمات دفعة واحدة,Sunting lirik sekaligus
|
||||
LyricsBulkEditHint,,空白と改行で区切ります。漢字とかなは1文字ずつ、引用符で囲んだ部分はまとめて1つのノートになります。,"Words are separated by spaces and line breaks. Kanji and kana are taken one character at a time, and a part enclosed in quotation marks becomes a single note.",以空格与换行分隔。汉字与假名逐字分开,用引号括起的部分作为一个音符。,以空格與換行分隔。漢字與假名逐字分開,用引號括起的部分作為一個音符。,"공백과 줄바꿈으로 나눕니다. 한자와 가나는 한 글자씩, 따옴표로 묶은 부분은 하나의 노트가 됩니다.",Las palabras se separan con espacios y saltos de línea. Los kanji y los kana se toman de uno en uno y la parte entre comillas forma una sola nota.,تُفصل الكلمات بالمسافات وفواصل الأسطر. تُؤخذ الكانجي والكانا حرفاً حرفاً، ويصبح الجزء المحاط بعلامتي اقتباس نوتة واحدة.,"Kata dipisahkan dengan spasi dan ganti baris. Kanji dan kana diambil satu per satu, dan bagian dalam tanda kutip menjadi satu not."
|
||||
LyricCountFormat,,{0} / {1},{0} / {1},{0} / {1},{0} / {1},{0} / {1},{0} / {1},{0} / {1},{0} / {1}
|
||||
ButtonApply,,適用,Apply,应用,套用,적용,Aplicar,تطبيق,Terapkan
|
||||
ButtonCancel,,取り消し,Cancel,取消,取消,취소,Cancelar,إلغاء,Batal
|
||||
ButtonReset,,元に戻す,Revert,还原,還原,되돌리기,Revertir,استرجاع,Kembalikan
|
||||
DetachEditor,,別ウィンドウで編集,Edit in a separate window,在独立窗口中编辑,在獨立視窗中編輯,별도 창에서 편집,Editar en una ventana aparte,التحرير في نافذة منفصلة,Sunting di jendela terpisah
|
||||
|
@@ -198,6 +198,15 @@
|
||||
<data name="PitchPointCentsDescription" xml:space="preserve"><value>The offset from the pitch of the note. 100 cents is a semitone.</value></data>
|
||||
<data name="SelectAllNotes" xml:space="preserve"><value>Select all the notes</value></data>
|
||||
<data name="SelectionCountFormat" xml:space="preserve"><value>{0} notes selected</value></data>
|
||||
<data name="NoteContextCopy" xml:space="preserve"><value>Copy the notes</value></data>
|
||||
<data name="NoteContextPaste" xml:space="preserve"><value>Paste the notes</value></data>
|
||||
<data name="OctaveUp" xml:space="preserve"><value>Move an octave up</value></data>
|
||||
<data name="OctaveDown" xml:space="preserve"><value>Move an octave down</value></data>
|
||||
<data name="QuantizeLength" xml:space="preserve"><value>Round the lengths to the snap</value></data>
|
||||
<data name="ResetGroup" xml:space="preserve"><value>Reset</value></data>
|
||||
<data name="ResetVibrato" xml:space="preserve"><value>Reset the vibrato</value></data>
|
||||
<data name="ResetTiming" xml:space="preserve"><value>Reset the timing</value></data>
|
||||
<data name="ResetNote" xml:space="preserve"><value>Reset the notes to the defaults</value></data>
|
||||
<data name="UstImportedFormat" xml:space="preserve"><value>Loaded {0} notes</value></data>
|
||||
<data name="UstImportFailed" xml:space="preserve"><value>The UST file could not be read</value></data>
|
||||
<data name="UstImportEmpty" xml:space="preserve"><value>The file has no notes to load</value></data>
|
||||
@@ -208,4 +217,11 @@
|
||||
<data name="UstPhraseOffsetFormat" xml:space="preserve"><value>from tick {0} of the original</value></data>
|
||||
<data name="NoteTempo" xml:space="preserve"><value>Tempo</value></data>
|
||||
<data name="NoteTempoDescription" xml:space="preserve"><value>0 follows the tempo of the score. A value changes the tempo from this note onward.</value></data>
|
||||
<data name="EditLyrics" xml:space="preserve"><value>Edit the lyrics together</value></data>
|
||||
<data name="LyricsBulkEditHint" xml:space="preserve"><value>Words are separated by spaces and line breaks. Kanji and kana are taken one character at a time, and a part enclosed in quotation marks becomes a single note.</value></data>
|
||||
<data name="LyricCountFormat" xml:space="preserve"><value>{0} / {1}</value></data>
|
||||
<data name="ButtonApply" xml:space="preserve"><value>Apply</value></data>
|
||||
<data name="ButtonCancel" xml:space="preserve"><value>Cancel</value></data>
|
||||
<data name="ButtonReset" xml:space="preserve"><value>Revert</value></data>
|
||||
<data name="DetachEditor" xml:space="preserve"><value>Edit in a separate window</value></data>
|
||||
</root>
|
||||
@@ -198,6 +198,15 @@
|
||||
<data name="PitchPointCentsDescription" xml:space="preserve"><value>El desvío respecto al tono de la nota. 100 centésimas equivalen a un semitono.</value></data>
|
||||
<data name="SelectAllNotes" xml:space="preserve"><value>Seleccionar todas las notas</value></data>
|
||||
<data name="SelectionCountFormat" xml:space="preserve"><value>{0} notas seleccionadas</value></data>
|
||||
<data name="NoteContextCopy" xml:space="preserve"><value>Copiar las notas</value></data>
|
||||
<data name="NoteContextPaste" xml:space="preserve"><value>Pegar las notas</value></data>
|
||||
<data name="OctaveUp" xml:space="preserve"><value>Subir una octava</value></data>
|
||||
<data name="OctaveDown" xml:space="preserve"><value>Bajar una octava</value></data>
|
||||
<data name="QuantizeLength" xml:space="preserve"><value>Ajustar las duraciones al ajuste</value></data>
|
||||
<data name="ResetGroup" xml:space="preserve"><value>Restablecer</value></data>
|
||||
<data name="ResetVibrato" xml:space="preserve"><value>Restablecer el vibrato</value></data>
|
||||
<data name="ResetTiming" xml:space="preserve"><value>Restablecer los tiempos</value></data>
|
||||
<data name="ResetNote" xml:space="preserve"><value>Restablecer las notas a los valores predeterminados</value></data>
|
||||
<data name="UstImportedFormat" xml:space="preserve"><value>Se cargaron {0} notas</value></data>
|
||||
<data name="UstImportFailed" xml:space="preserve"><value>No se pudo leer el archivo UST</value></data>
|
||||
<data name="UstImportEmpty" xml:space="preserve"><value>El archivo no tiene notas que cargar</value></data>
|
||||
@@ -208,4 +217,11 @@
|
||||
<data name="UstPhraseOffsetFormat" xml:space="preserve"><value>desde el tic {0} del original</value></data>
|
||||
<data name="NoteTempo" xml:space="preserve"><value>Tempo</value></data>
|
||||
<data name="NoteTempoDescription" xml:space="preserve"><value>0 sigue el tempo de la partitura. Un valor cambia el tempo a partir de esta nota.</value></data>
|
||||
<data name="EditLyrics" xml:space="preserve"><value>Editar las letras en conjunto</value></data>
|
||||
<data name="LyricsBulkEditHint" xml:space="preserve"><value>Las palabras se separan con espacios y saltos de línea. Los kanji y los kana se toman de uno en uno y la parte entre comillas forma una sola nota.</value></data>
|
||||
<data name="LyricCountFormat" xml:space="preserve"><value>{0} / {1}</value></data>
|
||||
<data name="ButtonApply" xml:space="preserve"><value>Aplicar</value></data>
|
||||
<data name="ButtonCancel" xml:space="preserve"><value>Cancelar</value></data>
|
||||
<data name="ButtonReset" xml:space="preserve"><value>Revertir</value></data>
|
||||
<data name="DetachEditor" xml:space="preserve"><value>Editar en una ventana aparte</value></data>
|
||||
</root>
|
||||
@@ -198,6 +198,15 @@
|
||||
<data name="PitchPointCentsDescription" xml:space="preserve"><value>Selisih dari nada not. 100 sen sama dengan satu seminada.</value></data>
|
||||
<data name="SelectAllNotes" xml:space="preserve"><value>Pilih semua not</value></data>
|
||||
<data name="SelectionCountFormat" xml:space="preserve"><value>{0} not terpilih</value></data>
|
||||
<data name="NoteContextCopy" xml:space="preserve"><value>Salin not</value></data>
|
||||
<data name="NoteContextPaste" xml:space="preserve"><value>Tempel not</value></data>
|
||||
<data name="OctaveUp" xml:space="preserve"><value>Naikkan satu oktaf</value></data>
|
||||
<data name="OctaveDown" xml:space="preserve"><value>Turunkan satu oktaf</value></data>
|
||||
<data name="QuantizeLength" xml:space="preserve"><value>Bulatkan panjang ke pengancingan</value></data>
|
||||
<data name="ResetGroup" xml:space="preserve"><value>Setel ulang</value></data>
|
||||
<data name="ResetVibrato" xml:space="preserve"><value>Setel ulang vibrato</value></data>
|
||||
<data name="ResetTiming" xml:space="preserve"><value>Setel ulang pewaktuan</value></data>
|
||||
<data name="ResetNote" xml:space="preserve"><value>Setel ulang not ke bawaan</value></data>
|
||||
<data name="UstImportedFormat" xml:space="preserve"><value>Memuat {0} not</value></data>
|
||||
<data name="UstImportFailed" xml:space="preserve"><value>Berkas UST tidak dapat dibaca</value></data>
|
||||
<data name="UstImportEmpty" xml:space="preserve"><value>Berkas tidak memiliki not untuk dimuat</value></data>
|
||||
@@ -208,4 +217,11 @@
|
||||
<data name="UstPhraseOffsetFormat" xml:space="preserve"><value>dari tik {0} aslinya</value></data>
|
||||
<data name="NoteTempo" xml:space="preserve"><value>Tempo</value></data>
|
||||
<data name="NoteTempoDescription" xml:space="preserve"><value>0 mengikuti tempo partitur. Sebuah nilai mengubah tempo mulai dari not ini.</value></data>
|
||||
<data name="EditLyrics" xml:space="preserve"><value>Sunting lirik sekaligus</value></data>
|
||||
<data name="LyricsBulkEditHint" xml:space="preserve"><value>Kata dipisahkan dengan spasi dan ganti baris. Kanji dan kana diambil satu per satu, dan bagian dalam tanda kutip menjadi satu not.</value></data>
|
||||
<data name="LyricCountFormat" xml:space="preserve"><value>{0} / {1}</value></data>
|
||||
<data name="ButtonApply" xml:space="preserve"><value>Terapkan</value></data>
|
||||
<data name="ButtonCancel" xml:space="preserve"><value>Batal</value></data>
|
||||
<data name="ButtonReset" xml:space="preserve"><value>Kembalikan</value></data>
|
||||
<data name="DetachEditor" xml:space="preserve"><value>Sunting di jendela terpisah</value></data>
|
||||
</root>
|
||||
@@ -198,6 +198,15 @@
|
||||
<data name="PitchPointCentsDescription" xml:space="preserve"><value>노트 음정으로부터의 차이입니다. 100센트가 반음입니다.</value></data>
|
||||
<data name="SelectAllNotes" xml:space="preserve"><value>모든 노트 선택</value></data>
|
||||
<data name="SelectionCountFormat" xml:space="preserve"><value>{0}개 선택 중</value></data>
|
||||
<data name="NoteContextCopy" xml:space="preserve"><value>노트 복사</value></data>
|
||||
<data name="NoteContextPaste" xml:space="preserve"><value>노트 붙여넣기</value></data>
|
||||
<data name="OctaveUp" xml:space="preserve"><value>한 옥타브 올리기</value></data>
|
||||
<data name="OctaveDown" xml:space="preserve"><value>한 옥타브 내리기</value></data>
|
||||
<data name="QuantizeLength" xml:space="preserve"><value>길이를 스냅에 맞추기</value></data>
|
||||
<data name="ResetGroup" xml:space="preserve"><value>되돌리기</value></data>
|
||||
<data name="ResetVibrato" xml:space="preserve"><value>비브라토 되돌리기</value></data>
|
||||
<data name="ResetTiming" xml:space="preserve"><value>발성 타이밍 되돌리기</value></data>
|
||||
<data name="ResetNote" xml:space="preserve"><value>노트를 기본값으로 되돌리기</value></data>
|
||||
<data name="UstImportedFormat" xml:space="preserve"><value>노트 {0}개를 불러왔습니다</value></data>
|
||||
<data name="UstImportFailed" xml:space="preserve"><value>UST를 읽지 못했습니다</value></data>
|
||||
<data name="UstImportEmpty" xml:space="preserve"><value>불러올 노트가 없습니다</value></data>
|
||||
@@ -208,4 +217,11 @@
|
||||
<data name="UstPhraseOffsetFormat" xml:space="preserve"><value>원곡 {0}틱부터</value></data>
|
||||
<data name="NoteTempo" xml:space="preserve"><value>템포</value></data>
|
||||
<data name="NoteTempoDescription" xml:space="preserve"><value>0이면 악보의 템포를 따릅니다. 값을 넣으면 이 노트부터 템포가 바뀝니다.</value></data>
|
||||
<data name="EditLyrics" xml:space="preserve"><value>가사 일괄 편집</value></data>
|
||||
<data name="LyricsBulkEditHint" xml:space="preserve"><value>공백과 줄바꿈으로 나눕니다. 한자와 가나는 한 글자씩, 따옴표로 묶은 부분은 하나의 노트가 됩니다.</value></data>
|
||||
<data name="LyricCountFormat" xml:space="preserve"><value>{0} / {1}</value></data>
|
||||
<data name="ButtonApply" xml:space="preserve"><value>적용</value></data>
|
||||
<data name="ButtonCancel" xml:space="preserve"><value>취소</value></data>
|
||||
<data name="ButtonReset" xml:space="preserve"><value>되돌리기</value></data>
|
||||
<data name="DetachEditor" xml:space="preserve"><value>별도 창에서 편집</value></data>
|
||||
</root>
|
||||
@@ -198,6 +198,15 @@
|
||||
<data name="PitchPointCentsDescription" xml:space="preserve"><value>ノートの音程からのずれです。100セントが半音です。</value></data>
|
||||
<data name="SelectAllNotes" xml:space="preserve"><value>すべてのノートを選択</value></data>
|
||||
<data name="SelectionCountFormat" xml:space="preserve"><value>{0} 個を選択中</value></data>
|
||||
<data name="NoteContextCopy" xml:space="preserve"><value>ノートをコピー</value></data>
|
||||
<data name="NoteContextPaste" xml:space="preserve"><value>ノートを貼り付け</value></data>
|
||||
<data name="OctaveUp" xml:space="preserve"><value>オクターブ上げる</value></data>
|
||||
<data name="OctaveDown" xml:space="preserve"><value>オクターブ下げる</value></data>
|
||||
<data name="QuantizeLength" xml:space="preserve"><value>長さを吸着に合わせる</value></data>
|
||||
<data name="ResetGroup" xml:space="preserve"><value>戻す</value></data>
|
||||
<data name="ResetVibrato" xml:space="preserve"><value>ビブラートを戻す</value></data>
|
||||
<data name="ResetTiming" xml:space="preserve"><value>発声タイミングを戻す</value></data>
|
||||
<data name="ResetNote" xml:space="preserve"><value>ノートを既定に戻す</value></data>
|
||||
<data name="UstImportedFormat" xml:space="preserve"><value>{0} 個のノートを読み込みました</value></data>
|
||||
<data name="UstImportFailed" xml:space="preserve"><value>USTを読み込めませんでした</value></data>
|
||||
<data name="UstImportEmpty" xml:space="preserve"><value>読み込めるノートがありません</value></data>
|
||||
@@ -208,4 +217,11 @@
|
||||
<data name="UstPhraseOffsetFormat" xml:space="preserve"><value>元の {0} ティック目から</value></data>
|
||||
<data name="NoteTempo" xml:space="preserve"><value>テンポ</value></data>
|
||||
<data name="NoteTempoDescription" xml:space="preserve"><value>0でこの譜面のテンポに従います。値を入れるとこのノートから先のテンポが変わります。</value></data>
|
||||
<data name="EditLyrics" xml:space="preserve"><value>歌詞をまとめて編集</value></data>
|
||||
<data name="LyricsBulkEditHint" xml:space="preserve"><value>空白と改行で区切ります。漢字とかなは1文字ずつ、引用符で囲んだ部分はまとめて1つのノートになります。</value></data>
|
||||
<data name="LyricCountFormat" xml:space="preserve"><value>{0} / {1}</value></data>
|
||||
<data name="ButtonApply" xml:space="preserve"><value>適用</value></data>
|
||||
<data name="ButtonCancel" xml:space="preserve"><value>取り消し</value></data>
|
||||
<data name="ButtonReset" xml:space="preserve"><value>元に戻す</value></data>
|
||||
<data name="DetachEditor" xml:space="preserve"><value>別ウィンドウで編集</value></data>
|
||||
</root>
|
||||
@@ -198,6 +198,15 @@
|
||||
<data name="PitchPointCentsDescription" xml:space="preserve"><value>相对音符音高的偏移。100 音分为半音。</value></data>
|
||||
<data name="SelectAllNotes" xml:space="preserve"><value>选择所有音符</value></data>
|
||||
<data name="SelectionCountFormat" xml:space="preserve"><value>已选择 {0} 个音符</value></data>
|
||||
<data name="NoteContextCopy" xml:space="preserve"><value>复制音符</value></data>
|
||||
<data name="NoteContextPaste" xml:space="preserve"><value>粘贴音符</value></data>
|
||||
<data name="OctaveUp" xml:space="preserve"><value>升高八度</value></data>
|
||||
<data name="OctaveDown" xml:space="preserve"><value>降低八度</value></data>
|
||||
<data name="QuantizeLength" xml:space="preserve"><value>将长度对齐到吸附</value></data>
|
||||
<data name="ResetGroup" xml:space="preserve"><value>重置</value></data>
|
||||
<data name="ResetVibrato" xml:space="preserve"><value>重置颤音</value></data>
|
||||
<data name="ResetTiming" xml:space="preserve"><value>重置发声时间</value></data>
|
||||
<data name="ResetNote" xml:space="preserve"><value>将音符重置为默认值</value></data>
|
||||
<data name="UstImportedFormat" xml:space="preserve"><value>已载入 {0} 个音符</value></data>
|
||||
<data name="UstImportFailed" xml:space="preserve"><value>无法读取 UST 文件</value></data>
|
||||
<data name="UstImportEmpty" xml:space="preserve"><value>文件中没有可载入的音符</value></data>
|
||||
@@ -208,4 +217,11 @@
|
||||
<data name="UstPhraseOffsetFormat" xml:space="preserve"><value>自原曲第 {0} 刻</value></data>
|
||||
<data name="NoteTempo" xml:space="preserve"><value>速度</value></data>
|
||||
<data name="NoteTempoDescription" xml:space="preserve"><value>0 表示沿用乐谱的速度。填入数值则从该音符起改变速度。</value></data>
|
||||
<data name="EditLyrics" xml:space="preserve"><value>批量编辑歌词</value></data>
|
||||
<data name="LyricsBulkEditHint" xml:space="preserve"><value>以空格与换行分隔。汉字与假名逐字分开,用引号括起的部分作为一个音符。</value></data>
|
||||
<data name="LyricCountFormat" xml:space="preserve"><value>{0} / {1}</value></data>
|
||||
<data name="ButtonApply" xml:space="preserve"><value>应用</value></data>
|
||||
<data name="ButtonCancel" xml:space="preserve"><value>取消</value></data>
|
||||
<data name="ButtonReset" xml:space="preserve"><value>还原</value></data>
|
||||
<data name="DetachEditor" xml:space="preserve"><value>在独立窗口中编辑</value></data>
|
||||
</root>
|
||||
@@ -198,6 +198,15 @@
|
||||
<data name="PitchPointCentsDescription" xml:space="preserve"><value>相對音符音高的偏移。100 音分為半音。</value></data>
|
||||
<data name="SelectAllNotes" xml:space="preserve"><value>選擇所有音符</value></data>
|
||||
<data name="SelectionCountFormat" xml:space="preserve"><value>已選擇 {0} 個音符</value></data>
|
||||
<data name="NoteContextCopy" xml:space="preserve"><value>複製音符</value></data>
|
||||
<data name="NoteContextPaste" xml:space="preserve"><value>貼上音符</value></data>
|
||||
<data name="OctaveUp" xml:space="preserve"><value>升高八度</value></data>
|
||||
<data name="OctaveDown" xml:space="preserve"><value>降低八度</value></data>
|
||||
<data name="QuantizeLength" xml:space="preserve"><value>將長度對齊到吸附</value></data>
|
||||
<data name="ResetGroup" xml:space="preserve"><value>重設</value></data>
|
||||
<data name="ResetVibrato" xml:space="preserve"><value>重設顫音</value></data>
|
||||
<data name="ResetTiming" xml:space="preserve"><value>重設發聲時間</value></data>
|
||||
<data name="ResetNote" xml:space="preserve"><value>將音符重設為預設值</value></data>
|
||||
<data name="UstImportedFormat" xml:space="preserve"><value>已載入 {0} 個音符</value></data>
|
||||
<data name="UstImportFailed" xml:space="preserve"><value>無法讀取 UST 檔案</value></data>
|
||||
<data name="UstImportEmpty" xml:space="preserve"><value>檔案中沒有可載入的音符</value></data>
|
||||
@@ -208,4 +217,11 @@
|
||||
<data name="UstPhraseOffsetFormat" xml:space="preserve"><value>自原曲第 {0} 刻</value></data>
|
||||
<data name="NoteTempo" xml:space="preserve"><value>速度</value></data>
|
||||
<data name="NoteTempoDescription" xml:space="preserve"><value>0 表示沿用樂譜的速度。填入數值則從該音符起改變速度。</value></data>
|
||||
<data name="EditLyrics" xml:space="preserve"><value>批次編輯歌詞</value></data>
|
||||
<data name="LyricsBulkEditHint" xml:space="preserve"><value>以空格與換行分隔。漢字與假名逐字分開,用引號括起的部分作為一個音符。</value></data>
|
||||
<data name="LyricCountFormat" xml:space="preserve"><value>{0} / {1}</value></data>
|
||||
<data name="ButtonApply" xml:space="preserve"><value>套用</value></data>
|
||||
<data name="ButtonCancel" xml:space="preserve"><value>取消</value></data>
|
||||
<data name="ButtonReset" xml:space="preserve"><value>還原</value></data>
|
||||
<data name="DetachEditor" xml:space="preserve"><value>在獨立視窗中編輯</value></data>
|
||||
</root>
|
||||
+12
-15
@@ -5,13 +5,15 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>1.6.1</Version>
|
||||
<Version>1.7.4</Version>
|
||||
<Platforms>AnyCPU;x64;x64</Platforms>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ILRepack" Version="2.0.46" PrivateAssets="all" ExcludeAssets="all" GeneratePathProperty="true" />
|
||||
<PackageReference Include="NAudio" Version="2.3.0" />
|
||||
<PackageReference Include="WorldNet" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -22,18 +24,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="NAudio">
|
||||
<HintPath>$(YMM4DirPath)NAudio.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="NAudio.Core">
|
||||
<HintPath>$(YMM4DirPath)NAudio.Core.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="NAudio.Midi">
|
||||
<HintPath>$(YMM4DirPath)NAudio.Midi.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="NCalc.Core">
|
||||
<HintPath>$(YMM4DirPath)NCalc.Core.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
@@ -87,13 +77,20 @@
|
||||
<Compile Include="..\YMM4-GitHubUpdateNotifier\GitHubUpdateNotifier\*.cs" LinkBase="GitHubUpdateNotifier" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\YMM4-Telemetry\Telemetry.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\YukkuriMovieMaker.Generator\YukkuriMovieMaker.Generator\YukkuriMovieMaker.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
<AdditionalFiles Include="**/*.csv" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(SkipPluginDeploy)' != 'true'">
|
||||
<Exec Command="mkdir "$(YMM4DirPath)user\plugin\$(ProjectName)" > NUL 2>&1
copy "$(TargetPath)" "$(YMM4DirPath)user\plugin\$(ProjectName)\"
copy "$(TargetDir)WorldNet.dll" "$(YMM4DirPath)user\plugin\$(ProjectName)\"" />
|
||||
<Target Name="MergePluginAssembly" AfterTargets="PostBuildEvent" Inputs="$(TargetPath);$(TargetDir)NAudio.dll;$(TargetDir)NAudio.Core.dll;$(TargetDir)NAudio.Asio.dll;$(TargetDir)NAudio.Midi.dll;$(TargetDir)NAudio.Wasapi.dll;$(TargetDir)NAudio.WinMM.dll" Outputs="$(TargetDir)plugin\$(TargetFileName)">
|
||||
<MakeDir Directories="$(TargetDir)plugin" />
|
||||
<Exec Command=""$(PkgILRepack)\tools\ILRepack.exe" /out:"$(TargetDir)plugin\$(TargetFileName)" /lib:"$([System.IO.Path]::GetDirectoryName('$(TargetPath)'))" /lib:"$([System.IO.Path]::GetDirectoryName('$(YMM4DirPath)'))" /internalize "$(TargetPath)" "$(TargetDir)NAudio.dll" "$(TargetDir)NAudio.Core.dll" "$(TargetDir)NAudio.Asio.dll" "$(TargetDir)NAudio.Midi.dll" "$(TargetDir)NAudio.Wasapi.dll" "$(TargetDir)NAudio.WinMM.dll"" />
|
||||
</Target>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="MergePluginAssembly" Condition="'$(SkipPluginDeploy)' != 'true'">
|
||||
<Exec Command="mkdir "$(YMM4DirPath)user\plugin\$(ProjectName)" > NUL 2>&1
copy "$(TargetDir)plugin\$(TargetFileName)" "$(YMM4DirPath)user\plugin\$(ProjectName)\"
copy "$(TargetDir)WorldNet.dll" "$(YMM4DirPath)user\plugin\$(ProjectName)\"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,100 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Telemetry;
|
||||
|
||||
namespace UTAU;
|
||||
|
||||
internal static class UTAUTelemetry
|
||||
{
|
||||
private const int MaxChainLength = 5;
|
||||
private const int MaxFrames = 100;
|
||||
|
||||
private static readonly Assembly Own = typeof(UTAUTelemetry).Assembly;
|
||||
private static int _started;
|
||||
|
||||
public static void EnsureStartedOnce()
|
||||
{
|
||||
if (Interlocked.Exchange(ref _started, 1) != 0)
|
||||
return;
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
|
||||
|
||||
var application = Application.Current;
|
||||
if (application is not null)
|
||||
application.DispatcherUnhandledException += OnDispatcherUnhandledException;
|
||||
|
||||
TelemetryReporter.Start();
|
||||
}
|
||||
|
||||
public static void Report(Exception exception) => TelemetryReporter.Report(exception);
|
||||
|
||||
private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
=> ReportOwn(e.ExceptionObject as Exception);
|
||||
|
||||
private static void OnUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
|
||||
=> ReportOwn(e.Exception);
|
||||
|
||||
private static void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
=> ReportOwn(e.Exception);
|
||||
|
||||
private static void ReportOwn(Exception? exception)
|
||||
{
|
||||
if (exception is not null && IsOwn(exception))
|
||||
TelemetryReporter.Report(exception);
|
||||
}
|
||||
|
||||
private static bool IsOwn(Exception exception)
|
||||
{
|
||||
var current = exception;
|
||||
for (var depth = 0; current is not null && depth < MaxChainLength; depth++)
|
||||
{
|
||||
if (HasOwnFrame(current))
|
||||
return true;
|
||||
|
||||
current = current is AggregateException aggregate && aggregate.InnerExceptions.Count > 0
|
||||
? aggregate.InnerExceptions[0]
|
||||
: current.InnerException;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HasOwnFrame(Exception exception)
|
||||
{
|
||||
StackFrame[]? frames;
|
||||
|
||||
try
|
||||
{
|
||||
frames = new StackTrace(exception, false).GetFrames();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (frames is null)
|
||||
return false;
|
||||
|
||||
for (var index = 0; index < Math.Min(frames.Length, MaxFrames); index++)
|
||||
{
|
||||
MethodBase? method;
|
||||
|
||||
try
|
||||
{
|
||||
method = frames[index].GetMethod();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (method?.DeclaringType is { } declaringType && ReferenceEquals(declaringType.Assembly, Own))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,10 @@ internal static class UTAUUpdateNotifier
|
||||
};
|
||||
await new Notifier(Owner, Repository, options).NotifyAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
catch (Exception exception)
|
||||
{
|
||||
if (exception is not UpdateCheckException)
|
||||
UTAUTelemetry.Report(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-3
@@ -4,7 +4,7 @@ using YukkuriMovieMaker.Plugin.Voice;
|
||||
|
||||
namespace UTAU;
|
||||
|
||||
[PluginDetails(AuthorName = "routersys", ContentId = "")]
|
||||
[PluginDetails(AuthorName = "routersys", ContentId = "nc501723")]
|
||||
internal sealed class UTAUVoicePlugin : IVoicePlugin
|
||||
{
|
||||
public const string EngineName = "UTAU";
|
||||
@@ -18,16 +18,30 @@ internal sealed class UTAUVoicePlugin : IVoicePlugin
|
||||
|
||||
public bool IsVoicesCached => VoiceBankRepository.IsLoaded;
|
||||
|
||||
public Task UpdateVoicesAsync() => Task.Run(VoiceBankRepository.Reload);
|
||||
public Task UpdateVoicesAsync() => Task.Run(Reload);
|
||||
|
||||
static IEnumerable<IVoiceSpeaker> GetVoices()
|
||||
{
|
||||
UTAUTelemetry.EnsureStartedOnce();
|
||||
UTAUUpdateNotifier.EnsureCheckedOnce();
|
||||
|
||||
if (!VoiceBankRepository.IsLoaded)
|
||||
VoiceBankRepository.Reload();
|
||||
Reload();
|
||||
|
||||
foreach (var bank in VoiceBankRepository.Banks)
|
||||
yield return new UTAUVoiceSpeaker(bank);
|
||||
}
|
||||
|
||||
static void Reload()
|
||||
{
|
||||
try
|
||||
{
|
||||
VoiceBankRepository.Reload();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
UTAUTelemetry.Report(exception);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,19 @@ internal sealed class UTAUVoiceSpeaker(VoiceBank bank) : IVoiceSpeaker
|
||||
=> currentParameter is UTAUVoiceParameter ? currentParameter : CreateVoiceParameter();
|
||||
|
||||
public async Task<IVoicePronounce?> CreateVoiceAsync(string text, IVoicePronounce? pronounce, IVoiceParameter? parameter, string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await CreateAsync(text, pronounce, parameter, filePath).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception exception) when (exception is not InvalidOperationException)
|
||||
{
|
||||
UTAUTelemetry.Report(exception);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
async Task<IVoicePronounce?> CreateAsync(string text, IVoicePronounce? pronounce, IVoiceParameter? parameter, string filePath)
|
||||
{
|
||||
var param = parameter as UTAUVoiceParameter ?? new UTAUVoiceParameter();
|
||||
var isUst = UstSource.TryGetPath(text, out var ustPath);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Windows.Input;
|
||||
using UTAU.Notes;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
|
||||
namespace UTAU.ViewModels;
|
||||
|
||||
internal sealed class LyricsBulkEditViewModel : Bindable
|
||||
{
|
||||
readonly string original;
|
||||
string text;
|
||||
|
||||
public LyricsBulkEditViewModel(string lyrics, int noteCount)
|
||||
{
|
||||
original = lyrics ?? string.Empty;
|
||||
text = original;
|
||||
NoteCount = noteCount;
|
||||
ResetCommand = new ActionCommand(_ => Text != original, _ => Text = original);
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => text;
|
||||
set => Set(ref text, value ?? string.Empty, nameof(Text), nameof(LyricCount), nameof(CountText), nameof(HasMismatch));
|
||||
}
|
||||
|
||||
public int NoteCount { get; }
|
||||
|
||||
public int LyricCount => LyricSplitter.Split(text).Count;
|
||||
|
||||
public string CountText => string.Format(Texts.LyricCountFormat, LyricCount, NoteCount);
|
||||
|
||||
public bool HasMismatch => LyricCount != NoteCount;
|
||||
|
||||
public ICommand ResetCommand { get; }
|
||||
|
||||
public IReadOnlyList<string> Lyrics => LyricSplitter.Split(text);
|
||||
}
|
||||
@@ -32,6 +32,9 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
public const double MinimumFitQuarterNoteWidth = 24.0;
|
||||
public const double MinimumFitPixelsPerTick = MinimumFitQuarterNoteWidth / TimeBase.TicksPerQuarterNote;
|
||||
public const double MinimumFitSemitoneHeight = 10.0;
|
||||
public const int OctaveSemitones = 12;
|
||||
|
||||
static readonly List<UTAUNote> copiedNotes = [];
|
||||
|
||||
readonly UTAUVoicePronounce pronounce;
|
||||
readonly Dispatcher dispatcher;
|
||||
@@ -51,6 +54,10 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
Rect selectionBox;
|
||||
bool isSelectionBoxVisible;
|
||||
bool isBatching;
|
||||
bool isDetached;
|
||||
bool isMutatingSource;
|
||||
bool layoutPending;
|
||||
bool isDisposed;
|
||||
ObservableCollection<PitchPoint>? observedPitchPoints;
|
||||
PitchPoint? selectedPitchPoint;
|
||||
PointCollection pitchCurve = [];
|
||||
@@ -84,6 +91,7 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
source = pronounce.Notes;
|
||||
Notes = [.. source.Select(x => new NoteViewModel(x, this))];
|
||||
Notes.CollectionChanged += OnNotesChanged;
|
||||
source.CollectionChanged += OnSourceChanged;
|
||||
ZoomInCommand = new ActionCommand(_ => pixelsPerTick < MaximumPixelsPerTick, _ => ZoomHorizontally(ZoomStep));
|
||||
ZoomOutCommand = new ActionCommand(_ => pixelsPerTick > MinimumPixelsPerTick, _ => ZoomHorizontally(1.0 / ZoomStep));
|
||||
ZoomVerticalInCommand = new ActionCommand(_ => semitoneHeight < MaximumSemitoneHeight, _ => ZoomVertically(ZoomStep));
|
||||
@@ -91,6 +99,16 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
InsertRestCommand = new ActionCommand(_ => selectedNotes.Count > 0, _ => InsertRest());
|
||||
RemoveNoteCommand = new ActionCommand(_ => selectedNotes.Count > 0 && Notes.Count > selectedNotes.Count, _ => RemoveSelected());
|
||||
SelectAllCommand = new ActionCommand(_ => Notes.Count > 0, _ => SelectAll());
|
||||
OctaveUpCommand = new ActionCommand(_ => selectedNotes.Count > 0, _ => Transpose(OctaveSemitones));
|
||||
OctaveDownCommand = new ActionCommand(_ => selectedNotes.Count > 0, _ => Transpose(-OctaveSemitones));
|
||||
QuantizeLengthCommand = new ActionCommand(_ => selectedNotes.Count > 0 && !SnapDivision.IsFree, _ => QuantizeLength());
|
||||
ResetVibratoCommand = new ActionCommand(_ => selectedNotes.Count > 0, _ => ResetVibrato());
|
||||
ResetTimingCommand = new ActionCommand(_ => selectedNotes.Count > 0, _ => ResetTiming());
|
||||
ResetNoteCommand = new ActionCommand(_ => selectedNotes.Count > 0, _ => ResetNote());
|
||||
CopyNotesCommand = new ActionCommand(_ => selectedNotes.Count > 0, _ => CopyNotes());
|
||||
PasteNotesCommand = new ActionCommand(_ => copiedNotes.Count > 0, _ => PasteNotes());
|
||||
EditLyricsCommand = new ActionCommand(_ => selectedNotes.Count > 0, _ => LyricsEditRequested?.Invoke(this, EventArgs.Empty));
|
||||
DetachCommand = new ActionCommand(_ => CanDetach, _ => DetachRequested?.Invoke(this, EventArgs.Empty));
|
||||
AddPitchPointCommand = new ActionCommand(_ => SelectedNote is not null, _ => AddPitchPoint());
|
||||
RemovePitchPointCommand = new ActionCommand(_ => SelectedPitchPoint is not null, _ => RemoveSelectedPitchPoint());
|
||||
ResetPitchCommand = new ActionCommand(_ => SelectedNote is not null, _ => ResetPitch());
|
||||
@@ -119,6 +137,42 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
|
||||
public ICommand SelectAllCommand { get; }
|
||||
|
||||
public ICommand OctaveUpCommand { get; }
|
||||
|
||||
public ICommand OctaveDownCommand { get; }
|
||||
|
||||
public ICommand QuantizeLengthCommand { get; }
|
||||
|
||||
public ICommand ResetVibratoCommand { get; }
|
||||
|
||||
public ICommand ResetTimingCommand { get; }
|
||||
|
||||
public ICommand ResetNoteCommand { get; }
|
||||
|
||||
public ICommand CopyNotesCommand { get; }
|
||||
|
||||
public ICommand PasteNotesCommand { get; }
|
||||
|
||||
public ICommand EditLyricsCommand { get; }
|
||||
|
||||
public ICommand DetachCommand { get; }
|
||||
|
||||
public bool IsDetached
|
||||
{
|
||||
get => isDetached;
|
||||
set
|
||||
{
|
||||
if (Set(ref isDetached, value))
|
||||
OnPropertyChanged(nameof(CanDetach));
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanDetach => !isDetached;
|
||||
|
||||
public event EventHandler? LyricsEditRequested;
|
||||
|
||||
public event EventHandler? DetachRequested;
|
||||
|
||||
public string ImportMessage => pronounce.ImportMessage;
|
||||
|
||||
public string RenderMessage => pronounce.RenderMessage;
|
||||
@@ -303,6 +357,7 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
|
||||
public void SetViewport(double left, double width)
|
||||
{
|
||||
FlushLayout();
|
||||
viewportLeft = left;
|
||||
viewportWidth = width;
|
||||
if (!MoveWindow())
|
||||
@@ -320,6 +375,130 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
visibleLast = -1;
|
||||
}
|
||||
|
||||
void OnSourceChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (isMutatingSource)
|
||||
return;
|
||||
|
||||
if (dispatcher.CheckAccess())
|
||||
AcceptSourceChange();
|
||||
else
|
||||
dispatcher.BeginInvoke(AcceptSourceChange);
|
||||
}
|
||||
|
||||
void AcceptSourceChange()
|
||||
{
|
||||
if (isDisposed || !Resynchronise())
|
||||
return;
|
||||
|
||||
RequestLayout();
|
||||
}
|
||||
|
||||
void RequestLayout()
|
||||
{
|
||||
if (layoutPending)
|
||||
return;
|
||||
|
||||
layoutPending = true;
|
||||
dispatcher.BeginInvoke(FlushLayout, DispatcherPriority.Normal);
|
||||
}
|
||||
|
||||
void MutateSource(Action action)
|
||||
{
|
||||
if (isMutatingSource)
|
||||
{
|
||||
action();
|
||||
return;
|
||||
}
|
||||
|
||||
isMutatingSource = true;
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
finally
|
||||
{
|
||||
isMutatingSource = false;
|
||||
if (Resynchronise())
|
||||
layoutPending = true;
|
||||
FlushLayout();
|
||||
}
|
||||
}
|
||||
|
||||
bool Resynchronise()
|
||||
{
|
||||
if (!SyncNotes())
|
||||
return false;
|
||||
|
||||
RepairSelection();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void FlushLayout()
|
||||
{
|
||||
if (isDisposed || !layoutPending)
|
||||
return;
|
||||
|
||||
layoutPending = false;
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
bool SyncNotes()
|
||||
{
|
||||
if (IsSynchronised())
|
||||
return false;
|
||||
|
||||
var orphans = new Dictionary<UTAUNote, NoteViewModel>(Notes.Count);
|
||||
foreach (var note in Notes)
|
||||
orphans.TryAdd(note.Note, note);
|
||||
|
||||
var rebuilt = new List<NoteViewModel>(source.Count);
|
||||
foreach (var note in source)
|
||||
rebuilt.Add(orphans.Remove(note, out var viewModel) ? viewModel : new NoteViewModel(note, this));
|
||||
|
||||
for (var index = VisibleNotes.Count - 1; index >= 0; index--)
|
||||
{
|
||||
if (orphans.ContainsKey(VisibleNotes[index].Note))
|
||||
VisibleNotes.RemoveAt(index);
|
||||
}
|
||||
|
||||
foreach (var orphan in orphans.Values)
|
||||
{
|
||||
selectedNotes.Remove(orphan);
|
||||
orphan.IsSelected = false;
|
||||
orphan.IsPrimary = false;
|
||||
orphan.Dispose();
|
||||
}
|
||||
|
||||
Notes.Clear();
|
||||
foreach (var viewModel in rebuilt)
|
||||
Notes.Add(viewModel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsSynchronised()
|
||||
{
|
||||
if (Notes.Count != source.Count)
|
||||
return false;
|
||||
|
||||
for (var index = 0; index < source.Count; index++)
|
||||
{
|
||||
if (!ReferenceEquals(Notes[index].Note, source[index]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RepairSelection()
|
||||
{
|
||||
if (selectedNote is null ? selectedNotes.Count == 0 : selectedNotes.Contains(selectedNote))
|
||||
return;
|
||||
|
||||
SetPrimary(selectedNotes.LastOrDefault());
|
||||
}
|
||||
|
||||
void ResetWindow()
|
||||
{
|
||||
windowStartTicks = int.MaxValue;
|
||||
@@ -967,8 +1146,14 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (isDisposed)
|
||||
return;
|
||||
|
||||
isDisposed = true;
|
||||
pronounce.PropertyChanged -= OnPronouncePropertyChanged;
|
||||
ObservePitchPoints(null);
|
||||
layoutPending = false;
|
||||
source.CollectionChanged -= OnSourceChanged;
|
||||
Notes.CollectionChanged -= OnNotesChanged;
|
||||
VisibleNotes.Clear();
|
||||
selectedNotes.Clear();
|
||||
@@ -1242,9 +1427,7 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
Tone = selectedNote?.Note.Tone ?? MusicalTone.MiddleC.NoteNumber,
|
||||
LengthTicks = SnapDivision.IsFree ? UTAUNote.DefaultLengthTicks : SnapDivision.Ticks,
|
||||
};
|
||||
source.Insert(index + 1, rest);
|
||||
Notes.Insert(index + 1, new NoteViewModel(rest, this));
|
||||
InvalidateLayout();
|
||||
MutateSource(() => source.Insert(index + 1, rest));
|
||||
}
|
||||
|
||||
void RemoveSelected()
|
||||
@@ -1256,15 +1439,157 @@ internal sealed class NoteEditorViewModel : Bindable, IDisposable
|
||||
var index = Notes.IndexOf(removing[0]);
|
||||
Select(null);
|
||||
|
||||
foreach (var note in removing)
|
||||
MutateSource(() =>
|
||||
{
|
||||
source.Remove(note.Note);
|
||||
Notes.Remove(note);
|
||||
note.Dispose();
|
||||
}
|
||||
foreach (var note in removing)
|
||||
source.Remove(note.Note);
|
||||
});
|
||||
|
||||
Select(Notes[Math.Min(index, Notes.Count - 1)]);
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
public string ReadSelectedLyrics()
|
||||
=> LyricSplitter.Join(selectedNotes.OrderBy(Notes.IndexOf).Select(x => x.Note.Lyric));
|
||||
|
||||
public int ApplyLyrics(IReadOnlyList<string> lyrics)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(lyrics);
|
||||
var targets = selectedNotes.OrderBy(Notes.IndexOf).ToArray();
|
||||
var count = Math.Min(lyrics.Count, targets.Length);
|
||||
if (count == 0)
|
||||
return 0;
|
||||
|
||||
Batch(() =>
|
||||
{
|
||||
for (var index = 0; index < count; index++)
|
||||
targets[index].Note.Lyric = lyrics[index];
|
||||
});
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void Transpose(int semitones)
|
||||
{
|
||||
if (selectedNotes.Count == 0)
|
||||
return;
|
||||
|
||||
var shift = Math.Clamp(
|
||||
semitones,
|
||||
-selectedNotes.Min(x => x.Note.Tone),
|
||||
127 - selectedNotes.Max(x => x.Note.Tone));
|
||||
if (shift == 0)
|
||||
return;
|
||||
|
||||
Batch(
|
||||
() =>
|
||||
{
|
||||
foreach (var note in selectedNotes)
|
||||
note.Tone += shift;
|
||||
},
|
||||
InvalidateTones);
|
||||
}
|
||||
|
||||
void QuantizeLength()
|
||||
{
|
||||
if (selectedNotes.Count == 0 || SnapDivision.IsFree)
|
||||
return;
|
||||
|
||||
Batch(() =>
|
||||
{
|
||||
foreach (var note in selectedNotes)
|
||||
note.LengthTicks = SnapLength(note.Note.LengthTicks);
|
||||
});
|
||||
}
|
||||
|
||||
void ResetVibrato()
|
||||
{
|
||||
if (selectedNotes.Count == 0)
|
||||
return;
|
||||
|
||||
var defaults = new VibratoSettings();
|
||||
Batch(() =>
|
||||
{
|
||||
foreach (var note in selectedNotes)
|
||||
defaults.CopyTo(note.Note.Vibrato);
|
||||
});
|
||||
}
|
||||
|
||||
void ResetTiming()
|
||||
{
|
||||
if (selectedNotes.Count == 0)
|
||||
return;
|
||||
|
||||
Batch(() =>
|
||||
{
|
||||
foreach (var note in selectedNotes)
|
||||
ResetTiming(note.Note);
|
||||
});
|
||||
}
|
||||
|
||||
void ResetNote()
|
||||
{
|
||||
if (selectedNotes.Count == 0)
|
||||
return;
|
||||
|
||||
var defaults = new VibratoSettings();
|
||||
Batch(() =>
|
||||
{
|
||||
foreach (var note in selectedNotes)
|
||||
{
|
||||
var target = note.Note;
|
||||
target.TempoOverride = UTAUNote.FollowScoreValue;
|
||||
target.Velocity = UTAUNote.DefaultVelocity;
|
||||
target.Intensity = UTAUNote.DefaultIntensity;
|
||||
target.Modulation = UTAUNote.DefaultModulation;
|
||||
ResetTiming(target);
|
||||
defaults.CopyTo(target.Vibrato);
|
||||
for (var index = target.PitchPoints.Count - 1; index >= 0; index--)
|
||||
target.PitchPoints.RemoveAt(index);
|
||||
}
|
||||
});
|
||||
|
||||
SelectedPitchPoint = null;
|
||||
}
|
||||
|
||||
static void ResetTiming(UTAUNote note)
|
||||
{
|
||||
note.PreutteranceOverride = UTAUNote.FollowOtoValue;
|
||||
note.OverlapOverride = UTAUNote.FollowOtoValue;
|
||||
note.StartPointMilliseconds = UTAUNote.DefaultStartPointMilliseconds;
|
||||
note.FadeInMilliseconds = UTAUNote.DefaultFadeInMilliseconds;
|
||||
note.FadeOutMilliseconds = UTAUNote.DefaultFadeOutMilliseconds;
|
||||
}
|
||||
|
||||
void CopyNotes()
|
||||
{
|
||||
if (selectedNotes.Count == 0)
|
||||
return;
|
||||
|
||||
copiedNotes.Clear();
|
||||
foreach (var note in selectedNotes.OrderBy(Notes.IndexOf))
|
||||
copiedNotes.Add(note.Note.Clone());
|
||||
}
|
||||
|
||||
void PasteNotes()
|
||||
{
|
||||
if (copiedNotes.Count == 0)
|
||||
return;
|
||||
|
||||
var first = (selectedNotes.Count == 0 ? Notes.Count - 1 : selectedNotes.Max(Notes.IndexOf)) + 1;
|
||||
MutateSource(() =>
|
||||
{
|
||||
var index = first;
|
||||
foreach (var copied in copiedNotes)
|
||||
{
|
||||
source.Insert(index, copied.Clone());
|
||||
index++;
|
||||
}
|
||||
});
|
||||
|
||||
ClearSelection();
|
||||
for (var offset = 0; offset < copiedNotes.Count; offset++)
|
||||
AddToSelection(Notes[first + offset]);
|
||||
SetPrimary(Notes[first]);
|
||||
}
|
||||
|
||||
void AddPitchPoint()
|
||||
|
||||
@@ -78,6 +78,7 @@ internal sealed class UTAUSettingsViewModel : Bindable
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
UTAUTelemetry.Report(exception);
|
||||
StatusText = exception.Message;
|
||||
}
|
||||
finally
|
||||
@@ -138,6 +139,7 @@ internal sealed class UTAUSettingsViewModel : Bindable
|
||||
}
|
||||
catch (Exception exception) when (exception is IOException or UnauthorizedAccessException or System.ComponentModel.Win32Exception)
|
||||
{
|
||||
UTAUTelemetry.Report(exception);
|
||||
StatusText = exception.Message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ internal sealed class VoiceBankViewModel(VoiceBank bank)
|
||||
}
|
||||
catch (Exception exception) when (exception is NotSupportedException or IOException or UriFormatException or ArgumentException)
|
||||
{
|
||||
UTAUTelemetry.Report(exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<UserControl x:Class="UTAU.Views.LyricsBulkEditView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:root="clr-namespace:UTAU"
|
||||
xmlns:vm="clr-namespace:UTAU.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="560"
|
||||
d:DataContext="{d:DesignInstance Type={x:Type vm:LyricsBulkEditViewModel}}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="26"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBox x:Name="LyricBox" Grid.Row="0"
|
||||
Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}"
|
||||
AcceptsReturn="True" TextWrapping="Wrap"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
SpellCheck.IsEnabled="False"
|
||||
ToolTip="{x:Static root:Texts.LyricsBulkEditHint}"/>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding CountText}">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Opacity" Value="0.75"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding HasMismatch}" Value="True">
|
||||
<Setter Property="Opacity" Value="1"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Width="88" Height="26" Content="{x:Static root:Texts.ButtonReset}" Command="{Binding ResetCommand}"/>
|
||||
<Button Width="88" Height="26" Content="{x:Static root:Texts.ButtonCancel}" IsCancel="True"/>
|
||||
<Button x:Name="ApplyButton" Width="88" Height="26" IsDefault="True"
|
||||
Content="{x:Static root:Texts.ButtonApply}" Click="Apply_Click"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace UTAU.Views;
|
||||
|
||||
public partial class LyricsBulkEditView : UserControl
|
||||
{
|
||||
public LyricsBulkEditView()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += (_, _) =>
|
||||
{
|
||||
LyricBox.Focus();
|
||||
LyricBox.SelectAll();
|
||||
};
|
||||
}
|
||||
|
||||
public event EventHandler? Applied;
|
||||
|
||||
void Apply_Click(object sender, RoutedEventArgs e) => Applied?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Window x:Class="UTAU.Views.LyricsBulkEditWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:root="clr-namespace:UTAU"
|
||||
xmlns:v="clr-namespace:UTAU.Views"
|
||||
xmlns:vm="clr-namespace:UTAU.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type={x:Type vm:LyricsBulkEditViewModel}}"
|
||||
Title="{x:Static root:Texts.EditLyrics}"
|
||||
Width="560" Height="320" MinWidth="360" MinHeight="220"
|
||||
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
|
||||
<Window.Style>
|
||||
<Style TargetType="{x:Type Window}" BasedOn="{StaticResource {x:Type Window}}"/>
|
||||
</Window.Style>
|
||||
<v:LyricsBulkEditView x:Name="View"/>
|
||||
</Window>
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Windows;
|
||||
using UTAU.ViewModels;
|
||||
|
||||
namespace UTAU.Views;
|
||||
|
||||
public partial class LyricsBulkEditWindow : Window
|
||||
{
|
||||
internal LyricsBulkEditWindow(LyricsBulkEditViewModel viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = viewModel;
|
||||
ViewModel = viewModel;
|
||||
View.Applied += OnApplied;
|
||||
}
|
||||
|
||||
internal LyricsBulkEditViewModel ViewModel { get; }
|
||||
|
||||
void OnApplied(object? sender, EventArgs e)
|
||||
{
|
||||
DialogResult = true;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
+3
-387
@@ -5,402 +5,18 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:root="clr-namespace:UTAU"
|
||||
xmlns:vm="clr-namespace:UTAU.ViewModels"
|
||||
xmlns:v="clr-namespace:UTAU.Views"
|
||||
xmlns:c="clr-namespace:YukkuriMovieMaker.Controls;assembly=YukkuriMovieMaker.Controls"
|
||||
xmlns:icons="clr-namespace:YukkuriMovieMaker.Resources.Icons;assembly=YukkuriMovieMaker.Plugin"
|
||||
xmlns:theme="clr-namespace:YukkuriMovieMaker.Theme;assembly=YukkuriMovieMaker.Plugin"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="440" d:DesignWidth="960"
|
||||
d:DataContext="{d:DesignInstance Type={x:Type vm:NoteEditorViewModel}}">
|
||||
<UserControl.Resources>
|
||||
<SolidColorBrush x:Key="AccidentalRowBrush" Color="#26000000"/>
|
||||
<SolidColorBrush x:Key="AccidentalKeyBrush" Color="#59000000"/>
|
||||
<SolidColorBrush x:Key="NaturalKeyBrush" Color="#14FFFFFF"/>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibility"/>
|
||||
</UserControl.Resources>
|
||||
<c:PopupButton Content="{x:Static root:Texts.EditNotes}"
|
||||
<c:PopupButton x:Name="PopupHost"
|
||||
Content="{x:Static root:Texts.EditNotes}"
|
||||
PopupWidth="980"
|
||||
PopupHeight="480"
|
||||
ResizeMode="Both"
|
||||
BeginEdit="PopupButton_BeginEdit"
|
||||
EndEdit="PopupButton_EndEdit">
|
||||
<c:PopupButton.PopupContent>
|
||||
<Grid UseLayoutRounding="False">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="280"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="26"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="72"/>
|
||||
<RowDefinition Height="14"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" Grid.ColumnSpan="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||
<Button Width="26" Height="26" Command="{Binding ZoomOutCommand}" ToolTip="{x:Static root:Texts.ZoomOut}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.MagnifyMinusOutline}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ZoomInCommand}" ToolTip="{x:Static root:Texts.ZoomIn}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.MagnifyPlusOutline}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ZoomVerticalOutCommand}" ToolTip="{x:Static root:Texts.ZoomVerticalOut}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.ArrowCollapseVertical}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ZoomVerticalInCommand}" ToolTip="{x:Static root:Texts.ZoomVerticalIn}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.ArrowExpandVertical}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding FitCommand}" ToolTip="{x:Static root:Texts.FitToWindow}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.FitToScreenOutline}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding InsertRestCommand}" ToolTip="{x:Static root:Texts.InsertRest}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Plus}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding RemoveNoteCommand}" ToolTip="{x:Static root:Texts.RemoveNote}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Delete}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding SelectAllCommand}" ToolTip="{x:Static root:Texts.SelectAllNotes}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.SelectAll}}"/>
|
||||
<TextBlock Text="{x:Static root:Texts.SnapLabel}" VerticalAlignment="Center" Margin="6,0,3,0"/>
|
||||
<ComboBox Width="88" Height="26" VerticalContentAlignment="Center"
|
||||
ItemsSource="{Binding SnapDivisions}"
|
||||
SelectedItem="{Binding SnapDivision}"
|
||||
DisplayMemberPath="Name"/>
|
||||
<TextBlock Text="{x:Static root:Texts.ExpressionLabel}" VerticalAlignment="Center" Margin="12,0,3,0"/>
|
||||
<ComboBox Width="110" Height="26" VerticalContentAlignment="Center"
|
||||
ItemsSource="{Binding Expressions}"
|
||||
SelectedItem="{Binding SelectedExpression}"
|
||||
DisplayMemberPath="Name"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ResetExpressionCommand}" ToolTip="{x:Static root:Texts.ResetExpression}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Restore}}"/>
|
||||
<TextBlock Text="{Binding SelectionText}" VerticalAlignment="Center" Margin="12,0,0,0" Opacity="0.75"/>
|
||||
<TextBlock Text="{Binding GuideText}" VerticalAlignment="Center" Margin="12,0,0,0" Opacity="0.75"/>
|
||||
</StackPanel>
|
||||
|
||||
<DockPanel Grid.Column="1">
|
||||
<v:ScrollingText DockPanel.Dock="Right" Text="{Binding RenderMessage}" VerticalAlignment="Center" Margin="12,0,0,0"
|
||||
Foreground="{DynamicResource {x:Static theme:YMM4Colors.WarningBannerForegroundBrushKey}}"/>
|
||||
<v:ScrollingText Text="{Binding ImportMessage}" VerticalAlignment="Center" Margin="12,0,0,0" Opacity="0.75"/>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
|
||||
<ScrollViewer x:Name="VerticalScroller" Grid.Row="1" Grid.Column="0"
|
||||
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"
|
||||
SizeChanged="Scroller_SizeChanged">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="42"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ItemsControl Grid.Column="0" ItemsSource="{Binding Keyboard}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Height="{Binding Height}"
|
||||
BorderThickness="0,0,1,1"
|
||||
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
|
||||
MouseLeftButtonDown="Key_MouseLeftButtonDown"
|
||||
Cursor="Hand">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="{StaticResource NaturalKeyBrush}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsAccidental}" Value="True">
|
||||
<Setter Property="Background" Value="{StaticResource AccidentalKeyBrush}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Right"
|
||||
Margin="0,0,3,0" FontSize="9" Opacity="0.75" IsHitTestVisible="False"/>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ScrollViewer x:Name="HorizontalScroller" Grid.Column="1"
|
||||
HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled"
|
||||
ScrollChanged="HorizontalScroller_ScrollChanged"
|
||||
SizeChanged="Scroller_SizeChanged">
|
||||
<Canvas x:Name="RollCanvas"
|
||||
Width="{Binding CanvasWidth}"
|
||||
Height="{Binding CanvasHeight}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Background="Transparent"
|
||||
ToolTip="{x:Static root:Texts.NoteEditorHint}"
|
||||
MouseMove="RollCanvas_MouseMove"
|
||||
MouseLeftButtonDown="RollCanvas_MouseLeftButtonDown"
|
||||
MouseLeftButtonUp="RollCanvas_MouseLeftButtonUp"
|
||||
MouseLeave="RollCanvas_MouseLeave"
|
||||
MouseDown="RollCanvas_MouseDown"
|
||||
MouseUp="RollCanvas_MouseUp"
|
||||
PreviewMouseWheel="RollCanvas_PreviewMouseWheel">
|
||||
<ItemsControl ItemsSource="{Binding Keyboard}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Height="{Binding Height}" Width="{Binding RollWidth}"
|
||||
BorderThickness="0,0,0,1"
|
||||
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsAccidental}" Value="True">
|
||||
<Setter Property="Background" Value="{StaticResource AccidentalRowBrush}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding TimeGridLines}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Rectangle Width="1" Height="{Binding Height}"
|
||||
Fill="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}">
|
||||
<Rectangle.Style>
|
||||
<Style TargetType="Rectangle">
|
||||
<Setter Property="Opacity" Value="0.4"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsBar}" Value="True">
|
||||
<Setter Property="Opacity" Value="0.9"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Rectangle.Style>
|
||||
</Rectangle>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding VisibleNotes}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
<Setter Property="Canvas.Top" Value="{Binding Top}"/>
|
||||
<Setter Property="Panel.ZIndex" Value="1"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Width="{Binding Width}" Height="{Binding Height}"
|
||||
MouseLeftButtonDown="Note_MouseLeftButtonDown"
|
||||
ToolTip="{Binding ToneName}">
|
||||
<Border BorderThickness="1">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
|
||||
<Setter Property="Opacity" Value="0.6"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsRest}" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"/>
|
||||
<Setter Property="Opacity" Value="0.35"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsSelected}" Value="True">
|
||||
<Setter Property="Opacity" Value="1"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<Border IsHitTestVisible="False"
|
||||
BorderBrush="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibility}}">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="Opacity" Value="0.55"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsPrimary}" Value="True">
|
||||
<Setter Property="BorderThickness" Value="2"/>
|
||||
<Setter Property="Opacity" Value="1"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock Text="{Binding Display}" FontSize="10" Margin="4,0,0,0"
|
||||
VerticalAlignment="Center" ClipToBounds="True" IsHitTestVisible="False"
|
||||
Foreground="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
|
||||
<Rectangle Width="6" HorizontalAlignment="Right" Fill="Transparent" Cursor="SizeWE"
|
||||
MouseLeftButtonDown="NoteResize_MouseLeftButtonDown"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Polyline Points="{Binding PitchCurve}" StrokeThickness="1.5" Panel.ZIndex="2"
|
||||
Stroke="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Opacity="0.85"
|
||||
IsHitTestVisible="False"/>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding PitchHandles}" Panel.ZIndex="3">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
<Setter Property="Canvas.Top" Value="{Binding Top}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Rectangle Width="{Binding Size}" Height="{Binding Size}" Cursor="SizeAll"
|
||||
Fill="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Stroke="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
|
||||
StrokeThickness="1"
|
||||
ToolTip="{x:Static root:Texts.PitchHandleHint}"
|
||||
MouseLeftButtonDown="PitchHandle_MouseLeftButtonDown"
|
||||
MouseRightButtonDown="PitchHandle_MouseRightButtonDown"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Rectangle Width="1" Height="{Binding CanvasHeight}" Panel.ZIndex="4"
|
||||
Canvas.Left="{Binding GuideLeft}"
|
||||
Fill="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Opacity="0.6"
|
||||
IsHitTestVisible="False"
|
||||
Visibility="{Binding IsGuideVisible, Converter={StaticResource BooleanToVisibility}}"/>
|
||||
|
||||
<Rectangle Panel.ZIndex="5" IsHitTestVisible="False" StrokeThickness="1" Opacity="0.35"
|
||||
Canvas.Left="{Binding SelectionBoxLeft}"
|
||||
Canvas.Top="{Binding SelectionBoxTop}"
|
||||
Width="{Binding SelectionBoxWidth}"
|
||||
Height="{Binding SelectionBoxHeight}"
|
||||
Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
|
||||
Stroke="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Visibility="{Binding IsSelectionBoxVisible, Converter={StaticResource BooleanToVisibility}}"/>
|
||||
</Canvas>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
|
||||
|
||||
<Grid Grid.Row="2" Grid.Column="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="42"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="{Binding SelectedExpression.Name}" FontSize="9" Opacity="0.75"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,3,0"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
<ScrollViewer x:Name="StripScroller" Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled">
|
||||
<Canvas x:Name="StripCanvas"
|
||||
Width="{Binding CanvasWidth}"
|
||||
Height="{Binding StripCanvasHeight}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Background="Transparent"
|
||||
ToolTip="{x:Static root:Texts.ExpressionHint}"
|
||||
MouseLeftButtonDown="StripCanvas_MouseLeftButtonDown"
|
||||
MouseLeftButtonUp="StripCanvas_MouseLeftButtonUp"
|
||||
MouseMove="StripCanvas_MouseMove"
|
||||
MouseLeave="StripCanvas_MouseLeave">
|
||||
<ItemsControl ItemsSource="{Binding TimeGridLines}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Rectangle Width="1" Height="72" Opacity="0.4"
|
||||
Fill="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding ExpressionBars}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
<Setter Property="Canvas.Top" Value="{Binding Top}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Width="{Binding Width}" Height="{Binding Height}"
|
||||
Background="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
|
||||
IsHitTestVisible="False">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Opacity" Value="0.6"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Note.IsSelected}" Value="True">
|
||||
<Setter Property="Opacity" Value="1"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Polyline Points="{Binding ExpressionCurvePoints}" StrokeThickness="1.5"
|
||||
Stroke="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
|
||||
IsHitTestVisible="False"/>
|
||||
</Canvas>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
<ScrollBar x:Name="HorizontalBar" Grid.Row="3" Grid.Column="0" Orientation="Horizontal"
|
||||
Margin="42,0,0,0" Scroll="HorizontalBar_Scroll"/>
|
||||
|
||||
<Grid Grid.Row="1" Grid.RowSpan="3" Grid.Column="1" IsEnabled="{Binding HasSelection}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="26"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel>
|
||||
<c:PropertiesEditor Targets="{Binding SelectedNoteTargets}" IsScrollViewerEnabled="False"/>
|
||||
<c:PropertiesEditor Target="{Binding SelectedPitchPoint}" IsScrollViewerEnabled="False"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Width="26" Height="26" Command="{Binding AddPitchPointCommand}" ToolTip="{x:Static root:Texts.AddPitchPoint}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Plus}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding RemovePitchPointCommand}" ToolTip="{x:Static root:Texts.RemovePitchPoint}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Minus}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ResetPitchCommand}" ToolTip="{x:Static root:Texts.ResetPitch}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Restore}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<ContentControl x:Name="SurfaceHost"/>
|
||||
</c:PopupButton.PopupContent>
|
||||
</c:PopupButton>
|
||||
</UserControl>
|
||||
+69
-339
@@ -1,9 +1,6 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
|
||||
@@ -11,27 +8,9 @@ namespace UTAU.Views;
|
||||
|
||||
public partial class NoteEditor : UserControl, IPropertyEditorControl
|
||||
{
|
||||
enum DragMode
|
||||
{
|
||||
None,
|
||||
Tone,
|
||||
Length,
|
||||
PitchHandle,
|
||||
Expression,
|
||||
Select,
|
||||
}
|
||||
|
||||
const double WheelScrollStep = 64.0;
|
||||
|
||||
DragMode dragMode;
|
||||
NoteViewModel? dragTarget;
|
||||
PitchPoint? dragPoint;
|
||||
Point dragOrigin;
|
||||
bool dragMoved;
|
||||
bool isPanning;
|
||||
Point panOrigin;
|
||||
double panHorizontalOffset;
|
||||
double panVerticalOffset;
|
||||
readonly NoteEditorSurface surface = new();
|
||||
NoteEditorWindow? detached;
|
||||
NoteEditorViewModel? attached;
|
||||
|
||||
public event EventHandler? BeginEdit;
|
||||
|
||||
@@ -40,7 +19,7 @@ public partial class NoteEditor : UserControl, IPropertyEditorControl
|
||||
public NoteEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += (_, _) => RequestFit();
|
||||
SurfaceHost.Content = surface;
|
||||
}
|
||||
|
||||
internal UTAUVoicePronounce? Pronounce
|
||||
@@ -60,332 +39,83 @@ public partial class NoteEditor : UserControl, IPropertyEditorControl
|
||||
if (d is not NoteEditor editor)
|
||||
return;
|
||||
|
||||
editor.CloseDetached();
|
||||
editor.Attach(null);
|
||||
editor.ViewModel?.Dispose();
|
||||
editor.DataContext = editor.Pronounce is null ? null : new NoteEditorViewModel(editor.Pronounce);
|
||||
editor.RequestFit();
|
||||
editor.surface.DataContext = editor.Pronounce is null ? null : new NoteEditorViewModel(editor.Pronounce);
|
||||
editor.DataContext = editor.surface.DataContext;
|
||||
editor.Attach(editor.surface.DataContext as NoteEditorViewModel);
|
||||
editor.surface.RequestFit();
|
||||
}
|
||||
|
||||
NoteEditorViewModel? ViewModel => DataContext as NoteEditorViewModel;
|
||||
NoteEditorViewModel? ViewModel => surface.DataContext as NoteEditorViewModel;
|
||||
|
||||
void RequestFit() => Dispatcher.BeginInvoke(UpdateFit, DispatcherPriority.Loaded);
|
||||
internal NoteEditorWindow? DetachedWindow => detached;
|
||||
|
||||
void UpdateFit()
|
||||
void Attach(NoteEditorViewModel? viewModel)
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
if (attached is not null)
|
||||
attached.DetachRequested -= OnDetachRequested;
|
||||
|
||||
attached = viewModel;
|
||||
|
||||
if (attached is not null)
|
||||
attached.DetachRequested += OnDetachRequested;
|
||||
}
|
||||
|
||||
void OnDetachRequested(object? sender, EventArgs e) => Detach();
|
||||
|
||||
internal void Detach()
|
||||
{
|
||||
if (detached is not null)
|
||||
{
|
||||
detached.Activate();
|
||||
return;
|
||||
}
|
||||
|
||||
ClosePopup();
|
||||
SurfaceHost.Content = null;
|
||||
PopupHost.IsEnabled = false;
|
||||
if (ViewModel is { } viewModel)
|
||||
viewModel.IsDetached = true;
|
||||
|
||||
detached = new NoteEditorWindow(surface);
|
||||
if (OwnerWindow() is { } owner)
|
||||
detached.Owner = owner;
|
||||
detached.Closed += OnDetachedClosed;
|
||||
BeginEdit?.Invoke(this, EventArgs.Empty);
|
||||
detached.Show();
|
||||
surface.RequestFit();
|
||||
}
|
||||
|
||||
internal void CloseDetached() => detached?.Close();
|
||||
|
||||
void OnDetachedClosed(object? sender, EventArgs e)
|
||||
{
|
||||
if (detached is null)
|
||||
return;
|
||||
|
||||
viewModel.FitToViewport(HorizontalScroller.ActualWidth, VerticalScroller.ActualHeight);
|
||||
viewModel.SetViewport(HorizontalScroller.HorizontalOffset, HorizontalScroller.ViewportWidth);
|
||||
detached.Closed -= OnDetachedClosed;
|
||||
detached.Release();
|
||||
detached = null;
|
||||
SurfaceHost.Content = surface;
|
||||
PopupHost.IsEnabled = true;
|
||||
if (ViewModel is { } viewModel)
|
||||
viewModel.IsDetached = false;
|
||||
EndEdit?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
void Scroller_SizeChanged(object sender, SizeChangedEventArgs e) => UpdateFit();
|
||||
void ClosePopup()
|
||||
{
|
||||
if (PopupHost.Template?.FindName("PART_Popup", PopupHost) is Popup popup)
|
||||
popup.IsOpen = false;
|
||||
}
|
||||
|
||||
static Window? OwnerWindow()
|
||||
=> Application.Current?.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive)
|
||||
?? Application.Current?.MainWindow;
|
||||
|
||||
void PopupButton_BeginEdit(object sender, EventArgs e) => BeginEdit?.Invoke(this, e);
|
||||
|
||||
void PopupButton_EndEdit(object sender, EventArgs e) => EndEdit?.Invoke(this, e);
|
||||
|
||||
void HorizontalScroller_ScrollChanged(object sender, ScrollChangedEventArgs e)
|
||||
{
|
||||
HorizontalBar.Maximum = Math.Max(e.ExtentWidth - e.ViewportWidth, 0.0);
|
||||
HorizontalBar.ViewportSize = e.ViewportWidth;
|
||||
HorizontalBar.LargeChange = e.ViewportWidth;
|
||||
HorizontalBar.SmallChange = WheelScrollStep;
|
||||
HorizontalBar.Value = e.HorizontalOffset;
|
||||
StripScroller.Width = e.ViewportWidth;
|
||||
StripScroller.ScrollToHorizontalOffset(e.HorizontalOffset);
|
||||
ViewModel?.SetViewport(e.HorizontalOffset, e.ViewportWidth);
|
||||
}
|
||||
|
||||
void HorizontalBar_Scroll(object sender, ScrollEventArgs e)
|
||||
=> HorizontalScroller.ScrollToHorizontalOffset(e.NewValue);
|
||||
|
||||
void RollCanvas_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
var factor = e.Delta > 0 ? NoteEditorViewModel.ZoomStep : 1.0 / NoteEditorViewModel.ZoomStep;
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
|
||||
{
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
|
||||
viewModel.ZoomVertically(factor);
|
||||
else
|
||||
viewModel.ZoomHorizontally(factor);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
|
||||
{
|
||||
HorizontalScroller.ScrollToHorizontalOffset(HorizontalScroller.HorizontalOffset - Math.Sign(e.Delta) * WheelScrollStep);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
VerticalScroller.ScrollToVerticalOffset(VerticalScroller.VerticalOffset - Math.Sign(e.Delta) * WheelScrollStep);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void RollCanvas_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton != MouseButton.Middle)
|
||||
return;
|
||||
|
||||
isPanning = true;
|
||||
panOrigin = e.GetPosition(RollCanvas);
|
||||
panHorizontalOffset = HorizontalScroller.HorizontalOffset;
|
||||
panVerticalOffset = VerticalScroller.VerticalOffset;
|
||||
RollCanvas.CaptureMouse();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void RollCanvas_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton != MouseButton.Middle)
|
||||
return;
|
||||
|
||||
EndPan();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void RollCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
if (e.ClickCount >= 2)
|
||||
{
|
||||
if (viewModel.SelectedNote is not { } selected || selected.IsRest)
|
||||
return;
|
||||
|
||||
var position = e.GetPosition(RollCanvas);
|
||||
var ticks = viewModel.TicksFromCanvasX(position.X) - selected.StartTicks;
|
||||
viewModel.AddPitchPointAt(
|
||||
Math.Clamp(ticks, 0, selected.Note.LengthTicks),
|
||||
viewModel.CentsFromCanvasY(position.Y, selected.Note.Tone));
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
dragMode = DragMode.Select;
|
||||
dragOrigin = e.GetPosition(RollCanvas);
|
||||
viewModel.UpdateSelectionBox(dragOrigin, dragOrigin);
|
||||
RollCanvas.CaptureMouse();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void EndPan()
|
||||
{
|
||||
if (!isPanning)
|
||||
return;
|
||||
|
||||
isPanning = false;
|
||||
RollCanvas.ReleaseMouseCapture();
|
||||
}
|
||||
|
||||
void Key_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: KeyRowViewModel row } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
viewModel.SelectToneCommand.Execute(row);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void Note_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: NoteViewModel note } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
e.Handled = true;
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
|
||||
{
|
||||
viewModel.ToggleSelection(note);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
|
||||
{
|
||||
viewModel.SelectRange(note);
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.MakePrimary(note);
|
||||
BeginDrag(note, DragMode.Tone, e);
|
||||
}
|
||||
|
||||
void NoteResize_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: NoteViewModel note } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
viewModel.MakePrimary(note);
|
||||
BeginDrag(note, DragMode.Length, e);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void PitchHandle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: PitchHandleViewModel handle } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
viewModel.SelectedPitchPoint = handle.Point;
|
||||
dragMode = DragMode.PitchHandle;
|
||||
dragPoint = handle.Point;
|
||||
RollCanvas.CaptureMouse();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void PitchHandle_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: PitchHandleViewModel handle } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
viewModel.RemovePitchPoint(handle.Point);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void BeginDrag(NoteViewModel note, DragMode mode, MouseButtonEventArgs e)
|
||||
{
|
||||
dragMode = mode;
|
||||
dragTarget = note;
|
||||
dragOrigin = e.GetPosition(RollCanvas);
|
||||
dragMoved = false;
|
||||
ViewModel?.BeginTransform();
|
||||
RollCanvas.CaptureMouse();
|
||||
}
|
||||
|
||||
void RollCanvas_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
var position = e.GetPosition(RollCanvas);
|
||||
viewModel.UpdateGuide(position);
|
||||
|
||||
if (isPanning)
|
||||
{
|
||||
HorizontalScroller.ScrollToHorizontalOffset(panHorizontalOffset - (position.X - panOrigin.X));
|
||||
VerticalScroller.ScrollToVerticalOffset(panVerticalOffset - (position.Y - panOrigin.Y));
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragMode == DragMode.Select)
|
||||
{
|
||||
viewModel.UpdateSelectionBox(dragOrigin, position);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragMode == DragMode.PitchHandle && dragPoint is not null && viewModel.SelectedNote is { } owner)
|
||||
{
|
||||
var ticks = viewModel.TicksFromCanvasX(position.X) - owner.StartTicks;
|
||||
viewModel.MovePitchPoint(
|
||||
dragPoint,
|
||||
Math.Clamp(ticks, 0, owner.Note.LengthTicks),
|
||||
viewModel.CentsFromCanvasY(position.Y, owner.Note.Tone));
|
||||
viewModel.ShowPitchGuide(dragPoint);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragMode == DragMode.None || dragTarget is null)
|
||||
return;
|
||||
|
||||
if (dragMode == DragMode.Tone)
|
||||
{
|
||||
var delta = (int)Math.Round((dragOrigin.Y - position.Y) / viewModel.SemitoneHeight);
|
||||
dragMoved |= delta != 0;
|
||||
viewModel.TransformTones(delta);
|
||||
return;
|
||||
}
|
||||
|
||||
var deltaTicks = viewModel.TicksFromCanvasX(position.X - dragOrigin.X);
|
||||
dragMoved |= deltaTicks != 0;
|
||||
viewModel.TransformLengths(deltaTicks);
|
||||
}
|
||||
|
||||
void RollCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) => EndDrag();
|
||||
|
||||
void RollCanvas_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
ViewModel?.HideGuide();
|
||||
if (e.MiddleButton != MouseButtonState.Pressed)
|
||||
EndPan();
|
||||
if (e.LeftButton != MouseButtonState.Pressed)
|
||||
EndDrag();
|
||||
}
|
||||
|
||||
void EndDrag()
|
||||
{
|
||||
if (dragMode is DragMode.None or DragMode.Expression)
|
||||
return;
|
||||
|
||||
if (dragMode == DragMode.Select)
|
||||
{
|
||||
dragMode = DragMode.None;
|
||||
RollCanvas.ReleaseMouseCapture();
|
||||
ViewModel?.CommitSelectionBox(Keyboard.Modifiers.HasFlag(ModifierKeys.Control));
|
||||
return;
|
||||
}
|
||||
|
||||
var shouldRelayout = dragMode is DragMode.Tone or DragMode.Length;
|
||||
var collapseTarget = dragMode == DragMode.Tone && !dragMoved && ViewModel is { SelectedCount: > 1 }
|
||||
? dragTarget
|
||||
: null;
|
||||
dragMode = DragMode.None;
|
||||
dragTarget = null;
|
||||
dragPoint = null;
|
||||
dragMoved = false;
|
||||
RollCanvas.ReleaseMouseCapture();
|
||||
ViewModel?.EndTransform();
|
||||
if (collapseTarget is not null)
|
||||
ViewModel?.Select(collapseTarget);
|
||||
if (shouldRelayout)
|
||||
ViewModel?.InvalidateLayout();
|
||||
}
|
||||
|
||||
void StripCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (ViewModel is null)
|
||||
return;
|
||||
|
||||
dragMode = DragMode.Expression;
|
||||
StripCanvas.CaptureMouse();
|
||||
ApplyExpression(e.GetPosition(StripCanvas));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void StripCanvas_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (dragMode != DragMode.Expression || e.LeftButton != MouseButtonState.Pressed)
|
||||
return;
|
||||
|
||||
ApplyExpression(e.GetPosition(StripCanvas));
|
||||
}
|
||||
|
||||
void StripCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) => EndExpressionDrag();
|
||||
|
||||
void StripCanvas_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton != MouseButtonState.Pressed)
|
||||
EndExpressionDrag();
|
||||
}
|
||||
|
||||
void EndExpressionDrag()
|
||||
{
|
||||
if (dragMode != DragMode.Expression)
|
||||
return;
|
||||
|
||||
dragMode = DragMode.None;
|
||||
StripCanvas.ReleaseMouseCapture();
|
||||
ViewModel?.CommitExpression();
|
||||
}
|
||||
|
||||
void ApplyExpression(Point position)
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
var ticks = Math.Max(viewModel.TicksFromCanvasX(position.X), 0);
|
||||
viewModel.SetExpressionAt(ticks, 1.0 - position.Y / NoteEditorViewModel.StripHeight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
<UserControl x:Class="UTAU.Views.NoteEditorSurface"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:root="clr-namespace:UTAU"
|
||||
xmlns:vm="clr-namespace:UTAU.ViewModels"
|
||||
xmlns:v="clr-namespace:UTAU.Views"
|
||||
xmlns:c="clr-namespace:YukkuriMovieMaker.Controls;assembly=YukkuriMovieMaker.Controls"
|
||||
xmlns:icons="clr-namespace:YukkuriMovieMaker.Resources.Icons;assembly=YukkuriMovieMaker.Plugin"
|
||||
xmlns:theme="clr-namespace:YukkuriMovieMaker.Theme;assembly=YukkuriMovieMaker.Plugin"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="440" d:DesignWidth="960"
|
||||
d:DataContext="{d:DesignInstance Type={x:Type vm:NoteEditorViewModel}}">
|
||||
<UserControl.Resources>
|
||||
<SolidColorBrush x:Key="AccidentalRowBrush" Color="#26000000"/>
|
||||
<SolidColorBrush x:Key="AccidentalKeyBrush" Color="#59000000"/>
|
||||
<SolidColorBrush x:Key="NaturalKeyBrush" Color="#14FFFFFF"/>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibility"/>
|
||||
</UserControl.Resources>
|
||||
<Grid UseLayoutRounding="False">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="280"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="26"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="72"/>
|
||||
<RowDefinition Height="14"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" Grid.ColumnSpan="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||
<Button Width="26" Height="26" Command="{Binding ZoomOutCommand}" ToolTip="{x:Static root:Texts.ZoomOut}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.MagnifyMinusOutline}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ZoomInCommand}" ToolTip="{x:Static root:Texts.ZoomIn}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.MagnifyPlusOutline}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ZoomVerticalOutCommand}" ToolTip="{x:Static root:Texts.ZoomVerticalOut}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.ArrowCollapseVertical}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ZoomVerticalInCommand}" ToolTip="{x:Static root:Texts.ZoomVerticalIn}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.ArrowExpandVertical}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding FitCommand}" ToolTip="{x:Static root:Texts.FitToWindow}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.FitToScreenOutline}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding InsertRestCommand}" ToolTip="{x:Static root:Texts.InsertRest}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Plus}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding RemoveNoteCommand}" ToolTip="{x:Static root:Texts.RemoveNote}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Delete}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding SelectAllCommand}" ToolTip="{x:Static root:Texts.SelectAllNotes}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.SelectAll}}"/>
|
||||
<TextBlock Text="{x:Static root:Texts.SnapLabel}" VerticalAlignment="Center" Margin="6,0,3,0"/>
|
||||
<ComboBox Width="88" Height="26" VerticalContentAlignment="Center"
|
||||
ItemsSource="{Binding SnapDivisions}"
|
||||
SelectedItem="{Binding SnapDivision}"
|
||||
DisplayMemberPath="Name"/>
|
||||
<TextBlock Text="{x:Static root:Texts.ExpressionLabel}" VerticalAlignment="Center" Margin="12,0,3,0"/>
|
||||
<ComboBox Width="110" Height="26" VerticalContentAlignment="Center"
|
||||
ItemsSource="{Binding Expressions}"
|
||||
SelectedItem="{Binding SelectedExpression}"
|
||||
DisplayMemberPath="Name"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ResetExpressionCommand}" ToolTip="{x:Static root:Texts.ResetExpression}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Restore}}"/>
|
||||
<TextBlock Text="{Binding SelectionText}" VerticalAlignment="Center" Margin="12,0,0,0" Opacity="0.75"/>
|
||||
<TextBlock Text="{Binding GuideText}" VerticalAlignment="Center" Margin="12,0,0,0" Opacity="0.75"/>
|
||||
</StackPanel>
|
||||
|
||||
<DockPanel Grid.Column="1">
|
||||
<v:ScrollingText DockPanel.Dock="Right" Text="{Binding RenderMessage}" VerticalAlignment="Center" Margin="12,0,0,0"
|
||||
Foreground="{DynamicResource {x:Static theme:YMM4Colors.WarningBannerForegroundBrushKey}}"/>
|
||||
<v:ScrollingText Text="{Binding ImportMessage}" VerticalAlignment="Center" Margin="12,0,0,0" Opacity="0.75"/>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
|
||||
<ScrollViewer x:Name="VerticalScroller" Grid.Row="1" Grid.Column="0"
|
||||
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"
|
||||
SizeChanged="Scroller_SizeChanged">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="42"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ItemsControl Grid.Column="0" ItemsSource="{Binding Keyboard}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Height="{Binding Height}"
|
||||
BorderThickness="0,0,1,1"
|
||||
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
|
||||
MouseLeftButtonDown="Key_MouseLeftButtonDown"
|
||||
Cursor="Hand">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="{StaticResource NaturalKeyBrush}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsAccidental}" Value="True">
|
||||
<Setter Property="Background" Value="{StaticResource AccidentalKeyBrush}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Right"
|
||||
Margin="0,0,3,0" FontSize="9" Opacity="0.75" IsHitTestVisible="False"/>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ScrollViewer x:Name="HorizontalScroller" Grid.Column="1"
|
||||
HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled"
|
||||
ScrollChanged="HorizontalScroller_ScrollChanged"
|
||||
SizeChanged="Scroller_SizeChanged">
|
||||
<Canvas x:Name="RollCanvas"
|
||||
Width="{Binding CanvasWidth}"
|
||||
Height="{Binding CanvasHeight}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Background="Transparent"
|
||||
ToolTip="{x:Static root:Texts.NoteEditorHint}"
|
||||
MouseMove="RollCanvas_MouseMove"
|
||||
MouseLeftButtonDown="RollCanvas_MouseLeftButtonDown"
|
||||
MouseLeftButtonUp="RollCanvas_MouseLeftButtonUp"
|
||||
MouseLeave="RollCanvas_MouseLeave"
|
||||
MouseDown="RollCanvas_MouseDown"
|
||||
MouseUp="RollCanvas_MouseUp"
|
||||
PreviewMouseWheel="RollCanvas_PreviewMouseWheel">
|
||||
<Canvas.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="{x:Static root:Texts.NoteContextCopy}" Command="{Binding CopyNotesCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.ContentCopy}}"/>
|
||||
<MenuItem Header="{x:Static root:Texts.NoteContextPaste}" Command="{Binding PasteNotesCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.ContentPaste}}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="{x:Static root:Texts.SelectAllNotes}" Command="{Binding SelectAllCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.SelectAll}}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="{x:Static root:Texts.OctaveUp}" Command="{Binding OctaveUpCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.ArrowUp}}"/>
|
||||
<MenuItem Header="{x:Static root:Texts.OctaveDown}" Command="{Binding OctaveDownCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.ArrowDown}}"/>
|
||||
<MenuItem Header="{x:Static root:Texts.QuantizeLength}" Command="{Binding QuantizeLengthCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.Magnet}}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="{x:Static root:Texts.ResetGroup}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.Restore}}">
|
||||
<MenuItem Header="{x:Static root:Texts.ResetPitch}" Command="{Binding ResetPitchCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.VectorCurve}}"/>
|
||||
<MenuItem Header="{x:Static root:Texts.ResetVibrato}" Command="{Binding ResetVibratoCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.SineWave}}"/>
|
||||
<MenuItem Header="{x:Static root:Texts.ResetTiming}" Command="{Binding ResetTimingCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.TimerOutline}}"/>
|
||||
<MenuItem Header="{x:Static root:Texts.ResetNote}" Command="{Binding ResetNoteCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.BackupRestore}}"/>
|
||||
</MenuItem>
|
||||
<Separator/>
|
||||
<MenuItem Header="{x:Static root:Texts.EditLyrics}" Command="{Binding EditLyricsCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.TextBoxEdit}}"/>
|
||||
<MenuItem Header="{x:Static root:Texts.DetachEditor}" Command="{Binding DetachCommand}"
|
||||
Icon="{DynamicResource {x:Static icons:IconKeys.OpenInNew}}"
|
||||
Visibility="{Binding CanDetach, Converter={StaticResource BooleanToVisibility}}"/>
|
||||
</ContextMenu>
|
||||
</Canvas.ContextMenu>
|
||||
<ItemsControl ItemsSource="{Binding Keyboard}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Height="{Binding Height}" Width="{Binding RollWidth}"
|
||||
BorderThickness="0,0,0,1"
|
||||
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsAccidental}" Value="True">
|
||||
<Setter Property="Background" Value="{StaticResource AccidentalRowBrush}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding TimeGridLines}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Rectangle Width="1" Height="{Binding Height}"
|
||||
Fill="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}">
|
||||
<Rectangle.Style>
|
||||
<Style TargetType="Rectangle">
|
||||
<Setter Property="Opacity" Value="0.4"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsBar}" Value="True">
|
||||
<Setter Property="Opacity" Value="0.9"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Rectangle.Style>
|
||||
</Rectangle>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding VisibleNotes}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
<Setter Property="Canvas.Top" Value="{Binding Top}"/>
|
||||
<Setter Property="Panel.ZIndex" Value="1"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Width="{Binding Width}" Height="{Binding Height}"
|
||||
MouseLeftButtonDown="Note_MouseLeftButtonDown"
|
||||
MouseRightButtonDown="Note_MouseRightButtonDown"
|
||||
ToolTip="{Binding ToneName}">
|
||||
<Border BorderThickness="1">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
|
||||
<Setter Property="Opacity" Value="0.6"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsRest}" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"/>
|
||||
<Setter Property="Opacity" Value="0.35"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsSelected}" Value="True">
|
||||
<Setter Property="Opacity" Value="1"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<Border IsHitTestVisible="False"
|
||||
BorderBrush="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibility}}">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="Opacity" Value="0.55"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsPrimary}" Value="True">
|
||||
<Setter Property="BorderThickness" Value="2"/>
|
||||
<Setter Property="Opacity" Value="1"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock Text="{Binding Display}" FontSize="10" Margin="4,0,0,0"
|
||||
VerticalAlignment="Center" ClipToBounds="True" IsHitTestVisible="False"
|
||||
Foreground="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
|
||||
<Rectangle Width="6" HorizontalAlignment="Right" Fill="Transparent" Cursor="SizeWE"
|
||||
MouseLeftButtonDown="NoteResize_MouseLeftButtonDown"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Polyline Points="{Binding PitchCurve}" StrokeThickness="1.5" Panel.ZIndex="2"
|
||||
Stroke="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Opacity="0.85"
|
||||
IsHitTestVisible="False"/>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding PitchHandles}" Panel.ZIndex="3">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
<Setter Property="Canvas.Top" Value="{Binding Top}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Rectangle Width="{Binding Size}" Height="{Binding Size}" Cursor="SizeAll"
|
||||
Fill="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Stroke="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
|
||||
StrokeThickness="1"
|
||||
ToolTip="{x:Static root:Texts.PitchHandleHint}"
|
||||
MouseLeftButtonDown="PitchHandle_MouseLeftButtonDown"
|
||||
MouseRightButtonDown="PitchHandle_MouseRightButtonDown"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Rectangle Width="1" Height="{Binding CanvasHeight}" Panel.ZIndex="4"
|
||||
Canvas.Left="{Binding GuideLeft}"
|
||||
Fill="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Opacity="0.6"
|
||||
IsHitTestVisible="False"
|
||||
Visibility="{Binding IsGuideVisible, Converter={StaticResource BooleanToVisibility}}"/>
|
||||
|
||||
<Rectangle Panel.ZIndex="5" IsHitTestVisible="False" StrokeThickness="1" Opacity="0.35"
|
||||
Canvas.Left="{Binding SelectionBoxLeft}"
|
||||
Canvas.Top="{Binding SelectionBoxTop}"
|
||||
Width="{Binding SelectionBoxWidth}"
|
||||
Height="{Binding SelectionBoxHeight}"
|
||||
Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
|
||||
Stroke="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"
|
||||
Visibility="{Binding IsSelectionBoxVisible, Converter={StaticResource BooleanToVisibility}}"/>
|
||||
</Canvas>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
|
||||
|
||||
<Grid Grid.Row="2" Grid.Column="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="42"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="{Binding SelectedExpression.Name}" FontSize="9" Opacity="0.75"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,3,0"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
<ScrollViewer x:Name="StripScroller" Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled">
|
||||
<Canvas x:Name="StripCanvas"
|
||||
Width="{Binding CanvasWidth}"
|
||||
Height="{Binding StripCanvasHeight}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Background="Transparent"
|
||||
ToolTip="{x:Static root:Texts.ExpressionHint}"
|
||||
MouseLeftButtonDown="StripCanvas_MouseLeftButtonDown"
|
||||
MouseLeftButtonUp="StripCanvas_MouseLeftButtonUp"
|
||||
MouseMove="StripCanvas_MouseMove"
|
||||
MouseLeave="StripCanvas_MouseLeave">
|
||||
<ItemsControl ItemsSource="{Binding TimeGridLines}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Rectangle Width="1" Height="72" Opacity="0.4"
|
||||
Fill="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding ExpressionBars}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
|
||||
<Setter Property="Canvas.Top" Value="{Binding Top}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Width="{Binding Width}" Height="{Binding Height}"
|
||||
Background="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
|
||||
IsHitTestVisible="False">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Opacity" Value="0.6"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Note.IsSelected}" Value="True">
|
||||
<Setter Property="Opacity" Value="1"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Polyline Points="{Binding ExpressionCurvePoints}" StrokeThickness="1.5"
|
||||
Stroke="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
|
||||
IsHitTestVisible="False"/>
|
||||
</Canvas>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
<ScrollBar x:Name="HorizontalBar" Grid.Row="3" Grid.Column="0" Orientation="Horizontal"
|
||||
Margin="42,0,0,0" Scroll="HorizontalBar_Scroll"/>
|
||||
|
||||
<Grid Grid.Row="1" Grid.RowSpan="3" Grid.Column="1" IsEnabled="{Binding HasSelection}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="26"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel>
|
||||
<c:PropertiesEditor Targets="{Binding SelectedNoteTargets}" IsScrollViewerEnabled="False"/>
|
||||
<c:PropertiesEditor Target="{Binding SelectedPitchPoint}" IsScrollViewerEnabled="False"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Width="26" Height="26" Command="{Binding AddPitchPointCommand}" ToolTip="{x:Static root:Texts.AddPitchPoint}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Plus}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding RemovePitchPointCommand}" ToolTip="{x:Static root:Texts.RemovePitchPoint}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Minus}}"/>
|
||||
<Button Width="26" Height="26" Command="{Binding ResetPitchCommand}" ToolTip="{x:Static root:Texts.ResetPitch}"
|
||||
Content="{DynamicResource {x:Static icons:IconKeys.Restore}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,402 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using UTAU.Notes;
|
||||
using UTAU.ViewModels;
|
||||
|
||||
namespace UTAU.Views;
|
||||
|
||||
public partial class NoteEditorSurface : UserControl
|
||||
{
|
||||
enum DragMode
|
||||
{
|
||||
None,
|
||||
Tone,
|
||||
Length,
|
||||
PitchHandle,
|
||||
Expression,
|
||||
Select,
|
||||
}
|
||||
|
||||
const double WheelScrollStep = 64.0;
|
||||
|
||||
DragMode dragMode;
|
||||
NoteViewModel? dragTarget;
|
||||
PitchPoint? dragPoint;
|
||||
Point dragOrigin;
|
||||
bool dragMoved;
|
||||
bool isPanning;
|
||||
Point panOrigin;
|
||||
double panHorizontalOffset;
|
||||
double panVerticalOffset;
|
||||
NoteEditorViewModel? attached;
|
||||
|
||||
public NoteEditorSurface()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += (_, _) => RequestFit();
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
OnDataContextChanged(this, default);
|
||||
}
|
||||
|
||||
void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (attached is not null)
|
||||
attached.LyricsEditRequested -= OnLyricsEditRequested;
|
||||
|
||||
attached = DataContext as NoteEditorViewModel;
|
||||
|
||||
if (attached is not null)
|
||||
attached.LyricsEditRequested += OnLyricsEditRequested;
|
||||
|
||||
if (RollCanvas.ContextMenu is { } menu)
|
||||
menu.DataContext = DataContext;
|
||||
}
|
||||
|
||||
void OnLyricsEditRequested(object? sender, EventArgs e)
|
||||
{
|
||||
if (ViewModel is not { } viewModel || viewModel.SelectedCount == 0)
|
||||
return;
|
||||
|
||||
var dialog = new LyricsBulkEditWindow(new LyricsBulkEditViewModel(viewModel.ReadSelectedLyrics(), viewModel.SelectedCount));
|
||||
if (OwnerWindow() is { } owner && !ReferenceEquals(owner, dialog))
|
||||
dialog.Owner = owner;
|
||||
if (dialog.ShowDialog() == true)
|
||||
viewModel.ApplyLyrics(dialog.ViewModel.Lyrics);
|
||||
}
|
||||
|
||||
static Window? OwnerWindow()
|
||||
=> Application.Current?.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive)
|
||||
?? Application.Current?.MainWindow;
|
||||
|
||||
NoteEditorViewModel? ViewModel => DataContext as NoteEditorViewModel;
|
||||
|
||||
internal void RequestFit() => Dispatcher.BeginInvoke(UpdateFit, DispatcherPriority.Loaded);
|
||||
|
||||
void UpdateFit()
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
viewModel.FitToViewport(HorizontalScroller.ActualWidth, VerticalScroller.ActualHeight);
|
||||
viewModel.SetViewport(HorizontalScroller.HorizontalOffset, HorizontalScroller.ViewportWidth);
|
||||
}
|
||||
|
||||
void Scroller_SizeChanged(object sender, SizeChangedEventArgs e) => UpdateFit();
|
||||
|
||||
void HorizontalScroller_ScrollChanged(object sender, ScrollChangedEventArgs e)
|
||||
{
|
||||
HorizontalBar.Maximum = Math.Max(e.ExtentWidth - e.ViewportWidth, 0.0);
|
||||
HorizontalBar.ViewportSize = e.ViewportWidth;
|
||||
HorizontalBar.LargeChange = e.ViewportWidth;
|
||||
HorizontalBar.SmallChange = WheelScrollStep;
|
||||
HorizontalBar.Value = e.HorizontalOffset;
|
||||
StripScroller.Width = e.ViewportWidth;
|
||||
StripScroller.ScrollToHorizontalOffset(e.HorizontalOffset);
|
||||
ViewModel?.SetViewport(e.HorizontalOffset, e.ViewportWidth);
|
||||
}
|
||||
|
||||
void HorizontalBar_Scroll(object sender, ScrollEventArgs e)
|
||||
=> HorizontalScroller.ScrollToHorizontalOffset(e.NewValue);
|
||||
|
||||
void RollCanvas_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
var factor = e.Delta > 0 ? NoteEditorViewModel.ZoomStep : 1.0 / NoteEditorViewModel.ZoomStep;
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
|
||||
{
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
|
||||
viewModel.ZoomVertically(factor);
|
||||
else
|
||||
viewModel.ZoomHorizontally(factor);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
|
||||
{
|
||||
HorizontalScroller.ScrollToHorizontalOffset(HorizontalScroller.HorizontalOffset - Math.Sign(e.Delta) * WheelScrollStep);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
VerticalScroller.ScrollToVerticalOffset(VerticalScroller.VerticalOffset - Math.Sign(e.Delta) * WheelScrollStep);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void RollCanvas_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton != MouseButton.Middle)
|
||||
return;
|
||||
|
||||
isPanning = true;
|
||||
panOrigin = e.GetPosition(RollCanvas);
|
||||
panHorizontalOffset = HorizontalScroller.HorizontalOffset;
|
||||
panVerticalOffset = VerticalScroller.VerticalOffset;
|
||||
RollCanvas.CaptureMouse();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void RollCanvas_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton != MouseButton.Middle)
|
||||
return;
|
||||
|
||||
EndPan();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void RollCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
if (e.ClickCount >= 2)
|
||||
{
|
||||
if (viewModel.SelectedNote is not { } selected || selected.IsRest)
|
||||
return;
|
||||
|
||||
var position = e.GetPosition(RollCanvas);
|
||||
var ticks = viewModel.TicksFromCanvasX(position.X) - selected.StartTicks;
|
||||
viewModel.AddPitchPointAt(
|
||||
Math.Clamp(ticks, 0, selected.Note.LengthTicks),
|
||||
viewModel.CentsFromCanvasY(position.Y, selected.Note.Tone));
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
dragMode = DragMode.Select;
|
||||
dragOrigin = e.GetPosition(RollCanvas);
|
||||
viewModel.UpdateSelectionBox(dragOrigin, dragOrigin);
|
||||
RollCanvas.CaptureMouse();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void EndPan()
|
||||
{
|
||||
if (!isPanning)
|
||||
return;
|
||||
|
||||
isPanning = false;
|
||||
RollCanvas.ReleaseMouseCapture();
|
||||
}
|
||||
|
||||
void Key_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: KeyRowViewModel row } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
viewModel.SelectToneCommand.Execute(row);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void Note_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: NoteViewModel note } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
e.Handled = true;
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
|
||||
{
|
||||
viewModel.ToggleSelection(note);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
|
||||
{
|
||||
viewModel.SelectRange(note);
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.MakePrimary(note);
|
||||
BeginDrag(note, DragMode.Tone, e);
|
||||
}
|
||||
|
||||
void Note_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: NoteViewModel note } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
if (!note.IsSelected)
|
||||
viewModel.Select(note);
|
||||
}
|
||||
|
||||
void NoteResize_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: NoteViewModel note } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
viewModel.MakePrimary(note);
|
||||
BeginDrag(note, DragMode.Length, e);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void PitchHandle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: PitchHandleViewModel handle } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
viewModel.SelectedPitchPoint = handle.Point;
|
||||
dragMode = DragMode.PitchHandle;
|
||||
dragPoint = handle.Point;
|
||||
RollCanvas.CaptureMouse();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void PitchHandle_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is not FrameworkElement { DataContext: PitchHandleViewModel handle } || ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
viewModel.RemovePitchPoint(handle.Point);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void BeginDrag(NoteViewModel note, DragMode mode, MouseButtonEventArgs e)
|
||||
{
|
||||
dragMode = mode;
|
||||
dragTarget = note;
|
||||
dragOrigin = e.GetPosition(RollCanvas);
|
||||
dragMoved = false;
|
||||
ViewModel?.BeginTransform();
|
||||
RollCanvas.CaptureMouse();
|
||||
}
|
||||
|
||||
void RollCanvas_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
var position = e.GetPosition(RollCanvas);
|
||||
viewModel.UpdateGuide(position);
|
||||
|
||||
if (isPanning)
|
||||
{
|
||||
HorizontalScroller.ScrollToHorizontalOffset(panHorizontalOffset - (position.X - panOrigin.X));
|
||||
VerticalScroller.ScrollToVerticalOffset(panVerticalOffset - (position.Y - panOrigin.Y));
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragMode == DragMode.Select)
|
||||
{
|
||||
viewModel.UpdateSelectionBox(dragOrigin, position);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragMode == DragMode.PitchHandle && dragPoint is not null && viewModel.SelectedNote is { } owner)
|
||||
{
|
||||
var ticks = viewModel.TicksFromCanvasX(position.X) - owner.StartTicks;
|
||||
viewModel.MovePitchPoint(
|
||||
dragPoint,
|
||||
Math.Clamp(ticks, 0, owner.Note.LengthTicks),
|
||||
viewModel.CentsFromCanvasY(position.Y, owner.Note.Tone));
|
||||
viewModel.ShowPitchGuide(dragPoint);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragMode == DragMode.None || dragTarget is null)
|
||||
return;
|
||||
|
||||
if (dragMode == DragMode.Tone)
|
||||
{
|
||||
var delta = (int)Math.Round((dragOrigin.Y - position.Y) / viewModel.SemitoneHeight);
|
||||
dragMoved |= delta != 0;
|
||||
viewModel.TransformTones(delta);
|
||||
return;
|
||||
}
|
||||
|
||||
var deltaTicks = viewModel.TicksFromCanvasX(position.X - dragOrigin.X);
|
||||
dragMoved |= deltaTicks != 0;
|
||||
viewModel.TransformLengths(deltaTicks);
|
||||
}
|
||||
|
||||
void RollCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) => EndDrag();
|
||||
|
||||
void RollCanvas_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
ViewModel?.HideGuide();
|
||||
if (e.MiddleButton != MouseButtonState.Pressed)
|
||||
EndPan();
|
||||
if (e.LeftButton != MouseButtonState.Pressed)
|
||||
EndDrag();
|
||||
}
|
||||
|
||||
void EndDrag()
|
||||
{
|
||||
if (dragMode is DragMode.None or DragMode.Expression)
|
||||
return;
|
||||
|
||||
if (dragMode == DragMode.Select)
|
||||
{
|
||||
dragMode = DragMode.None;
|
||||
RollCanvas.ReleaseMouseCapture();
|
||||
ViewModel?.CommitSelectionBox(Keyboard.Modifiers.HasFlag(ModifierKeys.Control));
|
||||
return;
|
||||
}
|
||||
|
||||
var shouldRelayout = dragMode is DragMode.Tone or DragMode.Length;
|
||||
var collapseTarget = dragMode == DragMode.Tone && !dragMoved && ViewModel is { SelectedCount: > 1 }
|
||||
? dragTarget
|
||||
: null;
|
||||
dragMode = DragMode.None;
|
||||
dragTarget = null;
|
||||
dragPoint = null;
|
||||
dragMoved = false;
|
||||
RollCanvas.ReleaseMouseCapture();
|
||||
ViewModel?.EndTransform();
|
||||
if (collapseTarget is not null)
|
||||
ViewModel?.Select(collapseTarget);
|
||||
if (shouldRelayout)
|
||||
ViewModel?.InvalidateLayout();
|
||||
}
|
||||
|
||||
void StripCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (ViewModel is null)
|
||||
return;
|
||||
|
||||
dragMode = DragMode.Expression;
|
||||
StripCanvas.CaptureMouse();
|
||||
ApplyExpression(e.GetPosition(StripCanvas));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
void StripCanvas_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (dragMode != DragMode.Expression || e.LeftButton != MouseButtonState.Pressed)
|
||||
return;
|
||||
|
||||
ApplyExpression(e.GetPosition(StripCanvas));
|
||||
}
|
||||
|
||||
void StripCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) => EndExpressionDrag();
|
||||
|
||||
void StripCanvas_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton != MouseButtonState.Pressed)
|
||||
EndExpressionDrag();
|
||||
}
|
||||
|
||||
void EndExpressionDrag()
|
||||
{
|
||||
if (dragMode != DragMode.Expression)
|
||||
return;
|
||||
|
||||
dragMode = DragMode.None;
|
||||
StripCanvas.ReleaseMouseCapture();
|
||||
ViewModel?.CommitExpression();
|
||||
}
|
||||
|
||||
void ApplyExpression(Point position)
|
||||
{
|
||||
if (ViewModel is not { } viewModel)
|
||||
return;
|
||||
|
||||
var ticks = Math.Max(viewModel.TicksFromCanvasX(position.X), 0);
|
||||
viewModel.SetExpressionAt(ticks, 1.0 - position.Y / NoteEditorViewModel.StripHeight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<Window x:Class="UTAU.Views.NoteEditorWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:root="clr-namespace:UTAU"
|
||||
xmlns:vm="clr-namespace:UTAU.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type={x:Type vm:NoteEditorViewModel}}"
|
||||
Title="{x:Static root:Texts.EditNotes}"
|
||||
Width="1180" Height="640" MinWidth="640" MinHeight="360"
|
||||
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
|
||||
<Window.Style>
|
||||
<Style TargetType="{x:Type Window}" BasedOn="{StaticResource {x:Type Window}}"/>
|
||||
</Window.Style>
|
||||
<ContentControl x:Name="SurfaceHost"/>
|
||||
</Window>
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace UTAU.Views;
|
||||
|
||||
public partial class NoteEditorWindow : Window
|
||||
{
|
||||
internal NoteEditorWindow(NoteEditorSurface surface)
|
||||
{
|
||||
InitializeComponent();
|
||||
SurfaceHost.Content = surface;
|
||||
}
|
||||
|
||||
internal NoteEditorSurface? Surface => SurfaceHost.Content as NoteEditorSurface;
|
||||
|
||||
internal NoteEditorSurface? Release()
|
||||
{
|
||||
var surface = SurfaceHost.Content as NoteEditorSurface;
|
||||
SurfaceHost.Content = null;
|
||||
return surface;
|
||||
}
|
||||
}
|
||||
サブモジュール
+1
サブモジュール YMM4-Telemetry が 04010903ca で追加されました。
新しいイシューから参照
ユーザーをブロックする