Skip to content

Commit

Permalink
Fixed bugs in ALR
Browse files Browse the repository at this point in the history
ConfigFileResolver now better handles paths.

FileDateBehaviour parsing has  been restored. AP.exe now (restores previous behavior and) crashes if a file date is required in the filename but is not present.
  • Loading branch information
atruskie committed Nov 29, 2017
1 parent e586e94 commit 9a4e4ce
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 23 deletions.
15 changes: 4 additions & 11 deletions Acoustics/Acoustics.Shared/ConfigFile/ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,14 @@ public static bool TryResolveConfigFile(string file, IEnumerable<DirectoryEntry>

// this is a holdover from concrete file systems. The concept of a working directory has no real
// equivalent in a virtual file system but this is implemented for compatibility
var workingDirectory = Directory.GetCurrentDirectory().ToDirectoryEntry();
var localConfig = workingDirectory.CombineFile(file);
if (localConfig.Exists)
// GetFullPath should take care of relative paths relative to current working directory
var fullPath = Path.GetFullPath(file);
if (File.Exists(fullPath))
{
configFile = localConfig;
configFile = fullPath.ToFileEntry();
return true;
}

// if it does not exist
// and is rooted, it can't exist
if (Path.IsPathRooted(file))
{
return false;
}

if (searchPaths != null)
{
foreach (var directory in searchPaths)
Expand Down
4 changes: 2 additions & 2 deletions Acoustics/Acoustics.Test/Acoustics.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
<PostBuildEvent>rem copy configs
xcopy "$(SolutionDir)AnalysisConfigFiles" "$(TargetDir)ConfigFiles\" /S /Y</PostBuildEvent>
</PropertyGroup>
<Import Project="..\..\AudioAnalysis\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\AudioAnalysis\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,63 @@ public void TestAnalyzeSr64000Recording()
Assert.AreEqual(28, twoMapsImage.Width);
Assert.AreEqual(652, twoMapsImage.Height);
}

[TestMethod]
public void TestEnsuresFailureForNoDate()
{
var recordingPath = PathHelper.ResolveAsset("geckos.wav");

var configPath = PathHelper.ResolveConfigFile("Towsey.Acoustic.yml");
//var indexPropertiesFile = PathHelper.ResolveConfigFile("IndexPropertiesConfig.yml");
//indexPropertiesFile.CopyTo(Path.Combine(this.outputDirectory.FullName, "IndexPropertiesConfig.yml"));

// modify config file
// because of difficulties in dealing with dynamic config files, just edit the text file!!!!!
var configLines = File.ReadAllLines(configPath.FullName);
configLines[configLines.IndexOf(x => x.StartsWith("RequireDateInFilename:"))] = "RequireDateInFilename: true";

// write the edited Config file to temporary output directory
var newConfigPath = this.outputDirectory.CombineFile("Towsey.Acoustic.yml");
File.WriteAllLines(newConfigPath.FullName, configLines);

var arguments = new AnalyseLongRecording.Arguments
{
Source = recordingPath,
Config = newConfigPath,
Output = this.outputDirectory,
MixDownToMono = true,
};

Assert.ThrowsException<InvalidFileDateException>(() => AnalyseLongRecording.Execute(arguments));
}

[TestMethod]
public void TestEnsuresFailureWithAmbiguousDate()
{
var recordingPath = this.outputDirectory.CombineFile("20160801_110000_continuous1.wav");

var configPath = PathHelper.ResolveConfigFile("Towsey.Acoustic.yml");
//var indexPropertiesFile = PathHelper.ResolveConfigFile("IndexPropertiesConfig.yml");
//indexPropertiesFile.CopyTo(Path.Combine(this.outputDirectory.FullName, "IndexPropertiesConfig.yml"));

// modify config file
// because of difficulties in dealing with dynamic config files, just edit the text file!!!!!
var configLines = File.ReadAllLines(configPath.FullName);
configLines[configLines.IndexOf(x => x.StartsWith("RequireDateInFilename:"))] = "RequireDateInFilename: true";

// write the edited Config file to temporary output directory
var newConfigPath = this.outputDirectory.CombineFile("Towsey.Acoustic.yml");
File.WriteAllLines(newConfigPath.FullName, configLines);

var arguments = new AnalyseLongRecording.Arguments
{
Source = recordingPath,
Config = newConfigPath,
Output = this.outputDirectory,
MixDownToMono = true,
};

Assert.ThrowsException<InvalidFileDateException>(() => AnalyseLongRecording.Execute(arguments));
}
}
}
14 changes: 12 additions & 2 deletions AudioAnalysis/AnalysisBase/FileSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,21 @@ public FileSegment(FileInfo source, int sampleRate, TimeSpan duration, FileDateB
/// Implies `FileDateBehavior.Required`.
/// NOTE: Start offset will be set to start of file, and end offset set to the end of the file.
/// </summary>
public FileSegment(FileInfo source, TimeAlignment alignment, IAudioUtility utility = null)
public FileSegment(
FileInfo source,
TimeAlignment alignment,
IAudioUtility utility = null,
FileDateBehavior dateBehavior = FileDateBehavior.Try)
{
Contract.Requires(source != null);
if (alignment != TimeAlignment.None)
{
Contract.Requires(
dateBehavior == FileDateBehavior.Required,
"If TimeAlignment is required, a date must be required in the filename");
}

this.dateBehavior = alignment == TimeAlignment.None ? FileDateBehavior.Try : FileDateBehavior.Required;
this.dateBehavior = dateBehavior;
this.Source = source;
this.Alignment = alignment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static void Execute(Arguments arguments)

// 4. get the segment of audio to be analysed
// if tiling output, specify that FileSegment needs to be able to read the date
var fileSegment = new FileSegment(sourceAudio, arguments.AlignToMinute);
var fileSegment = new FileSegment(sourceAudio, arguments.AlignToMinute, null, defaultBehavior);
var bothOffsetsProvided = arguments.StartOffset.HasValue && arguments.EndOffset.HasValue;
if (bothOffsetsProvided)
{
Expand Down
7 changes: 1 addition & 6 deletions AudioAnalysis/AnalysisPrograms/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<add key="AudioUtilitySoxExe" value="audio-utils\sox\sox.exe" />
<add key="AudioUtilityShntoolExe" value="audio-utils\shntool\shntool.exe" />
<add key="AudioUtilityWav2PngExe" value="audio-utils\wav2png\wav2png.exe" />

<!-- Audio utility locations for linux -->
<add key="AudioUtilityFfmpegExeLinux" value="/usr/local/bin/ffmpeg" />
<add key="AudioUtilityFfprobeExeLinux" value="/usr/local/bin/ffprobe" />
Expand All @@ -18,18 +17,14 @@
<add key="AudioUtilitySoxExeLinux" value="/usr/bin/sox" />
<add key="AudioUtilityShntoolExeLinux" value="/usr/bin/shntool" />
<add key="AudioUtilityWav2PngExeLinux" value="/usr/local/bin/wav2png" />

<!-- Default target sample rate -->
<!-- chose this value because it is simple fraction (4/5) of 22050Hz -->
<!-- <add key="DefaultTargetSampleRate" value="17640" /> -->
<add key="DefaultTargetSampleRate" value="22050" />

<add key="StandardFileDateFormat" value="yyyyMMdd_HHmmsszzz" />
<add key="StandardFileDateFormatUtc" value="yyyyMMdd_HHmmssZ" />
<add key="StandardFileDateFormatSm2" value="yyyyMMdd_HHmmss" />

<add key="ClientSettingsProvider.ServiceUri" value="" />

<!--<add key="log4Net.Internal.Debug" value="true"/>-->
</appSettings>
<system.diagnostics>
Expand Down Expand Up @@ -90,4 +85,4 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public static FileInfo Find(dynamic configuration, FileInfo originalConfigFile)
return null;
}

return Find((string)configuration[AnalysisKeys.KeyIndexPropertiesConfig], originalConfigFile.ToFileEntry()).ToFileInfo();
return Find((string)configuration[AnalysisKeys.KeyIndexPropertiesConfig], originalConfigFile.ToFileEntry())?.ToFileInfo();
}

/// <summary>
Expand Down

0 comments on commit 9a4e4ce

Please sign in to comment.