Fixes to effect and tree synchronisation

This commit is contained in:
2021-04-17 14:46:36 +01:00
parent 0dde64e5fc
commit 2e6ea5eecc
3 changed files with 38 additions and 12 deletions

View File

@@ -204,6 +204,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public Queue<Runnable>processQueue = 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<String, String> 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<String, EffectGroup> effs) {
Debug.trace();
int sel = effectChain.getSelectedIndex();
KVPair<String, String> 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<String, String> p = new KVPair<String, String>(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<String, String> 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<String, String> 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<String, String> p = effectChain.getItemAt(i);
if (p.getKey().equals(key)) {

View File

@@ -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<String,EffectGroup>();
loadEffectsFromFolder(new File(Options.get("path.storage"), "System"));
if (location != null) {
loadEffectsFromFolder(location);
}
loadEffectsFromFolder(getLocation());
}
public void loadEffectsFromFolder(File dir) {

View File

@@ -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;