Skip to content

Commit

Permalink
hoo-hoo
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Nov 8, 2020
1 parent 647a458 commit 24a36f2
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions main.py
@@ -1,52 +1,50 @@
#!/usr/bin/env python3
from json import loads as parse_json
from chunk import Chunk
from sys import argv
from pathlib import Path
from ffmpeg import FFmpeg
from chunk import Chunk
import asyncio

# i've taken this from here
# https://github.com/possan/op1-to-ableton-drumrack/blob/master/convert.py
def get_aif_json(path):
aif = open(path, "rb")
# i don't care about the first 12 bytes
aif.read(12)
for _ in range(10):
try:
chunk = Chunk(aif)
if chunk.getname() == b'APPL':
header = chunk.read(4)
if header == b'op-1':
json = parse_json(
chunk.read(
chunk.getsize() - 4
).decode('utf-8').strip('\0').strip()
)
aif.close()
return json
chunk.skip()
except EOFError:
aif.close()
return None
aif = open(path, "rb")
# i don't care about the first 12 bytes
aif.read(12)
for _ in range(10):
try:
chunk = Chunk(aif)
if chunk.getname() == b'APPL':
header = chunk.read(4)
if header == b'op-1':
json = parse_json(
chunk.read(
chunk.getsize() - 4
).decode('utf-8').strip('\0').strip()
)
aif.close()
return json
chunk.skip()
except EOFError:
aif.close()
return None

aif = argv[1]
target_dir = "."
if len(argv) > 2:
target_dir = argv[2]
json = get_aif_json(aif)
samples = []
target_dir = argv[2]
json = get_aif_json(aif)
samples = []

Path(target_dir).mkdir(parents=True, exist_ok=True)

loop = asyncio.get_event_loop()
for index in range(len(json['start'])):
start = json['start'][index] / 4096 / 44100
end = json['end'][index] / 4096 / 44100
loop.run_until_complete(FFmpeg().option('y').input(aif).output(
f"{target_dir}/{index:02d}.wav",
ss=(start),
to=(end)
).execute())
start = json['start'][index] / 4096 / 44100
end = json['end'][index] / 4096 / 44100
loop.run_until_complete(FFmpeg().option('y').input(aif).output(
f"{target_dir}/{index:02d}.wav",
ss=(start),
to=(end)
).execute())

loop.close

0 comments on commit 24a36f2

Please sign in to comment.