(function () {
  var prelude = {
    channels: [{
      name: 'square1',
      config: {
        instrument: {
          waveform: 'square?d=0.75',
          sampleRate: 44100,
          bpm: 300,
          fadeOut: {
            from: 0,
            to: 3
          }
        },
        audio: {
          volume: 0.1
        }
      },
      notes: [
        [-7, 0.5], [null, 1.5],
        [5, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
        [-2, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [3, 0.5], [null, 0.5], [5, 0.5], [null, 1.5],

        [-7, 0.5], [-7, 0.5],
        [5, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
        [-2, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [3, 0.5], [null, 0.5], [5, 0.5], [null, 0.5],

        [-7, 0.5], [null, 1.5],
        [5, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
        [-2, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [3, 0.5], [null, 0.5], [5, 0.5], [null, 1.5],

        -7, 5, -7, -2, 0, 10, 8, [12, 3],
        [14, 0.5], [16, 0.5], [17, 12],

        [9, 3], [7, 3], [9, 10]
      ]
    }, {
      name: 'triangle',
      config: {
        instrument: {
          waveform: 'triangle',
          sampleRate: 44100,
          bpm: 300,
          fadeOut: {
            from: 0.4,
            to: 1
          }
        },
        audio: {
          volume: 0.1
        }
      },
      notes: [
        [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
        [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
        [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
        [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],

        [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
        [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
        [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
        [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],

        [-19, 0.5], [null, 1.5],
        [-7, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
        [-14, 0.5], [null, 0.5], [-12, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-7, 0.5], [null, 1.5],

        [-19, 0.5], [-19, 0.5],
        [-7, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
        [-14, 0.5], [null, 0.5], [-12, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5]

        [-19, 0.5], [null, 1.5],
        [-7, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
        [-14, 0.5], [null, 0.5], [-12, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-7, 0.5], [null, 1.5],

        [-19, 0.5], [-19, 0.5],
        [-7, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
        [-14, 0.5], [null, 0.5], [-12, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5]
      ]
    }, {
      name: 'noise',
      config: {
        instrument: {
          waveform: 'noise',
          sampleRate: 44100,
          bpm: 300,
          fadeOut: {
            from: 0,
            to: 2
          }
        },
        audio: {
          volume: 0.1
        }
      },
      notes: [
        [null, 16],
        [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9],
        [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9],
        [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9],
        [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9],

        [0, 0.5], [0, 0.5], [0, 0.5], [null, 0.5],
        [0, 0.5], [null, 0.5], [null, 2], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5],
        [null, 2], [0, 0.5], [null, 0.5], [null, 4], [0, 0.5], [null, 0.5], null, [0, 0.5], [null, 0.5], null,
        [0, 0.5], [null, 0.5], [null, 2], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5],
        [null, 2], [0, 0.5], [null, 0.5], [null, 4], [0, 0.5], [null, 0.5], null, [0, 0.5], [null, 0.5], null,
      ]
    }],
    loop: false
  }

  var main = {
    channels: [{
      name: 'square1',
      config: {
        instrument: {
          waveform: 'square?d=0.75',
          sampleRate: 44100,
          bpm: 300,
          fadeOut: {
            from: 0,
            to: 3
          }
        },
        audio: {
          volume: 0.1
        }
      },
      notes: (function () {
        var overtune = [
          [null, 2],
          [0, 2], -4, [0, 2], -4,
          [1, 2], [0, 2], [-2, 2], -4, [-2, 0.5], [0, 6.5],

          -9, -7, null,
          -7, -7, -7, -5, -4, -2, -4,

          [null, 2],
          0, 0, [0, 2], [0, 2],
          [1, 2], [0, 2], [-2, 2], [-4, 2], null,

          -4, -4, -4, -2, [0, 2],
          [-5, 2], -5, [-4, 2], [-2, 2], [0, 2],

          [null, 2],

          [3, 2], [1, 2], [0, 2], [-2, 2], [-4, 2], -5, [-4, 3], [null, 2],
          [0, 2], [-2, 2], [-4, 2], [-5, 2], [-7, 2], -8, [-7, 3], [null, 2],
          [3, 2], [1, 2], [0, 2], [-2, 2], -4, [0, 2], 0, -2, -4
        ]

        var verse = [
          [null, 2],
          [0, 1.5], [0, 0.5], [0, 2], [-12, 1.5], [-12, 0.5], [-12, 2],
          [0, 2], [0, 2], [0, 2], [null, 2],
          [0, 1.5], [0, 0.5], 0, -2, -4,
          [-12, 0.5], [-14, 0.5], [-16, 1], null,
          [1, 2], [1, 3], [3, 0.5], [5, 3.5], 3, [3, 8],

          0, 3, 3, [3, 2], [3, 2], 5, null,
          -16, -12, -9, [8, 1.5], [7, 1.5], [5, 1], [3, 2], [3, 0.5], [5, 1.5],

          [-7, 0.5], [null, 1.5],
          [5, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
          [-2, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [3, 0.5], [null, 0.5], [5, 0.5], [null, 1.5],

          [-7, 0.5], [-7, 0.5],
          [5, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
          [-2, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [3, 0.5], [null, 0.5], [5, 0.5], [null, 0.5],

          [-7, 0.5], [null, 1.5],
          [5, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
          [-2, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [3, 0.5], [null, 0.5], [5, 0.5], [null, 1.5],

          [-7, 0.5], [-7, 0.5],
          [5, 0.5], [null, 0.5], [-7, 0.5], [null, 0.5],
          [-5, 0.5], [null, 0.5], [-4, 0.5], [null, 0.5], [-2, 0.5], [null, 0.5], [-4, 0.5], [null, 0.5]
        ]
        return overtune.concat(verse)
      })()
    }, {
      name: 'triangle',
      config: {
        instrument: {
          waveform: 'triangle',
          sampleRate: 44100,
          bpm: 300,
          fadeOut: {
            from: 0.4,
            to: 1
          }
        },
        audio: {
          volume: 0.1
        }
      },
      notes: (function () {
        var overtune = [
          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],
          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],
          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],
          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],

          [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-12, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
          [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-12, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
          [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-12, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5],
          [-17, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-14, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],

          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],
          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],
          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],
          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],

          [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 1.5], [-19, 0.5], [null, 0.5],
          [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 1.5], [-19, 0.5], [null, 0.5],
          [-19, 0.5], [null, 0.5], [-19, 0.5], [null, 1.5], [-19, 0.5], [null, 0.5],
          [-17, 0.5], [null, 0.5], [-16, 0.5], [null, 1.5], [-16, 0.5], [null, 0.5],

          [-23, 0.5], [null, 0.5], [-23, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-23, 0.5], [null, 0.5],
          [-23, 0.5], [null, 0.5], [-28, 0.5], [null, 0.5], [-26, 0.5], [null, 0.5], [-23, 0.5], [null, 0.5],
          [-21, 0.5], [null, 0.5], [-21, 0.5], [null, 0.5], [-14, 0.5], [null, 0.5], [-21, 0.5], [null, 0.5],
          [-21, 0.5], [null, 0.5], [-26, 0.5], [null, 0.5], [-24, 0.5], [null, 0.5], [-21, 0.5], [null, 0.5],

          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-12, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],
          [-16, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5],
          [-14, 0.5], [null, 0.5], [-26, 0.5], [null, 0.5], [-24, 0.5], [null, 0.5], [-26, 0.5], [null, 0.5],
          [-24, 0.5], [null, 0.5], [-24, 0.5], [null, 0.5], [-23, 0.5], [null, 0.5], [-21, 0.5], [null, 0.5],

          [-23, 0.5], [null, 0.5], [-23, 0.5], [null, 0.5], [-16, 0.5], [null, 0.5], [-23, 0.5], [null, 0.5],
          [-23, 0.5], [null, 0.5], [-28, 0.5], [null, 0.5], [-26, 0.5], [null, 0.5], [-23, 0.5], [null, 0.5],
          [-21, 0.5], [null, 0.5], [-21, 0.5], [null, 0.5], [-14, 0.5], [null, 0.5], [-21, 0.5], [null, 0.5],
          [-21, 0.5], [null, 0.5], [-21, 0.5], [null, 0.5], [-19, 0.5], [null, 0.5], [-17, 0.5], [null, 0.5],
        ]

        var verse = [
          [-16, 0.5], [null, 0.5], [-4, 0.5], [-4, 0.5], [-16, 0.5], [null, 0.5], [-4, 0.5], [-4, 0.5],
          [-16, 0.5], [null, 0.5], [-4, 0.5], [-4, 0.5], [-16, 0.5], [null, 0.5], [-4, 0.5], [-4, 0.5],
          [-16, 0.5], [null, 0.5], [-4, 0.5], [-4, 0.5], [-16, 0.5], [null, 0.5], [-4, 0.5], [-4, 0.5],
          [-16, 0.5], [null, 0.5], [-4, 0.5], [-4, 0.5], [-16, 0.5], [null, 0.5], [-4, 0.5], [-4, 0.5],

          [-16, 0.5], [null, 0.5], [-7, 0.5], [-7, 0.5], [-16, 0.5], [null, 0.5], [-7, 0.5], [-7, 0.5],
          [-16, 0.5], [null, 0.5], [-7, 0.5], [-7, 0.5], [-16, 0.5], [null, 0.5], [-7, 0.5], [-7, 0.5],
          [-16, 0.5], [null, 0.5], [-11, 0.5], [-11, 0.5], [-16, 0.5], [null, 0.5], [-11, 0.5], [-11, 0.5],
          [-16, 0.5], [null, 0.5], [-11, 0.5], [-11, 0.5], [-16, 0.5], [null, 0.5], [-11, 0.5], [-11, 0.5],

          [-16, 0.5], [null, 0.5], [-9, 0.5], [-9, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [-9, 0.5],
          [-16, 0.5], [null, 0.5], [-9, 0.5], [-9, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [-9, 0.5],
          [-16, 0.5], [null, 0.5], [-9, 0.5], [-9, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [-9, 0.5],
          [-16, 0.5], [null, 0.5], [-9, 0.5], [-9, 0.5], [-16, 0.5], [null, 0.5], [-9, 0.5], [-9, 0.5],

          -24, [null, 0.5], [-24, 0.5], [-17, 0.5], [null, 0.5], -12,
          null, -24, -17, -12,
          -23, [null, 0.5], [-23, 0.5], [-19, 0.5], [null, 0.5], -16,
          -21, -21, -19, -17,

          -19, null, null, -19,
          -19, null, null, -19,
          null, null, null, null,
          -24, null, -21, null,

          -19, null, null, -19,
          -19, null, null, -19,
          null, null, null, null,
          -21, null, -19, -17,
        ]
        return overtune.concat(verse)
      })()
    }, {
      name: 'noise',
      config: {
        instrument: {
          waveform: 'noise',
          sampleRate: 44100,
          bpm: 300,
          fadeOut: {
            from: 0,
            to: 2
          }
        },
        audio: {
          volume: 0.1
        }
      },
      notes: (function () {
        var overtune = [
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],

          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],

          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],

          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],

          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],

          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5],

          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5],
        ]

        var verse = [
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],

          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],

          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5],

          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5],
          [0, 0.1], [null, 0.9], [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.1], [null, 0.9],
          [0, 0.1], [null, 0.9], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5],

          [null, 3], [0, 0.5], [null, 0.5],
          [-2, 0.5], [null, 2.5], [0, 0.5], [null, 1.5],

          [null, 3],
          [-2, 0.5], [null, 1.5], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5],

          [null, 3], [0, 0.5], [null, 0.5],
          [-2, 0.5], [null, 2.5], [0, 0.5], [null, 1.5],

          [null, 3],
          [-2, 0.5], [null, 1.5], [0, 0.5], [null, 0.5], [0, 0.5], [null, 0.5],
        ]
        return overtune.concat(verse)
      })()
    }],
    loop: true
  }

  var chapters = [prelude, main]
  dispatchEvent(new CustomEvent('chaptersLoaded', {detail: chapters}))
})()
