Skip to content

Commit

Permalink
Taking care of compiler warnings and bump version to 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
coraxx committed Apr 17, 2023
1 parent 999151b commit 5931ea6
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 80 deletions.
15 changes: 10 additions & 5 deletions MergeSynced/Analysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ public class Analysis
/// <param name="b">Dataset B</param>
/// <param name="c">Cross correlation</param>
/// <returns></returns>
public static void CrossCorrelation(float[] a, float[] b, out float[] c)
public static void CrossCorrelation(float[]? a, float[]? b, out float[]? c)
{
if (a == null || b == null)
{
c = null;
return;
}
// Both arrays must be same size, if not, take smaller count
int size = a.Length < b.Length ? a.Length : b.Length;

Expand Down Expand Up @@ -84,12 +89,12 @@ public static void CrossCorrelation(float[] a, float[] b, out float[] c)
}
}

public static double CalculateDelay(float[] corrData, int sampleRate)
public static double CalculateDelay(float[]? corrData, int sampleRate)
{
float max = corrData.Max();
int maxIndex = Array.IndexOf(corrData, max);
float max = corrData!.Max();
int maxIndex = Array.IndexOf(corrData!, max);
double resFromLeft = (double)maxIndex / sampleRate;
double resFromRight = (double)(corrData.Length - maxIndex) / sampleRate;
double resFromRight = (double)(corrData!.Length - maxIndex) / sampleRate;
Debug.WriteLine($"{resFromLeft}s _delay (from left)");
Debug.WriteLine($"{resFromRight}s _delay (from right)");

Expand Down
14 changes: 7 additions & 7 deletions MergeSynced/Audio/WavTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class WavTools
/// <param name="l">Output of left channel</param>
/// <param name="r">Output of right channel</param>
/// <returns>Details of wav file</returns>
public WavHeader ReadWav(string filename, out float[] l, out float[] r)
public WavHeader? ReadWav(string filename, out float[]? l, out float[]? r)
{
l = r = null;

Expand All @@ -26,7 +26,7 @@ public WavHeader ReadWav(string filename, out float[] l, out float[] r)
using (FileStream fs = File.Open(filename, FileMode.Open))
{
BinaryReader reader = new BinaryReader(fs);
WavHeader header = new WavHeader();
WavHeader? header = new WavHeader();

// chunk 0
// reading int 32 as 4 bytes/chars for debugging header
Expand Down Expand Up @@ -62,7 +62,7 @@ public WavHeader ReadWav(string filename, out float[] l, out float[] r)
}

// chunk 2 can have more header data before data
byte[] byteArray = null;
byte[]? byteArray = null;
int bytes = 0;
while (reader.BaseStream.Position != reader.BaseStream.Length)
{
Expand All @@ -86,7 +86,7 @@ public WavHeader ReadWav(string filename, out float[] l, out float[] r)
int nValues = bytes / bytesForSamples + 1;


float[] asFloat;
float[]? asFloat;
switch (header.BitDepth)
{
case 64:
Expand Down Expand Up @@ -161,7 +161,7 @@ public WavHeader ReadWav(string filename, out float[] l, out float[] r)
/// <param name="filename">Path to file name</param>
/// <param name="m">Output of left channel</param>
/// <returns>Details of wav file</returns>
public WavHeader ReadWav(string filename, out float[] m)
public WavHeader? ReadWav(string filename, out float[]? m)
{
m = null;

Expand All @@ -170,7 +170,7 @@ public WavHeader ReadWav(string filename, out float[] m)
using (FileStream fs = File.Open(filename, FileMode.Open))
{
BinaryReader reader = new BinaryReader(fs);
WavHeader header = new WavHeader();
WavHeader? header = new WavHeader();

// chunk 0
// reading int 32 as 4 bytes/chars for debugging header
Expand Down Expand Up @@ -206,7 +206,7 @@ public WavHeader ReadWav(string filename, out float[] m)
}

// chunk 2 can have more header data before data
byte[] byteArray = null;
byte[]? byteArray = null;
int bytes = 0;
while (reader.BaseStream.Position != reader.BaseStream.Length)
{
Expand Down
8 changes: 4 additions & 4 deletions MergeSynced/Controls/CheckBoxMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class CheckBoxMedia: INotifyPropertyChanged
private SolidColorBrush _typeBrush = new SolidColorBrush(Colors.Gray);
private bool _isSelected;
private string _description = string.Empty;
private string _languageId = string.Empty;
private string _codecType = string.Empty;
private string? _languageId = string.Empty;
private string? _codecType = string.Empty;
private int _index = -1;

public SolidColorBrush TypeBrush
Expand Down Expand Up @@ -44,7 +44,7 @@ public string Description
}
}

public string LanguageId
public string? LanguageId
{
get => _languageId;
set
Expand All @@ -54,7 +54,7 @@ public string LanguageId
}
}

public string CodecType
public string? CodecType
{
get => _codecType;
set
Expand Down
8 changes: 4 additions & 4 deletions MergeSynced/MergeSynced.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<PublishSingleFile>true</PublishSingleFile>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>Assets\MergeSyncedLogoSimple.ico</ApplicationIcon>
<AssemblyVersion>2.0.1.0</AssemblyVersion>
<FileVersion>2.0.1</FileVersion>
<CFBundleVersion>2.0.1</CFBundleVersion>
<CFBundleShortVersionString>2.0.1</CFBundleShortVersionString>
<CFBundleName>MergeSynced</CFBundleName>
<CFBundleDisplayName>MergeSynced</CFBundleDisplayName>
<CFBundleExecutable>MergeSynced</CFBundleExecutable>
<CFBundleIdentifier>com.coraxx.mergesynced</CFBundleIdentifier>
<CFBundlePackageType>APPL</CFBundlePackageType>
<CFBundleSignature>????</CFBundleSignature>
<CFBundleVersion>2.0.0</CFBundleVersion>
<CFBundleShortVersionString>2.0.0</CFBundleShortVersionString>
<CFBundleIconFile>Assets/MergeSyncedLogoSimple.icns</CFBundleIconFile>
<NSHighResolutionCapable>true</NSHighResolutionCapable>
</PropertyGroup>
Expand Down
42 changes: 21 additions & 21 deletions MergeSynced/Tools/ExternalProcesses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class ExternalProcesses
{
#region Fields

public Process FfmpegProcess;
public Process FfprobeProcess;
public Process? FfmpegProcess;
public Process? FfprobeProcess;
public bool FfmpegWasAborted;

public Process MkvmergeProcess;
public Process MkvmergeProcess = null!;
public bool MkvmergeWasAborted;

#endregion
Expand Down Expand Up @@ -118,7 +118,7 @@ public void CallFfprobe(string filePath, string workingDir = @"C:\temp")
FfprobeProcess.BeginErrorReadLine();
}

public bool ParseFfprobeJson(MediaData md)
public bool ParseFfprobeJson(MediaData? md)
{
if (md == null) return false;
md.Clear();
Expand All @@ -127,19 +127,19 @@ public bool ParseFfprobeJson(MediaData md)
{
JObject json = JObject.Parse(_probeJson.ToString());

if (json["format"] == null || json["streams"] == null || json["format"]["duration"] == null) return false;
if (json["format"] == null || json["streams"] == null || json["format"]?["duration"] == null) return false;

// Get length of file
md.Duration = TimeSpan.FromSeconds(Convert.ToDouble(json["format"]["duration"].ToString(), new CultureInfo("en-us")));
md.Duration = TimeSpan.FromSeconds(Convert.ToDouble(json["format"]?["duration"]?.ToString(), new CultureInfo("en-us")));

bool audioTrackSelected = false;

foreach (JToken stream in json["streams"])
foreach (JToken stream in json["streams"]!)
{
string language = string.Empty;
string? language = string.Empty;
if (stream["tags"] != null)
{
if (stream["tags"]["language"] != null) language = stream["tags"]["language"].ToString();
if (stream["tags"]?["language"] != null) language = stream["tags"]?["language"]?.ToString();
}
else
{
Expand Down Expand Up @@ -263,7 +263,7 @@ public bool AbortMerge()
{
MkvmergeProcess.Close();
MkvmergeProcess.Dispose();
MkvmergeProcess = null;
MkvmergeProcess = null!;
}

MkvmergeWasAborted = true;
Expand Down Expand Up @@ -301,7 +301,7 @@ public void CallMkvmerge(string args, DataReceivedEventHandler outputHandler, st
{
MkvmergeProcess.Close();
MkvmergeProcess.Dispose();
MkvmergeProcess = null;
MkvmergeProcess = null!;
}
}

Expand Down Expand Up @@ -331,7 +331,7 @@ public void CallMkvmerge(string args, DataReceivedEventHandler outputHandler, st
MkvmergeProcess.BeginErrorReadLine();
}

public bool ParseMkvmergeJson(MediaData md)
public bool ParseMkvmergeJson(MediaData? md)
{
if (md == null) return false;
md.Clear();
Expand All @@ -343,24 +343,24 @@ public bool ParseMkvmergeJson(MediaData md)
if (json["tracks"] == null) return false;

// Get length of file
string duration = string.Empty;
string? duration = string.Empty;
if (json["container"]?["properties"]?["duration"] != null)
duration = json["container"]["properties"]["duration"].ToString();
duration = json["container"]?["properties"]?["duration"]?.ToString();
// ReSharper disable once PossibleLossOfFraction
if (duration != string.Empty) md.Duration = TimeSpan.FromSeconds(Convert.ToInt32(duration.Substring(0, duration.Length - 6)) / 1000); // ns -> ms -> s
if (duration != string.Empty) md.Duration = TimeSpan.FromSeconds(Convert.ToInt32(duration?.Substring(0, duration.Length - 6)) / 1000); // ns -> ms -> s

bool audioTrackSelected = false;

foreach (JToken stream in json["tracks"])
foreach (JToken stream in json["tracks"]!)
{
CheckBoxMedia cb = new CheckBoxMedia
{
IsSelected = md.IsMainMedia
};
string codecName = stream["codec"]?.ToString();
string? codecName = stream["codec"]?.ToString();
if (stream["properties"] != null)
{
if (stream["properties"]["language"] != null) cb.LanguageId = stream["properties"]["language"].ToString();
if (stream["properties"]?["language"] != null) cb.LanguageId = stream["properties"]?["language"]?.ToString();
}
else
{
Expand Down Expand Up @@ -403,9 +403,9 @@ public bool ParseMkvmergeJson(MediaData md)
{
if (json["chapters"] != null)
{
foreach (JToken stream in json["chapters"])
foreach (JToken stream in json["chapters"]!)
{
if (stream["num_entries"] == null || stream["num_entries"].ToObject<int>() <= 0) continue;
if (stream["num_entries"] == null || stream["num_entries"]!.ToObject<int>() <= 0) continue;
CheckBoxMedia cb = new CheckBoxMedia
{
IsSelected = md.IsMainMedia,
Expand All @@ -421,7 +421,7 @@ public bool ParseMkvmergeJson(MediaData md)

if (json["attachments"] != null)
{
foreach (JToken stream in json["attachments"])
foreach (JToken stream in json["attachments"]!)
{
if (stream["file_name"] == null || stream["id"] == null) continue;
CheckBoxMedia cb = new CheckBoxMedia
Expand Down
4 changes: 2 additions & 2 deletions MergeSynced/Tools/ProcessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void ProcessExited(object sender, EventArgs e)
}

process.EnableRaisingEvents = true;
process.Exited += ProcessExited;
process.Exited += ProcessExited!;

try
{
Expand All @@ -38,7 +38,7 @@ void ProcessExited(object sender, EventArgs e)
}
finally
{
process.Exited -= ProcessExited;
process.Exited -= ProcessExited!;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions MergeSynced/ViewModels/MergeSyncedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class MergeSyncedViewModel : ViewModelBase

#region Items

public MediaData MediaDataA { get; } = new MediaData { IsMainMedia = true };
public MediaData? MediaDataA { get; } = new MediaData { IsMainMedia = true };

public MediaData MediaDataB { get; } = new MediaData { IsMainMedia = false };
public MediaData? MediaDataB { get; } = new MediaData { IsMainMedia = false };

#endregion

Expand Down
Loading

0 comments on commit 5931ea6

Please sign in to comment.