libopenmpt  0.2.3532
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 
61 namespace openmpt {
62 
63 class LIBOPENMPT_CXX_API exception : public std::exception {
64 private:
65  char * text;
66 public:
67  exception( const std::string & text ) throw();
68  virtual ~exception() throw();
69  virtual const char * what() const throw();
70 }; // class exception
71 
73 
77 LIBOPENMPT_CXX_API std::uint32_t get_library_version();
78 
80 
84 LIBOPENMPT_CXX_API std::uint32_t get_core_version();
85 
86 namespace string {
87 
89 static const char library_version [] = "library_version";
91 static const char library_features[] = "library_features";
93 static const char core_version [] = "core_version";
95 static const char build [] = "build";
97 static const char credits [] = "credits";
99 static const char contact [] = "contact";
100 
102 
111 LIBOPENMPT_CXX_API std::string get( const std::string & key );
112 
113 } // namespace string
114 
116 
119 LIBOPENMPT_CXX_API std::vector<std::string> get_supported_extensions();
120 
122 
126 LIBOPENMPT_CXX_API bool is_extension_supported( const std::string & extension );
127 
129 
135 LIBOPENMPT_CXX_API double could_open_propability( std::istream & stream, double effort = 1.0, std::ostream & log = std::clog );
136 
137 class module_impl;
138 
139 class module_ext;
140 
141 namespace detail {
142 
143 typedef std::map< std::string, std::string > initial_ctls_map;
144 
145 } // namespace detail
146 
147 class LIBOPENMPT_CXX_API module {
148 
149  friend class module_ext;
150 
151 public:
152 
156 
161  RENDER_MASTERGAIN_MILLIBEL = 1,
163 
168  RENDER_STEREOSEPARATION_PERCENT = 2,
170 
181  RENDER_INTERPOLATIONFILTER_LENGTH = 3,
183 
190  RENDER_VOLUMERAMPING_STRENGTH = 4
191  };
192 
194  command_note = 0,
195  command_instrument = 1,
196  command_volumeffect = 2,
197  command_effect = 3,
198  command_volume = 4,
199  command_parameter = 5
200  };
201 
202 private:
203  module_impl * impl;
204 private:
205  // non-copyable
206  module( const module & );
207  void operator = ( const module & );
208 private:
209  // for module_ext
210  module();
211  void set_impl( module_impl * i );
212 public:
214 
221  module( std::istream & stream, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
229  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() );
238  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() );
247  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() );
255  module( const std::vector<char> & data, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
264  module( const char * beg, const char * end, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
273  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() );
282  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() );
283  virtual ~module();
284 public:
285 
287 
291  void select_subsong( std::int32_t subsong );
293 
300  void set_repeat_count( std::int32_t repeat_count );
302 
309  std::int32_t get_repeat_count() const;
310 
312 
315  double get_duration_seconds() const;
316 
318 
323  double set_position_seconds( double seconds );
325 
329  double get_position_seconds() const;
330 
332 
340  double set_position_order_row( std::int32_t order, std::int32_t row );
341 
343 
349  std::int32_t get_render_param( int param ) const;
351 
358  void set_render_param( int param, std::int32_t value );
359 
361 
362 
372  std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * mono );
374 
385  std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right );
387 
400  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 );
402 
412  std::size_t read( std::int32_t samplerate, std::size_t count, float * mono );
414 
425  std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right );
427 
440  std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right );
442 
452  std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_stereo );
454 
464  std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_quad );
466 
476  std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, float * interleaved_stereo );
478 
488  std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, float * interleaved_quad );
491 
492 
496  std::vector<std::string> get_metadata_keys() const;
498 
503  std::string get_metadata( const std::string & key ) const;
504 
505  std::int32_t get_current_speed() const;
506  std::int32_t get_current_tempo() const;
507  std::int32_t get_current_order() const;
508  std::int32_t get_current_pattern() const;
509  std::int32_t get_current_row() const;
510  std::int32_t get_current_playing_channels() const;
511 
512  float get_current_channel_vu_mono( std::int32_t channel ) const;
513  float get_current_channel_vu_left( std::int32_t channel ) const;
514  float get_current_channel_vu_right( std::int32_t channel ) const;
515  float get_current_channel_vu_rear_left( std::int32_t channel ) const;
516  float get_current_channel_vu_rear_right( std::int32_t channel ) const;
517 
518  std::int32_t get_num_subsongs() const;
519  std::int32_t get_num_channels() const;
520  std::int32_t get_num_orders() const;
521  std::int32_t get_num_patterns() const;
522  std::int32_t get_num_instruments() const;
523  std::int32_t get_num_samples() const;
524 
525  std::vector<std::string> get_subsong_names() const;
526  std::vector<std::string> get_channel_names() const;
527  std::vector<std::string> get_order_names() const;
528  std::vector<std::string> get_pattern_names() const;
529  std::vector<std::string> get_instrument_names() const;
530  std::vector<std::string> get_sample_names() const;
531 
532  std::int32_t get_order_pattern( std::int32_t order ) const;
533 
534  std::int32_t get_pattern_num_rows( std::int32_t pattern ) const;
535 
536  std::uint8_t get_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
537 
538  std::string format_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
539  std::string highlight_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const;
540 
541  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;
542  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;
543 
544  std::vector<std::string> get_ctls() const;
545 
546  std::string ctl_get( const std::string & ctl ) const;
547  void ctl_set( const std::string & ctl, const std::string & value );
548 
549  // remember to add new functions to both C and C++ interfaces and to increase OPENMPT_API_VERSION_MINOR
550 
551 }; // class module
552 
553 } // namespace openmpt
554 
559 #endif // LIBOPENMPT_HPP