2 #include <boost/bind.hpp>
3 #include <wx/graphics.h>
4 #include "audio_plot.h"
5 #include "lib/decoder_factory.h"
6 #include "lib/audio_decoder.h"
7 #include "lib/audio_analysis.h"
8 #include "wx/wx_util.h"
15 using boost::shared_ptr;
17 AudioPlot::AudioPlot (wxWindow* parent, shared_ptr<AudioAnalysis> a, int c)
22 Connect (wxID_ANY, wxEVT_PAINT, wxPaintEventHandler (AudioPlot::paint), 0, this);
24 SetMinSize (wxSize (640, 512));
28 AudioPlot::paint (wxPaintEvent &)
31 wxGraphicsContext* gc = wxGraphicsContext::Create (dc);
36 int const width = GetSize().GetWidth();
37 float const xs = width / float (_analysis->points (_channel));
38 int const height = GetSize().GetHeight ();
39 float const ys = height / 60;
41 wxGraphicsPath grid = gc->CreatePath ();
42 gc->SetFont (gc->CreateFont (*wxSMALL_FONT));
43 for (int i = -60; i <= 0; i += 10) {
44 int const y = height - (i + 60) * ys;
45 grid.MoveToPoint (0, y);
46 grid.AddLineToPoint (width, y);
47 gc->DrawText (std_to_wx (String::compose ("%1dB", i)), width - 32, y - 12);
49 gc->SetPen (*wxLIGHT_GREY_PEN);
50 gc->StrokePath (grid);
52 wxGraphicsPath path[AudioPoint::COUNT];
54 for (int i = 0; i < AudioPoint::COUNT; ++i) {
55 path[i] = gc->CreatePath ();
56 path[i].MoveToPoint (0, height - (max (_analysis->get_point(_channel, 0)[i], -60.0f) + 60) * ys);
59 for (int i = 0; i < _analysis->points(_channel); ++i) {
60 for (int j = 0; j < AudioPoint::COUNT; ++j) {
61 path[j].AddLineToPoint (i * xs, height - (max (_analysis->get_point(_channel, i)[j], -60.0f) + 60) * ys);
65 gc->SetPen (*wxBLUE_PEN);
66 gc->StrokePath (path[AudioPoint::RMS]);
68 gc->SetPen (*wxRED_PEN);
69 gc->StrokePath (path[AudioPoint::PEAK]);