Пример #1
0
LRESULT CMainWindow::OnWndProc(unsigned int msg, WPARAM wParam, LPARAM lParam)
{
	if(m_taskBarList && (msg == m_taskBarList->GetCreatedMessage()))
	{
		static const int buttonCount = 3;
		static const UINT buttonIds[buttonCount] =
		{
			ID_FILE_PREVIOUSTRACK,
			ID_FILE_PAUSE,
			ID_FILE_NEXTTRACK
		};

		m_taskBarList->Initialize(m_hWnd);
		m_taskBarList->CreateThumbButtons(buttonCount, buttonIds);

		m_taskBarList->SetThumbButtonText(ID_FILE_PREVIOUSTRACK,	_T("Previous Track"));
		m_taskBarList->SetThumbButtonIcon(ID_FILE_PREVIOUSTRACK,	m_prevTrackIcon);

		m_taskBarList->SetThumbButtonText(ID_FILE_NEXTTRACK,		_T("Next Track"));
		m_taskBarList->SetThumbButtonIcon(ID_FILE_NEXTTRACK,		m_nextTrackIcon);

		UpdatePlaybackButtons();
	}
	return TRUE;
}
Пример #2
0
bool CMainWindow::PlayFile(const CPsfPathToken& pathToken, const boost::filesystem::path& archivePath)
{
	EnableWindow(m_hWnd, FALSE);

	Reset();
	try
	{
		CPsfBase::TagMap tags;
		CPsfLoader::LoadPsf(m_virtualMachine, pathToken, archivePath, &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"));
			m_virtualMachine.SetVolumeAdjust(m_volumeAdjust);
		}
		catch(...)
		{

		}
		m_fileInformationPanel->SetTags(m_tags);
		m_spu0RegViewPanel->SetSpu(&m_virtualMachine.GetSpuCore(0));
		m_spu1RegViewPanel->SetSpu(&m_virtualMachine.GetSpuCore(1));
		m_virtualMachine.SetReverbEnabled(m_reverbEnabled);
		m_virtualMachine.Resume();
		m_ready = true;
		if(m_repeatMode != TRACK_REPEAT)
		{
			double fade = 10;
			if(m_tags.HasTag("length"))
			{
				double length = CPsfTags::ConvertTimeString(m_tags.GetTagValue("length").c_str());
				m_trackLength = static_cast<uint64>(length * 60.0);
			}
			if(m_tags.HasTag("fade"))
			{
				fade = CPsfTags::ConvertTimeString(m_tags.GetTagValue("fade").c_str());
			}
			m_fadePosition = m_trackLength;
			m_trackLength +=  static_cast<uint64>(fade * 60.0);
		}
	}
	catch(const std::exception& except)
	{
		std::tstring errorString = _T("Couldn't load PSF file: \r\n\r\n");
		errorString += string_cast<std::tstring>(except.what());
		MessageBox(m_hWnd, errorString.c_str(), NULL, 16);
	}

	EnableWindow(m_hWnd, TRUE);

	UpdateTitle();
	UpdatePlaybackButtons();
	UpdateClock();

	return m_ready;
}
Пример #3
0
void CMainWindow::OnPause()
{
	if(!m_ready) return;
	if(m_virtualMachine.GetStatus() == CVirtualMachine::PAUSED)
	{
		m_virtualMachine.Resume();
	}
	else
	{
		m_virtualMachine.Pause();
	}
	UpdatePlaybackButtons();
}
Пример #4
0
void CMainWindow::UpdateFade()
{
	if(m_trackLength != 0)
	{
		if(m_frames >= m_trackLength)
		{
			unsigned int itemCount = m_playlist.GetItemCount();
			if((m_currentPlaylistItem + 1) == itemCount)
			{
				if(m_repeatMode == PLAYLIST_REPEAT)
				{
					m_currentPlaylistItem = 0;
					OnPlaylistItemDblClick(m_currentPlaylistItem);
				}
				else if(m_repeatMode == PLAYLIST_SHUFFLE)
				{
					OnNext();
				}
				else
				{
					Reset();
					UpdatePlaybackButtons();
				}
			}
			else
			{
				OnNext();
			}
		}
		else if(m_frames >= m_fadePosition)
		{
			float currentRatio = static_cast<float>(m_frames - m_fadePosition) / static_cast<float>(m_trackLength - m_fadePosition);
			float currentVolume = (1.0f - currentRatio) * m_volumeAdjust;
			m_virtualMachine.SetVolumeAdjust(currentVolume);
		}
	}
}
Пример #5
0
CMainWindow::CMainWindow(CPsfVm& virtualMachine)
    : Framework::Win32::CDialog(MAKEINTRESOURCE(IDD_MAINWINDOW))
    , m_virtualMachine(virtualMachine)
    , m_ready(false)
    , m_frames(0)
    , m_lastUpdateTime(~0)
    , m_selectedAudioPlugin(DEFAULT_SOUND_HANDLER_ID)
    , m_selectedCharEncoding(DEFAULT_CHAR_ENCODING_ID)
    , m_playlistPanel(NULL)
    , m_fileInformationPanel(NULL)
    , m_spu0RegViewPanel(NULL)
    , m_spu1RegViewPanel(NULL)
    , m_currentPlaylistItem(0)
    , m_repeatMode(DEFAULT_REPEAT_MODE)
    , m_trackLength(0)
    , m_accel(CreateAccelerators())
    , m_reverbEnabled(true)
    , m_playListOnceIcon(NULL)
    , m_repeatListIcon(NULL)
    , m_shuffleListIcon(NULL)
    , m_repeatTrackIcon(NULL)
    , m_toolTip(NULL)
    , m_trayPopupMenu(NULL)
    , m_configPopupMenu(NULL)
    , m_useTrayIcon(false)
    , m_trayIconServer(NULL)
    , m_taskBarList(NULL)
    , m_randomSeed(0)
{
	OSVERSIONINFO versionInfo;
	memset(&versionInfo, 0, sizeof(OSVERSIONINFO));
	versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&versionInfo);
	if(versionInfo.dwMajorVersion > 6)
	{
		m_useTrayIcon = false;
	}
	else if(versionInfo.dwMajorVersion == 6)
	{
		m_useTrayIcon = versionInfo.dwMinorVersion < 1;
	}
	else
	{
		m_useTrayIcon = true;
	}
#ifdef FORCE_ENABLE_TRAYICON
	m_useTrayIcon = true;
#endif

	if(!m_useTrayIcon)
	{
		m_taskBarList = new Framework::Win32::CTaskBarList();
	}

	{
		srand(static_cast<unsigned int>(time(NULL)) * 0x13579ACD);
		float delta = (static_cast<float>(rand()) / static_cast<float>(RAND_MAX));
		m_randomSeed = delta * static_cast<float>(0xCAFECAFE) + 0xDAEBB042;
	}

	CAppConfig::GetInstance().RegisterPreferenceBoolean(PREF_REVERB_ENABLED, true);
	CAppConfig::GetInstance().RegisterPreferenceInteger(PREF_SOUNDHANDLER_ID, DEFAULT_SOUND_HANDLER_ID);
	CAppConfig::GetInstance().RegisterPreferenceInteger(PREF_CHAR_ENCODING_ID, DEFAULT_CHAR_ENCODING_ID);
	CAppConfig::GetInstance().RegisterPreferenceInteger(PREF_REPEAT_MODE, DEFAULT_REPEAT_MODE);

	m_reverbEnabled = CAppConfig::GetInstance().GetPreferenceBoolean(PREF_REVERB_ENABLED);
	m_repeatMode = static_cast<REPEAT_MODE>(CAppConfig::GetInstance().GetPreferenceInteger(PREF_REPEAT_MODE));

	LoadAudioPluginPreferences();
	LoadCharEncodingPreferences();

	for(unsigned int i = 0; i < MAX_PANELS; i++)
	{
		m_panels[i] = NULL;
	}

	SetClassPtr();

	SetTimer(m_hWnd, TIMER_UPDATE_CLOCK, 200, NULL);
	SetTimer(m_hWnd, TIMER_UPDATE_FADE, 50, NULL);
	SetTimer(m_hWnd, TIMER_UPDATE_DISCOVERIES, 100, NULL);

	{
		int smallIconSizeX = GetSystemMetrics(SM_CXSMICON);
		int smallIconSizeY = GetSystemMetrics(SM_CYSMICON);
		int bigIconSizeX = GetSystemMetrics(SM_CXICON);
		int bigIconSizeY = GetSystemMetrics(SM_CYICON);

		HICON smallIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAIN), IMAGE_ICON, smallIconSizeX, smallIconSizeY, 0));
		HICON bigIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAIN), IMAGE_ICON, bigIconSizeX, bigIconSizeY, 0));

		SetIcon(ICON_SMALL, smallIcon);
		SetIcon(ICON_BIG, bigIcon);
	}

	m_trayPopupMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_TRAY_POPUP));
	m_configPopupMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_CONFIG_POPUP));

	m_virtualMachine.OnNewFrame.connect(std::bind(&CMainWindow::OnNewFrame, this));

	m_toolTip = new Framework::Win32::CToolTip(m_hWnd);
	m_toolTip->Activate(true);

	ChangeAudioPlugin(FindAudioPlugin(m_selectedAudioPlugin));

	m_playListOnceIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PLAYONCE), IMAGE_ICON, 16, 16, 0));
	m_repeatListIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_REPEAT_LIST), IMAGE_ICON, 16, 16, 0));
	m_shuffleListIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_SHUFFLE_LIST), IMAGE_ICON, 16, 16, 0));
	m_repeatTrackIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_REPEAT_TRACK), IMAGE_ICON, 16, 16, 0));
	m_configIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CONFIG), IMAGE_ICON, 16, 16, 0));
	m_playIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PLAY), IMAGE_ICON, 16, 16, 0));
	m_pauseIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PAUSE), IMAGE_ICON, 16, 16, 0));
	m_prevTrackIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PREV_TRACK), IMAGE_ICON, 16, 16, 0));
	m_nextTrackIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NEXT_TRACK), IMAGE_ICON, 16, 16, 0));

	m_timerLabel = Framework::Win32::CStatic(GetItem(IDC_TIMER_LABEL));
	m_titleLabel = Framework::Win32::CStatic(GetItem(IDC_TITLE_LABEL));

	m_placeHolder = Framework::Win32::CStatic(GetItem(IDC_PLACEHOLDER));

	m_configButton = Framework::Win32::CButton(GetItem(IDC_CONFIG_BUTTON));
	m_toolTip->AddTool(m_configButton.m_hWnd, _T("Configuration"));
	m_configButton.SetIcon(m_configIcon);

	m_repeatButton = Framework::Win32::CButton(GetItem(IDC_REPEAT_BUTTON));
	m_toolTip->AddTool(m_repeatButton.m_hWnd, _T(""));
	UpdateRepeatButton();

	m_pauseButton = Framework::Win32::CButton(GetItem(IDC_PAUSE_BUTTON));

	//Initialize symbol fonts
	CreateSymbolFonts();

	{
		m_pauseButton.SetFont(m_webdingsFont);
		SendMessage(GetItem(ID_FILE_PREVIOUSTRACK), WM_SETFONT, reinterpret_cast<WPARAM>(static_cast<HFONT>(m_webdingsFont)), 0);
		SendMessage(GetItem(ID_FILE_NEXTTRACK), WM_SETFONT, reinterpret_cast<WPARAM>(static_cast<HFONT>(m_webdingsFont)), 0);
		SendMessage(GetItem(IDC_PREVTAB_BUTTON), WM_SETFONT, reinterpret_cast<WPARAM>(static_cast<HFONT>(m_webdingsFont)), 0);
		SendMessage(GetItem(IDC_NEXTTAB_BUTTON), WM_SETFONT, reinterpret_cast<WPARAM>(static_cast<HFONT>(m_webdingsFont)), 0);
	}

	if(m_segoeUiSymbolFont.IsValid())
	{
		SendMessage(GetItem(IDC_EJECT_BUTTON), WM_SETFONT, reinterpret_cast<WPARAM>(static_cast<HFONT>(m_segoeUiSymbolFont)), 0);
		SendMessage(GetItem(IDC_EJECT_BUTTON), WM_SETTEXT, NULL, reinterpret_cast<LPARAM>(_T("\u23CF")));
	}

	//Create tray icon
	if(m_useTrayIcon)
	{
		m_trayIconServer = new Framework::Win32::CTrayIconServer();

		Framework::Win32::CTrayIcon* trayIcon = m_trayIconServer->Insert();
		trayIcon->SetIcon(LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAIN)));
		trayIcon->SetTip(_T("PsfPlayer"));

		m_trayIconServer->RegisterHandler(std::bind(&CMainWindow::OnTrayIconEvent, this,
		                                            std::placeholders::_1, std::placeholders::_2));
	}

	//Create play list panel
	m_playlistPanel = new CPlaylistPanel(m_hWnd, m_playlist);
	m_playlistPanel->OnItemDblClick.connect(std::bind(&CMainWindow::OnPlaylistItemDblClick, this, std::placeholders::_1));
	m_playlistPanel->OnAddClick.connect(std::bind(&CMainWindow::OnPlaylistAddClick, this));
	m_playlistPanel->OnRemoveClick.connect(std::bind(&CMainWindow::OnPlaylistRemoveClick, this, std::placeholders::_1));
	m_playlistPanel->OnSaveClick.connect(std::bind(&CMainWindow::OnPlaylistSaveClick, this));

	//Create file information panel
	m_fileInformationPanel = new CFileInformationPanel(m_hWnd);

	//Create RegView panels
	m_spu0RegViewPanel = new CSpuRegViewPanel(m_hWnd, _T("SPU0"));
	m_spu1RegViewPanel = new CSpuRegViewPanel(m_hWnd, _T("SPU1"));

	//Initialize panels
	m_panels[0] = m_playlistPanel;
	m_panels[1] = m_fileInformationPanel;
	m_panels[2] = m_spu0RegViewPanel;
	m_panels[3] = m_spu1RegViewPanel;

	CreateAudioPluginMenu();
	UpdateAudioPluginMenu();

	CreateCharEncodingMenu();
	UpdateCharEncodingMenu();

	UpdateClock();
	UpdateTitle();
	UpdatePlaybackButtons();
	UpdateConfigMenu();

	m_currentPanel = -1;
	ActivatePanel(0);
}