Пример #1
0
        /// <summary>
        /// Constructor
        /// <para>Initialises all fields.</para>
        /// </summary>
        /// <param name="song">Song that was serialised from the "SongName.xml".</param>
        public UtilityHelper(Song song, ProgressBar progressBar)
        {
            //Init Buffer
            AudioBuffer  = new AudioBuffer();
            ResultBuffer = new ResultBuffer();

            //Init Classes
            AudioRecording = new AudioRecording(AudioBuffer);
            API_Helper     = new API_Helper(AudioBuffer, ResultBuffer, ConfigFileHelper.ConfigApiAddress);
            DataAnalyzer   = new DataAnalyzer(ResultBuffer);

            SongHelper.InitHelper(song);
            SongHelper.ProgressMade += OnProgressMade;

            _progressBar = progressBar;

            cts = new CancellationTokenSource();
        }
        /// <summary>
        /// Compares the Essentia data with the musical data based on timing and value of note. Uses the <see cref="SongHelper"/>.
        /// </summary>
        /// <param name="essentiaData">Data that shall be compared with the current note.</param>
        /// <returns></returns>
        public SongObject CompareWithSheet(EssentiaModel essentiaData)
        {
            string     noteToCompare = GetNoteFromData(essentiaData);
            SongObject songObject    = SongHelper.GetNext();

            //SongHelper.GetNext() sometimes returns an invalid object
            //Temporary Hack (not even working...)
            if (songObject == null)
            {
                if (DevFlags.LoggingEnabled)
                {
                    Logger.AnalyzerLog("songObject couldn't be loaded - " + songObject.ToString());
                }
                return(null);
            }

            //if(DevFlags.LoggingEnabled) Logger.AnalyzerLog("Comparing: " + songObject.Name + " - " + noteToCompare);
            if (CompareNamesOf(songObject.Name, noteToCompare) &&
                InRange(songObject.TimePosition, essentiaData.time))
            {
                if (DevFlags.LoggingEnabled)
                {
                    Logger.AnalyzerLog("Equal");
                }
            }
            else
            {
                songObject.Type = Highlight.None;
                if (DevFlags.LoggingEnabled)
                {
                    Logger.AnalyzerLog("Not equal");
                }
            }

            if (SongHelper.IncreaseIndex(essentiaData.time, songObject))
            {
                //End of Song
                InfoContainer.DisplayResults();
                Logger.Log("Analyzer: END OF SONG, now crashing?");
                throw new Exception("End of Song");
            }

            return(songObject);
        }