libopenmpt  0.2.4238
cross-platform C++ and C library to decode tracked music files
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
libopenmpt.hpp
Go to the documentation of this file.
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 
10 #ifndef LIBOPENMPT_HPP
11 #define LIBOPENMPT_HPP
12 
13 #include "libopenmpt_config.h"
14 
15 #include <exception>
16 #include <iostream>
17 #include <istream>
18 #include <map>
19 #include <ostream>
20 #include <string>
21 #include <vector>
22 
23 #ifdef MPT_ANCIENT_VS2008
24 #include "cstdint.h"
25 #else
26 #include <cstdint>
27 #endif
28 
67 namespace openmpt {
68 
69 class LIBOPENMPT_CXX_API exception : public std::exception {
70 private:
71  char * text;
72 public:
73  exception( const std::string & text ) throw();
74  virtual ~exception() throw();
75  virtual const char * what() const throw();
76 }; // class exception
77 
79 
83 LIBOPENMPT_CXX_API std::uint32_t get_library_version();
84 
86 
90 LIBOPENMPT_CXX_API std::uint32_t get_core_version();
91 
92 namespace string {
93 
95 static const char library_version [] = "library_version";
97 static const char library_features[] = "library_features";
99 static const char core_version [] = "core_version";
101 static const char build [] = "build";
103 static const char credits [] = "credits";
105 static const char contact [] = "contact";
107 static const char license [] = "license";
108 
110 
120 LIBOPENMPT_CXX_API std::string get( const std::string & key );
121 
122 } // namespace string
123 
125 
128 LIBOPENMPT_CXX_API std::vector<std::string> get_supported_extensions();
129 
131 
135 LIBOPENMPT_CXX_API bool is_extension_supported( const std::string & extension );
136 
138 
144 LIBOPENMPT_CXX_API double could_open_propability( std::istream & stream, double effort = 1.0, std::ostream & log = std::clog );
145 
146 class module_impl;
147 
148 class module_ext;
149 
150 namespace detail {
151 
152 typedef std::map< std::string, std::string > initial_ctls_map;
153 
154 } // namespace detail
155 
156 class LIBOPENMPT_CXX_API module {
157 
158  friend class module_ext;
159 
160 public:
161 
165 
170  RENDER_MASTERGAIN_MILLIBEL = 1,
172 
177  RENDER_STEREOSEPARATION_PERCENT = 2,
179 
190  RENDER_INTERPOLATIONFILTER_LENGTH = 3,
192 
199  RENDER_VOLUMERAMPING_STRENGTH = 4
200  };
201 
203  command_note = 0,
204  command_instrument = 1,
205  command_volumeffect = 2,
206  command_effect = 3,
207  command_volume = 4,
208  command_parameter = 5
209  };
210 
211 private:
212  module_impl * impl;
213 private:
214  // non-copyable
215  module( const module & );
216  void operator = ( const module & );
217 private:
218  // for module_ext
219  module();
220  void set_impl( module_impl * i );
221 public:
223 
230  module( std::istream & stream, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
238  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() );
247  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() );
256  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() );
264  module( const std::vector<char> & data, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
273  module( const char * beg, const char * end, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
282  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() );
291  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() );
292  virtual ~module();
293 public:
294 
296 
300  void select_subsong( std::int32_t subsong );
302 
309  void set_repeat_count( std::int32_t repeat_count );
311 
318  std::int32_t get_repeat_count() const;
319 
321 
324  double get_duration_seconds() const;
325 
327 
332  double set_position_seconds( double seconds );
334 
338  double get_position_seconds() const;
339 
341 
349  double set_position_order_row( std::int32_t order, std::int32_t row );
350 
352 
358  std::int32_t get_render_param( int param ) const;
360 
367  void set_render_param( int param, std::int32_t value );
368 
370 
371 
381  std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * mono );
383 
394  std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right );
396 
409  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 );
411 
421  std::size_t read( std::int32_t samplerate, std::size_t count, float * mono );
423 
434  std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right );
436 
449  std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right );
451 
461  std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_stereo );
463 
473  std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_quad );
475 
485  std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, float * interleaved_stereo );
487 
497  std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, float * interleaved_quad );
500 
501 
505  std::vector<std::string> get_metadata_keys() const;
507 
512  std::string get_metadata( const std::string & key ) const;
513 
514  std::int32_t get_current_speed() const;
515  std::int32_t get_current_tempo() const;
516  std::int32_t get_current_order() const;
517  std::int32_t get_current_pattern() const;
518  std::int32_t get_current_row() const;
519  std::int32_t get_current_playing_channels() const;
520 
521  float get_current_channel_vu_mono( std::int32_t channel ) const;
522  float get_current_channel_vu_left( std::int32_t channel ) const;
523  float get_current_channel_vu_right( std::int32_t channel ) const;
524  float get_current_channel_vu_rear_left( std::int32_t channel ) const;
525  float get_current_channel_vu_rear_right( std::int32_t channel ) const;
526 
527  std::int32_t get_num_subsongs() const;
528  std::int32_t get_num_channels() const;
529  std::int32_t get_num_orders() const;
530  std::int32_t get_num_patterns() const;
531  std::int32_t get_num_instruments() const;
532  std::int32_t get_num_samples() const;
533 
534  std::vector<std::string> get_subsong_names() const;
535  std::vector<std::string> get_channel_names() const;
536  std::vector<std::string> get_order_names() const;
537  std::vector<std::string> get_pattern_names() const;
538  std::vector<std::string> get_instrument_names() const;
539  std::vector<std::string> get_sample_names() const;
540 
541  std::int32_t get_order_pattern( std::int32_t order ) const;
542 
543  std::int32_t get_pattern_num_rows( std::int32_t pattern ) const;
544 
545  std::uint8_t get_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
546 
547  std::string format_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
548  std::string highlight_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
549 
550  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;
551  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;
552 
553  std::vector<std::string> get_ctls() const;
554 
555  std::string ctl_get( const std::string & ctl ) const;
556  void ctl_set( const std::string & ctl, const std::string & value );
557 
558  // remember to add new functions to both C and C++ interfaces and to increase OPENMPT_API_VERSION_MINOR
559 
560 }; // class module
561 
562 } // namespace openmpt
563 
568 #endif // LIBOPENMPT_HPP