/* ==============================================
     zmd2mid ドライバの行う初期化命令を埋め込む
   ============================================== */

#include "Putcode.h"

#define Bn 0xB0+trk
#define En 0xE0+trk

#include "config.h"
int zmscinit(UBYTE *MTrk,DWORD delta,DWORD *gate_old,DWORD trk);
int zmscinit_delta(DWORD delta);

int zmscinit(UBYTE *MTrk,DWORD delta,DWORD *gate_old,DWORD trk)
{
	UBYTE *MTrk_ = MTrk;

	MTrk += Putcode(MTrk,*gate_old+delta,Bn,0x79,0x00);	/* reset all contorollers */
	MTrk += Putcode(MTrk,delta,Bn,0x7D,0x00);			/* OMNI mode on */
	MTrk += Putcode(MTrk,delta,Bn,0x7F,0x00);			/* MONO mode off */
	MTrk += Putcode(MTrk,delta,Bn,0x7A,0x7F);			/* local on */
	MTrk += Putcode(MTrk,delta,Bn,0x65,0x00);			/* fine tuning neutral */
	MTrk += Putcode(MTrk,delta,Bn,0x64,0x01);
	MTrk += Putcode(MTrk,delta,Bn,0x06,0x40);
	MTrk += Putcode(MTrk,delta,Bn,0x26,0x00);
	MTrk += Putcode(MTrk,delta,Bn,0x65,0x00);			/* cource tuning neutral */
	MTrk += Putcode(MTrk,delta,Bn,0x64,0x02);
	MTrk += Putcode(MTrk,delta,Bn,0x06,0x40);
	MTrk += Putcode(MTrk,delta,Bn,0x65,0x00);			/* pitch bend range = 1oct. */
	MTrk += Putcode(MTrk,delta,Bn,0x64,0x00);
	MTrk += Putcode(MTrk,delta,Bn,0x06,0x0C);
	MTrk += Putcode(MTrk,delta,Bn,0x07,0x3F);			/* Volume=63 */
	MTrk += Putcode(MTrk,delta,Bn,0x0A,0x40);			/* Panpot=中央 */
	MTrk += Putcode(MTrk,delta,Bn,0x01,0x00);			/* pitch modulation=0 */
	MTrk += Putcode(MTrk,delta,Bn,0x40,0x00);			/* dumper off */
	MTrk += Putcode(MTrk,delta,En,0x00,0x40);			/* pitch bend neutral */

	*gate_old = 0;
	return MTrk - MTrk_;
}

int zmscinit_delta(DWORD delta)
{
	return delta * 19;
}
