public void AverageFiles() { double avg = 0; string temp, check = null; MetaDataType tag; configMgr = new ConfigMgr(); Dictionary <int, string> DeserializedDict = configMgr.DeserializeIntoDict(_workingDirectory + @"\DRconfig.xml", new Dictionary <int, string>()); DeserializedDict.TryGetValue(7, out check); DeserializedDict.TryGetValue(2, out temp); tagsDictionary.TryGetValue(temp, out tag); if (!mbApiInterface.Library_QueryFilesEx("domain=SelectedFiles", ref files)) { files = new string[0]; } if (files.Length == 0) { MessageBox.Show("No files selected."); return; } for (int i = 0; i < files.Length; i++) { string taggedVal = mbApiInterface.Library_GetFileTag(files[i], tag); try { avg += Convert.ToDouble(Regex.Replace(taggedVal, @"[a-zA-Z /\s/g :]", ""), CultureInfo.GetCultureInfo("en-us")); } catch (System.FormatException e) { MessageBox.Show("Please tag all of the files first!"); return; } } avg = (avg / files.Length); if (check == "None") { MessageBox.Show("[NO TAG CONFIGURED - Files Not Tagged] \n\nAverage DR of selected files: " + Convert.ToString(Math.Round(avg, 2)) + " LU"); return; } //Write tag to files: for (int i = 0; i < files.Length; i++) { DeserializedDict.TryGetValue(7, out temp); tagsDictionary.TryGetValue(temp, out tag); mbApiInterface.Library_SetFileTag(files[i], tag, Math.Round(avg, 2) + " LU"); mbApiInterface.Library_CommitTagsToFile(files[i]); } //MessageBox.Show("Temp: " + temp + "\nTag: " + tag + "\nData: " + data[i]); mbApiInterface.MB_RefreshPanels(); MessageBox.Show("[FILES TAGGED] \n\nAverage DR of selected files: " + Convert.ToString(Math.Round(avg, 2)) + " LU"); return; }
public void GetCurrentLoudness() { //string tempculture = Thread.CurrentThread.CurrentCulture.Name; //Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); //Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US"); string temp, check = null; MetaDataType tag, tag2; configMgr = new ConfigMgr(); Dictionary <int, string> DeserializedDict = configMgr.DeserializeIntoDict(_workingDirectory + @"\DRconfig.xml", new Dictionary <int, string>()); DeserializedDict.TryGetValue(0, out temp); DeserializedDict.TryGetValue(8, out check); if ((check == "None") || (temp == "None")) { MessageBox.Show("Please configure tag in EBU R128 Settings."); return; } tagsDictionary.TryGetValue(temp, out tag); tagsDictionary.TryGetValue(check, out tag2); if (!mbApiInterface.Library_QueryFilesEx("domain=SelectedFiles", ref files)) { files = new string[0]; } if (files.Length == 0) { MessageBox.Show("No files selected."); return; } for (int i = 0; i < files.Length; i++) { // Add regex to remove non-numeric characters from tags. string taggedVal = Regex.Replace(mbApiInterface.Library_GetFileTag(files[i], tag), @"[a-zA-Z /\s/g :]", ""); string gainVal = Regex.Replace(mbApiInterface.Library_GetFileProperty(files[i], FilePropertyType.ReplayGainTrack), @"[a-zA-Z /\s/g :]", ""); Convert.ToString(gainVal, CultureInfo.GetCultureInfo("en-us")); //gainVal = Regex.Replace(gainVal, ",", "."); //MessageBox.Show("Tagged Value: " + taggedVal + "\nGain Value: " + gainVal); try { double cur = Convert.ToDouble(taggedVal, CultureInfo.GetCultureInfo("en-us")) + Convert.ToDouble(gainVal); //MessageBox.Show("CUR: " + cur); mbApiInterface.Library_SetFileTag(files[i], tag2, Math.Round(cur, 2) + " LUFS"); mbApiInterface.Library_CommitTagsToFile(files[i]); } catch (System.FormatException e) { MessageBox.Show("Please tag all of the files first! \n "); return; } } mbApiInterface.MB_RefreshPanels(); MessageBox.Show("Files tagged."); //Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(tempculture); //Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(tempculture); return; }
public void ParseValues(int currentSong) { configMgr = new ConfigMgr(); Dictionary <int, string> DeserializedDict = configMgr.DeserializeIntoDict(_workingDirectory + @"\DRconfig.xml", new Dictionary <int, string>()); int I = 0; using (var reader = new StreamReader(_fileDirectory + CurrentTitle(currentSong) + ".txt")) { while (!reader.EndOfStream) { var line = reader.ReadLine(); if (line.StartsWith(" I:") | line.StartsWith(" Threshold:") | line.StartsWith(" LRA:") | line.StartsWith(" LRA low:") | line.StartsWith(" LRA high:") | line.StartsWith(" Peak:")) { line = Regex.Replace(line, @"[a-zA-Z /\s/g :]", ""); data[I] = line; I++; } } int i = 0; foreach (var o in DeserializedDict) { string unit = null; //MessageBox.Show("Key: " + o.Key + "\nVal: " + o.Value.ToString()); if (o.Value != "None" && o.Key != 7 && o.Key != 8) { if (o.Key == 2) { unit = " LU"; } else if (o.Key == 6) { unit = " dBFS"; } else { unit = " LUFS"; } string temp; MetaDataType tag; DeserializedDict.TryGetValue(i, out temp); tagsDictionary.TryGetValue(temp, out tag); //MessageBox.Show("Temp: " + temp + "\nTag: " + tag + "\nData: " + data[i]); mbApiInterface.Library_SetFileTag(files[currentSong], tag, data[i] + unit); } i += 1; } mbApiInterface.Library_CommitTagsToFile(files[currentSong]); mbApiInterface.MB_RefreshPanels(); _checkNum += 1; if (_checkNum == _selectedNum) { MessageBox.Show("Tagging Complete!"); } //MessageBox.Show(data[0] + "\n" + data[1] + "\n" + data[2] + "\n" + data[3] + "\n" + data[4] + "\n" + data[5]); return; } }