1 /* 2 * This file is part of libsidplayfp, a SID player engine. 3 * 4 * Copyright 2011-2020 Leandro Nini <drfiemost@users.sourceforge.net> 5 * Copyright 2007-2010 Antti Lankila 6 * Copyright 2000 Simon White 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 */ 22 23 #ifndef SIDTUNE_H 24 #define SIDTUNE_H 25 26 #include <stdint.h> 27 28 #include "sidplayfp/siddefs.h" 29 30 class SidTuneInfo; 31 32 namespace libsidplayfp 33 { 34 class SidTuneBase; 35 class sidmemory; 36 } 37 38 /** 39 * SidTune 40 */ 41 class SID_EXTERN SidTune 42 { 43 public: 44 static const int MD5_LENGTH = 32; 45 46 private: 47 /// Filename extensions to append for various file types. 48 static const char** fileNameExtensions; 49 50 private: // ------------------------------------------------------------- 51 libsidplayfp::SidTuneBase* tune; 52 53 const char* m_statusString; 54 55 bool m_status; 56 57 public: // ---------------------------------------------------------------- 58 59 /** 60 * Load a sidtune from a file. 61 * 62 * To retrieve data from standard input pass in filename "-". 63 * If you want to override the default filename extensions use this 64 * contructor. Please note, that if the specified "fileName" 65 * does exist and the loader is able to determine its file format, 66 * this function does not try to append any file name extension. 67 * See "SidTune.cpp" for the default list of file name extensions. 68 * You can specify "fileName = 0", if you do not want to 69 * load a sidtune. You can later load one with open(). 70 * 71 * @param fileName 72 * @param fileNameExt 73 * @param separatorIsSlash 74 */ 75 SidTune(const char* fileName, const char **fileNameExt = 0, 76 bool separatorIsSlash = false); 77 78 /** 79 * Load a single-file sidtune from a memory buffer. 80 * Currently supported: PSID and MUS formats. 81 * 82 * @param oneFileFormatSidtune the buffer that contains song data 83 * @param sidtuneLength length of the buffer 84 */ 85 SidTune(const uint_least8_t* oneFileFormatSidtune, uint_least32_t sidtuneLength); 86 87 ~SidTune(); 88 89 /** 90 * The SidTune class does not copy the list of file name extensions, 91 * so make sure you keep it. If the provided pointer is 0, the 92 * default list will be activated. This is a static list which 93 * is used by all SidTune objects. 94 * 95 * @param fileNameExt 96 */ 97 void setFileNameExtensions(const char **fileNameExt); 98 99 /** 100 * Load a sidtune into an existing object from a file. 101 * 102 * @param fileName 103 * @param separatorIsSlash 104 */ 105 void load(const char* fileName, bool separatorIsSlash = false); 106 107 /** 108 * Load a sidtune into an existing object from a buffer. 109 * 110 * @param sourceBuffer the buffer that contains song data 111 * @param bufferLen length of the buffer 112 */ 113 void read(const uint8_t* sourceBuffer, uint_least32_t bufferLen); 114 115 /** 116 * Select sub-song. 117 * 118 * @param songNum the selected song (0 = default starting song) 119 * @return active song number, 0 if no tune is loaded. 120 */ 121 unsigned int selectSong(unsigned int songNum); 122 123 /** 124 * Retrieve current active sub-song specific information. 125 * 126 * @return a pointer to #SidTuneInfo, 0 if no tune is loaded. The pointer must not be deleted. 127 */ 128 const SidTuneInfo* getInfo() const; 129 130 /** 131 * Select sub-song and retrieve information. 132 * 133 * @param songNum the selected song (0 = default starting song) 134 * @return a pointer to #SidTuneInfo, 0 if no tune is loaded. The pointer must not be deleted. 135 */ 136 const SidTuneInfo* getInfo(unsigned int songNum); 137 138 /** 139 * Determine current state of object. 140 * Upon error condition use #statusString to get a descriptive 141 * text string. 142 * 143 * @return current state (true = okay, false = error) 144 */ 145 bool getStatus() const; 146 147 /** 148 * Error/status message of last operation. 149 */ 150 const char* statusString() const; 151 152 /** 153 * Copy sidtune into C64 memory (64 KB). 154 */ 155 bool placeSidTuneInC64mem(libsidplayfp::sidmemory& mem); 156 157 /** 158 * Calculates the MD5 hash of the tune, old method. 159 * Not providing an md5 buffer will cause the internal one to be used. 160 * If provided, buffer must be MD5_LENGTH + 1 161 * 162 * @return a pointer to the buffer containing the md5 string, 0 if no tune is loaded. 163 */ 164 const char *createMD5(char *md5 = 0); 165 166 /** 167 * Calculates the MD5 hash of the tune, new method, introduced in HVSC#68. 168 * Not providing an md5 buffer will cause the internal one to be used. 169 * If provided, buffer must be MD5_LENGTH + 1 170 * 171 * @return a pointer to the buffer containing the md5 string, 0 if no tune is loaded. 172 */ 173 const char *createMD5New(char *md5 = 0); 174 175 const uint_least8_t* c64Data() const; 176 177 private: // prevent copying 178 SidTune(const SidTune&); 179 SidTune& operator=(SidTune&); 180 }; 181 182 #endif /* SIDTUNE_H */ 183