Skip to content

Commit 2c645ed

Browse files
committed
BASSのプラグインバージョンも表示するよう変更
1 parent 4848c5a commit 2c645ed

File tree

4 files changed

+81
-45
lines changed

4 files changed

+81
-45
lines changed

LoopMusicPlayer/Core/Player.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ public class Player : IDisposable
3333
"basswma",
3434
"basswv",
3535
};
36-
private static List<int> bassPluginsHandleList = new List<int>();
36+
private static List<int> bassPluginsHandleList { get; set; } = new();
37+
public static List<Tuple<string, string>> bassPluginsVersionList { get; private set; } = new();
3738
private static CBassLibraryLoader? bassLibraryLoader = null;
38-
public static void Init(string BasePath, int Device = -1) {
39+
public static void Init(string BasePath, int Device = -1)
40+
{
3941
bassLibraryLoader = new CBassLibraryLoader();
4042

4143
//Linux環境で、bassflacは2回以上Loadを実施しないと、正常にLoadできない(なんで?)
@@ -55,24 +57,27 @@ public static void Init(string BasePath, int Device = -1) {
5557
{
5658
pluginName = BasePath + $"lib{pluginName}.so";
5759
}
58-
else if(OperatingSystem.IsAndroid())
60+
else if (OperatingSystem.IsAndroid())
5961
{
6062
pluginName = $"lib{pluginName}.so";
6163
}
6264
int pluginHandle = Bass.PluginLoad(pluginName);
63-
if (pluginHandle != 0)
65+
if (pluginHandle != 0) {
66+
PluginInfo info = Bass.PluginGetInfo(pluginHandle);
6467
bassPluginsHandleList.Add(pluginHandle);
68+
bassPluginsVersionList.Add(new Tuple<string, string>(bassPluginsList[i].Replace("_", "").ToUpperInvariant(), info.Version.ToString()));
69+
}
6570
}
6671
Bass.Init(Device);
6772
initialized = true;
6873
}
6974

70-
public static void Free() {
71-
for (int i = 0; i < bassPluginsHandleList.Count; i++)
72-
{
73-
Bass.PluginFree(bassPluginsHandleList[i]);
74-
}
75+
public static void Free()
76+
{
77+
foreach (var i in bassPluginsHandleList)
78+
Bass.PluginFree(i);
7579
bassPluginsHandleList.Clear();
80+
bassPluginsVersionList.Clear();
7681
Bass.Free();
7782
bassLibraryLoader?.Dispose();
7883
bassLibraryLoader = null;
@@ -94,12 +99,12 @@ public uint LoopCount
9499
{
95100
get
96101
{
97-
lock(LockObj)
102+
lock (LockObj)
98103
return _LoopCount;
99104
}
100105
private set
101106
{
102-
lock(LockObj)
107+
lock (LockObj)
103108
_LoopCount = value;
104109
}
105110
}
@@ -132,20 +137,21 @@ private set
132137

133138
public Player(string filepath, double volume, bool streaming, Stream? stream = null)
134139
{
135-
if(!initialized)
140+
if (!initialized)
136141
throw new Exception("Player class is not initialized.");
137142
this.FilePath = filepath;
138143
Ended = false;
139144

140-
if (streaming) {
141-
if(stream is not null)
145+
if (streaming)
146+
{
147+
if (stream is not null)
142148
this.reader = new MusicFileReaderStreaming(stream);
143149
else
144150
this.reader = new MusicFileReaderStreaming(filepath);
145151
}
146152
else
147153
{
148-
if(stream is not null)
154+
if (stream is not null)
149155
this.reader = new MusicFileReaderMemory(stream);
150156
else
151157
this.reader = new MusicFileReaderMemory(filepath);
@@ -228,7 +234,7 @@ public int StreamProc(int handle, IntPtr buffer, int length, IntPtr user)
228234

229235
if (NextIsLoop && reader.SamplePosition + (int)(Const.byte_per_float * (length / reader.Channels)) >= LoopEnd)
230236
{
231-
int tmplength = (int)((LoopEnd - reader.SamplePosition)* reader.Channels * Const.float_per_byte);
237+
int tmplength = (int)((LoopEnd - reader.SamplePosition) * reader.Channels * Const.float_per_byte);
232238
num += reader.ReadSamples(buffer, 0, tmplength);
233239
reader.SamplePosition = LoopStart;
234240
num += reader.ReadSamples(buffer, tmplength, length - tmplength);
@@ -242,8 +248,10 @@ public int StreamProc(int handle, IntPtr buffer, int length, IntPtr user)
242248

243249
if (num < 0) num = 0;
244250

245-
if(this.EndAction is not null && num != length) {
246-
if(!Ended) {
251+
if (this.EndAction is not null && num != length)
252+
{
253+
if (!Ended)
254+
{
247255
Ended = true;
248256
this.EndAction(this, EventArgs.Empty);
249257
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace LoopMusicPlayer.DataClass;
4+
5+
public class VersionItem
6+
{
7+
public string Name { get; }
8+
public string Version { get; }
9+
10+
public VersionItem(string name, string version)
11+
{
12+
this.Name = name;
13+
this.Version = version;
14+
}
15+
}

LoopMusicPlayer/ViewModels/MainViewModel.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,13 @@ private void OnLoop(object? sender, EventArgs e)
109109

110110
// ThirdPartyLicenses
111111

112-
public ObservableCollection<LicenseItem> LicenseList { get; set; }
112+
public ObservableCollection<LicenseItem> LicenseList { get; }
113113

114114
// About
115115
public string AppName => $"{Assembly.GetExecutingAssembly().GetName().Name}";
116-
public string Version => $"{Assembly.GetExecutingAssembly().GetName().Version}";
117-
public string ManagedBassVersion => $"{typeof(Bass).Assembly.GetName().Version?.ToString(3)}";
118-
public string BASSVersion => $"{Bass.Version}";
119-
public string AvaloniaVersion => $"{typeof(AvaloniaObject).Assembly.GetName().Version?.ToString(3)}";
120-
public string DotnetVersion => RuntimeInformation.FrameworkDescription.Substring(5); //".NET "を切る
121116
public string Copyright => "(c) 2021-2024 Mr-Ojii";
122117

118+
public ObservableCollection<VersionItem> VersionList { get; }
123119

124120

125121
private int _playingIndex = 0;
@@ -160,6 +156,18 @@ public MainViewModel()
160156
//なんか、名前順じゃないので、並び替える
161157
LicenseList = new ObservableCollection<LicenseItem>(LicenseList.OrderBy(s => s.Name));
162158

159+
VersionList = new ObservableCollection<VersionItem>() {
160+
new VersionItem(this.AppName, $"{Assembly.GetExecutingAssembly().GetName().Version}"),
161+
new VersionItem(".NET", RuntimeInformation.FrameworkDescription.Substring(5)), //".NET "を切る
162+
new VersionItem("Avalonia UI", $"{typeof(AvaloniaObject).Assembly.GetName().Version?.ToString(3)}"),
163+
new VersionItem("BASS", $"{Bass.Version}"),
164+
new VersionItem("ManagedBass", $"{typeof(Bass).Assembly.GetName().Version?.ToString(3)}"),
165+
};
166+
foreach (var i in Player.bassPluginsVersionList)
167+
{
168+
VersionList.Add(new VersionItem(i.Item1, i.Item2));
169+
}
170+
VersionList = new ObservableCollection<VersionItem>(VersionList.OrderBy(s => s.Name));
163171

164172
if (!Bass.GetDeviceInfo(Bass.CurrentDevice, out device_info))
165173
return;
@@ -289,7 +297,8 @@ public async Task UpdatePlayer(IStorageFile file)
289297
var stream = await file.OpenReadAsync();
290298
var path = FileToPath(file);
291299
bool playing = true;
292-
if (this.Player is not null) {
300+
if (this.Player is not null)
301+
{
293302
var status = this.Player.Status();
294303
playing = (status == PlaybackState.Playing || status == PlaybackState.Stalled);
295304
}
@@ -306,7 +315,7 @@ public async Task UpdatePlayer(IStorageFile file)
306315
if (this.Player.IsLoop)
307316
{
308317
this.LoopStart = this.Player.LoopStart / (double)this.Player.TotalSamples;
309-
this.LoopEnd = this.Player.LoopEnd /(double)this.Player.TotalSamples;
318+
this.LoopEnd = this.Player.LoopEnd / (double)this.Player.TotalSamples;
310319
}
311320
this.Player.EndAction += this.OnEnd;
312321
this.Player.LoopAction += this.OnLoop;
@@ -358,7 +367,7 @@ private async Task RandomChoice()
358367
[RelayCommand]
359368
private void SkipM5()
360369
{
361-
if(this.Player is null)
370+
if (this.Player is null)
362371
return;
363372

364373
long to = Math.Clamp(this.Player.SamplePosition - 5 * this.Player.SampleRate, 0, this.Player.TotalSamples - 1);
@@ -371,7 +380,7 @@ private void SkipM5()
371380
[RelayCommand]
372381
private void SkipP5()
373382
{
374-
if(this.Player is null)
383+
if (this.Player is null)
375384
return;
376385

377386
long to = Math.Clamp(this.Player.SamplePosition + 5 * this.Player.SampleRate, 0, this.Player.TotalSamples - 1);
@@ -409,7 +418,7 @@ private void SongUp()
409418

410419
if (this._playingIndex == _selectedIndex)
411420
this._playingIndex -= 1;
412-
else if(this._playingIndex == _selectedIndex - 1)
421+
else if (this._playingIndex == _selectedIndex - 1)
413422
this._playingIndex += 1;
414423
}
415424
[RelayCommand]
@@ -426,7 +435,7 @@ private void SongDown()
426435

427436
if (this._playingIndex == _selectedIndex)
428437
this._playingIndex += 1;
429-
else if(this._playingIndex == _selectedIndex + 1)
438+
else if (this._playingIndex == _selectedIndex + 1)
430439
this._playingIndex -= 1;
431440
}
432441

LoopMusicPlayer/Views/MainView.axaml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,25 @@
200200
<TabItem.Header>
201201
<ic:SymbolIcon Symbol="Info" IsFilled="True" />
202202
</TabItem.Header>
203-
<Grid ColumnDefinitions="Auto,Auto" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Center">
204-
<Image Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Width="256" Height="256" Source="avares://LoopMusicPlayer/Assets/icon.ico" />
205-
<TextBlock Text="{Binding AppName}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" FontWeight="Bold" HorizontalAlignment="Center" Margin="10"/>
206-
<TextBlock Text="LoopMusicPlayer" Grid.Row="2" Grid.Column="0"/>
207-
<TextBlock Text="{Binding Version}" Grid.Row="2" Grid.Column="1"/>
208-
<TextBlock Text=".NET" Grid.Row="3" Grid.Column="0"/>
209-
<TextBlock Text="{Binding DotnetVersion}" Grid.Row="3" Grid.Column="1"/>
210-
<TextBlock Text="Avalonia UI" Grid.Row="4" Grid.Column="0"/>
211-
<TextBlock Text="{Binding AvaloniaVersion}" Grid.Row="4" Grid.Column="1"/>
212-
<TextBlock Text="BASS" Grid.Row="5" Grid.Column="0"/>
213-
<TextBlock Text="{Binding BASSVersion}" Grid.Row="5" Grid.Column="1"/>
214-
<TextBlock Text="ManagedBass" Grid.Row="6" Grid.Column="0"/>
215-
<TextBlock Text="{Binding ManagedBassVersion}" Grid.Row="6" Grid.Column="1"/>
216-
<TextBlock Text="{Binding Copyright}" Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="10"/>
217-
</Grid>
203+
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
204+
<Image Width="256" Height="256" HorizontalAlignment="Center" Source="avares://LoopMusicPlayer/Assets/icon.ico" />
205+
<TextBlock Text="{Binding AppName}" FontWeight="Bold" HorizontalAlignment="Center" Margin="10"/>
206+
<ItemsControl ItemsSource="{Binding VersionList}" Grid.IsSharedSizeScope="True">
207+
<ItemsControl.ItemTemplate>
208+
<DataTemplate>
209+
<Grid HorizontalAlignment="Center">
210+
<Grid.ColumnDefinitions>
211+
<ColumnDefinition Width="Auto" SharedSizeGroup="NameGroup" />
212+
<ColumnDefinition Width="Auto" SharedSizeGroup="VersionGroup" />
213+
</Grid.ColumnDefinitions>
214+
<TextBlock Text="{Binding Name}" Grid.Column="0" />
215+
<TextBlock Text="{Binding Version}" Grid.Column="1" />
216+
</Grid>
217+
</DataTemplate>
218+
</ItemsControl.ItemTemplate>
219+
</ItemsControl>
220+
<TextBlock Text="{Binding Copyright}" HorizontalAlignment="Center" Margin="10"/>
221+
</StackPanel>
218222
</TabItem>
219223

220224
</TabControl>

0 commit comments

Comments
 (0)