ffi-openmpt 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cff9c1335f501d6c4567b5f3fd9f314413426608f2fd83ff43c40cd8ac3430d5
4
- data.tar.gz: 6bc3d44745d502705a18b8b85bf6608ac94f9315ed4dcfb4b8bf56f048462709
3
+ metadata.gz: 5d30e0517446c3cf2bfabeefd2d7b3ec0db4485a27a8ee6564a854826c5a5e90
4
+ data.tar.gz: eb85f0fc61a052cfc7d032634a3229d4527d1579931d67e3e23c1ed1b658e8b1
5
5
  SHA512:
6
- metadata.gz: 39aa9577df5787ffb062a2a0045e4fc2f374343a32246f6f383bcfde63ad7722c3b99b01f0affe244e68973c80a59905a95c3339865f2ed9f74dd7cfd730a504
7
- data.tar.gz: 72e57d5e865ab26e44b72727b9bb2a05a05b930a4c5a4155fbdcb753c07c965647a32d1abf4565a18ee95ea9e3581ea57df4d294182982a2dfda9685440ca690
6
+ metadata.gz: ef774fbdfa2c3c80d39dee216fdf09ad894a79a8f6f1895c09101460c622239d5257cdf046bb790f097f4bf7350aa234739e1ffe7fd73e993a7910e7b90f2167
7
+ data.tar.gz: 26f6137c8f81ea90c1ebe205ed8fa2686c022d5b959d828275a323fc5116ef0b60073b6b1de7ca7fc6b59cd0d06af5eb91c035a57496a399fe0765757c6f5cdf
data/.travis.yml CHANGED
@@ -4,15 +4,15 @@ language: ruby
4
4
  cache: bundler
5
5
 
6
6
  before_install:
7
- - gem install bundler -v 1.16.1
7
+ - gem install bundler -v 2.0.1
8
8
  - ./test/install-libopenmpt.sh
9
9
  - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TRAVIS_BUILD_DIR/usr/lib
10
10
 
11
11
  rvm:
12
- - 2.2.10
13
12
  - 2.3.8
14
13
  - 2.4.5
15
- - 2.5.3
14
+ - 2.5.5
15
+ - 2.6.2
16
16
  - rbx-3
17
17
  - ruby-head
18
18
 
@@ -29,7 +29,5 @@ matrix:
29
29
  exclude:
30
30
  - rvm: rbx-3
31
31
  env: TEST_LIBOPENMPT_VERSION=0.3.12
32
- - rvm: 2.2.10
33
- env: TEST_LIBOPENMPT_VERSION=0.3.12
34
32
  - rvm: 2.3.8
35
33
  env: TEST_LIBOPENMPT_VERSION=0.3.12
data/CHANGES.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changes log for the Ruby OpenMPT library (ffi-openmpt)
2
2
 
3
+ ## Version 0.4.0
4
+
5
+ * Update the minimum ruby version to 2.3.
6
+ * Update to use bundler 2.0.1.
7
+ * Update the string example in README.md.
8
+ * Simplify the API string code example.
9
+ * Add sample_name to the ruby interface.
10
+ * Align info method names with the C++ API.
11
+ * Ensure memory is always freed in String::get.
12
+ * Ensure memory is always freed in Module methods.
13
+ * Ensure memory is always freed in OpenMPT methods.
14
+ * Update the memory handling code example in the README.
15
+ * Use `warn` not `puts` for error messages in mod-2-raw.
16
+ * Fix wording of an error message in mod-2-raw.
17
+ * Add Module#sample_names to the ruby interface.
18
+ * Add a note in Module::new about MemoryPointer.
19
+ * Remove Module#sample_name. It's not in the C++ API.
20
+ * Generalize getting name lists from a mod.
21
+ * Add Module#instrument_names to the ruby interface.
22
+ * Add Module#pattern_names to the ruby interface.
23
+ * Add Module#order_names to the ruby interface.
24
+ * Add Module#channel_names to the ruby interface.
25
+ * Add Module#subsong_names to the ruby interface.
26
+
3
27
  ## Version 0.3.0
4
28
 
5
29
  * Wrap the libopenmpt module read mono functions.
data/README.md CHANGED
@@ -55,17 +55,20 @@ Not all `libopenmpt` methods are wrapped yet, but enough functionality is suppli
55
55
  `libopenmpt` manages the memory of any strings it returns. This means that you must free up such memory explicitly after you have finished with them when using the C API. Such strings are returned to ruby as [`FFI::Pointer`][ffi-pointer] objects, so the string value can be copied to a ruby string as follows:
56
56
 
57
57
  ```ruby
58
- include FFI::OpenMPT::API
59
- ptr = openmpt_get_string('url')
60
- str = ptr.read_string
61
- openmpt_free_string(ptr)
58
+ begin
59
+ ptr = FFI::OpenMPT::API.openmpt_get_string('url')
60
+ str = ptr.read_string
61
+ ensure
62
+ FFI::OpenMPT::API.openmpt_free_string(ptr)
63
+ end
64
+
62
65
  puts str
63
66
  ```
64
67
 
65
68
  The ruby interface handles all this for you:
66
69
 
67
70
  ```ruby
68
- str = FFI::OpenMPT.string(:url)
71
+ str = FFI::OpenMPT::String.get(:url)
69
72
  puts str
70
73
  ```
71
74
 
@@ -127,7 +130,7 @@ Until this library reaches version 1.0.0 the API may be subject to breaking chan
127
130
 
128
131
  The Ruby OpenMPT code (ffi-openmpt) is released under the BSD licence.
129
132
 
130
- Copyright (c) 2018, Robert Haines
133
+ Copyright (c) 2018, 2019 Robert Haines
131
134
  All rights reserved.
132
135
 
133
136
  See LICENCE for more details.
data/examples/mod-2-raw CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- # Copyright (c) 2018 Robert Haines.
4
+ # Copyright (c) 2018, 2019 Robert Haines.
5
5
  #
6
6
  # Licensed under the BSD License. See LICENCE for details.
7
7
 
@@ -9,7 +9,7 @@ require 'ffi/openmpt'
9
9
 
10
10
  def get_filename(var)
11
11
  if var.nil?
12
- puts 'Please supply a filename to interrogate.'
12
+ warn 'Please supply a filename to convert.'
13
13
  exit(1)
14
14
  end
15
15
 
@@ -28,13 +28,13 @@ end
28
28
 
29
29
  # Does this file exist? Is it readable?
30
30
  unless ::File.readable?(mod_path)
31
- puts "'#{mod_path}' does not exist, or is not readable."
31
+ warn "'#{mod_path}' does not exist, or is not readable."
32
32
  exit(1)
33
33
  end
34
34
 
35
35
  # Can libopenmpt open this file?
36
36
  unless ::FFI::OpenMPT.probe_file(mod_path)
37
- puts 'libopenmpt can not open this file. Are you sure it is a mod?'
37
+ warn 'libopenmpt can not open this file. Are you sure it is a mod?'
38
38
  exit(1)
39
39
  end
40
40
 
data/examples/mod-info CHANGED
@@ -45,10 +45,10 @@ end
45
45
  puts "Tracker....: #{mod.tracker}"
46
46
  puts "Title......: #{mod.title}"
47
47
  puts "Duration...: #{duration_mins}:#{duration_secs.round(3)}"
48
- puts "Subsongs...: #{mod.subsongs}"
49
- puts "Channels...: #{mod.channels}"
50
- puts "Orders.....: #{mod.orders}"
51
- puts "Patterns...: #{mod.patterns}"
52
- puts "Instruments: #{mod.instruments}"
53
- puts "Samples....: #{mod.samples}"
48
+ puts "Subsongs...: #{mod.num_subsongs}"
49
+ puts "Channels...: #{mod.num_channels}"
50
+ puts "Orders.....: #{mod.num_orders}"
51
+ puts "Patterns...: #{mod.num_patterns}"
52
+ puts "Instruments: #{mod.num_instruments}"
53
+ puts "Samples....: #{mod.num_samples}"
54
54
  end
data/ffi-openmpt.gemspec CHANGED
@@ -28,11 +28,11 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
30
30
 
31
- spec.required_ruby_version = '>= 2.2.0'
31
+ spec.required_ruby_version = '>= 2.3.0'
32
32
 
33
33
  spec.add_runtime_dependency 'ffi', '~> 1.9'
34
34
 
35
- spec.add_development_dependency 'bundler', '~> 1.16'
35
+ spec.add_development_dependency 'bundler', '~> 2.0.1'
36
36
  spec.add_development_dependency 'coveralls', '~> 0.8'
37
37
  spec.add_development_dependency 'minitest', '~> 5.0'
38
38
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -19,6 +19,7 @@ module FFI
19
19
 
20
20
  # Allocate a reusable single int buffer.
21
21
  # This is for use by the 'get_render_params'-type calls.
22
+ # FFI::MemoryPointer is garbage collected automatically.
22
23
  @int_value = ::FFI::MemoryPointer.new(:int, 1)
23
24
  end
24
25
 
@@ -45,36 +46,60 @@ module FFI
45
46
  openmpt_module_get_duration_seconds(@mod)
46
47
  end
47
48
 
48
- def subsongs
49
+ def num_subsongs
49
50
  return if closed?
50
51
  openmpt_module_get_num_subsongs(@mod)
51
52
  end
52
53
 
53
- def channels
54
+ def subsong_names
55
+ get_names(num_subsongs, :openmpt_module_get_subsong_name)
56
+ end
57
+
58
+ def num_channels
54
59
  return if closed?
55
60
  openmpt_module_get_num_channels(@mod)
56
61
  end
57
62
 
58
- def orders
63
+ def channel_names
64
+ get_names(num_channels, :openmpt_module_get_channel_name)
65
+ end
66
+
67
+ def num_orders
59
68
  return if closed?
60
69
  openmpt_module_get_num_orders(@mod)
61
70
  end
62
71
 
63
- def patterns
72
+ def order_names
73
+ get_names(num_orders, :openmpt_module_get_order_name)
74
+ end
75
+
76
+ def num_patterns
64
77
  return if closed?
65
78
  openmpt_module_get_num_patterns(@mod)
66
79
  end
67
80
 
68
- def instruments
81
+ def pattern_names
82
+ get_names(num_patterns, :openmpt_module_get_pattern_name)
83
+ end
84
+
85
+ def num_instruments
69
86
  return if closed?
70
87
  openmpt_module_get_num_instruments(@mod)
71
88
  end
72
89
 
73
- def samples
90
+ def instrument_names
91
+ get_names(num_instruments, :openmpt_module_get_instrument_name)
92
+ end
93
+
94
+ def num_samples
74
95
  return if closed?
75
96
  openmpt_module_get_num_samples(@mod)
76
97
  end
77
98
 
99
+ def sample_names
100
+ get_names(num_samples, :openmpt_module_get_sample_name)
101
+ end
102
+
78
103
  def repeat_count
79
104
  openmpt_module_get_repeat_count(@mod)
80
105
  end
@@ -98,20 +123,18 @@ module FFI
98
123
 
99
124
  def metadata_keys
100
125
  ptr = openmpt_module_get_metadata_keys(@mod)
101
- str = ptr.read_string
126
+ ptr.read_string.split(';').map(&:to_sym)
127
+ ensure
102
128
  openmpt_free_string(ptr)
103
-
104
- str.split(';').map(&:to_sym)
105
129
  end
106
130
 
107
131
  def metadata(key)
108
132
  return if closed? || !metadata_keys.include?(key)
109
133
 
110
134
  ptr = openmpt_module_get_metadata(@mod, key.to_s)
111
- str = ptr.read_string
135
+ ptr.read_string
136
+ ensure
112
137
  openmpt_free_string(ptr)
113
-
114
- str
115
138
  end
116
139
 
117
140
  def gain
@@ -231,6 +254,15 @@ module FFI
231
254
  @closed = (mod.address == 0)
232
255
  mod
233
256
  end
257
+
258
+ def get_names(num, get)
259
+ (0...num).reduce([]) do |acc, i|
260
+ ptr = send(get, @mod, i)
261
+ acc << ptr.read_string
262
+ ensure
263
+ openmpt_free_string(ptr)
264
+ end
265
+ end
234
266
  end
235
267
  end
236
268
  end
@@ -17,10 +17,9 @@ module FFI
17
17
 
18
18
  def self.supported_extensions
19
19
  ptr = API.openmpt_get_supported_extensions
20
- exts = ptr.read_string.split(';').map(&:to_sym)
20
+ ptr.read_string.split(';').map(&:to_sym)
21
+ ensure
21
22
  API.openmpt_free_string(ptr)
22
-
23
- exts
24
23
  end
25
24
 
26
25
  def self.extension_supported?(ext)
@@ -33,10 +32,9 @@ module FFI
33
32
 
34
33
  def self.error_string(error)
35
34
  ptr = API.openmpt_error_string(error)
36
- str = ptr.read_string
35
+ ptr.read_string
36
+ ensure
37
37
  API.openmpt_free_string(ptr)
38
-
39
- str
40
38
  end
41
39
 
42
40
  def self.probe_file(filename)
@@ -34,10 +34,9 @@ module FFI
34
34
 
35
35
  def self.get(key)
36
36
  ptr = API.openmpt_get_string(key.to_s)
37
- str = ptr.read_string
37
+ ptr.read_string
38
+ ensure
38
39
  API.openmpt_free_string(ptr)
39
-
40
- str
41
40
  end
42
41
 
43
42
  def self.method_missing(name, *args)
@@ -6,6 +6,6 @@
6
6
 
7
7
  module FFI
8
8
  module OpenMPT
9
- VERSION = '0.3.0'
9
+ VERSION = '0.4.0'
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-openmpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Haines
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-24 00:00:00.000000000 Z
11
+ date: 2019-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.16'
33
+ version: 2.0.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.16'
40
+ version: 2.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -139,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
- version: 2.2.0
142
+ version: 2.3.0
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
145
  - - ">="