Skip to content

Commit

Permalink
Revert the stdout/stderr capturing
Browse files Browse the repository at this point in the history
  • Loading branch information
simlmx committed Nov 20, 2018
1 parent 01d19ac commit d2a5e73
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Next Release

* Revert the stdout/stderr capture as it caused other issues.

# 0.4.0

* Capture the stdout/stderr of the plugin. (79d33bd)
Expand Down
5 changes: 2 additions & 3 deletions pyvst/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ def vst(self):
raise RuntimeError('You must first load a vst using `self.load_vst`.')
return self._vst

def load_vst(self, path_to_so_file=None, verbose=False):
def load_vst(self, path_to_so_file=None):
"""
Loads a vst. If there was already a vst loaded, we will release it.
:param path_to_so_file: Path to the .so file to use as a plugin. If we call this without
any path, we will simply try to reload using the same path as the last call.
:param verbose: Set to False (default) to capture the VST's stdout/stderr.
"""
reloading = False
if path_to_so_file is None:
Expand All @@ -95,7 +94,7 @@ def load_vst(self, path_to_so_file=None, verbose=False):
params = [self._vst.get_param_value(i) for i in range(self._vst.num_params)]
del self._vst

self._vst = VstPlugin(path_to_so_file, self._callback, verbose=verbose)
self._vst = VstPlugin(path_to_so_file, self._callback)

# If we are reloading the same VST, put back the parameters where they were.
if reloading:
Expand Down
30 changes: 9 additions & 21 deletions pyvst/vstplugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import contextlib
from ctypes import (cdll, Structure, POINTER, CFUNCTYPE,
c_void_p, c_int, c_float, c_int32, c_double, c_char,
addressof, byref, pointer, cast, string_at, create_string_buffer)
from warnings import warn

import numpy
from wurlitzer import pipes

from .vstwrap import (
AudioMasterOpcodes,
Expand All @@ -32,22 +30,14 @@ def _default_audio_master_callback(effect, opcode, *args):


class VstPlugin:
def __init__(self, filename, audio_master_callback=None, verbose=False):
"""
:param verbose: Set to True to show the plugin's stdout/stderr. By default (False),
we capture it.
"""
self.verbose = verbose

def __init__(self, filename, audio_master_callback=None):
if audio_master_callback is None:
audio_master_callback = _default_audio_master_callback
self._lib = cdll.LoadLibrary(filename)
self._lib.VSTPluginMain.argtypes = [AUDIO_MASTER_CALLBACK_TYPE]
self._lib.VSTPluginMain.restype = POINTER(AEffect)

# Capture stdout and stderr, unless in verbose mode
with pipes() if not verbose else contextlib.suppress():
self._effect = self._lib.VSTPluginMain(AUDIO_MASTER_CALLBACK_TYPE(audio_master_callback)).contents
self._effect = self._lib.VSTPluginMain(AUDIO_MASTER_CALLBACK_TYPE(audio_master_callback)).contents

assert self._effect.magic == MAGIC

Expand All @@ -70,8 +60,7 @@ def _dispatch(self, opcode, index=0, value=0, ptr=None, opt=0.):
if ptr is None:
ptr = c_void_p(None)
# self._effect.dispatcher.argtypes = [POINTER(AEffect), c_int32, c_int32, c_int, c_void_p, c_float]
with pipes() if not self.verbose else contextlib.suppress():
output = self._effect.dispatcher(byref(self._effect), c_int32(opcode), c_int32(index), c_int(value), ptr, c_float(opt))
output = self._effect.dispatcher(byref(self._effect), c_int32(opcode), c_int32(index), c_int(value), ptr, c_float(opt))
return output

# Parameters
Expand Down Expand Up @@ -166,13 +155,12 @@ def process(self, input=None, sample_frames=None):

output = self._make_empty_array(sample_frames, self.num_outputs)

with pipes() if not self.verbose else contextlib.suppress():
self._effect.process_replacing(
byref(self._effect),
input,
output,
sample_frames
)
self._effect.process_replacing(
byref(self._effect),
input,
output,
sample_frames
)

output = numpy.vstack([numpy.ctypeslib.as_array(output[i], shape=(sample_frames,))
for i in range(self.num_outputs)])
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
packages = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
install_requires=[
'numpy>=1.15.1',
'wurlitzer==1.0.1',
],
extras_require={
'dev': [
Expand Down

0 comments on commit d2a5e73

Please sign in to comment.