detect volume and tone pots

This commit is contained in:
Branislav Stojkovic
2019-03-02 12:31:02 +01:00
parent b3497cdca8
commit bc0d759d39
8 changed files with 168 additions and 21 deletions
@@ -247,6 +247,9 @@ public class Tree {
if (p1 == null || p2 == null)
return null;
if (p1 == p2)
return p1;
if (p1 != p2)
return this;
@@ -272,6 +275,20 @@ public class Tree {
return findCommonParent(t.get(0), findCommonParent(remainder));
}
public Tree findParent(Tree t) {
if (children == null)
return null;
if (children.contains(t))
return this;
for (Tree c : children)
{
Tree p = c.findParent(t);
if (p != null)
return p;
}
return null;
}
public boolean contains(Tree t) {
if (this == t)
return true;
Binary file not shown.
@@ -237,7 +237,7 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
// Rotate if needed
if (theta != 0) {
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
AffineTransform rotation = AffineTransform.getRotateInstance(theta, controlPoints[0].x, controlPoints[0].y);
// Skip the last two because terminals are already rotated
for (int i = 0; i < body.length - 2; i++) {
Shape shape = body[i];
@@ -462,7 +462,7 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
case DP3T:
return (index1 == 1 && index2 == index1 + 2 * (position + 1)) || (index2 == 6 && index2 == index1 + 2 * (3 - position));
case DP4T:
return (index1 == 1 && index2 == index1 + 2 * (position + 1)) || (index2 == 8 && index2 == index1 + 2 * (3 - position));
return (index1 == 1 && index2 == index1 + 2 * (position + 1)) || (index2 == 8 && index2 == index1 + 2 * (4 - position));
case DP3T_5pos:
if (position % 2 == 0)
return (index1 == 1 && index2 == index1 + position + 2) || (index2 == 6 && index2 == index1 + 6 - position);
@@ -156,10 +156,10 @@ public class SingleCoilPickup extends AbstractSingleOrHumbuckerPickup {
: darkerOrLighter(color);
}
g2d.setColor(finalBorderColor);
if (body[0] != null)
g2d.draw(body[0]);
g2d.draw(body[3]);
g2d.setColor(finalBorderColor);
g2d.draw(body[0]);
if (body[3] != null)
g2d.draw(body[3]);
if (!outlineMode) {
g2d.setColor(getPoleColor());
@@ -203,7 +203,7 @@ public class SingleCoilPickup extends AbstractSingleOrHumbuckerPickup {
int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels());
int holeMargin = getClosestOdd(HOLE_MARGIN.convertToPixels());
int baseRadius = (int) BASE_RADIUS.convertToPixels();
int coilOffset = 0;
int coilOffset = 0;
if (getType() == SingleCoilType.Stratocaster) {
coilOffset = lipWidth / 2;
@@ -251,7 +251,7 @@ public class SingleCoilPickup extends AbstractSingleOrHumbuckerPickup {
base.subtract(new Area(new Ellipse2D.Double(x - teleLipLength / 2 - holeSize / 2, y, holeSize, holeSize)));
base.subtract(new Area(new Ellipse2D.Double(x + teleLipLength / 2 - holeSize / 2, y, holeSize, holeSize)));
base.subtract(new Area(new Ellipse2D.Double(x - holeSize / 2, y - teleHoleSpacing, holeSize, holeSize)));
body[4] = base;
}
@@ -290,15 +290,17 @@ public class SingleCoilPickup extends AbstractSingleOrHumbuckerPickup {
int railLength = (int) RAIL_LENGTH.convertToPixels();
poleArea.add(new Area(new RoundRectangle2D.Double(x - railLength / 2, y - coilOffset - width / 2 - railWidth
/ 2, railLength, railWidth, railWidth / 2, railWidth / 2)));
}
body[2] = poleArea;
body[0] =
new Area(new RoundRectangle2D.Double(x - coilLength / 2, y - coilOffset - width, coilLength, width, width,
}
body[0] =
new Area(new RoundRectangle2D.Double(x - coilLength / 2, y - coilOffset - width, coilLength, width, width,
width));
((Area) body[4]).subtract((Area) body[3]);
body[2] = poleArea;
if (body[3] == null) {
((Area)body[4]).subtract((Area) body[0]);
}
// Rotate if needed
if (orientation != Orientation.DEFAULT) {
@@ -37,7 +37,10 @@ import org.diylc.components.guitar.JazzBassPickup;
import org.diylc.components.guitar.P90Pickup;
import org.diylc.components.guitar.PBassPickup;
import org.diylc.components.guitar.SingleCoilPickup;
import org.diylc.components.passive.AxialFilmCapacitor;
import org.diylc.components.passive.PotentiometerPanel;
import org.diylc.components.passive.RadialCeramicDiskCapacitor;
import org.diylc.components.passive.RadialFilmCapacitor;
import org.diylc.core.IDIYComponent;
import org.diylc.netlist.Tree.ITreeWalker;
@@ -46,6 +49,7 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
private static Set<String> JACK_TYPES = new HashSet<String>();
private static Set<String> POT_TYPES = new HashSet<String>();
private static Set<String> PICKUP_TYPES = new HashSet<String>();
private static Set<String> CAP_TYPES = new HashSet<String>();
static {
JACK_TYPES.add(OpenJack1_4.class.getCanonicalName());
JACK_TYPES.add(ClosedJack1_4.class.getCanonicalName());
@@ -57,6 +61,10 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
PICKUP_TYPES.add(P90Pickup.class.getCanonicalName());
PICKUP_TYPES.add(JazzBassPickup.class.getCanonicalName());
PICKUP_TYPES.add(PBassPickup.class.getCanonicalName());
CAP_TYPES.add(RadialCeramicDiskCapacitor.class.getCanonicalName());
CAP_TYPES.add(RadialFilmCapacitor.class.getCanonicalName());
CAP_TYPES.add(AxialFilmCapacitor.class.getCanonicalName());
}
@Override
@@ -168,17 +176,137 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
boolean humCancelling = noiseCount == 0;
if (humCancelling)
notes.add("This position is hum-cancelling");
notes.add("This configuration is hum-cancelling");
else
notes.add("This position is NOT hum-cancelling");
notes.add("This configuration is NOT hum-cancelling");
if (positiveCount > 1 || negativeCount > 1) {
if (positiveCount > 1 || negativeCount > 1 || (positiveCount == 1 && negativeCount == 1)) {
boolean inPhase = (positiveCount == 0 && negativeCount > 0) || (positiveCount > 0 && negativeCount == 0);
if (inPhase)
notes.add("Pickup coils are wired in-phase");
notes.add("All pickup coils are wired in-phase");
else
notes.add("Pickup coils are wired OUT-of-phase");
notes.add("Some pickup coils are wired OUT-of-phase");
}
// locate volume and tone pots
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupReverseMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupReverseMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
Set<IDIYComponent<?>> pots = tree.extractComponents(POT_TYPES);
for (IDIYComponent<?> pot : pots) {
TreeLeaf leaf1 = new TreeLeaf(pot, 0, 1);
TreeLeaf leaf2 = new TreeLeaf(pot, 1, 2);
Tree tree1 = tree.locate(leaf1, false);
Tree tree2 = tree.locate(leaf2, false);
if ((tree1 == null && tree2 != null) || (tree1 != null && tree2 == null)) {
boolean tonePotReversed = tree1 != null;
Tree t = tree1 == null ? tree2 : tree1;
Tree p = tree.findParent(t);
if (p != null && p.getChildren().size() == 2) {
Set<IDIYComponent<?>> caps = p.extractComponents(CAP_TYPES);
if (caps != null && caps.size() == 1) {
for (Map.Entry<IDIYComponent<?>, Tree> r : pickupRoots.entrySet()) {
Tree toneParent = tree.findCommonParent(p, r.getValue());
if (toneParent != null && toneParent.getConnectionType() == TreeConnectionType.Parallel) {
if (tonePotReversed) {
List<IDIYComponent<?>> pickupList = tonePotPickupReverseMap.get(pot);
if (pickupList == null) {
pickupList = new ArrayList<IDIYComponent<?>>();
tonePotPickupReverseMap.put(pot, pickupList);
}
pickupList.add(r.getKey());
} else {
List<IDIYComponent<?>> pickupList = tonePotPickupMap.get(pot);
if (pickupList == null) {
pickupList = new ArrayList<IDIYComponent<?>>();
tonePotPickupMap.put(pot, pickupList);
}
pickupList.add(r.getKey());
}
}
}
}
}
}
// volume
if (tree1 == null || tree2 == null)
continue;
for (Map.Entry<IDIYComponent<?>, Tree> r : pickupRoots.entrySet()) {
Tree parent1 = tree.findCommonParent(tree1, r.getValue());
Tree parent2 = tree.findCommonParent(tree2, r.getValue());
if (parent1 != null && parent2 != null && parent1.getConnectionType() == TreeConnectionType.Series && parent2.getConnectionType() == TreeConnectionType.Parallel)
{
List<IDIYComponent<?>> pickupList = volPotPickupMap.get(pot);
if (pickupList == null) {
pickupList = new ArrayList<IDIYComponent<?>>();
volPotPickupMap.put(pot, pickupList);
}
pickupList.add(r.getKey());
} else if (parent1 != null && parent2 != null && parent1.getConnectionType() == TreeConnectionType.Parallel && parent2.getConnectionType() == TreeConnectionType.Series)
{
List<IDIYComponent<?>> pickupList = volPotPickupReverseMap.get(pot);
if (pickupList == null) {
pickupList = new ArrayList<IDIYComponent<?>>();
volPotPickupReverseMap.put(pot, pickupList);
}
pickupList.add(r.getKey());
}
}
}
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : volPotPickupMap.entrySet()) {
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
boolean first = true;
for (IDIYComponent<?> c : e.getValue()) {
if (!first)
sb.append(e.getValue().size() == 2 ? " and " : ", ");
first = false;
sb.append("'").append(c.getName()).append("'");
}
notes.add(sb.toString());
}
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : volPotPickupReverseMap.entrySet()) {
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
boolean first = true;
for (IDIYComponent<?> c : e.getValue()) {
if (!first)
sb.append(e.getValue().size() == 2 ? " and " : ", ");
first = false;
sb.append("'").append(c.getName()).append("'");
}
sb.append(", but is wired in REVERSE!");
notes.add(sb.toString());
}
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : tonePotPickupMap.entrySet()) {
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
boolean first = true;
for (IDIYComponent<?> c : e.getValue()) {
if (!first)
sb.append(e.getValue().size() == 2 ? " and " : ", ");
first = false;
sb.append("'").append(c.getName()).append("'");
}
notes.add(sb.toString());
}
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : tonePotPickupReverseMap.entrySet()) {
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
boolean first = true;
for (IDIYComponent<?> c : e.getValue()) {
if (!first)
sb.append(e.getValue().size() == 2 ? " and " : ", ");
first = false;
sb.append("'").append(c.getName()).append("'");
}
sb.append(", but is wired in REVERSE!");
notes.add(sb.toString());
}
}
return new Summary(netlist, notes, tree);
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -2528,7 +2528,7 @@
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>"Analyze Guitar Wiring" can figure out if wiring is hum-cancelling and in or out of phase for each position, can detect split-coil wiring and series/parallel humbucking mode</description>
<description>"Analyze Guitar Wiring" can figure out if wiring is hum-cancelling and in or out of phase for each position, split-coil wiring, series/parallel humbucking mode, volume and tone potentiometers</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>