diff --git a/aegisub/build/aegisub_vs2008/aegisub_vs2008.vcproj b/aegisub/build/aegisub_vs2008/aegisub_vs2008.vcproj index 7f4596bb5..2ddc0eb31 100644 --- a/aegisub/build/aegisub_vs2008/aegisub_vs2008.vcproj +++ b/aegisub/build/aegisub_vs2008/aegisub_vs2008.vcproj @@ -495,10 +495,6 @@ RelativePath="..\..\src\audio_provider_hd.h" > - - @@ -1443,10 +1439,6 @@ RelativePath="..\..\src\spellchecker_hunspell.h" > - - @@ -1571,10 +1563,6 @@ RelativePath="..\..\src\subtitles_provider_libass.h" > - - SetDisplayTimer(&UpdateTimer); player->SetProvider(provider); player->OpenStream(); diff --git a/aegisub/src/audio_display.h b/aegisub/src/audio_display.h index fd971de7b..9b76b9847 100644 --- a/aegisub/src/audio_display.h +++ b/aegisub/src/audio_display.h @@ -44,10 +44,10 @@ #include #endif -#include "audio_player_manager.h" -#include "audio_provider_manager.h" #include "audio_renderer_spectrum.h" +class AudioPlayer; +class AudioProvider; class AssDialogue; class SubtitlesGrid; class AudioBox; diff --git a/aegisub/src/audio_player.cpp b/aegisub/src/audio_player.cpp index dc01dc053..67e8ec99c 100644 --- a/aegisub/src/audio_player.cpp +++ b/aegisub/src/audio_player.cpp @@ -34,9 +34,6 @@ /// @ingroup audio_output /// - -/////////// -// Headers #include "config.h" #ifdef WITH_ALSA @@ -46,7 +43,6 @@ #include "audio_player_dsound.h" #include "audio_player_dsound2.h" #endif -#include "audio_player_manager.h" #ifdef WITH_OPENAL #include "audio_player_openal.h" #endif @@ -62,8 +58,6 @@ #include "compat.h" #include "main.h" - - /// @brief Constructor /// AudioPlayer::AudioPlayer() { @@ -71,8 +65,6 @@ AudioPlayer::AudioPlayer() { displayTimer = NULL; } - - /// @brief Destructor /// AudioPlayer::~AudioPlayer() { @@ -82,44 +74,6 @@ AudioPlayer::~AudioPlayer() { CloseStream(); } - - -/// @brief Set provider -/// @param _provider -/// -void AudioPlayer::SetProvider(AudioProvider *_provider) { - provider = _provider; -} - - - -/// @brief Get provider -/// @return -/// -AudioProvider *AudioPlayer::GetProvider() { - return provider; -} - - - -/// @brief Get mutex -/// @return -/// -wxMutex *AudioPlayer::GetMutex() { - return NULL; -} - - - -/// @brief Set timer -/// @param timer -/// -void AudioPlayer::SetDisplayTimer(wxTimer *timer) { - displayTimer = timer; -} - - - /// @brief Ask to stop later /// void AudioPlayer::RequestStop() { @@ -128,16 +82,12 @@ void AudioPlayer::RequestStop() { AddPendingEvent(event); // thread safe } - -///////// -// Event DEFINE_EVENT_TYPE(wxEVT_STOP_AUDIO) BEGIN_EVENT_TABLE(AudioPlayer, wxEvtHandler) EVT_COMMAND (1000, wxEVT_STOP_AUDIO, AudioPlayer::OnStopAudio) END_EVENT_TABLE() - /// @brief DOCME /// @param event /// @@ -145,31 +95,23 @@ void AudioPlayer::OnStopAudio(wxCommandEvent &event) { Stop(false); } - - /// @brief Get player /// @return /// -AudioPlayer* AudioPlayerFactoryManager::GetAudioPlayer() { - // List of providers - wxArrayString list = GetFactoryList(lagi_wxString(OPT_GET("Audio/Player")->GetString())); +AudioPlayer* AudioPlayerFactory::GetAudioPlayer() { + std::vector list = GetClasses(OPT_GET("Audio/Player")->GetString()); + if (list.empty()) throw _T("No audio players are available."); - // None available - if (list.Count() == 0) throw _T("No audio players are available."); - - // Get provider wxString error; - for (unsigned int i=0;iCreatePlayer(); + AudioPlayer *player = Create(list[i]); if (player) return player; } catch (wxString err) { error += list[i] + _T(" factory: ") + err + _T("\n"); } catch (const wxChar *err) { error += list[i] + _T(" factory: ") + wxString(err) + _T("\n"); } catch (...) { error += list[i] + _T(" factory: Unknown error\n"); } } - - // Failed throw error; } @@ -177,40 +119,26 @@ AudioPlayer* AudioPlayerFactoryManager::GetAudioPlayer() { /// @brief Register all factories /// -void AudioPlayerFactoryManager::RegisterProviders() { +void AudioPlayerFactory::RegisterProviders() { #ifdef WITH_ALSA - RegisterFactory(new AlsaPlayerFactory(),_T("ALSA")); + Register("ALSA"); #endif #ifdef WITH_DIRECTSOUND - RegisterFactory(new DirectSoundPlayerFactory(),_T("DirectSound-old")); - RegisterFactory(new DirectSoundPlayer2Factory(),_T("DirectSound")); + Register("DirectSound-old"); + Register("DirectSound"); #endif #ifdef WITH_OPENAL - RegisterFactory(new OpenALPlayerFactory(),_T("OpenAL")); + Register("OpenAL"); #endif #ifdef WITH_PORTAUDIO - RegisterFactory(new PortAudioPlayerFactory(),_T("PortAudio")); + Register("PortAudio"); #endif #ifdef WITH_PULSEAUDIO - RegisterFactory(new PulseAudioPlayerFactory(),_T("PulseAudio")); + Register("PulseAudio"); #endif #ifdef WITH_OSS - RegisterFactory(new OSSPlayerFactory(),_T("OSS")); + Register("OSS"); #endif } - - -/// @brief Clear all factories -/// -void AudioPlayerFactoryManager::ClearProviders() { - ClearFactories(); -} - - - -/// DOCME -template std::map* FactoryManager::factories=NULL; - - - +template<> AudioPlayerFactory::map *FactoryBase::classes = NULL; diff --git a/aegisub/src/audio_player_alsa.cpp b/aegisub/src/audio_player_alsa.cpp index 1cc3ddf83..64bff84fe 100644 --- a/aegisub/src/audio_player_alsa.cpp +++ b/aegisub/src/audio_player_alsa.cpp @@ -40,14 +40,9 @@ #ifdef WITH_ALSA - -/////////// -// Headers #include #include "audio_player_alsa.h" -#include "audio_player_manager.h" -#include "audio_provider_manager.h" #include "main.h" #include "compat.h" #include "frame_main.h" @@ -65,8 +60,6 @@ AlsaPlayer::AlsaPlayer() provider = 0; } - - /// @brief Destructor /// AlsaPlayer::~AlsaPlayer() @@ -74,8 +67,6 @@ AlsaPlayer::~AlsaPlayer() CloseStream(); } - - /// @brief Open stream /// void AlsaPlayer::OpenStream() @@ -105,8 +96,6 @@ void AlsaPlayer::OpenStream() open = true; } - - /// @brief DOCME /// void AlsaPlayer::SetUpHardware() @@ -202,8 +191,6 @@ void AlsaPlayer::SetUpHardware() snd_pcm_hw_params_free(hwparams); } - - /// @brief DOCME /// void AlsaPlayer::SetUpAsync() @@ -249,8 +236,6 @@ void AlsaPlayer::SetUpAsync() } } - - /// @brief Close stream /// @return /// @@ -270,8 +255,6 @@ void AlsaPlayer::CloseStream() open = false; } - - /// @brief Play /// @param start /// @param count @@ -301,8 +284,6 @@ void AlsaPlayer::Play(int64_t start,int64_t count) if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15); } - - /// @brief Stop /// @param timerToo /// @return @@ -326,8 +307,6 @@ void AlsaPlayer::Stop(bool timerToo) } } - - /// @brief DOCME /// @return /// @@ -336,8 +315,6 @@ bool AlsaPlayer::IsPlaying() return playing; } - - /// @brief Set end /// @param pos /// @@ -346,8 +323,6 @@ void AlsaPlayer::SetEndPosition(int64_t pos) end_frame = pos; } - - /// @brief Set current position /// @param pos /// @@ -356,8 +331,6 @@ void AlsaPlayer::SetCurrentPosition(int64_t pos) cur_frame = pos; } - - /// @brief DOCME /// @return /// @@ -366,8 +339,6 @@ int64_t AlsaPlayer::GetStartPosition() return start_frame; } - - /// @brief DOCME /// @return /// @@ -376,8 +347,6 @@ int64_t AlsaPlayer::GetEndPosition() return end_frame; } - - /// @brief Get current position /// @return /// @@ -390,8 +359,6 @@ int64_t AlsaPlayer::GetCurrentPosition() return cur_frame - delay; } - - /// @brief DOCME /// @param pcm_callback /// @@ -439,7 +406,4 @@ void AlsaPlayer::async_write_handler(snd_async_handler_t *pcm_callback) free(buf); } - #endif // WITH_ALSA - - diff --git a/aegisub/src/audio_player_alsa.h b/aegisub/src/audio_player_alsa.h index ab4e28cd9..595473a92 100644 --- a/aegisub/src/audio_player_alsa.h +++ b/aegisub/src/audio_player_alsa.h @@ -37,9 +37,6 @@ #ifdef WITH_ALSA - -/////////// -// Headers #include #include "include/aegisub/audio_player.h" @@ -148,22 +145,4 @@ public: double GetVolume() { return volume; } }; - - - -/// DOCME -/// @class AlsaPlayerFactory -/// @brief DOCME -/// -/// DOCME -class AlsaPlayerFactory : public AudioPlayerFactory { -public: - - /// @brief DOCME - /// - AudioPlayer *CreatePlayer() { return new AlsaPlayer(); } -}; - #endif - - diff --git a/aegisub/src/audio_player_dsound.h b/aegisub/src/audio_player_dsound.h index f10884887..47aec34d1 100644 --- a/aegisub/src/audio_player_dsound.h +++ b/aegisub/src/audio_player_dsound.h @@ -183,25 +183,5 @@ public: /// @return /// double GetVolume() { return volume; } - - //wxMutex *GetMutex() { return &DSMutex; } }; - - - -/// DOCME -/// @class DirectSoundPlayerFactory -/// @brief DOCME -/// -/// DOCME -class DirectSoundPlayerFactory : public AudioPlayerFactory { -public: - - /// @brief DOCME - /// - AudioPlayer *CreatePlayer() { return new DirectSoundPlayer(); } -}; - #endif - - diff --git a/aegisub/src/audio_player_dsound2.h b/aegisub/src/audio_player_dsound2.h index 9e3bd5842..51c754b5f 100644 --- a/aegisub/src/audio_player_dsound2.h +++ b/aegisub/src/audio_player_dsound2.h @@ -34,15 +34,12 @@ /// @ingroup audio_output /// - #ifdef WITH_DIRECTSOUND #include "include/aegisub/audio_player.h" - class DirectSoundPlayer2Thread; - /// @class DirectSoundPlayer2 /// @brief New implementation of DirectSound-based audio player /// @@ -50,7 +47,6 @@ class DirectSoundPlayer2Thread; /// and performs all playback operations, and use the player object as a proxy to /// send commands to the playback thread. class DirectSoundPlayer2 : public AudioPlayer { - /// The playback thread DirectSoundPlayer2Thread *thread; @@ -86,18 +82,4 @@ public: void SetVolume(double vol); double GetVolume(); }; - - - -/// @class DirectSoundPlayer2Factory -/// @brief Factory class for DirectSoundPlayer2 -class DirectSoundPlayer2Factory : public AudioPlayerFactory { -public: - - /// @brief Create a DirectSoundPlayer2 object - AudioPlayer *CreatePlayer() { return new DirectSoundPlayer2(); } -}; - #endif - - diff --git a/aegisub/src/audio_player_manager.h b/aegisub/src/audio_player_manager.h deleted file mode 100644 index bb1982af4..000000000 --- a/aegisub/src/audio_player_manager.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2005-2007, 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 Project http://www.aegisub.org/ -// -// $Id$ - -/// @file audio_player_manager.h -/// @brief Manage available audio output implementations -/// @ingroup audio_output -/// - - -#pragma once - - -/////////// -// Headers -#ifndef AGI_PRE -#include - -#include -#include -#include -#endif - -#include "factory_manager.h" -#include "include/aegisub/audio_player.h" - - -////////////// -// Prototypes -class AudioProvider; - - - -/// DOCME -/// @class AudioPlayerFactoryManager -/// @brief DOCME -/// -/// DOCME -class AudioPlayerFactoryManager : public FactoryManager { -public: - static AudioPlayer *GetAudioPlayer(); - static void RegisterProviders(); - static void ClearProviders(); -}; - - - -///////// -// Event -DECLARE_EVENT_TYPE(wxEVT_STOP_AUDIO, -1) - - - - diff --git a/aegisub/src/audio_player_openal.cpp b/aegisub/src/audio_player_openal.cpp index f68ed05b1..456c4c38d 100644 --- a/aegisub/src/audio_player_openal.cpp +++ b/aegisub/src/audio_player_openal.cpp @@ -34,19 +34,13 @@ /// @ingroup audio_output /// - #include "config.h" #ifdef WITH_OPENAL - -/////////// -// Headers #include -#include "audio_player_manager.h" #include "audio_player_openal.h" -#include "audio_provider_manager.h" #include "frame_main.h" #include "utils.h" @@ -61,14 +55,11 @@ #include #endif - // Auto-link to OpenAL lib for MSVC #ifdef _MSC_VER #pragma comment(lib, "openal32.lib") #endif - - /// @brief Constructor /// OpenALPlayer::OpenALPlayer() @@ -80,8 +71,6 @@ OpenALPlayer::OpenALPlayer() provider = 0; } - - /// @brief Destructor /// OpenALPlayer::~OpenALPlayer() @@ -375,6 +364,3 @@ int64_t OpenALPlayer::GetCurrentPosition() #endif // WITH_OPENAL - - - diff --git a/aegisub/src/audio_player_openal.h b/aegisub/src/audio_player_openal.h index 4c2a1ddd3..be172689c 100644 --- a/aegisub/src/audio_player_openal.h +++ b/aegisub/src/audio_player_openal.h @@ -36,11 +36,6 @@ #ifdef WITH_OPENAL - - -/////////// -// Headers -#include "audio_player_manager.h" #include "include/aegisub/audio_player.h" #include "include/aegisub/audio_provider.h" #include "utils.h" @@ -56,8 +51,6 @@ #include #endif - - /// DOCME /// @class OpenALPlayer /// @brief DOCME @@ -164,23 +157,4 @@ public: /// double GetVolume() { return volume; } }; - - - - -/// DOCME -/// @class OpenALPlayerFactory -/// @brief DOCME -/// -/// DOCME -class OpenALPlayerFactory : public AudioPlayerFactory { -public: - - /// @brief DOCME - /// - AudioPlayer *CreatePlayer() { return new OpenALPlayer(); } -}; - #endif - - diff --git a/aegisub/src/audio_player_oss.cpp b/aegisub/src/audio_player_oss.cpp index f28eb430f..5a2b62eca 100644 --- a/aegisub/src/audio_player_oss.cpp +++ b/aegisub/src/audio_player_oss.cpp @@ -37,13 +37,9 @@ #ifdef WITH_OSS -/////////// -// Headers #include -#include "audio_player_manager.h" #include "audio_player_oss.h" -#include "audio_provider_manager.h" #include "frame_main.h" #include "compat.h" #include "main.h" diff --git a/aegisub/src/audio_player_oss.h b/aegisub/src/audio_player_oss.h index 4cb6c9749..b7d6f2b36 100644 --- a/aegisub/src/audio_player_oss.h +++ b/aegisub/src/audio_player_oss.h @@ -37,10 +37,6 @@ #include "config.h" #ifdef WITH_OSS - - -/////////// -// Headers #ifndef AGI_PRE #include #endif @@ -58,13 +54,8 @@ #include "include/aegisub/audio_provider.h" #include "utils.h" - -////////////// -// Prototypes class OSSPlayer; - - /// DOCME /// @class OSSPlayerThread /// @brief DOCME @@ -153,21 +144,4 @@ public: /// double GetVolume() { return volume; } }; - - - - -/// DOCME -/// @class OSSPlayerFactory -/// @brief DOCME -/// -/// DOCME -class OSSPlayerFactory : public AudioPlayerFactory { -public: - - /// @brief DOCME - /// - AudioPlayer *CreatePlayer() { return new OSSPlayer(); } -}; - #endif diff --git a/aegisub/src/audio_player_portaudio.h b/aegisub/src/audio_player_portaudio.h index 169faa0a2..e22416d7c 100644 --- a/aegisub/src/audio_player_portaudio.h +++ b/aegisub/src/audio_player_portaudio.h @@ -37,9 +37,6 @@ #ifdef WITH_PORTAUDIO - -/////////// -// Headers #include "include/aegisub/audio_player.h" #include "include/aegisub/audio_provider.h" #include "utils.h" @@ -47,7 +44,6 @@ extern "C" { #include } - /// @class PortAudioPlayer /// @brief PortAudio Player /// @@ -126,16 +122,4 @@ public: wxArrayString GetOutputDevices(wxString favorite); }; - - -/// @class PortAudioPlayerFactory -/// @brief PortAudio Player Factory -class PortAudioPlayerFactory : public AudioPlayerFactory { -public: - - /// @brief Create player - /// @return New PortAudio Player - AudioPlayer *CreatePlayer() { return new PortAudioPlayer(); } -}; - #endif //ifdef WITH_PORTAUDIO diff --git a/aegisub/src/audio_player_pulse.cpp b/aegisub/src/audio_player_pulse.cpp index d718cbd32..25b7d5420 100644 --- a/aegisub/src/audio_player_pulse.cpp +++ b/aegisub/src/audio_player_pulse.cpp @@ -34,20 +34,15 @@ /// @ingroup audio_output /// - #include "config.h" #ifdef WITH_PULSEAUDIO - -/////////// -// Headers #ifndef AGI_PRE #include #endif #include "audio_player_pulse.h" -#include "audio_provider_manager.h" #include "utils.h" @@ -451,7 +446,4 @@ void PulseAudioPlayer::pa_stream_notify(pa_stream *p, PulseAudioPlayer *thread) thread->stream_notify.Post(); } - #endif // WITH_PULSEAUDIO - - diff --git a/aegisub/src/audio_player_pulse.h b/aegisub/src/audio_player_pulse.h index af0debf5b..01a70b832 100644 --- a/aegisub/src/audio_player_pulse.h +++ b/aegisub/src/audio_player_pulse.h @@ -34,12 +34,7 @@ /// @ingroup audio_output /// - #ifdef WITH_PULSEAUDIO - - -/////////// -// Headers #ifndef AGI_PRE #include #endif @@ -50,14 +45,8 @@ #include "include/aegisub/audio_provider.h" #include "utils.h" - -////////////// -// Prototypes class PulseAudioPlayer; - - - /// DOCME /// @class PulseAudioPlayer /// @brief DOCME @@ -170,22 +159,4 @@ public: double GetVolume() { return volume; } }; - - - -/// DOCME -/// @class PulseAudioPlayerFactory -/// @brief DOCME -/// -/// DOCME -class PulseAudioPlayerFactory : public AudioPlayerFactory { -public: - - /// @brief DOCME - /// - AudioPlayer *CreatePlayer() { return new PulseAudioPlayer(); } -}; - #endif - - diff --git a/aegisub/src/audio_provider.cpp b/aegisub/src/audio_provider.cpp index 417ad9e87..59e3b7974 100644 --- a/aegisub/src/audio_provider.cpp +++ b/aegisub/src/audio_provider.cpp @@ -35,15 +35,12 @@ /// -/////////// -// Headers #include "config.h" #ifndef AGI_PRE #include #endif -#include "audio_display.h" #ifdef WITH_AVISYNTH #include "audio_provider_avs.h" #endif @@ -57,71 +54,17 @@ #include "compat.h" #include "main.h" - - - /// @brief Constructor /// -AudioProvider::AudioProvider() { - raw = NULL; +AudioProvider::AudioProvider() : raw(NULL) { } - - /// @brief Destructor /// AudioProvider::~AudioProvider() { - // Clear buffers delete[] raw; } - - -/// @brief Get number of channels -/// @return -/// -int AudioProvider::GetChannels() { - return channels; -} - - - -/// @brief Get number of samples -/// @return -/// -int64_t AudioProvider::GetNumSamples() { - return num_samples; -} - - - -/// @brief Get sample rate -/// @return -/// -int AudioProvider::GetSampleRate() { - return sample_rate; -} - - - -/// @brief Get bytes per sample -/// @return -/// -int AudioProvider::GetBytesPerSample() { - return bytes_per_sample; -} - - - -/// @brief Get filename -/// @return -/// -wxString AudioProvider::GetFilename() { - return filename; -} - - - /// @brief Get waveform /// @param min /// @param peak @@ -193,8 +136,6 @@ void AudioProvider::GetWaveForm(int *min,int *peak,int64_t start,int w,int h,int } } - - /// @brief Get audio with volume /// @param buf /// @param start @@ -230,15 +171,12 @@ void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count, } } - - /// @brief Get provider /// @param filename /// @param cache /// @return /// -AudioProvider *AudioProviderFactoryManager::GetAudioProvider(wxString filename, int cache) { - // Prepare provider +AudioProvider *AudioProviderFactory::GetProvider(wxString filename, int cache) { AudioProvider *provider = NULL; if (!OPT_GET("Provider/Audio/PCM/Disable")->GetBool()) { @@ -248,27 +186,22 @@ AudioProvider *AudioProviderFactoryManager::GetAudioProvider(wxString filename, if (provider->GetBytesPerSample() == 2 && provider->GetSampleRate() >= 32000 && provider->GetChannels() == 1) return provider; else { - provider = CreateConvertAudioProvider(provider); - return provider; + return CreateConvertAudioProvider(provider); } } } // List of providers - wxArrayString list = GetFactoryList(lagi_wxString(OPT_GET("Audio/Provider")->GetString())); + std::vector list = GetClasses(OPT_GET("Audio/Provider")->GetString()); - // None available - if (list.Count() == 0) throw _T("No audio providers are available."); + if (list.empty()) throw _T("No audio providers are available."); // Get provider wxString error; - for (unsigned int i=0;iCreateProvider(filename.wc_str()); - if (prov) { - provider = prov; - break; - } + provider = Create(list[i], filename); + if (provider) break; } catch (wxString err) { error += list[i] + _T(" factory: ") + err + _T("\n"); } catch (const wxChar *err) { error += list[i] + _T(" factory: ") + wxString(err) + _T("\n"); } @@ -296,11 +229,10 @@ AudioProvider *AudioProviderFactoryManager::GetAudioProvider(wxString filename, // Reassign if (final) { delete provider; - provider = final; + return final; } } - // Return return provider; } @@ -308,26 +240,13 @@ AudioProvider *AudioProviderFactoryManager::GetAudioProvider(wxString filename, /// @brief Register all providers /// -void AudioProviderFactoryManager::RegisterProviders() { +void AudioProviderFactory::RegisterProviders() { #ifdef WITH_AVISYNTH - RegisterFactory(new AvisynthAudioProviderFactory(),_T("Avisynth")); + Register("Avisynth"); #endif #ifdef WITH_FFMPEGSOURCE - RegisterFactory(new FFmpegSourceAudioProviderFactory(),_T("FFmpegSource")); + Register("FFmpegSource"); #endif } - - -/// @brief Clear all providers -/// -void AudioProviderFactoryManager::ClearProviders() { - ClearFactories(); -} - - - -/// DOCME -template std::map* FactoryManager::factories=NULL; - - +template<> AudioProviderFactory::map *FactoryBase::classes = NULL; diff --git a/aegisub/src/audio_provider_avs.h b/aegisub/src/audio_provider_avs.h index 424d4b8d4..3514eca12 100644 --- a/aegisub/src/audio_provider_avs.h +++ b/aegisub/src/audio_provider_avs.h @@ -34,9 +34,6 @@ /// @ingroup audio_input /// - -/////////// -// Headers #ifdef WITH_AVISYNTH #include #include "include/aegisub/audio_provider.h" @@ -69,31 +66,12 @@ public: wxString GetFilename(); - /// @brief // Only exists for x86 Windows, always delivers machine (little) endian + /// @brief Only exists for x86 Windows, always delivers machine (little) endian /// @return /// - bool AreSamplesNativeEndian() { return true; } + bool AreSamplesNativeEndian() const { return true; } void GetAudio(void *buf, int64_t start, int64_t count); void GetWaveForm(int *min,int *peak,int64_t start,int w,int h,int samples,float scale); }; - - - -/// DOCME -/// @class AvisynthAudioProviderFactory -/// @brief DOCME -/// -/// DOCME -class AvisynthAudioProviderFactory : public AudioProviderFactory { -public: - - /// @brief DOCME - /// @param file - /// - AudioProvider *CreateProvider(wxString file) { return new AvisynthAudioProvider(file); } -}; - #endif - - diff --git a/aegisub/src/audio_provider_convert.h b/aegisub/src/audio_provider_convert.h index f7daf9965..e335e8ef4 100644 --- a/aegisub/src/audio_provider_convert.h +++ b/aegisub/src/audio_provider_convert.h @@ -34,9 +34,6 @@ /// @ingroup audio_input /// - -/////////// -// Headers #include "include/aegisub/audio_provider.h" @@ -66,7 +63,7 @@ public: /// @brief // That's one of the points of it! // By its nature, the ConvertAudioProvider always delivers machine endian: /// @return /// - bool AreSamplesNativeEndian() { return true; } + bool AreSamplesNativeEndian() const { return true; } void GetAudio(void *buf, int64_t start, int64_t count); @@ -76,6 +73,3 @@ public: }; AudioProvider *CreateConvertAudioProvider(AudioProvider *source_provider); - - - diff --git a/aegisub/src/audio_provider_downmix.h b/aegisub/src/audio_provider_downmix.h index 5412b8a1b..871420aa7 100644 --- a/aegisub/src/audio_provider_downmix.h +++ b/aegisub/src/audio_provider_downmix.h @@ -59,11 +59,7 @@ public: /// @brief // Downmixing requires samples to be native endian beforehand /// - bool AreSamplesNativeEndian() { return true; } + bool AreSamplesNativeEndian() const { return true; } void GetAudio(void *buf, int64_t start, int64_t count); - }; - - - diff --git a/aegisub/src/audio_provider_dummy.h b/aegisub/src/audio_provider_dummy.h index 4fe744b56..89d7e57fd 100644 --- a/aegisub/src/audio_provider_dummy.h +++ b/aegisub/src/audio_provider_dummy.h @@ -34,12 +34,8 @@ /// @ingroup audio_input /// - -/////////// -// Headers #include "include/aegisub/audio_provider.h" - /// DOCME /// @class DummyAudioProvider /// @brief DOCME @@ -58,9 +54,7 @@ public: /// @brief DOCME /// - bool AreSamplesNativeEndian() { return true; } + bool AreSamplesNativeEndian() const { return true; } void GetAudio(void *buf, int64_t start, int64_t count); }; - - diff --git a/aegisub/src/audio_provider_ffmpegsource.h b/aegisub/src/audio_provider_ffmpegsource.h index f584c2e2a..d47c0d65f 100644 --- a/aegisub/src/audio_provider_ffmpegsource.h +++ b/aegisub/src/audio_provider_ffmpegsource.h @@ -34,8 +34,6 @@ /// @ingroup audio_input ffms /// -/////////// -// Headers #ifdef WITH_FFMPEGSOURCE #include "include/aegisub/audio_provider.h" #include "ffmpegsource_common.h" @@ -62,24 +60,8 @@ public: /// @brief Checks sample endianness /// @return Returns true. /// FFMS always delivers native endian samples. - bool AreSamplesNativeEndian() { return true; } + bool AreSamplesNativeEndian() const { return true; } virtual void GetAudio(void *buf, int64_t start, int64_t count); }; - - - -/// @class FFmpegSourceAudioProviderFactory -/// @brief Creates a FFmpegSource audio provider. -class FFmpegSourceAudioProviderFactory : public AudioProviderFactory { -public: - /// @brief Creates a FFmpegSource audio provider. - /// @param video The audio filename to open. - /// @return Returns the audio provider. - AudioProvider *CreateProvider(wxString file) { return new FFmpegSourceAudioProvider(file); } -}; - -#endif /* WITH_FFMPEGSOURCE */ - - - +#endif diff --git a/aegisub/src/audio_provider_hd.h b/aegisub/src/audio_provider_hd.h index 71cc1e6b4..db39d6792 100644 --- a/aegisub/src/audio_provider_hd.h +++ b/aegisub/src/audio_provider_hd.h @@ -34,9 +34,6 @@ /// @ingroup audio_input /// - -/////////// -// Headers #ifndef AGI_PRE #include #include @@ -44,8 +41,6 @@ #include "include/aegisub/audio_provider.h" - - /// DOCME /// @class HDAudioProvider /// @brief DOCME @@ -79,9 +74,7 @@ public: /// @brief DOCME /// - bool AreSamplesNativeEndian() { return samples_native_endian; } + bool AreSamplesNativeEndian() const { return samples_native_endian; } void GetAudio(void *buf, int64_t start, int64_t count); }; - - diff --git a/aegisub/src/audio_provider_manager.h b/aegisub/src/audio_provider_manager.h deleted file mode 100644 index 44f621c58..000000000 --- a/aegisub/src/audio_provider_manager.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2006, 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 Project http://www.aegisub.org/ -// -// $Id$ - -/// @file audio_provider_manager.h -/// @brief Manage available audio provider implementations -/// @ingroup audio_input -/// - - -#pragma once - - -/////////// -// Headers -#ifndef AGI_PRE -#include -#endif - -#include "include/aegisub/audio_provider.h" -#include "factory_manager.h" - - -/// DOCME -/// @class AudioProviderFactoryManager -/// @brief DOCME -/// -/// DOCME -class AudioProviderFactoryManager : public FactoryManager { -public: - static void RegisterProviders(); - static AudioProvider *GetAudioProvider(wxString filename, int cache=-1); - static void ClearProviders(); -}; - - diff --git a/aegisub/src/audio_provider_pcm.cpp b/aegisub/src/audio_provider_pcm.cpp index 4e3804fab..3491e69be 100644 --- a/aegisub/src/audio_provider_pcm.cpp +++ b/aegisub/src/audio_provider_pcm.cpp @@ -436,7 +436,7 @@ public: /// @brief DOCME /// @return /// - bool AreSamplesNativeEndian() + bool AreSamplesNativeEndian() const { // 8 bit samples don't consider endianness if (bytes_per_sample < 2) return true; @@ -657,7 +657,7 @@ public: /// @brief DOCME /// @return /// - bool AreSamplesNativeEndian() + bool AreSamplesNativeEndian() const { // 8 bit samples don't consider endianness if (bytes_per_sample < 2) return true; diff --git a/aegisub/src/audio_provider_pcm.h b/aegisub/src/audio_provider_pcm.h index 7be8c5717..46425d6a7 100644 --- a/aegisub/src/audio_provider_pcm.h +++ b/aegisub/src/audio_provider_pcm.h @@ -34,9 +34,6 @@ /// @ingroup audio_input /// - -/////////// -// Headers #ifndef AGI_PRE #include @@ -116,7 +113,3 @@ public: // Construct the right PCM audio provider (if any) for the file AudioProvider *CreatePCMAudioProvider(const wxString &filename); - - - - diff --git a/aegisub/src/audio_provider_ram.h b/aegisub/src/audio_provider_ram.h index ed53e55ed..1c5cb9a62 100644 --- a/aegisub/src/audio_provider_ram.h +++ b/aegisub/src/audio_provider_ram.h @@ -34,20 +34,14 @@ /// @ingroup audio_input /// - -/////////// -// Headers #include "include/aegisub/audio_provider.h" - /// DOCME /// @class RAMAudioProvider /// @brief DOCME /// /// DOCME class RAMAudioProvider : public AudioProvider { -private: - /// DOCME char** blockcache; @@ -63,12 +57,6 @@ public: RAMAudioProvider(AudioProvider *source); ~RAMAudioProvider(); - - /// @brief DOCME - /// - bool AreSamplesNativeEndian() { return samples_native_endian; } - + bool AreSamplesNativeEndian() const { return samples_native_endian; } void GetAudio(void *buf, int64_t start, int64_t count); }; - - diff --git a/aegisub/src/audio_renderer_spectrum.cpp b/aegisub/src/audio_renderer_spectrum.cpp index ce17f7329..de95cedd5 100644 --- a/aegisub/src/audio_renderer_spectrum.cpp +++ b/aegisub/src/audio_renderer_spectrum.cpp @@ -53,6 +53,7 @@ #include +#include "include/aegisub/audio_provider.h" #include "audio_renderer_spectrum.h" #include "colorspace.h" #include "fft.h" diff --git a/aegisub/src/audio_renderer_spectrum.h b/aegisub/src/audio_renderer_spectrum.h index 2a3c7db4f..e89cedc96 100644 --- a/aegisub/src/audio_renderer_spectrum.h +++ b/aegisub/src/audio_renderer_spectrum.h @@ -36,15 +36,11 @@ /// /// Calculate and render a frequency-power spectrum for PCM audio data. - - - #ifndef AGI_PRE #include #endif -#include "audio_provider_manager.h" - +class AudioProvider; // Specified and implemented in cpp file, interface is private to spectrum code class AudioSpectrumCacheManager; diff --git a/aegisub/src/dialog_spellchecker.cpp b/aegisub/src/dialog_spellchecker.cpp index 7de4e624c..f27d5be22 100644 --- a/aegisub/src/dialog_spellchecker.cpp +++ b/aegisub/src/dialog_spellchecker.cpp @@ -50,7 +50,7 @@ #include "help_button.h" #include "libresrc/libresrc.h" #include "main.h" -#include "spellchecker_manager.h" +#include "include/aegisub/spellchecker.h" #include "subs_edit_box.h" #include "subs_edit_ctrl.h" #include "subs_grid.h" @@ -96,7 +96,7 @@ DialogSpellChecker::DialogSpellChecker(wxFrame *parent) SetIcon(BitmapToIcon(GETIMAGE(spellcheck_toolbutton_24))); // Get spell checker - spellchecker = SpellCheckerFactoryManager::GetSpellChecker(); + spellchecker = SpellCheckerFactory::GetSpellChecker(); if (!spellchecker) { wxMessageBox(_T("No spellchecker available."),_T("Error"),wxICON_ERROR); Destroy(); diff --git a/aegisub/src/dialog_style_editor.cpp b/aegisub/src/dialog_style_editor.cpp index b3e48b802..e5b50d6b0 100644 --- a/aegisub/src/dialog_style_editor.cpp +++ b/aegisub/src/dialog_style_editor.cpp @@ -57,7 +57,7 @@ #include "main.h" #include "subs_grid.h" #include "subs_preview.h" -#include "subtitles_provider_manager.h" +#include "include/aegisub/subtitles_provider.h" #include "utils.h" #include "validators.h" @@ -361,7 +361,7 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit // Preview SubsPreview = NULL; PreviewText = NULL; - if (SubtitlesProviderFactoryManager::ProviderAvailable()) { + if (!SubtitlesProviderFactory::GetClasses().empty()) { PreviewText = new wxTextCtrl(this,TEXT_PREVIEW,lagi_wxString(OPT_GET("Tool/Style Editor/Preview Text")->GetString())); previewButton = new ColourButton(this,BUTTON_PREVIEW_COLOR,wxSize(45,16),lagi_wxColour(OPT_GET("Colour/Style Editor/Background/Preview")->GetColour())); SubsPreview = new SubtitlesPreview(this,-1,wxDefaultPosition,wxSize(100,60),wxSUNKEN_BORDER,lagi_wxColour(OPT_GET("Colour/Style Editor/Background/Preview")->GetColour())); diff --git a/aegisub/src/dialog_video_details.cpp b/aegisub/src/dialog_video_details.cpp index 59e65dcb7..fadc9b889 100644 --- a/aegisub/src/dialog_video_details.cpp +++ b/aegisub/src/dialog_video_details.cpp @@ -34,17 +34,12 @@ /// @ingroup secondary_ui /// - -/////////// -// Headers #include "config.h" #ifndef AGI_PRE #include #endif -#include "audio_box.h" -#include "audio_provider_manager.h" #include "dialog_video_details.h" #include "utils.h" #include "video_context.h" diff --git a/aegisub/src/factory_manager.h b/aegisub/src/factory_manager.h index bb717809d..57b86bb73 100644 --- a/aegisub/src/factory_manager.h +++ b/aegisub/src/factory_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2008, Rodrigo Braz Monteiro +// Copyright (c) 2010, Thomas Goyne // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -34,117 +34,111 @@ /// @ingroup utility /// - #pragma once - -/////////// -// Headers #ifndef AGI_PRE +#include #include +#include -#include #include #endif - -///////////////// -// Factory class -template - -/// DOCME -/// @class FactoryManager -/// @brief DOCME -/// -/// DOCME -class FactoryManager { +template +class FactoryBase { protected: + typedef std::map > map; + typedef typename map::iterator iterator; - /// DOCME - static std::map *factories; + static map *classes; + static void DoRegister(func function, std::string name, bool hide, std::vector &subtypes) { + if (!classes) classes = new map; - /// @brief DOCME - /// - static void ClearFactories() { - if (factories && !factories->empty()) { - typename std::map::iterator iter; - for (iter = factories->begin(); iter != factories->end(); iter++) { - delete iter->second; - } - factories->clear(); + if (subtypes.empty()) { + classes->insert(std::make_pair(name, std::make_pair(hide, function))); } - delete factories; - } - - - /// @brief // Register one factory type (with possible subtypes) - /// @param factory - /// @param name - /// @param 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; - - // Prepare subtypes - if (subTypes.GetCount() == 0) subTypes.Add(_T("")); else { - for (unsigned int i=0;iinsert(std::make_pair(name + '/' + subtypes[i], std::make_pair(hide, function))); } } - - // Insert each subtype - for (unsigned int i=0;iinsert(std::make_pair(name.Lower() + subTypes[i],factory)); - } } + static func Find(std::string name) { + if (!classes) return NULL; - /// @brief // Get a factory with name - /// @param name - /// @return - /// - static T *GetFactory(wxString name) { - // No factories - if (factories == NULL) { - factories = new std::map; - return NULL; - } - - // Search for factory that matches - typename std::map::iterator cur; - for (cur = factories->begin();cur != factories->end();cur++) { - if (cur->first.StartsWith(name)) return cur->second; - } - - // None found + iterator factory = classes->find(name); + if (factory != classes->end()) return factory->second.second; return NULL; } public: - - /// @brief // Virtual destructor - /// - virtual ~FactoryManager() { - ClearFactories(); - }; - - - /// @brief // Get list of all factories, with favourite as first - /// @param favourite - /// - static wxArrayString GetFactoryList(wxString favourite=_T("")) { - if (factories == NULL) factories = new std::map; - wxArrayString list; - favourite = favourite.Lower(); - for (typename std::map::iterator cur=factories->begin();cur!=factories->end();cur++) { - if (cur->first == favourite) list.Insert(cur->first,0); - else list.Add(cur->first); + static void Clear() { + delete classes; + } + static std::vector GetClasses(std::string favourite="") { + std::vector list; + if (!classes) return list; + std::string cmp; + std::transform(favourite.begin(), favourite.end(), favourite.begin(), ::tolower); + for (iterator cur=classes->begin();cur!=classes->end();cur++) { + cmp.clear(); + std::transform(cur->first.begin(), cur->first.end(), std::back_inserter(cmp), ::tolower); + if (cmp == favourite) list.insert(list.begin(), cur->first); + else if (!cur->second.first) list.push_back(cur->first); } return list; } + virtual ~FactoryBase() { + delete classes; + } }; +template +class Factory0 : public FactoryBase { + typedef Base *(*func)(); + template + static Base* create() { + return new T; + } +public: + static Base* Create(std::string name) { + func factory = FactoryBase::Find(name); + if (factory) { + return factory(); + } + else { + return NULL; + } + } + template + static void Register(std::string name, bool hide = false, std::vector subTypes = std::vector()) { + DoRegister(&Factory0::create, name, hide, subTypes); + } +}; + +template +class Factory1 : public FactoryBase { + typedef Base *(*func)(Arg1); + template + static Base* create(Arg1 a1) { + return new T(a1); + } +public: + static Base* Create(std::string name, Arg1 a1) { + func factory = FactoryBase::Find(name); + if (factory) { + return factory(a1); + } + else { + return NULL; + } + } + + template + static void Register(std::string name, bool hide = false, std::vector subTypes = std::vector()) { + DoRegister(&Factory1::create, name, hide, subTypes); + } +}; diff --git a/aegisub/src/frame_main_events.cpp b/aegisub/src/frame_main_events.cpp index a10c29d84..c2ea46e58 100644 --- a/aegisub/src/frame_main_events.cpp +++ b/aegisub/src/frame_main_events.cpp @@ -34,7 +34,6 @@ /// @ingroup main_ui -////////////////// Include headers #include "config.h" #ifndef AGI_PRE @@ -79,6 +78,7 @@ #include "dialog_video_details.h" #include "frame_main.h" #include "hotkeys.h" +#include "include/aegisub/audio_player.h" #include "keyframe.h" #include "libresrc/libresrc.h" #include "main.h" diff --git a/aegisub/src/include/aegisub/audio_player.h b/aegisub/src/include/aegisub/audio_player.h index fa3429df2..9c3b8b05b 100644 --- a/aegisub/src/include/aegisub/audio_player.h +++ b/aegisub/src/include/aegisub/audio_player.h @@ -34,37 +34,26 @@ /// @ingroup main_headers audio_output /// - #pragma once - -/////////// -// Headers #ifndef AGI_PRE #include #include #include #endif -#include "aegisub.h" +#include "factory_manager.h" - -////////////// -// Prototypes class AudioProvider; - - /// @class AudioPlayer /// @brief DOCME /// /// DOCME class AudioPlayer : public wxEvtHandler { -private: void OnStopAudio(wxCommandEvent &event); protected: - /// DOCME AudioProvider *provider; @@ -98,27 +87,20 @@ public: virtual void SetEndPosition(int64_t pos)=0; virtual void SetCurrentPosition(int64_t pos)=0; - virtual wxMutex *GetMutex(); + virtual wxMutex *GetMutex() { return NULL; } - virtual void SetProvider(AudioProvider *provider); - AudioProvider *GetProvider(); + virtual void SetProvider(AudioProvider *new_provider) { provider = new_provider; } + AudioProvider *GetProvider() const { return provider; } - void SetDisplayTimer(wxTimer *timer); + void SetDisplayTimer(wxTimer *timer) { displayTimer = timer; } DECLARE_EVENT_TABLE() }; - - -/// @class AudioPlayerFactory -/// @brief DOCME -/// -/// DOCME -class AudioPlayerFactory { +class AudioPlayerFactory : public Factory0 { public: - - /// @brief DOCME - /// - virtual ~AudioPlayerFactory() {} - virtual AudioPlayer *CreatePlayer()=0; + static void RegisterProviders(); + static AudioPlayer *GetAudioPlayer(); }; + +DECLARE_EVENT_TYPE(wxEVT_STOP_AUDIO, -1) diff --git a/aegisub/src/include/aegisub/audio_provider.h b/aegisub/src/include/aegisub/audio_provider.h index 40a16295c..9e646f4ae 100644 --- a/aegisub/src/include/aegisub/audio_provider.h +++ b/aegisub/src/include/aegisub/audio_provider.h @@ -34,24 +34,13 @@ /// @ingroup main_headers audio_input /// - #pragma once - -/////////// -// Headers #ifndef AGI_PRE #include #endif -#include "aegisub.h" - - -////////////// -// Prototypes -class VideoProvider; - - +#include "factory_manager.h" /// @class AudioProvider /// @brief DOCME @@ -88,30 +77,26 @@ public: AudioProvider(); virtual ~AudioProvider(); - virtual wxString GetFilename(); + virtual wxString GetFilename() const { return filename; }; virtual void GetAudio(void *buf, int64_t start, int64_t count)=0; void GetAudioWithVolume(void *buf, int64_t start, int64_t count, double volume); - int64_t GetNumSamples(); - int GetSampleRate(); - int GetBytesPerSample(); - int GetChannels(); - virtual bool AreSamplesNativeEndian() = 0; + int64_t GetNumSamples() const { return num_samples; } + int GetSampleRate() const { return sample_rate; } + int GetBytesPerSample() const { return bytes_per_sample; } + int GetChannels() const { return channels; } + virtual bool AreSamplesNativeEndian() const = 0; void GetWaveForm(int *min,int *peak,int64_t start,int w,int h,int samples,float scale); }; - - +/// DOCME /// @class AudioProviderFactory /// @brief DOCME /// /// DOCME -class AudioProviderFactory { +class AudioProviderFactory : public Factory1 { public: - - /// @brief DOCME - /// - virtual ~AudioProviderFactory() {} - virtual AudioProvider *CreateProvider(wxString filename)=0; + static void RegisterProviders(); + static AudioProvider *GetProvider(wxString filename, int cache=-1); }; diff --git a/aegisub/src/include/aegisub/spellchecker.h b/aegisub/src/include/aegisub/spellchecker.h index 36b736fae..6898ee5c1 100644 --- a/aegisub/src/include/aegisub/spellchecker.h +++ b/aegisub/src/include/aegisub/spellchecker.h @@ -34,19 +34,14 @@ /// @ingroup main_headers spelling /// - #pragma once - -/////////// -// Headers #ifndef AGI_PRE #include #include #endif -#include "aegisub.h" - +#include "factory_manager.h" /// @class SpellChecker /// @brief DOCME @@ -54,16 +49,10 @@ /// DOCME class SpellChecker { public: - - /// @brief DOCME - /// - SpellChecker() {} - /// @brief DOCME /// virtual ~SpellChecker() {} - /// @brief DOCME /// @param word /// @return @@ -83,19 +72,13 @@ public: virtual void SetLanguage(wxString language)=0; }; - - -/// @class SpellCheckerFactory +/// DOCME +/// @class SpellCheckerFactoryManager /// @brief DOCME /// /// DOCME -class SpellCheckerFactory { +class SpellCheckerFactory : public Factory0 { public: - - /// @brief DOCME - /// - virtual ~SpellCheckerFactory() {} - virtual SpellChecker *CreateSpellChecker()=0; + static SpellChecker *GetSpellChecker(); + static void RegisterProviders(); }; - - diff --git a/aegisub/src/include/aegisub/subtitles_provider.h b/aegisub/src/include/aegisub/subtitles_provider.h index f80ccb6c7..89d31142e 100644 --- a/aegisub/src/include/aegisub/subtitles_provider.h +++ b/aegisub/src/include/aegisub/subtitles_provider.h @@ -34,20 +34,12 @@ /// @ingroup main_headers subtitle_rendering /// - #pragma once -/////////// -// Headers -#include "aegisub.h" -#include "video_frame.h" +#include "factory_manager.h" - -////////////// -// Prototypes class AssFile; - - +class AegiVideoFrame; /// @class SubtitlesProvider /// @brief DOCME @@ -55,7 +47,7 @@ class AssFile; /// DOCME class SubtitlesProvider { public: - virtual ~SubtitlesProvider(); + virtual ~SubtitlesProvider() { }; virtual void LoadSubtitles(AssFile *subs)=0; @@ -63,22 +55,16 @@ public: /// @param dst /// @param time /// - virtual void DrawSubtitles(AegiVideoFrame &dst,double time) {} + virtual void DrawSubtitles(AegiVideoFrame &dst,double time)=0; }; - - -/// @class SubtitlesProviderFactory +/// DOCME +/// @class SubtitlesProviderFactoryManager /// @brief DOCME /// /// DOCME -class SubtitlesProviderFactory { +class SubtitlesProviderFactory : public Factory1 { public: - - /// @brief DOCME - /// - virtual ~SubtitlesProviderFactory() {} - virtual SubtitlesProvider *CreateProvider(wxString subType=_T(""))=0; + static SubtitlesProvider *GetProvider(); + static void RegisterProviders(); }; - - diff --git a/aegisub/src/include/aegisub/video_provider.h b/aegisub/src/include/aegisub/video_provider.h index f01b0a10c..c56152be5 100644 --- a/aegisub/src/include/aegisub/video_provider.h +++ b/aegisub/src/include/aegisub/video_provider.h @@ -69,16 +69,3 @@ public: /// @return Returns true if caching is desired, false otherwise. virtual bool WantsCaching() const { return false; } }; - -/// @class VideoProviderFactory -/// @brief DOCME -/// -/// DOCME -class VideoProviderFactory { -public: - - /// @brief DOCME - /// - virtual ~VideoProviderFactory() {} - virtual VideoProvider *CreateProvider(wxString video)=0; -}; diff --git a/aegisub/src/md5.h b/aegisub/src/md5.h index 698c995d8..5eb6d6c46 100644 --- a/aegisub/src/md5.h +++ b/aegisub/src/md5.h @@ -21,7 +21,7 @@ ghost@aladdin.com */ -/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ +/* $Id$ */ /* Independent implementation of MD5 (RFC 1321). diff --git a/aegisub/src/plugin_manager.cpp b/aegisub/src/plugin_manager.cpp index 3344cf16c..1751a44aa 100644 --- a/aegisub/src/plugin_manager.cpp +++ b/aegisub/src/plugin_manager.cpp @@ -34,16 +34,13 @@ /// @ingroup main /// - -/////////// -// Headers #include "config.h" -#include "audio_player_manager.h" -#include "audio_provider_manager.h" +#include "include/aegisub/audio_player.h" +#include "include/aegisub/audio_provider.h" +#include "include/aegisub/spellchecker.h" +#include "include/aegisub/subtitles_provider.h" #include "plugin_manager.h" -#include "spellchecker_manager.h" -#include "subtitles_provider_manager.h" #include "video_provider_manager.h" @@ -59,15 +56,14 @@ PluginManager::PluginManager() { } - /// @brief Destructor /// PluginManager::~PluginManager() { - VideoProviderFactoryManager::ClearProviders(); - AudioProviderFactoryManager::ClearProviders(); - AudioPlayerFactoryManager::ClearProviders(); - SubtitlesProviderFactoryManager::ClearProviders(); - SpellCheckerFactoryManager::ClearProviders(); + VideoProviderFactory::Clear(); + AudioProviderFactory::Clear(); + AudioPlayerFactory::Clear(); + SubtitlesProviderFactory::Clear(); + SpellCheckerFactory::Clear(); #ifdef WITH_AUTO4_LUA if (lua) { @@ -85,11 +81,11 @@ PluginManager::~PluginManager() { void PluginManager::RegisterBuiltInPlugins() { if (!init) { // Managers - VideoProviderFactoryManager::RegisterProviders(); - AudioProviderFactoryManager::RegisterProviders(); - AudioPlayerFactoryManager::RegisterProviders(); - SubtitlesProviderFactoryManager::RegisterProviders(); - SpellCheckerFactoryManager::RegisterProviders(); + VideoProviderFactory::RegisterProviders(); + AudioProviderFactory::RegisterProviders(); + AudioPlayerFactory::RegisterProviders(); + SubtitlesProviderFactory::RegisterProviders(); + SpellCheckerFactory::RegisterProviders(); // Automation languages #ifdef WITH_AUTO4_LUA @@ -101,5 +97,3 @@ void PluginManager::RegisterBuiltInPlugins() { // Done init = true; } - - diff --git a/aegisub/src/preferences.cpp b/aegisub/src/preferences.cpp index c34e150e1..dce87162b 100644 --- a/aegisub/src/preferences.cpp +++ b/aegisub/src/preferences.cpp @@ -20,6 +20,8 @@ #ifndef AGI_PRE +#include + #include #include #include @@ -37,10 +39,10 @@ #include "libresrc/libresrc.h" #include "preferences.h" #include "main.h" -#include "subtitles_provider_manager.h" +#include "include/aegisub/audio_player.h" +#include "include/aegisub/audio_provider.h" +#include "include/aegisub/subtitles_provider.h" #include "video_provider_manager.h" -#include "audio_player_manager.h" -#include "audio_provider_manager.h" /// Define make all platform-specific options visible in a single view. #define SHOW_ALL 1 @@ -296,15 +298,20 @@ Advanced_Interface::Advanced_Interface(wxTreebook *book): OptionPage(book, _("Ba SetSizerAndFit(sizer); } +static wxArrayString vec_to_arrstr(std::vector const& vec) { + wxArrayString arrstr; + std::copy(vec.begin(), vec.end(), std::back_inserter(arrstr)); + return arrstr; +} /// Advanced Audio preferences subpage Advanced_Audio::Advanced_Audio(wxTreebook *book): OptionPage(book, _("Audio"), PAGE_SUB) { wxFlexGridSizer *expert = PageSizer(_("Expert")); - wxArrayString ap_choice = AudioProviderFactoryManager::GetFactoryList(); + wxArrayString ap_choice = vec_to_arrstr(AudioProviderFactory::GetClasses()); OptionChoice(expert, _("Audio provider"), ap_choice, "Audio/Provider"); - wxArrayString apl_choice = AudioPlayerFactoryManager::GetFactoryList(); + wxArrayString apl_choice = vec_to_arrstr(AudioPlayerFactory::GetClasses()); OptionChoice(expert, _("Audio player"), apl_choice, "Audio/Player"); wxFlexGridSizer *cache = PageSizer(_("Cache")); @@ -340,10 +347,10 @@ Advanced_Audio::Advanced_Audio(wxTreebook *book): OptionPage(book, _("Audio"), P Advanced_Video::Advanced_Video(wxTreebook *book): OptionPage(book, _("Video")) { wxFlexGridSizer *expert = PageSizer(_("Expert")); - wxArrayString vp_choice = VideoProviderFactoryManager::GetFactoryList(); + wxArrayString vp_choice = vec_to_arrstr(VideoProviderFactory::GetClasses()); OptionChoice(expert, _("Video provider"), vp_choice, "Video/Provider"); - wxArrayString sp_choice = SubtitlesProviderFactoryManager::GetFactoryList(); + wxArrayString sp_choice = vec_to_arrstr(SubtitlesProviderFactory::GetClasses()); OptionChoice(expert, _("Subtitle provider"), sp_choice, "Subtitle/Provider"); diff --git a/aegisub/src/preferences_base.cpp b/aegisub/src/preferences_base.cpp index 7b3094bdc..503c7ffbf 100644 --- a/aegisub/src/preferences_base.cpp +++ b/aegisub/src/preferences_base.cpp @@ -37,10 +37,9 @@ #include "libresrc/libresrc.h" #include "preferences.h" #include "main.h" -#include "subtitles_provider_manager.h" +#include "include/aegisub/audio_player.h" +#include "include/aegisub/audio_provider.h" #include "video_provider_manager.h" -#include "audio_player_manager.h" -#include "audio_provider_manager.h" #include "preferences_base.h" diff --git a/aegisub/src/spellchecker.cpp b/aegisub/src/spellchecker.cpp index 606f296de..34b847e26 100644 --- a/aegisub/src/spellchecker.cpp +++ b/aegisub/src/spellchecker.cpp @@ -34,9 +34,6 @@ /// @ingroup spelling /// - -/////////// -// Headers #include "config.h" #ifdef WITH_HUNSPELL @@ -44,26 +41,22 @@ #endif #include "compat.h" +#include "include/aegisub/spellchecker.h" #include "main.h" -#include "spellchecker_manager.h" - - /// @brief Get spell checker /// @return /// -SpellChecker *SpellCheckerFactoryManager::GetSpellChecker() { +SpellChecker *SpellCheckerFactory::GetSpellChecker() { // List of providers - wxArrayString list = GetFactoryList(lagi_wxString(OPT_GET("Tool/Spell Checker/Backend")->GetString())); - - // None available - if (list.Count() == 0) return 0; //throw _T("No spell checkers are available."); + std::vector list = GetClasses(OPT_GET("Tool/Spell Checker/Backend")->GetString()); + if (list.empty()) return NULL; // Get provider wxString error; - for (unsigned int i=0;iCreateSpellChecker(); + SpellChecker *checker = Create(list[i]); if (checker) return checker; } catch (wxString err) { error += list[i] + _T(" factory: ") + err + _T("\n"); } @@ -75,27 +68,12 @@ SpellChecker *SpellCheckerFactoryManager::GetSpellChecker() { throw error; } - - /// @brief Register all providers /// -void SpellCheckerFactoryManager::RegisterProviders() { +void SpellCheckerFactory::RegisterProviders() { #ifdef WITH_HUNSPELL - RegisterFactory(new HunspellSpellCheckerFactory(),_T("Hunspell")); + Register("Hunspell"); #endif } - - -/// @brief Clear all providers -/// -void SpellCheckerFactoryManager::ClearProviders() { - ClearFactories(); -} - - - -/// DOCME -template std::map* FactoryManager::factories=NULL; - - +template<> SpellCheckerFactory::map *FactoryBase::classes = NULL; diff --git a/aegisub/src/spellchecker_hunspell.h b/aegisub/src/spellchecker_hunspell.h index dfa407292..1ac33ce0d 100644 --- a/aegisub/src/spellchecker_hunspell.h +++ b/aegisub/src/spellchecker_hunspell.h @@ -49,7 +49,6 @@ namespace agi { } } - /// @class HunspellSpellChecker /// @brief Hunspell spell checker /// @@ -88,19 +87,4 @@ public: void SetLanguage(wxString language); }; - - -/// @class HunspellSpellCheckerFactory -/// @brief Hunspell SpellChecker Factory -/// -class HunspellSpellCheckerFactory : public SpellCheckerFactory { -public: - - /// @brief Create new Hunspell Spell checker. - /// - SpellChecker *CreateSpellChecker() { return new HunspellSpellChecker(); } -}; - #endif - - diff --git a/aegisub/src/spellchecker_manager.h b/aegisub/src/spellchecker_manager.h deleted file mode 100644 index 93f271d9e..000000000 --- a/aegisub/src/spellchecker_manager.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2006, 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 Project http://www.aegisub.org/ -// -// $Id$ - -/// @file spellchecker_manager.h -/// @brief Factory class for spell checkers -/// @ingroup spelling -/// - - -#pragma once - - -/////////// -// Headers -#include "factory_manager.h" -#include "include/aegisub/spellchecker.h" - - -/// DOCME -/// @class SpellCheckerFactoryManager -/// @brief DOCME -/// -/// DOCME -class SpellCheckerFactoryManager : public FactoryManager { -public: - static SpellChecker *GetSpellChecker(); - static void RegisterProviders(); - static void ClearProviders(); -}; - - diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index 5282a02eb..d111f4d8b 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -48,7 +48,7 @@ #include "ass_dialogue.h" #include "compat.h" #include "main.h" -#include "spellchecker_manager.h" +#include "include/aegisub/spellchecker.h" #include "subs_edit_box.h" #include "subs_edit_ctrl.h" #include "subs_grid.h" @@ -88,7 +88,7 @@ enum { /// SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, SubtitlesGrid *grid) : ScintillaTextCtrl(parent, wxID_ANY, "", wxDefaultPosition, wsize, style) -, spellchecker(SpellCheckerFactoryManager::GetSpellChecker()) +, spellchecker(SpellCheckerFactory::GetSpellChecker()) , thesaurus(Thesaurus::GetThesaurus()) , grid(grid) { diff --git a/aegisub/src/subs_grid.cpp b/aegisub/src/subs_grid.cpp index 33b90ea13..93b08d03a 100644 --- a/aegisub/src/subs_grid.cpp +++ b/aegisub/src/subs_grid.cpp @@ -45,10 +45,13 @@ #include #endif +#include "include/aegisub/audio_provider.h" #include "ass_file.h" #include "ass_karaoke.h" #include "ass_override.h" #include "ass_style.h" +#include "audio_box.h" +#include "audio_display.h" #include "charset_conv.h" #include "dialog_paste_over.h" #include "frame_main.h" diff --git a/aegisub/src/subs_grid.h b/aegisub/src/subs_grid.h index 5c3b7bd63..d34c375dc 100644 --- a/aegisub/src/subs_grid.h +++ b/aegisub/src/subs_grid.h @@ -44,9 +44,6 @@ #include #endif -#include "audio_box.h" -#include "audio_display.h" -#include "audio_provider_manager.h" #include "base_grid.h" class AssFile; @@ -54,7 +51,6 @@ class AssEntry; class AssDialogue; class SubsEditBox; class FrameMain; -class AudioDisplay; typedef std::list::iterator entryIter; diff --git a/aegisub/src/subs_preview.cpp b/aegisub/src/subs_preview.cpp index 396917b68..4b17e9085 100644 --- a/aegisub/src/subs_preview.cpp +++ b/aegisub/src/subs_preview.cpp @@ -47,7 +47,7 @@ #include "ass_file.h" #include "ass_style.h" #include "subs_preview.h" -#include "subtitles_provider_manager.h" +#include "include/aegisub/subtitles_provider.h" #include "video_provider_dummy.h" @@ -139,7 +139,7 @@ void SubtitlesPreview::OnSize(wxSizeEvent &evt) { bmp.reset(new wxBitmap(w, h, -1)); vid.reset(new DummyVideoProvider(0.0, 10, w, h, backColour, true)); try { - provider.reset(SubtitlesProviderFactoryManager::GetProvider()); + provider.reset(SubtitlesProviderFactory::GetProvider()); } catch (...) { wxMessageBox( diff --git a/aegisub/src/subtitle_format_dvd.cpp b/aegisub/src/subtitle_format_dvd.cpp index 9ef994dad..5d59dc8c7 100644 --- a/aegisub/src/subtitle_format_dvd.cpp +++ b/aegisub/src/subtitle_format_dvd.cpp @@ -42,7 +42,7 @@ #include "ass_dialogue.h" #include "ass_file.h" #include "subtitle_format_dvd.h" -#include "subtitles_provider_manager.h" +#include "include/aegisub/subtitles_provider.h" #include "video_provider_dummy.h" @@ -115,7 +115,7 @@ void DVDSubtitleFormat::GetSubPictureList(std::vector &pics) { pics.resize(count); SubtitlesProvider *provider = NULL; - provider = SubtitlesProviderFactoryManager::GetProvider(); + provider = SubtitlesProviderFactory::GetProvider(); provider->LoadSubtitles(GetAssFile()); //TessDllAPI tess; diff --git a/aegisub/src/subtitles_provider.cpp b/aegisub/src/subtitles_provider.cpp index f5a084d21..9e5564e3f 100644 --- a/aegisub/src/subtitles_provider.cpp +++ b/aegisub/src/subtitles_provider.cpp @@ -34,9 +34,6 @@ /// @ingroup subtitle_rendering /// - -/////////// -// Headers #include "config.h" #include "compat.h" @@ -47,47 +44,22 @@ #ifdef WITH_LIBASS #include "subtitles_provider_libass.h" #endif -#include "subtitles_provider_manager.h" - - -/// @brief Destructor -/// -SubtitlesProvider::~SubtitlesProvider() { -} - - - -/// @brief Check if provider available (doesn't verify provider works!) -/// @return -/// -bool SubtitlesProviderFactoryManager::ProviderAvailable() { - // List of providers - wxArrayString list = GetFactoryList(lagi_wxString(OPT_GET("Subtitle/Provider")->GetString())); - - // None available - return (list.Count() > 0); -} - - /// @brief Get provider /// @return /// -SubtitlesProvider* SubtitlesProviderFactoryManager::GetProvider() { - // List of providers - wxArrayString list = GetFactoryList(lagi_wxString(OPT_GET("Subtitle/Provider")->GetString())); - - // None available - if (list.Count() == 0) throw _T("No subtitle providers are available."); +SubtitlesProvider* SubtitlesProviderFactory::GetProvider() { + std::vector list = GetClasses(OPT_GET("Subtitle/Provider")->GetString()); + if (list.empty()) throw _T("No subtitle providers are available."); // Get provider wxString error; - for (unsigned int i=0;iCreateProvider(subType); + size_t pos = list[i].find('/'); + std::string name = list[i].substr(0, pos); + std::string subType = pos < list[i].size() - 1 ? list[i].substr(pos + 1) : ""; + SubtitlesProvider *provider = Create(list[i], subType); if (provider) return provider; } catch (wxString err) { error += list[i] + _T(" factory: ") + err + _T("\n"); } @@ -99,31 +71,15 @@ SubtitlesProvider* SubtitlesProviderFactoryManager::GetProvider() { throw error; } - - /// @brief Register providers /// -void SubtitlesProviderFactoryManager::RegisterProviders() { +void SubtitlesProviderFactory::RegisterProviders() { #ifdef WITH_CSRI - CSRISubtitlesProviderFactory *csri = new CSRISubtitlesProviderFactory(); - RegisterFactory(csri,_T("CSRI"),csri->GetSubTypes()); + Register("CSRI", false, CSRISubtitlesProvider::GetSubTypes()); #endif #ifdef WITH_LIBASS - RegisterFactory(new LibassSubtitlesProviderFactory(),_T("libass")); + Register("libass"); #endif } - - -/// @brief Clear providers -/// -void SubtitlesProviderFactoryManager::ClearProviders() { - ClearFactories(); -} - - - -/// DOCME -template std::map* FactoryManager::factories=NULL; - - +template<> SubtitlesProviderFactory::map *FactoryBase::classes = NULL; diff --git a/aegisub/src/subtitles_provider_csri.cpp b/aegisub/src/subtitles_provider_csri.cpp index 16aa654a3..cb779bd9f 100644 --- a/aegisub/src/subtitles_provider_csri.cpp +++ b/aegisub/src/subtitles_provider_csri.cpp @@ -34,12 +34,8 @@ /// @ingroup subtitle_rendering /// - -/////////// -// Headers #include "config.h" - #ifdef WITH_CSRI #include "ass_file.h" @@ -50,39 +46,29 @@ /// @brief Constructor /// @param type /// -CSRISubtitlesProvider::CSRISubtitlesProvider(wxString type) { - subType = type; - instance = NULL; +CSRISubtitlesProvider::CSRISubtitlesProvider(std::string type) : subType(type) { } /// @brief Destructor /// CSRISubtitlesProvider::~CSRISubtitlesProvider() { if (!tempfile.empty()) wxRemoveFile(tempfile); - if (instance) csri_close(instance); - instance = NULL; } /// @brief Load subtitles /// @param subs /// void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) { - // Close - if (instance) csri_close(instance); - instance = NULL; - // CSRI variables csri_rend *cur,*renderer=NULL; - csri_info *info; // Select renderer bool canOpenMem = true; for (cur = csri_renderer_default();cur;cur=csri_renderer_next(cur)) { - info = csri_renderer_info(cur); - wxString name(info->name,wxConvUTF8); + std::string name(csri_renderer_info(cur)->name); if (name == subType) { renderer = cur; - if (name.StartsWith(_T("vsfilter"))) canOpenMem = false; + if (name.find("vsfilter") != name.npos) canOpenMem = false; break; } } @@ -99,7 +85,7 @@ void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) { if (canOpenMem) { std::vector data; subs->SaveMemory(data,wxSTRING_ENCODING); - instance = csri_open_mem(renderer,&data[0],data.size(),NULL); + instance.reset(csri_open_mem(renderer,&data[0],data.size(),NULL), &csri_close); } // Open from disk @@ -110,7 +96,7 @@ void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) { tempfile += L".ass"; } subs->Save(tempfile,false,false,wxSTRING_ENCODING); - instance = csri_open_file(renderer,tempfile.utf8_str(),NULL); + instance.reset(csri_open_file(renderer,tempfile.utf8_str(),NULL), &csri_close); } } @@ -121,7 +107,7 @@ void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) { /// void CSRISubtitlesProvider::DrawSubtitles(AegiVideoFrame &dst,double time) { // Check if CSRI loaded properly - if (!instance) return; + if (!instance.get()) return; // Load data into frame csri_frame frame; @@ -146,31 +132,19 @@ void CSRISubtitlesProvider::DrawSubtitles(AegiVideoFrame &dst,double time) { format.width = dst.w; format.height = dst.h; format.pixfmt = frame.pixfmt; - int error = csri_request_fmt(instance,&format); + int error = csri_request_fmt(instance.get(),&format); if (error) return; // Render - csri_render(instance,&frame,time); + csri_render(instance.get(),&frame,time); } /// @brief Get CSRI subtypes /// -wxArrayString CSRISubtitlesProviderFactory::GetSubTypes() { - csri_info *info; - wxArrayString final; +std::vector CSRISubtitlesProvider::GetSubTypes() { + std::vector final; for (csri_rend *cur = csri_renderer_default();cur;cur = csri_renderer_next(cur)) { - // Get renderer name - info = csri_renderer_info(cur); - const char* buffer = info->name; - - // wxWidgets isn't initialized, so h4x into a wxString - int len = strlen(buffer); - wxString str; - str.Alloc(len+1); - for (int i=0;iname); } return final; } diff --git a/aegisub/src/subtitles_provider_csri.h b/aegisub/src/subtitles_provider_csri.h index ddc954bd9..8800d5046 100644 --- a/aegisub/src/subtitles_provider_csri.h +++ b/aegisub/src/subtitles_provider_csri.h @@ -36,13 +36,14 @@ #ifdef WITH_CSRI -#include "include/aegisub/subtitles_provider.h" -#ifdef WIN32 -/// DOCME -#define CSRIAPI +#ifndef AGI_PRE +#include +#include #endif -#ifdef __WINDOWS__ +#include "include/aegisub/subtitles_provider.h" +#ifdef WIN32 +#define CSRIAPI #include "../../contrib/csri/include/csri/csri.h" #else #include @@ -55,32 +56,19 @@ /// DOCME class CSRISubtitlesProvider : public SubtitlesProvider { /// DOCME - wxString subType; + std::string subType; /// DOCME - csri_inst *instance; + std::tr1::shared_ptr instance; wxString tempfile; public: - CSRISubtitlesProvider(wxString subType); + CSRISubtitlesProvider(std::string subType); ~CSRISubtitlesProvider(); void LoadSubtitles(AssFile *subs); void DrawSubtitles(AegiVideoFrame &dst,double time); -}; -/// DOCME -/// @class CSRISubtitlesProviderFactory -/// @brief DOCME -/// -/// DOCME -class CSRISubtitlesProviderFactory : public SubtitlesProviderFactory { -public: - /// @brief DOCME - /// @param subType - /// - SubtitlesProvider *CreateProvider(wxString subType=_T("")) { return new CSRISubtitlesProvider(subType); } - wxArrayString GetSubTypes(); + static std::vector GetSubTypes(); }; - #endif diff --git a/aegisub/src/subtitles_provider_libass.cpp b/aegisub/src/subtitles_provider_libass.cpp index acbcd73cc..69c272a24 100644 --- a/aegisub/src/subtitles_provider_libass.cpp +++ b/aegisub/src/subtitles_provider_libass.cpp @@ -34,11 +34,8 @@ /// @ingroup subtitle_rendering /// -/////////// -// Headers #include "config.h" - #ifdef WITH_LIBASS #ifndef AGI_PRE @@ -61,7 +58,6 @@ extern "C" { #include "video_context.h" - /// @brief Handle libass messages /// static void msg_callback(int level, const char *fmt, va_list args, void *data) { @@ -74,11 +70,9 @@ static void msg_callback(int level, const char *fmt, va_list args, void *data) { LOG_D("subtitle/provider/libass") << buf; } - - /// @brief Constructor /// -LibassSubtitlesProvider::LibassSubtitlesProvider() { +LibassSubtitlesProvider::LibassSubtitlesProvider(std::string) { // Initialize library static bool first = true; if (first) { @@ -117,15 +111,11 @@ LibassSubtitlesProvider::LibassSubtitlesProvider() { ass_set_fonts(ass_renderer, NULL, "Sans", 1, config_path, 1); } - - /// @brief Destructor /// LibassSubtitlesProvider::~LibassSubtitlesProvider() { } - - /// @brief Load subtitles /// @param subs /// @@ -140,8 +130,6 @@ void LibassSubtitlesProvider::LoadSubtitles(AssFile *subs) { if (!ass_track) throw _T("libass failed to load subtitles."); } - - /// DOCME #define _r(c) ((c)>>24) @@ -210,10 +198,7 @@ void LibassSubtitlesProvider::DrawSubtitles(AegiVideoFrame &frame,double time) { } } - - /// DOCME ASS_Library* LibassSubtitlesProvider::ass_library; - #endif // WITH_LIBASS diff --git a/aegisub/src/subtitles_provider_libass.h b/aegisub/src/subtitles_provider_libass.h index 8c512de86..fb89f91a1 100644 --- a/aegisub/src/subtitles_provider_libass.h +++ b/aegisub/src/subtitles_provider_libass.h @@ -34,12 +34,9 @@ /// @ingroup subtitle_rendering /// -/////////// -// Headers - #ifdef WITH_LIBASS -#include "subtitles_provider_manager.h" +#include "include/aegisub/subtitles_provider.h" extern "C" { #ifdef __VISUALC__ #include "stdint.h" @@ -55,8 +52,6 @@ extern "C" { /// /// DOCME class LibassSubtitlesProvider : public SubtitlesProvider { -private: - /// DOCME static ASS_Library* ass_library; @@ -67,27 +62,10 @@ private: ASS_Track* ass_track; public: - LibassSubtitlesProvider(); + LibassSubtitlesProvider(std::string); ~LibassSubtitlesProvider(); void LoadSubtitles(AssFile *subs); void DrawSubtitles(AegiVideoFrame &dst,double time); }; - - - -/// DOCME -/// @class LibassSubtitlesProviderFactory -/// @brief DOCME -/// -/// DOCME -class LibassSubtitlesProviderFactory : public SubtitlesProviderFactory { -public: - - /// @brief DOCME - /// @param subType - /// - SubtitlesProvider *CreateProvider(wxString subType=_T("")) { return new LibassSubtitlesProvider(); } -}; - #endif diff --git a/aegisub/src/subtitles_provider_manager.h b/aegisub/src/subtitles_provider_manager.h deleted file mode 100644 index 4369fe6e1..000000000 --- a/aegisub/src/subtitles_provider_manager.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2007, 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 Project http://www.aegisub.org/ -// -// $Id$ - -/// @file subtitles_provider_manager.h -/// @brief Keep track of installed subtitle renderers -/// @ingroup subtitle_rendering -/// - - -#pragma once - - -/////////// -// Headers -#include "factory_manager.h" -#include "include/aegisub/subtitles_provider.h" -#include "video_frame.h" - - -/// DOCME -/// @class SubtitlesProviderFactoryManager -/// @brief DOCME -/// -/// DOCME -class SubtitlesProviderFactoryManager : public FactoryManager { -public: - static SubtitlesProvider *GetProvider(); - static void RegisterProviders(); - static void ClearProviders(); - static bool ProviderAvailable(); -}; - - - diff --git a/aegisub/src/threaded_frame_source.cpp b/aegisub/src/threaded_frame_source.cpp index a21ccf7a6..dd9d7f85f 100644 --- a/aegisub/src/threaded_frame_source.cpp +++ b/aegisub/src/threaded_frame_source.cpp @@ -45,7 +45,7 @@ #include "ass_exporter.h" #include "ass_file.h" #include "compat.h" -#include "subtitles_provider_manager.h" +#include "include/aegisub/subtitles_provider.h" #include "video_provider_manager.h" // Test if a line is a dialogue line which is not visible at the given time @@ -152,8 +152,8 @@ void *ThreadedFrameSource::Entry() { ThreadedFrameSource::ThreadedFrameSource(wxString videoFileName, wxEvtHandler *parent) : wxThread() -, provider(SubtitlesProviderFactoryManager::GetProvider()) -, videoProvider(VideoProviderFactoryManager::GetProvider(videoFileName)) +, provider(SubtitlesProviderFactory::GetProvider()) +, videoProvider(VideoProviderFactory::GetProvider(videoFileName)) , parent(parent) , nextTime(-1.) , jobReady(jobMutex) diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index 8f0ee1d35..1fdc41e86 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -59,6 +59,8 @@ #include "ass_time.h" #include "audio_display.h" #include "compat.h" +#include "include/aegisub/audio_player.h" +#include "include/aegisub/audio_provider.h" #include "include/aegisub/video_provider.h" #include "keyframe.h" #include diff --git a/aegisub/src/video_out_gl.h b/aegisub/src/video_out_gl.h index 7bc7c2393..7c67c26ef 100644 --- a/aegisub/src/video_out_gl.h +++ b/aegisub/src/video_out_gl.h @@ -27,7 +27,7 @@ // // Aegisub Project http://www.aegisub.org/ // -// $Id: video_out_gl.h 3613 2009-10-05 00:06:11Z plorkyeran $ +// $Id$ /// @file video_out_gl.h /// @brief OpenGL based video renderer diff --git a/aegisub/src/video_provider_avs.h b/aegisub/src/video_provider_avs.h index 389462475..beceb5b6e 100644 --- a/aegisub/src/video_provider_avs.h +++ b/aegisub/src/video_provider_avs.h @@ -95,19 +95,4 @@ public: wxString GetWarning() const; wxString GetDecoderName() const { return wxString(L"Avisynth/") + decoderName; } }; - -/// DOCME -/// @class AvisynthVideoProviderFactory -/// @brief DOCME -/// -/// DOCME -class AvisynthVideoProviderFactory : public VideoProviderFactory { -public: - - /// @brief DOCME - /// @param video - /// - VideoProvider *CreateProvider(wxString video) { return new AvisynthVideoProvider(video); } -}; - #endif diff --git a/aegisub/src/video_provider_ffmpegsource.h b/aegisub/src/video_provider_ffmpegsource.h index 1ced5e125..c7e1626cc 100644 --- a/aegisub/src/video_provider_ffmpegsource.h +++ b/aegisub/src/video_provider_ffmpegsource.h @@ -86,15 +86,4 @@ public: /// @return Returns true. bool WantsCaching() const { return true; } }; - -/// @class FFmpegSourceVideoProviderFactory -/// @brief Creates a FFmpegSource video provider. -class FFmpegSourceVideoProviderFactory : public VideoProviderFactory { -public: - /// @brief Creates a FFmpegSource video provider. - /// @param video The video filename to open. - /// @return Returns the video provider. - VideoProvider *CreateProvider(wxString video) { return new FFmpegSourceVideoProvider(video); } -}; - #endif /* WITH_FFMPEGSOURCE */ diff --git a/aegisub/src/video_provider_manager.cpp b/aegisub/src/video_provider_manager.cpp index 80d917b83..a9ff88d1a 100644 --- a/aegisub/src/video_provider_manager.cpp +++ b/aegisub/src/video_provider_manager.cpp @@ -57,7 +57,7 @@ /// @param video /// @return /// -VideoProvider *VideoProviderFactoryManager::GetProvider(wxString video) { +VideoProvider *VideoProviderFactory::GetProvider(wxString video) { // First check special case of dummy video if (video.StartsWith(_T("?dummy:"))) { return new DummyVideoProvider(video.wc_str()); @@ -73,21 +73,23 @@ VideoProvider *VideoProviderFactoryManager::GetProvider(wxString video) { LOG_E("manager/video/provider/yuv4mpeg") << "Provider creation failed with reason: "<< temp.c_str() << " trying other providers"; } catch (...) { - LOG_E("manager/video/provider/yuv4mpeg") << "Provider creation failed (uknown reason) trying other providers"; + LOG_E("manager/video/provider/yuv4mpeg") << "Provider creation failed (unknown reason) trying other providers"; } // List of providers - wxArrayString list = GetFactoryList(lagi_wxString(OPT_GET("Video/Provider")->GetString())); + std::vector list = GetClasses(OPT_GET("Video/Provider")->GetString()); + if (video.StartsWith("?dummy")) list.insert(list.begin(), "Dummy"); + list.insert(list.begin(), "YUV4MPEG"); // None available - if (list.Count() == 0) throw _T("No video providers are available."); + if (list.empty()) throw _T("No video providers are available."); // Get provider wxString error; - for (unsigned int i=0;iCreateProvider(video); + VideoProvider *provider = Create(list[i], video); if (provider) { // Cache if necessary if (provider->WantsCaching()) { @@ -105,30 +107,18 @@ VideoProvider *VideoProviderFactoryManager::GetProvider(wxString video) { throw error; } - - /// @brief Register all providers /// -void VideoProviderFactoryManager::RegisterProviders() { +void VideoProviderFactory::RegisterProviders() { #ifdef WITH_AVISYNTH - RegisterFactory(new AvisynthVideoProviderFactory(),_T("Avisynth")); + Register("Avisynth"); #endif #ifdef WITH_FFMPEGSOURCE - RegisterFactory(new FFmpegSourceVideoProviderFactory(),_T("FFmpegSource")); + Register("FFmpegSource"); #endif + Register("Dummy", true); + Register("YUV4MPEG", true); } - - -/// @brief Clear all providers -/// -void VideoProviderFactoryManager::ClearProviders() { - ClearFactories(); -} - - - /// DOCME -template std::map* FactoryManager::factories=NULL; - - +template<> VideoProviderFactory::map *FactoryBase::classes = NULL; diff --git a/aegisub/src/video_provider_manager.h b/aegisub/src/video_provider_manager.h index d1d76c2bb..774856e73 100644 --- a/aegisub/src/video_provider_manager.h +++ b/aegisub/src/video_provider_manager.h @@ -34,30 +34,11 @@ /// @ingroup video_input /// - - - -////////// -// Headers -#ifndef AGI_PRE -#include -#endif - #include "factory_manager.h" #include "include/aegisub/video_provider.h" -#include "video_frame.h" - -/// DOCME -/// @class VideoProviderFactoryManager -/// @brief DOCME -/// -/// DOCME -class VideoProviderFactoryManager : public FactoryManager { +class VideoProviderFactory : public Factory1 { public: - static void RegisterProviders(); static VideoProvider *GetProvider(wxString video); - static void ClearProviders(); + static void RegisterProviders(); }; - -