mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
"Analyze Guitar Wiring" can figure out if wiring is hum-cancelling and
in or out of phase for each position
This commit is contained in:
@@ -25,6 +25,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Tree {
|
||||
|
||||
@@ -158,6 +159,44 @@ public class Tree {
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
if (leaf != null)
|
||||
return new Tree(leaf);
|
||||
return new Tree(new ArrayList<Tree>(children), connectionType);
|
||||
List<Tree> newChildren = new ArrayList<Tree>();
|
||||
for (Tree t : children)
|
||||
newChildren.add((Tree) t.clone());
|
||||
return new Tree(newChildren, connectionType);
|
||||
}
|
||||
|
||||
public Tree filter(Set<String> types) {
|
||||
if (leaf != null) {
|
||||
if (types.contains(leaf.getComponent().getClass().getCanonicalName()))
|
||||
return new Tree(leaf);
|
||||
return null;
|
||||
}
|
||||
List<Tree> newChildren = new ArrayList<Tree>();
|
||||
for (Tree t : children) {
|
||||
Tree child = t.filter(types);
|
||||
if (child != null)
|
||||
newChildren.add(child);
|
||||
}
|
||||
if (newChildren.isEmpty())
|
||||
return null;
|
||||
return new Tree(newChildren, connectionType);
|
||||
}
|
||||
|
||||
public void walk(ITreeWalker walker) {
|
||||
if (leaf != null) {
|
||||
walker.visit(leaf);
|
||||
} else {
|
||||
for (Tree t : children) {
|
||||
walker.visit(t);
|
||||
t.walk(walker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface ITreeWalker {
|
||||
|
||||
void visit(Tree t);
|
||||
|
||||
void visit(TreeLeaf l);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -35,6 +35,7 @@ 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.netlist.Tree.ITreeWalker;
|
||||
|
||||
public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
||||
|
||||
@@ -72,13 +73,64 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
return summaries;
|
||||
}
|
||||
|
||||
private int positiveCount;
|
||||
private int negativeCount;
|
||||
private int noiseCount;
|
||||
|
||||
private Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
||||
List<String> notes = new ArrayList<String>();
|
||||
|
||||
Tree tree = constructTree(netlist);
|
||||
|
||||
Tree pickupTree = tree.filter(PICKUP_TYPES);
|
||||
|
||||
if (pickupTree == null || pickupTree.getChildren().isEmpty()) {
|
||||
notes.add("No pickups are detected in this switch configuration");
|
||||
} else {
|
||||
positiveCount = 0;
|
||||
negativeCount = 0;
|
||||
noiseCount = 0;
|
||||
pickupTree.walk(new ITreeWalker() {
|
||||
|
||||
@Override
|
||||
public void visit(Tree t) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TreeLeaf l) {
|
||||
if ((l.toString().toLowerCase().contains("north") && (l.toString().toLowerCase().contains("->"))) ||
|
||||
(l.toString().toLowerCase().contains("south") && (l.toString().toLowerCase().contains("<-"))))
|
||||
noiseCount++;
|
||||
if ((l.toString().toLowerCase().contains("north") && (l.toString().toLowerCase().contains("<-"))) ||
|
||||
(l.toString().toLowerCase().contains("south") && (l.toString().toLowerCase().contains("->"))))
|
||||
noiseCount--;
|
||||
|
||||
if (l.toString().toLowerCase().contains("->"))
|
||||
positiveCount++;
|
||||
if (l.toString().toLowerCase().contains("<-"))
|
||||
negativeCount++;
|
||||
}
|
||||
});
|
||||
|
||||
boolean humCancelling = noiseCount == 0;
|
||||
|
||||
if (humCancelling)
|
||||
notes.add("This position is hum-cancelling");
|
||||
else
|
||||
notes.add("This position is NOT hum-cancelling");
|
||||
|
||||
if (positiveCount > 1 || negativeCount > 1) {
|
||||
boolean inPhase = (positiveCount == 0 && negativeCount > 0) || (positiveCount > 0 && negativeCount == 0);
|
||||
if (inPhase)
|
||||
notes.add("The pickups are wired in-phase");
|
||||
else
|
||||
notes.add("This pickups are wired out-of-phase");
|
||||
}
|
||||
}
|
||||
|
||||
return new Summary(netlist, notes, tree);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Tree constructTree(Netlist netlist) throws TreeException {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1725,6 +1725,8 @@ public class ActionFactory {
|
||||
sb.append("<p style=\"font-family: " + new JLabel().getFont().getName() + "; font-size: 9px\"><b>Switch configuration: ").append(summary.getNetlist().getSwitchSetup()).append("</b><br><br>");
|
||||
|
||||
sb.append("Parallel/Series connectivity tree:<br><br>").append(summary.getTree().toHTML(0));
|
||||
if (!summary.getNotes().isEmpty())
|
||||
sb.append("<br><br>Notes:<br>");
|
||||
for (String v : summary.getNotes()) {
|
||||
sb.append(" ").append(v).append("<br>");
|
||||
}
|
||||
|
||||
@@ -2526,6 +2526,10 @@
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added 4-position Tele switch type to the "Lever Switch" component</description>
|
||||
</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>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Increase the range of zoom slider for images to 500%</description>
|
||||
|
||||
Reference in New Issue
Block a user