mirror of
https://github.com/libretro/Play-.git
synced 2025-02-20 19:51:10 +00:00
PsfPlayer: Added ability to change character encoding interpretation of tags.
git-svn-id: http://svn.purei.org/purei/trunk@651 b36208d7-6611-0410-8bec-b1987f11c4a2
This commit is contained in:
parent
5aef006c90
commit
6e20e2540f
@ -4,7 +4,7 @@
|
||||
//Don't put tabs here since it will screw up the installer package
|
||||
|
||||
#define APP_NAME _T("PsfPlayer")
|
||||
#define APP_VERSION (44)
|
||||
#define APP_VERSIONSTR _T("0.44")
|
||||
#define APP_VERSION (45)
|
||||
#define APP_VERSIONSTR _T("0.45")
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "PsfTags.h"
|
||||
#include "string_cast_sjis.h"
|
||||
#include "string_cast_win1252.h"
|
||||
#include "Utf8.h"
|
||||
|
||||
using namespace Framework;
|
||||
@ -23,13 +24,13 @@ CPsfTags::~CPsfTags()
|
||||
|
||||
void CPsfTags::Init()
|
||||
{
|
||||
SetDefaultCharEncoding(SHIFT_JIS);
|
||||
SetStringConverter(m_defaultEncoding);
|
||||
SetDefaultCharEncoding(CE_WINDOWS_1252);
|
||||
}
|
||||
|
||||
void CPsfTags::SetDefaultCharEncoding(const CHAR_ENCODING& encoding)
|
||||
{
|
||||
m_defaultEncoding = encoding;
|
||||
SetStringConverter(m_defaultEncoding);
|
||||
}
|
||||
|
||||
bool CPsfTags::HasTag(const char* tagName) const
|
||||
@ -145,10 +146,13 @@ void CPsfTags::SetStringConverter(const CHAR_ENCODING& encoding)
|
||||
{
|
||||
switch(encoding)
|
||||
{
|
||||
case SHIFT_JIS:
|
||||
case CE_WINDOWS_1252:
|
||||
m_stringConverter = string_cast_win1252;
|
||||
break;
|
||||
case CE_SHIFT_JIS:
|
||||
m_stringConverter = string_cast_sjis;
|
||||
break;
|
||||
case UTF8:
|
||||
case CE_UTF8:
|
||||
m_stringConverter = Utf8::ConvertFromSafe;
|
||||
break;
|
||||
default:
|
||||
|
@ -13,9 +13,10 @@ public:
|
||||
|
||||
enum CHAR_ENCODING
|
||||
{
|
||||
INVALID,
|
||||
SHIFT_JIS,
|
||||
UTF8,
|
||||
CE_INVALID = 0,
|
||||
CE_WINDOWS_1252 = 1,
|
||||
CE_SHIFT_JIS = 2,
|
||||
CE_UTF8 = 3,
|
||||
};
|
||||
|
||||
CPsfTags();
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define WNDSTYLEEX (0)
|
||||
|
||||
#define ID_FILE_AUDIOPLUGIN_PLUGIN_0 (0xBEEF)
|
||||
#define ID_FILE_CHARENCODING_ENCODING_0 (0xCEEF)
|
||||
|
||||
#define PLAYLIST_EXTENSION _T("psfpl")
|
||||
#define PLAYLIST_FILTER _T("PsfPlayer Playlists (*.") PLAYLIST_EXTENSION _T(")\0*.") PLAYLIST_EXTENSION _T("\0")
|
||||
@ -30,6 +31,9 @@
|
||||
#define PREF_SOUNDHANDLER_ID ("soundhandler.id")
|
||||
#define DEFAULT_SOUND_HANDLER_ID (1)
|
||||
|
||||
#define PREF_CHAR_ENCODING_ID ("charencoding.id")
|
||||
#define DEFAULT_CHAR_ENCODING_ID (CPsfTags::CE_WINDOWS_1252)
|
||||
|
||||
CMainWindow::SOUNDHANDLER_INFO CMainWindow::m_handlerInfo[] =
|
||||
{
|
||||
{ 1, _T("Win32 WaveOut"), _T("SH_WaveOut.dll") },
|
||||
@ -37,6 +41,14 @@ CMainWindow::SOUNDHANDLER_INFO CMainWindow::m_handlerInfo[] =
|
||||
{ NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
CMainWindow::CHARENCODING_INFO CMainWindow::m_charEncodingInfo[] =
|
||||
{
|
||||
{ CPsfTags::CE_WINDOWS_1252, _T("Windows 1252") },
|
||||
{ CPsfTags::CE_SHIFT_JIS, _T("Shift-JIS") },
|
||||
{ CPsfTags::CE_UTF8, _T("UTF-8") },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
using namespace Framework;
|
||||
using namespace std;
|
||||
|
||||
@ -45,6 +57,7 @@ m_virtualMachine(virtualMachine),
|
||||
m_ready(false),
|
||||
m_frames(0),
|
||||
m_selectedAudioPlugin(DEFAULT_SOUND_HANDLER_ID),
|
||||
m_selectedCharEncoding(DEFAULT_CHAR_ENCODING_ID),
|
||||
m_ejectButton(NULL),
|
||||
m_pauseButton(NULL),
|
||||
m_repeatButton(NULL),
|
||||
@ -60,7 +73,10 @@ m_trackLength(0),
|
||||
m_accel(CreateAccelerators())
|
||||
{
|
||||
CAppConfig::GetInstance().RegisterPreferenceInteger(PREF_SOUNDHANDLER_ID, DEFAULT_SOUND_HANDLER_ID);
|
||||
CAppConfig::GetInstance().RegisterPreferenceInteger(PREF_CHAR_ENCODING_ID, DEFAULT_CHAR_ENCODING_ID);
|
||||
|
||||
LoadAudioPluginPreferences();
|
||||
LoadCharEncodingPreferences();
|
||||
|
||||
for(unsigned int i = 0; i < MAX_PANELS; i++)
|
||||
{
|
||||
@ -160,6 +176,10 @@ m_accel(CreateAccelerators())
|
||||
|
||||
CreateAudioPluginMenu();
|
||||
UpdateAudioPluginMenu();
|
||||
|
||||
CreateCharEncodingMenu();
|
||||
UpdateCharEncodingMenu();
|
||||
|
||||
UpdateClock();
|
||||
UpdateTitle();
|
||||
UpdateButtons();
|
||||
@ -296,6 +316,18 @@ long CMainWindow::OnCommand(unsigned short nID, unsigned short nCmd, HWND hContr
|
||||
case ID_FILE_AUDIOPLUGIN_PLUGIN_0 + 9:
|
||||
ChangeAudioPlugin(nID - ID_FILE_AUDIOPLUGIN_PLUGIN_0);
|
||||
break;
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 0:
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 1:
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 2:
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 3:
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 4:
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 5:
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 6:
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 7:
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 8:
|
||||
case ID_FILE_CHARENCODING_ENCODING_0 + 9:
|
||||
ChangeCharEncoding(nID - ID_FILE_CHARENCODING_ENCODING_0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
@ -565,6 +597,66 @@ void CMainWindow::ChangeAudioPlugin(unsigned int pluginIdx)
|
||||
UpdateAudioPluginMenu();
|
||||
}
|
||||
|
||||
void CMainWindow::CreateCharEncodingMenu()
|
||||
{
|
||||
Win32::CMenuItem pluginSubMenu(CreatePopupMenu());
|
||||
|
||||
for(unsigned int i = 0; m_charEncodingInfo[i].name != NULL; i++)
|
||||
{
|
||||
tstring caption = m_charEncodingInfo[i].name;
|
||||
InsertMenu(pluginSubMenu, i, MF_STRING, ID_FILE_CHARENCODING_ENCODING_0 + i, caption.c_str());
|
||||
}
|
||||
|
||||
Win32::CMenuItem pluginMenu(Win32::CMenuItem::FindById(m_popupMenu, ID_FILE_CHARACTERENCODING));
|
||||
MENUITEMINFO ItemInfo;
|
||||
memset(&ItemInfo, 0, sizeof(MENUITEMINFO));
|
||||
ItemInfo.cbSize = sizeof(MENUITEMINFO);
|
||||
ItemInfo.fMask = MIIM_SUBMENU;
|
||||
ItemInfo.hSubMenu = pluginSubMenu;
|
||||
|
||||
SetMenuItemInfo(pluginMenu, ID_FILE_CHARACTERENCODING, FALSE, &ItemInfo);
|
||||
}
|
||||
|
||||
void CMainWindow::UpdateCharEncodingMenu()
|
||||
{
|
||||
for(unsigned int i = 0; m_charEncodingInfo[i].name != NULL; i++)
|
||||
{
|
||||
Win32::CMenuItem pluginSubMenuEntry(Win32::CMenuItem::FindById(m_popupMenu, ID_FILE_CHARENCODING_ENCODING_0 + i));
|
||||
pluginSubMenuEntry.Check(m_charEncodingInfo[i].id == m_selectedCharEncoding);
|
||||
}
|
||||
}
|
||||
|
||||
void CMainWindow::ChangeCharEncoding(unsigned int encodingIdx)
|
||||
{
|
||||
CHARENCODING_INFO* encodingInfo = m_charEncodingInfo + encodingIdx;
|
||||
m_selectedCharEncoding = encodingInfo->id;
|
||||
CAppConfig::GetInstance().SetPreferenceInteger(PREF_CHAR_ENCODING_ID, m_selectedCharEncoding);
|
||||
UpdateCharEncodingMenu();
|
||||
}
|
||||
|
||||
void CMainWindow::LoadCharEncodingPreferences()
|
||||
{
|
||||
int charEncodingId = CAppConfig::GetInstance().GetPreferenceInteger(PREF_CHAR_ENCODING_ID);
|
||||
int charEncodingIdx = FindCharEncoding(charEncodingId);
|
||||
if(charEncodingIdx == -1)
|
||||
{
|
||||
m_selectedCharEncoding = DEFAULT_CHAR_ENCODING_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_selectedCharEncoding = charEncodingId;
|
||||
}
|
||||
}
|
||||
|
||||
int CMainWindow::FindCharEncoding(unsigned int encodingId)
|
||||
{
|
||||
for(unsigned int i = 0; m_charEncodingInfo[i].name != NULL; i++)
|
||||
{
|
||||
if(m_charEncodingInfo[i].id == encodingId) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
HACCEL CMainWindow::CreateAccelerators()
|
||||
{
|
||||
Win32::CAcceleratorTableGenerator tableGenerator;
|
||||
@ -735,6 +827,7 @@ bool CMainWindow::PlayFile(const char* path)
|
||||
CPsfBase::TagMap tags;
|
||||
CPsfLoader::LoadPsf(m_virtualMachine, path, &tags);
|
||||
m_tags = CPsfTags(tags);
|
||||
m_tags.SetDefaultCharEncoding(static_cast<CPsfTags::CHAR_ENCODING>(m_selectedCharEncoding));
|
||||
try
|
||||
{
|
||||
m_volumeAdjust = boost::lexical_cast<float>(m_tags.GetTagValue("volume"));
|
||||
|
@ -56,6 +56,12 @@ private:
|
||||
const TCHAR* dllName;
|
||||
};
|
||||
|
||||
struct CHARENCODING_INFO
|
||||
{
|
||||
int id;
|
||||
const TCHAR* name;
|
||||
};
|
||||
|
||||
CSoundHandler* CreateHandler(const TCHAR*);
|
||||
|
||||
void OnNewFrame();
|
||||
@ -84,15 +90,21 @@ private:
|
||||
void UpdateTitle();
|
||||
void UpdateButtons();
|
||||
void UpdateRepeatButton();
|
||||
void CreateAudioPluginMenu();
|
||||
void UpdateAudioPluginMenu();
|
||||
|
||||
void Reset();
|
||||
void ActivatePanel(unsigned int);
|
||||
|
||||
void CreateAudioPluginMenu();
|
||||
void UpdateAudioPluginMenu();
|
||||
void ChangeAudioPlugin(unsigned int);
|
||||
void LoadAudioPluginPreferences();
|
||||
int FindAudioPlugin(unsigned int);
|
||||
void ChangeAudioPlugin(unsigned int);
|
||||
|
||||
void CreateCharEncodingMenu();
|
||||
void UpdateCharEncodingMenu();
|
||||
void ChangeCharEncoding(unsigned int);
|
||||
void LoadCharEncodingPreferences();
|
||||
int FindCharEncoding(unsigned int);
|
||||
|
||||
HACCEL CreateAccelerators();
|
||||
|
||||
@ -133,9 +145,11 @@ private:
|
||||
uint64 m_fadePosition;
|
||||
float m_volumeAdjust;
|
||||
int m_selectedAudioPlugin;
|
||||
int m_selectedCharEncoding;
|
||||
REPEAT_MODE m_repeatMode;
|
||||
|
||||
static SOUNDHANDLER_INFO m_handlerInfo[];
|
||||
static CHARENCODING_INFO m_charEncodingInfo[];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -111,6 +111,7 @@ BEGIN
|
||||
POPUP "File"
|
||||
BEGIN
|
||||
MENUITEM "Audio Plugin", ID_FILE_AUDIOPLUGIN
|
||||
MENUITEM "Character Encoding", ID_FILE_CHARACTERENCODING
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "About", ID_FILE_ABOUT
|
||||
MENUITEM "Quit", ID_FILE_EXIT
|
||||
|
@ -19,13 +19,14 @@
|
||||
#define ID_FILE_QUIT 40010
|
||||
#define ID_FILE_ABOUT 40015
|
||||
#define ID_FILE_AUDIOPLUGIN 40016
|
||||
#define ID_FILE_CHARACTERENCODING 40020
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 107
|
||||
#define _APS_NEXT_COMMAND_VALUE 40020
|
||||
#define _APS_NEXT_COMMAND_VALUE 40021
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user