1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
/*
* libopenmpt_impl.hpp
* -------------------
* Purpose: libopenmpt private interface
* Notes : This is not a public header. Do NOT ship in distributions dev packages.
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#ifndef LIBOPENMPT_IMPL_HPP
#define LIBOPENMPT_IMPL_HPP
#include "libopenmpt_internal.h"
#include "libopenmpt.hpp"
#include <iosfwd>
#include <memory>
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4512) // assignment operator could not be generated
#endif
// forward declarations
namespace OpenMPT {
class FileReaderTraitsStdStream;
typedef FileReaderTraitsStdStream FileReaderTraitsDefault;
namespace detail {
template <typename Tbase>
class FileReader;
} // namespace detail
typedef detail::FileReader<FileReaderTraitsDefault> FileReader;
class CSoundFile;
class Dither;
} // namespace OpenMPT
namespace openmpt {
namespace version {
std::uint32_t get_library_version();
std::uint32_t get_core_version();
std::string get_string( const std::string & key );
} // namespace version
class log_interface {
protected:
log_interface();
public:
virtual ~log_interface();
virtual void log( const std::string & message ) const = 0;
}; // class log_interface
class std_ostream_log : public log_interface {
private:
std::ostream & destination;
public:
std_ostream_log( std::ostream & dst );
virtual ~std_ostream_log();
void log( const std::string & message ) const override;
}; // class CSoundFileLog_std_ostream
class log_forwarder;
struct callback_stream_wrapper {
void * stream;
std::size_t (*read)( void * stream, void * dst, std::size_t bytes );
int (*seek)( void * stream, std::int64_t offset, int whence );
std::int64_t (*tell)( void * stream );
}; // struct callback_stream_wrapper
class module_impl {
protected:
struct subsong_data {
double duration;
std::int32_t start_row;
std::int32_t start_order;
std::int32_t sequence;
subsong_data( double duration, std::int32_t start_row, std::int32_t start_order, std::int32_t sequence );
}; // struct subsong_data
typedef std::vector<subsong_data> subsongs_type;
enum class song_end_action {
fadeout_song,
continue_song,
stop_song,
};
static const std::int32_t all_subsongs = -1;
std::unique_ptr<log_interface> m_Log;
std::unique_ptr<log_forwarder> m_LogForwarder;
std::int32_t m_current_subsong;
double m_currentPositionSeconds;
std::unique_ptr<OpenMPT::CSoundFile> m_sndFile;
bool m_loaded;
bool m_mixer_initialized;
std::unique_ptr<OpenMPT::Dither> m_Dither;
subsongs_type m_subsongs;
float m_Gain;
song_end_action m_ctl_play_at_end;
bool m_ctl_load_skip_samples;
bool m_ctl_load_skip_patterns;
bool m_ctl_load_skip_plugins;
bool m_ctl_load_skip_subsongs_init;
bool m_ctl_seek_sync_samples;
std::vector<std::string> m_loaderMessages;
public:
void PushToCSoundFileLog( const std::string & text ) const;
void PushToCSoundFileLog( int loglevel, const std::string & text ) const;
protected:
std::string mod_string_to_utf8( const std::string & encoded ) const;
void apply_mixer_settings( std::int32_t samplerate, int channels );
void apply_libopenmpt_defaults();
subsongs_type get_subsongs() const;
void init_subsongs( subsongs_type & subsongs ) const;
bool has_subsongs_inited() const;
void ctor( const std::map< std::string, std::string > & ctls );
void load( const OpenMPT::FileReader & file, const std::map< std::string, std::string > & ctls );
bool is_loaded() const;
std::size_t read_wrapper( std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right );
std::size_t read_wrapper( std::size_t count, float * left, float * right, float * rear_left, float * rear_right );
std::size_t read_interleaved_wrapper( std::size_t count, std::size_t channels, std::int16_t * interleaved );
std::size_t read_interleaved_wrapper( std::size_t count, std::size_t channels, float * interleaved );
std::pair< std::string, std::string > format_and_highlight_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int command ) const;
std::pair< std::string, std::string > format_and_highlight_pattern_row_channel( std::int32_t p, std::int32_t r, std::int32_t c, std::size_t width, bool pad ) const;
static double could_open_probability( const OpenMPT::FileReader & file, double effort, std::unique_ptr<log_interface> log );
public:
static std::vector<std::string> get_supported_extensions();
static bool is_extension_supported( const char * extension );
static bool is_extension_supported( const std::string & extension );
static double could_open_probability( callback_stream_wrapper stream, double effort, std::unique_ptr<log_interface> log );
static double could_open_probability( std::istream & stream, double effort, std::unique_ptr<log_interface> log );
static std::size_t probe_file_header_get_recommended_size();
static int probe_file_header( std::uint64_t flags, const std::uint8_t * data, std::size_t size, std::uint64_t filesize );
static int probe_file_header( std::uint64_t flags, const void * data, std::size_t size, std::uint64_t filesize );
static int probe_file_header( std::uint64_t flags, const std::uint8_t * data, std::size_t size );
static int probe_file_header( std::uint64_t flags, const void * data, std::size_t size );
static int probe_file_header( std::uint64_t flags, std::istream & stream );
static int probe_file_header( std::uint64_t flags, callback_stream_wrapper stream );
module_impl( callback_stream_wrapper stream, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
module_impl( std::istream & stream, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
module_impl( const std::vector<std::uint8_t> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
module_impl( const std::vector<char> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
module_impl( const std::uint8_t * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
module_impl( const char * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
module_impl( const void * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
~module_impl();
public:
void select_subsong( std::int32_t subsong );
std::int32_t get_selected_subsong() const;
void set_repeat_count( std::int32_t repeat_count );
std::int32_t get_repeat_count() const;
double get_duration_seconds() const;
double set_position_seconds( double seconds );
double get_position_seconds() const;
double set_position_order_row( std::int32_t order, std::int32_t row );
std::int32_t get_render_param( int param ) const;
void set_render_param( int param, std::int32_t value );
std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * mono );
std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right );
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 );
std::size_t read( std::int32_t samplerate, std::size_t count, float * mono );
std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right );
std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right );
std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_stereo );
std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_quad );
std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, float * interleaved_stereo );
std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, float * interleaved_quad );
std::vector<std::string> get_metadata_keys() const;
std::string get_metadata( const std::string & key ) const;
std::int32_t get_current_speed() const;
std::int32_t get_current_tempo() const;
std::int32_t get_current_order() const;
std::int32_t get_current_pattern() const;
std::int32_t get_current_row() const;
std::int32_t get_current_playing_channels() const;
float get_current_channel_vu_mono( std::int32_t channel ) const;
float get_current_channel_vu_left( std::int32_t channel ) const;
float get_current_channel_vu_right( std::int32_t channel ) const;
float get_current_channel_vu_rear_left( std::int32_t channel ) const;
float get_current_channel_vu_rear_right( std::int32_t channel ) const;
std::int32_t get_num_subsongs() const;
std::int32_t get_num_channels() const;
std::int32_t get_num_orders() const;
std::int32_t get_num_patterns() const;
std::int32_t get_num_instruments() const;
std::int32_t get_num_samples() const;
std::vector<std::string> get_subsong_names() const;
std::vector<std::string> get_channel_names() const;
std::vector<std::string> get_order_names() const;
std::vector<std::string> get_pattern_names() const;
std::vector<std::string> get_instrument_names() const;
std::vector<std::string> get_sample_names() const;
std::int32_t get_order_pattern( std::int32_t o ) const;
std::int32_t get_pattern_num_rows( std::int32_t p ) const;
std::uint8_t get_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int cmd ) const;
std::string format_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int cmd ) const;
std::string highlight_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int cmd ) const;
std::string format_pattern_row_channel( std::int32_t p, std::int32_t r, std::int32_t c, std::size_t width, bool pad ) const;
std::string highlight_pattern_row_channel( std::int32_t p, std::int32_t r, std::int32_t c, std::size_t width, bool pad ) const;
std::vector<std::string> get_ctls() const;
std::string ctl_get( std::string ctl, bool throw_if_unknown = true ) const;
void ctl_set( std::string ctl, const std::string & value, bool throw_if_unknown = true );
}; // class module_impl
namespace helper {
template<typename T, typename... Args> std::unique_ptr<T> make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
} // namespace helper
} // namespace openmpt
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#endif // LIBOPENMPT_IMPL_HPP
|