public void addPlot(PlotEntity entity) { var newIndex = currentListBox.Items.Count; currentListBox.Items.Add(entity.Name); plotEntities.Add(entity); currentListBox.SelectedIndex = newIndex; }
public void build(PlotEntity entity) { plots.Add(entity.BuildData); double fftSpacing = 32000 / entity.BuildData.Length; plot.plt.PlotSignal(entity.BuildData, sampleRate: fftSpacing, markerSize: 0); plot.Render(); }
public async Task <PlotEntity> Save(PlotEntity entity) { Stream myStream; SaveFileDialog saveFileDialog1 = new SaveFileDialog { RestoreDirectory = true }; string str = null; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { if ((myStream = saveFileDialog1.OpenFile()) != null) { TextWriter tw = new StreamWriter(myStream); str = saveFileDialog1.FileName; entity.Name = str; foreach (double s in entity.BuildData) { tw.WriteLine(s.ToString()); } tw.Close(); myStream.Close(); } } progressChanged(this, new PlotEventArgs(10)); DataContractSerializer dcs = new DataContractSerializer(typeof(PlotEntity)); using (Stream stream = new FileStream(str + ".xml", FileMode.Create, FileAccess.Write)) { using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream, Encoding.UTF8)) { writer.WriteStartDocument(); dcs.WriteObject(writer, entity); } } progressChanged(this, new PlotEventArgs(30)); var zipFile = ZipFile.Open(str + ".zip", ZipArchiveMode.Create); progressChanged(this, new PlotEventArgs(40)); zipFile.CreateEntryFromFile(str + ".xml", "meta.xml"); progressChanged(this, new PlotEventArgs(50)); zipFile.CreateEntryFromFile(entity.AudioFilePath, "audio.wav"); progressChanged(this, new PlotEventArgs(70)); zipFile.Dispose(); File.Delete(str); File.Delete(str + ".xml"); File.Delete(entity.AudioFilePath); progressChanged(this, new PlotEventArgs(100)); progressChanged(this, new PlotEventArgs(0)); return(entity); }
public async Task <PlotEntity> Restore() { PlotEntity entity = new PlotEntity(); OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() == DialogResult.Cancel) { return(null); } string filename = openFileDialog1.FileName; using (ZipArchive zip = ZipFile.Open(filename, ZipArchiveMode.Read)) foreach (ZipArchiveEntry entry in zip.Entries) { if (entry.Name == "meta.xml") { entry.ExtractToFile("meta.xml", true); } } progressChanged(this, new PlotEventArgs(10)); DataContractSerializer dcs = new DataContractSerializer(typeof(PlotEntity)); using (Stream stream = new FileStream("meta.xml", FileMode.Open, FileAccess.ReadWrite)) { var xmlQuotas = new XmlDictionaryReaderQuotas(); xmlQuotas.MaxArrayLength = 32768;//extended array length using (XmlDictionaryReader xmlreader = XmlDictionaryReader.CreateTextReader(stream, xmlQuotas)) { entity = (PlotEntity)dcs.ReadObject(xmlreader); } } progressChanged(this, new PlotEventArgs(50)); using (ZipArchive zip = ZipFile.Open(filename, ZipArchiveMode.Read)) foreach (ZipArchiveEntry entry in zip.Entries) { if (entry.Name == "audio.wav") { entity.AudioFilePath = Path.Combine(Path.Combine(Path.GetTempPath(), "Audiofiles"), "audio" + String.Format("{0:dd_mm_yy_hh_mm_ss}", entity.CreationDate)); entry.ExtractToFile(entity.AudioFilePath, true); } } File.Delete("meta.xml"); progressChanged(this, new PlotEventArgs(100)); progressChanged(this, new PlotEventArgs(0)); return(entity); }
private void Stop_btn_Click(object sender, EventArgs e) { var newEntity = new PlotEntity { Name = "unnamed" + String.Format("{0:dd_mm_yy_hh_mm_ss}", DateTime.Now), BuildData = audioProc.GetFft(), AudioFilePath = audioProc.StopRecording(), CreationDate = DateTime.Now, Duration = audioProc.getDuration() }; newEntity.calculatePeakFrequency(); plotList.addPlot(newEntity); plotBuilder.build(newEntity); formLogic.changeState(APP_STATE.Opened); textTimer.stop(); listBox1.Update(); }
public void setCurrentPlot(PlotEntity entity) { plotEntities[currentIndex] = entity; currentListBox.Items[currentIndex] = entity.Name; onIndexChanged(null, null); }