Instrument library makes some noises again.

looper
Ben Niemann 7 years ago
parent 851cf125ca
commit 21eb56ff61

@ -15,7 +15,7 @@ class PassThru(node.Node):
desc.port('in', 'input', 'audio')
desc.port('out', 'output', 'audio')
def __init__(self, event_loop, name, id):
def __init__(self, event_loop, name='passthru', id=None):
super().__init__(event_loop, name, id)
self._input = ports.AudioInputPort('in')

@ -47,7 +47,7 @@ class SoundFontInstrument(Instrument):
def __init__(self, name, collection, path, bank, preset):
super().__init__(
name,
hashlib.md5('%s:%d:%d' % (path, bank, preset)).hexdigest())
hashlib.md5(('%s:%d:%d' % (path, bank, preset)).encode('utf-8')).hexdigest())
self.collection = collection
self.path = path

@ -234,6 +234,7 @@ class EditorApp(BaseEditorApp):
logger.info("Creating EditorWindow.")
self.win = EditorWindow(self)
await self.win.setup()
self.win.show()
if self.paths:
@ -265,7 +266,7 @@ class EditorApp(BaseEditorApp):
async def cleanup(self):
if self.win is not None:
self.win.closeAll()
await self.win.cleanup()
self.win = None
await super().cleanup()

@ -118,6 +118,21 @@ class EditorWindow(ui_base.CommonMixin, QMainWindow):
self.restoreState(
self.app.settings.value('mainwindow/state', b''))
async def setup(self):
await self._instrument_library_dialog.setup()
async def cleanup(self):
await self._instrument_library_dialog.cleanup()
self.hide()
while self._project_tabs.count() > 0:
view = self._project_tabs.widget(0)
view.close()
self._project_tabs.removeTab(0)
self._settings_dialog.close()
self.close()
def createStartView(self):
view = QWidget(self)
@ -365,14 +380,6 @@ class EditorWindow(ui_base.CommonMixin, QMainWindow):
event.accept()
self.app.quit()
def closeAll(self):
while self._project_tabs.count() > 0:
view = self._project_tabs.widget(0)
view.close()
self._project_tabs.removeTab(0)
self._settings_dialog.close()
self.close()
def setCurrentProjectView(self, project_view):
if project_view == self._current_project_view:
return

@ -45,6 +45,9 @@ class InstrumentLibraryDialog(ui_base.CommonMixin, QtWidgets.QDialog):
logger.info("InstrumentLibrary created")
self._pipeline_mixer_id = None
self._pipeline_instrument_id = None
self.setWindowTitle("noisicaä - Instrument Library")
self.tabs = QtWidgets.QTabWidget(self)
@ -152,18 +155,65 @@ class InstrumentLibraryDialog(ui_base.CommonMixin, QtWidgets.QDialog):
def library(self):
return self.app.instrument_library
# def closeEvent(self, event):
# self.library.dispatch_command(
# "/ui_state",
# UpdateUIState(
# visible=False,
# geometry=bytes(self.saveGeometry()),
# page=self.tabs.currentIndex(),
# instruments_splitter_state=bytes(
# self.instruments_page.saveState()),
# instruments_list_item=self.instruments_list.currentRow(),
# instruments_search_text=self.instruments_search.text(),
# ))
async def setup(self):
logger.info("Setting up instrument library dialog...")
self._pipeline_mixer_id = await self.audioproc_client.add_node(
'passthru', name='library-mixer')
await self.audioproc_client.connect_ports(
self._pipeline_mixer_id, 'out', 'sink', 'in')
async def cleanup(self):
logger.info("Cleaning up instrument library dialog...")
if self._pipeline_instrument_id is not None:
assert self._pipeline_mixer_id is not None
await self.removeInstrumentFromPipeline()
if self._pipeline_mixer_id is not None:
await self.audioproc_client.disconnect_ports(
self._pipeline_mixer_id, 'out', 'sink', 'in')
await self.audioproc_client.remove_node(
self._pipeline_mixer_id)
self._pipeline_mixer_id = None
async def addInstrumentToPipeline(self, node_type, **args):
assert self._pipeline_instrument_id is None
self._pipeline_instrument_id = await self.audioproc_client.add_node(
node_type, **args)
await self.audioproc_client.connect_ports(
self._pipeline_instrument_id, 'out',
self._pipeline_mixer_id, 'in')
self._pipeline_event_source_id = await self.audioproc_client.add_node(
'track_event_source')
await self.audioproc_client.connect_ports(
self._pipeline_event_source_id, 'out',
self._pipeline_instrument_id, 'in')
async def removeInstrumentFromPipeline(self):
assert self._pipeline_instrument_id is not None
await self.audioproc_client.disconnect_ports(
self._pipeline_event_source_id, 'out',
self._pipeline_instrument_id, 'in')
await self.audioproc_client.remove_node(
self._pipeline_event_source_id)
self._pipeline_event_source_id = None
await self.audioproc_client.disconnect_ports(
self._pipeline_instrument_id, 'out',
self._pipeline_mixer_id, 'in')
await self.audioproc_client.remove_node(
self._pipeline_instrument_id)
self._pipeline_instrument_id = None
def closeEvent(self, event):
if self._pipeline_instrument_id is not None:
self.call_async(self.removeInstrumentFromPipeline())
super().closeEvent(event)
def updateInstrumentList(self):
self.instruments_list.clear()
@ -201,6 +251,11 @@ class InstrumentLibraryDialog(ui_base.CommonMixin, QtWidgets.QDialog):
return
instr = item.instrument
self.call_async(self.setCurrentInstrument(item.instrument))
async def setCurrentInstrument(self, instr):
if self._pipeline_instrument_id:
await self.removeInstrumentFromPipeline()
self.instrument_name.setText(instr.name)
@ -215,6 +270,11 @@ class InstrumentLibraryDialog(ui_base.CommonMixin, QtWidgets.QDialog):
self.instrument_location.setText(
"bank %d, preset %d" % (instr.bank, instr.preset))
await self.addInstrumentToPipeline(
'fluidsynth',
soundfont_path=instr.path,
bank=instr.bank, preset=instr.preset)
self.piano.setVisible(True)
self.piano.setFocus(Qt.OtherFocusReason)

@ -26,6 +26,10 @@ class CommonMixin(object):
def window(self):
return self.__app.win
@property
def audioproc_client(self):
return self.__app.audioproc_client
@property
def event_loop(self):
return self.__app.process.event_loop

Loading…
Cancel
Save