@@ -0,0 +1,2858 @@
+package training;%0A%0Aimport analysis.ScoreAnalyser;%0Aimport analysis.bars.Bar;%0Aimport analysis.bars.BarNote;%0Aimport analysis.harmonic.ChordDegree;%0Aimport training.probability.MarkovMatrix;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0A%0A/**%0A * Class for Melodic sequences learning%0A */%0Apublic class MelodicLearner %7B%0A    private HashMap%3CChordDegree, MarkovMatrix%3CInteger%3E%3E trainingData_;%0A%0A    /**%0A     * Constructor%0A     */%0A    public MelodicLearner() %7B%0A        trainingData_ = new HashMap%3C%3E();%0A    %7D%0A%0A    /**%0A     * Process training on a specific score%0A     * @param score Extracted features of the score%0A     */%0A    public void learnExample(ScoreAnalyser score) %7B%0A        ArrayList%3CChordDegree%3E degrees = score.getDegreeList();%0A        ArrayList%3CBar%3E bars = score.getBarLexer().getBars();%0A        int beatsPerBar = score.getBeatsPerBar();%0A%0A        ChordDegree degree = degrees.get(0);%0A        int deg_ind = 1;%0A        for (Bar bar : bars) %7B%0A            double bar_frac = 0.0;%0A            for (;bar_frac %3C beatsPerBar; ++deg_ind) %7B%0A                ArrayList%3CInteger%3E notes = getDegreeNotes(degree, bar, bar_frac, beatsPerBar);%0A                bar_frac += (double)beatsPerBar / degree.getBarFractionDen();%0A                if (deg_ind %3C degrees.size())%0A                    degree = degrees.get(deg_ind);%0A                else%0A                    degree = null;%0A%0A %7D%0A        %7D%0A    %7D%0A%0A    /**%0A     * Get all the notes in a section of the score corresponding to a specific degree%0A     * @param degree The degree of the section%0A     * @param bar The bar containing the section%0A     * @param low_bound The beginning beat of the section relative to the bar%0A     * @param beatsPerBar The number of beats per bar%0A     * @return%0A     */%0A    private ArrayList%3CInteger%3E getDegreeNotes(ChordDegree degree, Bar bar, double low_bound, int beatsPerBar) %7B%0A        ArrayList%3CInteger%3E result = new ArrayList%3C%3E();%0A        double high_bound = low_bound + (double)beatsPerBar / degree.getBarFractionDen();%0A        ArrayList%3CBarNote%3E notes = bar.getNotes();%0A        for (BarNote note : notes) %7B%0A            double startTime = note.getStartTime();%0A            if (low_bound %3C startTime && startTime %3C high_bound) %7B%0A                if (note.getDuration() %3E 0)%0A                    result.add(note.getPitch());%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    private void addEntry(ChordDegree context, ArrayList%3CInteger%3E pitches) %7B%0A        MarkovMatrix%3CInteger%3E mat = trainingData_.get(context);%0A        if (mat == null) %7B%0A            mat = new MarkovMatrix%3C%3E(1);%0A            for (Integer entry : pitches)%0A                mat.addEntry(entry);%0A            mat.resetContext();%0A            trainingData_.put(context, mat);%0A        %7D%0A        else %7B%0A            for (Integer entry : pitches)%0A                mat.addEntry(entry);%0A            mat.resetContext();%0A        %7D%0A    %7D%0A%7D%0A

add basic melodic learner