class FFI::OpenMPT::Module
Attributes
sample_rate[R]
Public Class Methods
new(filename, sample_rate = 48_000)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 15 def initialize(filename, sample_rate = 48_000) @closed = false @mod = read_mod(filename) @sample_rate = sample_rate # Allocate a reusable single int buffer. # This is for use by the 'get_render_params'-type calls. # FFI::MemoryPointer is garbage collected automatically. @int_value = ::FFI::MemoryPointer.new(:int, 1) end
open(filename) { |m| ... }
click to toggle source
# File lib/ffi/openmpt/module.rb, line 26 def self.open(filename) m = new(filename) if block_given? begin yield m ensure m.close end end m end
Public Instance Methods
channel_names()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 63 def channel_names get_names(num_channels, :openmpt_module_get_channel_name) end
close()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 261 def close return if closed? @closed = true openmpt_module_destroy(@mod) end
closed?()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 267 def closed? @closed end
current_channel_vu_mono(channel)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 148 def current_channel_vu_mono(channel) openmpt_module_get_current_channel_vu_mono(@mod, channel) end
current_channel_vu_stereo(channel)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 152 def current_channel_vu_stereo(channel) [ openmpt_module_get_current_channel_vu_left(@mod, channel), openmpt_module_get_current_channel_vu_right(@mod, channel) ] end
current_order()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 132 def current_order openmpt_module_get_current_order(@mod) end
current_pattern()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 136 def current_pattern openmpt_module_get_current_pattern(@mod) end
current_playing_channels()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 144 def current_playing_channels openmpt_module_get_current_playing_channels(@mod) end
current_row()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 140 def current_row openmpt_module_get_current_row(@mod) end
current_speed()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 124 def current_speed openmpt_module_get_current_speed(@mod) end
current_tempo()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 128 def current_tempo openmpt_module_get_current_tempo(@mod) end
duration()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 44 def duration return if closed? openmpt_module_get_duration_seconds(@mod) end
gain()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 175 def gain success = openmpt_module_get_render_param( @mod, OPENMPT_MODULE_RENDER_MASTERGAIN_MILLIBEL, @int_value ) success == 1 ? @int_value.read_int : nil end
gain=(value)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 183 def gain=(value) openmpt_module_set_render_param( @mod, OPENMPT_MODULE_RENDER_MASTERGAIN_MILLIBEL, value ) end
instrument_names()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 90 def instrument_names get_names(num_instruments, :openmpt_module_get_instrument_name) end
interpolation_filter()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 203 def interpolation_filter success = openmpt_module_get_render_param( @mod, OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, @int_value ) success == 1 ? @int_value.read_int : nil end
interpolation_filter=(value)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 211 def interpolation_filter=(value) openmpt_module_set_render_param( @mod, OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, value ) end
metadata(key)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 166 def metadata(key) return if closed? || !metadata_keys.include?(key) ptr = openmpt_module_get_metadata(@mod, key.to_s) ptr.read_string ensure openmpt_free_string(ptr) end
metadata_keys()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 159 def metadata_keys ptr = openmpt_module_get_metadata_keys(@mod) ptr.read_string.split(';').map(&:to_sym) ensure openmpt_free_string(ptr) end
method_missing(name, *args)
click to toggle source
Calls superclass method
# File lib/ffi/openmpt/module.rb, line 271 def method_missing(name, *args) respond_to?(name) ? metadata(name) : super end
num_channels()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 58 def num_channels return if closed? openmpt_module_get_num_channels(@mod) end
num_instruments()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 85 def num_instruments return if closed? openmpt_module_get_num_instruments(@mod) end
num_orders()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 67 def num_orders return if closed? openmpt_module_get_num_orders(@mod) end
num_patterns()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 76 def num_patterns return if closed? openmpt_module_get_num_patterns(@mod) end
num_samples()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 94 def num_samples return if closed? openmpt_module_get_num_samples(@mod) end
num_subsongs()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 49 def num_subsongs return if closed? openmpt_module_get_num_subsongs(@mod) end
order_names()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 72 def order_names get_names(num_orders, :openmpt_module_get_order_name) end
pattern_names()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 81 def pattern_names get_names(num_patterns, :openmpt_module_get_pattern_name) end
position()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 111 def position return if closed? openmpt_module_get_position_seconds(@mod) end
position=(param)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 116 def position=(param) if param.is_a?(Array) openmpt_module_set_position_order_row(@mod, param[0], param[1]) else openmpt_module_set_position_seconds(@mod, param) end end
read_float_mono(frames, buffer)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 235 def read_float_mono(frames, buffer) openmpt_module_read_float_mono(@mod, @sample_rate, frames, buffer) end
read_float_stereo(frames, left, right)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 249 def read_float_stereo(frames, left, right) openmpt_module_read_float_stereo( @mod, @sample_rate, frames, left, right ) end
read_interleaved_float_stereo(frames, buffer)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 255 def read_interleaved_float_stereo(frames, buffer) openmpt_module_read_interleaved_float_stereo( @mod, @sample_rate, frames, buffer ) end
read_interleaved_stereo(frames, buffer)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 243 def read_interleaved_stereo(frames, buffer) openmpt_module_read_interleaved_stereo( @mod, @sample_rate, frames, buffer ) end
read_mono(frames, buffer)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 231 def read_mono(frames, buffer) openmpt_module_read_mono(@mod, @sample_rate, frames, buffer) end
read_stereo(frames, left, right)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 239 def read_stereo(frames, left, right) openmpt_module_read_stereo(@mod, @sample_rate, frames, left, right) end
repeat_count()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 103 def repeat_count openmpt_module_get_repeat_count(@mod) end
repeat_count=(count)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 107 def repeat_count=(count) openmpt_module_set_repeat_count(@mod, count) end
respond_to_missing?(name, *all)
click to toggle source
Calls superclass method
# File lib/ffi/openmpt/module.rb, line 275 def respond_to_missing?(name, *all) metadata_keys.include?(name) || super end
sample_names()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 99 def sample_names get_names(num_samples, :openmpt_module_get_sample_name) end
sample_rate=(rate)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 40 def sample_rate=(rate) @sample_rate = rate if (8_000..192_000).cover?(rate) end
stereo_separation()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 189 def stereo_separation success = openmpt_module_get_render_param( @mod, OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT, @int_value ) success == 1 ? @int_value.read_int : nil end
stereo_separation=(value)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 197 def stereo_separation=(value) openmpt_module_set_render_param( @mod, OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT, value ) end
subsong_names()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 54 def subsong_names get_names(num_subsongs, :openmpt_module_get_subsong_name) end
volume_ramping()
click to toggle source
# File lib/ffi/openmpt/module.rb, line 217 def volume_ramping success = openmpt_module_get_render_param( @mod, OPENMPT_MODULE_RENDER_VOLUMERAMPING_STRENGTH, @int_value ) success == 1 ? @int_value.read_int : nil end
volume_ramping=(value)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 225 def volume_ramping=(value) openmpt_module_set_render_param( @mod, OPENMPT_MODULE_RENDER_VOLUMERAMPING_STRENGTH, value ) end
Private Instance Methods
get_names(num, get)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 293 def get_names(num, get) (0...num).reduce([]) do |acc, i| begin ptr = send(get, @mod, i) acc << ptr.read_string ensure openmpt_free_string(ptr) end end end
read_mod(filename)
click to toggle source
# File lib/ffi/openmpt/module.rb, line 281 def read_mod(filename) data = ::File.binread(filename) mod = openmpt_module_create_from_memory2( data, data.bytesize, LogSilent, nil, ErrorIgnore, nil, nil, nil, nil ) @closed = (mod.address == 0) mod end