midilib 2.0.4 → 2.0.5
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 +7 -0
- data/README.rdoc +9 -4
- data/Rakefile +2 -6
- data/examples/from_scratch.rb +3 -5
- data/examples/measures_mbt.rb +4 -4
- data/examples/print_program_changes.rb +9 -9
- data/examples/reader2text.rb +188 -188
- data/examples/seq2text.rb +17 -17
- data/examples/split.rb +19 -19
- data/examples/strings.rb +14 -14
- data/examples/transpose.rb +31 -31
- data/html/IO.html +65 -169
- data/html/MIDI.html +138 -256
- data/html/MIDI/ActiveSense.html +89 -178
- data/html/MIDI/ChannelEvent.html +95 -183
- data/html/MIDI/ChannelPressure.html +105 -190
- data/html/MIDI/Clock.html +89 -178
- data/html/MIDI/Continue.html +89 -178
- data/html/MIDI/Controller.html +107 -192
- data/html/MIDI/Event.html +138 -222
- data/html/MIDI/IO.html +45 -157
- data/html/MIDI/IO/MIDIFile.html +596 -568
- data/html/MIDI/IO/SeqReader.html +272 -314
- data/html/MIDI/IO/SeqWriter.html +229 -305
- data/html/MIDI/KeySig.html +129 -211
- data/html/MIDI/MIDI.html +45 -154
- data/html/MIDI/MIDI/MIDI.html +45 -154
- data/html/MIDI/MIDI/MIDI/Array.html +87 -185
- data/html/MIDI/Marker.html +71 -170
- data/html/MIDI/Measure.html +95 -190
- data/html/MIDI/Measures.html +103 -193
- data/html/MIDI/MetaEvent.html +180 -253
- data/html/MIDI/NoteEvent.html +118 -204
- data/html/MIDI/NoteOff.html +95 -183
- data/html/MIDI/NoteOn.html +95 -183
- data/html/MIDI/PitchBend.html +106 -191
- data/html/MIDI/PolyPressure.html +106 -189
- data/html/MIDI/ProgramChange.html +105 -190
- data/html/MIDI/Realtime.html +98 -184
- data/html/MIDI/Sequence.html +246 -311
- data/html/MIDI/SongPointer.html +106 -191
- data/html/MIDI/SongSelect.html +105 -190
- data/html/MIDI/Start.html +89 -178
- data/html/MIDI/Stop.html +89 -178
- data/html/MIDI/SystemCommon.html +71 -170
- data/html/MIDI/SystemExclusive.html +108 -193
- data/html/MIDI/SystemReset.html +89 -178
- data/html/MIDI/Tempo.html +135 -213
- data/html/MIDI/TimeSig.html +135 -214
- data/html/MIDI/Track.html +217 -291
- data/html/MIDI/TuneRequest.html +98 -184
- data/html/MIDI/Utils.html +89 -189
- data/html/README_rdoc.html +237 -257
- data/html/TODO_rdoc.html +64 -139
- data/html/created.rid +14 -14
- data/html/css/fonts.css +167 -0
- data/html/{rdoc.css → css/rdoc.css} +265 -218
- data/html/fonts/Lato-Light.ttf +0 -0
- data/html/fonts/Lato-LightItalic.ttf +0 -0
- data/html/fonts/Lato-Regular.ttf +0 -0
- data/html/fonts/Lato-RegularItalic.ttf +0 -0
- data/html/fonts/SourceCodePro-Bold.ttf +0 -0
- data/html/fonts/SourceCodePro-Regular.ttf +0 -0
- data/html/images/add.png +0 -0
- data/html/images/arrow_up.png +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/tag_blue.png +0 -0
- data/html/index.html +187 -169
- data/html/js/darkfish.js +41 -33
- data/html/js/jquery.js +4 -18
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search.js +20 -5
- data/html/js/search_index.js +1 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +1111 -498
- data/install.rb +43 -32
- data/lib/midilib/consts.rb +407 -407
- data/lib/midilib/event.rb +295 -294
- data/lib/midilib/info.rb +5 -5
- data/lib/midilib/io/midifile.rb +266 -267
- data/lib/midilib/io/seqreader.rb +106 -106
- data/lib/midilib/io/seqwriter.rb +59 -60
- data/lib/midilib/measure.rb +69 -69
- data/lib/midilib/sequence.rb +68 -70
- data/lib/midilib/track.rb +96 -102
- data/lib/midilib/utils.rb +15 -15
- data/test/event_equality.rb +50 -50
- data/test/test_event.rb +120 -122
- data/test/test_io.rb +35 -48
- data/test/test_sequence.rb +60 -60
- data/test/test_track.rb +154 -154
- data/test/test_varlen.rb +23 -25
- metadata +65 -57
    
        data/lib/midilib/utils.rb
    CHANGED
    
    | @@ -1,18 +1,18 @@ | |
| 1 1 | 
             
            module MIDI
         | 
| 2 2 |  | 
| 3 | 
            -
            # Utility methods.
         | 
| 4 | 
            -
            class Utils
         | 
| 3 | 
            +
              # Utility methods.
         | 
| 4 | 
            +
              class Utils
         | 
| 5 5 |  | 
| 6 6 | 
             
                # MIDI note names. NOTE_NAMES[0] is 'C', NOTE_NAMES[1] is 'C#', etc.
         | 
| 7 7 | 
             
                NOTE_NAMES = [
         | 
| 8 | 
            -
             | 
| 8 | 
            +
                  'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'
         | 
| 9 9 | 
             
                ]
         | 
| 10 10 |  | 
| 11 11 | 
             
                # Given a MIDI note number, return the name and octave as a string.
         | 
| 12 12 | 
             
                def Utils.note_to_s(num)
         | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 13 | 
            +
                  note = num % 12
         | 
| 14 | 
            +
                  octave = num / 12
         | 
| 15 | 
            +
                  return "#{NOTE_NAMES[note]}#{octave - 1}"
         | 
| 16 16 | 
             
                end
         | 
| 17 17 |  | 
| 18 18 | 
             
                # Given an integer, returns it as a variable length array of bytes (the
         | 
| @@ -22,15 +22,15 @@ class Utils | |
| 22 22 | 
             
                # input from a stream of bytes. Therefore we don't supply it here. That is
         | 
| 23 23 | 
             
                # a part of the MIDIFile class.
         | 
| 24 24 | 
             
                def Utils.as_var_len(val)
         | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 25 | 
            +
                  buffer = []
         | 
| 26 | 
            +
                  buffer << (val & 0x7f)
         | 
| 27 | 
            +
                  val = (val >> 7)
         | 
| 28 | 
            +
                  while val > 0
         | 
| 29 | 
            +
                    buffer << (0x80 + (val & 0x7f))
         | 
| 30 | 
            +
                    val = (val >> 7)
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                  return buffer.reverse!
         | 
| 33 33 | 
             
                end
         | 
| 34 34 |  | 
| 35 | 
            -
            end
         | 
| 35 | 
            +
              end
         | 
| 36 36 | 
             
            end
         | 
    
        data/test/event_equality.rb
    CHANGED
    
    | @@ -6,76 +6,76 @@ | |
| 6 6 |  | 
| 7 7 | 
             
            module MIDI
         | 
| 8 8 |  | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
            	end
         | 
| 9 | 
            +
              class Event
         | 
| 10 | 
            +
                def ==(an_obj)
         | 
| 11 | 
            +
                  return an_obj.instance_of?(self.class) &&
         | 
| 12 | 
            +
                    @status == an_obj.status &&
         | 
| 13 | 
            +
                    @delta_time == an_obj.delta_time &&
         | 
| 14 | 
            +
                    @time_from_start == an_obj.time_from_start
         | 
| 16 15 | 
             
                end
         | 
| 16 | 
            +
              end
         | 
| 17 17 |  | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
            	end
         | 
| 18 | 
            +
              class ChannelEvent
         | 
| 19 | 
            +
                def ==(an_obj)
         | 
| 20 | 
            +
                  return super(an_obj) && @channel == an_obj.channel
         | 
| 22 21 | 
             
                end
         | 
| 22 | 
            +
              end
         | 
| 23 23 |  | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
            	end
         | 
| 24 | 
            +
              class NoteEvent < ChannelEvent
         | 
| 25 | 
            +
                def ==(an_obj)
         | 
| 26 | 
            +
                  return super(an_obj) &&
         | 
| 27 | 
            +
                    @note == an_obj.note && @velocity == an_obj.velocity
         | 
| 29 28 | 
             
                end
         | 
| 29 | 
            +
              end
         | 
| 30 30 |  | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
            	end
         | 
| 31 | 
            +
              class Controller < ChannelEvent
         | 
| 32 | 
            +
                def ==(an_obj)
         | 
| 33 | 
            +
                  return super(an_obj) &&
         | 
| 34 | 
            +
                    @controller == an_obj.controller && @value == an_obj.value
         | 
| 36 35 | 
             
                end
         | 
| 36 | 
            +
              end
         | 
| 37 37 |  | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
            	end
         | 
| 38 | 
            +
              class ProgramChange < ChannelEvent
         | 
| 39 | 
            +
                def ==(an_obj)
         | 
| 40 | 
            +
                  return super(an_obj) && @program == an_obj.program
         | 
| 42 41 | 
             
                end
         | 
| 42 | 
            +
              end
         | 
| 43 43 |  | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
            	end
         | 
| 44 | 
            +
              class ChannelPressure < ChannelEvent
         | 
| 45 | 
            +
                def ==(an_obj)
         | 
| 46 | 
            +
                  return super(an_obj) && @pressure == an_obj.pressure
         | 
| 48 47 | 
             
                end
         | 
| 48 | 
            +
              end
         | 
| 49 49 |  | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
            	end
         | 
| 50 | 
            +
              class PitchBend < ChannelEvent
         | 
| 51 | 
            +
                def ==(an_obj)
         | 
| 52 | 
            +
                  return super(an_obj) && @value == an_obj.value
         | 
| 54 53 | 
             
                end
         | 
| 54 | 
            +
              end
         | 
| 55 55 |  | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
            	end
         | 
| 56 | 
            +
              class SystemExclusive < SystemCommon
         | 
| 57 | 
            +
                def ==(an_obj)
         | 
| 58 | 
            +
                  return super(an_obj) && @data == an_obj.data
         | 
| 60 59 | 
             
                end
         | 
| 60 | 
            +
              end
         | 
| 61 61 |  | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
            	end
         | 
| 62 | 
            +
              class SongPointer < SystemCommon
         | 
| 63 | 
            +
                def ==(an_obj)
         | 
| 64 | 
            +
                  return super(an_obj) && @pointer == an_obj.pointer
         | 
| 66 65 | 
             
                end
         | 
| 66 | 
            +
              end
         | 
| 67 67 |  | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
            	end
         | 
| 68 | 
            +
              class SongSelect < SystemCommon
         | 
| 69 | 
            +
                def ==(an_obj)
         | 
| 70 | 
            +
                  return super(an_obj) && @song == an_obj.song
         | 
| 72 71 | 
             
                end
         | 
| 72 | 
            +
              end
         | 
| 73 73 |  | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
            	end
         | 
| 74 | 
            +
              class MetaEvent < Event
         | 
| 75 | 
            +
                def ==(an_obj)
         | 
| 76 | 
            +
                  return super(an_obj) && @meta_type == an_obj.meta_type &&
         | 
| 77 | 
            +
                    @data == an_obj.data
         | 
| 79 78 | 
             
                end
         | 
| 79 | 
            +
              end
         | 
| 80 80 |  | 
| 81 81 | 
             
            end
         | 
    
        data/test/test_event.rb
    CHANGED
    
    | @@ -8,130 +8,128 @@ require 'midilib' | |
| 8 8 |  | 
| 9 9 | 
             
            class EventTester < Test::Unit::TestCase
         | 
| 10 10 |  | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 11 | 
            +
              def test_note_on
         | 
| 12 | 
            +
                e = MIDI::NoteOn.new
         | 
| 13 | 
            +
                assert_equal(MIDI::NOTE_ON, e.status)
         | 
| 14 | 
            +
                assert_equal(0, e.channel)
         | 
| 15 | 
            +
                assert_equal(64, e.note)
         | 
| 16 | 
            +
                assert_equal(64, e.velocity)
         | 
| 17 | 
            +
                assert_equal(0, e.delta_time)
         | 
| 18 | 
            +
                assert_equal(0, e.time_from_start)
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def test_to_s
         | 
| 22 | 
            +
                e = MIDI::NoteOn.new
         | 
| 23 | 
            +
                assert_equal("0: ch 00 on 40 40", e.to_s)
         | 
| 24 | 
            +
                e.print_decimal_numbers = true
         | 
| 25 | 
            +
                assert_equal("0: ch 0 on 64 64", e.to_s)
         | 
| 26 | 
            +
                e.print_note_names = true
         | 
| 27 | 
            +
                assert_equal("0: ch 0 on E4 64", e.to_s)
         | 
| 28 | 
            +
                e.print_decimal_numbers = false
         | 
| 29 | 
            +
                assert_equal("0: ch 00 on E4 40", e.to_s)
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              def test_pitch_bend
         | 
| 33 | 
            +
                e = MIDI::PitchBend.new(0, 128)
         | 
| 34 | 
            +
                b = e.data_as_bytes
         | 
| 35 | 
            +
                assert_equal(0, b[1])	# lsb, 7 bits
         | 
| 36 | 
            +
                assert_equal(1, b[2])	# msb, 7 bits
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                e.value = (3 << 7) + 42
         | 
| 39 | 
            +
                b = e.data_as_bytes
         | 
| 40 | 
            +
                assert_equal(42, b[1])	# lsb, 7 bits
         | 
| 41 | 
            +
                assert_equal(3, b[2])	# msb, 7 bits
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              def test_quantize_1
         | 
| 45 | 
            +
                e = MIDI::NoteOn.new
         | 
| 46 | 
            +
                e.quantize_to(4)
         | 
| 47 | 
            +
                assert_equal(0, e.time_from_start)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                # Each value in this array is the expected quantized value of
         | 
| 50 | 
            +
                # its index in the array.
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                # Test with quantize_to(4)
         | 
| 53 | 
            +
                [0, 0, 4, 4, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12, 16].each_with_index do |after, before|
         | 
| 54 | 
            +
                  e.time_from_start = before
         | 
| 55 | 
            +
                  e.quantize_to(4)
         | 
| 56 | 
            +
                  assert_equal(after, e.time_from_start)
         | 
| 19 57 | 
             
                end
         | 
| 20 58 |  | 
| 21 | 
            -
                 | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
            	# its index in the array.
         | 
| 28 | 
            -
             | 
| 29 | 
            -
            	# Test with quantize_to(4)
         | 
| 30 | 
            -
            	[0, 0, 4, 4, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12, 16].each_with_index {
         | 
| 31 | 
            -
            	    | after, before |
         | 
| 32 | 
            -
            	    e.time_from_start = before
         | 
| 33 | 
            -
            	    e.quantize_to(4)
         | 
| 34 | 
            -
            	    assert_equal(after, e.time_from_start)
         | 
| 35 | 
            -
            	}
         | 
| 36 | 
            -
             | 
| 37 | 
            -
            	# Test with quantize_to(6)
         | 
| 38 | 
            -
            	[0, 0, 0, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 12, 12,
         | 
| 39 | 
            -
            	 18, 18, 18, 18, 18, 18, 24].each_with_index {
         | 
| 40 | 
            -
            	    | after, before |
         | 
| 41 | 
            -
            	    e.time_from_start = before
         | 
| 42 | 
            -
            	    e.quantize_to(6)
         | 
| 43 | 
            -
            	    assert_equal(after, e.time_from_start)
         | 
| 44 | 
            -
            	}
         | 
| 45 | 
            -
                end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                def test_to_s
         | 
| 48 | 
            -
            	e = MIDI::NoteOn.new
         | 
| 49 | 
            -
            	assert_equal("0: ch 00 on 40 40", e.to_s)
         | 
| 50 | 
            -
            	e.print_decimal_numbers = true
         | 
| 51 | 
            -
            	assert_equal("0: ch 0 on 64 64", e.to_s)
         | 
| 52 | 
            -
            	e.print_note_names = true
         | 
| 53 | 
            -
            	assert_equal("0: ch 0 on E4 64", e.to_s)
         | 
| 54 | 
            -
            	e.print_decimal_numbers = false
         | 
| 55 | 
            -
            	assert_equal("0: ch 00 on E4 40", e.to_s)
         | 
| 56 | 
            -
                end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                def test_pitch_bend
         | 
| 59 | 
            -
                  e = MIDI::PitchBend.new(0, 128)
         | 
| 60 | 
            -
                  b = e.data_as_bytes
         | 
| 61 | 
            -
                  assert_equal(0, b[1])	# lsb, 7 bits
         | 
| 62 | 
            -
                  assert_equal(1, b[2])	# msb, 7 bits
         | 
| 63 | 
            -
             | 
| 64 | 
            -
                  e.value = (3 << 7) + 42
         | 
| 65 | 
            -
                  b = e.data_as_bytes
         | 
| 66 | 
            -
                  assert_equal(42, b[1])	# lsb, 7 bits
         | 
| 67 | 
            -
                  assert_equal(3, b[2])	# msb, 7 bits
         | 
| 68 | 
            -
                end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
                def test_quantize
         | 
| 71 | 
            -
            	e = MIDI::NoteOn.new(0, 64, 64, 0)
         | 
| 72 | 
            -
            	e.quantize_to(80)
         | 
| 73 | 
            -
            	assert_equal(0, e.time_from_start)
         | 
| 74 | 
            -
             | 
| 75 | 
            -
            	e.time_from_start = 1
         | 
| 76 | 
            -
            	e.quantize_to(80)
         | 
| 77 | 
            -
            	assert_equal(0, e.time_from_start)
         | 
| 78 | 
            -
             | 
| 79 | 
            -
            	e.time_from_start = 70
         | 
| 80 | 
            -
            	e.quantize_to(80)
         | 
| 81 | 
            -
            	assert_equal(80, e.time_from_start)
         | 
| 82 | 
            -
             | 
| 83 | 
            -
            	e.time_from_start = 100
         | 
| 84 | 
            -
            	e.quantize_to(80)
         | 
| 85 | 
            -
            	assert_equal(80, e.time_from_start)
         | 
| 86 | 
            -
             | 
| 87 | 
            -
            	e.time_from_start = 398
         | 
| 88 | 
            -
            	e.quantize_to(80)
         | 
| 89 | 
            -
            	assert_equal(400, e.time_from_start)
         | 
| 90 | 
            -
             | 
| 91 | 
            -
            	e.time_from_start = 405
         | 
| 92 | 
            -
            	e.quantize_to(80)
         | 
| 93 | 
            -
            	assert_equal(400, e.time_from_start)
         | 
| 94 | 
            -
             | 
| 95 | 
            -
            	e.time_from_start = 439
         | 
| 96 | 
            -
            	e.quantize_to(80)
         | 
| 97 | 
            -
            	assert_equal(400, e.time_from_start)
         | 
| 98 | 
            -
             | 
| 99 | 
            -
            	e.time_from_start = 440
         | 
| 100 | 
            -
            	e.quantize_to(80)
         | 
| 101 | 
            -
            	assert_equal(480, e.time_from_start)
         | 
| 102 | 
            -
             | 
| 103 | 
            -
            	e.time_from_start = 441
         | 
| 104 | 
            -
            	e.quantize_to(80)
         | 
| 105 | 
            -
            	assert_equal(480, e.time_from_start)
         | 
| 106 | 
            -
                end
         | 
| 107 | 
            -
             | 
| 108 | 
            -
                def test_meta_strings
         | 
| 109 | 
            -
            	e = MIDI::MetaEvent.new(MIDI::META_TEXT, [97, 98, 99])
         | 
| 110 | 
            -
            	assert_equal([97, 98, 99], e.data)
         | 
| 111 | 
            -
            	assert_equal('abc', e.data_as_str)
         | 
| 112 | 
            -
             | 
| 113 | 
            -
                    assert_equal([MIDI::META_EVENT, MIDI::META_TEXT, 3, 97, 98, 99], e.data_as_bytes)
         | 
| 114 | 
            -
                end
         | 
| 115 | 
            -
             | 
| 116 | 
            -
                def test_meta_event_string_in_ctor
         | 
| 117 | 
            -
            	e = MIDI::MetaEvent.new(MIDI::META_TEXT, 'abc')
         | 
| 118 | 
            -
            	assert_equal([97, 98, 99], e.data)
         | 
| 119 | 
            -
            	assert_equal('abc', e.data_as_str)
         | 
| 120 | 
            -
                    assert_equal([MIDI::META_EVENT, MIDI::META_TEXT, 3, 97, 98, 99], e.data_as_bytes)
         | 
| 121 | 
            -
                end
         | 
| 122 | 
            -
             | 
| 123 | 
            -
                def test_meta_event_data_assignment
         | 
| 124 | 
            -
            	foobar_as_array = [102, 111, 111, 98, 97, 114]
         | 
| 125 | 
            -
             | 
| 126 | 
            -
            	e = MIDI::MetaEvent.new(MIDI::META_TEXT, [97, 98, 99])
         | 
| 127 | 
            -
            	e.data = 'foobar'
         | 
| 128 | 
            -
            	assert_equal('foobar', e.data_as_str)
         | 
| 129 | 
            -
            	assert_equal(foobar_as_array, e.data)
         | 
| 130 | 
            -
             | 
| 131 | 
            -
            	e.data = nil
         | 
| 132 | 
            -
            	e.data = foobar_as_array
         | 
| 133 | 
            -
            	assert_equal('foobar', e.data_as_str)
         | 
| 134 | 
            -
            	assert_equal(foobar_as_array, e.data)
         | 
| 59 | 
            +
                # Test with quantize_to(6)
         | 
| 60 | 
            +
                [0, 0, 0, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 12, 12,
         | 
| 61 | 
            +
                  18, 18, 18, 18, 18, 18, 24].each_with_index do |after, before|
         | 
| 62 | 
            +
                  e.time_from_start = before
         | 
| 63 | 
            +
                  e.quantize_to(6)
         | 
| 64 | 
            +
                  assert_equal(after, e.time_from_start)
         | 
| 135 65 | 
             
                end
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              def test_quantize_2
         | 
| 69 | 
            +
                e = MIDI::NoteOn.new(0, 64, 64, 0)
         | 
| 70 | 
            +
                e.quantize_to(80)
         | 
| 71 | 
            +
                assert_equal(0, e.time_from_start)
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                e.time_from_start = 1
         | 
| 74 | 
            +
                e.quantize_to(80)
         | 
| 75 | 
            +
                assert_equal(0, e.time_from_start)
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                e.time_from_start = 70
         | 
| 78 | 
            +
                e.quantize_to(80)
         | 
| 79 | 
            +
                assert_equal(80, e.time_from_start)
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                e.time_from_start = 100
         | 
| 82 | 
            +
                e.quantize_to(80)
         | 
| 83 | 
            +
                assert_equal(80, e.time_from_start)
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                e.time_from_start = 398
         | 
| 86 | 
            +
                e.quantize_to(80)
         | 
| 87 | 
            +
                assert_equal(400, e.time_from_start)
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                e.time_from_start = 405
         | 
| 90 | 
            +
                e.quantize_to(80)
         | 
| 91 | 
            +
                assert_equal(400, e.time_from_start)
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                e.time_from_start = 439
         | 
| 94 | 
            +
                e.quantize_to(80)
         | 
| 95 | 
            +
                assert_equal(400, e.time_from_start)
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                e.time_from_start = 440
         | 
| 98 | 
            +
                e.quantize_to(80)
         | 
| 99 | 
            +
                assert_equal(480, e.time_from_start)
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                e.time_from_start = 441
         | 
| 102 | 
            +
                e.quantize_to(80)
         | 
| 103 | 
            +
                assert_equal(480, e.time_from_start)
         | 
| 104 | 
            +
              end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
              def test_meta_strings
         | 
| 107 | 
            +
                e = MIDI::MetaEvent.new(MIDI::META_TEXT, [97, 98, 99])
         | 
| 108 | 
            +
                assert_equal([97, 98, 99], e.data)
         | 
| 109 | 
            +
                assert_equal('abc', e.data_as_str)
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                assert_equal([MIDI::META_EVENT, MIDI::META_TEXT, 3, 97, 98, 99], e.data_as_bytes)
         | 
| 112 | 
            +
              end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
              def test_meta_event_string_in_ctor
         | 
| 115 | 
            +
                e = MIDI::MetaEvent.new(MIDI::META_TEXT, 'abc')
         | 
| 116 | 
            +
                assert_equal([97, 98, 99], e.data)
         | 
| 117 | 
            +
                assert_equal('abc', e.data_as_str)
         | 
| 118 | 
            +
                assert_equal([MIDI::META_EVENT, MIDI::META_TEXT, 3, 97, 98, 99], e.data_as_bytes)
         | 
| 119 | 
            +
              end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
              def test_meta_event_data_assignment
         | 
| 122 | 
            +
                foobar_as_array = [102, 111, 111, 98, 97, 114]
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                e = MIDI::MetaEvent.new(MIDI::META_TEXT, [97, 98, 99])
         | 
| 125 | 
            +
                e.data = 'foobar'
         | 
| 126 | 
            +
                assert_equal('foobar', e.data_as_str)
         | 
| 127 | 
            +
                assert_equal(foobar_as_array, e.data)
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                e.data = nil
         | 
| 130 | 
            +
                e.data = foobar_as_array
         | 
| 131 | 
            +
                assert_equal('foobar', e.data_as_str)
         | 
| 132 | 
            +
                assert_equal(foobar_as_array, e.data)
         | 
| 133 | 
            +
              end
         | 
| 136 134 |  | 
| 137 135 | 
             
            end
         | 
    
        data/test/test_io.rb
    CHANGED
    
    | @@ -11,53 +11,40 @@ require 'event_equality' | |
| 11 11 |  | 
| 12 12 | 
             
            class IOTester < Test::Unit::TestCase
         | 
| 13 13 |  | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
                 | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
                 | 
| 35 | 
            -
             | 
| 36 | 
            -
                 | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
            	puts '    comparing sequences' if $DEBUG
         | 
| 51 | 
            -
            	compare_sequences(seq0, seq1)
         | 
| 52 | 
            -
                  ensure
         | 
| 53 | 
            -
            	File.delete(OUTPUT_FILE) if File.exist?(OUTPUT_FILE)
         | 
| 54 | 
            -
                end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                def test_read_strings
         | 
| 57 | 
            -
            	seq = MIDI::Sequence.new
         | 
| 58 | 
            -
            	File.open(SEQ_TEST_FILE, 'rb') { |f| seq.read(f) }
         | 
| 59 | 
            -
            	assert_equal('Sequence Name', seq.tracks[0].name)
         | 
| 60 | 
            -
            	assert_equal(MIDI::GM_PATCH_NAMES[0], seq.tracks[1].instrument)
         | 
| 61 | 
            -
                end
         | 
| 14 | 
            +
              SEQ_TEST_FILE = File.join(File.dirname(__FILE__), 'test.mid')
         | 
| 15 | 
            +
              OUTPUT_FILE = 'testout.mid'
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def compare_tracks(t0, t1)
         | 
| 18 | 
            +
                assert_equal(t0.name, t1.name, 'track names differ')
         | 
| 19 | 
            +
                assert_equal(t0.events.length, t1.events.length,
         | 
| 20 | 
            +
                             'number of track events differ')
         | 
| 21 | 
            +
                t0.each_with_index { |ev0, i| assert_equal(ev0, t1.events[i], 'events differ') }
         | 
| 22 | 
            +
                assert_equal(t0.instrument, t1.instrument)
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def compare_sequences(s0, s1)
         | 
| 26 | 
            +
                assert_equal(s0.name, s1.name, 'sequence names differ')
         | 
| 27 | 
            +
                assert_equal(s0.tracks.length, s1.tracks.length,
         | 
| 28 | 
            +
                             'number of tracks differ')
         | 
| 29 | 
            +
                s0.each_with_index { |track0, i| compare_tracks(track0, s1.tracks[i]) }
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              def test_read_and_write
         | 
| 33 | 
            +
                seq0 = MIDI::Sequence.new()
         | 
| 34 | 
            +
                File.open(SEQ_TEST_FILE, 'rb') { |f| seq0.read(f) }
         | 
| 35 | 
            +
                File.open(OUTPUT_FILE, 'wb') { |f| seq0.write(f) }
         | 
| 36 | 
            +
                seq1 = MIDI::Sequence.new()
         | 
| 37 | 
            +
                File.open(OUTPUT_FILE, 'rb') { |f| seq1.read(f) }
         | 
| 38 | 
            +
                compare_sequences(seq0, seq1)
         | 
| 39 | 
            +
              ensure
         | 
| 40 | 
            +
                File.delete(OUTPUT_FILE) if File.exist?(OUTPUT_FILE)
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              def test_read_strings
         | 
| 44 | 
            +
                seq = MIDI::Sequence.new
         | 
| 45 | 
            +
                File.open(SEQ_TEST_FILE, 'rb') { |f| seq.read(f) }
         | 
| 46 | 
            +
                assert_equal('Sequence Name', seq.tracks[0].name)
         | 
| 47 | 
            +
                assert_equal(MIDI::GM_PATCH_NAMES[0], seq.tracks[1].instrument)
         | 
| 48 | 
            +
              end
         | 
| 62 49 |  | 
| 63 50 | 
             
            end
         |