libopenmpt_ext.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /*
  2. * libopenmpt_ext.h
  3. * ----------------
  4. * Purpose: libopenmpt public c interface for libopenmpt extensions
  5. * Notes :
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #ifndef LIBOPENMPT_EXT_H
  10. #define LIBOPENMPT_EXT_H
  11. #include "libopenmpt_config.h"
  12. #include "libopenmpt.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /*!
  17. * \page libopenmpt_ext_c_overview libopenmpt_ext C API
  18. *
  19. * libopenmpt_ext is included in all builds by default.
  20. *
  21. * \section libopenmpt-ext-c-detailed Detailed documentation
  22. *
  23. * \ref libopenmpt_ext_c
  24. *
  25. */
  26. /*! \defgroup libopenmpt_ext_c libopenmpt_ext C */
  27. /*! \addtogroup libopenmpt_ext_c
  28. * @{
  29. */
  30. /*! \brief Opaque type representing a libopenmpt extension module
  31. */
  32. typedef struct openmpt_module_ext openmpt_module_ext;
  33. /*! \brief Construct an openmpt_module_ext
  34. *
  35. * \param stream_callbacks Input stream callback operations.
  36. * \param stream Input stream to load the module from.
  37. * \param logfunc Logging function where warning and errors are written. The logging function may be called throughout the lifetime of openmpt_module_ext. May be NULL.
  38. * \param loguser User-defined data associated with this module. This value will be passed to the logging callback function (logfunc)
  39. * \param errfunc Error function to define error behaviour. May be NULL.
  40. * \param erruser Error function user context. Used to pass any user-defined data associated with this module to the logging function.
  41. * \param error Pointer to an integer where an error may get stored. May be NULL.
  42. * \param error_message Pointer to a string pointer where an error message may get stored. May be NULL.
  43. * \param ctls A map of initial ctl values, see openmpt_module_get_ctls.
  44. * \return A pointer to the constructed openmpt_module_ext, or NULL on failure.
  45. * \remarks The input data can be discarded after an openmpt_module_ext has been constructed successfully.
  46. * \sa openmpt_stream_callbacks
  47. * \sa \ref libopenmpt_c_fileio
  48. * \since 0.3.0
  49. */
  50. LIBOPENMPT_API openmpt_module_ext * openmpt_module_ext_create( openmpt_stream_callbacks stream_callbacks, void * stream, openmpt_log_func logfunc, void * loguser, openmpt_error_func errfunc, void * erruser, int * error, const char * * error_message, const openmpt_module_initial_ctl * ctls );
  51. /*! \brief Construct an openmpt_module_ext
  52. *
  53. * \param filedata Data to load the module from.
  54. * \param filesize Amount of data available.
  55. * \param logfunc Logging function where warning and errors are written. The logging function may be called throughout the lifetime of openmpt_module_ext.
  56. * \param loguser User-defined data associated with this module. This value will be passed to the logging callback function (logfunc)
  57. * \param errfunc Error function to define error behaviour. May be NULL.
  58. * \param erruser Error function user context. Used to pass any user-defined data associated with this module to the logging function.
  59. * \param error Pointer to an integer where an error may get stored. May be NULL.
  60. * \param error_message Pointer to a string pointer where an error message may get stored. May be NULL.
  61. * \param ctls A map of initial ctl values, see openmpt_module_get_ctls.
  62. * \return A pointer to the constructed openmpt_module_ext, or NULL on failure.
  63. * \remarks The input data can be discarded after an openmpt_module_ext has been constructed successfully.
  64. * \sa \ref libopenmpt_c_fileio
  65. * \since 0.3.0
  66. */
  67. LIBOPENMPT_API openmpt_module_ext * openmpt_module_ext_create_from_memory( const void * filedata, size_t filesize, openmpt_log_func logfunc, void * loguser, openmpt_error_func errfunc, void * erruser, int * error, const char * * error_message, const openmpt_module_initial_ctl * ctls );
  68. /*! \brief Unload a previously created openmpt_module_ext from memory.
  69. *
  70. * \param mod_ext The module to unload.
  71. */
  72. LIBOPENMPT_API void openmpt_module_ext_destroy( openmpt_module_ext * mod_ext );
  73. /*! \brief Retrieve the openmpt_module handle from an openmpt_module_ext handle.
  74. *
  75. * \param mod_ext The extension module handle to convert
  76. * \return An equivalent openmpt_module handle to pass to standard libopenmpt functions
  77. * \since 0.3.0
  78. */
  79. LIBOPENMPT_API openmpt_module * openmpt_module_ext_get_module( openmpt_module_ext * mod_ext );
  80. /*! Retrieve a libopenmpt extension.
  81. *
  82. * \param mod_ext The module handle to work on.
  83. * \param interface_id The name of the extension interface to retrieve (e.g. LIBOPENMPT_EXT_C_INTERFACE_PATTERN_VIS).
  84. * \param interface Appropriate structure of interface function pointers which is to be filled by this function (e.g. a pointer to a openmpt_module_ext_interface_pattern_vis structure).
  85. * \param interface_size Size of the interface's structure of function pointers (e.g. sizeof(openmpt_module_ext_interface_pattern_vis)).
  86. * \return 1 on success, 0 if the interface was not found.
  87. * \since 0.3.0
  88. */
  89. LIBOPENMPT_API int openmpt_module_ext_get_interface( openmpt_module_ext * mod_ext, const char * interface_id, void * interface, size_t interface_size );
  90. #ifndef LIBOPENMPT_EXT_C_INTERFACE_PATTERN_VIS
  91. #define LIBOPENMPT_EXT_C_INTERFACE_PATTERN_VIS "pattern_vis"
  92. #endif
  93. /*! Pattern command type */
  94. #define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_UNKNOWN 0
  95. #define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_GENERAL 1
  96. #define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_GLOBAL 2
  97. #define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_VOLUME 3
  98. #define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_PANNING 4
  99. #define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_PITCH 5
  100. typedef struct openmpt_module_ext_interface_pattern_vis {
  101. /*! Get pattern command type for pattern highlighting
  102. *
  103. * \param mod_ext The module handle to work on.
  104. * \param pattern The pattern whose data should be retrieved.
  105. * \param row The row from which the data should be retrieved.
  106. * \param channel The channel from which the data should be retrieved.
  107. * \return The command type in the effect column at the given pattern position (see OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_*)
  108. * \sa openmpt_module_ext_interface_pattern_vis::get_pattern_row_channel_volume_effect_type
  109. */
  110. int ( * get_pattern_row_channel_volume_effect_type ) ( openmpt_module_ext * mod_ext, int32_t pattern, int32_t row, int32_t channel );
  111. /*! Get pattern command type for pattern highlighting
  112. *
  113. * \param mod_ext The module handle to work on.
  114. * \param pattern The pattern whose data should be retrieved.
  115. * \param row The row from which the data should be retrieved.
  116. * \param channel The channel from which the data should be retrieved.
  117. * \return The command type in the effect column at the given pattern position (see OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_*)
  118. * \sa openmpt_module_ext_interface_pattern_vis::get_pattern_row_channel_volume_effect_type
  119. */
  120. int ( * get_pattern_row_channel_effect_type ) ( openmpt_module_ext * mod_ext, int32_t pattern, int32_t row, int32_t channel );
  121. } openmpt_module_ext_interface_pattern_vis;
  122. #ifndef LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE
  123. #define LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE "interactive"
  124. #endif
  125. typedef struct openmpt_module_ext_interface_interactive {
  126. /*! Set the current ticks per row (speed)
  127. *
  128. * \param mod_ext The module handle to work on.
  129. * \param speed The new tick count in range [1, 65535].
  130. * \return 1 on success, 0 on failure.
  131. * \remarks The tick count may be reset by pattern commands at any time.
  132. * \sa openmpt_module_get_current_speed
  133. */
  134. int ( * set_current_speed ) ( openmpt_module_ext * mod_ext, int32_t speed );
  135. /*! Set the current module tempo
  136. *
  137. * \param mod_ext The module handle to work on.
  138. * \param tempo The new tempo in range [32, 512]. The exact meaning of the value depends on the tempo mode used by the module.
  139. * \return 1 on success, 0 on failure.
  140. * \remarks The tempo may be reset by pattern commands at any time. Use openmpt_module_ext_interface_interactive::set_tempo_factor to apply a tempo factor that is independent of pattern commands.
  141. * \sa openmpt_module_get_current_tempo
  142. */
  143. int ( * set_current_tempo ) ( openmpt_module_ext * mod_ext, int32_t tempo );
  144. /*! Set the current module tempo factor without affecting playback pitch
  145. *
  146. * \param mod_ext The module handle to work on.
  147. * \param factor The new tempo factor in range ]0.0, 4.0] - 1.0 means unmodified tempo.
  148. * \return 1 on success, 0 on failure.
  149. * \remarks Modifying the tempo without applying the same pitch factor using openmpt_module_ext_interface_interactive::set_pitch_factor may cause rhythmic samples (e.g. drum loops) to go out of sync.
  150. * \sa openmpt_module_ext_interface_interactive::get_tempo_factor
  151. */
  152. int ( * set_tempo_factor ) ( openmpt_module_ext * mod_ext, double factor );
  153. /*! Gets the current module tempo factor
  154. *
  155. * \param mod_ext The module handle to work on.
  156. * \return The current tempo factor.
  157. * \sa openmpt_module_ext_interface_interactive::set_tempo_factor
  158. */
  159. double ( * get_tempo_factor ) ( openmpt_module_ext * mod_ext );
  160. /*! Set the current module pitch factor without affecting playback speed
  161. *
  162. * \param mod_ext The module handle to work on.
  163. * \param factor The new pitch factor in range ]0.0, 4.0] - 1.0 means unmodified pitch.
  164. * \return 1 on success, 0 on failure.
  165. * \remarks Modifying the pitch without applying the the same tempo factor using openmpt_module_ext_interface_interactive::set_tempo_factor may cause rhythmic samples (e.g. drum loops) to go out of sync.
  166. * \remarks To shift the pich by `n` semitones, the parameter can be calculated as follows: `pow( 2.0, n / 12.0 )`
  167. * \sa openmpt_module_ext_interface_interactive::get_pitch_factor
  168. */
  169. int ( * set_pitch_factor ) ( openmpt_module_ext * mod_ext, double factor );
  170. /*! Gets the current module pitch factor
  171. *
  172. * \param mod_ext The module handle to work on.
  173. * \return The current pitch factor.
  174. * \sa openmpt_module_ext_interface_interactive::set_pitch_factor
  175. */
  176. double ( * get_pitch_factor ) ( openmpt_module_ext * mod_ext );
  177. /*! Set the current global volume
  178. *
  179. * \param mod_ext The module handle to work on.
  180. * \param volume The new global volume in range [0.0, 1.0]
  181. * \return 1 on success, 0 on failure.
  182. * \remarks The global volume may be reset by pattern commands at any time. Use openmpt_module_set_render_param to apply a global overall volume factor that is independent of pattern commands.
  183. * \sa openmpt_module_ext_interface_interactive::get_global_volume
  184. */
  185. int ( * set_global_volume ) ( openmpt_module_ext * mod_ext, double volume );
  186. /*! Get the current global volume
  187. *
  188. * \param mod_ext The module handle to work on.
  189. * \return The current global volume in range [0.0, 1.0]
  190. * \sa openmpt_module_ext_interface_interactive::set_global_volume
  191. */
  192. double ( * get_global_volume ) ( openmpt_module_ext * mod_ext );
  193. /*! Set the current channel volume for a channel
  194. *
  195. * \param mod_ext The module handle to work on.
  196. * \param channel The channel whose volume should be set, in range [0, openmpt_module_get_num_channels()[
  197. * \param volume The new channel volume in range [0.0, 1.0]
  198. * \return 1 on success, 0 on failure (channel out of range).
  199. * \remarks The channel volume may be reset by pattern commands at any time.
  200. * \sa openmpt_module_ext_interface_interactive::get_channel_volume
  201. */
  202. int ( * set_channel_volume ) ( openmpt_module_ext * mod_ext, int32_t channel, double volume );
  203. /*! Get the current channel volume for a channel
  204. *
  205. * \param mod_ext The module handle to work on.
  206. * \param channel The channel whose volume should be retrieved, in range [0, openmpt_module_get_num_channels()[
  207. * \return The current channel volume in range [0.0, 1.0]
  208. * \sa openmpt_module_ext_interface_interactive::set_channel_volume
  209. */
  210. double ( * get_channel_volume ) ( openmpt_module_ext * mod_ext, int32_t channel );
  211. /*! Set the current mute status for a channel
  212. *
  213. * \param mod_ext The module handle to work on.
  214. * \param channel The channel whose mute status should be set, in range [0, openmpt_module_get_num_channels()[
  215. * \param mute The new mute status. true is muted, false is unmuted.
  216. * \return 1 on success, 0 on failure (channel out of range).
  217. * \sa openmpt_module_ext_interface_interactive::get_channel_mute_status
  218. */
  219. int ( * set_channel_mute_status ) ( openmpt_module_ext * mod_ext, int32_t channel, int mute );
  220. /*! Get the current mute status for a channel
  221. *
  222. * \param mod_ext The module handle to work on.
  223. * \param channel The channel whose mute status should be retrieved, in range [0, openmpt_module_get_num_channels()[
  224. * \return The current channel mute status. 1 is muted, 0 is unmuted, -1 means the instrument was out of range
  225. * \sa openmpt_module_ext_interface_interactive::set_channel_mute_status
  226. */
  227. int ( * get_channel_mute_status ) ( openmpt_module_ext * mod_ext, int32_t channel );
  228. /*! Set the current mute status for an instrument
  229. *
  230. * \param mod_ext The module handle to work on.
  231. * \param instrument The instrument whose mute status should be set, in range [0, openmpt_module_get_num_instruments()[ if openmpt_module_get_num_instruments is not 0, otherwise in [0, openmpt_module_get_num_samples()[
  232. * \param mute The new mute status. true is muted, false is unmuted.
  233. * \return 1 on success, 0 on failure (instrument out of range).
  234. * \sa openmpt_module_ext_interface_interactive::get_instrument_mute_status
  235. */
  236. int ( * set_instrument_mute_status ) ( openmpt_module_ext * mod_ext, int32_t instrument, int mute );
  237. /*! Get the current mute status for an instrument
  238. *
  239. * \param mod_ext The module handle to work on.
  240. * \param instrument The instrument whose mute status should be retrieved, in range [0, openmpt_module_get_num_instruments()[ if openmpt_module_get_num_instruments is not 0, otherwise in [0, openmpt_module_get_num_samples()[
  241. * \return The current instrument mute status. 1 is muted, 0 is unmuted, -1 means the instrument was out of range
  242. * \sa openmpt_module_ext_interface_interactive::set_instrument_mute_status
  243. */
  244. int ( * get_instrument_mute_status ) ( openmpt_module_ext * mod_ext, int32_t instrument );
  245. /*! Play a note using the specified instrument
  246. *
  247. * \param mod_ext The module handle to work on.
  248. * \param instrument The instrument that should be played, in range [0, openmpt_module_get_num_instruments()[ if openmpt_module_get_num_instruments is not 0, otherwise in [0, openmpt_module_get_num_samples()[
  249. * \param note The note to play, in rage [0, 119]. 60 is the middle C.
  250. * \param volume The volume at which the note should be triggered, in range [0.0, 1.0]
  251. * \param panning The panning position at which the note should be triggered, in range [-1.0, 1.0], 0.0 is center.
  252. * \return The channel on which the note is played. This can pe be passed to openmpt_module_ext_interface_interactive::stop_note to stop the note. -1 means that no channel could be allocated and the note is not played.
  253. * \sa openmpt_module_ext_interface_interactive::stop_note
  254. * \sa openmpt_module_ext_interface_interactive2::note_off
  255. * \sa openmpt_module_ext_interface_interactive2::note_fade
  256. */
  257. int32_t ( * play_note ) ( openmpt_module_ext * mod_ext, int32_t instrument, int32_t note, double volume, double panning );
  258. /*! Stop the note playing on the specified channel
  259. *
  260. * \param mod_ext The module handle to work on.
  261. * \param channel The channel on which the note should be stopped. This is the value returned by a previous play_note call.
  262. * \return 1 on success, 0 on failure (channel out of range).
  263. * \sa openmpt_module_ext_interface_interactive::play_note
  264. * \sa openmpt_module_ext_interface_interactive2::note_off
  265. * \sa openmpt_module_ext_interface_interactive2::note_fade
  266. */
  267. int ( * stop_note ) ( openmpt_module_ext * mod_ext, int32_t channel );
  268. } openmpt_module_ext_interface_interactive;
  269. #ifndef LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE2
  270. #define LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE2 "interactive2"
  271. #endif
  272. typedef struct openmpt_module_ext_interface_interactive2 {
  273. //! Sends a key-off command for the note playing on the specified channel
  274. /*!
  275. * \param mod_ext The module handle to work on.
  276. * \param channel The channel on which the key-off event should be triggered. This is the value returned by a previous play_note call.
  277. * \return 1 on success, 0 on failure (channel out of range).
  278. * \remarks This method releases envelopes and sample sustain loops. If the sample has no sustain loop, or if the module does not use instruments, it does nothing.
  279. * \sa openmpt_module_ext_interface_interactive::play_note
  280. * \sa openmpt_module_ext_interface_interactive::stop_note
  281. * \sa openmpt_module_ext_interface_interactive2::note_fade
  282. * \since 0.6.0
  283. */
  284. int ( *note_off ) ( openmpt_module_ext * mod_ext, int32_t channel );
  285. //! Sends a note fade command for the note playing on the specified channel
  286. /*!
  287. * \param mod_ext The module handle to work on.
  288. * \param channel The channel on which the note should be faded. This is the value returned by a previous play_note call.
  289. * \return 1 on success, 0 on failure (channel out of range).
  290. * \remarks This method uses the instrument's fade-out value. If the module does not use instruments, or the instrument's fade-out value is 0, it does nothing.
  291. * \sa openmpt_module_ext_interface_interactive::play_note
  292. * \sa openmpt_module_ext_interface_interactive::stop_note
  293. * \sa openmpt_module_ext_interface_interactive2::note_fade
  294. * \since 0.6.0
  295. */
  296. int ( *note_fade ) ( openmpt_module_ext * mod_ext, int32_t channel );
  297. //! Set the current panning for a channel
  298. /*!
  299. * \param mod_ext The module handle to work on.
  300. * \param channel The channel that should be panned. This is the value returned by a previous play_note call.
  301. * \param panning The panning position to set on the channel, in range [-1.0, 1.0], 0.0 is center.
  302. * \return 1 on success, 0 on failure (channel out of range).
  303. * \remarks This command affects subsequent notes played on the same channel, and may itself be overridden by subsequent panning commands encountered in the module itself.
  304. * \sa openmpt_module_ext_interface_interactive2::get_channel_panning
  305. * \since 0.6.0
  306. */
  307. int ( *set_channel_panning) ( openmpt_module_ext * mod_ext, int32_t channel, double panning );
  308. //! Get the current panning position for a channel
  309. /*!
  310. * \param mod_ext The module handle to work on.
  311. * \param channel The channel whose panning should be retrieved. This is the value returned by a previous play_note call.
  312. * \return The current channel panning, in range [-1.0, 1.0], 0.0 is center.
  313. * \sa openmpt_module_ext_interface_interactive2::set_channel_panning
  314. * \since 0.6.0
  315. */
  316. double (*get_channel_panning) ( openmpt_module_ext * mod_ext, int32_t channel );
  317. //! Set the finetune for the currently playing note on a channel
  318. /*!
  319. * \param mod_ext The module handle to work on.
  320. * \param channel The channel whose finetune will be changed, in range [0, openmpt::module::get_num_channels()[
  321. * \param finetune The finetune to set on the channel, in range [-1.0, 1.0], 0.0 is center.
  322. * \throws openmpt::exception Throws an exception derived from openmpt::exception if the channel index is invalid.
  323. * \remarks The finetune range depends on the pitch wheel depth of the instrument playing on the current channel; for sample-based modules, the depth of this command is fixed to +/-1 semitone.
  324. * \remarks This command does not affect subsequent notes played on the same channel, but may itself be overridden by subsequent finetune commands encountered in the module itself.
  325. * \sa openmpt_module_ext_interface_interactive2::get_note_finetune
  326. * \since 0.6.0
  327. */
  328. int ( *set_note_finetune) ( openmpt_module_ext * mod_ext, int32_t channel, double finetune );
  329. //! Get the finetune for the currently playing note on a channel
  330. /*!
  331. * \param mod_ext The module handle to work on.
  332. * \param channel The channel whose finetune should be retrieved, in range [0, openmpt::module::get_num_channels()[
  333. * \return The current channel finetune, in range [-1.0, 1.0], 0.0 is center.
  334. * \remarks The finetune range depends on the pitch wheel depth of the instrument playing on the current channel; for sample-based modules, the depth of this command is fixed to +/-1 semitone.
  335. * \throws openmpt::exception Throws an exception derived from openmpt::exception if the channel is outside the specified range.
  336. * \sa openmpt_module_ext_interface_interactive2::set_note_finetune
  337. * \since 0.6.0
  338. */
  339. double (*get_note_finetune) ( openmpt_module_ext * mod_ext, int32_t channel );
  340. } openmpt_module_ext_interface_interactive2;
  341. /* add stuff here */
  342. #ifdef __cplusplus
  343. }
  344. #endif
  345. /*!
  346. * @}
  347. */
  348. #endif /* LIBOPENMPT_EXT_H */