Skip to content

Commit

Permalink
Code quality improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Jun 17, 2024
1 parent c1e3e62 commit 42e90bb
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void AddConfigFile(string path, Dictionary<string, FilterGraphNode> lastNodes, L
continue;
}

switch (split[0].ToLower(CultureInfo.InvariantCulture)) {
switch (split[0].ToLowerInvariant()) {
// Control
case "include":
string included = Path.Combine(Path.GetDirectoryName(path), string.Join(' ', split, 1, split.Length - 1));
Expand All @@ -50,7 +50,7 @@ void AddConfigFile(string path, Dictionary<string, FilterGraphNode> lastNodes, L
break;
case "channel":
activeChannels.Clear();
if (split.Length == 2 && split[1].ToLower(CultureInfo.InvariantCulture) == "all") {
if (split.Length == 2 && split[1].ToLowerInvariant() == "all") {
activeChannels.AddRange(channelLabels);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Cavern.QuickEQ.Format/FilterSet/MultEQXFilterSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public override void Export(string path) {
label.pairDesignation, label.pair, label.location,
channelRef.gain.ToString(CultureInfo.InvariantCulture),
GetDelay(channel).ToString(CultureInfo.InvariantCulture),
channelRef.switchPolarity.ToString().ToLower()));
channelRef.switchPolarity.ToString().ToLowerInvariant()));
if (++channel != guids.Length) {
result.AppendLine(",");
} else {
Expand Down
7 changes: 3 additions & 4 deletions Cavern.QuickEQ/Equalization/PeakingEqualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ public static PeakingEQ[] ParseEQFile(IEnumerable<string> lines) {
List<PeakingEQ> result = new List<PeakingEQ>();
foreach (string line in lines) {
string[] parts = line.Split(new[] { ':', ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 11 && parts[0].ToLower() == "filter" && parts[2].ToLower() == "on" && parts[3].ToLower() == "pk" &&
QMath.TryParseDouble(parts[5], out double freq) &&
QMath.TryParseDouble(parts[8], out double gain) &&
QMath.TryParseDouble(parts[11], out double q)) {
if (parts.Length > 11 && parts[0].ToLowerInvariant() == "filter" && parts[2].ToLowerInvariant() == "on" &&
parts[3].ToLowerInvariant() == "pk" && QMath.TryParseDouble(parts[5], out double freq) &&
QMath.TryParseDouble(parts[8], out double gain) && QMath.TryParseDouble(parts[11], out double q)) {
result.Add(new PeakingEQ(Listener.DefaultSampleRate, freq, q, gain));
}
}
Expand Down
2 changes: 1 addition & 1 deletion Cavern/Filters/Allpass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Allpass(int sampleRate, double centerFreq, double q, double gain) : base(
/// Parse a Filter line of Equalizer APO which was split at spaces to a Cavern <see cref="Allpass"/> filter.<br />
/// Sample: ON AP Fc 100 Hz Q 10
/// </summary>
public static Allpass FromEqualizerAPO(string[] splitLine, int sampleRate) {
public static new Allpass FromEqualizerAPO(string[] splitLine, int sampleRate) {
if (QMath.TryParseDouble(splitLine[4], out double freq) && QMath.TryParseDouble(splitLine[7], out double q)) {
return new Allpass(sampleRate, freq, q);
}
Expand Down
2 changes: 1 addition & 1 deletion Cavern/Filters/Bandpass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Bandpass(int sampleRate, double centerFreq, double q, double gain) : base
/// Sample: Filter: ON BP Fc 100 Hz
/// Sample with Q-factor: Filter: ON BP Fc 100 Hz Q 10
/// </summary>
public static Bandpass FromEqualizerAPO(string[] splitLine, int sampleRate) {
public static new Bandpass FromEqualizerAPO(string[] splitLine, int sampleRate) {
if (QMath.TryParseDouble(splitLine[4], out double freq)) {
if (splitLine.Length < 7) {
return new Bandpass(sampleRate, freq);
Expand Down
2 changes: 1 addition & 1 deletion Cavern/Filters/BiquadFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected BiquadFilter(int sampleRate, double centerFreq, double q, double gain)
/// Parse a Filter line of Equalizer APO which was split at spaces to a Cavern <see cref="BiquadFilter"/> filter,
/// detecting its type.<br />
/// </summary>
public static BiquadFilter FromEqualizerAPO(string[] splitLine, int sampleRate) => splitLine[2].ToUpper() switch {
public static BiquadFilter FromEqualizerAPO(string[] splitLine, int sampleRate) => splitLine[2].ToUpperInvariant() switch {
"PK" => PeakingEQ.FromEqualizerAPO(splitLine, sampleRate),
"LP" => Lowpass.FromEqualizerAPO(splitLine, sampleRate),
"LPQ" => Lowpass.FromEqualizerAPO(splitLine, sampleRate),
Expand Down
2 changes: 1 addition & 1 deletion Cavern/Filters/Delay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static Delay FromEqualizerAPO(string[] splitLine, int sampleRate) {
if (splitLine.Length < 3 || !QMath.TryParseDouble(splitLine[1], out double delay)) {
throw new FormatException(nameof(splitLine));
}
return splitLine[2].ToLower(CultureInfo.InvariantCulture) switch {
return splitLine[2].ToLowerInvariant() switch {
"ms" => new Delay(delay, sampleRate),
"samples" => new Delay((int)delay),
_ => throw new ArgumentOutOfRangeException(splitLine[0]),
Expand Down
4 changes: 2 additions & 2 deletions Cavern/Filters/HighShelf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public HighShelf(int sampleRate, double centerFreq, double q, double gain) : bas
/// Sample with fixed shelf: Filter: ON HS Fc 100 Hz Gain 0 dB
/// Sample with custom shelf: Filter: ON HSC 12 dB Fc 100 Hz Gain 0 dB
/// </summary>
public static HighShelf FromEqualizerAPO(string[] splitLine, int sampleRate) {
string type = splitLine[2].ToLower();
public static new HighShelf FromEqualizerAPO(string[] splitLine, int sampleRate) {
string type = splitLine[2].ToLowerInvariant();
if (type == "hs" && QMath.TryParseDouble(splitLine[4], out double freq) && QMath.TryParseDouble(splitLine[5], out double gain)) {
return new HighShelf(sampleRate, freq, QFactor.FromSlope(0.9, gain));
} else if (type == "hsc" && QMath.TryParseDouble(splitLine[3], out double slope) &&
Expand Down
4 changes: 2 additions & 2 deletions Cavern/Filters/Highpass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public Highpass(int sampleRate, double centerFreq, double q, double gain) : base
/// Sample with fixed Q factor: Filter: ON HP Fc 100 Hz
/// Sample with custom Q factor: Filter: ON HPQ Fc 100 Hz Q 0.7071
/// </summary>
public static Highpass FromEqualizerAPO(string[] splitLine, int sampleRate) {
string type = splitLine[2].ToLower();
public static new Highpass FromEqualizerAPO(string[] splitLine, int sampleRate) {
string type = splitLine[2].ToLowerInvariant();
if (type == "hp" && QMath.TryParseDouble(splitLine[4], out double freq)) {
return new Highpass(sampleRate, freq);
} else if (type == "hpq" && QMath.TryParseDouble(splitLine[4], out freq) && QMath.TryParseDouble(splitLine[7], out double q)) {
Expand Down
4 changes: 2 additions & 2 deletions Cavern/Filters/LowShelf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public LowShelf(int sampleRate, double centerFreq, double q, double gain) : base
/// Sample with fixed shelf: Filter: ON LS Fc 100 Hz Gain 0 dB
/// Sample with custom shelf: Filter: ON LSC 12 dB Fc 100 Hz Gain 0 dB
/// </summary>
public static LowShelf FromEqualizerAPO(string[] splitLine, int sampleRate) {
string type = splitLine[2].ToLower();
public static new LowShelf FromEqualizerAPO(string[] splitLine, int sampleRate) {
string type = splitLine[2].ToLowerInvariant();
if (type == "ls" && QMath.TryParseDouble(splitLine[4], out double freq) && QMath.TryParseDouble(splitLine[5], out double gain)) {
return new LowShelf(sampleRate, freq, QFactor.FromSlope(0.9, gain));
} else if (type == "lsc" && QMath.TryParseDouble(splitLine[3], out double slope) &&
Expand Down
4 changes: 2 additions & 2 deletions Cavern/Filters/Lowpass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public Lowpass(int sampleRate, double centerFreq, double q, double gain) : base(
/// Sample with fixed Q factor: Filter: ON LP Fc 100 Hz
/// Sample with custom Q factor: Filter: ON LPQ Fc 100 Hz Q 0.7071
/// </summary>
public static Lowpass FromEqualizerAPO(string[] splitLine, int sampleRate) {
string type = splitLine[2].ToLower();
public static new Lowpass FromEqualizerAPO(string[] splitLine, int sampleRate) {
string type = splitLine[2].ToLowerInvariant();
if (type == "lp" && QMath.TryParseDouble(splitLine[4], out double freq)) {
return new Lowpass(sampleRate, freq);
} else if (type == "lpq" && QMath.TryParseDouble(splitLine[4], out freq) && QMath.TryParseDouble(splitLine[7], out double q)) {
Expand Down
2 changes: 1 addition & 1 deletion Cavern/Filters/Notch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Notch(int sampleRate, double centerFreq, double q, double gain) : base(sa
/// Sample with default Q-factor: Filter: ON NO Fc 100 Hz
/// Sample with custom Q-factor: Filter: ON NO Fc 100 Hz Q 30
/// </summary>
public static Notch FromEqualizerAPO(string[] splitLine, int sampleRate) {
public static new Notch FromEqualizerAPO(string[] splitLine, int sampleRate) {
if (QMath.TryParseDouble(splitLine[4], out double freq)) {
if (splitLine.Length < 7) {
return new Notch(sampleRate, freq, 30);
Expand Down
2 changes: 1 addition & 1 deletion Cavern/Filters/PeakingEQ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PeakingEQ(int sampleRate, double centerFreq, double q, double gain) : bas
/// Sample with Q factor: Filter: ON PK Fc 100 Hz Gain 0 dB Q 10<br />
/// Sample with bandwidth: Filter: ON PK Fc 100 Hz Gain 0 dB BW Oct 0.1442
/// </summary>
public static PeakingEQ FromEqualizerAPO(string[] splitLine, int sampleRate) {
public static new PeakingEQ FromEqualizerAPO(string[] splitLine, int sampleRate) {
if (QMath.TryParseDouble(splitLine[4], out double freq) && QMath.TryParseDouble(splitLine[7], out double gain)) {
if (splitLine[9].Equals("Q") && QMath.TryParseDouble(splitLine[10], out double q)) {
return new PeakingEQ(sampleRate, freq, q, gain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public override void Execute(string[] args, int offset, MainWindow app) {
Execute(value, app);
return;
}
if (args[offset].ToLower(CultureInfo.InvariantCulture).Equals(true1) ||
args[offset].ToLower(CultureInfo.InvariantCulture).Equals(true2)) {
if (args[offset].ToLowerInvariant().Equals(true1) ||
args[offset].ToLowerInvariant().Equals(true2)) {
Execute(true, app);
return;
}
if (args[offset].ToLower(CultureInfo.InvariantCulture).Equals(false1) ||
args[offset].ToLower(CultureInfo.InvariantCulture).Equals(false2)) {
if (args[offset].ToLowerInvariant().Equals(false1) ||
args[offset].ToLowerInvariant().Equals(false2)) {
Execute(false, app);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions CavernSamples/CavernizeGUI/MainWindow.Rendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Action Render(string path) {
BitDepth bits = codec == Codec.PCM_Float ? BitDepth.Float32 : force24Bit.IsChecked ? BitDepth.Int24 : BitDepth.Int16;
if (!codec.IsEnvironmental()) {
SetBlockSize(activeRenderTarget);
string exportFormat = path[^4..].ToLower(CultureInfo.InvariantCulture);
string exportFormat = path[^4..].ToLowerInvariant();
bool mkvTarget = exportFormat.Equals(".mkv");
string exportName = mkvTarget ? path[..^4] + waveExtension : path;
int channelCount = activeRenderTarget.OutputChannels;
Expand Down Expand Up @@ -257,7 +257,7 @@ void RenderTask(Track target, AudioWriter writer, bool dynamicOnly, bool heightO
targetCodec += massivelyMultichannel;
}

if (writer is RIFFWaveWriter && finalName[^4..].ToLower(CultureInfo.InvariantCulture).Equals(".mkv")) {
if (writer is RIFFWaveWriter && finalName[^4..].ToLowerInvariant().Equals(".mkv")) {
string exportedAudio = finalName[..^4] + waveExtension;
taskEngine.UpdateStatus("Merging to final container...");
if (!ffmpeg.Launch(string.Format("-i \"{0}\" -i \"{1}\" -map 0:v? -map 1:a -map 0:s? -c:v copy -c:a {2} " +
Expand Down

0 comments on commit 42e90bb

Please sign in to comment.