mod_specifications.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /*
  2. * mod_specifications.cpp
  3. * ----------------------
  4. * Purpose: Mod specifications characterise the features of every editable module format in OpenMPT, such as the number of supported channels, samples, effects, etc...
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #include "stdafx.h"
  10. #include "mod_specifications.h"
  11. #include "../common/misc_util.h"
  12. #include <algorithm>
  13. OPENMPT_NAMESPACE_BEGIN
  14. namespace ModSpecs
  15. {
  16. constexpr CModSpecifications mptm_ =
  17. {
  18. /*
  19. TODO: Proper, less arbitrarily chosen values here.
  20. NOTE: If changing limits, see whether:
  21. -savefile format and GUI methods can handle new values(might not be a small task :).
  22. */
  23. MOD_TYPE_MPT, // Internal MODTYPE value
  24. "mptm", // File extension
  25. NOTE_MIN, // Minimum note index
  26. NOTE_MAX, // Maximum note index
  27. 4000, // Pattern max.
  28. 4000, // Order max.
  29. MAX_SEQUENCES, // Sequences max
  30. 1, // Channel min
  31. 127, // Channel max
  32. 32, // Min tempo
  33. 1000, // Max tempo
  34. 1, // Min Speed
  35. 255, // Max Speed
  36. 1, // Min pattern rows
  37. 1024, // Max pattern rows
  38. 25, // Max mod name length
  39. 25, // Max sample name length
  40. 12, // Max sample filename length
  41. 25, // Max instrument name length
  42. 12, // Max instrument filename length
  43. 0, // Max comment line length
  44. 3999, // SamplesMax
  45. 255, // instrumentMax
  46. MixLevels::v1_17RC3, // defaultMixLevels
  47. SONG_LINEARSLIDES | SONG_EXFILTERRANGE | SONG_ITOLDEFFECTS | SONG_ITCOMPATGXX, // Supported song flags
  48. 200, // Max MIDI mapping directives
  49. MAX_ENVPOINTS, // Envelope point count
  50. true, // Has notecut.
  51. true, // Has noteoff.
  52. true, // Has notefade.
  53. true, // Has envelope release node
  54. true, // Has song comments
  55. true, // Has "+++" pattern
  56. true, // Has "---" pattern
  57. true, // Has restart position (order)
  58. true, // Supports plugins
  59. true, // Custom pattern time signatures
  60. true, // Pattern names
  61. true, // Has artist name
  62. true, // Has default resampling
  63. true, // Fixed point tempo
  64. " JFEGHLKRXODB?CQATI?SMNVW?UY?P?Z\\:#+*?????????", // Supported Effects
  65. " vpcdabuh??gfe?o", // Supported Volume Column commands
  66. };
  67. constexpr CModSpecifications mod_ =
  68. {
  69. MOD_TYPE_MOD, // Internal MODTYPE value
  70. "mod", // File extension
  71. 25, // Minimum note index
  72. 108, // Maximum note index
  73. 128, // Pattern max.
  74. 128, // Order max.
  75. 1, // Only one order list
  76. 1, // Channel min
  77. 99, // Channel max
  78. 32, // Min tempo
  79. 255, // Max tempo
  80. 1, // Min Speed
  81. 31, // Max Speed
  82. 64, // Min pattern rows
  83. 64, // Max pattern rows
  84. 20, // Max mod name length
  85. 22, // Max sample name length
  86. 0, // Max sample filename length
  87. 0, // Max instrument name length
  88. 0, // Max instrument filename length
  89. 0, // Max comment line length
  90. 31, // SamplesMax
  91. 0, // instrumentMax
  92. MixLevels::Compatible, // defaultMixLevels
  93. SONG_PT_MODE | SONG_AMIGALIMITS | SONG_ISAMIGA, // Supported song flags
  94. 0, // Max MIDI mapping directives
  95. 0, // No instrument envelopes
  96. false, // No notecut.
  97. false, // No noteoff.
  98. false, // No notefade.
  99. false, // No envelope release node
  100. false, // No song comments
  101. false, // Doesn't have "+++" pattern
  102. false, // Doesn't have "---" pattern
  103. true, // Has restart position (order)
  104. false, // Doesn't support plugins
  105. false, // No custom pattern time signatures
  106. false, // No pattern names
  107. false, // Doesn't have artist name
  108. false, // Doesn't have default resampling
  109. false, // Integer tempo
  110. " 0123456789ABCD?FF?E??????????????????????????", // Supported Effects
  111. " ???????????????", // Supported Volume Column commands
  112. };
  113. constexpr CModSpecifications xm_ =
  114. {
  115. MOD_TYPE_XM, // Internal MODTYPE value
  116. "xm", // File extension
  117. 13, // Minimum note index
  118. 108, // Maximum note index
  119. 256, // Pattern max.
  120. 255, // Order max.
  121. 1, // Only one order list
  122. 1, // Channel min
  123. 32, // Channel max
  124. 32, // Min tempo
  125. 1000, // Max tempo
  126. 1, // Min Speed
  127. 31, // Max Speed
  128. 1, // Min pattern rows
  129. 256, // Max pattern rows
  130. 20, // Max mod name length
  131. 22, // Max sample name length
  132. 0, // Max sample filename length
  133. 22, // Max instrument name length
  134. 0, // Max instrument filename length
  135. 0, // Max comment line length
  136. 128 * 16, // SamplesMax (actually 16 per instrument)
  137. 128, // instrumentMax
  138. MixLevels::CompatibleFT2, // defaultMixLevels
  139. SONG_LINEARSLIDES, // Supported song flags
  140. 0, // Max MIDI mapping directives
  141. 12, // Envelope point count
  142. false, // No notecut.
  143. true, // Has noteoff.
  144. false, // No notefade.
  145. false, // No envelope release node
  146. false, // No song comments
  147. false, // Doesn't have "+++" pattern
  148. false, // Doesn't have "---" pattern
  149. true, // Has restart position (order)
  150. false, // Doesn't support plugins
  151. false, // No custom pattern time signatures
  152. false, // No pattern names
  153. false, // Doesn't have artist name
  154. false, // Doesn't have default resampling
  155. false, // Integer tempo
  156. " 0123456789ABCDRFFTE???GHK??XPL??????W????????", // Supported Effects
  157. " vpcdabuhlrg????", // Supported Volume Column commands
  158. };
  159. // XM with MPT extensions
  160. constexpr CModSpecifications xmEx_ =
  161. {
  162. MOD_TYPE_XM, // Internal MODTYPE value
  163. "xm", // File extension
  164. 13, // Minimum note index
  165. 108, // Maximum note index
  166. 256, // Pattern max.
  167. 255, // Order max.
  168. 1, // Only one order list
  169. 1, // Channel min
  170. 127, // Channel max
  171. 32, // Min tempo
  172. 1000, // Max tempo
  173. 1, // Min Speed
  174. 31, // Max Speed
  175. 1, // Min pattern rows
  176. 1024, // Max pattern rows
  177. 20, // Max mod name length
  178. 22, // Max sample name length
  179. 0, // Max sample filename length
  180. 22, // Max instrument name length
  181. 0, // Max instrument filename length
  182. 0, // Max comment line length
  183. MAX_SAMPLES - 1, // SamplesMax (actually 32 per instrument(256 * 32 = 8192), but limited to MAX_SAMPLES = 4000)
  184. 255, // instrumentMax
  185. MixLevels::CompatibleFT2, // defaultMixLevels
  186. SONG_LINEARSLIDES | SONG_EXFILTERRANGE, // Supported song flags
  187. 200, // Max MIDI mapping directives
  188. 12, // Envelope point count
  189. false, // No notecut.
  190. true, // Has noteoff.
  191. false, // No notefade.
  192. false, // No envelope release node
  193. true, // Has song comments
  194. false, // Doesn't have "+++" pattern
  195. false, // Doesn't have "---" pattern
  196. true, // Has restart position (order)
  197. true, // Supports plugins
  198. false, // No custom pattern time signatures
  199. true, // Pattern names
  200. true, // Has artist name
  201. false, // Doesn't have default resampling
  202. false, // Integer tempo
  203. " 0123456789ABCDRFFTE???GHK?YXPLZ\\?#??W????????", // Supported Effects
  204. " vpcdabuhlrg????", // Supported Volume Column commands
  205. };
  206. constexpr CModSpecifications s3m_ =
  207. {
  208. MOD_TYPE_S3M, // Internal MODTYPE value
  209. "s3m", // File extension
  210. 13, // Minimum note index
  211. 108, // Maximum note index
  212. 100, // Pattern max.
  213. 255, // Order max.
  214. 1, // Only one order list
  215. 1, // Channel min
  216. 32, // Channel max
  217. 33, // Min tempo
  218. 255, // Max tempo
  219. 1, // Min Speed
  220. 255, // Max Speed
  221. 64, // Min pattern rows
  222. 64, // Max pattern rows
  223. 27, // Max mod name length
  224. 27, // Max sample name length
  225. 12, // Max sample filename length
  226. 0, // Max instrument name length
  227. 0, // Max instrument filename length
  228. 0, // Max comment line length
  229. 99, // SamplesMax
  230. 0, // instrumentMax
  231. MixLevels::Compatible, // defaultMixLevels
  232. SONG_FASTVOLSLIDES | SONG_AMIGALIMITS | SONG_S3MOLDVIBRATO, // Supported song flags
  233. 0, // Max MIDI mapping directives
  234. 0, // No instrument envelopes
  235. true, // Has notecut.
  236. false, // No noteoff.
  237. false, // No notefade.
  238. false, // No envelope release node
  239. false, // No song comments
  240. true, // Has "+++" pattern
  241. true, // Has "---" pattern
  242. false, // Doesn't have restart position (order)
  243. false, // Doesn't support plugins
  244. false, // No custom pattern time signatures
  245. false, // No pattern names
  246. false, // Doesn't have artist name
  247. false, // Doesn't have default resampling
  248. false, // Integer tempo
  249. " JFEGHLKRXODB?CQATI?SMNVW?U?????????? ????????", // Supported Effects
  250. " vp?????????????", // Supported Volume Column commands
  251. };
  252. // S3M with MPT extensions
  253. constexpr CModSpecifications s3mEx_ =
  254. {
  255. MOD_TYPE_S3M, // Internal MODTYPE value
  256. "s3m", // File extension
  257. 13, // Minimum note index
  258. 108, // Maximum note index
  259. 100, // Pattern max.
  260. 255, // Order max.
  261. 1, // Only one order list
  262. 1, // Channel min
  263. 32, // Channel max
  264. 33, // Min tempo
  265. 255, // Max tempo
  266. 1, // Min Speed
  267. 255, // Max Speed
  268. 64, // Min pattern rows
  269. 64, // Max pattern rows
  270. 27, // Max mod name length
  271. 27, // Max sample name length
  272. 12, // Max sample filename length
  273. 0, // Max instrument name length
  274. 0, // Max instrument filename length
  275. 0, // Max comment line length
  276. 99, // SamplesMax
  277. 0, // instrumentMax
  278. MixLevels::Compatible, // defaultMixLevels
  279. SONG_FASTVOLSLIDES | SONG_AMIGALIMITS, // Supported song flags
  280. 0, // Max MIDI mapping directives
  281. 0, // No instrument envelopes
  282. true, // Has notecut.
  283. false, // No noteoff.
  284. false, // No notefade.
  285. false, // No envelope release node
  286. false, // No song comments
  287. true, // Has "+++" pattern
  288. true, // Has "---" pattern
  289. false, // Doesn't have restart position (order)
  290. false, // Doesn't support plugins
  291. false, // No custom pattern time signatures
  292. false, // No pattern names
  293. false, // Doesn't have artist name
  294. false, // Doesn't have default resampling
  295. false, // Integer tempo
  296. " JFEGHLKRXODB?CQATI?SMNVW?UY?P?Z????? ????????", // Supported Effects
  297. " vp?????????????", // Supported Volume Column commands
  298. };
  299. constexpr CModSpecifications it_ =
  300. {
  301. MOD_TYPE_IT, // Internal MODTYPE value
  302. "it", // File extension
  303. 1, // Minimum note index
  304. 120, // Maximum note index
  305. 200, // Pattern max.
  306. 256, // Order max.
  307. 1, // Only one order list
  308. 1, // Channel min
  309. 64, // Channel max
  310. 32, // Min tempo
  311. 255, // Max tempo
  312. 1, // Min Speed
  313. 255, // Max Speed
  314. 1, // Min pattern rows
  315. 200, // Max pattern rows
  316. 25, // Max mod name length
  317. 25, // Max sample name length
  318. 12, // Max sample filename length
  319. 25, // Max instrument name length
  320. 12, // Max instrument filename length
  321. 75, // Max comment line length
  322. 99, // SamplesMax
  323. 99, // instrumentMax
  324. MixLevels::Compatible, // defaultMixLevels
  325. SONG_LINEARSLIDES | SONG_ITOLDEFFECTS | SONG_ITCOMPATGXX, // Supported song flags
  326. 0, // Max MIDI mapping directives
  327. 25, // Envelope point count
  328. true, // Has notecut.
  329. true, // Has noteoff.
  330. true, // Has notefade.
  331. false, // No envelope release node
  332. true, // Has song comments
  333. true, // Has "+++" pattern
  334. true, // Has "--" pattern
  335. false, // Doesn't have restart position (order)
  336. false, // Doesn't support plugins
  337. false, // No custom pattern time signatures
  338. false, // No pattern names
  339. false, // Doesn't have artist name
  340. false, // Doesn't have default resampling
  341. false, // Integer tempo
  342. " JFEGHLKRXODB?CQATI?SMNVW?UY?P?Z????? ????????", // Supported Effects
  343. " vpcdab?h??gfe??", // Supported Volume Column commands
  344. };
  345. constexpr CModSpecifications itEx_ =
  346. {
  347. MOD_TYPE_IT, // Internal MODTYPE value
  348. "it", // File extension
  349. 1, // Minimum note index
  350. 120, // Maximum note index
  351. 240, // Pattern max.
  352. 256, // Order max.
  353. 1, // Only one order list
  354. 1, // Channel min
  355. 127, // Channel max
  356. 32, // Min tempo
  357. 512, // Max tempo
  358. 1, // Min Speed
  359. 255, // Max Speed
  360. 1, // Min pattern rows
  361. 1024, // Max pattern rows
  362. 25, // Max mod name length
  363. 25, // Max sample name length
  364. 12, // Max sample filename length
  365. 25, // Max instrument name length
  366. 12, // Max instrument filename length
  367. 75, // Max comment line length
  368. 3999, // SamplesMax
  369. 255, // instrumentMax
  370. MixLevels::Compatible, // defaultMixLevels
  371. SONG_LINEARSLIDES | SONG_EXFILTERRANGE | SONG_ITOLDEFFECTS | SONG_ITCOMPATGXX, // Supported song flags
  372. 200, // Max MIDI mapping directives
  373. 25, // Envelope point count
  374. true, // Has notecut.
  375. true, // Has noteoff.
  376. true, // Has notefade.
  377. false, // No envelope release node
  378. true, // Has song comments
  379. true, // Has "+++" pattern
  380. true, // Has "---" pattern
  381. false, // Doesn't have restart position (order)
  382. true, // Supports plugins
  383. false, // No custom pattern time signatures
  384. true, // Pattern names
  385. true, // Has artist name
  386. false, // Doesn't have default resampling
  387. false, // Integer tempo
  388. " JFEGHLKRXODB?CQATI?SMNVW?UY?P?Z\\?#?? ????????", // Supported Effects
  389. " vpcdab?h??gfe??", // Supported Volume Column commands
  390. };
  391. const std::array<const CModSpecifications *, 8> Collection = { &mptm_, &mod_, &s3m_, &s3mEx_, &xm_, &xmEx_, &it_, &itEx_ };
  392. const CModSpecifications &mptm = mptm_;
  393. const CModSpecifications &mod = mod_;
  394. const CModSpecifications &s3m = s3m_;
  395. const CModSpecifications &s3mEx = s3mEx_;
  396. const CModSpecifications &xm = xm_;
  397. const CModSpecifications &xmEx = xmEx_;
  398. const CModSpecifications &it = it_;
  399. const CModSpecifications &itEx = itEx_;
  400. } // namespace ModSpecs
  401. MODTYPE CModSpecifications::ExtensionToType(std::string ext)
  402. {
  403. if(ext.empty())
  404. {
  405. return MOD_TYPE_NONE;
  406. } else if(ext[0] == '.')
  407. {
  408. ext.erase(0, 1);
  409. }
  410. ext = mpt::ToLowerCaseAscii(ext);
  411. for(const auto &spec : ModSpecs::Collection)
  412. {
  413. if(ext == spec->fileExtension)
  414. {
  415. return spec->internalType;
  416. }
  417. }
  418. return MOD_TYPE_NONE;
  419. }
  420. bool CModSpecifications::HasNote(ModCommand::NOTE note) const
  421. {
  422. if(note >= noteMin && note <= noteMax)
  423. return true;
  424. else if(ModCommand::IsSpecialNote(note))
  425. {
  426. if(note == NOTE_NOTECUT)
  427. return hasNoteCut;
  428. else if(note == NOTE_KEYOFF)
  429. return hasNoteOff;
  430. else if(note == NOTE_FADE)
  431. return hasNoteFade;
  432. else
  433. return (internalType == MOD_TYPE_MPT);
  434. } else if(note == NOTE_NONE)
  435. return true;
  436. return false;
  437. }
  438. bool CModSpecifications::HasVolCommand(ModCommand::VOLCMD volcmd) const
  439. {
  440. if(volcmd >= MAX_VOLCMDS) return false;
  441. if(volcommands[volcmd] == '?') return false;
  442. return true;
  443. }
  444. bool CModSpecifications::HasCommand(ModCommand::COMMAND cmd) const
  445. {
  446. if(cmd >= MAX_EFFECTS) return false;
  447. if(commands[cmd] == '?') return false;
  448. return true;
  449. }
  450. char CModSpecifications::GetVolEffectLetter(ModCommand::VOLCMD volcmd) const
  451. {
  452. if(volcmd >= MAX_VOLCMDS) return '?';
  453. return volcommands[volcmd];
  454. }
  455. char CModSpecifications::GetEffectLetter(ModCommand::COMMAND cmd) const
  456. {
  457. if(cmd >= MAX_EFFECTS) return '?';
  458. return commands[cmd];
  459. }
  460. OPENMPT_NAMESPACE_END