src/core/preprocess/ReadMIDI.java
private void scaleTickData(ArrayList<Integer> inputTickData, ArrayList<Integer> outputTickData, Metadata metadata) {

        class FrequencyValue {
            int frequency = 1;
            final int value;

            FrequencyValue(int value) {
                this.value = value;
            }

            void increment() {
                frequency++;
            }
        }

        HashMap<Integer, FrequencyValue> frequencyValueHashMap = new HashMap<>();
        ArrayList<FrequencyValue> frequencyValues = new ArrayList<>();
        ArrayList<FrequencyValue> valueFrequencies = new ArrayList<>();

        for (Integer data : inputTickData) {
            if (frequencyValueHashMap.containsKey(data)) frequencyValueHashMap.get(data).increment();
            else {
                FrequencyValue frequencyValue = new FrequencyValue(data);
                frequencyValueHashMap.put(data, frequencyValue);
                frequencyValues.add(frequencyValue);
                valueFrequencies.add(frequencyValue);
            }
        }
        frequencyValues.sort((o1, o2) -> o1.frequency == o2.frequency ? 0 : o2.frequency - o1.frequency);
        valueFrequencies.sort((o1, o2) -> o1.value == o2.value ? 0 : o2.value - o1.value);

        metadata.numberOfEncodedTicks = Math.min(metadata.maxNumberOfEncodedTicks, frequencyValues.size());

        int count = 0;
        for (FrequencyValue frequencyValue : frequencyValues) {
            metadata.tickValueMapping.put(frequencyValue.value, count);
            metadata.tickValueReverseMapping.put(count, frequencyValue.value);
            if (++count == metadata.numberOfEncodedTicks) break;
        }

        HashMap<Integer, Integer> updatedMapping = new HashMap<>();
        for (int oldIndex = metadata.numberOfEncodedTicks - 1; oldIndex < frequencyValues.size(); oldIndex++) {

            int minDistance = Integer.MAX_VALUE;
            int minIndex = -1;
            for (int newIndex = 0; newIndex < metadata.numberOfEncodedTicks; newIndex++) {
                updatedMapping.put(frequencyValues.get(newIndex).value, frequencyValues.get(newIndex).value);
                int currentDistance = Math.abs(frequencyValues.get(newIndex).value - frequencyValues.get(oldIndex).value);
                if (currentDistance > 0 && currentDistance < minDistance) {
                    minDistance = currentDistance;
                    minIndex = newIndex;
                }
            }

            updatedMapping.put(frequencyValues.get(oldIndex).value, frequencyValues.get(minIndex).value);
        }
        for (Integer data: inputTickData) outputTickData.add(updatedMapping.get(data));

    }
/**
     * Scales tick data between zero and one.
     *
     * @param inputTickData input tick data.
     * @param outputTickData output tick data.
     * @param metadata record data.
     */
Scales tick data between zero and one.

@param inputTickData input tick data.
@param outputTickData output tick data.
@param metadata record data.
Scales tick data between zero and one . @param inputTickData input tick data . @param outputTickData output tick data . @param metadata record data .
private void scaleTickData(ArrayList<Integer> inputTickData, ArrayList<Integer> outputTickData, Metadata metadata) {
        class FrequencyValue {
            int frequency = 1;
            final int value;
            FrequencyValue(int value) {
                this.value = value;
            }
            void increment() {
                frequency++;
            }
        }
        HashMap<Integer, FrequencyValue> frequencyValueHashMap = new HashMap<>();
        ArrayList<FrequencyValue> frequencyValues = new ArrayList<>();
        ArrayList<FrequencyValue> valueFrequencies = new ArrayList<>();
        for (Integer data : inputTickData) {
            if (frequencyValueHashMap.containsKey(data)) frequencyValueHashMap.get(data).increment();
            else {
                FrequencyValue frequencyValue = new FrequencyValue(data);
                frequencyValueHashMap.put(data, frequencyValue);
                frequencyValues.add(frequencyValue);
                valueFrequencies.add(frequencyValue);
            }
        }
        frequencyValues.sort((o1, o2) -> o1.frequency == o2.frequency ? 0 : o2.frequency - o1.frequency);
        valueFrequencies.sort((o1, o2) -> o1.value == o2.value ? 0 : o2.value - o1.value);
        metadata.numberOfEncodedTicks = Math.min(metadata.maxNumberOfEncodedTicks, frequencyValues.size());
        int count = 0;
        for (FrequencyValue frequencyValue : frequencyValues) {
            metadata.tickValueMapping.put(frequencyValue.value, count);
            metadata.tickValueReverseMapping.put(count, frequencyValue.value);
            if (++count == metadata.numberOfEncodedTicks) break;
        }
        HashMap<Integer, Integer> updatedMapping = new HashMap<>();
        for (int oldIndex = metadata.numberOfEncodedTicks - 1; oldIndex < frequencyValues.size(); oldIndex++) {
            int minDistance = Integer.MAX_VALUE;
            int minIndex = -1;
            for (int newIndex = 0; newIndex < metadata.numberOfEncodedTicks; newIndex++) {
                updatedMapping.put(frequencyValues.get(newIndex).value, frequencyValues.get(newIndex).value);
                int currentDistance = Math.abs(frequencyValues.get(newIndex).value - frequencyValues.get(oldIndex).value);
                if (currentDistance > 0 && currentDistance < minDistance) {
                    minDistance = currentDistance;
                    minIndex = newIndex;
                }
            }
            updatedMapping.put(frequencyValues.get(oldIndex).value, frequencyValues.get(minIndex).value);
        }
        for (Integer data: inputTickData) outputTickData.add(updatedMapping.get(data));
    }
private void scaleTickData ( ArrayList < Integer > inputTickData , ArrayList < Integer > outputTickData , Metadata metadata ) { class FrequencyValue { int frequency = 1 ; final int value ; FrequencyValue ( int value ) { this . value = value ; } void increment ( ) { frequency ++ ; } } HashMap < Integer , FrequencyValue > frequencyValueHashMap = new HashMap < > ( ) ; ArrayList < FrequencyValue > frequencyValues = new ArrayList < > ( ) ; ArrayList < FrequencyValue > valueFrequencies = new ArrayList < > ( ) ; for ( Integer data : inputTickData ) { if ( frequencyValueHashMap . containsKey ( data ) ) frequencyValueHashMap . get ( data ) . increment ( ) ; else { FrequencyValue frequencyValue = new FrequencyValue ( data ) ; frequencyValueHashMap . put ( data , frequencyValue ) ; frequencyValues . add ( frequencyValue ) ; valueFrequencies . add ( frequencyValue ) ; } } frequencyValues . sort ( ( o1 , o2 ) -> o1 . frequency == o2 . frequency ? 0 : o2 . frequency - o1 . frequency ) ; valueFrequencies . sort ( ( o1 , o2 ) -> o1 . value == o2 . value ? 0 : o2 . value - o1 . value ) ; metadata . numberOfEncodedTicks = Math . min ( metadata . maxNumberOfEncodedTicks , frequencyValues . size ( ) ) ; int count = 0 ; for ( FrequencyValue frequencyValue : frequencyValues ) { metadata . tickValueMapping . put ( frequencyValue . value , count ) ; metadata . tickValueReverseMapping . put ( count , frequencyValue . value ) ; if ( ++ count == metadata . numberOfEncodedTicks ) break ; } HashMap < Integer , Integer > updatedMapping = new HashMap < > ( ) ; for ( int oldIndex = metadata . numberOfEncodedTicks - 1 ; oldIndex < frequencyValues . size ( ) ; oldIndex ++ ) { int minDistance = Integer . MAX_VALUE ; int minIndex = - 1 ; for ( int newIndex = 0 ; newIndex < metadata . numberOfEncodedTicks ; newIndex ++ ) { updatedMapping . put ( frequencyValues . get ( newIndex ) . value , frequencyValues . get ( newIndex ) . value ) ; int currentDistance = Math . abs ( frequencyValues . get ( newIndex ) . value - frequencyValues . get ( oldIndex ) . value ) ; if ( currentDistance > 0 && currentDistance < minDistance ) { minDistance = currentDistance ; minIndex = newIndex ; } } updatedMapping . put ( frequencyValues . get ( oldIndex ) . value , frequencyValues . get ( minIndex ) . value ) ; } for ( Integer data : inputTickData ) outputTickData . add ( updatedMapping . get ( data ) ) ; }
Scales tick data between zero and one.
Scales tick data between zero and one .