Skip to content

Commit

Permalink
Crossover pipeline step UI
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Jun 9, 2024
1 parent 5a6868a commit 1ed5542
Show file tree
Hide file tree
Showing 23 changed files with 328 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void AddSplitPoint(int index, string name) {
ReferenceChannel channel = ((InputChannel)end[i].Filter).Channel;
end[i].AddChild(new OutputChannel(channel));
}
return;
}
}

Expand Down
21 changes: 21 additions & 0 deletions CavernSamples/Cavern.WPF/BaseClasses/OkCancelDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Windows;

namespace Cavern.WPF.BaseClasses {
/// <summary>
/// A dialog with OK and Cancel buttons.
/// </summary>
public class OkCancelDialog : Window {
/// <summary>
/// Closes the dialog with the settings applied.
/// </summary>
protected virtual void OK(object _, RoutedEventArgs e) {
DialogResult = true;
Close();
}

/// <summary>
/// Closes the dialog with no change applied.
/// </summary>
protected void Cancel(object _, RoutedEventArgs e) => Close();
}
}
5 changes: 3 additions & 2 deletions CavernSamples/Cavern.WPF/BiquadEditor.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Window
<base:OkCancelDialog
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:base="clr-namespace:Cavern.WPF.BaseClasses"
x:Class="Cavern.WPF.BiquadEditor"
mc:Ignorable="d"
Title="{StaticResource Title}" Width="536" Height="372">
Expand Down Expand Up @@ -34,4 +35,4 @@
<Button Margin="0,0,10,10" Width="80" Height="20" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Content="{StaticResource BtnCa}" Click="Cancel"/>
</Grid>
</Window>
</base:OkCancelDialog>
16 changes: 2 additions & 14 deletions CavernSamples/Cavern.WPF/BiquadEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
using Cavern.QuickEQ.Graphing.Overlays;
using Cavern.QuickEQ.Utilities;
using Cavern.Utilities;
using Cavern.WPF.BaseClasses;

using Color = System.Windows.Media.Color;

namespace Cavern.WPF {
/// <summary>
/// Biquad filter customization/editor window.
/// </summary>
public partial class BiquadEditor : Window {
public partial class BiquadEditor : OkCancelDialog {
/// <summary>
/// The filter created by the user's inputs.
/// </summary>
Expand Down Expand Up @@ -131,18 +132,5 @@ void Draw() {
/// use this check handler to never let it be checked.
/// </summary>
void DisableCheck(object sender, RoutedEventArgs _) => ((CheckBox)sender).IsChecked = false;

/// <summary>
/// Closes the dialog with the filter selected.
/// </summary>
void OK(object _, RoutedEventArgs e) {
DialogResult = true;
Close();
}

/// <summary>
/// Closes the dialog with no filter selected.
/// </summary>
void Cancel(object _, RoutedEventArgs e) => Close();
}
}
5 changes: 3 additions & 2 deletions CavernSamples/Cavern.WPF/ChannelSelector.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Window x:Class="Cavern.WPF.ChannelSelector"
<base:OkCancelDialog x:Class="Cavern.WPF.ChannelSelector"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:base="clr-namespace:Cavern.WPF.BaseClasses"
mc:Ignorable="d"
Title="{StaticResource Title}" Width="570" Height="350">
<Window.Resources>
Expand Down Expand Up @@ -70,4 +71,4 @@
<Button Margin="0,0,10,10" Width="80" Height="20" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Content="{StaticResource BtnCa}" Click="Cancel"/>
</Grid>
</Window>
</base:OkCancelDialog>
16 changes: 2 additions & 14 deletions CavernSamples/Cavern.WPF/ChannelSelector.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using System.Windows.Controls;

using Cavern.Channels;
using Cavern.WPF.BaseClasses;

namespace Cavern.WPF {
/// <summary>
/// Channel layout selector dialog.
/// </summary>
public partial class ChannelSelector : Window {
public partial class ChannelSelector : OkCancelDialog {
/// <summary>
/// Set when OK is clicked, contains the channels selected by the user.
/// </summary>
Expand Down Expand Up @@ -63,18 +64,5 @@ public ChannelSelector() {
[ReferenceChannel.TopRearRight] = topRearRight,
};
}

/// <summary>
/// Closes the dialog with the filter selected.
/// </summary>
void OK(object _, RoutedEventArgs e) {
DialogResult = true;
Close();
}

/// <summary>
/// Closes the dialog with no filter selected.
/// </summary>
void Cancel(object _, RoutedEventArgs e) => Close();
}
}
36 changes: 35 additions & 1 deletion CavernSamples/Cavern.WPF/Consts/Language.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Globalization;
using System.Windows;

using Cavern.Channels;

namespace Cavern.WPF.Consts {
/// <summary>
/// Handle fetching of language strings and translations.
/// </summary>
static class Language {
public static class Language {
/// <summary>
/// Get the shared translation between windows.
/// </summary>
Expand All @@ -21,6 +23,38 @@ static class Language {
/// </summary>
public static ResourceDictionary GetChannelSelectorStrings() => channelSelectorCache ??= GetFor("ChannelSelectorStrings");

/// <summary>
/// Return a channel's name in the user's language or fall back to its short name.
/// </summary>
public static string Translate(this ReferenceChannel channel) {
ResourceDictionary dictionary = GetChannelSelectorStrings();
return channel switch {
ReferenceChannel.FrontLeft => (string)dictionary["SpGFL"],
ReferenceChannel.FrontLeftCenter => (string)dictionary["SpFLC"],
ReferenceChannel.FrontCenter => (string)dictionary["SpGFC"],
ReferenceChannel.FrontRightCenter => (string)dictionary["SpFRC"],
ReferenceChannel.FrontRight => (string)dictionary["SpGFR"],
ReferenceChannel.WideLeft => (string)dictionary["SpGWL"],
ReferenceChannel.WideRight => (string)dictionary["SpGWR"],
ReferenceChannel.SideLeft => (string)dictionary["SpGSL"],
ReferenceChannel.ScreenLFE => (string)dictionary["SpLFE"],
ReferenceChannel.SideRight => (string)dictionary["SpGSR"],
ReferenceChannel.RearLeft => (string)dictionary["SpGRL"],
ReferenceChannel.RearCenter => (string)dictionary["SpGRC"],
ReferenceChannel.RearRight => (string)dictionary["SpGRR"],
ReferenceChannel.TopFrontLeft => (string)dictionary["SpTFL"],
ReferenceChannel.TopFrontCenter => (string)dictionary["SpTFC"],
ReferenceChannel.TopFrontRight => (string)dictionary["SpTFR"],
ReferenceChannel.TopSideLeft => (string)dictionary["SpTSL"],
ReferenceChannel.GodsVoice => (string)dictionary["SpTGV"],
ReferenceChannel.TopSideRight => (string)dictionary["SpTSR"],
ReferenceChannel.TopRearLeft => (string)dictionary["SpTRL"],
ReferenceChannel.TopRearCenter => (string)dictionary["SpTRC"],
ReferenceChannel.TopRearRight => (string)dictionary["SpTRR"],
_ => channel.GetShortName()
};
}

/// <summary>
/// Get the translation of a resource file in the user's language, or in English if a translation couldn't be found.
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions CavernSamples/Cavern.WPF/Utils/ChannelOnUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Cavern.Channels;
using Cavern.WPF.Consts;

namespace Cavern.WPF.Utils {
/// <summary>
/// Used to display a channel's name on a UI in the user's language and contain which <see cref="ReferenceChannel"/> it is.
/// </summary>
public class ChannelOnUI(ReferenceChannel channel) {
/// <summary>
/// The displayed channel.
/// </summary>
public ReferenceChannel Channel = channel;

/// <inheritdoc/>
public override string ToString() => Channel.Translate();
}
}
12 changes: 12 additions & 0 deletions CavernSamples/FilterStudio/Consts/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Windows;

using FilterStudio.Windows;
using FilterStudio.Windows.PipelineSteps;

namespace FilterStudio.Consts {
/// <summary>
Expand All @@ -20,6 +21,12 @@ static class Language {
public static ResourceDictionary GetConvolutionLengthDialogStrings() =>
convolutionLengthDialogCache ??= GetFor("ConvolutionLengthDialogStrings");

/// <summary>
/// Get the <see cref="CrossoverDialog"/>'s translation.
/// </summary>
public static ResourceDictionary GetCrossoverDialogStrings() =>
crossoverDialogCache ??= GetFor("CrossoverDialogStrings");

/// <summary>
/// Get the translation of a resource file in the user's language, or in English if a translation couldn't be found.
/// </summary>
Expand All @@ -46,5 +53,10 @@ static ResourceDictionary GetFor(string resource) {
/// The loaded translation of the <see cref="ConvolutionLengthDialog"/> for reuse.
/// </summary>
static ResourceDictionary convolutionLengthDialogCache;

/// <summary>
/// The loaded translation of the <see cref="CrossoverDialog"/> for reuse.
/// </summary>
static ResourceDictionary crossoverDialogCache;
}
}
18 changes: 18 additions & 0 deletions CavernSamples/FilterStudio/FilterStudio.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<Compile Update="Windows\ConvolutionLengthDialog.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\PipelineSteps\CrossoverDialog.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\PipelineSteps\CrossoverSetup.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="..\VoidX.WPF\NumericUpDown.xaml">
Expand All @@ -27,11 +33,23 @@
<Page Update="Resources\ConvolutionLengthDialogStrings.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Resources\CrossoverDialogStrings.hu-HU.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Resources\CrossoverDialogStrings.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Resources\MainWindowStrings.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\ConvolutionLengthDialog.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\PipelineSteps\CrossoverDialog.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\PipelineSteps\CrossoverSetup.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
60 changes: 43 additions & 17 deletions CavernSamples/FilterStudio/MainWindow.Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,31 @@
using VoidX.WPF;

using FilterStudio.Graphs;
using FilterStudio.Windows.PipelineSteps;

namespace FilterStudio {
// Handlers of the pipeline graph control
partial class MainWindow {
/// <summary>
/// Add a new empty pipeline step after the selected node.
/// </summary>
void AddStep(object sender, RoutedEventArgs e) {
StyledNode node = pipeline.GetSelectedNode(sender);
if (node == null) {
Error((string)language["NPNod"]);
return;
}
void AddStep(object sender, RoutedEventArgs e) => PipelineAddition(sender, (uid) => {
pipeline.Source.AddSplitPoint(uid, (string)language["NSNew"]);
return true;
});

if (!int.TryParse(node.Id, out int uid)) {
if (node.Id == PipelineEditor.inNodeUid) {
Error((string)language["NPNod"]);
return;
} else {
uid = pipeline.Source.SplitPoints.Count;
}
/// <summary>
/// Add a new crossover step after the selected node.
/// </summary>
void AddCrossover(object sender, RoutedEventArgs e) => PipelineAddition(sender, (uid) => {
CrossoverDialog dialog = new(GetChannels());
if (!dialog.ShowDialog().Value) {
return false;
}
pipeline.Source.AddSplitPoint(uid, (string)language["NSNew"]);
pipeline.Source = pipeline.Source; // Force a reload of the pipeline graph
pipeline.SelectNode(uid.ToString()); // Force a reload of the filter graph on the new step
}
// TODO: create the crossover graph, using grouping by frequencies -> make it in Cavern.QuickEQ.Format to be reused
return true;
});

/// <summary>
/// Clear the currently selected pipeline step (remove all its filters).
Expand Down Expand Up @@ -77,6 +75,33 @@ void DeleteStep(object sender, RoutedEventArgs e) {
ReloadGraph(); // Force a reload of the filter graph
}

/// <summary>
/// Add a new step in the pipeline before the currently selected node.
/// </summary>
/// <param name="sender">Either the selected node or a control if not called from a right-click menu</param>
/// <param name="addBeforeUid">Tries to add the step to the pipeline and returns if the addition was successful</param>
void PipelineAddition(object sender, Func<int, bool> addBeforeUid) {
StyledNode node = pipeline.GetSelectedNode(sender);
if (node == null) {
Error((string)language["NPNod"]);
return;
}

if (!int.TryParse(node.Id, out int uid)) {
if (node.Id == PipelineEditor.inNodeUid) {
Error((string)language["NPNod"]);
return;
} else {
uid = pipeline.Source.SplitPoints.Count;
}
}

if (addBeforeUid(uid)) {
pipeline.Source = pipeline.Source; // Force a reload of the pipeline graph
pipeline.SelectNode(uid.ToString()); // Force a reload of the filter graph on the new step
}
}

/// <summary>
/// Handle right-clicking on a pipeline <paramref name="element"/>.
/// </summary>
Expand All @@ -87,6 +112,7 @@ void PipelineRightClick(object element) {

List<(string, Action<object, RoutedEventArgs>)> menuItems = [
((string)language["OpAdP"], (_, e) => AddStep(element, e)),
((string)language["OpAdC"], (_, e) => AddCrossover(element, e)),
(null, null), // Separator for deletion
((string)language["CoCle"], (_, e) => ClearStep(element, e)),
((string)language["CoDel"], (_, e) => DeleteStep(element, e))
Expand Down
1 change: 1 addition & 0 deletions CavernSamples/FilterStudio/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</MenuItem>
<MenuItem Header="{StaticResource MPipe}" Style="{StaticResource RootMenuItem}">
<MenuItem Header="{StaticResource OpAdP}" Click="AddStep"/>
<MenuItem Header="{StaticResource OpAdC}" Click="AddCrossover"/>
<Separator/>
<MenuItem Header="{StaticResource OpCle}" Click="ClearStep"/>
<MenuItem Header="{StaticResource OpDeP}" Click="DeleteStep"/>
Expand Down
Loading

0 comments on commit 1ed5542

Please sign in to comment.