Class: FFI::OpenMPT::Module
- Inherits:
-
Object
- Object
- FFI::OpenMPT::Module
show all
- Includes:
- API
- Defined in:
- lib/ffi/openmpt/module.rb
Constant Summary
Constants included
from API
API::ErrorDefault, API::ErrorIgnore, API::ErrorLog, API::ErrorStore, API::LogDefault, API::LogSilent, API::OPENMPT_ERROR_ARGUMENT_NULL_POINTER, API::OPENMPT_ERROR_BASE, API::OPENMPT_ERROR_DOMAIN, API::OPENMPT_ERROR_EXCEPTION, API::OPENMPT_ERROR_FUNC_RESULT_DEFAULT, API::OPENMPT_ERROR_FUNC_RESULT_LOG, API::OPENMPT_ERROR_FUNC_RESULT_NONE, API::OPENMPT_ERROR_FUNC_RESULT_STORE, API::OPENMPT_ERROR_GENERAL, API::OPENMPT_ERROR_INVALID_ARGUMENT, API::OPENMPT_ERROR_INVALID_MODULE_POINTER, API::OPENMPT_ERROR_LENGTH, API::OPENMPT_ERROR_LOGIC, API::OPENMPT_ERROR_OK, API::OPENMPT_ERROR_OUT_OF_MEMORY, API::OPENMPT_ERROR_OUT_OF_RANGE, API::OPENMPT_ERROR_OVERFLOW, API::OPENMPT_ERROR_RANGE, API::OPENMPT_ERROR_RUNTIME, API::OPENMPT_ERROR_UNDERFLOW, API::OPENMPT_ERROR_UNKNOWN, API::OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, API::OPENMPT_MODULE_RENDER_MASTERGAIN_MILLIBEL, API::OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT, API::OPENMPT_MODULE_RENDER_VOLUMERAMPING_STRENGTH, API::OPENMPT_PROBE_FILE_HEADER_FLAGS_CONTAINERS, API::OPENMPT_PROBE_FILE_HEADER_FLAGS_DEFAULT, API::OPENMPT_PROBE_FILE_HEADER_FLAGS_MODULES, API::OPENMPT_PROBE_FILE_HEADER_FLAGS_NONE, API::OPENMPT_PROBE_FILE_HEADER_RESULT_ERROR, API::OPENMPT_PROBE_FILE_HEADER_RESULT_FAILURE, API::OPENMPT_PROBE_FILE_HEADER_RESULT_SUCCESS, API::OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#channel_names ⇒ Object
-
#close ⇒ Object
-
#closed? ⇒ Boolean
-
#current_channel_vu_mono(channel) ⇒ Object
-
#current_channel_vu_stereo(channel) ⇒ Object
-
#current_order ⇒ Object
-
#current_pattern ⇒ Object
-
#current_playing_channels ⇒ Object
-
#current_row ⇒ Object
-
#current_speed ⇒ Object
-
#current_tempo ⇒ Object
-
#duration ⇒ Object
-
#gain ⇒ Object
-
#gain=(value) ⇒ Object
-
#initialize(filename, sample_rate = 48_000) ⇒ Module
constructor
A new instance of Module.
-
#instrument_names ⇒ Object
-
#interpolation_filter ⇒ Object
-
#interpolation_filter=(value) ⇒ Object
-
#metadata(key) ⇒ Object
-
#metadata_keys ⇒ Object
-
#method_missing(name, *args) ⇒ Object
-
#num_channels ⇒ Object
-
#num_instruments ⇒ Object
-
#num_orders ⇒ Object
-
#num_patterns ⇒ Object
-
#num_samples ⇒ Object
-
#num_subsongs ⇒ Object
-
#order_names ⇒ Object
-
#pattern_names ⇒ Object
-
#position ⇒ Object
-
#position=(param) ⇒ Object
-
#read_float_mono(frames, buffer) ⇒ Object
-
#read_float_stereo(frames, left, right) ⇒ Object
-
#read_interleaved_float_stereo(frames, buffer) ⇒ Object
-
#read_interleaved_stereo(frames, buffer) ⇒ Object
-
#read_mono(frames, buffer) ⇒ Object
-
#read_stereo(frames, left, right) ⇒ Object
-
#repeat_count ⇒ Object
-
#repeat_count=(count) ⇒ Object
-
#respond_to_missing?(name, *all) ⇒ Boolean
-
#sample_names ⇒ Object
-
#stereo_separation ⇒ Object
-
#stereo_separation=(value) ⇒ Object
-
#subsong_names ⇒ Object
-
#volume_ramping ⇒ Object
-
#volume_ramping=(value) ⇒ Object
Constructor Details
#initialize(filename, sample_rate = 48_000) ⇒ Module
Returns a new instance of Module.
15
16
17
18
19
20
21
22
23
24
|
# 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
@int_value = ::FFI::MemoryPointer.new(:int, 1)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
271
272
273
|
# File 'lib/ffi/openmpt/module.rb', line 271
def method_missing(name, *args)
respond_to?(name) ? metadata(name) : super
end
|
Instance Attribute Details
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
13
14
15
|
# File 'lib/ffi/openmpt/module.rb', line 13
def sample_rate
@sample_rate
end
|
Class Method Details
.open(filename) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# 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
|
Instance Method Details
#channel_names ⇒ Object
63
64
65
|
# File 'lib/ffi/openmpt/module.rb', line 63
def channel_names
get_names(num_channels, :openmpt_module_get_channel_name)
end
|
#close ⇒ Object
261
262
263
264
265
|
# File 'lib/ffi/openmpt/module.rb', line 261
def close
return if closed?
@closed = true
openmpt_module_destroy(@mod)
end
|
#closed? ⇒ Boolean
267
268
269
|
# File 'lib/ffi/openmpt/module.rb', line 267
def closed?
@closed
end
|
#current_channel_vu_mono(channel) ⇒ Object
148
149
150
|
# 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) ⇒ Object
152
153
154
155
156
157
|
# 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 ⇒ Object
132
133
134
|
# File 'lib/ffi/openmpt/module.rb', line 132
def current_order
openmpt_module_get_current_order(@mod)
end
|
#current_pattern ⇒ Object
136
137
138
|
# File 'lib/ffi/openmpt/module.rb', line 136
def current_pattern
openmpt_module_get_current_pattern(@mod)
end
|
#current_playing_channels ⇒ Object
144
145
146
|
# File 'lib/ffi/openmpt/module.rb', line 144
def current_playing_channels
openmpt_module_get_current_playing_channels(@mod)
end
|
#current_row ⇒ Object
140
141
142
|
# File 'lib/ffi/openmpt/module.rb', line 140
def current_row
openmpt_module_get_current_row(@mod)
end
|
#current_speed ⇒ Object
124
125
126
|
# File 'lib/ffi/openmpt/module.rb', line 124
def current_speed
openmpt_module_get_current_speed(@mod)
end
|
#current_tempo ⇒ Object
128
129
130
|
# File 'lib/ffi/openmpt/module.rb', line 128
def current_tempo
openmpt_module_get_current_tempo(@mod)
end
|
#duration ⇒ Object
44
45
46
47
|
# File 'lib/ffi/openmpt/module.rb', line 44
def duration
return if closed?
openmpt_module_get_duration_seconds(@mod)
end
|
#gain ⇒ Object
175
176
177
178
179
180
181
|
# 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
|
#instrument_names ⇒ Object
90
91
92
|
# File 'lib/ffi/openmpt/module.rb', line 90
def instrument_names
get_names(num_instruments, :openmpt_module_get_instrument_name)
end
|
#interpolation_filter ⇒ Object
203
204
205
206
207
208
209
|
# 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) ⇒ Object
166
167
168
169
170
171
172
173
|
# 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
|
159
160
161
162
163
164
|
# 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
|
#num_channels ⇒ Object
58
59
60
61
|
# File 'lib/ffi/openmpt/module.rb', line 58
def num_channels
return if closed?
openmpt_module_get_num_channels(@mod)
end
|
#num_instruments ⇒ Object
85
86
87
88
|
# File 'lib/ffi/openmpt/module.rb', line 85
def num_instruments
return if closed?
openmpt_module_get_num_instruments(@mod)
end
|
#num_orders ⇒ Object
67
68
69
70
|
# File 'lib/ffi/openmpt/module.rb', line 67
def num_orders
return if closed?
openmpt_module_get_num_orders(@mod)
end
|
#num_patterns ⇒ Object
76
77
78
79
|
# File 'lib/ffi/openmpt/module.rb', line 76
def num_patterns
return if closed?
openmpt_module_get_num_patterns(@mod)
end
|
#num_samples ⇒ Object
94
95
96
97
|
# File 'lib/ffi/openmpt/module.rb', line 94
def num_samples
return if closed?
openmpt_module_get_num_samples(@mod)
end
|
#num_subsongs ⇒ Object
49
50
51
52
|
# File 'lib/ffi/openmpt/module.rb', line 49
def num_subsongs
return if closed?
openmpt_module_get_num_subsongs(@mod)
end
|
#order_names ⇒ Object
72
73
74
|
# File 'lib/ffi/openmpt/module.rb', line 72
def order_names
get_names(num_orders, :openmpt_module_get_order_name)
end
|
#pattern_names ⇒ Object
81
82
83
|
# File 'lib/ffi/openmpt/module.rb', line 81
def pattern_names
get_names(num_patterns, :openmpt_module_get_pattern_name)
end
|
#position ⇒ Object
111
112
113
114
|
# File 'lib/ffi/openmpt/module.rb', line 111
def position
return if closed?
openmpt_module_get_position_seconds(@mod)
end
|
#position=(param) ⇒ Object
116
117
118
119
120
121
122
|
# 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) ⇒ Object
235
236
237
|
# 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) ⇒ Object
249
250
251
252
253
|
# 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) ⇒ Object
255
256
257
258
259
|
# 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) ⇒ Object
243
244
245
246
247
|
# 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) ⇒ Object
231
232
233
|
# 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) ⇒ Object
239
240
241
|
# 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 ⇒ Object
103
104
105
|
# File 'lib/ffi/openmpt/module.rb', line 103
def repeat_count
openmpt_module_get_repeat_count(@mod)
end
|
#repeat_count=(count) ⇒ Object
107
108
109
|
# 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) ⇒ Boolean
275
276
277
|
# File 'lib/ffi/openmpt/module.rb', line 275
def respond_to_missing?(name, *all)
metadata_keys.include?(name) || super
end
|
#sample_names ⇒ Object
99
100
101
|
# File 'lib/ffi/openmpt/module.rb', line 99
def sample_names
get_names(num_samples, :openmpt_module_get_sample_name)
end
|
#stereo_separation ⇒ Object
189
190
191
192
193
194
195
|
# 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) ⇒ Object
#subsong_names ⇒ Object
54
55
56
|
# File 'lib/ffi/openmpt/module.rb', line 54
def subsong_names
get_names(num_subsongs, :openmpt_module_get_subsong_name)
end
|
#volume_ramping ⇒ Object
217
218
219
220
221
222
223
|
# 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) ⇒ Object