// Copyright (c) Arlo Godfrey. All Rights Reserved. // Licensed under the GNU Lesser General Public License, Version 3.0 with additional terms. // See the LICENSE, LICENSE.LESSER and LICENSE.ADDITIONAL files in the project root for more information. using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using CommunityToolkit.Diagnostics; using OwlCore.Extensions; using StrixMusic.Sdk.AppModels; using StrixMusic.Sdk.CoreModels; namespace StrixMusic.Sdk.AdapterModels { /// /// Merged multiple into a single /// public class MergedImage : IImage, IMergedMutable { private readonly ICoreImage _preferredSource; private readonly List _sources; /// /// Initializes a new instance of the class. /// public MergedImage(IReadOnlyList sources) { Guard.IsNotNull(sources, nameof(sources)); _sources = sources.ToList(); _preferredSource = _sources[0]; } /// public Uri Uri => _preferredSource.Uri; /// public double Height => _preferredSource.Height; /// public double Width => _preferredSource.Width; /// public IReadOnlyList Sources => _sources; /// public event EventHandler? SourcesChanged; /// public void AddSource(ICoreImage itemToMerge) { Guard.IsNotNull(itemToMerge, nameof(itemToMerge)); _sources.Add(itemToMerge); SourcesChanged?.Invoke(this, EventArgs.Empty); } /// public void RemoveSource(ICoreImage itemToRemove) { Guard.IsNotNull(itemToRemove, nameof(itemToRemove)); _sources.Remove(itemToRemove); SourcesChanged?.Invoke(this, EventArgs.Empty); } /// public bool Equals(ICoreImage other) { return other?.Uri == Uri; } /// public async ValueTask DisposeAsync() { await _sources.InParallel(x => x.DisposeAsync().AsTask()); } } }