Browse Source

Save and restore canvas positions in new sibling file to project

tags/1.9.8
falkTX 7 years ago
parent
commit
eee6dc433a
3 changed files with 76 additions and 3 deletions
  1. +1
    -0
      source/carla_backend_qt.py
  2. +29
    -3
      source/carla_host.py
  3. +46
    -0
      source/patchcanvas.py

+ 1
- 0
source/carla_backend_qt.py View File

@@ -74,6 +74,7 @@ class CarlaHostSignals(QObject):
TransportModeChangedCallback = pyqtSignal(int)
BufferSizeChangedCallback = pyqtSignal(int)
SampleRateChangedCallback = pyqtSignal(float)
ProjectLoadFinishedCallback = pyqtSignal()
NSMCallback = pyqtSignal(int, int, str)
InfoCallback = pyqtSignal(str)
ErrorCallback = pyqtSignal(str)


+ 29
- 3
source/carla_host.py View File

@@ -466,6 +466,7 @@ class HostWindow(QMainWindow):
host.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
host.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback)
host.SampleRateChangedCallback.connect(self.slot_handleSampleRateChangedCallback)
host.ProjectLoadFinishedCallback.connect(self.slot_handleProjectLoadFinishedCallback)

host.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback)
host.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback)
@@ -557,6 +558,9 @@ class HostWindow(QMainWindow):
# --------------------------------------------------------------------------------------------------------
# Files

def makeExtraFilename(self):
return self.fProjectFilename.rsplit(".",1)[0]+".json"

def loadProjectNow(self):
if not self.fProjectFilename:
return qCritical("ERROR: loading project without filename set")
@@ -565,11 +569,9 @@ class HostWindow(QMainWindow):

self.projectLoadingStarted()
self.fIsProjectLoading = True

self.host.load_project(self.fProjectFilename)

self.fIsProjectLoading = False
self.projectLoadingFinished()
# Project finished loading is sent by engine

def loadProjectLater(self, filename):
self.fProjectFilename = QFileInfo(filename).absoluteFilePath()
@@ -582,6 +584,11 @@ class HostWindow(QMainWindow):

self.host.save_project(self.fProjectFilename)

with open(self.makeExtraFilename(), 'w') as fh:
json.dump({
'canvas': patchcanvas.saveGroupPositions(),
}, fh)

def projectLoadingStarted(self):
self.ui.rack.setEnabled(False)
self.ui.graphicsView.setEnabled(False)
@@ -591,6 +598,18 @@ class HostWindow(QMainWindow):
self.ui.graphicsView.setEnabled(True)
QTimer.singleShot(1000, self.slot_canvasRefresh)

extrafile = self.makeExtraFilename()
if not os.path.exists(extrafile):
return

try:
with open(extrafile, "r") as fh:
canvasdata = json.load(fh)['canvas']
except:
return

patchcanvas.restoreGroupPositions(canvasdata)

# --------------------------------------------------------------------------------------------------------
# Files (menu actions)

@@ -803,6 +822,11 @@ class HostWindow(QMainWindow):
self.fSampleRate = newSampleRate
self.refreshTransport(True)

@pyqtSlot()
def slot_handleProjectLoadFinishedCallback(self):
self.fIsProjectLoading = False
self.projectLoadingFinished()

# --------------------------------------------------------------------------------------------------------
# Plugins

@@ -2346,6 +2370,8 @@ def engineCallback(host, action, pluginId, value1, value2, value3, valueStr):
host.BufferSizeChangedCallback.emit(value1)
elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
host.SampleRateChangedCallback.emit(value3)
elif action == ENGINE_CALLBACK_PROJECT_LOAD_FINISHED:
host.ProjectLoadFinishedCallback.emit()
elif action == ENGINE_CALLBACK_NSM:
host.NSMCallback.emit(value1, value2, valueStr)
elif action == ENGINE_CALLBACK_IDLE:


+ 46
- 0
source/patchcanvas.py View File

@@ -756,6 +756,52 @@ def getGroupPos(group_id, port_mode=PORT_MODE_OUTPUT):
qCritical("PatchCanvas::getGroupPos(%i, %s) - unable to find group" % (group_id, port_mode2str(port_mode)))
return QPointF(0, 0)

def saveGroupPositions():
if canvas.debug:
print("PatchCanvas::getGroupPositions()")

ret = []

for group in canvas.group_list:
if group.split:
pos1 = group.widgets[0].pos()
pos2 = group.widgets[1].pos()
else:
pos1 = group.widgets[0].pos()
pos2 = QPointF(0, 0)

ret.append({
"name" : group.group_name,
"pos1x": pos1.x(),
"pos1y": pos1.y(),
"pos2x": pos2.x(),
"pos2y": pos2.y(),
"split": group.split,
})

return ret

def restoreGroupPositions(dataList):
if canvas.debug:
print("PatchCanvas::restoreGroupPositions(...)")

map = {}

for group in canvas.group_list:
map[group.group_name] = group

for data in dataList:
name = data['name']
group = map.get(name, None)

if group is None:
continue

group.widgets[0].setPos(data['pos1x'], data['pos1y'])

if group.split and group.widgets[1]:
group.widgets[1].setPos(data['pos2x'], data['pos2y'])

def setGroupPos(group_id, group_pos_x, group_pos_y):
setGroupPosFull(group_id, group_pos_x, group_pos_y, group_pos_x, group_pos_y)



Loading…
Cancel
Save