midilib 2.0.4 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog +2 -1
  3. data/Credits +44 -2
  4. data/README.rdoc +13 -9
  5. data/Rakefile +36 -53
  6. data/TODO.rdoc +13 -2
  7. data/examples/from_scratch.rb +4 -6
  8. data/examples/measures_mbt.rb +11 -11
  9. data/examples/print_program_changes.rb +11 -11
  10. data/examples/reader2text.rb +191 -191
  11. data/examples/seq2text.rb +18 -18
  12. data/examples/split.rb +21 -20
  13. data/examples/strings.rb +15 -15
  14. data/examples/transpose.rb +41 -42
  15. data/html/MIDI/ActiveSense.html +89 -213
  16. data/html/MIDI/ChannelEvent.html +95 -224
  17. data/html/MIDI/ChannelPressure.html +103 -241
  18. data/html/MIDI/Clock.html +89 -213
  19. data/html/MIDI/Continue.html +89 -213
  20. data/html/MIDI/Controller.html +105 -246
  21. data/html/MIDI/Event.html +134 -358
  22. data/html/MIDI/IO/MIDIFile.html +544 -1148
  23. data/html/MIDI/IO/SeqReader.html +273 -577
  24. data/html/MIDI/IO/SeqWriter.html +233 -439
  25. data/html/MIDI/IO.html +48 -164
  26. data/html/MIDI/KeySig.html +148 -291
  27. data/html/MIDI/Marker.html +73 -192
  28. data/html/MIDI/Measure.html +104 -267
  29. data/html/MIDI/Measures.html +106 -259
  30. data/html/MIDI/MetaEvent.html +171 -352
  31. data/html/MIDI/NoteEvent.html +114 -276
  32. data/html/MIDI/NoteOff.html +95 -223
  33. data/html/MIDI/NoteOn.html +95 -223
  34. data/html/MIDI/PitchBend.html +104 -242
  35. data/html/MIDI/PolyPressure.html +102 -246
  36. data/html/MIDI/ProgramChange.html +103 -241
  37. data/html/MIDI/Realtime.html +96 -230
  38. data/html/MIDI/Sequence.html +256 -576
  39. data/html/MIDI/SongPointer.html +104 -242
  40. data/html/MIDI/SongSelect.html +103 -241
  41. data/html/MIDI/Start.html +89 -213
  42. data/html/MIDI/Stop.html +89 -213
  43. data/html/MIDI/SystemCommon.html +73 -192
  44. data/html/MIDI/SystemExclusive.html +106 -244
  45. data/html/MIDI/SystemReset.html +89 -213
  46. data/html/MIDI/Tempo.html +127 -309
  47. data/html/MIDI/TimeSig.html +119 -300
  48. data/html/MIDI/Track.html +214 -494
  49. data/html/MIDI/TuneRequest.html +96 -230
  50. data/html/MIDI/Utils.html +91 -233
  51. data/html/MIDI.html +142 -526
  52. data/html/Object.html +197 -0
  53. data/html/README_rdoc.html +280 -486
  54. data/html/TODO_rdoc.html +68 -145
  55. data/html/created.rid +15 -14
  56. data/html/css/fonts.css +167 -0
  57. data/html/css/rdoc.css +639 -0
  58. data/html/fonts/Lato-Light.ttf +0 -0
  59. data/html/fonts/Lato-LightItalic.ttf +0 -0
  60. data/html/fonts/Lato-Regular.ttf +0 -0
  61. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  62. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  63. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  64. data/html/images/add.png +0 -0
  65. data/html/images/arrow_up.png +0 -0
  66. data/html/images/delete.png +0 -0
  67. data/html/images/tag_blue.png +0 -0
  68. data/html/index.html +230 -446
  69. data/html/js/darkfish.js +22 -91
  70. data/html/js/navigation.js +4 -41
  71. data/html/js/navigation.js.gz +0 -0
  72. data/html/js/search.js +41 -25
  73. data/html/js/search_index.js +1 -1
  74. data/html/js/search_index.js.gz +0 -0
  75. data/html/js/searcher.js +9 -8
  76. data/html/js/searcher.js.gz +0 -0
  77. data/html/table_of_contents.html +1111 -505
  78. data/install.rb +53 -34
  79. data/lib/midilib/consts.rb +406 -408
  80. data/lib/midilib/event.rb +335 -306
  81. data/lib/midilib/info.rb +5 -7
  82. data/lib/midilib/io/midifile.rb +424 -452
  83. data/lib/midilib/io/seqreader.rb +200 -192
  84. data/lib/midilib/io/seqwriter.rb +151 -147
  85. data/lib/midilib/measure.rb +78 -80
  86. data/lib/midilib/mergesort.rb +39 -0
  87. data/lib/midilib/sequence.rb +93 -87
  88. data/lib/midilib/track.rb +71 -118
  89. data/lib/midilib/utils.rb +17 -20
  90. data/lib/midilib.rb +5 -5
  91. data/test/event_equality.rb +50 -52
  92. data/test/test_event.rb +120 -124
  93. data/test/test_io.rb +118 -38
  94. data/test/test_mergesort.rb +37 -0
  95. data/test/test_midifile.rb +6 -19
  96. data/test/test_sequence.rb +62 -61
  97. data/test/test_track.rb +126 -155
  98. data/test/test_varlen.rb +23 -27
  99. metadata +67 -62
  100. data/html/IO.html +0 -259
  101. data/html/MIDI/MIDI/MIDI/Array.html +0 -353
  102. data/html/MIDI/MIDI/MIDI.html +0 -204
  103. data/html/MIDI/MIDI.html +0 -204
  104. data/html/js/jquery.js +0 -18
  105. data/html/rdoc.css +0 -543
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9bef04b13853bd3e16488263bd4fdf5fe3f43bc9fa8f48f6967ff8cd78fc2a16
4
+ data.tar.gz: fd3bf8e7ed497e1396a228b7f6506f25067b2673b381fd6b5312899369e490db
5
+ SHA512:
6
+ metadata.gz: 1fabc2a6c78a0152d48f6139e644cea2ef67b90c66b38ec085d6eabf4e11ce0c0a6549d5a34ea7020e05b0b3cd069db000e80444daacb8681afe03d458965e15
7
+ data.tar.gz: 10ce51a6d08c5181cafea51f1772d110cee3a7c244ad47ed06be76b8395f4dfcdf3cfb79a8cd15d9c5dd8c235094fc30013a5d25e0c396574452a1765f38bea1
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,9 +48,51 @@ 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
52
 
53
53
  Lucas lfzawacki (lfzawacki on Github)
54
54
 
55
55
  Found a bug in the MIDI::IO::SeqReader class: the pitch_bend method's
56
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}.
94
+
95
+ @kaorukobo on Github
96
+
97
+ Found a bug caused by note offs coming right before note ons. See
98
+ https://github.com/jimm/midilib/pull/21 for a detailed write-up.
data/README.rdoc CHANGED
@@ -8,7 +8,7 @@ http://github.com/jimm/midilib and the RubyGems.org page is
8
8
  http://rubygems.org/gems/midilib, where you can also find all the RDoc
9
9
  documentation.
10
10
 
11
- midilib is compatible with both Ruby 1.8.x and 1.9.x.
11
+ midilib is compatible with Ruby 2.6 and higher.
12
12
 
13
13
 
14
14
  == Dependencies
@@ -55,12 +55,11 @@ runs all of the tests in the test directory.
55
55
 
56
56
  == Overview
57
57
 
58
- The midilib MIDI file reader only understands MIDI file format 1, where a
59
- sequence is made up of multiple tracks. It doesn't yet understand format 0
60
- (a single track containing all events) or format 2 (a collection of format 0
61
- files in one 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.
62
61
 
63
- d=== MIDI::Sequence
62
+ === MIDI::Sequence
64
63
 
65
64
  A sequence contains a collection of tracks and global information like the
66
65
  sequence's pulses per quarter note (ppqn) and time signature.
@@ -290,7 +289,7 @@ information. Though the first edition book is available online, I encourage
290
289
  you to purchase a copy of the latest edition.
291
290
 
292
291
  A description of the MIDI file format can be found in a few places such as
293
- http://www.borg.com/~jglatt/tech/midifile.htm.
292
+ https://www.csie.ntu.edu.tw/~r92092/ref/midi/.
294
293
 
295
294
  The MIDI message reference at http://www.jimmenard.com/midi_ref.html
296
295
  describes the format of MIDI commands.
@@ -314,7 +313,7 @@ describes the format of MIDI commands.
314
313
  = Administrivia
315
314
 
316
315
  Author:: Jim Menard (mailto:jim@jimmenard.com)
317
- Copyright:: Copyright (c) 2003-2012 Jim Menard
316
+ Copyright:: Copyright (c) 2003-2013 Jim Menard
318
317
  License:: Distributed under the same license as Ruby.
319
318
 
320
319
 
@@ -327,7 +326,7 @@ http://www.ruby-lang.org/en/LICENSE.txt.
327
326
  midilib may be freely copied in its entirety providing this notice, all
328
327
  source code, all documentation, and all other files are included.
329
328
 
330
- midilib is Copyright (c) 2003-2012 by Jim Menard.
329
+ midilib is Copyright (c) 2003-2013 by Jim Menard.
331
330
 
332
331
  The song "No Fences" contained in the MIDI file examples/NoFences.mid is
333
332
  Copyright (c) 1992 by Jim Menard (jim@jimmenard.com). It may be freely used
@@ -336,6 +335,11 @@ for non-commercial purposes as long as the author is given credit.
336
335
 
337
336
  == Recent Changes
338
337
 
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
+
339
343
  === Changes for 2.0.3:
340
344
 
341
345
  New MIDI::Sequence.pulses_to_seconds 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