private void BtnStartClick(object sender, EventArgs e) { DefaultFingerprintConfiguration configuration = new DefaultFingerprintConfiguration(); switch (hashAlgorithm) { case HashAlgorithm.LSH: if (!fileList.Any()) { MessageBox.Show(Resources.SelectFolderWithSongs, Resources.Songs, MessageBoxButtons.OK, MessageBoxIcon.Information); break; } WinQueryResults winQueryResults = new WinQueryResults( _numSecondsToAnalyze.Enabled ? (int)_numSecondsToAnalyze.Value : 0, _numStartAtSecond.Enabled ? (int)_numStartAtSecond.Value : 0, (int)_nudHashtables.Value, (int)_nudKeys.Value, Convert.ToInt32(_nudThreshold.Value), WinUtils.GetStride((StrideType)_cmbStrideType.SelectedIndex, (int)_nudQueryStrideMax.Value, (int)_nudQueryStrideMin.Value, configuration.SamplesPerFingerprint), tagService, modelService, queryCommandBuilder); winQueryResults.Show(); winQueryResults.Refresh(); winQueryResults.ExtractCandidatesWithMinHashAlgorithm(fileList); break; case HashAlgorithm.NeuralHasher: throw new NotImplementedException(); case HashAlgorithm.None: throw new NotImplementedException(); } }
private void BtnQueryFromMicrophoneClick(object sender, EventArgs e) { DefaultFingerprintConfiguration configuration = new DefaultFingerprintConfiguration(); int secondsToRecord = (int)_nudSecondsToRecord.Value; int sampleRate = (int)_nudSampleRate.Value; string pathToFile = "mic_" + DateTime.Now.Ticks + ".wav"; _gbQueryMicrophoneBox.Enabled = false; Task<float[]>.Factory.StartNew(() => audioService.ReadMonoFromMicrophoneToFile(pathToFile, sampleRate, secondsToRecord)).ContinueWith( task => { _gbQueryMicrophoneBox.Enabled = true; WinQueryResults winQueryResults = new WinQueryResults( secondsToRecord, 0, (int)_nudHashtables.Value, (int)_nudKeys.Value, (int)_nudThreshold.Value, WinUtils.GetStride((StrideType)_cmbStrideType.SelectedIndex, (int)_nudQueryStrideMax.Value, (int)_nudQueryStrideMin.Value, configuration.SamplesPerFingerprint), tagService, modelService, queryCommandBuilder); winQueryResults.Show(); winQueryResults.Refresh(); winQueryResults.ExtractCandidatesUsingSamples(task.Result); }, TaskScheduler.FromCurrentSynchronizationContext()); }
private void InsertInDatabase(int start, int end) { int topWavelets = (int)_nudTopWav.Value; IStride stride = null; Invoke( new Action( () => { stride = WinUtils.GetStride( (StrideType)_cmbStrideType.SelectedIndex, (int)_nudStride.Value, 0, new DefaultFingerprintConfiguration().SamplesPerFingerprint); }), null); Action actionInterface = () => { _pbTotalSongs.PerformStep(); _nudProcessed.Value = processed; _nudLeft.Value = left; _nudBadFiles.Value = badFiles; _nudDetectedDuplicates.Value = duplicates; }; Action <object[], Color> actionAddItems = (parameters, color) => { int index = _dgvFillDatabase.Rows.Add(parameters); _dgvFillDatabase.FirstDisplayedScrollingRowIndex = index; if (color != Color.Empty) { _dgvFillDatabase.Rows[index].DefaultCellStyle.BackColor = color; } }; for (int i = start; i < end; i++) { // Process the corresponding files if (stopFlag) { return; } TagInfo tags = tagService.GetTagInfo(fileList[i]); // Get Tags from file if (tags == null || tags.IsEmpty) { badFiles++; processed++; left--; Invoke(actionAddItems, new object[] { "TAGS ARE NULL", fileList[i], 0, 0 }, Color.Red); Invoke(actionInterface); continue; } string isrc = tags.ISRC; string artist = tags.Artist; // Artist string title = tags.Title; // Title int releaseYear = tags.Year; string album = tags.Album; double duration = tags.Duration; // Duration // Check whether the duration is OK if (duration < MinTrackLength || duration > MaxTrackLength) { // Duration too small badFiles++; processed++; left--; Invoke(actionAddItems, new object[] { "Bad duration", fileList[i], 0, 0 }, Color.Red); Invoke(actionInterface); continue; } // Check whether the tags are properly defined if (string.IsNullOrEmpty(isrc) && (string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(title))) { badFiles++; processed++; left--; Invoke( actionAddItems, new object[] { "ISRC Tag is missing. Skipping file...", fileList[i], 0, 0 }, Color.Red); Invoke(actionInterface); continue; } IModelReference trackReference; try { lock (this) { // Check if this file is already in the database if (IsDuplicateFile(isrc, artist, title)) { duplicates++; // There is such file in the database processed++; left--; Invoke(actionInterface); continue; } var track = new TrackData(isrc, artist, title, album, releaseYear, (int)duration); trackReference = modelService.InsertTrack(track); // Insert new Track in the database } } catch (Exception e) { // catch any exception and abort the insertion processed++; left--; badFiles++; MessageBox.Show(e.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Invoke(actionInterface); return; } int count; try { var hashDatas = fingerprintCommandBuilder .BuildFingerprintCommand() .From(fileList[i]) .WithFingerprintConfig( config => { config.TopWavelets = topWavelets; config.Stride = stride; }) .UsingServices(audioService) .Hash() .Result; // Create SubFingerprints modelService.InsertHashDataForTrack(hashDatas, trackReference); count = hashDatas.Count; } catch (Exception e) { // catch any exception and abort the insertion MessageBox.Show(e.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); badFiles++; processed++; left--; Invoke(actionInterface); return; } Invoke(actionAddItems, new object[] { artist, title, isrc, duration, count }, Color.Empty); left--; processed++; Invoke(actionInterface); } }