(
// MAIN LAUNCH (loads necessary files and definitions)

var appEnvironment;

//push new environment
appEnvironment = Environment.make;
appEnvironment.push;

s.waitForBoot({
	var preampBusses, accompBusses, postampBusses;

	~hash = Date.getDate.hash.asString;
	~cRes = 1;

	// load all files
	"tkam_musical_data_generator.scd".loadRelative;
	"tkam_sonifier.scd".loadRelative;
	"tkam_gui.scd".loadRelative;
	"tkam_transcriber.scd".loadRelative;

	# preampBusses, accompBusses, postampBusses = ~allocBusses.value(s);
	~defineSynths.value(s, preampBusses, accompBusses, postampBusses);

	~genAll = {arg seed;
		~dUnit = 8.reciprocal;
		~musicData = ~genMusicData.value(seed);
		~scoreData = ~genScoreData.value(~musicData[0]);
		~sectionData = ~musicData[4];
		~patterns = ~genPatterns.value(~musicData[0], ~musicData[1], ~musicData[2], ~musicData[3], ~sectionData,
			preampBusses, accompBusses, postampBusses);
		~sectionNavDict = ~musicData[5];
		~isPlaying = false;
	};

	~patternProxy = EventPatternProxy.new;

	~tempoClock = TempoClock.new(1);
	~dir = thisProcess.nowExecutingPath.dirname;
	"loading app".postln;
	~genAll.value(19800725);
	~play = Synth.new(\masterPlayerControl_ ++ ~hash);
	4.collect({arg p; Synth.new(\clip_ ++ ~hash, [\bin,  accompBusses[p].index, \bus, postampBusses[5].index])});
	~generateGUI.value(preampBusses, accompBusses, postampBusses);
	"ready".postln;
});
appEnvironment.pop;
)
