2016-01-11 15:25:58 +00:00
|
|
|
<template>
|
|
|
|
<div id="equalizer">
|
|
|
|
<div class="presets">
|
2016-01-17 05:14:12 +00:00
|
|
|
<label class="select-wrapper" @change="loadPreset">
|
|
|
|
<select v-model="selectedPresetIndex">
|
|
|
|
<option value="-1">Preset</option>
|
|
|
|
<option v-for="preset in presets" :value="$index">{{* preset.name }}</option>
|
|
|
|
</select>
|
|
|
|
</label>
|
2016-01-11 15:25:58 +00:00
|
|
|
</div>
|
|
|
|
<div class="bands">
|
|
|
|
<span class="band" v-for="band in bands">
|
2016-01-16 18:11:24 +00:00
|
|
|
<label>{{* band.label }}</label>
|
|
|
|
<input
|
|
|
|
type="range"
|
|
|
|
min="-20"
|
|
|
|
max="20"
|
|
|
|
step="0.01"
|
|
|
|
orient="vertical"
|
2016-01-17 05:14:12 +00:00
|
|
|
data-orientation="vertical"
|
|
|
|
:value="band.filter.gain.value">
|
2016-01-11 15:25:58 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import _ from 'lodash';
|
|
|
|
import $ from 'jquery';
|
2016-01-17 05:14:12 +00:00
|
|
|
import rangeslider from 'rangeslider.js';
|
2016-01-11 15:25:58 +00:00
|
|
|
|
|
|
|
import preferenceStore from '../../stores/preference';
|
|
|
|
import utils from '../../services/utils';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
bands: [],
|
2016-01-17 05:14:12 +00:00
|
|
|
selectedPresetIndex: -1,
|
2016-01-11 15:25:58 +00:00
|
|
|
|
|
|
|
presets: [
|
|
|
|
{
|
2016-01-17 05:14:12 +00:00
|
|
|
name: 'Default',
|
2016-01-11 15:25:58 +00:00
|
|
|
gains: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Classical',
|
|
|
|
gains: [-1, -1, -1, -1, -1, -1, -7, -7, -7, -9],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Club',
|
|
|
|
gains: [-1, -1, 8, 5, 5, 5, 3, -1, -1, -1],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Dance',
|
|
|
|
gains: [9, 7, 2, -1, -1, -5, -7, -7, -1, -1],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Full Bass',
|
|
|
|
gains: [-8, 9, 9, 5, 1, -4, -8, -10, -11, -11]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Full Treble',
|
|
|
|
gains: [-9, -9, -9, -4, 2, 11, 16, 16, 16, 16]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Headphone',
|
|
|
|
gains: [4, 11, 5, -3, -2, 1, 4, 9, 12, 14]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Large Hall',
|
|
|
|
gains: [10, 10, 5, 5, -1, -4, -4, -4, -1, -1],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Live',
|
|
|
|
gains: [-4, -1, 4, 5, 5, 5, 4, 2, 2, 2],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Pop',
|
|
|
|
gains: [-1, 4, 7, 8, 5, -1, -2, -2, -1, -1],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Reggae',
|
|
|
|
gains: [-1, -1, -1, -5, -1, 6, 6, -1, -1, -1],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Rock',
|
|
|
|
gains: [8, 4, -5, -8, -3, 4, 8, 11, 11, 11],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Soft Rock',
|
|
|
|
gains: [4, 4, 2, -1, -4, -5, -3, -1, 2, 8],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Techno',
|
|
|
|
gains: [8, 5, -1, -5, -4, -1, 8, 9, 9, 8],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* Init the equalizer.
|
|
|
|
*
|
2016-01-17 14:26:24 +00:00
|
|
|
* @param {Element} player The audio player's DOM.
|
2016-01-11 15:25:58 +00:00
|
|
|
*/
|
|
|
|
init(player) {
|
|
|
|
var AudioContext = window.AudioContext || window.webkitAudioContext || false;
|
|
|
|
var context = new AudioContext();
|
|
|
|
|
|
|
|
var gainNode = context.createGain();
|
|
|
|
gainNode.gain.value = 1;
|
|
|
|
|
|
|
|
var source = context.createMediaElementSource(player);
|
|
|
|
source.connect(gainNode);
|
|
|
|
|
|
|
|
var prevFilter = null;
|
|
|
|
|
|
|
|
var savedGains = preferenceStore.get('equalizerGains');
|
|
|
|
|
|
|
|
// Create 10 bands with the frequencies similar to those of Winamp and connect them together.
|
|
|
|
[60, 170, 310, 600, 1000, 3000, 6000, 12000, 14000, 16000].forEach((f, i) => {
|
|
|
|
var filter = context.createBiquadFilter();
|
|
|
|
|
|
|
|
filter.type = 'peaking';
|
|
|
|
filter.gain.value = savedGains[i];
|
|
|
|
filter.Q.value = 1;
|
|
|
|
filter.frequency.value = f;
|
|
|
|
|
|
|
|
if (!prevFilter) {
|
|
|
|
gainNode.connect(filter);
|
|
|
|
} else {
|
|
|
|
prevFilter.connect(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
prevFilter = filter;
|
|
|
|
|
|
|
|
this.bands.push({
|
|
|
|
filter,
|
|
|
|
label: (f + '').replace('000', 'K'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
prevFilter.connect(context.destination);
|
2016-01-17 05:14:12 +00:00
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
$('#equalizer input[type="range"]').each((i, el) => {
|
|
|
|
$(el).rangeslider({
|
|
|
|
// Force the polyfill and its styles on all browsers
|
|
|
|
polyfill: false,
|
|
|
|
|
|
|
|
onSlide: (position, value) => {
|
|
|
|
this.changeGain(this.bands[i].filter, value);
|
|
|
|
},
|
|
|
|
|
|
|
|
onSlideEnd: () => {
|
|
|
|
this.selectedPresetIndex = -1;
|
|
|
|
this.save();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-01-11 15:25:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-01-17 05:14:12 +00:00
|
|
|
* Change the gain value for a band/filter.
|
2016-01-11 15:25:58 +00:00
|
|
|
*
|
2016-01-17 05:14:12 +00:00
|
|
|
* @param {Object} filter The filter object
|
|
|
|
* @param {Object} value
|
2016-01-11 15:25:58 +00:00
|
|
|
*/
|
2016-01-17 05:14:12 +00:00
|
|
|
changeGain(filter, value) {
|
|
|
|
filter.gain.value = value;
|
2016-01-11 15:25:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-01-17 05:14:12 +00:00
|
|
|
* Load a preset when the user select it from the dropdown.
|
2016-01-11 15:25:58 +00:00
|
|
|
*/
|
2016-01-17 05:14:12 +00:00
|
|
|
loadPreset() {
|
|
|
|
if (this.selectedPresetIndex === -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var preset = this.presets[this.selectedPresetIndex];
|
|
|
|
|
2016-01-11 15:25:58 +00:00
|
|
|
$('#equalizer input[type=range]').each((i, input) => {
|
|
|
|
this.bands[i].filter.gain.value = preset.gains[i];
|
|
|
|
input.value = preset.gains[i];
|
|
|
|
});
|
|
|
|
|
2016-01-17 05:14:12 +00:00
|
|
|
$('#equalizer input[type="range"]').rangeslider('update', true);
|
|
|
|
|
2016-01-11 15:25:58 +00:00
|
|
|
this.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the current user's equalizer preferences into local storage.
|
|
|
|
*/
|
|
|
|
save() {
|
|
|
|
preferenceStore.set('equalizerGains', _.pluck(this.bands, 'filter.gain.value'));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'equalizer:init': function (player) {
|
|
|
|
if (utils.isAudioContextSupported()) {
|
|
|
|
this.init(player);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2016-01-17 05:14:12 +00:00
|
|
|
<style lang="sass">
|
2016-01-11 15:25:58 +00:00
|
|
|
@import "resources/assets/sass/partials/_vars.scss";
|
|
|
|
@import "resources/assets/sass/partials/_mixins.scss";
|
|
|
|
|
|
|
|
#equalizer {
|
|
|
|
position: absolute;
|
|
|
|
bottom: $footerHeight;
|
|
|
|
width: 100%;
|
|
|
|
background: rgba(0, 0, 0, 0.9);
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
left: 0;
|
|
|
|
|
|
|
|
.presets {
|
2016-01-17 05:14:12 +00:00
|
|
|
padding: 8px 16px;
|
2016-01-11 15:25:58 +00:00
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
justify-content: space-between;
|
|
|
|
flex: 1;
|
|
|
|
align-content: center;
|
2016-01-16 05:15:33 +00:00
|
|
|
z-index: 1;
|
2016-01-17 05:14:12 +00:00
|
|
|
border-bottom: 1px solid rgba(255, 255, 255, .1);
|
|
|
|
|
|
|
|
.select-wrapper {
|
|
|
|
position: relative;
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
content: '\f107';
|
|
|
|
font-family: FontAwesome;
|
|
|
|
color: $colorHighlight;
|
|
|
|
display: inline-block;
|
|
|
|
position: absolute;
|
|
|
|
right: 8px;
|
|
|
|
top: 3px;
|
|
|
|
pointer-events: none;
|
2016-01-11 15:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-17 05:14:12 +00:00
|
|
|
|
|
|
|
select {
|
|
|
|
background: none;
|
|
|
|
color: $colorMainText;
|
|
|
|
padding-left: 0;
|
|
|
|
width: 100px;
|
|
|
|
text-transform: none;
|
|
|
|
}
|
2016-01-11 15:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.bands {
|
2016-01-17 05:14:12 +00:00
|
|
|
padding: 16px;
|
2016-01-11 15:25:58 +00:00
|
|
|
display: flex;
|
|
|
|
left: 0;
|
|
|
|
justify-content: space-between;
|
|
|
|
font-size: 70%;
|
|
|
|
align-items: center;
|
2016-01-16 05:15:33 +00:00
|
|
|
z-index: 1;
|
2016-01-11 15:25:58 +00:00
|
|
|
|
|
|
|
.band {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
}
|
2016-01-12 14:53:15 +00:00
|
|
|
|
2016-01-17 05:14:12 +00:00
|
|
|
/**
|
|
|
|
* The range slider styles
|
|
|
|
*/
|
|
|
|
.rangeslider {
|
|
|
|
background: transparent;
|
2016-01-17 05:39:12 +00:00
|
|
|
box-shadow: none;
|
2016-01-17 05:14:12 +00:00
|
|
|
|
|
|
|
&--vertical {
|
|
|
|
min-height: 100px;
|
|
|
|
|
|
|
|
&::before {
|
|
|
|
content: " ";
|
|
|
|
position: absolute;
|
|
|
|
left: 9px;
|
|
|
|
width: 2px;
|
|
|
|
background: rgba(255, 255, 255, 0.2);
|
|
|
|
z-index: 1;
|
|
|
|
height: 100%;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.rangeslider__fill {
|
|
|
|
width: 2px;
|
|
|
|
background: #fff;
|
|
|
|
position: absolute;
|
|
|
|
left: 9px;
|
|
|
|
box-shadow: none;
|
|
|
|
border-radius: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.rangeslider__handle {
|
|
|
|
left: 0;
|
|
|
|
background: #fff;
|
|
|
|
border: 0;
|
|
|
|
height: 2px;
|
|
|
|
width: 100%;
|
|
|
|
border-radius: 0;
|
|
|
|
box-shadow: none;
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@media only screen and (max-device-width : 768px) {
|
2016-01-12 14:53:15 +00:00
|
|
|
position: fixed;
|
|
|
|
max-width: 414px;
|
|
|
|
left: auto;
|
|
|
|
right: 0;
|
|
|
|
bottom: $footerHeight + 5px;
|
|
|
|
display: block;
|
|
|
|
height: auto;
|
|
|
|
|
|
|
|
.presets {
|
|
|
|
overflow-x: auto;
|
|
|
|
white-space: nowrap;
|
|
|
|
display: block;
|
|
|
|
height: 48px;
|
|
|
|
flex: none;
|
|
|
|
padding: 6px 0 0;
|
|
|
|
margin: 0 0;
|
|
|
|
overflow-y: hidden;
|
2016-01-12 15:00:04 +00:00
|
|
|
-webkit-overflow-scrolling: touch;
|
2016-01-12 14:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
label {
|
|
|
|
line-height: 20px;
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 15:25:58 +00:00
|
|
|
}
|
|
|
|
</style>
|