|
| 1 | +class Mml2midiTest < MrubycTestCase |
| 2 | + def setup |
| 3 | + @data = Array.new |
| 4 | + end |
| 5 | + |
| 6 | + ######################################### |
| 7 | + |
| 8 | + description "Just an A" |
| 9 | + def basic_case |
| 10 | + duration = MML2MIDI.new.compile("a") { |p, d| @data << [p, d] } |
| 11 | + assert_equal [[0, [:note, 69, 4]]], @data |
| 12 | + assert_equal 4, duration |
| 13 | + end |
| 14 | + |
| 15 | + description "A flat" |
| 16 | + def a_flat_case |
| 17 | + duration = MML2MIDI.new.compile("AA-") { |p, d| @data << [p, d] } |
| 18 | + assert_equal [[0, [:note, 69, 4]], [4, [:note, 68, 4]]], @data |
| 19 | + assert_equal 8, duration |
| 20 | + end |
| 21 | + |
| 22 | + description "C flat" |
| 23 | + def c_flat_case |
| 24 | + duration = MML2MIDI.new.compile("CC-") { |p, d| @data << [p, d] } |
| 25 | + assert_equal [[0, [:note, 60, 4]], [4, [:note, 59, 4]]], @data |
| 26 | + assert_equal 8, duration |
| 27 | + end |
| 28 | + |
| 29 | + description "Change tempo" |
| 30 | + def tempo_case |
| 31 | + duration = MML2MIDI.new.compile("T240a") { |p, d| @data << [p, d] } |
| 32 | + assert_equal [[0, [:tempo, 240]], [0, [:note, 69, 4]]], @data |
| 33 | + assert_equal 4, duration |
| 34 | + end |
| 35 | + |
| 36 | + description "Rest octave" |
| 37 | + def rest_case |
| 38 | + duration = MML2MIDI.new.compile("ara") { |p, d| @data << [p, d] } |
| 39 | + assert_equal [[0, [:note, 69, 4]], [8, [:note, 69, 4]]], @data |
| 40 | + assert_equal 12, duration |
| 41 | + end |
| 42 | + |
| 43 | + description "Specify octave" |
| 44 | + def specify_octave_case |
| 45 | + duration = MML2MIDI.new.compile("O5aO3a") { |p, d| @data << [p, d] } |
| 46 | + assert_equal [[0, [:note, 81, 4]],[4, [:note, 57, 4]]], @data |
| 47 | + assert_equal 8, duration |
| 48 | + end |
| 49 | + |
| 50 | + description "Decrease octave" |
| 51 | + def decrease_octave_case |
| 52 | + duration = MML2MIDI.new.compile("a>a") { |p, d| @data << [p, d] } |
| 53 | + assert_equal [[0, [:note, 69, 4]],[4, [:note, 57, 4]]], @data |
| 54 | + assert_equal 8, duration |
| 55 | + end |
| 56 | + |
| 57 | + description "Increase octave" |
| 58 | + def increase_octave_case |
| 59 | + duration = MML2MIDI.new.compile("a<a") { |p, d| @data << [p, d] } |
| 60 | + assert_equal [[0, [:note, 69, 4]],[4, [:note, 81, 4]]], @data |
| 61 | + assert_equal 8, duration |
| 62 | + end |
| 63 | + |
| 64 | + description "Specify length" |
| 65 | + def specify_length_case |
| 66 | + duration = MML2MIDI.new.compile("a2a16") { |p, d| @data << [p, d] } |
| 67 | + assert_equal [[0, [:note, 69, 8]], [8, [:note, 69, 1]]], @data |
| 68 | + assert_equal 9, duration |
| 69 | + end |
| 70 | + |
| 71 | + description "Dotted note without length specified" |
| 72 | + def dotted_without_length_note_case |
| 73 | + duration = MML2MIDI.new.compile("a.a") { |p, d| @data << [p, d] } |
| 74 | + assert_equal [[0, [:note, 69, 6]],[6, [:note, 69, 4]]], @data |
| 75 | + assert_equal 10, duration |
| 76 | + end |
| 77 | + |
| 78 | + description "Dotted note with length specified" |
| 79 | + def dotted_with_length_note_case |
| 80 | + duration = MML2MIDI.new.compile("a4.") { |p, d| @data << [p, d] } |
| 81 | + assert_equal [[0, [:note, 69, 6]]], @data |
| 82 | + assert_equal 6, duration |
| 83 | + end |
| 84 | + |
| 85 | + description "Specify Q value" |
| 86 | + def q_1_case |
| 87 | + duration = MML2MIDI.new.compile("Q4aQ8a") { |p, d| @data << [p, d] } |
| 88 | + assert_equal [[0, [:note, 69, 2]], [4, [:note, 69, 4]]], @data |
| 89 | + assert_equal 8, duration |
| 90 | + end |
| 91 | + |
| 92 | + description "Rest after Q note" |
| 93 | + def q_2_case |
| 94 | + duration = MML2MIDI.new.compile("Q4a") { |p, d| @data << [p, d] } |
| 95 | + assert_equal [[0, [:note, 69, 2]]], @data |
| 96 | + assert_equal 4, duration |
| 97 | + end |
| 98 | + |
| 99 | + description "Q value of a rest" |
| 100 | + def q_rest_case |
| 101 | + duration = MML2MIDI.new.compile("Q4r") { |p, d| @data << [p, d] } |
| 102 | + assert_equal [], @data |
| 103 | + assert_equal 4, duration |
| 104 | + end |
| 105 | + |
| 106 | + description "Q rest and rest should unite" |
| 107 | + def q_note_following_rest_case |
| 108 | + duration = MML2MIDI.new.compile("Q4ar") { |p, d| @data << [p, d] } |
| 109 | + assert_equal [[0, [:note, 69, 2]]], @data |
| 110 | + assert_equal 8, duration |
| 111 | + end |
| 112 | + |
| 113 | + description "Super Mario A part" |
| 114 | + def mario_a_case |
| 115 | + [ |
| 116 | + "T200 L8 O5 Q4 e e r e r c e r g r4. > g r4.", |
| 117 | + "T200 L8 Q6 < c r4 > g r4 e r4 a r b r b- a r", |
| 118 | + "T200 L8 Q6 g6 < e6 g6 a r f g r e r c d > b r4", |
| 119 | + "T200 L8 Q6 r4 l< g g- f d+ r e r > g+ a < c r > a < c d", |
| 120 | + "T200 L8 Q6 r4 g g- f d+ r e r < c r c c r4.", |
| 121 | + "T200 L8 Q6 r4 > g g- f d+ r e r > g+ a < c r > a < c d", |
| 122 | + "T200 L8 Q6 r4 e-8 r4 d r4 c r r4 r2" |
| 123 | + ].each do |measure| |
| 124 | + duration = MML2MIDI.new.compile(measure) { |p, d| @data << [p, d] } |
| 125 | + # assert_equal 60, duration |
| 126 | + end |
| 127 | + end |
| 128 | + |
| 129 | + description "Super Mario B part" |
| 130 | + def mario_b_case |
| 131 | + [ |
| 132 | + "T200 L8 O3 Q4 d d r d r d d r g r4. > g r4.", |
| 133 | + "T200 L8 Q6 < g r4 e r4 c r4 f r g r g- f r", |
| 134 | + "T200 L8 Q6 e6 < c6 e6 f r d e r c r > a b g r4", |
| 135 | + "T200 L8 Q6 c r4 g r4 < c r > f r4 < c r4 > f r", |
| 136 | + "T200 L8 Q6 c r4 e r4 g < c r < f r f f r >> g r", |
| 137 | + "T200 L8 Q6 c r4 g r4 < c r > f r4 < c r4 > f r", |
| 138 | + "T200 L8 Q6 c r a- r4 b- r4 < c r4 > g g r c r" |
| 139 | + ].each do |measure| |
| 140 | + duration = MML2MIDI.new.compile(measure) { |p, d| @data << [p, d] } |
| 141 | + # assert_equal 48, duration |
| 142 | + end |
| 143 | + end |
| 144 | + |
| 145 | + description "Danger Zone" |
| 146 | + def danger_zone_case |
| 147 | + [ |
| 148 | + "T120 Q6 L8 r O2 c d f g4 f4 < g a r4 a4. a r4 a a a4 a4 g a r4 a4. a r4 a a < c4 c4 > Q8 g1 Q6 g1 g a r4 a4. a r4 a a a4 a4 g a r4 a4. a r4 a a a4 a4", |
| 149 | + "T120 Q6 L8 r O2 c d f g4 f4 d << d r4 d4. d >> r c d f g4 f4 d << d r4 d4. d >> r c d f g4 f4 c4. > g < c2 d c4 > g < c4 c4 d4. d d2 r c d f g4 f4 d4. d d2 r c d f g4 f4" |
| 150 | + ].each do |measure| |
| 151 | + duration = MML2MIDI.new.compile(measure) { |p, d| @data << [p, d] } |
| 152 | + # assert_equal 238, duration |
| 153 | + end |
| 154 | + end |
| 155 | +end |
0 commit comments