diff --git a/noisicaa/audioproc/__init__.py b/noisicaa/audioproc/__init__.py index e69de29b..c0600fb2 100644 --- a/noisicaa/audioproc/__init__.py +++ b/noisicaa/audioproc/__init__.py @@ -0,0 +1 @@ +from .audioproc_client import AudioProcClientMixin diff --git a/noisicaa/audioproc/audioproc_client.py b/noisicaa/audioproc/audioproc_client.py index 46a898d3..b3e44a00 100644 --- a/noisicaa/audioproc/audioproc_client.py +++ b/noisicaa/audioproc/audioproc_client.py @@ -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 diff --git a/noisicaa/editor_main.py b/noisicaa/editor_main.py index 1134fa43..e20474b9 100644 --- a/noisicaa/editor_main.py +++ b/noisicaa/editor_main.py @@ -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)) diff --git a/noisicaa/music/project_client.py b/noisicaa/music/project_client.py index 65daa788..f3231857 100644 --- a/noisicaa/music/project_client.py +++ b/noisicaa/music/project_client.py @@ -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 diff --git a/noisicaa/ui/editor_app.py b/noisicaa/ui/editor_app.py index 55463634..47864a33 100644 --- a/noisicaa/ui/editor_app.py +++ b/noisicaa/ui/editor_app.py @@ -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) diff --git a/noisicaa/ui/project_registry.py b/noisicaa/ui/project_registry.py index 65ad1995..ab623ead 100644 --- a/noisicaa/ui/project_registry.py +++ b/noisicaa/ui/project_registry.py @@ -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)