<commit_before>package analysis;

import analysis.bars.BarLexer;
import analysis.harmonic.ChordDegree;
import analysis.harmonic.ChordDegreeSequenceExtractor;
import analysis.harmonic.HarmonicProcessor;
import analysis.metadata.MetadataExtractor;
import jm.music.data.Score;
import jm.util.Read;
import analysis.harmonic.Scale;
import analysis.harmonic.Tonality;

import java.util.ArrayList;

/**
 * Class for Score analysis. Execute all the steps of the analysis on a specific score.
 * This class can be serialized in XML using the XStream library to create an input file for the training.
 */
public class ScoreAnalyser {
    private transient String fileName_;
    private transient Score score_;

    // Data of the score.
    private transient String title_;
    private Tonality tonality_;
    private double barUnit_;
    private int beatsPerBar_;
    private int tempo_;
    private int partNb_;
    private ArrayList<ChordDegree> degreeList_;
    private BarLexer barLexer_;
    private double quantum_;
    private transient ChordDegreeSequenceExtractor chordDegreeExtrator_;
    private transient Scale scale_;
    private int barNumber_;

    /**
     * Constructor for ScoreAnalyser
     * @param midiFile Path to MIDI file to analyse
     */
    public ScoreAnalyser(String midiFile) {
        score_ = new Score();
        try {
            Read.midi(score_, midiFile);
            fileName_ = midiFile.substring(midiFile.lastIndexOf('/') + 1, midiFile.length());
            title_ = score_.getTitle();
            tonality_ = MetadataExtractor.getTonality(score_.getKeySignature(), score_.getKeyQuality());
            scale_ = MetadataExtractor.computeScale(tonality_);
            barUnit_ = MetadataExtractor.computeBarUnit(score_.getDenominator());
            beatsPerBar_ = score_.getNumerator();
            tempo_ = (int)score_.getTempo();
            partNb_ = score_.getPartArray().length;
            quantum_ = MetadataExtractor.findQuantum(score_);
            barLexer_ = new BarLexer(score_, quantum_);
            degreeList_ = new HarmonicProcessor(tonality_, barLexer_).getDegreeList();
            barNumber_ = barLexer_.getBarNumber();
        }
        catch (Exception e) {
            System.err.println("Error: ScoreAnalyser midi file can't be found");
        }
    }

    /**
     * Display the important extracted data after analysis.
     */
    public void printScoreInfo() {
        StringBuilder sb = new StringBuilder("--------------------- Score MetaData ------------------------\n");
        sb.append("Processed File: ").append(fileName_).append("\n");
        sb.append("Score's Tonality: ").append(tonality_.toString()).append("\n");
        sb.append("Score's Scale: ").append(scale_.toString()).append(" = [ ");
        for (int n : scale_.getScale())
            sb.append(Tonality.pitchToFrenchString(n, true)).append(" ");
        sb.append("]\n");
        sb.append("Score's Bar Unit: ").append(+ barUnit_).append("\n");
        sb.append("Score's Beat Per Bar: ").append(beatsPerBar_).append("\n");
        sb.append("Score's Bar Number: ").append(barLexer_.getBarNumber()).append("\n");
        sb.append("------------------------ DegreeList ------------------------\n");
        sb.append(degreeList_).append("\n\n");
        System.out.println(sb);<commit_msg>analysis: score-analyser: improve error messages<commit_after>package analysis;

import analysis.bars.BarLexer;
import analysis.harmonic.ChordDegree;
import analysis.harmonic.ChordDegreeSequenceExtractor;
import analysis.harmonic.HarmonicProcessor;
import analysis.metadata.MetadataExtractor;
import jm.music.data.Score;
import jm.util.Read;
import analysis.harmonic.Scale;
import analysis.harmonic.Tonality;

import java.util.ArrayList;

/**
 * Class for Score analysis. Execute all the steps of the analysis on a specific score.
 * This class can be serialized in XML using the XStream library to create an input file for the training.
 */
public class ScoreAnalyser {
    private transient String fileName_;
    private transient Score score_;

    // Data of the score.
    private transient String title_;
    private Tonality tonality_;
    private double barUnit_;
    private int beatsPerBar_;
    private int tempo_;
    private int partNb_;
    private ArrayList<ChordDegree> degreeList_;
    private BarLexer barLexer_;
    private double quantum_;
    private transient ChordDegreeSequenceExtractor chordDegreeExtrator_;
    private transient Scale scale_;
    private int barNumber_;

    /**
     * Constructor for ScoreAnalyser
     * @param midiFile Path to MIDI file to analyse
     */
    public ScoreAnalyser(String midiFile) {
        score_ = new Score();
        try {
            Read.midi(score_, midiFile);
            fileName_ = midiFile.substring(midiFile.lastIndexOf('/') + 1, midiFile.length());
            title_ = score_.getTitle();
            tonality_ = MetadataExtractor.getTonality(score_.getKeySignature(), score_.getKeyQuality());
            scale_ = MetadataExtractor.computeScale(tonality_);
            barUnit_ = MetadataExtractor.computeBarUnit(score_.getDenominator());
            beatsPerBar_ = score_.getNumerator();
            tempo_ = (int)score_.getTempo();
            partNb_ = score_.getPartArray().length;
            quantum_ = MetadataExtractor.findQuantum(score_);
            barLexer_ = new BarLexer(score_, quantum_);
            degreeList_ = new HarmonicProcessor(tonality_, barLexer_).getDegreeList();
            barNumber_ = barLexer_.getBarNumber();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.err.println("ScoreAnalyser: An error occurred while processing " + midiFile);
        }
    }

    /**
     * Display the important extracted data after analysis.
     */
    public void printScoreInfo() {
        StringBuilder sb = new StringBuilder("--------------------- Score MetaData ------------------------\n");
        sb.append("Processed File: ").append(fileName_).append("\n");
        sb.append("Score's Tonality: ").append(tonality_.toString()).append("\n");
        sb.append("Score's Scale: ").append(scale_.toString()).append(" = [ ");
        for (int n : scale_.getScale())
            sb.append(Tonality.pitchToFrenchString(n, true)).append(" ");
        sb.append("]\n");
        sb.append("Score's Bar Unit: ").append(+ barUnit_).append("\n");
        sb.append("Score's Beat Per Bar: ").append(beatsPerBar_).append("\n");
        sb.append("Score's Bar Number: ").append(barLexer_.getBarNumber()).append("\n");
        sb.append("------------------------ DegreeList ------------------------\n");
        sb.append(degreeList_).append("\n\n");
        System.out.println(sb);
{'fraction_non_alphanumeric': 0.13770053475935828, 'fraction_numerical': 0.00029708853238265005, 'mean_word_length': 2.774103139013453, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '904573', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1800, 'n_words': 450}