Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/html/app.js
blob: b54cd9c5c985d07e0b69e2ba171022816ac76de3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

// Sounds theme
var soundThemes = [ "audio/theme_piano", "audio/theme_guitar", "audio/theme_violon", "audio/theme_oboe", "audio/theme_trompet", "audio/theme_mallets", "audio/theme_soprano"];
var soundNotesPos = [ 24, 536, 1024, 1536, 2057, 2569, 3048, 4040, 4552, 5032, 5560, 6064, 6349, 6570, 6836, 7072, 8056, 8560, 9072, 10071, 10575, 11071, 12063, 13061, 14063, 15062 ];


// Main app class
enyo.kind({
	name: "Abcd.App",
	kind: enyo.Control,
	classes: "main",
	components: [
		{components: [
			{name: "logo", kind: "Image", classes: "logo", src: "images/logo.png"},
			{name: "instrument", kind: "Image", classes: "instrument", src: "images/instrument0.png", ontap: "nextInstrument"},
			{name: "letter", content: "", classes: "letter" }
		]},
		{components: [
			{name: "credit", kind: "Image", src: "images/credit.png", classes: "creditButton", ontap: "displayCredits"},
			{name: "learn", kind: "Image", src: "images/learn.png", classes: "learnButton", ontap: "learnGame"},
			{name: "play", kind: "Image", src: "images/play.png", classes: "playButton", ontap: "playGame"},	
			{name: "build", kind: "Image", src: "images/build.png", classes: "buildButton", ontap: "buildGame"}		
		]},
		{kind: "Signals", onEndOfSound: "endOfSound", onSoundTimeupdate: "soundTimeupdate"}		
	],
	
	// Constructor, save home
	create: function() {
		this.inherited(arguments);
		Abcd.context.home = this;
		this.playTheme();
	},
	
	// Play theme
	playTheme: function() {
		this.soundindex = 0;
		this.soundpos = 0;
		Abcd.sound.play(soundThemes[this.soundindex]);
	},
	
	// Play learn game
	learnGame: function(e, s) {
		Abcd.sound.pause();	
		Abcd.context.screen = new Abcd.Learn().renderInto(document.getElementById("body"));	
	},
	
	// Sound ended, play next instrument
	endOfSound: function(e, s) {
		if (s == soundThemes[this.soundindex])
			this.nextInstrument();
	},
	
	nextInstrument: function() {
		this.soundindex = (this.soundindex + 1) % soundThemes.length;
		this.soundpos = 0;
		this.$.letter.setContent("");		
		this.$.instrument.setSrc("images/instrument"+this.soundindex+".png");
		Abcd.sound.play(soundThemes[this.soundindex]);	
	},
	
	soundTimeupdate: function(e, s) {
		for (var i = this.soundpos ; i < soundNotesPos.length ; i++) {
			var val = soundNotesPos[i];
			this.soundpos = i;
			if (s >= val - 50 && s < val + 50) {
				this.$.letter.setContent(String.fromCharCode(65+i));
				return;
			}
			if (val > s) {
				break;
			}
		}
		this.$.letter.setContent("");		
	}
});