##synth

//including helper for MoogFilter, SinOsc and Adsr
##include helper

//initializing filter
MoogFilter fil = new MoogFilter();

//main function that gets called every tick
num Tick()
{
	//set filter's cutoff and filter's resonance to custom parameters
	//param['c'] maps to @c and param['r'] to @r and so on; case sensitive!
	fil.cutoff = param['c'];
	fil.res = param['r'];

	//declare variable mod, and set it's value to a sineWave's sample
	//frequency is a keyword, it is filled in by the current note's frequency
	//it is multiplicated by @f
	num mod = SinOsc(frequency*param['f']);

	//apply adsr envelope to mod, parameters are attack, decay, sustain, release
	mod = mod * Adsr(0.05, 0.2, 0.2, 0.2);

	//declare variable sample, and set it's value to a sineWave's sample
	//the second parameter of SineOsc is it's phase, we use mod for it
	//as mod(and any audibles) are only in the range of -1.0 to 1.0 multiply with @m
	num sample = SinOsc(frequency, mod*param['m']);
	
	//apply adsr to sample
	sample = sample * Adsr(0.01, 0.5, 0.5, 0.5, true);
	
	//apply filter to to sample
	sample = fil.Tick(sample);

	//return sample to be played
	return sample;
}

//go into tune mode, all music is written here
##tune

//A stands for the first channel, there is channels from A-Z
//starting with @ are commands, uppercase are builtin, lowercase are custom(look at synth part)
A @I0 @V0.5 @c0.3 @r0.5 @f2 @m4 @O4

// lowercase letters from a-g are notes, a number after it is the notelength(eg. 4=quarter)
// < and > lowers and raises the octave
// a "t" after a note declares a note to be part of a triplet
A d4 d < a8t ft at > d4

//commands can be changed whenever
A @c0.2 @r0.7 @f4 @m8
A d4 d < a8t ft at > d4

A @c0.5 @r0.5 @f0.5 @m4
A d4 d < a8t ft at > d4

//instead of just a number a channel command parameter can be a sequence
//the sequence is written in [val val val]speed, it iterates over all values
//every single step has the length of a note of the value "speed"
//so @f[2 0.5]16 means that @f first is 2, one 16th note later 0.5, one 16th note later 2, and so on
A @c0.3 @f[2 0.5]16 @m4
A d4 d < a8t ft at > d4
