Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://cdnjs.cloudflare.com/ajax/libs/tunajs/1.0.1/tuna-min.js" type="text/javascript"></script>
<button id="start">start music</button>
<button id="dry">dry</button>
<button id="wet">wet</button>
    
              
            
!

CSS

              
                button {
    width: 100px;
    height: 30px;
    border: 2px solid #456;
}

button:hover {
    cursor: pointer;
}
              
            
!

JS

              
                /*
    This is a demo of the Tuna delay node. See the source at https://github.com/Theodeus/tuna
*/

var inited = false;
var delay;
var source;
var audioContext;
function init() {
    //create an audio context and load an example audio file
    initAudioContext().then(function() {
        //create an instance of Tuna by passing the AudioContext we use
        var tuna = new Tuna(audioContext);
        //create a new Tuna delay instance
        delay = new tuna.Delay({
            delayTime: 95 //a short delayTime to create a slap-back delay
        });
        //connect the source to the Tuna delay
        source.connect(delay);
        //connect delay as a standard web audio node to the audio context destination
        delay.connect(audioContext.destination);
        //start playing!
        source.start(audioContext.currentTime);

        inited = true;  
    });
}

/*
    This is just the boilerplate needed to load an audio file, create the audio context and provide the dry/wet button functionality
*/

function initAudioContext() {
    return new Promise(function(resolve, reject) {
        var AC = "AudioContext" in window ? AudioContext : "webkitAudioContext" in window ? webkitAudioContext : document.write("Web Audio not supported");
        audioContext = new AC();
        source = audioContext.createBufferSource();
        var format = checkAudioFormat();
        var xhr = new XMLHttpRequest();

        xhr.open("GET", "https://oskareriksson.se/gitarrkompet." + format);
        xhr.responseType = "arraybuffer";
        xhr.onload = function(e) {
            audioContext.decodeAudioData(e.target.response, function(b) {
                source.buffer = b;
                resolve();
            });
        }
        xhr.send(null);      
    })
     
}

/* 
    Check file format to use
*/

function checkAudioFormat () {
  var elem = document.createElement('audio');
  if (elem.canPlayType) {
    if (elem.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
      return "ogg";
    }
    if (elem.canPlayType('audio/mpeg; codecs="mp3"').replace(/^no$/, '')) {
      return "mp3";
    }
  }
  return false;
}

/*
    Setup dry/wet/start buttons
*/
var start = document.getElementById("start");
var dry = document.getElementById("dry");
var wet = document.getElementById("wet");
dry.disabled = true;
wet.disabled = true;

start.addEventListener("click", function(e) {
    if (!inited) init();
    dry.disabled = false;
    wet.disabled = false;
    start.disabled = true;
});

dry.addEventListener("click", function(e) {
    if (!inited) init();
    if (delay) delay.bypass = true;
});

wet.addEventListener("click", function(e) {
    if (!inited) init();
    if (delay) delay.bypass = false;
});
              
            
!
999px

Console