Skip to content
Snippets Groups Projects
Commit 6e5f3786 authored by Eric Rosenbaum's avatar Eric Rosenbaum
Browse files

Prevent buffer detach issues with copy/paste on firefox

parent 24d2e344
No related branches found
No related tags found
No related merge requests found
...@@ -295,10 +295,9 @@ class SoundEditor extends React.Component { ...@@ -295,10 +295,9 @@ class SoundEditor extends React.Component {
const trimStart = this.state.trimStart === null ? 0.0 : this.state.trimStart; const trimStart = this.state.trimStart === null ? 0.0 : this.state.trimStart;
const trimEnd = this.state.trimEnd === null ? 1.0 : this.state.trimEnd; const trimEnd = this.state.trimEnd === null ? 1.0 : this.state.trimEnd;
const trimStartSamples = trimStart * this.props.samples.length;
const trimEndSamples = trimEnd * this.props.samples.length;
const newCopyBuffer = this.copyCurrentBuffer(); const newCopyBuffer = this.copyCurrentBuffer();
const trimStartSamples = trimStart * newCopyBuffer.samples.length;
const trimEndSamples = trimEnd * newCopyBuffer.samples.length;
newCopyBuffer.samples = newCopyBuffer.samples.slice(trimStartSamples, trimEndSamples); newCopyBuffer.samples = newCopyBuffer.samples.slice(trimStartSamples, trimEndSamples);
this.setState({ this.setState({
...@@ -335,19 +334,20 @@ class SoundEditor extends React.Component { ...@@ -335,19 +334,20 @@ class SoundEditor extends React.Component {
} }
paste () { paste () {
// If there's no selection, paste at the end of the sound // If there's no selection, paste at the end of the sound
const {samples} = this.copyCurrentBuffer();
if (this.state.trimStart === null) { if (this.state.trimStart === null) {
const newLength = this.props.samples.length + this.state.copyBuffer.samples.length; const newLength = samples.length + this.state.copyBuffer.samples.length;
const newSamples = new Float32Array(newLength); const newSamples = new Float32Array(newLength);
newSamples.set(this.props.samples, 0); newSamples.set(samples, 0);
newSamples.set(this.state.copyBuffer.samples, this.props.samples.length); newSamples.set(this.state.copyBuffer.samples, samples.length);
this.submitNewSamples(newSamples, this.props.sampleRate, false); this.submitNewSamples(newSamples, this.props.sampleRate, false);
this.handlePlay(); this.handlePlay();
} else { } else {
// else replace the selection with the pasted sound // else replace the selection with the pasted sound
const trimStartSamples = this.state.trimStart * this.props.samples.length; const trimStartSamples = this.state.trimStart * samples.length;
const trimEndSamples = this.state.trimEnd * this.props.samples.length; const trimEndSamples = this.state.trimEnd * samples.length;
const firstPart = this.props.samples.slice(0, trimStartSamples); const firstPart = samples.slice(0, trimStartSamples);
const lastPart = this.props.samples.slice(trimEndSamples); const lastPart = samples.slice(trimEndSamples);
const newLength = firstPart.length + this.state.copyBuffer.samples.length + lastPart.length; const newLength = firstPart.length + this.state.copyBuffer.samples.length + lastPart.length;
const newSamples = new Float32Array(newLength); const newSamples = new Float32Array(newLength);
newSamples.set(firstPart, 0); newSamples.set(firstPart, 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment