Skip to content

Commit a9fcb66

Browse files
authored
Modernize BardMusicPlayer (#298)
* ImplicitUsing * Make use of more modern latest C# & .net features. * Nullable & Cleanup * Enabled nullable and project clean-up to follow .editorconfig code styling. * Fixed an unlikely siren exception when refreshing lyrics time while editing.
1 parent 06124e9 commit a9fcb66

35 files changed

+811
-878
lines changed

BardMusicPlayer/App.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ protected override void OnStartup(StartupEventArgs e)
2727
// LogManager.Initialize(new(view.Log));
2828

2929
//Load the last used catalog
30-
var CatalogFile = BmpPigeonhole.Instance.LastLoadedCatalog;
31-
if (File.Exists(CatalogFile))
32-
BmpCoffer.Initialize(CatalogFile);
30+
var catalogFile = BmpPigeonhole.Instance.LastLoadedCatalog;
31+
if (File.Exists(catalogFile))
32+
BmpCoffer.Initialize(catalogFile);
3333
else
3434
BmpCoffer.Initialize(Globals.Globals.DataPath + @"\MusicCatalog.db");
3535

BardMusicPlayer/BardMusicPlayer.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
<UseWPF>true</UseWPF>
99
<ApplicationIcon>bmp.ico</ApplicationIcon>
1010
<ApplicationManifest>app.manifest</ApplicationManifest>
11-
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
12-
<PackageProjectUrl>https://bardmusicplayer.com</PackageProjectUrl>
13-
<RepositoryUrl>https://github.com/BardMusicPlayer/BardMusicPlayer</RepositoryUrl>
14-
<RepositoryType>git</RepositoryType>
1511
<Platforms>x64</Platforms>
1612
<PlatformTarget>x64</PlatformTarget>
1713
<Configurations>Debug;Release</Configurations>
14+
<ImplicitUsings>enable</ImplicitUsings>
15+
<Nullable>enable</Nullable>
16+
</PropertyGroup>
1817

18+
<PropertyGroup>
19+
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
20+
<PackageProjectUrl>https://bardmusicplayer.com</PackageProjectUrl>
21+
<RepositoryUrl>https://github.com/BardMusicPlayer/BardMusicPlayer</RepositoryUrl>
22+
<RepositoryType>git</RepositoryType>
1923
<AssemblyTitle>BardMusicPlayer</AssemblyTitle>
2024
<Product>BardMusicPlayer</Product>
2125
<Authors>MoogleTroupe</Authors>

BardMusicPlayer/Controls/BardExtSettingsWindow.xaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,20 @@
5555
<ColumnDefinition />
5656
</Grid.ColumnDefinitions>
5757
<Label Grid.Row="0" Grid.ColumnSpan="3" Content="Post song title:" />
58-
<ComboBox Grid.Row="1" Grid.Column="0" x:Name="Songtitle_Chat_Type" HorizontalAlignment="Left"
58+
<ComboBox Grid.Row="1" Grid.Column="0" x:Name="SongTitleChatType" HorizontalAlignment="Left"
5959
VerticalAlignment="Stretch" Width="80" Padding="5"
6060
SelectionChanged="SongTitle_Post_Type_SelectionChanged">
6161
<ComboBoxItem>Say</ComboBoxItem>
6262
<ComboBoxItem>Yell</ComboBoxItem>
6363
<ComboBoxItem>Party</ComboBoxItem>
6464
</ComboBox>
65-
<TextBox Grid.Row="1" Grid.Column="2" x:Name="Songtitle_Chat_Prefix" Text="" Width="30"
65+
<TextBox Grid.Row="1" Grid.Column="2" x:Name="SongTitleChatPrefix" Text="" Width="30"
6666
Padding="5"
6767
HorizontalAlignment="Left" VerticalAlignment="Stretch" />
6868
<Button Grid.Row="1" Grid.Column="4" Content="Send Title" Click="PostSongTitle_Click" />
6969
<Label Grid.Row="1" Grid.Column="6" Content="AutoPost" HorizontalAlignment="Left"
7070
VerticalAlignment="Top" />
71-
<ComboBox Grid.Row="1" Grid.Column="8" x:Name="Songtitle_Post_Type" Text="AutoPost via"
71+
<ComboBox Grid.Row="1" Grid.Column="8" x:Name="SongTitlePostType" Text="AutoPost via"
7272
HorizontalAlignment="Left" VerticalAlignment="Stretch" MinWidth="45" Padding="5"
7373
SelectionChanged="SongTitle_Post_Type_SelectionChanged">
7474
<ComboBoxItem>Off</ComboBoxItem>
@@ -99,7 +99,7 @@
9999
</Grid.ColumnDefinitions>
100100
<Label Grid.Row="0" Grid.ColumnSpan="3" Content="Post a message in chat:" />
101101
<Label Grid.Row="1" Grid.Column="0" Content="Chat Type:" VerticalAlignment="Center" />
102-
<ComboBox Grid.Row="1" Grid.Column="1" x:Name="Chat_Type" HorizontalAlignment="Left"
102+
<ComboBox Grid.Row="1" Grid.Column="1" x:Name="ChatType" HorizontalAlignment="Left"
103103
VerticalAlignment="Top" Width="120" Padding="5">
104104
<ComboBoxItem>Say</ComboBoxItem>
105105
<ComboBoxItem>Yell</ComboBoxItem>
@@ -120,7 +120,7 @@
120120
<ColumnDefinition Width="Auto" />
121121
</Grid.ColumnDefinitions>
122122
<Label Grid.Column="0" Content="Lyrics Track Number:" />
123-
<controls:NumericUpDown Grid.Column="1" x:Name="Lyrics_TrackNr"
123+
<controls:NumericUpDown Grid.Column="1" x:Name="LyricsTrackNr"
124124
Background="{DynamicResource MaterialDesignBackground}"
125125
Padding="0" VerticalAlignment="Center" HorizontalAlignment="Left"
126126
FontSize="8"
@@ -145,16 +145,16 @@
145145
<RowDefinition Height="*" />
146146
<RowDefinition Height="Auto" />
147147
</Grid.RowDefinitions>
148-
<Grid Grid.Row="0" x:Name="CPUDisplay" />
148+
<Grid Grid.Row="0" x:Name="CpuDisplay" />
149149
<Grid Grid.Row="1">
150150
<Grid.ColumnDefinitions>
151151
<ColumnDefinition Width="50" />
152152
<ColumnDefinition Width="50" />
153153
<ColumnDefinition Width="90" />
154154
</Grid.ColumnDefinitions>
155-
<Button Grid.Column="0" x:Name="Save_CPU" Content="Set" Click="Save_CPU_Click" Padding="0" />
156-
<Button Grid.Column="1" x:Name="Clear_CPU" Content="Clear" Click="Clear_CPU_Click" Padding="0" />
157-
<Button Grid.Column="2" x:Name="Reset_CPU" Content="All Processors" Click="Reset_CPU_Click"
155+
<Button Grid.Column="0" x:Name="SaveCpu" Content="Set" Click="Save_CPU_Click" Padding="0" />
156+
<Button Grid.Column="1" x:Name="ClearCpu" Content="Clear" Click="Clear_CPU_Click" Padding="0" />
157+
<Button Grid.Column="2" x:Name="ResetCpu" Content="All Processors" Click="Reset_CPU_Click"
158158
Padding="0" />
159159
</Grid>
160160
</Grid>
Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Windows;
1+
using System.Windows;
42
using System.Windows.Controls;
53
using System.Windows.Input;
64
using BardMusicPlayer.DalamudBridge;
@@ -15,80 +13,80 @@ namespace BardMusicPlayer.Controls;
1513
/// </summary>
1614
public sealed partial class BardExtSettingsWindow
1715
{
18-
private Performer _performer;
19-
private List<CheckBox> _cpuBoxes = new();
16+
private readonly Performer? _performer;
17+
private readonly List<CheckBox> _cpuBoxes = new();
2018

21-
public BardExtSettingsWindow(Performer performer)
19+
public BardExtSettingsWindow(Performer? performer)
2220
{
2321
_performer = performer;
2422
InitializeComponent();
25-
Title = "Settings for: " + _performer.PlayerName;
23+
Title = "Settings for: " + _performer?.PlayerName;
2624

27-
Songtitle_Post_Type.SelectedIndex = 0;
28-
Songtitle_Chat_Type.SelectedIndex = 0;
29-
Chat_Type.SelectedIndex = 0;
25+
SongTitlePostType.SelectedIndex = 0;
26+
SongTitleChatType.SelectedIndex = 0;
27+
ChatType.SelectedIndex = 0;
3028

3129
//Get the values for the song parsing bard
3230
var tpBard = BmpMaestro.Instance.GetSongTitleParsingBard();
3331
if (tpBard.Value != null)
3432
{
35-
if (tpBard.Value.game.Pid == _performer.game.Pid)
33+
if (_performer != null && tpBard.Value.game.Pid == _performer.game.Pid)
3634
{
37-
Songtitle_Chat_Prefix.Text = tpBard.Key.prefix;
35+
SongTitleChatPrefix.Text = tpBard.Key.prefix;
3836

3937
if (tpBard.Key.channelType.ChannelCode == ChatMessageChannelType.Say.ChannelCode)
40-
Songtitle_Chat_Type.SelectedIndex = 0;
38+
SongTitleChatType.SelectedIndex = 0;
4139
else if (tpBard.Key.channelType.ChannelCode == ChatMessageChannelType.Yell.ChannelCode)
42-
Songtitle_Chat_Type.SelectedIndex = 1;
40+
SongTitleChatType.SelectedIndex = 1;
4341
else if (tpBard.Key.channelType.ChannelCode == ChatMessageChannelType.Party.ChannelCode)
44-
Songtitle_Chat_Type.SelectedIndex = 2;
42+
SongTitleChatType.SelectedIndex = 2;
4543

46-
Songtitle_Post_Type.SelectedIndex = tpBard.Key.channelType.Equals(ChatMessageChannelType.None) ? 0 : 1;
44+
SongTitlePostType.SelectedIndex = tpBard.Key.channelType.Equals(ChatMessageChannelType.None) ? 0 : 1;
4745
}
4846
}
4947

50-
Lyrics_TrackNr.Value = performer.SingerTrackNr.ToString();
51-
GfxTest.IsChecked = _performer.game.GfxSettingsLow;
52-
PopulateCPUTab();
48+
LyricsTrackNr.Value = performer?.SingerTrackNr.ToString();
49+
GfxTest.IsChecked = _performer?.game.GfxSettingsLow;
50+
PopulateCpuTab();
5351
}
5452

5553
private void SongTitle_Post_Type_SelectionChanged(object sender, SelectionChangedEventArgs e)
5654
{
57-
var chanType = Songtitle_Chat_Type.SelectedIndex switch
55+
var chanType = SongTitleChatType.SelectedIndex switch
5856
{
5957
0 => ChatMessageChannelType.Say,
6058
1 => ChatMessageChannelType.Yell,
6159
2 => ChatMessageChannelType.Party,
6260
_ => ChatMessageChannelType.None
6361
};
6462

65-
switch (Songtitle_Post_Type.SelectedIndex)
63+
switch (SongTitlePostType.SelectedIndex)
6664
{
6765
case 0:
6866
BmpMaestro.Instance.SetSongTitleParsingBard(ChatMessageChannelType.None, "", null);
6967
break;
7068
case 1:
71-
BmpMaestro.Instance.SetSongTitleParsingBard(chanType, Songtitle_Chat_Prefix.Text, _performer);
69+
BmpMaestro.Instance.SetSongTitleParsingBard(chanType, SongTitleChatPrefix.Text, _performer);
7270
break;
7371
}
7472
}
7573

7674
private void PostSongTitle_Click(object sender, RoutedEventArgs e)
7775
{
78-
if (_performer.SongName == "")
76+
if (_performer?.SongName == "")
7977
return;
8078

81-
var chanType = Songtitle_Chat_Type.SelectedIndex switch
79+
var chanType = SongTitleChatType.SelectedIndex switch
8280
{
8381
0 => ChatMessageChannelType.Say,
8482
1 => ChatMessageChannelType.Yell,
8583
2 => ChatMessageChannelType.Party,
8684
_ => ChatMessageChannelType.None
8785
};
8886

89-
if (_performer.SongName != null)
87+
if (_performer?.SongName != null)
9088
{
91-
var songName = $"{Songtitle_Chat_Prefix.Text} {_performer.SongName} {Songtitle_Chat_Prefix.Text}";
89+
var songName = $"{SongTitleChatPrefix.Text} {_performer.SongName} {SongTitleChatPrefix.Text}";
9290
_performer.game.SendText(chanType, songName);
9391
}
9492
}
@@ -97,7 +95,7 @@ private void ChatInputText_KeyDown(object sender, KeyEventArgs e)
9795
{
9896
if (e.Key == Key.Return)
9997
{
100-
var chanType = Chat_Type.SelectedIndex switch
98+
var chanType = ChatType.SelectedIndex switch
10199
{
102100
0 => ChatMessageChannelType.Say,
103101
1 => ChatMessageChannelType.Yell,
@@ -107,7 +105,7 @@ private void ChatInputText_KeyDown(object sender, KeyEventArgs e)
107105
_ => ChatMessageChannelType.None
108106
};
109107
var text = new string(ChatInputText.Text.ToCharArray());
110-
_performer.game.SendText(chanType, text);
108+
_performer?.game.SendText(chanType, text);
111109
ChatInputText.Text = "";
112110
}
113111
}
@@ -117,46 +115,49 @@ private void Lyrics_TrackNr_PreviewMouseUp(object sender, MouseButtonEventArgs e
117115
if (sender is NumericUpDown ctl) ctl.OnValueChanged += Lyrics_TrackNr_OnValueChanged;
118116
}
119117

120-
private void Lyrics_TrackNr_OnValueChanged(object sender, int s)
118+
private void Lyrics_TrackNr_OnValueChanged(object? sender, int s)
121119
{
122-
_performer.SingerTrackNr = s;
120+
if (_performer != null) _performer.SingerTrackNr = s;
123121
if (sender is NumericUpDown ctl) ctl.OnValueChanged -= Lyrics_TrackNr_OnValueChanged;
124122
}
125123

126124
#region CPU-Tab
127-
private void PopulateCPUTab()
125+
private void PopulateCpuTab()
128126
{
129127
//Get the our application's process.
130-
var process = _performer.game.Process;
128+
var _ = _performer?.game.Process;
131129

132130
//Get the processor count of our machine.
133131
var cpuCount = Environment.ProcessorCount;
134-
var AffinityMask = (long)_performer.game.GetAffinity();
135-
136-
var res = (int)Math.Ceiling(cpuCount / (double)3);
137-
var idx = 1;
138-
for (var col = 0; col != 3; col++)
132+
if (_performer != null)
139133
{
140-
CPUDisplay.ColumnDefinitions.Add(new ColumnDefinition());
141-
142-
for (var i = 0; i != res + 1; i++)
134+
var affinityMask = (long)_performer.game.GetAffinity();
135+
136+
var res = (int)Math.Ceiling(cpuCount / (double)3);
137+
var idx = 1;
138+
for (var col = 0; col != 3; col++)
143139
{
144-
if (idx == cpuCount+1)
145-
break;
146-
if (CPUDisplay.RowDefinitions.Count < res +1)
147-
CPUDisplay.RowDefinitions.Add(new RowDefinition());
148-
var uc = new CheckBox
140+
CpuDisplay.ColumnDefinitions.Add(new ColumnDefinition());
141+
142+
for (var i = 0; i != res + 1; i++)
149143
{
150-
Name = "CPU" + idx,
151-
Content = "CPU" + idx
152-
};
153-
if ((AffinityMask & (1 << idx-1)) > 0) //-1 since we count at 1
154-
uc.IsChecked = true;
155-
_cpuBoxes.Add(uc);
156-
CPUDisplay.Children.Add(uc);
157-
Grid.SetRow(uc, i);
158-
Grid.SetColumn(uc, CPUDisplay.ColumnDefinitions.Count - 1);
159-
idx++;
144+
if (idx == cpuCount+1)
145+
break;
146+
if (CpuDisplay.RowDefinitions.Count < res +1)
147+
CpuDisplay.RowDefinitions.Add(new RowDefinition());
148+
var uc = new CheckBox
149+
{
150+
Name = "CPU" + idx,
151+
Content = "CPU" + idx
152+
};
153+
if ((affinityMask & (1 << idx-1)) > 0) //-1 since we count at 1
154+
uc.IsChecked = true;
155+
_cpuBoxes.Add(uc);
156+
CpuDisplay.Children.Add(uc);
157+
Grid.SetRow(uc, i);
158+
Grid.SetColumn(uc, CpuDisplay.ColumnDefinitions.Count - 1);
159+
idx++;
160+
}
160161
}
161162
}
162163
}
@@ -181,7 +182,7 @@ private void Save_CPU_Click(object sender, RoutedEventArgs e)
181182
return;
182183
}
183184
else
184-
_performer.game.SetAffinity((long)mask);
185+
_performer?.game.SetAffinity((long)mask);
185186
}
186187

187188
private void Clear_CPU_Click(object sender, RoutedEventArgs e)
@@ -206,17 +207,17 @@ private void GfxTest_Checked(object sender, RoutedEventArgs e)
206207
{
207208
if (GfxTest.IsChecked != null && (bool)GfxTest.IsChecked)
208209
{
209-
if (_performer.game.GfxSettingsLow)
210+
if (_performer != null && _performer.game.GfxSettingsLow)
210211
return;
211-
_performer.game.GfxSetLow(true);
212-
_performer.game.GfxSettingsLow = true;
212+
_performer?.game.GfxSetLow(true);
213+
if (_performer != null) _performer.game.GfxSettingsLow = true;
213214
}
214215
else
215216
{
216-
if (!_performer.game.GfxSettingsLow)
217+
if (_performer != null && !_performer.game.GfxSettingsLow)
217218
return;
218-
_performer.game.GfxSetLow(false);
219-
_performer.game.GfxSettingsLow = false;
219+
_performer?.game.GfxSetLow(false);
220+
if (_performer != null) _performer.game.GfxSettingsLow = false;
220221
}
221222
}
222-
}
223+
}

BardMusicPlayer/Controls/BardView.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
99
xmlns:local="clr-namespace:BardMusicPlayer.Pigeonhole;assembly=BardMusicPlayer.Pigeonhole"
1010
mc:Ignorable="d"
11-
d:DesignHeight="450" d:DesignWidth="800">
11+
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance }">
1212
<Grid>
1313
<Grid.RowDefinitions>
1414
<RowDefinition Height="30" />
@@ -32,19 +32,19 @@
3232
Click="OpenInstrumentButton_Click" />
3333
<Button Grid.Column="1" x:Name="CloseInstrumentButton" Margin="0,2,0,1" Height="Auto" Content="Close"
3434
ToolTip="Close Instruments"
35-
Click="CloseInstrumentButton_Click" Visibility="Hidden"/>
35+
Click="CloseInstrumentButton_Click" Visibility="Hidden" />
3636
<Button Grid.Column="2" x:Name="SendEnsembleButton" Margin="2,2,2,1" Height="Auto" Content="Send Ensemble"
3737
ToolTip="Sends ensemble ready check"
3838
Click="RdyCheck_Click" />
3939
<Button Grid.Column="7" Margin="0,2,0,1" Height="Auto" Content="..."
40-
x:Name="More_Options"
40+
x:Name="MoreOptions"
4141
Click="MenuButton_PreviewMouseLeftButtonDown"
4242
ContextMenuService.Placement="Bottom" ContextMenuService.ShowOnDisabled="True">
4343
<Button.ContextMenu>
4444
<ContextMenu>
45-
<CheckBox Content="Auto-Equip Performer(s)" x:Name="Autoequip_CheckBox"
45+
<CheckBox Content="Auto-Equip Performer(s)" x:Name="AutoEquipCheckBox"
4646
Unchecked="AutoEquip_CheckBox_Checked" Checked="AutoEquip_CheckBox_Checked" />
47-
<CheckBox Content="Set all Gfx to low" x:Name="GfxLow_CheckBox"
47+
<CheckBox Content="Set all Gfx to low" x:Name="GfxLowCheckBox"
4848
Unchecked="GfxLow_CheckBox_Checked" Checked="GfxLow_CheckBox_Checked" />
4949
<MenuItem Header="Load Performer Settings" Click="Load_Performer_Settings" />
5050
<MenuItem Header="Save Performer Settings" Click="Save_Performer_Settings" />
@@ -70,7 +70,7 @@
7070
<ColumnDefinition Width="130" /> <!-- 3 -->
7171
<ColumnDefinition Width="Auto" /> <!-- 4 Spacer-->
7272
<ColumnDefinition Width="140" /> <!-- 5 -->
73-
<ColumnDefinition Width="10" /> <!-- 6 dalamud-->
73+
<ColumnDefinition Width="10" /> <!-- 6 Dalamud-->
7474
<ColumnDefinition Width="10" /> <!-- 7 spacer-->
7575
<ColumnDefinition Width="Auto" /> <!-- 8 track-->
7676
<ColumnDefinition Width="Auto" /> <!-- 9 octave-->

0 commit comments

Comments
 (0)