📄 mixdlg.cpp
字号:
///////////////////////////////////////////////
// MixDlg.cpp : implementation file
// $Revision:
#include <sstream>
#include "stdafx.h"
#include "resource.h"
#include "mixer.h"
#include "MixDlg.h"
#include "KeyDefDlg.h"
#include "ColGen.h"
#include "WrapList.h"
#include "WrapChildTrack.h"
//#include "MiXoException.h"
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const int CMixDlg::cm_iMaxPresetNameLen=100;
const int CMixDlg::cm_iMaxMenuItemNameLen=100;
#pragma warning( disable : 4355 )
//m_cChildRect(5,5,45,150)
CMixDlg::CMixDlg(const char *szName,CMixerStatus *pcMixer,const char *sz)
: CAbWin(sz),m_pcMixer(pcMixer),
m_lstTrackWin(),m_cChildRect(5,5,64,155),m_cMinRect(0,0,170,190),m_bAlwaysOnTop(true),
m_iFontHt(6),m_cKeyHandler(m_pcMixer->GetKeyTable(),m_pcMixer,this),m_pcKeyDefDlg(NULL),
m_strTitle(),m_bOpenOnDblClk(true),m_lstpColGen(),m_iCurrColGen(0),
m_iCurUpTrack(0)
{
if(strcmp(szName,"miXo") == 0)
m_strTitle=szName;
else{
stringstream stm;
stm << "miXo (" << szName << ")" << ends;
m_strTitle=stm.str();
}
SetWindowRect(CWinRect(-1,-1,-1,-1));
for(int i=0;i<cm_iMaxColors;i++)
m_lstpColGen[i]=NULL;
m_lstpColGen[0]=new CDefColGen();
m_lstpColGen[1]=new COldColGen();
m_lstpColGen[2]=new CRedColGen();
}
CMixDlg::~CMixDlg()
{
CMixDlg::DeInit();
CColGen *p;
int i=0;
while((p=m_lstpColGen[i])) {
delete p;
i++;
}
}
void CMixDlg::Init(HWND hPar)
{
// InitFromReg();
if(GetWindowRect() == CWinRect(-1,-1,-1,-1)) {
POINT ptCursor;
GetCursorPos(&ptCursor);
SetWindowRect(CWinRect(ptCursor.x,ptCursor.y,ptCursor.x+350,ptCursor.y+100));
}
NewChildren();
CAbWin::Init(hPar);
}
void CMixDlg::NewChildren()
{
DelChildren();
int iNum=m_pcMixer->GetSet()->GetSize();
for(int i=0;i<iNum;i++) {
CTrackWin cTrackWin(m_pcMixer->GetKeyTable(),m_pcMixer->GetSet()->GetTrackByIndex(i),GetModuleName(),m_lstpColGen[m_iCurrColGen]);
m_lstTrackWin.push_back(cTrackWin);
CWrapChildTrack cChildTrackWin(&m_lstTrackWin.back());
m_pcMixer->GetWrapList().AddWin(&cChildTrackWin);
}
}
void CMixDlg::DelChildren()
{
LockTrackWins(true);
m_lstTrackWin.clear();
m_pcMixer->GetWrapList().ForgetHandlesAndPointers();
}
void CMixDlg::PreCreate()
{
int iNum=(m_lstTrackWin.size());
CWinRect rMe(GetWindowRect().X(),GetWindowRect().Y(),
GetWindowRect().X()+(m_cChildRect.X()*2)+(iNum)*m_cChildRect.Wd(),
m_cChildRect.Y()+GetWindowRect().Y()+m_cChildRect.Y1());
if(rMe.Wd() < m_cMinRect.Wd())
rMe.SetWd(m_cMinRect.Wd());
SetWindowClientRect(rMe);
// if(IsWindow()) {
// CalcWindowRectSize();
// const CWinRect r=GetWindowRect();
// ::SetWindowPos(GetWndHandle(),HWND_TOPMOST,r.X(),r.Y(),r.Wd(),r.Ht(),SWP_NOZORDER|SWP_NOACTIVATE);
// }
}
void CMixDlg::CreateChildren()
{
for(int i=0;i<m_lstTrackWin.size();i++) {
// m_lstTrackWin[i].Init(GetWndHandle());
CWinRect r(m_cChildRect.X()+(i*m_cChildRect.Wd()),m_cChildRect.Y(),
m_cChildRect.X()+((i+1)*m_cChildRect.Wd())-1,m_cChildRect.Y1());
#ifdef _DEBUG
assert(!m_lstTrackWin[i].IsWindow());
#endif
// m_lstTrackWin[i].SetWindowRect(r);
// m_lstTrackWin[i].Create();
CWrapChildTrack cChildTrackWin(&m_lstTrackWin[i]);
m_pcMixer->GetWrapList().CreateChild(GetWndHandle(),&cChildTrackWin,r);
}
LockTrackWins(false);
}
void CMixDlg::Create()
{
PreCreate();
CAbWin::Create();
SetWindowZpos();
CreateChildren();
InitMainMenu();
InitPrsMenu();
InitMenu();
CreateColorsMenu();
}
void CMixDlg::DeInit() {
LockTrackWins(true);
for(TLstTrackWin::iterator ite=m_lstTrackWin.begin();ite < m_lstTrackWin.end();ite++)
ite->DeInit();
m_pcMixer->GetWrapList().ForgetHandles();
SetWindowRect(CWinRect(-1,-1,-1,-1));
if(m_pcKeyDefDlg) {
delete m_pcKeyDefDlg;
m_pcKeyDefDlg=NULL;
}
m_pcMixer->GetWrapList().DeInitWindows();
CAbWin::DeInit();
}
LRESULT CMixDlg::WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg){
case WM_USER:
if(wParam == 0x1) //see KeyDefDlg
{
m_cKeyHandler.ClearPendingEvents();
for(int i=0;i<m_lstTrackWin.size();i++) {
m_lstTrackWin[i].ReInitChildren();
}
return true;
}
break;
case WM_KEYDOWN:
if(m_cKeyHandler.KeyDown(int(wParam),lParam))
return 0;
break;
case WM_KEYUP:
if(m_cKeyHandler.KeyUp(int(wParam),lParam))
return 0;
break;
// case WM_TIMER:
// m_cKeyHandler.ProcessCmd(wParam);
// return 0;
case WM_COMMAND:
{
int mID=LOWORD(wParam);
switch(mID) {
case IDMI_ALWAYSONTOP:
m_bAlwaysOnTop=(m_bAlwaysOnTop)?false:true;
InitMenu();
SetWindowZpos();
return TRUE;
break;
case IDMI_EDITKEYDEF:
StartKeyDefDlg();
return TRUE;
break;
case IDMI_MUTE:
DoMute();
return TRUE;
break;
case IDMI_BYPASS:
DoBypass();
return TRUE;
break;
case IDMI_OPENONDBLCLK:
m_bOpenOnDblClk=(m_bOpenOnDblClk)?false:true;
InitMenu();
return TRUE;
break;
case IDMI_AUTONAME:
if(m_pcMixer) {
m_pcMixer->AutoAddMixerPreset();
InitPrsMenu();
return TRUE;
}
break;
case IDMI_IM_FAST:
m_pcMixer->SetSampleDataAccuracy(10);
UpdateMonitorMenu(mID);
return TRUE;
case IDMI_IM_NORMAL:
m_pcMixer->SetSampleDataAccuracy(20);
UpdateMonitorMenu(mID);
return TRUE;
case IDMI_IM_SLOW:
m_pcMixer->SetSampleDataAccuracy(50);
UpdateMonitorMenu(mID);
return TRUE;
case IDMI_IM_OFF:
m_pcMixer->SetSampleDataAccuracy(32768);
UpdateMonitorMenu(mID);
return TRUE;
default:
if(mID > IDMI_STYLE_FIRST && mID < IDMI_STYLE_LAST) {
SetStyle(mID);
return true;
}
if(mID >= IDMI_CS_DEFAULT) {
ChangeColorGen(mID-IDMI_CS_DEFAULT);
return true;
}
if(mID >=IDMI_FIRST_STOREPRS) {
StorePrs(mID);
return true;
}
if(mID >=IDMI_FIRST_PRESET) {
DoLoadPrs(mID);
return true;
}
break;
}
}
}
return CAbWin::WindowProc(hWnd,uMsg,wParam,lParam);
}
void CMixDlg::UpdateTracks()
{
if(IsWindow()) {
if(m_iCurUpTrack < m_lstTrackWin.size()) {
m_lstTrackWin[m_iCurUpTrack].UpdateSlid();
m_iCurUpTrack++;
}else{
m_iCurUpTrack=0;
}
}
}
/*
for(TLstTrackWin::iterator ite=m_lstTrackWin.begin();ite < m_lstTrackWin.end();ite++)
{
ite->UpdateSlid();
}
}
}
*/
void CMixDlg::DoPendingKeyEvents()
{
m_cKeyHandler.ProcessPendingEvents();
}
void CMixDlg::SetWindowZpos()
{
if(m_bAlwaysOnTop)
::SetWindowPos(GetWndHandle(),HWND_TOPMOST,0,0,10,10,SWP_NOMOVE|SWP_NOSIZE);
else
::SetWindowPos(GetWndHandle(),HWND_NOTOPMOST,0,0,10,10,SWP_NOMOVE|SWP_NOSIZE);
}
void CMixDlg::StartKeyDefDlg()
{
if(m_pcKeyDefDlg) {
if(m_pcKeyDefDlg->IsWindow()) {
m_pcKeyDefDlg->ShowWindow();
return;
}
}else{
m_pcKeyDefDlg=new CKeyDefDlg(m_pcMixer->GetKeyTable(),GetModuleName());
}
// m_pcKeyDefDlg->PreSetSelection(strName);
m_pcKeyDefDlg->Create("KEYDEFDLG",GetWndHandle(),NULL);
}
void CMixDlg::InitFromReg()
{
string szRegPath="\\Software\\Jeskola\\Buzz\\MiXo\\";
char szRegClass[]="BOOL";
string strAlways="AlwaysOnTop";
BYTE ulAlways;
DWORD ulSize=sizeof(ulAlways);
DWORD dwType=REG_DWORD; unsigned long uDispo;
HKEY hRegKey;
long l=::RegCreateKeyEx(HKEY_CURRENT_USER,szRegPath.c_str(),0,szRegClass,
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hRegKey,&uDispo);
if(l != ERROR_SUCCESS)
throw CAbException(::GetLastError(),__FILE__,__LINE__);
l=::RegQueryValueEx(hRegKey,strAlways.c_str(),NULL,&dwType,&ulAlways,&ulSize);
RegCloseKey(hRegKey);
}
void CMixDlg::StorePrs(int id)
{
char szBuf[cm_iMaxPresetNameLen];
if(::GetMenuString(GetMenuHandle(),id,szBuf,cm_iMaxPresetNameLen,MF_BYCOMMAND)) {
m_pcMixer->AddNamedMixerPreset(ExtractPrsName(szBuf));
}
}
void CMixDlg::DoLoadPrs(int id)
{
char szBuf[cm_iMaxPresetNameLen];
if(::GetMenuString(GetMenuHandle(),id,szBuf,cm_iMaxPresetNameLen,MF_BYCOMMAND)) {
LoadPrs(ExtractPrsName(szBuf));
}
}
void CMixDlg::LoadPrs(string s)
{
LockTrackWins(true);
m_pcMixer->LoadMixerPreset(s);
if(!SetMixerTracks())
{
DelChildren();
ReGo();
}
LockTrackWins(false);
InitMainMenu();
}
void CMixDlg::DoBypass()
{
switch(m_pcMixer->GetMode())
{
case CMixerTrack::em_Mute:
case CMixerTrack::em_Normal:
m_pcMixer->SetMode(CMixerTrack::em_Bypass);
break;
case CMixerTrack::em_Bypass:
m_pcMixer->SetMode(CMixerTrack::em_Normal);
break;
}
InitMainMenu();
}
void CMixDlg::DoSlidGraying()
{
bool bGray=false;
if(m_pcMixer->GetMode() != CMixerTrack::em_Normal)
bGray=true;
for(int i=0;i<m_lstTrackWin.size();i++) {
m_lstTrackWin[i].GraySlid(bGray);
}
}
void CMixDlg::DoMute()
{
switch(m_pcMixer->GetMode())
{
case CMixerTrack::em_Bypass:
case CMixerTrack::em_Normal:
m_pcMixer->SetMode(CMixerTrack::em_Mute);
break;
case CMixerTrack::em_Mute:
m_pcMixer->SetMode(CMixerTrack::em_Normal);
break;
}
InitMainMenu();
}
void CMixDlg::LockTrackWins(bool b)
{
for(TLstTrackWin::iterator ite=m_lstTrackWin.begin();ite < m_lstTrackWin.end();ite++)
ite->SetUpdateLock(b);
}
bool CMixDlg::SetMixerTracks()
{
int iNumOfTracks=m_pcMixer->GetSet()->GetSize();
int iNumOfWins=m_lstTrackWin.size();
if(iNumOfTracks != iNumOfWins)
return false;
int i=0;
for(TLstTrackWin::iterator ite=m_lstTrackWin.begin();ite < m_lstTrackWin.end();ite++,i++) {
ite->SetMixerTrack(m_pcMixer->GetSet()->GetTrackByIndex(i));
}
return true;
}
void CMixDlg::LoadPreset(int i)
{
if(i > m_pcMixer->GetNumOfMixerPresets())
return;
LoadPrs(m_pcMixer->GetNameOfMixerPreset(i-1));
}
void CMixDlg::SetMode(int i)
{
if(i == m_pcMixer->GetMode())
return;
switch(i) {
case 0:
m_pcMixer->SetMode(CMixerTrack::em_Normal);
break;
case 1:
m_pcMixer->SetMode(CMixerTrack::em_Mute);
break;
case 2:
m_pcMixer->SetMode(CMixerTrack::em_Bypass);
break;
}
InitMainMenu();
}
void CMixDlg::SetStyle(int iMenuId)
{
LockTrackWins(true);
char szBuf[cm_iMaxMenuItemNameLen];
::GetMenuString(GetMenuHandle(),iMenuId,szBuf,cm_iMaxMenuItemNameLen,MF_BYCOMMAND);
//need two steps here-1st remove all classes and then create them from scratch
for(TLstTrackWin::iterator ite=m_lstTrackWin.begin();ite < m_lstTrackWin.end();ite++)
ite->SetStyle(szBuf);
for(ite=m_lstTrackWin.begin();ite < m_lstTrackWin.end();ite++)
ite->CreateSlidWin();
DoSlidGraying();
LockTrackWins(false);
InitMenu();
}
/////////////////////////////////
//Menu Creation and Modifications
void CMixDlg::CreateColorsMenu()
{
HMENU hSubMenu=::GetSubMenu(GetMenuHandle(),ID_MN_IDX_XMENU); //0=first entry in menu !!!!!!!!
int i=0;
while(::DeleteMenu(hSubMenu,IDMI_CS_DEFAULT+i,MF_BYCOMMAND))
i++;
CColGen *p;
i=0;
while((p=m_lstpColGen[i])){
const char *sz1=p->GetName();
stringstream stm;
stm << sz1 << " Colors" << ends;
string str=stm.str();
const char *sz=str.c_str();
::AppendMenu(hSubMenu,MF_ENABLED|MF_STRING,IDMI_CS_DEFAULT+i,sz);
i++;
}
ChangeColorGen(m_iCurrColGen);
::DrawMenuBar(GetWndHandle());
return;
}
void CMixDlg::InitMainMenu()
{
switch(m_pcMixer->GetMode())
{
case CMixerTrack::em_Bypass:
SetMenuItemText("&Mute",IDMI_MUTE);
SetMenuItemText("&Activate",IDMI_BYPASS);
break;
case CMixerTrack::em_Mute:
SetMenuItemText("Un&mute",IDMI_MUTE);
SetMenuItemText("&Bypass",IDMI_BYPASS);
break;
default:
SetMenuItemText("&Mute",IDMI_MUTE);
SetMenuItemText("&Bypass",IDMI_BYPASS);
break;
}
::DrawMenuBar(GetWndHandle());
DoSlidGraying();
}
void CMixDlg::InitMenu()
{
::CheckMenuItem(GetMenuHandle(),IDMI_ALWAYSONTOP,(m_bAlwaysOnTop)?MF_CHECKED:MF_UNCHECKED);
::CheckMenuItem(GetMenuHandle(),IDMI_OPENONDBLCLK,(m_bOpenOnDblClk)?MF_CHECKED:MF_UNCHECKED);
if(!m_lstTrackWin.empty()) {
char szBuf[cm_iMaxMenuItemNameLen];
const char *szStyle=m_lstTrackWin.front().GetStyle();
for(int i=IDMI_STYLE_FIRST+1;i<IDMI_STYLE_LAST;i++) {
::GetMenuString(GetMenuHandle(),i,szBuf,cm_iMaxMenuItemNameLen,MF_BYCOMMAND);
int iCmp=stricmp(szBuf,szStyle);
::CheckMenuItem(GetMenuHandle(),i,(iCmp == 0)?MF_CHECKED:MF_UNCHECKED);
}
}
}
void CMixDlg::ChangeColorGen(int iNew)
{
for(int i=0;i<2;i++) {
::CheckMenuItem(GetMenuHandle(),IDMI_CS_DEFAULT+m_iCurrColGen,(i==0)?MF_UNCHECKED:MF_CHECKED);
m_iCurrColGen=iNew;
}
if(m_lstpColGen[m_iCurrColGen]) {
for(TLstTrackWin::iterator ite=m_lstTrackWin.begin();ite < m_lstTrackWin.end();ite++,i++) {
ite->SetColorGen(m_lstpColGen[m_iCurrColGen]);
}
}
}
void CMixDlg::InitPrsMenu()
{
HMENU hPrsMenu=::GetSubMenu(GetMenuHandle(),ID_MN_IDX_PRESET);
HMENU hSubMenu=::GetSubMenu(hPrsMenu,ID_MN_IDX_STORE); //0=first entry in menu !!!!!!!!
int i=0;
while(::DeleteMenu(hPrsMenu,IDMI_FIRST_PRESET+i,MF_BYCOMMAND))
i++;
i=0;
while(::DeleteMenu(hSubMenu,IDMI_FIRST_STOREPRS+i,MF_BYCOMMAND))
i++;
if(m_pcMixer) {
int iNum=m_pcMixer->GetNumOfMixerPresets();
for(i=0;i<iNum;i++)
{ //TODO check for internal
stringstream stm;
stm << (i+1) << ":" << m_pcMixer->GetNameOfMixerPreset(i) << ends;
::AppendMenu(hPrsMenu,MF_ENABLED|MF_STRING,IDMI_FIRST_PRESET+i,stm.str().c_str());
if(hSubMenu)
::AppendMenu(hSubMenu,MF_ENABLED|MF_STRING,IDMI_FIRST_STOREPRS+i,stm.str().c_str());
}
}
::DrawMenuBar(GetWndHandle());
}
//////////////
//Menu Helpers
void CMixDlg::SetMenuItemText(string s,int id)
{
if(!IsWindow())
return;
char szBuf[cm_iMaxMenuItemNameLen];
MENUITEMINFO mnuInfo;
mnuInfo.cbSize=sizeof(MENUITEMINFO);
mnuInfo.fMask=MIIM_DATA|MIIM_TYPE;
mnuInfo.fType=MFT_STRING;
mnuInfo.wID=id;
mnuInfo.dwTypeData=szBuf;
mnuInfo.cch=cm_iMaxMenuItemNameLen;
if((::GetMenuItemInfo(GetMenuHandle(),id,FALSE,&mnuInfo)) != 0)
{
if(s.length() >= cm_iMaxMenuItemNameLen)
throw CAbException(::GetLastError(),__FILE__,__LINE__);
strcpy(szBuf,s.c_str());
mnuInfo.dwTypeData=szBuf;
mnuInfo.cch=strlen(szBuf);
::SetMenuItemInfo(GetMenuHandle(),id,FALSE,&mnuInfo);
}else
throw CAbException(::GetLastError(),__FILE__,__LINE__);
}
string CMixDlg::ExtractPrsName(const char*sz)
{
string str=sz;
string strPrs=str.substr((str.find(":")+1));
return strPrs;
}
void CMixDlg::UpdateMonitorMenu(int mId)
{
bool bOnOff=true;
if(mId == IDMI_IM_OFF)
bOnOff=false;
for(TLstTrackWin::iterator ite=m_lstTrackWin.begin();ite < m_lstTrackWin.end();ite++) {
ite->SetMonitor(bOnOff);
}
::CheckMenuItem(GetMenuHandle(),IDMI_IM_FAST,MF_UNCHECKED);
::CheckMenuItem(GetMenuHandle(),IDMI_IM_NORMAL,MF_UNCHECKED);
::CheckMenuItem(GetMenuHandle(),IDMI_IM_SLOW,MF_UNCHECKED);
::CheckMenuItem(GetMenuHandle(),IDMI_IM_OFF,MF_UNCHECKED);
::CheckMenuItem(GetMenuHandle(),mId,MF_CHECKED);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -