1 /*************************************************************************** 2 * Copyright (C) 2008-2021 by Andrzej Rybczak * 3 * andrzej@rybczak.net * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program; if not, write to the * 17 * Free Software Foundation, Inc., * 18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * 19 ***************************************************************************/ 20 21 #include <boost/lexical_cast.hpp> 22 #include <cassert> 23 #include "utility/type_conversions.h" 24 channelsToString(int channels)25std::string channelsToString(int channels) 26 { 27 switch (channels) 28 { 29 case 1: 30 return "Mono"; 31 case 2: 32 return "Stereo"; 33 default: 34 return boost::lexical_cast<std::string>(channels); 35 } 36 } 37 charToColor(char c)38NC::Color charToColor(char c) 39 { 40 switch (c) 41 { 42 case '0': 43 return NC::Color::Default; 44 case '1': 45 return NC::Color::Black; 46 case '2': 47 return NC::Color::Red; 48 case '3': 49 return NC::Color::Green; 50 case '4': 51 return NC::Color::Yellow; 52 case '5': 53 return NC::Color::Blue; 54 case '6': 55 return NC::Color::Magenta; 56 case '7': 57 return NC::Color::Cyan; 58 case '8': 59 return NC::Color::White; 60 case '9': 61 return NC::Color::End; 62 default: 63 throw std::runtime_error("invalid character"); 64 } 65 } 66 tagTypeToString(mpd_tag_type tag)67std::string tagTypeToString(mpd_tag_type tag) 68 { 69 switch (tag) 70 { 71 case MPD_TAG_ARTIST: 72 return "Artist"; 73 case MPD_TAG_ALBUM: 74 return "Album"; 75 case MPD_TAG_ALBUM_ARTIST: 76 return "Album Artist"; 77 case MPD_TAG_TITLE: 78 return "Title"; 79 case MPD_TAG_TRACK: 80 return "Track"; 81 case MPD_TAG_GENRE: 82 return "Genre"; 83 case MPD_TAG_DATE: 84 return "Date"; 85 case MPD_TAG_COMPOSER: 86 return "Composer"; 87 case MPD_TAG_PERFORMER: 88 return "Performer"; 89 case MPD_TAG_COMMENT: 90 return "Comment"; 91 case MPD_TAG_DISC: 92 return "Disc"; 93 default: 94 return ""; 95 } 96 } 97 tagTypeToSetFunction(mpd_tag_type tag)98MPD::MutableSong::SetFunction tagTypeToSetFunction(mpd_tag_type tag) 99 { 100 switch (tag) 101 { 102 case MPD_TAG_ARTIST: 103 return &MPD::MutableSong::setArtist; 104 case MPD_TAG_ALBUM: 105 return &MPD::MutableSong::setAlbum; 106 case MPD_TAG_ALBUM_ARTIST: 107 return &MPD::MutableSong::setAlbumArtist; 108 case MPD_TAG_TITLE: 109 return &MPD::MutableSong::setTitle; 110 case MPD_TAG_TRACK: 111 return &MPD::MutableSong::setTrack; 112 case MPD_TAG_GENRE: 113 return &MPD::MutableSong::setGenre; 114 case MPD_TAG_DATE: 115 return &MPD::MutableSong::setDate; 116 case MPD_TAG_COMPOSER: 117 return &MPD::MutableSong::setComposer; 118 case MPD_TAG_PERFORMER: 119 return &MPD::MutableSong::setPerformer; 120 case MPD_TAG_COMMENT: 121 return &MPD::MutableSong::setComment; 122 case MPD_TAG_DISC: 123 return &MPD::MutableSong::setDisc; 124 default: 125 return nullptr; 126 } 127 } 128 charToTagType(char c)129mpd_tag_type charToTagType(char c) 130 { 131 switch (c) 132 { 133 case 'a': 134 return MPD_TAG_ARTIST; 135 case 'A': 136 return MPD_TAG_ALBUM_ARTIST; 137 case 't': 138 return MPD_TAG_TITLE; 139 case 'b': 140 return MPD_TAG_ALBUM; 141 case 'y': 142 return MPD_TAG_DATE; 143 case 'n': 144 return MPD_TAG_TRACK; 145 case 'g': 146 return MPD_TAG_GENRE; 147 case 'c': 148 return MPD_TAG_COMPOSER; 149 case 'p': 150 return MPD_TAG_PERFORMER; 151 case 'd': 152 return MPD_TAG_DISC; 153 case 'C': 154 return MPD_TAG_COMMENT; 155 default: 156 assert(false); 157 return MPD_TAG_ARTIST; 158 } 159 } 160 charToGetFunction(char c)161MPD::Song::GetFunction charToGetFunction(char c) 162 { 163 switch (c) 164 { 165 case 'l': 166 return &MPD::Song::getLength; 167 case 'D': 168 return &MPD::Song::getDirectory; 169 case 'f': 170 return &MPD::Song::getName; 171 case 'a': 172 return &MPD::Song::getArtist; 173 case 'A': 174 return &MPD::Song::getAlbumArtist; 175 case 't': 176 return &MPD::Song::getTitle; 177 case 'b': 178 return &MPD::Song::getAlbum; 179 case 'y': 180 return &MPD::Song::getDate; 181 case 'n': 182 return &MPD::Song::getTrackNumber; 183 case 'N': 184 return &MPD::Song::getTrack; 185 case 'g': 186 return &MPD::Song::getGenre; 187 case 'c': 188 return &MPD::Song::getComposer; 189 case 'p': 190 return &MPD::Song::getPerformer; 191 case 'd': 192 return &MPD::Song::getDisc; 193 case 'C': 194 return &MPD::Song::getComment; 195 case 'P': 196 return &MPD::Song::getPriority; 197 default: 198 return nullptr; 199 } 200 } 201 getFunctionToTagType(MPD::Song::GetFunction f)202boost::optional<mpd_tag_type> getFunctionToTagType(MPD::Song::GetFunction f) 203 { 204 if (f == &MPD::Song::getArtist) 205 return MPD_TAG_ARTIST; 206 else if (f == &MPD::Song::getTitle) 207 return MPD_TAG_TITLE; 208 else if (f == &MPD::Song::getAlbum) 209 return MPD_TAG_ALBUM; 210 else if (f == &MPD::Song::getAlbumArtist) 211 return MPD_TAG_ALBUM_ARTIST; 212 else if (f == &MPD::Song::getTrack) 213 return MPD_TAG_TRACK; 214 else if (f == &MPD::Song::getDate) 215 return MPD_TAG_DATE; 216 else if (f == &MPD::Song::getGenre) 217 return MPD_TAG_GENRE; 218 else if (f == &MPD::Song::getComposer) 219 return MPD_TAG_COMPOSER; 220 else if (f == &MPD::Song::getPerformer) 221 return MPD_TAG_PERFORMER; 222 else if (f == &MPD::Song::getComment) 223 return MPD_TAG_COMMENT; 224 else if (f == &MPD::Song::getDisc) 225 return MPD_TAG_DISC; 226 else if (f == &MPD::Song::getComment) 227 return MPD_TAG_COMMENT; 228 else 229 return boost::none; 230 } 231 itemTypeToString(MPD::Item::Type type)232std::string itemTypeToString(MPD::Item::Type type) 233 { 234 std::string result; 235 switch (type) 236 { 237 case MPD::Item::Type::Directory: 238 result = "directory"; 239 break; 240 case MPD::Item::Type::Song: 241 result = "song"; 242 break; 243 case MPD::Item::Type::Playlist: 244 result = "playlist"; 245 break; 246 } 247 return result; 248 } 249