Source

libtaginfo / libtaginfo / taginfo.h

  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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
/*
 * Copyright (C) 2008-2013 J.Rios <anonbeat@gmail.com>
 * Copyright (C) 2013 Jörn Magens
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This Program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file LICENSE.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth 
 * Floor, Boston, MA  02110-1301  USA
 * https://www.gnu.org/licenses/lgpl-2.1.txt
 *
 * Author:
 * 	Jörn Magens <shuerhaaken@googlemail.com>
 * 	Matias De lellis <mati86dl@gmail.com>
 * 	Pavel Vasin <rat4vier@gmail.com>
 */


#ifndef TAGINFO_H
#define TAGINFO_H

#include "taginfo_image.h"

#include <stdio.h>
#include <string.h>

#include <tag.h>
#include <apetag.h>
#include <asftag.h>
#include <fileref.h>
#include <id3v2tag.h>
#include <flacfile.h>
#include <modtag.h>
#include <mp4tag.h>
#include <xiphcomment.h>


using namespace TagLib;
using namespace std;

/*! \mainpage TagInfo Documentation
 * 
 * libtaginfo is a wrapper library for taglib and alows access to media tags in an abstract way.
 * C and vala bindings for the C++ API are coming with this library.
 * 
 * Known tag formats are: 
 *  - Ape tags, 
 *  - Asf tags and 
 *  - Id3 tags (v1, v2.2, v2.3, v2.4),
 *  - Mod tags.
 *  - Mp4 tags, 
 *  - Xiphcomment/Vorbis tag, 
 * 
 * These tags are used with the following media files (extensions / mime):
 *  - aac  : audio/aac, audio/aacp, audio/mp4, audio/x-aac
 *  - aif  : audio/x-aiff
 *  - aiff : audio/x-aiff
 *  - ape  : application/x-ape
 *  - asf  : audio/x-ms-asf, video/x-ms-asf
 *  - flac : audio/flac, audio/x-flac+ogg, audio/x-flac
 *  - it   : audio/x-it
 *  - m4a  : audio/mp4a-latm, audio/x-m4a
 *  - m4b  : audio/m4b
 *  - m4p  : audio/x-m4p
 *  - mod  : audio/x-mod
 *  - mp3  : audio/mpeg, audio/x-mpegurl
 *  - mp4  : audio/mp4, video/mp4
 *  - mpc  : audio/mpc, audio/x-musepack
 *  - oga  : audio/x-vorbis+ogg, audio/ogg
 *  - ogg  : audio/x-vorbis+ogg, audio/ogg
 *  - s3m  : audio/x-s3m
 *  - spx  : audio/x-spx, audio/x-speex, audio/x-speex+ogg
 *  - tta  : audio/tta, audio/x-tta
 *  - wav  : audio/x-wav
 *  - wma  : audio/x-ms-wma
 *  - wmv  : video/x-ms-wmv, video/x-msvideo
 *  - wv   : application/x-wavpack, audio/wavpack, audio/x-wavpack
 *  - xm   : audio/x-xm
 *
 * There is an API for accessing the following media tags:
 *  - Album
 *  - Album artist
 *  - Artist
 *  - Comments;
 *  - Compilation/V.A. flag
 *  - Composer;
 *  - Copyright;
 *  - Encoder;
 *  - Genre
 *  - Homepage;
 *  - Images (embedded image files)
 *  - Original artist
 *  - Play count
 *  - Rating (1 - 5 stars, 0 not set) 
 *  - Title
 *  - Track count;
 *  - Track number;
 *  - User defined album labels;
 *  - User defined artist labels;
 *  - User defined track labels;
 *  - Volume count;
 *  - Volume number;
 *  - Year
 * 
 * However, some media tags are not supported by some tag formats. (E.g. mod tags are very limited)
 * 
 * There is an API for accessing the following audio properties:
 *  - Bitrate
 *  - Channel count
 *  - Lenght in seconds
 *  - Sample rate
 *          
 */

 /*!
  * 
  * Contains classes for abstract access to media file tags.
  */
namespace TagInfo {
    
    //! The enumeration type for the media file type
    /*! Enumerator for the type of the media file. */
    enum MediaFileType {
        //! Unknown media file type
        MEDIA_FILE_TYPE_UNKNOWN, 
        //! Aac media file
        MEDIA_FILE_TYPE_AAC,
        //! Aiff media file
        MEDIA_FILE_TYPE_AIF,
        //! Ape media file
        MEDIA_FILE_TYPE_APE,
        //! Asf media file
        MEDIA_FILE_TYPE_ASF,
        //! Flac media file
        MEDIA_FILE_TYPE_FLAC,
        //! M4A media file
        MEDIA_FILE_TYPE_M4A,
        //! M4B media file
        MEDIA_FILE_TYPE_M4B,
        //! M4P media file
        MEDIA_FILE_TYPE_M4P,
        //! MP3 media file
        MEDIA_FILE_TYPE_MP3,
        //! MP4 media file
        MEDIA_FILE_TYPE_MP4,
        //! MPC media file
        MEDIA_FILE_TYPE_MPC,
        //! Oga media file
        MEDIA_FILE_TYPE_OGA,
        //! Ogg media file
        MEDIA_FILE_TYPE_OGG,
        //! Tta media file
        MEDIA_FILE_TYPE_TTA,
        //! Wave media file
        MEDIA_FILE_TYPE_WAV,
        //! Wma media file
        MEDIA_FILE_TYPE_WMA,
        //! WavPack media file
        MEDIA_FILE_TYPE_WV,
        //! Speex media file
        MEDIA_FILE_TYPE_SPEEX,
        //! Wmv media file
        MEDIA_FILE_TYPE_WMV,
        //! Mod media file
        MEDIA_FILE_TYPE_MOD,
        //! Impulse Tracker media file
        MEDIA_FILE_TYPE_IT,
        //! Xm media file
        MEDIA_FILE_TYPE_XM,
        //! S3m media file
        MEDIA_FILE_TYPE_S3M
    };
    
    
    //! A simple, generic interface to common audio meta data fields
    
    /*!
    * This is an attempt to abstract away the difference in the meta data formats
    * of various audio codecs and tagging schemes.  
    */
    class Info {
        protected :
            //! Constructor to be called from implementations
            Info(const String &filename = "");

            //! \a TagLib::FileRef of the media file
            TagLib::FileRef * taglib_fileref;
            
            //! \a TagLib::File of the media file
            TagLib::File *    taglib_file;
            
            //! \a TagLib::Tag of the media file
            TagLib::Tag *     taglib_tag;

            //! The path of the media file
            String file_name;
            
            //Tags

            //! Title of the Info object 
            String title;
            //! Genre of the Info object 
            String genre;
            //! Artist of the Info object 
            String artist;
            //! Album artist of the Info object 
            String album_artist;
            //! Album of the Info object
            String album;
            //! Composer of the Info object
            String composer;
            //! Comments of the Info object
            String comments;
            //! Homepage of the Info object
            String homepage;
            //! Encoder of the Info object
            String encoder;
            //! Copyright of the Info object
            String copyright;
            //! Original artist of the Info object
            String original_artist;
            //! Track number of the Info object
            int    track_number;
            //! Track count of the Info object
            int    track_count;
            //! Year of the Info object
            int    year;
            //! Whether the media file is part of a compilation
            bool   is_compilation;

            //! Volume number of the Info object
            int    volume_number;
            //! Volume count of the Info object
            int    volume_count;
            
            
            //Audioproperties
            //! Lenght in seconds
            int    length_seconds;
            //! Bitrate
            int    bitrate;
            //! Sample rate
            int    samplerate;
            //! Channel count
            int    channels;
            
            //Extras
            //! Play count
            int    playcount;
            //! Rating (1 - 5 stars, 0 not set) 
            int    rating;

            //! User defined track labels
            StringList track_labels;
            //! User defined track labels as string with "|" as delimiter
            String     track_labels_string;
            //! User defined artist labels
            StringList artist_labels;
            //! User defined artist labels as string with "|" as delimiter
            String     artist_labels_string;
            //! User defined album labels
            StringList album_labels;
            //! User defined album labels as string with "|" as delimiter
            String     album_labels_string;
            
            
            //! Setting tags on the info object will set these ChangedData flags, so that everything can be handled more efficiently. 
            ulong changedflag;
            
            //! Whether there is image data available
            bool has_image;
            
            //! Whether the info object is valid
            bool valid;
            
            //! Load the abstact basic tags from TagLib::Tag
            //! This will only do something if \param tag is not NULL
            void   load_base_tags(TagLib::Tag * tag);
            
            //! Save the abstact basic tags to TagLib::Tag
            //! This will only do something if \param tag is not NULL
            void   save_base_tags(TagLib::Tag * tag);
            
            //! Function to be used with implementations to set up TagLib::File 
            virtual bool setup_file_ref();
            
            
        public:
            
            //General stuff

            //! \return name of media file
            String get_file_name(void);

            //! Information if the media file could be recognized and appears to be valid
            //! \return true if valid 
            bool is_valid();
            
            //Tag access functions
            
            //! Get the title of a media track.
            /*!
            \return The title as %TagLib::String
            */
            String get_title(void) const;
            
            //! Set the title tag.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_title is a TagLib::String.
            */
            void   set_title(const String new_title);
            
            
            //! Get the genre of a media track.
            /*!
            \return The genre as TagLib::String
            */
            String get_genre(void) const;
            
            /*!
             * Set the genre tag.
             */
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            void   set_genre(const String new_genre);
            
            //! Get the artist tag of a media track.
            /*!
            \return The artist tag as TagLib::String
            */
            String get_artist(void) const;
            
            //! Set the artist tag of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_artist as TagLib::String
            */
            void   set_artist(const String new_artist);
            
            //! Get the album artist tag of a media track.
            /*!
            \return The album artist tag as TagLib::String
            */
            String get_album_artist(void) const;
            
            //! Set the album artist tag of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_artist as TagLib::String
            */
            void   set_album_artist(const String new_artist);
            
            //! Get the album tag of a media track.
            /*!
            \return The album tag as TagLib::String
            */
            String get_album(void) const;
            
            //! Set the album tag of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_album as TagLib::String
            */
            void   set_album(const String new_album);
            
            //! Get the composer tag of a media track.
            /*!
            \return The composer tag as TagLib::String
            */
            String get_composer(void) const;
            
            //! Set the composer tag of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_composer as TagLib::String
            */
            void   set_composer(const String new_composer);
            
            //! Get the comments tag of a media track.
            /*!
            \return The comments tag as TagLib::String
            */
            String get_comments(void) const;
            
            //! Set the comments tag of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_comments as TagLib::String
            */
            void   set_comments(const String new_comments);
            
            //! Get the track_number tag of a media track.
            /*!
            \return The track_number tag as int
            */
            int  get_track_number() const;
            
            //! Set the track number of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_track_number as int
            */
            void set_track_number(const int new_track_number);
            
            //! Set the track count of a media track.
            //! This is the amount of tracks of the album the media file was taken from.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_track_count as int
            */
            void set_track_count(const int new_track_count);
            
            //! Get the track_count tag of a media track.
            //! This is the amount of tracks of the album the media file was taken from.
            /*!
            \return The track_count tag as int
            */
            int  get_track_count() const;
            
            
            //! Get the year tag of a media track.
            /*!
            \return The year tag as int
            */
            int  get_year() const;
            
            //! Set the year of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_year as int
            */
            void set_year(const int new_year);
            
            //Extra
            
            //! Get the homepage tag of a media track.
            /*!
            \return The homepage tag as TagLib::String
            */
            String get_homepage(void) const;
            
            //! Set the homepage tag of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_homepage as TagLib::String
            */
            void   set_homepage(const String new_homepage);
            
            //! Get the performer tag of a media track.
            /*!
            \return The performer tag as TagLib::String
            */
            String get_original_artist(void) const;
            
            //! Set the original artist tag of a media track.
            //! For some implementations this is the performer tag 
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_artist as TagLib::String
            */
            void   set_original_artist(const String new_artist);
            
            //! Get the encoder tag of a media track.
            /*!
            \return The encoder tag as TagLib::String
            */
            String get_encoder(void) const;
            
            //! Set the encoder tag of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_encoder as TagLib::String
            */
            void   set_encoder(const String new_encoder);
            
            //! Get the copyright tag of a media track.
            /*!
            \return The copyright tag as TagLib::String
            */
            String get_copyright(void) const;
            
            //! Set the copyright tag of a media track.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_copyright as TagLib::String
            */
            void   set_copyright(const String new_copyright);
            
            //! Get the playcount tag of a media track.
            /*!
            \return The playcount tag as int
            */
            int  get_playcount() const;
            
            //! Set the playcount tag of a media track.
            //! Some implementations may not support this tag
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_playcount as int
            */
            void set_playcount(int new_playcount);
            
            //! Get the rating tag of a media track.
            //! rating 1 - 5 ;  0 -> not set
            /*!
            \return The rating tag as int
            */
            int  get_rating() const;
            
            //! Set the rating tag of a media track.
            //! rating 1 - 5 ;  0 -> not set
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param new_rating as integer
            */
            void set_rating(const int new_rating);
            
            //! Get volume number of a media track. (like CD 2 of 3)
            /*!
            \return The volume number as int
            */
            int  get_volume_number() const;
            
            //! Set volume number of a media track. (like CD 2 of 3)
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param number as int
            */
            void set_volume_number(const int number);
            
            //! Get volume count of a media track. (like CD 2 of 3)
            /*!
            \return The volume count as int
            */
            int  get_volume_count() const;
            
            //! Set volume count of a media track. (like CD 2 of 3)
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            /*!
            \param count as int
            */
            void set_volume_count(const int count);
            
            //! Get information on the availability of an image
            /*!
             * This information is just a quick lookup if something is there.
            \return true if there is image data
            */
            bool get_has_image() const;
            
            //Audio properties access functions
            
            //! Get the length of the media file in seconds.
            int  get_length_seconds() const;
            //! Get the bitrate of the media file.
            int  get_bitrate() const;
            //! Get the number of channels of the media file.
            int  get_channels() const;
            //! Get the samplerate of the media file.
            int  get_samplerate() const;
           
            
            //Labels

            
            //! Get a list of embedded track labels.
            StringList get_track_labels_list() const;
            //! Set a list of embedded track labels.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            void       set_track_labels_list(const StringList &new_track_labels_list);
            
            //! Get a list of embedded artist labels.
            StringList get_artist_labels_list() const;
            //! Set a list of embedded artist labels.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            void       set_artist_labels_list(const StringList &new_artist_labels_list);
            
            //! Get a list of embedded album labels.
            StringList get_album_labels_list() const;
            //! Set a list of embedded album labels.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            void       set_album_labels_list(const StringList &new_album_labels_list);
            
            
            //Misc

            //! Get wether the media file is part of a compilation/various artists album, or not.
            bool get_is_compilation() const;
            //! Set wether the media file is part of a compilation/various artists album, or not.
            //! This function will set the according ChangedData flag
            //! This will not be saved to file before save() is called on the Info object.
            void set_is_compilation(bool compilation);
            
            
            ~Info();
            
            /*!
             * Loads tags and properties from the Info object of a file.
             * String returns are coming as TagLib::String.
             */
            virtual bool load(void);
            
            /*!
             * Saves the tags of the Info object to the media file.
             */
            virtual bool save(void);
            
            
            //! Get an array of images from the Info object.
            //! After this function was called, \param image_count will 
            //! hold the number of images in the returend array.
            //! The ownership of the images is on the caller side. You have
            //! to destroy all the images in the retured array 
            //! \return Array of Image
            virtual Image ** get_images(int &image_count) const;
            
            //! Set an array of Image to the Info object.
            //! The ownership of the images remains on the caller side.
            //! \param images is an array of Image. Will overwrite any other Image in the
            //! Info object 
            //! \param image_count shall be the lenght of the image array.
            virtual void     set_images(const Image ** images, const int image_count);

            //! Get an embedded Lyrics String from the Info object.
            //! \return String with lyrics
            virtual String   get_lyrics(void) const;
            
            //! Set an embedded Lyrics String to be saved to Info object.
            virtual bool     set_lyrics(const String &lyrics);
            
            /*!
             * Create a Info object from \a media file.
             *
             * This is a recommended way for accessing media tags through libtaginfo.
             * create_tag_info() will return a matching Info subclass
             * \return the according Info subclass
             * \param file is the path to a media file.
             *
             * This function will make use of the file extension to find out the media type
             */
            static Info * create_tag_info(const String &file);
            
            /*!
             * Create a Info from \a file. If \a format is given, libtaginfo will try to create 
             * an Info object for the desired \a format.
             * This is a recommended way for accessing media tags through libtaginfo.
             * create_tag_info_with_format() will return a matching Info subclass
             * \return the according Info subclass
             * \param file is the path to a media file.
             * \param format is the MediaFileType.
             */
            static Info * create_tag_info_with_format(const String &file, MediaFileType format);
            
            /*!
             * Create a Info from \param filename . If \param mime_type is given, libtaginfo 
             * will try to create an Info object for the desired mime_type.
             * This is a recommended way for accessing media tags through libtaginfo.
             * create_tag_info_from_mime() will return a matching Info subclass
             * \return the according Info subclass
             * \param filename is the path to a media file.
             * \param mime_type is the mime type of the media file (e.g. "audio/x-vorbis+ogg") 
             * as TagLib::String.
             */
            static Info * create_tag_info_from_mime(const String &filename, const String &mime_type);
    };
    
    

}
#endif