From 395b3d9d8fcf062ce55ead55c444059c7fac1e8f Mon Sep 17 00:00:00 2001
From: Paul Kaplan <pkaplan@media.mit.edu>
Date: Mon, 14 Jan 2019 12:54:34 -0500
Subject: [PATCH] Prevent 0 sample sounds while trimming #715

---
 src/containers/sound-editor.jsx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/containers/sound-editor.jsx b/src/containers/sound-editor.jsx
index abe292724..7316a8de7 100644
--- a/src/containers/sound-editor.jsx
+++ b/src/containers/sound-editor.jsx
@@ -120,8 +120,10 @@ class SoundEditor extends React.Component {
             const sampleCount = samples.length;
             const startIndex = Math.floor(this.state.trimStart * sampleCount);
             const endIndex = Math.floor(this.state.trimEnd * sampleCount);
-            const clippedSamples = samples.slice(startIndex, endIndex);
-            this.submitNewSamples(clippedSamples, sampleRate);
+            if (endIndex > startIndex) { // Strictly greater to prevent 0 sample sounds
+                const clippedSamples = samples.slice(startIndex, endIndex);
+                this.submitNewSamples(clippedSamples, sampleRate);
+            }
         }
     }
     handleUpdateTrimEnd (trimEnd) {
-- 
GitLab