Skip to content

Commit 4c69fd7

Browse files
authored
Group all 'Separate Audio' context menu updates in a single undo/redo transaction (#5146)
1 parent e7254f3 commit 4c69fd7

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/classes/waveform.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
SAMPLES_PER_SECOND = 20
4242

4343

44-
def get_audio_data(files: dict):
44+
def get_audio_data(files: dict, transaction_id=None):
4545
"""Get a Clip object form libopenshot, and grab audio data
4646
For for the given files and clips, start threads to gather audio data.
4747
@@ -52,11 +52,11 @@ def get_audio_data(files: dict):
5252
clip_list = files[file_id]
5353

5454
log.info("Clip loaded, start thread")
55-
t = threading.Thread(target=get_waveform_thread, args=[file_id, clip_list], daemon=True)
55+
t = threading.Thread(target=get_waveform_thread, args=[file_id, clip_list, transaction_id], daemon=True)
5656
t.start()
5757

5858

59-
def get_waveform_thread(file_id, clip_list):
59+
def get_waveform_thread(file_id, clip_list, transaction_id):
6060
"""
6161
For the given file ID and clip IDs, update audio data.
6262
@@ -117,7 +117,10 @@ def getAudioData(file, channel=-1, tid=None):
117117
return
118118

119119
# Transaction id to group all deletes together
120-
tid = str(uuid.uuid4())
120+
if transaction_id:
121+
tid = transaction_id
122+
else:
123+
tid = str(uuid.uuid4())
121124

122125
# If the file doesn't have audio data, generate it.
123126
# A pending audio_data process will have audio_data == [-999]

src/windows/views/webview.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ def Transform_Triggered(self, action, clip_ids):
10461046
# Clear transform
10471047
self.window.TransformSignal.emit("")
10481048

1049-
def Show_Waveform_Triggered(self, clip_ids):
1049+
def Show_Waveform_Triggered(self, clip_ids, transaction_id=None):
10501050
"""Show a waveform for all selected clips"""
10511051

10521052
# Group clip IDs under each File ID
@@ -1062,7 +1062,7 @@ def Show_Waveform_Triggered(self, clip_ids):
10621062
files[file_id].append(clip.data.get("id"))
10631063

10641064
# Get audio data for all "selected" files/clips
1065-
get_audio_data(files)
1065+
get_audio_data(files, transaction_id=transaction_id)
10661066

10671067
def Hide_Waveform_Triggered(self, clip_ids):
10681068
"""Hide the waveform for the selected clip"""
@@ -1117,6 +1117,10 @@ def Split_Audio_Triggered(self, action, clip_ids):
11171117
# Get translation method
11181118
_ = get_app()._tr
11191119

1120+
# Group transactions
1121+
tid = self.get_uuid()
1122+
get_app().updates.transaction_id = tid
1123+
11201124
# Loop through each selected clip
11211125
for clip_id in clip_ids:
11221126

@@ -1179,7 +1183,7 @@ def Split_Audio_Triggered(self, action, clip_ids):
11791183

11801184
# Generate waveform for new clip
11811185
log.info("Generate waveform for split audio track clip id: %s" % clip.id)
1182-
self.Show_Waveform_Triggered([clip.id])
1186+
self.Show_Waveform_Triggered([clip.id], transaction_id=tid)
11831187

11841188
if action == MENU_SPLIT_AUDIO_MULTIPLE:
11851189
# Get # of channels on clip
@@ -1232,7 +1236,7 @@ def Split_Audio_Triggered(self, action, clip_ids):
12321236

12331237
# Generate waveform for new clip
12341238
log.info("Generate waveform for split audio track clip ids: %s" % str(separate_clip_ids))
1235-
self.Show_Waveform_Triggered(separate_clip_ids)
1239+
self.Show_Waveform_Triggered(separate_clip_ids, transaction_id=tid)
12361240

12371241
for clip_id in clip_ids:
12381242

@@ -1248,9 +1252,12 @@ def Split_Audio_Triggered(self, action, clip_ids):
12481252
clip.data["has_audio"] = {"Points": [p_object]}
12491253

12501254
# Save filter on original clip
1251-
self.update_clip_data(clip.data, only_basic_props=False, ignore_reader=True)
1255+
self.update_clip_data(clip.data, only_basic_props=False, ignore_reader=True, transaction_id=tid)
12521256
clip.save()
12531257

1258+
# Clear transaction
1259+
get_app().updates.transaction_id = None
1260+
12541261
def Layout_Triggered(self, action, clip_ids):
12551262
"""Callback for the layout context menus"""
12561263
log.debug(action)

0 commit comments

Comments
 (0)