Class: FFI::OpenMPT::Module

Inherits:
Object
  • Object
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

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

  # 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

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) ? (name) : super
end

Instance Attribute Details

#sample_rateObject

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_namesObject



63
64
65
# File 'lib/ffi/openmpt/module.rb', line 63

def channel_names
  get_names(num_channels, :openmpt_module_get_channel_name)
end

#closeObject



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

Returns:

  • (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_orderObject



132
133
134
# File 'lib/ffi/openmpt/module.rb', line 132

def current_order
  openmpt_module_get_current_order(@mod)
end

#current_patternObject



136
137
138
# File 'lib/ffi/openmpt/module.rb', line 136

def current_pattern
  openmpt_module_get_current_pattern(@mod)
end

#current_playing_channelsObject



144
145
146
# File 'lib/ffi/openmpt/module.rb', line 144

def current_playing_channels
  openmpt_module_get_current_playing_channels(@mod)
end

#current_rowObject



140
141
142
# File 'lib/ffi/openmpt/module.rb', line 140

def current_row
  openmpt_module_get_current_row(@mod)
end

#current_speedObject



124
125
126
# File 'lib/ffi/openmpt/module.rb', line 124

def current_speed
  openmpt_module_get_current_speed(@mod)
end

#current_tempoObject



128
129
130
# File 'lib/ffi/openmpt/module.rb', line 128

def current_tempo
  openmpt_module_get_current_tempo(@mod)
end

#durationObject



44
45
46
47
# File 'lib/ffi/openmpt/module.rb', line 44

def duration
  return if closed?
  openmpt_module_get_duration_seconds(@mod)
end

#gainObject



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

#gain=(value) ⇒ Object



183
184
185
186
187
# 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_namesObject



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_filterObject



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



211
212
213
214
215
# 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) ⇒ Object



166
167
168
169
170
171
172
173
# File 'lib/ffi/openmpt/module.rb', line 166

def (key)
  return if closed? || !.include?(key)

  ptr = (@mod, key.to_s)
  ptr.read_string
ensure
  openmpt_free_string(ptr)
end

#metadata_keysObject



159
160
161
162
163
164
# File 'lib/ffi/openmpt/module.rb', line 159

def 
  ptr = (@mod)
  ptr.read_string.split(';').map(&:to_sym)
ensure
  openmpt_free_string(ptr)
end

#num_channelsObject



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_instrumentsObject



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_ordersObject



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_patternsObject



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_samplesObject



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_subsongsObject



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_namesObject



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_namesObject



81
82
83
# File 'lib/ffi/openmpt/module.rb', line 81

def pattern_names
  get_names(num_patterns, :openmpt_module_get_pattern_name)
end

#positionObject



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_countObject



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

Returns:

  • (Boolean)


275
276
277
# File 'lib/ffi/openmpt/module.rb', line 275

def respond_to_missing?(name, *all)
  .include?(name) || super
end

#sample_namesObject



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_separationObject



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



197
198
199
200
201
# 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_namesObject



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_rampingObject



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



225
226
227
228
229
# 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