Skip to content

Commit

Permalink
Commandline mode would load WAVs twice unnecessarily, no longer disca…
Browse files Browse the repository at this point in the history
…rded silent channels
  • Loading branch information
maxim-zhao committed Sep 8, 2021
1 parent 38c3e30 commit cb6c490
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
16 changes: 14 additions & 2 deletions LibSidWiz/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace LibSidWiz
/// </summary>
public class Channel: IDisposable
{
private readonly bool _autoReloadOnSettingChanged;
private SampleBuffer _samples;
private SampleBuffer _samplesForTrigger;
private string _filename;
Expand Down Expand Up @@ -54,6 +55,11 @@ public class Channel: IDisposable
private bool _renderIfSilent;
private double _fillBase;

public Channel(bool autoReloadOnSettingChanged)
{
_autoReloadOnSettingChanged = autoReloadOnSettingChanged;
}

public enum Sides
{
Left,
Expand Down Expand Up @@ -202,7 +208,10 @@ public Sides Side
bool needReload = value != _side;
_side = value;
Changed?.Invoke(this, needReload);
LoadDataAsync();
if (_autoReloadOnSettingChanged)
{
LoadDataAsync();
}
}
}

Expand All @@ -216,7 +225,10 @@ public bool HighPassFilter
bool needReload = value != _filter;
_filter = value;
Changed?.Invoke(this, needReload);
LoadDataAsync();
if (_autoReloadOnSettingChanged)
{
LoadDataAsync();
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions SidWiz/SidWizPlusGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class ProgramSettings
public string SidPlayPath { get; set; }

[Browsable(false)]
public Channel DefaultChannelSettings { get; set; } = new Channel
public Channel DefaultChannelSettings { get; set; } = new Channel(true)
{
Algorithm = new PeakSpeedTrigger(),
LabelColor = Color.White,
Expand Down Expand Up @@ -301,7 +301,7 @@ private void CloneChannelButton_Click(object sender, EventArgs e)
}

// Duplicate the channel
var channel = new Channel();
var channel = new Channel(true);
channel.FromJson(source.ToJson(), false);
// Insert it after the selected one
_settings.Channels.Insert(index + 1, channel);
Expand All @@ -317,7 +317,7 @@ private void CloneChannelButton_Click(object sender, EventArgs e)
private void AddChannel(string filename)
{
// We create a new Channel
var channel = new Channel();
var channel = new Channel(true);
channel.FromJson(_programSettings.DefaultChannelSettings.ToJson(), true);
channel.Changed += ChannelOnChanged;
lock (_settings)
Expand Down Expand Up @@ -1189,7 +1189,7 @@ private void SplitChannel(object sender, EventArgs e)
}

// We clone the channel for the right side
var right = new Channel();
var right = new Channel(true);
var json = channel.ToJson();
right.FromJson(json, false);
right.Side = Channel.Sides.Right;
Expand Down
56 changes: 30 additions & 26 deletions SidWizPlus/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private class Settings
public bool AutoScaleIgnoreYm2413Percussion { get; set; }

// ReSharper disable once StringLiteralTypo
[Option("labelsfromvgm", Required = false, HelpText = "Attempt to label channels based on their (filename")]
[Option("labelsfromvgm", Required = false, HelpText = "Attempt to label channels based on their filename")]
public bool ChannelLabelsFromVgm { get; set; }

// ReSharper disable once StringLiteralTypo
Expand All @@ -107,8 +107,9 @@ private class Settings
// ReSharper disable once StringLiteralTypo
[Option("triggerlookahead", Required = false, HelpText = "Number of frames to allow the trigger to look ahead, zero means no lookahead", DefaultValue = 0)]
public int TriggerLookahead { get; set; }

// ReSharper disable once StringLiteralTypo
[Option("triggerlookaheadonfailure", Required = false, HelpText = "Number of frames to allow the trigger to look ahead when failing to find a match with the default", DefaultValue = 0)]
[Option("triggerlookaheadonfailure", Required = false, HelpText = "Number of frames to allow the trigger to look ahead when failing to find a match with the default", DefaultValue = 1)]
public int TriggerLookaheadOnFailureFrames { get; set; }

// ReSharper disable once StringLiteralTypo
Expand Down Expand Up @@ -316,30 +317,33 @@ static void Main(string[] args)
var channels = settings.InputFiles
.AsParallel()
.Select(filename =>
{
var channel = new Channel
{
Filename = filename,
LineColor = ParseColor(settings.LineColor),
LineWidth = settings.LineWidth,
FillColor = ParseColor(settings.FillColor),
FillBase = settings.FillBase,
Label = Channel.GuessNameFromMultidumperFilename(filename),
Algorithm = CreateTriggerAlgorithm(settings.TriggerAlgorithm),
TriggerLookaheadFrames = settings.TriggerLookahead,
TriggerLookaheadOnFailureFrames = settings.TriggerLookaheadOnFailureFrames,
ZeroLineWidth = settings.ZeroLineWidth,
ZeroLineColor = ParseColor(settings.ZeroLineColor),
LabelFont = settings.ChannelLabelsFont == null
? null
: new Font(settings.ChannelLabelsFont, settings.ChannelLabelsSize),
LabelColor = ParseColor(settings.ChannelLabelsColor),
HighPassFilter = settings.HighPass
};
channel.LoadDataAsync().Wait();
channel.ViewWidthInMilliseconds = settings.ViewWidthMs;
return channel;
}).Where(ch => ch.SampleCount > 0).ToList();
var channel = new Channel(false)
{
Filename = filename,
LineColor = ParseColor(settings.LineColor),
LineWidth = settings.LineWidth,
FillColor = ParseColor(settings.FillColor),
FillBase = settings.FillBase,
Label = Channel.GuessNameFromMultidumperFilename(filename),
Algorithm = CreateTriggerAlgorithm(settings.TriggerAlgorithm),
TriggerLookaheadFrames = settings.TriggerLookahead,
TriggerLookaheadOnFailureFrames = settings.TriggerLookaheadOnFailureFrames,
ZeroLineWidth = settings.ZeroLineWidth,
ZeroLineColor = ParseColor(settings.ZeroLineColor),
LabelFont = settings.ChannelLabelsFont == null
? null
: new Font(settings.ChannelLabelsFont, settings.ChannelLabelsSize),
LabelColor = ParseColor(settings.ChannelLabelsColor),
HighPassFilter = settings.HighPass
};
channel.LoadDataAsync().Wait();
// We can only set this when the file is loaded
channel.ViewWidthInMilliseconds = settings.ViewWidthMs;
return channel;
})
.Where(ch => ch.SampleCount > 0 && !ch.IsSilent)
.ToList();

if (settings.AutoScalePercentage > 0)
{
Expand Down Expand Up @@ -713,7 +717,7 @@ private static void Render(Settings settings, IReadOnlyCollection<Channel> chann
catch (Exception ex)
{
// Should mean it was cancelled
Console.WriteLine($"Rendering cancelled: {ex.Message}");
Console.WriteLine($"Rendering cancelled: {ex.Message}\n{ex}");
}
finally
{
Expand Down

0 comments on commit cb6c490

Please sign in to comment.