# small test program
# algorithmic music generation
# using Display#change_keyboard_control and sleep()
# Copyright (c) 2001 by Mathieu Bouchard

require "X11/Display"
$d = X11::Display.new

def tone1(i,d=100)
	$d.change_keyboard_control(X11::KeyboardControl[:bell_pitch=>
		(55*2**(i/12.0)).to_i
	])
	$d.bell(0)
	$d.flush
	sleep d/1000.0
end

def pat1(a,b)
	yield a
	yield a+1 ; yield b
	yield a+4 ; yield b+12
	yield a+1 ; yield b
end

def pat2(a)
	yield a,a
	yield a,a+1
	yield a+3,a+7
	yield a+3,a+3
end

k=[2,2,4,2]
i=0
while true
	pat2(0) {|a,b|
		pat1(24+a,b) {|x|
			tone1 x,100*k[i]
			i+=1; i%=k.length
		}
	}
end
