midilib 4.0.2 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Credits +6 -0
- data/README.rdoc +2 -2
- data/lib/midilib/event.rb +9 -6
- data/lib/midilib/info.rb +2 -2
- data/lib/midilib/io/midifile.rb +15 -1
- data/lib/midilib/sequence.rb +2 -2
- data/test/test_io.rb +42 -3
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5959297a9ede4ca603a582ec44efb8231769fc680ec15e6b9acd047450f21b39
|
|
4
|
+
data.tar.gz: 6280cadcf9ba1d546f6b93152432a7ce5ede16a485356e43ffaa3023e79e1b98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 672ae72fb8d654d1684ce042883b6b808ed0db2838cd221fb6c3367a1e6fe92847b44024e297291b2bb1305c89456dbf56e8e5570e30d138a631ab03e8c2abd9
|
|
7
|
+
data.tar.gz: 97f2e14ee3ceb8cb1623b4512f846bdb3438b2ba2160df40047116027e7869202ba7f48571faf0f8ea1aa8c69d5dba1796b5f2172ae9748bebc80433e699311d
|
data/Credits
CHANGED
|
@@ -103,3 +103,9 @@ Miika Alonen (@amiika on Github)
|
|
|
103
103
|
the addition of end of track meta events when reading and writing MIDI
|
|
104
104
|
files.
|
|
105
105
|
Found and fixed a bug in SongPointer#data_as_bytes.
|
|
106
|
+
|
|
107
|
+
@bardrop on Github
|
|
108
|
+
|
|
109
|
+
Noticed that midilib doesn't skip alien chunks as required by the spec,
|
|
110
|
+
and fixed that shortcoming. AI assistance was used for code changes
|
|
111
|
+
under the supervision of @bardrop.
|
data/README.rdoc
CHANGED
|
@@ -330,12 +330,12 @@ License:: Distributed under the same license as Ruby.
|
|
|
330
330
|
|
|
331
331
|
midilib is copyrighted free software by Jim Menard and is released under the
|
|
332
332
|
same license as Ruby. See the Ruby license at
|
|
333
|
-
|
|
333
|
+
https://www.ruby-lang.org/en/about/license.txt.
|
|
334
334
|
|
|
335
335
|
midilib may be freely copied in its entirety providing this notice, all
|
|
336
336
|
source code, all documentation, and all other files are included.
|
|
337
337
|
|
|
338
|
-
midilib is Copyright (c) 2003-
|
|
338
|
+
midilib is Copyright (c) 2003-2026 by Jim Menard.
|
|
339
339
|
|
|
340
340
|
The song "No Fences" contained in the MIDI file examples/NoFences.mid is
|
|
341
341
|
Copyright (c) 1992 by Jim Menard (jim@jimmenard.com). It may be freely used
|
data/lib/midilib/event.rb
CHANGED
|
@@ -483,13 +483,16 @@ module MIDI
|
|
|
483
483
|
when META_SMPTE
|
|
484
484
|
'smpte'
|
|
485
485
|
when META_TIME_SIG
|
|
486
|
-
'time signature'
|
|
486
|
+
'time signature' # subclass adds more info
|
|
487
487
|
when META_KEY_SIG
|
|
488
|
-
'key signature'
|
|
488
|
+
'key signature' # subclass adds more info
|
|
489
489
|
when META_SEQ_SPECIF
|
|
490
490
|
'sequence specific'
|
|
491
|
+
when META_SET_TEMPO
|
|
492
|
+
'tempo' # subclass adds more info
|
|
491
493
|
else
|
|
492
|
-
#
|
|
494
|
+
# Other possible @meta_type values can be handled by
|
|
495
|
+
# subclasses.
|
|
493
496
|
'(other)'
|
|
494
497
|
end
|
|
495
498
|
str
|
|
@@ -538,7 +541,7 @@ module MIDI
|
|
|
538
541
|
end
|
|
539
542
|
|
|
540
543
|
def to_s
|
|
541
|
-
"
|
|
544
|
+
super << " #{@data} msecs per qnote (#{Tempo.mpq_to_bpm(@data)} bpm)"
|
|
542
545
|
end
|
|
543
546
|
end
|
|
544
547
|
|
|
@@ -584,9 +587,9 @@ module MIDI
|
|
|
584
587
|
end
|
|
585
588
|
|
|
586
589
|
# Returns the time signature for the event as a string.
|
|
587
|
-
# Example: "time
|
|
590
|
+
# Example: "0: time signature 3/4 (clocks=24, qnotes = 8)"
|
|
588
591
|
def to_s
|
|
589
|
-
"
|
|
592
|
+
super << " #{@data[0]}/#{2**@data[1]} (clocks=#{@data[2]}, qnotes=#{@data[3]})"
|
|
590
593
|
end
|
|
591
594
|
end
|
|
592
595
|
|
data/lib/midilib/info.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module MIDI
|
|
2
2
|
VERSION_MAJOR = 4
|
|
3
3
|
VERSION_MINOR = 0
|
|
4
|
-
VERSION_TWEAK =
|
|
4
|
+
VERSION_TWEAK = 4
|
|
5
5
|
Version = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_TWEAK}"
|
|
6
|
-
Copyright = 'Copyright (c) 2003-
|
|
6
|
+
Copyright = 'Copyright (c) 2003-2026 by Jim Menard <jim@jimmenard.com>'
|
|
7
7
|
end
|
data/lib/midilib/io/midifile.rb
CHANGED
|
@@ -134,6 +134,20 @@ module MIDI
|
|
|
134
134
|
|
|
135
135
|
# End of NOPs.
|
|
136
136
|
|
|
137
|
+
# Read through the next 'MTrk' header string, skipping any chunk of
|
|
138
|
+
# another type before it (its type, length and data). The MIDI file spec
|
|
139
|
+
# says that readers should "expect alien chunks and treat them as if
|
|
140
|
+
# they weren't there".
|
|
141
|
+
def skip_alien_chunks
|
|
142
|
+
while (type = get_bytes(4)) != MTrk_BYTE_ARRAY
|
|
143
|
+
len = read32
|
|
144
|
+
error("invalid chunk length #{len} for #{type.pack('C*').inspect}") if len.negative?
|
|
145
|
+
get_bytes(len)
|
|
146
|
+
end
|
|
147
|
+
rescue EOFError
|
|
148
|
+
error('unexpected EOF while trying to skip alien chunk')
|
|
149
|
+
end
|
|
150
|
+
|
|
137
151
|
# Read through 'MThd' or 'MTrk' header string. If skip is true, attempt
|
|
138
152
|
# to skip initial trash. If there is an error, #error is called.
|
|
139
153
|
def read_mt_header_string(bytes, skip)
|
|
@@ -191,7 +205,7 @@ module MIDI
|
|
|
191
205
|
status = 0 # (Possibly running) status byte
|
|
192
206
|
|
|
193
207
|
@bytes_to_be_read = 0
|
|
194
|
-
|
|
208
|
+
skip_alien_chunks
|
|
195
209
|
|
|
196
210
|
@bytes_to_be_read = read32
|
|
197
211
|
@curr_ticks = @ticks_so_far = 0
|
data/lib/midilib/sequence.rb
CHANGED
|
@@ -96,12 +96,12 @@ module MIDI
|
|
|
96
96
|
# "dotted_quarter_triplet" returns the length of a dotted quarter-note
|
|
97
97
|
# triplet and "32nd" returns 1/32.
|
|
98
98
|
def note_to_length(name)
|
|
99
|
-
name.strip
|
|
99
|
+
name = name.strip
|
|
100
100
|
name =~ /^(dotted)?(.*?)(triplet)?$/
|
|
101
101
|
dotted = Regexp.last_match(1)
|
|
102
102
|
note_name = Regexp.last_match(2)
|
|
103
103
|
triplet = Regexp.last_match(3)
|
|
104
|
-
note_name.strip
|
|
104
|
+
note_name = note_name.strip
|
|
105
105
|
mult = 1.0
|
|
106
106
|
mult = 1.5 if dotted
|
|
107
107
|
mult /= 3.0 if triplet
|
data/test/test_io.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'test/unit'
|
|
2
|
+
require 'stringio'
|
|
2
3
|
require_relative '../lib/midilib'
|
|
3
4
|
require_relative '../lib/midilib/consts'
|
|
4
5
|
require_relative 'event_equality'
|
|
@@ -58,6 +59,44 @@ class IOTester < Test::Unit::TestCase
|
|
|
58
59
|
File.delete(OUTPUT_FILE) if File.exist?(OUTPUT_FILE)
|
|
59
60
|
end
|
|
60
61
|
|
|
62
|
+
# The MIDI file spec says that readers should "expect alien chunks and
|
|
63
|
+
# treat them as if they weren't there".
|
|
64
|
+
def test_read_skips_alien_chunks
|
|
65
|
+
data = File.binread(SEQ_TEST_FILE)
|
|
66
|
+
alien = "XFIH" + [4].pack('N') + "\x01\x02\x03\x04".b
|
|
67
|
+
first_track_len = data[18, 4].unpack1('N')
|
|
68
|
+
second_track_start = 14 + 8 + first_track_len
|
|
69
|
+
with_aliens = data[0, 14] + alien + data[14...second_track_start] +
|
|
70
|
+
alien + data[second_track_start..]
|
|
71
|
+
|
|
72
|
+
seq0 = MIDI::Sequence.new
|
|
73
|
+
seq0.read(StringIO.new(data))
|
|
74
|
+
seq1 = MIDI::Sequence.new
|
|
75
|
+
seq1.read(StringIO.new(with_aliens))
|
|
76
|
+
compare_sequences(seq0, seq1)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_read_alien_chunk_with_negative_length
|
|
80
|
+
data = File.binread(SEQ_TEST_FILE)
|
|
81
|
+
alien = 'XFIH' + [0x80000004].pack('N') + "\x01\x02\x03\x04".b
|
|
82
|
+
io = StringIO.new(data[0, 14] + alien + data[14..])
|
|
83
|
+
|
|
84
|
+
e = assert_raise(RuntimeError) { MIDI::Sequence.new.read(io) }
|
|
85
|
+
assert_match(/invalid chunk length -4 for "XFIH"/, e.message)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_read_eof_in_alien_chunk
|
|
89
|
+
data = File.binread(SEQ_TEST_FILE)
|
|
90
|
+
alien = 'XFIH' + [4].pack('N') + "\x01\x02\x03\x04".b
|
|
91
|
+
|
|
92
|
+
# EOF in the type, the length and the data of the chunk
|
|
93
|
+
[2, 6, 10].each do |len|
|
|
94
|
+
io = StringIO.new(data[0, 14] + alien[0, len])
|
|
95
|
+
e = assert_raise(RuntimeError) { MIDI::Sequence.new.read(io) }
|
|
96
|
+
assert_match(/unexpected EOF while trying to skip alien chunk/, e.message)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
61
100
|
def test_read_callback
|
|
62
101
|
seq = MIDI::Sequence.new
|
|
63
102
|
names = []
|
|
@@ -261,9 +300,9 @@ class IOTester < Test::Unit::TestCase
|
|
|
261
300
|
assert_equal(out_track.events.length + 1, in_track.events.length)
|
|
262
301
|
out_track.events.each_with_index do |event, i|
|
|
263
302
|
in_event = in_track.events[i]
|
|
264
|
-
assert_equal(event.data_as_bytes,
|
|
265
|
-
assert_equal(event.delta_time,
|
|
266
|
-
assert_equal(event.time_from_start,
|
|
303
|
+
assert_equal(event.data_as_bytes, in_event.data_as_bytes)
|
|
304
|
+
assert_equal(event.delta_time, in_event.delta_time)
|
|
305
|
+
assert_equal(event.time_from_start, in_event.time_from_start)
|
|
267
306
|
end
|
|
268
307
|
|
|
269
308
|
# Last event is a end of track meta event
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: midilib
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.0.
|
|
4
|
+
version: 4.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jim Menard
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: |
|
|
14
13
|
midilib is a pure Ruby MIDI library useful for reading and
|
|
@@ -61,7 +60,6 @@ homepage: http://github.com/jimm/midilib
|
|
|
61
60
|
licenses:
|
|
62
61
|
- Ruby
|
|
63
62
|
metadata: {}
|
|
64
|
-
post_install_message:
|
|
65
63
|
rdoc_options:
|
|
66
64
|
- "--main"
|
|
67
65
|
- README.rdoc
|
|
@@ -79,8 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
79
77
|
version: '0'
|
|
80
78
|
requirements:
|
|
81
79
|
- none
|
|
82
|
-
rubygems_version:
|
|
83
|
-
signing_key:
|
|
80
|
+
rubygems_version: 4.0.17
|
|
84
81
|
specification_version: 4
|
|
85
82
|
summary: MIDI file and event manipulation library
|
|
86
83
|
test_files: []
|