Skip to content

Commit

Permalink
Add Markers plugin (katspaugh#2196)
Browse files Browse the repository at this point in the history
* change let to var to prevent 'wavesurfer is already defined' error in chrome

This fixes the region plugin as well as the annotations plugin.

* add "markers" plugin

This adds pro-tools style markers to a waveform, for easy jumping to
predefined points.

* remove markers from zoom example

* remove crashy event listener

* clean up event handlers on destroy

* add changelog entry for marker plugin

* add @SInCE tag

* fetch url format

* add PR number
  • Loading branch information
osheroff authored and sandiz committed Sep 1, 2021
1 parent a8f4423 commit 8a02e94
Show file tree
Hide file tree
Showing 7 changed files with 451 additions and 35 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
wavesurfer.js changelog
=======================

x.x.x (unreleased)
------------------
- Markers plugin: add new plugin that allows for timeline markers (#2196)

4.5.0 (14.02.2021)
------------------
- Split channels: `overlay` param now properly displays a single canvas (#2161)
- Fixed memory leak with `destroy()` in `WebAudio` backend (#1940)
- Fixed `WaveSurfer.load(url)` not working when passing a HTMLMediaElement as
the url parameter, with the WebAudio backend.
the url parameter, with the WebAudio backend.
- Microphone plugin: remove deprecated `MediaStream.stop` call (#2168)
- Regions plugin: stop region dragging when mouse leaves canvas (#2158)

Expand Down
41 changes: 16 additions & 25 deletions example/annotation/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Create a WaveSurfer instance.
*/
let wavesurfer;
var wavesurfer; // eslint-disable-line no-var

/**
* Init & load.
Expand Down Expand Up @@ -58,12 +58,9 @@ document.addEventListener('DOMContentLoaded', function() {
// wavesurfer.getDuration()
// )
// );
wavesurfer.util
.ajax({
responseType: 'json',
url: 'annotations.json'
})
.on('success', function(data) {
fetch('annotations.json')
.then(r => r.json())
.then(data => {
loadRegions(data);
saveRegions();
});
Expand Down Expand Up @@ -97,6 +94,18 @@ document.addEventListener('DOMContentLoaded', function() {
playButton.style.display = '';
pauseButton.style.display = 'none';
});


document.querySelector(
'[data-action="delete-region"]'
).addEventListener('click', function() {
let form = document.forms.edit;
let regionId = form.dataset.region;
if (regionId) {
wavesurfer.regions.list[regionId].remove();
form.reset();
}
});
});

/**
Expand Down Expand Up @@ -246,21 +255,3 @@ function showNote(region) {
showNote.el.textContent = region.data.note || '–';
}

/**
* Bind controls.
*/
window.GLOBAL_ACTIONS['delete-region'] = function() {
let form = document.forms.edit;
let regionId = form.dataset.region;
if (regionId) {
wavesurfer.regions.list[regionId].remove();
form.reset();
}
};

window.GLOBAL_ACTIONS['export'] = function() {
window.open(
'data:application/json;charset=utf-8,' +
encodeURIComponent(localStorage.regions)
);
};
9 changes: 1 addition & 8 deletions example/annotation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h1 itemprop="name">wavesurfer.js Annotations Tool</h1>
</div>

<div class="row" style="margin: 30px 0">
<div class="col-sm-8">
<div class="col-sm-10">
<p>
Click on a region to enter an annotation.<br />
Shift-click plays a region in a loop.
Expand All @@ -67,13 +67,6 @@ <h1 itemprop="name">wavesurfer.js Annotations Tool</h1>
</span>
</button>
</div>

<div class="col-sm-2">
<button class="btn btn-info btn-block" data-action="export" title="Export annotations to JSON">
<i class="glyphicon glyphicon-file"></i>
Export
</button>
</div>
</div>
</div>

Expand Down
39 changes: 39 additions & 0 deletions example/markers/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

// Create an instance
var wavesurfer; // eslint-disable-line no-var

// Init & load audio file
document.addEventListener('DOMContentLoaded', function() {
// Init
wavesurfer = WaveSurfer.create({
container: document.querySelector('#waveform'),
waveColor: '#A8DBA8',
progressColor: '#3B8686',
backend: 'MediaElement',
plugins: [
WaveSurfer.markers.create({
markers: [
{
time: 5.5,
label: "V1",
color: '#ff990a'
},
{
time: 10,
label: "V2",
color: '#00ffcc',
position: 'top'
}
]
})
]
});

wavesurfer.on('error', function(e) {
console.warn(e);
});

// Load audio from URL
wavesurfer.load('../media/demo.wav');
});
121 changes: 121 additions & 0 deletions example/markers/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>wavesurfer.js | Markers</title>

<link href="data:image/gif;" rel="icon" type="image/x-icon" />

<!-- Bootstrap -->
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">

<link rel="stylesheet" href="../css/style.css" />
<link rel="stylesheet" href="../css/ribbon.css" />
<link rel="screenshot" itemprop="screenshot" href="https://katspaugh.github.io/wavesurfer.js/example/screenshot.png" />

<!-- wavesurfer.js -->
<script src="../../dist/wavesurfer.js"></script>

<!-- plugins -->
<script src="../../dist/plugin/wavesurfer.timeline.js"></script>
<script src="../../dist/plugin/wavesurfer.markers.js"></script>
<script src="../../dist/plugin/wavesurfer.minimap.js"></script>

<!-- App -->
<script src="../trivia.js"></script>
<script src="app.js"></script>

<!-- highlight.js for syntax highlighting in this example -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>

<body itemscope itemtype="http://schema.org/WebApplication">
<div class="container">
<div class="header">
<ul class="nav nav-pills pull-right">
<li><a href="/"><i class="glyphicon glyphicon-home"></i></a></li>
</ul>

<h1 itemprop="name">wavesurfer.js Markers</h1>
</div>

<div id="demo">
<div id="waveform">
<!-- Here be waveform -->
</div>

<div class="controls">
<button class="btn btn-primary" data-action="play">
<i class="glyphicon glyphicon-play"></i>
Play
/
<i class="glyphicon glyphicon-pause"></i>
Pause
</button>
</div>
</div>

<div class="row marketing">
<p>
<pre><code>var wavesurfer = WaveSurfer.create({
container: document.querySelector('#waveform'),
plugins: [
WaveSurfer.markers.create({
markers: [
{
time: 5.5,
label: "V1",
color: '#ff990a'
},
{
time: 10,
label: "V2",
color: '#00ffcc',
position: 'top'
}
]
})
]
});
</code></pre>
</p>

</div>


<div class="footer row">
<div class="col-sm-12">
<a rel="license" href="https://opensource.org/licenses/BSD-3-Clause"><img alt="BSD-3-Clause License" style="border-width:0" src="https://img.shields.io/badge/License-BSD%203--Clause-blue.svg" /></a>
</div>

<div class="col-sm-8">
<span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/Text" property="dct:title" rel="dct:type">wavesurfer.js</span> by <a href="https://github.com/katspaugh/wavesurfer.js">katspaugh</a> is licensed under a <a rel="license" href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause License</a>.
</div>

<div class="col-sm-4">
<p>
The sound file is from <a href="https://librivox.org/librivox-multilingual-short-works-collection-001-by-various/">librivox.org</a>.
</p>
</div>
</div>
</div>

<div class="github-fork-ribbon-wrapper right">
<div class="github-fork-ribbon">
<a itemprop="isBasedOnUrl" href="https://github.com/katspaugh/wavesurfer.js">Fork me on GitHub</a>
</div>
</div>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-50026819-1', 'wavesurfer.fm');
ga('send', 'pageview');
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion example/trivia.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let wavesurfer = window.wavesurfer;
var wavesurfer = window.wavesurfer; // eslint-disable-line no-var

let GLOBAL_ACTIONS = {
play: function() {
Expand Down
Loading

0 comments on commit 8a02e94

Please sign in to comment.