Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions Editors/Audio/AudioEditor/Commands/PlayAudioFileCommand.cs

This file was deleted.

3 changes: 1 addition & 2 deletions Editors/Audio/AudioEditor/Commands/SetAudioFilesCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Editors.Audio.AudioEditor.Core;
using Editors.Audio.AudioEditor.Events;
using Editors.Audio.AudioEditor.Presentation.Shared;
Expand All @@ -17,7 +16,7 @@ public class SetAudioFilesCommand(IAudioEditorStateService audioEditorStateServi
private readonly IEventHub _eventHub = eventHub;
private readonly IAudioRepository _audioRepository = audioRepository;

public void Execute(ObservableCollection<AudioFilesTreeNode> selectedAudioFiles, bool addToExistingAudioFiles)
public void Execute(List<AudioFilesTreeNode> selectedAudioFiles, bool addToExistingAudioFiles)
{
var usedSourceIds = new HashSet<uint>();
var audioProject = _audioEditorStateService.AudioProject;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Collections.Generic;

namespace Editors.Audio.AudioEditor.Events
{
public record AudioFilesExplorerNodeSelectedEvent(List<string> WavFilePaths);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace Editors.Audio.AudioEditor.Events
{
public record AddToWaveformCacheRequestedEvent(List<string> FilePaths);
public record CacheWaveformRequestedEvent(List<string> FilePaths);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace Editors.Audio.AudioEditor.Events
{
public record RemoveFromWaveformCacheRequestedEvent(List<string> FilePaths);
public record DecacheWaveformRequestedEvent(List<string> FilePaths);
}

This file was deleted.

6 changes: 6 additions & 0 deletions Editors/Audio/AudioEditor/Events/PlayAudioRequestedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Collections.Generic;

namespace Editors.Audio.AudioEditor.Events
{
public record PlayAudioRequestedEvent(List<string> WavFilePaths);
}
19 changes: 13 additions & 6 deletions Editors/Audio/AudioEditor/Presentation/AudioEditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@
Height="Auto"/>
<RowDefinition
Height="*"/>
<!--
Commented out until Waveform visuliser is intended to be displayed
<RowDefinition
Height="Auto"/>
-->
<RowDefinition
Height="161"/>
</Grid.RowDefinitions>

<AudioProjectExplorer:AudioProjectExplorerView
Expand All @@ -134,11 +133,19 @@
Grid.Column="0"
DataContext="{Binding AudioFilesExplorerViewModel}"/>

<WaveformVisualiser:WaveformVisualiserView
<GridSplitter
Grid.Row="3"
Height="5"
Background="{DynamicResource App.Border}"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
ResizeBehavior="PreviousAndNext"
ResizeDirection="Rows"/>

<WaveformVisualiser:WaveformVisualiserView
Grid.Row="4"
Grid.Column="0"
DataContext="{Binding WaveformVisualiserViewModel}"
Visibility="Hidden"/>
DataContext="{Binding WaveformVisualiserViewModel}"/>
</Grid>
</Grid>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Editors.Audio.AudioEditor.Presentation.AudioFilesExplorer;
using System.Windows.Media;
using Editors.Audio.AudioEditor.Presentation.Shared;

namespace Editors.Audio.AudioEditor.Presentation.AudioFilesExplorer
{
Expand All @@ -16,6 +17,21 @@ public AudioFilesExplorerView()

private void OnClearButtonClick(object sender, RoutedEventArgs e) => FilterTextBoxItem.Focus();

private void OnNodeDoubleClick(object sender, MouseButtonEventArgs e) => ViewModel.PlayWav();
private void OnNodeDoubleClick(object sender, MouseButtonEventArgs e)
{
var source = e.OriginalSource as DependencyObject;
while (source != null && source is not TreeViewItem)
source = VisualTreeHelper.GetParent(source);

var treeViewItem = source as TreeViewItem;
if (treeViewItem?.DataContext is not AudioFilesTreeNode node)
return;

if (node.Type == AudioFilesTreeNodeType.WavFile)
{
ViewModel.PlayWav();
e.Handled = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public AudioFilesExplorerViewModel(
AudioFilesTree = _audioFilesTreeBuilder.BuildTree(editablePack);
SetupIsExpandedHandlers(AudioFilesTree);

CacheRootWavFilesInWaveformVisualiser();
CacheRootWaveformVisualisations();
}

private void SetupIsExpandedHandlers(ObservableCollection<AudioFilesTreeNode> nodes)
Expand All @@ -90,7 +90,7 @@ private void SetupIsExpandedHandlers(ObservableCollection<AudioFilesTreeNode> no
}
}

private void CacheRootWavFilesInWaveformVisualiser()
private void CacheRootWaveformVisualisations()
{
var wavFilePaths = new List<string>();
foreach (var node in AudioFilesTree)
Expand All @@ -100,7 +100,7 @@ private void CacheRootWavFilesInWaveformVisualiser()
}

if (wavFilePaths.Count > 0)
_eventHub.Publish(new AddToWaveformCacheRequestedEvent(wavFilePaths));
_eventHub.Publish(new CacheWaveformRequestedEvent(wavFilePaths));
}

private void OnNodeIsExpandedChanged(object sender, bool isExpanded)
Expand All @@ -119,9 +119,9 @@ private void OnNodeIsExpandedChanged(object sender, bool isExpanded)
return;

if (isExpanded)
_eventHub.Publish(new AddToWaveformCacheRequestedEvent(wavFilePaths));
_eventHub.Publish(new CacheWaveformRequestedEvent(wavFilePaths));
else
_eventHub.Publish(new RemoveFromWaveformCacheRequestedEvent(wavFilePaths));
_eventHub.Publish(new DecacheWaveformRequestedEvent(wavFilePaths));
}
}

Expand All @@ -145,64 +145,56 @@ private void OnPackFileContainerSetAsMainEditable(PackFileContainer packFileCont
private void RefreshAudioFilesTree(PackFileContainer packFileContainer)
{
AudioFilesTree = _audioFilesTreeBuilder.BuildTree(packFileContainer);
CacheRootWavFilesInWaveformVisualiser();
CacheRootWaveformVisualisations();
}

private void OnSelectedTreeNodesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
SetSelectedTreeNodes(e);
var selectedWavNodes = GetSelectedWavNodes();

if (SelectedTreeNodes.Count == 1)
if (selectedWavNodes != null && selectedWavNodes.Count == 1)
{
var selectedNode = e.NewItems[0] as AudioFilesTreeNode;
if (selectedNode.Type == AudioFilesTreeNodeType.WavFile)
{
var selectedAudioFile = SelectedTreeNodes[0];
_eventHub.Publish(new DisplayWaveformVisualiserRequestedEvent(selectedAudioFile.FilePath));
}
var wavFilePaths = new List<string> { selectedWavNodes[0].FilePath };
_eventHub.Publish(new AudioFilesExplorerNodeSelectedEvent(wavFilePaths));
}

SetButtonEnablement();
}

private void SetSelectedTreeNodes(NotifyCollectionChangedEventArgs e)
private List<AudioFilesTreeNode> GetSelectedWavNodes()
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (AudioFilesTreeNode addedNode in e.NewItems)
{
if (addedNode.Type != AudioFilesTreeNodeType.WavFile)
SelectedTreeNodes.Remove(addedNode);
}
}
if (SelectedTreeNodes == null || SelectedTreeNodes.Count == 0)
return [];

var result = new List<AudioFilesTreeNode>();
foreach (var node in SelectedTreeNodes)
if (node.Type == AudioFilesTreeNodeType.WavFile)
result.Add(node);
return result;
}

private void SetButtonEnablement()
{
IsPlayAudioButtonEnabled = SelectedTreeNodes.Count == 1;
var selectedWavNodes = GetSelectedWavNodes();
IsPlayAudioButtonEnabled = selectedWavNodes.Count == 1;

var selectedAudioProjectExplorerNode = _audioEditorStateService.SelectedAudioProjectExplorerNode;
if (selectedAudioProjectExplorerNode == null)
return;

if (SelectedTreeNodes.Count > 0)
if (selectedWavNodes.Count > 0)
{
if (selectedAudioProjectExplorerNode.Type == AudioProjectTreeNodeType.ActionEventType
|| selectedAudioProjectExplorerNode.Type == AudioProjectTreeNodeType.DialogueEvent)
{
IsSetAudioFilesButtonEnabled = true;

if (_audioEditorStateService.AudioFiles.Count > 0)
IsAddAudioFilesButtonEnabled = true;
else
IsAddAudioFilesButtonEnabled = false;
IsAddAudioFilesButtonEnabled = _audioEditorStateService.AudioFiles.Count > 0;
return;
}
}
else
{
IsSetAudioFilesButtonEnabled = false;
IsAddAudioFilesButtonEnabled = false;
}

IsSetAudioFilesButtonEnabled = false;
IsAddAudioFilesButtonEnabled = false;
}

partial void OnFilterQueryChanged(string value) => DebounceFilterAudioFilesTreeForFilterQuery();
Expand Down Expand Up @@ -250,17 +242,32 @@ private static void ToggleNodeExpansion(AudioFilesTreeNode node, bool shouldExpa
ToggleNodeExpansion(child, shouldExpand);
}

[RelayCommand] public void SetAudioFiles() => _uiCommandFactory.Create<SetAudioFilesCommand>().Execute(SelectedTreeNodes, false);
[RelayCommand] public void SetAudioFiles()
{
var selectedWavs = GetSelectedWavNodes();
if (selectedWavs.Count == 0)
return;

[RelayCommand] public void AddToAudioFiles() => _uiCommandFactory.Create<SetAudioFilesCommand>().Execute(SelectedTreeNodes, true);
_uiCommandFactory.Create<SetAudioFilesCommand>().Execute(selectedWavs, false);
}

[RelayCommand] public void AddToAudioFiles()
{
var selectedWavs = GetSelectedWavNodes();
if (selectedWavs.Count == 0)
return;

_uiCommandFactory.Create<SetAudioFilesCommand>().Execute(selectedWavs, true);
}

[RelayCommand] public void PlayWav()
{
if (!IsPlayAudioButtonEnabled)
var selectedWavNodes = GetSelectedWavNodes();
if (selectedWavNodes == null || selectedWavNodes.Count != 1)
return;

var selectedAudioFile = SelectedTreeNodes[0];
_uiCommandFactory.Create<PlayAudioFileCommand>().Execute(selectedAudioFile.FileName, selectedAudioFile.FilePath);
var wavFilePaths = new List<string> { selectedWavNodes[0].FilePath };
_eventHub.Publish(new PlayAudioRequestedEvent(wavFilePaths));
}

[RelayCommand] public void ClearText() => FilterQuery = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Editors.Audio.AudioEditor.Commands;
using Editors.Audio.AudioEditor.Core;
using Editors.Audio.AudioEditor.Events;
using Editors.Audio.AudioEditor.Presentation.Shared;
Expand Down Expand Up @@ -517,7 +516,8 @@ private void SetAudioFilesFromViewerItem(List<AudioFile> audioFiles, bool isRowE

[RelayCommand] public void PlayWav(AudioFile audioFile)
{
_uiCommandFactory.Create<PlayAudioFileCommand>().Execute(audioFile.WavPackFileName, audioFile.WavPackFilePath);
var wavFilePaths = new List<string> { audioFile.WavPackFilePath };
_eventHub.Publish(new PlayAudioRequestedEvent(wavFilePaths));
}

private void SetInitialSettings()
Expand Down
Loading
Loading