From 98d4516560a3870271259a75ae7503a7af57bc70 Mon Sep 17 00:00:00 2001 From: hsshss <5428297+hsshss@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:37:39 +0900 Subject: [PATCH 1/3] Split a multi-part module's parts over 16-part machines, one per port A port map can now say that each of its ports leads to a 16-part module of its own. Songs for an SC-88 or SC-88Pro address the second part group with 50 xx xx and let its parts listen to port A (CHANNEL MSG RX PORT); XG songs address parts 17 and up by part number. With the option on, PartSplitter lays these out over the ports: channel messages are routed by a table of the port and channel each part receives, 5x addresses go to the partner port as 4x, MODE-1 patch common goes to both ports of the pair, and XG part numbers pick the port. Off by default, and then the splitter is not in the chain at all. The CLI's play command takes --split for the same, and counts what it sends by port. --- IMPLEMENTATION.md | 18 ++ README.ja.md | 1 + README.md | 3 + src/Glosa.App/Services/AppSettings.cs | 7 + src/Glosa.App/Services/PlayerService.cs | 52 ++- src/Glosa.App/Strings.Designer.cs | 18 ++ src/Glosa.App/Strings.ja.resx | 6 + src/Glosa.App/Strings.resx | 6 + src/Glosa.App/ViewModels/MainViewModel.cs | 1 + src/Glosa.App/ViewModels/PortMapViewModel.cs | 9 + src/Glosa.App/Views/PortMapWindow.axaml | 113 ++++--- src/Glosa.Cli/Program.cs | 32 +- src/Glosa.Core/Emulation/PartSplitter.cs | 320 +++++++++++++++++++ tests/Glosa.Tests/AppSettingsTests.cs | 4 +- tests/Glosa.Tests/PartSplitterTests.cs | 267 ++++++++++++++++ tests/Glosa.Tests/PortMapViewModelTests.cs | 13 + 16 files changed, 797 insertions(+), 73 deletions(-) create mode 100644 src/Glosa.Core/Emulation/PartSplitter.cs create mode 100644 tests/Glosa.Tests/PartSplitterTests.cs diff --git a/IMPLEMENTATION.md b/IMPLEMENTATION.md index 8fa5fbae..a7f60715 100644 --- a/IMPLEMENTATION.md +++ b/IMPLEMENTATION.md @@ -386,6 +386,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`。既定で有効、環境設定で切れる)。リストの先頭ではなく落とした先頭から始めるのが要点で、ドロップは「これを聴かせろ」という指示だから。 diff --git a/README.ja.md b/README.ja.md index 0b41eb1e..fc4fe2a7 100644 --- a/README.ja.md +++ b/README.ja.md @@ -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つのポートにつないでいるときは切っておきます。 - **ポートマップ**は複数作れます。機材ごとに作っておくと便利です。 - いちばん上のマップは既定のマップです。消すことはできず、どのマップにも当てはまらない曲はこのマップで鳴ります。 - マップに**対象音源**を登録しておくと、その音源向けの曲はそのマップで鳴ります。 diff --git a/README.md b/README.md index 0d242bb9..b9baa758 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/Glosa.App/Services/AppSettings.cs b/src/Glosa.App/Services/AppSettings.cs index d85b5113..e44dbbf8 100644 --- a/src/Glosa.App/Services/AppSettings.cs +++ b/src/Glosa.App/Services/AppSettings.cs @@ -53,6 +53,13 @@ public sealed class PortMap /// /// THRU, no emulation, is what a map with nothing said about it plays as. public string UseModule { get; set; } = "THRU"; + + /// + /// 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 (). + /// + /// Off for a 32-part machine on two ports, which takes them as they are. + public bool SplitParts { get; set; } } /// One of the words a song is detected from, and whether it is searched. diff --git a/src/Glosa.App/Services/PlayerService.cs b/src/Glosa.App/Services/PlayerService.cs index f44d9fae..f7f740c0 100644 --- a/src/Glosa.App/Services/PlayerService.cs +++ b/src/Glosa.App/Services/PlayerService.cs @@ -18,10 +18,11 @@ public readonly record struct ToneMapChoice(ToneMap Maps, byte Map, IReadOnlyLis /// /// /// The chain is the one the console harness builds: -/// Sequencer → EmulationFilter → CapitalToneFallback → PortSink → IMidiOutput. 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 (). +/// Sequencer → EmulationFilter → [PartSplitter] → CapitalToneFallback → PortSink → IMidiOutput. +/// 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 (). The splitter is in it only for a port map +/// that asks for it (). /// public sealed class PlayerService : IDisposable { @@ -43,11 +44,14 @@ public sealed class PlayerService : IDisposable private readonly Lock _devices = new(); private readonly PortSink _ports; + /// The ports, behind the Capital Tone Fallback. Kept from song to song. + private readonly CapitalToneFallback _fallback; + /// - /// 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: , or a in + /// front of it. The emulation layer sends here, and so does the initialisation. /// - private readonly CapitalToneFallback _fallback; + private volatile IEventSink _machines; private EmulationFilter _filter; private DefDocument? _definition; @@ -55,7 +59,8 @@ 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 @@ -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. /// - 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; } @@ -281,10 +291,21 @@ public void UseInit(IReadOnlyList 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)"; } + /// + /// 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 (, + /// ), which sends to it. + /// + public void UseSplit(bool split) + { + Sequencer.Stop(); + _machines = split ? new PartSplitter(_fallback) : _fallback; + } + /// /// Has the Capital Tone Fallback judge program changes by a machine's tables, or stop /// when is null. Takes effect with the song being set 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. /// public string? SendInit() { @@ -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; } @@ -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; diff --git a/src/Glosa.App/Strings.Designer.cs b/src/Glosa.App/Strings.Designer.cs index 97eff873..53d5ed0a 100644 --- a/src/Glosa.App/Strings.Designer.cs +++ b/src/Glosa.App/Strings.Designer.cs @@ -1881,6 +1881,24 @@ public static string PortMapResetOf { } } + /// + /// Looks up a localized string similar to Distribute parts over other ports, 16 each. + /// + public static string PortMapSplitParts { + get { + return ResourceManager.GetString("PortMapSplitParts", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Turn this on when each port of this map leads to a 16-part sound module of its own. Messages for the 32 parts of an SC-88 or SC-88Pro, or for XG parts from the 17th on, are sent to the module on the port that takes that part. Leave it off when a real SC-88 or SC-88Pro is connected to two ports.. + /// + public static string PortMapSplitPartsTip { + get { + return ResourceManager.GetString("PortMapSplitPartsTip", resourceCulture); + } + } + /// /// Looks up a localized string similar to Target Modules. /// diff --git a/src/Glosa.App/Strings.ja.resx b/src/Glosa.App/Strings.ja.resx index fa4d864d..972eb48d 100644 --- a/src/Glosa.App/Strings.ja.resx +++ b/src/Glosa.App/Strings.ja.resx @@ -663,6 +663,12 @@ define.override.yaml を修正するか削除して Glosa を起動し直して このマップのポートに接続されている音源を指定してください。 + + パートを16ずつ別のポートへ振り分ける + + + このマップの各ポートに16パートの音源を1台ずつつないでいるときにチェックを入れてください。SC-88・SC-88Pro の32パートや XG の17番目以降のパートに宛てたメッセージを、そのパートを受け持つポートの音源へ送ります。SC-88・SC-88Pro の実機を2つのポートにつないでいるときは外してください。 + ポート {0} diff --git a/src/Glosa.App/Strings.resx b/src/Glosa.App/Strings.resx index 312d85bd..fb5e48db 100644 --- a/src/Glosa.App/Strings.resx +++ b/src/Glosa.App/Strings.resx @@ -666,6 +666,12 @@ Fix or delete define.override.yaml, and restart Glosa. Choose the sound module connected to this map’s ports. + + Distribute parts over other ports, 16 each + + + Turn this on when each port of this map leads to a 16-part sound module of its own. Messages for the 32 parts of an SC-88 or SC-88Pro, or for XG parts from the 17th on, are sent to the module on the port that takes that part. Leave it off when a real SC-88 or SC-88Pro is connected to two ports. + Port {0} diff --git a/src/Glosa.App/ViewModels/MainViewModel.cs b/src/Glosa.App/ViewModels/MainViewModel.cs index c5a98645..0806305f 100644 --- a/src/Glosa.App/ViewModels/MainViewModel.cs +++ b/src/Glosa.App/ViewModels/MainViewModel.cs @@ -1972,6 +1972,7 @@ public void ApplyEmulation(string? target = null, bool twoPorts = false) SoundCanvasTones? tones = CapitalToneFallback ? SoundCanvasTones.Of(UseModule) : null; _player.UseFallback(tones); if (tones is not null) Note(string.Format(Strings.NoteFallbackTables, tones.Model)); + _player.UseSplit(ActiveMap?.SplitParts ?? false); // With no DEF: the reset define.yaml's initializeType names, and the tone map of the // model the song was written for where the module carries it (ToneMap). diff --git a/src/Glosa.App/ViewModels/PortMapViewModel.cs b/src/Glosa.App/ViewModels/PortMapViewModel.cs index 40aaa201..e0667eb0 100644 --- a/src/Glosa.App/ViewModels/PortMapViewModel.cs +++ b/src/Glosa.App/ViewModels/PortMapViewModel.cs @@ -28,6 +28,7 @@ public PortMapViewModel(PortMap map, IReadOnlyList devices, Model = map; Title = map.Title; UseModule = map.UseModule.Length > 0 ? map.UseModule : null; + SplitParts = map.SplitParts; Modules = [.. map.Modules]; Modules.CollectionChanged += (_, _) => Model.Modules = [.. Modules]; _devices = devices; @@ -64,6 +65,12 @@ public PortMapViewModel(PortMap map, IReadOnlyList devices, [ObservableProperty] public partial string? UseModule { get; set; } + /// + /// Whether a song's parts beyond 16 are laid out over the ports (). + /// + [ObservableProperty] + public partial bool SplitParts { get; set; } + /// The target modules that hand the outputs to this map. public ObservableCollection Modules { get; } @@ -165,6 +172,8 @@ public void Lay(int index, MidiDeviceInfo? device) partial void OnTitleChanged(string value) => Model.Title = value; + partial void OnSplitPartsChanged(bool value) => Model.SplitParts = value; + /// /// An empty answer is dropped rather than stored. A combo box clears its selection when /// its list stops containing the chosen item, as on loading a definition that does not diff --git a/src/Glosa.App/Views/PortMapWindow.axaml b/src/Glosa.App/Views/PortMapWindow.axaml index e02515e9..105d5cbb 100644 --- a/src/Glosa.App/Views/PortMapWindow.axaml +++ b/src/Glosa.App/Views/PortMapWindow.axaml @@ -6,7 +6,7 @@ xmlns:m="using:Glosa.Midi" x:Class="Glosa.App.Views.PortMapWindow" x:DataType="vm:MainViewModel" - Width="630" Height="572" MinWidth="560" MinHeight="420" + Width="630" Height="598" MinWidth="560" MinHeight="420" Title="{x:Static l:Strings.PortMapTitle}"> @@ -111,59 +111,68 @@ - - - - - - - - - - - - - - - - - - - + + + + - -