<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows;
using AudioAlign.WaveControls;
using System.Windows.Media;
using AudioAlign.Audio.Matching.Dixon2005;

namespace AudioAlign {
    public class DtwPath : Control {

        /// <summary>
        /// Specified how much times the scroll mode bitmap should be larger than the actual control's width.
        /// The bigger it is, the more memory is consumed, but the less bitmap copy operations need to be executed.
        /// </summary>
        private const int SCROLL_WIDTH_FACTOR = 3;

        private WriteableBitmap writeableBitmap;
        private int position;
        private int[] pixelColumn;
        //private SpectrogramMode mode;

        private IMatrix cellCostMatrix;
        private IMatrix totalCostMatrix;
        private int size;
        int[] pixels;
        int pathColor, minColor, maxColor, undefColor;

        private int[] colorPalette;
        private bool paletteDemo = false;
        private int paletteDemoIndex = 0;

        public bool Drawing { get; set; }

        //public SpectrogramMode Mode {
        //    get { return (SpectrogramMode)GetValue(ModeProperty); }
        //    set { SetValue(ModeProperty, value); }
        //}

        //public static readonly DependencyProperty ModeProperty =
        //    DependencyProperty.Register("Mode", typeof(SpectrogramMode), typeof(Spectrogram),
        //    new UIPropertyMetadata(SpectrogramMode.Scroll, OnModeChanged));

        //private static void OnModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
        //    Spectrogram spectrogram = d as Spectrogram;
        //    spectrogram.mode = (SpectrogramMode)e.NewValue;
        //}

        public int SpectrogramSize {
            get { return (int)GetValue(SpectrogramSizeProperty); }
            set { SetValue(SpectrogramSizeProperty, value); }
        }

        public static readonly DependencyProperty SpectrogramSizeProperty =
            DependencyProperty.Register("SpectrogramSize", typeof(int), typeof(DtwPath),
            new UIPropertyMetadata(1024) {
                CoerceValueCallback = CoerceSpectrogramSize,
                PropertyChangedCallback = OnSpectrogramSizeChanged
            });

        private static object CoerceSpectrogramSize(DependencyObject d, object value) {
            int i = (int)value;
            return i < 1 ? 1 : i;
        }

        private static void OnSpectrogramSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
            DtwPath spectrogram = d as DtwPath;
            spectrogram.InitializeBitmap(true);
        }

        public float Minimum {
            get { return (float)GetValue(MinimumProperty); }
            set { SetValue(MinimumProperty, value); }
        }

        public static readonly DependencyProperty MinimumProperty =
            DependencyProperty.Register("Minimum", typeof(float), typeof(DtwPath), new UIPropertyMetadata(-100f));

        public float Maximum {
            get { return (float)GetValue(MaximumProperty); }
            set { SetValue(MaximumProperty, value); }
        }

        public static readonly DependencyProperty MaximumProperty =
            DependencyProperty.Register("Maximum", typeof(float), typeof(DtwPath), new UIPropertyMetadata(0f));

        public DtwPath() {
            ColorGradient gradient = new ColorGradient(0, 1);
            gradient.AddStop(Colors.Black, 0);
            gradient.AddStop(Colors.White, 1);
            colorPalette = gradient.GetGradient(500).Select(c => GetColorValue(c)).ToArray();

            pathColor = GetColorValue(Colors.Red);
            minColor = GetColorValue(Colors.Green);
            maxColor = GetColorValue(Colors.Magenta);
            undefColor = GetColorValue(Colors.Blue);

            ClipToBounds = true;
            //mode = Mode;
        }

        public void Init(int size, IMatrix cellCostMatrix, IMatrix totalCostMatrix) {<commit_msg>* bugfixes and refactoring * IMPROVEMENT OLTW now (probably) working perfectly :) * UI dtw matrix/path style fit to MATCH<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows;
using AudioAlign.WaveControls;
using System.Windows.Media;
using AudioAlign.Audio.Matching.Dixon2005;

namespace AudioAlign {
    public class DtwPath : Control {

        /// <summary>
        /// Specified how much times the scroll mode bitmap should be larger than the actual control's width.
        /// The bigger it is, the more memory is consumed, but the less bitmap copy operations need to be executed.
        /// </summary>
        private const int SCROLL_WIDTH_FACTOR = 3;

        private WriteableBitmap writeableBitmap;
        private int position;
        private int[] pixelColumn;
        //private SpectrogramMode mode;

        private IMatrix cellCostMatrix;
        private IMatrix totalCostMatrix;
        private int size;
        int[] pixels;
        int pathColor, minColor, maxColor, undefColor;

        private int[] colorPalette;
        private bool paletteDemo = false;
        private int paletteDemoIndex = 0;

        public bool Drawing { get; set; }

        //public SpectrogramMode Mode {
        //    get { return (SpectrogramMode)GetValue(ModeProperty); }
        //    set { SetValue(ModeProperty, value); }
        //}

        //public static readonly DependencyProperty ModeProperty =
        //    DependencyProperty.Register("Mode", typeof(SpectrogramMode), typeof(Spectrogram),
        //    new UIPropertyMetadata(SpectrogramMode.Scroll, OnModeChanged));

        //private static void OnModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
        //    Spectrogram spectrogram = d as Spectrogram;
        //    spectrogram.mode = (SpectrogramMode)e.NewValue;
        //}

        public int SpectrogramSize {
            get { return (int)GetValue(SpectrogramSizeProperty); }
            set { SetValue(SpectrogramSizeProperty, value); }
        }

        public static readonly DependencyProperty SpectrogramSizeProperty =
            DependencyProperty.Register("SpectrogramSize", typeof(int), typeof(DtwPath),
            new UIPropertyMetadata(1024) {
                CoerceValueCallback = CoerceSpectrogramSize,
                PropertyChangedCallback = OnSpectrogramSizeChanged
            });

        private static object CoerceSpectrogramSize(DependencyObject d, object value) {
            int i = (int)value;
            return i < 1 ? 1 : i;
        }

        private static void OnSpectrogramSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
            DtwPath spectrogram = d as DtwPath;
            spectrogram.InitializeBitmap(true);
        }

        public float Minimum {
            get { return (float)GetValue(MinimumProperty); }
            set { SetValue(MinimumProperty, value); }
        }

        public static readonly DependencyProperty MinimumProperty =
            DependencyProperty.Register("Minimum", typeof(float), typeof(DtwPath), new UIPropertyMetadata(-100f));

        public float Maximum {
            get { return (float)GetValue(MaximumProperty); }
            set { SetValue(MaximumProperty, value); }
        }

        public static readonly DependencyProperty MaximumProperty =
            DependencyProperty.Register("Maximum", typeof(float), typeof(DtwPath), new UIPropertyMetadata(0f));

        public DtwPath() {
            ColorGradient gradient = new ColorGradient(0, 1);
            gradient.AddStop(Colors.Black, 0);
            gradient.AddStop(Colors.White, 1);
            colorPalette = gradient.GetGradient(500).Select(c => GetColorValue(c)).ToArray();

            pathColor = GetColorValue(Colors.Green);
            minColor = GetColorValue(Colors.Magenta);
            maxColor = GetColorValue(Colors.Red);
            undefColor = GetColorValue(Colors.White);

            ClipToBounds = true;
            //mode = Mode;
        }

        public void Init(int size, IMatrix cellCostMatrix, IMatrix totalCostMatrix) {
{'fraction_non_alphanumeric': 0.084007242003621, 'fraction_numerical': 0.005552202776101388, 'mean_word_length': 2.5546975546975546, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4640785', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2054, 'n_words': 554}