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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AudioViewModel.cs" company="HandBrake Project (http://handbrake.fr)">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// The Audio View Model
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.ViewModels
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Linq;
using Caliburn.Micro;
using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Model.Encoding;
using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.Interop.Model.Encoding;
using HandBrakeWPF.ViewModels.Interfaces;
/// <summary>
/// The Audio View Model
/// </summary>
[Export(typeof(IAudioViewModel))]
public class AudioViewModel : ViewModelBase, IAudioViewModel
{
/// <summary>
/// Initializes a new instance of the <see cref="AudioViewModel"/> class.
/// </summary>
/// <param name="windowManager">
/// The window manager.
/// </param>
/// <param name="userSettingService">
/// The user Setting Service.
/// </param>
public AudioViewModel(IWindowManager windowManager, IUserSettingService userSettingService)
{
this.AudioTracks = new ObservableCollection<AudioTrack>();
this.SampleRates = new ObservableCollection<string> { "Auto", "48", "44.1", "32", "24", "22.05" };
this.AudioBitrates = this.GetAppropiateBitrates(AudioEncoder.ffaac, Mixdown.DolbyProLogicII);
this.AudioEncoders = EnumHelper<AudioEncoder>.GetEnumList();
this.AudioMixdowns = EnumHelper<Mixdown>.GetEnumList();
}
/// <summary>
/// Gets or sets AudioTracks.
/// </summary>
public ObservableCollection<AudioTrack> AudioTracks { get; set; }
/// <summary>
/// Gets or sets SourceTracks.
/// </summary>
public IEnumerable<Audio> SourceTracks { get; set; }
/// <summary>
/// Gets or sets AudioEncoders.
/// </summary>
public IEnumerable<AudioEncoder> AudioEncoders { get; set; }
/// <summary>
/// Gets or sets AudioMixdowns.
/// </summary>
public IEnumerable<Mixdown> AudioMixdowns { get; set; }
/// <summary>
/// Gets or sets SampleRates.
/// </summary>
public IEnumerable<string> SampleRates { get; set; }
/// <summary>
/// Gets or sets AudioBitrates.
/// </summary>
public IEnumerable<int> AudioBitrates { get; set; }
/// <summary>
/// Add an Audio Track
/// </summary>
public void Add()
{
if (SourceTracks != null)
{
Audio track = this.SourceTracks.FirstOrDefault();
if (track != null)
{
this.AudioTracks.Add(new AudioTrack { ScannedTrack = track });
}
}
}
/// <summary>
/// Remove the Selected Track
/// </summary>
/// <param name="track">
/// The track.
/// </param>
public void Remove(AudioTrack track)
{
this.AudioTracks.Remove(track);
}
/// <summary>
/// Set the Source Title
/// </summary>
/// <param name="title">
/// The title.
/// </param>
/// <param name="preset">
/// The preset.
/// </param>
/// <param name="task">
/// The task.
/// </param>
public void SetSource(Title title, Preset preset, EncodeTask task)
{
this.SourceTracks = title.AudioTracks;
}
/// <summary>
/// Setup this tab for the specified preset.
/// </summary>
/// <param name="preset">
/// The preset.
/// </param>
public void SetPreset(Preset preset)
{
if (preset != null && preset.Task != null)
{
// Store the previously selected tracks
List<Audio> selectedTracks = this.AudioTracks.Select(track => track.ScannedTrack).ToList();
this.AudioTracks.Clear();
// Add the tracks from the preset
foreach (AudioTrack track in preset.Task.AudioTracks)
{
this.AudioTracks.Add(new AudioTrack(track));
}
// Attempt to restore the previously selected tracks.
// or fallback to the first source track.
foreach (AudioTrack track in this.AudioTracks)
{
if (selectedTracks.Count != 0)
{
track.ScannedTrack = selectedTracks[0];
selectedTracks.RemoveAt(0);
}
else
{
if (this.SourceTracks != null)
{
track.ScannedTrack = this.SourceTracks.FirstOrDefault();
}
}
}
}
}
/// <summary>
/// Get Appropiate Bitrates for the selected encoder and mixdown.
/// </summary>
/// <param name="encoder">
/// The encoder.
/// </param>
/// <param name="mixdown">
/// The mixdown.
/// </param>
/// <returns>
/// A List of valid audio bitrates
/// </returns>
private IEnumerable<int> GetAppropiateBitrates(AudioEncoder encoder, Mixdown mixdown)
{
return new ObservableCollection<int> { 32, 40, 48, 56, 64, 80, 96, 112, 128, 160 };
}
}
}
|