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
@@ -7,73 +7,74 @@ require 'test/unit'
7
7
  require 'midilib'
8
8
 
9
9
  class SequenceTester < Test::Unit::TestCase
10
+ def setup
11
+ @seq = MIDI::Sequence.new
12
+ @track = MIDI::Track.new(@seq)
13
+ @seq.tracks << @track
14
+ 3.times { @track.events << MIDI::NoteOn.new(0, 64, 64, 100) }
15
+ @track.recalc_times
16
+ end
10
17
 
11
- def setup
12
- @seq = MIDI::Sequence.new
13
- @track = MIDI::Track.new(@seq)
14
- @seq.tracks << @track
15
- 3.times { @track.events << MIDI::NoteOn.new(0, 64, 64, 100) }
16
- @track.recalc_times
17
- end
18
+ def test_basics
19
+ assert_equal(120, @seq.beats_per_minute)
20
+ assert_equal(1, @seq.tracks.length)
21
+ assert_equal(MIDI::Track::UNNAMED, @seq.name)
22
+ assert_equal(MIDI::Sequence::DEFAULT_TEMPO, @seq.bpm)
23
+ end
18
24
 
19
- def test_basics
20
- assert_equal(120, @seq.beats_per_minute)
21
- assert_equal(1, @seq.tracks.length)
22
- assert_equal(MIDI::Track::UNNAMED, @seq.name)
23
- assert_equal(MIDI::Sequence::DEFAULT_TEMPO, @seq.bpm)
24
- end
25
+ def test_pulses_to_seconds
26
+ # At a tempo of 120 BPM 480 pulses (one quarter note) should take 0.5 seconds
27
+ assert_in_delta 0.5, @seq.pulses_to_seconds(480), 0.00001
25
28
 
26
- def test_pulses_to_seconds
27
- # At a tempo of 120 BPM 480 pulses (one quarter note) should take 0.5 seconds
28
- assert_in_delta 0.5, @seq.pulses_to_seconds(480), 0.00001
29
+ # A half note should take one second
30
+ assert_in_delta 1.0, @seq.pulses_to_seconds(480 * 2), 0.00001
29
31
 
30
- # A half note should take one second
31
- assert_in_delta 1.0, @seq.pulses_to_seconds(480*2), 0.00001
32
+ # An eight note should take 0.25 seconds
33
+ assert_in_delta 0.25, @seq.pulses_to_seconds(480 / 2), 0.00001
34
+ end
32
35
 
33
- # An eight note should take 0.25 seconds
34
- assert_in_delta 0.25, @seq.pulses_to_seconds(480/2), 0.00001
35
- end
36
+ def test_length_to_delta
37
+ assert_equal(480, @seq.ppqn)
38
+ assert_equal(480, @seq.length_to_delta(1))
39
+ assert_equal(240, @seq.length_to_delta(0.5))
36
40
 
37
- def test_length_to_delta
38
- assert_equal(480, @seq.ppqn)
39
- assert_equal(480, @seq.length_to_delta(1))
40
- assert_equal(240, @seq.length_to_delta(0.5))
41
+ @seq.ppqn = 12
42
+ assert_equal(12, @seq.ppqn)
43
+ assert_equal(12, @seq.length_to_delta(1))
44
+ assert_equal(6, @seq.length_to_delta(0.5))
45
+ # rounding tests
46
+ assert_equal(6, @seq.length_to_delta(0.49))
47
+ assert_equal(5, @seq.length_to_delta(0.45))
48
+ end
41
49
 
42
- @seq.ppqn = 12
43
- assert_equal(12, @seq.ppqn)
44
- assert_equal(12, @seq.length_to_delta(1))
45
- assert_equal(6, @seq.length_to_delta(0.5))
46
- assert_equal(5, @seq.length_to_delta(0.49))
47
- end
50
+ def test_note_to_length
51
+ assert_equal(1, @seq.note_to_length('quarter'))
52
+ assert_equal(4, @seq.note_to_length('whole'))
53
+ assert_equal(1.5, @seq.note_to_length('dotted quarter'))
54
+ assert_equal(1.0 / 3.0, @seq.note_to_length('quarter triplet'))
55
+ assert_equal(0.5, @seq.note_to_length('dotted quarter triplet'))
56
+ assert_equal(1.0 / 4, @seq.note_to_length('sixteenth'))
57
+ assert_equal(1.0 / 4, @seq.note_to_length('16th'))
58
+ assert_equal(1.0 / 8, @seq.note_to_length('thirty second'))
59
+ assert_equal(1.0 / 8, @seq.note_to_length('32nd'))
60
+ assert_equal(1.0 / 16, @seq.note_to_length('sixty fourth'))
61
+ assert_equal(1.0 / 16, @seq.note_to_length('sixtyfourth'))
62
+ assert_equal(1.0 / 16, @seq.note_to_length('64th'))
63
+ end
48
64
 
49
- def test_note_to_length
50
- assert_equal(1, @seq.note_to_length('quarter'))
51
- assert_equal(4, @seq.note_to_length('whole'))
52
- assert_equal(1.5, @seq.note_to_length('dotted quarter'))
53
- assert_equal(1.0 / 3.0, @seq.note_to_length('quarter triplet'))
54
- assert_equal(0.5, @seq.note_to_length('dotted quarter triplet'))
55
- assert_equal(1.0 / 4, @seq.note_to_length('sixteenth'))
56
- assert_equal(1.0 / 4, @seq.note_to_length('16th'))
57
- assert_equal(1.0 / 8, @seq.note_to_length('thirty second'))
58
- assert_equal(1.0 / 8, @seq.note_to_length('32nd'))
59
- assert_equal(1.0 / 16, @seq.note_to_length('sixty fourth'))
60
- assert_equal(1.0 / 16, @seq.note_to_length('sixtyfourth'))
61
- assert_equal(1.0 / 16, @seq.note_to_length('64th'))
62
- end
63
-
64
- def test_note_to_delta
65
- assert_equal(480, @seq.note_to_delta('quarter'))
66
- assert_equal(480 * 4, @seq.note_to_delta('whole'))
67
- assert_equal(720, @seq.note_to_delta('dotted quarter'))
68
- assert_equal(480 / 3.0, @seq.note_to_delta('quarter triplet'))
69
- assert_equal((480 / 3.0) * 1.5,
70
- @seq.note_to_delta('dotted quarter triplet'))
71
- assert_equal(480 / 4, @seq.note_to_delta('sixteenth'))
72
- assert_equal(480 / 4, @seq.note_to_delta('16th'))
73
- assert_equal(480 / 8, @seq.note_to_delta('thirty second'))
74
- assert_equal(480 / 8, @seq.note_to_delta('32nd'))
75
- assert_equal(480 / 16, @seq.note_to_delta('sixty fourth'))
76
- assert_equal(480 / 16, @seq.note_to_delta('sixtyfourth'))
77
- assert_equal(480 / 16, @seq.note_to_delta('64th'))
78
- end
65
+ def test_note_to_delta
66
+ assert_equal(480, @seq.note_to_delta('quarter'))
67
+ assert_equal(480 * 4, @seq.note_to_delta('whole'))
68
+ assert_equal(720, @seq.note_to_delta('dotted quarter'))
69
+ assert_equal(480 / 3.0, @seq.note_to_delta('quarter triplet'))
70
+ assert_equal((480 / 3.0) * 1.5,
71
+ @seq.note_to_delta('dotted quarter triplet'))
72
+ assert_equal(480 / 4, @seq.note_to_delta('sixteenth'))
73
+ assert_equal(480 / 4, @seq.note_to_delta('16th'))
74
+ assert_equal(480 / 8, @seq.note_to_delta('thirty second'))
75
+ assert_equal(480 / 8, @seq.note_to_delta('32nd'))
76
+ assert_equal(480 / 16, @seq.note_to_delta('sixty fourth'))
77
+ assert_equal(480 / 16, @seq.note_to_delta('sixtyfourth'))
78
+ assert_equal(480 / 16, @seq.note_to_delta('64th'))
79
+ end
79
80
  end
data/test/test_track.rb CHANGED
@@ -7,166 +7,137 @@ require 'test/unit'
7
7
  require 'midilib'
8
8
 
9
9
  class TrackTester < Test::Unit::TestCase
10
-
11
- def setup
12
- @seq = MIDI::Sequence.new
13
- @track = MIDI::Track.new(@seq)
14
- @seq.tracks << @track
15
- 3.times { @track.events << MIDI::NoteOn.new(0, 64, 64, 100) }
16
- @track.recalc_times
17
- end
18
-
19
- def test_basics
20
- assert_equal(3, @track.events.length)
21
- 3.times { | i |
22
- assert_equal(100, @track.events[i].delta_time)
23
- assert_equal((i+1) * 100, @track.events[i].time_from_start)
24
- }
25
- assert_equal(MIDI::Track::UNNAMED, @track.name)
26
- end
27
-
28
- def test_append_event
29
- @track.events << MIDI::NoteOn.new(0, 64, 64, 100)
30
- @track.recalc_times
31
- assert_equal(4, @track.events.length)
32
- 4.times { | i |
33
- assert_equal((i+1) * 100, @track.events[i].time_from_start)
34
- }
10
+ def setup
11
+ @seq = MIDI::Sequence.new
12
+ @track = MIDI::Track.new(@seq)
13
+ @seq.tracks << @track
14
+ 3.times { @track.events << MIDI::NoteOn.new(0, 64, 64, 100) }
15
+ @track.recalc_times
16
+ end
17
+
18
+ def test_basics
19
+ assert_equal(3, @track.events.length)
20
+ 3.times do |i|
21
+ assert_equal(100, @track.events[i].delta_time)
22
+ assert_equal((i + 1) * 100, @track.events[i].time_from_start)
35
23
  end
36
-
37
- def test_append_list
38
- @track.events +=
39
- (1..12).collect { | i | MIDI::NoteOn.new(0, 64, 64, 3) }
40
- @track.recalc_times
41
-
42
- 3.times { | i |
43
- assert_equal(100, @track.events[i].delta_time)
44
- assert_equal((i+1) * 100, @track.events[i].time_from_start)
45
- }
46
- 12.times { | i |
47
- assert_equal(3, @track.events[3 + i].delta_time)
48
- assert_equal(300 + ((i+1) * 3),
49
- @track.events[3 + i].time_from_start)
50
- }
24
+ assert_equal(MIDI::Track::UNNAMED, @track.name)
25
+ end
26
+
27
+ def test_append_event
28
+ @track.events << MIDI::NoteOn.new(0, 64, 64, 100)
29
+ @track.recalc_times
30
+ assert_equal(4, @track.events.length)
31
+ 4.times do |i|
32
+ assert_equal((i + 1) * 100, @track.events[i].time_from_start)
51
33
  end
34
+ end
52
35
 
53
- def test_insert
54
- @track.events[1,0] = MIDI::NoteOn.new(0, 64, 64, 3)
55
- @track.recalc_times
56
- assert_equal(100, @track.events[0].time_from_start)
57
- assert_equal(103, @track.events[1].time_from_start)
58
- assert_equal(203, @track.events[2].time_from_start)
59
- assert_equal(303, @track.events[3].time_from_start)
60
- end
36
+ def test_append_list
37
+ @track.events +=
38
+ (1..12).collect { |i| MIDI::NoteOn.new(0, 64, 64, 3) }
39
+ @track.recalc_times
61
40
 
62
- def test_merge
63
- list = (1..12).collect { | i | MIDI::NoteOn.new(0, 64, 64, 10) }
64
- @track.merge(list)
65
- assert_equal(15, @track.events.length)
66
- assert_equal(10, @track.events[0].time_from_start)
67
- assert_equal(10, @track.events[0].delta_time)
68
- assert_equal(20, @track.events[1].time_from_start)
69
- assert_equal(10, @track.events[1].delta_time)
70
- assert_equal(30, @track.events[2].time_from_start)
71
- assert_equal(40, @track.events[3].time_from_start)
72
- assert_equal(50, @track.events[4].time_from_start)
73
- assert_equal(60, @track.events[5].time_from_start)
74
- assert_equal(70, @track.events[6].time_from_start)
75
- assert_equal(80, @track.events[7].time_from_start)
76
- assert_equal(90, @track.events[8].time_from_start)
77
- assert_equal(100, @track.events[9].time_from_start)
78
- assert_equal(100, @track.events[10].time_from_start)
79
- assert_equal(110, @track.events[11].time_from_start)
80
- assert_equal(120, @track.events[12].time_from_start)
81
- assert_equal(200, @track.events[13].time_from_start)
82
- assert_equal(300, @track.events[14].time_from_start)
41
+ 3.times do |i|
42
+ assert_equal(100, @track.events[i].delta_time)
43
+ assert_equal((i + 1) * 100, @track.events[i].time_from_start)
83
44
  end
84
-
85
- def test_recalc_delta_from_times
86
- @track.each { | event | event.delta_time = 0 }
87
- @track.recalc_delta_from_times
88
- @track.each { | event | assert_equal(100, event.delta_time) }
45
+ 12.times do |i|
46
+ assert_equal(3, @track.events[3 + i].delta_time)
47
+ assert_equal(300 + ((i + 1) * 3),
48
+ @track.events[3 + i].time_from_start)
89
49
  end
90
-
91
- def test_recalc_delta_from_times_unsorted
92
- @track.events[0].time_from_start = 100
93
- @track.events[1].time_from_start = 50
94
- @track.events[2].time_from_start = 150
95
- @track.recalc_delta_from_times
96
- prev_start_time = 0
97
- @track.each { | event |
98
- assert(prev_start_time <= event.time_from_start)
99
- assert(event.delta_time > 0)
100
- prev_start_time = event.time_from_start
101
- }
102
- end
103
-
104
- def test_sort
105
- e = @track.events[0]
106
- e.time_from_start = 300
107
- e = @track.events[1]
108
- e.time_from_start = 100
109
- e = @track.events[2]
110
- e.time_from_start = 200
111
-
112
- @track.sort
113
-
114
- assert_equal(100, @track.events[0].time_from_start)
115
- assert_equal(100, @track.events[0].delta_time)
116
-
117
- assert_equal(200, @track.events[1].time_from_start)
118
- assert_equal(100, @track.events[1].delta_time)
119
-
120
- assert_equal(300, @track.events[2].time_from_start)
121
- assert_equal(100, @track.events[2].delta_time)
122
- end
123
-
124
- def test_quantize
125
- @seq.ppqn = 80
126
-
127
- @track.quantize(1) # Quantize to a quarter note
128
- assert_equal(80, @track.events[0].time_from_start) # was 100
129
- assert_equal(240, @track.events[1].time_from_start) # was 200
130
- assert_equal(320, @track.events[2].time_from_start) # was 300
131
- end
132
-
133
- def test_instrument
134
- @track.instrument = 'foo'
135
- assert_equal('foo', @track.instrument)
136
- end
137
-
138
- def test_old_note_class_names
139
- x = MIDI::NoteOn.new(0, 64, 64, 10)
140
- assert(x.kind_of?(MIDI::NoteOnEvent)) # old name
141
- x = MIDI::NoteOff.new(0, 64, 64, 10)
142
- assert(x.kind_of?(MIDI::NoteOffEvent)) # old name
143
- end
144
-
145
- def test_mergesort
146
- @track.events = []
147
-
148
- # Two events with later start times but earlier in the event list
149
- e2 = MIDI::NoteOff.new(0, 64, 64, 100)
150
- e2.time_from_start = 100
151
- @track.events << e2
152
-
153
- e3 = MIDI::NoteOn.new(0, 64, 64, 100)
154
- e3.time_from_start = 100
155
- @track.events << e3
156
-
157
- # Earliest start time, latest in the list of events
158
- e1 = MIDI::NoteOn.new(0, 64, 64, 100)
159
- e1.time_from_start = 0
160
- @track.events << e1
161
-
162
- # Recalc sorts. Make sure note off/note on pair at t 100 are in the
163
- # correct order.
164
- @track.recalc_delta_from_times
165
-
166
- # These tests would fail before we moved to mergesort.
167
- assert_equal(e1, @track.events[0])
168
- assert_equal(e2, @track.events[1])
169
- assert_equal(e3, @track.events[2])
170
-
50
+ end
51
+
52
+ def test_insert
53
+ @track.events[1, 0] = MIDI::NoteOn.new(0, 64, 64, 3)
54
+ @track.recalc_times
55
+ assert_equal(100, @track.events[0].time_from_start)
56
+ assert_equal(103, @track.events[1].time_from_start)
57
+ assert_equal(203, @track.events[2].time_from_start)
58
+ assert_equal(303, @track.events[3].time_from_start)
59
+ end
60
+
61
+ def test_merge
62
+ list = (1..12).collect { |i| MIDI::NoteOn.new(0, 64, 64, 10) }
63
+ @track.merge(list)
64
+ assert_equal(15, @track.events.length)
65
+ assert_equal(10, @track.events[0].time_from_start)
66
+ assert_equal(10, @track.events[0].delta_time)
67
+ assert_equal(20, @track.events[1].time_from_start)
68
+ assert_equal(10, @track.events[1].delta_time)
69
+ assert_equal(30, @track.events[2].time_from_start)
70
+ assert_equal(40, @track.events[3].time_from_start)
71
+ assert_equal(50, @track.events[4].time_from_start)
72
+ assert_equal(60, @track.events[5].time_from_start)
73
+ assert_equal(70, @track.events[6].time_from_start)
74
+ assert_equal(80, @track.events[7].time_from_start)
75
+ assert_equal(90, @track.events[8].time_from_start)
76
+ assert_equal(100, @track.events[9].time_from_start)
77
+ assert_equal(100, @track.events[10].time_from_start)
78
+ assert_equal(110, @track.events[11].time_from_start)
79
+ assert_equal(120, @track.events[12].time_from_start)
80
+ assert_equal(200, @track.events[13].time_from_start)
81
+ assert_equal(300, @track.events[14].time_from_start)
82
+ end
83
+
84
+ def test_recalc_delta_from_times
85
+ @track.each { |event| event.delta_time = 0 }
86
+ @track.recalc_delta_from_times
87
+ @track.each { |event| assert_equal(100, event.delta_time) }
88
+ end
89
+
90
+ def test_recalc_delta_from_times_unsorted
91
+ @track.events[0].time_from_start = 100
92
+ @track.events[1].time_from_start = 50
93
+ @track.events[2].time_from_start = 150
94
+ @track.recalc_delta_from_times
95
+ prev_start_time = 0
96
+ @track.each do |event|
97
+ assert(prev_start_time <= event.time_from_start)
98
+ assert(event.delta_time > 0)
99
+ prev_start_time = event.time_from_start
171
100
  end
101
+ end
102
+
103
+ def test_sort
104
+ e = @track.events[0]
105
+ e.time_from_start = 300
106
+ e = @track.events[1]
107
+ e.time_from_start = 100
108
+ e = @track.events[2]
109
+ e.time_from_start = 200
110
+
111
+ @track.sort
112
+
113
+ assert_equal(100, @track.events[0].time_from_start)
114
+ assert_equal(100, @track.events[0].delta_time)
115
+
116
+ assert_equal(200, @track.events[1].time_from_start)
117
+ assert_equal(100, @track.events[1].delta_time)
118
+
119
+ assert_equal(300, @track.events[2].time_from_start)
120
+ assert_equal(100, @track.events[2].delta_time)
121
+ end
122
+
123
+ def test_quantize
124
+ @seq.ppqn = 80
125
+
126
+ @track.quantize(1) # Quantize to a quarter note
127
+ assert_equal(80, @track.events[0].time_from_start) # was 100
128
+ assert_equal(240, @track.events[1].time_from_start) # was 200
129
+ assert_equal(320, @track.events[2].time_from_start) # was 300
130
+ end
131
+
132
+ def test_instrument
133
+ @track.instrument = 'foo'
134
+ assert_equal('foo', @track.instrument)
135
+ end
136
+
137
+ def test_old_note_class_names
138
+ x = MIDI::NoteOn.new(0, 64, 64, 10)
139
+ assert(x.is_a?(MIDI::NoteOnEvent)) # old name
140
+ x = MIDI::NoteOff.new(0, 64, 64, 10)
141
+ assert(x.is_a?(MIDI::NoteOffEvent)) # old name
142
+ end
172
143
  end
data/test/test_varlen.rb CHANGED
@@ -7,34 +7,30 @@ require 'test/unit'
7
7
  require 'midilib'
8
8
 
9
9
  class VarLenTester < Test::Unit::TestCase
10
+ VAR_LEN_TEST_DATA = {
11
+ 0x00000000 => 0x00,
12
+ 0x00000040 => 0x40,
13
+ 0x0000007F => 0x7F,
14
+ 0x00000080 => 0x8100,
15
+ 0x00002000 => 0xC000,
16
+ 0x00003FFF => 0xFF7F,
17
+ 0x00004000 => 0x818000,
18
+ 0x00100000 => 0xC08000,
19
+ 0x001FFFFF => 0xFFFF7F,
20
+ 0x00200000 => 0x81808000,
21
+ 0x08000000 => 0xC0808000,
22
+ 0x0FFFFFFF => 0xFFFFFF7F
23
+ }
10
24
 
11
- VAR_LEN_TEST_DATA = {
12
- 0x00000000 => 0x00,
13
- 0x00000040 => 0x40,
14
- 0x0000007F => 0x7F,
15
- 0x00000080 => 0x8100,
16
- 0x00002000 => 0xC000,
17
- 0x00003FFF => 0xFF7F,
18
- 0x00004000 => 0x818000,
19
- 0x00100000 => 0xC08000,
20
- 0x001FFFFF => 0xFFFF7F,
21
- 0x00200000 => 0x81808000,
22
- 0x08000000 => 0xC0808000,
23
- 0x0FFFFFFF => 0xFFFFFF7F,
24
- }
25
-
26
- def num_to_var_len(num, answer)
27
- varlen = MIDI::Utils.as_var_len(num)
28
- varlen.reverse.each { | b |
29
- assert_equal(answer & 0xff, b)
30
- answer = answer >> 8
31
- }
32
- end
33
-
34
- def test_num_to_var_len
35
- VAR_LEN_TEST_DATA.each { | varlen, answer |
36
- num_to_var_len(varlen, answer)
37
- }
25
+ def num_to_var_len(num, answer)
26
+ varlen = MIDI::Utils.as_var_len(num)
27
+ varlen.reverse.each do |b|
28
+ assert_equal(answer & 0xff, b)
29
+ answer = answer >> 8
38
30
  end
31
+ end
39
32
 
33
+ def test_num_to_var_len
34
+ VAR_LEN_TEST_DATA.each { |varlen, answer| num_to_var_len(varlen, answer) }
35
+ end
40
36
  end