Improved gain curve editing
This commit is contained in:
@@ -398,15 +398,15 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
||||
}
|
||||
});
|
||||
|
||||
sampleWaveform.addMouseWheelListener(new MouseWheelListener() {
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
if (selectedSentence == null) return;
|
||||
if (selectedSentence.isLocked()) return;
|
||||
int val = ((int)gainPercent.getValue()) - e.getWheelRotation();
|
||||
if (val < 1) val = 1;
|
||||
gainPercent.setValue(val);
|
||||
}
|
||||
});
|
||||
// sampleWaveform.addMouseWheelListener(new MouseWheelListener() {
|
||||
// public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
// if (selectedSentence == null) return;
|
||||
// if (selectedSentence.isLocked()) return;
|
||||
// int val = ((int)gainPercent.getValue()) - e.getWheelRotation();
|
||||
// if (val < 1) val = 1;
|
||||
// gainPercent.setValue(val);
|
||||
// }
|
||||
// });
|
||||
|
||||
sampleControl.add(sampleWaveform, BorderLayout.CENTER);
|
||||
|
||||
@@ -3473,6 +3473,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
||||
try {
|
||||
b.save();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(AudiobookRecorder.this, "There was an error saving the book: " + e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1686,14 +1686,16 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
||||
sentenceNode.appendChild(Book.makeTextNode(doc, "peak", getPeak()));
|
||||
sentenceNode.appendChild(Book.makeTextNode(doc, "detected", beenDetected()));
|
||||
Element gp = doc.createElement("gainpoints");
|
||||
for (Integer loc : gainPoints.keySet()) {
|
||||
Double g = gainPoints.get(loc);
|
||||
Element p = doc.createElement("gainpoint");
|
||||
p.setAttribute("location", String.format("%d", loc));
|
||||
p.setAttribute("gain", String.format("%.3g", g));
|
||||
gp.appendChild(p);
|
||||
if (gainPoints != null) {
|
||||
for (Integer loc : gainPoints.keySet()) {
|
||||
Double g = gainPoints.get(loc);
|
||||
Element p = doc.createElement("gainpoint");
|
||||
p.setAttribute("location", String.format("%d", loc));
|
||||
p.setAttribute("gain", String.format("%.3g", g));
|
||||
gp.appendChild(p);
|
||||
}
|
||||
sentenceNode.appendChild(gp);
|
||||
}
|
||||
sentenceNode.appendChild(gp);
|
||||
return sentenceNode;
|
||||
}
|
||||
|
||||
@@ -1835,10 +1837,17 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
||||
}
|
||||
|
||||
public TreeMap<Integer, Double> getGainPoints() {
|
||||
Debug.trace();
|
||||
if (gainPoints == null) {
|
||||
gainPoints = new TreeMap<Integer, Double>();
|
||||
}
|
||||
return gainPoints;
|
||||
}
|
||||
|
||||
public void addGainPoint(Integer loc, Double g) {
|
||||
if (gainPoints == null) {
|
||||
gainPoints = new TreeMap<Integer, Double>();
|
||||
}
|
||||
gainPoints.put(loc, g);
|
||||
CacheManager.removeFromCache(this);
|
||||
}
|
||||
@@ -1848,6 +1857,18 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
||||
CacheManager.removeFromCache(this);
|
||||
}
|
||||
|
||||
public void adjustGainPoint(Integer loc, Double adj) {
|
||||
if (gainPoints == null) {
|
||||
gainPoints = new TreeMap<Integer, Double>();
|
||||
return;
|
||||
}
|
||||
Double gp = gainPoints.get(loc);
|
||||
if (gp == null) return;
|
||||
gp += adj;
|
||||
gainPoints.put(loc, gp);
|
||||
CacheManager.removeFromCache(this);
|
||||
}
|
||||
|
||||
public double[] calculateGains() {
|
||||
double[] gains = new double[sampleSize];
|
||||
|
||||
|
||||
@@ -2,16 +2,18 @@ package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import javax.swing.JPanel;
|
||||
import java.util.TreeMap;
|
||||
import java.util.ArrayList;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
|
||||
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
||||
public class Waveform extends JPanel implements MouseListener, MouseMotionListener, MouseWheelListener {
|
||||
|
||||
Sentence sentence = null;
|
||||
|
||||
@@ -46,6 +48,7 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
super();
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
addMouseWheelListener(this);
|
||||
}
|
||||
|
||||
public void setSentence(Sentence s) {
|
||||
@@ -267,6 +270,37 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
dragging = 0;
|
||||
}
|
||||
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
if (sentence == null) return;
|
||||
if (sentence.isLocked()) return;
|
||||
|
||||
if (displayGainCurve) {
|
||||
int x = e.getX() * step + offset;
|
||||
int f = -1;
|
||||
int diff = Integer.MAX_VALUE;
|
||||
|
||||
TreeMap<Integer, Double> gc = sentence.getGainPoints();
|
||||
for (Integer loc : gc.keySet()) {
|
||||
int d = Math.abs(loc - x);
|
||||
if (d < diff) {
|
||||
diff = d;
|
||||
f = loc;
|
||||
}
|
||||
}
|
||||
|
||||
if (diff / step < 5) {
|
||||
sentence.adjustGainPoint(f, (0 - e.getWheelRotation()) / 100d);
|
||||
repaint();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int val = ((int)AudiobookRecorder.window.gainPercent.getValue()) - e.getWheelRotation();
|
||||
if (val < 1) val = 1;
|
||||
AudiobookRecorder.window.gainPercent.setValue(val);
|
||||
}
|
||||
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (displayGainCurve) {
|
||||
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
@@ -278,6 +312,17 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
int x = e.getX() * step + offset;
|
||||
double y = (double)(h - e.getY()) / (double)h * 2.0;
|
||||
|
||||
sentence.addGainPoint(x, y);
|
||||
repaint();
|
||||
} else if (e.getButton() == MouseEvent.BUTTON2) {
|
||||
Dimension size = getSize();
|
||||
|
||||
int w = size.width;
|
||||
int h = size.height;
|
||||
|
||||
int x = e.getX() * step + offset;
|
||||
double y = 1.0d;
|
||||
|
||||
sentence.addGainPoint(x, y);
|
||||
repaint();
|
||||
} else if (e.getButton() == MouseEvent.BUTTON3) {
|
||||
|
||||
Reference in New Issue
Block a user