Skip to content

Commit 766add8

Browse files
committed
add new feature for adding audio directories
1 parent cc68001 commit 766add8

31 files changed

+905
-176
lines changed

XIVEVENT/App.xaml

Lines changed: 72 additions & 45 deletions
Large diffs are not rendered by default.

XIVEVENT/AppContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void LoadEvents() {
9191
}
9292

9393
private void SetupAudio() {
94-
// load sound cache
94+
AppViewModel.Instance.RefreshAudioCacheDirectories();
9595
AppViewModel.Instance.RefreshAudioCache();
9696
AppViewModel.Instance.RefreshAudioDevices();
9797
}

XIVEVENT/Audio/CachedAudioFile.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
// --------------------------------------------------------------------------------------------------------------------
1010

1111
namespace XIVEVENT.Audio {
12+
using System;
1213
using System.Collections.Generic;
1314
using System.Linq;
1415

1516
using NAudio.Wave;
1617

17-
public class CachedAudioFile {
18+
public class CachedAudioFile : IDisposable {
1819
public CachedAudioFile(string audioFileName) {
1920
using AudioFileReader audioFileReader = new AudioFileReader(audioFileName);
2021
this.WaveFormat = audioFileReader.WaveFormat;
@@ -50,8 +51,18 @@ public CachedAudioFile(string audioFileName) {
5051
}
5152
}
5253

53-
public float[] AudioData { get; }
54+
public float[] AudioData { get; private set; }
5455

5556
public WaveFormat WaveFormat { get; }
57+
58+
public void Dispose() {
59+
this.AudioData = null;
60+
// this is needed or refreshing audio files won't recover the data fast enough and it will be a growing memory size
61+
GC.Collect();
62+
}
63+
64+
~CachedAudioFile() {
65+
this.Dispose();
66+
}
5667
}
5768
}

XIVEVENT/Audio/DisposableSound.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ public void DisposeDirectSound(object sender, StoppedEventArgs e) {
5454
this.Dispose();
5555
}
5656
}
57-
}
57+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<UserControl
2+
x:Class="XIVEVENT.Controls.AudioDirectories"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:XIVEVENT.Controls"
7+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:viewModels="clr-namespace:XIVEVENT.ViewModels"
10+
d:DesignHeight="450"
11+
d:DesignWidth="800"
12+
mc:Ignorable="d">
13+
14+
<Grid>
15+
<Grid.RowDefinitions>
16+
<RowDefinition Height="*" />
17+
<RowDefinition Height="Auto" />
18+
</Grid.RowDefinitions>
19+
<DataGrid
20+
x:Name="AudioDirectoriesDataGrid"
21+
Grid.Row="0"
22+
AutoGenerateColumns="False"
23+
CanUserAddRows="False"
24+
CanUserDeleteRows="False"
25+
CanUserReorderColumns="False"
26+
CanUserResizeRows="False"
27+
IsReadOnly="True"
28+
ItemsSource="{Binding Source={x:Static viewModels:AppViewModel.Instance}, Path=AudioCacheDirectories, Mode=TwoWay}"
29+
SelectionMode="Single"
30+
SelectionUnit="FullRow">
31+
<DataGrid.Columns>
32+
<DataGridTemplateColumn>
33+
<DataGridTemplateColumn.CellTemplate>
34+
<DataTemplate>
35+
<Button
36+
Width="20"
37+
Height="20"
38+
Padding="0"
39+
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=DataContext.DeleteDirectoryCommand}"
40+
CommandParameter="{Binding}"
41+
ToolTip="{Binding Locale[SoundSettings_DeleteDirectoryText], Source={StaticResource AppViewModel}}">
42+
<materialDesign:PackIcon Kind="DeleteEmpty" />
43+
</Button>
44+
</DataTemplate>
45+
</DataGridTemplateColumn.CellTemplate>
46+
</DataGridTemplateColumn>
47+
48+
<DataGridTemplateColumn>
49+
<DataGridTemplateColumn.CellTemplate>
50+
<DataTemplate>
51+
<Button
52+
Width="20"
53+
Height="20"
54+
Padding="0"
55+
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=DataContext.EditDirectoryCommand}"
56+
CommandParameter="{Binding}"
57+
ToolTip="{Binding Locale[SoundSettings_EditDirectoryText], Source={StaticResource AppViewModel}}">
58+
<materialDesign:PackIcon Kind="Settings" />
59+
</Button>
60+
</DataTemplate>
61+
</DataGridTemplateColumn.CellTemplate>
62+
</DataGridTemplateColumn>
63+
64+
<DataGridTextColumn
65+
Binding="{Binding Current}"
66+
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
67+
Header="{Binding Locale[SoundSettings_DirectoryText], Source={StaticResource AppViewModel}}" />
68+
</DataGrid.Columns>
69+
</DataGrid>
70+
<StackPanel
71+
Grid.Row="1"
72+
Orientation="Horizontal">
73+
<Button
74+
Margin="0,2,5,2"
75+
Padding="8,0"
76+
Command="{Binding AddDirectoryCommand}"
77+
Style="{StaticResource MaterialDesignRaisedAccentButton}"
78+
ToolTip="{Binding Locale[SoundSettings_AddDirectoryText], Source={StaticResource AppViewModel}}">
79+
<materialDesign:PackIcon Kind="AddCircle" />
80+
</Button>
81+
<TextBlock
82+
Margin="0,10"
83+
Foreground="{DynamicResource MaterialDesignBody}"
84+
Text="{Binding Locale[SoundSettings_DirectoriesText], Source={StaticResource AppViewModel}}"
85+
TextWrapping="Wrap" />
86+
87+
</StackPanel>
88+
</Grid>
89+
</UserControl>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="AudioDirectories.xaml.cs">
3+
// Copyright© 2021 Ryan Wilson
4+
// Licensed under the MIT license. See LICENSE.md in the solution root for full license information.
5+
// </copyright>
6+
// <summary>
7+
// AudioDirectories.xaml.cs Implementation
8+
// </summary>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
11+
namespace XIVEVENT.Controls {
12+
using System.Windows.Controls;
13+
14+
using XIVEVENT.ViewModels;
15+
16+
/// <summary>
17+
/// Interaction logic for AudioDirectories.xaml
18+
/// </summary>
19+
public partial class AudioDirectories : UserControl {
20+
public AudioDirectories() {
21+
this.InitializeComponent();
22+
23+
this.DataContext = AudioDirectoriesViewModel.Instance;
24+
}
25+
}
26+
}

XIVEVENT/Controls/AudioFiles.xaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<UserControl
2+
x:Class="XIVEVENT.Controls.AudioFiles"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:XIVEVENT.Controls"
7+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:viewModels="clr-namespace:XIVEVENT.ViewModels"
10+
d:DesignHeight="450"
11+
d:DesignWidth="800"
12+
mc:Ignorable="d">
13+
14+
<Grid>
15+
<Grid.RowDefinitions>
16+
<RowDefinition Height="Auto" />
17+
<RowDefinition Height="*" />
18+
<RowDefinition Height="Auto" />
19+
</Grid.RowDefinitions>
20+
<ProgressBar
21+
Grid.Row="0"
22+
Margin="0,2"
23+
IsIndeterminate="True"
24+
Visibility="{Binding IsAudioFilesLoading, Converter={StaticResource BooleanToVisibilityConverter}, Source={StaticResource AppViewModel}}" />
25+
<DataGrid
26+
x:Name="SoundFilesDataGrid"
27+
Grid.Row="1"
28+
CanUserAddRows="False"
29+
CanUserDeleteRows="False"
30+
CanUserReorderColumns="False"
31+
CanUserResizeRows="False"
32+
IsReadOnly="True"
33+
ItemsSource="{Binding Source={x:Static viewModels:AppViewModel.Instance}, Path=AudioFiles, Mode=OneWay}"
34+
SelectionMode="Single"
35+
SelectionUnit="FullRow" />
36+
<StackPanel
37+
Grid.Row="2"
38+
Orientation="Horizontal">
39+
<Button
40+
Margin="0,2,5,2"
41+
Padding="8,0"
42+
Command="{Binding RefreshAudioFilesCommand}"
43+
Style="{StaticResource MaterialDesignRaisedAccentButton}"
44+
ToolTip="{Binding Locale[SoundSettings_RereshFilesText], Source={StaticResource AppViewModel}}">
45+
<materialDesign:PackIcon Kind="Refresh" />
46+
</Button>
47+
<TextBlock
48+
Grid.Column="1"
49+
Margin="0,10"
50+
Foreground="{DynamicResource MaterialDesignBody}"
51+
Text="{Binding Locale[SoundSettings_FilesText], Source={StaticResource AppViewModel}}"
52+
TextWrapping="Wrap" />
53+
</StackPanel>
54+
</Grid>
55+
</UserControl>

XIVEVENT/Controls/AudioFiles.xaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="AudioFiles.xaml.cs">
3+
// Copyright© 2021 Ryan Wilson
4+
// Licensed under the MIT license. See LICENSE.md in the solution root for full license information.
5+
// </copyright>
6+
// <summary>
7+
// AudioFiles.xaml.cs Implementation
8+
// </summary>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
11+
namespace XIVEVENT.Controls {
12+
using System.Windows.Controls;
13+
14+
using XIVEVENT.ViewModels;
15+
16+
/// <summary>
17+
/// Interaction logic for AudioFiles.xaml
18+
/// </summary>
19+
public partial class AudioFiles : UserControl {
20+
public AudioFiles() {
21+
this.InitializeComponent();
22+
23+
this.DataContext = AudioFilesViewModel.Instance;
24+
}
25+
}
26+
}

XIVEVENT/Controls/ChatCodes.xaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
<DataGrid
3232
x:Name="ChatCodesDataGrid"
3333
Grid.Row="0"
34-
Margin="0,2"
35-
Padding="2"
3634
CanUserAddRows="False"
3735
CanUserDeleteRows="False"
3836
CanUserReorderColumns="False"
@@ -45,10 +43,14 @@
4543
Margin="0,2"
4644
Command="{Binding SaveChatCodesCommand}"
4745
Style="{StaticResource MaterialDesignRaisedAccentButton}">
48-
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
49-
<materialDesign:PackIcon Margin="0,0,5,0" Kind="ZipDisk" />
46+
<StackPanel
47+
VerticalAlignment="Center"
48+
Orientation="Horizontal">
49+
<materialDesign:PackIcon
50+
Margin="0,0,5,0"
51+
Kind="ZipDisk" />
5052
<TextBlock Text="{Binding Locale[ChatCodes_SaveChangesText], Source={StaticResource AppViewModel}}" />
5153
</StackPanel>
5254
</Button>
5355
</Grid>
54-
</UserControl>
56+
</UserControl>

XIVEVENT/Controls/DirectoryEdit.xaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<UserControl
2+
x:Class="XIVEVENT.Controls.DirectoryEdit"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:properties="clr-namespace:XIVEVENT.Properties"
8+
xmlns:system="clr-namespace:System;assembly=mscorlib"
9+
xmlns:viewModels="clr-namespace:XIVEVENT.ViewModels"
10+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
11+
Width="320"
12+
d:DesignHeight="300"
13+
d:DesignWidth="300"
14+
mc:Ignorable="d">
15+
16+
<Grid Margin="16">
17+
<Grid.RowDefinitions>
18+
<RowDefinition />
19+
<RowDefinition />
20+
</Grid.RowDefinitions>
21+
<StackPanel Grid.Row="0">
22+
<TextBox
23+
wpf:HintAssist.HelperText="{Binding Locale[SoundSettings_DirectoryText], Source={StaticResource AppViewModel}}"
24+
Style="{DynamicResource MaterialDesignFloatingHintTextBox}"
25+
Text="{Binding Current}" />
26+
</StackPanel>
27+
<StackPanel
28+
Grid.Row="1"
29+
Margin="0,16,0,0"
30+
HorizontalAlignment="Center"
31+
Orientation="Horizontal">
32+
<Button
33+
Command="{x:Static wpf:DialogHost.CloseDialogCommand}"
34+
Style="{DynamicResource MaterialDesignFlatButton}">
35+
<Button.CommandParameter>
36+
<system:Boolean>False</system:Boolean>
37+
</Button.CommandParameter>
38+
CANCEL
39+
</Button>
40+
<Button
41+
Command="{x:Static wpf:DialogHost.CloseDialogCommand}"
42+
IsDefault="True"
43+
Style="{DynamicResource MaterialDesignFlatButton}">
44+
<Button.CommandParameter>
45+
<system:Boolean>True</system:Boolean>
46+
</Button.CommandParameter>
47+
OK
48+
</Button>
49+
</StackPanel>
50+
</Grid>
51+
</UserControl>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="DirectoryEdit.xaml.cs">
3+
// Copyright© 2021 Ryan Wilson
4+
// Licensed under the MIT license. See LICENSE.md in the solution root for full license information.
5+
// </copyright>
6+
// <summary>
7+
// DirectoryEdit.xaml.cs Implementation
8+
// </summary>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
11+
namespace XIVEVENT.Controls {
12+
using System.Windows.Controls;
13+
14+
/// <summary>
15+
/// Interaction logic for DirectoryEdit.xaml
16+
/// </summary>
17+
public partial class DirectoryEdit : UserControl {
18+
public DirectoryEdit() {
19+
this.InitializeComponent();
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)