Repository navigation
Expand file tree
/
Copy pathMainWindowViewModel.cs
More file actions
95 lines (81 loc) · 2.93 KB
/
Copy pathMainWindowViewModel.cs
File metadata and controls
95 lines (81 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using DevExpress.Mvvm;
using SamplePlayer.Controls;
namespace SamplePlayer
{
public class MainWindowViewModel : ViewModelBase
{
private string _root;
private ObservableCollection<SampleControlViewModel> _sampleControls;
private SampleControlViewModel _currentSample;
public SampleControlViewModel CurrentSample
{
get { return _currentSample; }
set
{
if (CurrentSample != null)
CurrentSample.StopPlayback();
SetProperty(ref _currentSample, value, () => CurrentSample);
if (CurrentSample != null)
CurrentSample.PlaySample();
}
}
public ObservableCollection<SampleControlViewModel> SampleControls
{
get { return _sampleControls; }
set { SetProperty(ref _sampleControls, value, () => SampleControls); }
}
public string Root
{
get { return _root; }
set { SetProperty(ref _root, value, () => Root); }
}
public Func<string> SelectRootFunction { get; set; }
public DelegateCommand SelectRootCommand { get; set; }
public DelegateCommand EnterPressedCommand { get; set; }
public DelegateCommand StopPlaybackCommand { get; set; }
public MainWindowViewModel()
{
SelectRootCommand = new DelegateCommand(SelectRoot);
SampleControls = new ObservableCollection<SampleControlViewModel>();
EnterPressedCommand = new DelegateCommand(LoadControls);
StopPlaybackCommand = new DelegateCommand(StopPlayback);
}
private void StopPlayback()
{
CurrentSample.StopPlayback();
}
private void SelectRoot()
{
string root = SelectRootFunction.Invoke();
if (String.IsNullOrEmpty(root))
return;
this.Root = root;
LoadControls();
}
private void LoadControls()
{
SampleControls = new ObservableCollection<SampleControlViewModel>();
string[] files = Directory.GetFiles(Root, "*.wav", SearchOption.AllDirectories);
foreach (var f in files)
{
var info = new FileInfo(f);
var sample = new SampleControlViewModel();
sample.FileSource = f;
sample.SampleName = info.Name;
sample.ShortFilePath = GetShortFilePath(info.FullName);
this.SampleControls.Add(sample);
}
}
private string GetShortFilePath(string fullname)
{
IEnumerable<string> f = fullname.Split('\\').Reverse().Take(2).Reverse();
string r = string.Join("\\", f.ToArray());
return r;
}
}
}