Skip to content

Commit

Permalink
Support for Metronome marks
Browse files Browse the repository at this point in the history
- New shapes to support beat units
- Handling of logical/physical shapes in the samples repository
- Addition of Leland as a music font
- Better update following the selection of music or text family
  • Loading branch information
hbitteur committed Nov 13, 2024
1 parent 988233a commit 8a3efe6
Show file tree
Hide file tree
Showing 104 changed files with 5,419 additions and 1,823 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ nbproject
*.mf
*.orig
build/*
app/bin/*
dist/*
config/run.properties
data/args
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ dependencies {
[group: 'javax.media', name: 'jai-core', version: '1.1.3'],
[group: 'net.imagej', name: 'ij', version: '1.53j'],
[group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.27'],
[group: 'org.audiveris', name: 'proxymusic', version: '4.0.2'],
[group: 'org.audiveris', name: 'proxymusic', version: '4.0.3'],
[group: 'org.jgrapht', name: 'jgrapht-core', version: '1.5.1'],
[group: 'org.jfree', name: 'jfreechart', version: '1.5.3'],
[group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13.2'],
Expand Down
1 change: 1 addition & 0 deletions app/config/user-actions.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<!-- <action domain="TOOL" section="20" class="org.audiveris.omr.ui.GuiActions" method="defineShapeColors" />-->
<!-- <action domain="DEBUG" section="50" class="org.audiveris.omr.Debug" method="injectChordNames"/>-->
<!-- <action domain="DEBUG" section="35" class="org.audiveris.omr.Debug" method="checkSources"/>
<action domain="DEBUG" section="40" class="org.audiveris.omr.Debug" method="checkTemplates"/>-->
Expand Down
11 changes: 5 additions & 6 deletions nb-configuration.xml → app/nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1">
<word>arg</word>
<word>arpeggiato</word>
<word>Audiveris</word>
<word>barline</word>
Expand Down
Binary file added app/res/Leland.otf
Binary file not shown.
Binary file modified app/res/basic-classifier.zip
Binary file not shown.
39 changes: 21 additions & 18 deletions app/src/main/java/org/audiveris/omr/classifier/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,32 @@ public class Sample

private static final Logger logger = LoggerFactory.getLogger(Sample.class);

/** For comparing Sample instances by shape. */
public static final Comparator<Sample> byShape = (Sample s1,
Sample s2) -> Integer.compare(
s1.getShape().ordinal(),
s2.getShape().ordinal());
/** For comparing Sample instances by (logical) shape. */
public static final Comparator<Sample> byShape = (s1,
s2) -> //
Integer.compare(s1.getShape().ordinal(), s2.getShape().ordinal());

/** For comparing Sample instances by physical shape. */
public static final Comparator<Sample> byPhysicalShape = (s1,
s2) -> //
Integer.compare(
s1.getShape().getPhysicalShape().ordinal(),
s2.getShape().getPhysicalShape().ordinal());

/** For comparing Sample instances by normalized width. */
public static final Comparator<Sample> byNormalizedWidth = (Sample s1,
Sample s2) -> Double.compare(
s1.getNormalizedWidth(),
s2.getNormalizedWidth());
public static final Comparator<Sample> byNormalizedWidth = (s1,
s2) -> //
Double.compare(s1.getNormalizedWidth(), s2.getNormalizedWidth());

/** For comparing Sample instances by normalized height. */
public static final Comparator<Sample> byNormalizedHeight = (Sample s1,
Sample s2) -> Double.compare(
s1.getNormalizedHeight(),
s2.getNormalizedHeight());
public static final Comparator<Sample> byNormalizedHeight = (s1,
s2) -> //
Double.compare(s1.getNormalizedHeight(), s2.getNormalizedHeight());

/** For comparing Sample instances by normalized weight. */
public static final Comparator<Sample> byNormalizedWeight = (Sample s1,
Sample s2) -> Double.compare(
s1.getNormalizedWeight(),
s2.getNormalizedWeight());
public static final Comparator<Sample> byNormalizedWeight = (s1,
s2) -> //
Double.compare(s1.getNormalizedWeight(), s2.getNormalizedWeight());

//~ Instance fields ----------------------------------------------------------------------------

Expand Down Expand Up @@ -340,7 +343,7 @@ public static Shape getRecordableShape (Shape shape)
return null;
}

Shape physicalShape = shape.getPhysicalShape();
final Shape physicalShape = shape.getPhysicalShape();

if (physicalShape.isTrainable() && (physicalShape != Shape.NOISE)) {
return physicalShape;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ public void addSample (Shape shape,
SampleSheet sampleSheet,
Double pitch)
{
shape = Sample.getRecordableShape(shape);
final Shape physicalShape = Sample.getRecordableShape(shape);

if (shape != null) {
if (physicalShape != null) {
final Sample sample = new Sample(glyph, interline, shape, pitch);
addSample(sample, sampleSheet);
}
Expand Down Expand Up @@ -480,8 +480,7 @@ public void checkAllSamples (Collection<Sample> conflictings,
Collections.sort(
allSamples,
(Sample s1,
Sample s2) ->
{
Sample s2) -> {
int comp = Integer.compare(s1.getWeight(), s2.getWeight());

if (comp != 0) {
Expand Down Expand Up @@ -518,7 +517,7 @@ public void checkAllSamples (Collection<Sample> conflictings,
}

if ((s.getInterline() == interline) && s.getRunTable().equals(runTable)) {
if (s.getShape() != sample.getShape()) {
if (s.getShape().getPhysicalShape() != sample.getShape().getPhysicalShape()) {
logger.warn(
"Conflicting shapes between {}/{} and {}/{}",
getSheetName(sample),
Expand Down Expand Up @@ -566,8 +565,7 @@ public void checkFontSamples ()
Collections.sort(
fontSamples,
(Sample s1,
Sample s2) ->
{
Sample s2) -> {
int comp = Integer.compare(s1.getWeight(), s2.getWeight());

if (comp != 0) {
Expand Down Expand Up @@ -605,7 +603,7 @@ public void checkFontSamples ()
}

if ((s.getInterline() == interline) && s.getRunTable().equals(runTable)) {
if (s.getShape() != sample.getShape()) {
if (s.getShape().getPhysicalShape() != sample.getShape().getPhysicalShape()) {
logger.warn(
"Conflicting shapes between {}/{} and {}/{}",
getSheetName(sample),
Expand Down Expand Up @@ -786,8 +784,7 @@ public SampleSheet findSampleSheet (String name,
}

root.getFileSystem().close();
} catch (IOException ignored) {
}
} catch (IOException ignored) {}
}

if (sampleSheet == null) {
Expand Down Expand Up @@ -1644,7 +1641,7 @@ public boolean removeListener (ChangeListener listener)
*/
public void removeSample (Sample sample)
{
SampleSheet sampleSheet = getSampleSheet(sample);
final SampleSheet sampleSheet = getSampleSheet(sample);

if (isSymbols(sampleSheet.getDescriptor().getName())) {
logger.info("A font-based symbol cannot be removed");
Expand Down Expand Up @@ -1753,7 +1750,7 @@ public void splitTrainAndTest (List<Sample> train,
// Flag redundant font-based samples as such
checkFontSamples();

// Gather samples by shape
// Gather samples by physical shape
EnumMap<Shape, List<Sample>> shapeSamples = new EnumMap<>(Shape.class);

for (Sample sample : getAllSamples()) {
Expand All @@ -1762,11 +1759,11 @@ public void splitTrainAndTest (List<Sample> train,
continue;
}

Shape shape = sample.getShape();
List<Sample> list = shapeSamples.get(shape);
Shape physicalShape = sample.getShape().getPhysicalShape();
List<Sample> list = shapeSamples.get(physicalShape);

if (list == null) {
shapeSamples.put(shape, list = new ArrayList<>());
shapeSamples.put(physicalShape, list = new ArrayList<>());
}

list.add(sample);
Expand Down
27 changes: 16 additions & 11 deletions app/src/main/java/org/audiveris/omr/classifier/SampleSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class SampleSheet
/** True if image is already on disk. */
private boolean imageSaved = true;

/** Samples gathered by shape. */
/** Samples gathered by logical shape. */
private final EnumMap<Shape, ArrayList<Sample>> shapeMap = new EnumMap<>(Shape.class);

/** Has this sheet been modified?. */
Expand Down Expand Up @@ -137,7 +137,8 @@ private SampleSheet (SampleList value,
this.descriptor = descriptor;

for (Sample sample : value.samples) {
Shape shape = sample.getShape();
final Shape shape = sample.getShape();

if (shape == null) {
logger.warn("Null shape sample:{} in sheet:{}", sample, descriptor.getName());
} else {
Expand Down Expand Up @@ -423,8 +424,8 @@ void privateAddSample (Sample sample)
*/
void privateRemoveSample (Sample sample)
{
Shape shape = sample.getShape();
ArrayList<Sample> list = shapeMap.get(shape);
final Shape shape = sample.getShape();
final ArrayList<Sample> list = shapeMap.get(shape);

if ((list == null) || !list.contains(sample)) {
logger.warn("{} not found in {}", sample, this);
Expand Down Expand Up @@ -650,13 +651,17 @@ private void afterUnmarshal (Unmarshaller um,

for (Sample sample : samples) {
final Shape shape = sample.getShape();
switch (shape) {
case FLAG_1_UP -> modified |= sample.renameShapeAs(Shape.FLAG_1_DOWN);
case FLAG_2_UP -> modified |= sample.renameShapeAs(Shape.FLAG_2_DOWN);
case FLAG_3_UP -> modified |= sample.renameShapeAs(Shape.FLAG_3_DOWN);
case FLAG_4_UP -> modified |= sample.renameShapeAs(Shape.FLAG_4_DOWN);
case FLAG_5_UP -> modified |= sample.renameShapeAs(Shape.FLAG_5_DOWN);
default -> {}
if (shape == null) {
logger.warn("Null shape for sample: {}", sample);
} else {
switch (shape) {
case FLAG_1_UP -> modified |= sample.renameShapeAs(Shape.FLAG_1_DOWN);
case FLAG_2_UP -> modified |= sample.renameShapeAs(Shape.FLAG_2_DOWN);
case FLAG_3_UP -> modified |= sample.renameShapeAs(Shape.FLAG_3_DOWN);
case FLAG_4_UP -> modified |= sample.renameShapeAs(Shape.FLAG_4_DOWN);
case FLAG_5_UP -> modified |= sample.renameShapeAs(Shape.FLAG_5_DOWN);
default -> {}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public class SampleBrowser
/** Panel for sheets selection. */
private SheetSelector sheetSelector;

/** Panel for shapes selection. */
/** Panel for (physical) shapes selection. */
private ShapeSelector shapeSelector;

//~ Constructors -------------------------------------------------------------------------------
Expand Down Expand Up @@ -459,19 +459,15 @@ private JFrame defineLayout (JFrame frame)
// boardsPane.addBoard(
// new SampleEvaluationBoard(sampleController, DeepClassifier.getInstance()));
//
JSplitPane centerPane = new JSplitPane(
VERTICAL_SPLIT,
sheetSelector,
boardsPane.getComponent());
JSplitPane centerPane =
new JSplitPane(VERTICAL_SPLIT, sheetSelector, boardsPane.getComponent());
centerPane.setBorder(null);
centerPane.setOneTouchExpandable(true);
centerPane.setName("centerPane");

// Right
JSplitPane rightPane = new JSplitPane(
VERTICAL_SPLIT,
sampleListing,
sampleContext.getComponent());
JSplitPane rightPane =
new JSplitPane(VERTICAL_SPLIT, sampleListing, sampleContext.getComponent());
rightPane.setBorder(null);
rightPane.setOneTouchExpandable(true);
rightPane.setName("rightPane");
Expand Down Expand Up @@ -537,15 +533,15 @@ public void displayAll (Collection<Sample> samples)
EnumSet<Shape> shapeSet = EnumSet.noneOf(Shape.class);

for (Sample sample : samples) {
shapeSet.add(sample.getShape());
shapeSet.add(sample.getShape().getPhysicalShape());
}

shapeSelector.populateWith(shapeSet);
shapeSelector.select(shapeSet);

// Populate samples
List<Sample> sorted = new ArrayList<>(samples);
Collections.sort(sorted, Sample.byShape); // Must be ordered by shape for listing
Collections.sort(sorted, Sample.byPhysicalShape); // Ordered by physical shape for listing
sampleListing.populateWith(sorted);

connectSelectors(true); // Re-enable standard triggers: sheets -> shapes -> samples
Expand Down Expand Up @@ -1028,8 +1024,7 @@ private static class SampleEvaluationBoard
@Override
protected void evaluate (Glyph glyph)
{
if (glyph instanceof Sample) {
final Sample sample = (Sample) glyph;
if (glyph instanceof Sample sample) {
selector.setEvals(
classifier.evaluate(
glyph,
Expand All @@ -1045,11 +1040,13 @@ protected void evaluate (Glyph glyph)
}
}

//----------//
// Selector //
//----------//
private abstract static class Selector<E>
extends TitledPanel
implements ChangeListener
{

// Buttons
protected final JButton selectAll = new JButton("Select All");

Expand Down Expand Up @@ -1243,7 +1240,7 @@ public Component getListCellRendererComponent (JList<? extends Shape> list,
// ShapeSelector //
//---------------//
/**
* Display a list of available shapes (within selected sheets) and let user make a
* Display a list of available physical shapes (within selected sheets) and let user make a
* selection.
*/
private class ShapeSelector
Expand Down Expand Up @@ -1282,8 +1279,8 @@ private class ShapePopup
{
super("ShapePopup");

ApplicationActionMap actionMap = OmrGui.getApplication().getContext().getActionMap(
SampleBrowser.this);
ApplicationActionMap actionMap =
OmrGui.getApplication().getContext().getActionMap(SampleBrowser.this);
add(new JMenuItem(actionMap.get("removeShapes")));
}
}
Expand All @@ -1293,7 +1290,7 @@ private class ShapePopup
// SheetSelector //
//---------------//
/**
* Display a list of available sheets and let user make a selection.
* Display a list of available sheets and let the user make a selection.
*/
private class SheetSelector
extends Selector<Descriptor>
Expand Down Expand Up @@ -1337,8 +1334,8 @@ private class SheetPopup
{
super("SheetPopup");

ApplicationActionMap actionMap = OmrGui.getApplication().getContext().getActionMap(
SampleBrowser.this);
ApplicationActionMap actionMap =
OmrGui.getApplication().getContext().getActionMap(SampleBrowser.this);
add(new JMenuItem(actionMap.get("removeSheets")));
add(new JMenuItem(actionMap.get("validateSheets")));
}
Expand Down
Loading

0 comments on commit 8a3efe6

Please sign in to comment.