Skip to content

Commit

Permalink
Name mapped matrixed channels
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Jan 8, 2025
1 parent 20ba934 commit 1c6ebcd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
5 changes: 5 additions & 0 deletions Cavern/Channels/ChannelPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public static ChannelPrototype[] GetAlternative(ReferenceChannel[] source) {
return result;
}

/// <summary>
/// Convert a <see cref="ReferenceChannel"/> to the name of the channels.
/// </summary>
public static string GetName(ReferenceChannel source) => Mapping[(int)source].Name;

/// <summary>
/// Convert a mapping of <see cref="ReferenceChannel"/>s to the names of the channels.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion CavernSamples/CavernizeGUI/Elements/DownmixedRenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ public override ReferenceChannel[] WiredChannels {
}
}

ReferenceChannel[] mapped = GetNameMappedChannels(Channels);
(ReferenceChannel, ReferenceChannel, ReferenceChannel)[] result =
new (ReferenceChannel, ReferenceChannel, ReferenceChannel)[count];
count = 0;
for (int i = 0; i < merge.Length; i++) {
if (merge[i].source < 0) {
result[count++] = (Channels[~merge[i].source], Channels[merge[i - 1].target], Channels[merge[i].target]);
result[count++] = (mapped[~merge[i].source], mapped[merge[i - 1].target], mapped[merge[i].target]);
}
}
return result;
Expand Down
48 changes: 27 additions & 21 deletions CavernSamples/CavernizeGUI/Elements/RenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@ public class RenderTarget(string name, ReferenceChannel[] channels) {
/// </summary>
public int OutputChannels { get; protected set; } = channels.Length;

/// <summary>
/// Top rear channels are used as &quot;side&quot; channels as no true rears are available in some standard mappings or in WAVEFORMATEX channel masks.
/// These have to be mapped back to sides in some cases, for example, for the wiring popup.
/// </summary>
protected static ReferenceChannel[] GetNameMappedChannels(ReferenceChannel[] source) {
ReferenceChannel[] result = source.FastClone();
bool side = false, rear = false;
for (int i = 0; i < result.Length; i++) {
side |= result[i] == ReferenceChannel.TopSideLeft;
rear |= result[i] == ReferenceChannel.TopRearLeft;
}
if (side && rear) {
return result;
}

for (int i = 0; i < result.Length; i++) {
if (result[i] == ReferenceChannel.TopRearLeft) {
result[i] = ReferenceChannel.TopSideLeft;
}
if (result[i] == ReferenceChannel.TopRearRight) {
result[i] = ReferenceChannel.TopSideRight;
}
}
return result;
}

/// <summary>
/// Apply this render target on the system's output.
/// </summary>
Expand All @@ -56,27 +82,7 @@ public virtual void Apply() {
/// Top rear channels are used as &quot;side&quot; channels as no true rears are available in standard mappings.
/// These have to be mapped back to sides in some cases, for example, for the wiring popup.
/// </summary>
public ReferenceChannel[] GetNameMappedChannels() {
ReferenceChannel[] result = WiredChannels.FastClone();
bool side = false, rear = false;
for (int i = 0; i < result.Length; i++) {
side |= result[i] == ReferenceChannel.TopSideLeft;
rear |= result[i] == ReferenceChannel.TopRearLeft;
}
if (side && rear) {
return result;
}

for (int i = 0; i < result.Length; i++) {
if (result[i] == ReferenceChannel.TopRearLeft) {
result[i] = ReferenceChannel.TopSideLeft;
}
if (result[i] == ReferenceChannel.TopRearRight) {
result[i] = ReferenceChannel.TopSideRight;
}
}
return result;
}
public ReferenceChannel[] GetNameMappedChannels() => GetNameMappedChannels(WiredChannels);

/// <summary>
/// Gets if a channel is actually present in the final file or just used for downmixing in <see cref="DownmixedRenderTarget"/>.
Expand Down
3 changes: 2 additions & 1 deletion CavernSamples/CavernizeGUI/MainWindow.Popups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ void DisplayWiring(object _, RoutedEventArgs e) {
(ReferenceChannel source, ReferenceChannel posPhase, ReferenceChannel negPhase)[] matrixed = downmix.MatrixWirings;
for (int i = 0; i < matrixed.Length; i++) {
output.AppendLine(string.Format((string)language["ChCMx"],
matrixed[i].source, matrixed[i].posPhase, matrixed[i].negPhase));
ChannelPrototype.GetName(matrixed[i].source), ChannelPrototype.GetName(matrixed[i].posPhase),
ChannelPrototype.GetName(matrixed[i].negPhase)));
}
}
MessageBox.Show(output.ToString(), (string)language["WrGui"]);
Expand Down

0 comments on commit 1c6ebcd

Please sign in to comment.