Skip to content

Commit

Permalink
Load modules that are in buffers via tempfile tricks
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewryanscott committed Oct 18, 2016
1 parent 51183b7 commit b98cf90
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions sunvox/slot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from collections import defaultdict
from contextlib import contextmanager
from io import BytesIO
import os
import tempfile

from . import dll

Expand Down Expand Up @@ -165,8 +167,25 @@ def load_file(self, file):
def load_filename(self, filename):
return self.process.load(self.number, filename)

def load_module(self, file_name, x, y, z):
return self.process.load_module(self.number, file_name, x, y, z)
def load_module(self, file_name, x=512, y=512, z=512):
value = None
if isinstance(file_name, BytesIO):
value = file_name.getvalue()
elif hasattr(file_name, 'mtype'):
import rv
value = rv.Synth(file_name).read()
elif hasattr(file_name, 'read'):
value = file_name.read()
if value is not None:
fd, file_name = tempfile.mkstemp('.sunsynth')
file_name = file_name.encode('utf8')
os.write(fd, value)
os.close(fd)
try:
return self.process.load_module(self.number, file_name, x, y, z)
finally:
if value is not None:
os.unlink(file_name)

def lock(self):
self.locks += 1
Expand Down

0 comments on commit b98cf90

Please sign in to comment.