mirror of
https://github.com/alexkay/spek.git
synced 2025-06-09 20:02:19 +03:00
Draw the spectrogram
This commit is contained in:
parent
f81ce84826
commit
98b2cb0ab8
@ -115,6 +115,8 @@ struct spek_pipeline * spek_pipeline_open(
|
|||||||
p->output = malloc(bands * sizeof(float));
|
p->output = malloc(bands * sizeof(float));
|
||||||
spek_audio_start(p->cx, samples);
|
spek_audio_start(p->cx, samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct spek_audio_properties * spek_pipeline_properties(struct spek_pipeline *pipeline)
|
const struct spek_audio_properties * spek_pipeline_properties(struct spek_pipeline *pipeline)
|
||||||
@ -124,7 +126,7 @@ const struct spek_audio_properties * spek_pipeline_properties(struct spek_pipeli
|
|||||||
|
|
||||||
void spek_pipeline_start(struct spek_pipeline *p)
|
void spek_pipeline_start(struct spek_pipeline *p)
|
||||||
{
|
{
|
||||||
if (!p->properties->error) return;
|
if (p->properties->error) return;
|
||||||
|
|
||||||
p->input_pos = 0;
|
p->input_pos = 0;
|
||||||
p->worker_done = false;
|
p->worker_done = false;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
BEGIN_EVENT_TABLE(SpekSpectrogram, wxPanel)
|
BEGIN_EVENT_TABLE(SpekSpectrogram, wxPanel)
|
||||||
EVT_PAINT(SpekSpectrogram::on_paint)
|
EVT_PAINT(SpekSpectrogram::on_paint)
|
||||||
|
EVT_SIZE(SpekSpectrogram::on_size)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -45,7 +46,8 @@ SpekSpectrogram::SpekSpectrogram(wxFrame *parent) :
|
|||||||
wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE),
|
wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE),
|
||||||
pipeline(NULL),
|
pipeline(NULL),
|
||||||
palette(RULER, BANDS),
|
palette(RULER, BANDS),
|
||||||
image()
|
image(1, 1),
|
||||||
|
prev_width(-1)
|
||||||
{
|
{
|
||||||
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
|
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
|
||||||
|
|
||||||
@ -77,6 +79,17 @@ void SpekSpectrogram::on_paint(wxPaintEvent& evt)
|
|||||||
render(dc);
|
render(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpekSpectrogram::on_size(wxSizeEvent& evt)
|
||||||
|
{
|
||||||
|
wxSize size = GetClientSize();
|
||||||
|
bool width_changed = this->prev_width != size.GetWidth();
|
||||||
|
this->prev_width = size.GetWidth();
|
||||||
|
|
||||||
|
if (!this->path.IsEmpty() && width_changed) {
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SpekSpectrogram::render(wxDC& dc)
|
void SpekSpectrogram::render(wxDC& dc)
|
||||||
{
|
{
|
||||||
wxSize size = GetClientSize();
|
wxSize size = GetClientSize();
|
||||||
@ -119,6 +132,12 @@ void SpekSpectrogram::render(wxDC& dc)
|
|||||||
TPAD - 2 * GAP - 2 * normal_height
|
TPAD - 2 * GAP - 2 * normal_height
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this->image.GetHeight() > 1) {
|
||||||
|
// Draw the spectrogram.
|
||||||
|
wxBitmap bmp(this->image.Scale(w - LPAD - RPAD, h - TPAD - BPAD /*TODO:, wxIMAGE_QUALITY_HIGH*/));
|
||||||
|
dc.DrawBitmap(bmp, LPAD, TPAD);
|
||||||
|
}
|
||||||
|
|
||||||
// Border around the spectrogram.
|
// Border around the spectrogram.
|
||||||
// TODO: check if this uses antialiasing
|
// TODO: check if this uses antialiasing
|
||||||
dc.DrawRectangle(LPAD, TPAD, w - LPAD - RPAD, h - TPAD - BPAD);
|
dc.DrawRectangle(LPAD, TPAD, w - LPAD - RPAD, h - TPAD - BPAD);
|
||||||
@ -139,20 +158,20 @@ void SpekSpectrogram::pipeline_cb(int sample, float *values, void *cb_data)
|
|||||||
uint32_t color = get_color(level);
|
uint32_t color = get_color(level);
|
||||||
s->image.SetRGB(
|
s->image.SetRGB(
|
||||||
sample,
|
sample,
|
||||||
y,
|
BANDS - y - 1,
|
||||||
color >> 16,
|
color >> 16,
|
||||||
(color >> 8) & 0xFF,
|
(color >> 8) & 0xFF,
|
||||||
color & 0xFF
|
color & 0xFF
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
s->Refresh(false); // TODO: refresh only one pixel column
|
s->Refresh(); // TODO: refresh only one pixel column
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SpekSpectrogram::start()
|
void SpekSpectrogram::start()
|
||||||
{
|
{
|
||||||
if(this->pipeline) {
|
if (this->pipeline) {
|
||||||
spek_pipeline_close(this->pipeline);
|
spek_pipeline_close(this->pipeline);
|
||||||
this->pipeline = NULL;
|
this->pipeline = NULL;
|
||||||
}
|
}
|
||||||
@ -178,7 +197,7 @@ void SpekSpectrogram::start()
|
|||||||
this->image.Create(1, 1);
|
this->image.Create(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh(false);
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modified version of Dan Bruton's algorithm:
|
// Modified version of Dan Bruton's algorithm:
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void on_paint(wxPaintEvent& evt);
|
void on_paint(wxPaintEvent& evt);
|
||||||
|
void on_size(wxSizeEvent& evt);
|
||||||
void render(wxDC& dc);
|
void render(wxDC& dc);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
@ -43,6 +44,7 @@ private:
|
|||||||
wxString desc;
|
wxString desc;
|
||||||
wxImage palette;
|
wxImage palette;
|
||||||
wxImage image;
|
wxImage image;
|
||||||
|
int prev_width;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
@ -36,18 +36,6 @@ namespace Spek {
|
|||||||
surface.write_to_png (file_name);
|
surface.write_to_png (file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int prev_width = -1;
|
|
||||||
protected override void size_allocate (Gdk.Rectangle allocation) {
|
|
||||||
base.size_allocate (allocation);
|
|
||||||
|
|
||||||
bool width_changed = prev_width != allocation.width;
|
|
||||||
prev_width = allocation.width;
|
|
||||||
|
|
||||||
if (file_name != null && width_changed) {
|
|
||||||
start ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool expose_event (EventExpose event) {
|
protected override bool expose_event (EventExpose event) {
|
||||||
var window = get_window ();
|
var window = get_window ();
|
||||||
var cr = cairo_create (window);
|
var cr = cairo_create (window);
|
||||||
@ -64,13 +52,6 @@ namespace Spek {
|
|||||||
int text_width, text_height;
|
int text_width, text_height;
|
||||||
|
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
// Draw the spectrogram.
|
|
||||||
cr.translate (LPAD, h - BPAD);
|
|
||||||
cr.scale (1, -(h - TPAD - BPAD) / image.get_height ());
|
|
||||||
cr.set_source_surface (image, 0, 0);
|
|
||||||
cr.paint ();
|
|
||||||
cr.identity_matrix ();
|
|
||||||
|
|
||||||
// Prepare to draw the rulers.
|
// Prepare to draw the rulers.
|
||||||
cr.set_source_rgb (1, 1, 1);
|
cr.set_source_rgb (1, 1, 1);
|
||||||
cr.set_line_width (1);
|
cr.set_line_width (1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user