Skip to content

Commit 8a3cab5

Browse files
committed
Save
1 parent c919d7f commit 8a3cab5

File tree

2 files changed

+15
-113
lines changed

2 files changed

+15
-113
lines changed

modules/core/src/main/java/jsymbolic2/featureutils/Feature.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jsymbolic2.featureutils;
22

33
import ace.datatypes.FeatureDefinition;
4+
import java.util.Objects;
45
import jsymbolic2.processing.MIDIIntermediateRepresentations;
56

67
import javax.sound.midi.Sequence;
@@ -97,4 +98,9 @@ public int[] getDependencyOffsets() {
9798
public String toString() {
9899
return getFeatureDefinition().getFeatureDescription();
99100
}
101+
102+
@Override
103+
public boolean equals(Object obj) {
104+
return Objects.equals();
105+
}
100106
}

modules/core/src/main/java/jsymbolic2/processing/MIDIFeatureProcessor.java

Lines changed: 9 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import ace.datatypes.DataBoard;
44
import ace.datatypes.DataSet;
55
import ace.datatypes.FeatureDefinition;
6+
import java.util.HashSet;
7+
import java.util.Set;
68
import java.util.concurrent.ExecutionException;
79
import java.util.concurrent.ForkJoinTask;
810
import jsymbolic2.featureutils.Feature;
911
import jsymbolic2.featureutils.FeatureExtractorAccess;
10-
import jsymbolic2.featureutils.MEIFeatureExtractor;
11-
import jsymbolic2.featureutils.Feature;
1212
import mckay.utilities.sound.midi.MIDIMethods;
1313
import org.apache.commons.lang3.ArrayUtils;
1414
import org.ddmal.jmei2midi.meielements.meispecific.MeiSpecificStorage;
@@ -65,7 +65,13 @@ public class MIDIFeatureProcessor {
6565
* The features that are to be extracted (including dependencies of features to be saved, not just the
6666
* features to be saved themselves).
6767
*/
68-
private Feature[] features;
68+
private List<Feature> features;
69+
70+
/**
71+
* The features that are to be extracted (including dependencies of features to be saved, not just the
72+
* features to be saved themselves).
73+
*/
74+
private Set<String> features;
6975

7076
/**
7177
* The dependencies of the features in the feature_extractors field.
@@ -416,59 +422,6 @@ public double[][][] getFeatures(Sequence[] windows, MeiSpecificStorage meiSpecif
416422
return results;
417423
}
418424

419-
private void processFeature(Sequence[] windows, MeiSpecificStorage meiSpecificStorage, double[][][] results, int win, MIDIIntermediateRepresentations intermediate, int feat) throws Exception {
420-
// Only extract this feature if enough previous information
421-
// is available to extract this feature
422-
if (win >= maxFeatureOffsets[feat]) {
423-
// Find the correct feature
424-
Feature feature = features[feat];
425-
426-
double[][] otherFeatureValues = findPreviousExtractedFeatures(results, win, feat, feature);
427-
428-
//Check here if the file is an MEI file and if the feature is an MEI feature
429-
//Otherwise just extract the midi feature data
430-
if (null == meiSpecificStorage && feature instanceof MEIFeatureExtractor) {
431-
//Skip if this is a non-mei file as mei features are not valid
432-
return;
433-
}
434-
if (null != meiSpecificStorage && feature instanceof MEIFeatureExtractor) {
435-
results[win][feat] = ((MEIFeatureExtractor) feature).extractMEIFeature(meiSpecificStorage, windows[win], intermediate, otherFeatureValues);
436-
return;
437-
}
438-
// Store the extracted feature values
439-
results[win][feat] = feature.extractFeature(windows[win], intermediate, otherFeatureValues);
440-
return;
441-
}
442-
results[win][feat] = null;
443-
}
444-
445-
/**
446-
* Find previously extracted feature values that this feature needs
447-
*
448-
* @param results
449-
* @param win
450-
* @param feat
451-
* @param feature
452-
* @return
453-
*/
454-
private double[][] findPreviousExtractedFeatures(double[][][] results, int win, int feat, Feature feature) {
455-
double[][] otherFeatureValues = null;
456-
if (featureExtractorDependencies[feat] != null) {
457-
otherFeatureValues = new double[featureExtractorDependencies[feat].length][];
458-
for (int i = 0; i < featureExtractorDependencies[feat].length; i++) {
459-
int featureIndice = featureExtractorDependencies[feat][i];
460-
/* TODO Check if this is a correct bug fix */
461-
if (feature.getDependencyOffsets() == null) {
462-
otherFeatureValues[i] = results[win][featureIndice];
463-
} else {
464-
int offset = feature.getDependencyOffsets()[i];
465-
otherFeatureValues[i] = results[win + offset][featureIndice];
466-
}
467-
}
468-
}
469-
return otherFeatureValues;
470-
}
471-
472425
/**
473426
* Generates DataBoard based in list of DataSets that were constructed during features extractions
474427
*
@@ -639,63 +592,6 @@ private void updateExtraDependencies(Feature[] allFeatureExtractors, String[] al
639592
}
640593
}
641594

642-
/**
643-
* Find the indices of the feature extractor dependencies for each feature extractor
644-
*/
645-
private void prepareIndicies() {
646-
featureExtractorDependencies = new int[features.length][];
647-
String[] feature_names = new String[features.length];
648-
for (int feat = 0; feat < feature_names.length; feat++)
649-
feature_names[feat] = features[feat].getFeatureDefinition().name;
650-
String[][] featureDependenciesStr = new String[features.length][];
651-
for (int feat = 0; feat < featureDependenciesStr.length; feat++)
652-
featureDependenciesStr[feat] = features[feat].getDependencies();
653-
for (int i = 0; i < featureDependenciesStr.length; i++)
654-
if (null != featureDependenciesStr[i]) {
655-
featureExtractorDependencies[i] = new int[featureDependenciesStr[i].length];
656-
for (int j = 0; j < featureDependenciesStr[i].length; j++)
657-
for (int k = 0; k < feature_names.length; k++)
658-
if (featureDependenciesStr[i][j].equals(feature_names[k]))
659-
featureExtractorDependencies[i][j] = k;
660-
}
661-
}
662-
663-
/**
664-
* Find the maximum offset for each feature
665-
*/
666-
private void setMaxOffset() {
667-
maxFeatureOffsets = new int[features.length];
668-
for (int feat = 0; feat < maxFeatureOffsets.length; feat++) {
669-
if (null == features[feat].getDependencyOffsets()) {
670-
maxFeatureOffsets[feat] = 0;
671-
continue;
672-
}
673-
int[] offsetsOfCurrentFeature = features[feat].getDependencyOffsets();
674-
maxFeatureOffsets[feat] = Math.abs(offsetsOfCurrentFeature[0]);
675-
for (int offsetOfCurrentFeature : offsetsOfCurrentFeature) {
676-
maxFeatureOffsets[feat] = Math.max(Math.abs(offsetOfCurrentFeature), offsetOfCurrentFeature);
677-
}
678-
}
679-
}
680-
681-
/**
682-
* Find the dependencies of each feature marked to be extracted.
683-
* Mark an entry as null if that entry's matching feature is not set to be extracted.
684-
* Note that an entry will also be null if the corresponding feature has no dependencies.
685-
*
686-
* @param allFeatureExtractors
687-
* @param featuresToSaveAmongAll
688-
* @return
689-
*/
690-
private String[][] getDependencies(Feature[] allFeatureExtractors, boolean[] featuresToSaveAmongAll) {
691-
String[][] dependencies = new String[allFeatureExtractors.length][];
692-
for (int feat = 0; feat < allFeatureExtractors.length; feat++) {
693-
dependencies[feat] = null;
694-
if (featuresToSaveAmongAll[feat]) dependencies[feat] = allFeatureExtractors[feat].getDependencies();
695-
}
696-
return dependencies;
697-
}
698-
699595
/**
700596
* Find the names of all features
701597
*

0 commit comments

Comments
 (0)