private static WavechartBox show(String title, bool hold, params Tuple<Signal, int>[] series)
{
WavechartBox form = null;
Thread formThread = null;
AutoResetEvent stopWaitHandle = new AutoResetEvent(false);
formThread = new Thread(() =>
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Show control in a form
form = new WavechartBox();
form.Text = title;
form.formThread = formThread;
if (!String.IsNullOrEmpty(title))
{
form.zedGraphControl.GraphPane.Title.IsVisible = true;
form.zedGraphControl.GraphPane.Title.Text = title;
}
var sequence = new ColorSequenceCollection(series.Length);
for (int i = 0; i < series.Length; i++)
{
var signal = series[i].Item1;
int channel = series[i].Item2;
ComplexSignal complex = signal as ComplexSignal;
if (complex != null && complex.Status != ComplexSignalStatus.Normal)
{
double[] spectrum = Accord.Audio.Tools.GetPowerSpectrum(complex.GetChannel(channel));
double[] frequencies = Accord.Audio.Tools.GetFrequencyVector(signal.Length, signal.SampleRate);
form.series.Add(new LineItem(i.ToString(), frequencies,
spectrum, sequence.GetColor(i), SymbolType.None));
form.zedGraphControl.GraphPane.XAxis.Title.Text = "Frequency";
form.zedGraphControl.GraphPane.YAxis.Title.Text = "Power";
}
else
{
double[] values;
if (signal.Channels == 1)
{
values = signal.ToDouble();
}
else
{
ExtractChannel extract = new ExtractChannel(channel);
values = extract.Apply(signal).ToDouble();
}
form.series.Add(new LineItem(i.ToString(), Vector.Range(0, signal.Length).ToDouble(),
values, sequence.GetColor(i), SymbolType.None));
form.zedGraphControl.GraphPane.XAxis.Title.Text = "Time";
form.zedGraphControl.GraphPane.YAxis.Title.Text = "Amplitude";
}
}
form.zedGraphControl.GraphPane.AxisChange();
stopWaitHandle.Set();
Application.Run(form);
});
formThread.SetApartmentState(ApartmentState.STA);
formThread.Start();
stopWaitHandle.WaitOne();
if (!hold)
formThread.Join();
return form;
}