Skip to content

Commit

Permalink
Always save snapshots, regen screenshot as needed, save indicator
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Dec 22, 2023
1 parent 1d20980 commit a4418dc
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 16 deletions.
4 changes: 4 additions & 0 deletions html/css/pedals.css
Original file line number Diff line number Diff line change
Expand Up @@ -1032,3 +1032,7 @@ body > .mod-settings.mod-window-visible {
.plugin-description p::selection {
background: #4f2157
}

#pedalboard-info .js-save.unmodified-changes {
background-color: #883996;
}
33 changes: 20 additions & 13 deletions html/js/desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Desktop(elements) {
data: JSON.stringify(addressing),
success: function (resp) {
if (resp) {
self.pedalboardModified = true
self.setPedalboardAsModified(true)
callback(true)
} else {
new Bug("Couldn't address parameter, not allowed")
Expand Down Expand Up @@ -467,6 +467,15 @@ function Desktop(elements) {
})
}

this.setPedalboardAsModified = function (modified) {
this.pedalboardModified = modified
if (modified) {
elements.saveButton.addClass('unmodified-changes')
} else {
elements.saveButton.removeClass('unmodified-changes')
}
}

elements.devicesIcon.statusTooltip()
this.ccDeviceManager = new ControlChainDeviceManager({
devicesIcon: elements.devicesIcon,
Expand Down Expand Up @@ -540,7 +549,7 @@ function Desktop(elements) {
var source = syncMode === "link" ? "Ableton Link" : "MIDI"
new Notification('info', 'BPM addressing removed, incompatible with ' + source + ' sync mode', 8000)
}
self.pedalboardModified = true
self.setPedalboardAsModified(true)
},
setSyncMode: function(syncMode, callback) {
$.ajax({
Expand Down Expand Up @@ -583,7 +592,7 @@ function Desktop(elements) {
var source = syncMode === "link" ? "Ableton Link" : "MIDI"
new Notification('info', 'BPM addressing removed, incompatible with ' + source + ' sync mode', 8000)
}
self.pedalboardModified = true
self.setPedalboardAsModified(true)
callback(true)
} else {
new Bug("Couldn't address parameter")
Expand Down Expand Up @@ -855,7 +864,7 @@ function Desktop(elements) {

transfer.reportFinished = function () {
self.pedalboardEmpty = false
self.pedalboardModified = true
self.setPedalboardAsModified(true)
}

transfer.reportError = function (error) {
Expand Down Expand Up @@ -987,7 +996,6 @@ function Desktop(elements) {
url: '/snapshot/save',
method: 'POST',
success: function () {
self.pedalboardModified = true
new Notification('info', 'Pedalboard snapshot saved', 2000)
},
error: function () {
Expand Down Expand Up @@ -1015,7 +1023,6 @@ function Desktop(elements) {
}
self.pedalboardPresetId = resp.id
self.pedalboardPresetName = resp.title
self.pedalboardModified = true
self.titleBox.text((self.title || 'Untitled') + " - " + resp.title)
new Notification('info', 'Pedalboard snapshot saved', 2000)
},
Expand Down Expand Up @@ -1456,13 +1463,13 @@ Desktop.prototype.makePedalboard = function (el, effectBox) {
self.title = ''
self.pedalboardBundle = null
self.pedalboardEmpty = true
self.pedalboardModified = false
self.pedalboardPresetId = 0
self.pedalboardPresetName = ''
self.pedalboardDemoPluginsNotified = false
self.titleBox.text('Untitled')
self.titleBox.addClass("blend")
self.transportControls.resetControlsEnabled()
self.setPedalboardAsModified(false)

callback(true)
},
Expand All @@ -1488,7 +1495,7 @@ Desktop.prototype.makePedalboard = function (el, effectBox) {
},

pluginParameterChange: function (port, value) {
self.pedalboardModified = true
self.setPedalboardAsModified(true)
ws.send(sprintf("param_set %s %f", port, value))
},

Expand All @@ -1497,12 +1504,12 @@ Desktop.prototype.makePedalboard = function (el, effectBox) {
},

pluginPatchSet: function (instance, uri, valuetype, value) {
self.pedalboardModified = true
self.setPedalboardAsModified(true)
ws.send(sprintf("patch_set %s %s %s %s", instance, uri, valuetype, value))
},

pluginMove: function (instance, x, y) {
self.pedalboardModified = true
self.setPedalboardAsModified(true)
ws.send(sprintf("plugin_pos %s %f %f", instance, x, y))
},

Expand Down Expand Up @@ -1582,7 +1589,7 @@ Desktop.prototype.makePedalboard = function (el, effectBox) {
// Bind events
el.bind('modified', function () {
self.pedalboardEmpty = false
self.pedalboardModified = true
self.setPedalboardAsModified(true)
})
/*
el.bind('dragStart', function () {
Expand Down Expand Up @@ -1837,8 +1844,8 @@ Desktop.prototype.loadPedalboard = function (bundlepath, callback) {
self.title = resp.name
self.pedalboardBundle = bundlepath
self.pedalboardEmpty = false
self.pedalboardModified = false
self.pedalboardDemoPluginsNotified = false
self.setPedalboardAsModified(false)
self.titleBox.text(resp.name);
self.titleBox.removeClass("blend");

Expand Down Expand Up @@ -1876,7 +1883,7 @@ Desktop.prototype.saveCurrentPedalboard = function (asNew, callback) {
self.title = title
self.pedalboardBundle = errorOrPath
self.pedalboardEmpty = false
self.pedalboardModified = false
self.setPedalboardAsModified(false)
self.titleBox.text(title + " - " + self.pedalboardPresetName)

if (self.previousPedalboardList != null) {
Expand Down
2 changes: 1 addition & 1 deletion html/js/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ $('document').ready(function() {
success: function (resp) {
desktop.pedalboard.pedalboard('scheduleAdapt', true)
desktop.pedalboardEmpty = empty && !modified
desktop.pedalboardModified = modified
desktop.pedalboardPresetId = snapshotId
desktop.pedalboardPresetName = resp.name
desktop.setPedalboardAsModified(modified)

if (resp.ok) {
desktop.titleBox.text((desktop.title || 'Untitled') + " - " + resp.name)
Expand Down
2 changes: 1 addition & 1 deletion html/js/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function SnapshotsManager(options) {
options.pedalPresetsWindow.find('.js-assign-all').addClass('disabled')
}

// Replace options value and text so we can a sequential list 0, 1, 2, etc.
// Replace options value and text so we get a sequential list 1, 2, 3, etc.
var i = 0
options.pedalPresetsList.children().each(function(option) {
var optionHtml = $(this).html()
Expand Down
4 changes: 4 additions & 0 deletions mod/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,10 @@ def snapshot_load(self, idx, from_hmi, abort_catcher, callback):
# callback must be last action
callback(True)

def save_snapshots_to_disk(self):
if self.pedalboard_path:
self.save_state_snapshots(self.pedalboard_path)

@gen.coroutine
def page_load(self, idx, abort_catcher, callback):
if not self.addressings.addressing_pages:
Expand Down
14 changes: 13 additions & 1 deletion mod/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(self):
self.recordhandle = None
self.external_ui_timer = None

self.screenshot_needed = False
self.screenshot_generator = ScreenshotGenerator()
self.websockets = []

Expand Down Expand Up @@ -155,10 +156,12 @@ def hmi_reinit_cb(self):

# Add a new plugin, starts enabled (ie, not bypassed)
def web_add(self, instance, uri, x, y, callback):
self.screenshot_needed = True
self.host.add_plugin(instance, uri, x, y, callback)

# Remove a plugin
def web_remove(self, instance, callback):
self.screenshot_needed = True
self.host.remove_plugin(instance, callback)

# Address a plugin parameter
Expand All @@ -181,10 +184,12 @@ def web_set_sync_mode(self, mode, callback):

# Connect 2 ports
def web_connect(self, port_from, port_to, callback):
self.screenshot_needed = True
self.host.connect(port_from, port_to, callback)

# Disconnect 2 ports
def web_disconnect(self, port_from, port_to, callback):
self.screenshot_needed = True
self.host.disconnect(port_from, port_to, callback)

# Save the current pedalboard
Expand All @@ -196,7 +201,10 @@ def web_save_pedalboard(self, title, asNew, callback):
if self.hmi.initialized and self.host.descriptor.get('hmi_set_pb_name', False):
self.hmi_set_pb_name(newTitle or title)

self.screenshot_generator.schedule_screenshot(bundlepath)
if bundlepath and self.screenshot_needed:
self.screenshot_needed = False
self.screenshot_generator.schedule_screenshot(bundlepath)

return bundlepath, newTitle

# Get list of Hardware MIDI devices
Expand Down Expand Up @@ -334,11 +342,13 @@ def ws_patch_set(self, instance, uri, valuetype, valuedata, ws):

# Set a plugin block position within the canvas
def ws_plugin_position(self, instance, x, y, ws):
self.screenshot_needed = True
self.host.set_position(instance, x, y)
self.msg_callback_broadcast("plugin_pos %s %d %d" % (instance, x, y), ws)

# set the size of the pedalboard (in 1:1 view, aka "full zoom")
def ws_pedalboard_size(self, width, height):
self.screenshot_needed = True
self.host.set_pedalboard_size(width, height)

def ws_show_external_ui(self, instance):
Expand Down Expand Up @@ -412,6 +422,7 @@ def msg_callback_broadcast(self, msg, ws2):
ws.write_message(msg)

def load_pedalboard(self, bundlepath, isDefault):
self.screenshot_needed = False
self.host.send_notmodified("feature_enable processing 0")
title = self.host.load(bundlepath, isDefault)
self.host.send_notmodified("feature_enable processing 1")
Expand All @@ -429,6 +440,7 @@ def load_pedalboard(self, bundlepath, isDefault):

def reset(self, callback):
logging.debug("SESSION RESET")
self.screenshot_needed = False
self.host.send_notmodified("feature_enable processing 0")

def host_callback(resp):
Expand Down
4 changes: 4 additions & 0 deletions mod/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,7 @@ def post(self, mode):
class SnapshotSave(JsonRequestHandler):
def post(self):
ok = SESSION.host.snapshot_save()
SESSION.host.save_snapshots_to_disk()
self.write(ok)

class SnapshotSaveAs(JsonRequestHandler):
Expand All @@ -1611,6 +1612,7 @@ def get(self):

yield gen.Task(SESSION.host.hmi_report_ss_name_if_current, idx)

SESSION.host.save_snapshots_to_disk()
self.write({
'ok': idx is not None,
'id': idx,
Expand All @@ -1630,6 +1632,7 @@ def get(self):

yield gen.Task(SESSION.host.hmi_report_ss_name_if_current, idx)

SESSION.host.save_snapshots_to_disk()
self.write({
'ok': ok,
'title': title,
Expand All @@ -1639,6 +1642,7 @@ class SnapshotRemove(JsonRequestHandler):
def get(self):
idx = int(self.get_argument('id'))
ok = SESSION.host.snapshot_remove(idx)
SESSION.host.save_snapshots_to_disk()
self.write(ok)

class SnapshotList(JsonRequestHandler):
Expand Down

0 comments on commit a4418dc

Please sign in to comment.