1 // --------------------------------------------------------------------------------------------------------------------
2 // <copyright file="Audio.cs" company="HandBrake Project (http://handbrake.fr)">
3 //   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
4 // </copyright>
5 // <summary>
6 //   An object representing an AudioTrack associated with a Title, in a DVD
7 // </summary>
8 // --------------------------------------------------------------------------------------------------------------------
9 
10 namespace HandBrakeWPF.Services.Scan.Model
11 {
12     using System;
13 
14     /// <summary>
15     /// An object representing an AudioTrack associated with a Title, in a DVD
16     /// </summary>
17     [Serializable]
18     public class Audio
19     {
20         /// <summary>
21         /// Initializes a new instance of the <see cref="Audio"/> class.
22         /// </summary>
Audio()23         public Audio()
24         {
25         }
26 
27         /// <summary>
28         /// Initializes a new instance of the <see cref="Audio"/> class.
29         /// </summary>
30         /// <param name="trackNumber">
31         /// The track number.
32         /// </param>
33         /// <param name="language">
34         /// The language.
35         /// </param>
36         /// <param name="languageCode">
37         /// The language code.
38         /// </param>
39         /// <param name="description">
40         /// The description.
41         /// </param>
42         /// <param name="codec">
43         /// The codec.
44         /// </param>
45         /// <param name="sampleRate">
46         /// The sample rate.
47         /// </param>
48         /// <param name="bitrate">
49         /// The bitrate.
50         /// </param>
51         /// <param name="channelLayout">
52         /// The channel Layout.
53         /// </param>
Audio(int trackNumber, string language, string languageCode, string description, int codec, int sampleRate, int bitrate, long channelLayout, string name)54         public Audio(int trackNumber, string language, string languageCode, string description, int codec, int sampleRate, int bitrate, long channelLayout, string name)
55         {
56             this.ChannelLayout = channelLayout;
57             this.Name = name;
58             this.TrackNumber = trackNumber;
59             this.Language = language;
60             this.LanguageCode = languageCode;
61             this.Description = description;
62             this.Codec = codec;
63             this.SampleRate = sampleRate;
64             this.Bitrate = bitrate;
65         }
66 
Audio(int trackNumber)67         public Audio(int trackNumber)
68         {
69             this.TrackNumber = trackNumber;
70         }
71 
72         /// <summary>
73         /// Gets or sets The track number of this Audio Track
74         /// </summary>
75         public int TrackNumber { get; set; }
76 
77         /// <summary>
78         /// Gets or sets The language (if detected) of this Audio Track
79         /// </summary>
80         public string Language { get; set; }
81 
82         /// <summary>
83         /// Gets or sets LanguageCode.
84         /// </summary>
85         public string LanguageCode { get; set; }
86 
87         /// <summary>
88         /// Gets or sets Description.
89         /// </summary>
90         public string Description { get; set; }
91 
92         /// <summary>
93         /// Gets or sets The primary format of this Audio Track
94         /// </summary>
95         public int Codec { get; set; }
96 
97         /// <summary>
98         /// Gets or sets The frequency (in MHz) of this Audio Track
99         /// </summary>
100         public int SampleRate { get; set; }
101 
102         /// <summary>
103         /// Gets or sets The bitrate (in kbps) of this Audio Track
104         /// </summary>
105         public int Bitrate { get; set; }
106 
107         /// <summary>
108         /// Gets or sets the channel layout of the source track (mixdown)
109         /// </summary>
110         public long ChannelLayout { get; set; }
111 
112         public string Name { get; set; }
113 
114         /// <summary>
115         /// Override of the ToString method to make this object easier to use in the UI
116         /// </summary>
117         /// <returns>A string formatted as: {track #} {language} ({format}) ({sub-format})</returns>
ToString()118         public override string ToString()
119         {
120             if (this.Description == "None Found")
121             {
122                 return this.Description;
123             }
124 
125             return string.Format("{0} {1}", this.TrackNumber, this.Description);
126         }
127 
128         /// <summary>
129         /// The equals.
130         /// </summary>
131         /// <param name="other">
132         /// The other.
133         /// </param>
134         /// <returns>
135         /// The System.Boolean.
136         /// </returns>
Equals(Audio other)137         public bool Equals(Audio other)
138         {
139             if (ReferenceEquals(null, other))
140             {
141                 return false;
142             }
143 
144             if (ReferenceEquals(this, other))
145             {
146                 return true;
147             }
148 
149             return other.TrackNumber == this.TrackNumber && object.Equals(other.Language, this.Language) && object.Equals(other.LanguageCode, this.LanguageCode) && object.Equals(other.Codec, this.Codec);
150         }
151 
152         /// <summary>
153         /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
154         /// </summary>
155         /// <returns>
156         /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
157         /// </returns>
158         /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>. </param><filterpriority>2</filterpriority>
Equals(object obj)159         public override bool Equals(object obj)
160         {
161             if (ReferenceEquals(null, obj))
162             {
163                 return false;
164             }
165 
166             if (ReferenceEquals(this, obj))
167             {
168                 return true;
169             }
170 
171             if (obj.GetType() != typeof(Audio))
172             {
173                 return false;
174             }
175 
176             return this.Equals((Audio)obj);
177         }
178 
179         /// <summary>
180         /// Serves as a hash function for a particular type.
181         /// </summary>
182         /// <returns>
183         /// A hash code for the current <see cref="T:System.Object"/>.
184         /// </returns>
185         /// <filterpriority>2</filterpriority>
GetHashCode()186         public override int GetHashCode()
187         {
188             unchecked
189             {
190                 int result = this.TrackNumber;
191                 result = (result * 397) ^ (this.Language != null ? this.Language.GetHashCode() : 0);
192                 result = (result * 397) ^ (this.LanguageCode != null ? this.LanguageCode.GetHashCode() : 0);
193                 result = (result * 397) ^ (this.Codec.GetHashCode());
194                 return result;
195             }
196         }
197     }
198 }