kwave  18.07.70
FileInfo.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  FileInfo.cpp - information about an audio file
3  -------------------
4  begin : Mar 13 2002
5  copyright : (C) 2002 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 #include <KLocalizedString>
20 
21 #include "libkwave/FileInfo.h"
22 #include "libkwave/MetaDataList.h"
23 #include "libkwave/String.h"
24 
26 #define FILE_INFO_PROPERTY_PREFIX _("FILE_INFO: ")
27 
28 /***************************************************************************/
30 {
33  QString(), QString());
34 
36  FP_NONE,
37  _(I18N_NOOP("Album")),
38  _(I18N_NOOP("Name of the album if the source is an album\n"
39  "that consist of more medias.")));
41  FP_NONE,
42  _(I18N_NOOP("Annotation")),
43  _(I18N_NOOP(
44  "Provides general comments about the file or the subject of\n"
45  "the file. If the comment is several sentences long, end\n"
46  "each sentence with a period. Do not include newline\n"
47  "characters!")));
49  FP_NONE,
50  _(I18N_NOOP("Archival location")),
51  _(I18N_NOOP("Indicates where the subject of the file is archived.")));
53  FP_NONE,
54  _(I18N_NOOP("Author")),
55  _(I18N_NOOP("Identifies the name of the author of the original\n"
56  "subject of the file."
57  "\nExample: 'van Beethoven, Ludwig'")));
60  _(I18N_NOOP("Lower Bitrate")),
61  _(I18N_NOOP("Specifies the lower limit in a VBR bitstream.")));
64  _(I18N_NOOP("Bitrate Mode")),
65  _(I18N_NOOP("Bitrate Mode (ABR, VBR, CBR, etc...)")));
68  _(I18N_NOOP("Bitrate")),
69  _(I18N_NOOP(
70  "Nominal bitrate of the audio stream in bits per second")));
73  _(I18N_NOOP("Upper Bitrate")),
74  _(I18N_NOOP("Specifies the upper limit in a VBR bitstream.")));
77  _(I18N_NOOP("Bits per Sample")),
78  _(I18N_NOOP("Specifies the number of bits per sample.")));
81  _(I18N_NOOP("CD")),
82  _(I18N_NOOP(
83  "Number of the CD, if the source is an album of more CDROMs")));
86  _(I18N_NOOP("CDS")),
87  _(I18N_NOOP(
88  "Number of CDs, if the source is an album of more CDROMs")));
90  FP_NONE,
91  _(I18N_NOOP("Commissioned")),
92  _(I18N_NOOP("Lists the name of the person or organization\n"
93  "that commissioned the subject of the file.")));
95  FP_NONE,
96  _(I18N_NOOP("Comments")),
97  _(I18N_NOOP(
98  "Provides general comments about the file or the subject of\n"
99  "the file. If the comment is several sentences long, end\n"
100  "each sentence with a period. Do not include newline\n"
101  "characters!")));
104  _(I18N_NOOP("Compression")),
105  _(I18N_NOOP("Sets a mode for compressing the audio\n"
106  "data to reduce disk space.")));
108  FP_NONE,
109  _(I18N_NOOP("Contact")),
110  _(I18N_NOOP("Contact information for the creators or distributors of\n"
111  "the track. This could be a URL, an email address, the\n"
112  "physical address of the producing label.")));
114  FP_NONE,
115  _(I18N_NOOP("Copyright")),
116  _(I18N_NOOP("Records the copyright information for the file. "
117  "If there are\n"
118  "multiple copyrights, separate them by a semicolon followed\n"
119  "by a space.\n"
120  "Example: 'Copyright Linux community 2002'")));
122  FP_NONE,
123  _(I18N_NOOP("Copyrighted")),
124  _(I18N_NOOP("Indicates whether the file is protected by "
125  "copyright or not.")));
127  FP_NONE,
128  _(I18N_NOOP("Date")),
129  _(I18N_NOOP("Specifies the date the subject of the file was created.\n"
130  "Example: '2001-12-24'")));
132  FP_NONE,
133  _(I18N_NOOP("Engineer")),
134  _(I18N_NOOP("Shows the name of the engineer who worked on the file.\n"
135  "If there are multiple engineers, separate the names by\n"
136  "a semicolon and a blank.")));
139  _(I18N_NOOP("Estimated Length")),
140  _(I18N_NOOP("Estimated length of the file in samples")));
143  _(I18N_NOOP("Filename")),
144  _(I18N_NOOP("Name of the opened file")));
147  _(I18N_NOOP("File Size")),
148  _(I18N_NOOP("Size of the file in bytes")));
150  FP_NONE,
151  _(I18N_NOOP("Genre")),
152  _(I18N_NOOP("Describes the genre or style of the original work.\n"
153  "Examples: 'classic', 'pop'")));
155  FP_READONLY,
156  _(I18N_NOOP("ISRC")),
157  _(I18N_NOOP("ISRC number for the track; see the ISRC intro page\n"
158  "for more information on ISRC numbers.\n"
159  "http://www.ifpi.org/site-content/online/isrc_intro.html")));
161  FP_NONE,
162  _(I18N_NOOP("Keywords")),
163  _(I18N_NOOP("Provides a list of keywords that refer to the\n"
164  "file or subject of the file.")));
166  FP_INTERNAL,
167  _(I18N_NOOP("Labels")),
168  _(I18N_NOOP("The list of labels/markers.")));
171  _(I18N_NOOP("Length")),
172  _(I18N_NOOP("Length of the file in samples.")));
174  FP_NONE,
175  _(I18N_NOOP("License")),
176  _(I18N_NOOP("License information, e.g., 'All Rights Reserved',\n"
177  "'Any Use Permitted', an URL to a license or the\n"
178  "EFF Open Audio License ('distributed under the\n"
179  "terms of the Open Audio License.\n"
180  "See http://www.eff.org/IP/Open_licenses/eff_oal.html\n"
181  "for details'), etc.")));
183  FP_NONE,
184  _(I18N_NOOP("Medium")),
185  _(I18N_NOOP("Describes the original subject of the file,\n"
186  "where it was first recorded.\n"
187  "Example: 'orchestra'")));
190  _(I18N_NOOP("Mime Type")),
191  _(I18N_NOOP("Mime type of the file format")));
194  _(I18N_NOOP("Emphasis")),
195  _(I18N_NOOP("Audio emphasis mode")));
198  _(I18N_NOOP("Layer")),
199  _(I18N_NOOP("MPEG Layer, I, II or III")));
202  _(I18N_NOOP("Mode Extension")),
203  _(I18N_NOOP("MPEG Mode Extension (only if Joint Stereo)")));
206  _(I18N_NOOP("Version")),
207  _(I18N_NOOP("MPEG Version, 1, 2 or 2.5")));
209  FP_NONE,
210  _(I18N_NOOP("Name")),
211  _(I18N_NOOP("Stores the title of the subject of the file.\n"
212  "Example: \"Symphony No.6, Op.68 'Pastoral'\"")));
215  _(I18N_NOOP("Opus Frame Length")),
216  _(I18N_NOOP("Opus Frame Length in ms (supported values are "
217  "2.5, 5, 10, 20, 40, or 60 ms)")));
219  FP_NONE,
220  _(I18N_NOOP("Organization")),
221  _(I18N_NOOP("Name of the organization producing the track\n"
222  "(i.e. the 'record label')")));
225  _(I18N_NOOP("Original")),
226  _(I18N_NOOP("Indicates whether the file is an original or a copy")));
228  FP_NONE,
229  _(I18N_NOOP("Performer")),
230  _(I18N_NOOP("The artist(s) who performed the work. In classical\n"
231  "music this would be the conductor, orchestra, soloists.\n"
232  "In an audio book it would be the actor who did the reading.")));
234  FP_NONE,
235  _(I18N_NOOP("Private")),
236  _(I18N_NOOP("Indicates whether the subject is private")));
238  FP_NONE,
239  _(I18N_NOOP("Product")),
240  _(I18N_NOOP("Specifies the name or the title the\n"
241  "file was originally intended for.\n"
242  "Example: 'Linux audio collection'")));
245  _(I18N_NOOP("Sample Format")),
246  _(I18N_NOOP("Format used for storing the digitized audio samples.\n"
247  "Example: '32-bit IEEE floating-point'")));
250  _(I18N_NOOP("Sample Rate")),
251  _(I18N_NOOP("Number of samples per second")));
253  FP_NONE,
254  _(I18N_NOOP("Software")),
255  _(I18N_NOOP("Identifies the name of the software package\n"
256  "used to create the file.\n"
257  "Example: 'Kwave v0.6.4-1'")));
259  FP_NONE,
260  _(I18N_NOOP("Source")),
261  _(I18N_NOOP("Identifies the name of the person or organization\n"
262  "who supplied the original subject of the file.\n"
263  "Example: 'Chaotic Sound Research'")));
265  FP_NONE,
266  _(I18N_NOOP("Source form")),
267  _(I18N_NOOP("Identifies the original form of\n"
268  "the material that was digitized.\n"
269  "Examples: 'Record/Vinyl/90RPM', 'Audio DAT', "
270  "'tape/CrO2/60min'")));
272  FP_NONE,
273  _(I18N_NOOP("Subject")),
274  _(I18N_NOOP("Describes the subject of the file.\n"
275  "Example: 'Bird voices at early morning'")));
277  FP_NONE,
278  _(I18N_NOOP("Technician")),
279  _(I18N_NOOP(
280  "Identifies the technician who digitized the subject file.\n"
281  "Example: 'Torvalds, Linus'")));
284  _(I18N_NOOP("Track")),
285  _(I18N_NOOP("Track of the CD if the source was a CDROM.")));
288  _(I18N_NOOP("Tracks")),
289  _(I18N_NOOP("Number of tracks of the CD if the source was a CDROM.")));
292  _(I18N_NOOP("Channels")),
293  _(I18N_NOOP("Specifies the number of channels of the signal.")));
296  _(I18N_NOOP("Base Quality")),
297  _(I18N_NOOP("Base quality of the compression in VBR mode")));
299  FP_NONE,
300  _(I18N_NOOP("Version")),
301  _(I18N_NOOP("May be used to differentiate multiple versions\n"
302  "of the same track title in a single collection.\n"
303  "(e.g. remix info)")));
304 
305  // please do not simply extend here, sort in alphabetically instead...
306 
307 }
308 
309 /***************************************************************************/
310 QList<Kwave::FileProperty> Kwave::FileInfo::PropertyTypesMap::all() const
311 {
312  return keys();
313 }
314 
315 /***************************************************************************/
316 /***************************************************************************/
320 {
322 }
323 
324 /***************************************************************************/
326  :Kwave::MetaData(
327  (meta_data_list.selectByType(metaDataType()).isEmpty()) ?
329  meta_data_list.selectByType(metaDataType()).values().first()
330  ),
332 {
334 
335  foreach (const Kwave::MetaData &meta_data, meta_data_list) {
336  foreach (Kwave::FileProperty key, m_property_map.keys()) {
337  QString name = FILE_INFO_PROPERTY_PREFIX +
338  m_property_map.name(key);
339  if (meta_data.hasProperty(name)) {
340  // take over each supported property
341  QVariant value = meta_data[name];
342  setProperty(name, value);
343  }
344  }
345  }
346 }
347 
348 /***************************************************************************/
350 {
351 }
352 
353 /***************************************************************************/
355 {
356  if (!m_property_map.keys().contains(key))
357  return false;
359  return hasProperty(name);
360 }
361 
362 /***************************************************************************/
363 void Kwave::FileInfo::set(Kwave::FileProperty key, const QVariant &value)
364 {
365  if (!m_property_map.keys().contains(key))
366  return;
368  setProperty(name, value);
369 }
370 
371 /***************************************************************************/
373 {
374  if (!m_property_map.keys().contains(key))
375  return QVariant();
377 
378  if (!hasProperty(name)) return QVariant();
379  return property(name);
380 }
381 
382 /***************************************************************************/
383 QList<Kwave::FileProperty> Kwave::FileInfo::allKnownProperties() const
384 {
385  return m_property_map.all();
386 }
387 
388 /***************************************************************************/
389 const QMap<Kwave::FileProperty, QVariant> Kwave::FileInfo::properties() const
390 {
391  QMap<Kwave::FileProperty, QVariant> map;
392  foreach (Kwave::FileProperty key, m_property_map.keys()) {
393  if (!contains(key)) continue;
394  map[key] = get(key);
395  }
396  return map;
397 }
398 
399 /***************************************************************************/
401 {
402  QVariant value = get(Kwave::INF_LENGTH);
403  bool ok = false;
404  sample_index_t len = static_cast<sample_index_t>(value.toULongLong(&ok));
405  return (ok) ? len : 0;
406 }
407 
408 /***************************************************************************/
410 {
411  set(Kwave::INF_LENGTH, QVariant(static_cast<qulonglong>(length)));
412 }
413 
414 /***************************************************************************/
415 double Kwave::FileInfo::rate() const
416 {
417  QVariant value = get(Kwave::INF_SAMPLE_RATE);
418  bool ok = false;
419  double r = value.toDouble(&ok);
420  return (ok) ? r : 0;
421 }
422 
423 /***************************************************************************/
425 {
427 }
428 
429 /***************************************************************************/
430 unsigned int Kwave::FileInfo::bits() const
431 {
432  QVariant value = get(Kwave::INF_BITS_PER_SAMPLE);
433  bool ok = false;
434  unsigned int bits = value.toUInt(&ok);
435  return (ok) ? bits : 0;
436 }
437 
438 /***************************************************************************/
439 void Kwave::FileInfo::setBits(unsigned int bits)
440 {
442 }
443 
444 /***************************************************************************/
445 unsigned int Kwave::FileInfo::tracks() const
446 {
447  QVariant value = get(Kwave::INF_CHANNELS);
448  bool ok = false;
449  unsigned int tracks = value.toUInt(&ok);
450  return (ok) ? tracks : 0;
451 }
452 
453 /***************************************************************************/
455 {
457 }
458 
459 /***************************************************************************/
461 {
462  qDebug("--- dump of file info ---");
463  qDebug(" id = #%s", DBG(id()));
464  qDebug("default properties:");
465  qDebug(" length = %lu samples", static_cast<unsigned long int>(length()));
466  qDebug(" rate = %0.1f Hz", rate());
467  qDebug(" bits = %u", bits());
468  qDebug(" tracks = %u", tracks());
469 
470 // qDebug("labels:");
471 // foreach (Kwave::Label label, m_labels) {
472 // qDebug(" [%10lu] = '%s'", static_cast<unsigned long int>(label.pos()),
473 // DBG(label.name()));
474 // }
475 
476  qDebug("other properties:");
477  QMap<Kwave::FileProperty, QVariant>::Iterator it;
478  foreach (Kwave::FileProperty key, m_property_map.keys()) {
479  if (!contains(key)) continue;
480  QVariant val = get(key);
481  QString name = m_property_map.name(key);
482  qDebug(" '%s' = '%s'", DBG(name), DBG(val.toString()));
483 
484 // for updating the list of properties in the appendix of the handbook:
485 // QString name = m_property_map.name(key);
486 // QString descr = m_property_map.description(key, false);
487 // qDebug("\t <row>");
488 // qDebug("\t\t<entry colname='c1'>&no-i18n-tag;%s</entry>", DBG(name));
489 // qDebug("\t\t<entry colname='c2'>");
490 // qDebug("\t\t %s", DBG(descr.replace(_("\n"), _("\n\t\t "))));
491 // qDebug("\t\t</entry>");
492 // qDebug("\t </row>");
493  }
494  qDebug("-------------------------");
495 }
496 
497 /***************************************************************************/
498 /***************************************************************************/
bool contains(const FileProperty property) const
Definition: FileInfo.cpp:354
bool hasProperty(const QString &p) const
Definition: MetaData.cpp:104
virtual void fill() Q_DECL_OVERRIDE
Definition: FileInfo.cpp:29
Definition: App.h:33
double rate() const
Definition: FileInfo.cpp:415
QString name(FileProperty key) const
Definition: FileInfo.h:227
QVariant get(FileProperty key) const
Definition: FileInfo.cpp:372
PropertyTypesMap m_property_map
Definition: FileInfo.h:277
#define FILE_INFO_PROPERTY_PREFIX
Definition: FileInfo.cpp:26
quint64 sample_index_t
Definition: Sample.h:28
virtual ~FileInfo() Q_DECL_OVERRIDE
Definition: FileInfo.cpp:349
void set(FileProperty key, const QVariant &value)
Definition: FileInfo.cpp:363
void setRate(double rate)
Definition: FileInfo.cpp:424
QList< FileProperty > keys() const
Definition: TypesMap.h:150
QList< FileProperty > allKnownProperties() const
Definition: FileInfo.cpp:383
sample_index_t length() const
Definition: FileInfo.cpp:400
static const QString STDPROP_TYPE
Definition: MetaData.h:41
const QMap< FileProperty, QVariant > properties() const
Definition: FileInfo.cpp:389
void setLength(sample_index_t length)
Definition: FileInfo.cpp:409
virtual void append(FileProperty index, Flags data, const QString &name, const QString &description)
Definition: TypesMap.h:72
void setTracks(unsigned int tracks)
Definition: FileInfo.cpp:454
void setProperty(const QString &p, const QVariant &value)
Definition: MetaData.cpp:93
unsigned int tracks() const
Definition: FileInfo.cpp:445
void setBits(unsigned int bits)
Definition: FileInfo.cpp:439
static QString metaDataType()
Definition: FileInfo.h:154
#define _(m)
Definition: memcpy.c:66
QString name(IDX type) const
Definition: TypesMap.h:117
#define DBG(qs)
Definition: String.h:55
virtual QList< FileProperty > all() const
Definition: FileInfo.cpp:310
unsigned int bits() const
Definition: FileInfo.cpp:430
QVariant property(const QString &p) const
Definition: MetaData.cpp:110
FileProperty
Definition: FileInfo.h:45
virtual void dump() const Q_DECL_OVERRIDE
Definition: FileInfo.cpp:460