Skip to content

Commit

Permalink
Rhythm improved for NextInVoice relation and implicit tuplets
Browse files Browse the repository at this point in the history
  • Loading branch information
hbitteur committed Dec 20, 2024
1 parent baf2904 commit 4042db2
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 189 deletions.
100 changes: 75 additions & 25 deletions app/src/main/java/org/audiveris/omr/sheet/rhythm/ChordsMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

Expand All @@ -43,13 +44,21 @@ public class ChordsMapper

private final List<AbstractChordInter> olds;

private final List<AbstractChordInter> remainingNews = new ArrayList<>();

private final List<AbstractChordInter> remainingOlds = new ArrayList<>();

private final List<AbstractChordInter> extinctExplicits;

private final VoiceDistance vd;

private final Set<ChordPair> blackList;

private final Set<ChordPair> whiteList;
private final Set<ChordPair> sameList;

private final Set<ChordPair> nextList;

private final Set<ChordPair> mappedNext;

//~ Constructors -------------------------------------------------------------------------------

Expand All @@ -61,21 +70,26 @@ public class ChordsMapper
* @param extinctExplicits extinct chords but with explicit SameVoiceRelation
* @param vd the VoiceDistance to use
* @param blackList known incompatibilities
* @param whiteList explicit compatibilities
* @param sameList explicit compatibilities
* @param nextList explicit connections
*/
public ChordsMapper (List<AbstractChordInter> news,
List<AbstractChordInter> olds,
List<AbstractChordInter> extinctExplicits,
VoiceDistance vd,
Set<ChordPair> blackList,
Set<ChordPair> whiteList)
Set<ChordPair> sameList,
Set<ChordPair> nextList)
{
this.news = news;
this.olds = olds;
this.extinctExplicits = extinctExplicits;
this.vd = vd;
this.blackList = blackList;
this.whiteList = whiteList;
this.sameList = sameList;
this.nextList = nextList;

mappedNext = processNext(news, olds, remainingNews, remainingOlds);
}

//~ Methods ------------------------------------------------------------------------------------
Expand All @@ -88,25 +102,63 @@ public ChordsMapper (List<AbstractChordInter> news,
public Mapping process ()
{
final Mapping output = new Mapping();
final InjectionSolver solver = new InjectionSolver(
news.size(),
olds.size() + news.size(),
new MyDistance());
final int[] links = solver.solve();

for (int i = 0; i < links.length; i++) {
final AbstractChordInter ch = news.get(i);
final int index = links[i];

if (index < olds.size()) {
AbstractChordInter act = olds.get(index);
output.pairs.add(new ChordPair(ch, act));

// Process the next in voice immediately
output.pairs.addAll(mappedNext);

if (!remainingNews.isEmpty()) {
final InjectionSolver solver = new InjectionSolver(
remainingNews.size(),
remainingOlds.size() + remainingNews.size(),
new MyDistance());
final int[] links = solver.solve();

for (int i = 0; i < links.length; i++) {
final AbstractChordInter ch = remainingNews.get(i);
final int index = links[i];

if (index < remainingOlds.size()) {
AbstractChordInter act = remainingOlds.get(index);
output.pairs.add(new ChordPair(ch, act));
}
}
}

return output;
}

//-------------//
// processNext //
//-------------//
/**
* Process the potential NextInVoice cases.
*
* @param news original rookies
* @param olds original actives
* @param remainingNews rookies still to link
* @param remainingOlds actives still to link
* @return the pre-mapped pairs
*/
private Set<ChordPair> processNext (List<AbstractChordInter> news,
List<AbstractChordInter> olds,
List<AbstractChordInter> remainingNews,
List<AbstractChordInter> remainingOlds)
{
final Set<ChordPair> mapped = new LinkedHashSet<>();
remainingNews.addAll(news);
remainingOlds.addAll(olds);

for (ChordPair pair : nextList) {
if (news.contains(pair.one) && olds.contains(pair.two)) {
mapped.add(pair);
remainingNews.remove(pair.one);
remainingOlds.remove(pair.two);
}
}

return mapped;
}

//~ Inner Classes ------------------------------------------------------------------------------

//---------//
Expand All @@ -117,7 +169,6 @@ public Mapping process ()
*/
public static class Mapping
{

/** Proposed mapping. */
public List<ChordPair> pairs = new ArrayList<>();

Expand Down Expand Up @@ -174,30 +225,29 @@ public AbstractChordInter ref (AbstractChordInter ch)
private class MyDistance
implements InjectionSolver.Distance
{

@Override
public int getDistance (int in,
int ip,
StringBuilder details)
{
// No link to an old chord
if (ip >= olds.size()) {
if (ip >= remainingOlds.size()) {
if (details != null) {
details.append("NO_LINK=").append(VoiceDistance.NO_LINK);
}

return VoiceDistance.NO_LINK;
}

AbstractChordInter newChord = news.get(in);
AbstractChordInter oldChord = olds.get(ip);
AbstractChordInter newChord = remainingNews.get(in);
AbstractChordInter oldChord = remainingOlds.get(ip);

// White list
for (ChordPair pair : whiteList) {
// Same voice
for (ChordPair pair : sameList) {
if (pair.two == oldChord) {
if (pair.one == newChord) {
if (details != null) {
details.append("WHITE");
details.append("SAME");
}

return 0;
Expand Down
Loading

0 comments on commit 4042db2

Please sign in to comment.