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
/*
 * 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;

/** @file */

/*! \mainpage TagInfo Documentation
 * 
 * <b>libtaginfo is a wrapper library for taglib</b> 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
 *          
 */

 /*!
  * 
  * The \namespace TagInfo contains classes for abstract access to media file tags.
  */
namespace TagInfo {
    
    //! \enum MediaFileType describes 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
    
    /*!
    * Info is an abstract base class for media tag reading/writing  
    */
    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
            
            String get_album_artist(void) const;
            void   set_album_artist(const String new_artist);
            
            String get_album(void) const;
            void   set_album(const String new_album);
            
            String get_artist(void) const;
            void   set_artist(const String new_artist);
            
            String get_comments(void) const;
            void   set_comments(const String new_comments);
            
            String get_composer(void) const;
            void   set_composer(const String new_composer);
            
            String get_copyright(void) const;
            void   set_copyright(const String new_copyright);
            
            String get_encoder(void) const;
            void   set_encoder(const String new_encoder);
            
            String get_genre(void) const;
            void   set_genre(const String new_genre);
            
            bool get_has_image() const;
            
            String get_homepage(void) const;
            void   set_homepage(const String new_homepage);
            
            bool get_is_compilation() const;
            void set_is_compilation(bool compilation);
            
            String get_original_artist(void) const;
            void   set_original_artist(const String new_artist);
            
            int  get_playcount() const;
            void set_playcount(int new_playcount);
            
            int  get_rating() const;
            void set_rating(const int new_rating);
            
            String get_title(void) const;
            void   set_title(const String new_title);
            
            int  get_track_count() const;
            void set_track_count(const int new_track_count);
            
            int  get_track_number() const;
            void set_track_number(const int new_track_number);
            
            int  get_volume_count() const;
            void set_volume_count(const int count);
            
            int  get_volume_number() const;
            void set_volume_number(const int number);
            
            int  get_year() const;
            void set_year(const int new_year);
            
            //Audio properties access functions
            
            int  get_length_seconds() const;
            int  get_bitrate() const;
            int  get_channels() const;
            int  get_samplerate() const;
           
            
            //Labels
            
            StringList get_track_labels_list() const;
            void       set_track_labels_list(const StringList &new_track_labels_list);
            
            StringList get_artist_labels_list() const;
            void       set_artist_labels_list(const StringList &new_artist_labels_list);
            
            StringList get_album_labels_list() const;
            void       set_album_labels_list(const StringList &new_album_labels_list);
            
            
            
            ~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);
            
            
            virtual Image ** get_images(int &image_count) const;
            virtual void     set_images(const Image ** images, const int image_count);

            virtual String   get_lyrics(void) const;
            virtual bool     set_lyrics(const String &lyrics);
            
            // CREATION METHODS
            static Info * create(const String &filename);
            static Info * create_with_format(const String &file, MediaFileType format);
            static Info * create_from_mime(const String &filename, const String &mime_type);
    };
}
#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.