JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<div class="center">
<pre class="output0">Downloading ML Model</pre>
<pre class="output1"></pre>
<pre class="output2"></pre>
<pre class="output3"></pre>
</div>
body {
padding: 0;
margin: 0;
width: 100vw;
position: relative;
}
pre {
font-family: 'Roboto Mono', monospace;
padding : 30px;
}
.center {
display: flex;
flex-direction: row;
justify-content: center;
}
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//Play with this to get back a larger or smaller blend of melodies
var numInterpolations = 4; //numInterpolations containing 32 notes
// generates an array where indices correspond to midi notes
var everyNote = 'C,C#,D,D#,E,F,F#,G,G#,A,A#,B,'.repeat(20).split(',').map( function(x,i) {
return x + '' + Math.floor(i/12);
});
//returns the midi pitch value for the given note.
//returns -1 if not found
function toMidi(note) {
return everyNote.indexOf(note);
}
//If you want to try out other melodies copy and paste any of these in https://github.....
var MELODY1 = { notes: [
{pitch: toMidi('A3'), quantizedStartStep: 0, quantizedEndStep: 4},
{pitch: toMidi('D4'), quantizedStartStep: 4, quantizedEndStep: 6},
{pitch: toMidi('E4'), quantizedStartStep: 6, quantizedEndStep: 8},
{pitch: toMidi('F4'), quantizedStartStep: 8, quantizedEndStep: 10},
{pitch: toMidi('D4'), quantizedStartStep: 10, quantizedEndStep: 12},
{pitch: toMidi('E4'), quantizedStartStep: 12, quantizedEndStep: 16},
{pitch: toMidi('C4'), quantizedStartStep: 16, quantizedEndStep: 20},
{pitch: toMidi('D4'), quantizedStartStep: 20, quantizedEndStep: 26},
{pitch: toMidi('A3'), quantizedStartStep: 26, quantizedEndStep: 28},
{pitch: toMidi('A3'), quantizedStartStep: 28, quantizedEndStep: 32}
]};
//you can also just put in the midi pitch note if you know it
var MELODY2 = { notes: [
{pitch: 50, quantizedStartStep: 0, quantizedEndStep: 1},
{pitch: 53, quantizedStartStep: 1, quantizedEndStep: 2},
{pitch: 58, quantizedStartStep: 2, quantizedEndStep: 3},
{pitch: 58, quantizedStartStep: 3, quantizedEndStep: 4},
{pitch: 58, quantizedStartStep: 4, quantizedEndStep: 5},
{pitch: 53, quantizedStartStep: 5, quantizedEndStep: 6},
{pitch: 53, quantizedStartStep: 6, quantizedEndStep: 7},
{pitch: 53, quantizedStartStep: 7, quantizedEndStep: 8},
{pitch: 52, quantizedStartStep: 8, quantizedEndStep: 9},
{pitch: 55, quantizedStartStep: 9, quantizedEndStep: 10},
{pitch: 60, quantizedStartStep: 10, quantizedEndStep: 11},
{pitch: 60, quantizedStartStep: 11, quantizedEndStep: 12},
{pitch: 60, quantizedStartStep: 12, quantizedEndStep: 13},
{pitch: 60, quantizedStartStep: 13, quantizedEndStep: 14},
{pitch: 60, quantizedStartStep: 14, quantizedEndStep: 15},
{pitch: 52, quantizedStartStep: 15, quantizedEndStep: 16},
{pitch: 57, quantizedStartStep: 16, quantizedEndStep: 17},
{pitch: 57, quantizedStartStep: 17, quantizedEndStep: 18},
{pitch: 57, quantizedStartStep: 18, quantizedEndStep: 19},
{pitch: 65, quantizedStartStep: 19, quantizedEndStep: 20},
{pitch: 65, quantizedStartStep: 20, quantizedEndStep: 21},
{pitch: 65, quantizedStartStep: 21, quantizedEndStep: 22},
{pitch: 57, quantizedStartStep: 22, quantizedEndStep: 23},
{pitch: 57, quantizedStartStep: 23, quantizedEndStep: 24},
{pitch: 57, quantizedStartStep: 24, quantizedEndStep: 25},
{pitch: 57, quantizedStartStep: 25, quantizedEndStep: 26},
{pitch: 62, quantizedStartStep: 26, quantizedEndStep: 27},
{pitch: 62, quantizedStartStep: 27, quantizedEndStep: 28},
{pitch: 65, quantizedStartStep: 28, quantizedEndStep: 29},
{pitch: 65, quantizedStartStep: 29, quantizedEndStep: 30},
{pitch: 69, quantizedStartStep: 30, quantizedEndStep: 31},
{pitch: 69, quantizedStartStep: 31, quantizedEndStep: 32}
]};
// go to https://goo.gl/magenta/musicvae-checkpoints to see more checkpoint urls
var melodiesModelCheckPoint = 'https://storage.googleapis.com/download.magenta.tensorflow.org/models/music_vae/dljs/mel_small';
//Uses promises to chain together asynchronous operations.
//Check out https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises for info on promises
new musicvae.MusicVAE(melodiesModelCheckPoint)
.initialize()
.then(function(musicVAE) {
//blends between the given two melodies and returns numInterpolations note sequences
var noteSequences = musicVAE.interpolate([MELODY1, MELODY2], numInterpolations);
noteSequences.forEach(function(noteSequence, index) {
displayMelodies(noteSequence.notes, index);
});
});
// takes the given array of notes and index. updates the output <spans>
function displayMelodies(notes, index) {
var output = 'Melody ' + index + ' <br>';
output += JSON.stringify(notes, null, ' ') + '<br><br>';
document.querySelector('.output' + index).innerHTML = output;
}
Also see: Tab Triggers