90 lines
No EOL
3.3 KiB
C#
90 lines
No EOL
3.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using JD.Audio.Annotations;
|
|
using JD.Audio.Sound;
|
|
using JD.Collections.Extensions;
|
|
using JD.MessageService;
|
|
using TeaBox;
|
|
using TeaBox.Gui;
|
|
|
|
namespace TempoBlaster.Model
|
|
{
|
|
/// <summary>
|
|
/// Resolves conflicts when the beats in the wave does not fit the beats in the trk.
|
|
/// </summary>
|
|
public class MarkerConflictsResolver
|
|
{
|
|
private readonly Wave _wave;
|
|
private readonly IList<Beat> _originalWaveMarkers;
|
|
|
|
public MarkerConflictsResolver(Wave wave, IList<Beat> originalWaveMarkers)
|
|
{
|
|
_wave = wave;
|
|
_originalWaveMarkers = originalWaveMarkers;
|
|
}
|
|
|
|
public void Resolve()
|
|
{
|
|
if (IsWaveRemastered)
|
|
{
|
|
MessageDialog dialog = new MessageDialog();
|
|
dialog.MainIcon = MessageDialogIcon.Warning;
|
|
dialog.MainMessage = "The wave doesn't have any marker.";
|
|
|
|
var useTrkMarkers = dialog.AddButton("Update the wave with the trk markers");
|
|
useTrkMarkers.Content = "Wave will be updated with the markers found in the trk";
|
|
|
|
var fixLater = dialog.AddButton("I will fix later");
|
|
fixLater.Content = "Keep wave without markers.";
|
|
|
|
var response = dialog.ShowDialog();
|
|
if (response == useTrkMarkers)
|
|
{
|
|
_originalWaveMarkers.AddRange(_wave.Annotations.Markers);
|
|
MarkerExporter.Export(_wave);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (_originalWaveMarkers.Count == 0)
|
|
{
|
|
MessageService.ShowWarning("This wave file does not contain any marker. Will open with the track markers. Make sure to fix the wave.");
|
|
return;
|
|
}
|
|
|
|
if (HasConflicts)
|
|
{
|
|
MessageDialog dialog = new MessageDialog();
|
|
dialog.MainIcon = MessageDialogIcon.Warning;
|
|
dialog.MainMessage = "The markers in the track does not correspond with the markers in the wave.";
|
|
|
|
var useWaveMarkers = dialog.AddButton("Update the track with the wave markers");
|
|
useWaveMarkers.Content = "Track document will contain the new marker informations. You may need to adjust annotations to match the new markers.";
|
|
|
|
var fixLater = dialog.AddButton("I will fix later");
|
|
fixLater.Content = "Keep using local track values. User will still need to update the track with the wave markers later.";
|
|
|
|
var response = dialog.ShowDialog();
|
|
if (response == useWaveMarkers)
|
|
{
|
|
using (_wave.Annotations.BeginUpdate())
|
|
{
|
|
_wave.Annotations.Markers.Clear();
|
|
_wave.Annotations.Markers.AddRange(_originalWaveMarkers);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool HasConflicts
|
|
{
|
|
get { return !_originalWaveMarkers.Select(x => x.Sample).SequenceEqual(_wave.Annotations.Markers.Select(x => x.Sample)); }
|
|
}
|
|
|
|
private bool IsWaveRemastered
|
|
{
|
|
get { return _originalWaveMarkers.Count == 0 && _wave.Annotations.Markers.Count > 0; }
|
|
}
|
|
}
|
|
} |