Skip to content

Commit b787c1a

Browse files
committed
Supports MIDI Realtime clock
1 parent 12e6f7b commit b787c1a

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

test/tests/midi_test.rb

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2+
class Machine
3+
def self.board_millis
4+
1000
5+
end
6+
end
7+
8+
class MIDI
9+
attr_accessor :play_status, :previous_clock_time, :duration_per_clock
10+
end
11+
112
class MidiTest < MrubycTestCase
213
def setup
314
@midi = MIDI.new
@@ -18,20 +29,63 @@ def note_off_with_nil_velocity_case
1829
end
1930

2031
description "task_when_chord_mode_on_with_major"
21-
def convert_chord_pattern_with_major
32+
def convert_chord_pattern_with_major_case
2233
assert_equal [0, 4, 7], @midi.convert_chord_pattern(0)
2334
end
2435

25-
def convert_toggle_chord_pattern
36+
description "toggle_chord_pattern_up_and_down"
37+
def toggle_chord_pattern_case
2638
# major -> major7th
27-
@midi.update_event(MIDI::KEYCODE[:MI_CRDNPTN], :press)
28-
@midi.process_request(MIDI::KEYCODE[:MI_CRDNPTN], {})
39+
@midi.update_event(MIDI::KEYCODE[:MI_NEXTCRD], :press)
40+
@midi.process_request(MIDI::KEYCODE[:MI_NEXTCRD], {})
2941
assert_equal :major7th, @midi.chord_pattern
3042

43+
# major7th -> major
44+
@midi.update_event(MIDI::KEYCODE[:MI_PREVCRD], :press)
45+
@midi.process_request(MIDI::KEYCODE[:MI_PREVCRD], {})
46+
assert_equal :major, @midi.chord_pattern
47+
3148
# augmented7th -> major
3249
@midi.chord_pattern = :augmented7th
33-
@midi.update_event(MIDI::KEYCODE[:MI_CRDNPTN], :press)
34-
@midi.process_request(MIDI::KEYCODE[:MI_CRDNPTN], {})
50+
@midi.update_event(MIDI::KEYCODE[:MI_NEXTCRD], :press)
51+
@midi.process_request(MIDI::KEYCODE[:MI_NEXTCRD], {})
3552
assert_equal :major, @midi.chord_pattern
53+
54+
# major -> augmented7th
55+
@midi.update_event(MIDI::KEYCODE[:MI_PREVCRD], :press)
56+
@midi.process_request(MIDI::KEYCODE[:MI_PREVCRD], {})
57+
assert_equal :augmented7th, @midi.chord_pattern
58+
end
59+
60+
description "midi realtime clock stop"
61+
def send_midi_realtime_clock_stop_case
62+
# @play_status :stop
63+
@midi.play_status = :stop
64+
@midi.send_srt_clock
65+
assert_equal [], @midi.instance_variable_get("@buffer")
66+
end
67+
68+
description "midi realtime clock start first time"
69+
def send_midi_realtime_clock_first_time_case
70+
@midi.play_status = :start
71+
@midi.previous_clock_time = nil
72+
@midi.send_srt_clock
73+
assert_equal 1000, @midi.previous_clock_time
74+
assert_equal [[MIDI::SRT_TIMING_CLOCK]], @midi.instance_variable_get("@buffer")
75+
end
76+
77+
description "midi realtime clock start 2nd time"
78+
def send_midi_realtime_clock_2nd_time_case
79+
@midi.play_status = :start
80+
@midi.previous_clock_time = 500
81+
@midi.duration_per_clock = 150
82+
@midi.send_srt_clock
83+
# send midi clock 3 times
84+
assert_equal [
85+
[MIDI::SRT_TIMING_CLOCK],
86+
[MIDI::SRT_TIMING_CLOCK],
87+
[MIDI::SRT_TIMING_CLOCK]
88+
], @midi.instance_variable_get("@buffer")
89+
assert_equal 950, @midi.previous_clock_time
3690
end
3791
end

0 commit comments

Comments
 (0)