lichess orchestra: Lobby concerto for clavier, celesta and swells
parent
373930e0b7
commit
9882965237
|
@ -0,0 +1,61 @@
|
|||
function lichessLobbyMusic() {
|
||||
|
||||
var orchestra;
|
||||
|
||||
lichess.loadScript('/assets/javascripts/music/orchestra.js').then(function() {
|
||||
orchestra = lichessOrchestra();
|
||||
});
|
||||
|
||||
// 1200 -> 0
|
||||
// 2200 -> 23
|
||||
var ratingToPitch = function(rating) {
|
||||
return Math.round((rating - 1200) / 1000 * 23);
|
||||
}
|
||||
|
||||
var newHook = function(data) {
|
||||
var pitch = ratingToPitch(data.rating);
|
||||
var instrument;
|
||||
switch (data.perf) {
|
||||
case 'Blitz':
|
||||
instrument = 'clav';
|
||||
break;
|
||||
case 'Bullet':
|
||||
case 'Classical':
|
||||
instrument = 'celesta';
|
||||
break;
|
||||
default:
|
||||
instrument = 'swells';
|
||||
break;
|
||||
}
|
||||
orchestra.play(instrument, pitch);
|
||||
};
|
||||
|
||||
lichess.shepherd(function(theme) {
|
||||
var tour = new Shepherd.Tour({
|
||||
defaults: {
|
||||
classes: theme,
|
||||
scrollTo: true
|
||||
}
|
||||
});
|
||||
tour.addStep('music', {
|
||||
title: 'Music from lichess seeks',
|
||||
text: "Blitz seeks play the clavier.<br>" +
|
||||
"Classical and bullet play celesta.<br>" +
|
||||
"Variants play the swells.<br>" +
|
||||
"Rating determines the pitch.",
|
||||
attachTo: '#hooks_wrap',
|
||||
buttons: [{
|
||||
text: 'OK',
|
||||
action: tour.next
|
||||
}],
|
||||
});
|
||||
tour.start();
|
||||
});
|
||||
|
||||
return {
|
||||
receive: function(type, data) {
|
||||
if (!orchestra) return;
|
||||
if (type === 'had' && data.rating && data.rating !== 1500) newHook(data);
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,54 @@
|
|||
function lichessOrchestra() {
|
||||
|
||||
var soundDir = '/assets/sound/instrument/';
|
||||
|
||||
var instruments = {
|
||||
celesta: [],
|
||||
clav: [],
|
||||
swells: []
|
||||
},
|
||||
noteOverlap = 20,
|
||||
noteTimeout = 300,
|
||||
currentNotes = 0,
|
||||
maxPitch = 23;
|
||||
|
||||
// load celesta and clav sounds
|
||||
for (var i = 1; i <= 24; i++) {
|
||||
if (i > 9) {
|
||||
fn = 'c0' + i;
|
||||
} else {
|
||||
fn = 'c00' + i;
|
||||
}
|
||||
instruments.celesta.push(new Howl({
|
||||
src: [soundDir + 'celesta/' + fn + '.ogg', soundDir + 'celesta/' + fn + '.mp3'],
|
||||
volume: 0.2
|
||||
}))
|
||||
instruments.clav.push(new Howl({
|
||||
src: [soundDir + 'clav/' + fn + '.ogg', soundDir + 'clav/' + fn + '.mp3'],
|
||||
volume: 0.2
|
||||
}))
|
||||
}
|
||||
// load swell sounds
|
||||
for (var i = 1; i <= 3; i++) {
|
||||
instruments.swells.push(new Howl({
|
||||
src: [soundDir + 'swells/swell' + i + '.ogg', soundDir + 'swells/swell' + i + '.mp3'],
|
||||
volume: 1
|
||||
}))
|
||||
}
|
||||
|
||||
var play = function(instrument, pitch) {
|
||||
pitch = Math.max(0, Math.min(maxPitch, pitch));
|
||||
if (instrument === 'swells') pitch = Math.floor(pitch / 8);
|
||||
if (currentNotes < noteOverlap) {
|
||||
currentNotes++;
|
||||
instruments[instrument][pitch].play();
|
||||
setTimeout(function() {
|
||||
currentNotes--;
|
||||
}, noteTimeout);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
play: play
|
||||
};
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue