forked from mia/Aegisub
Add progress support back to HD Audio Cache with the new ProgressSink from libaegisub. Currently AudioProviderFactory::GetProvider() takes the ProgressSinkFactory however this should probably be moved up to the constructor for AudioProviderFactory. We'll see what the best option is when the others come around it's trivial to change.
Originally committed to SVN as r5347.
This commit is contained in:
parent
8240d3e6b6
commit
c0cf0c6a06
4 changed files with 16 additions and 20 deletions
26
aegisub/libmedia/cache/audio_hd.cpp
vendored
26
aegisub/libmedia/cache/audio_hd.cpp
vendored
|
@ -37,26 +37,19 @@
|
|||
#include "config.h"
|
||||
|
||||
#ifndef AGI_PRE
|
||||
//#include <wx/filefn.h>
|
||||
//#include <wx/filename.h>
|
||||
#endif
|
||||
|
||||
#include "audio_hd.h"
|
||||
//#include "compat.h"
|
||||
//#include "dialog_progress.h"
|
||||
//#include "frame_main.h"
|
||||
//#include "main.h"
|
||||
//#include "standard_paths.h"
|
||||
//#include "utils.h"
|
||||
|
||||
#include <libaegisub/io.h>
|
||||
|
||||
#include "audio_hd.h"
|
||||
|
||||
|
||||
namespace media {
|
||||
|
||||
/// @brief Constructor
|
||||
/// @param source
|
||||
///
|
||||
HDAudioProvider::HDAudioProvider(AudioProvider *src) {
|
||||
HDAudioProvider::HDAudioProvider(AudioProvider *src, agi::ProgressSinkFactory *progress_factory) {
|
||||
std::auto_ptr<AudioProvider> source(src);
|
||||
// Copy parameters
|
||||
bytes_per_sample = source->GetBytesPerSample();
|
||||
|
@ -84,9 +77,9 @@ HDAudioProvider::HDAudioProvider(AudioProvider *src) {
|
|||
if (!file_cache.is_open()) throw AudioOpenError("Unable to write to audio disk cache.");
|
||||
|
||||
// Start progress
|
||||
volatile bool canceled = false;
|
||||
// DialogProgress *progress = new DialogProgress(AegisubApp::Get()->frame,_T("Load audio"),&canceled,_T("Reading to Hard Disk cache"),0,num_samples);
|
||||
// progress->Show();
|
||||
ProgressSink *progress = progress_factory->create_progress_sink("Reading to Hard Disk cache");
|
||||
|
||||
volatile bool canceled = progress->get_cancelled();
|
||||
|
||||
// Write to disk
|
||||
int block = 4096;
|
||||
|
@ -95,7 +88,7 @@ HDAudioProvider::HDAudioProvider(AudioProvider *src) {
|
|||
if (block+i > num_samples) block = num_samples - i;
|
||||
source->GetAudio(data,i,block);
|
||||
file_cache.write(data,block * channels * bytes_per_sample);
|
||||
// progress->SetProgress(i,num_samples);
|
||||
progress->set_progress(i,num_samples);
|
||||
}
|
||||
file_cache.seekp(0);
|
||||
|
||||
|
@ -105,7 +98,8 @@ HDAudioProvider::HDAudioProvider(AudioProvider *src) {
|
|||
delete[] data;
|
||||
throw agi::UserCancelException("Audio loading cancelled by user");
|
||||
}
|
||||
// progress->Destroy();
|
||||
|
||||
delete progress;
|
||||
}
|
||||
|
||||
/// @brief Destructor
|
||||
|
|
3
aegisub/libmedia/cache/audio_hd.h
vendored
3
aegisub/libmedia/cache/audio_hd.h
vendored
|
@ -38,6 +38,7 @@
|
|||
#endif
|
||||
|
||||
#include <libaegisub/mutex.h>
|
||||
|
||||
#include "libmedia/audio.h"
|
||||
|
||||
namespace media {
|
||||
|
@ -66,7 +67,7 @@ class HDAudioProvider : public AudioProvider {
|
|||
static std::string DiskCacheName();
|
||||
|
||||
public:
|
||||
HDAudioProvider(AudioProvider *source);
|
||||
HDAudioProvider(AudioProvider *source, agi::ProgressSinkFactory *progress_factory);
|
||||
~HDAudioProvider();
|
||||
|
||||
bool AreSamplesNativeEndian() const { return samples_native_endian; }
|
||||
|
|
|
@ -108,7 +108,7 @@ void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count,
|
|||
/// @param cache
|
||||
/// @return
|
||||
///
|
||||
AudioProvider *AudioProviderFactory::GetProvider(std::string filename, int cache) {
|
||||
AudioProvider *AudioProviderFactory::GetProvider(std::string filename, agi::ProgressSinkFactory *progress_factory, int cache) {
|
||||
AudioProvider *provider = NULL;
|
||||
bool found = false;
|
||||
std::string msg;
|
||||
|
@ -172,7 +172,7 @@ AudioProvider *AudioProviderFactory::GetProvider(std::string filename, int cache
|
|||
if (cache == 1) return new RAMAudioProvider(provider);
|
||||
|
||||
// Convert to HD
|
||||
if (cache == 2) return new HDAudioProvider(provider);
|
||||
if (cache == 2) return new HDAudioProvider(provider, progress_factory);
|
||||
|
||||
throw AudioOpenError("Unknown caching method");
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <libaegisub/exception.h>
|
||||
#include <libaegisub/progress.h>
|
||||
#include <libmedia/factory_manager.h>
|
||||
|
||||
namespace media {
|
||||
|
@ -98,7 +99,7 @@ public:
|
|||
class AudioProviderFactory : public Factory1<AudioProvider, std::string> {
|
||||
public:
|
||||
static void RegisterProviders();
|
||||
static AudioProvider *GetProvider(std::string filename, int cache=-1);
|
||||
static AudioProvider *GetProvider(std::string filename, agi::ProgressSinkFactory *progress_factory, int cache=-1);
|
||||
};
|
||||
|
||||
DEFINE_BASE_EXCEPTION_NOINNER(AudioProviderError, agi::Exception);
|
||||
|
|
Loading…
Reference in a new issue