moony_test.lua 34.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
--[[
	Copyright (c) 2015 Hanspeter Portner (dev@open-music-kontrollers.ch)
	
	This is free software: you can redistribute it and/or modify
	it under the terms of the Artistic License 2.0 as published by
	The Perl Foundation.
	
	This source is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	Artistic License 2.0 for more details.
	
	You should have received a copy of the Artistic License 2.0
	along the source as a COPYING file. If not, obtain it from
	http://www.perlfoundation.org/artistic_license_2_0.
--]]

18 19
-- Map/unmap
print('[test] Map/unmap')
20 21 22
do
	local uri = 'http://test.org#foo'

23 24
	assert(Map[uri] == Map[uri])
	assert(Map(uri) == Map(uri))
25

26 27 28
	local urid = Map[uri]
	assert(Unmap[urid] == Unmap[urid])
	assert(Unmap(urid) == Unmap(urid))
29 30 31
end

-- Int
32
print('[test] Int')
33 34 35 36 37
do
	local function producer(forge)
		forge:frame_time(0)
		forge:int(0x7fffffff)
		
38
		forge:frame_time(0):int(0xffffffff)
39 40 41 42 43
	end

	local function consumer(seq)
		assert(#seq == 2)
		local atom = seq[1]
44
		assert(atom.type == Atom.Int)
45
		assert(#atom == 4)
46 47
		assert(type(atom.body) == 'number')
		assert(atom.body == 0x7fffffff)
48 49
		
		local atom = seq[2]
50
		assert(atom.type == Atom.Int)
51
		assert(#atom == 4)
52 53
		assert(type(atom.body) == 'number')
		assert(atom.body ~= 0xffffffff)
54 55 56 57 58
	end

	test(producer, consumer)
end

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
-- frame mismatch
print('[test] Frame mismatch')
do
	local function producer(forge)
		forge:frame_time(0)
		forge:tuple() -- would need a pop()
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
		assert(atom.type == Atom.Tuple)
	end

	test(producer, consumer)
end

76
-- Long
77
print('[test] Long')
78 79
do
	local function producer(forge)
80
		forge:frame_time(0):long(0x100000000)
81 82 83 84 85
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
86
		assert(atom.type == Atom.Long)
87
		assert(#atom == 8)
88 89
		assert(type(atom.body) == 'number')
		assert(atom.body == 0x100000000)
90 91 92 93 94 95
	end

	test(producer, consumer)
end

-- Float
96
print('[test] Float')
97 98 99 100 101 102 103 104 105
do
	local function producer(forge)
		forge:frame_time(0)
		forge:float(2.0)
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
106
		assert(atom.type == Atom.Float)
107
		assert(#atom == 4)
108 109
		assert(type(atom.body) == 'number')
		assert(atom.body == 2.0)
110 111 112 113 114 115
	end

	test(producer, consumer)
end

-- Double
116
print('[test] Double')
117 118
do
	local function producer(forge)
119
		forge:frame_time(0):double(0.12)
120 121 122 123 124
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
125
		assert(atom.type == Atom.Double)
126
		assert(#atom == 8)
127 128
		assert(type(atom.body) == 'number')
		assert(atom.body == 0.12)
129 130 131 132 133 134
	end

	test(producer, consumer)
end

-- Bool
135
print('[test] Bool')
136 137
do
	local function producer(forge)
Hanspeter Portner's avatar
Hanspeter Portner committed
138 139
		forge:beat_time(0.1):bool(true)
		forge:beat_time(0.2):bool(false)
140 141 142 143 144
	end

	local function consumer(seq)
		assert(#seq == 2)
		local atom = seq[1]
145
		assert(atom.type == Atom.Bool)
146
		assert(#atom == 4)
147 148
		assert(type(atom.body) == 'boolean')
		assert(atom.body == true)
149 150
		
		local atom = seq[2]
151
		assert(atom.type == Atom.Bool)
152
		assert(#atom == 4)
153 154 155
		assert(type(atom.body) == 'boolean')
		assert(type(atom.body) == 'boolean')
		assert(atom.body == false)
156 157 158 159 160 161
	end

	test(producer, consumer)
end

-- String
162
print('[test] String')
163 164 165 166 167 168 169 170 171 172 173
do
	local str = 'hello world'

	local function producer(forge)
		forge:frame_time(0)
		forge:string(str)
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
174
		assert(atom.type == Atom.String)
175
		assert(#atom == string.len(str) + 1)
176 177
		assert(type(atom.body) == 'string')
		assert(atom.body == str)
178 179 180 181 182 183
	end

	test(producer, consumer)
end

-- Literal
184
print('[test] Literal')
185 186
do
	local str = 'hello world'
187 188
	local datatype = Map['http://test.org#datatype']
	local lang = Map['http://test.org#lang']
189 190 191 192 193 194 195 196 197

	local function producer(forge)
		forge:frame_time(0)
		forge:literal(str, datatype, lang)
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
198
		assert(atom.type == Atom.Literal)
199
		assert(type(atom.body) == 'string')
200
		assert(#atom == 8 + string.len(str) + 1)
201
		assert(atom.body == str)
202 203
		assert(atom.datatype == datatype)
		assert(atom.lang == lang)
204
		assert(str, datatype, lang == atom:unpack())
205 206 207 208 209 210
	end

	test(producer, consumer)
end

-- URI
211
print('[test] URI')
212 213 214 215 216 217 218 219 220 221 222
do
	local uri = 'http://test.org'

	local function producer(forge)
		forge:frame_time(0)
		forge:uri(uri)
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
223
		assert(atom.type == Atom.URI)
224
		assert(#atom == string.len(uri) + 1)
225 226
		assert(type(atom.body) == 'string')
		assert(atom.body == uri)
227 228 229 230 231 232
	end

	test(producer, consumer)
end

-- Path
233
print('[test] Path')
234 235 236 237 238 239 240 241 242 243 244
do
	local path = '/tmp/lua.lua'

	local function producer(forge)
		forge:frame_time(0)
		forge:path(path)
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
245
		assert(atom.type == Atom.Path)
246
		assert(#atom == string.len(path) + 1)
247 248
		assert(type(atom.body) == 'string')
		assert(atom.body == path)
249 250 251 252 253 254
	end

	test(producer, consumer)
end

-- URID
255
print('[test] URID')
256 257
do
	local uri = 'http://test.org#uri'
258
	local urid = Map[uri]
259 260

	local function producer(forge)
261
		forge:frame_time(0):urid(urid)
262 263 264 265 266
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
267
		assert(atom.type == Atom.URID)
268
		assert(#atom == 4)
269 270 271
		assert(type(atom.body) == 'number')
		assert(atom.body == urid)
		assert(Unmap[atom.body] == uri)
272 273 274 275 276 277
	end

	test(producer, consumer)
end

-- Midi
278
print('[test] Midi')
279 280 281 282
do
	local m = {0x90, 0x2a, 0x7f}

	local function producer(forge)
Hanspeter Portner's avatar
Hanspeter Portner committed
283
		forge:time(0.1):midi(m)
284

Hanspeter Portner's avatar
Hanspeter Portner committed
285
		forge:time(0.2)
286
		forge:midi(string.char(table.unpack(m)))
287 288 289

		forge:time(0.3)
		forge:midi(table.unpack(m))
290 291 292
	end

	local function consumer(seq)
293 294
		assert(#seq == 3)

295
		local atom = seq[1]
296
		assert(atom.type == MIDI.MidiEvent)
297
		assert(type(atom.body) == 'string')
298
		assert(#atom == #m)
299 300 301 302
		assert(#atom.body == #m)
		assert(atom.body:byte(0, 0) == nil)
		assert(atom.body:byte(1, 3) == 0x90, 0x2a, 0x7f)
		assert(atom.body:byte(4, 4) == nil)
303 304

		atom = seq[2]
305
		assert(atom.type == MIDI.MidiEvent)
306 307 308 309 310 311 312 313 314 315 316
		assert(#atom == #m)
		assert(atom[0] == nil)
		assert(atom[1] == 0x90)
		assert(atom[2] == 0x2a)
		assert(atom[3] == 0x7f)
		assert(atom[4] == nil)

		local status, note, vel = atom:unpack()
		assert(status == m[1])
		assert(note == m[2])
		assert(vel == m[3])
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
		
		status, note, vel = atom:unpack(1, 2)
		assert(status == m[1])
		assert(note == m[2])
		assert(vel == nil)
		
		note, vel = atom:unpack(2, 3)
		assert(note == m[2])
		assert(vel == m[3])
		
		status, note, vel = atom:unpack(-1, 5)
		assert(status == m[1])
		assert(note == m[2])
		assert(vel == m[3])

		assert(atom:unpack(-1) == atom:unpack(0))
		assert(atom:unpack(0) == atom:unpack(1))
		
		assert(#{atom:unpack()} == #{atom:unpack(-100, 100)})
		assert(#{atom:unpack(1, 2)} == #{atom:unpack(2, 3)})
337 338 339

		atom = seq[3]
		assert(atom.type == MIDI.MidiEvent)
340
		assert(atom.body == string.char(table.unpack(m)))
341 342 343 344 345
	end

	test(producer, consumer)
end

346 347
-- MIDIResponder
print('[test] MIDIResponder')
348 349 350 351 352 353
do
	local _chan = 0x01
	local _note = 0x2a
	local _vel = 0x7f
	local note_on = {MIDI.NoteOn | _chan, _note, _vel}
	local note_off = {MIDI.NoteOff | _chan, _note, _vel}
354 355
	local start = {MIDI.Start, 0x1}
	local stop = {MIDI.Stop, 0x2}
356 357 358 359

	local function producer(forge)
		forge:frame_time(0):midi(note_on)
		forge:frame_time(1):midi(note_off)
360 361
		forge:frame_time(2):midi(start)
		forge:frame_time(3):midi(stop)
362 363 364 365
	end

	local note_on_responder = false
	local note_off_responder = false
366 367
	local note_start_responder = false
	local note_stop_responder = false
368

369
	local midi_responder = MIDIResponder({
370 371 372 373 374 375 376 377 378 379 380 381 382
		[MIDI.NoteOn] = function(self, frames, forge, chan, note, vel)
			assert(frames == 0)
			assert(chan == _chan)
			assert(note == _note)
			assert(vel == _vel)
			note_on_responded = true
		end,
		[MIDI.NoteOff] = function(self, frames, forge, chan, note, vel)
			assert(frames == 1)
			assert(chan == _chan)
			assert(note == _note)
			assert(vel == _vel)
			note_off_responded = true
383 384 385 386 387 388 389 390 391 392 393 394
		end,
		[MIDI.Start] = function(self, frames, forge, chan, dat1)
			assert(frames == 2)
			assert(chan == nil)
			assert(dat1 == 0x1)
			note_start_responded = true
		end,
		[MIDI.Stop] = function(self, frames, forge, chan, dat1)
			assert(frames == 3)
			assert(chan == nil)
			assert(dat1 == 0x2)
			note_stop_responded = true
395 396 397 398 399
		end
	})

	local function consumer(seq)
		for frames, atom in seq:foreach() do
400
			assert(midi_responder(frames, nil, atom) == true)
401 402 403 404
		end

		assert(note_on_responded)
		assert(note_off_responded)
405 406
		assert(note_start_responded)
		assert(note_stop_responded)
407 408 409 410 411
	end

	test(producer, consumer)
end

412 413 414 415 416 417 418 419 420 421
-- Chunk
print('[test] Chunk')
do
	local c = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}

	local function producer(forge)
		forge:frame_time(0)
		forge:chunk(c)

		forge:frame_time(0)
422
		forge:chunk(string.char(table.unpack(c)))
423 424 425

		forge:frame_time(0)
		forge:chunk(table.unpack(c))
426 427 428
	end

	local function consumer(seq)
429 430
		assert(#seq == 3)

431
		local atom = seq[1]
432
		assert(atom.type == Atom.Chunk)
433
		assert(type(atom.body) == 'string')
434
		assert(#atom == #c)
435 436 437 438
		assert(#atom.body == #c)
		assert(atom.body:byte(0) == nil)
		assert(atom.body:byte(1, 6) == 0x01, 0x02, 0x03, 0x04, 0x05, 0x06)
		assert(atom.body:byte(7) == nil)
439 440

		atom = seq[2]
441
		assert(atom.type == Atom.Chunk)
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
		assert(#atom == #c)
		assert(atom[0] == nil)
		assert(atom[1] == 0x01)
		assert(atom[2] == 0x02)
		assert(atom[3] == 0x03)
		assert(atom[4] == 0x04)
		assert(atom[5] == 0x05)
		assert(atom[6] == 0x06)
		assert(atom[7] == nil)

		local c1, c2, c3, c4, c5, c6 = atom:unpack()
		assert(c1 == c[1])
		assert(c2 == c[2])
		assert(c3 == c[3])
		assert(c4 == c[4])
		assert(c5 == c[5])
		assert(c6 == c[6])
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473

		c1, c2 = atom:unpack(1, 2)
		c4, c5, c6 = atom:unpack(4, 6)
		assert(c1 == c[1])
		assert(c2 == c[2])
		assert(c3 == c[3])
		assert(c4 == c[4])
		assert(c5 == c[5])
		assert(c6 == c[6])

		assert(atom:unpack(-1) == atom:unpack(0))
		assert(atom:unpack(0) == atom:unpack(1))
		
		assert(#{atom:unpack()} == #{atom:unpack(-100, 100)})
		assert(#{atom:unpack(1, 2)} == #{atom:unpack(2, 3)})
474 475 476

		atom = seq[3]
		assert(atom.type == Atom.Chunk)
477
		assert(atom.body == string.char(table.unpack(c)))
478 479 480 481 482 483
	end

	test(producer, consumer)
end

-- Tuple
484
print('[test] Tuple')
485 486 487 488
do
	local function producer(forge)
		forge:frame_time(0)
		local tup = forge:tuple()
489 490
		assert(tup ~= forge)
		tup:int(1):float(2.0):long(3):double(4.0):pop()
491 492

		forge:frame_time(1):tuple():pop()
493 494 495
	end

	local function consumer(seq)
496
		assert(#seq == 2)
497
		local atom = seq[1]
498
		assert(atom.type == Atom.Tuple)
499 500 501
		assert(#atom == 4)

		local sub = atom[1]
502
		assert(sub.type == Atom.Int)
503
		assert(sub.body == 1)
504 505
		
		sub = atom[2]
506
		assert(sub.type == Atom.Float)
507
		assert(sub.body == 2.0)
508 509
		
		sub = atom[3]
510
		assert(sub.type == Atom.Long)
511
		assert(sub.body == 3)
512 513
		
		sub = atom[4]
514
		assert(sub.type == Atom.Double)
515
		assert(sub.body == 4.0)
516 517 518 519 520

		assert(atom[0] == nil)
		assert(atom[5] == nil)

		for i, sub in atom:foreach() do
521
			assert(atom[i].body == sub.body)
522
		end
523 524 525

		local subsub
		sub, subsub = atom:unpack(1, 1)
526
		assert(sub.type == Atom.Int)
527 528 529
		assert(subsub == nil)
		
		sub, subsub = atom:unpack(2)
530 531
		assert(sub.type == Atom.Float)
		assert(subsub.type == Atom.Long)
532 533 534 535 536 537
		
		assert(atom:unpack(-1).type == atom:unpack(0).type)
		assert(atom:unpack(0).type == atom:unpack(1).type)
		
		assert(#{atom:unpack()} == #{atom:unpack(-100, 100)})
		assert(#{atom:unpack(1, 2)} == #{atom:unpack(3, 4)})
538 539 540 541 542 543

		atom = seq[2]
		assert(atom.type == Atom.Tuple)
		assert(#atom == 0)
		assert(atom[0] == nil)
		assert(atom[1] == nil)
544 545 546 547 548 549
	end

	test(producer, consumer)
end

-- Object
550
print('[test] Object')
551 552
do
	local id = 0
553 554 555 556
	local otype = Map['http://test.org#type']
	local key1 = Map['http://test.org#key1']
	local context2 = Map['http://test.org#context2']
	local key2 = Map['http://test.org#key2']
557 558

	local function producer(forge)
559
		assert(forge:frame_time(0) == forge)
560
		local obj = forge:object(id, otype)
561
		assert(obj ~= forge)
562

563
		assert(obj:key(key1):int(12) == obj)
564
		
565
		obj:property(key2, context2):long(13)
Hanspeter Portner's avatar
Hanspeter Portner committed
566

567
		assert(obj:pop() == nil)
568 569 570 571 572
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
573
		assert(atom.type == Atom.Object)
574 575 576 577 578
		assert(atom.id == 0)
		assert(atom.otype == otype)
		assert(#atom == 2)

		local sub = atom[key1]
579
		assert(sub.type == Atom.Int)
580 581
		
		sub = atom[key2]
582
		assert(sub.body == 13)
583 584

		for key, context, sub in atom:foreach() do
585
			assert(atom[key].body == sub.body)
586 587 588 589 590 591 592 593 594

			if(key == key2) then
				assert(context == context2)
			end
		end
	end

	test(producer, consumer)
end
595

Hanspeter Portner's avatar
Hanspeter Portner committed
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
-- Atom
print('[test] Atom')
do
	local forge0 = nil

	local function producer(forge)
		forge0 = forge

		forge:frame_time(0)
		forge:int(12)
	end

	local function consumer(seq)
		assert(#seq == 1)
		local atom = seq[1]
611
		assert(atom.type == Atom.Int)
612
		assert(atom.body == 12)
Hanspeter Portner's avatar
Hanspeter Portner committed
613

614
		forge0:frame_time(0):atom(atom)
Hanspeter Portner's avatar
Hanspeter Portner committed
615 616 617 618 619
	end

	test(producer, consumer)
end

620 621 622 623 624
-- OSC
print('[test] OSC')
do
	local function producer(forge)
		forge:frame_time(0)
625
		forge:message('/hello', 'sif', 'world', 12, 13.0)
626 627
		
		forge:frame_time(1)
628
		forge:message('/hallo', 'Shdt', 'velo', 12, 13.0, 1)
629 630
		
		forge:frame_time(2)
631
		forge:message('/yup', 'c', string.byte('a'))
632 633
		
		forge:frame_time(3)
634
		forge:message('/singletons', 'TFNI')
635 636
		
		forge:frame_time(4)
637
		forge:message('/chunky', 'mb', string.char(0x90, 0x20, 0x7f), string.char(0x01, 0x02, 0x03, 0x04))
Hanspeter Portner's avatar
Hanspeter Portner committed
638 639
		
		forge:frame_time(5)
640 641 642 643 644
		local bndl = forge:bundle(1)
		assert(bndl ~= forge)
		bndl:message('/one', 'i', 1)
		bndl:message('/two', 'i', 2)
		bndl:message('/three', 'i', 3)
645
		bndl:bundle(0.1):pop() -- nested
646
		assert(bndl:pop() == nil)
647 648
		
		forge:frame_time(6)
649
		forge:message('/color', 'r', 0xff00007f)
650 651 652
	end

	local function consumer(seq)
653
		assert(#seq == 7)
654 655 656

		local atom = seq[1]
		assert(atom.type == Atom.Object)
Hanspeter Portner's avatar
Hanspeter Portner committed
657 658
		assert(atom.otype == OSC.Message)
		local path = atom[OSC.messagePath]
659
		assert(path.type == Atom.String)
660
		assert(path.body == '/hello')
Hanspeter Portner's avatar
Hanspeter Portner committed
661
		local args = atom[OSC.messageArguments]
662 663 664 665
		assert(args.type == Atom.Tuple)
		assert(#args == 3)
		assert(args[0] == nil)
		assert(args[1].type == Atom.String)
666
		assert(args[1].body == 'world')
667
		assert(args[2].type == Atom.Int)
668
		assert(args[2].body == 12)
669
		assert(args[3].type == Atom.Float)
670
		assert(args[3].body == 13.0)
671 672 673 674
		assert(args[4] == nil)
		
		atom = seq[2]
		assert(atom.type == Atom.Object)
Hanspeter Portner's avatar
Hanspeter Portner committed
675 676
		assert(atom.otype == OSC.Message)
		path = atom[OSC.messagePath]
677
		assert(path.type == Atom.String)
678
		assert(path.body == '/hallo')
Hanspeter Portner's avatar
Hanspeter Portner committed
679
		args = atom[OSC.messageArguments]
680 681 682
		assert(args.type == Atom.Tuple)
		assert(#args == 4)
		assert(args[0] == nil)
683
		assert(args[1].type == Atom.URID)
684
		assert(args[1].body == Map['velo'])
685
		assert(args[2].type == Atom.Long)
686
		assert(args[2].body == 12)
687
		assert(args[3].type == Atom.Double)
688
		assert(args[3].body == 13.0)
689 690
		assert(args[4].type == Atom.Object)
		assert(args[4].otype == OSC.Timetag)
691 692
		assert(args[4][OSC.timetagIntegral].body == 0)
		assert(args[4][OSC.timetagFraction].body == 1)
693 694 695 696
		assert(args[5] == nil)
		
		atom = seq[3]
		assert(atom.type == Atom.Object)
Hanspeter Portner's avatar
Hanspeter Portner committed
697 698
		assert(atom.otype == OSC.Message)
		path = atom[OSC.messagePath]
699
		assert(path.type == Atom.String)
700
		assert(path.body == '/yup')
Hanspeter Portner's avatar
Hanspeter Portner committed
701
		args = atom[OSC.messageArguments]
702 703 704
		assert(args.type == Atom.Tuple)
		assert(#args == 1)
		assert(args[0] == nil)
705 706
		assert(args[1].type == Atom.Literal)
		assert(args[1].datatype == OSC.Char)
707
		assert(args[1].body == 'a')
708 709 710 711
		assert(args[2] == nil)
		
		atom = seq[4]
		assert(atom.type == Atom.Object)
Hanspeter Portner's avatar
Hanspeter Portner committed
712 713
		assert(atom.otype == OSC.Message)
		path = atom[OSC.messagePath]
714
		assert(path.type == Atom.String)
715
		assert(path.body == '/singletons')
Hanspeter Portner's avatar
Hanspeter Portner committed
716
		args = atom[OSC.messageArguments]
717
		assert(args.type == Atom.Tuple)
718
		assert(#args == 4)
719
		assert(args[0] == nil)
720
		assert(args[1].type == Atom.Bool)
721
		assert(args[1].body == true)
722
		assert(args[2].type == Atom.Bool)
723
		assert(args[2].body == false)
724 725 726 727
		assert(args[3].type == Atom.Literal)
		assert(args[3].datatype == OSC.Nil)
		assert(args[4].type == Atom.Literal)
		assert(args[4].datatype == OSC.Impulse)
728
		assert(args[4].body == '')
729 730 731 732
		assert(args[5] == nil)
		
		atom = seq[5]
		assert(atom.type == Atom.Object)
Hanspeter Portner's avatar
Hanspeter Portner committed
733 734 735
		assert(atom.otype == OSC.Message)
		path = atom[OSC.messagePath]
		assert(path.type == Atom.String)
736
		assert(path.body == '/chunky')
Hanspeter Portner's avatar
Hanspeter Portner committed
737 738 739 740
		args = atom[OSC.messageArguments]
		assert(args.type == Atom.Tuple)
		assert(#args == 2)
		assert(args[0] == nil)
741
		assert(args[1].type == MIDI.MidiEvent)
Hanspeter Portner's avatar
Hanspeter Portner committed
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
		assert(#args[1] == 3)
		assert(args[1][1] == 0x90)
		assert(args[1][2] == 0x20)
		assert(args[1][3] == 0x7f)
		assert(args[2].type == Atom.Chunk)
		assert(#args[2] == 4)
		assert(args[2][1] == 0x01)
		assert(args[2][2] == 0x02)
		assert(args[2][3] == 0x03)
		assert(args[2][4] == 0x04)
		assert(args[5] == nil)
		
		atom = seq[6]
		assert(atom.type == Atom.Object)
		assert(atom.otype == OSC.Bundle)
757 758 759
		local timetag = atom[OSC.bundleTimetag]
		assert(timetag.type == Atom.Object)
		assert(timetag.otype == OSC.Timetag)
760 761
		assert(timetag[OSC.timetagIntegral].body == 0)
		assert(timetag[OSC.timetagFraction].body == 1)
Hanspeter Portner's avatar
Hanspeter Portner committed
762
		local itms = atom[OSC.bundleItems]
763 764
		assert(itms.type == Atom.Tuple)
		assert(#itms == 4)
Hanspeter Portner's avatar
Hanspeter Portner committed
765 766 767 768 769
		assert(itms[1].otype == OSC.Message)
		assert(itms[2].otype == OSC.Message)
		assert(itms[3].otype == OSC.Message)
		assert(itms[4].otype == OSC.Bundle)
		assert(#itms[4][OSC.bundleItems] == 0)
770 771 772 773 774 775 776
		
		atom = seq[7]
		assert(atom.type == Atom.Object)
		assert(atom.otype == OSC.Message)
		args = atom[OSC.messageArguments]
		assert(args.type == Atom.Tuple)
		assert(#args== 1)
777 778
		assert(args[1].type == Atom.Literal)
		assert(args[1].datatype == OSC.RGBA)
779
		assert(args[1].body == 'ff00007f')
780 781 782 783 784
	end

	test(producer, consumer)
end

785 786 787 788 789 790
-- OSCResponder
print('[test] OSCResponder')
do
	local function producer(forge)
		forge:frame_time(0):message('/ping', 'i', 13)
		forge:frame_time(1):bundle(0):message('/pong', 's', 'world'):pop()
791

792
		forge:frame_time(2):message('/one/two/three', 'd', 12.3)
793 794 795 796 797 798
		forge:frame_time(2):message('/one/*/three', 'd', 12.3)
		forge:frame_time(2):message('/?ne/*/three', 'd', 12.3)
		forge:frame_time(2):message('/?ne/*/{three,four}', 'd', 12.3)
		forge:frame_time(2):message('/?ne/*/[tT]hree', 'd', 12.3)
		forge:frame_time(2):message('/?ne/*/[!T]hree', 'd', 12.3)
		forge:frame_time(2):message('/{one,eins}/*/{three,drei}', 'd', 12.3)
799 800 801 802
	end

	local ping_responded = false
	local pong_responded = false
803
	local complex_responded = 0
804

805
	local osc_responder = OSCResponder({
806
		['/ping'] = function(self, frames, forge, fmt, i)
807
			assert(frames == 0)
808
			assert(fmt == 'i')
809 810 811
			assert(i == 13)
			ping_responded = true
		end,
812
		['/pong'] = function(self, frames, forge, fmt, s)
813
			assert(frames == 1)
814
			assert(fmt == 's')
815 816 817
			assert(s == 'world')
			pong_responded = true
		end,
818
		['/one/two/three'] = function(self, frames, forge, fmt, d)
819
			assert(frames == 2)
820
			assert(fmt == 'd')
821 822 823
			assert(d == 12.3)
			complex_responded = complex_responded + 1
		end
824 825 826 827 828 829 830 831 832
	})

	local function consumer(seq)
		for frames, atom in seq:foreach() do
			assert(osc_responder(frames, nil, atom) == true)
		end

		assert(ping_responded)
		assert(pong_responded)
833
		assert(complex_responded == 7)
834 835 836 837 838
	end

	test(producer, consumer)
end

839 840 841 842 843 844 845 846 847 848 849 850 851
-- TimeResponder
print('[test] TimeResponder')
do
	local rolling = 0
	local bar_beat_responded = 0
	local bar_responded = 0
	local beat_unit_responded = 0
	local beats_per_bar_responded = 0
	local beats_per_minute_responded = 0
	local frame_responded = 0
	local frames_per_second_responded = 0
	local speed_responded = 0

852
	local time_cb = {
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
		[Time.barBeat] = function(self, frames, forge, bar_beat)
			if bar_beat_responded == 0 then
				assert(bar_beat == 0.0)
				bar_beat_responded = 1
			else
				assert(frames == 0)
				assert(bar_beat == 0.5)
				bar_beat_responded = 2
			end
		end,
		[Time.bar] = function(self, frames, forge, bar)
			if bar_responded == 0 then
				assert(bar == 0)
				bar_responded = 1
			else
				assert(frames == 0)
				assert(bar == 34)
				bar_responded = 2
			end
		end,
		[Time.beatUnit] = function(self, frames, forge, beat_unit)
			if beat_unit_responded == 0 then
				assert(beat_unit == 4)
				beat_unit_responded = 1
			else
				assert(frames == 0)
				assert(beat_unit == 8)
				beat_unit_responded = 2
			end
		end,
		[Time.beatsPerBar] = function(self, frames, forge, beats_per_bar)
			if beats_per_bar_responded == 0 then
				assert(beats_per_bar == 4.0)
				beats_per_bar_responded = 1
			else
				assert(frames == 0)
				assert(beats_per_bar == 6.0)
				beats_per_bar_responded = 2
			end
		end,
		[Time.beatsPerMinute] = function(self, frames, forge, beats_per_minute)
			if beats_per_minute_responded == 0 then
				assert(beats_per_minute == 120.0)
				beats_per_minute_responded = 1
			else
				assert(frames == 0)
				assert(beats_per_minute == 200.0)
				beats_per_minute_responded = 2
			end
		end,
		[Time.frame] = function(self, frames, forge, frame)
			if frame_responded == 0 then
				frame_responded = 1
			else
				frame_responded = 2
			end
		end,
		[Time.framesPerSecond] = function(self, frames, forge, frames_per_second)
			if frames_per_second_responded == 0 then
				assert(frames_per_second == 48000.0)
				frames_per_second_responded = 1
			else
				assert(frames == 0)
				assert(frames_per_second == 44100.0)
				frames_per_second_responded = 2
			end
		end,
		[Time.speed] = function(self, frames, forge, speed)
			rolling = speed > 0.0 and true or false
			if speed_responded == 0 then
				assert(speed == 0.0)
				speed_responded = 1
			else
				assert(frames == 0)
				assert(speed == 1.0)
				speed_responded = 2
			end
		end,
931 932
	}
	local time_responder = TimeResponder(time_cb)
933

934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
	local function producer(forge)
		local obj = forge:frame_time(0):object(0, Time.Position)
		obj:key(Time.barBeat):float(0.5)
		obj:key(Time.bar):long(34)
		obj:key(Time.beatUnit):int(8)
		obj:key(Time.beatsPerBar):float(6.0)
		obj:key(Time.beatsPerMinute):float(200.0)
		obj:key(Time.frame):long(23000)
		obj:key(Time.framesPerSecond):float(44100.0)
		obj:key(Time.speed):float(1.0)
		obj:pop()

		-- time:stash
		forge:frame_time(1)
		time_responder:stash(forge)
	end

951
	local function consumer(seq)
952
		assert(#seq == 2)
953 954 955

		local from = 0
		for frames, atom in seq:foreach() do
956 957 958 959 960 961
			if frames == 0 then
				assert(atom.type == Atom.Object)
				assert(atom.otype == Time.Position)
				time_responder(from, frames, nil, atom)
				from = frames
			end
962 963 964 965 966 967 968 969
		end
		time_responder(from, 256, nil, nil)

		assert(bar_beat_responded == 2)
		assert(bar_responded == 2)
		assert(beat_unit_responded == 2)
		assert(beats_per_bar_responded == 2)
		assert(beats_per_minute_responded == 2)
Hanspeter Portner's avatar
Hanspeter Portner committed
970
		assert(frame_responded == 2)
971 972
		assert(frames_per_second_responded == 2)
		assert(speed_responded == 2)
973

974
		assert(time_responder[Time.barBeat] > 0.5) --!
975 976 977 978 979 980 981
		assert(time_responder[Time.bar] == 34)
		assert(time_responder[Time.beatUnit] == 8)
		assert(time_responder[Time.beatsPerBar] == 6.0)
		assert(time_responder[Time.beatsPerMinute] == 200.0)
		assert(time_responder[Time.frame] == 23000 + 256)
		assert(time_responder[Time.framesPerSecond] == 44100.0)
		assert(time_responder[Time.speed] == 1.0)
982 983 984 985 986

		-- test time:stash
		local atom = seq[1]
		assert(atom.type == Atom.Object)
		assert(atom.otype == Time.Position)
987 988 989 990 991 992 993 994
		assert(atom[Time.barBeat].body == 0.5)
		assert(atom[Time.bar].body == 34)
		assert(atom[Time.beatUnit].body == 8)
		assert(atom[Time.beatsPerBar].body == 6.0)
		assert(atom[Time.beatsPerMinute].body == 200.0)
		assert(atom[Time.frame].body == 23000)
		assert(atom[Time.framesPerSecond].body == 44100.0)
		assert(atom[Time.speed].body == 1.0)
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006

		-- test time:apply
		--time_responder(0, 0, nil, atom)
		time_responder:apply(atom)
		assert(time_responder[Time.barBeat] == 0.5)
		assert(time_responder[Time.bar] == 34)
		assert(time_responder[Time.beatUnit] == 8)
		assert(time_responder[Time.beatsPerBar] == 6.0)
		assert(time_responder[Time.beatsPerMinute] == 200.0)
		assert(time_responder[Time.frame] == 23000)
		assert(time_responder[Time.framesPerSecond] == 44100.0)
		assert(time_responder[Time.speed] == 1.0)
1007 1008 1009 1010 1011
	end

	test(producer, consumer)
end

1012 1013 1014 1015 1016 1017
-- Sequence
print('[test] Sequence')
do

	local function producer(forge)
		forge:frame_time(0)
1018
		local subseq = forge:sequence(Atom.beatTime)
1019
		assert(subseq ~= forge)
1020

1021 1022
		subseq:time(1.1):int(1)
		subseq:beat_time(2.2):int(1)
1023

1024
		assert(subseq:pop() == nil)
1025 1026

		forge:frame_time(1):sequence():pop()
1027 1028 1029
	end

	local function consumer(seq)
1030
		assert(#seq == 2)
1031 1032 1033 1034 1035
		local subseq = seq[1]
		assert(subseq.type == Atom.Sequence)
		assert(#subseq == 2)

		for frames, atom in subseq:foreach() do
1036
			assert(not math.tointeger(frames)) -- beatTime is double
1037
			assert(atom.type == Atom.Int)
1038
			assert(atom.body == 1)
1039
		end
1040 1041 1042 1043 1044

		subseq = seq[2]
		assert(#subseq == 0)
		assert(subseq[0] == nil)
		assert(subseq[1] == nil)
1045 1046 1047 1048 1049
	end

	test(producer, consumer)
end

1050
-- Vector
1051 1052 1053 1054
print('[test] Vector')
do

	local function producer(forge)
Hanspeter Portner's avatar
Hanspeter Portner committed
1055
		forge:time(0)
1056 1057
		forge:vector(Atom.Int, {1, 2, 3, 4})

Hanspeter Portner's avatar
Hanspeter Portner committed
1058
		forge:time(1)
1059 1060
		forge:vector(Atom.Long, 5, 6, 7, 8)
		
Hanspeter Portner's avatar
Hanspeter Portner committed
1061
		forge:time(2)
1062 1063
		forge:vector(Atom.Bool, {true, false})
		
Hanspeter Portner's avatar
Hanspeter Portner committed
1064
		forge:time(3)
1065 1066
		forge:vector(Atom.Float, 1.0, 2.0)
		
Hanspeter Portner's avatar
Hanspeter Portner committed
1067
		forge:time(4)
1068 1069
		forge:vector(Atom.Double, {3.3, 4.4})
		
Hanspeter Portner's avatar
Hanspeter Portner committed
1070
		forge:time(5)
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
		forge:vector(Atom.URID, Atom.Int, Atom.Long)
	end

	local function consumer(seq)
		assert(#seq == 6)

		local vec = seq[1]
		assert(vec.type == Atom.Vector)
		assert(#vec == 4)
		assert(vec.child_type == Atom.Int)
		assert(vec.child_size == 4)

		for i, atom in vec:foreach() do
			assert(atom.type == Atom.Int)
1085
			assert(atom.body == i)
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
		end
		
		vec = seq[2]
		assert(vec.type == Atom.Vector)
		assert(#vec == 4)
		assert(vec.child_type == Atom.Long)
		assert(vec.child_size == 8)

		for i, atom in vec:foreach() do
			assert(atom.type == Atom.Long)
1096
			assert(atom.body == i + 4)
1097 1098 1099 1100 1101 1102 1103 1104
		end

		vec = seq[3]
		assert(vec.type == Atom.Vector)
		assert(#vec == 2)
		assert(vec.child_type == Atom.Bool)
		assert(vec.child_size == 4)
		assert(vec[0] == nil)
1105 1106
		assert(vec[1].body == true)
		assert(vec[2].body == false)
1107 1108 1109 1110 1111 1112 1113 1114
		assert(vec[3] == nil)

		vec = seq[4]
		assert(vec.type == Atom.Vector)
		assert(#vec == 2)
		assert(vec.child_type == Atom.Float)
		assert(vec.child_size == 4)
		local a, b = vec:unpack()
1115 1116
		assert(a.body == 1.0)
		assert(b.body == 2.0)
1117 1118 1119 1120 1121 1122 1123
		
		vec = seq[5]
		assert(vec.type == Atom.Vector)
		assert(#vec == 2)
		assert(vec.child_type == Atom.Double)
		assert(vec.child_size == 8)
		local a, b = vec:unpack()
1124 1125
		assert(a.body == 3.3)
		assert(b.body == 4.4)
1126 1127 1128 1129 1130 1131 1132
		
		vec = seq[6]
		assert(vec.type == Atom.Vector)
		assert(#vec == 2)
		assert(vec.child_type == Atom.URID)
		assert(vec.child_size == 4)
		local a, b = vec:unpack(1, 1)
1133
		assert(a.body == Atom.Int)
1134 1135
		assert(b == nil)
		local a, b = vec:unpack(2, 2)
1136
		assert(a.body == Atom.Long)
1137 1138 1139 1140 1141
		assert(b == nil)
	end

	test(producer, consumer)
end
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152

-- Options
print('[test] Options')
do

	assert(Core.sampleRate == Map['http://lv2plug.in/ns/lv2core#sampleRate'])
	assert(Options[Core.sampleRate] == 48000)
	assert(Options[Buf_Size.minBlockLength] == nil)
	assert(Options[Buf_Size.maxBlockLength] == nil)
	assert(Options[Buf_Size.sequenceSize] == nil)
end
1153 1154 1155 1156 1157 1158

-- Patch
print('[test] Patch')
do
	local subject = Map['http://open-music-kontrollers.ch/lv2/moony#subject']
	local property = Map['http://open-music-kontrollers.ch/lv2/moony#property']
1159
	local access = Patch.writable
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170

	local function producer(forge)
		forge:time(0):get(subject, property)

		forge:time(1):get(nil, property)

		local set = forge:time(2):set(subject, property)
		set:string('hello world'):pop()
		
		local set = forge:time(3):set(nil, property)
		set:string('hello world'):pop()
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190

		local patch = forge:time(4):patch(subject)
		patch:remove():key(access):urid(Patch.wildcard):pop()
		patch:add():key(access):urid(property):pop()
		patch:pop()

		patch = forge:time(5):patch(property)
		local remove = patch:remove()
		remove:key(RDFS.label):urid(Patch.wildcard)
		remove:key(RDFS.range):urid(Patch.wildcard)
		remove:key(Core.minimum):urid(Patch.wildcard)
		remove:key(Core.maximum):urid(Patch.wildcard)
		remove:pop()
		local add = patch:add()
		add:key(RDFS.label):string('A dummy label')
		add:key(RDFS.range):urid(Atom.Int)
		add:key(Core.minimum):int(0)
		add:key(Core.maximum):int(10)
		add:pop()
		patch:pop()
Hanspeter Portner's avatar
Hanspeter Portner committed
1191 1192 1193 1194

		local put = forge:time(6):put(subject)
		put:key(property):string('hello world')
		put:pop()
1195 1196 1197
	end

	local function consumer(seq)
Hanspeter Portner's avatar
Hanspeter Portner committed
1198
		assert(#seq == 7)
1199 1200 1201

		local get = seq[1]
		assert(get.type == Atom.Object)
1202
		assert(get.otype == Patch.Get)
1203
		assert(#get == 2)
1204 1205
		assert(get[Patch.subject].body == subject)
		assert(get[Patch.property].body == property)
1206 1207 1208

		get = seq[2]
		assert(get.type == Atom.Object)
1209
		assert(get.otype == Patch.Get)
1210 1211
		assert(#get == 1)
		assert(get[Patch.subject] == nil)
1212
		assert(get[Patch.property].body == property)
1213 1214 1215

		local set = seq[3]
		assert(set.type == Atom.Object)
1216
		assert(set.otype == Patch.Set)
1217
		assert(#set == 3)
1218 1219 1220
		assert(set[Patch.subject].body == subject)
		assert(set[Patch.property].body == property)
		assert(set[Patch.value].body == 'hello world')
1221 1222 1223

		set = seq[4]
		assert(set.type == Atom.Object)
1224
		assert(set.otype == Patch.Set)
1225 1226
		assert(#set == 2)
		assert(set[Patch.subject] == nil)
1227 1228
		assert(set[Patch.property].body == property)
		assert(set[Patch.value].body == 'hello world')
1229 1230 1231 1232 1233

		local patch = seq[5]
		assert(patch.type == Atom.Object)
		assert(patch.otype == Patch.Patch)
		assert(#patch == 3)
1234 1235 1236
		assert(patch[Patch.subject].body == subject)
		assert(patch[Patch.remove][access].body == Patch.wildcard) 
		assert(patch[Patch.add][access].body == property) 
1237 1238 1239 1240 1241

		patch = seq[6]
		assert(patch.type == Atom.Object)
		assert(patch.otype == Patch.Patch)
		assert(#patch == 3)
1242 1243 1244 1245 1246 1247 1248 1249 1250
		assert(patch[Patch.subject].body == property)
		assert(patch[Patch.remove][RDFS.label].body == Patch.wildcard)
		assert(patch[Patch.remove][RDFS.range].body == Patch.wildcard) 
		assert(patch[Patch.remove][Core.minimum].body == Patch.wildcard) 
		assert(patch[Patch.remove][Core.maximum].body == Patch.wildcard) 
		assert(patch[Patch.add][RDFS.label].body == 'A dummy label') 
		assert(patch[Patch.add][RDFS.range].body == Atom.Int) 
		assert(patch[Patch.add][Core.minimum].body == 0) 
		assert(patch[Patch.add][Core.maximum].body == 10) 
Hanspeter Portner's avatar
Hanspeter Portner committed
1251 1252 1253 1254 1255

		local put = seq[7]
		assert(put.type == Atom.Object)
		assert(put.otype == Patch.Put)
		assert(#put == 2)
1256
		assert(put[Patch.subject].body == subject)
Hanspeter Portner's avatar
Hanspeter Portner committed
1257 1258 1259
		local body = put[Patch.body]
		assert(body)
		assert(#body == 1)
1260
		assert(body[property].body == 'hello world')
1261 1262 1263 1264
	end

	test(producer, consumer)
end
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279

-- StateResponder
print('[test] StateResponder')
do
	prefix = 'http://open-music-kontrollers.ch/lv2/moony#test'
	local urid = {
		subject = Map[prefix],
		int = Map[prefix .. '#int'],
		flt = Map[prefix .. '#flt']
	}

	local flt_get_responded = false
	local flt_set_responded = false

	local state_int = {
1280 1281 1282 1283 1284
		[RDFS.label] = 'Int',
		[RDFS.range] = Atom.Int,
		[Core.minimum] = 0,
		[Core.maximum] = 10,
		[RDF.value] = 1
1285 1286 1287
	}

	local state_flt = {
1288 1289 1290 1291 1292
		[RDFS.label] = 'Flt',
		[RDFS.range] = Atom.Float,
		[Core.minimum] = -0.5,
		[Core.maximum] = 10.0,
		[RDF.value] = 1.0,
1293 1294
		[Patch.Get] = function(self, frames, forge)
			flt_get_responded = true
1295
			return self[RDF.value]
1296 1297 1298
		end,
		[Patch.Set] = function(self, frames, forge, value)
			flt_set_responded = true
1299
			self[RDF.value] = value
1300 1301 1302
		end
	}

1303
	local state = StateResponder({
1304 1305 1306 1307
		[Patch.writable] = {
			[urid.int] = state_int,
			[urid.flt] = state_flt
		}
1308 1309
	})

1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
	local function producer(forge)
		forge:frame_time(0):get(urid.subject, urid.int)
		forge:frame_time(1):set(urid.subject, urid.int):typed(Atom.Int, 2):pop()

		forge:frame_time(2):get(urid.subject, urid.flt)
		forge:frame_time(3):set(urid.subject, urid.flt):typed(Atom.Float, 2.0):pop()

		-- state:stash
		forge:frame_time(4)
		state:stash(forge)
	end
1321

1322 1323
	local function consumer(seq, forge)
		for frames, atom in seq:foreach() do
1324 1325 1326
			if frames < 4 then
				assert(state(frames, forge, atom) == true)
			end
1327 1328
		end

1329 1330
		assert(state_int[RDF.value] == 2)
		assert(state_flt[RDF.value] == 2.0)
1331 1332
		assert(flt_get_responded)
		assert(flt_set_responded)
1333 1334 1335 1336 1337 1338

		--test state:stash
		local atom = seq[5]
		assert(atom.type == Atom.Object)
		assert(#atom == 2)
		assert(atom[urid.int].type == Atom.Int)
1339
		assert(atom[urid.int].body == 1)
1340
		assert(atom[urid.flt].type == Atom.Float)
1341
		assert(atom[urid.flt].body == 1.0)
1342 1343 1344 1345 1346

		-- test state:apply
		state:apply(atom)
		assert(state_int[RDF.value] == 1)
		assert(state_flt[RDF.value] == 1.0)
1347 1348 1349 1350
	end

	test(producer, consumer)
end
1351

1352 1353 1354 1355 1356
-- Note 
print('[test] Note')
do
	assert(Note[0] == 'C0')
	assert(Note[1] == 'C#0')
1357 1358
	assert(Note(12) == 'C1')
	assert(Note(13) == 'C#1')
1359 1360 1361 1362

	assert(Note.C0 == 0)
	assert(Note['C#0'] == 1)
	assert(Note.C1 == 12)
1363
	assert(Note('C#1') == 13)
1364 1365 1366 1367 1368

	assert(Note.C5 == 60)
	assert(Note[60] == 'C5')

	assert(Note[-1] == nil)
1369
	assert(Note(0x80) == nil)
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
	assert(Note.foo == nil)
	assert(Note.bar == nil)

	local keys = {'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'H'}

	local function itr()
		return coroutine.wrap(function()
			for octave = 0, 9 do
				for i, key in ipairs(keys) do
					coroutine.yield(octave * #keys + i - 1, key