Skip to content

Commit

Permalink
add: export slice start in cue chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanTaquet committed Oct 25, 2016
1 parent 047df9e commit a5fa141
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Oe2sSLE_GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ def export_sample(self):
if filename:
try:
with open(filename, 'wb') as f:
e2s_sample.write(f, export_smpl=True)
e2s_sample.write(f, export_smpl=True, export_cue=True)
except Exception as e:
tk.messagebox.showwarning(
"Export sample as",
Expand Down Expand Up @@ -2090,7 +2090,7 @@ def fct():
while not ok:
try:
with open(filename, 'wb') as f:
e2s_sample.write(f, export_smpl=True)
e2s_sample.write(f, export_smpl=True, export_cue=True)
except Exception as e:
tk.messagebox.showwarning(
"Export sample as",
Expand Down
34 changes: 33 additions & 1 deletion e2s_sample_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def read(self, file):
"Expected {} chunk, got {}; ignored.".format(b"RIFF", self.header.id))
self.RIFF = RIFF.Form(file,self.header,registeredForms={b'WAVE':RIFF_korgWAVEChunkList})

def write(self, file, export_smpl=False, _do_clean=True):
def write(self, file, export_smpl=False, export_cue=False, _do_clean=True):
sample = self

if _do_clean:
Expand All @@ -385,6 +385,38 @@ def write(self, file, export_smpl=False, _do_clean=True):
sample.RIFF.chunkList.chunks.append(smpl_chunk)
uid += 1

if export_cue:
num_samples = len(sample.get_data()) // fmt.blockAlign
slices = []
for slice in esli.slices:
if not slice.length:
continue
# remove duplicates
skip = False
for other in slices:
if slice.start == other.start:
skip = True
break
if slice.start >= num_samples:
skip = True
break
if skip:
continue
slices.append(slice)
if slices:
cue = RIFF_cue()
for slice in slices:
cue_point = cue.add_cue_point()
cue_point.identifier = uid
cue_point.position = slice.start
cue_point.fccChunk = b'data'
#cue_point.chunkStart = 0
#cue_point.blockStart = 0
cue_point.sampleOffset = slice.start
uid += 1
cue_chunk = RIFF.Chunk(header=RIFF.ChunkHeader(id=b'cue '),data=cue)
sample.RIFF.chunkList.chunks.append(cue_chunk)

sample.update_header()
sample.header.write(file)
sample.RIFF.write(file)
Expand Down

0 comments on commit a5fa141

Please sign in to comment.