1 /* -*- mode: C; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ 2 /* 3 * Copyright (C) 2009-2011 Tiger Soldier <tigersoldier@gmail.com> 4 * 5 * This file is part of OSD Lyrics. 6 * 7 * OSD Lyrics is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * OSD Lyrics is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with OSD Lyrics. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #ifndef _OL_MUSIC_INFO_H_ 21 #define _OL_MUSIC_INFO_H_ 22 #include <stdlib.h> 23 24 /** 25 * defines a music's infomation structure 26 */ 27 typedef struct _OlMusicInfo OlMusicInfo; 28 struct _OlMusicInfo 29 { 30 char *title; /* The title of the music */ 31 char *artist; /* The artist of the music */ 32 char *album; /* The album name of the music */ 33 int track_number; /* The track number of the music */ 34 char *uri; /* URI of the music */ 35 }; 36 37 OlMusicInfo *ol_music_info_new (); 38 39 /** 40 * @brief Initialize an OlMusicInfo 41 * All the fields of music_info will set to empty without memory free 42 * 43 * @param music_info 44 */ 45 void ol_music_info_init (OlMusicInfo *music_info); 46 47 /** 48 * @brief Clears an OlMusicInfo 49 * All fields will be freed if they are not empty 50 * 51 * @param music_info 52 */ 53 void ol_music_info_clear (OlMusicInfo *music_info); 54 void ol_music_info_copy (OlMusicInfo *dest, const OlMusicInfo *src); 55 56 /** 57 * @brief Sets the value of music title 58 * 59 * @param music_info An OlMusicInfo 60 * @param title The value of title. If not NULL, it will be copied 61 * inside the music_info 62 */ 63 void ol_music_info_set_title (OlMusicInfo *music_info, 64 const char *title); 65 const char *ol_music_info_get_title (const OlMusicInfo *music_info); 66 67 /** 68 * @brief Sets the artist of music 69 * 70 * @param music_info An OlMusicInfo 71 * @param artist The value of artist. If not NULL, it will be copied 72 * inside the music_info 73 */ 74 void ol_music_info_set_artist (OlMusicInfo *music_info, 75 const char *artist); 76 const char *ol_music_info_get_artist (const OlMusicInfo *music_info); 77 78 /** 79 * @brief Sets the name of music album 80 * 81 * @param music_info An OlMusicInfo 82 * @param album The name of album. If not NULL, it will be copied 83 * inside the music_info 84 */ 85 void ol_music_info_set_album (OlMusicInfo *music_info, 86 const char *album); 87 const char *ol_music_info_get_album (const OlMusicInfo *music_info); 88 89 void ol_music_info_set_track_number (OlMusicInfo *music_info, 90 int track_number); 91 int ol_music_info_get_track_number (const OlMusicInfo *music_info); 92 93 /** 94 * @brief Sets the location of music file 95 * 96 * @param music_info An OlMusicInfo 97 * @param uri The value of uri. If not NULL, it will be copied 98 * inside the music_info 99 */ 100 void ol_music_info_set_uri (OlMusicInfo *music_info, 101 const char *uri); 102 const char *ol_music_info_get_uri (const OlMusicInfo *music_info); 103 104 /** 105 * @brief Check whether two MusicInfos are equal 106 * Two MusicInfos are equal if and only if all their fields are equal 107 * 108 * @param lhs An OlMusicInfo, or NULL 109 * @param rhs An OlMusicInfo, or NULL 110 * 111 * @return If lhs is equal to rhs, return 1. Otherwise return 0 112 */ 113 int ol_music_info_equal (const OlMusicInfo *lhs, 114 const OlMusicInfo *rhs); 115 116 /** 117 * @ Free music_info, including its members. 118 * 119 * @param music_info 120 */ 121 void ol_music_info_destroy (OlMusicInfo *music_info); 122 123 /** 124 * @brief Converts a music info to a string 125 * The returned buffer is NUL-terminated 126 * @param music_info A MusicInfo 127 * @param buffer Buffer of serialzed string, or NULL. 128 * If not NULL, the serialzed string is terminated with NUL. 129 * @param count The size of the buffer. 130 * 131 * @return The length of the serialized string, regardless of the size of buffer. 132 */ 133 int ol_music_info_serialize (OlMusicInfo *music_info, 134 char *buffer, 135 size_t count); 136 137 /** 138 * @brief Converts a string to an OlMusicInfo 139 * 140 * @param music_info A MusicInfo 141 * @param data The serialized string from an OlMusicInfo 142 * 143 * @return 1 if succeeded, or 0 if failed 144 */ 145 int ol_music_info_deserialize (OlMusicInfo *music_info, 146 const char *data); 147 #endif /* _OL_MUSIC_INFO_H_ */ 148