From 7545be27204273834f3111172397531531828336 Mon Sep 17 00:00:00 2001 From: hsshss <5428297+hsshss@users.noreply.github.com> Date: Tue, 13 Oct 2026 23:00:00 +0900 Subject: [PATCH 1/3] Put effects on the audio plugins and show how each is doing Brack.NET 1.2.0 puts a chain of effects on each instrument and on the master, and meters each chain. The audio plugins window is laid out again around them: a card for each instrument with its MIDI lamp, its level, its CPU load and its effects, which can be bypassed and dragged into order; the master's effects after the cards; and the output's device, level, load and dropouts above its settings. Instruments and effects are added from a list that can be narrowed, which offers only the effects built for the CPU their chain runs on. An editor's hold on the audio ends when Brack says it closed, which it now does for the editors a reload or a removal takes with the chain. A rack with only master effects is saved on closing. The view model's tests keep the scan's cache in a settings folder of their own. --- DEVELOPMENT.ja.md | 2 +- DEVELOPMENT.md | 5 +- Directory.Build.props | 2 +- IMPLEMENTATION.md | 4 +- README.ja.md | 15 +- README.md | 17 +- src/Glosa.App/Glosa.App.csproj | 3 +- src/Glosa.App/Strings.Designer.cs | 220 +++++++- src/Glosa.App/Strings.ja.resx | 80 ++- src/Glosa.App/Strings.resx | 80 ++- .../ViewModels/AudioPluginsViewModel.cs | 518 ++++++++++++++---- src/Glosa.App/Views/AudioPluginsWindow.axaml | 431 +++++++++++---- .../Views/AudioPluginsWindow.axaml.cs | 89 ++- src/Glosa.App/Views/PluginPickerWindow.axaml | 50 ++ .../Views/PluginPickerWindow.axaml.cs | 63 +++ src/Glosa.Midi.Brack/BrackRack.cs | 181 ++++-- .../Glosa.Tests/AudioPluginsViewModelTests.cs | 53 +- tests/Glosa.Tests/BrackRackTests.cs | 148 ++++- tests/Glosa.Tests/Glosa.Tests.csproj | 4 +- 19 files changed, 1635 insertions(+), 330 deletions(-) create mode 100644 src/Glosa.App/Views/PluginPickerWindow.axaml create mode 100644 src/Glosa.App/Views/PluginPickerWindow.axaml.cs diff --git a/DEVELOPMENT.ja.md b/DEVELOPMENT.ja.md index 7bfb6d35..93180c15 100644 --- a/DEVELOPMENT.ja.md +++ b/DEVELOPMENT.ja.md @@ -36,7 +36,7 @@ push と pull request のたびに、`.github/workflows/ci.yml` が Windows・ma 無ければ、`BrackVersion` に書いたバージョンの NuGet パッケージを nuget.org から取る。隣にリポジトリの無い CI とリリースは、これを使う。 `BrackVersion` が空ならどちらも使わず、Brack 無しでビルドする。 隣にリポジトリがあってもパッケージで確かめたいときは、`-p:UseBrackPackage=true` を付ける。 -ソースから参照しているときは、テストが Brack のテスト用の音源(`build/bin/brack-test-synth.clap`)でプラグインを鳴らすので、Brack をテスト込みでビルドしておく。macOS では Brack がメインスレッドで動くので、テストは自前のエントリポイント(`tests/Glosa.Tests/Program.cs`)で別のスレッドに移し、メインスレッドではランループを回す。 +ソースから参照しているときは、テストが Brack のテスト用の音源とエフェクト(`build/bin/brack-test-synth.clap`、`build/bin/brack-test-gain.clap`)でプラグインを鳴らすので、Brack をテスト込みでビルドしておく。macOS では Brack がメインスレッドで動くので、テストは自前のエントリポイント(`tests/Glosa.Tests/Program.cs`)で別のスレッドに移し、メインスレッドではランループを回す。 GUI: diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index acfdad6a..360b20fd 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -47,8 +47,9 @@ native library Brack has built (on Windows, `brack.dll` in `build\bin` and in `BrackVersion` from nuget.org, as CI and the releases do, having no checkout beside. With `BrackVersion` empty it takes neither, and builds without Brack. To try the package with a checkout beside, add `-p:UseBrackPackage=true`. Built from source, -Brack is also played by the tests through its test instrument -(`build/bin/brack-test-synth.clap`), so build Brack with its tests. On macOS, where Brack +Brack is also played by the tests through its test instrument and effect +(`build/bin/brack-test-synth.clap`, `build/bin/brack-test-gain.clap`), so build Brack with its +tests. On macOS, where Brack works on the main thread, the tests' own entry point (`tests/Glosa.Tests/Program.cs`) runs them on another thread and keeps the main thread's run loop running. diff --git a/Directory.Build.props b/Directory.Build.props index c3b87fa1..e35c598c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -26,7 +26,7 @@ defined. Whether it runs on this system is found at run time. --> - 1.1.0 + 1.2.0 $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)../brack/bindings/dotnet/Brack/Brack.csproj')) Project Package diff --git a/IMPLEMENTATION.md b/IMPLEMENTATION.md index 97265183..589cd65e 100644 --- a/IMPLEMENTATION.md +++ b/IMPLEMENTATION.md @@ -610,6 +610,8 @@ MIDI はそのノートポートへ、受け取ったバイト列のまま渡す - **バッファ(音声デバイスの周期)は時間で選び、新しいラックでは 20 ms にする**(`BrackRack.Buffer`)。Brack の既定(256 フレーム)は弾いた音にすぐ応えるための短さで、曲を再生するだけの Glosa には要らない。長いほど、重いプラグインやほかの処理があっても音が途切れにくい。ただし Brack はメッセージを届いた 1 周期後に置くので、周期のぶんプラグインの音は MIDI ポートの先の機械より遅れる。20 ms は Windows の共有モードの周期(10 ms、これより短くしても効かない)の倍で、遅れも 20 ms ほどに収まる。Brack の設定はフレーム数なので、選んだときの出力デバイスのレートで換算して持ち、出力デバイスを変えるときは新しいデバイスのレートで換算し直す。既定の出力が変わるなどしてレートの違うデバイスで鳴ると長さも変わり、窓にはそのときのレートでの長さが出る。 - **サンプリングレートは、プラグインを動かすレート(`process_sample_rate`)を選ぶ。** 出力デバイスのレートは共有モードでは OS のミキサーのもので、Brack から変えられるのは Windows の排他モードだけ。排他モードは遅れを短くするためのもので、使っている間はほかのアプリの音が出なくなるので、設定に出さない。出力と違うレートを選ぶと、Brack が出力のレートに変換する。**変換の品質は設定に出さず、新しいラックで最高(Ultra)にする**(`BrackRack.Load`)。品質を下げる理由は CPU と遅れだが、測ると CPU の負荷は High より増えず(テスト用の音源で、44.1 kHz と 96 kHz から 48 kHz へ)、変換の遅れ(最大 9 ms ほど)は再生するだけの Glosa には効かない。 - **マスターボリュームはプラグインの音だけにかかり、Brack のマスターゲインとしてセッションに持つ**(`settings.yaml` には書かない)。MIDI ポートの先の機械の音量は Glosa から変えられないので、効く出力が無いときに出さないよう、どれかのポートマップにプラグインのポートが 1 つでもあるときだけ曲名の右に出す(`MainViewModel.UsesAudioPlugins`)。 +- **エフェクトは、音源ごとの連なりと、すべての音源をミックスした音にかけるマスターの連なりに置く**(`BrackRack.AddEffect`、Brack の `brack_add_effect`)。エフェクトは出力デバイスにならない。Brack は連なりを 1 つのプロセスで動かすので、エフェクトは音源と同じアーキテクチャのもの(マスターではプレイヤーと同じもの)しか読み込めない。そのため、追加する一覧には連なりのアーキテクチャのエフェクトだけを出す(`AudioPluginsViewModel.EffectPicker`)。 +- **ラックの窓の音源のメーターは、エフェクトがかかるメインの出力ポートのチャンネルだけを出す**(`BrackRack.Meters`)。出力の多い音源ですべてのポートを出すと、カードが縦に伸びるため。 - **送れなかったとき(プラグインがクラッシュした、ラックから外された、キューがあふれた)は出力の異常として曲を止める。** 黙って落とすと、ノートオフが届かず鳴り続けることがある。 - **メッセージは、送ったその場で Brack に渡し、周期の中のどこで送ったかは Brack が保つ**(`BrackRack.Send`、`brack_send_midi`)。Brack は時刻の無いメッセージに届いた時刻を記録し、音声デバイスの 1 周期後の、周期の中で届いた位置に置く(Brack の `ArrivalClock`)。Brack はメッセージを周期の頭でしか取り出さないので、以前はそのまま送ると、周期の中のどこで送ったかで最大で 1 周期揺れた。それを避けるため、Glosa の側で描画位置とストップウォッチから音声の時計を推定し、フレームで指定して送っていた(`RenderClock`、`brack_send_midi_at`)。外から見えるのは周期ごとにまとめて進む描画位置だけなので、推定には窓が要り、Brack が動いたまま別のレートのデバイスへ移ると(既定の出力が 44.1 kHz の Bluetooth イヤホンから 192 kHz の USB スピーカーに変わった、など)時計がずれた。音声のコールバックの時刻を直接見られる Brack が求めるほうが情報がよく、切り替えも Brack の中で分かるので、推定は Brack に移した。macOS の実デバイスで測ると、揺れの幅は Glosa で推定していたとき(0.005〜0.011 ms)よりわずかに大きいが 0.12 ms 以下で、遅れは平均で 1.2〜2.5 ms 短くなった(周期 480・960 フレーム、96 kHz と 192 kHz)。Windows と Linux ではまだ測っていない。 - **macOS では、UI スレッドは Brack の仕事を止まって待たない。** macOS の Brack は、プラグインがそこを AppKit のメインスレッドと見なすので、プロセスのメインスレッドで動き、ほかのスレッドからの呼び出しはそれを待つ(Brack の `brack.h`)。プレイヤーのメインスレッドは UI スレッドで、Avalonia がランループを回している。終了するときにセッションの読み込みがまだ終わっていなければ、ディスパッチャのループを回しながら待つ(`MainViewModel.RunUntil`)。止まって待つと、読み込みのほうもメインスレッドを待ち、プレイヤーが終わらなかった。ラックを変える操作は、もとから UI スレッドの外で行う。 @@ -624,7 +626,7 @@ MIDI はそのノートポートへ、受け取ったバイト列のまま渡す | macOS(Apple シリコン、`osx-arm64`) | x64・ARM64 | | Linux(x64、`linux-x64`) | x86・x64 | | Linux(ARM64、`linux-arm64`) | x86・x64・ARM64(エミュレーションには Box86・Box64・FEX-Emu を使う) | -- **「ファイルから...」は、macOS ではフォルダを選ぶ窓を開く**(`AudioPluginsWindow.OnAddFile`)。macOS のプラグインは CLAP・VST3・VST2 のどれもバンドル(フォルダ)で、ファイルを選ぶ窓では選べない。macOS がパッケージと見なさないバンドル(Brack がビルドするものなど)は、開いても中に入るだけになる。単体のファイルで置かれた CLAP(`.clap` という名前の dylib)は、Brack は読み込めるが、この窓では選べない。Avalonia はファイルとフォルダの両方を選べる窓を出せず、そうした CLAP も見当たらないので、このままにしている。ほかの OS ではファイルを選ぶ窓を開き、選べるのは Windows の形(`.clap`・`.vst3`・VST2 の `.dll`)だけ。Linux の VST2(`.so`)とフォルダのバンドルはまだ選べない。 +- **「ファイルから...」は、macOS ではフォルダを選ぶ窓を開く**(`PluginPickerWindow.OnAddFile`)。macOS のプラグインは CLAP・VST3・VST2 のどれもバンドル(フォルダ)で、ファイルを選ぶ窓では選べない。macOS がパッケージと見なさないバンドル(Brack がビルドするものなど)は、開いても中に入るだけになる。単体のファイルで置かれた CLAP(`.clap` という名前の dylib)は、Brack は読み込めるが、この窓では選べない。Avalonia はファイルとフォルダの両方を選べる窓を出せず、そうした CLAP も見当たらないので、このままにしている。ほかの OS ではファイルを選ぶ窓を開き、選べるのは Windows の形(`.clap`・`.vst3`・VST2 の `.dll`)だけ。Linux の VST2(`.so`)とフォルダのバンドルはまだ選べない。 ## CoreMIDI バックエンド diff --git a/README.ja.md b/README.ja.md index 9144145a..fe974dd2 100644 --- a/README.ja.md +++ b/README.ja.md @@ -94,13 +94,22 @@ TMIDI Player の定義ファイルを読み込むと、TMIDI Player と同じ** **設定 → オーディオプラグイン...** で、使う音源プラグインをラックに並べます。 -- CLAP・VST3・VST2 の標準のフォルダにある音源は、右の一覧に出ます。 +- **音源を追加...** で、CLAP・VST3・VST2 の標準のフォルダにある音源の一覧が出ます。 ダブルクリックか **追加** でラックに入れます。 ほかの場所にあるものは **ファイルから...** で入れます。 -- ラックのプラグインの MIDI ポートは、ポートマップ設定でほかの MIDI デバイスと同じように選べます。 +- ラックの音源の MIDI ポートは、ポートマップ設定でほかの MIDI デバイスと同じように選べます。 一覧では、プラグインに印が付きます。 -- プラグインを右クリックすると、エディタを開く・名前を変える・読み込み直す・削除する、が出ます。 +- エディタは **エディタ** かダブルクリックで開きます。 + **⋯** か右クリックで、エディタを開く・名前を変える・エフェクトを追加する・読み込み直す・削除する、が出ます。 名前を変えても、ポートマップの割り当てはそのまま付いていきます。 +- 音源ごとの **エフェクトを追加...** で、その音源にエフェクトをかけられます。 + **マスター** のエフェクトは、すべての音源をミックスした音にかかります。 + エフェクトは上から順にかかり、ドラッグで並べ替えられます。 + チェックを外すと、そのエフェクトを通さずに鳴らします。 + 使えるのは、かける音源と同じアーキテクチャのもの(マスターでは Glosa と同じもの)だけです。 +- 音源ごとに、MIDI が届いているか、音量のメーター、CPU の負荷が出ます。 + メーターの右の印は、音がフルスケールを超えると点き、クリックで消えます。 + 窓の下には、出力デバイスの様子と、音が途切れた回数が出ます。 - エディタで変えた設定は、ラックと一緒に自動で保存されます。 - Glosa と違うアーキテクチャのプラグインも使えます(Windows の x64 版では 32 ビットのプラグインなど)。 - 設定の **オーディオ出力** で、出力デバイス・サンプリングレート・バッファの長さを選べます。 diff --git a/README.md b/README.md index 8f7c33b5..c1f01e34 100644 --- a/README.md +++ b/README.md @@ -95,13 +95,22 @@ Which map is used is chosen in **Settings → Port Map**. "Auto" picks one for e **Settings → Audio Plugins...** sets up the rack of instrument plugins to use. -- Instruments in the standard CLAP, VST3 and VST2 folders are listed on the right. +- **Add Instrument...** lists the instruments in the standard CLAP, VST3 and VST2 folders. A double click or **Add** puts one in the rack. One kept anywhere else is added with **From File...**. -- The MIDI ports of the plugins in the rack can be chosen in Port Map Settings just like other MIDI devices. +- The MIDI ports of the instruments in the rack can be chosen in Port Map Settings just like other MIDI devices. The list marks them as plugins. -- Right-clicking a plugin offers to open its editor, rename it, reload it and remove it. - Port maps follow a renamed plugin. +- **Editor** or a double click opens a plugin's editor. + **⋯** or a right click offers to open its editor, rename it, add an effect, reload it and remove it. + Port maps follow a renamed instrument. +- **Add Effect...** under an instrument puts an effect on its sound. + The effects under **Master** act on the mix of every instrument. + Effects act in order from the top, and dragging reorders them. + Unchecking an effect lets the sound through it unprocessed. + Only effects built for the same architecture as their instrument (under Master, as Glosa) can be used. +- Each instrument shows whether MIDI is arriving, a level meter and its CPU load. + The mark beside a meter lights when the sound goes past full scale, and a click clears it. + The bottom of the window shows what the output device is doing and how many times the sound broke up. - What is changed in an editor is saved with the rack. - Plugins built for another architecture than Glosa's work too (32-bit plugins in the x64 build on Windows, for example). - **Audio Output** in the settings chooses the output device, the sample rate and the buffer length. diff --git a/src/Glosa.App/Glosa.App.csproj b/src/Glosa.App/Glosa.App.csproj index 99474725..4b9ad5b9 100644 --- a/src/Glosa.App/Glosa.App.csproj +++ b/src/Glosa.App/Glosa.App.csproj @@ -28,9 +28,10 @@ - + + + + + + + + + + + + + + + + + + + + + + + - + + + + @@ -38,144 +204,195 @@ + + +