640,6,158,8,107,29,87,27,273,48,1683,17,2045,29,232,30,229,24,177,23,252,34,290,26,390,28,187,36,794,44,916,51,574,44,305,49,536,31,1292,45,559,50,321,43,726,43,527,52,1041,37,837,69,733,57,1039,72,396,56,322,70,287,58,115,54,129,56,154,42,2511,60,387,79,365,40,415,69,132,65,425,46,460,24,991,32,1073,46,369,46,307,40,191,44,538,37,401,35,378,37,265,31,390,34,1583,57,588,57,464,55,228,56,226,70,184,51,555,58,174,47,752,63,825,40,302,36,670,34,951,26,796,27,1161,37,496,36,364,52,254,42,1042,27,1240,40,337,26,837,37,884,34,2660,37,430,51,352,38,367,51,466,24,1805,43,666,38,890,40,1971,37,775,28,1834,25,2714,36,1969,33,816,19,3449,8,18
_info
{"project":"music-components","branch":"master","version":51,"versionDate":"2024-05-22T13:24:25.000Z","fromVersion":0,"reset":true,"checksumDocs":"88-66735"}
init.ls
(function(){
return function(sound){
return window.MusicStaff = include("musicStaff/musicStaff");
};
})();
lib/calcNoteDuration/calc.ls
(function(){
return function(value, bpm){
return value * 4 * 60 / bpm * 1000;
};
})();
lib/calcTotalBeats/calc.ls
(function(){
return function(notesParsed){
var totalBars, i$, len$, note, totalBeats;
totalBars = 0;
for (i$ = 0, len$ = notesParsed.length; i$ < len$; ++i$) {
note = notesParsed[i$];
totalBars += note.dottedValue;
}
totalBeats = totalBars * 4;
return totalBeats;
};
})();
lib/external/wavAudioEncoder/wavAudioEncoder.js
// https://github.com/higuma/wav-audio-encoder-js
(function(self) {
var min = Math.min,
max = Math.max;
var setString = function(view, offset, str) {
var len = str.length;
for (var i = 0; i < len; ++i)
view.setUint8(offset + i, str.charCodeAt(i));
};
var Encoder = function(sampleRate, numChannels) {
this.sampleRate = sampleRate;
this.numChannels = numChannels;
this.numSamples = 0;
this.dataViews = [];
};
Encoder.prototype.encode = function(buffer) {
var len = buffer[0].length,
nCh = this.numChannels,
view = new DataView(new ArrayBuffer(len * nCh * 2)),
offset = 0;
for (var i = 0; i < len; ++i)
for (var ch = 0; ch < nCh; ++ch) {
var x = buffer[ch][i] * 0x7fff;
view.setInt16(offset, x < 0 ? max(x, -0x8000) : min(x, 0x7fff), true);
offset += 2;
}
this.dataViews.push(view);
this.numSamples += len;
};
Encoder.prototype.finish = function(mimeType) {
var dataSize = this.numChannels * this.numSamples * 2,
view = new DataView(new ArrayBuffer(44));
setString(view, 0, 'RIFF');
view.setUint32(4, 36 + dataSize, true);
setString(view, 8, 'WAVE');
setString(view, 12, 'fmt ');
view.setUint32(16, 16, true);
view.setUint16(20, 1, true);
view.setUint16(22, this.numChannels, true);
view.setUint32(24, this.sampleRate, true);
view.setUint32(28, this.sampleRate * 4, true);
view.setUint16(32, this.numChannels * 2, true);
view.setUint16(34, 16, true);
setString(view, 36, 'data');
view.setUint32(40, dataSize, true);
this.dataViews.unshift(view);
var blob = new Blob(this.dataViews, { type: 'audio/wav' });
this.cleanup();
return blob;
};
Encoder.prototype.cancel = Encoder.prototype.cleanup = function() {
delete this.dataViews;
};
self.WavAudioEncoder = Encoder;
})(window);
lib/keys/keys.ls
(function(){
var octaveShifts, notes, sharpKeysMaj, flatKeysMaj, sharpKeysMin, flatKeysMin, keys, i$, len$, i, sharpKey, flatKey;
octaveShifts = {
flat: {
violin: [0, 1, 0, 1, 0, 1],
bass: [-1, 0, -1, 0, -1, 0],
alto: [-1, 0, -1, 0, -1, 0]
},
sharp: {
violin: [1, 1, 1, 1, 0, 1],
bass: [0, 0, 0, 0, -1, 0],
alto: [0, 0, 0, 0, -1, 0]
}
};
notes = {
flat: ["B", "E", "A", "D", "G", "C"],
sharp: ["F", "C", "G", "D", "A", "E"]
};
sharpKeysMaj = ["Gmaj", "Dmaj", "Amaj", "Emaj", "Hmaj", "Fsmaj"];
flatKeysMaj = ["Fmaj", "Bfmaj", "Efmaj", "Afmaj", "Dfmaj", "Gfmaj"];
sharpKeysMin = ["Emin", "Bmin", "Fsmin", "Csmin", "Gsmin", "Dsmin"];
flatKeysMin = ["Dmin", "Gmin", "Cmin", "Fmin", "Bfmin", "Efmin"];
keys = {};
for (i$ = 0, len$ = sharpKeysMaj.length; i$ < len$; ++i$) {
i = i$;
sharpKey = sharpKeysMaj[i$];
keys[sharpKey] = {
sign: "sharp",
notes: notes.sharp.slice(0, i + 1),
octaveShifts: {
violin: octaveShifts.sharp.violin.slice(0, i + 1),
bass: octaveShifts.sharp.bass.slice(0, i + 1),
alto: octaveShifts.sharp.alto.slice(0, i + 1)
}
};
}
for (i$ = 0, len$ = flatKeysMaj.length; i$ < len$; ++i$) {
i = i$;
flatKey = flatKeysMaj[i$];
keys[flatKey] = {
sign: "flat",
notes: notes.flat.slice(0, i + 1),
octaveShifts: {
violin: octaveShifts.flat.violin.slice(0, i + 1),
bass: octaveShifts.flat.bass.slice(0, i + 1),
alto: octaveShifts.flat.alto.slice(0, i + 1)
}
};
}
for (i$ = 0, len$ = sharpKeysMin.length; i$ < len$; ++i$) {
i = i$;
sharpKey = sharpKeysMin[i$];
keys[sharpKey] = {
sign: "sharp",
notes: notes.sharp.slice(0, i + 1),
octaveShifts: {
violin: octaveShifts.sharp.violin.slice(0, i + 1),
bass: octaveShifts.sharp.bass.slice(0, i + 1),
alto: octaveShifts.sharp.alto.slice(0, i + 1)
}
};
}
for (i$ = 0, len$ = flatKeysMin.length; i$ < len$; ++i$) {
i = i$;
flatKey = flatKeysMin[i$];
keys[flatKey] = {
sign: "flat",
notes: notes.flat.slice(0, i + 1),
octaveShifts: {
violin: octaveShifts.flat.violin.slice(0, i + 1),
bass: octaveShifts.flat.bass.slice(0, i + 1),
alto: octaveShifts.flat.alto.slice(0, i + 1)
}
};
}
return keys;
})();
lib/svg/shape/arrow-left.svg
lib/svg/shape/arrow-right.svg
lib/svg/shape/minus.svg
lib/svg/shape/plus.svg
lib/util/downloadFile/download.ls
(function(){
return function(fileName, fileBlob){
var blobUrl, a;
blobUrl = URL.createObjectURL(fileBlob);
a = document.createElement('a');
a.href = blobUrl;
a.download = fileName || 'ide-download.mp3';
document.body.appendChild(a);
a.click();
return document.body.removeChild(a);
};
})();
lib/util/heapInfo/info.ls
(function(){
return function(n){
var n2, heapInfo;
if (!include("../isDebug/isDebug")()) {
return;
}
n = _.replaceAll(n, "/../", "");
n = _.replaceAll(n, "-", "_");
n = _.replaceAll(n, "/", "_");
n2 = "heap_info_" + n;
heapInfo = eval("function " + n2 + "(){};\nnew " + n2 + "();");
n = _.replaceAll(n, "page_app01_pages_", "");
heapInfo[n] = new XMLSerializer();
return heapInfo;
};
})();
lib/util/isDebug/isDebug.ls
(function(){
return function(){
var debug;
debug = Store("debug");
if (debug == null) {
debug = false;
} else if (!debug) {
debug = false;
Store.remove("debug");
}
return debug;
};
})();
lib/util/loadSoundsAsBase64/load.ls
(function(){
return function(urls, done){
var currentUrl, resultSoundsBase64, loadSoundAsBase64, next;
urls = _.ensureArray(urls);
currentUrl = -1;
resultSoundsBase64 = [];
loadSoundAsBase64 = function(url){
return include("/lib/util/loadWithCache/load")({
url: url.url,
type: "base64",
localCacheFolder: "base64CacheSounds",
localCacheFileName: "musicComponents_Sampler_" + url.file,
validateFunction: function(base64){
return base64.indexOf("data:audio/mpeg") === 0;
},
onLoaded: function(base64){
resultSoundsBase64.push(base64);
return next();
},
onLoadFailed: function(error){
return debug('load sound error', error);
}
});
};
next = function(){
if (++currentUrl === urls.length) {
done(resultSoundsBase64);
return;
}
return loadSoundAsBase64(urls[currentUrl]);
};
return next();
};
})();
lib/util/loadWithCache/download/_xhr/xhr.ls
(function(){
return function(p){
var onError, xhr;
onError = function(error){
if (p.retry) {
return p.onFailed(error);
} else {
p.retry = true;
return setTimeout(function(){
return include(THISFILE)(p);
}, 100);
}
};
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
var result, blob, reader;
if (xhr.readyState !== 4) {
return;
}
if (xhr.status === 500) {
onError("not_found");
return;
}
if (xhr.status !== 200) {
onError("offline");
return;
}
if (p.responseType === "json") {
result = xhr.response;
return p.onLoaded(result);
} else if (p.responseType === "blob") {
blob = xhr.response;
reader = new window.FileReader();
reader.readAsDataURL(blob);
return reader.onloadend = function(){
var base64;
base64 = reader.result;
return p.onLoaded(base64);
};
}
};
xhr.open("GET", p.url);
xhr.setRequestHeader("X-auth-token", Store("token"));
xhr.responseType = p.responseType;
return xhr.send();
};
})();
lib/util/loadWithCache/download/base64/download.ls
(function(){
return function(o){
return include("../_xhr/xhr")({
url: o.url,
responseType: "blob",
onFailed: function(error){
return typeof o.onLoadFailedPool == 'function' ? o.onLoadFailedPool(error) : void 8;
},
onLoaded: function(result){
o.base64 = result;
if (!_.includes(o.base64, ";base64,") || o.validateFunction(o.base64) !== true) {
if (typeof o.onLoadFailedPool == 'function') {
o.onLoadFailedPool("corrupted");
}
return;
}
if (engine.isMobileApp !== true) {
return o.onLoadedPool(o.base64);
} else {
return include("../../saveToCache/save")(o);
}
}
});
};
})();
lib/util/loadWithCache/download/download.ls
(function(){
return function(o){
if (engine.simulateOffline) {
return typeof o.onLoadFailedPool == 'function' ? o.onLoadFailedPool("simulateOffline download blocked") : void 8;
} else if (o.type === "base64") {
return include("base64/download")(o);
} else {
return include("text/download")(o);
}
};
})();
lib/util/loadWithCache/download/text/download.ls
(function(){
return function(o){
return include("../_xhr/xhr")({
url: o.url,
responseType: "json",
onFailed: function(error){
return typeof o.onLoadFailedPool == 'function' ? o.onLoadFailedPool(error) : void 8;
},
onLoaded: function(result){
o.text = result.text;
if (o.validateFunction(o.text) !== true) {
if (typeof o.onLoadFailedPool == 'function') {
o.onLoadFailedPool("corrupted");
}
return;
}
if (engine.isMobileApp !== true) {
return o.onLoadedPool(o.text);
} else {
return include("../../saveToCache/save")(o);
}
}
});
};
})();
lib/util/loadWithCache/load.ls
(function(){
var pool;
pool = {};
return function(o){
o.localCacheFilePath == null && (o.localCacheFilePath = o.localCacheFolder.toString() + o.localCacheFileName.toString());
o.onLoadedPool = function(text){
var a, i$, len$, o2;
a = pool[o.localCacheFilePath];
delete pool[o.localCacheFilePath];
if (!a) {
log.log({
event: "debugLoadWithCacheError",
type: o.type,
localCacheFilePath: o.localCacheFilePath,
textStub: text != null ? text.substring(0, 50) : void 8,
debugInfo: o.debugInfo
});
}
for (i$ = 0, len$ = a.length; i$ < len$; ++i$) {
o2 = a[i$];
o2.onLoaded(text);
}
return o.debugInfo = "onLoaded";
};
o.onLoadFailedPool = function(error){
var a, i$, len$, o2;
a = pool[o.localCacheFilePath];
delete pool[o.localCacheFilePath];
if (!a) {
log.log({
event: "debugLoadWithCacheError",
type: o.type,
localCacheFilePath: o.localCacheFilePath,
error: error,
debugInfo: o.debugInfo
});
}
for (i$ = 0, len$ = a.length; i$ < len$; ++i$) {
o2 = a[i$];
o2.onLoadFailed(error);
}
return o.debugInfo = "onLoadFailed";
};
if (pool[o.localCacheFilePath]) {
return pool[o.localCacheFilePath].push(o);
} else {
pool[o.localCacheFilePath] = [o];
if (o.resetCache || engine.isMobileApp === false) {
return include("download/download")(o);
} else {
return include("loadFromCache/load")(o);
}
}
};
})();
lib/util/loadWithCache/loadFromCache/load.ls
(function(){
var queue;
queue = [];
return function(o){
var queueItemDone, nextQueueItem;
queueItemDone = function(o1){
queue.splice(queue.indexOf(o1), 1);
return nextQueueItem();
};
nextQueueItem = function(){
var totalActive, o1;
if (queue.length === 0) {
return;
}
totalActive = _.filter(queue, "isLoading").length;
if (totalActive >= 12) {
return;
}
o1 = _.find(queue, function(q){
return q.isLoading == null;
});
if (!o1) {
return;
}
o1.isLoading = true;
return include("load/load")(o1, queueItemDone);
};
queue.push(o);
return nextQueueItem();
};
})();
lib/util/loadWithCache/loadFromCache/load/load.ls
(function(){
return function(o, onDone){
return app.fileSystem.readFile(o.localCacheFilePath, function(error, result){
var text;
text = result != null ? result.data : void 8;
if (text) {
trySafe(function(){
return o.onLoadedPool(text);
});
} else {
include("../../download/download")(o);
}
return onDone(o);
});
};
})();
lib/util/loadWithCache/saveToCache/save.ls
(function(){
return function(o){
var t;
t = o.base64 || o.text;
return app.fileSystem.removeFile(o.localCacheFilePath + "_temp", function(){
return app.fileSystem.writeFile(o.localCacheFilePath + "_temp", t, 0, function(error){
return app.fileSystem.readFile(o.localCacheFilePath + "_temp", function(error, result){
var t2;
t2 = result != null ? result.data : void 8;
if (t2 === t) {
return app.fileSystem.removeFile(o.localCacheFilePath, function(){
return app.fileSystem.moveFile(o.localCacheFilePath + "_temp", o.localCacheFilePath, function(){
return trySafe(function(){
return o.onLoadedPool(t);
});
});
});
} else {
return trySafe(function(){
return o.onLoadFailedPool("save_to_cache_error");
});
}
});
});
});
};
})();
lib/util/resolveCustomSoundUrls/resolve.ls
(function(){
return function(soundsIds){
var soundUrls, i$, ref$, len$, soundId, text, server, url;
soundUrls = [];
for (i$ = 0, len$ = (ref$ = _.ensureArray(soundsIds)).length; i$ < len$; ++i$) {
soundId = ref$[i$];
text = encodeURIComponent(soundId);
server = "https://sounds.anton.app";
url = "" + server + "/sound?text=" + soundId + "&vendor=solocode&lang=de-DE&gender=Male&voice=custom&token=" + Store("token") + "&userId=" + Store("userId") + "";
soundUrls.push({
url: url,
file: soundId
});
}
return soundUrls;
};
})();
lib/util/sound/createSound/audioLoadFailed/audio.ls
(function(){
return function(o){
var duration, startTime, timeout;
duration = 300;
startTime = null;
timeout = null;
o.onFrame = function(){
var currentPosition;
if (startTime) {
currentPosition = new Date() - startTime;
if (typeof o.onProgress == 'function') {
o.onProgress(currentPosition, duration);
}
return requestAnimationFrame(o.onFrame);
}
};
o.play = function(){
if (o.dontSetLastSound !== true) {
app.lastSound = o;
}
startTime = new Date();
timeout = setTimeout(function(){
o.stop();
return typeof o.onFinish == 'function' ? o.onFinish() : void 8;
}, duration);
return o.onFrame();
};
o.stop = function(){
var currentPosition;
if (startTime) {
currentPosition = new Date() - startTime;
currentPosition = Math.min(duration, currentPosition);
if (typeof o.onProgress == 'function') {
o.onProgress(currentPosition, duration);
}
clearTimeout(timeout);
timeout = null;
return startTime = null;
}
};
o.duration = function(){
return duration;
};
if (o.status === "playAsFastAsPossible") {
o.play();
}
return o.status = "ready";
};
})();
lib/util/sound/createSound/create.ls
(function(){
return function(o){
var generateAudioData, onDecodeError, onDecoded;
generateAudioData = function(){
return include("generateAudioData/generate")(o, onDecodeError, onDecoded);
};
onDecodeError = function(){
return include("audioLoadFailed/audio")(o);
};
onDecoded = function(audioData){
var sound;
o.play = function(){
var sound;
if (o.dontSetLastSound !== true) {
app.lastSound = o;
}
if (typeof o.stop == 'function') {
o.stop();
}
sound = include("sound/sound")(o, audioData);
o.stop = sound.stop;
o.fadeout = sound.fadeout;
return sound.play();
};
if (!o.duration) {
sound = include("sound/sound")(o, audioData);
o.duration = sound.duration;
if (typeof o.onLoaded == 'function') {
o.onLoaded();
}
if (o.status === "playAsFastAsPossible") {
o.play();
}
return o.status = "ready";
}
};
return generateAudioData();
};
})();
lib/util/sound/createSound/generateAudioData/concatBuffers/concat.ls
(function(){
return function(buffers){
var numberOfChannels, totalLength, sampleRate, concatBuffer, i$, to$, i, channel, pos, j$, len$, j, buffer;
numberOfChannels = _.minBy(buffers, 'numberOfChannels').numberOfChannels;
totalLength = _.reduce(buffers, function(sum, b){
return sum += b.length;
}, 0);
sampleRate = buffers[0].sampleRate;
concatBuffer = sound.audioContext.createBuffer(numberOfChannels, totalLength, sampleRate);
for (i$ = 0, to$ = numberOfChannels - 1; i$ <= to$; ++i$) {
i = i$;
channel = concatBuffer.getChannelData(i);
pos = 0;
for (j$ = 0, len$ = buffers.length; j$ < len$; ++j$) {
j = j$;
buffer = buffers[j$];
channel.set(buffer.getChannelData(i), pos);
pos += buffer.length;
}
}
return concatBuffer;
};
})();
lib/util/sound/createSound/generateAudioData/generate.ls
(function(){
return function(o, onDecodeError, onDecoded){
var buffer, arrayBuffers, current, buffers, concat;
if (_.isString(o.base64)) {
o.base64 = {
base64: o.base64
};
}
if (!_.isArray(o.base64)) {
o.base64 = [o.base64];
}
o.base64 = _.map(o.base64, function(b){
if (_.isString(b)) {
return {
base64: b
};
} else {
return b;
}
});
if (o.base64.length === 1) {
buffer = include("generateBuffer/generate")(o.base64[0]);
return sound.audioContext.decodeAudioData(buffer, onDecoded, onDecodeError);
} else {
arrayBuffers = _.map(o.base64, function(base64){
return include("generateBuffer/generate")(base64);
});
current = -1;
buffers = [];
concat = function(){
var concatBuffer;
if (++current === arrayBuffers.length) {
concatBuffer = include("concatBuffers/concat")(buffers);
return onDecoded(concatBuffer);
} else {
return sound.audioContext.decodeAudioData(arrayBuffers[current], function(b){
o.base64[current].duration = _.round(b.duration * 1000);
buffers.push(b);
return concat();
}, onDecodeError);
}
};
return concat();
}
};
})();
lib/util/sound/createSound/generateAudioData/generateBuffer/generate.ls
(function(){
return function(base64){
var data, characters, numbers, i$, len$, i, c, array;
data = base64.base64.split("base64,")[1].trim();
characters = atob(data);
numbers = new Array(characters.length);
for (i$ = 0, len$ = characters.length; i$ < len$; ++i$) {
i = i$;
c = characters[i$];
numbers[i] = characters.charCodeAt(i);
}
array = new Uint8Array(numbers);
return array.buffer;
};
})();
lib/util/sound/createSound/sound/applyGain/applyGain.ls
(function(){
return function(o, gain, currentTime, volume){
var g, c, i$, ref$, len$, b;
g = 1;
c = 0;
for (i$ = 0, len$ = (ref$ = o.base64).length; i$ < len$; ++i$) {
b = ref$[i$];
if (currentTime < (c += b.duration)) {
if (b.gain) {
g = b.gain;
} else {
g = 1;
}
break;
}
}
return gain.gain.value = volume * g;
};
})();
lib/util/sound/createSound/sound/calcAnalyserData/calcAnalyserData.ls
(function(){
var dataArray;
dataArray = new Uint8Array(32);
return function(o, analyser){
if (!o.enableAnalyser) {
return;
}
analyser.getByteFrequencyData(dataArray);
return {
vol: _.max(dataArray) / 255,
fft: _.map(dataArray, function(i){
return i / 255;
}),
raw: dataArray
};
};
})();
lib/util/sound/createSound/sound/createAnalyser/create.ls
(function(){
return function(){
var a;
a = sound.audioContext.createAnalyser();
a.fftSize = 64;
return a;
};
})();
lib/util/sound/createSound/sound/createGain/create.ls
(function(){
return function(volume){
var g;
g = sound.audioContext.createGain();
g.gain.value = volume || 1;
return g;
};
})();
lib/util/sound/createSound/sound/createSource/create.ls
(function(){
return function(audioData){
var source;
source = sound.audioContext.createBufferSource();
source.buffer = audioData;
return source;
};
})();
lib/util/sound/createSound/sound/sound.ls
(function(){
return function(o, audioData){
var onFinish, onProgress, volume, source, gain, analyser, duration, isStopped, startTime, currentTime, connectChain, disconnectChain, play, stop, fadeout;
onFinish = o.onFinish;
onProgress = o.onProgress;
volume = o.volume;
source = include("createSource/create")(audioData);
gain = include("createGain/create")(volume);
analyser = include("createAnalyser/create")();
duration = source.buffer.duration * 1000;
isStopped = false;
startTime = new Date();
currentTime = null;
connectChain = function(){
source.connect(gain);
gain.connect(analyser);
analyser.connect(sound.audioContext.destination);
if (typeof AudioRecorderDestination != 'undefined' && AudioRecorderDestination !== null) {
return analyser.connect(AudioRecorderDestination);
}
};
disconnectChain = function(){
source.disconnect(0);
gain.disconnect(0);
return analyser.disconnect(0);
};
play = function(){
var pitchFactor, isLoop, onFrame;
volume = o.volume || 1;
pitchFactor = o.pitchFactor || 1;
isLoop = o.isLoop;
connectChain();
if (!isLoop) {
setTimeout(function(){
if (!isStopped) {
source.stop();
disconnectChain();
if (typeof onProgress == 'function') {
onProgress(duration, duration);
}
if (typeof onFinish == 'function') {
onFinish();
}
return isStopped = true;
}
}, duration / pitchFactor);
}
onFrame = function(){
currentTime = new Date() - startTime;
if (currentTime < duration / pitchFactor && !isStopped) {
if (typeof onProgress == 'function') {
onProgress(currentTime, duration / pitchFactor, include("calcAnalyserData/calcAnalyserData")(o, analyser));
}
include("applyGain/applyGain")(o, gain, currentTime, volume);
return requestAnimationFrame(onFrame);
}
};
if (onProgress) {
onFrame();
}
if (isLoop) {
source.loop = true;
}
if (pitchFactor) {
source.playbackRate.value = pitchFactor;
}
if (volume) {
gain.gain.value = volume;
}
if (source.start) {
return source.start(0);
} else if (source.play) {
return source.play(0);
} else if (source.noteOn) {
return source.noteOn(0);
}
};
stop = function(){
if (isStopped) {
return;
}
isStopped = true;
try {
source.stop();
} catch (e$) {}
return disconnectChain();
};
fadeout = function(duration){
var step, fadeOut;
duration = duration || 100;
step = gain.gain.value / duration;
return fadeOut = setInterval(function(){
if (gain.gain.value > 0) {
return gain.gain.value -= step;
} else {
clearInterval(fadeOut);
return stop();
}
}, 1);
};
return {
play: play,
stop: stop,
fadeout: fadeout,
duration: function(){
return duration;
}
};
};
})();
lib/util/sound/initAudioContext/_playSilence/playSilence.ls
(function(){
return function(){
var s, g;
if (sound.audioContext == null) {
return;
}
s = sound.audioContext.createBufferSource();
s.buffer = sound.audioContext.createBuffer(1, 1, 44100);
s.connect(sound.audioContext.destination);
g = sound.audioContext.createGain();
g.gain.value = 0;
g.connect(sound.audioContext.destination);
s.connect(g);
s.start(0);
return s.disconnect();
};
})();
lib/util/sound/initAudioContext/createAudioContextOnFirstInteraction/create.ls
(function(){
return function(){
var init;
init = function(){
document.removeEventListener("touchend", init);
document.removeEventListener("mousedown", init);
include("../../refreshAudioContext/refresh")();
return include("../_playSilence/playSilence")();
};
document.addEventListener('touchend', init);
return document.addEventListener('mousedown', init);
};
})();
lib/util/sound/initAudioContext/init.ls
(function(){
return function(){
if (window.sound) {
return;
}
window.sound = {};
if (engine.isMobileApp) {
include("../refreshAudioContext/refresh")();
} else {
include("createAudioContextOnFirstInteraction/create")();
}
if (engine.isMobileApp) {
include("pauseAndResume/pauseAndResume")();
}
if (navigator.userAgent.indexOf("Crosswalk/23") > -1) {
return include("keepAliveAndroid/keepAliveAndroid")();
}
};
})();
lib/util/sound/initAudioContext/keepAliveAndroid/keepAliveAndroid.ls
(function(){
return function(){
return setInterval(function(){
return include("../_playSilence/playSilence")();
}, 30000);
};
})();
lib/util/sound/initAudioContext/pauseAndResume/pauseAndResume.ls
(function(){
return function(){
var onPause, onResume;
onPause = function(){
var ref$;
return (ref$ = window.sound.audioContext) != null ? typeof ref$.suspend == 'function' ? ref$.suspend() : void 8 : void 8;
};
onResume = function(){
return include("/lib/util/sound/refreshAudioContext/refresh")();
};
document.addEventListener("resume", onResume, false);
return document.addEventListener("pause", onPause, false);
};
})();
lib/util/sound/refreshAudioContext/refresh.ls
(function(){
return function(){
var ref$, ref1$;
if (window.AudioContext) {
if ((ref$ = window.sound.audioContext) != null) {
if (typeof ref$.close == 'function') {
ref$.close();
}
}
return window.sound.audioContext = new AudioContext();
} else if (window.webkitAudioContext) {
if ((ref1$ = window.sound.audioContext) != null) {
if (typeof ref1$.close == 'function') {
ref1$.close();
}
}
return window.sound.audioContext = new webkitAudioContext();
}
};
})();
lib/util/sound/sound.ls
(function(){
return function(o){
include("createSound/create")(o);
return {
play: function(onFinish, onProgress){
var p, isLoop, pitchFactor, volume;
if (onFinish && !_.isFunction(onFinish)) {
p = onFinish;
onFinish = p.onFinish;
onProgress = p.onProgress;
isLoop = p.isLoop;
pitchFactor = p.pitchFactor;
volume = p.volume;
}
if (onFinish) {
o.onFinish = onFinish;
} else {
delete o.onFinish;
}
if (onProgress) {
o.onProgress = onProgress;
} else {
delete o.onProgress;
}
if (isLoop) {
o.isLoop = isLoop;
}
if (pitchFactor) {
o.pitchFactor = pitchFactor;
} else {
delete o.pitchFactor;
}
if (volume) {
o.volume = volume;
}
if (o.play != null) {
return o.play();
} else {
return o.status = "playAsFastAsPossible";
}
},
stop: function(){
if (o.stop != null) {
return o.stop();
}
},
fadeout: function(){
if (o.fadeout != null) {
return o.fadeout();
}
},
duration: function(){
if (o.duration != null) {
return o.duration();
}
},
heapInfo: include("/lib/util/heapInfo/info")("sound")
};
};
})();
lib/util/webmToMp3/webmToMp3.ls
(function(){
return function(webmBlob, done){
var reader;
if (!window.WavAudioEncoder) {
include("/lib/external/wavAudioEncoder/wavAudioEncoder.js");
}
reader = new FileReader();
reader.readAsArrayBuffer(webmBlob);
return reader.onloadend = function(){
var buffer;
buffer = reader.result;
return sound.audioContext.decodeAudioData(buffer, function(raw){
var data, encoder, blob, file, encodeUrl, formData, xhr;
data = raw.getChannelData(0);
encoder = new WavAudioEncoder(raw.sampleRate, 1);
encoder.encode([data]);
blob = encoder.finish();
file = new File([blob], "filename.wav");
encodeUrl = "https://apis-debug.solocode.com/audioEncodeMp3?loadProject=true";
formData = new FormData();
formData.append('soundFile', file);
xhr = new XMLHttpRequest();
xhr.onload = function(){
var mp3Blob;
if (xhr.response.type === "application/json") {
debug(xhr.response);
return;
}
mp3Blob = xhr.response;
return done(mp3Blob);
};
xhr.onerror = function(e){
return debug("xhr error");
};
xhr.open('POST', encodeUrl);
xhr.responseType = 'blob';
return xhr.send(formData);
});
};
};
})();
musicKeyboard/_shared/getIndexFromNote/get.ls
(function(){
return function(o, note){
var octave, relativeNote, relativeOctave, relativeNoteIndex, noteIndex;
octave = _.last(note) * 1;
relativeNote = note.slice(0, -1);
relativeOctave = octave - o.startOctave;
relativeNoteIndex = _.indexOf(o.scaleNotes, relativeNote);
noteIndex = relativeNoteIndex + o.scaleNotes.length * relativeOctave;
return noteIndex;
};
})();
musicKeyboard/_shared/getNoteFromIndex/get.ls
(function(){
return function(o, i){
var relativeOctave, relativeNote, octave, note;
relativeOctave = Math.floor(i / o.scaleNotes.length);
relativeNote = o.scaleNotes[i - relativeOctave * o.scaleNotes.length];
octave = relativeOctave + o.startOctave;
note = relativeNote + "" + octave;
return note;
};
})();
musicKeyboard/_shared/keyWidth/width.ls
(function(){
return function(o){
var width;
width = body.width() / (o.scaleNotes.length + 1) * o.keyZoom;
if (width > o.maxKeyWidth) {
return o.maxKeyWidth;
} else {
return width;
}
};
})();
musicKeyboard/_shared/moveToRootKey/move.ls
(function(){
return function(o){
var getIndexFromNote;
getIndexFromNote = include("../getIndexFromNote/get");
return requestAnimationFrame(function(){
var bodyWidth, keysWidth, scrollWidth, rootNoteIndex, scrollPosition;
bodyWidth = body.width();
keysWidth = o.keysDiv.width();
if (keysWidth <= bodyWidth) {
return;
}
scrollWidth = keysWidth - bodyWidth;
rootNoteIndex = getIndexFromNote(o, o.rootKey);
scrollPosition = _.min([o.keyWidth * rootNoteIndex, scrollWidth]);
return o.keysDiv.parent().scrollLeft = scrollPosition;
});
};
})();
musicKeyboard/_shared/noteOff/off.ls
(function(){
return function(o){
var getIndexFromNote;
getIndexFromNote = include("../getIndexFromNote/get");
return function(note){
var isHalftone, index, div;
isHalftone = _.includes(note, 's');
index = getIndexFromNote(o, note);
div = o.keysDiv.findAll(".instrumentKeyboardKey")[index];
if (!div) {
return;
}
return div.css({
backgroundColor: isHalftone
? Color.black
: Color.white
});
};
};
})();
musicKeyboard/_shared/noteOn/on.ls
(function(){
return function(o){
var getIndexFromNote;
getIndexFromNote = include("../getIndexFromNote/get");
return function(note){
var isHalftone, index, div;
isHalftone = _.includes(note, 's');
index = getIndexFromNote(o, note);
div = o.keysDiv.findAll(".instrumentKeyboardKey")[index];
if (!div) {
return;
}
return div.css({
backgroundColor: Color.blue[500]
});
};
};
})();
musicKeyboard/_shared/scale/scale.ls
(function(){
return function(o){
switch (o.scale) {
case "major":
return ['C', 'D', 'E', 'F', 'G', 'A', 'B'];
case "minor":
return ['C', 'D', 'Ds', 'F', 'G', 'Gs', 'As'];
default:
return ['C', 'Cs', 'D', 'Ds', 'E', 'F', 'Fs', 'G', 'Gs', 'A', 'As', 'B'];
}
};
})();
musicKeyboard/header/header.ls
(function(){
return function(o){
var update, div;
update = function(){
return div.empty().append(include("move/move")(o), include("zoom/zoom")(o), include("scale/scale")(o));
};
div = Div().css({
backgroundColor: Color.grey[200],
borderBottom: "1px solid " + Color.grey[300],
display: "flex",
justifyContent: "left",
padding: "0.3em"
});
div.update = update;
update();
return div;
};
})();
musicKeyboard/header/move/move.ls
(function(){
return function(o){
var getIndexFromNote, getNoteFromIndex, up, down, update, div, left, right;
getIndexFromNote = include("../../_shared/getIndexFromNote/get");
getNoteFromIndex = include("../../_shared/getNoteFromIndex/get");
up = function(){
o.rootKey = getNoteFromIndex(o, getIndexFromNote(o, o.rootKey) + 1);
return o.update();
};
down = function(){
o.rootKey = getNoteFromIndex(o, getIndexFromNote(o, o.rootKey) - 1);
return o.update();
};
update = function(){
var bodyWidth, keysWidth, scrollLeft, currentScrollLeft, canScrollLeft, canScrollRight;
bodyWidth = Math.round(body.width());
keysWidth = Math.round(o.keysDiv.width());
scrollLeft = keysWidth - bodyWidth;
currentScrollLeft = Math.round(o.keysDiv.parent().scrollLeft);
canScrollLeft = bodyWidth < keysWidth && currentScrollLeft > 0;
canScrollRight = bodyWidth < keysWidth && currentScrollLeft < scrollLeft;
if (canScrollLeft) {
left.setColor(Color.grey[800]);
left.tap(down);
}
if (canScrollRight) {
right.setColor(Color.grey[800]);
return right.tap(up);
}
};
div = Div().css({
display: "flex",
justifyContent: "left",
backgroundColor: Color.grey[250],
marginRight: "0.3em"
}).append(left = SvgIcon({
svg: path("/lib/svg/shape/arrow-left.svg"),
color: Color.grey[500]
}).css({
marginRight: "0.61em",
marginLeft: "0.5em",
marginTop: "0.5em",
marginBottom: "0.5em"
}), right = SvgIcon({
svg: path("/lib/svg/shape/arrow-right.svg"),
color: Color.grey[500]
}).css({
margin: "0.5em"
}));
requestAnimationFrame(function(){
return requestAnimationFrame(function(){
return update();
});
});
return div;
};
})();
musicKeyboard/header/scale/menu/background/background.ls
(function(){
return function(o){
var click, div;
click = function(){
return o.close();
};
div = Div().addClass("mainMenu").addClass("keyManagerScope").css({
position: "fixed",
left: 0,
right: 0,
top: 0,
bottom: 0,
cursor: "default",
zIndex: 101
}).append(Div().css({
position: "absolute",
top: 0,
bottom: 0,
width: "100%",
backgroundColor: Color.grey[700],
opacity: 0.2
}), Div().addClass("keyManager-esc").bind("keyManager", click)).tap({
up: click,
animation: "none"
}).bind("touchstart", function(e){
return e.preventDefault();
});
div.css({
cursor: "default"
});
return div;
};
})();
musicKeyboard/header/scale/menu/items/animate/animate.ls
(function(){
return function(div){
return div.keyframeAnimate({
duration: 200,
keyframes: app.navbarPosition === "top"
? {
"0%": {
transform: "translateY(-20px)",
opacity: 0
},
"70%": {
transform: "translateY(3px)",
opacity: 1
},
"100%": {
transform: "translateY(0px)",
opacity: 1
}
}
: {
"0%": {
transform: "translateY(20px)",
opacity: 0
},
"70%": {
transform: "translateY(-3px)",
opacity: 1
},
"100%": {
transform: "translateY(0px)",
opacity: 1
}
}
});
};
})();
musicKeyboard/header/scale/menu/items/corner/corner.ls
(function(){
return function(o){
return o.corner = Div().css({
position: "absolute",
top: "-7px",
marginLeft: "-7px",
left: "0px",
width: "14px",
height: "14px",
transform: "rotate(45deg)",
backgroundColor: "white"
});
};
})();
musicKeyboard/header/scale/menu/items/item/icon/icon.ls
(function(){
return function(item){
if (item.icon) {
return SvgIcon({
svg: item.icon,
color: item.selected
? Color.blue[500]
: Color.grey[600]
}).css({
flex: "0 0 auto",
marginRight: "0.4em",
marginTop: "0.2em"
});
}
};
})();
musicKeyboard/header/scale/menu/items/item/isDebugIcon/isDebugIcon.ls
(function(){
return function(item){
if (item.isDebug) {
return SvgIcon({
svg: path("/lib/svg/shape/under-construction.svg")
}).css({
flex: "0 0 auto",
margin: "0 0.3em"
});
}
};
})();
musicKeyboard/header/scale/menu/items/item/item.ls
(function(){
return function(o, item, index){
var click;
if (item.isDebug && engine.isDebug !== true) {
return;
}
click = function(){
o.close();
return item.click();
};
return Div().css({
display: "flex",
padding: "0.6em",
maxWidth: "90vw",
lineHeight: "1.4em",
borderTop: index > 0 ? "1px solid " + Color.grey[200] : void 8
}).append(Div().append(include("icon/icon")(item), typeof item.badge == 'function' ? item.badge() : void 8), include("label/label")(item), include("isDebugIcon/isDebugIcon")(item)).tap({
up: click,
animation: "hover"
});
};
})();
musicKeyboard/header/scale/menu/items/item/label/label.ls
(function(){
return function(item){
return Div().css({
flex: "1 1 auto",
color: item.selected ? Color.blue[500] : void 8,
paddingRight: "0.4em"
}).html(item.label);
};
})();
musicKeyboard/header/scale/menu/items/items.ls
(function(){
return function(o){
var updatePosition, div, index, item;
updatePosition = function(){
return include("updatePosition/update")(div, o);
};
div = Div().css({
display: "flex",
flexDirection: "column",
alignItems: "stretch",
position: "absolute",
backgroundColor: "white",
textAlign: "left"
}).append(include("corner/corner")(o), o.header, (function(){
var i$, ref$, len$, results$ = [];
for (i$ = 0, len$ = (ref$ = o.items).length; i$ < len$; ++i$) {
index = i$;
item = ref$[i$];
if (!item) {
continue;
} else {
results$.push(include("item/item")(o, item, index));
}
}
return results$;
}())).onWindowResize(updatePosition);
include("animate/animate")(div);
requestAnimationFrame(function(){
return updatePosition();
});
return div;
};
})();
musicKeyboard/header/scale/menu/items/updatePosition/update.ls
(function(){
return function(div, o){
var offset, offset2, left, right, adjustLeft1, adjustLeft2;
if (o.div.isVisible() === false) {
o.background.remove();
return;
}
offset = o.div.offset();
offset2 = div.offset();
left = offset.left + offset.width / 2 - offset2.width / 2;
right = body.width() - left - offset2.width;
adjustLeft1 = right < 20 ? -(20 - right) : 0;
left += adjustLeft1;
adjustLeft2 = left < 20 ? 20 - left : 0;
left += adjustLeft2;
div.css({
left: left + "px"
}).css(app.navbarPosition === "top"
? {
top: offset.top + offset.height + 5 + "px",
bottom: ""
}
: {
top: "",
bottom: body.height() - offset.top + 10 + "px"
});
return o.corner.css({
left: offset2.width / 2 - adjustLeft1 - adjustLeft2 + "px"
}).css(app.navbarPosition === "top"
? {
top: "-7px",
bottom: ""
}
: {
top: "",
bottom: "-7px"
});
};
})();
musicKeyboard/header/scale/menu/menu.ls
(function(){
return function(o){
o.close = function(){
return o.background.remove();
};
body.append(o.background = include("background/background")(o).keyframeAnimate({
keyframes: {
"0%": {
opacity: 0
},
"100%": {
opacity: 1
}
},
duration: 200
}).append(include("items/items")(o)));
return o;
};
})();
musicKeyboard/header/scale/scale.ls
(function(){
return function(o){
var menu, div;
menu = function(){
return include("menu/menu")({
div: div,
items: [
{
label: "Full",
click: function(){
o.scale = "full";
return o.update();
}
}, {
label: "Moll",
click: function(){
o.scale = "minor";
return o.update();
}
}, {
label: "Dur",
click: function(){
o.scale = "major";
return o.update();
}
}
]
});
};
div = Div().css({
display: "flex",
justifyContent: "left",
backgroundColor: Color.grey[250],
marginRight: "0.3em"
}).append(Div().css({
marginRight: "2px",
padding: "0.5em",
backgroundColor: Color.grey[300],
lineHeight: "1em"
}).html(o.scale.toUpperCase().slice(0, 3)).append().tap(menu));
return div;
};
})();
musicKeyboard/header/zoom/zoom.ls
(function(){
return function(o){
var up, down;
up = function(){
o.keyZoom = (function(){
switch (o.keyZoom) {
case 0.5:
return 0.75;
case 0.75:
return 1;
case 1:
return 1.5;
default:
return 2;
}
}());
return o.update();
};
down = function(){
o.keyZoom = (function(){
switch (o.keyZoom) {
case 2:
return 1.5;
case 1.5:
return 1;
case 1:
return 0.75;
default:
return 0.5;
}
}());
return o.update();
};
return Div().css({
display: "flex",
justifyContent: "left",
backgroundColor: Color.grey[250],
marginRight: "0.3em"
}).append(SvgIcon({
svg: path("/lib/svg/shape/plus.svg"),
color: o.keyZoom < 2
? Color.grey[800]
: Color.grey[500]
}).css({
paddingRight: "0.61em",
paddingLeft: "0.5em",
paddingTop: "0.5em",
paddingBottom: "0.5em"
}).tap(o.keyZoom < 2 ? up : void 8), SvgIcon({
svg: path("/lib/svg/shape/minus.svg"),
color: o.keyZoom > 0.5
? Color.grey[800]
: Color.grey[500]
}).css({
padding: "0.5em"
}).tap(o.keyZoom > 0.5 ? down : void 8));
};
})();
musicKeyboard/keyboard.ls
(function(){
return function(o){
var set, div;
o = o || {};
o.totalOctaves = o.totalOctaves || 3;
o.startOctave = o.startOctave || 2;
o.rootKey = o.rootKey || "C3";
o.keyZoom = o.keyZoom || 1;
o.maxKeyWidth = o.maxKeyWidth || 50;
o.keyHeight = o.keysHeight || "9em";
o.noteOn = include("_shared/noteOn/on")(o);
o.noteOff = include("_shared/noteOff/off")(o);
set = function(p){
_.merge(o, p);
return o.update();
};
o.update = function(){
o.scaleNotes = include("_shared/scale/scale")(o);
o.keyWidth = include("_shared/keyWidth/width")(o);
div.empty().append(include("header/header")(o), include("keys/keys")(o));
return include("_shared/moveToRootKey/move")(o);
};
div = Div();
div.update = o.update;
div.noteOn = o.noteOn;
div.noteOff = o.noteOff;
div.set = set;
o.update();
return div;
};
})();
musicKeyboard/keys/keys.ls
(function(){
return function(o){
var updateSounds, started, totalTouches, move, start, end, div, octave;
updateSounds = include("updateSounds/update");
started = false;
totalTouches = 0;
move = function(e){
return updateSounds(o, e);
};
start = function(e){
updateSounds(o, e);
if (!started) {
started = true;
o.keysDiv.bind("touchmove mousemove", move);
return o.keysDiv.bind("touchend mouseup mouseout", end, true);
}
};
end = function(e){
updateSounds(o, e);
if (e.type === "mouseup" || e.type === "mouseout" || (e.touches && e.touches.length === 0)) {
started = false;
o.keysDiv.unbind("touchmove mousemove", move);
return o.keysDiv.unbind("touchend mouseup mouseout", end, true);
}
};
div = Div().css({
textAlign: "center",
height: o.keyHeight,
overflow: "hidden",
whiteSpace: "nowrap",
lineHeight: 0
}).append(o.keysDiv = Div().css({
display: "inline-block",
height: "100%"
}).append((function(){
var i$, to$, results$ = [];
for (i$ = o.startOctave, to$ = o.startOctave + o.totalOctaves; i$ < to$; ++i$) {
octave = i$;
results$.push(include("octave/octave")(o, octave));
}
return results$;
}())).bind("touchstart mousedown", start));
return div;
};
})();
musicKeyboard/keys/octave/key/key.ls
(function(){
return function(o, octave, note){
var isHalftone;
isHalftone = _.includes(note, 's');
return Div().addClass("instrumentKeyboardKey").css({
border: "1px solid " + Color.grey[200],
backgroundColor: isHalftone
? Color.black
: Color.white,
color: isHalftone
? Color.white
: Color.black,
height: "100%",
width: o.keyWidth + "px",
zIndex: isHalftone ? 2 : 1,
display: "inline-flex",
alignItems: "flex-end",
paddingBottom: "0.2em",
fontSize: "0.8em"
}).append(note + "" + octave);
};
})();
musicKeyboard/keys/octave/octave.ls
(function(){
return function(o, octave){
var note;
return Div().css({
height: "100%",
display: "inline-block",
pointerEvents: "none"
}).append((function(){
var i$, ref$, len$, results$ = [];
for (i$ = 0, len$ = (ref$ = o.scaleNotes).length; i$ < len$; ++i$) {
note = ref$[i$];
results$.push(include("key/key")(o, octave, note));
}
return results$;
}()));
};
})();
musicKeyboard/keys/updateSounds/calcTouches/calc.ls
(function(){
return function(e){
if (e.type === "mouseup") {
return [];
} else if (e != null && e.touches) {
return _.map(e.touches, function(touch){
return {
x: touch.pageX,
y: touch.pageX
};
});
} else {
return [{
x: e.pageX,
y: e.pageY
}];
}
};
})();
musicKeyboard/keys/updateSounds/update.ls
(function(){
var previousSounds;
previousSounds = [];
return function(o, e){
var touches, offsetLeft, sounds, getNoteFromIndex, startSounds, i$, len$, i, note, stopSounds;
touches = include("calcTouches/calc")(e);
offsetLeft = o.keysDiv.offset().left;
sounds = _.sortBy(_.map(touches, function(touch){
var touchX, keyWidth, keyNumber;
touchX = touch.x;
keyWidth = o.keyWidth;
keyNumber = Math.floor((touchX - offsetLeft) / keyWidth);
return keyNumber;
}));
getNoteFromIndex = include("../../_shared/getNoteFromIndex/get");
startSounds = _.difference(sounds, previousSounds);
for (i$ = 0, len$ = startSounds.length; i$ < len$; ++i$) {
i = startSounds[i$];
note = getNoteFromIndex(o, i);
o.noteOn(note);
if (typeof o.onPress == 'function') {
o.onPress(note);
}
}
stopSounds = _.difference(previousSounds, sounds);
for (i$ = 0, len$ = stopSounds.length; i$ < len$; ++i$) {
i = stopSounds[i$];
note = getNoteFromIndex(o, i);
o.noteOff(note);
if (typeof o.onRelease == 'function') {
o.onRelease(note);
}
}
return previousSounds = sounds;
};
})();
musicPlayer/musicPlayer.ls
(function(){
return function(o){
var play, stop, toggle, setMusicAscii, setInstrument, getInstrumentMap;
o = o || {};
o.instrument = o.instrument || "piano";
o.musicSampler = include("/../music-components/musicSampler/sampler")({
instrument: o.instrument
});
o.musicSequencer = include("/../music-components/musicSequencer/sequencer")({
musicAscii: o.musicAscii,
onNoteStart: function(note, time){
return o.musicSampler.noteOn(note);
},
onNoteEnd: function(note, time){
return o.musicSampler.noteOff(note);
}
});
play = function(onFinish, onProgress){
o.musicSequencer.reset();
return o.musicSequencer.play(onFinish, onProgress);
};
stop = function(){
o.musicSequencer.stop();
return o.musicSequencer.reset();
};
toggle = function(){
if (o.musicSequencer.isPlaying()) {
return stop();
} else {
return play();
}
};
setMusicAscii = function(musicAscii){
return o.musicSequencer.set({
musicAscii: musicAscii
});
};
setInstrument = function(instrument){
return o.musicSampler.set({
instrument: instrument
});
};
getInstrumentMap = function(){
return o.musicSampler.getInstrumentMap();
};
return {
play: play,
stop: stop,
toggle: toggle,
setMusicAscii: setMusicAscii,
setInstrument: setInstrument,
getInstrumentMap: getInstrumentMap
};
};
})();
musicRecorder/prepareSilence/prepare.ls
(function(){
return function(done){
var urls;
urls = include("/lib/util/resolveCustomSoundUrls/resolve")("sample-silence");
return include("/lib/util/loadSoundsAsBase64/load")(urls, function(base64){
var silence;
silence = include("/lib/util/sound/sound")({
base64: base64,
isLoop: true,
volume: 0
});
return done(silence);
});
};
})();
musicRecorder/recorder.ls
(function(){
return function(){
var audioRecorder, audioRecorderData, silence, start, stop, data;
if (!window.AudioRecorderDestination) {
window.AudioRecorderDestination = sound.audioContext.createMediaStreamDestination();
}
audioRecorder = new MediaRecorder(AudioRecorderDestination.stream, {
mimeType: 'audio/webm',
audioBitsPerSecond: 128000
});
audioRecorderData = null;
audioRecorder.addEventListener("dataavailable", function(e){
console.log('dataavailable', e);
return audioRecorderData = e.data;
});
silence = null;
include("prepareSilence/prepare")(function(s){
return silence = s;
});
start = function(){
silence.play();
return audioRecorder.start();
};
stop = function(){
silence.stop();
return audioRecorder.stop();
};
data = function(){
return audioRecorderData;
};
return {
start: start,
stop: stop,
data: data
};
};
})();
musicSampler/calcPitchFactor/calc.ls
(function(){
return function(srcNote, destNote){
var replacements, i$, len$, replacement, octaveNotes, allNotes, s, d, pitchFactor;
replacements = [
{
note: "Df",
replacement: "Cs"
}, {
note: "Ef",
replacement: "Ds"
}, {
note: "Gf",
replacement: "Fs"
}, {
note: "Af",
replacement: "Gs"
}, {
note: "Bf",
replacement: "As"
}
];
for (i$ = 0, len$ = replacements.length; i$ < len$; ++i$) {
replacement = replacements[i$];
if (_.includes(destNote, replacement.note)) {
destNote = destNote.replace(replacement.note, replacement.replacement);
}
}
octaveNotes = ['C', 'Cs', 'D', 'Ds', 'E', 'F', 'Fs', 'G', 'Gs', 'A', 'As', 'B'];
allNotes = _.flatten(_.map([0, 1, 2, 3, 4, 5, 6, 7], function(i){
return _.map(octaveNotes, function(j){
return j + "" + i;
});
}));
s = _.indexOf(allNotes, srcNote);
d = _.indexOf(allNotes, destNote);
return pitchFactor = Math.pow(2.0, (d - s) / 12.0);
};
})();
musicSampler/instrumentMap/map.ls
(function(){
var instrumentMap;
return instrumentMap = [
{
id: "accoustic-guitar",
title: "Guitar",
soundId: "sample-accoustic-guitar-c3",
rootKey: "C3"
}, {
id: "cello-bowed",
title: "Cello (bowed)",
soundId: "sample-cello-bowed-c2",
rootKey: "C2"
}, {
id: "cello-pizzicato",
title: "Cello (plucked)",
soundId: "sample-cello-pizzicato-c2",
rootKey: "C2"
}, {
id: "double-bass-bowed",
title: "Double Bass (bowed)",
soundId: "sample-double-bass-bowed-c1",
rootKey: "C1"
}, {
id: "double-bass-pizzicato",
title: "Double Bass (plucked)",
soundId: "sample-double-bass-pizzicato-c1",
rootKey: "C1"
}, {
id: "electric-bass",
title: "E-Bass",
soundId: "sample-electric-bass-c2",
rootKey: "C2"
}, {
id: "electric-guitar",
title: "E-Guitar",
soundId: "sample-electric-guitar-c3",
rootKey: "C3"
}, {
id: "flute",
title: "Flute",
soundId: "sample-flute-c3",
rootKey: "C3"
}, {
id: "glockenspiel",
title: "Chimes",
soundId: "sample-glockenspiel-c4",
rootKey: "C4"
}, {
id: "piano",
title: "Piano",
soundId: "sample-piano-c3",
rootKey: "C3"
}, {
id: "violin-bowed",
title: "Violin (bowed)",
soundId: "sample-violin-bowed-c4",
rootKey: "C4"
}, {
id: "violin-pizzicato",
title: "Violin (plucked)",
soundId: "sample-violin-pizzicato-c4",
rootKey: "C4"
}, {
id: "trumpet",
title: "Trumpet",
soundId: "sample-trumpet-c4",
rootKey: "C4"
}, {
id: "trombone",
title: "Trombone",
soundId: "sample-trombone-c2",
rootKey: "C2"
}, {
id: "saxophone",
title: "Saxophone",
soundId: "sample-saxophone-c3",
rootKey: "C3"
}, {
id: "harp",
title: "Harp",
soundId: "sample-harp-c3",
rootKey: "C3"
}, {
id: "organ",
title: "Organ",
soundId: "sample-organ-c3",
rootKey: "C3"
}, {
id: "didgeridoo",
title: "Didgeridoo",
soundId: "sample-didgeridoo-c3",
rootKey: "C3"
}, {
id: "horn",
title: "Horn",
soundId: "sample-horn-c3",
rootKey: "C3"
}, {
id: "oboe",
title: "Oboe",
soundId: "sample-oboe-c5",
rootKey: "C5"
}, {
id: "clarinet",
title: "Clarinet",
soundId: "sample-clarinet-c3",
rootKey: "C3"
}, {
id: "concert-flute",
title: "Concert Flute",
soundId: "sample-concert-flute-c4",
rootKey: "C4"
}, {
id: "piccolo",
title: "Piccolo",
soundId: "sample-piccolo-c5",
rootKey: "C5"
}, {
id: "bassoon",
title: "Bassoon",
soundId: "sample-bassoon-c2",
rootKey: "C2"
}, {
id: "tuba",
title: "Tuba",
soundId: "sample-tuba-c1",
rootKey: "C1"
}, {
id: "percussion",
title: "Percussion (multi-sample)",
sounds: [
{
soundId: "sample-percussion-tambourine",
rootKey: "C4"
}, {
soundId: "sample-percussion-shaker",
rootKey: "D4"
}, {
soundId: "sample-percussion-claves",
rootKey: "E4"
}, {
soundId: "sample-percussion-clap",
rootKey: "F4"
}, {
soundId: "sample-percussion-snap",
rootKey: "G4"
}
]
}
];
})();
musicSampler/prepareMulti/prepare.ls
(function(){
return function(o){
var i$, ref$, len$, sound, results$ = [];
o.voices = [];
for (i$ = 0, len$ = (ref$ = o.instrument.sounds).length; i$ < len$; ++i$) {
sound = ref$[i$];
results$.push(include("prepareSample/prepare")(o, sound, fn$));
}
return results$;
function fn$(){
if (o.voices.length === o.instrument.sounds.length) {
o.isReady = true;
return typeof o.onReady == 'function' ? o.onReady() : void 8;
}
}
};
})();
musicSampler/prepareMulti/prepareSample/prepare.ls
(function(){
return function(o, sound, done){
var urls;
urls = include("/lib/util/resolveCustomSoundUrls/resolve")(sound.soundId);
return include("/lib/util/loadSoundsAsBase64/load")(urls, function(base64){
o.voices.push({
rootKey: sound.rootKey,
sound: include("/lib/util/sound/sound")({
base64: base64,
volume: 0.1
})
});
return done();
});
};
})();
musicSampler/prepareVoices/prepare.ls
(function(){
return function(o){
var i$, to$, i, results$ = [];
o.voices = [];
for (i$ = 0, to$ = o.totalVoices; i$ < to$; ++i$) {
i = i$;
results$.push(include("prepareVoice/prepare")(o, i, fn$));
}
return results$;
function fn$(){
if (o.voices.length === o.totalVoices) {
o.isReady = true;
return typeof o.onReady == 'function' ? o.onReady() : void 8;
}
}
};
})();
musicSampler/prepareVoices/prepareVoice/prepare.ls
(function(){
return function(o, i, done){
var prepareVoice, urls;
prepareVoice = function(base64){
o.voices.push({
index: i,
lastPlayed: 0,
sound: include("/lib/util/sound/sound")({
base64: base64
})
});
return done();
};
if (o.instrument.base64) {
return prepareVoice(o.instrument.base64);
} else {
urls = include("/lib/util/resolveCustomSoundUrls/resolve")(o.instrument.soundId);
return include("/lib/util/loadSoundsAsBase64/load")(urls, prepareVoice);
}
};
})();
musicSampler/sampler.ls
(function(){
return function(o){
var instrumentMap, calcpitchFactor, noteOn, noteOff, set, init;
o = o || {};
o.instrument = o.instrument || "percussion";
o.fadeoutDuration = o.fadeoutDuration || 50;
o.totalOctaves = o.totalOctaves || 3;
o.startOctave = o.startOctave || 2;
o.totalVoices = o.totalVoices || 4;
instrumentMap = include("instrumentMap/map");
calcpitchFactor = include("calcPitchFactor/calc");
noteOn = function(note){
var n, voice, ref$, pitchFactor, lastPlayed;
if (_.isString(note)) {
n = note;
} else {
n = note.note + "";
if (note.originalSign) {
n += note.originalSign;
}
n += note.octave;
}
if (o.instrument.sounds) {
voice = _.find(o.voices, function(v){
return v.rootKey === n;
});
return voice != null ? (ref$ = voice.sound) != null ? ref$.play({
volume: note.volume || 0.5
}) : void 8 : void 8;
} else {
pitchFactor = calcpitchFactor(o.instrument.rootKey, n);
voice = _.minBy(o.voices, "lastPlayed");
lastPlayed = new Date();
voice.lastPlayed = lastPlayed.getTime();
voice.noteUid = note.uid;
return voice.sound.play({
pitchFactor: pitchFactor,
volume: note.volume || 0.5
});
}
};
noteOff = function(note){
var voice, ref$;
voice = _.find(o.voices, {
noteUid: note.uid
});
return voice != null ? (ref$ = voice.sound) != null ? ref$.fadeout(o.fadeoutDuration) : void 8 : void 8;
};
set = function(p){
_.merge(o, p);
return init();
};
init = function(){
var ref$;
o.instrument = o.instrument.base64
? o.instrument
: _.find(instrumentMap, {
id: o.instrument
});
if ((ref$ = o.instrument) != null && ref$.sounds) {
return include("prepareMulti/prepare")(o);
} else {
return include("prepareVoices/prepare")(o);
}
};
init();
return {
noteOn: noteOn,
noteOff: noteOff,
isReady: function(){
return o.isReady;
},
getInstrumentMap: function(){
return instrumentMap;
},
set: set
};
};
})();
musicSequencer/calcMetronomeEvents/calc.ls
(function(){
return function(o){
var beatDuration, totalTicks, tick, totalBeats, beat, bar;
beatDuration = include("/lib/calcNoteDuration/calc")(0.25, o.bpm);
totalTicks = Math.floor(o.currentTime / beatDuration * 4) + 1;
tick = totalTicks % o.metricDenominator + 1;
if (tick !== o.currentMetronomeTick) {
totalBeats = Math.floor(totalTicks / 4);
beat = totalBeats % 4;
bar = Math.floor(totalBeats / o.metricNumerator);
if (typeof o.onProgress == 'function') {
o.onProgress({
bar: bar,
beat: beat,
tick: tick
});
}
if (totalBeats >= o.totalBeats) {
o.reset();
if (typeof o.onFinish == 'function') {
o.onFinish();
}
}
return o.currentMetronomeTick = tick;
}
};
})();
musicSequencer/calcNoteEvents/calc.ls
(function(){
return function(o){
var notesToPlay, i$, len$, note, notesToStop;
notesToPlay = _.remove(o.scheduledNotes, function(note){
var noteStart;
noteStart = include("/lib/calcNoteDuration/calc")(note.start, o.bpm);
return noteStart <= o.currentTime;
});
if (notesToPlay.length) {
for (i$ = 0, len$ = notesToPlay.length; i$ < len$; ++i$) {
note = notesToPlay[i$];
if (typeof o.onNoteStart == 'function') {
o.onNoteStart(note);
}
o.currentNotes.push(note);
}
notesToPlay = [];
}
notesToStop = _.remove(o.currentNotes, function(note){
var noteEnd;
noteEnd = include("/lib/calcNoteDuration/calc")(note.end, o.bpm);
return noteEnd <= o.currentTime;
});
if (notesToStop.length) {
for (i$ = 0, len$ = notesToStop.length; i$ < len$; ++i$) {
note = notesToStop[i$];
if (typeof o.onNoteEnd == 'function') {
o.onNoteEnd(note);
}
o.completdNotes.push(note);
}
return notesToStop = [];
}
};
})();
musicSequencer/notesParser/note/note.ls
(function(){
return function(o, part){
var note, ref$, dots, ref1$, value, ref2$, ref3$, ref4$, dottedValue, noteParsed, octave, noteSignShort, noteSign, keys, key, keySign, ref5$, sign, parsedNote;
note = part.split("-")[0];
if ((ref$ = note.match(/\./g)) != null && ref$.length) {
dots = (ref1$ = note.match(/\./g)) != null ? ref1$.length : void 8;
note = note.replace(/\./g, '');
}
value = ((ref2$ = part.split("-")) != null ? ref2$[1] : void 8) || o.currentNoteValue || o.defaultNoteValue;
if (typeof value.match == 'function' && ((ref3$ = value.match(/\./g)) != null && ref3$.length)) {
dots = (ref4$ = value.match(/\./g)) != null ? ref4$.length : void 8;
value = value.replace(/\./g, '');
}
value = eval(value);
o.currentNoteValue = value;
dottedValue = dots ? value * (2 - 1 / Math.pow(2, dots)) : value;
if (note === "P") {
noteParsed = {
type: "rest",
value: eval(value)
};
return noteParsed;
}
octave = note.length === 1 || _.includes(["s", "f"], _.last(note))
? o.currentOctave || o.defaultOctave
: _.last(note);
o.currentOctave = octave;
noteSignShort = _.includes(["s", "f"], _.last(note))
? _.last(note)
: _.includes(["s", "f"], note[1]) ? note[1] : void 8;
noteSign = noteSignShort === "s"
? "sharp"
: noteSignShort === "f" ? "flat" : void 8;
keys = include("/lib/keys/keys");
key = o.key;
keySign = _.includes((ref5$ = keys[key]) != null ? ref5$.notes : void 8, note[0]) ? keys[key].sign : void 8;
sign = o.currentSign != null && o.currentSign !== noteSign && noteSign !== keySign
? noteSign || "natural"
: !o.currentSign && noteSign !== keySign ? noteSign || "natural" : void 8;
o.currentSign = sign !== "natural" ? sign : void 8;
parsedNote = {
type: "note",
note: _.first(note),
sign: sign != null ? sign : null,
dots: dots,
octave: octave * 1,
value: value,
dottedValue: dottedValue,
start: o.currentTime,
end: o.currentTime + dottedValue,
originalSign: noteSignShort,
uid: helpers.guid(8)
};
o.currentTime += dottedValue;
return parsedNote;
};
})();
musicSequencer/notesParser/parser.ls
(function(){
return function(o){
var parsedNotes, i$, ref$, len$, i, part, partTrimmed, parsedNote;
parsedNotes = [];
o.currentValue = null;
o.currentSign = null;
o.currentOctave = null;
o.currentTime = 0;
for (i$ = 0, len$ = (ref$ = o.musicAscii.split(/\s/g)).length; i$ < len$; ++i$) {
i = i$;
part = ref$[i$];
partTrimmed = part.trim();
parsedNote = (fn$());
parsedNotes.push(parsedNote);
}
return parsedNotes;
function fn$(){
switch (partTrimmed) {
case "||":
return {
type: "separator",
bold: true
};
case "||:":
return {
type: "separator",
bold: true,
repeat: "start"
};
case ":||":
return {
type: "separator",
bold: true,
repeat: "end"
};
case "|":
o.currentSign = null;
return {
type: "separator"
};
default:
return include("note/note")(o, partTrimmed);
}
}
};
})();
musicSequencer/sequencer.ls
(function(){
return function(o){
var ref$, musicAscii, set;
o = o || {};
o.bpm = o.bpm || 120;
o.currentTime = (ref$ = o.currentTime) != null ? ref$ : 0;
o.defaults = {
noteValue: "1/4",
metric: "4/4",
octave: 4
};
o.isPlaying = false;
musicAscii = "||: C-1 |: P-1 | C-1/4 P E F :| G-1/2 P G | E-1/8 P F-1/16 P A-1/32 P :|| ||";
o.init = function(){
o.metric = o.metric || o.defaults.metric;
o.musicAscii = o.musicAscii || musicAscii;
o.notesParsed = include("notesParser/parser")({
musicAscii: o.musicAscii,
defaultNoteValue: o.defaults.noteValue,
defaultOctave: o.defaults.octave
});
o.totalBeats = include("/lib/calcTotalBeats/calc")(o.notesParsed);
o.metricNumerator = o.metric.split("/")[0] * 1;
o.metricDenominator = o.metric.split("/")[1] * 1;
return o.reset();
};
o.reset = function(){
o.stop();
o.scheduledNotes = _.clone(o.notesParsed);
o.currentNotes = [];
o.completdNotes = [];
o.currentMetronomeTick = 0;
return o.currentTime = 0;
};
o.stop = function(){
var i$, ref$, len$, note, results$ = [];
o.isPlaying = false;
clearInterval(o.timer);
if (o.currentNotes) {
for (i$ = 0, len$ = (ref$ = o.currentNotes).length; i$ < len$; ++i$) {
note = ref$[i$];
results$.push(typeof o.onNoteEnd == 'function' ? o.onNoteEnd(note) : void 8);
}
return results$;
}
};
o.play = function(onFinish, onProgress){
o.isPlaying = true;
o.onFinish = onFinish;
o.onProgress = onProgress;
clearInterval(o.timer);
o.prevTime = new Date();
return o.timer = setInterval(function(){
var now, d;
now = new Date();
d = now - o.prevTime;
o.currentTime += d;
o.prevTime = now;
include("calcNoteEvents/calc")(o);
return include("calcMetronomeEvents/calc")(o);
}, 25);
};
set = function(p){
_.merge(o, p);
return o.init();
};
o.init();
return {
isPlaying: function(){
return o.isPlaying;
},
play: o.play,
stop: o.stop,
reset: o.reset,
set: set
};
};
})();
musicStaff/musicStaff.ls
(function(){
return function(o){
var noteOn, noteOff, init, lsg, ratio, wUnit, wNum, hUnit, hNum, w, h, svg;
noteOn = function(note){
var elements, i$, len$, results$ = [];
elements = svg.findAll(".note-" + note);
for (i$ = 0, len$ = elements.length; i$ < len$; ++i$) {
results$.push((fn$.call(this, elements[i$])));
}
return results$;
function fn$(el){
if (el.hasClass("head")) {
el.attr({
fill: Color.blue[500]
});
}
if (el.hasClass("line")) {
el.attr({
stroke: Color.blue[500]
});
}
if (el.hasClass("stem")) {
el.attr({
stroke: Color.blue[500]
});
}
if (el.hasClass("flag")) {
el.attr({
fill: Color.blue[500]
});
}
if (el.hasClass("sign")) {
return el.attr({
fill: Color.blue[500]
});
}
}
};
noteOff = function(note){
var elements, i$, len$, results$ = [];
elements = svg.findAll(".note-" + note);
for (i$ = 0, len$ = elements.length; i$ < len$; ++i$) {
results$.push((fn$.call(this, elements[i$])));
}
return results$;
function fn$(el){
if (el.hasClass("head")) {
el.attr({
fill: Color.black
});
}
if (el.hasClass("line")) {
el.attr({
stroke: Color.black
});
}
if (el.hasClass("stem")) {
el.attr({
stroke: Color.black
});
}
if (el.hasClass("flag")) {
el.attr({
fill: Color.black
});
}
if (el.hasClass("sign")) {
return el.attr({
fill: Color.black
});
}
}
};
init = function(){
var i$, ref$, len$, results$ = [];
if (o.onNoteStart || o.onNoteEnd) {
for (i$ = 0, len$ = (ref$ = svg.findAll(".zone")).length; i$ < len$; ++i$) {
results$.push((fn$.call(this, ref$[i$])));
}
return results$;
}
function fn$(zone){
var noteClass, note, valueClass, value;
noteClass = _.find(zone.classes(), function(c){
return _.includes(c, 'note-');
});
note = noteClass.split('-')[1];
valueClass = _.find(zone.classes(), function(c){
return _.includes(c, 'value-');
});
value = valueClass.split('-')[1] * 4 * 60 / 120 * 1000;
return zone.tap({
down: function(){
if (typeof o.onNoteStart == 'function') {
o.onNoteStart(note);
}
noteOn(note);
return setTimeout(function(){
if (typeof o.onNoteEnd == 'function') {
o.onNoteEnd(note);
}
return noteOff(note);
}, value);
}
});
}
};
lsg = include("/../c-renderer/musicStaff/renderer.lsr")(o);
ratio = lsg.width / lsg.height;
if (o.width) {
wUnit = _.includes(o.width, "px") ? "px" : "em";
wNum = o.width.replace(wUnit, '') * 1;
}
if (o.height) {
hUnit = _.includes(o.height, "px") ? "px" : "em";
hNum = o.height.replace(hUnit, '') * 1;
}
if (!wUnit) {
wUnit = hUnit;
}
if (!hUnit) {
hUnit = wUnit;
}
if (wNum && !hNum) {
hNum = Math.round(wNum / ratio);
} else if (hNum && !wNum) {
wNum = Math.round(hNum * ratio);
}
w = wNum + wUnit;
h = hNum + hUnit;
svg = SvgIcon({
svg: LSG2.toSVG(lsg),
width: w,
height: h
});
svg.noteOn = noteOn;
svg.noteOff = noteOff;
init();
return svg;
};
})();
musicStaff/notesParser/note/note.ls
(function(){
return function(o, part){
var note, ref$, dots, ref1$, value, ref2$, ref3$, ref4$, dottedValue, noteParsed, octave, noteSignShort, noteSign, keys, key, keySign, ref5$, sign, parsedNote;
note = part.split("-")[0];
if ((ref$ = note.match(/\./g)) != null && ref$.length) {
dots = (ref1$ = note.match(/\./g)) != null ? ref1$.length : void 8;
note = note.replace(/\./g, '');
}
value = ((ref2$ = part.split("-")) != null ? ref2$[1] : void 8) || o.currentNoteValue || o.defaultNoteValue;
if (typeof value.match == 'function' && ((ref3$ = value.match(/\./g)) != null && ref3$.length)) {
dots = (ref4$ = value.match(/\./g)) != null ? ref4$.length : void 8;
value = value.replace(/\./g, '');
}
value = eval(value);
o.currentNoteValue = value;
dottedValue = dots ? value * (2 - 1 / Math.pow(2, dots)) : value;
if (note === "P") {
noteParsed = {
type: "rest",
value: eval(value)
};
return noteParsed;
}
octave = note.length === 1 || _.includes(["s", "f"], _.last(note))
? o.currentOctave || o.defaultOctave
: _.last(note);
o.currentOctave = octave;
noteSignShort = _.includes(["s", "f"], _.last(note))
? _.last(note)
: _.includes(["s", "f"], note[1]) ? note[1] : void 8;
noteSign = noteSignShort === "s"
? "sharp"
: noteSignShort === "f" ? "flat" : void 8;
keys = include("/../music-components/lib/keys/keys");
key = o.key;
keySign = _.includes((ref5$ = keys[key]) != null ? ref5$.notes : void 8, note[0]) ? keys[key].sign : void 8;
sign = o.currentSign != null && o.currentSign !== noteSign && noteSign !== keySign
? noteSign || "natural"
: !o.currentSign && noteSign !== keySign ? noteSign || "natural" : void 8;
o.currentSign = sign !== "natural" ? sign : void 8;
parsedNote = {
type: "note",
note: _.first(note),
sign: sign != null ? sign : null,
dots: dots,
octave: octave * 1,
value: value,
dottedValue: dottedValue,
start: o.currentTime,
end: o.currentTime + dottedValue,
originalSign: noteSignShort
};
o.currentTime += dottedValue;
return parsedNote;
};
})();
musicStaff/notesParser/parser.ls
(function(){
return function(o){
var parsedNotes, i$, ref$, len$, i, part, partTrimmed, parsedNote;
parsedNotes = [];
o.currentValue = null;
o.currentSign = null;
o.currentOctave = null;
o.currentTime = 0;
for (i$ = 0, len$ = (ref$ = o.musicAscii.split(/\s/g)).length; i$ < len$; ++i$) {
i = i$;
part = ref$[i$];
partTrimmed = part.trim();
if (partTrimmed) {
parsedNote = (fn$());
}
if (parsedNote) {
parsedNotes.push(parsedNote);
}
}
return parsedNotes;
function fn$(){
switch (partTrimmed) {
case "||":
return {
type: "separator",
bold: true
};
case "||:":
return {
type: "separator",
bold: true,
repeat: "start"
};
case ":||":
return {
type: "separator",
bold: true,
repeat: "end"
};
case "|":
o.currentSign = null;
return {
type: "separator"
};
default:
return include("note/note")(o, partTrimmed);
}
}
};
})();
pages/test/page.ls
(function(){
return function(page){
var audioRecorder;
audioRecorder = include("/musicRecorder/recorder")();
page.sampler = include("/../music-components/musicSampler/sampler")({
instrument: "piano"
});
page.musicAscii = "Cs D E F";
return {
top: function(){
return include("/../app01/addons/topbar2/topbar")({
title: "Instrumente-Tastatur",
subMenuItems: function(){
var instruments, i$, len$, results$ = [];
instruments = page.sampler.getInstrumentMap();
for (i$ = 0, len$ = instruments.length; i$ < len$; ++i$) {
results$.push((fn$.call(this, instruments[i$])));
}
return results$;
function fn$(instrument){
return {
label: instrument.title,
click: function(){
page.sampler.set({
instrument: instrument.id,
startOctave: instrument.sounds
? _.last(_.first(instrument.sounds).rootKey) * 1
: _.last(instrument.rootKey) * 1 - 1
});
return page.keyboard.set({
rootKey: instrument.rootKey,
startOctave: instrument.sounds
? debug(_.last(_.first(instrument.sounds).rootKey) * 1)
: _.last(instrument.rootKey) * 1 - 1
});
}
};
}
}
});
},
bottom: function(){
return page.keyboard = include("/../music-components/musicKeyboard/keyboard")({
scale: "full",
startOctave: 4,
onPress: function(note){
page.sampler.noteOn(note);
return page.score.noteOn(note);
},
onRelease: function(note){
debug(note);
page.sampler.noteOff(note);
return page.score.noteOff(note);
}
});
},
start: function(){
return projects.load("music-components", function(){
var timeCode;
page.sequencer = include("/../music-components/musicSequencer/sequencer")({
musicAscii: page.musicAscii,
onNoteStart: function(note){
debug(note);
return page.sampler.noteOn(note);
},
onNoteEnd: function(note){
debug(note);
return page.sampler.noteOff(note);
}
});
return page.append(page.score = include("/../music-components/musicStaff/musicStaff")({
width: "350px",
noMetric: true,
notes: {
musicAscii: page.musicAscii
},
onNoteStart: function(note){
page.sampler.noteOn(note);
return page.keyboard.noteOn(note);
},
onNoteEnd: function(note){
page.sampler.noteOff(note);
return page.keyboard.noteOff(note);
}
}), Button({
label: "play"
}).css({
margin: "0.1em"
}).tap(function(){
return page.sequencer.play(function(){
return timeCode.html("0.0.0");
}, function(tick){
return timeCode.html(tick.bar + "." + tick.beat + "." + tick.tick);
});
}), Button({
label: "stop"
}).css({
margin: "0.1em"
}).tap(function(){
return page.sequencer.stop();
}), Button({
label: "reset"
}).css({
margin: "0.1em"
}).tap(function(){
return page.sequencer.reset();
}), Button({
label: "sequence rec"
}).css({
margin: "0.1em"
}).tap(function(){
audioRecorder.start();
return page.sequencer.play(function(){
return setTimeout(audioRecorder.stop, 500);
});
}), Button({
label: "start rec"
}).css({
margin: "0.1em"
}).tap(function(){
return audioRecorder.start();
}), Button({
label: "stop rec"
}).css({
margin: "0.1em"
}).tap(function(){
return audioRecorder.stop();
}), Button({
label: "play rec"
}).css({
margin: "0.1em"
}).tap(function(){
var webm, url, audio;
webm = audioRecorder.data();
url = URL.createObjectURL(webm);
audio = new Audio();
audio.src = url;
return audio.play();
}), Button({
label: "download rec"
}).css({
margin: "0.1em"
}).tap(function(){
var webm;
webm = audioRecorder.data();
return include("/lib/util/webmToMp3/webmToMp3")(webm, function(mp3){
return include("/lib/util/downloadFile/download")('test.mp3', mp3);
});
}), timeCode = Div().css({
margin: "0.5em"
}).html("0.0.0"));
});
}
};
};
})();
todo.ls
(function(){})();