mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
detect humbucking or split mode
This commit is contained in:
@@ -24,9 +24,12 @@ package org.diylc.netlist;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class Tree {
|
||||
|
||||
private List<Tree> children;
|
||||
@@ -193,6 +196,72 @@ public class Tree {
|
||||
}
|
||||
}
|
||||
|
||||
public Set<IDIYComponent<?>> extractComponents(Set<String> types) {
|
||||
Set<IDIYComponent<?>> res = new HashSet<IDIYComponent<?>>();
|
||||
if (leaf != null && types.contains(leaf.getComponent().getClass().getCanonicalName())) {
|
||||
res.add(leaf.getComponent());
|
||||
} else if (children != null) {
|
||||
for (Tree t : children) {
|
||||
Set<IDIYComponent<?>> childRes = t.extractComponents(types);
|
||||
if (childRes != null)
|
||||
res.addAll(childRes);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public Tree locate(TreeLeaf l, boolean forceDirection) {
|
||||
if (leaf != null && leaf.equals(l, forceDirection))
|
||||
return this;
|
||||
if (children != null) {
|
||||
for (Tree t : children) {
|
||||
Tree childL = t.locate(l, forceDirection);
|
||||
if (childL != null) {
|
||||
// if (t.getLeaf() != null)
|
||||
// return this;
|
||||
return childL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Tree findCommonParent(Tree t1, Tree t2) {
|
||||
if (children == null)
|
||||
return null;
|
||||
|
||||
Tree p1 = null;
|
||||
Tree p2 = null;
|
||||
for (Tree c : children) {
|
||||
if (c.contains(t1))
|
||||
p1 = c;
|
||||
if (c.contains(t2))
|
||||
p2 = c;
|
||||
}
|
||||
|
||||
if (p1 == null || p2 == null)
|
||||
return null;
|
||||
|
||||
if (p1 != p2)
|
||||
return this;
|
||||
|
||||
return p1.findCommonParent(t1, t2);
|
||||
}
|
||||
|
||||
public boolean contains(Tree t) {
|
||||
if (this == t)
|
||||
return true;
|
||||
|
||||
if (children == null)
|
||||
return false;
|
||||
if (children.contains(t))
|
||||
return true;
|
||||
for (Tree c : children)
|
||||
if (c.contains(t))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface ITreeWalker {
|
||||
|
||||
void visit(Tree t);
|
||||
|
||||
@@ -89,6 +89,15 @@ public class TreeLeaf implements ITree {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean equals(TreeLeaf other, boolean forceDirection) {
|
||||
if (component == null) {
|
||||
if (other.component != null)
|
||||
return false;
|
||||
} else if (!component.equals(other.component))
|
||||
return false;
|
||||
return (pointIndex1 == other.pointIndex1 && pointIndex2 == other.pointIndex2) || (!forceDirection && (pointIndex1 == other.pointIndex2 && pointIndex2 == other.pointIndex1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
Binary file not shown.
@@ -127,6 +127,8 @@ public abstract class AbstractGuitarPickup extends AbstractTransparentComponent<
|
||||
|
||||
protected abstract Shape[] getBody();
|
||||
|
||||
public abstract boolean isHumbucker();
|
||||
|
||||
protected int getMainLabelYOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
@@ -132,4 +132,8 @@ public abstract class AbstractSingleOrHumbuckerPickup extends AbstractGuitarPick
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isHumbucker() {
|
||||
return getPolarity() == Polarity.Humbucking;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,6 +371,11 @@ public class HumbuckerPickup extends AbstractGuitarPickup {
|
||||
protected int getMainLabelYOffset() {
|
||||
return (int) (getType().getWidth().convertToPixels() / 2 - 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHumbucker() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
|
||||
@@ -29,12 +29,14 @@ import java.util.Set;
|
||||
import org.diylc.common.INetlistAnalyzer;
|
||||
import org.diylc.components.electromechanical.ClosedJack1_4;
|
||||
import org.diylc.components.electromechanical.OpenJack1_4;
|
||||
import org.diylc.components.guitar.AbstractGuitarPickup;
|
||||
import org.diylc.components.guitar.HumbuckerPickup;
|
||||
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.PotentiometerPanel;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.netlist.Tree.ITreeWalker;
|
||||
|
||||
public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
||||
@@ -111,6 +113,25 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
negativeCount++;
|
||||
}
|
||||
});
|
||||
|
||||
Set<IDIYComponent<?>> pickups = tree.extractComponents(PICKUP_TYPES);
|
||||
for (IDIYComponent<?> c : pickups) {
|
||||
if (c instanceof AbstractGuitarPickup) {
|
||||
AbstractGuitarPickup pickup = (AbstractGuitarPickup)c;
|
||||
if (((AbstractGuitarPickup) c).isHumbucker()) {
|
||||
TreeLeaf nLeaf = new TreeLeaf(pickup, 0, 1);
|
||||
TreeLeaf sLeaf = new TreeLeaf(pickup, 2, 3);
|
||||
Tree nTree = tree.locate(nLeaf, false);
|
||||
Tree sTree = tree.locate(sLeaf, false);
|
||||
Tree parent = tree.findCommonParent(nTree, sTree);
|
||||
if (nTree != null && sTree != null && parent != null) {
|
||||
notes.add(pickup.getName() + " pickup engaged in humbucking mode with coils wired in " + parent.getConnectionType().name().toLowerCase());
|
||||
} else if ((nTree == null && sTree != null) || (nTree != null && sTree == null)) {
|
||||
notes.add(pickup.getName() + " pickup engaged in coil-split mode");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean humCancelling = noiseCount == 0;
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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</description>
|
||||
<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>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
|
||||
Reference in New Issue
Block a user