Mp3tag is a library for reading the meta-data of mp3 audio files. Currently it supports only ID3v1.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mp3tag.h Source File

mp3tag.h

00001 /* mbed library for reading ID3v1 tags in mp3 files
00002  * Copyright (c) 2010 Christian Schmiljun
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE.
00021  */
00022 
00023 #ifndef _MP3_TAG_H
00024 #define _MP3_TAG_H
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 
00030 #include "defines.h"
00031 #include "ff.h"
00032 
00033 #define MP3_ID3_TITLE_LENGTH        30
00034 #define MP3_ID3_ARTIST_LENGTH       30
00035 #define MP3_ID3_ALBUM_LENGTH        30
00036 #define MP3_ID3_YEAR_LENGTH          4
00037 #define MP3_ID3_COMMENT_LENGTH      30
00038 
00039 /** Struct with the layout of id3tags version 1.
00040  *
00041  * @attention Strings are either space- or zero-padded. Unset string entries are filled using an empty string. Strings not allways null-terminated.
00042  *
00043  * Size: 128 bytes
00044  */
00045 typedef struct Id3V1Tag
00046 {
00047     char tag [3];                                    /*!< "TAG" */
00048     char title [MP3_ID3_TITLE_LENGTH];               /*!< title, MP3_ID3_TITLE_LENGTH characters */
00049     char artist [MP3_ID3_ARTIST_LENGTH];             /*!< artist, MP3_ID3_ARTIST_LENGTH characters */
00050     char album [MP3_ID3_ALBUM_LENGTH];               /*!< album, MP3_ID3_ALBUM_LENGTH characters */
00051     char year [MP3_ID3_YEAR_LENGTH];                 /*!< year, MP3_ID3_YEAR_LENGTH characters */
00052     char comment [MP3_ID3_COMMENT_LENGTH];           /*!< comment, MP3_ID3_COMMENT_LENGTH characters or (MP3_ID3_COMMENT_LENGTH - 2), if the track number is stored in the last two bytes */
00053     char genre ;                                     /*!< index in a list of genres, or 255 - see mp3tag_genres */
00054 } Id3V1Tag;
00055 
00056 #define MP3_ID3_GENRES 148
00057 
00058 #ifdef __cplusplus
00059 extern "C" {
00060 #endif
00061 
00062 extern const char* const mp3tag_genres[MP3_ID3_GENRES];  /*!< list of genres, see http://www.multimediasoft.com/amp3dj/help/index.html?amp3dj_00003e.htm*/
00063 
00064 
00065 /** Read id3tag from a file.
00066  * 
00067  * @param openFile
00068  *   Open/readable audio file. (mp3)
00069  *
00070  * @param tag
00071  *   Return value with id3tag.
00072  *  
00073  * @return TRUE on success, tag has the informations; FALSE on failure, tag isn't modiefied, openFile isn't open/readable or file has no id3v1. 
00074  */
00075 bool mp3tag_readTag(FILE* openFile, Id3V1Tag* tag);
00076 
00077 /** Read id3tag from a file.
00078  * 
00079  * @param openFile
00080  *   Open/readable audio file. (mp3)
00081  *
00082  * @param tag
00083  *   Return value with id3tag.
00084  *  
00085  * @return TRUE on success, tag has the informations; FALSE on failure, tag isn't modiefied, openFile isn't open/readable or file has no id3v1. 
00086  */
00087 bool mp3tag_readTagFF(FIL* openFile, Id3V1Tag* tag);
00088 
00089 /** Get track number from an id3tag.
00090  * 
00091  * @param tag
00092  *  Id3tag.
00093  *  
00094  * @return Track number if exist, or 0. 
00095  */
00096 char mp3tag_getTrackNumber(Id3V1Tag* tag);
00097 
00098 #ifdef __cplusplus
00099 }
00100 #endif
00101 
00102 #endif