Skip to content

Commit

Permalink
Glue: If unselected items are between selected items, also glue those
Browse files Browse the repository at this point in the history
  • Loading branch information
L3337 committed Jul 10, 2023
1 parent 5aa0e6e commit 33b4324
Showing 1 changed file with 48 additions and 32 deletions.
80 changes: 48 additions & 32 deletions src/sgui/daw/sequencer/context_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sgui.daw.lib import item as item_lib
from sglib.lib import util
from sglib.lib.translate import _
from sglib.log import LOG

import copy
import re
Expand Down Expand Up @@ -453,40 +454,55 @@ def glue_selected():
]
for f_i in range(TRACK_COUNT_ALL):
f_track_items = [x for x in f_selected if x.track_num == f_i]
if len(f_track_items) > 1:
f_did_something = True
f_track_items.sort()
f_new_ref = f_track_items[0].clone()
f_items_dict = constants.DAW_PROJECT.get_items_dict()
f_old_name = f_items_dict.get_name_by_uid(f_new_ref.item_uid)
f_new_name = constants.DAW_PROJECT.get_next_default_item_name(
f_old_name,
f_items_dict,
)
f_new_uid = constants.DAW_PROJECT.create_empty_item(f_new_name)
f_new_item = constants.DAW_PROJECT.get_item_by_uid(f_new_uid)
if len(f_track_items) <= 1:
continue
f_did_something = True
f_track_items.sort()
# Include items between the start and end that were not selected
start = f_track_items[0].start_beat
end = f_track_items[-1].start_beat
f_track_items.clear()
for item in shared.CURRENT_SEQUENCE.items:
if (
item.track_num == f_i
and
item.start_beat >= start
and
item.start_beat <= end
):
f_track_items.append(item)
f_track_items.sort()
f_new_ref = f_track_items[0].clone()
f_items_dict = constants.DAW_PROJECT.get_items_dict()
f_old_name = f_items_dict.get_name_by_uid(f_new_ref.item_uid)
f_new_name = constants.DAW_PROJECT.get_next_default_item_name(
f_old_name,
f_items_dict,
)
f_new_uid = constants.DAW_PROJECT.create_empty_item(f_new_name)
f_new_item = constants.DAW_PROJECT.get_item_by_uid(f_new_uid)
f_tempo = shared.CURRENT_SEQUENCE.get_tempo_at_pos(
f_new_ref.start_beat,
)
f_last_ref = f_track_items[-1]
f_new_ref.item_uid = f_new_uid
f_new_ref.length_beats = (
f_last_ref.start_beat - f_new_ref.start_beat
) + f_last_ref.length_beats
shared.CURRENT_SEQUENCE.add_item_ref_by_uid(f_new_ref)
f_first = True
for f_ref in f_track_items:
f_tempo = shared.CURRENT_SEQUENCE.get_tempo_at_pos(
f_new_ref.start_beat,
f_ref.start_beat,
)
f_last_ref = f_track_items[-1]
f_new_ref.item_uid = f_new_uid
f_new_ref.length_beats = (
f_last_ref.start_beat - f_new_ref.start_beat
) + f_last_ref.length_beats
shared.CURRENT_SEQUENCE.add_item_ref_by_uid(f_new_ref)
f_first = True
for f_ref in f_track_items:
f_tempo = shared.CURRENT_SEQUENCE.get_tempo_at_pos(
f_ref.start_beat,
)
f_item = constants.DAW_PROJECT.get_item_by_uid(f_ref.item_uid)
f_new_item.extend(f_new_ref, f_ref, f_item, f_tempo)
if not f_first:
shared.CURRENT_SEQUENCE.remove_item_ref(f_ref)
else:
f_first = False
#util.print_sorted_dict(locals())
item_lib.save_item(f_new_name, f_new_item)
f_item = constants.DAW_PROJECT.get_item_by_uid(f_ref.item_uid)
f_new_item.extend(f_new_ref, f_ref, f_item, f_tempo)
if not f_first:
shared.CURRENT_SEQUENCE.remove_item_ref(f_ref)
else:
f_first = False
#util.print_sorted_dict(locals())
item_lib.save_item(f_new_name, f_new_item)
if f_did_something:
constants.DAW_PROJECT.save_sequence(shared.CURRENT_SEQUENCE)
constants.DAW_PROJECT.commit(_("Glue sequencer items"))
Expand Down

0 comments on commit 33b4324

Please sign in to comment.