libopenmpt.hpp 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. /*
  2. * libopenmpt.hpp
  3. * --------------
  4. * Purpose: libopenmpt public c++ interface
  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. #ifndef LIBOPENMPT_HPP
  10. #define LIBOPENMPT_HPP
  11. #include "libopenmpt_config.h"
  12. #include <exception>
  13. #include <iosfwd>
  14. #include <iostream>
  15. #include <map>
  16. #include <string>
  17. #include <string_view>
  18. #include <vector>
  19. #include <cstddef>
  20. #include <cstdint>
  21. /*!
  22. * \page libopenmpt_cpp_overview C++ API
  23. *
  24. * \section libopenmpt_cpp_error Error Handling
  25. *
  26. * libopenmpt C++ uses C++ exception handling for errror reporting.
  27. *
  28. * Unless otherwise noted, any libopenmpt function may throw exceptions and
  29. * all exceptions thrown by libopenmpt itself are derived from
  30. * openmpt::exception.
  31. * In addition, any libopenmpt function may also throw any exception specified
  32. * by the C++ language and C++ standard library. These are all derived from
  33. * std::exception.
  34. *
  35. * \section libopenmpt_cpp_strings Strings
  36. *
  37. * - All strings returned from libopenmpt are encoded in UTF-8.
  38. * - All strings passed to libopenmpt should also be encoded in UTF-8.
  39. * Behaviour in case of invalid UTF-8 is unspecified.
  40. * - libopenmpt does not enforce or expect any particular Unicode
  41. * normalization form.
  42. *
  43. * \section libopenmpt_cpp_fileio File I/O
  44. *
  45. * libopenmpt can use 3 different strategies for file I/O.
  46. *
  47. * - openmpt::module::module() with any kind of memory buffer as parameter will
  48. * load the module from the provided memory buffer, which will require loading
  49. * all data upfront by the library
  50. * caller.
  51. * - openmpt::module::module() with a seekable std::istream as parameter will
  52. * load the module via the stream interface. libopenmpt will not implement an
  53. * additional buffering layer in this case whih means the callbacks are assumed
  54. * to be performant even with small i/o sizes.
  55. * - openmpt::module::module() with an unseekable std::istream as parameter
  56. * will load the module via the stream interface. libopempt will make an
  57. * internal copy as it goes along, and sometimes have to pre-cache the whole
  58. * file in case it needs to know the complete file size. This strategy is
  59. * intended to be used if the file is located on a high latency network.
  60. *
  61. * | constructor | speed | memory consumption |
  62. * | ----------------: | :----: | :----------------: |
  63. * | memory buffer | <p style="background-color:green" >fast </p> | <p style="background-color:yellow">medium</p> |
  64. * | seekable stream | <p style="background-color:red" >slow </p> | <p style="background-color:green" >low </p> |
  65. * | unseekable stream | <p style="background-color:yellow">medium</p> | <p style="background-color:red" >high </p> |
  66. *
  67. * In all cases, the data or stream passed to the constructor is no longer
  68. * needed after the openmpt::module has been constructed and can be destroyed
  69. * by the caller.
  70. *
  71. * \section libopenmpt_cpp_outputformat Output Format
  72. *
  73. * libopenmpt supports a wide range of PCM output formats:
  74. * [8000..192000]/[mono|stereo|quad]/[f32|i16].
  75. *
  76. * Unless you have some very specific requirements demanding a particular aspect
  77. * of the output format, you should always prefer 48000/stereo/f32 as the
  78. * libopenmpt PCM format.
  79. *
  80. * - Please prefer 48000Hz unless the user explicitly demands something else.
  81. * Practically all audio equipment and file formats use 48000Hz nowadays.
  82. * - Practically all module formats are made for stereo output. Mono will not
  83. * give you any measurable speed improvements and can trivially be obtained from
  84. * the stereo output anyway. Quad is not expected by almost all modules and even
  85. * if they do use surround effects, they expect the effects to be mixed to
  86. * stereo.
  87. * - Floating point output provides headroom instead of hard clipping if the
  88. * module is louder than 0dBFs, will give you a better signal-to-noise ratio
  89. * than int16 output, and avoid the need to apply an additional dithering to the
  90. * output by libopenmpt. Unless your platform has no floating point unit at all,
  91. * floating point will thus also be slightly faster.
  92. *
  93. * \section libopenmpt_cpp_threads libopenmpt in multi-threaded environments
  94. *
  95. * - libopenmpt is thread-aware.
  96. * - Individual libopenmpt objects are not thread-safe.
  97. * - libopenmpt itself does not spawn any user-visible threads but may spawn
  98. * threads for internal use.
  99. * - You must ensure to only ever access a particular libopenmpt object via
  100. * non-const member functions from a single thread at a time.
  101. * - You may access a particular libopenmpt object concurrently from different
  102. * threads when using only const member functions from all threads.
  103. * - Consecutive accesses can happen from different threads.
  104. * - Different objects can be accessed concurrently from different threads.
  105. *
  106. * \section libopenmpt-cpp-windows Windows support
  107. *
  108. * Using the libopenmpt C++ API when libopenmpt is compiled as a DLL on Windows
  109. * requires `#define LIBOPENMPT_USE_DLL` (or some equivalent build system
  110. * configuration) before `#include <libopenmpt/libopenmpt.hpp>` in order to
  111. * correctly import the symbols from the DLL.
  112. *
  113. * \section libopenmpt-cpp-detailed Detailed documentation
  114. *
  115. * \ref libopenmpt_cpp
  116. *
  117. * \section libopenmpt_cpp_examples Example
  118. *
  119. * \include libopenmpt_example_cxx.cpp
  120. *
  121. */
  122. /*! \defgroup libopenmpt_cpp libopenmpt C++ */
  123. namespace openmpt {
  124. /*! \addtogroup libopenmpt_cpp
  125. @{
  126. */
  127. #if defined(_MSC_VER)
  128. #pragma warning(push)
  129. #pragma warning(disable:4275)
  130. #endif
  131. //! libopenmpt exception base class
  132. /*!
  133. Base class used for all exceptions that are thrown by libopenmpt itself. Libopenmpt may additionally throw any exception thrown by the standard library which are all derived from std::exception.
  134. \sa \ref libopenmpt_cpp_error
  135. */
  136. class LIBOPENMPT_CXX_API exception : public std::exception {
  137. private:
  138. char * text;
  139. public:
  140. exception( const std::string & text ) noexcept;
  141. exception( const exception & other ) noexcept;
  142. exception( exception && other ) noexcept;
  143. exception & operator = ( const exception & other ) noexcept;
  144. exception & operator = ( exception && other ) noexcept;
  145. virtual ~exception() noexcept;
  146. const char * what() const noexcept override;
  147. }; // class exception
  148. #if defined(_MSC_VER)
  149. #pragma warning(pop)
  150. #endif
  151. //! Get the libopenmpt version number
  152. /*!
  153. Returns the libopenmpt version number.
  154. \return The value represents (major << 24 + minor << 16 + patch << 0).
  155. \remarks libopenmpt < 0.3.0-pre used the following scheme: (major << 24 + minor << 16 + revision).
  156. */
  157. LIBOPENMPT_CXX_API std::uint32_t get_library_version();
  158. //! Get the core version number
  159. /*!
  160. Return the OpenMPT core version number.
  161. \return The value represents (majormajor << 24 + major << 16 + minor << 8 + minorminor).
  162. */
  163. LIBOPENMPT_CXX_API std::uint32_t get_core_version();
  164. namespace string {
  165. //! Return a verbose library version string from openmpt::string::get(). \deprecated Please use `"library_version"` directly.
  166. static const char library_version LIBOPENMPT_ATTR_DEPRECATED [] = "library_version";
  167. //! Return a verbose library features string from openmpt::string::get(). \deprecated Please use `"library_features"` directly.
  168. static const char library_features LIBOPENMPT_ATTR_DEPRECATED [] = "library_features";
  169. //! Return a verbose OpenMPT core version string from openmpt::string::get(). \deprecated Please use `"core_version"` directly.
  170. static const char core_version LIBOPENMPT_ATTR_DEPRECATED [] = "core_version";
  171. //! Return information about the current build (e.g. the build date or compiler used) from openmpt::string::get(). \deprecated Please use `"build"` directly.
  172. static const char build LIBOPENMPT_ATTR_DEPRECATED [] = "build";
  173. //! Return all contributors from openmpt::string::get(). \deprecated Please use `"credits"` directly.
  174. static const char credits LIBOPENMPT_ATTR_DEPRECATED [] = "credits";
  175. //! Return contact information about libopenmpt from openmpt::string::get(). \deprecated Please use `"contact"` directly.
  176. static const char contact LIBOPENMPT_ATTR_DEPRECATED [] = "contact";
  177. //! Return the libopenmpt license from openmpt::string::get(). \deprecated Please use `"license"` directly.
  178. static const char license LIBOPENMPT_ATTR_DEPRECATED [] = "license";
  179. //! Get library related metadata.
  180. /*!
  181. \param key Key to query.
  182. Possible keys are:
  183. - "library_version": verbose library version string
  184. - "library_version_major": libopenmpt major version number
  185. - "library_version_minor": libopenmpt minor version number
  186. - "library_version_patch": libopenmpt patch version number
  187. - "library_version_prerel": libopenmpt pre-release version string
  188. - "library_version_is_release": "1" if the version is an officially released version
  189. - "library_features": verbose library features string
  190. - "core_version": verbose OpenMPT core version string
  191. - "source_url": original source code URL
  192. - "source_date": original source code date
  193. - "source_revision": original source code revision
  194. - "source_is_modified": "1" if the original source has been modified
  195. - "source_has_mixed_revisions": "1" if the original source has been compiled from different various revision
  196. - "source_is_package": "1" if the original source has been obtained from a source pacakge instead of source code version control
  197. - "build": information about the current build (e.g. the build date or compiler used)
  198. - "build_compiler": information about the compiler used to build libopenmpt
  199. - "credits": all contributors
  200. - "contact": contact information about libopenmpt
  201. - "license": the libopenmpt license
  202. - "url": libopenmpt website URL
  203. - "support_forum_url": libopenmpt support and discussions forum URL
  204. - "bugtracker_url": libopenmpt bug and issue tracker URL
  205. \return A (possibly multi-line) string containing the queried information. If no information is available, the string is empty.
  206. */
  207. LIBOPENMPT_CXX_API std::string get( const std::string & key );
  208. } // namespace string
  209. //! Get a list of supported file extensions
  210. /*!
  211. \return The list of extensions supported by this libopenmpt build. The extensions are returned lower-case without a leading dot.
  212. */
  213. LIBOPENMPT_CXX_API std::vector<std::string> get_supported_extensions();
  214. //! Query whether a file extension is supported
  215. /*!
  216. \param extension file extension to query without a leading dot. The case is ignored.
  217. \return true if the extension is supported by libopenmpt, false otherwise.
  218. \deprecated Please use openmpt::is_extension_supported2().
  219. */
  220. LIBOPENMPT_ATTR_DEPRECATED LIBOPENMPT_CXX_API bool is_extension_supported( const std::string & extension );
  221. //! Query whether a file extension is supported
  222. /*!
  223. \param extension file extension to query without a leading dot. The case is ignored.
  224. \return true if the extension is supported by libopenmpt, false otherwise.
  225. \since 0.5.0
  226. */
  227. LIBOPENMPT_CXX_API bool is_extension_supported2( std::string_view extension );
  228. //! Roughly scan the input stream to find out whether libopenmpt might be able to open it
  229. /*!
  230. \param stream Input stream to scan.
  231. \param effort Effort to make when validating stream. Effort 0.0 does not even look at stream at all and effort 1.0 completely loads the file from stream. A lower effort requires less data to be loaded but only gives a rough estimate answer. Use an effort of 0.25 to only verify the header data of the module file.
  232. \param log Log where warning and errors are written.
  233. \return Probability between 0.0 and 1.0.
  234. \remarks openmpt::probe_file_header() provides a simpler and faster interface that fits almost all use cases better. It is recommended to use openmpt::probe_file_header() instead of openmpt::could_open_probability().
  235. \remarks openmpt::could_open_probability() can return any value between 0.0 and 1.0. Only 0.0 and 1.0 are definitive answers, all values in between are just estimates. In general, any return value >0.0 means that you should try loading the file, and any value below 1.0 means that loading may fail. If you want a threshold above which you can be reasonably sure that libopenmpt will be able to load the file, use >=0.5. If you see the need for a threshold below which you could reasonably outright reject a file, use <0.25 (Note: Such a threshold for rejecting on the lower end is not recommended, but may be required for better integration into some other framework's probe scoring.).
  236. \remarks openmpt::could_open_probability() expects the complete file data to be eventually available to it, even if it is asked to just parse the header. Verification will be unreliable (both false positives and false negatives), if you pretend that the file is just some few bytes of initial data threshold in size. In order to really just access the first bytes of a file, check in your std::istream implementation whether data or seeking is requested beyond your initial data threshold, and in that case, return an error. openmpt::could_open_probability() will treat this as any other I/O error and return 0.0. You must not expect the correct result in this case. You instead must remember that it asked for more data than you currently want to provide to it and treat this situation as if openmpt::could_open_probability() returned 0.5.
  237. \sa \ref libopenmpt_c_fileio
  238. \sa openmpt::probe_file_header()
  239. \since 0.3.0
  240. */
  241. LIBOPENMPT_CXX_API double could_open_probability( std::istream & stream, double effort = 1.0, std::ostream & log = std::clog );
  242. //! Roughly scan the input stream to find out whether libopenmpt might be able to open it
  243. /*!
  244. \deprecated Please use openmpt::could_open_probability().
  245. */
  246. LIBOPENMPT_ATTR_DEPRECATED LIBOPENMPT_CXX_API double could_open_propability( std::istream & stream, double effort = 1.0, std::ostream & log = std::clog );
  247. //! Get recommended header size for successfull format probing
  248. /*!
  249. \sa openmpt::probe_file_header()
  250. \since 0.3.0
  251. */
  252. LIBOPENMPT_CXX_API std::size_t probe_file_header_get_recommended_size();
  253. //! Probe for module formats in openmpt::probe_file_header(). \since 0.3.0 \deprecated Please use openmpt::probe_file_header_flags_modules2.
  254. static const std::uint64_t probe_file_header_flags_modules LIBOPENMPT_ATTR_DEPRECATED = 0x1ull;
  255. //! Probe for module-specific container formats in openmpt::probe_file_header(). \since 0.3.0 \deprecated Please use openmpt::probe_file_header_flags_containers2.
  256. static const std::uint64_t probe_file_header_flags_containers LIBOPENMPT_ATTR_DEPRECATED = 0x2ull;
  257. //! Probe for the default set of formats in openmpt::probe_file_header(). \since 0.3.0 \deprecated Please use openmpt::probe_file_header_flags_default2.
  258. static const std::uint64_t probe_file_header_flags_default LIBOPENMPT_ATTR_DEPRECATED = 0x1ull | 0x2ull;
  259. //! Probe for no formats in openmpt::probe_file_header(). \since 0.3.0 \deprecated Please use openmpt::probe_file_header_flags_none2.
  260. static const std::uint64_t probe_file_header_flags_none LIBOPENMPT_ATTR_DEPRECATED = 0x0ull;
  261. //! Possible values for openmpt::probe_file_header() flags parameter. \since 0.6.0
  262. enum probe_file_header_flags : std::uint64_t {
  263. //! Probe for module formats in openmpt::probe_file_header(). \since 0.6.0
  264. probe_file_header_flags_modules2 = 0x1ull,
  265. //! Probe for module-specific container formats in openmpt::probe_file_header(). \since 0.6.0
  266. probe_file_header_flags_containers2 = 0x2ull,
  267. //! Probe for the default set of formats in openmpt::probe_file_header(). \since 0.6.0
  268. probe_file_header_flags_default2 = probe_file_header_flags_modules2 | probe_file_header_flags_containers2,
  269. //! Probe for no formats in openmpt::probe_file_header(). \since 0.6.0
  270. probe_file_header_flags_none2 = 0x0ull
  271. };
  272. //! Possible return values for openmpt::probe_file_header(). \since 0.3.0
  273. enum probe_file_header_result {
  274. probe_file_header_result_success = 1,
  275. probe_file_header_result_failure = 0,
  276. probe_file_header_result_wantmoredata = -1
  277. };
  278. //! Probe the provided bytes from the beginning of a file for supported file format headers to find out whether libopenmpt might be able to open it
  279. /*!
  280. \param flags Bit mask of openmpt::probe_file_header_flags_modules2 and openmpt::probe_file_header_flags_containers2, or openmpt::probe_file_header_flags_default2.
  281. \param data Beginning of the file data.
  282. \param size Size of the beginning of the file data.
  283. \param filesize Full size of the file data on disk.
  284. \remarks It is recommended to provide openmpt::probe_file_header_get_recommended_size() bytes of data for data and size. If the file is smaller, only provide the filesize amount and set size and filesize to the file's size.
  285. \remarks openmpt::could_open_probability() provides a more elaborate interface that might be required for special use cases. It is recommended to use openmpt::probe_file_header() though, if possible.
  286. \retval probe_file_header_result_success The file will most likely be supported by libopenmpt.
  287. \retval probe_file_header_result_failure The file is not supported by libopenmpt.
  288. \retval probe_file_header_result_wantmoredata An answer could not be determined with the amount of data provided.
  289. \sa openmpt::probe_file_header_get_recommended_size()
  290. \sa openmpt::could_open_probability()
  291. \since 0.5.0
  292. */
  293. LIBOPENMPT_CXX_API int probe_file_header( std::uint64_t flags, const std::byte * data, std::size_t size, std::uint64_t filesize );
  294. //! Probe the provided bytes from the beginning of a file for supported file format headers to find out whether libopenmpt might be able to open it
  295. /*!
  296. \param flags Bit mask of openmpt::probe_file_header_flags_modules2 and openmpt::probe_file_header_flags_containers2, or openmpt::probe_file_header_flags_default2.
  297. \param data Beginning of the file data.
  298. \param size Size of the beginning of the file data.
  299. \param filesize Full size of the file data on disk.
  300. \remarks It is recommended to provide openmpt::probe_file_header_get_recommended_size() bytes of data for data and size. If the file is smaller, only provide the filesize amount and set size and filesize to the file's size.
  301. \remarks openmpt::could_open_probability() provides a more elaborate interface that might be required for special use cases. It is recommended to use openmpt::probe_file_header() though, if possible.
  302. \retval probe_file_header_result_success The file will most likely be supported by libopenmpt.
  303. \retval probe_file_header_result_failure The file is not supported by libopenmpt.
  304. \retval probe_file_header_result_wantmoredata An answer could not be determined with the amount of data provided.
  305. \sa openmpt::probe_file_header_get_recommended_size()
  306. \sa openmpt::could_open_probability()
  307. \since 0.3.0
  308. */
  309. LIBOPENMPT_CXX_API int probe_file_header( std::uint64_t flags, const std::uint8_t * data, std::size_t size, std::uint64_t filesize );
  310. //! Probe the provided bytes from the beginning of a file for supported file format headers to find out whether libopenmpt might be able to open it
  311. /*!
  312. \param flags Bit mask of openmpt::probe_file_header_flags_modules2 and openmpt::probe_file_header_flags_containers2, or openmpt::probe_file_header_flags_default2.
  313. \param data Beginning of the file data.
  314. \param size Size of the beginning of the file data.
  315. \remarks It is recommended to use the overload of this function that also takes the filesize as parameter if at all possile. libopenmpt can provide more accurate answers if the filesize is known.
  316. \remarks It is recommended to provide openmpt::probe_file_header_get_recommended_size() bytes of data for data and size. If the file is smaller, only provide the filesize amount and set size to the file's size.
  317. \remarks openmpt::could_open_probability() provides a more elaborate interface that might be required for special use cases. It is recommended to use openmpt::probe_file_header() though, if possible.
  318. \retval probe_file_header_result_success The file will most likely be supported by libopenmpt.
  319. \retval probe_file_header_result_failure The file is not supported by libopenmpt.
  320. \retval probe_file_header_result_wantmoredata An answer could not be determined with the amount of data provided.
  321. \sa openmpt::probe_file_header_get_recommended_size()
  322. \sa openmpt::could_open_probability()
  323. \since 0.5.0
  324. */
  325. LIBOPENMPT_CXX_API int probe_file_header( std::uint64_t flags, const std::byte * data, std::size_t size );
  326. //! Probe the provided bytes from the beginning of a file for supported file format headers to find out whether libopenmpt might be able to open it
  327. /*!
  328. \param flags Bit mask of openmpt::probe_file_header_flags_modules2 and openmpt::probe_file_header_flags_containers2, or openmpt::probe_file_header_flags_default2.
  329. \param data Beginning of the file data.
  330. \param size Size of the beginning of the file data.
  331. \remarks It is recommended to use the overload of this function that also takes the filesize as parameter if at all possile. libopenmpt can provide more accurate answers if the filesize is known.
  332. \remarks It is recommended to provide openmpt::probe_file_header_get_recommended_size() bytes of data for data and size. If the file is smaller, only provide the filesize amount and set size to the file's size.
  333. \remarks openmpt::could_open_probability() provides a more elaborate interface that might be required for special use cases. It is recommended to use openmpt::probe_file_header() though, if possible.
  334. \retval probe_file_header_result_success The file will most likely be supported by libopenmpt.
  335. \retval probe_file_header_result_failure The file is not supported by libopenmpt.
  336. \retval probe_file_header_result_wantmoredata An answer could not be determined with the amount of data provided.
  337. \sa openmpt::probe_file_header_get_recommended_size()
  338. \sa openmpt::could_open_probability()
  339. \since 0.3.0
  340. */
  341. LIBOPENMPT_CXX_API int probe_file_header( std::uint64_t flags, const std::uint8_t * data, std::size_t size );
  342. //! Probe the provided bytes from the beginning of a file for supported file format headers to find out whether libopenmpt might be able to open it
  343. /*!
  344. \param flags Bit mask of openmpt::probe_file_header_flags_modules2 and openmpt::probe_file_header_flags_containers2, or openmpt::probe_file_header_flags_default2.
  345. \param stream Input stream to scan.
  346. \remarks stream is left in an unspecified state when this function returns.
  347. \remarks openmpt::could_open_probability() provides a more elaborate interface that might be required for special use cases. It is recommended to use openmpt::probe_file_header() though, if possible.
  348. \retval probe_file_header_result_success The file will most likely be supported by libopenmpt.
  349. \retval probe_file_header_result_failure The file is not supported by libopenmpt.
  350. \retval probe_file_header_result_wantmoredata An answer could not be determined with the amount of data provided.
  351. \sa openmpt::probe_file_header_get_recommended_size()
  352. \sa openmpt::could_open_probability()
  353. \since 0.3.0
  354. */
  355. LIBOPENMPT_CXX_API int probe_file_header( std::uint64_t flags, std::istream & stream );
  356. class module_impl;
  357. class module_ext;
  358. namespace detail {
  359. typedef std::map< std::string, std::string > initial_ctls_map;
  360. } // namespace detail
  361. class LIBOPENMPT_CXX_API module {
  362. friend class module_ext;
  363. public:
  364. //! Parameter index to use with openmpt::module::get_render_param and openmpt::module::set_render_param
  365. enum render_param {
  366. //! Master Gain
  367. /*!
  368. The related value represents a relative gain in milliBel.\n
  369. The default value is 0.\n
  370. The supported value range is unlimited.\n
  371. */
  372. RENDER_MASTERGAIN_MILLIBEL = 1,
  373. //! Stereo Separation
  374. /*!
  375. The related value represents the stereo separation generated by the libopenmpt mixer in percent.\n
  376. The default value is 100.\n
  377. The supported value range is [0,200].\n
  378. */
  379. RENDER_STEREOSEPARATION_PERCENT = 2,
  380. //! Interpolation Filter
  381. /*!
  382. The related value represents the interpolation filter length used by the libopenmpt mixer.\n
  383. The default value is 0, which indicates a recommended default value.\n
  384. The supported value range is [0,inf). Values greater than the implementation limit are clamped to the maximum supported value.\n
  385. Currently supported values:
  386. - 0: internal default
  387. - 1: no interpolation (zero order hold)
  388. - 2: linear interpolation
  389. - 4: cubic interpolation
  390. - 8: windowed sinc with 8 taps
  391. */
  392. RENDER_INTERPOLATIONFILTER_LENGTH = 3,
  393. //! Volume Ramping Strength
  394. /*!
  395. The related value represents the amount of volume ramping done by the libopenmpt mixer.\n
  396. The default value is -1, which indicates a recommended default value.\n
  397. The meaningful value range is [-1..10].\n
  398. A value of 0 completely disables volume ramping. This might cause clicks in sound output.\n
  399. Higher values imply slower/softer volume ramps.
  400. */
  401. RENDER_VOLUMERAMPING_STRENGTH = 4
  402. };
  403. //! Parameter index to use with openmpt::module::get_pattern_row_channel_command, openmpt::module::format_pattern_row_channel_command and openmpt::module::highlight_pattern_row_channel_command
  404. enum command_index {
  405. command_note = 0,
  406. command_instrument = 1,
  407. command_volumeffect = 2,
  408. command_effect = 3,
  409. command_volume = 4,
  410. command_parameter = 5
  411. };
  412. private:
  413. module_impl * impl;
  414. private:
  415. // non-copyable
  416. module( const module & );
  417. void operator = ( const module & );
  418. private:
  419. // for module_ext
  420. module();
  421. void set_impl( module_impl * i );
  422. public:
  423. //! Construct an openmpt::module
  424. /*!
  425. \param stream Input stream from which the module is loaded. After the constructor has finished successfully, the input position of stream is set to the byte after the last byte that has been read. If the constructor fails, the state of the input position of stream is undefined.
  426. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  427. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  428. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  429. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  430. \sa \ref libopenmpt_cpp_fileio
  431. */
  432. module( std::istream & stream, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  433. /*!
  434. \param data Data to load the module from.
  435. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  436. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  437. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  438. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  439. \sa \ref libopenmpt_cpp_fileio
  440. \since 0.5.0
  441. */
  442. module( const std::vector<std::byte> & data, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  443. /*!
  444. \param beg Begin of data to load the module from.
  445. \param end End of data to load the module from.
  446. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  447. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  448. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  449. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  450. \sa \ref libopenmpt_cpp_fileio
  451. \since 0.5.0
  452. */
  453. module( const std::byte * beg, const std::byte * end, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  454. /*!
  455. \param data Data to load the module from.
  456. \param size Amount of data available.
  457. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  458. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  459. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  460. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  461. \sa \ref libopenmpt_cpp_fileio
  462. \since 0.5.0
  463. */
  464. module( const std::byte * data, std::size_t size, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  465. /*!
  466. \param data Data to load the module from.
  467. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  468. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  469. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  470. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  471. \sa \ref libopenmpt_cpp_fileio
  472. */
  473. module( const std::vector<std::uint8_t> & data, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  474. /*!
  475. \param beg Begin of data to load the module from.
  476. \param end End of data to load the module from.
  477. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  478. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  479. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  480. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  481. \sa \ref libopenmpt_cpp_fileio
  482. */
  483. module( const std::uint8_t * beg, const std::uint8_t * end, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  484. /*!
  485. \param data Data to load the module from.
  486. \param size Amount of data available.
  487. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  488. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  489. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  490. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  491. \sa \ref libopenmpt_cpp_fileio
  492. */
  493. module( const std::uint8_t * data, std::size_t size, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  494. /*!
  495. \param data Data to load the module from.
  496. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  497. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  498. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  499. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  500. \sa \ref libopenmpt_cpp_fileio
  501. */
  502. module( const std::vector<char> & data, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  503. /*!
  504. \param beg Begin of data to load the module from.
  505. \param end End of data to load the module from.
  506. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  507. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  508. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  509. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  510. \sa \ref libopenmpt_cpp_fileio
  511. */
  512. module( const char * beg, const char * end, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  513. /*!
  514. \param data Data to load the module from.
  515. \param size Amount of data available.
  516. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  517. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  518. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  519. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  520. \sa \ref libopenmpt_cpp_fileio
  521. */
  522. module( const char * data, std::size_t size, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  523. /*!
  524. \param data Data to load the module from.
  525. \param size Amount of data available.
  526. \param log Log where any warnings or errors are printed to. The lifetime of the reference has to be as long as the lifetime of the module instance.
  527. \param ctls A map of initial ctl values, see openmpt::module::get_ctls.
  528. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the provided file cannot be opened.
  529. \remarks The input data can be discarded after an openmpt::module has been constructed successfully.
  530. \sa \ref libopenmpt_cpp_fileio
  531. */
  532. module( const void * data, std::size_t size, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
  533. virtual ~module();
  534. public:
  535. //! Select a sub-song from a multi-song module
  536. /*!
  537. \param subsong Index of the sub-song. -1 plays all sub-songs consecutively.
  538. \throws openmpt::exception Throws an exception derived from openmpt::exception if sub-song is not in range [-1,openmpt::module::get_num_subsongs()[
  539. \sa openmpt::module::get_num_subsongs, openmpt::module::get_selected_subsong, openmpt::module::get_subsong_names
  540. \remarks Whether subsong -1 (all subsongs consecutively), subsong 0 or some other subsong is selected by default, is an implementation detail and subject to change. If you do not want to care about subsongs, it is recommended to just not call openmpt::module::select_subsong() at all.
  541. */
  542. void select_subsong( std::int32_t subsong );
  543. //! Get currently selected sub-song from a multi-song module
  544. /*!
  545. \return Currently selected sub-song. -1 for all subsongs consecutively, 0 or greater for the current sub-song index.
  546. \sa openmpt::module::get_num_subsongs, openmpt::module::select_subsong, openmpt::module::get_subsong_names
  547. \since 0.3.0
  548. */
  549. std::int32_t get_selected_subsong() const;
  550. //! Set Repeat Count
  551. /*!
  552. \param repeat_count Repeat Count
  553. - -1: repeat forever
  554. - 0: play once, repeat zero times (the default)
  555. - n>0: play once and repeat n times after that
  556. \sa openmpt::module::get_repeat_count
  557. */
  558. void set_repeat_count( std::int32_t repeat_count );
  559. //! Get Repeat Count
  560. /*!
  561. \return Repeat Count
  562. - -1: repeat forever
  563. - 0: play once, repeat zero times (the default)
  564. - n>0: play once and repeat n times after that
  565. \sa openmpt::module::set_repeat_count
  566. */
  567. std::int32_t get_repeat_count() const;
  568. //! Get approximate song duration
  569. /*!
  570. \return Approximate duration of current sub-song in seconds.
  571. \remarks The function may return infinity if the pattern data is too complex to evaluate.
  572. */
  573. double get_duration_seconds() const;
  574. //! Set approximate current song position
  575. /*!
  576. \param seconds Seconds to seek to. If seconds is out of range, the position gets set to song start or end respectively.
  577. \return Approximate new song position in seconds.
  578. \sa openmpt::module::get_position_seconds
  579. */
  580. double set_position_seconds( double seconds );
  581. //! Get current song position
  582. /*!
  583. \return Current song position in seconds.
  584. \sa openmpt::module::set_position_seconds
  585. */
  586. double get_position_seconds() const;
  587. //! Set approximate current song position
  588. /*!
  589. If order or row are out of range, to position is not modified and the current position is returned.
  590. \param order Pattern order number to seek to.
  591. \param row Pattern row number to seek to.
  592. \return Approximate new song position in seconds.
  593. \sa openmpt::module::set_position_seconds
  594. \sa openmpt::module::get_position_seconds
  595. */
  596. double set_position_order_row( std::int32_t order, std::int32_t row );
  597. //! Get render parameter
  598. /*!
  599. \param param Parameter to query. See openmpt::module::render_param.
  600. \return The current value of the parameter.
  601. \throws openmpt::exception Throws an exception derived from openmpt::exception if param is invalid.
  602. \sa openmpt::module::render_param
  603. \sa openmpt::module::set_render_param
  604. */
  605. std::int32_t get_render_param( int param ) const;
  606. //! Set render parameter
  607. /*!
  608. \param param Parameter to set. See openmpt::module::render_param.
  609. \param value The value to set param to.
  610. \throws openmpt::exception Throws an exception derived from openmpt::exception if param is invalid or value is out of range.
  611. \sa openmpt::module::render_param
  612. \sa openmpt::module::get_render_param
  613. */
  614. void set_render_param( int param, std::int32_t value );
  615. /*@{*/
  616. //! Render audio data
  617. /*!
  618. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  619. \param count Number of audio frames to render per channel.
  620. \param mono Pointer to a buffer of at least count elements that receives the mono/center output.
  621. \return The number of frames actually rendered.
  622. \retval 0 The end of song has been reached.
  623. \remarks The output buffers are only written to up to the returned number of elements.
  624. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  625. \remarks It is recommended to use the floating point API because of the greater dynamic range and no implied clipping.
  626. \sa \ref libopenmpt_cpp_outputformat
  627. */
  628. std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * mono );
  629. //! Render audio data
  630. /*!
  631. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  632. \param count Number of audio frames to render per channel.
  633. \param left Pointer to a buffer of at least count elements that receives the left output.
  634. \param right Pointer to a buffer of at least count elements that receives the right output.
  635. \return The number of frames actually rendered.
  636. \retval 0 The end of song has been reached.
  637. \remarks The output buffers are only written to up to the returned number of elements.
  638. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  639. \remarks It is recommended to use the floating point API because of the greater dynamic range and no implied clipping.
  640. \sa \ref libopenmpt_cpp_outputformat
  641. */
  642. std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right );
  643. //! Render audio data
  644. /*!
  645. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  646. \param count Number of audio frames to render per channel.
  647. \param left Pointer to a buffer of at least count elements that receives the left output.
  648. \param right Pointer to a buffer of at least count elements that receives the right output.
  649. \param rear_left Pointer to a buffer of at least count elements that receives the rear left output.
  650. \param rear_right Pointer to a buffer of at least count elements that receives the rear right output.
  651. \return The number of frames actually rendered.
  652. \retval 0 The end of song has been reached.
  653. \remarks The output buffers are only written to up to the returned number of elements.
  654. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  655. \remarks It is recommended to use the floating point API because of the greater dynamic range and no implied clipping.
  656. \sa \ref libopenmpt_cpp_outputformat
  657. */
  658. std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right );
  659. //! Render audio data
  660. /*!
  661. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  662. \param count Number of audio frames to render per channel.
  663. \param mono Pointer to a buffer of at least count elements that receives the mono/center output.
  664. \return The number of frames actually rendered.
  665. \retval 0 The end of song has been reached.
  666. \remarks The output buffers are only written to up to the returned number of elements.
  667. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  668. \remarks Floating point samples are in the [-1.0..1.0] nominal range. They are not clipped to that range though and thus might overshoot.
  669. \sa \ref libopenmpt_cpp_outputformat
  670. */
  671. std::size_t read( std::int32_t samplerate, std::size_t count, float * mono );
  672. //! Render audio data
  673. /*!
  674. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  675. \param count Number of audio frames to render per channel.
  676. \param left Pointer to a buffer of at least count elements that receives the left output.
  677. \param right Pointer to a buffer of at least count elements that receives the right output.
  678. \return The number of frames actually rendered.
  679. \retval 0 The end of song has been reached.
  680. \remarks The output buffers are only written to up to the returned number of elements.
  681. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  682. \remarks Floating point samples are in the [-1.0..1.0] nominal range. They are not clipped to that range though and thus might overshoot.
  683. \sa \ref libopenmpt_cpp_outputformat
  684. */
  685. std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right );
  686. //! Render audio data
  687. /*!
  688. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  689. \param count Number of audio frames to render per channel.
  690. \param left Pointer to a buffer of at least count elements that receives the left output.
  691. \param right Pointer to a buffer of at least count elements that receives the right output.
  692. \param rear_left Pointer to a buffer of at least count elements that receives the rear left output.
  693. \param rear_right Pointer to a buffer of at least count elements that receives the rear right output.
  694. \return The number of frames actually rendered.
  695. \retval 0 The end of song has been reached.
  696. \remarks The output buffers are only written to up to the returned number of elements.
  697. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  698. \remarks Floating point samples are in the [-1.0..1.0] nominal range. They are not clipped to that range though and thus might overshoot.
  699. \sa \ref libopenmpt_cpp_outputformat
  700. */
  701. std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right );
  702. //! Render audio data
  703. /*!
  704. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  705. \param count Number of audio frames to render per channel.
  706. \param interleaved_stereo Pointer to a buffer of at least count*2 elements that receives the interleaved stereo output in the order (L,R).
  707. \return The number of frames actually rendered.
  708. \retval 0 The end of song has been reached.
  709. \remarks The output buffers are only written to up to the returned number of elements.
  710. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  711. \remarks It is recommended to use the floating point API because of the greater dynamic range and no implied clipping.
  712. \sa \ref libopenmpt_cpp_outputformat
  713. */
  714. std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_stereo );
  715. //! Render audio data
  716. /*!
  717. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  718. \param count Number of audio frames to render per channel.
  719. \param interleaved_quad Pointer to a buffer of at least count*4 elements that receives the interleaved quad surround output in the order (L,R,RL,RR).
  720. \return The number of frames actually rendered.
  721. \retval 0 The end of song has been reached.
  722. \remarks The output buffers are only written to up to the returned number of elements.
  723. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  724. \remarks It is recommended to use the floating point API because of the greater dynamic range and no implied clipping.
  725. \sa \ref libopenmpt_cpp_outputformat
  726. */
  727. std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_quad );
  728. //! Render audio data
  729. /*!
  730. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  731. \param count Number of audio frames to render per channel.
  732. \param interleaved_stereo Pointer to a buffer of at least count*2 elements that receives the interleaved stereo output in the order (L,R).
  733. \return The number of frames actually rendered.
  734. \retval 0 The end of song has been reached.
  735. \remarks The output buffers are only written to up to the returned number of elements.
  736. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  737. \remarks Floating point samples are in the [-1.0..1.0] nominal range. They are not clipped to that range though and thus might overshoot.
  738. \sa \ref libopenmpt_cpp_outputformat
  739. */
  740. std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, float * interleaved_stereo );
  741. //! Render audio data
  742. /*!
  743. \param samplerate Sample rate to render output. Should be in [8000,192000], but this is not enforced.
  744. \param count Number of audio frames to render per channel.
  745. \param interleaved_quad Pointer to a buffer of at least count*4 elements that receives the interleaved quad surround output in the order (L,R,RL,RR).
  746. \return The number of frames actually rendered.
  747. \retval 0 The end of song has been reached.
  748. \remarks The output buffers are only written to up to the returned number of elements.
  749. \remarks You can freely switch between any of the "read*" variants if you see a need to do so. libopenmpt tries to introduce as little switching annoyances as possible. Normally, you would only use a single one of these functions for rendering a particular module.
  750. \remarks Floating point samples are in the [-1.0..1.0] nominal range. They are not clipped to that range though and thus might overshoot.
  751. \sa \ref libopenmpt_cpp_outputformat
  752. */
  753. std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, float * interleaved_quad );
  754. /*@}*/
  755. //! Get the list of supported metadata item keys
  756. /*!
  757. \return Metadata item keys supported by openmpt::module::get_metadata
  758. \sa openmpt::module::get_metadata
  759. */
  760. std::vector<std::string> get_metadata_keys() const;
  761. //! Get a metadata item value
  762. /*!
  763. \param key Metadata item key to query. Use openmpt::module::get_metadata_keys to check for available keys.
  764. Possible keys are:
  765. - type: Module format extension (e.g. it) or another similar identifier for modules formats that typically do not use a file extension
  766. - type_long: Format name associated with the module format (e.g. Impulse Tracker)
  767. - originaltype: Module format extension (e.g. it) of the original module in case the actual type is a converted format (e.g. mo3 or gdm)
  768. - originaltype_long: Format name associated with the module format (e.g. Impulse Tracker) of the original module in case the actual type is a converted format (e.g. mo3 or gdm)
  769. - container: Container format the module file is embedded in, if any (e.g. umx)
  770. - container_long: Full container name if the module is embedded in a container (e.g. Unreal Music)
  771. - tracker: Tracker that was (most likely) used to save the module file, if known
  772. - artist: Author of the module
  773. - title: Module title
  774. - date: Date the module was last saved, in ISO-8601 format.
  775. - message: Song message. If the song message is empty or the module format does not support song messages, a list of instrument and sample names is returned instead.
  776. - message_raw: Song message. If the song message is empty or the module format does not support song messages, an empty string is returned.
  777. - warnings: A list of warnings that were generated while loading the module.
  778. \return The associated value for key.
  779. \sa openmpt::module::get_metadata_keys
  780. */
  781. std::string get_metadata( const std::string & key ) const;
  782. //! Get the current estimated beats per minute (BPM).
  783. /*!
  784. \remarks Many module formats lack time signature metadata. It is common that this estimate is off by a factor of two, but other multipliers are also possible.
  785. \remarks Due to the nature of how module tempo works, the estimate may change slightly after switching libopenmpt's output to a different sample rate.
  786. \return The current estimated BPM.
  787. */
  788. double get_current_estimated_bpm() const;
  789. //! Get the current speed
  790. /*!
  791. \return The current speed in ticks per row.
  792. */
  793. std::int32_t get_current_speed() const;
  794. //! Get the current tempo
  795. /*!
  796. \return The current tempo in tracker units. The exact meaning of this value depends on the tempo mode being used.
  797. */
  798. std::int32_t get_current_tempo() const;
  799. //! Get the current order
  800. /*!
  801. \return The current order at which the module is being played back.
  802. */
  803. std::int32_t get_current_order() const;
  804. //! Get the current pattern
  805. /*!
  806. \return The current pattern that is being played.
  807. */
  808. std::int32_t get_current_pattern() const;
  809. //! Get the current row
  810. /*!
  811. \return The current row at which the current pattern is being played.
  812. */
  813. std::int32_t get_current_row() const;
  814. //! Get the current amount of playing channels.
  815. /*!
  816. \return The amount of sample channels that are currently being rendered.
  817. */
  818. std::int32_t get_current_playing_channels() const;
  819. //! Get an approximate indication of the channel volume.
  820. /*!
  821. \param channel The channel whose volume should be retrieved.
  822. \return The approximate channel volume.
  823. \remarks The returned value is solely based on the note velocity and does not take the actual waveform of the playing sample into account.
  824. */
  825. float get_current_channel_vu_mono( std::int32_t channel ) const;
  826. //! Get an approximate indication of the channel volume on the front-left speaker.
  827. /*!
  828. \param channel The channel whose volume should be retrieved.
  829. \return The approximate channel volume.
  830. \remarks The returned value is solely based on the note velocity and does not take the actual waveform of the playing sample into account.
  831. */
  832. float get_current_channel_vu_left( std::int32_t channel ) const;
  833. //! Get an approximate indication of the channel volume on the front-right speaker.
  834. /*!
  835. \param channel The channel whose volume should be retrieved.
  836. \return The approximate channel volume.
  837. \remarks The returned value is solely based on the note velocity and does not take the actual waveform of the playing sample into account.
  838. */
  839. float get_current_channel_vu_right( std::int32_t channel ) const;
  840. //! Get an approximate indication of the channel volume on the rear-left speaker.
  841. /*!
  842. \param channel The channel whose volume should be retrieved.
  843. \return The approximate channel volume.
  844. \remarks The returned value is solely based on the note velocity and does not take the actual waveform of the playing sample into account.
  845. */
  846. float get_current_channel_vu_rear_left( std::int32_t channel ) const;
  847. //! Get an approximate indication of the channel volume on the rear-right speaker.
  848. /*!
  849. \param channel The channel whose volume should be retrieved.
  850. \return The approximate channel volume.
  851. \remarks The returned value is solely based on the note velocity and does not take the actual waveform of the playing sample into account.
  852. */
  853. float get_current_channel_vu_rear_right( std::int32_t channel ) const;
  854. //! Get the number of sub-songs
  855. /*!
  856. \return The number of sub-songs in the module. This includes any "hidden" songs (songs that share the same sequence, but start at different order indices) and "normal" sub-songs or "sequences" (if the format supports them).
  857. \sa openmpt::module::get_subsong_names, openmpt::module::select_subsong, openmpt::module::get_selected_subsong
  858. */
  859. std::int32_t get_num_subsongs() const;
  860. //! Get the number of pattern channels
  861. /*!
  862. \return The number of pattern channels in the module. Not all channels do necessarily contain data.
  863. \remarks The number of pattern channels is completely independent of the number of output channels. libopenmpt can render modules in mono, stereo or quad surround, but the choice of which of the three modes to use must not be made based on the return value of this function, which may be any positive integer amount. Only use this function for informational purposes.
  864. */
  865. std::int32_t get_num_channels() const;
  866. //! Get the number of orders
  867. /*!
  868. \return The number of orders in the current sequence of the module.
  869. */
  870. std::int32_t get_num_orders() const;
  871. //! Get the number of patterns
  872. /*!
  873. \return The number of distinct patterns in the module.
  874. */
  875. std::int32_t get_num_patterns() const;
  876. //! Get the number of instruments
  877. /*!
  878. \return The number of instrument slots in the module. Instruments are a layer on top of samples, and are not supported by all module formats.
  879. */
  880. std::int32_t get_num_instruments() const;
  881. //! Get the number of samples
  882. /*!
  883. \return The number of sample slots in the module.
  884. */
  885. std::int32_t get_num_samples() const;
  886. //! Get a list of sub-song names
  887. /*!
  888. \return All sub-song names.
  889. \sa openmpt::module::get_num_subsongs, openmpt::module::select_subsong, openmpt::module::get_selected_subsong
  890. */
  891. std::vector<std::string> get_subsong_names() const;
  892. //! Get a list of channel names
  893. /*!
  894. \return All channel names.
  895. \sa openmpt::module::get_num_channels
  896. */
  897. std::vector<std::string> get_channel_names() const;
  898. //! Get a list of order names
  899. /*!
  900. \return All order names.
  901. \sa openmpt::module::get_num_orders
  902. */
  903. std::vector<std::string> get_order_names() const;
  904. //! Get a list of pattern names
  905. /*!
  906. \return All pattern names.
  907. \sa openmpt::module::get_num_patterns
  908. */
  909. std::vector<std::string> get_pattern_names() const;
  910. //! Get a list of instrument names
  911. /*!
  912. \return All instrument names.
  913. \sa openmpt::module::get_num_instruments
  914. */
  915. std::vector<std::string> get_instrument_names() const;
  916. //! Get a list of sample names
  917. /*!
  918. \return All sample names.
  919. \sa openmpt::module::get_num_samples
  920. */
  921. std::vector<std::string> get_sample_names() const;
  922. //! Get pattern at order position
  923. /*!
  924. \param order The order item whose pattern index should be retrieved.
  925. \return The pattern index found at the given order position of the current sequence.
  926. */
  927. std::int32_t get_order_pattern( std::int32_t order ) const;
  928. //! Get the number of rows in a pattern
  929. /*!
  930. \param pattern The pattern whose row count should be retrieved.
  931. \return The number of rows in the given pattern. If the pattern does not exist, 0 is returned.
  932. */
  933. std::int32_t get_pattern_num_rows( std::int32_t pattern ) const;
  934. //! Get raw pattern content
  935. /*!
  936. \param pattern The pattern whose data should be retrieved.
  937. \param row The row from which the data should be retrieved.
  938. \param channel The channel from which the data should be retrieved.
  939. \param command The cell index at which the data should be retrieved. See openmpt::module::command_index
  940. \return The internal, raw pattern data at the given pattern position.
  941. */
  942. std::uint8_t get_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
  943. //! Get formatted (human-readable) pattern content
  944. /*!
  945. \param pattern The pattern whose data should be retrieved.
  946. \param row The row from which the data should be retrieved.
  947. \param channel The channel from which the data should be retrieved.
  948. \param command The cell index at which the data should be retrieved.
  949. \return The formatted pattern data at the given pattern position. See openmpt::module::command_index
  950. \sa openmpt::module::highlight_pattern_row_channel_command
  951. */
  952. std::string format_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
  953. //! Get highlighting information for formatted pattern content
  954. /*!
  955. \param pattern The pattern whose data should be retrieved.
  956. \param row The row from which the data should be retrieved.
  957. \param channel The channel from which the data should be retrieved.
  958. \param command The cell index at which the data should be retrieved. See openmpt::module::command_index
  959. \return The highlighting string for the formatted pattern data as retrieved by openmpt::module::get_pattern_row_channel_command at the given pattern position.
  960. \remarks The returned string will map each character position of the string returned by openmpt::module::get_pattern_row_channel_command to a highlighting instruction.
  961. Possible highlighting characters are:
  962. - " " : empty/space
  963. - "." : empty/dot
  964. - "n" : generic note
  965. - "m" : special note
  966. - "i" : generic instrument
  967. - "u" : generic volume column effect
  968. - "v" : generic volume column parameter
  969. - "e" : generic effect column effect
  970. - "f" : generic effect column parameter
  971. \sa openmpt::module::get_pattern_row_channel_command
  972. */
  973. std::string highlight_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
  974. //! Get formatted (human-readable) pattern content
  975. /*!
  976. \param pattern The pattern whose data should be retrieved.
  977. \param row The row from which the data should be retrieved.
  978. \param channel The channel from which the data should be retrieved.
  979. \param width The maximum number of characters the string should contain. 0 means no limit.
  980. \param pad If true, the string will be resized to the exact length provided in the width parameter.
  981. \return The formatted pattern data at the given pattern position.
  982. \sa openmpt::module::highlight_pattern_row_channel
  983. */
  984. std::string format_pattern_row_channel( std::int32_t pattern, std::int32_t row, std::int32_t channel, std::size_t width = 0, bool pad = true ) const;
  985. //! Get highlighting information for formatted pattern content
  986. /*!
  987. \param pattern The pattern whose data should be retrieved.
  988. \param row The row from which the data should be retrieved.
  989. \param channel The channel from which the data should be retrieved.
  990. \param width The maximum number of characters the string should contain. 0 means no limit.
  991. \param pad If true, the string will be resized to the exact length provided in the width parameter.
  992. \return The highlighting string for the formatted pattern data as retrieved by openmpt::module::format_pattern_row_channel at the given pattern position.
  993. \sa openmpt::module::format_pattern_row_channel
  994. */
  995. std::string highlight_pattern_row_channel( std::int32_t pattern, std::int32_t row, std::int32_t channel, std::size_t width = 0, bool pad = true ) const;
  996. //! Retrieve supported ctl keys
  997. /*!
  998. \return A vector containing all supported ctl keys.
  999. \remarks Currently supported ctl values are:
  1000. - load.skip_samples (boolean): Set to "1" to avoid loading samples into memory
  1001. - load.skip_patterns (boolean): Set to "1" to avoid loading patterns into memory
  1002. - load.skip_plugins (boolean): Set to "1" to avoid loading plugins
  1003. - load.skip_subsongs_init (boolean): Set to "1" to avoid pre-initializing sub-songs. Skipping results in faster module loading but slower seeking.
  1004. - seek.sync_samples (boolean): Set to "1" to sync sample playback when using openmpt::module::set_position_seconds or openmpt::module::set_position_order_row.
  1005. - subsong (integer): The current subsong. Setting it has identical semantics as openmpt::module::select_subsong(), getting it returns the currently selected subsong.
  1006. - play.at_end (text): Chooses the behaviour when the end of song is reached:
  1007. - "fadeout": Fades the module out for a short while. Subsequent reads after the fadeout will return 0 rendered frames.
  1008. - "continue": Returns 0 rendered frames when the song end is reached. Subsequent reads will continue playing from the song start or loop start.
  1009. - "stop": Returns 0 rendered frames when the song end is reached. Subsequent reads will return 0 rendered frames.
  1010. - play.tempo_factor (floatingpoint): Set a floating point tempo factor. "1.0" is the default tempo.
  1011. - play.pitch_factor (floatingpoint): Set a floating point pitch factor. "1.0" is the default pitch.
  1012. - render.resampler.emulate_amiga (boolean): Set to "1" to enable the Amiga resampler for Amiga modules. This emulates the sound characteristics of the Paula chip and overrides the selected interpolation filter. Non-Amiga module formats are not affected by this setting.
  1013. - render.resampler.emulate_amiga_type (string): Configures the filter type to use for the Amiga resampler. Supported values are:
  1014. - "auto": Filter type is chosen by the library and might change. This is the default.
  1015. - "a500": Amiga A500 filter.
  1016. - "a1200": Amiga A1200 filter.
  1017. - "unfiltered": BLEP synthesis without model-specific filters. The LED filter is ignored by this setting. This filter mode is considered to be experimental and might change in the future.
  1018. - render.opl.volume_factor (floatingpoint): Set volume factor applied to synthesized OPL sounds, relative to the default OPL volume.
  1019. - dither (integer): Set the dither algorithm that is used for the 16 bit versions of openmpt::module::read. Supported values are:
  1020. - 0: No dithering.
  1021. - 1: Default mode. Chosen by OpenMPT code, might change.
  1022. - 2: Rectangular, 0.5 bit depth, no noise shaping (original ModPlug Tracker).
  1023. - 3: Rectangular, 1 bit depth, simple 1st order noise shaping
  1024. An exclamation mark ("!") or a question mark ("?") can be appended to any ctl key in order to influence the behaviour in case of an unknown ctl key. "!" causes an exception to be thrown; "?" causes the ctl to be silently ignored. In case neither is appended to the key name, unknown init_ctls are ignored by default and other ctls throw an exception by default.
  1025. */
  1026. std::vector<std::string> get_ctls() const;
  1027. //! Get current ctl value
  1028. /*!
  1029. \param ctl The ctl key whose value should be retrieved.
  1030. \return The associated ctl value.
  1031. \sa openmpt::module::get_ctls
  1032. \deprecated Please use openmpt::module::ctl_get_boolean(), openmpt::module::ctl_get_integer(), openmpt::module::ctl_get_floatingpoint(), or openmpt::module::ctl_get_text().
  1033. */
  1034. LIBOPENMPT_ATTR_DEPRECATED std::string ctl_get( const std::string & ctl ) const;
  1035. //! Get current ctl boolean value
  1036. /*!
  1037. \param ctl The ctl key whose value should be retrieved.
  1038. \return The associated ctl value.
  1039. \sa openmpt::module::get_ctls
  1040. \since 0.5.0
  1041. */
  1042. bool ctl_get_boolean( std::string_view ctl ) const;
  1043. //! Get current ctl integer value
  1044. /*!
  1045. \param ctl The ctl key whose value should be retrieved.
  1046. \return The associated ctl value.
  1047. \sa openmpt::module::get_ctls
  1048. \since 0.5.0
  1049. */
  1050. std::int64_t ctl_get_integer( std::string_view ctl ) const;
  1051. //! Get current ctl floatingpoint value
  1052. /*!
  1053. \param ctl The ctl key whose value should be retrieved.
  1054. \return The associated ctl value.
  1055. \sa openmpt::module::get_ctls
  1056. \since 0.5.0
  1057. */
  1058. double ctl_get_floatingpoint( std::string_view ctl ) const;
  1059. //! Get current ctl text value
  1060. /*!
  1061. \param ctl The ctl key whose value should be retrieved.
  1062. \return The associated ctl value.
  1063. \sa openmpt::module::get_ctls
  1064. \since 0.5.0
  1065. */
  1066. std::string ctl_get_text( std::string_view ctl ) const;
  1067. //! Set ctl value
  1068. /*!
  1069. \param ctl The ctl key whose value should be set.
  1070. \param value The value that should be set.
  1071. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the value is not sensible (e.g. negative tempo factor) or under the circumstances outlined in openmpt::module::get_ctls.
  1072. \sa openmpt::module::get_ctls
  1073. \deprecated Please use openmpt::module::ctl_set_bool(), openmpt::module::ctl_set_int(), openmpt::module::ctl_set_floatingpoint(), or openmpt::module::ctl_set_string().
  1074. */
  1075. LIBOPENMPT_ATTR_DEPRECATED void ctl_set( const std::string & ctl, const std::string & value );
  1076. //! Set ctl boolean value
  1077. /*!
  1078. \param ctl The ctl key whose value should be set.
  1079. \param value The value that should be set.
  1080. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the value is not sensible (e.g. negative tempo factor) or under the circumstances outlined in openmpt::module::get_ctls.
  1081. \sa openmpt::module::get_ctls
  1082. \since 0.5.0
  1083. */
  1084. void ctl_set_boolean( std::string_view ctl, bool value );
  1085. //! Set ctl integer value
  1086. /*!
  1087. \param ctl The ctl key whose value should be set.
  1088. \param value The value that should be set.
  1089. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the value is not sensible (e.g. negative tempo factor) or under the circumstances outlined in openmpt::module::get_ctls.
  1090. \sa openmpt::module::get_ctls
  1091. \since 0.5.0
  1092. */
  1093. void ctl_set_integer( std::string_view ctl, std::int64_t value );
  1094. //! Set ctl floatingpoint value
  1095. /*!
  1096. \param ctl The ctl key whose value should be set.
  1097. \param value The value that should be set.
  1098. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the value is not sensible (e.g. negative tempo factor) or under the circumstances outlined in openmpt::module::get_ctls.
  1099. \sa openmpt::module::get_ctls
  1100. \since 0.5.0
  1101. */
  1102. void ctl_set_floatingpoint( std::string_view ctl, double value );
  1103. //! Set ctl text value
  1104. /*!
  1105. \param ctl The ctl key whose value should be set.
  1106. \param value The value that should be set.
  1107. \throws openmpt::exception Throws an exception derived from openmpt::exception in case the value is not sensible (e.g. negative tempo factor) or under the circumstances outlined in openmpt::module::get_ctls.
  1108. \sa openmpt::module::get_ctls
  1109. \since 0.5.0
  1110. */
  1111. void ctl_set_text( std::string_view ctl, std::string_view value );
  1112. // remember to add new functions to both C and C++ interfaces and to increase OPENMPT_API_VERSION_MINOR
  1113. }; // class module
  1114. /*!
  1115. @}
  1116. */
  1117. } // namespace openmpt
  1118. #endif // LIBOPENMPT_HPP