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
22 changes: 21 additions & 1 deletion IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ drift : 1.1 us over the run (0.06 us per second)
実機の MIDI ケーブルでは、ベンドやエクスプレッションを細かく書いた曲ほどシークが速くなる。

**追いつきは、設定に関係なく MIDI ケーブルの速さ(3125 バイト/秒)以下で送る。** 追いつきは目標までを一度に渡すので、ケーブルより速いと間にあるバッファが溢れる。Linux の ALSA は、ハードウェアの出力バッファが溢れると送り手に知らせずに捨て、受け側アプリのキューが溢れるとキューごと捨てる。
環境設定の転送レート上限は、SysEx だけでなくすべてのメッセージに、ポートごとに効く(ポートはそれぞれ別のケーブル)。シークの始めの音切り、停止時のオールサウンドオフ、追いつきで溜めた値もこれに従う。
転送レート上限はポートマップごとに持ち、曲を流すマップのものが効く(`PortMap.TransferRate`)。取りこぼす古い音源と、上限の要らないオーディオプラグインやソフトウェア音源とは、別のマップでつなぐため。上限は SysEx だけでなくすべてのメッセージに、ポートごとに効く(ポートはそれぞれ別のケーブル)。シークの始めの音切り、停止時のオールサウンドオフ、追いつきで溜めた値もこれに従う。
同じ時刻のイベントは順番どおりに送るので、先のイベントが上限で待てば、別のポートの後のイベントも待つ。

**シークの始めには、設定に関係なくオールサウンドオフとオールノートオフを送る。** リセットオールコントローラは送らない。前へのシークは、それまでに曲が設定したものを送り直さないため。一時停止も同じ理由で、送るのはオールサウンドオフとオールノートオフだけにする(設定で止めていなければ)。
Expand All @@ -66,6 +66,8 @@ F7 で分けた SysEx の前半と後半の間に来たシークは、SysEx が
WinMM は SysEx をドライバが後から送るので、送り終わるまで待ってから音切りを送る(`IEventSink.WaitUntilSent`)。
停止時も、開いたままの SysEx は F7 で閉じてからオールサウンドオフなどを送る。打ち切った SysEx の後半は、先頭のデータバイトを落として送る。

**止めるときは、押さえている鍵盤を先に離す。** 停止・一時停止・シークでオールサウンドオフなどを送る前に、まだ押さえている鍵盤にノートオフを送る(`Sequencer.ReleaseKeys`)。押さえている数は、送ったノートオンとノートオフからポート・チャンネル・鍵盤ごとに数える。SOUND Canvas VA は、モノモードのパートで鳴っているノートをオールサウンドオフとオールノートオフで止めると、そのパートがおかしくなり、後に来るノートが別の音で鳴る。GS リセットでも直らず、次の曲に残る。ノートオフで離してから止めると起きない。

ひとつだけ即応でない場面がある。チャンネルメッセージが延々と続く区間は内側のループが一気に送り切るまで依頼を見ない。ミリ秒の単位で、途中で止めるとその区間だけ中途半端に送った状態になるので、あえて区切っていない。

## 曲送りとプレイリスト
Expand Down Expand Up @@ -386,6 +388,24 @@ SC-55 で作られた曲には、存在しない音色を指定していても
- 何を送ったかではなく機械が何を持っているかを追うので、**曲をまたいでも状態を持ち越す**。
切り替えは出力音源と同じく次の曲から効く。

## パートの分割

**17 パート以上の音源に宛てた曲を、各ポートの 16 パートの音源へ割り振る**(ポートマップ設定の「パートを16ずつ別のポートへ振り分ける」。マップごとで、既定は切)。
SC-88・SC-88Pro の曲は、ポート A からエクスクルーシブ `50 xx xx` で B 群のパートを設定し、CHANNEL MSG RX PORT(`00 01 1x`)で B 群のパートにポート A のチャンネルを受けさせる。XG の曲は `08 pp xx` のパート番号 16 以降でポート B 以降のパートを指す。各ポートに 16 パートの音源を 1 台ずつつないだ機材では、どれもそのままでは届かない。

- **マップの設定にした。** ポートが 1 台の SC-88Pro の 2 つの入力か、別々の 2 台かは、つないだ人にしか分からない(リセットを送るポートと同じ)。SC-88Pro の実機なら `50 xx xx` を自分で受けるので、分けてはいけない。
- **切っているときはチェーンに入れない。** 入れたまま素通しにはしない。分割の状態を追うコードが、切っている人の演奏に一切関わらないようにするため。
- 置く場所はエミュレーション層とその初期化の後、代理発音(CTF)の前(`PartSplitter`)。初期化が `50 4x 00` などで B 群に送るものも、分けた先の音源に届く。代理発音はポートごとのパートを追うので、分けた後のものを見る。液晶と演奏モニタはエミュレーション層のものを見るので、表示は分けない。
- **チャンネルメッセージは、各パートがどのポートのどのチャンネルを受けるかの表で送り先を決める。** RX CHANNEL や RX PORT のエクスクルーシブを音源へ転送するやり方では再現できない。B7 がポート A の ch6 を受ける曲なら、B の音源の ch6 には、ポート A の ch6 を写したものだけを届け、ポート B の ch6 は届けてはいけないが、音源には届いたメッセージがどのポートから来たかを見分ける手段が無い。そこで RX CHANNEL・RX PORT は表に書き取って音源へは送らず、受けるパートが見つかったチャンネルメッセージを、そのパートを受け持つポートの、そのパート本来のチャンネルへ送る。表が初期値のままなら素通しと同じになる。
- **GS は SC-88Pro の取扱説明書(「Individual Parameter Transmission」のアドレスの表)に従う。**
- `5x xx xx` は受けたのと反対側のパート群なので、相方のポート(A と B、C と D、E と F)へ `4x xx xx` にして送る。
- PATCH COMMON(`40 00 xx`〜`40 0F xx`。マスター・GS Reset・エフェクト)は、MODE-1(シングルモジュールモード)なら 32 パート共通なので相方にも送る。MODE-2 ならそのポートだけ。どちらのモードかは System Mode Set(`00 00 7F`)で追い、来るまでは初期値の MODE-1 とする。
- MODE-1 では、`50 00 xx`〜`50 0F xx`(相方の群の PATCH COMMON)は落とす。アドレスの表でこのブロックは「MODE-1 では使えない」灰色になっている(SC-88Pro の取扱説明書 193 ページ「Address Block map」)。
- System Mode Set は 16 パートの音源には意味が無い(SC-55 は無視する)ので、両方のポートへの GS Reset に置き換える。
- GS Reset は RX CHANNEL を戻すが RX PORT は戻さない。RX PORT はシステムパラメータで、System Mode Set でだけ戻る。
- **XG はパート番号でポートを決める。** MU では、パート番号がどのポートから来たかによらずパートを指す。パート 16〜31 はポート B、32〜47 は C。パートに属さないもの(XG System On、エフェクト、ドラムセットアップ)は機械全体のものなので、ポート A〜D のすべてへ送る。インサーションエフェクトとバリエーションを掛けるパートは、そのパートのポートへだけ番号を直して送り、ほかのポートには OFF を送る。
- 状態は曲ごとに作り直し、曲の途中から前へ戻したときも初期値に戻す。分けた先の音源は SC-88 の電源を入れ直したのと同じ状態から曲を始める。

## ドロップ再生

曲やフォルダをウィンドウへ落とすとプレイリストに入り、**落とした先頭の曲から演奏が始まる**(`AutoDropPlay`。既定で有効、環境設定で切れる)。リストの先頭ではなく落とした先頭から始めるのが要点で、ドロップは「これを聴かせろ」という指示だから。
Expand Down
1 change: 1 addition & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ TMIDI Player の定義ファイルを読み込むと、TMIDI Player と同じ**
- **出力音源**には、そのポートの先につないでいる音源の機種を選びます。
エミュレーションと、曲の前に送るリセットに使われます。
- **リセット**に印を付けたポートへは、曲の前に出力音源のリセット(GS Reset、XG System On など)を送ります。
- **パートを16ずつ別のポートへ振り分ける**は、各ポートに16パートの音源を1台ずつつないでいるときに入れます。SC-88・SC-88Pro の32パートや XG の17番目以降のパートに宛てたメッセージを、そのパートを受け持つポートの音源へ送ります。SC-88・SC-88Pro の実機を2つのポートにつないでいるときは切っておきます。
- **ポートマップ**は複数作れます。機材ごとに作っておくと便利です。
- いちばん上のマップは既定のマップです。消すことはできず、どのマップにも当てはまらない曲はこのマップで鳴ります。
- マップに**対象音源**を登録しておくと、その音源向けの曲はそのマップで鳴ります。
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ In **Settings → Port Map Settings...**, assign MIDI devices to ports A to F.
- For **Module**, choose the model of the module connected at the other end of that port (the output module).
It is used for emulation and for the reset sent before each song.
- Ports with **Reset** checked are sent the output module's reset (GS Reset, XG System On and so on) before each song.
- Turn on **Distribute parts over other ports, 16 each** when each port leads to its own 16-part module.
Messages for the 32 parts of an SC-88 or SC-88Pro, or for XG parts 17 and up, are then sent to the module on the port that plays that part.
Leave it off when the ports lead to the two inputs of a real SC-88 or SC-88Pro.
- Several **port maps** can be made. Making one for each set of equipment is handy.
- The top map is the default map. It cannot be deleted, and songs no other map fits are played with it.
- Add **Target Modules** to a map, and songs for those modules are played with that map.
Expand Down
19 changes: 13 additions & 6 deletions src/Glosa.App/Services/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public sealed class PortMap
/// </summary>
/// <remarks>THRU, no emulation, is what a map with nothing said about it plays as.</remarks>
public string UseModule { get; set; } = "THRU";

/// <summary>
/// Whether each port leads to a 16-part machine of its own, so a song's parts beyond 16
/// are laid out over the ports (<see cref="PartSplitter"/>).
/// </summary>
/// <remarks>Off for a 32-part machine on two ports, which takes them as they are.</remarks>
public bool SplitParts { get; set; }

/// <summary>
/// The most bytes a second handed to each of this map's ports, for hardware that cannot
/// keep up. 0 is unlimited.
/// </summary>
public int TransferRate { get; set; }
}

/// <summary>One of the words a song is detected from, and whether it is searched.</summary>
Expand Down Expand Up @@ -209,12 +222,6 @@ public sealed class AppSettings
/// <summary>The priority of the thread that sends the song.</summary>
public PlaybackPriority Priority { get; set; } = PlaybackPriority.High;

/// <summary>
/// The most bytes a second handed to each port, for hardware that cannot keep up. 0 is
/// unlimited.
/// </summary>
public int TransferRate { get; set; }

/// <summary>Whether stopping also resets the output devices, besides All Notes Off.</summary>
public bool UseMidiOutReset { get; set; } = true;

Expand Down
52 changes: 37 additions & 15 deletions src/Glosa.App/Services/PlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ public readonly record struct ToneMapChoice(ToneMap Maps, byte Map, IReadOnlyLis
/// </summary>
/// <remarks>
/// The chain is the one the console harness builds:
/// <c>Sequencer → EmulationFilter → CapitalToneFallback → PortSink → IMidiOutput</c>. The
/// filter is always in it, even with no DEF loaded, because the panel state the display reads
/// lives there. The fallback is always in it too, and does nothing until it is given a
/// machine's tables (<see cref="UseFallback"/>).
/// <c>Sequencer → EmulationFilter → [PartSplitter] → CapitalToneFallback → PortSink → IMidiOutput</c>.
/// The filter is always in it, even with no DEF loaded, because the panel state the display
/// reads lives there. The fallback is always in it too, and does nothing until it is given a
/// machine's tables (<see cref="UseFallback"/>). The splitter is in it only for a port map
/// that asks for it (<see cref="UseSplit"/>).
/// </remarks>
public sealed class PlayerService : IDisposable
{
Expand All @@ -43,19 +44,23 @@ public sealed class PlayerService : IDisposable
private readonly Lock _devices = new();
private readonly PortSink _ports;

/// <summary>The ports, behind the Capital Tone Fallback. Kept from song to song.</summary>
private readonly CapitalToneFallback _fallback;

/// <summary>
/// What reaches the machines: the ports, behind the Capital Tone Fallback. The emulation
/// layer sends here, and so does the initialisation. Kept from song to song.
/// What reaches the machines: <see cref="_fallback"/>, or a <see cref="PartSplitter"/> in
/// front of it. The emulation layer sends here, and so does the initialisation.
/// </summary>
private readonly CapitalToneFallback _fallback;
private volatile IEventSink _machines;
private EmulationFilter _filter;
private DefDocument? _definition;

public PlayerService()
{
_ports = new PortSink(_outputs);
_fallback = new CapitalToneFallback(_ports);
_filter = new EmulationFilter(_fallback, new EmulationSettings(), new PatchMapSet());
_machines = _fallback;
_filter = new EmulationFilter(_machines, new EmulationSettings(), new PatchMapSet());
Options = new PlaybackOptions();
Sequencer = new Sequencer(_filter, Options, Backends.Timer);
// Recomposer data has its endless loops played out as it is read, so the setting
Expand All @@ -77,7 +82,12 @@ public PlayerService()
/// thread allowed to send while a song is going. An output that refuses is treated as
/// any other send that fails there.
/// </remarks>
private void SendInitAgain() => MidiScript.Run(_init, _fallback);
private void SendInitAgain()
{
IEventSink machines = _machines;
if (machines is PartSplitter splitter) splitter.Reset();
MidiScript.Run(_init, machines);
}

public PlaybackOptions Options { get; }

Expand Down Expand Up @@ -281,10 +291,21 @@ public void UseInit(IReadOnlyList<ScriptAction> actions, ToneMapChoice? map = nu

EmulationSettings settings =
map is { } choice ? choice.Maps.Settings(choice.Map) ?? new() : new();
UseFilter(new EmulationFilter(_fallback, settings, new PatchMapSet()));
UseFilter(new EmulationFilter(_machines, settings, new PatchMapSet()));
EmulationLabel = "(no definition)";
}

/// <summary>
/// Puts a part splitter in front of the machines, a new one for the song being set up, or
/// takes it out. Before the emulation layer is built (<see cref="UseInit"/>,
/// <see cref="ApplyEmulation"/>), which sends to it.
/// </summary>
public void UseSplit(bool split)
{
Sequencer.Stop();
_machines = split ? new PartSplitter(_fallback) : _fallback;
}

/// <summary>
/// Has the Capital Tone Fallback judge program changes by a machine's tables, or stop
/// when <paramref name="tones"/> is null. Takes effect with the song being set up.
Expand Down Expand Up @@ -393,9 +414,10 @@ private void RestoreMapsOnTheWayOut()
/// and is done on the transport's thread as the song is set up.
///
/// Past the emulation layer: the initialisation is its own output and must not be run
/// back through it. Through the Capital Tone Fallback, which has to see the resets and
/// the map the parts are put on as the machine does. A refusal is returned rather than
/// thrown: the emulation is in place either way, and the caller decides what to tell.
/// back through it. Through the part splitter and the Capital Tone Fallback, which have to
/// see the resets and the map the parts are put on as the machine does. A refusal is
/// returned rather than thrown: the emulation is in place either way, and the caller
/// decides what to tell.
/// </remarks>
public string? SendInit()
{
Expand All @@ -406,7 +428,7 @@ private void RestoreMapsOnTheWayOut()
ToneMapChoice? map = _map;
RestoreMaps(map is { Maps.Lasting: true } chosen ? DevicesOn(chosen.Ports) : []);

MidiScript.Run(_init, _fallback);
MidiScript.Run(_init, _machines);
RememberMaps(map);
return null;
}
Expand All @@ -427,7 +449,7 @@ public void ApplyEmulation(string useModule, string targetModule)
EmulationSetup setup = new EmulationBuilder(_definition)
.Build(useModule, targetModule, filterSection: "NONE");

UseFilter(new EmulationFilter(_fallback, setup.Settings, setup.Patches));
UseFilter(new EmulationFilter(_machines, setup.Settings, setup.Patches));

EmulationLabel = $"[{setup.Resolution.Key}] {setup.Resolution.Commands}";
_init = setup.InitActions;
Expand Down
Loading
Loading