mirror of https://github.com/odrling/Aegisub
Slightly simplify parts of AudioDisplay
Originally committed to SVN as r5588.
This commit is contained in:
parent
e5d660e281
commit
3e708eab10
|
@ -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
|
|
||||||
if (new_position != position)
|
|
||||||
{
|
|
||||||
position = new_position;
|
position = new_position;
|
||||||
RecalculateThumb();
|
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,16 +554,11 @@ 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
|
|
||||||
// avoid mutual recursion with the scrollbar and timeline.
|
|
||||||
if (pixel_position != scroll_left)
|
|
||||||
{
|
|
||||||
scroll_left = pixel_position;
|
scroll_left = pixel_position;
|
||||||
scrollbar->SetPosition(scroll_left);
|
scrollbar->SetPosition(scroll_left);
|
||||||
timeline->SetPosition(scroll_left);
|
timeline->SetPosition(scroll_left);
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AudioDisplay::ScrollPixelToCenter(int pixel_position)
|
void AudioDisplay::ScrollPixelToCenter(int pixel_position)
|
||||||
|
@ -757,13 +716,16 @@ float AudioDisplay::GetAmplitudeScale() const
|
||||||
|
|
||||||
void AudioDisplay::ReloadRenderingSettings()
|
void AudioDisplay::ReloadRenderingSettings()
|
||||||
{
|
{
|
||||||
|
if (OPT_GET("Audio/Spectrum")->GetBool())
|
||||||
|
{
|
||||||
|
AudioSpectrumRenderer *audio_spectrum_renderer = new AudioSpectrumRenderer;
|
||||||
|
|
||||||
int64_t spectrum_quality = OPT_GET("Audio/Renderer/Spectrum/Quality")->GetInt();
|
int64_t spectrum_quality = OPT_GET("Audio/Renderer/Spectrum/Quality")->GetInt();
|
||||||
#ifdef WITH_FFTW
|
#ifdef WITH_FFTW
|
||||||
// FFTW is so fast we can afford to upgrade quality by two levels
|
// FFTW is so fast we can afford to upgrade quality by two levels
|
||||||
spectrum_quality += 2;
|
spectrum_quality += 2;
|
||||||
#endif
|
#endif
|
||||||
if (spectrum_quality < 0) spectrum_quality = 0;
|
spectrum_quality = mid(0LL, spectrum_quality, 5LL);
|
||||||
if (spectrum_quality > 5) spectrum_quality = 5;
|
|
||||||
|
|
||||||
// Quality indexes: 0 1 2 3 4 5
|
// Quality indexes: 0 1 2 3 4 5
|
||||||
int spectrum_width[] = {8, 9, 9, 9, 10, 11};
|
int spectrum_width[] = {8, 9, 9, 9, 10, 11};
|
||||||
|
@ -773,12 +735,14 @@ void AudioDisplay::ReloadRenderingSettings()
|
||||||
spectrum_width[spectrum_quality],
|
spectrum_width[spectrum_quality],
|
||||||
spectrum_distance[spectrum_quality]);
|
spectrum_distance[spectrum_quality]);
|
||||||
|
|
||||||
if (OPT_GET("Audio/Spectrum")->GetBool())
|
audio_renderer_provider.reset(audio_spectrum_renderer);
|
||||||
audio_renderer->SetRenderer(audio_spectrum_renderer.get());
|
}
|
||||||
else
|
else
|
||||||
audio_renderer->SetRenderer(audio_waveform_renderer.get());
|
{
|
||||||
|
audio_renderer_provider.reset(new AudioWaveformRenderer);
|
||||||
|
}
|
||||||
|
|
||||||
audio_renderer->Invalidate();
|
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
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue