home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************\
- Copyright (C) James Boer, 2002.
- All rights reserved worldwide.
-
- This software is provided "as is" without express or implied
- warranties. You may freely copy and compile this source into
- applications you distribute provided that the copyright text
- below is included in the resulting source code, for example:
- "Portions Copyright (C) James Boer, 2002"
- \***********************************************************/
-
- #include "stdafx.h"
- #include "audiotest.h"
- #include "SoundScript.h"
-
- #include "AudioTest.h"
- #include "Segment.h"
- #include "Audio.h"
-
- #include "AudioTestDlg.h"
- #include "System.h"
- #include "Sound2D.h"
- #include "Sound3D.h"
-
- using namespace Audio;
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- #define GET_CURRENT_SOUNDSCAPE() \
- int iIndex = m_SoundScapes.GetCurSel();\
- if(iIndex == LB_ERR) return;\
- ISoundScape* pSoundScape = static_cast<ISoundScape*>(m_SoundScapes.GetItemDataPtr(iIndex));\
- if(!pSoundScape) return;
-
-
- /////////////////////////////////////////////////////////////////////////////
- // SoundScript property page
-
- IMPLEMENT_DYNCREATE(CSoundScript, CPropertyPage)
-
- CSoundScript::CSoundScript() : CPropertyPage(CSoundScript::IDD)
- {
- //{{AFX_DATA_INIT(CSoundScript)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_bInit = false;
- }
-
- CSoundScript::~CSoundScript()
- {
- }
-
- void CSoundScript::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSoundScript)
- DDX_Control(pDX, IDC_SLIDER_SSVOLUME, m_Volume);
- DDX_Control(pDX, IDC_LIST_SS_SOUNDS, m_SoundScapes);
- DDX_Control(pDX, IDC_PAUSESS, m_Pause);
- DDX_Control(pDX, IDC_STOPSS, m_Stop);
- DDX_Control(pDX, IDC_PLAYSS, m_Play);
- //}}AFX_DATA_MAP
- }
-
-
- void CSoundScript::ClearList()
- {
- if(m_bInit)
- {
- /*
- ISoundScape* pSoundScape;
- int iSize = m_SoundScapes.GetCount();
- for(int i = 0; i < iSize; i++)
- {
- pSoundScape = static_cast<ISoundScape*>(m_SoundScapes.GetItemDataPtr(0));
- pSoundScape->Term();
- m_SoundScapes.DeleteString(0);
- }
- */
- m_SoundScapes.ResetContent();
- }
- }
-
-
- void CSoundScript::UpdateControls()
- {
- GET_CURRENT_SOUNDSCAPE();
- float fVal;
- pSoundScape->GetVolume(fVal);
- m_Volume.SetPos(static_cast<int>(fVal * 10000.0f));
- }
-
-
- BEGIN_MESSAGE_MAP(CSoundScript, CPropertyPage)
- //{{AFX_MSG_MAP(CSoundScript)
- ON_BN_CLICKED(IDC_SS_INITIALIZE, OnSSInitialize)
- ON_BN_CLICKED(IDC_SS_DELETE, OnSSDelete)
- ON_BN_CLICKED(IDC_LOADSS, OnLoadSS)
- ON_BN_CLICKED(IDC_UNLOADSS, OnUnloadSS)
- ON_BN_CLICKED(IDC_PLAYSS, OnPlaySS)
- ON_BN_CLICKED(IDC_PAUSESS, OnPauseSS)
- ON_BN_CLICKED(IDC_STOPSS, OnStopSS)
- ON_WM_DESTROY()
- ON_WM_HSCROLL()
- ON_LBN_SELCHANGE(IDC_LIST_SS_SOUNDS, OnSelchangeListSSSounds)
- ON_LBN_DBLCLK(IDC_LIST_SS_SOUNDS, OnDblclkListSsSounds)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSoundScript message handlers
-
-
-
- BOOL CSoundScript::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
-
- // Load the play button icons
- m_hPlayIcon = LoadIcon(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_PLAY));
- m_hPauseIcon = LoadIcon(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_PAUSE));
- m_hStopIcon = LoadIcon(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_STOP));
-
- // Set the master play control buttons
- m_Play.SetIcon(m_hPlayIcon);
- m_Pause.SetIcon(m_hPauseIcon);
- m_Stop.SetIcon(m_hStopIcon);
-
- m_bInit = true;
-
- m_Volume.SetRange(0, 10000);
- m_Volume.SetPos(10000);
- m_Volume.Invalidate();
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
- void CSoundScript::OnSSInitialize()
- {
- CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- "Script Files (.txt)|*.txt|All Files (*.*)|*.*||");
-
- if(dlg.DoModal() != IDOK)
- return;
-
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char fname[_MAX_FNAME];
- char ext[_MAX_EXT];
-
- POSITION pos = dlg.GetStartPosition();
- CString sPathName;
- while(pos)
- {
- sPathName = dlg.GetNextPathName(pos);
- _splitpath(sPathName, drive, dir, fname, ext);
-
- if(!SoundMgr()->LoadScript((const char*)sPathName))
- {
- AfxMessageBox("Error parsing sound script");
- return;
- }
- }
-
- std::string sName;
- SoundMgr()->ResetSoundItr();
- while(SoundMgr()->GetNextSound(sName))
- {
- //DebugOut(1, "Registered Sound = %s", sName.c_str());
- }
- SoundMgr()->ResetSound3DItr();
- while(SoundMgr()->GetNextSound3D(sName))
- {
- //DebugOut(1, "Registered Sound3D = %s", sName.c_str());
- }
- SoundMgr()->ResetSoundScapeItr();
- while(SoundMgr()->GetNextSoundScape(sName))
- {
- //DebugOut(1, "Registered Soundscape = %s", sName.c_str());
- ISoundScape* pSoundScape;
- if(!SoundMgr()->CreateSoundScape(pSoundScape))
- return;
- if(!SoundMgr()->InitSoundScape(sName, pSoundScape))
- {
- AfxMessageBox("Error initializing audio file");
- return;
- }
-
- int iIndex = m_SoundScapes.AddString(sName.c_str());
- if(iIndex != LB_ERR)
- m_SoundScapes.SetItemDataPtr(iIndex, pSoundScape);
- }
-
- }
-
- void CSoundScript::OnDestroy()
- {
- CPropertyPage::OnDestroy();
- ClearList();
- }
-
- void CSoundScript::OnSSDelete()
- {
- GET_CURRENT_SOUNDSCAPE();
- pSoundScape->Destroy();
- int iSize = m_SoundScapes.DeleteString(iIndex);
- if(!iSize)
- return;
- if(iIndex > (iSize - 1))
- iIndex = iSize - 1;
- m_SoundScapes.SetCurSel(iIndex);
- }
-
- void CSoundScript::OnLoadSS()
- {
- GET_CURRENT_SOUNDSCAPE();
- pSoundScape->Load();
- }
-
- void CSoundScript::OnUnloadSS()
- {
- GET_CURRENT_SOUNDSCAPE();
- pSoundScape->Unload();
- }
-
- void CSoundScript::OnPlaySS()
- {
- GET_CURRENT_SOUNDSCAPE();
- pSoundScape->Play();
- }
-
- void CSoundScript::OnPauseSS()
- {
- GET_CURRENT_SOUNDSCAPE();
- pSoundScape->Pause();
- }
-
- void CSoundScript::OnStopSS()
- {
- GET_CURRENT_SOUNDSCAPE();
- pSoundScape->Stop();
- }
-
-
- void CSoundScript::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- if(pScrollBar->IsKindOf(RUNTIME_CLASS(CSliderCtrl)))
- {
- CSliderCtrl* pSlider = reinterpret_cast<CSliderCtrl*>(pScrollBar);
- if(!pSlider)
- return;
- GET_CURRENT_SOUNDSCAPE();
- if(pSlider == &m_Volume)
- {
- pSoundScape->SetVolume(static_cast<float>(pSlider->GetPos()) / 10000.0f);
- }
- }
- CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
- }
-
- void CSoundScript::OnSelchangeListSSSounds()
- {
- UpdateControls();
- }
-
- void CSoundScript::OnDblclkListSsSounds()
- {
- OnPlaySS();
- }
-