Large diffs are not rendered by default.

@@ -0,0 +1,3 @@
var $builtinmodule = function() {
return {};
};
@@ -0,0 +1,49 @@
var $builtinmodule = function() {
var mod, sampleWrapper;

mod = {};

sampleWrapper = {
getSound : new Sk.builtin.func(function (sample) {
Sk.builtin.pyCheckArgs('getSound', arguments, 1);
return sample._sound;
}),

getSampleValue : new Sk.builtin.func(function (sample) {
Sk.builtin.pyCheckArgs('getSampleValue', arguments, 1);
return new Sk.builtin.float_(sample._internalSound.getLeftSample(sample._index));
}),

setSampleValue : new Sk.builtin.func(function (sample, value) {
Sk.builtin.pyCheckArgs('setSampleValue', arguments, 2);
sample._internalSound.setLeftSample(sample._index, Sk.ffi.unwrapo(value));
}),
};

mod.Sample = Sk.misceval.buildClass(mod, function ($gbl, $loc) {
$loc.__init__ = new Sk.builtin.func(function (self, sound, index) {
Sk.builtin.pyCheckArgs('__init__', arguments, 3);
self._sound = sound;
self._internalSound = sound._sound;
self._index = Sk.ffi.unwrapo(index);
});

$loc.__str__ = new Sk.builtin.func(function (self) {
Sk.builtin.pyCheckArgs('__str__', arguments, 1);
return new Sk.builtin.str('Sample at ' + self._index + ' with value ' +
self._internalSound.getLeftSample(self._index));
});

$loc.__repr__ = new Sk.builtin.func(function (self) {
Sk.builtin.pyCheckArgs('__repr__', arguments, 1);
return new Sk.builtin.str('Sample at ' + self._index + ' with value ' +
self._internalSound.getLeftSample(self._index));
});

goog.object.extend($loc, sampleWrapper);
}, 'Sample', []);

goog.object.extend(mod, sampleWrapper);

return mod;
};
@@ -0,0 +1,317 @@
// Do not include this module directly as it has dependencies
var $builtinmodule = function() {
var soundWrapper, mod, Sample;

mod = {};

// Dependency
Sample = Sk.sysmodules.mp$subscript('sound.sample').$d.Sample;

soundWrapper = {
stopPlaying: new Sk.builtin.func(function (sound) {
Sk.builtin.pyCheckArgs('stopPlaying', arguments, 1);
sound._sound.stop();
}),

play : new Sk.builtin.func(function(sound) {
Sk.builtin.pyCheckArgs('play', arguments, 1);
sound._sound.play();
}),

blockingPlay : new Sk.builtin.func(function(sound) {
Sk.builtin.pyCheckArgs('blockingPlay', arguments, 1);
Sk.future(function (continueWith) {
sound._sound.play(continueWith);
});
}),

getDuration : new Sk.builtin.func(function(sound) {
Sk.builtin.pyCheckArgs('getDuration', arguments, 1);
return new Sk.builtin.float_(sound._sound.getDuration());
}),

getNumSamples : new Sk.builtin.func(function(sound) {
Sk.builtin.pyCheckArgs('getNumSamples', arguments, 1);
return new Sk.builtin.int_(sound._sound.getLength());
}),

getLength : new Sk.builtin.func(function(sound) {
Sk.builtin.pyCheckArgs('getLength', arguments, 1);
return new Sk.builtin.int_(sound._sound.getLength());
}),

getSamplingRate : new Sk.builtin.func(function(sound) {
Sk.builtin.pyCheckArgs('getSamplingRate', arguments, 1);
return new Sk.builtin.int_(sound._sound.getSamplingRate());
}),

setSampleValueAt : new Sk.builtin.func(function(sound, index, value) {
var length;

Sk.builtin.pyCheckArgs('setSampleValueAt', arguments, 3);

length = sound._sound.getLength();

if(index < 0 || index >= length) {
throw new Sk.builtin.ValueError('Index must have a value between 0 and ' + length);
}

if(!(value instanceof Sk.builtin.int_)) {
throw new Sk.builtin.TypeError('Value must be an integer');
}

value = Sk.ffi.unwrapo(value);

if(value < -32768) { value = -32768; }
if(value > 32767) { value = 32767; }

sound._sound.setLeftSample(Sk.ffi.unwrapo(index), pythy.Sound.map16BitIntToFloat(value));
}),

setLeftSample : new Sk.builtin.func(function(sound, index, value) {
var length;

Sk.builtin.pyCheckArgs('setLeftSample', arguments, 3);

length = sound._sound.getLength();

if(index < 0 || index >= length) {
throw new Sk.builtin.ValueError('Index must have a value between 0 and ' + length);
}

if(!(value instanceof Sk.builtin.int_)) {
throw new Sk.builtin.TypeError('Value must be an integer');
}

value = Sk.ffi.unwrapo(value);

if(value < -32768) { value = -32768; }
if(value > 32767) { value = 32767; }

sound._sound.setLeftSample(Sk.ffi.unwrapo(index), pythy.Sound.map16BitIntToFloat(value));
}),

setRightSample : new Sk.builtin.func(function(sound, index, value) {
var length;

Sk.builtin.pyCheckArgs('setRightSample', arguments, 3);

length = sound._sound.getLength();

if(index < 0 || index >= length) {
throw new Sk.builtin.ValueError('Index must have a value between 0 and ' + length);
}

if(!(value instanceof Sk.builtin.int_)) {
throw new Sk.builtin.TypeError('Value must be an integer');
}

value = Sk.ffi.unwrapo(value);

if(value < -32768) { value = -32768; }
if(value > 32767) { value = 32767; }

sound._sound.setRightSample(Sk.ffi.unwrapo(index), pythy.Sound.map16BitIntToFloat(value));
}),

getSampleValueAt : new Sk.builtin.func(function(sound, index) {
var length;

Sk.builtin.pyCheckArgs('getSampleValueAt', arguments, 2);

length = sound._sound.getLength();

if(index < 0 || index >= length) {
throw new Sk.builtin.ValueError('Index must have a value between 0 and ' + length);
}

return new Sk.builtin.int_(pythy.Sound.mapFloatTo16BitInt(sound._sound.getLeftSample(Sk.ffi.unwrapo(index))));
}),

getLeftSample : new Sk.builtin.func(function(sound, index) {
var length;

Sk.builtin.pyCheckArgs('getLeftSample', arguments, 2);

length = sound._sound.getLength();

if(index < 0 || index >= length) {
throw new Sk.builtin.ValueError('Index must have a value between 0 and ' + length);
}

return new Sk.builtin.int_(pythy.Sound.mapFloatTo16BitInt(sound._sound.getLeftSample(Sk.ffi.unwrapo(index))));
}),

getRightSample : new Sk.builtin.func(function(sound, index) {
var length;

Sk.builtin.pyCheckArgs('getRightSample', arguments, 2);

length = sound._sound.getLength();

if(index < 0 || index >= length) {
throw new Sk.builtin.ValueError('Index must have a value between 0 and ' + length);
}

return new Sk.builtin.int_(pythy.Sound.mapFloatTo16BitInt(sound._sound.getRightSample(Sk.ffi.unwrapo(index))));
}),

getSampleObjectAt : new Sk.builtin.func(function (sound, index) {
var length;

Sk.builtin.pyCheckArgs('getSampleObjectAt', arguments, 2);

length = sound._sound.getLength();

if(index < 0 || index >= length) {
throw new Sk.builtin.ValueError('Index must have a value between 0 and ' + length);
}

return Sk.misceval.callsim(Sample, sound, index);
}),

getSamples : new Sk.builtin.func(function (sound) {
var samples, len;

Sk.builtin.pyCheckArgs('getSamples', arguments, 1);

samples = [];
len = sound._sound.getLength();

for(var i = 0; i < len; i++) {
samples.push(Sk.misceval.callsim(Sample, sound, Sk.builtin.int_(i)));
}

return new Sk.builtin.list(samples);
})
};

mod.Sound = Sk.misceval.buildClass(mod, function ($gbl, $loc) {
var onError;

onError = function (continueWith) {
return function (errorMsg) {
if(errorMsg.indexOf('File') !== -1) {
continueWith(new Sk.builtin.ValueError(errorMsg + '. Is the URL incorrect?'));
} else {
continueWith(new Sk.builtin.ValueError(errorMsg));
}
}
};

$loc.__init__ = new Sk.builtin.func(function (sound) {
var arg0, res, arg1, arg2;

Sk.builtin.pyCheckArgs('__init__', arguments, [2, 3]);

arg0 = arguments[1];

if(arg0 instanceof Sk.builtin.str) {
arg0 = Sk.ffi.unwrapo(arg0); //url
res = Sk.future(function (continueWith) {
new window.pythy.Sound(continueWith, onError(continueWith), arg0);
});
} else if(arg0.tp$name === 'Sound') {
res = Sk.future(function (continueWith) {
new window.pythy.Sound(continueWith, onError(continueWith), arg0._sound);
});
} else {
arg1 = Sk.ffi.unwrapo(arguments[1]); //numSamples
arg2 = Sk.ffi.unwrapo(arguments[2]); //samplingRate
res = Sk.future(function (continueWith) {
new window.pythy.Sound(continueWith, onError(continueWith), arg1, arg2);
});
}

if(res instanceof window.pythy.Sound) {
sound._sound = res;
} else if(res) {
throw res;
}
});

$loc.__str__ = new Sk.builtin.func(function(sound) {
var str;

Sk.builtin.pyCheckArgs('__str__', arguments, 1);

str = 'Sound, ';

if(sound._sound.url) {
str += 'File: ' + sound._sound.url + ', ';
}

return new Sk.builtin.str(str + 'Number of samples: ' + sound._sound.getLength());
});

$loc.__repr__ = new Sk.builtin.func(function(sound) {
var str;

Sk.builtin.pyCheckArgs('__repr__', arguments, 1);

str = 'Sound, ';

if(sound._sound.url) {
str += 'File: ' + sound._sound.url + ', ';
}

return new Sk.builtin.str(str + 'Number of samples: ' + sound._sound.getLength());
});

$loc.writeToFile = new Sk.builtin.func(function(sound, path) {
Sk.builtin.pyCheckArgs('writeToFile', arguments, 2);
sound._sound.save(Sk.ffi.unwrapo(path));
});

$loc.duplicate = new Sk.builtin.func(function (sound) {
Sk.builtin.pyCheckArgs('duplicate', arguments, 1);
return Sk.misceval.callsim(mod.Sound, sound);
});

goog.object.extend($loc, soundWrapper);

}, 'Sound', []);

goog.object.extend(mod, soundWrapper);

goog.object.extend(mod, {
duplicateSound: new Sk.builtin.func(function (sound) {
Sk.builtin.pyCheckArgs('duplicateSound', arguments, 1);
return Sk.misceval.callsim(mod.Sound, sound);
}),

makeSound: new Sk.builtin.func(function (url) {
Sk.builtin.pyCheckArgs('makeSound', arguments, 1);
return Sk.misceval.callsim(mod.Sound, url);
}),

makeEmptySound: new Sk.builtin.func(function (numSamples, samplingRate) {
Sk.builtin.pyCheckArgs('makeEmptySound', arguments, [1, 2]);
return Sk.misceval.callsim(mod.Sound, numSamples, samplingRate);
}),

makeEmptySoundBySeconds: new Sk.builtin.func(function (seconds, samplingRate) {
var numSamples;

Sk.builtin.pyCheckArgs('makeEmptySoundBySeconds', arguments, [1, 2]);

if(Sk.ffi.unwrapo(seconds) < 0) {
throw new Sk.builtin.ValueError('Duration can not be negative');
}
numSamples = Sk.ffi.unwrapo(seconds) * (Sk.ffi.unwrapo(samplingRate) || window.pythy.Sound.SAMPLE_RATE);
return Sk.misceval.callsim(mod.Sound, new Sk.builtin.int_(numSamples), samplingRate);
}),

openSoundTool: new Sk.builtin.func(function (sound) {
Sk.builtin.pyCheckArgs('openSoundTool', arguments, 1);
window.pythy.soundTool.start(sound._sound);
}),

writeSoundTo : new Sk.builtin.func(function(sound, path) {
Sk.builtin.pyCheckArgs('writeSoundTo', arguments, 2);
sound._sound.save(Sk.ffi.unwrapo(path));
})
});

return mod;
};
@@ -0,0 +1,46 @@
var $builtinmodule = function(name)
{
var mod = {};

var STOCK_REPORTS = {
'FB': [ 1.1, 1.0, 0.7, 0.12, -0.3, -0.34, -0.1, -0.45, -0.74],
'AAPL': [ 0.47, 0.53, 0.42, 0.41, 0.30, 0.10, -0.46, -0.84, -1.13],
'MSFT': [ 0.75, 0.80, 0.71, 0.67, 0.5, 0.15, 0.09, 0.03, 0.31],
'GOOG': [-0.27, -0.15, -0.11, 0.12, 0.3, 0.1, -0.3, -0.1, -0.09]};

function normalize_ticker(ticker) {
switch (ticker.toLowerCase()) {
case "facebook": case "fb":
return "FB";
case "apple": case "aapl":
return "AAPL";
case "microsoft": case "msft":
return "MSFT";
case "google": case "goog":
return "GOOG";
default: return null;
}
}

mod.get_current = new Sk.builtin.func(function(ticker) {
Sk.builtin.pyCheckArgs("get_current", arguments, 1, 1);
Sk.builtin.pyCheckType("ticker", "string", Sk.builtin.checkString(ticker));
ticker = normalize_ticker(ticker.v);
if (ticker === null) {
throw new Sk.builtin.ValueError("Stock data is only available for the following companies: Facebook, Apple, Microsoft, Google.");
}
return Sk.ffi.remapToPy(STOCK_REPORTS[ticker][0]);
});

mod.get_past = new Sk.builtin.func(function(ticker) {
Sk.builtin.pyCheckArgs("get_past", arguments, 1, 1);
Sk.builtin.pyCheckType("ticker", "string", Sk.builtin.checkString(ticker));
ticker = normalize_ticker(ticker.v);
if (ticker === null) {
throw new Sk.builtin.ValueError("Stock data is only available for the following companies: Facebook, Apple, Microsoft, Google.");
}
return Sk.ffi.remapToPy(STOCK_REPORTS[ticker]);
});

return mod;
}