Add minimum trimmable length for audio trimmer

This commit is contained in:
Paul Kaplan committed 2017-09-18 13:01:41 -04:00
1 parent a7975e5d2f
commit fe4f0a5973
1 file changed
+4 -2
+4 -2
View File
@@ -4,6 +4,8 @@ import bindAll from 'lodash.bindall';
import AudioTrimmerComponent from '../components/audio-trimmer/audio-trimmer.jsx';
import {getEventXY} from '../lib/touch-utils';
const MIN_LENGTH = 0.01; // Used to stop sounds being trimmed smaller than 1%
class AudioTrimmer extends React.Component {
constructor (props) {
super(props);
@@ -20,14 +22,14 @@ class AudioTrimmer extends React.Component {
handleTrimStartMouseMove (e) {
const containerSize = this.containerElement.getBoundingClientRect().width;
const dx = (getEventXY(e).x - this.initialX) / containerSize;
const newTrim = Math.max(0, Math.min(this.props.trimEnd, this.initialTrim + dx));
const newTrim = Math.max(0, Math.min(this.props.trimEnd - MIN_LENGTH, this.initialTrim + dx));
this.props.onSetTrimStart(newTrim);
e.preventDefault();
}
handleTrimEndMouseMove (e) {
const containerSize = this.containerElement.getBoundingClientRect().width;
const dx = (getEventXY(e).x - this.initialX) / containerSize;
const newTrim = Math.min(1, Math.max(this.props.trimStart, this.initialTrim + dx));
const newTrim = Math.min(1, Math.max(this.props.trimStart + MIN_LENGTH, this.initialTrim + dx));
this.props.onSetTrimEnd(newTrim);
e.preventDefault();
}