Make AudioDisplay use scoped_ptr for pointers it owns

Originally committed to SVN as r4905.
This commit is contained in:
Thomas Goyne 2010-12-08 08:09:05 +00:00
parent 7f076bbbc9
commit 5f39b99b78
2 changed files with 20 additions and 35 deletions

View File

@ -536,20 +536,18 @@ public:
AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *_controller)
AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *controller)
: wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS|wxBORDER_SIMPLE)
, audio_renderer(new AudioRenderer)
, audio_spectrum_renderer(new AudioSpectrumRenderer)
, audio_waveform_renderer(new AudioWaveformRenderer)
, provider(0)
, controller(_controller)
, controller(controller)
, scrollbar(new AudioDisplayScrollbar(this))
, timeline(new AudioDisplayTimeline(this))
, dragged_object(0)
, old_selection(0, 0)
{
scrollbar = new AudioDisplayScrollbar(this);
timeline = new AudioDisplayTimeline(this);
audio_renderer = new AudioRenderer;
audio_spectrum_renderer = new AudioSpectrumRenderer;
audio_waveform_renderer = new AudioWaveformRenderer;
scroll_left = 0;
pixel_audio_width = 0;
scale_amplitude = 1.0;
@ -572,13 +570,6 @@ AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *_controller)
AudioDisplay::~AudioDisplay()
{
delete audio_renderer;
delete audio_spectrum_renderer;
delete audio_waveform_renderer;
delete timeline;
delete scrollbar;
controller->RemoveAudioListener(this);
controller->RemoveTimingListener(this);
}
@ -778,9 +769,9 @@ void AudioDisplay::ReloadRenderingSettings()
spectrum_distance[spectrum_quality]);
if (OPT_GET("Audio/Spectrum")->GetBool())
audio_renderer->SetRenderer(audio_spectrum_renderer);
audio_renderer->SetRenderer(audio_spectrum_renderer.get());
else
audio_renderer->SetRenderer(audio_waveform_renderer);
audio_renderer->SetRenderer(audio_waveform_renderer.get());
audio_renderer->Invalidate();
@ -957,9 +948,7 @@ void AudioDisplay::SetDraggedObject(AudioDisplayInteractionObject *new_obj)
{
// Special case for audio markers being dragged: they use a temporary wrapper object
// which must be deleted when it is no longer used.
AudioMarkerInteractionObject *dragged_marker = dynamic_cast<AudioMarkerInteractionObject*>(dragged_object);
if (dragged_marker)
delete dragged_marker;
delete dynamic_cast<AudioMarkerInteractionObject*>(dragged_object);
dragged_object = new_obj;
@ -1090,7 +1079,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event)
if (!controller->IsPlaying())
RemoveTrackCursor();
if (scrollbar->OnMouseEvent(event))
SetDraggedObject(scrollbar);
SetDraggedObject(scrollbar.get());
return;
}
@ -1101,7 +1090,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event)
if (!controller->IsPlaying())
RemoveTrackCursor();
if (timeline->OnMouseEvent(event))
SetDraggedObject(timeline);
SetDraggedObject(timeline.get());
return;
}

View File

@ -46,11 +46,7 @@
#include <wx/window.h>
#endif
#include "selection_controller.h"
#ifndef AGI_AUDIO_CONTROLLER_INCLUDED
#error You must include "audio_controller.h" before "audio_display.h"
#endif
#include <libaegisub/scoped_ptr.h>
class AudioRenderer;
@ -83,7 +79,7 @@ public:
/// @return True to take mouse capture, false to release mouse capture
///
/// Assuming no object has the mouse capture, the audio display uses other methods
/// in the object implementing this interface to deterine whether a mouse event
/// in the object implementing this interface to determine whether a mouse event
/// should go to the object. If the mouse event goes to the object, this method
/// is called.
///
@ -116,13 +112,13 @@ class AudioDisplay: public wxWindow, private AudioControllerAudioEventListener,
private:
/// The audio renderer manager
AudioRenderer *audio_renderer;
agi::scoped_ptr<AudioRenderer> audio_renderer;
/// The renderer for audio spectrums
AudioSpectrumRenderer *audio_spectrum_renderer;
/// The renderer for audio spectra
agi::scoped_ptr<AudioSpectrumRenderer> audio_spectrum_renderer;
/// The renderer for audio waveforms
AudioWaveformRenderer *audio_waveform_renderer;
agi::scoped_ptr<AudioWaveformRenderer> audio_waveform_renderer;
/// Our current audio provider
AudioProvider *provider;
@ -132,10 +128,10 @@ private:
/// Scrollbar helper object
AudioDisplayScrollbar *scrollbar;
agi::scoped_ptr<AudioDisplayScrollbar> scrollbar;
/// Timeline helper object
AudioDisplayTimeline *timeline;
agi::scoped_ptr<AudioDisplayTimeline> timeline;
/// Current object on display being dragged, if any