shithub: neindaw

ref: 8606ddf48890de2de0f25b771f9ca60ce4ede412
dir: /ay/piper/

View raw version
#!/bin/rc
rfork ne

awk '
	BEGIN {
		eb[1] = "Hold"
		eb[2] = "Alternate"
		eb[4] = "Attack"
		eb[8] = "Continue"

		es["d"] = 0  # \_________
		es["D"] = 8  # \|\|\|\|\|
		es["a"] = 4  # /|________
		es["A"] = 12 # /|/|/|/|/|
		es["r"] = 14 # /\/\/\/\/\
		es["R"] = 10 # \/\/\/\/\/
		es["h"] = 13 # /¯¯¯¯¯¯¯¯¯
		es["H"] = 11 # \|¯¯¯¯¯¯¯¯

		period["0"] = 2000
		period["1"] = 1000
		period["2"] = 500
		period["3"] = 333.3333
		period["4"] = 250
		period["5"] = 200
		period["6"] = 166.6666
		period["7"] = 142.8571
		period["8"] = 125
		period["9"] = 111.1111
		period["a"] = 100
		period["b"] = 50

		chan["0"] = "A"
		chan["1"] = "B"
		chan["2"] = "C"

		note["D","5"] = 587.3295
		note["C","5"] = 523.2511
		note["B","4"] = 493.8833
		note["A","4"] = 440
		note["G","4"] = 391.9954
		note["F","4"] = 349.2282
		note["E","4"] = 329.6276
		note["D","4"] = 293.6648
		note["C","4"] = 261.6256
		note["B","3"] = 246.9417
		note["A","3"] = 220
		note["G","3"] = 195.9977
		note["F","3"] = 174.6141
		note["E","3"] = 164.8138
		note["D","3"] = 146.8324
		note["C","3"] = 130.8128
		note["B","2"] = 123.4708
		note["A","2"] = 110
		note["G","2"] = 97.99886
		note["F","2"] = 87.30706
		note["E","2"] = 82.40689
		note["D","2"] = 73.41619
		note["C","2"] = 65.40639
		note["B","1"] = 61.73541
		note["A","1"] = 55
		note["G","1"] = 48.99943
		note["F","1"] = 43.65353
		note["E","1"] = 41.20344
		note["D","1"] = 36.70810
		note["C","1"] = 32.70320
	}

	{
		split($1, a, ",")
		split(a[1], c, "")
	}

	# key
	# kXCONVL
	# 1234567
	# X = ay number
	# C = channel (0, 1, 2)
	# O = octave
	# N = note
	# V = velocity
	# L = length
	/^k[0-9]/ {
		path = "/n/ay/" c[2] "/AY-3-8910/"
		ch = path chan[c[3]]
		freq = note[c[5],c[4]]
		if(freq != ""){
			print freq >> (ch "/Tone/Frequency/ctl")
			if(c[6] != "")
				print c[6]/10 >> (ch "/Volume/ctl")
			print (c[7] != "") >> (ch "/Envelope/ctl")
			if(c[7] != "")
				print period[c[7]] >> (path "/Envelope/Period/ctl")
			print 1 >> (path "/Envelope/Hit/ctl")
		}else{
			c[6] = "" # stop playing if invalid note/octave
		}

		print (c[6] != "") >> (ch "/Tone/Enable/ctl")
		fflush()
		next
	}

	# envelope
	# eXSP
	# 1234
	# X = ay number
	# S = shape (see "es_" var)
	# P = period (see "period" var)
	/^e[0-9]/ {
		# FIXME lol
		next
	}
'