cp_loader_it_info.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*************************************************************************/
  2. /* cp_loader_it_info.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "cp_loader_it.h"
  31. CPLoader::Error CPLoader_IT::load_header(bool p_dont_set) {
  32. char aux_songname[26];
  33. file->get_byte_array((uint8_t *)aux_songname, 26);
  34. if (!p_dont_set)
  35. song->set_name(aux_songname);
  36. uint8_t aux_hlmin = file->get_byte();
  37. uint8_t aux_hlmaj = file->get_byte();
  38. if (aux_hlmin == 0) aux_hlmin = 4;
  39. if (aux_hlmaj == 0) aux_hlmaj = 16;
  40. if (!p_dont_set) {
  41. song->set_row_highlight_minor(aux_hlmin);
  42. song->set_row_highlight_major(aux_hlmaj);
  43. }
  44. header.ordnum = file->get_word();
  45. header.insnum = file->get_word();
  46. header.smpnum = file->get_word();
  47. header.patnum = file->get_word();
  48. header.cwt = file->get_word(); /* Created with tracker (y.xx = 0x0yxx) */
  49. header.cmwt = file->get_word(); /* Compatible with tracker ver > than val. */
  50. header.flags = file->get_word();
  51. if (!p_dont_set) {
  52. song->set_stereo(header.flags & 1);
  53. song->set_linear_slides(header.flags & 8);
  54. song->set_old_effects(header.flags & 16);
  55. song->set_compatible_gxx(header.flags & 32);
  56. song->set_instruments(header.flags & 4);
  57. }
  58. header.special = file->get_word();
  59. if (!p_dont_set) {
  60. song->set_global_volume(file->get_byte());
  61. song->set_mixing_volume(file->get_byte());
  62. song->set_speed(file->get_byte());
  63. song->set_tempo(file->get_byte());
  64. song->set_stereo_separation(file->get_byte());
  65. } else {
  66. file->get_byte(); // skip
  67. file->get_byte(); // skip
  68. file->get_byte(); // skip
  69. file->get_byte(); // skip
  70. file->get_byte(); // skip
  71. }
  72. file->get_byte(); // ZERO Byte
  73. header.msglength = file->get_word();
  74. header.msgoffset = file->get_dword();
  75. char chibi[4];
  76. file->get_byte_array((uint8_t *)chibi, 4);
  77. header.is_chibi = (chibi[0] == 'C' && chibi[1] == 'H' && chibi[2] == 'B' && chibi[3] == 'I');
  78. for (int i = 0; i < 64; i++) {
  79. uint8_t panbyte = file->get_byte();
  80. uint8_t pan_dst = (panbyte < 65) ? panbyte : 32;
  81. bool surround_dst = (panbyte == 100);
  82. bool mute_dst = (panbyte >= 128);
  83. if (!p_dont_set) {
  84. song->set_channel_pan(i, pan_dst);
  85. song->set_channel_surround(i, surround_dst);
  86. song->set_channel_mute(i, mute_dst);
  87. }
  88. }
  89. for (int i = 0; i < 64; i++) {
  90. unsigned char cv = file->get_byte();
  91. if (!p_dont_set)
  92. song->set_channel_volume(i, cv);
  93. }
  94. CP_ERR_COND_V(file->eof_reached(), FILE_CORRUPTED);
  95. CP_ERR_COND_V(file->get_error(), FILE_CORRUPTED);
  96. return FILE_OK;
  97. }
  98. CPLoader::Error CPLoader_IT::load_effects() {
  99. if (!header.is_chibi)
  100. return FILE_OK; //no effects, regular IT file
  101. /* GOTO End of IT header */
  102. file->seek(0xC0 + header.ordnum + header.insnum * 4 + header.smpnum * 4 + header.patnum * 4);
  103. if (file->get_byte() > 0) //not made with this version, ignore extended info
  104. return FILE_OK;
  105. /* Chibitracker Extended info */
  106. switch (file->get_byte()) {
  107. case CPSong::REVERB_MODE_ROOM: {
  108. song->set_reverb_mode(CPSong::REVERB_MODE_ROOM);
  109. } break;
  110. case CPSong::REVERB_MODE_STUDIO_SMALL: {
  111. song->set_reverb_mode(CPSong::REVERB_MODE_STUDIO_SMALL);
  112. } break;
  113. case CPSong::REVERB_MODE_STUDIO_MEDIUM: {
  114. song->set_reverb_mode(CPSong::REVERB_MODE_STUDIO_MEDIUM);
  115. } break;
  116. case CPSong::REVERB_MODE_STUDIO_LARGE: {
  117. song->set_reverb_mode(CPSong::REVERB_MODE_STUDIO_LARGE);
  118. } break;
  119. case CPSong::REVERB_MODE_HALL: {
  120. song->set_reverb_mode(CPSong::REVERB_MODE_HALL);
  121. } break;
  122. case CPSong::REVERB_MODE_SPACE_ECHO: {
  123. song->set_reverb_mode(CPSong::REVERB_MODE_SPACE_ECHO);
  124. } break;
  125. case CPSong::REVERB_MODE_ECHO: {
  126. song->set_reverb_mode(CPSong::REVERB_MODE_ECHO);
  127. } break;
  128. case CPSong::REVERB_MODE_DELAY: {
  129. song->set_reverb_mode(CPSong::REVERB_MODE_DELAY);
  130. } break;
  131. case CPSong::REVERB_MODE_HALF_ECHO: {
  132. song->set_reverb_mode(CPSong::REVERB_MODE_HALF_ECHO);
  133. } break;
  134. }
  135. //chorus
  136. song->set_chorus_speed_hz10(file->get_byte());
  137. song->set_chorus_delay_ms(file->get_byte());
  138. song->set_chorus_depth_ms10(file->get_byte());
  139. song->set_chorus_separation_ms(file->get_byte());
  140. for (int i = 0; i < CPPattern::WIDTH; i++) {
  141. song->set_channel_reverb(i, file->get_byte());
  142. }
  143. for (int i = 0; i < CPPattern::WIDTH; i++) {
  144. song->set_channel_chorus(i, file->get_byte());
  145. }
  146. return FILE_OK;
  147. }
  148. CPLoader::Error CPLoader_IT::load_message() {
  149. if (!(header.special & 1)) {
  150. return FILE_OK;
  151. }
  152. file->seek(header.msgoffset);
  153. //(void*)tmpmsg=malloc(header.msglength+1);
  154. char message[8000];
  155. char *tmpmsg = message;
  156. file->get_byte_array((uint8_t *)tmpmsg, header.msglength);
  157. tmpmsg[header.msglength] = 0;
  158. for (int i = 0; i < header.msglength; i++)
  159. if (tmpmsg[i] == '\r') tmpmsg[i] = '\n';
  160. song->set_message(tmpmsg);
  161. return FILE_OK;
  162. }
  163. CPLoader::Error CPLoader_IT::load_orders() {
  164. file->seek(0xC0);
  165. for (int i = 0; i < header.ordnum; i++) {
  166. uint8_t aux_order = file->get_byte();
  167. CPOrder order = CP_ORDER_NONE;
  168. if (i >= CPSong::MAX_ORDERS)
  169. continue;
  170. if (aux_order == 254) {
  171. order = CP_ORDER_BREAK;
  172. } else if (aux_order < 200) {
  173. order = aux_order;
  174. //nothing!
  175. }
  176. song->set_order(i, order);
  177. }
  178. if (file->eof_reached() || file->get_error()) {
  179. return FILE_CORRUPTED;
  180. }
  181. return FILE_OK;
  182. }