<script src="https://cdn.jsdelivr.net/npm/@magenta/music@1.0.0"> </script>
    <link href='https://fonts.googleapis.com/css?family=Codystar' rel='stylesheet'>

    <div class='content' id='wait'>Put on headphones. We'll wait.</div>
    <div class='content' id='start' onclick="start()">CLICK TO TRIO ENDLESSLY.</div>
    <div class='content' id='playing'>
      <marquee scrollamount=15>ENDLESS TRIOS</marquee>
      <marquee scrollamount=15 direction=right >ENDLESS TRIOS</marquee>
      <div class='button' id='next' onclick="sampleAndPlayForever()">Next Trios</div> 
      <marquee behavior=alternate id='count' direction=right>0 TRIOS</marquee>
      <div class='button' onclick="stop()">END TRIOS</div>
      <marquee scrollamount=15>ENDLESS TRIOS</marquee>
      <marquee scrollamount=15 direction=right>ENDLESS TRIOS</marquee>
      <div class='button' onclick="changeTempo(1)">Faster Trios</div>
      <marquee behavior=alternate id='tempo'>bpm</marquee>
      <div class='button' onclick="changeTempo(-1)">Slower Trios</div>
      <marquee scrollamount=15>ENDLESS TRIOS</marquee>
      <marquee scrollamount=15 direction=right>ENDLESS TRIOS</marquee>
  <footer class='footer'>
    Plays back real-time generated 3-part (melody, bass, drums) from a miniaturized <a href="https://g.co/magenta/musicvae" target="_blank">MusicVAE</a> model. Listen to samples from the full model on <a href="https://www.youtube.com/watch?v=xU1W3c9p2RU&list=PLBUMAYA6kvGVds2N7HIMQnZc0SMFk99Yl" target="_blank">YouTube</a> or sample your own in <a href="https://goo.gl/magenta/musicvae-colab" target="_blank">Colab</a>.
body {
.content {
  min-height: 100vh;
  font-family: 'Codystar';
  font-size: 28px;
.footer {
  font-family: 'Poppins', Arial, sans-serif;
  font-size: 15px;
  height: 25px;

#start, marquee.button, div.button {
  cursor: pointer;

#start:hover, div.button:hover, marquee.button:hover {
    color: magenta

div.button {
  text-align: center;

marquee, div.button {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
// Instantiate the model by specifying the desired checkpoint.
const model = new mm.MusicVAE(

const player = new mm.Player();

let stopSignal = false;
let count = 0;
let tempo = 80;

const sampleAndPlayForever = () => {
  count += 1;
  document.getElementById('count').innerHTML = `${count} trios`;
  return model.sample(1)
    .then((samples) => player.start(samples[0], tempo))
    .then(stopSignal ? undefined : sampleAndPlayForever)

const changeTempo = (delta) => {
  tempo = Math.max(Math.min(tempo + delta * 10, 120), 40);
  const tempoCounter = document.getElementById('tempo');
  tempoCounter.setAttribute('scrollamount', tempo / 10);
  tempoCounter.innerHTML = `${tempo} bpm`;

const start = () =>  {
  mm.Player.tone.context.resume();  // Required on mobile.
  document.getElementById('start').style.display = "none";
  stopSignal = false;

const stop = () => {
  stopSignal = true;
  document.getElementById('wait').style.display = "none";
  document.getElementById('start').style.display = "block";

Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.