Skip to content

Commit

Permalink
Merge branch 'vangelis' into feature/export_chain
Browse files Browse the repository at this point in the history
  • Loading branch information
riban committed Nov 7, 2024
2 parents e6caa74 + d4c55fd commit b992ad4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
8 changes: 8 additions & 0 deletions zyngine/zynthian_chain_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1578,19 +1578,27 @@ def get_next_free_zmop_index(self):
def get_synth_processor(self, midi_chan):
"""Get a synth processor on MIDI channel
If several synth chains in the same MIDI channel, take the first one.
if not synth processors, try other processor types.
chan : MIDI channel
Returns : Processor or None on failure
"""
# Try to find a Synth processor in the specified MIDI channel ...
for chain_id in self.midi_chan_2_chain_ids[midi_chan]:
processors = self.get_processors(chain_id, "MIDI Synth")
if len(processors) > 0:
return processors[0]
# If not synth processors, try other processor types...
for chain_id in self.midi_chan_2_chain_ids[midi_chan]:
processors = self.get_processors(chain_id)
if len(processors) > 0:
return processors[0]
return None

def get_synth_preset_name(self, midi_chan):
"""Get the preset name for a synth on MIDI channel
If several synth chains in the same MIDI channel, take the first one.
if not synth processors, try other processor types.
chan : MIDI channel
Returns : Preset name or None on failure
Expand Down
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 @@ -349,7 +352,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 @@ -359,7 +363,8 @@ 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)

Expand All @@ -369,7 +374,8 @@ def merge_snapshot(self, fpath):
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
8 changes: 4 additions & 4 deletions zyngui/zynthian_gui_zynpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ def _set_grid_size(self, value):

# Function to name selected sequence
def rename_sequence(self, params=None):
self.zyngui.show_keyboard(self.do_rename_sequence, self.zynseq.get_sequence_name(
self.bank, self.selected_pad), 16)
current_name = self.zynseq.get_sequence_name(self.bank, self.selected_pad)
self.zyngui.show_keyboard(self.do_rename_sequence, current_name, 16)

# Function to rename selected sequence
def do_rename_sequence(self, name):
self.zynseq.set_sequence_name(self.bank, self.selected_pad, name)
self.refresh_pad(self.selected_pad)

def update_layout(self):
super().update_layout()
Expand Down Expand Up @@ -328,7 +329,7 @@ def refresh_pad(self, pad, mode=None, state=None, group=None):
midi_chan = self.zynseq.libseq.getChannel(self.bank, pad, 0)
title = self.zynseq.get_sequence_name(self.bank, pad)
try:
str(int(title)) # Test for default (integer index)
int(title) # Test for default (integer index)
title = self.chain_manager.get_synth_preset_name(midi_chan)
except:
pass
Expand Down Expand Up @@ -554,7 +555,6 @@ def send_controller_value(self, zctrl):
self.zynseq.libseq.setBeatsPerBar(zctrl.value)
elif zctrl.symbol == 'playmode':
self.set_play_mode(zctrl.value)
# self.refresh_pad(self.selected_pad, force=True) #TODO Is this required?
elif zctrl.symbol == 'midi_chan':
self.zynseq.set_midi_channel(
self.bank, self.selected_pad, 0, zctrl.value)
Expand Down

0 comments on commit b992ad4

Please sign in to comment.