Skip to content

Commit

Permalink
Filter set step renaming and merging
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Jul 16, 2024
1 parent d65d505 commit 6471536
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 84 deletions.
35 changes: 5 additions & 30 deletions Cavern.QuickEQ.Format/ConfigurationFile/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,6 @@ public void ClearSplitPoint(int index) {
}
}

/// <summary>
/// Clears all filters in one of the <see cref="SplitPoints"/> by <paramref name="name"/>.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">The <paramref name="name"/> was not found
/// among the <see cref="SplitPoints"/></exception>
public void ClearSplitPoint(string name) => ClearSplitPoint(GetSplitPointIndexByName(name));

/// <summary>
/// Remove any splits, leave only one continuous graph of filters.
/// </summary>
Expand All @@ -170,6 +163,11 @@ public void MergeSplitPoints() {
splitPoints.RemoveRange(1, SplitPoints.Count - 1);
}

/// <summary>
/// Change the <paramref name="name"/> of an existing split point at a given <paramref name="index"/>.
/// </summary>
public void RenameSplitPoint(int index, string name) => splitPoints[index] = (name, splitPoints[index].roots);

/// <summary>
/// Get the index of a given <paramref name="channel"/> in the configuration. This is the input and output it's wired to.
/// </summary>
Expand Down Expand Up @@ -227,15 +225,6 @@ public void RemoveSplitPoint(int index) {
splitPoints.RemoveAt(index);
}

/// <summary>
/// Removes one of the <see cref="SplitPoints"/> by <paramref name="name"/> and clears all the filters it contains.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">The <paramref name="name"/> was not found
/// among the <see cref="SplitPoints"/></exception>
/// <exception cref="IndexOutOfRangeException">The last split point can't be removed. To bypass this restriction,
/// you could add an empty split point and remove the previous last one.</exception>
public void RemoveSplitPoint(string name) => RemoveSplitPoint(GetSplitPointIndexByName(name));

/// <summary>
/// Adds an entry to the <see cref="SplitPoints"/> with the current state of the configuration, creating new
/// <see cref="InputChannel"/>s after each existing <see cref="OutputChannel"/>.
Expand Down Expand Up @@ -341,19 +330,5 @@ static bool Optimize(FilterGraphNode node) {
}
}
}

/// <summary>
/// Get the index in the <see cref="SplitPoints"/> list by a split point's <paramref name="name"/>.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">The <paramref name="name"/> was not found
/// among the <see cref="SplitPoints"/></exception>
int GetSplitPointIndexByName(string name) {
for (int i = 0, c = SplitPoints.Count; i < c; i++) {
if (SplitPoints[i].name == name) {
return i;
}
}
throw new ArgumentOutOfRangeException(nameof(name));
}
}
}
13 changes: 11 additions & 2 deletions CavernSamples/FilterStudio/Consts/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ public static ResourceDictionary GetConvolutionLengthDialogStrings() =>
/// <summary>
/// Get the <see cref="CrossoverDialog"/>'s translation.
/// </summary>
public static ResourceDictionary GetCrossoverDialogStrings() =>
crossoverDialogCache ??= GetFor("CrossoverDialogStrings");
public static ResourceDictionary GetCrossoverDialogStrings() => crossoverDialogCache ??= GetFor("CrossoverDialogStrings");

/// <summary>
/// Get the <see cref="RenameDialog"/>'s translation.
/// </summary>
public static ResourceDictionary GetRenameDialogStrings() => renameDialogCache ??= GetFor("RenameDialogStrings");

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

/// <summary>
/// The loaded translation of the <see cref="RenameDialog"/> for reuse.
/// </summary>
static ResourceDictionary renameDialogCache;
}
}
12 changes: 12 additions & 0 deletions CavernSamples/FilterStudio/FilterStudio.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<Compile Update="Windows\PipelineSteps\CrossoverSetup.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\RenameDialog.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="..\VoidX.WPF\NumericUpDown.xaml">
Expand All @@ -42,6 +45,12 @@
<Page Update="Resources\MainWindowStrings.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Resources\RenameDialogStrings.hu-HU.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Resources\RenameDialogStrings.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\ConvolutionLengthDialog.xaml">
<SubType>Designer</SubType>
</Page>
Expand All @@ -51,5 +60,8 @@
<Page Update="Windows\PipelineSteps\CrossoverSetup.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\RenameDialog.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion CavernSamples/FilterStudio/MainWindow.Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void SetDirection(LayerDirection direction) {
/// <summary>
/// When the user lost the graph because it was moved outside the screen, this function redisplays it in the center of the frame.
/// </summary>
void Recenter(object _, RoutedEventArgs e) => pipeline.Source = pipeline.Source;
void Reload(object _, RoutedEventArgs e) => pipeline.Source = pipeline.Source;

/// <summary>
/// Converts all filters to convolutions and merges them downwards if they only have a single child.
Expand Down
73 changes: 42 additions & 31 deletions CavernSamples/FilterStudio/MainWindow.Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
using System.Windows;

using Cavern;
using Cavern.Filters;
using Cavern.Format.ConfigurationFile.Presets;
using Cavern.QuickEQ.Crossover;
using VoidX.WPF;

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

namespace FilterStudio {
Expand Down Expand Up @@ -39,46 +40,55 @@ void AddCrossover(object sender, RoutedEventArgs e) => PipelineAddition(sender,
});

/// <summary>
/// Clear the currently selected pipeline step (remove all its filters).
/// Merge all pipeline steps to one.
/// </summary>
void ClearStep(object sender, RoutedEventArgs e) {
StyledNode node = pipeline.GetSelectedNode(sender);
if (node == null) {
Error((string)language["NPNod"]);
return;
}

if (int.TryParse(node.Id, out int uid)) {
pipeline.Source.ClearSplitPoint(uid);
} else {
Error((string)language["NPiSi"]);
return;
}
ReloadGraph(); // Force a reload of the filter graph
void MergeSteps(object _, RoutedEventArgs e) {
pipeline.Source.MergeSplitPoints();
Reload(null, null);
}

/// <summary>
/// Delete the currently selected step from the pipeline.
/// Rename the currently selected pipeline step through a popup.
/// </summary>
void DeleteStep(object sender, RoutedEventArgs e) {
StyledNode node = pipeline.GetSelectedNode(sender);
if (node == null) {
Error((string)language["NPNod"]);
return;
void RenameStep(object sender, RoutedEventArgs e) => PipelineAction(sender, uid => {
RenameDialog rename = new RenameDialog(pipeline.Source.SplitPoints[uid].name);
if (rename.ShowDialog().Value) {
pipeline.Source.RenameSplitPoint(uid, rename.NewName);
}
});

/// <summary>
/// Clear the currently selected pipeline step (remove all its filters).
/// </summary>
void ClearStep(object sender, RoutedEventArgs e) => PipelineAction(sender, pipeline.Source.ClearSplitPoint);

/// <summary>
/// Delete the currently selected step from the pipeline.
/// </summary>
void DeleteStep(object sender, RoutedEventArgs e) => PipelineAction(sender, uid => {
try {
pipeline.Source.RemoveSplitPoint(node.LabelText);
} catch (ArgumentOutOfRangeException) {
Error((string)language["NPiSi"]);
return;
pipeline.Source.RemoveSplitPoint(uid);
} catch (IndexOutOfRangeException) {
Error((string)language["NLaSP"]);
return;
}
});

pipeline.Source = pipeline.Source; // Force a reload of the pipeline graph
ReloadGraph(); // Force a reload of the filter graph
/// <summary>
/// Perform an action on a pipeline step, then reload both the pipeline and the graph.
/// </summary>
/// <param name="sender">Either the selection from the graph or the menu item initializing the operation</param>
/// <param name="action">What should happen with the pipeline step by its uid</param>
void PipelineAction(object sender, Action<int> action) {
StyledNode node = pipeline.GetSelectedNode(sender);
if (node == null) {
Error((string)language["NPNod"]);
} else if (int.TryParse(node.Id, out int uid)) {
action(uid);
Reload(null, null);
pipeline.SelectNode(uid.ToString()); // Reselect the previously selected node if it's still present
} else {
Error((string)language["NPiSi"]);
}
}

/// <summary>
Expand All @@ -103,8 +113,8 @@ void PipelineAddition(object sender, Func<int, bool> addBeforeUid) {
}

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
Reload(null, null);
pipeline.SelectNode(uid.ToString()); // Select the new step
}
}

Expand All @@ -120,6 +130,7 @@ void PipelineRightClick(object element) {
((string)language["OpAdP"], (_, e) => AddStep(element, e)),
((string)language["OpAdC"], (_, e) => AddCrossover(element, e)),
(null, null), // Separator for deletion
((string)language["CoRen"], (_, e) => RenameStep(element, e)),
((string)language["CoCle"], (_, e) => ClearStep(element, e)),
((string)language["CoDel"], (_, e) => DeleteStep(element, e))
];
Expand Down
5 changes: 4 additions & 1 deletion CavernSamples/FilterStudio/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<MenuItem Header="{StaticResource OpAdP}" Click="AddStep"/>
<MenuItem Header="{StaticResource OpAdC}" Click="AddCrossover"/>
<Separator/>
<MenuItem Header="{StaticResource OpMer}" Click="MergeSteps"/>
<Separator/>
<MenuItem Header="{StaticResource OpRen}" Click="RenameStep"/>
<MenuItem Header="{StaticResource OpCle}" Click="ClearStep"/>
<MenuItem Header="{StaticResource OpDeP}" Click="DeleteStep"/>
</MenuItem>
Expand All @@ -54,7 +57,7 @@
<MenuItem Name="dirBT" Header="{StaticResource SOpBT}" IsCheckable="True" Click="SetDirectionBT"/>
<MenuItem Name="dirRL" Header="{StaticResource SOpRL}" IsCheckable="True" Click="SetDirectionRL"/>
</MenuItem>
<MenuItem Header="{StaticResource OpRec}" Click="Recenter"/>
<MenuItem Header="{StaticResource OpRec}" Click="Reload"/>
<Separator/>
<MenuItem Header="{StaticResource OpCon}" Click="ConvertToConvolution"/>
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
<system:String x:Key="SOpBT">_Lentről fel</system:String>
<system:String x:Key="SOpRL">_Jobbról balra</system:String>
<system:String x:Key="OpRec">_Középre mozgatás</system:String>
<system:String x:Key="OpCon">K_onvertálás konvolúcióvá... (egyesítés, visszavonhatatlan)</system:String>
<system:String x:Key="OpCon">K_onvertálás konvolúcióvá... (szűrőegyesítés, visszavonhatatlan)</system:String>

<system:String x:Key="MPipe">Szű_rőszettek</system:String>
<system:String x:Key="OpAdP">Ü_res szett hozzáadása a kiválasztott szett elé</system:String>
<system:String x:Key="OpAdC">K_eresztváltó hozzáadása a kiválasztott szett elé...</system:String>
<system:String x:Key="LabXO">Keresztváltó</system:String>
<system:String x:Key="OpMer">_Összes szett egyesítése (visszavonhatatlan)</system:String>
<system:String x:Key="OpCle">Kiválasztott szett _kiürítése</system:String>
<system:String x:Key="CoCle">_Kiürítés</system:String>
<system:String x:Key="OpRen">Kiválasztott szett _átnevezése</system:String>
<system:String x:Key="CoRen">_Átnevezés</system:String>
<system:String x:Key="OpDeP">Kiválasztott szett _törlése</system:String>

<system:String x:Key="MHelp">Sú_gó</system:String>
Expand Down
5 changes: 4 additions & 1 deletion CavernSamples/FilterStudio/Resources/MainWindowStrings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
<system:String x:Key="SOpBT">_Bottom to top</system:String>
<system:String x:Key="SOpRL">_Right to left</system:String>
<system:String x:Key="OpRec">_Recenter</system:String>
<system:String x:Key="OpCon">_Convert to convolution... (merging, irreversible)</system:String>
<system:String x:Key="OpCon">_Convert to convolution... (filter merging, irreversible)</system:String>

<system:String x:Key="MPipe">Filter _sets</system:String>
<system:String x:Key="OpAdP">_Add empty set before the selected set</system:String>
<system:String x:Key="OpAdC">Add c_rossover before the selected set...</system:String>
<system:String x:Key="LabXO">Crossover</system:String>
<system:String x:Key="OpMer">_Merge all sets (irreversible)</system:String>
<system:String x:Key="OpCle">_Clear selected set</system:String>
<system:String x:Key="CoCle">_Clear</system:String>
<system:String x:Key="OpRen">_Rename selected set</system:String>
<system:String x:Key="CoRen">_Rename</system:String>
<system:String x:Key="OpDeP">_Delete selected set</system:String>

<system:String x:Key="MHelp">_Help</system:String>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="TRena">Átnevezés</system:String>
<system:String x:Key="DNewN">{0} új neve:</system:String>
</ResourceDictionary>
6 changes: 6 additions & 0 deletions CavernSamples/FilterStudio/Resources/RenameDialogStrings.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="TRena">Rename</system:String>
<system:String x:Key="DNewN">New name of {0}:</system:String>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Window x:Class="FilterStudio.Windows.ConvolutionLengthDialog"
<base:OkCancelDialog x:Class="FilterStudio.Windows.ConvolutionLengthDialog"
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;assembly=Cavern.WPF"
xmlns:voidx="clr-namespace:VoidX.WPF"
mc:Ignorable="d"
Title="{StaticResource TConv}" Width="400" Height="110" Background="#696969">
Expand All @@ -24,4 +25,4 @@
<Button Margin="0,0,10,10" Width="80" Height="20" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Content="{StaticResource BtnCa}" Click="Cancel"/>
</Grid>
</Window>
</base:OkCancelDialog>
18 changes: 3 additions & 15 deletions CavernSamples/FilterStudio/Windows/ConvolutionLengthDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Windows;

using Cavern.WPF.BaseClasses;

namespace FilterStudio.Windows {
/// <summary>
/// Shows a filter length selector when converting a filter graph to convolution filters.
/// </summary>
public partial class ConvolutionLengthDialog : Window {
public partial class ConvolutionLengthDialog : OkCancelDialog {
/// <summary>
/// The user-selected number of convolution samples per filter.
/// </summary>
Expand All @@ -22,18 +23,5 @@ public ConvolutionLengthDialog() {
Resources.MergedDictionaries.Add(Cavern.WPF.Consts.Language.GetCommonStrings());
InitializeComponent();
}

/// <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();
}
}
Loading

0 comments on commit 6471536

Please sign in to comment.