From 2e6ea5eeccd558ebfa4583497b883921dc7bde67 Mon Sep 17 00:00:00 2001 From: Matt Jenkins Date: Sat, 17 Apr 2021 14:46:36 +0100 Subject: [PATCH] Fixes to effect and tree synchronisation --- .../audiobookrecorder/AudiobookRecorder.java | 43 +++++++++++++++---- src/uk/co/majenko/audiobookrecorder/Book.java | 6 +-- .../majenko/audiobookrecorder/Sentence.java | 1 + 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java index a65239a..c8fca70 100644 --- a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java +++ b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java @@ -204,6 +204,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener { public QueueprocessQueue = null; public QueueMonitor queueMonitor = null; + boolean effectsUpdating = false; // crude lock + void buildToolbar(Container ob) { Debug.trace(); toolBar = new MainToolBar(this); @@ -637,10 +639,12 @@ public class AudiobookRecorder extends JFrame implements DocumentListener { public void actionPerformed(ActionEvent e) { Debug.trace(); Debug.d(e); + if (effectsUpdating) return; if (selectedSentence != null) { int i = effectChain.getSelectedIndex(); KVPair p = effectChain.getItemAt(i); if (p == null) return; + System.err.println("I want to select effect " + p.getKey()); selectedSentence.setEffectChain(p.getKey()); updateWaveform(true); } @@ -823,8 +827,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener { locked.setSelected(s.isLocked()); attention.setSelected(s.getAttentionFlag()); - setEffectChain(s.getEffectChain()); - postSentenceGap.setEnabled(!s.isLocked()); gainPercent.setEnabled(!s.isLocked()); reprocessAudioFFT.setEnabled(!s.isLocked()); @@ -3109,8 +3111,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener { public void updateEffectChains(TreeMap effs) { Debug.trace(); - int sel = effectChain.getSelectedIndex(); - KVPair ent = effectChain.getItemAt(sel); + effectsUpdating = true; + System.err.println("Updating effect chains"); while (effectChain.getItemCount() > 0) { effectChain.removeItemAt(0); } @@ -3122,15 +3124,40 @@ public class AudiobookRecorder extends JFrame implements DocumentListener { KVPair p = new KVPair(k, e.toString()); effectChain.addItem(p); } - if (ent != null) { - setEffectChain(ent.getKey()); -// } else { -// setEffectChain(getBook().getDefaultEffect()); + if (selectedSentence != null) { + String key = selectedSentence.getEffectChain(); + for (int i = 0; i < effectChain.getItemCount(); i++) { + KVPair p = effectChain.getItemAt(i); + if (p.getKey().equals(key)) { + effectChain.setSelectedIndex(i); + effectsUpdating = false; + return; + } + } } + effectsUpdating = false; + } + + public void showSelectedEffectChain(String key) { + Debug.trace(); + effectsUpdating = true; + System.err.println("Looking for effect " + key + "..."); + for (int i = 0; i < effectChain.getItemCount(); i++) { + KVPair p = effectChain.getItemAt(i); + System.err.println(" Testing " + p.getKey() + "..."); + if (p.getKey().equals(key)) { + System.err.println(" Found it."); + effectChain.setSelectedIndex(i); + effectsUpdating = false; + return; + } + } + effectsUpdating = false; } public void setEffectChain(String key) { Debug.trace(); + System.err.println("Setting effect " + key); for (int i = 0; i < effectChain.getItemCount(); i++) { KVPair p = effectChain.getItemAt(i); if (p.getKey().equals(key)) { diff --git a/src/uk/co/majenko/audiobookrecorder/Book.java b/src/uk/co/majenko/audiobookrecorder/Book.java index d8e38b4..7123bc3 100644 --- a/src/uk/co/majenko/audiobookrecorder/Book.java +++ b/src/uk/co/majenko/audiobookrecorder/Book.java @@ -479,7 +479,7 @@ public class Book extends BookTreeNode { } AudiobookRecorder.window.setBookNotes(notes); AudiobookRecorder.window.noiseFloorLabel.setNoiseFloor(getNoiseFloorDB()); -// AudiobookRecorder.window.updateEffectChains(effects); + AudiobookRecorder.window.updateEffectChains(effects); TreeNode p = getParent(); if (p instanceof BookTreeNode) { BookTreeNode btn = (BookTreeNode)p; @@ -594,9 +594,7 @@ public class Book extends BookTreeNode { Debug.trace(); effects = new TreeMap(); loadEffectsFromFolder(new File(Options.get("path.storage"), "System")); - if (location != null) { - loadEffectsFromFolder(location); - } + loadEffectsFromFolder(getLocation()); } public void loadEffectsFromFolder(File dir) { diff --git a/src/uk/co/majenko/audiobookrecorder/Sentence.java b/src/uk/co/majenko/audiobookrecorder/Sentence.java index 7c4af50..2a96773 100644 --- a/src/uk/co/majenko/audiobookrecorder/Sentence.java +++ b/src/uk/co/majenko/audiobookrecorder/Sentence.java @@ -1763,6 +1763,7 @@ public class Sentence extends BookTreeNode implements Cacheable { Debug.trace(); AudiobookRecorder.setSelectedSentence(this); AudiobookRecorder.window.setSentenceNotes(notes); + AudiobookRecorder.window.showSelectedEffectChain(getEffectChain()); TreeNode p = getParent(); if (p instanceof BookTreeNode) { BookTreeNode btn = (BookTreeNode)p;