Don't get the duration from the audio controller on audio open

The audio controller's provider may not have been updated yet.
This commit is contained in:
Thomas Goyne 2014-05-26 09:14:51 -07:00
parent cca97a58f6
commit 960dc3723b
3 changed files with 14 additions and 7 deletions

View file

@ -115,6 +115,10 @@ class AudioController final : public wxEvtHandler {
/// @return The index of the first sample that is wholly inside the millisecond
int64_t SamplesFromMilliseconds(int64_t ms) const;
/// Get the duration of the currently open audio in milliseconds, or 0 if none
/// @return Duration in milliseconds
int GetDuration() const;
public:
AudioController(agi::Context *context);
~AudioController();
@ -161,10 +165,6 @@ public:
/// Returns 0 if playback is stopped. The return value is only approximate.
int GetPlaybackPosition();
/// Get the duration of the currently open audio in milliseconds, or 0 if none
/// @return Duration in milliseconds
int GetDuration() const;
/// @brief Get the primary playback range
/// @return An immutable TimeRange object
TimeRange GetPrimaryPlaybackRange() const;

View file

@ -655,7 +655,7 @@ void AudioDisplay::SetZoomLevel(int new_zoom_level)
double cursor_time = (scroll_left + cursor_pos) * ms_per_pixel;
ms_per_pixel = new_ms_per_pixel;
pixel_audio_width = std::max(1, int(controller->GetDuration() / ms_per_pixel));
pixel_audio_width = std::max(1, int(GetDuration() / ms_per_pixel));
audio_renderer->SetMillisecondsPerPixel(ms_per_pixel);
scrollbar->ChangeLengths(pixel_audio_width, client_width);
@ -1164,6 +1164,12 @@ void AudioDisplay::OnFocus(wxFocusEvent &)
RefreshRect(scrollbar->GetBounds(), false);
}
int AudioDisplay::GetDuration() const
{
if (!provider) return 0;
return (provider->GetNumSamples() * 1000 + provider->GetSampleRate() - 1) / provider->GetSampleRate();
}
void AudioDisplay::OnAudioOpen(AudioProvider *provider)
{
this->provider = provider;
@ -1174,7 +1180,7 @@ void AudioDisplay::OnAudioOpen(AudioProvider *provider)
audio_renderer->SetAudioProvider(provider);
audio_renderer->SetCacheMaxSize(OPT_GET("Audio/Renderer/Spectrum/Memory Max")->GetInt() * 1024 * 1024);
timeline->ChangeAudio(controller->GetDuration());
timeline->ChangeAudio(GetDuration());
ms_per_pixel = 0;
SetZoomLevel(zoom_level);

View file

@ -228,7 +228,8 @@ class AudioDisplay: public wxWindow {
void OnMouseEnter(wxMouseEvent&);
void OnMouseLeave(wxMouseEvent&);
// AudioControllerAudioEventListener implementation
int GetDuration() const;
void OnAudioOpen(AudioProvider *provider);
void OnPlaybackPosition(int ms_position);
void OnSelectionChanged();