diff --git a/src/containers/sound-editor.jsx b/src/containers/sound-editor.jsx index 4be944a4a7b8cdfb378e206f6826b312dade05ac..49e2bff6859c022b9ae8f785af8b6d3551aef37d 100644 --- a/src/containers/sound-editor.jsx +++ b/src/containers/sound-editor.jsx @@ -15,6 +15,7 @@ class SoundEditor extends React.Component { constructor (props) { super(props); bindAll(this, [ + 'copyCurrentSamples', 'handleStoppedPlaying', 'handleChangeName', 'handlePlay', @@ -67,7 +68,7 @@ class SoundEditor extends React.Component { if (this.undoStack.length >= UNDO_STACK_SIZE) { this.undoStack.shift(); // Drop the first element off the array } - this.undoStack.push(this.props.samples.slice(0)); + this.undoStack.push(this.copyCurrentSamples()); } this.resetState(samples, sampleRate); this.props.onUpdateSoundBuffer( @@ -115,6 +116,10 @@ class SoundEditor extends React.Component { effectFactory (name) { return () => this.handleEffect(name); } + copyCurrentSamples () { + // Cannot reliably use props.samples because it gets detached by Firefox + return this.audioBufferPlayer.buffer.getChannelData(0); + } handleEffect (name) { const effects = new AudioEffects(this.audioBufferPlayer.buffer, name); effects.process(({renderedBuffer}) => { @@ -125,7 +130,7 @@ class SoundEditor extends React.Component { }); } handleUndo () { - this.redoStack.push(this.props.samples.slice(0)); + this.redoStack.push(this.copyCurrentSamples()); const samples = this.undoStack.pop(); if (samples) { this.submitNewSamples(samples, this.props.sampleRate, true); @@ -135,7 +140,7 @@ class SoundEditor extends React.Component { handleRedo () { const samples = this.redoStack.pop(); if (samples) { - this.undoStack.push(this.props.samples.slice(0)); + this.undoStack.push(this.copyCurrentSamples()); this.submitNewSamples(samples, this.props.sampleRate, true); this.handlePlay(); } diff --git a/test/__mocks__/audio-buffer-player.js b/test/__mocks__/audio-buffer-player.js index dabf72bc37d2ba6553530ada7dc4e9851f4f53a7..476b2b64964f9abb237faacb1048514de3076362 100644 --- a/test/__mocks__/audio-buffer-player.js +++ b/test/__mocks__/audio-buffer-player.js @@ -2,6 +2,9 @@ export default class MockAudioBufferPlayer { constructor (samples, sampleRate) { this.samples = samples; this.sampleRate = sampleRate; + this.buffer = { + getChannelData: jest.fn(() => samples) + }; this.play = jest.fn((trimStart, trimEnd, onUpdate) => { this.onUpdate = onUpdate; });