surface_master 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_device.rb CHANGED
@@ -1,505 +1,316 @@
1
1
  require "helper"
2
2
 
3
3
  describe SurfaceMaster::Launchpad::Device do
4
-
5
- CONTROL_BUTTONS = {
6
- :up => 0x68,
7
- :down => 0x69,
8
- :left => 0x6A,
9
- :right => 0x6B,
10
- :session => 0x6C,
11
- :user1 => 0x6D,
12
- :user2 => 0x6E,
13
- :mixer => 0x6F
14
- }
15
- SCENE_BUTTONS = {
16
- :scene1 => 0x08,
17
- :scene2 => 0x18,
18
- :scene3 => 0x28,
19
- :scene4 => 0x38,
20
- :scene5 => 0x48,
21
- :scene6 => 0x58,
22
- :scene7 => 0x68,
23
- :scene8 => 0x78
24
- }
25
- COLORS = {
26
- nil => 0, 0 => 0, :off => 0,
27
- 1 => 1, :lo => 1, :low => 1,
28
- 2 => 2, :med => 2, :medium => 2,
29
- 3 => 3, :hi => 3, :high => 3
30
- }
31
- STATES = {
32
- :down => 127,
33
- :up => 0
34
- }
35
-
36
- def expects_output(device, *args)
37
- args = [args] unless args.first.is_a?(Array)
38
- messages = args.collect {|data| {:message => data, :timestamp => 0}}
39
- device.instance_variable_get('@output').expects(:write).with(messages)
4
+ CONTROL_BUTTONS = { up: 0x68,
5
+ down: 0x69,
6
+ left: 0x6A,
7
+ right: 0x6B,
8
+ session: 0x6C,
9
+ user1: 0x6D,
10
+ user2: 0x6E,
11
+ mixer: 0x6F }
12
+ SCENE_BUTTONS = { scene1: 0x59,
13
+ scene2: 0x4F,
14
+ scene3: 0x45,
15
+ scene4: 0x3B,
16
+ scene5: 0x31,
17
+ scene6: 0x27,
18
+ scene7: 0x1D,
19
+ scene8: 0x13 }
20
+ STATES = { down: 127,
21
+ up: 0 }
22
+
23
+ def expects_output(device, args)
24
+ messages = args.map { |data| device.send(:sysex_prefix) + data + [device.send(:sysex_suffix)] }
25
+ device.instance_variable_get("@output").expects(write_sysex: messages)
40
26
  end
41
27
 
42
28
  def stub_input(device, *args)
43
- device.instance_variable_get('@input').stubs(:read).returns(args)
29
+ device.instance_variable_get("@input").stubs(:read).returns(args)
44
30
  end
45
31
 
46
32
  describe '#initialize' do
47
-
48
- it 'tries to initialize both input and output when not specified' do
33
+ it "tries to initialize both input and output when not specified" do
49
34
  Portmidi.expects(:input_devices).returns(mock_devices)
50
35
  Portmidi.expects(:output_devices).returns(mock_devices)
51
- d = Launchpad::Device.new
52
- refute_nil d.instance_variable_get('@input')
53
- refute_nil d.instance_variable_get('@output')
36
+ d = SurfaceMaster::Launchpad::Device.new
37
+ refute_nil d.instance_variable_get("@input")
38
+ refute_nil d.instance_variable_get("@output")
54
39
  end
55
40
 
56
- it 'does not try to initialize input when set to false' do
41
+ it "does not try to initialize input when set to false" do
57
42
  Portmidi.expects(:input_devices).never
58
- d = Launchpad::Device.new(:input => false)
59
- assert_nil d.instance_variable_get('@input')
60
- refute_nil d.instance_variable_get('@output')
43
+ d = SurfaceMaster::Launchpad::Device.new(input: false)
44
+ assert_nil d.instance_variable_get("@input")
45
+ refute_nil d.instance_variable_get("@output")
61
46
  end
62
47
 
63
- it 'does not try to initialize output when set to false' do
48
+ it "does not try to initialize output when set to false" do
64
49
  Portmidi.expects(:output_devices).never
65
- d = Launchpad::Device.new(:output => false)
66
- refute_nil d.instance_variable_get('@input')
67
- assert_nil d.instance_variable_get('@output')
50
+ d = SurfaceMaster::Launchpad::Device.new(output: false)
51
+ refute_nil d.instance_variable_get("@input")
52
+ assert_nil d.instance_variable_get("@output")
68
53
  end
69
54
 
70
- it 'does not try to initialize any of both when set to false' do
55
+ it "does not try to initialize any of both when set to false" do
71
56
  Portmidi.expects(:input_devices).never
72
57
  Portmidi.expects(:output_devices).never
73
- d = Launchpad::Device.new(:input => false, :output => false)
74
- assert_nil d.instance_variable_get('@input')
75
- assert_nil d.instance_variable_get('@output')
58
+ d = SurfaceMaster::Launchpad::Device.new(input: false, output: false)
59
+ assert_nil d.instance_variable_get("@input")
60
+ assert_nil d.instance_variable_get("@output")
76
61
  end
77
62
 
78
- it 'initializes the correct input output devices when specified by name' do
79
- Portmidi.stubs(:input_devices).returns(mock_devices(:id => 4, :name => 'Launchpad Name'))
80
- Portmidi.stubs(:output_devices).returns(mock_devices(:id => 5, :name => 'Launchpad Name'))
81
- d = Launchpad::Device.new(:device_name => 'Launchpad Name')
82
- assert_equal Portmidi::Input, (input = d.instance_variable_get('@input')).class
63
+ it "initializes the correct input output devices when specified by name" do
64
+ Portmidi.stubs(:input_devices).returns(mock_devices(id: 4, name: "Launchpad Name"))
65
+ Portmidi.stubs(:output_devices).returns(mock_devices(id: 5, name: "Launchpad Name"))
66
+ d = SurfaceMaster::Launchpad::Device.new(device_name: "Launchpad Name")
67
+ assert_equal Portmidi::Input, (input = d.instance_variable_get("@input")).class
83
68
  assert_equal 4, input.device_id
84
- assert_equal Portmidi::Output, (output = d.instance_variable_get('@output')).class
69
+ assert_equal Portmidi::Output, (output = d.instance_variable_get("@output")).class
85
70
  assert_equal 5, output.device_id
86
71
  end
87
72
 
88
- it 'initializes the correct input output devices when specified by id' do
89
- Portmidi.stubs(:input_devices).returns(mock_devices(:id => 4))
90
- Portmidi.stubs(:output_devices).returns(mock_devices(:id => 5))
91
- d = Launchpad::Device.new(:input_device_id => 4, :output_device_id => 5, :device_name => 'nonexistant')
92
- assert_equal Portmidi::Input, (input = d.instance_variable_get('@input')).class
73
+ it "initializes the correct input output devices when specified by id" do
74
+ Portmidi.stubs(:input_devices).returns(mock_devices(id: 4))
75
+ Portmidi.stubs(:output_devices).returns(mock_devices(id: 5))
76
+ d = SurfaceMaster::Launchpad::Device.new(input_device_id: 4,
77
+ output_device_id: 5,
78
+ device_name: "nonexistant")
79
+ assert_equal Portmidi::Input, (input = d.instance_variable_get("@input")).class
93
80
  assert_equal 4, input.device_id
94
- assert_equal Portmidi::Output, (output = d.instance_variable_get('@output')).class
81
+ assert_equal Portmidi::Output, (output = d.instance_variable_get("@output")).class
95
82
  assert_equal 5, output.device_id
96
83
  end
97
84
 
98
- it 'raises NoSuchDeviceError when requested input device does not exist' do
99
- assert_raises Launchpad::NoSuchDeviceError do
100
- Portmidi.stubs(:input_devices).returns(mock_devices(:name => 'Launchpad Input'))
101
- Launchpad::Device.new
85
+ it "raises NoSuchDeviceError when requested input device does not exist" do
86
+ assert_raises SurfaceMaster::NoSuchDeviceError do
87
+ Portmidi.stubs(:input_devices).returns(mock_devices(name: "Launchpad Input"))
88
+ SurfaceMaster::Launchpad::Device.new
102
89
  end
103
90
  end
104
91
 
105
- it 'raises NoSuchDeviceError when requested output device does not exist' do
106
- assert_raises Launchpad::NoSuchDeviceError do
107
- Portmidi.stubs(:output_devices).returns(mock_devices(:name => 'Launchpad Output'))
108
- Launchpad::Device.new
92
+ it "raises NoSuchDeviceError when requested output device does not exist" do
93
+ assert_raises SurfaceMaster::NoSuchDeviceError do
94
+ Portmidi.stubs(:output_devices).returns(mock_devices(name: "Launchpad Output"))
95
+ SurfaceMaster::Launchpad::Device.new
109
96
  end
110
97
  end
111
98
 
112
- it 'raises DeviceBusyError when requested input device is busy' do
113
- assert_raises Launchpad::DeviceBusyError do
99
+ it "raises DeviceBusyError when requested input device is busy" do
100
+ assert_raises SurfaceMaster::DeviceBusyError do
114
101
  Portmidi::Input.stubs(:new).raises(RuntimeError)
115
- Launchpad::Device.new
102
+ SurfaceMaster::Launchpad::Device.new
116
103
  end
117
104
  end
118
105
 
119
- it 'raises DeviceBusyError when requested output device is busy' do
120
- assert_raises Launchpad::DeviceBusyError do
106
+ it "raises DeviceBusyError when requested output device is busy" do
107
+ assert_raises SurfaceMaster::DeviceBusyError do
121
108
  Portmidi::Output.stubs(:new).raises(RuntimeError)
122
- Launchpad::Device.new
109
+ SurfaceMaster::Launchpad::Device.new
123
110
  end
124
111
  end
125
112
 
126
- it 'stores the logger given' do
113
+ it "stores the logger given" do
127
114
  logger = Logger.new(nil)
128
- device = Launchpad::Device.new(:logger => logger)
115
+ device = SurfaceMaster::Launchpad::Device.new(logger: logger)
129
116
  assert_same logger, device.logger
130
117
  end
131
-
132
118
  end
133
119
 
134
120
  describe '#close' do
135
-
136
- it 'does not fail when neither input nor output are there' do
137
- Launchpad::Device.new(:input => false, :output => false).close
121
+ it "does not fail when neither input nor output are there" do
122
+ SurfaceMaster::Launchpad::Device.new(input: false, output: false).close
138
123
  end
139
124
 
140
- describe 'with input and output devices' do
141
-
125
+ describe "with input and output devices" do
142
126
  before do
143
- Portmidi::Input.stubs(:new).returns(@input = mock('input'))
144
- Portmidi::Output.stubs(:new).returns(@output = mock('output', :write => nil))
145
- @device = Launchpad::Device.new
127
+ Portmidi::Input.stubs(:new).returns(@input = mock("input"))
128
+ Portmidi::Output.stubs(:new).returns(@output = mock("output"))
129
+ @device = SurfaceMaster::Launchpad::Device.new
146
130
  end
147
131
 
148
- it 'closes input/output and raise NoInputAllowedError/NoOutputAllowedError on subsequent read/write accesses' do
132
+ it "closes input/output, and raises No<x>AllowedError on subsequent accesses" do
149
133
  @input.expects(:close)
150
134
  @output.expects(:close)
151
135
  @device.close
152
- assert_raises Launchpad::NoInputAllowedError do
153
- @device.read_pending_actions
136
+ assert_raises SurfaceMaster::NoInputAllowedError do
137
+ @device.read
154
138
  end
155
- assert_raises Launchpad::NoOutputAllowedError do
156
- @device.change(:session)
139
+ assert_raises SurfaceMaster::NoOutputAllowedError do
140
+ @device.change(cc: :mixer, red: 0x00, green: 0x00, blue: 0x00)
157
141
  end
158
142
  end
159
-
160
143
  end
161
-
162
144
  end
163
145
 
164
146
  describe '#closed?' do
165
-
166
- it 'returns true when neither input nor output are there' do
167
- assert Launchpad::Device.new(:input => false, :output => false).closed?
147
+ it "returns true when neither input nor output are there" do
148
+ assert SurfaceMaster::Launchpad::Device.new(input: false, output: false).closed?
168
149
  end
169
150
 
170
- it 'returns false when initialized with input' do
171
- assert !Launchpad::Device.new(:input => true, :output => false).closed?
151
+ it "returns false when initialized with input" do
152
+ assert !SurfaceMaster::Launchpad::Device.new(input: true, output: false).closed?
172
153
  end
173
154
 
174
- it 'returns false when initialized with output' do
175
- assert !Launchpad::Device.new(:input => false, :output => true).closed?
155
+ it "returns false when initialized with output" do
156
+ assert !SurfaceMaster::Launchpad::Device.new(input: false, output: true).closed?
176
157
  end
177
158
 
178
- it 'returns false when initialized with both but true after calling close' do
179
- d = Launchpad::Device.new
159
+ it "returns false when initialized with both but true after calling close" do
160
+ d = SurfaceMaster::Launchpad::Device.new
180
161
  assert !d.closed?
181
162
  d.close
182
163
  assert d.closed?
183
164
  end
184
-
185
165
  end
186
166
 
187
- {
188
- :reset => [0xB0, 0x00, 0x00],
189
- :flashing_on => [0xB0, 0x00, 0x20],
190
- :flashing_off => [0xB0, 0x00, 0x21],
191
- :flashing_auto => [0xB0, 0x00, 0x28]
167
+ { reset: [[0x22, 0x00],
168
+ [0xB0, 0x00, 0x00]],
169
+ # flashing_on: [0xB0, 0x00, 0x20],
170
+ # flashing_off: [0xB0, 0x00, 0x21],
171
+ # flashing_auto: [0xB0, 0x00, 0x28],
192
172
  }.each do |method, codes|
193
173
  describe "##{method}" do
194
-
195
- it 'raises NoOutputAllowedError when not initialized with output' do
196
- assert_raises Launchpad::NoOutputAllowedError do
197
- Launchpad::Device.new(:output => false).send(method)
174
+ it "raises NoOutputAllowedError when not initialized with output" do
175
+ assert_raises SurfaceMaster::NoOutputAllowedError do
176
+ SurfaceMaster::Launchpad::Device.new(output: false).send(method)
198
177
  end
199
178
  end
200
179
 
201
180
  it "sends #{codes.inspect}" do
202
- d = Launchpad::Device.new
203
- expects_output(d, *codes)
181
+ d = SurfaceMaster::Launchpad::Device.new
182
+ expects_output(d, codes)
204
183
  d.send(method)
205
184
  end
206
-
207
- end
208
- end
209
-
210
- describe '#test_leds' do
211
-
212
- it 'raises NoOutputAllowedError when not initialized with output' do
213
- assert_raises Launchpad::NoOutputAllowedError do
214
- Launchpad::Device.new(:output => false).test_leds
215
- end
216
- end
217
-
218
- describe 'initialized with output' do
219
-
220
- before do
221
- @device = Launchpad::Device.new(:input => false)
222
- end
223
-
224
- it 'returns nil' do
225
- assert_nil @device.test_leds
226
- end
227
-
228
- COLORS.merge(nil => 3).each do |name, value|
229
- if value == 0
230
- it "sends 0xB0, 0x00, 0x00 when given #{name}" do
231
- expects_output(@device, 0xB0, 0x00, 0x00)
232
- @device.test_leds(value)
233
- end
234
- else
235
- it "sends 0xB0, 0x00, 0x7C + #{value} when given #{name}" do
236
- d = Launchpad::Device.new
237
- expects_output(@device, 0xB0, 0x00, 0x7C + value)
238
- value.nil? ? @device.test_leds : @device.test_leds(value)
239
- end
240
- end
241
- end
242
-
243
185
  end
244
-
245
186
  end
246
187
 
247
188
  describe '#change' do
248
-
249
- it 'raises NoOutputAllowedError when not initialized with output' do
250
- assert_raises Launchpad::NoOutputAllowedError do
251
- Launchpad::Device.new(:output => false).change(:up)
189
+ it "raises NoOutputAllowedError when not initialized with output" do
190
+ assert_raises SurfaceMaster::NoOutputAllowedError do
191
+ SurfaceMaster::Launchpad::Device.new(output: false)
192
+ .change(cc: :mixer, red: 0x00, green: 0x00, blue: 0x00)
252
193
  end
253
194
  end
254
195
 
255
- describe 'initialized with output' do
256
-
196
+ describe "initialized with output" do
257
197
  before do
258
- @device = Launchpad::Device.new(:input => false)
198
+ @device = SurfaceMaster::Launchpad::Device.new(input: false)
259
199
  end
260
200
 
261
- it 'returns nil' do
262
- assert_nil @device.change(:up)
201
+ it "returns nil" do
202
+ assert_nil @device.change(cc: :mixer, red: 0x00, green: 0x00, blue: 0x00)
263
203
  end
264
204
 
265
- describe 'control buttons' do
205
+ describe "control buttons" do
266
206
  CONTROL_BUTTONS.each do |type, value|
267
- it "sends 0xB0, #{value}, 12 when given #{type}" do
268
- expects_output(@device, 0xB0, value, 12)
269
- @device.change(type)
207
+ input = { cc: type, red: 0x01, green: 0x02, blue: 0x03 }
208
+ output = [0x0B, value, 0x01, 0x02, 0x03]
209
+ it "sends #{output.inspect} when given #{input.inspect}" do
210
+ expects_output(@device, [output])
211
+ @device.change(input)
270
212
  end
271
213
  end
272
214
  end
273
215
 
274
- describe 'scene buttons' do
216
+ describe "scene buttons" do
275
217
  SCENE_BUTTONS.each do |type, value|
276
- it "sends 0x90, #{value}, 12 when given #{type}" do
277
- expects_output(@device, 0x90, value, 12)
278
- @device.change(type)
218
+ input = { cc: type, red: 0x01, green: 0x02, blue: 0x03 }
219
+ output = [0x0B, value, 0x01, 0x02, 0x03]
220
+ it "sends #{output.inspect} when given #{input.inspect}" do
221
+ expects_output(@device, [output])
222
+ @device.change(input)
279
223
  end
280
224
  end
281
225
  end
282
226
 
283
- describe 'grid buttons' do
227
+ describe "grid buttons" do
284
228
  8.times do |x|
285
229
  8.times do |y|
286
- it "sends 0x90, #{16 * y + x}, 12 when given :grid, :x => #{x}, :y => #{y}" do
287
- expects_output(@device, 0x90, 16 * y + x, 12)
288
- @device.change(:grid, :x => x, :y => y)
289
- end
290
- end
291
- end
292
-
293
- it 'raises NoValidGridCoordinatesError if x is not specified' do
294
- assert_raises Launchpad::NoValidGridCoordinatesError do
295
- @device.change(:grid, :y => 1)
296
- end
297
- end
298
-
299
- it 'raises NoValidGridCoordinatesError if x is below 0' do
300
- assert_raises Launchpad::NoValidGridCoordinatesError do
301
- @device.change(:grid, :x => -1, :y => 1)
302
- end
303
- end
304
-
305
- it 'raises NoValidGridCoordinatesError if x is above 7' do
306
- assert_raises Launchpad::NoValidGridCoordinatesError do
307
- @device.change(:grid, :x => 8, :y => 1)
308
- end
309
- end
310
-
311
- it 'raises NoValidGridCoordinatesError if y is not specified' do
312
- assert_raises Launchpad::NoValidGridCoordinatesError do
313
- @device.change(:grid, :x => 1)
314
- end
315
- end
316
-
317
- it 'raises NoValidGridCoordinatesError if y is below 0' do
318
- assert_raises Launchpad::NoValidGridCoordinatesError do
319
- @device.change(:grid, :x => 1, :y => -1)
320
- end
321
- end
230
+ input = { grid: [x, y], red: 0x01, green: 0x02, blue: 0x03 }
231
+ output = [0x0B, 10 * y + x + 11, 0x01, 0x02, 0x03]
322
232
 
323
- it 'raises NoValidGridCoordinatesError if y is above 7' do
324
- assert_raises Launchpad::NoValidGridCoordinatesError do
325
- @device.change(:grid, :x => 1, :y => 8)
326
- end
327
- end
328
-
329
- end
330
-
331
- describe 'colors' do
332
- COLORS.each do |red_key, red_value|
333
- COLORS.each do |green_key, green_value|
334
- it "sends 0x90, 0, #{16 * green_value + red_value + 12} when given :red => #{red_key}, :green => #{green_key}" do
335
- expects_output(@device, 0x90, 0, 16 * green_value + red_value + 12)
336
- @device.change(:grid, :x => 0, :y => 0, :red => red_key, :green => green_key)
233
+ it "sends #{output.inspect} when given #{input.inspect}" do
234
+ expects_output(@device, [output])
235
+ @device.change(input)
337
236
  end
338
237
  end
339
238
  end
340
239
 
341
- it 'raises NoValidBrightnessError if red is below 0' do
342
- assert_raises Launchpad::NoValidBrightnessError do
343
- @device.change(:grid, :x => 0, :y => 0, :red => -1)
240
+ it "raises NoValidGridCoordinatesError if x is nil" do
241
+ assert_raises SurfaceMaster::Launchpad::NoValidGridCoordinatesError do
242
+ @device.change(grid: [nil, 1], red: 0x01, green: 0x02, blue: 0x03)
344
243
  end
345
244
  end
346
245
 
347
- it 'raises NoValidBrightnessError if red is above 3' do
348
- assert_raises Launchpad::NoValidBrightnessError do
349
- @device.change(:grid, :x => 0, :y => 0, :red => 4)
246
+ it "raises NoValidGridCoordinatesError if it only gets one coordinate" do
247
+ assert_raises SurfaceMaster::Launchpad::NoValidGridCoordinatesError do
248
+ @device.change(grid: [1], red: 0x01, green: 0x02, blue: 0x03)
350
249
  end
351
250
  end
352
251
 
353
- it 'raises NoValidBrightnessError if red is an unknown symbol' do
354
- assert_raises Launchpad::NoValidBrightnessError do
355
- @device.change(:grid, :x => 0, :y => 0, :red => :unknown)
252
+ it "raises NoValidGridCoordinatesError if x is below 0" do
253
+ assert_raises SurfaceMaster::Launchpad::NoValidGridCoordinatesError do
254
+ @device.change(grid: [-1, 1], red: 0x01, green: 0x02, blue: 0x03)
356
255
  end
357
256
  end
358
257
 
359
- it 'raises NoValidBrightnessError if green is below 0' do
360
- assert_raises Launchpad::NoValidBrightnessError do
361
- @device.change(:grid, :x => 0, :y => 0, :green => -1)
258
+ it "raises NoValidGridCoordinatesError if x is above 7" do
259
+ assert_raises SurfaceMaster::Launchpad::NoValidGridCoordinatesError do
260
+ @device.change(grid: [8, 1], red: 0x01, green: 0x02, blue: 0x03)
362
261
  end
363
262
  end
364
263
 
365
- it 'raises NoValidBrightnessError if green is above 3' do
366
- assert_raises Launchpad::NoValidBrightnessError do
367
- @device.change(:grid, :x => 0, :y => 0, :green => 4)
264
+ it "raises NoValidGridCoordinatesError if y is nil" do
265
+ assert_raises SurfaceMaster::Launchpad::NoValidGridCoordinatesError do
266
+ @device.change(grid: [1, nil], red: 0x01, green: 0x02, blue: 0x03)
368
267
  end
369
268
  end
370
269
 
371
- it 'raises NoValidBrightnessError if green is an unknown symbol' do
372
- assert_raises Launchpad::NoValidBrightnessError do
373
- @device.change(:grid, :x => 0, :y => 0, :green => :unknown)
270
+ it "raises NoValidGridCoordinatesError if y is below 0" do
271
+ assert_raises SurfaceMaster::Launchpad::NoValidGridCoordinatesError do
272
+ @device.change(grid: [1, -1], red: 0x01, green: 0x02, blue: 0x03)
374
273
  end
375
274
  end
376
275
 
377
- end
378
-
379
- describe 'mode' do
380
-
381
- it 'sends color + 12 when nothing given' do
382
- expects_output(@device, 0x90, 0, 12)
383
- @device.change(:grid, :x => 0, :y => 0, :red => 0, :green => 0)
384
- end
385
-
386
- it 'sends color + 12 when given :normal' do
387
- expects_output(@device, 0x90, 0, 12)
388
- @device.change(:grid, :x => 0, :y => 0, :red => 0, :green => 0, :mode => :normal)
389
- end
390
-
391
- it 'sends color + 8 when given :flashing' do
392
- expects_output(@device, 0x90, 0, 8)
393
- @device.change(:grid, :x => 0, :y => 0, :red => 0, :green => 0, :mode => :flashing)
394
- end
395
-
396
- it 'sends color when given :buffering' do
397
- expects_output(@device, 0x90, 0, 0)
398
- @device.change(:grid, :x => 0, :y => 0, :red => 0, :green => 0, :mode => :buffering)
276
+ it "raises NoValidGridCoordinatesError if y is above 7" do
277
+ assert_raises SurfaceMaster::Launchpad::NoValidGridCoordinatesError do
278
+ @device.change(grid: [1, 8], red: 0x01, green: 0x02, blue: 0x03)
279
+ end
399
280
  end
400
-
401
- end
402
-
403
- end
404
-
405
- end
406
-
407
- describe '#change_all' do
408
-
409
- it 'raises NoOutputAllowedError when not initialized with output' do
410
- assert_raises Launchpad::NoOutputAllowedError do
411
- Launchpad::Device.new(:output => false).change_all
412
- end
413
- end
414
-
415
- describe 'initialized with output' do
416
-
417
- before do
418
- @device = Launchpad::Device.new(:input => false)
419
- end
420
-
421
- it 'returns nil' do
422
- assert_nil @device.change_all([0])
423
- end
424
-
425
- it 'fills colors with 0, set grid layout to XY and flush colors' do
426
- expects_output(@device, 0xB0, 0, 0x01)
427
- expects_output(@device, *([[0x92, 17, 17]] * 20 + [[0x92, 12, 12]] * 20))
428
- @device.change_all([5] * 40)
429
281
  end
430
-
431
- it 'cuts off exceeding colors, set grid layout to XY and flush colors' do
432
- expects_output(@device, 0xB0, 0, 0x01)
433
- expects_output(@device, *([[0x92, 17, 17]] * 40))
434
- @device.change_all([5] * 100)
435
- end
436
-
437
282
  end
438
-
439
283
  end
440
284
 
441
- describe '#buffering_mode' do
442
-
443
- it 'raises NoOutputAllowedError when not initialized with output' do
444
- assert_raises Launchpad::NoOutputAllowedError do
445
- Launchpad::Device.new(:output => false).buffering_mode
285
+ describe '#read' do
286
+ it "raises NoInputAllowedError when not initialized with input" do
287
+ assert_raises SurfaceMaster::NoInputAllowedError do
288
+ SurfaceMaster::Launchpad::Device.new(input: false).read
446
289
  end
447
290
  end
448
291
 
449
- {
450
- nil => [0xB0, 0x00, 0x20],
451
- {} => [0xB0, 0x00, 0x20],
452
- {:display_buffer => 1} => [0xB0, 0x00, 0x21],
453
- {:update_buffer => 1} => [0xB0, 0x00, 0x24],
454
- {:copy => true} => [0xB0, 0x00, 0x30],
455
- {:flashing => true} => [0xB0, 0x00, 0x28],
456
- {
457
- :display_buffer => 1,
458
- :update_buffer => 1,
459
- :copy => true,
460
- :flashing => true
461
- } => [0xB0, 0x00, 0x3D]
462
- }.each do |opts, codes|
463
- it "sends #{codes.inspect} when called with #{opts.inspect}" do
464
- d = Launchpad::Device.new
465
- expects_output(d, *codes)
466
- d.buffering_mode(opts)
467
- end
468
- end
469
-
470
- end
471
-
472
- describe '#read_pending_actions' do
473
-
474
- it 'raises NoInputAllowedError when not initialized with input' do
475
- assert_raises Launchpad::NoInputAllowedError do
476
- Launchpad::Device.new(:input => false).read_pending_actions
477
- end
478
- end
479
-
480
- describe 'initialized with input' do
481
-
292
+ describe "initialized with input" do
482
293
  before do
483
- @device = Launchpad::Device.new(:output => false)
294
+ @device = SurfaceMaster::Launchpad::Device.new(output: false)
484
295
  end
485
296
 
486
- describe 'control buttons' do
297
+ describe "control buttons" do
487
298
  CONTROL_BUTTONS.each do |type, value|
488
299
  STATES.each do |state, velocity|
489
300
  it "builds proper action for control button #{type}, #{state}" do
490
- stub_input(@device, {:timestamp => 0, :message => [0xB0, value, velocity]})
491
- assert_equal [{:timestamp => 0, :state => state, :type => type}], @device.read_pending_actions
301
+ stub_input(@device, timestamp: 0, message: [0xB0, value, velocity])
302
+ assert_equal [{ timestamp: 0, state: state, type: type }], @device.read
492
303
  end
493
304
  end
494
305
  end
495
306
  end
496
307
 
497
- describe 'scene buttons' do
308
+ describe "scene buttons" do
498
309
  SCENE_BUTTONS.each do |type, value|
499
310
  STATES.each do |state, velocity|
500
311
  it "builds proper action for scene button #{type}, #{state}" do
501
- stub_input(@device, {:timestamp => 0, :message => [0x90, value, velocity]})
502
- assert_equal [{:timestamp => 0, :state => state, :type => type}], @device.read_pending_actions
312
+ stub_input(@device, timestamp: 0, message: [0x90, value, velocity])
313
+ assert_equal [{ timestamp: 0, state: state, type: type }], @device.read
503
314
  end
504
315
  end
505
316
  end
@@ -510,21 +321,22 @@ describe SurfaceMaster::Launchpad::Device do
510
321
  8.times do |y|
511
322
  STATES.each do |state, velocity|
512
323
  it "builds proper action for grid button #{x},#{y}, #{state}" do
513
- stub_input(@device, {:timestamp => 0, :message => [0x90, 16 * y + x, velocity]})
514
- assert_equal [{:timestamp => 0, :state => state, :type => :grid, :x => x, :y => y}], @device.read_pending_actions
324
+ stub_input(@device, timestamp: 0, message: [0x90, 10 * y + x + 11, velocity])
325
+ assert_equal [{ timestamp: 0, state: state, type: :grid, x: x, y: y }], @device.read
515
326
  end
516
327
  end
517
328
  end
518
329
  end
519
330
  end
520
331
 
521
- it 'builds proper actions for multiple pending actions' do
522
- stub_input(@device, {:timestamp => 1, :message => [0x90, 0, 127]}, {:timestamp => 2, :message => [0xB0, 0x68, 0]})
523
- assert_equal [{:timestamp => 1, :state => :down, :type => :grid, :x => 0, :y => 0}, {:timestamp => 2, :state => :up, :type => :up}], @device.read_pending_actions
332
+ it "builds proper actions for multiple pending actions" do
333
+ TEST_MESSAGES = [{ timestamp: 1, message: [0x90, 0x0B, 0x7F] },
334
+ { timestamp: 2, message: [0xB0, 0x68, 0x00] }]
335
+ TEST_OUTPUTS = [{ timestamp: 1, state: :down, type: :grid, x: 0, y: 0 },
336
+ { timestamp: 2, state: :up, type: :up }]
337
+ stub_input(@device, *TEST_MESSAGES)
338
+ assert_equal TEST_OUTPUTS, @device.read
524
339
  end
525
-
526
340
  end
527
-
528
341
  end
529
-
530
342
  end