Move the creation of the progress dialog for the audio caches to AudioProvider and just pass the BackgroundRunner to the caches. This still isn't the right place to be creating it, but this removes the UI-dependency for both caches.

Originally committed to SVN as r5646.
This commit is contained in:
Thomas Goyne 2011-09-28 19:49:37 +00:00
parent a9dc1f045d
commit dfef9191f9
5 changed files with 32 additions and 20 deletions

View File

@ -52,6 +52,8 @@
#include "audio_provider_pcm.h"
#include "audio_provider_ram.h"
#include "compat.h"
#include "dialog_progress.h"
#include "frame_main.h"
#include "main.h"
/// @brief Constructor
@ -161,11 +163,13 @@ AudioProvider *AudioProviderFactory::GetProvider(wxString filename, int cache) {
return provider;
}
DialogProgress progress(AegisubApp::Get()->frame, _("Load audio"));
// Convert to RAM
if (cache == 1) return new RAMAudioProvider(provider);
if (cache == 1) return new RAMAudioProvider(provider, &progress);
// Convert to HD
if (cache == 2) return new HDAudioProvider(provider);
if (cache == 2) return new HDAudioProvider(provider, &progress);
throw AudioOpenError("Unknown caching method");
}

View File

@ -41,18 +41,16 @@
#include <wx/filename.h>
#endif
#include <libaegisub/background_runner.h>
#include "audio_provider_hd.h"
#include "compat.h"
#include "dialog_progress.h"
#include "frame_main.h"
#include "main.h"
#include "standard_paths.h"
#include "utils.h"
HDAudioProvider::HDAudioProvider(AudioProvider *src) {
HDAudioProvider::HDAudioProvider(AudioProvider *src, agi::BackgroundRunner *br) {
std::auto_ptr<AudioProvider> source(src);
// Copy parameters
bytes_per_sample = source->GetBytesPerSample();
@ -76,8 +74,7 @@ HDAudioProvider::HDAudioProvider(AudioProvider *src) {
file_cache.Open(diskCacheFilename,wxFile::read_write);
if (!file_cache.IsOpened()) throw AudioOpenError("Unable to write to audio disk cache.");
DialogProgress progress(AegisubApp::Get()->frame, "Load audio", "Reading to Hard Disk cache");
progress.Run(bind(&HDAudioProvider::FillCache, this, src, std::tr1::placeholders::_1));
br->Run(bind(&HDAudioProvider::FillCache, this, src, std::tr1::placeholders::_1));
}
HDAudioProvider::~HDAudioProvider() {
@ -87,6 +84,8 @@ HDAudioProvider::~HDAudioProvider() {
}
void HDAudioProvider::FillCache(AudioProvider *src, agi::ProgressSink *ps) {
ps->SetMessage(STD_STR(_("Reading to Hard Disk cache")));
int64_t block = 4096;
data = new char[block * channels * bytes_per_sample];
for (int64_t i = 0; i < num_samples; i += block) {

View File

@ -41,7 +41,10 @@
#include "include/aegisub/audio_provider.h"
namespace agi { class ProgressSink; }
namespace agi {
class BackgroundRunner;
class ProgressSink;
}
/// DOCME
/// @class HDAudioProvider
@ -70,7 +73,7 @@ class HDAudioProvider : public AudioProvider {
void FillCache(AudioProvider *src, agi::ProgressSink *ps);
public:
HDAudioProvider(AudioProvider *source);
HDAudioProvider(AudioProvider *source, agi::BackgroundRunner *br);
~HDAudioProvider();
bool AreSamplesNativeEndian() const { return samples_native_endian; }

View File

@ -36,9 +36,11 @@
#include "config.h"
#include <libaegisub/background_runner.h>
#include "audio_provider_ram.h"
#include "dialog_progress.h"
#include "frame_main.h"
#include "compat.h"
#include "main.h"
#include "utils.h"
@ -46,7 +48,7 @@
#define CacheBlockSize ((1 << CacheBits))
RAMAudioProvider::RAMAudioProvider(AudioProvider *src) {
RAMAudioProvider::RAMAudioProvider(AudioProvider *src, agi::BackgroundRunner *br) {
std::auto_ptr<AudioProvider> source(src);
samples_native_endian = source->AreSamplesNativeEndian();
@ -55,7 +57,7 @@ RAMAudioProvider::RAMAudioProvider(AudioProvider *src) {
int64_t ssize = source->GetNumSamples() * source->GetBytesPerSample();
blockcount = (ssize + CacheBlockSize - 1) >> CacheBits;
blockcache = new char*[blockcount];
memset(blockcache, blockcount * sizeof(char*), 0);
memset(blockcache, 0, blockcount * sizeof(char*));
// Allocate cache blocks
try {
@ -75,8 +77,7 @@ RAMAudioProvider::RAMAudioProvider(AudioProvider *src) {
sample_rate = source->GetSampleRate();
filename = source->GetFilename();
DialogProgress progress(AegisubApp::Get()->frame, _("Load audio"), _("Reading into RAM"));
progress.Run(std::tr1::bind(&RAMAudioProvider::FillCache, this, src, std::tr1::placeholders::_1));
br->Run(std::tr1::bind(&RAMAudioProvider::FillCache, this, src, std::tr1::placeholders::_1));
}
RAMAudioProvider::~RAMAudioProvider() {
@ -84,6 +85,8 @@ RAMAudioProvider::~RAMAudioProvider() {
}
void RAMAudioProvider::FillCache(AudioProvider *source, agi::ProgressSink *ps) {
ps->SetMessage(STD_STR(_("Reading into RAM")));
int64_t readsize = CacheBlockSize / source->GetBytesPerSample();
for (int i = 0; i < blockcount; i++) {
source->GetAudio((char*)blockcache[i], i * readsize, std::min(readsize, num_samples - i * readsize));

View File

@ -36,7 +36,10 @@
#include "include/aegisub/audio_provider.h"
namespace agi { class ProgressSink; }
namespace agi {
class BackgroundRunner;
class ProgressSink;
}
/// DOCME
/// @class RAMAudioProvider
@ -57,7 +60,7 @@ class RAMAudioProvider : public AudioProvider {
void FillCache(AudioProvider *source, agi::ProgressSink *ps);
public:
RAMAudioProvider(AudioProvider *source);
RAMAudioProvider(AudioProvider *source, agi::BackgroundRunner *br);
~RAMAudioProvider();
bool AreSamplesNativeEndian() const { return samples_native_endian; }