"use strict";

/* --------------------------------------------------- */
/* SkyDragon Story track 15 (02a)                      */
/* Self; Pity...                                       */
/* (Goddess Catacombs theme)                           */
/* (c) Sean Kelly, 2016                                */
/* --------------------------------------------------- */
// This tune used to rely on purely the loop flag for all channels
// even though sq/sin/st are half the total duration of tri.
// This is perfectly legal, but plays poorly with tune transition
// queueing, which will cut over each channel when it runs empty.
DATA_CHIPTUNES["Self; Pity"] = {
		"chip": "oneofeach"
	,	"bpm": 240 // beats per minute; 120 in 8ths
	,	"priority": 1 // baseline nonzero for BGM
	,	"songdata" : {
			"sq":	// name of a channel on the chip	
				[
					{"command": "env", // set linear ramp envelope applied to every note; dur is measured in seconds, 0 means length of current note
						"data": {"start": 1.0, "end": 0.0, "dur": 0.5}
					}
				,	{"command": "sweep", // set linear frequency sweep applied to every note (start and end multiply base note frequency)
						"data": {"start": 1.0, "end": 1.0, "dur": 0}
					}
				,	{"command": "vol", // set overall volume of channel; 0.1 is a sane "loud" level
						"data": {"level": 0.025}
					}
				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.5}
					}
				//,	{"command": "tempo", // change tempo mid-tune
				//		"data": {"bpm": 120}
				//	}
				,	{"command": "detune", // detune in cents to be applied to the oscillator (for "richer" sound when 2 similar frequencies overlap)
						"data": {"cents": 0}
					}
				
				,	{"command": "jump", // reset the loop counter
						"data": {"reset": true}
					}

				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 1.2"
						,	"En5 .8"
						,	"Gn5 1.2"
						,	"Cn6 .8"
						,	"En6 1.2"
						,	"Cn6 .8"
						,	"Dn6 1.2"
						,	"Bn5 .8"
						,	"Gn5 2"
						,	"Dn6 6"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 1.2"
						,	"Cn4 .8"
						,	"Fn4 1.2"
						,	"An4 .8"
						,	"Cn5 1.2"
						,	"An4 .8"
						,	"Bn4 1.2"
						,	"Gn4 .8"
						,	"Dn4 2"
						,	"Gn4 6"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 1.2"
						,	"En5 .8"
						,	"Gn5 1.2"
						,	"Cn6 .8"
						,	"En6 1.2"
						,	"Cn6 .8"
						,	"Dn6 1.2"
						,	"Bn5 .8"
						,	"Gn5 2"
						,	"Gn6 6"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 1.2"
						,	"En4 .8"
						,	"Fn4 1.2"
						,	"Cn5 .8"
						,	"An4 1.2"
						,	"Fn4 .8"
						,	"Bn4 1.2"
						,	"Gn4 .8"
						,	"Dn4 2"
						,	"Bn3 6"
						]
					}

				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 2"
						,	"Fn5 1.2"
						,	"Cn6 .8"
						,	"An5 1.2"
						,	"Fn5 .8"
						,	"Gn5 1.2"
						,	"Dn6 .8"
						,	"Bn5 1.2"
						,	"Gn5 4.8"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 2"
						,	"Fn4 1.2"
						,	"Cn5 .8"
						,	"An4 1.2"
						,	"Fn4 .8"
						,	"Bn4 1.2"
						,	"Gn4 .8"
						,	"Dn4 1.2"
						,	"Gn4 4.8"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 2"
						,	"Fn5 1.2"
						,	"Cn6 .8"
						,	"An5 1.2"
						,	"Fn5 .8"
						,	"Gn5 1.2"
						,	"Dn6 .8"
						,	"Bn5 1.2"
						,	"Gn5 4.8"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 2"
						,	"Fn4 1.2"
						,	"Cn5 .8"
						,	"An4 1.2"
						,	"Fn4 .8"
						,	"Bn4 1.2"
						,	"Gn4 .8"
						,	"Dn4 4"
						,	"Gn4 4"
						]
					}

				,	{"command": "jump", // go forwards/backwards delta commands if loop counter < times; increase loop counter
						"data": {"delta": -8, "times": 1}
					}

				//,	{"command": "jump", // reset the loop counter
				//		"data": {"reset": true}
				//	}
				//,	{"command": "jump", // go forwards/backwards delta commands if loop counter < times; increase loop counter
				//		"data": {"delta": -4, "times": 1}
				//	}
				]
		,	"sin":	// name of a channel on the chip	
				[
					{"command": "env", // set linear ramp envelope applied to every note
						"data": {"start": 1.0, "end": 0.5, "dur": 2}
					}
				,	{"command": "sweep", // set linear frequency sweep applied to every note (start and end multiply base note frequency)
						"data": {"start": 1.0, "end": 1.0, "dur": 0}
					}
				,	{"command": "vol", // set overall volume of channel
						"data": {"level": 0.075}
					}
				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.5}
					}
				//,	{"command": "tempo", // change tempo mid-tune
				//		"data": {"bpm": 120}
				//	}
				,	{"command": "detune", // detune in cents to be applied to the oscillator (for "richer" sound when 2 similar frequencies overlap)
						"data": {"cents": 2}
					}
				
				,	{"command": "jump", // reset the loop counter
						"data": {"reset": true}
					}

				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Cn3 6"
						,	"Bn2 8"
						,	"Cn3 2"
						,	"An2 6"
						,	"Gn2 6"
						,	"Bn2 4"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Cn3 6"
						,	"Bn2 8"
						,	"Cn3 2"
						,	"An2 6"
						,	"Gn2 6"
						,	"En2 4"
						]
					}

				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Fn2 6"
						,	"Gn2 6"
						,	"En2 2"
						,	"Fn2 6"
						,	"Gn2 4"
						,	"Dn2 2"
						,	"Bn1 2"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Fn2 6"
						,	"Gn2 6"
						,	"En2 2"
						,	"Fn2 6"
						,	"Gn2 8"
						,	"Dn2 2"
						]
					}

				,	{"command": "jump", // go forwards/backwards delta commands if loop counter < times; increase loop counter
						"data": {"delta": -4, "times": 1}
					}
				]
		,	"st":	// name of a channel on the chip	
				[
					{"command": "env", // set linear ramp envelope applied to every note; dur is measured in seconds, 0 means length of current note
						"data": {"start": 1.0, "end": 0.0, "dur": 0.5}
					}
				,	{"command": "sweep", // set linear frequency sweep applied to every note (start and end multiply base note frequency)
						"data": {"start": 1.0, "end": 1.0, "dur": 0}
					}
				,	{"command": "vol", // set overall volume of channel; 0.1 is a sane "loud" level
						"data": {"level": 0.025}
					}
				,	{"command": "detune", // detune in cents to be applied to the oscillator (for "richer" sound when 2 similar frequencies overlap)
						"data": {"cents": 2}
					}

				,	{"command": "jump", // reset the loop counter
						"data": {"reset": true}
					}

				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.75}
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 1.4"
						,	"En5 .8"
						,	"Gn5 1.2"
						,	"Cn6 .8"
						,	"En6 1.2"
						,	"Cn6 .8"
						,	"Dn6 1.2"
						,	"Bn5 .8"
						,	"Gn5 2"
						,	"Dn6 6"
						]
					}
				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.25}
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 1.2"
						,	"Cn4 .8"
						,	"Fn4 1.2"
						,	"An4 .8"
						,	"Cn5 1.2"
						,	"An4 .8"
						,	"Bn4 1.2"
						,	"Gn4 .8"
						,	"Dn4 2"
						,	"Gn4 6"
						]
					}
				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.75}
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 1.2"
						,	"Gn4 .8"
						,	"Cn5 1.2"
						,	"En5 .8"
						,	"Gn5 1.2"
						,	"En5 .8"
						,	"Gn5 1.2"
						,	"Dn5 .8"
						,	"Bn4 2"
						,	"Bn5 6"
						]
					}
				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.25}
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 1.2"
						,	"An4 .8"
						,	"Cn5 1.2"
						,	"An5 .8"
						,	"Fn5 1.2"
						,	"Cn5 .8"
						,	"Gn5 1.2"
						,	"Dn5 .8"
						,	"Bn4 2"
						,	"Gn4 6"
						]
					}

				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.75}
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 2"
						,	"Fn5 1.2"
						,	"Cn6 .8"
						,	"An5 1.2"
						,	"Fn5 .8"
						,	"Gn5 1.2"
						,	"Dn6 .8"
						,	"Bn5 1.2"
						,	"Gn5 4.8"
						]
					}
				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.25}
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 2"
						,	"Fn4 1.2"
						,	"Cn5 .8"
						,	"An4 1.2"
						,	"Fn4 .8"
						,	"Bn4 1.2"
						,	"Gn4 .8"
						,	"Dn4 1.2"
						,	"Gn4 4.8"
						]
					}
				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.75}
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 2"
						,	"An4 1.2"
						,	"Fn5 .8"
						,	"Cn5 1.2"
						,	"An4 .8"
						,	"Bn4 1.2"
						,	"Gn5 .8"
						,	"Dn5 1.2"
						,	"Bn4 4.8"
						]
					}
				,	{"command": "pan", // linearly-divided fraction of the audio going to the right channel, with the remainder going to the left
						"data": {"position": 0.25}
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 2"
						,	"An4 1.2"
						,	"Fn5 .8"
						,	"Cn5 1.2"
						,	"An4 .8"
						,	"Gn5 1.2"
						,	"Dn5 .8"
						,	"Bn4 4"
						,	"Fn5 3.8"
						]
					}

				,	{"command": "jump", // go forwards/backwards delta commands if loop counter < times; increase loop counter
						"data": {"delta": -16, "times": 1}
					}
				]
		,	"tri":	// name of a channel on the chip	
				[
					{"command": "env", // set linear ramp envelope applied to every note
						"data": {"start": 0.75, "end": 1.0, "dur": 0.0}
					}
				,	{"command": "vol", // set overall volume of channel
						"data": {"level": 0.05}
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Rst 122"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Gn4 6"
						,	"Gn4 6"
						,	"En5 2"
						,	"Cn5 2"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Gn4 6"
						,	"Gn4 6"
						,	"Gn4 4"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Gn4 6"
						,	"Gn4 6"
						,	"En5 2"
						,	"An4 2"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Gn4 6"
						,	"Gn4 6"
						,	"Gn4 4"
						]
					}

				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"An4 6"
						,	"Bn4 6"
						,	"Cn5 2"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"An4 6"
						,	"Bn4 6"
						,	"Gn4 2"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"An4 6"
						,	"Bn4 6"
						,	"Cn5 2"
						]
					}
				,	{"command": "notes", // strings of the form "NnO L" where NnO is the Note-modifier-Octave note to play (from DEF_CHIPTUNE_PITCHES) and L is the length in beats or fractions (can be multiple characters as long as parseFloat will take it)
						"data": [
							"Cn5 6"
						,	"Dn5 8"
						,	"En5 2"
						]
					}
				]
		}
	};
