private void LoadBeatLabels() { var colors = new List <Color> { Color.Yellow, Color.Gold, Color.Goldenrod, Color.SaddleBrown, Color.CadetBlue, Color.BlueViolet }; openFileDialog.DefaultExt = ".txt"; openFileDialog.Filter = @"Audacity Beat Labels|*.txt|All Files|*.*"; openFileDialog.FilterIndex = 0; openFileDialog.InitialDirectory = _lastFolder; openFileDialog.FileName = ""; if (openFileDialog.ShowDialog() == DialogResult.OK) { _lastFolder = Path.GetDirectoryName(openFileDialog.FileName); try { string line; StringBuilder data = new StringBuilder(); using (var sr = new StreamReader(openFileDialog.FileName)) { while ((line = sr.ReadLine()) != null) { data.Append(line); } } string beats = data.ToString(); const string pattern = @"(\d*\.\d*)\s(\d*\.\d*)\s(\d)"; MatchCollection matches = Regex.Matches(beats, pattern); int numBeats = Convert.ToInt32(matches.Cast <Match>().Max(x => x.Groups[3].Value)); _beatMarks = new List <MarkCollection>(numBeats); for (int i = 0; i < numBeats; i++) { MarkCollection markscoll = new MarkCollection() { MarkColor = colors[i], Name = string.Format("Audacity Beat {0} Marks", i + 1) }; _beatMarks.Add(markscoll); } foreach (Match match in matches) { TimeSpan time = TimeSpan.FromSeconds(Convert.ToDouble(match.Groups[1].Value)); int beatnumber = Convert.ToInt32(match.Groups[3].Value); _beatMarks[beatnumber - 1].Marks.Add(time); } PopulateMarkListFromMarkCollection(); //UpdateRange(_beatMarks.Count); } catch (Exception ex) { string msg = "There was an error importing the Audacity beat marks: " + ex.Message; MessageBox.Show(msg, @"Audacity Import Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } }
private void LoadBarLabels() { openFileDialog.DefaultExt = ".txt"; openFileDialog.Filter = @"Audacity Bar Labels|*.txt|All Files|*.*"; openFileDialog.FilterIndex = 0; openFileDialog.InitialDirectory = _lastFolder; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _lastFolder = Path.GetDirectoryName(openFileDialog.FileName); try { String everything; using (StreamReader sr = new StreamReader(openFileDialog.FileName)) { everything = sr.ReadToEnd(); } // Remove the \r so we're just left with a \n (allows importing of Sean's Audacity beat marks everything = everything.Replace("\r", ""); string[] lines = everything.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); if (lines.Count() > 0) { _beatMarks = new List <MarkCollection>(1); _barMarks = new MarkCollection() { MarkColor = Color.Yellow, Name = "Audacity Marks" }; foreach (string line in lines) { string mark; if (line.IndexOf("\t") > 0) { mark = line.Split('\t')[0].Trim(); } else { mark = line.Trim().Split(' ')[0].Trim(); } TimeSpan time = TimeSpan.FromSeconds(Convert.ToDouble(mark)); _barMarks.Marks.Add(time); } _beatMarks.Add(_barMarks); PopulateMarkListFromMarkCollection(); } } catch (Exception ex) { string msg = "There was an error importing the Audacity bar marks: " + ex.Message; MessageBox.Show(msg, @"Audacity Import Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } }
public void TestBeatTrackImport() { var colors = new List <Color> { Color.Yellow, Color.Gold, Color.Goldenrod, Color.SaddleBrown, Color.CadetBlue, Color.BlueViolet }; string line; StringBuilder data = new StringBuilder(); using (var sr = new StreamReader(File.Open(@"C:\Users\tony.eberle\Google Drive\Christmas Software\Vixen 2.5.0.9\Data\Beat Tracks\Winter-Wonderland-edit-beat-track.txt", FileMode.Open))) //using (var sr = new StreamReader(File.Open(@"C:\Users\Tony\Google Drive\Christmas Software\xlights show 2013\Jingle Bells Bing Crosby Beat Track.txt", FileMode.Open))) { while ((line = sr.ReadLine()) != null) { data.AppendLine(line); } } string beats = data.ToString(); const string pattern = @"(\d*\.\d*)\s(\d*\.\d*)\s(\d)"; MatchCollection matches = Regex.Matches(beats, pattern); int numBeats = Convert.ToInt32(matches.Cast <Match>().Max(x => x.Groups[3].Value)); var marks = new List <MarkCollection>(numBeats); for (int i = 0; i < numBeats; i++) { MarkCollection markscoll = new MarkCollection(); markscoll.MarkColor = colors[i]; markscoll.Id = i + 1; marks.Add(markscoll); } foreach (Match match in matches) { TimeSpan time = TimeSpan.FromSeconds(Convert.ToDouble(match.Groups[1].Value)); int beatnumber = Convert.ToInt32(match.Groups[3].Value); marks[beatnumber - 1].Marks.Add(time); } float value = (float)23 / 1000; CalculateStuff(marks); figuretime(marks); }
public void TestBarTrackImport() { string line; StringBuilder data = new StringBuilder(); using (var sr = new StreamReader(File.Open(@"C:\Users\tony.eberle\Google Drive\Christmas Software\Vixen 2.5.0.9\Data\Beat Tracks\Winter-Wonderland-edit-beat-track.txt", FileMode.Open))) //using (var sr = new StreamReader(File.Open(@"C:\Users\Tony\Google Drive\Christmas Software\xlights show 2013\Jingle Bells Bing Crosby Bar Track.txt", FileMode.Open))) { while ((line = sr.ReadLine()) != null) { data.AppendLine(line); } } string beats = data.ToString(); // Remove the \r so we're just left with a \n (allows importing of Sean's Audacity beat marks beats = beats.Replace("\r", ""); string[] lines = beats.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); if (lines.Count() > 0) { MarkCollection markscoll = new MarkCollection() { MarkColor = Color.Yellow, Name = "Audacity Marks" }; foreach (string str in lines) { string mark; if (str.IndexOf("\t") > 0) { mark = str.Split('\t')[0].Trim(); } else { mark = str.Trim().Split(' ')[0].Trim(); } TimeSpan time = TimeSpan.FromSeconds(Convert.ToDouble(mark)); markscoll.Marks.Add(time); } } }