Slightly simplify parts of AudioDisplay

Originally committed to SVN as r5588.
This commit is contained in:
Thomas Goyne 2011-09-15 05:16:18 +00:00
parent e5d660e281
commit 3e708eab10
4 changed files with 47 additions and 96 deletions

View file

@ -90,18 +90,14 @@ class AudioDisplayScrollbar : public AudioDisplayInteractionObject {
public: public:
AudioDisplayScrollbar(AudioDisplay *_display) AudioDisplayScrollbar(AudioDisplay *display)
: dragging(false) : dragging(false)
, data_length(1) , data_length(1)
, page_length(1) , page_length(1)
, position(0) , position(0)
, sel_start(-1) , sel_start(-1)
, sel_length(0) , sel_length(0)
, display(_display) , display(display)
{
}
virtual ~AudioDisplayScrollbar()
{ {
} }
@ -118,15 +114,9 @@ public:
} }
const wxRect & GetBounds() const const wxRect & GetBounds() const { return bounds; }
{
return bounds;
}
int GetPosition() const int GetPosition() const { return position; }
{
return position;
}
int SetPosition(int new_position) int SetPosition(int new_position)
{ {
@ -137,13 +127,8 @@ public:
if (new_position < 0) if (new_position < 0)
new_position = 0; new_position = 0;
// This check is required to avoid mutual recursion with the display position = new_position;
if (new_position != position) RecalculateThumb();
{
position = new_position;
RecalculateThumb();
display->ScrollPixelToLeft(position);
}
return position; return position;
} }
@ -170,7 +155,7 @@ public:
const int data_length_less_page = data_length - page_length; const int data_length_less_page = data_length - page_length;
const int shaft_length_less_thumb = bounds.width - thumb.width; const int shaft_length_less_thumb = bounds.width - thumb.width;
SetPosition(data_length_less_page * thumb_left / shaft_length_less_thumb); display->ScrollPixelToLeft(data_length_less_page * thumb_left / shaft_length_less_thumb);
dragging = true; dragging = true;
} }
@ -264,10 +249,6 @@ public:
{ {
} }
virtual ~AudioDisplayTimeline()
{
}
int GetHeight() const int GetHeight() const
{ {
int width, height; int width, height;
@ -284,10 +265,7 @@ public:
bounds.y = 0; bounds.y = 0;
} }
const wxRect & GetBounds() const const wxRect & GetBounds() const { return bounds; }
{
return bounds;
}
void ChangeAudio(int64_t new_length, int new_samplerate) void ChangeAudio(int64_t new_length, int new_samplerate)
{ {
@ -339,15 +317,7 @@ public:
void SetPosition(int new_pixel_left) void SetPosition(int new_pixel_left)
{ {
if (new_pixel_left < 0) pixel_left = std::max(new_pixel_left, 0);
new_pixel_left = 0;
if (new_pixel_left != pixel_left)
{
pixel_left = new_pixel_left;
display->ScrollPixelToLeft(pixel_left);
}
} }
bool OnMouseEvent(wxMouseEvent &event) bool OnMouseEvent(wxMouseEvent &event)
@ -359,7 +329,7 @@ public:
} }
else if (event.LeftIsDown()) else if (event.LeftIsDown())
{ {
SetPosition(pixel_left - event.GetPosition().x + drag_lastpos.x); display->ScrollPixelToLeft(pixel_left - event.GetPosition().x + drag_lastpos.x);
drag_lastpos = event.GetPosition(); drag_lastpos = event.GetPosition();
dragging = true; dragging = true;
@ -486,10 +456,6 @@ public:
default_snap = false; default_snap = false;
} }
virtual ~AudioMarkerInteractionObject()
{
}
virtual bool OnMouseEvent(wxMouseEvent &event) virtual bool OnMouseEvent(wxMouseEvent &event)
{ {
if (event.Dragging()) if (event.Dragging())
@ -534,8 +500,6 @@ AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *controller, agi::C
: wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS|wxBORDER_SIMPLE) : wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS|wxBORDER_SIMPLE)
, context(context) , context(context)
, audio_renderer(new AudioRenderer) , audio_renderer(new AudioRenderer)
, audio_spectrum_renderer(new AudioSpectrumRenderer)
, audio_waveform_renderer(new AudioWaveformRenderer)
, provider(0) , provider(0)
, controller(controller) , controller(controller)
, scrollbar(new AudioDisplayScrollbar(this)) , scrollbar(new AudioDisplayScrollbar(this))
@ -590,15 +554,10 @@ void AudioDisplay::ScrollPixelToLeft(int pixel_position)
if (pixel_position < 0) if (pixel_position < 0)
pixel_position = 0; pixel_position = 0;
// This check is required to avoid needless redraws, but more importantly to scroll_left = pixel_position;
// avoid mutual recursion with the scrollbar and timeline. scrollbar->SetPosition(scroll_left);
if (pixel_position != scroll_left) timeline->SetPosition(scroll_left);
{ Refresh();
scroll_left = pixel_position;
scrollbar->SetPosition(scroll_left);
timeline->SetPosition(scroll_left);
Refresh();
}
} }
@ -757,28 +716,33 @@ float AudioDisplay::GetAmplitudeScale() const
void AudioDisplay::ReloadRenderingSettings() void AudioDisplay::ReloadRenderingSettings()
{ {
int64_t spectrum_quality = OPT_GET("Audio/Renderer/Spectrum/Quality")->GetInt();
#ifdef WITH_FFTW
// FFTW is so fast we can afford to upgrade quality by two levels
spectrum_quality += 2;
#endif
if (spectrum_quality < 0) spectrum_quality = 0;
if (spectrum_quality > 5) spectrum_quality = 5;
// Quality indexes: 0 1 2 3 4 5
int spectrum_width[] = {8, 9, 9, 9, 10, 11};
int spectrum_distance[] = {8, 8, 7, 6, 6, 5};
audio_spectrum_renderer->SetResolution(
spectrum_width[spectrum_quality],
spectrum_distance[spectrum_quality]);
if (OPT_GET("Audio/Spectrum")->GetBool()) if (OPT_GET("Audio/Spectrum")->GetBool())
audio_renderer->SetRenderer(audio_spectrum_renderer.get()); {
else AudioSpectrumRenderer *audio_spectrum_renderer = new AudioSpectrumRenderer;
audio_renderer->SetRenderer(audio_waveform_renderer.get());
audio_renderer->Invalidate(); int64_t spectrum_quality = OPT_GET("Audio/Renderer/Spectrum/Quality")->GetInt();
#ifdef WITH_FFTW
// FFTW is so fast we can afford to upgrade quality by two levels
spectrum_quality += 2;
#endif
spectrum_quality = mid(0LL, spectrum_quality, 5LL);
// Quality indexes: 0 1 2 3 4 5
int spectrum_width[] = {8, 9, 9, 9, 10, 11};
int spectrum_distance[] = {8, 8, 7, 6, 6, 5};
audio_spectrum_renderer->SetResolution(
spectrum_width[spectrum_quality],
spectrum_distance[spectrum_quality]);
audio_renderer_provider.reset(audio_spectrum_renderer);
}
else
{
audio_renderer_provider.reset(new AudioWaveformRenderer);
}
audio_renderer->SetRenderer(audio_renderer_provider.get());
Refresh(); Refresh();
} }
@ -1230,13 +1194,11 @@ void AudioDisplay::OnSelectionChanged()
// Only redraw the parts of the selection that changed, to avoid flicker // Only redraw the parts of the selection that changed, to avoid flicker
if (s1 != s2) if (s1 != s2)
{ {
wxRect r(std::min(s1, s2)-10, audio_top, abs(s1-s2)+20, audio_height); RefreshRect(wxRect(std::min(s1, s2)-10, audio_top, abs(s1-s2)+20, audio_height));
RefreshRect(r);
} }
if (e1 != e2) if (e1 != e2)
{ {
wxRect r(std::min(e1, e2)-10, audio_top, abs(e1-e2)+20, audio_height); RefreshRect(wxRect(std::min(e1, e2)-10, audio_top, abs(e1-e2)+20, audio_height));
RefreshRect(r);
} }
} }
else else

View file

@ -50,8 +50,7 @@
namespace agi { struct Context; } namespace agi { struct Context; }
class AudioRenderer; class AudioRenderer;
class AudioSpectrumRenderer; class AudioRendererBitmapProvider;
class AudioWaveformRenderer;
class AudioKaraoke; class AudioKaraoke;
class AudioProvider; class AudioProvider;
@ -106,11 +105,8 @@ private:
/// The audio renderer manager /// The audio renderer manager
agi::scoped_ptr<AudioRenderer> audio_renderer; agi::scoped_ptr<AudioRenderer> audio_renderer;
/// The renderer for audio spectra /// The current audio renderer
agi::scoped_ptr<AudioSpectrumRenderer> audio_spectrum_renderer; agi::scoped_ptr<AudioRendererBitmapProvider> audio_renderer_provider;
/// The renderer for audio waveforms
agi::scoped_ptr<AudioWaveformRenderer> audio_waveform_renderer;
/// Our current audio provider /// Our current audio provider
AudioProvider *provider; AudioProvider *provider;
@ -191,9 +187,9 @@ private:
void OnKeyDown(wxKeyEvent& event); void OnKeyDown(wxKeyEvent& event);
// AudioControllerAudioEventListener implementation // AudioControllerAudioEventListener implementation
virtual void OnAudioOpen(AudioProvider *provider); void OnAudioOpen(AudioProvider *provider);
virtual void OnPlaybackPosition(int64_t sample_position); void OnPlaybackPosition(int64_t sample_position);
virtual void OnSelectionChanged(); void OnSelectionChanged();
void OnMarkerMoved(); void OnMarkerMoved();
public: public:

View file

@ -140,9 +140,6 @@ void AudioRenderer::SetRenderer(AudioRendererBitmapProvider *_renderer)
{ {
if (renderer == _renderer) return; if (renderer == _renderer) return;
if (renderer)
renderer->SetProvider(0);
renderer = _renderer; renderer = _renderer;
Invalidate(); Invalidate();

View file

@ -207,10 +207,6 @@ public:
/// can be functional. /// can be functional.
/// ///
/// Changing renderer invalidates all cached bitmaps. /// Changing renderer invalidates all cached bitmaps.
///
/// The old renderer will have its audio provider reset to 0 and the new renderer will
/// have its audio provider set to the current. This is done in part to ensure that
/// the renderers have any internal caches cleared.
void SetRenderer(AudioRendererBitmapProvider *renderer); void SetRenderer(AudioRendererBitmapProvider *renderer);
/// @brief Change audio provider /// @brief Change audio provider