

% Set fancy music settings
	SetNotes

% Global variables	
	Order = 1;
	V = [];
	tm = 1;
	tmr = 1;

if Order == 1;

	% Play the I, IV, V
	N  = [1 6 8];

	% Play crazy I,II,III
	%N = [1 2 3];
	
	if tm == 1
		TM = [	.1 .6 .3;
				.2 .1 .7;
				.7 .3 0   ];
	
	elseif tm == 2;
		TM = [	.1 .2 .7;
				.2 .7 .1;
				.7 .1 .2  ];

	elseif tm == 3;	
			TM = [ 	.7 .1 .2;
			 	.1 .9 0;
				.2 0 .8]; 

	elseif tm == 4;	
			TM = [ 	.95 0 .05;
			 	.05 .8 .15;
				0 .2 .8]; 
	end




	%TM = zeros(3); TM(1,:) = 1;


	if tmr == 1;	
		TMR = [ .7 .2 .05 .05;
			.1 .2 .3 .4;
			.2 .1 .1 .6;
			.01 .03 .45 .45];
		
		for i = 1:4; TMR(:,i) = TMR(:,i)/norm(TMR(:,i),1); end;
	
		elseif tmr == 2;	
		TMR = [ .5 .4 .05 .05;
			.4 .2 .3 .1;
			.6 .2 .1 .3;
			.7 .1 .05 .05];
	
		for i = 1:4; TMR(:,i) = TMR(:,i)/norm(TMR(:,i),1); end;
	end;



	v = rand(3,1); 
	v = v/norm(v,1);
	P = round(100*v);
	
	w = rand(4,1); 
	w = w/norm(w,1);
	Q = round(100*w);
	


	for i = 1:100;
	
		NoteList(1:P(1)) = N(1);
		NoteList(P(1)+1:P(1)+1+P(2)) = N(2);
		NoteList(P(1)+1+P(2)+1:100) = N(3);
	
		% Select a note based on the probabilities
		Note = NoteList(randi(100,1));
		
		RestList(1:Q(1)) = 1;
		RestList(Q(1)+1:Q(1)+1+Q(2)) = 2;
		RestList(Q(1)+2+Q(2):Q(1)+2+Q(2)+Q(3)) = 3;
		RestList(Q(1)+3+Q(2)+Q(3):100) = 4;
	
		% Select a note based on the probabilities
		Rest = R{RestList(randi(100,1))};
		if tmr == 3; Rest = []; end
			
		
		V = [V; M(:,Note); Rest];
		%V = [V; M(:,randi(3,1)); Rest];
		v = TM*v;
		P = round(100*v);

	 end
	
	 W = GaussianSmooth(V);
	 sound(.5*W,Fr)
	 %sound(.5*V,Fr)
	 

else

	N = [1 3 5 6 8 10 11 13];

	V = [];
	TM = zeros(64);
	% Happy Birthday Notes %
	%	C4	D4	E4	F4	G4	A4	Bb4	C5
	TM(1,2) = .67; TM(1,5) = .33;
% TM = [	0	.67	0	0	0	0	0	.33;
	TM(2,1) = 1;
%		1	0 	0	0	0	0	0	0;
	TM(3,1) = 1;
%		1	0	0	0	0	0	0	0;
	TM(4,4) = 1;
%		0 	0	0	1	0	0	0	0;
	TM(5,6) = 1;
%		0	0	0	0	0	1	0	0;
	TM(6,4) = .5; TM(6,5) = .5;
%		0	0	0	.5	.5	0	0	0;
	TM(7,7) = .5;
%		0	0	0	0	0	0	1	0;
	TM(8,1) = 1;
%		1	0	0	0	0	0	0	0;
	TM(9,8) = 1;
%		0	0	0	0	0	0	1	0;
	TM(10,8) = 1;
%		1	0	0	0	0	0	0	0;
	TM(11,1) = .5; TM(11,2) = .5;
%		.5	.5	0	0	0	0	0	0;
	TM(12,4) = 1;
%		0	0	0	1	0	0	0	0;
	TM(13,1) = 1;
%		1	0	0	0	0	0	0	0;
	TM(14,3) = 1; TM(14,5) = 1;
%		0	0	.5	0	.5	0	0	0;
	TM(15,4) = 1;
%		0	0	0	1	0	0	0	0;
	TM(16,6) = 1;
%		0	0	0	0	0	1	0	0;
	TM(17,3) = 1;
%		0	0	1	0	0	0	0	0	]';

	
v = rand(size(TM,2),1); 
v = v/norm(v,1);

P = round(100*v);

for i = 1:100;
	
		NoteList(1:P(1)) = N(1);
		NoteList(P(1)+1:P(1)+1+P(2)) = N(2);
		NoteList(P(1)+1+P(2)+1:100) = N(3);
	
		% Select a note based on the probabilities
		Note = NoteList(randi(100,1));
		
		V = [V; M(:,Note)];
		P = round(100*TM*v);

end

	 sound(.5*V,Fr)
end
