Skip to content

Commit

Permalink
👍 Add Import(IEnumerable<Track>) to TrackBaseSound
Browse files Browse the repository at this point in the history
  • Loading branch information
AutumnSky1010 committed Dec 4, 2024
1 parent fa76ee1 commit ea42889
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/SoundMaker/Sounds/TrackBaseSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TrackBaseSound(SoundFormat format, int tempo)
/// トラックを管理する辞書<br/>
/// 開始時間(ミリ秒)とトラック(複数)のペア
/// </summary>
private readonly Dictionary<int, List<Track>> _tracksTimeMap = [];
private Dictionary<int, List<Track>> _tracksTimeMap = [];

/// <summary>
/// Creates a new track with the specified wave type and start time. <br/>
Expand Down Expand Up @@ -304,4 +304,27 @@ private static short[] NormalizeAndClamp(double[] wave)
return (short)Math.Clamp(scaledSample, MinValue, MaxValue);
}).ToArray();
}

/// <summary>
/// Imports tracks into the internal map based on their start times. <br/>
/// トラックを開始時間に基づいて内部のマップにインポートするメソッド。
/// </summary>
/// <param name="from">The tracks to import. <br/> インポートするトラック。</param>
public void Import(IEnumerable<Track> from)
{
var map = new Dictionary<int, List<Track>>();
foreach (var track in from)
{
if (map.TryGetValue(track.StartMilliSecond, out var tracks))
{
tracks.Add(track);
}
else
{
map.Add(track.StartMilliSecond, [track]);
}
}

_tracksTimeMap = map;
}
}

0 comments on commit ea42889

Please sign in to comment.