libopenmpt  0.2.4115
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 #include <cstdint>
24 
63 namespace openmpt {
64 
65 class LIBOPENMPT_CXX_API exception : public std::exception {
66 private:
67  char * text;
68 public:
69  exception( const std::string & text ) throw();
70  virtual ~exception() throw();
71  virtual const char * what() const throw();
72 }; // class exception
73 
75 
79 LIBOPENMPT_CXX_API std::uint32_t get_library_version();
80 
82 
86 LIBOPENMPT_CXX_API std::uint32_t get_core_version();
87 
88 namespace string {
89 
91 static const char library_version [] = "library_version";
93 static const char library_features[] = "library_features";
95 static const char core_version [] = "core_version";
97 static const char build [] = "build";
99 static const char credits [] = "credits";
101 static const char contact [] = "contact";
103 static const char license [] = "license";
104 
106 
116 LIBOPENMPT_CXX_API std::string get( const std::string & key );
117 
118 } // namespace string
119 
121 
124 LIBOPENMPT_CXX_API std::vector<std::string> get_supported_extensions();
125 
127 
131 LIBOPENMPT_CXX_API bool is_extension_supported( const std::string & extension );
132 
134 
140 LIBOPENMPT_CXX_API double could_open_propability( std::istream & stream, double effort = 1.0, std::ostream & log = std::clog );
141 
142 class module_impl;
143 
144 class module_ext;
145 
146 namespace detail {
147 
148 typedef std::map< std::string, std::string > initial_ctls_map;
149 
150 } // namespace detail
151 
152 class LIBOPENMPT_CXX_API module {
153 
154  friend class module_ext;
155 
156 public:
157 
161 
166  RENDER_MASTERGAIN_MILLIBEL = 1,
168 
173  RENDER_STEREOSEPARATION_PERCENT = 2,
175 
186  RENDER_INTERPOLATIONFILTER_LENGTH = 3,
188 
195  RENDER_VOLUMERAMPING_STRENGTH = 4
196  };
197 
199  command_note = 0,
200  command_instrument = 1,
201  command_volumeffect = 2,
202  command_effect = 3,
203  command_volume = 4,
204  command_parameter = 5
205  };
206 
207 private:
208  module_impl * impl;
209 private:
210  // non-copyable
211  module( const module & );
212  void operator = ( const module & );
213 private:
214  // for module_ext
215  module();
216  void set_impl( module_impl * i );
217 public:
219 
226  module( std::istream & stream, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
234  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() );
243  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() );
252  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() );
260  module( const std::vector<char> & data, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
269  module( const char * beg, const char * end, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
278  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() );
287  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() );
288  virtual ~module();
289 public:
290 
292 
296  void select_subsong( std::int32_t subsong );
298 
305  void set_repeat_count( std::int32_t repeat_count );
307 
314  std::int32_t get_repeat_count() const;
315 
317 
320  double get_duration_seconds() const;
321 
323 
328  double set_position_seconds( double seconds );
330 
334  double get_position_seconds() const;
335 
337 
345  double set_position_order_row( std::int32_t order, std::int32_t row );
346 
348 
354  std::int32_t get_render_param( int param ) const;
356 
363  void set_render_param( int param, std::int32_t value );
364 
366 
367 
377  std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * mono );
379 
390  std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right );
392 
405  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 );
407 
417  std::size_t read( std::int32_t samplerate, std::size_t count, float * mono );
419 
430  std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right );
432 
445  std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right );
447 
457  std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_stereo );
459 
469  std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_quad );
471 
481  std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, float * interleaved_stereo );
483 
493  std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, float * interleaved_quad );
496 
497 
501  std::vector<std::string> get_metadata_keys() const;
503 
508  std::string get_metadata( const std::string & key ) const;
509 
510  std::int32_t get_current_speed() const;
511  std::int32_t get_current_tempo() const;
512  std::int32_t get_current_order() const;
513  std::int32_t get_current_pattern() const;
514  std::int32_t get_current_row() const;
515  std::int32_t get_current_playing_channels() const;
516 
517  float get_current_channel_vu_mono( std::int32_t channel ) const;
518  float get_current_channel_vu_left( std::int32_t channel ) const;
519  float get_current_channel_vu_right( std::int32_t channel ) const;
520  float get_current_channel_vu_rear_left( std::int32_t channel ) const;
521  float get_current_channel_vu_rear_right( std::int32_t channel ) const;
522 
523  std::int32_t get_num_subsongs() const;
524  std::int32_t get_num_channels() const;
525  std::int32_t get_num_orders() const;
526  std::int32_t get_num_patterns() const;
527  std::int32_t get_num_instruments() const;
528  std::int32_t get_num_samples() const;
529 
530  std::vector<std::string> get_subsong_names() const;
531  std::vector<std::string> get_channel_names() const;
532  std::vector<std::string> get_order_names() const;
533  std::vector<std::string> get_pattern_names() const;
534  std::vector<std::string> get_instrument_names() const;
535  std::vector<std::string> get_sample_names() const;
536 
537  std::int32_t get_order_pattern( std::int32_t order ) const;
538 
539  std::int32_t get_pattern_num_rows( std::int32_t pattern ) const;
540 
541  std::uint8_t get_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
542 
543  std::string format_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
544  std::string highlight_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
545 
546  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;
547  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;
548 
549  std::vector<std::string> get_ctls() const;
550 
551  std::string ctl_get( const std::string & ctl ) const;
552  void ctl_set( const std::string & ctl, const std::string & value );
553 
554  // remember to add new functions to both C and C++ interfaces and to increase OPENMPT_API_VERSION_MINOR
555 
556 }; // class module
557 
558 } // namespace openmpt
559 
564 #endif // LIBOPENMPT_HPP