More common refactorings like renaming variables, removing empty statements and unused variables, etc

This commit is contained in:
Kwoth
2022-01-09 16:46:08 +01:00
parent 2ce3262d59
commit f07a855912
75 changed files with 447 additions and 465 deletions

View File

@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Music.Common;
public sealed class MultimediaTimer : IDisposable
{
private LpTimeProcDelegate _lpTimeProc;
private LpTimeProcDelegate lpTimeProc;
private readonly uint _eventId;
private readonly Action<object> _callback;
private readonly object _state;
@@ -18,8 +18,8 @@ public sealed class MultimediaTimer : IDisposable
_callback = callback;
_state = state;
_lpTimeProc = CallbackInternal;
_eventId = timeSetEvent((uint)period, 1, _lpTimeProc, 0, TimerMode.Periodic);
lpTimeProc = CallbackInternal;
_eventId = timeSetEvent((uint)period, 1, lpTimeProc, 0, TimerMode.Periodic);
}
/// <summary>
@@ -58,13 +58,13 @@ public sealed class MultimediaTimer : IDisposable
/// <summary>
/// The timeKillEvent function cancels a specified timer event.
/// </summary>
/// <param name="uTimerID">
/// <param name="uTimerId">
/// Identifier of the timer event to cancel.
/// This identifier was returned by the timeSetEvent function when the timer event was set up.
/// </param>
/// <returns>Returns TIMERR_NOERROR if successful or MMSYSERR_INVALPARAM if the specified timer event does not exist.</returns>
[DllImport("Winmm.dll")]
private static extern int timeKillEvent(uint uTimerID);
private static extern int timeKillEvent(uint uTimerId);
private void CallbackInternal(
uint uTimerId,
@@ -76,12 +76,12 @@ public sealed class MultimediaTimer : IDisposable
public void Dispose()
{
_lpTimeProc = default;
lpTimeProc = default;
timeKillEvent(_eventId);
}
private delegate void LpTimeProcDelegate(
uint uTimerID,
uint uTimerId,
uint uMsg,
int dwUser,
int dw1,

View File

@@ -22,7 +22,7 @@ public sealed class MusicPlayer : IMusicPlayer
public float Volume { get; private set; } = 1.0f;
private readonly AdjustVolumeDelegate AdjustVolume;
private readonly AdjustVolumeDelegate _adjustVolume;
private readonly VoiceClient _vc;
private readonly IMusicQueue _queue;
@@ -30,8 +30,8 @@ public sealed class MusicPlayer : IMusicPlayer
private readonly IVoiceProxy _proxy;
private readonly ISongBuffer _songBuffer;
private bool _skipped;
private int? _forceIndex;
private bool skipped;
private int? forceIndex;
private readonly Thread _thread;
private readonly Random _rng;
@@ -48,9 +48,9 @@ public sealed class MusicPlayer : IMusicPlayer
_vc = GetVoiceClient(qualityPreset);
if (_vc.BitDepth == 16)
AdjustVolume = AdjustVolumeInt16;
_adjustVolume = AdjustVolumeInt16;
else
AdjustVolume = AdjustVolumeFloat32;
_adjustVolume = AdjustVolumeFloat32;
_songBuffer = new PoopyBufferImmortalized(_vc.InputLength);
@@ -95,9 +95,9 @@ public sealed class MusicPlayer : IMusicPlayer
continue;
}
if (_skipped)
if (skipped)
{
_skipped = false;
skipped = false;
_queue.Advance();
continue;
}
@@ -182,9 +182,9 @@ public sealed class MusicPlayer : IMusicPlayer
{
// doing the skip this way instead of in the condition
// ensures that a song will for sure be skipped
if (_skipped)
if (skipped)
{
_skipped = false;
skipped = false;
break;
}
@@ -268,10 +268,9 @@ public sealed class MusicPlayer : IMusicPlayer
_ = OnCompleted?.Invoke(this, track);
HandleQueuePostTrack();
_skipped = false;
skipped = false;
_ = _proxy.StopSpeakingAsync();
;
await Task.Delay(100);
}
@@ -285,16 +284,16 @@ public sealed class MusicPlayer : IMusicPlayer
// if nothing is read from the buffer, song is finished
if (data.Length == 0) return null;
AdjustVolume(data, Volume);
_adjustVolume(data, Volume);
return _proxy.SendPcmFrame(vc, data, length);
}
private void HandleQueuePostTrack()
{
if (_forceIndex is { } forceIndex)
if (this.forceIndex is { } forceIndex)
{
_queue.SetIndex(forceIndex);
_forceIndex = null;
this.forceIndex = null;
return;
}
@@ -419,7 +418,7 @@ public sealed class MusicPlayer : IMusicPlayer
public void Clear()
{
_queue.Clear();
_skipped = true;
skipped = true;
}
public IReadOnlyCollection<IQueuedTrackInfo> GetQueuedTracks()
@@ -430,7 +429,7 @@ public sealed class MusicPlayer : IMusicPlayer
public void Next()
{
_skipped = true;
skipped = true;
IsStopped = false;
IsPaused = false;
}
@@ -439,8 +438,8 @@ public sealed class MusicPlayer : IMusicPlayer
{
if (_queue.SetIndex(index))
{
_forceIndex = index;
_skipped = true;
forceIndex = index;
skipped = true;
IsStopped = false;
IsPaused = false;
return true;
@@ -463,7 +462,7 @@ public sealed class MusicPlayer : IMusicPlayer
IsKilled = true;
IsStopped = true;
IsPaused = false;
_skipped = true;
skipped = true;
}
public bool TryRemoveTrackAt(int index, out IQueuedTrackInfo? trackInfo)
@@ -472,7 +471,7 @@ public sealed class MusicPlayer : IMusicPlayer
return false;
if (isCurrent)
_skipped = true;
skipped = true;
return true;
}

View File

@@ -91,7 +91,7 @@ public sealed partial class MusicQueue : IMusicQueue
var currentNode = tracks.First!;
int i;
for (i = 1; i <= this.index; i++)
for (i = 1; i <= index; i++)
currentNode = currentNode.Next!; // can't be null because index is always in range of the count
var added = new QueuedTrackInfo(trackInfo, queuer);
@@ -110,7 +110,7 @@ public sealed partial class MusicQueue : IMusicQueue
foreach (var track in toEnqueue)
{
var added = new QueuedTrackInfo(track, queuer);
this.tracks.AddLast(added);
tracks.AddLast(added);
}
}
}
@@ -156,7 +156,7 @@ public sealed partial class MusicQueue : IMusicQueue
if (newIndex < 0 || newIndex >= tracks.Count)
return false;
this.index = newIndex;
index = newIndex;
return true;
}
}
@@ -170,11 +170,11 @@ public sealed partial class MusicQueue : IMusicQueue
trackInfo = removedNode.Value;
tracks.Remove(removedNode);
if (i <= this.index)
--this.index;
if (i <= index)
--index;
if (this.index < 0)
this.index = Count;
if (index < 0)
index = Count;
// if it was the last song in the queue
// // wrap back to start
@@ -303,7 +303,7 @@ public sealed partial class MusicQueue : IMusicQueue
if (remoteAt < 0 || remoteAt >= tracks.Count)
return false;
if (remoteAt == this.index) isCurrent = true;
if (remoteAt == index) isCurrent = true;
RemoveAtInternal(remoteAt, out trackInfo);

View File

@@ -5,12 +5,12 @@ namespace NadekoBot.Modules.Music;
public sealed class YtdlYoutubeResolver : IYoutubeResolver
{
private static readonly string[] durationFormats =
private static readonly string[] _durationFormats =
{
"ss", "m\\:ss", "mm\\:ss", "h\\:mm\\:ss", "hh\\:mm\\:ss", "hhh\\:mm\\:ss"
};
private static readonly Regex expiryRegex = new(@"(?:[\?\&]expire\=(?<timestamp>\d+))");
private static readonly Regex _expiryRegex = new(@"(?:[\?\&]expire\=(?<timestamp>\d+))");
private static readonly Regex _simplePlaylistRegex = new(@"&list=(?<id>[\w\-]{12,})", RegexOptions.Compiled);
@@ -85,7 +85,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
return default;
}
if (!TimeSpan.TryParseExact(dataArray[4], durationFormats, CultureInfo.InvariantCulture, out var time))
if (!TimeSpan.TryParseExact(dataArray[4], _durationFormats, CultureInfo.InvariantCulture, out var time))
time = TimeSpan.Zero;
var thumbnail = Uri.IsWellFormedUriString(dataArray[3], UriKind.Absolute) ? dataArray[3].Trim() : string.Empty;
@@ -108,7 +108,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
private static TimeSpan GetExpiry(string streamUrl)
{
var match = expiryRegex.Match(streamUrl);
var match = _expiryRegex.Match(streamUrl);
if (match.Success && double.TryParse(match.Groups["timestamp"].ToString(), out var timestamp))
{
var realExpiry = timestamp.ToUnixTimestamp() - DateTime.UtcNow;