Modified all providers to separate them between factory and factory manager. This will make plugin system easier. Also, made hunspell register manually as well.

Originally committed to SVN as r1946.
This commit is contained in:
Rodrigo Braz Monteiro 2008-03-07 02:32:29 +00:00
parent 6bdee2a765
commit 974efa126b
29 changed files with 325 additions and 135 deletions

View file

@ -878,15 +878,15 @@ void AudioDisplay::SetFile(wxString file) {
is_dummy = true;
provider = new DummyAudioProvider(150*60*1000, true); // 150 minutes noise
} else {
provider = AudioProviderFactory::GetAudioProvider(file);
provider = AudioProviderFactoryManager::GetAudioProvider(file);
}
#else
provider = AudioProviderFactory::GetAudioProvider(file);
provider = AudioProviderFactoryManager::GetAudioProvider(file);
#endif
// Get player
wxLogDebug(_T("AudioDisplay::SetFile: get audio player"));
player = AudioPlayerFactory::GetAudioPlayer();
player = AudioPlayerFactoryManager::GetAudioPlayer();
player->SetDisplayTimer(&UpdateTimer);
player->SetProvider(provider);
player->OpenStream();
@ -1022,12 +1022,12 @@ void AudioDisplay::Play(int start,int end) {
try {
// Get provider
if (!VideoContext::Get()->videoName.StartsWith(_T("?dummy")))
provider = AudioProviderFactory::GetAudioProvider(VideoContext::Get()->videoName, 0);
provider = AudioProviderFactoryManager::GetAudioProvider(VideoContext::Get()->videoName, 0);
else
return;
// Get player
player = AudioPlayerFactory::GetAudioPlayer();
player = AudioPlayerFactoryManager::GetAudioPlayer();
player->SetDisplayTimer(&UpdateTimer);
player->SetProvider(provider);
player->OpenStream();

View file

@ -126,7 +126,7 @@ void AudioPlayer::OnStopAudio(wxCommandEvent &event) {
//////////////
// Get player
AudioPlayer* AudioPlayerFactory::GetAudioPlayer() {
AudioPlayer* AudioPlayerFactoryManager::GetAudioPlayer() {
// List of providers
wxArrayString list = GetFactoryList(Options.AsText(_T("Audio player")));
@ -152,26 +152,26 @@ AudioPlayer* AudioPlayerFactory::GetAudioPlayer() {
//////////////////////////
// Register all factories
void AudioPlayerFactory::RegisterProviders() {
void AudioPlayerFactoryManager::RegisterProviders() {
#ifdef WITH_ALSA
new AlsaPlayerFactory();
RegisterFactory(new AlsaPlayerFactory(),_T("ALSA"));
#endif
#ifdef WITH_DIRECTSOUND
new DirectSoundPlayerFactory();
RegisterFactory(new DirectSoundPlayerFactory(),_T("DirectSound"));
#endif
#ifdef WITH_OPENAL
new OpenALPlayerFactory();
RegisterFactory(new OpenALPlayerFactory(),_T("OpenAL"));
#endif
#ifdef WITH_PORTAUDIO
new PortAudioPlayerFactory();
RegisterFactory(new PortAudioPlayerFactory(),_T("PortAudio"));
#endif
#ifdef WITH_PULSEAUDIO
new PulseAudioPlayerFactory();
RegisterFactory(new PulseAudioPlayerFactory(),_T("PulseAudio"));
#endif
}
//////////
// Static
template <class AudioPlayerFactory> std::map<wxString,AudioPlayerFactory*>* AegisubFactory<AudioPlayerFactory>::factories=NULL;
template <class AudioPlayerFactory> std::map<wxString,AudioPlayerFactory*>* FactoryManager<AudioPlayerFactory>::factories=NULL;

View file

@ -44,7 +44,7 @@
#include <wx/timer.h>
#include <wx/thread.h>
#include <stdint.h>
#include "factory.h"
#include "factory_manager.h"
//////////////
@ -96,18 +96,22 @@ public:
///////////
// Factory
class AudioPlayerFactory : public AegisubFactory<AudioPlayerFactory> {
protected:
virtual AudioPlayer *CreatePlayer()=0;
AudioPlayerFactory(wxString name) { RegisterFactory(name); }
class AudioPlayerFactory {
public:
virtual AudioPlayer *CreatePlayer()=0;
};
///////////////////
// Factory Manager
class AudioPlayerFactoryManager : public FactoryManager<AudioPlayerFactory> {
public:
virtual ~AudioPlayerFactory() {}
static AudioPlayer *GetAudioPlayer();
static void RegisterProviders();
};
/////////
// Event
DECLARE_EVENT_TYPE(wxEVT_STOP_AUDIO, -1)

View file

@ -137,7 +137,6 @@ public:
class DirectSoundPlayerFactory : public AudioPlayerFactory {
public:
AudioPlayer *CreatePlayer() { return new DirectSoundPlayer(); }
DirectSoundPlayerFactory() : AudioPlayerFactory(_T("dsound")) {}
};
#endif

View file

@ -191,7 +191,7 @@ void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count,
////////////////
// Get provider
AudioProvider *AudioProviderFactory::GetAudioProvider(wxString filename, int cache) {
AudioProvider *AudioProviderFactoryManager::GetAudioProvider(wxString filename, int cache) {
// Prepare provider
AudioProvider *provider = NULL;
@ -254,16 +254,16 @@ AudioProvider *AudioProviderFactory::GetAudioProvider(wxString filename, int cac
///////////////////////////
// Register all providers
void AudioProviderFactory::RegisterProviders() {
void AudioProviderFactoryManager::RegisterProviders() {
#ifdef WITH_AVISYNTH
new AvisynthAudioProviderFactory();
RegisterFactory(new AvisynthAudioProviderFactory(),_T("Avisynth"));
#endif
#ifdef WITH_FFMPEG
new LAVCAudioProviderFactory();
RegisterFactory(new LAVCAudioProviderFactory(),_T("FFMPEG"));
#endif
}
//////////
// Static
template <class AudioProviderFactory> std::map<wxString,AudioProviderFactory*>* AegisubFactory<AudioProviderFactory>::factories=NULL;
template <class AudioProviderFactory> std::map<wxString,AudioProviderFactory*>* FactoryManager<AudioProviderFactory>::factories=NULL;

View file

@ -41,7 +41,7 @@
// Headers
#include <wx/wxprec.h>
#include <stdint.h>
#include "factory.h"
#include "factory_manager.h"
//////////////
@ -84,13 +84,16 @@ public:
///////////
// Factory
class AudioProviderFactory : public AegisubFactory<AudioProviderFactory> {
protected:
virtual AudioProvider *CreateProvider(wxString filename)=0;
AudioProviderFactory(wxString name) { RegisterFactory(name); }
class AudioProviderFactory {
public:
virtual ~AudioProviderFactory() {}
static AudioProvider *GetAudioProvider(wxString filename, int cache=-1);
static void RegisterProviders();
virtual AudioProvider *CreateProvider(wxString filename)=0;
};
///////////////////
// Factory Manager
class AudioProviderFactoryManager : public FactoryManager<AudioProviderFactory> {
public:
static void RegisterProviders();
static AudioProvider *GetAudioProvider(wxString filename, int cache=-1);
};

View file

@ -71,7 +71,6 @@ public:
class AvisynthAudioProviderFactory : public AudioProviderFactory {
public:
AudioProvider *CreateProvider(wxString file) { return new AvisynthAudioProvider(file); }
AvisynthAudioProviderFactory() : AudioProviderFactory(_T("avisynth")) {}
};
#endif

View file

@ -390,12 +390,12 @@ DialogOptions::DialogOptions(wxWindow *parent)
// Second sizer
videoSizer4->Add(new wxStaticText(videoPage,-1,_("Video provider: ")),0,wxALIGN_CENTER_VERTICAL | wxRIGHT,10);
wxArrayString choices4 = VideoProviderFactory::GetFactoryList();
wxArrayString choices4 = VideoProviderFactoryManager::GetFactoryList();
control = new wxComboBox(videoPage,-1,_T(""),wxDefaultPosition,wxDefaultSize,choices4,wxCB_DROPDOWN | wxCB_READONLY);
Bind(control,_T("Video provider"),1);
videoSizer4->Add(control,1,wxEXPAND);
videoSizer4->Add(new wxStaticText(videoPage,-1,_("Subtitles provider: ")),0,wxALIGN_CENTER_VERTICAL | wxRIGHT,10);
wxArrayString choices5 = SubtitlesProviderFactory::GetFactoryList();
wxArrayString choices5 = SubtitlesProviderFactoryManager::GetFactoryList();
control = new wxComboBox(videoPage,-1,_T(""),wxDefaultPosition,wxDefaultSize,choices5,wxCB_DROPDOWN | wxCB_READONLY);
Bind(control,_T("Subtitles provider"),1);
videoSizer4->Add(control,1,wxEXPAND);
@ -529,8 +529,8 @@ DialogOptions::DialogOptions(wxWindow *parent)
wxString choices3[3] = { _T("ConvertToMono"), _T("GetLeftChannel"), _T("GetRightChannel") };
#endif
AddComboControl(audioAdvPage,audioAdvSizer1,_("Audio provider"),_T("Audio Provider"),AudioProviderFactory::GetFactoryList(),true,1);
AddComboControl(audioAdvPage,audioAdvSizer1,_("Audio player"),_T("Audio Player"),AudioPlayerFactory::GetFactoryList(),true,1);
AddComboControl(audioAdvPage,audioAdvSizer1,_("Audio provider"),_T("Audio Provider"),AudioProviderFactoryManager::GetFactoryList(),true,1);
AddComboControl(audioAdvPage,audioAdvSizer1,_("Audio player"),_T("Audio Player"),AudioPlayerFactoryManager::GetFactoryList(),true,1);
AddComboControl(audioAdvPage,audioAdvSizer1,_("Cache type"),_T("Audio Cache"),wxArrayString(3,choices2),true);
#ifdef WIN32
AddComboControl(audioAdvPage,audioAdvSizer1,_("Avisynth down-mixer"),_T("Audio Downmixer"),wxArrayString(3,choices3),false);

View file

@ -70,7 +70,7 @@ DialogSpellChecker::DialogSpellChecker(wxFrame *parent)
SetIcon(BitmapToIcon(wxBITMAP(spellcheck_toolbutton)));
// Get spell checker
spellchecker = SpellCheckerFactory::GetSpellChecker();
spellchecker = SpellCheckerFactoryManager::GetSpellChecker();
if (!spellchecker) {
wxMessageBox(_T("No spellchecker available."),_T("Error"),wxICON_ERROR);
Destroy();

View file

@ -299,7 +299,7 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit
// Preview
SubsPreview = NULL;
PreviewText = NULL;
if (SubtitlesProviderFactory::ProviderAvailable()) {
if (SubtitlesProviderFactoryManager::ProviderAvailable()) {
PreviewText = new wxTextCtrl(this,TEXT_PREVIEW,Options.AsText(_T("Style editor preview text")));
previewButton = new ColourButton(this,BUTTON_PREVIEW_COLOR,wxSize(45,16),Options.AsColour(_T("Style editor preview background")));
SubsPreview = new SubtitlesPreview(this,-1,wxDefaultPosition,wxSize(100,60),wxSUNKEN_BORDER,Options.AsColour(_T("Style editor preview background")));

107
aegisub/factory_manager.h Normal file
View file

@ -0,0 +1,107 @@
// Copyright (c) 2007-2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
///////////
// Headers
#include <map>
#include <wx/string.h>
#include <wx/arrstr.h>
/////////////////
// Factory class
template <class T>
class FactoryManager {
protected:
// Static map of all factories
static std::map<wxString,T*> *factories;
// Register one factory type (with possible subtypes)
static void RegisterFactory(T* factory,wxString name, wxArrayString subTypes=wxArrayString()) {
// Create factories if it doesn't exist
if (factories == NULL) factories = new std::map<wxString,T*>;
// Prepare subtypes
if (subTypes.GetCount() == 0) subTypes.Add(_T(""));
else {
for (unsigned int i=0;i<subTypes.GetCount();i++) {
subTypes[i] = _T("/") + subTypes[i];
}
}
// Insert each subtype
for (unsigned int i=0;i<subTypes.GetCount();i++) {
factories->insert(std::make_pair(name.Lower() + subTypes[i],factory));
}
}
// Get a factory with name
static T *GetFactory(wxString name) {
// No factories
if (factories == NULL) {
factories = new std::map<wxString,T*>;
return NULL;
}
// Search for factory that matches
typename std::map<wxString,T*>::iterator cur;
for (cur = factories->begin();cur != factories->end();cur++) {
if (cur->first.StartsWith(name)) return cur->second;
}
// None found
return NULL;
}
public:
// Virtual destructor
virtual ~FactoryManager() {}
// Get list of all factories, with favourite as first
static wxArrayString GetFactoryList(wxString favourite=_T("")) {
if (factories == NULL) factories = new std::map<wxString,T*>;
wxArrayString list;
favourite = favourite.Lower();
for (typename std::map<wxString,T*>::iterator cur=factories->begin();cur!=factories->end();cur++) {
if (cur->first == favourite) list.Insert(cur->first,0);
else list.Add(cur->first);
}
return list;
}
};

View file

@ -160,7 +160,11 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) {
SetModificationType(MOD_VIDEO_RELOAD);
SetInt(_T("Avisynth MemoryMax"),64,1700);
SetBool(_T("Threaded Video"),false,1700);
#ifdef __WINDOWS__
SetText(_T("Video Provider"),_T("Avisynth"),1700);
#else
SetText(_T("Video Provider"),_T("FFMPEG"),1945);
#endif
SetBool(_T("Allow Ancient Avisynth"),false,1700);
SetText(_T("Avisynth subs renderer"),_T("vsfilter"),1700);
SetBool(_T("Avisynth render own subs"),true,1700);
@ -190,13 +194,15 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) {
SetModificationType(MOD_AUDIO_RELOAD);
SetInt(_T("Audio Cache"),1,1700);
#if defined(__WINDOWS__)
SetText(_T("Audio Player"),_T("dsound"),1700);
SetText(_T("Audio Player"),_T("DirectSound"),1945);
SetText(_T("Audio Provider"),_T("avisynth"),1700);
#elif defined(__APPLE__)
SetText(_T("Audio Player"), _T("openal"));
SetText(_T("Audio Provider"),_T("FFMPEG"),1945);
#else
SetText(_T("Audio Player"),_T("portaudio")); // FIXME: should this be something else? perhaps alsa on linux and portaudio on everything else?
SetText(_T("Audio Provider"),_T("FFMPEG"),1945);
#endif
SetText(_T("Audio Provider"),_T("avisynth"),1700); // TODO: proper default on non-windows
SetText(_T("Audio Downmixer"),_T("ConvertToMono"),1700);
SetText(_T("Audio Alsa Device"), _T("plughw:0,0"));
SetText(_T("Audio HD Cache Location"),_T("default"),1700);

View file

@ -41,6 +41,7 @@
#include "audio_provider.h"
#include "audio_player.h"
#include "subtitles_provider.h"
#include "spellchecker.h"
///////////////
@ -60,10 +61,11 @@ PluginManager::~PluginManager() {
// Registers all built-in plugins
void PluginManager::RegisterBuiltInPlugins() {
if (!init) {
VideoProviderFactory::RegisterProviders();
AudioProviderFactory::RegisterProviders();
AudioPlayerFactory::RegisterProviders();
SubtitlesProviderFactory::RegisterProviders();
VideoProviderFactoryManager::RegisterProviders();
AudioProviderFactoryManager::RegisterProviders();
AudioPlayerFactoryManager::RegisterProviders();
SubtitlesProviderFactoryManager::RegisterProviders();
SpellCheckerFactoryManager::RegisterProviders();
}
// Done

View file

@ -37,12 +37,15 @@
///////////
// Headers
#include "spellchecker.h"
#ifdef WITH_HUNSPELL
#include "spellchecker_hunspell.h"
#endif
#include "options.h"
/////////////////////
// Get spell checker
SpellChecker *SpellCheckerFactory::GetSpellChecker() {
SpellChecker *SpellCheckerFactoryManager::GetSpellChecker() {
// List of providers
wxArrayString list = GetFactoryList(Options.AsText(_T("Spell Checker")));
@ -66,6 +69,15 @@ SpellChecker *SpellCheckerFactory::GetSpellChecker() {
}
//////////////////////////
// Register all providers
void SpellCheckerFactoryManager::RegisterProviders() {
#ifdef WITH_HUNSPELL
RegisterFactory(new HunspellSpellCheckerFactory(),_T("Hunspell"));
#endif
}
//////////
// Static
template <class SpellCheckerFactory> std::map<wxString,SpellCheckerFactory*>* AegisubFactory<SpellCheckerFactory>::factories=NULL;
template <class SpellCheckerFactory> std::map<wxString,SpellCheckerFactory*>* FactoryManager<SpellCheckerFactory>::factories=NULL;

View file

@ -40,7 +40,7 @@
///////////
// Headers
#include <wx/wxprec.h>
#include "factory.h"
#include "factory_manager.h"
///////////////////////////
@ -63,12 +63,16 @@ public:
///////////
// Factory
class SpellCheckerFactory : public AegisubFactory<SpellCheckerFactory> {
protected:
virtual SpellChecker *CreateSpellChecker()=0;
SpellCheckerFactory(wxString name) { RegisterFactory(name); }
class SpellCheckerFactory {
public:
virtual ~SpellCheckerFactory() {}
static SpellChecker *GetSpellChecker();
virtual SpellChecker *CreateSpellChecker()=0;
};
///////////////////
// Factory Manager
class SpellCheckerFactoryManager : public FactoryManager<SpellCheckerFactory> {
public:
static SpellChecker *GetSpellChecker();
static void RegisterProviders();
};

View file

@ -39,7 +39,7 @@
#ifdef WITH_HUNSPELL
#include "spellchecker.h"
#include "spellchecker_hunspell.h"
#include "standard_paths.h"
#include "utils.h"
#include "options.h"
@ -52,42 +52,6 @@
#include <wx/txtstrm.h>
//////////////////
// Hunspell class
class HunspellSpellChecker : public SpellChecker {
private:
Hunspell *hunspell;
wxCSConv *conv;
wxString affpath;
wxString dicpath;
wxString usrdicpath;
void Reset();
public:
HunspellSpellChecker();
~HunspellSpellChecker();
void AddWord(wxString word);
bool CanAddWord(wxString word);
bool CheckWord(wxString word);
wxArrayString GetSuggestions(wxString word);
wxArrayString GetLanguageList();
void SetLanguage(wxString language);
};
///////////
// Factory
class HunspellSpellCheckerFactory : public SpellCheckerFactory {
public:
SpellChecker *CreateSpellChecker() { return new HunspellSpellChecker(); }
HunspellSpellCheckerFactory() : SpellCheckerFactory(_T("hunspell")) {}
} registerHunspell;
///////////////
// Constructor
HunspellSpellChecker::HunspellSpellChecker() {

View file

@ -0,0 +1,82 @@
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#ifdef WITH_HUNSPELL
#include "spellchecker.h"
#include <hunspell/hunspell.hxx>
#include <wx/wxprec.h>
//////////////////
// Hunspell class
class HunspellSpellChecker : public SpellChecker {
private:
Hunspell *hunspell;
wxCSConv *conv;
wxString affpath;
wxString dicpath;
wxString usrdicpath;
void Reset();
public:
HunspellSpellChecker();
~HunspellSpellChecker();
void AddWord(wxString word);
bool CanAddWord(wxString word);
bool CheckWord(wxString word);
wxArrayString GetSuggestions(wxString word);
wxArrayString GetLanguageList();
void SetLanguage(wxString language);
};
///////////
// Factory
class HunspellSpellCheckerFactory : public SpellCheckerFactory {
public:
SpellChecker *CreateSpellChecker() { return new HunspellSpellChecker(); }
};
#endif

View file

@ -70,7 +70,7 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri
CmdKeyClear('U',wxSTC_SCMOD_CTRL);
// Set spellchecker
spellchecker = SpellCheckerFactory::GetSpellChecker();
spellchecker = SpellCheckerFactoryManager::GetSpellChecker();
// Set thesaurus
thesaurus = Thesaurus::GetThesaurus();

View file

@ -143,7 +143,7 @@ void SubtitlesPreview::UpdateBitmap(int w,int h) {
// Try to get subtitles provider
SubtitlesProvider *provider = NULL;
try {
provider = SubtitlesProviderFactory::GetProvider();
provider = SubtitlesProviderFactoryManager::GetProvider();
}
catch (...) {
wxMessageBox(_T("Could not get any subtitles provider for the preview box. Make sure that you have a provider installed."),_T("No subtitles provider"),wxICON_ERROR);

View file

@ -97,7 +97,7 @@ void DVDSubtitleFormat::GetSubPictureList(std::vector<SubPicture> &pics) {
pics.resize(count);
SubtitlesProvider *provider = NULL;
provider = SubtitlesProviderFactory::GetProvider();
provider = SubtitlesProviderFactoryManager::GetProvider();
provider->LoadSubtitles(GetAssFile());
// Write lines

View file

@ -54,7 +54,7 @@ SubtitlesProvider::~SubtitlesProvider() {
////////////////////////////////////////////////////////////////
// Check if provider available (doesn't verify provider works!)
bool SubtitlesProviderFactory::ProviderAvailable() {
bool SubtitlesProviderFactoryManager::ProviderAvailable() {
// List of providers
wxArrayString list = GetFactoryList(Options.AsText(_T("Subtitles provider")));
@ -65,7 +65,7 @@ bool SubtitlesProviderFactory::ProviderAvailable() {
////////////////
// Get provider
SubtitlesProvider* SubtitlesProviderFactory::GetProvider() {
SubtitlesProvider* SubtitlesProviderFactoryManager::GetProvider() {
// List of providers
wxArrayString list = GetFactoryList(Options.AsText(_T("Subtitles provider")));
@ -94,16 +94,17 @@ SubtitlesProvider* SubtitlesProviderFactory::GetProvider() {
//////////////////////
// Register providers
void SubtitlesProviderFactory::RegisterProviders() {
void SubtitlesProviderFactoryManager::RegisterProviders() {
#ifdef WITH_CSRI
new CSRISubtitlesProviderFactory();
CSRISubtitlesProviderFactory *csri = new CSRISubtitlesProviderFactory();
RegisterFactory(csri,_T("CSRI"),csri->GetSubTypes());
#endif
#ifdef WITH_LIBASS
new LibassSubtitlesProviderFactory();
RegisterFactory(new LibassSubtitlesProviderFactory(),_T("libass"));
#endif
}
//////////
// Static
template <class SubtitlesProviderFactory> std::map<wxString,SubtitlesProviderFactory*>* AegisubFactory<SubtitlesProviderFactory>::factories=NULL;
template <class SubtitlesProviderFactory> std::map<wxString,SubtitlesProviderFactory*>* FactoryManager<SubtitlesProviderFactory>::factories=NULL;

View file

@ -41,7 +41,7 @@
// Headers
#include <wx/wxprec.h>
#include "video_frame.h"
#include "factory.h"
#include "factory_manager.h"
//////////////
@ -65,16 +65,19 @@ public:
///////////
// Factory
class SubtitlesProviderFactory : public AegisubFactory<SubtitlesProviderFactory> {
protected:
virtual SubtitlesProvider *CreateProvider(wxString subType=_T(""))=0;
SubtitlesProviderFactory(wxString name,wxArrayString subTypes=wxArrayString()) {
RegisterFactory(name,subTypes);
}
class SubtitlesProviderFactory {
public:
virtual ~SubtitlesProviderFactory() {}
virtual SubtitlesProvider *CreateProvider(wxString subType=_T(""))=0;
};
///////////////////
// Factory Manager
class SubtitlesProviderFactoryManager : public FactoryManager<SubtitlesProviderFactory> {
public:
static SubtitlesProvider *GetProvider();
static void RegisterProviders();
static bool ProviderAvailable();
};

View file

@ -75,7 +75,6 @@ class CSRISubtitlesProviderFactory : public SubtitlesProviderFactory {
public:
SubtitlesProvider *CreateProvider(wxString subType=_T("")) { return new CSRISubtitlesProvider(subType); }
wxArrayString GetSubTypes();
CSRISubtitlesProviderFactory() : SubtitlesProviderFactory(_T("csri"),GetSubTypes()) {}
};
#endif

View file

@ -329,13 +329,13 @@ void VideoContext::SetVideo(const wxString &filename) {
#endif
// Choose a provider
provider = VideoProviderFactory::GetProvider(filename,overFps);
provider = VideoProviderFactoryManager::GetProvider(filename,overFps);
loaded = provider != NULL;
// Get subtitles provider
try {
subsProvider = provider->GetAsSubtitlesProvider();
if (!subsProvider) subsProvider = SubtitlesProviderFactory::GetProvider();
if (!subsProvider) subsProvider = SubtitlesProviderFactoryManager::GetProvider();
}
catch (wxString err) { wxMessageBox(_T("Error while loading subtitles provider: ") + err,_T("Subtitles provider")); }
catch (const wchar_t *err) { wxMessageBox(_T("Error while loading subtitles provider: ") + wxString(err),_T("Subtitles provider")); }

View file

@ -55,7 +55,7 @@
////////////////
// Get provider
VideoProvider *VideoProviderFactory::GetProvider(wxString video,double fps) {
VideoProvider *VideoProviderFactoryManager::GetProvider(wxString video,double fps) {
// First check special case of dummy video
if (video.StartsWith(_T("?dummy:"))) {
return new DummyVideoProvider(video, fps);
@ -93,19 +93,19 @@ VideoProvider *VideoProviderFactory::GetProvider(wxString video,double fps) {
//////////////////////////
// Register all providers
void VideoProviderFactory::RegisterProviders() {
void VideoProviderFactoryManager::RegisterProviders() {
#ifdef WITH_AVISYNTH
new AvisynthVideoProviderFactory();
RegisterFactory(new AvisynthVideoProviderFactory(),_T("Avisynth"));
#endif
#ifdef WITH_DIRECTSHOW
new DirectShowVideoProviderFactory();
RegisterFactory(new DirectShowVideoProviderFactory(),_T("DirectShow"));
#endif
#ifdef WITH_FFMPEG
new LAVCVideoProviderFactory();
RegisterFactory(new LAVCVideoProviderFactory(),_T("FFMPEG"));
#endif
}
//////////
// Static
template <class VideoProviderFactory> std::map<wxString,VideoProviderFactory*>* AegisubFactory<VideoProviderFactory>::factories=NULL;
template <class VideoProviderFactory> std::map<wxString,VideoProviderFactory*>* FactoryManager<VideoProviderFactory>::factories=NULL;

View file

@ -41,7 +41,7 @@
// Headers
#include <wx/intl.h>
#include "video_frame.h"
#include "factory.h"
#include "factory_manager.h"
//////////////
@ -86,14 +86,16 @@ public:
///////////
// Factory
class VideoProviderFactory : public AegisubFactory<VideoProviderFactory> {
protected:
virtual VideoProvider *CreateProvider(wxString video,double fps=0.0)=0;
VideoProviderFactory(wxString name) { RegisterFactory(name); }
class VideoProviderFactory {
public:
virtual ~VideoProviderFactory() {}
static VideoProvider *GetProvider(wxString video,double fps=0.0);
static void RegisterProviders();
virtual VideoProvider *CreateProvider(wxString video,double fps=0.0)=0;
};
///////////////////
// Factory Manager
class VideoProviderFactoryManager : public FactoryManager<VideoProviderFactory> {
public:
static void RegisterProviders();
static VideoProvider *GetProvider(wxString video,double fps=0.0);
};

View file

@ -101,7 +101,6 @@ public:
class AvisynthVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new AvisynthVideoProvider(video,fps); }
AvisynthVideoProviderFactory() : VideoProviderFactory(_T("avisynth")) {}
};

View file

@ -124,7 +124,6 @@ public:
class DirectShowVideoProviderFactory : public VideoProviderFactory {
public:
VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new DirectShowVideoProvider(video,fps); }
DirectShowVideoProviderFactory() : VideoProviderFactory(_T("dshow")) {}
};
#endif

View file

@ -222,10 +222,11 @@
OpenMP="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdwx.h"
ProgramDataBaseFileName="$(IntDir)\vc90.pdb"
WarningLevel="3"
WarnAsError="true"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
DebugInformationFormat="0"
DisableSpecificWarnings="4267"
ForcedIncludeFiles="stdwx.h;config.h"
/>
@ -917,7 +918,7 @@
>
</File>
<File
RelativePath="..\..\aegisub\factory.h"
RelativePath="..\..\aegisub\factory_manager.h"
>
</File>
<File
@ -1672,6 +1673,10 @@
RelativePath="..\..\aegisub\spellchecker_hunspell.cpp"
>
</File>
<File
RelativePath="..\..\aegisub\spellchecker_hunspell.h"
>
</File>
<File
RelativePath="..\..\aegisub\thesaurus.cpp"
>