{"size": 2455, "ext": "js", "max_stars_repo_path": "sample/chord/viewmodel.js", "max_stars_repo_name": "ruly-rudel/tipsound", "max_stars_repo_stars_event_min_datetime": "2015-04-19T14:23:58.000Z", "max_stars_repo_stars_event_max_datetime": "2015-04-19T14:23:58.000Z", "max_issues_repo_path": "sample/chord/viewmodel.js", "max_issues_repo_name": "ruly-rudel/tipsound", "max_issues_repo_issues_event_min_datetime": "2015-04-19T14:10:12.000Z", "max_issues_repo_issues_event_max_datetime": "2015-06-07T12:52:52.000Z", "max_forks_repo_path": "sample/chord/viewmodel.js", "max_forks_repo_name": "ruly-rudel/tipsound", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 36.1029411765, "max_line_length": 102, "alphanum_fraction": 0.4814663951}
// Main viewmodel class
define(['lib/knockout-3.3.0', 'sample/chord/model', 'js/sf2'], function (ko, model, SF2) {
    "use strict";

    return function () { // ViewModel constructor
        var self = this;
        
        this.prepared = ko.observable(false);
        
        _.XB('http://gauzau.s30.xrea.com/A320U.sf2', function(r) {
            self.sf2 = SF2.createFromArrayBuffer(r);
            self.sf2.parseHeader();
            self.presetList(self.sf2.enumPresets());
            self.preset(self.presetList()[52]);
            self.prepared(true);
        });
        
        this.synth = ko.observable(
            "var p = vm.sf2.readPreset(vm.presetList().indexOf(vm.preset()));\n" +
            "var buf = ts.ModSF2.prepareBuffer(p.gen);\n\n" +
            
            "fg.register(\"piano\", ts.ModPoly(function() { return ts.ModSF2(p.gen, buf); }));\n" +
            "fg.register(\"seq\", ts.ModPolySeq());\n\n" +
    
            "fg.connect(\"seq\", \"piano\");\n" +
            "fg.connect(\"piano\", \"destination\");\n\n" +
            
            "fg.module.piano.parameter.gain.gain(vm.volume());\n\n" +
    
            "var ca = vm.chord().split(/[\\s|]/).filter(function (s) { return s != \"\"; });\n" +
            "var va = vm.breakValue().split(/[\\s|]/).filter(function (s) { return s != \"\"; });\n" +
            "fg.module.seq.parameter.sequence = ts.chordToSequence(ca, va, vm.tempo());\n\n"
        );
        
        //this.chord = ko.observable('C G Am Em F C F G');
        this.chord = ko.observable(
            'A B G#m C#m A B C#7sus4 C#7\n' +
            'A B E E A B E E\n' +
            'A B G# C#m F# F# B Cm6(-5)\n' +
            'C#m C(+5) E/B A#m7(-5) A A A/B B\n'
            );
            
        this.breakValue = ko.observable();
        this.breakKind = ko.observable([
            "[RS]8/3 F8/3 T8/3",
            "[RS]8/3 T8/3 F8/3",
            "R4 [RTFS]4",
        ]);
        
        this.preset = ko.observable();
        this.presetList = ko.observable();
        this.tempo = ko.observable(180);

        this.volume = ko.observable();

        this.playChord = function () {
            model.build(this.synth(), this);
            this.volume.subscribe(model.parameter.piano.gain.gain);
        
            model.play();
        };
        this.recycle = function () { model.recycle(); };
        this.stop = function() { model.stop(); };

        this.volume(1.0);
    };
});
