Skip to content

Commit

Permalink
+ Avoid last snapshot to be "resetted" when loading a snapshot after …
Browse files Browse the repository at this point in the history
…deleting all.

+ Auto-select current snapshot in snapshot list.
  • Loading branch information
jofemodo committed Nov 7, 2024
1 parent b4ee76f commit d4c55fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions zyngui/zynthian_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,19 +1047,19 @@ def get_alt_mode(self):
return self.alt_mode

def clean_all(self):
if self.chain_manager.get_chain_count() > 0:
if self.chain_manager.get_chain_count() > 1:
self.state_manager.save_last_state_snapshot()
self.state_manager.clean_all()
self.show_screen_reset('main_menu')

def clean_chains(self):
if self.chain_manager.get_chain_count() > 0:
if self.chain_manager.get_chain_count() > 1:
self.state_manager.save_last_state_snapshot()
self.state_manager.clean_chains()
self.show_screen_reset('main_menu')

def clean_sequences(self):
if self.chain_manager.get_chain_count() > 0:
if self.chain_manager.get_chain_count() > 1:
self.state_manager.save_last_state_snapshot()
self.state_manager.clean_sequences()
self.show_screen_reset('zynpad')
Expand Down
28 changes: 17 additions & 11 deletions zyngui/zynthian_gui_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def __init__(self):
self.index_offset = 0
super().__init__('Bank', True)
self.sm = self.zyngui.state_manager
self.cm = self.zyngui.chain_manager

self.check_bankless_mode()

def is_not_empty_snapshot(self):
return self.cm.get_chain_count() > 1 or self.cm.get_processor_count() > 0

def get_snapshot_fpath(self, f):
if f in ["last_state.zss", "default.zss"]:
return join(self.sm.snapshot_dir, f)
Expand Down Expand Up @@ -176,30 +180,29 @@ def load_snapshot_list(self):
self.list_data.append((self.sm.snapshot_dir, i, ".."))
i += 1

if self.zyngui.chain_manager.get_chain_count() or self.zyngui.chain_manager.get_processor_count() > 0:
if self.is_not_empty_snapshot():
# TODO: Add better validation of populated state, e.g. sequences
self.list_data.append(("SAVE", i, "Save as new snapshot"))
if self.bankless_mode:
self.list_data.append(("NEW_BANK", i, "New Bank"))
i = i + 1
i += 1
self.list_data.append((None, None, "> Saved snapshots:"))
if isfile(self.sm.default_snapshot_fpath):
self.list_data.append(
(self.sm.default_snapshot_fpath, i, "Default"))
self.list_data.append((self.sm.default_snapshot_fpath, i, "Default"))
i += 1
if isfile(self.sm.last_state_snapshot_fpath):
self.list_data.append(
(self.sm.last_state_snapshot_fpath, i, "Last State"))
self.list_data.append((self.sm.last_state_snapshot_fpath, i, "Last State"))
i += 1

self.change_index_offset(i)

for fpath in sorted(glob(f"{self.sm.snapshot_dir}/{self.sm.snapshot_bank}/*.zss")):
if isfile(fpath):
title = basename(fpath)[:-4].replace(';',
'>', 1).replace(';', '/')
title = basename(fpath)[:-4].replace(';', '>', 1).replace(';', '/')
self.list_data.append((fpath, i, title))
i += 1
if fpath == self.sm.last_snapshot_fpath:
self.index = i + 1

def fill_list(self):
self.check_bankless_mode()
Expand Down Expand Up @@ -346,7 +349,8 @@ def options_cb(self, option, param):
"Do you really want to delete '%s'" % fname, self.delete_confirmed, fpath)

def load_snapshot(self, fpath):
self.sm.save_last_state_snapshot()
if self.is_not_empty_snapshot():
self.sm.save_last_state_snapshot()
state = self.sm.load_snapshot(fpath)
if state is None:
self.zyngui.clean_all()
Expand All @@ -356,12 +360,14 @@ def load_snapshot(self, fpath):
self.zyngui.show_screen('audio_mixer', self.zyngui.SCREEN_HMODE_RESET)

def load_snapshot_chains(self, fpath):
self.sm.save_last_state_snapshot()
if self.is_not_empty_snapshot():
self.sm.save_last_state_snapshot()
self.sm.load_snapshot(fpath, load_sequences=False)
self.zyngui.show_screen('audio_mixer', self.zyngui.SCREEN_HMODE_RESET)

def load_snapshot_sequences(self, fpath):
self.sm.save_last_state_snapshot()
if self.is_not_empty_snapshot():
self.sm.save_last_state_snapshot()
self.sm.load_snapshot(fpath, load_chains=False)
self.zyngui.show_screen('zynpad', hmode=self.zyngui.SCREEN_HMODE_RESET)

Expand Down

0 comments on commit d4c55fd

Please sign in to comment.