//TemperGeneratorHW2
//temperament xml file generator for Hauptwerk 2
//Date: 26 august 2006
//Author: Jocelyn Druel (jocelyn DOT druel1 AT libertysurf DOT fr)
//License: GNU GPL
//Version: 1.00

Val=x_mdialog("Enter the parameters",..
	["UniqueTemperamentID",..
	"Name",..
	"Short Name",..
	"SupplierID",..
	"Supplier Name",..
	"Comments",..
	"Temperament Version"],..
	["900001",..
	"My New Temperament",..
	"New",..
	"800001",..
	"Smith",..
	"No comments",..
	"1"]);


Space1=x_mdialog("Enter the values in cents",..
	["A3 Frequency (Hz)";"C";"C#";"D";"D#";"E";"F";"F#";"G";"G#";"A";"A#";"B"],..
	["440";"0";"100.0";"200.0";"300.0";"400.0";"500.0";"600.0";"700.0";"800.0";"900.0";"1000.0";"1100.0"]);




a01="<?xml version=""1.0"" encoding=""UTF-8""?>";
a02="<Hauptwerk FileFormat=""Temperament"" FileFormatVersion=""2.00"">" ;
a03="<ObjectList ObjectType=""_General"">";
a04="	<_General>";
a05="		<Sys_ObjectID>1</Sys_ObjectID>";
a06="		<UniqueTemperamentID>"+Val(1)+"</UniqueTemperamentID>";
a07="		<Name>"+Val(2)+"</Name>";
a08="		<ShortName>"+Val(3)+"</ShortName>";
a09="		<SupplierID>"+Val(4)+"</SupplierID>";
a10="		<SupplierName>"+Val(5)+"</SupplierName>";
a11="		<Comments>"+Val(6)+"</Comments>";
a12="		<TemperamentVersion>"+Val(7)+"</TemperamentVersion>";
a13="	</_General>";
a14="</ObjectList>";
a15=" ";
a16="<ObjectList ObjectType=""note"">";




Matrix1=[a01;a02;a03;a04;a05;a06;a07;a08;a09;a10;a11;a12;a13;a14;a15;a16];

fa3=evstr(Space1(1));
fc3=fa3/(2^(900/1200));
f0=fc3/2^5;


for i=0:132
	octave1=int(i/12);
	note1=modulo(i,12);
	cent1=evstr(Space1(note1+2));

	if cent1==0 then
		freq1=f0*(2^octave1);
	else freq1=f0*(2^octave1)*(2^(cent1/1200));
	end;//if
	b01="	<note>";
	b02="		<MIDINoteNumberOnEightFootStop>"+string(i)+"</MIDINoteNumberOnEightFootStop>";
	b03="		<PitchHz>"+string(freq1)+"</PitchHz>";
	b04="	</note>";
	b05=" ";
	Matrix1=[Matrix1;b01;b02;b03;b04;b05];
end


c01="</ObjectList>";
c02="</Hauptwerk>";

Matrix1=[Matrix1;c01;c02];

name1=xgetfile("*.Temperament.Hauptwerk.xml",title="Enter File name (without any extension)");
full_name=name1+".Temperament.Hauptwerk.xml";

if MSDOS then 
  command1="del "+full_name;
  unix(command1);
else 
    command1="rm -f "+full_name;
    unix(command1);
end

[fd,err]=mopen(full_name,"w");
mputl(Matrix1,fd);
mclose('all');


