⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trackwin.cpp

📁 miXo is a buzz machine (www.buzzmachines.com) - a plugin for the freely available jeskola buzz track
💻 CPP
字号:
// TrackWin.cpp: implementation of the CTrackWin class.
//
//////////////////////////////////////////////////////////////////////
#include <sstream>
#include "stdafx.h"
#include "mixer.h"
#include "TrackWin.h"
#include "MixerTrack.h"
#include "MixerKeyTable.h"
#include "KeyDefDlg.h"
#include "ColorSlidWin.h"
#include "BuzzSlidWin.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

using namespace std;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTrackWin::CTrackWin(CMixerKeyTable *pcKey,CMixerTrack *pcTrack,const char*sz,CColGen *pcg)
:CAbWin(sz),m_pcTrack(pcTrack),m_pcKeyTable(pcKey),m_cOtherKeys("",sz),
m_ctxtName("",sz),m_cKeyWin0("",sz),m_cKeyWin1("",sz),m_cKeyWin2("",sz),m_cKeyWin3("",sz),
m_cChan("",sz),m_iCount(defFadeOut),m_pcKeyDefDlg(NULL),
m_bUpdateLock(true),m_bMouseMove(false),
m_pcSlid(NULL),m_iTxtHt(-1),m_strClassName()
{
	//new CColorSlidWin(sz,pcg)
	if(!m_pcSlid) 
		m_pcSlid=new CBuzzSlidWin(sz,pcg);
//		m_pcSlid=new CColorSlidWin(sz,pcg);
	assert(m_pcSlid);
}
CTrackWin::CTrackWin(const CTrackWin &c)
: CAbWin(c),m_pcTrack(c.m_pcTrack),m_pcKeyTable(c.m_pcKeyTable),
  m_ctxtName(c.m_ctxtName),m_cKeyWin0(c.m_cKeyWin0),m_cKeyWin1(c.m_cKeyWin1),
  m_cKeyWin2(c.m_cKeyWin2),m_cKeyWin3(c.m_cKeyWin3),m_cChan(c.m_cChan),
  m_cOtherKeys(c.m_cOtherKeys),
  m_iCount(c.m_iCount),m_pcKeyDefDlg(c.m_pcKeyDefDlg),
  m_bUpdateLock(c.m_bUpdateLock),m_bMouseMove(c.m_bMouseMove),
  m_iTxtHt(c.m_iTxtHt),m_strClassName(c.m_strClassName)
  //m_pcSlid(new CSlidWin(*c.m_pcSlid))
{
	//m_pcSlid=new CColorSlidWin(c.m_pcSlid->GetModuleName(),c.m_pcSlid->GetColorGen());
//	m_pcSlid=new CSlidWin(c.m_pcSlid->GetModuleName(),c.m_pcSlid->GetColorGen());
	assert(c.m_pcSlid);
//	m_pcSlid=new ;
	m_pcSlid=c.m_pcSlid->New();
};



CTrackWin::~CTrackWin()
{
	DeInitChildren();
	if(m_pcKeyDefDlg)
		delete m_pcKeyDefDlg;
	if(m_pcSlid)
		delete m_pcSlid;
}
HBRUSH CTrackWin::GetBgBrush() const 
{ 
	int iKeySetId;
	if(m_pcTrack && ((iKeySetId=m_pcTrack->GetKeySetId()) != -1) )
	{
		unsigned uRed,uGrn,uBlue;
		uRed=(iKeySetId*20)%255;
		uGrn=(iKeySetId*100)%255;
		uBlue=(iKeySetId*150)%255;
		return ::CreateSolidBrush(RGB(uRed,uGrn,uBlue));
	}
	return (HBRUSH)(COLOR_HIGHLIGHTTEXT+1); 
} 
void CTrackWin::Init(HWND hPar)
{
	stringstream stm;
	stm << "CTrackWin" << this << ends;
	m_strClassName=stm.str();
	CAbWin::Init(hPar);
}
void CTrackWin::InitChildren()
{
	assert(m_pcSlid);
	assert(m_pcKeyTable);
	assert(m_pcTrack);
	if(m_iTxtHt == -1) {
		TEXTMETRIC txtMetr;
		HDC hDC=::GetDC(GetWndHandle());
		::GetTextMetrics(hDC,&txtMetr);
		::ReleaseDC(GetWndHandle(),hDC);
		m_iTxtHt=txtMetr.tmHeight;
	}
	m_ctxtName.SetText(m_pcTrack->GetName());
	m_ctxtName.SetWindowRect(CWinRect(0,0,GetWindowRect().Wd(),m_iTxtHt));
	m_ctxtName.Init(GetWndHandle());
	m_ctxtName.SetWindowFont("Small",6);
	m_ctxtName.Create();
	int iKeySetId=m_pcTrack->GetKeySetId();
	m_cChan.SetText(m_pcKeyTable->GetNameOf(iKeySetId));
	m_cChan.SetWindowRect(CWinRect(0,m_iTxtHt,GetWindowRect().Wd(),m_iTxtHt*2));
	m_cChan.Init(GetWndHandle());
	m_cChan.SetWindowFont("Small",6);
	m_cChan.Create();

	const CMixerKeyDef *pcKeyDef=m_pcKeyTable->GetKeyDef(iKeySetId);
	if(pcKeyDef) {
		CMixerKeyDef cTmpKeyDef=*pcKeyDef;
		string szDispMax=cTmpKeyDef.GetDisplayKeyAndErase(cmd::Max);
		m_cKeyWin0.SetText(szDispMax.c_str());
		string szDispPlus=cTmpKeyDef.GetDisplayKeyAndErase(cmd::Plus);
		m_cKeyWin1.SetText(szDispPlus.c_str());
		string szDispMinus=cTmpKeyDef.GetDisplayKeyAndErase(cmd::Minus);
		m_cKeyWin2.SetText(szDispMinus.c_str());
		string szDispMin=cTmpKeyDef.GetDisplayKeyAndErase(cmd::Min);
		m_cKeyWin3.SetText(szDispMin.c_str());
		stringstream stmOthers;
		for(int i=0;i<cTmpKeyDef.GetSize();i++) {
			CKey *pKey=cTmpKeyDef.GetKey(i);
			if(pKey) {
				stmOthers << pKey->GetDispKey() << endl;
			}
		}
		stmOthers << ends;
		m_cOtherKeys.SetText(stmOthers.str().c_str());
	}
	int iOff=(GetWindowRect().Ht()/5)-(m_iTxtHt);
	int iTxtHt=m_iTxtHt+iOff;
	m_cKeyWin0.SetWindowRect(CWinRect(0,iTxtHt*1,GetWindowRect().Wd(),iTxtHt*2));
	m_cKeyWin1.SetWindowRect(CWinRect(0,iTxtHt*2,GetWindowRect().Wd(),iTxtHt*3));
	m_cKeyWin2.SetWindowRect(CWinRect(0,iTxtHt*3,GetWindowRect().Wd(),GetWindowRect().Ht()-iTxtHt/2));
	m_cKeyWin3.SetWindowRect(CWinRect(0,GetWindowRect().Ht()-iTxtHt+2,GetWindowRect().Wd(),GetWindowRect().Ht()-4));
	m_cOtherKeys.SetWindowRect(CWinRect(GetWindowRect().Wd()-14,iTxtHt*1,GetWindowRect().Wd(),GetWindowRect().Ht()-4));
	m_cKeyWin0.Init(GetWndHandle());
	m_cKeyWin1.Init(GetWndHandle());
	m_cKeyWin2.Init(GetWndHandle());
	m_cKeyWin3.Init(GetWndHandle());
	m_cOtherKeys.Init(GetWndHandle());
	m_cKeyWin0.SetStyle(WS_GROUP|WS_VISIBLE|WS_CHILD|SS_NOTIFY);
	m_cKeyWin1.SetStyle(WS_GROUP|WS_VISIBLE|WS_CHILD|SS_NOTIFY);
	m_cKeyWin2.SetStyle(WS_GROUP|WS_VISIBLE|WS_CHILD|SS_NOTIFY);
	m_cKeyWin3.SetStyle(WS_GROUP|WS_VISIBLE|WS_CHILD|SS_NOTIFY);
	m_cOtherKeys.SetStyle(WS_GROUP|WS_VISIBLE|WS_CHILD|SS_NOTIFY|SS_CENTER);
	m_cKeyWin0.SetWindowFont("Small",7);
	m_cKeyWin3.SetWindowFont("Small",7);
	m_cKeyWin1.SetWindowFont("FixedSys",10);
	m_cKeyWin2.SetWindowFont("FixedSys",10);
	m_cOtherKeys.SetWindowFont("Small",6);
	m_cKeyWin0.Create();
	m_cKeyWin1.Create();
	m_cKeyWin2.Create();
	m_cKeyWin3.Create();
	m_cOtherKeys.Create();
	CreateSlidWin();
}
void CTrackWin::CreateSlidWin()
{
	assert(m_pcSlid);
	int iOff=(GetWindowRect().Ht()/5)-(m_iTxtHt);
	int iTxtHt=m_iTxtHt+iOff;
	m_pcSlid->Init(GetWndHandle());
	m_pcSlid->SetWindowRect(CWinRect(16,2+iTxtHt*1,GetWindowRect().Wd()-16,GetWindowRect().Ht()-6));
	m_pcSlid->Create();
	m_pcSlid->ForceUpdate();
	UpdateSlid();
}
void CTrackWin::ReSetName()
{
	assert(m_pcTrack);
	m_ctxtName.SetText(m_pcTrack->GetName());
}
const string &CTrackWin::GetTrackName() const
{
	assert(m_pcTrack);
	return m_pcTrack->GetName();
}
void CTrackWin::Create()
{
	SetWindowFont("Small",6);
	CAbWin::Create();
	InitChildren();
//	::SetTimer(GetWndHandle(),1,50,NULL);
}
void CTrackWin::DeInitChildren()
{
	assert(m_pcSlid);
	m_ctxtName.DeInit();
	m_cKeyWin0.DeInit();
	m_cKeyWin1.DeInit();
	m_cKeyWin2.DeInit();
	m_cKeyWin3.DeInit();
	m_cChan.DeInit();
	m_cOtherKeys.DeInit();
	if(m_pcSlid)
		m_pcSlid->DeInit();
}
void CTrackWin::DeInit()
{
	DeInitChildren();
	CAbWin::DeInit();
}
const string &CTrackWin::GetTrackKeySetName() const
{
	return m_pcKeyTable->GetNameOf(m_pcTrack->GetKeySetId());
}
bool CTrackWin::UpdateSlid()
{
	assert(m_pcSlid);
	assert(m_pcTrack);
	if(m_bUpdateLock)
		return false;
	m_pcSlid->SetValue(m_pcTrack->GetRealTargetLevel());
	if(!m_pcSlid->SetSmValue(m_pcTrack->GetSampleData())) {
		m_iCount--;
		if(m_iCount <= 0) {
			m_pcTrack->SetSampleData(0.001f);
			m_iCount=defFadeOut;
		}
	}
	return m_pcSlid->DoUpdate(); 
}
void CTrackWin::DoContextMenu(WPARAM wParam,int x,int y)
{
	HMENU hmCtxt=CreatePopupMenu();
	if(!hmCtxt)
		throw CAbException(::GetLastError(),__FILE__,__LINE__);
	if(!AppendMenu(hmCtxt,MF_ENABLED|MF_STRING,mid_EditKeyDef,"Edit Key Def.."))
		throw CAbException(::GetLastError(),__FILE__,__LINE__);
	if(!AppendMenu(hmCtxt,MF_ENABLED|MF_SEPARATOR,0,""))
		throw CAbException(::GetLastError(),__FILE__,__LINE__);
	if(!AppendMenu(hmCtxt,MF_DISABLED|MF_STRING|MF_GRAYED,0,"Assign Key Def:"))
		throw CAbException(::GetLastError(),__FILE__,__LINE__);
	assert(m_pcKeyTable);
	assert(m_pcTrack);
	const string strName=m_pcKeyTable->GetNameOf(m_pcTrack->GetKeySetId());
	for(int i=0;i<m_pcKeyTable->GetSize();i++) {
		string str=m_pcKeyTable->GetNameOf(i);
		unsigned mode=MF_ENABLED|MF_STRING;
		if(strName == str) 
			mode|=MF_CHECKED;
		if(!AppendMenu(hmCtxt,mode,mid_FirstKeyDef+i,str.c_str()))
			throw CAbException(::GetLastError(),__FILE__,__LINE__);
	}
	BOOL msbRetVal=TrackPopupMenu(hmCtxt,TPM_RIGHTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_LEFTBUTTON,x,y,0,GetWndHandle(),NULL);
	if(msbRetVal == mid_EditKeyDef) {
		if(m_pcKeyDefDlg) {
			if(m_pcKeyDefDlg->IsWindow()) {
				m_pcKeyDefDlg->ShowWindow();
				return;
			}
		}else{
			m_pcKeyDefDlg=new CKeyDefDlg(m_pcKeyTable,GetModuleName());
		}
		m_pcKeyDefDlg->PreSetSelection(strName);
		m_pcKeyDefDlg->Create("KEYDEFDLG",GetWndHandle(),NULL);
	}
	if(msbRetVal >= mid_FirstKeyDef) {
		m_pcTrack->SetKeySetId(int(msbRetVal)-mid_FirstKeyDef);
		//DeInitChildren();
//		CWinRect r=GetWindowRect();
		HWND hPar=GetParHandle();
		DeInit();
//		SetWindowClientRect(CWinRect(-1,-1,-1,-1));
//		SetWindowRect(r);
//		m_iTxtHt=-1;
		Init(hPar);
		//InitChildren();
		Create();
	}
}
bool CTrackWin::UpdateLevelFromCursor()
{
	assert(m_pcSlid);
	assert(m_pcTrack);
	POINT pt;
	RECT r;
	::GetCursorPos(&pt);
	::GetWindowRect(m_pcSlid->GetWndHandle(),&r);
	if( m_bMouseMove ||
		(pt.x >= r.left) && (pt.x <= r.right) 
		&& (pt.y >= r.top) && (pt.y <= r.bottom) ) 
	{
		pt.y-=r.top;
		int iHt=m_pcSlid->GetWindowRect().Ht();
		float fVal=float(iHt-pt.y)/float(iHt);
		m_pcTrack->SetLevel(fVal);
		m_pcSlid->SetValue(fVal);
		return true;
	}
	return false;
}
bool CTrackWin::SetStyle(const string &str)
{
	bool b=m_bUpdateLock;
	bool bRet=false;
	CSlidWin *pOldSlid=m_pcSlid;
	assert(m_pcSlid);
	m_bUpdateLock=true;
	if(stricmp(str.c_str(),"buzz") == 0) {
		m_pcSlid=new CBuzzSlidWin(GetModuleName(),pOldSlid->GetColorGen());
		bRet=true;
	}
	if(stricmp(str.c_str(),"colored") == 0) {
		m_pcSlid=new CColorSlidWin(GetModuleName(),pOldSlid->GetColorGen());
		bRet=true;
	}
	if(bRet) {
		delete pOldSlid;
//		MakeSlid();
	}
	m_bUpdateLock=b;
	return bRet;
}
const char *CTrackWin::GetStyle() const
{
	assert(m_pcSlid);
	return m_pcSlid->GetName();
}

LRESULT CTrackWin::WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	assert(m_pcSlid);
	assert(m_pcTrack);
//	return CAbWin::WindowProc(hWnd,uMsg,wParam,lParam);
	switch(uMsg) {

	case WM_PARENTNOTIFY:
		if((LOWORD(wParam) == WM_LBUTTONDOWN) /*&& ((HWND)HIWORD(wParam) == m_pcSlid->GetWndHandle()) */)
		{
			m_bMouseMove=UpdateLevelFromCursor();			
			return 1;
		}
		break;
	case WM_SETCURSOR:
		switch(HIWORD(lParam))
		{
		case WM_LBUTTONUP:
			if(m_bMouseMove)
				UpdateLevelFromCursor();
			m_bMouseMove=false;
			break;
		case WM_MOUSEMOVE:
			if(m_bMouseMove)
				m_bMouseMove=UpdateLevelFromCursor();
			break;
		}
		break;
	case WM_USER:
		switch(wParam) {
//			DeInitChildren();	//from CKeyDefDlg
//			InitChildren();
		case 0x1:
			PostMessage(GetParHandle(),uMsg,wParam,lParam);
			return TRUE;
		case 0x2:
			m_pcTrack->SetLevel(m_pcSlid->GetValue());
			return TRUE;
		}
		break;

	case WM_CONTEXTMENU: 
		if(hWnd){
			POINTS pt=MAKEPOINTS(lParam);
			DoContextMenu(wParam,pt.x,pt.y);
			return 0;
		}
		break;
	}
	return CAbWin::WindowProc(hWnd,uMsg,wParam,lParam);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -