midilib 4.0.0 → 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 +3 -148
- data/Rakefile +5 -14
- data/examples/from_scratch.rb +2 -7
- data/examples/measures_mbt.rb +1 -6
- data/examples/print_program_changes.rb +1 -3
- data/examples/reader2text.rb +2 -7
- data/examples/seq2text.rb +1 -6
- data/examples/split.rb +1 -6
- data/examples/strings.rb +2 -7
- data/examples/transpose.rb +3 -8
- data/lib/midilib/consts.rb +2 -0
- 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_event.rb +1 -6
- data/test/test_io.rb +155 -11
- data/test/test_mergesort.rb +1 -6
- data/test/test_midifile.rb +1 -6
- data/test/test_sequence.rb +1 -6
- data/test/test_track.rb +1 -6
- data/test/test_varlen.rb +1 -6
- 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
|
@@ -322,7 +322,7 @@ describes the format of MIDI commands.
|
|
|
322
322
|
= Administrivia
|
|
323
323
|
|
|
324
324
|
Author:: Jim Menard (mailto:jim@jimmenard.com)
|
|
325
|
-
Copyright:: Copyright (c) 2003-
|
|
325
|
+
Copyright:: Copyright (c) 2003-2023 Jim Menard
|
|
326
326
|
License:: Distributed under the same license as Ruby.
|
|
327
327
|
|
|
328
328
|
|
|
@@ -330,162 +330,17 @@ 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
|
|
342
342
|
for non-commercial purposes as long as the author is given credit.
|
|
343
343
|
|
|
344
|
-
|
|
345
|
-
== Recent Changes
|
|
346
|
-
|
|
347
|
-
=== Changes for 2.0.5:
|
|
348
|
-
|
|
349
|
-
Updated +install.rb+ to work with newer versions of Ruby by using
|
|
350
|
-
+fileutils+ instead of +ftools+.
|
|
351
|
-
|
|
352
|
-
=== Changes for 2.0.3:
|
|
353
|
-
|
|
354
|
-
New MIDI::Sequence.pulses_to_seconds method.
|
|
355
|
-
|
|
356
|
-
=== Changes for 2.0.2:
|
|
357
|
-
|
|
358
|
-
Stop monkeypatching Array in MIDI::Track.
|
|
359
|
-
|
|
360
|
-
=== Changes for 2.0.0:
|
|
361
|
-
|
|
362
|
-
MIDI::NoteOnEvent and MIDI::NoteOffEvent renamed to MIDI::NoteOn and
|
|
363
|
-
MIDI::NoteOff. The old names will still work for a while.
|
|
364
|
-
|
|
365
|
-
The MIDI::Event boolean methods like meta? and note? have been removed. Use
|
|
366
|
-
the event classes themselves (for example, MIDI::MetaEvent === my_event or
|
|
367
|
-
my_event.kind_of?(MIDI::MetaEvent)). Case statements that use classes work,
|
|
368
|
-
too:
|
|
369
|
-
|
|
370
|
-
case my_event
|
|
371
|
-
when MIDI::NoteEvent # superclass of note on, note off, poly press
|
|
372
|
-
do_this()
|
|
373
|
-
when MIDI::Controller
|
|
374
|
-
do_that()
|
|
375
|
-
end
|
|
376
|
-
|
|
377
|
-
Introduced Adam Murray's stable sorting code for
|
|
378
|
-
MIDI::Track#recalc_delta_from_times. See
|
|
379
|
-
http://wiki.github.com/adamjmurray/cosy/midilib-notes and
|
|
380
|
-
http://github.com/adamjmurray/cosy/blob/master/lib/cosy/helper/midi_file_renderer_helper.rb
|
|
381
|
-
for details.
|
|
382
|
-
|
|
383
|
-
Aliased MIDI::Track#sort to MIDI::Track#recalc_delta_from_times, since all
|
|
384
|
-
sort did was sort the events then call recalc_delta_from_times, and
|
|
385
|
-
recalc_delta_from_times sorts the events before doing anything else.
|
|
386
|
-
|
|
387
|
-
MIDI::Tempo#mpq_to_bpm now returns a float.
|
|
388
|
-
|
|
389
|
-
=== Changes for 1.2.0:
|
|
390
|
-
|
|
391
|
-
Use byte arrays instead of strings for passing around data. All tests now pass
|
|
392
|
-
for both Ruby 1.8.X and 1.9.X.
|
|
393
|
-
|
|
394
|
-
=== New code repository
|
|
395
|
-
|
|
396
|
-
The midilib code is now hosted at Github (http://github.com/jimm/midilib).
|
|
397
|
-
|
|
398
|
-
=== Changes for 1.1.4:
|
|
399
|
-
|
|
400
|
-
* Fixed a bug in KeySig.data_as_bytes. Thanks to Noah Thorp for finding this
|
|
401
|
-
and the bug fixed in 1.1.3.
|
|
402
|
-
|
|
403
|
-
=== Changes for 1.1.3:
|
|
404
|
-
|
|
405
|
-
* Fixed the way midilib detects the behavior of IO.getc.
|
|
406
|
-
|
|
407
|
-
=== Changes for 1.1.2:
|
|
408
|
-
|
|
409
|
-
* Define MIDI::IO::MIDIFile.getc differently for different Ruby versions,
|
|
410
|
-
instead of checking for String.bytes every time we read a byte.
|
|
411
|
-
|
|
412
|
-
=== Changes for 1.1.1:
|
|
413
|
-
|
|
414
|
-
* Make MIDI::IO::MIDIFile.getc do the right thing for both Ruby 1.8 and 1.9.
|
|
415
|
-
|
|
416
|
-
=== Changes for 1.1.0:
|
|
417
|
-
|
|
418
|
-
* Added test/test.mid to list of files to be included when packaging midifile
|
|
419
|
-
for distribution.
|
|
420
|
-
|
|
421
|
-
=== Changes for 1.0.0:
|
|
422
|
-
|
|
423
|
-
* Fixed the bug in Track#recalc_delta_from_times found by Christopher Rose.
|
|
424
|
-
|
|
425
|
-
=== Changes for 0.8.7:
|
|
426
|
-
|
|
427
|
-
* Fixed the misspelled POLY_PRESSURE constant, thanks to Mario Pehle.
|
|
428
|
-
|
|
429
|
-
=== Changes for 0.8.6:
|
|
430
|
-
|
|
431
|
-
* Added missing test/test.mid.
|
|
432
|
-
|
|
433
|
-
=== Changes for 0.8.5:
|
|
434
|
-
|
|
435
|
-
* Fixed bugs in MIDI::PitchBend reading and writing, thanks to Emanuel
|
|
436
|
-
Borsboom.
|
|
437
|
-
|
|
438
|
-
* Fixed a bug in MIDI::Track#quantize.
|
|
439
|
-
|
|
440
|
-
* The argument to MIDI::Track#quantize has changed: it is now either a note
|
|
441
|
-
name ("sixteenth", "32nd", "8th triplet") or a length (1 = quarter, 0.25 =
|
|
442
|
-
sixteenth). This is a drastic change that will break all previous calls to
|
|
443
|
-
quantize. However, since that method was broken already, I don't feel it's
|
|
444
|
-
a burden to anybody to change the arguments.
|
|
445
|
-
|
|
446
|
-
=== Changes for 0.8.4:
|
|
447
|
-
|
|
448
|
-
* Realtime status bytes now set @is_realtime to true and return true when
|
|
449
|
-
realtime? is called.
|
|
450
|
-
|
|
451
|
-
* All system common events now set @is_system to true and return true when
|
|
452
|
-
system? is called, not just system exclusive events.
|
|
453
|
-
|
|
454
|
-
* Added examples/from_scratch.rb, which shows how to create a sequence
|
|
455
|
-
manually.
|
|
456
|
-
|
|
457
|
-
* New MIDI::Sequence methods that turn note length names like "32nd", "dotted
|
|
458
|
-
quarter", and "16th triplet" into delta times. See the docs below and
|
|
459
|
-
MIDI::Sequence::length_to_delta, MIDI::Sequence::note_to_length, and
|
|
460
|
-
MIDI::Sequence::note_to_delta.
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
=== Changes for 0.8.3:
|
|
464
|
-
|
|
465
|
-
* Added MIDI::NoteEvent.note_to_s, which returns note name as a string like
|
|
466
|
-
"C4" or "F#6".
|
|
467
|
-
|
|
468
|
-
* Added new boolean attributes to MIDI::Event: @print_decimal_numbers and
|
|
469
|
-
@print_note_names. These are used by all Event to_s methods. See
|
|
470
|
-
examples/seq2text.rb for an example.
|
|
471
|
-
|
|
472
|
-
=== Changes for 0.8.2:
|
|
473
|
-
|
|
474
|
-
* Changed MIDI::MetaEvent.type to MIDI::MetaEvent.event_type to avoid
|
|
475
|
-
runtime complaints about Object#type calls.
|
|
476
|
-
* Added 'b' binary flag to file open modes for Windows.
|
|
477
|
-
* Fixed $LOAD_PATH in example files.
|
|
478
|
-
* Fixed read and write block arguments.
|
|
479
|
-
* Fixed other example script bugs.
|
|
480
|
-
|
|
481
|
-
=== Changes for 0.8.1:
|
|
482
|
-
|
|
483
|
-
* Fixed track sorting.
|
|
484
|
-
* Fixed track's recalc_delta_from_times method.
|
|
485
|
-
* Fixed event quantization.
|
|
486
|
-
* More tests and documentation.
|
|
487
|
-
|
|
488
|
-
|
|
489
344
|
== Warranty
|
|
490
345
|
|
|
491
346
|
This software is provided "as is" and without any express or implied
|
data/Rakefile
CHANGED
|
@@ -42,20 +42,11 @@ spec = Gem::Specification.new do |s|
|
|
|
42
42
|
EOF
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
pkg.need_tar = true
|
|
51
|
-
end
|
|
52
|
-
else
|
|
53
|
-
# Creates a :package task (also named :gem). Also useful are
|
|
54
|
-
# :clobber_package and :repackage.
|
|
55
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
|
56
|
-
pkg.need_zip = true
|
|
57
|
-
pkg.need_tar = true
|
|
58
|
-
end
|
|
45
|
+
# Creates a :package task (also named :gem). Also useful are
|
|
46
|
+
# :clobber_package and :repackage.
|
|
47
|
+
Gem::PackageTask.new(spec) do |pkg|
|
|
48
|
+
pkg.need_zip = true
|
|
49
|
+
pkg.need_tar = true
|
|
59
50
|
end
|
|
60
51
|
|
|
61
52
|
# creates an "rdoc" task
|
data/examples/from_scratch.rb
CHANGED
|
@@ -5,13 +5,8 @@
|
|
|
5
5
|
# This script shows you how to create a new sequence from scratch and save it
|
|
6
6
|
# to a MIDI file. It creates a file called 'from_scratch.mid'.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# installed version out there somewhere.
|
|
11
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
12
|
-
|
|
13
|
-
require 'midilib/sequence'
|
|
14
|
-
require 'midilib/consts'
|
|
8
|
+
require_relative '../lib/midilib/sequence'
|
|
9
|
+
require_relative '../lib/midilib/consts'
|
|
15
10
|
include MIDI
|
|
16
11
|
|
|
17
12
|
seq = Sequence.new
|
data/examples/measures_mbt.rb
CHANGED
|
@@ -6,12 +6,7 @@
|
|
|
6
6
|
# in a "sequencer-style" manner:
|
|
7
7
|
# Measure:Beat:Tick Channel: Note-name
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
# This forces us to use the local copy, even if there is a previously
|
|
11
|
-
# installed version out there somewhere.
|
|
12
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
13
|
-
|
|
14
|
-
require 'midilib/sequence'
|
|
9
|
+
require_relative '../lib/midilib/sequence'
|
|
15
10
|
|
|
16
11
|
seq = MIDI::Sequence.new
|
|
17
12
|
File.open(ARGV[0], 'rb') { |file| seq.read(file) }
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# Shows use of print_decimal_numbers and print_channel_numbers_from_one.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require 'midilib/sequence'
|
|
5
|
+
require_relative '../lib/midilib/sequence'
|
|
8
6
|
|
|
9
7
|
DEFAULT_MIDI_TEST_FILE = 'NoFences.mid'
|
|
10
8
|
|
data/examples/reader2text.rb
CHANGED
|
@@ -9,13 +9,8 @@
|
|
|
9
9
|
# For a simpler way to do the same thing, see seq2text.rb.
|
|
10
10
|
#
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# installed version out there somewhere.
|
|
15
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
16
|
-
|
|
17
|
-
require 'midilib/sequence'
|
|
18
|
-
require 'midilib/io/midifile'
|
|
12
|
+
require_relative '../lib/midilib/sequence'
|
|
13
|
+
require_relative '../lib/midilib/io/midifile'
|
|
19
14
|
|
|
20
15
|
DEFAULT_MIDI_TEST_FILE = 'NoFences.mid'
|
|
21
16
|
|
data/examples/seq2text.rb
CHANGED
|
@@ -9,12 +9,7 @@
|
|
|
9
9
|
# reader2tex.rb.
|
|
10
10
|
#
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
# This forces us to use the local copy, even if there is a previously
|
|
14
|
-
# installed version out there somewhere.
|
|
15
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
16
|
-
|
|
17
|
-
require 'midilib/sequence'
|
|
12
|
+
require_relative '../lib/midilib/sequence'
|
|
18
13
|
|
|
19
14
|
DEFAULT_MIDI_TEST_FILE = 'NoFences.mid'
|
|
20
15
|
|
data/examples/split.rb
CHANGED
|
@@ -9,12 +9,7 @@
|
|
|
9
9
|
# If -x is specified, the 0th temp track is not included in each file.
|
|
10
10
|
# Instead, it is output in a separate file named 'tempo_track.mid'.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
# This forces us to use the local copy, even if there is a previously
|
|
14
|
-
# installed version out there somewhere.
|
|
15
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
16
|
-
|
|
17
|
-
require 'midilib/sequence'
|
|
12
|
+
require_relative '../lib/midilib/sequence'
|
|
18
13
|
|
|
19
14
|
DEFAULT_MIDI_TEST_FILE = 'NoFences.mid'
|
|
20
15
|
|
data/examples/strings.rb
CHANGED
|
@@ -5,13 +5,8 @@
|
|
|
5
5
|
# Prints all strings (track names, etc.) found in the MIDI file.
|
|
6
6
|
#
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# installed version out there somewhere.
|
|
11
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
12
|
-
|
|
13
|
-
require 'midilib/sequence'
|
|
14
|
-
require 'midilib/consts'
|
|
8
|
+
require_relative '../lib/midilib/sequence'
|
|
9
|
+
require_relative '../lib/midilib/consts'
|
|
15
10
|
|
|
16
11
|
DEFAULT_MIDI_TEST_FILE = 'NoFences.mid'
|
|
17
12
|
|
data/examples/transpose.rb
CHANGED
|
@@ -7,15 +7,10 @@
|
|
|
7
7
|
# -t half_steps default = 12 (one octave up)
|
|
8
8
|
#
|
|
9
9
|
|
|
10
|
-
# Start looking for MIDI module classes in the directory above this one.
|
|
11
|
-
# This forces us to use the local copy, even if there is a previously
|
|
12
|
-
# installed version out there somewhere.
|
|
13
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
14
|
-
|
|
15
10
|
require 'getoptlong'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
require_relative '../lib/midilib/sequence'
|
|
12
|
+
require_relative '../lib/midilib/io/seqreader'
|
|
13
|
+
require_relative '../lib/midilib/io/seqwriter'
|
|
19
14
|
|
|
20
15
|
def usage
|
|
21
16
|
$stderr.print <<~EOF
|
data/lib/midilib/consts.rb
CHANGED
|
@@ -77,6 +77,7 @@ module MIDI
|
|
|
77
77
|
# = 0 - 31 = continuous, MSB
|
|
78
78
|
# = 32 - 63 = continuous, LSB
|
|
79
79
|
# = 64 - 97 = switches
|
|
80
|
+
CC_BANK_MSB = 0
|
|
80
81
|
CC_MOD_WHEEL = 1
|
|
81
82
|
CC_BREATH_CONTROLLER = 2
|
|
82
83
|
CC_FOOT_CONTROLLER = 4
|
|
@@ -92,6 +93,7 @@ module MIDI
|
|
|
92
93
|
CC_GEN_PURPOSE_4 = 19
|
|
93
94
|
|
|
94
95
|
# [32 - 63] are LSB for [0 - 31]
|
|
96
|
+
CC_BANK_LSB = 32
|
|
95
97
|
CC_DATA_ENTRY_LSB = 38
|
|
96
98
|
|
|
97
99
|
#--
|
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_event.rb
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
# Start looking for MIDI classes in the directory above this one.
|
|
2
|
-
# This forces us to use the local copy of MIDI, even if there is
|
|
3
|
-
# a previously installed version out there somewhere.
|
|
4
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
5
|
-
|
|
6
1
|
require 'test/unit'
|
|
7
|
-
|
|
2
|
+
require_relative '../lib/midilib'
|
|
8
3
|
|
|
9
4
|
class EventTester < Test::Unit::TestCase
|
|
10
5
|
def test_note_on
|
data/test/test_io.rb
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
# Start looking for MIDI classes in the directory above this one.
|
|
2
|
-
# This forces us to use the local copy of MIDI, even if there is
|
|
3
|
-
# a previously installed version out there somewhere.
|
|
4
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
5
|
-
# Add current directory so we can find event_equality
|
|
6
|
-
$LOAD_PATH[0, 0] = File.dirname(__FILE__)
|
|
7
|
-
|
|
8
1
|
require 'test/unit'
|
|
9
|
-
require '
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
require 'stringio'
|
|
3
|
+
require_relative '../lib/midilib'
|
|
4
|
+
require_relative '../lib/midilib/consts'
|
|
5
|
+
require_relative 'event_equality'
|
|
12
6
|
|
|
13
7
|
class IOTester < Test::Unit::TestCase
|
|
14
8
|
SEQ_TEST_FILE = File.join(File.dirname(__FILE__), 'test.mid')
|
|
@@ -65,6 +59,44 @@ class IOTester < Test::Unit::TestCase
|
|
|
65
59
|
File.delete(OUTPUT_FILE) if File.exist?(OUTPUT_FILE)
|
|
66
60
|
end
|
|
67
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
|
+
|
|
68
100
|
def test_read_callback
|
|
69
101
|
seq = MIDI::Sequence.new
|
|
70
102
|
names = []
|
|
@@ -146,7 +178,7 @@ class IOTester < Test::Unit::TestCase
|
|
|
146
178
|
out_track.events << MIDI::NoteOff.new(0, 65, 127, 230)
|
|
147
179
|
end
|
|
148
180
|
|
|
149
|
-
File.open(
|
|
181
|
+
File.open(TEMPFILE, 'wb') { |file| out_seq.write(file) }
|
|
150
182
|
|
|
151
183
|
# Although start times are not written out to the MIDI file, we
|
|
152
184
|
# calculate them because we are about to compare the out events with the
|
|
@@ -166,4 +198,116 @@ class IOTester < Test::Unit::TestCase
|
|
|
166
198
|
assert(e.is_a?(MIDI::MetaEvent))
|
|
167
199
|
assert(e.meta_type == MIDI::META_TRACK_END)
|
|
168
200
|
end
|
|
201
|
+
|
|
202
|
+
def test_preserve_deltas_multiple_note_offs
|
|
203
|
+
out_seq = MIDI::Sequence.new
|
|
204
|
+
out_track = MIDI::Track.new(out_seq)
|
|
205
|
+
out_seq.tracks << out_track
|
|
206
|
+
out_track.events << MIDI::Tempo.new(MIDI::Tempo.bpm_to_mpq(120))
|
|
207
|
+
|
|
208
|
+
out_track = MIDI::Track.new(out_seq)
|
|
209
|
+
out_seq.tracks << out_track
|
|
210
|
+
out_track.events << MIDI::NoteOn.new(0, 65, 127, 100)
|
|
211
|
+
out_track.events << MIDI::NoteOff.new(0, 65, 127, 100)
|
|
212
|
+
out_track.events << MIDI::NoteOff.new(0, 65, 127, 100)
|
|
213
|
+
|
|
214
|
+
File.open(TEMPFILE, 'wb') { |file| out_seq.write(file) }
|
|
215
|
+
|
|
216
|
+
in_seq = MIDI::Sequence.new
|
|
217
|
+
File.open(TEMPFILE, 'rb') { |file| in_seq.read(file) }
|
|
218
|
+
in_track = in_seq.tracks[1]
|
|
219
|
+
|
|
220
|
+
out_track.recalc_times # so that start times are correct
|
|
221
|
+
|
|
222
|
+
assert_equal(out_track.events.length + 1, in_track.events.length)
|
|
223
|
+
out_track.events.each_with_index do |event, i|
|
|
224
|
+
assert_equal(event.data_as_bytes, in_track.events[i].data_as_bytes)
|
|
225
|
+
assert_equal(event.delta_time, in_track.events[i].delta_time)
|
|
226
|
+
assert_equal(event.time_from_start, in_track.events[i].time_from_start)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
# Last event is a end of track meta event
|
|
230
|
+
e = in_track.events.last
|
|
231
|
+
assert(e.is_a?(MIDI::MetaEvent))
|
|
232
|
+
assert(e.meta_type == MIDI::META_TRACK_END)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def test_preserve_deltas_multiple_note_on_zero_velocity
|
|
236
|
+
out_seq = MIDI::Sequence.new
|
|
237
|
+
out_track = MIDI::Track.new(out_seq)
|
|
238
|
+
out_seq.tracks << out_track
|
|
239
|
+
out_track.events << MIDI::Tempo.new(MIDI::Tempo.bpm_to_mpq(120))
|
|
240
|
+
|
|
241
|
+
out_track = MIDI::Track.new(out_seq)
|
|
242
|
+
out_seq.tracks << out_track
|
|
243
|
+
out_track.events << MIDI::NoteOn.new(0, 65, 127, 100)
|
|
244
|
+
out_track.events << MIDI::NoteOn.new(0, 65, 0, 100)
|
|
245
|
+
out_track.events << MIDI::NoteOn.new(0, 65, 0, 100)
|
|
246
|
+
|
|
247
|
+
File.open(TEMPFILE, 'wb') { |file| out_seq.write(file) }
|
|
248
|
+
|
|
249
|
+
in_seq = MIDI::Sequence.new
|
|
250
|
+
File.open(TEMPFILE, 'rb') { |file| in_seq.read(file) }
|
|
251
|
+
in_track = in_seq.tracks[1]
|
|
252
|
+
|
|
253
|
+
# Turn the note ons with zero velocity into note offs, and recalc start
|
|
254
|
+
# times so that time_from_start is correct.
|
|
255
|
+
[1, 2].each do |i|
|
|
256
|
+
out_track.events[i] = MIDI::NoteOff.new(0, 65, 64, 100)
|
|
257
|
+
end
|
|
258
|
+
out_track.recalc_times # so that start times are correct
|
|
259
|
+
|
|
260
|
+
assert_equal(out_track.events.length + 1, in_track.events.length)
|
|
261
|
+
out_track.events.zip(in_track.events).each do |out_event, in_event|
|
|
262
|
+
assert_equal(out_event.data_as_bytes, in_event.data_as_bytes)
|
|
263
|
+
assert_equal(out_event.delta_time, in_event.delta_time)
|
|
264
|
+
assert_equal(out_event.time_from_start, in_event.time_from_start)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# Last event is a end of track meta event
|
|
268
|
+
e = in_track.events.last
|
|
269
|
+
assert(e.is_a?(MIDI::MetaEvent))
|
|
270
|
+
assert(e.meta_type == MIDI::META_TRACK_END)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# Regression test. Running status output when writing a track's events was
|
|
274
|
+
# broken.
|
|
275
|
+
def test_running_status_output
|
|
276
|
+
out_seq = MIDI::Sequence.new
|
|
277
|
+
out_track = MIDI::Track.new(out_seq)
|
|
278
|
+
out_seq.tracks << out_track
|
|
279
|
+
out_track.events << MIDI::Tempo.new(MIDI::Tempo.bpm_to_mpq(120))
|
|
280
|
+
|
|
281
|
+
out_track = MIDI::Track.new(out_seq)
|
|
282
|
+
out_seq.tracks << out_track
|
|
283
|
+
out_track.events << MIDI::NoteOn.new(0, 65, 127, 100)
|
|
284
|
+
out_track.events << MIDI::NoteOn.new(0, 65, 0, 100)
|
|
285
|
+
out_track.events << MIDI::NoteOn.new(0, 65, 0, 100)
|
|
286
|
+
|
|
287
|
+
File.open(TEMPFILE, 'wb') { |file| out_seq.write(file) }
|
|
288
|
+
|
|
289
|
+
in_seq = MIDI::Sequence.new
|
|
290
|
+
File.open(TEMPFILE, 'rb') { |file| in_seq.read(file) }
|
|
291
|
+
in_track = in_seq.tracks[1]
|
|
292
|
+
|
|
293
|
+
# Turn the note ons with zero velocity into note offs, and recalc start
|
|
294
|
+
# times so that time_from_start is correct.
|
|
295
|
+
[1, 2].each do |i|
|
|
296
|
+
out_track.events[i] = MIDI::NoteOff.new(0, 65, 64, 100)
|
|
297
|
+
end
|
|
298
|
+
out_track.recalc_times # so that start times are correct
|
|
299
|
+
|
|
300
|
+
assert_equal(out_track.events.length + 1, in_track.events.length)
|
|
301
|
+
out_track.events.each_with_index do |event, i|
|
|
302
|
+
in_event = in_track.events[i]
|
|
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)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# Last event is a end of track meta event
|
|
309
|
+
e = in_track.events.last
|
|
310
|
+
assert(e.is_a?(MIDI::MetaEvent))
|
|
311
|
+
assert(e.meta_type == MIDI::META_TRACK_END)
|
|
312
|
+
end
|
|
169
313
|
end
|
data/test/test_mergesort.rb
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
# Start looking for MIDI classes in the directory above this one.
|
|
2
|
-
# This forces us to use the local copy of MIDI, even if there is
|
|
3
|
-
# a previously installed version out there somewhere.
|
|
4
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
5
|
-
|
|
6
1
|
require 'test/unit'
|
|
7
|
-
|
|
2
|
+
require_relative '../lib/midilib/mergesort'
|
|
8
3
|
|
|
9
4
|
class MergesortTester < Test::Unit::TestCase
|
|
10
5
|
def test_mergesort
|
data/test/test_midifile.rb
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
# Start looking for MIDI classes in the directory above this one.
|
|
2
|
-
# This forces us to use the local copy of MIDI, even if there is
|
|
3
|
-
# a previously installed version out there somewhere.
|
|
4
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
5
|
-
|
|
6
1
|
require 'test/unit'
|
|
7
2
|
require 'stringio'
|
|
8
|
-
|
|
3
|
+
require_relative '../lib/midilib'
|
|
9
4
|
|
|
10
5
|
class MIDI::IO::MIDIFile
|
|
11
6
|
attr_writer :io
|
data/test/test_sequence.rb
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
# Start looking for MIDI classes in the directory above this one.
|
|
2
|
-
# This forces us to use the local copy of MIDI, even if there is
|
|
3
|
-
# a previously installed version out there somewhere.
|
|
4
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
5
|
-
|
|
6
1
|
require 'test/unit'
|
|
7
|
-
|
|
2
|
+
require_relative '../lib/midilib'
|
|
8
3
|
|
|
9
4
|
class SequenceTester < Test::Unit::TestCase
|
|
10
5
|
def setup
|
data/test/test_track.rb
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
# Start looking for MIDI classes in the directory above this one.
|
|
2
|
-
# This forces us to use the local copy of MIDI, even if there is
|
|
3
|
-
# a previously installed version out there somewhere.
|
|
4
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
5
|
-
|
|
6
1
|
require 'test/unit'
|
|
7
|
-
|
|
2
|
+
require_relative '../lib/midilib'
|
|
8
3
|
|
|
9
4
|
class TrackTester < Test::Unit::TestCase
|
|
10
5
|
def setup
|
data/test/test_varlen.rb
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
# Start looking for MIDI classes in the directory above this one.
|
|
2
|
-
# This forces us to use the local copy of MIDI, even if there is
|
|
3
|
-
# a previously installed version out there somewhere.
|
|
4
|
-
$LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
5
|
-
|
|
6
1
|
require 'test/unit'
|
|
7
|
-
|
|
2
|
+
require_relative '../lib/midilib'
|
|
8
3
|
|
|
9
4
|
class VarLenTester < Test::Unit::TestCase
|
|
10
5
|
VAR_LEN_TEST_DATA = {
|
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: []
|