midilib 2.0.2 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7b4ef36d4f1d38a6f2c2bbf00fc34e7400822ab5f3f05242296bb383bf7cd35
4
+ data.tar.gz: e814f94bccbf648fb8ef7035551996673f6991114000ca7c7199c26cdee0d913
5
+ SHA512:
6
+ metadata.gz: f9942744aebb170da22efff3c845f9b976f473c6b1584f00abf7da4b680c730eeb597a0aff8fc45b32c965453283a6cb007172183284d9f6116ff89c31dfb57d
7
+ data.tar.gz: 588a781e7776ca3adf309ba1a1eb6b4668c1767927e832c05963c31c85bacd0aee11b68df6e5d930dae7911b5fca663c48806c90ff8e8f53ecd139aa3753db50
data/ChangeLog CHANGED
@@ -1,4 +1,5 @@
1
- For any further change descriptions, see the Git logs.
1
+ This change log is no longer maintaned. For further change descriptions,
2
+ see the Git logs.
2
3
 
3
4
  2007-12-11 Jim Menard <jim@iamplify.com>
4
5
 
data/Credits CHANGED
@@ -29,7 +29,7 @@ Jari Williamsson <jari.williamsson@mailbox.swipnet.se>
29
29
  Noah Thorp
30
30
 
31
31
  Found a bug in the code intended to make midilib work under Ruby 1.9.
32
- Found another bug in KeySing.data_as_bytes.
32
+ Found another bug in KeySig.data_as_bytes.
33
33
 
34
34
  Zach Chadwick (zachad on Github)
35
35
 
@@ -48,4 +48,46 @@ Shai Rosenfeld (shaiguitar on Github)
48
48
  J (dark-panda on Github)
49
49
 
50
50
  Instead of monkeypatching ::Array, put sorting methods into new
51
- MIDI::Array subclass to avoid clashes with Rails app.
51
+ MIDI::Array subclass to avoid clashes with Rails apps.
52
+
53
+ Lucas lfzawacki (lfzawacki on Github)
54
+
55
+ Found a bug in the MIDI::IO::SeqReader class: the pitch_bend method's
56
+ msb and lsb parameters were reversed.
57
+
58
+ Parki <parki06780678@gmail.com>
59
+
60
+ Reported failure of install.rb with newer versions of Ruby due to use of
61
+ old 'ftools' standard library component.
62
+
63
+ Adam Murray (adamjmurray on Github)
64
+
65
+ Submitted a patch that avoids writing empty data when writing tracks.
66
+
67
+ @dylee on Github
68
+
69
+ Submitted a patch that improves key signature event code and to_s.
70
+
71
+ @willm on Github
72
+
73
+ Suggested that Sequence.length_to_delta round the result instead of
74
+ truncating it.
75
+
76
+ @kaorukobo on Github
77
+
78
+ Fixed a bug where the delta offset of META_SEQ_NAME and META_COPYRIGHT
79
+ events were incorrectly always set to 0. The delta time may be any
80
+ value (although META_COPYRIGHT should normally be 0).
81
+
82
+ @rhelsing on Github
83
+
84
+ Added the ability to save MIDI format 0 files.
85
+
86
+ Miika Alonen (@amiika on Github)
87
+
88
+ Updated midilib for Ruby 2.7 and 3.0 by using blocks instead of Proc
89
+ objects and changing require to require_relative where appropriate.
90
+
91
+ @johnkolen on Github
92
+
93
+ Pointed out incorrect values for CC_GEN_PURPOSE_{5,6,7,8}.
data/README.rdoc CHANGED
@@ -1,16 +1,14 @@
1
1
  = midilib
2
2
 
3
3
  midilib is a pure Ruby MIDI library useful for reading and writing standard
4
- MIDI files and manipulating MIDI event data. Classes include MIDI::Sequence,
5
- MIDI::Track, MIDI::Event, and MIDI::IO::MIDIFile and its subclasses
6
- MIDI::IO::SeqReader and MIDI::IO::SeqWriter.
4
+ MIDI files and manipulating MIDI event data.
7
5
 
8
6
  The GitHub project page and Web site of midilib is
9
7
  http://github.com/jimm/midilib and the RubyGems.org page is
10
8
  http://rubygems.org/gems/midilib, where you can also find all the RDoc
11
9
  documentation.
12
10
 
13
- midilib is compatible with both Ruby 1.8.x and 1.9.x.
11
+ midilib is compatible with Ruby 2.6 and higher.
14
12
 
15
13
 
16
14
  == Dependencies
@@ -31,11 +29,10 @@ which requires Rake (http://rake.rubyforge.org).
31
29
  To install midilib as a gem, type
32
30
 
33
31
  % gem install midilib
34
- or
32
+ or, if you already have a previous version, use
35
33
  % gem update midilib
36
34
 
37
- if you already have a previous version. You may need root privileges to
38
- install or update the gem.
35
+ You may need root privileges to install or update the gem.
39
36
 
40
37
  === Manual Installation
41
38
 
@@ -58,10 +55,9 @@ runs all of the tests in the test directory.
58
55
 
59
56
  == Overview
60
57
 
61
- MIDI file IO only understands MIDI file format 1, where a sequence is made up
62
- of multiple tracks. It doesn't yet understand format 0 (a single track
63
- containing all events) or format 2 (a collection of format 0 files in one
64
- file).
58
+ midilib can read and write MIDI file formats 0 (one single track) or 1
59
+ multiple tracks. By default, it writes format 1 which is the most common
60
+ format. MIDI file format 2 is not yet supported.
65
61
 
66
62
  === MIDI::Sequence
67
63
 
@@ -293,10 +289,10 @@ information. Though the first edition book is available online, I encourage
293
289
  you to purchase a copy of the latest edition.
294
290
 
295
291
  A description of the MIDI file format can be found in a few places such as
296
- http://www.borg.com/~jglatt/tech/midifile.htm.
292
+ https://www.csie.ntu.edu.tw/~r92092/ref/midi/.
297
293
 
298
- The MIDI message reference at http://www.io.com/~jimm/midi_ref.html describes
299
- the format of MIDI commands.
294
+ The MIDI message reference at http://www.jimmenard.com/midi_ref.html
295
+ describes the format of MIDI commands.
300
296
 
301
297
 
302
298
  = To Do
@@ -317,7 +313,7 @@ the format of MIDI commands.
317
313
  = Administrivia
318
314
 
319
315
  Author:: Jim Menard (mailto:jim@jimmenard.com)
320
- Copyright:: Copyright (c) 2003-2012 Jim Menard
316
+ Copyright:: Copyright (c) 2003-2013 Jim Menard
321
317
  License:: Distributed under the same license as Ruby.
322
318
 
323
319
 
@@ -330,16 +326,29 @@ http://www.ruby-lang.org/en/LICENSE.txt.
330
326
  midilib may be freely copied in its entirety providing this notice, all
331
327
  source code, all documentation, and all other files are included.
332
328
 
333
- midilib is Copyright (c) 2003-2012 by Jim Menard.
329
+ midilib is Copyright (c) 2003-2013 by Jim Menard.
334
330
 
335
331
  The song "No Fences" contained in the MIDI file examples/NoFences.mid is
336
332
  Copyright (c) 1992 by Jim Menard (jim@jimmenard.com). It may be freely used
337
333
  for non-commercial purposes as long as the author is given credit.
338
334
 
339
335
 
340
- === Recent Changes
336
+ == Recent Changes
341
337
 
342
- ==== Changes for 2.0.0:
338
+ === Changes for 2.0.5:
339
+
340
+ Updated +install.rb+ to work with newer versions of Ruby by using
341
+ +fileutils+ instead of +ftools+.
342
+
343
+ === Changes for 2.0.3:
344
+
345
+ New MIDI::Sequence.pulses_to_seconds method.
346
+
347
+ === Changes for 2.0.2:
348
+
349
+ Stop monkeypatching Array in MIDI::Track.
350
+
351
+ === Changes for 2.0.0:
343
352
 
344
353
  MIDI::NoteOnEvent and MIDI::NoteOffEvent renamed to MIDI::NoteOn and
345
354
  MIDI::NoteOff. The old names will still work for a while.
@@ -368,51 +377,51 @@ recalc_delta_from_times sorts the events before doing anything else.
368
377
 
369
378
  MIDI::Tempo#mpq_to_bpm now returns a float.
370
379
 
371
- ==== Changes for 1.2.0:
380
+ === Changes for 1.2.0:
372
381
 
373
382
  Use byte arrays instead of strings for passing around data. All tests now pass
374
383
  for both Ruby 1.8.X and 1.9.X.
375
384
 
376
- ==== New code repository
385
+ === New code repository
377
386
 
378
387
  The midilib code is now hosted at Github (http://github.com/jimm/midilib).
379
388
 
380
- ==== Changes for 1.1.4:
389
+ === Changes for 1.1.4:
381
390
 
382
391
  * Fixed a bug in KeySig.data_as_bytes. Thanks to Noah Thorp for finding this
383
392
  and the bug fixed in 1.1.3.
384
393
 
385
- ==== Changes for 1.1.3:
394
+ === Changes for 1.1.3:
386
395
 
387
396
  * Fixed the way midilib detects the behavior of IO.getc.
388
397
 
389
- ==== Changes for 1.1.2:
398
+ === Changes for 1.1.2:
390
399
 
391
400
  * Define MIDI::IO::MIDIFile.getc differently for different Ruby versions,
392
401
  instead of checking for String.bytes every time we read a byte.
393
402
 
394
- ==== Changes for 1.1.1:
403
+ === Changes for 1.1.1:
395
404
 
396
405
  * Make MIDI::IO::MIDIFile.getc do the right thing for both Ruby 1.8 and 1.9.
397
406
 
398
- ==== Changes for 1.1.0:
407
+ === Changes for 1.1.0:
399
408
 
400
409
  * Added test/test.mid to list of files to be included when packaging midifile
401
410
  for distribution.
402
411
 
403
- ==== Changes for 1.0.0:
412
+ === Changes for 1.0.0:
404
413
 
405
414
  * Fixed the bug in Track#recalc_delta_from_times found by Christopher Rose.
406
415
 
407
- ==== Changes for 0.8.7:
416
+ === Changes for 0.8.7:
408
417
 
409
418
  * Fixed the misspelled POLY_PRESSURE constant, thanks to Mario Pehle.
410
419
 
411
- ==== Changes for 0.8.6:
420
+ === Changes for 0.8.6:
412
421
 
413
422
  * Added missing test/test.mid.
414
423
 
415
- ==== Changes for 0.8.5:
424
+ === Changes for 0.8.5:
416
425
 
417
426
  * Fixed bugs in MIDI::PitchBend reading and writing, thanks to Emanuel
418
427
  Borsboom.
@@ -425,7 +434,7 @@ The midilib code is now hosted at Github (http://github.com/jimm/midilib).
425
434
  quantize. However, since that method was broken already, I don't feel it's
426
435
  a burden to anybody to change the arguments.
427
436
 
428
- ==== Changes for 0.8.4:
437
+ === Changes for 0.8.4:
429
438
 
430
439
  * Realtime status bytes now set @is_realtime to true and return true when
431
440
  realtime? is called.
@@ -442,7 +451,7 @@ The midilib code is now hosted at Github (http://github.com/jimm/midilib).
442
451
  MIDI::Sequence::note_to_delta.
443
452
 
444
453
 
445
- ==== Changes for 0.8.3:
454
+ === Changes for 0.8.3:
446
455
 
447
456
  * Added MIDI::NoteEvent.note_to_s, which returns note name as a string like
448
457
  "C4" or "F#6".
@@ -451,7 +460,7 @@ The midilib code is now hosted at Github (http://github.com/jimm/midilib).
451
460
  @print_note_names. These are used by all Event to_s methods. See
452
461
  examples/seq2text.rb for an example.
453
462
 
454
- ==== Changes for 0.8.2:
463
+ === Changes for 0.8.2:
455
464
 
456
465
  * Changed MIDI::MetaEvent.type to MIDI::MetaEvent.event_type to avoid
457
466
  runtime complaints about Object#type calls.
@@ -460,7 +469,7 @@ The midilib code is now hosted at Github (http://github.com/jimm/midilib).
460
469
  * Fixed read and write block arguments.
461
470
  * Fixed other example script bugs.
462
471
 
463
- ==== Changes for 0.8.1:
472
+ === Changes for 0.8.1:
464
473
 
465
474
  * Fixed track sorting.
466
475
  * Fixed track's recalc_delta_from_times method.
data/Rakefile CHANGED
@@ -1,52 +1,46 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- if RUBY_VERSION >= '1.9'
4
- require 'rdoc/task'
5
- require 'rubygems/package_task'
6
- require 'rake/testtask'
7
- else
8
- require 'rake/rdoctask'
9
- require 'rake/gempackagetask'
10
- require 'rake/runtest'
11
- end
3
+ require 'rdoc/task'
4
+ require 'rubygems/package_task'
5
+ require 'rake/testtask'
12
6
 
13
7
  PROJECT_NAME = 'midilib'
14
8
  RDOC_DIR = 'html'
15
9
 
16
10
  PKG_FILES = FileList[ 'ChangeLog', 'Credits', 'Rakefile',
17
- 'README.rdoc', 'TODO.rdoc',
18
- 'examples/**/*',
19
- 'html/**/*',
20
- 'install.rb',
21
- 'lib/**/*.rb',
22
- 'test/**/*']
11
+ 'README.rdoc', 'TODO.rdoc',
12
+ 'examples/**/*',
13
+ 'html/**/*',
14
+ 'install.rb',
15
+ 'lib/**/*.rb',
16
+ 'test/**/*']
23
17
 
24
- task :default => [:package]
18
+ task default: [:package]
25
19
 
26
20
  spec = Gem::Specification.new do |s|
27
- s.platform = Gem::Platform::RUBY
28
- s.name = PROJECT_NAME
29
- s.version = `ruby -Ilib -e 'require "midilib/info"; puts MIDI::Version'`.strip
30
- s.requirements << 'none'
21
+ s.platform = Gem::Platform::RUBY
22
+ s.name = PROJECT_NAME
23
+ s.version = `ruby -Ilib -e 'require "midilib/info"; puts MIDI::Version'`.strip
24
+ s.requirements << 'none'
31
25
 
32
- s.require_path = 'lib'
26
+ s.require_path = 'lib'
33
27
 
34
- s.files = PKG_FILES.to_a
28
+ s.files = PKG_FILES.to_a
35
29
 
36
- s.has_rdoc = true
37
- s.rdoc_options << '--main' << 'README.rdoc'
38
- s.extra_rdoc_files = ['README.rdoc', 'TODO.rdoc']
30
+ s.rdoc_options << '--main' << 'README.rdoc'
31
+ s.extra_rdoc_files = ['README.rdoc', 'TODO.rdoc']
39
32
 
40
- s.author = 'Jim Menard'
41
- s.email = 'jim@jimmenard.com'
42
- s.homepage = 'http://github.com/jimm/midilib'
43
- s.rubyforge_project = PROJECT_NAME
33
+ s.author = 'Jim Menard'
34
+ s.email = 'jim@jimmenard.com'
35
+ s.homepage = 'http://github.com/jimm/midilib'
36
+ s.rubyforge_project = PROJECT_NAME
37
+ s.license = 'Ruby'
44
38
 
45
- s.summary = "MIDI file and event manipulation library"
46
- s.description = <<EOF
47
- midilib is a pure Ruby MIDI library useful for reading and
48
- writing standard MIDI files and manipulating MIDI event data.
49
- EOF
39
+ s.summary = 'MIDI file and event manipulation library'
40
+ s.description = <<~EOF
41
+ midilib is a pure Ruby MIDI library useful for reading and
42
+ writing standard MIDI files and manipulating MIDI event data.
43
+ EOF
50
44
  end
51
45
 
52
46
  if RUBY_VERSION >= '1.9'
@@ -66,29 +60,18 @@ else
66
60
  end
67
61
 
68
62
  # creates an "rdoc" task
69
- Rake::RDocTask.new do | rd |
70
- rd.main = 'README.rdoc'
71
- rd.title = PROJECT_NAME
72
- rd.rdoc_files.include('README.rdoc', 'TODO.rdoc', 'lib/**/*.rb')
63
+ Rake::RDocTask.new do |rd|
64
+ rd.main = 'README.rdoc'
65
+ rd.title = PROJECT_NAME
66
+ rd.rdoc_files.include('README.rdoc', 'TODO.rdoc', 'lib/**/*.rb')
73
67
  end
74
68
 
75
- desc "Publish gem"
76
- task :publish => [:rdoc, :package] do
69
+ desc 'Publish gem'
70
+ task publish: %i[rdoc package] do
77
71
  version = `ruby -Ilib -e 'require "midilib/info"; puts MIDI::Version'`.strip
78
72
  system "gem push pkg/midilib-#{version}.gem"
79
73
  end
80
74
 
81
- if RUBY_VERSION >= '1.9'
82
- Rake::TestTask.new do |t|
83
- t.libs << File.join(File.dirname(__FILE__), 'test')
84
- t.libs << File.join(File.dirname(__FILE__), 'lib')
85
- t.ruby_opts << '-rubygems'
86
- t.pattern = "test/**/test_*.rb"
87
- end
88
- else
89
- task :test do
90
- Rake::run_tests
91
- end
92
- end
75
+ Rake::TestTask.new
93
76
 
94
- task :clean => [:clobber_rdoc, :clobber_package]
77
+ task clean: %i[clobber_rdoc clobber_package]
data/TODO.rdoc CHANGED
@@ -1,6 +1,17 @@
1
1
  == Bugs
2
2
 
3
- No known bugs. (If that's not a challenge, I don't know what is.)
3
+ midilib does not handle tempo changes when calculating +beats_per_minute+.
4
+ The tempo events are correctly handled when reading/writing/moving them
5
+ around, it's just the functions that answer questions about the current
6
+ tempo that are wrong. See https://github.com/jimm/midilib/issues/8. The
7
+ method +beats_per_minute+ and related methods like +pulses_to_seconds+ will
8
+ have to take into account the possibility of more than one tempo event. They
9
+ will probably have to take new arguments specifying where in the sequence
10
+ the beats or pulses are being requested. For example we could have
11
+ +beats_per_minute(at_seconds: 0.0, at_beat: 0.0)+ (where the two keyword
12
+ args are mutually exclusive). Perhaps there should be separately named
13
+ public methods like +beats_per_minute_at_seconds+ and
14
+ +beats_per_minute_at_beat+ as well.
4
15
 
5
16
  == Features
6
17
 
@@ -15,7 +26,7 @@ No known bugs. (If that's not a challenge, I don't know what is.)
15
26
 
16
27
  * Implement key signature in SeqReader.
17
28
 
18
- * Format 0 files.
29
+ * Ignore unknown chunks in MIDI files. See the MIDI file spec.
19
30
 
20
31
  * Format 2 files(?).
21
32
 
@@ -14,7 +14,7 @@ require 'midilib/sequence'
14
14
  require 'midilib/consts'
15
15
  include MIDI
16
16
 
17
- seq = Sequence.new()
17
+ seq = Sequence.new
18
18
 
19
19
  # Create a first track for the sequence. This holds tempo events and stuff
20
20
  # like that.
@@ -40,10 +40,10 @@ track.events << Controller.new(0, CC_VOLUME, 127)
40
40
  # delta time length of a single quarter note.
41
41
  track.events << ProgramChange.new(0, 1, 0)
42
42
  quarter_note_length = seq.note_to_delta('quarter')
43
- [0, 2, 4, 5, 7, 9, 11, 12].each { | offset |
43
+ [0, 2, 4, 5, 7, 9, 11, 12].each do |offset|
44
44
  track.events << NoteOn.new(0, 64 + offset, 127, 0)
45
45
  track.events << NoteOff.new(0, 64 + offset, 127, quarter_note_length)
46
- }
46
+ end
47
47
 
48
48
  # Calling recalc_times is not necessary, because that only sets the events'
49
49
  # start times, which are not written out to the MIDI file. The delta times are
@@ -51,6 +51,4 @@ quarter_note_length = seq.note_to_delta('quarter')
51
51
 
52
52
  # track.recalc_times
53
53
 
54
- File.open('from_scratch.mid', 'wb') { | file |
55
- seq.write(file)
56
- }
54
+ File.open('from_scratch.mid', 'wb') { |file| seq.write(file) }
@@ -13,18 +13,18 @@ $LOAD_PATH[0, 0] = File.join(File.dirname(__FILE__), '..', 'lib')
13
13
 
14
14
  require 'midilib/sequence'
15
15
 
16
- seq = MIDI::Sequence.new()
17
- File.open(ARGV[0], 'rb') { | file | seq.read(file) }
16
+ seq = MIDI::Sequence.new
17
+ File.open(ARGV[0], 'rb') { |file| seq.read(file) }
18
18
 
19
19
  # Get all measures, so events can be mapped to measures:
20
20
  measures = seq.get_measures
21
21
 
22
- seq.each { | track |
23
- track.each { | e |
24
- if e.kind_of?(MIDI::NoteOn) then
25
- # Print out start of notes
26
- e.print_note_names = true
27
- puts measures.to_mbt(e) + " ch #{e.channel}: #{e.note_to_s}"
28
- end
29
- }
30
- }
22
+ seq.each do |track|
23
+ track.each do |e|
24
+ next unless e.is_a?(MIDI::NoteOn)
25
+
26
+ # Print out start of notes
27
+ e.print_note_names = true
28
+ puts measures.to_mbt(e) + " ch #{e.channel}: #{e.note_to_s}"
29
+ end
30
+ end
@@ -9,20 +9,20 @@ require 'midilib/sequence'
9
9
  DEFAULT_MIDI_TEST_FILE = 'NoFences.mid'
10
10
 
11
11
  # Read from MIDI file
12
- seq = MIDI::Sequence.new()
12
+ seq = MIDI::Sequence.new
13
13
 
14
- File.open(ARGV[0] || DEFAULT_MIDI_TEST_FILE, 'rb') { | file |
15
- # The block we pass in to Sequence.read is called at the end of every
16
- # track read. It is optional, but is useful for progress reports.
17
- seq.read(file)
18
- }
14
+ File.open(ARGV[0] || DEFAULT_MIDI_TEST_FILE, 'rb') do |file|
15
+ # The block we pass in to Sequence.read is called at the end of every
16
+ # track read. It is optional, but is useful for progress reports.
17
+ seq.read(file)
18
+ end
19
19
 
20
- seq.each { | track |
20
+ seq.each do |track|
21
21
  puts
22
22
  puts "*** track name \"#{track.name}\", \"#{track.instrument}\""
23
- track.each { | e |
23
+ track.each do |e|
24
24
  e.print_decimal_numbers = true
25
25
  e.print_channel_numbers_from_one = true
26
- puts e if e.kind_of?(MIDI::ProgramChange)
27
- }
28
- }
26
+ puts e if e.is_a?(MIDI::ProgramChange)
27
+ end
28
+ end