Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
defined. Whether it runs on this system is found at run time.
-->
<PropertyGroup>
<BrackVersion>1.2.0</BrackVersion>
<BrackVersion>2.0.0</BrackVersion>
<BrackProject>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)../brack/bindings/dotnet/Brack/Brack.csproj'))</BrackProject>
<BrackSource Condition="'$(UseBrackPackage)' != 'true' and Exists('$(BrackProject)')">Project</BrackSource>
<BrackSource Condition="'$(BrackSource)' == '' and '$(BrackVersion)' != ''">Package</BrackSource>
Expand Down
5 changes: 3 additions & 2 deletions IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ RCP を変換する `RCPCV.DLL` は Windows 専用なので、変換は自前で

プレイリストのどこまで聴いたか・どこを見ていたかは、開いているタブのぶんだけ設定の `openPlaylists` に覚える。開いていないリストの位置は覚えないので、閉じたタブを開き直すと先頭から始まる。

ウィンドウの位置と大きさ、演奏モニタとデバッグを開いていたかどうかも覚える(`Placement`)。
ウィンドウの位置と大きさ、どの窓を開いていたかも覚え、次の起動で開き直す(`Placement`)。

**設定は既定値も含めてすべて書く。** 書かなかった値は読むときの既定値になるので、既定値を変えると、前の既定値をわざと選んでいた人の設定まで変わってしまう。プレイリストは曲ごとの項目が多いので、既定値と同じ値を書かない(`OmitUnspecifiedVisitor`)。

Expand Down Expand Up @@ -609,7 +609,8 @@ MIDI はそのノートポートへ、受け取ったバイト列のまま渡す
- **音声デバイスは、出力が開いているかエディタが出ている間だけ動かし、最後に閉じてから 3 秒後に止める。** 出力は再生が止まるたびに閉じる([出力を開く・閉じる](#出力を開く閉じる))。動かし続けると、開いたままの音声ストリームが Windows のスリープを妨げる。すぐに止めると、最後の音の余韻が切れる。
- **バッファ(音声デバイスの周期)は時間で選び、新しいラックでは 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`)。
- **マスターボリュームとそのミュートはプラグインの音だけにかかり、Brack のマスターゲインとミュートとしてセッションに持つ**(`settings.yaml` には書かない)。MIDI ポートの先の機械の音量は Glosa から変えられないので、効く出力が無いときに出さないよう、どれかのポートマップにプラグインのポートが 1 つでもあるときだけ曲名の右に出す(`MainViewModel.UsesAudioPlugins`)。
- **音源ごとのボリュームとミュートも、Brack の音源のゲインとミュートとしてセッションに持ち、変えるときに Brack を待たない**(`BrackRack.SetGain`・`SetMute`)。ほかのラックの変更と違ってセッションの保存と状態の読み直しをせず、手元のラックの中身だけを書き換える。スライダーを動かし続ける間に、プラグインの読み込みで Brack が忙しくても窓が固まらないためで、保存は Brack が知らせる変更のたびに後からする。
- **エフェクトは、音源ごとの連なりと、すべての音源をミックスした音にかけるマスターの連なりに置く**(`BrackRack.AddEffect`、Brack の `brack_add_effect`)。エフェクトは出力デバイスにならない。Brack は連なりを 1 つのプロセスで動かすので、エフェクトは音源と同じアーキテクチャのもの(マスターではプレイヤーと同じもの)しか読み込めない。そのため、追加する一覧には連なりのアーキテクチャのエフェクトだけを出す(`AudioPluginsViewModel.EffectPicker`)。
- **ラックの窓の音源のメーターは、エフェクトがかかるメインの出力ポートのチャンネルだけを出す**(`BrackRack.Meters`)。出力の多い音源ですべてのポートを出すと、カードが縦に伸びるため。
- **送れなかったとき(プラグインがクラッシュした、ラックから外された、キューがあふれた)は出力の異常として曲を止める。** 黙って落とすと、ノートオフが届かず鳴り続けることがある。
Expand Down
6 changes: 5 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,19 @@ TMIDI Player の定義ファイルを読み込むと、TMIDI Player と同じ**
エフェクトは上から順にかかり、ドラッグで並べ替えられます。
チェックを外すと、そのエフェクトを通さずに鳴らします。
使えるのは、かける音源と同じアーキテクチャのもの(マスターでは Glosa と同じもの)だけです。
- 音源ごとのスライダーで、その音源の音量を変えられます(ダブルクリックでリセット)。
スライダーの左のスピーカーをクリックするとミュートできます。
- 音源ごとに、MIDI が届いているか、音量のメーター、CPU の負荷が出ます。
メーターの右の印は、音がフルスケールを超えると点き、クリックで消えます。
メーターの右の印は、音がフルスケールを超えると点きます。どれかのメーターをクリックすると、すべての印が消えます。
窓の下には、出力デバイスの様子と、音が途切れた回数が出ます。
- エディタで変えた設定は、ラックと一緒に自動で保存されます。
- Glosa と違うアーキテクチャのプラグインも使えます(Windows の x64 版では 32 ビットのプラグインなど)。
- 設定の **オーディオ出力** で、出力デバイス・サンプリングレート・バッファの長さを選べます。
複数同時に読み込むとエラーになるプラグインがあるときは、**プラグインを1つずつ読み込む** を入れます。
- どれかのポートマップでプラグインを使っていると、シークバーの上にマスターボリュームが出ます。
プラグインの音だけに効きます。
左のスピーカーをクリックするとミュートできます。
- 音量のスライダーは、Shift を押しながらドラッグすると、ふだんの 1/10 の細かさで動きます。

### 曲を追加して演奏する

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,19 @@ Which map is used is chosen in **Settings → Port Map**. "Auto" picks one for e
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's slider sets its volume (a double click resets it).
Clicking the speaker left of the slider mutes it.
- 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 mark beside a meter lights when the sound goes past full scale, and a click on any meter clears them all.
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.
When a plugin fails because several load at once, turn on **Load plugins one at a time**.
- While any port map uses a plugin, a master volume shows above the seek bar.
It acts on the plugins' sound only.
Clicking the speaker left of it mutes it.
- Dragging a volume slider with Shift held moves it a tenth as far, to set it finely.

### Adding and playing songs

Expand Down
72 changes: 72 additions & 0 deletions src/Glosa.App/Controls/DragTip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Threading;

namespace Glosa.App.Controls;

/// <summary>
/// Keeps a control's tooltip open while it is dragged, so that a slider shows what it is set to
/// as it moves.
/// </summary>
/// <remarks>
/// The tooltip service closes a tip on a press, and when the pointer strays off its control; it
/// sees the input after the control does, so the tip is opened again once the input is handled.
/// </remarks>
public static class DragTip
{
public static readonly AttachedProperty<bool> ShowProperty =
AvaloniaProperty.RegisterAttached<Control, bool>("Show", typeof(DragTip));

private static readonly AttachedProperty<bool> DraggingProperty =
AvaloniaProperty.RegisterAttached<Control, bool>("Dragging", typeof(DragTip));

static DragTip()
{
ShowProperty.Changed.AddClassHandler<Control>((control, e) =>
{
if (e.NewValue is not true) return;
control.AddHandler(InputElement.PointerPressedEvent, OnPressed, RoutingStrategies.Tunnel, handledEventsToo: true);
control.AddHandler(InputElement.PointerMovedEvent, OnMoved, RoutingStrategies.Tunnel, handledEventsToo: true);
control.AddHandler(InputElement.PointerReleasedEvent, OnReleased, RoutingStrategies.Tunnel, handledEventsToo: true);
});
}

public static bool GetShow(Control control) => control.GetValue(ShowProperty);

public static void SetShow(Control control, bool value) => control.SetValue(ShowProperty, value);

private static void OnPressed(object? sender, PointerPressedEventArgs e)
{
if (sender is not Control control || !e.GetCurrentPoint(control).Properties.IsLeftButtonPressed) return;
control.SetValue(DraggingProperty, true);
Open(control);
}

private static void OnMoved(object? sender, PointerEventArgs e)
{
if (sender is not Control control || !control.GetValue(DraggingProperty)) return;
// The button came up where the release was not delivered.
if (!e.GetCurrentPoint(control).Properties.IsLeftButtonPressed) End(control);
else Open(control);
}

private static void OnReleased(object? sender, PointerReleasedEventArgs e)
{
if (sender is Control control) End(control);
}

private static void Open(Control control)
=> Dispatcher.UIThread.Post(() =>
{
if (control.GetValue(DraggingProperty)) ToolTip.SetIsOpen(control, true);
});

private static void End(Control control)
{
if (!control.GetValue(DraggingProperty)) return;
control.SetValue(DraggingProperty, false);
ToolTip.SetIsOpen(control, false);
}
}
103 changes: 103 additions & 0 deletions src/Glosa.App/Controls/FineDrag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.VisualTree;

namespace Glosa.App.Controls;

/// <summary>
/// Lets a slider be dragged a tenth as far while Shift is held, to set it finely.
/// </summary>
/// <remarks>
/// A slider puts its value under the pointer. With Shift held, the value moves by the pointer's
/// travel instead, from where it is, so that Shift pressed or let go never makes it jump. The
/// move is taken at the window, before the slider would put the value under the pointer.
/// </remarks>
public static class FineDrag
{
/// <summary>How much of the pointer's travel moves the value while Shift is held.</summary>
public const double Fine = 0.1;

public static readonly AttachedProperty<bool> EnabledProperty =
AvaloniaProperty.RegisterAttached<Slider, bool>("Enabled", typeof(FineDrag));

private static readonly AttachedProperty<Drag?> DragProperty =
AvaloniaProperty.RegisterAttached<Slider, Drag?>("Drag", typeof(FineDrag));

/// <summary>A drag under way: once moved by travel, where the pointer and the value were last anchored.</summary>
private sealed class Drag
{
public bool ByTravel;
public bool Fine;
public double X;
public double Value;
}

static FineDrag()
{
EnabledProperty.Changed.AddClassHandler<Slider>((slider, e) =>
{
if (e.NewValue is not true) return;
slider.AddHandler(InputElement.PointerPressedEvent, OnPressed, RoutingStrategies.Tunnel, handledEventsToo: true);
slider.AddHandler(InputElement.PointerReleasedEvent, OnReleased, RoutingStrategies.Tunnel, handledEventsToo: true);
EventHandler<PointerEventArgs> moved = (_, args) => OnMoved(slider, args);
slider.AttachedToVisualTree += (_, args) =>
(args.RootVisual as InputElement)?.AddHandler(InputElement.PointerMovedEvent, moved, RoutingStrategies.Tunnel);
slider.DetachedFromVisualTree += (_, args) =>
(args.RootVisual as InputElement)?.RemoveHandler(InputElement.PointerMovedEvent, moved);
});
}

public static bool GetEnabled(Slider slider) => slider.GetValue(EnabledProperty);

public static void SetEnabled(Slider slider, bool value) => slider.SetValue(EnabledProperty, value);

private static void OnPressed(object? sender, PointerPressedEventArgs e)
{
if (sender is Slider slider && e.GetCurrentPoint(slider).Properties.IsLeftButtonPressed)
slider.SetValue(DragProperty, new Drag());
}

private static void OnMoved(Slider slider, PointerEventArgs e)
{
if (slider.GetValue(DragProperty) is not { } drag) return;
if (!e.GetCurrentPoint(slider).Properties.IsLeftButtonPressed)
{
slider.ClearValue(DragProperty);
return;
}

bool fine = e.KeyModifiers.HasFlag(KeyModifiers.Shift);
if (!drag.ByTravel && !fine) return;
if (slider.FindDescendantOfType<Track>() is not { } track) return;
double length = track.Bounds.Width - (track.Thumb?.Bounds.Width ?? 0);
if (length <= 0) return;

double x = e.GetPosition(track).X;
if (!drag.ByTravel || fine != drag.Fine)
{
drag.ByTravel = true;
drag.Fine = fine;
drag.X = x;
drag.Value = slider.Value;
}
double perPixel = (slider.Maximum - slider.Minimum) / length * (fine ? Fine : 1);
double value = drag.Value + (x - drag.X) * perPixel;
double clamped = Math.Clamp(value, slider.Minimum, slider.Maximum);
// Past an end, the travel back starts from it.
if (clamped != value)
{
drag.X = x;
drag.Value = clamped;
}
slider.SetCurrentValue(RangeBase.ValueProperty, clamped);
e.Handled = true;
}

private static void OnReleased(object? sender, PointerReleasedEventArgs e)
{
if (sender is Slider slider) slider.ClearValue(DragProperty);
}
}
9 changes: 3 additions & 6 deletions src/Glosa.App/Services/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ public sealed class WindowPlacement
public bool Maximized { get; set; }

/// <summary>
/// Whether the window was open when the player was last closed.
/// Whether the window was open when the player was last closed, to open it again. The main
/// window opens either way.
/// </summary>
/// <remarks>
/// Only the panes are opened again from this. The main window opens either way, and the
/// two settings windows are answers to a question that was asked last time, not this one.
/// </remarks>
public bool Open { get; set; }
}

Expand Down Expand Up @@ -299,7 +296,7 @@ public sealed class AppSettings

/// <summary>
/// Where each window was, by name: <c>main</c>, <c>settings</c>, <c>portMaps</c>,
/// <c>monitor</c>, <c>debug</c>.
/// <c>audioPlugins</c>, <c>monitor</c>, <c>debug</c>.
/// </summary>
/// <remarks>
/// A map rather than a field per window, since every window wants the same numbers.
Expand Down
Loading
Loading