OSDN Git Service

first commit
[lamexp/LameXP.git] / src / Model_AudioFile.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2010 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Model_AudioFile.h"
23
24 #include <QTime>
25
26 ////////////////////////////////////////////////////////////
27 // Constructor & Destructor
28 ////////////////////////////////////////////////////////////
29
30 AudioFileModel::AudioFileModel(const QString &path, const QString &name)
31 {
32         m_filePath = path;
33         m_fileName = name;
34         m_fileYear = 0;
35         m_filePosition = 0;
36         m_fileDuration = 0;
37         m_formatAudioSamplerate = 0;
38         m_formatAudioChannels = 0;
39         m_formatAudioBitdepth = 0;
40 }
41
42 AudioFileModel::~AudioFileModel(void)
43 {
44 }
45
46 ////////////////////////////////////////////////////////////
47 // Public Functions
48 ////////////////////////////////////////////////////////////
49
50 // ---------------------------------
51 // Getter methods
52 // ---------------------------------
53
54 const QString &AudioFileModel::filePath(void) const
55 {
56         return m_filePath;
57 }
58
59 const QString &AudioFileModel::fileName(void) const
60 {
61         return m_fileName;
62 }
63
64 const QString &AudioFileModel::fileArtist(void) const
65 {
66         return m_fileArtist;
67 }
68
69 const QString &AudioFileModel::fileAlbum(void) const
70 {
71         return m_fileAlbum;
72 }
73
74 const QString &AudioFileModel::fileGenre(void) const
75 {
76         return m_fileGenre;
77 }
78
79 const QString &AudioFileModel::fileComment(void) const
80 {
81         return m_fileComment;
82 }
83
84 unsigned int AudioFileModel::fileYear(void) const
85 {
86         return m_fileYear;
87 }
88
89 unsigned int AudioFileModel::filePosition(void) const
90 {
91         return m_filePosition;
92 }
93
94 unsigned int AudioFileModel::fileDuration(void) const
95 {
96         return m_fileDuration;
97 }
98
99 const QString &AudioFileModel::formatContainerType(void) const
100 {
101         return m_formatContainerType;
102 }
103
104 const QString &AudioFileModel::formatContainerProfile(void) const
105 {
106         return m_formatContainerProfile;
107 }
108
109 const QString &AudioFileModel::formatAudioType(void) const
110 {
111         return m_formatAudioType;
112 }
113
114 const QString &AudioFileModel::formatAudioProfile(void) const
115 {
116         return m_formatAudioProfile;
117 }
118
119 const QString &AudioFileModel::formatAudioVersion(void) const
120 {
121         return m_formatAudioVersion;
122 }
123
124 unsigned int AudioFileModel::formatAudioSamplerate(void) const
125 {
126         return m_formatAudioSamplerate;
127 }
128
129 unsigned int AudioFileModel::formatAudioChannels(void) const
130 {
131         return m_formatAudioChannels;
132 }
133
134 unsigned int AudioFileModel::formatAudioBitdepth(void) const
135 {
136         return m_formatAudioBitdepth;
137 }
138
139 const QString AudioFileModel::fileDurationInfo(void) const
140 {
141         if(m_fileDuration)
142         {
143                 QTime time = QTime().addSecs(m_fileDuration);
144                 return time.toString("hh:mm:ss");
145         }
146         else
147         {
148                 return QString();
149         }
150 }
151
152 const QString AudioFileModel::formatContainerInfo(void) const
153 {
154         if(!m_formatContainerType.isEmpty())
155         {
156                 QString info = m_formatContainerType;
157                 if(!m_formatContainerProfile.isEmpty()) info.append(" (Profile: ").append(m_formatContainerProfile).append(")");
158                 return info;
159         }
160         else
161         {
162                 return QString();
163         }
164 }
165
166 const QString AudioFileModel::formatAudioBaseInfo(void) const
167 {
168         if(m_formatAudioSamplerate || m_formatAudioChannels || m_formatAudioBitdepth)
169         {
170                 QString info;
171                 if(m_formatAudioChannels)
172                 {
173                         if(!info.isEmpty()) info.append(", ");
174                         info.append("Channels: ").append(QString::number(m_formatAudioChannels));
175                 }
176                 if(m_formatAudioSamplerate)
177                 {
178                         if(!info.isEmpty()) info.append(", ");
179                         info.append("Samplerate: ").append(QString::number(m_formatAudioSamplerate)).append(" Hz");
180                 }
181                 if(m_formatAudioBitdepth)
182                 {
183                         if(!info.isEmpty()) info.append(", ");
184                         info.append("Bitdepth: ").append(QString::number(m_formatAudioBitdepth)).append(" Bit");
185                 }
186                 return info;
187         }
188         else
189         {
190                 return QString();
191         }
192 }
193
194 const QString AudioFileModel::formatAudioCompressInfo(void) const
195 {
196         if(!m_formatAudioType.isEmpty())
197         {
198                 QString info;
199                 if(!m_formatAudioProfile.isEmpty() || !m_formatAudioVersion.isEmpty())
200                 {
201                         info.append("Type: ");
202                 }
203                 info.append(m_formatAudioType);
204                 if(!m_formatAudioProfile.isEmpty())
205                 {
206                         info.append(", Profile: ").append(m_formatAudioProfile);
207                 }
208                 if(!m_formatAudioVersion.isEmpty())
209                 {
210                         info.append(", Version: ").append(m_formatAudioVersion);
211                 }
212                 return info;
213         }
214         else
215         {
216                 return QString();
217         }
218 }
219
220 // ---------------------------------
221 // Setter methods
222 // ---------------------------------
223
224 void AudioFileModel::setFilePath(const QString &path)
225 {
226         m_filePath = path;
227 }
228
229 void AudioFileModel::setFileName(const QString &name)
230 {
231         m_fileName = name;
232 }
233
234 void AudioFileModel::setFileArtist(const QString &artist)
235 {
236         m_fileArtist = artist;
237 }
238
239 void AudioFileModel::setFileAlbum(const QString &album)
240 {
241         m_fileAlbum = album;
242 }
243
244 void AudioFileModel::setFileGenre(const QString &genre)
245 {
246         m_fileGenre = genre;
247 }
248
249 void AudioFileModel::setFileComment(const QString &comment)
250 {
251         m_fileComment = comment;
252 }
253
254 void AudioFileModel::setFileYear(unsigned int year)
255 {
256         m_fileYear = year;
257 }
258
259 void AudioFileModel::setFilePosition(unsigned int position)
260 {
261         m_filePosition = position;
262 }
263
264 void AudioFileModel::setFileDuration(unsigned int duration)
265 {
266         m_fileDuration = duration;
267 }
268
269 void AudioFileModel::setFormatContainerType(const QString &type)
270 {
271         m_formatContainerType = type;
272 }
273
274 void AudioFileModel::setFormatContainerProfile(const QString &profile)
275 {
276         m_formatContainerProfile = profile;
277 }
278
279 void AudioFileModel::setFormatAudioType(const QString &type)
280 {
281         m_formatAudioType = type;
282 }
283
284 void AudioFileModel::setFormatAudioProfile(const QString &profile)
285 {
286         m_formatAudioProfile = profile;
287 }
288
289 void AudioFileModel::setFormatAudioVersion(const QString &version)
290 {
291         m_formatAudioVersion = version;
292 }
293
294 void AudioFileModel::setFormatAudioSamplerate(unsigned int samplerate)
295 {
296         m_formatAudioSamplerate = samplerate;
297 }
298
299 void AudioFileModel::setFormatAudioChannels(unsigned int channels)
300 {
301         m_formatAudioChannels = channels;
302 }
303
304 void AudioFileModel::setFormatAudioBitdepth(unsigned int bitdepth)
305 {
306         m_formatAudioBitdepth = bitdepth;
307 }