From 07ac99f03b808c482241f98db2ee3a4758f1a7bd Mon Sep 17 00:00:00 2001 From: towsey Date: Tue, 21 Apr 2020 15:56:51 +1000 Subject: [PATCH] Update AcousticEvent.cs Issue #297 Create new constructor for ACousticEvent class to init with a track. --- src/AudioAnalysisTools/AcousticEvent.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/AudioAnalysisTools/AcousticEvent.cs b/src/AudioAnalysisTools/AcousticEvent.cs index 6f3a800db..944ec7b54 100644 --- a/src/AudioAnalysisTools/AcousticEvent.cs +++ b/src/AudioAnalysisTools/AcousticEvent.cs @@ -252,6 +252,29 @@ public AcousticEvent(TimeSpan segmentStartOffset, double eventStartSegmentRelati this.Oblong = null; } + /// + /// Initializes a new instance of the class. + /// This constructor is passed a track. + /// NOTE: The track is already in time relative to recording start. + /// + public AcousticEvent(TimeSpan segmentStartOffset, Track track) + : this() + { + var eventStartSegmentRelative = track.StartTimeSeconds - segmentStartOffset.TotalSeconds; + var eventEndSegmentRelative = eventStartSegmentRelative + track.TrackDurationSeconds; + this.SetEventPositionRelative(segmentStartOffset, eventStartSegmentRelative, eventEndSegmentRelative); + this.LowFrequencyHertz = track.LowFreqHertz; + this.HighFrequencyHertz = track.HighFreqHertz; + //this.SegmentDurationSeconds = frameCount * frameStep; + this.tracks = new List + { + track, + }; + + // have no info to convert time/Hz values to coordinates + this.Oblong = null; + } + /// /// Initializes a new instance of the class. /// This constructor currently works ONLY for linear Hertz scale events.