
Template.Score.helpers(
{
	'staves': function(){
		return []
		//return Staves.find()
	}
})

Template.Score.events(
{
	'click #AddContext':function(event,tmpl)
	{
		var svg = $("svg#Staves")[0];
		var renderer = new Vex.Flow.Renderer(svg,
		Vex.Flow.Renderer.Backends.RAPHAEL);
		tmpl.ctx = renderer.getContext();
	},

	'click #AddStave':function(event,tmpl)
	{
		tmpl.stave = new Vex.Flow.Stave(10, 0, 500);
		tmpl.stave.addClef("treble").setContext(tmpl.ctx).draw();
	},

	'click #AddVoice':function(event,tmpl)
	{
		// Create a voice in 4/4
		voice = new Vex.Flow.Voice({
		    num_beats: 4,
		    beat_value: 4,
		    resolution: Vex.Flow.RESOLUTION
		  });
	},
	
	'click #AddNote':function(event,tmpl)
	{
		
	  // Create the notes
	  var notes = [
	    // A quarter-note C.
	    new Vex.Flow.StaveNote({ keys: ["c/4"], duration: "q" }),

	    // A quarter-note D.
	    new Vex.Flow.StaveNote({ keys: ["d/4"], duration: "q" }),

	    // A quarter-note rest. Note that the key (b/4) specifies the vertical
	    // position of the rest.
	    new Vex.Flow.StaveNote({ keys: ["b/4"], duration: "qr" }),

	    // A C-Major chord.
	    new Vex.Flow.StaveNote({ keys: ["c/4", "e/4", "g/4"], duration: "q" })
	  ];

		// Add notes to voice
  		voice.addTickables(notes);

  		// Format and justify the notes to 500 pixels
		  var formatter = new Vex.Flow.Formatter().
		    joinVoices([voice]).format([voice], 500);

		  // Render voice
		  voice.draw(tmpl.ctx,tmpl.stave);
	}

})





