Start a audioproc process on startup. Properly shutdown processes on exit.

looper
Ben Niemann 7 years ago
parent 2cfe50cda1
commit e90d05f240
  1. 1
      noisicaa/audioproc/__init__.py
  2. 5
      noisicaa/audioproc/audioproc_client.py
  3. 11
      noisicaa/editor_main.py
  4. 5
      noisicaa/music/project_client.py
  5. 37
      noisicaa/ui/editor_app.py
  6. 8
      noisicaa/ui/project_registry.py

@ -0,0 +1 @@
from .audioproc_client import AudioProcClientMixin

@ -28,12 +28,15 @@ class AudioProcClientMixin(object):
self._session_id = await self._stub.call(
'START_SESSION', self.server.address)
async def disconnect(self):
async def disconnect(self, shutdown=False):
if self._session_id is not None:
await self._stub.call('END_SESSION', self._session_id)
self._session_id = None
if self._stub is not None:
if shutdown:
await self.shutdown()
await self._stub.close()
self._stub = None

@ -21,6 +21,9 @@ class Main(object):
self.manager = process_manager.ProcessManager(self.event_loop)
self.manager.server.add_command_handler(
'CREATE_PROJECT_PROCESS', self.handle_create_project_process)
self.manager.server.add_command_handler(
'CREATE_AUDIOPROC_PROCESS',
self.handle_create_audioproc_process)
self.stop_event = asyncio.Event()
self.returncode = 0
@ -118,6 +121,14 @@ class Main(object):
'project', 'noisicaa.music.project_process.ProjectProcess')
return proc.address
async def handle_create_audioproc_process(self, name):
# TODO: keep map of name->proc, only create processes for new
# names.
proc = await self.manager.start_process(
'audioproc<%s>' % name,
'noisicaa.audioproc.audioproc_process.AudioProcProcess')
return proc.address
if __name__ == '__main__':
sys.exit(Main().run(sys.argv))

@ -83,12 +83,15 @@ class ProjectClientMixin(object):
# Connected to a loaded project.
self.__set_project(root_id)
async def disconnect(self):
async def disconnect(self, shutdown=False):
if self._session_id is not None:
await self._stub.call('END_SESSION', self._session_id)
self._session_id = None
if self._stub is not None:
if shutdown:
await self.shutdown()
await self._stub.close()
self._stub = None

@ -15,6 +15,7 @@ from PyQt5.QtWidgets import (
QFileDialog,
)
from noisicaa import audioproc
from noisicaa import music
from noisicaa import devices
from ..exceptions import RestartAppException, RestartAppCleanException
@ -56,6 +57,22 @@ class ExceptHook(object):
errorbox.exec_()
class AudioProcClientImpl(object):
def __init__(self, event_loop, server):
super().__init__()
self.event_loop = event_loop
self.server = server
async def setup(self):
pass
async def cleanup(self):
pass
class AudioProcClient(audioproc.AudioProcClientMixin, AudioProcClientImpl):
pass
class BaseEditorApp(QApplication):
def __init__(self, process, runtime_settings, settings=None):
super().__init__(['noisicaä'])
@ -78,6 +95,8 @@ class BaseEditorApp(QApplication):
self.project_registry = None
self.sequencer = None
self.midi_hub = None
self.audioproc_client = None
self.audioproc_process = None
async def setup(self):
self.default_style = self.style().objectName()
@ -102,8 +121,22 @@ class BaseEditorApp(QApplication):
self.show_edit_areas_action.setChecked(
int(self.settings.value('dev/show_edit_areas', '0')))
self.audioproc_process = await self.process.manager.call(
'CREATE_AUDIOPROC_PROCESS', 'main')
self.audioproc_client = AudioProcClient(
self.process.event_loop, self.process.server)
await self.audioproc_client.setup()
await self.audioproc_client.connect(self.audioproc_process)
async def cleanup(self):
logger.info("Cleaning up.")
if self.audioproc_client is not None:
await self.audioproc_client.disconnect(shutdown=True)
await self.audioproc_client.cleanup()
self.audioproc_client = None
if self.midi_hub is not None:
self.midi_hub.stop()
self.midi_hub = None
@ -112,6 +145,10 @@ class BaseEditorApp(QApplication):
self.sequencer.close()
self.sequencer = None
if self.project_registry is not None:
await self.project_registry.close_all()
self.project_registry = None
def quit(self, exit_code=0):
self.process.quit(exit_code)

@ -40,7 +40,9 @@ class Project(object):
async def close(self):
await self.client.close()
await self.client.shutdown()
await self.client.disconnect(shutdown=True)
await self.client.cleanup()
self.client = None
class ProjectRegistry(object):
@ -64,3 +66,7 @@ class ProjectRegistry(object):
async def close_project(self, project):
await project.close()
del self.projects[project.path]
async def close_all(self):
for project in list(self.projects.values()):
await self.close_project(project)

Loading…
Cancel
Save