From 22d75f6483009aa451976a4629b1a011dd3c3b6f Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Thu, 5 Aug 2021 08:12:22 -0700 Subject: [PATCH] seems to work --- src/audiosegment/audiosegment.go | 26 +++++++++++---- src/server/server.go | 13 +++++--- src/server/templates/base.html | 56 ++++++++++++++++++-------------- 3 files changed, 60 insertions(+), 35 deletions(-) diff --git a/src/audiosegment/audiosegment.go b/src/audiosegment/audiosegment.go index 9b2baa6..d349dd1 100644 --- a/src/audiosegment/audiosegment.go +++ b/src/audiosegment/audiosegment.go @@ -30,13 +30,17 @@ func init() { const SECONDSATEND = 0.1 -func SplitEqual(fname string, secondsMax float64, secondsOverlap float64) (allSegments [][]models.AudioSegment, err error) { +func SplitEqual(fname string, secondsMax float64, secondsOverlap float64, splices int) (allSegments [][]models.AudioSegment, err error) { err = Convert(fname, fname+".mp3") if err != nil { return } fname = fname + ".mp3" + if splices > 0 { + secondsOverlap = 0 + } + cmd := fmt.Sprintf("%s", fname) logger.Debug(cmd) out, err := exec.Command("ffprobe", strings.Fields(cmd)...).CombinedOutput() @@ -84,11 +88,21 @@ func SplitEqual(fname string, secondsMax float64, secondsOverlap float64) (allSe continue } - r.segments, r.err = ffmpeg.SplitOnSilence(fnameTrunc, -22, 0.2, -0.2) - if r.err != nil { - logger.Error(r.err) - results <- r - continue + if splices == 0 { + r.segments, r.err = ffmpeg.SplitOnSilence(fnameTrunc, -22, 0.2, -0.2) + if r.err != nil { + logger.Error(r.err) + results <- r + continue + } + } else { + r.segments = make([]models.AudioSegment, splices) + for i, _ := range r.segments { + r.segments[i].Start = secondsDuration * float64(i) / float64(splices) + r.segments[i].End = secondsDuration * float64(i+1) / float64(splices) + r.segments[i].Duration = r.segments[i].End - r.segments[i].Start + r.segments[i].Filename = fnameTrunc + } } r.err = DrawSegments(r.segments) if r.err != nil { diff --git a/src/server/server.go b/src/server/server.go index 2a7dbdb..0f467bd 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -107,6 +107,7 @@ type Metadata struct { IsSynthPatch bool RemoveSilence bool RootNote string + Splices int } type FileData struct { @@ -336,6 +337,7 @@ func viewPatch(w http.ResponseWriter, r *http.Request) (err error) { patchtypeA, _ := r.URL.Query()["synthPatch"] removeSilenceA, _ := r.URL.Query()["removeSilence"] rootNoteA, _ := r.URL.Query()["rootNote"] + splicesA, _ := r.URL.Query()["splices"] patchtype := "drum" removeSilence := false rootNote := "A" @@ -364,8 +366,10 @@ func viewPatch(w http.ResponseWriter, r *http.Request) (err error) { if secondsEnd[0] != "" { startStop[1], _ = strconv.ParseFloat(secondsEnd[0], 64) } + splices, _ := strconv.Atoi(splicesA[0]) + log.Debugf("splices: %d", splices) - uuid, err := generateUserData(audioURL[0], startStop, patchtype, removeSilence, rootNote) + uuid, err := generateUserData(audioURL[0], startStop, patchtype, removeSilence, rootNote, splices) if err != nil { return } @@ -395,7 +399,7 @@ func viewMain(w http.ResponseWriter, r *http.Request, messageError string, templ return } -func generateUserData(u string, startStop []float64, patchType string, removeSilence bool, rootNote string) (uuid string, err error) { +func generateUserData(u string, startStop []float64, patchType string, removeSilence bool, rootNote string, splices int) (uuid string, err error) { log.Debug(u, startStop) log.Debug(patchType) if startStop[1]-startStop[0] < 12 { @@ -405,7 +409,7 @@ func generateUserData(u string, startStop []float64, patchType string, removeSil startStop[1] = startStop[0] + 5.75 } - uuid = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%+v %+v %+v %+v %+v", patchType, u, startStop, removeSilence, rootNote)))) + uuid = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%+v %+v %+v %+v %+v %+v", patchType, u, startStop, removeSilence, rootNote, splices)))) // create path to data pathToData := path.Join("data", uuid) @@ -495,7 +499,7 @@ func generateUserData(u string, startStop []float64, patchType string, removeSil // generate patches var segments [][]models.AudioSegment if patchType == "drum" { - segments, err = audiosegment.SplitEqual(shortName, 12, 1) + segments, err = audiosegment.SplitEqual(shortName, 12, 1, splices) if err != nil { return } @@ -533,6 +537,7 @@ func generateUserData(u string, startStop []float64, patchType string, removeSil IsSynthPatch: patchType == "synth", RemoveSilence: removeSilence, RootNote: rootNote, + Splices: splices, }) err = ioutil.WriteFile(path.Join(pathToData, "metadata.json"), b, 0644) diff --git a/src/server/templates/base.html b/src/server/templates/base.html index 7ff4fe3..7ffe4e4 100644 --- a/src/server/templates/base.html +++ b/src/server/templates/base.html @@ -458,29 +458,33 @@ -
+
-
+
+ + +
+
-
@@ -567,15 +571,17 @@ return true; }); - $('#synthPatch').change(function(e){ - console.log(e.target.value); - if (e.target.value == "drum") { - $("#optionRemoveSilence").show(); - $("#optionRootNote").hide(); - } else { - $("#optionRemoveSilence").hide(); - $("#optionRootNote").show(); - } + $('#synthPatch').change(function(e) { + console.log(e.target.value); + if (e.target.value == "drum") { + $("#optionRemoveSilence").show(); + $("#optionNumberSplices").show(); + $("#optionRootNote").hide(); + } else { + $("#optionRemoveSilence").hide(); + $("#optionNumberSplices").hide(); + $("#optionRootNote").show(); + } }) }); @@ -672,4 +678,4 @@ -((end )) +((end )) \ No newline at end of file