Spaces:
Running
Running
no more insanely small scales
Browse files
app.py
CHANGED
|
@@ -9,21 +9,30 @@ def _safer_eval(string:str) -> float:
|
|
| 9 |
|
| 10 |
def BeatSwap(audiofile, pattern: str = 'test', scale:float = 1, shift:float = 0, caching:bool = True, variableBPM:bool = False):
|
| 11 |
print()
|
| 12 |
-
print(f'
|
| 13 |
-
if scale == '' or scale is None: scale = 1
|
| 14 |
-
if shift == '' or shift is None: shift = 0
|
| 15 |
if pattern == '' or pattern is None: pattern = 'test'
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
if audiofile is not None:
|
| 19 |
try:
|
| 20 |
-
song=bm.song(path=audiofile, filename=audiofile.split('.')[-2][:-8]+'.'+audiofile.split('.')[-1], caching=caching)
|
| 21 |
except Exception as e:
|
| 22 |
print(f'Failed to load audio, retrying: {e}')
|
| 23 |
-
song=bm.song(path=audiofile, caching=caching)
|
| 24 |
else:
|
| 25 |
print(f'Audiofile is {audiofile}')
|
| 26 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
lib = 'madmom.BeatDetectionProcessor' if variableBPM is False else 'madmom.BeatTrackingProcessor'
|
| 28 |
song.beatmap.generate(lib=lib, caching=caching)
|
| 29 |
song.beatmap.shift(shift)
|
|
|
|
| 9 |
|
| 10 |
def BeatSwap(audiofile, pattern: str = 'test', scale:float = 1, shift:float = 0, caching:bool = True, variableBPM:bool = False):
|
| 11 |
print()
|
| 12 |
+
print(f'path = {audiofile}, pattern = "{pattern}", scale = {scale}, shift = {shift}, caching = {caching}, variable BPM = {variableBPM}', end=', ')
|
|
|
|
|
|
|
| 13 |
if pattern == '' or pattern is None: pattern = 'test'
|
| 14 |
+
try:
|
| 15 |
+
scale=_safer_eval(scale)
|
| 16 |
+
except: scale = 1
|
| 17 |
+
try:
|
| 18 |
+
shift=_safer_eval(shift)
|
| 19 |
+
except: shift = 0
|
| 20 |
+
if scale < 0.02: scale = 0.02
|
| 21 |
if audiofile is not None:
|
| 22 |
try:
|
| 23 |
+
song=bm.song(path=audiofile, filename=audiofile.split('.')[-2][:-8]+'.'+audiofile.split('.')[-1], caching=caching, log=False)
|
| 24 |
except Exception as e:
|
| 25 |
print(f'Failed to load audio, retrying: {e}')
|
| 26 |
+
song=bm.song(path=audiofile, caching=caching, log=False)
|
| 27 |
else:
|
| 28 |
print(f'Audiofile is {audiofile}')
|
| 29 |
return
|
| 30 |
+
try:
|
| 31 |
+
print(scale, shift, len(song.audio[0])/song.samplerate)
|
| 32 |
+
if len(song.audio[0]) > (song.samplerate*1800):
|
| 33 |
+
song.audio = np.asarray(song.audio)
|
| 34 |
+
song.audio = song.audio[:,:song.samplerate*1800]
|
| 35 |
+
except Exception as e: print(f'Reducing audio size failed, why? {e}')
|
| 36 |
lib = 'madmom.BeatDetectionProcessor' if variableBPM is False else 'madmom.BeatTrackingProcessor'
|
| 37 |
song.beatmap.generate(lib=lib, caching=caching)
|
| 38 |
song.beatmap.shift(shift)
|