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

📄 keycmd.cpp

📁 miXo is a buzz machine (www.buzzmachines.com) - a plugin for the freely available jeskola buzz track
💻 CPP
字号:
// KeyCmd.cpp: implementation of the CKeyCmd class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "mixer.h"
#include "KeyCmd.h"
#include "MixerKeyDef.h"
#include "MixerTrack.h"
#include "MixerKeyTable.h"
#include "MixerStatus.h"
#include "Key.h"
#include "MixDlg.h"

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

const char CKeyHandler::m_cszGlobal[]="global";
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CKeyHandler::CKeyHandler(CMixerKeyTable*kTable,CMixerStatus*mix,CMixDlg*dlg)
:m_pcKeyTable(kTable),m_pcMixerStatus(mix),m_pcMixDlg(dlg),m_lstKeyCmd(),
 m_iListLock(0)
{
}
CKeyHandler::~CKeyHandler()
{
}
bool CKeyHandler::KeyDown(int iKey,long lData)
{
	TLstKeyCmd::iterator ite;
									//first see if key is already pressed
	if((ite=GetFromListByKey(iKey))!=m_lstKeyCmd.end()){		//is in wait state?
		ite->PressedAgain(iKey,lData);
		return true;
	}
	// TODO: rewrite this part
	// first go through tracks, see if key is in them
	// then send associated commands
	
	// second: define parameter of type string
	//		so we can send commands to only one other
	//		keydef by name
	//		look them up at runtime, otherwise problems

	CMixerKeyDef *pKeyDef=m_pcKeyTable->FindFirstKeyDefByKey(iKey);
	while(pKeyDef) {
		if(pKeyDef->IsNameEqual(m_cszGlobal)) {
			StartProcessCmd(-1,pKeyDef,iKey);
		} else {
//			StartProcessCmd(pKeyDef->GetId(),pKeyDef,iKey);
			CMixerTrack *pMixerTrack=m_pcMixerStatus->GetSet()->FindFirstTrackByKeySet(pKeyDef->GetId());
			while(pMixerTrack) {
				StartProcessCmd(pKeyDef->GetId(),pKeyDef,iKey);
				pMixerTrack=m_pcMixerStatus->GetSet()->FindNextTrackByKeySet(pKeyDef->GetId());
			}
		}
		pKeyDef=m_pcKeyTable->FindNextKeyDefByKey(iKey);
	}

	// END TODO
	return true;
}
bool CKeyHandler::KeyUp(int iKey,long lData)
{
	WaitListLock();
	LockList();
	TLstKeyCmd::iterator ite=m_lstKeyCmd.begin();
	while(ite < m_lstKeyCmd.end()) {
		if(ite->GetMixerKey()->GetVirtKey() == iKey) {
			if(ite->IsDone()) {
				ite=m_lstKeyCmd.erase(ite);
				continue;
			} else {
				if(ite->IsKeyUp()) {
					ite=m_lstKeyCmd.erase(ite);
					continue;
				}
				else
					ite->SetKeyUp();
			}
		}
		ite++;
	}
	UnLockList();
	return true;
}
CKeyHandler::TLstKeyCmd::iterator CKeyHandler::GetFromListByKey(int iKey)
{
	TLstKeyCmd::iterator ite=m_lstKeyCmd.begin();
	while(ite < m_lstKeyCmd.end()) {
		if(ite->GetMixerKey()->GetVirtKey() == iKey)
			break;
		ite++;
	}
	return *(&ite);
}
void CKeyHandler::StartProcessCmd(int iKeyDefId,CMixerKeyDef *pKeyDef,int iKey)
{
	WaitListLock();
	LockList();
	unsigned uCurrId=m_uIdRun;
	CKeyCmd cKeyCmd(pKeyDef->GetKeyClassByKey(iKey),iKeyDefId,m_uIdRun++);
	m_lstKeyCmd.push_back(cKeyCmd);
	UnLockList();
}
void CKeyHandler::ScheduleKeyEvent(CKeyCmd p,unsigned long ul)
{
	WaitListLock();
	LockList();
	ul+=::GetTickCount();
	p.SetTime(ul);
	if(!m_lstKeyCmd.empty()) 
	{
		TLstKeyCmd::iterator ite=m_lstKeyCmd.begin();
		while(ite < m_lstKeyCmd.end()) {
			if(ite->GetTime() > ul) {
				m_lstKeyCmd.insert(ite,p);
				UnLockList();
				return;
			}
			ite++;
		}
	}
	m_lstKeyCmd.push_back(p);
	UnLockList();
}
void CKeyHandler::ProcessCmd(CKeyCmd p)
{
	bool bRun=true;
	while(bRun) {
		float f;
		cmd::TCmd TheCmd=p.Get();
		if(TheCmd == cmd::Panic) {
			ClearPendingEvents();
			return;
		}
		if(TheCmd > cmd::__BeginOne_Para) {
			char *c=(char*)&f;
			for(int i=0;i<sizeof(float)/sizeof(char);i++)
				c[i]=p.Get();
		}
		if(TheCmd == cmd::End) {
			if(p.GetToMode() != cmd::ToMe) {
				p.SetToMode(cmd::ToMe);
				continue;
			}
			if(p.GetRepeat() > 0) {
				p.Repeated();
				continue;
			}
			//TheCmd=0x0;	//!!
		}
		if(TheCmd == 0x0) {
			if(p.GetRepeat() > 0) {
				p.Repeated();
				continue;
			}
			if(p.IsKeyUp()) {
				p.SetDone();
				p.SetPosition(0);
				return;
			}
			p.SetPosition(0);
			p.SetDone();
			ScheduleKeyEvent(p,defaultKeyRetrig);
			return;
		}
		if(TheCmd == cmd::Repeat)
		{
			p.SetRepeat(f);
			p.SetRepeatPos();
			continue;
		}
		if((TheCmd > cmd::__BeginToCmd) && (TheCmd < cmd::__EndToCmd)) {
			p.SetToMode(TheCmd);		
			//TODO add ToOne 
			continue;
		}
		if(TheCmd == cmd::Wait) {
			unsigned u=unsigned(f);
			ScheduleKeyEvent(p,u);
			return;
		}
//		if((ite->GetMixerTrack() == NULL) || (ite->GetToMode() != cmd::ToMe) ) {
		m_pcMixerStatus->GetSet()->FilterCmd(TheCmd,static_cast<cmd::TCmd>(p.GetToMode()),p.GetKeyDefId(),f,0.0,0.0);
//		}else{
//			ite->GetMixerTrack()->DoCmd(TheCmd,f,0.0,0.0);
//		}
	}
}

void CKeyHandler::ProcessPendingEvents()
{
	if(m_lstKeyCmd.empty())
		return;
	unsigned long ulTick=::GetTickCount();
	TLstKeyCmd::iterator ite=m_lstKeyCmd.begin();
	if(m_lstKeyCmd.front().GetTime() <= ulTick) {
		CKeyCmd cCmd=m_lstKeyCmd.front();
		WaitListLock();
		LockList();
		m_lstKeyCmd.pop_front();
		UnLockList();
		ProcessCmd(cCmd);
	}
//	if(m_lstKeyCmd.front().IsDone() && m_lstKeyCmd.front().IsKeyUp())
}
void CKeyHandler::ClearPendingEvents()
{
	WaitListLock();
	LockList();
	m_lstKeyCmd.clear();
	UnLockList();
}
/*
void CKeyHandler::ProcessPendingEvents()
{
	unsigned long ulTick=::GetTickCount();
	TLstKeyCmd::iterator ite=m_lstKeyCmd.begin();
	while(ite != m_lstKeyCmd.end() ) {
		if(ite->GetTime() <= ulTick) {
			ProcessCmd(&(*ite));
			if(m_lstKeyCmd.empty())		//hit Panic
				return;
		}
		if(ite->IsDone() && ite->IsKeyUp())
			ite=m_lstKeyCmd.erase(ite);
		else
			ite++;
	}
}
*/

⌨️ 快捷键说明

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