📄 maphrcnv.c
字号:
if(dwSlave & (UINT32)(0x01L << i)) { /* synchronization */
status = gApiInfo[i].status;
if(gApiInfo[i].status != ID_STATUS_PLAY)
continue;
gApiInfo[i].status = ID_STATUS_PAUSE;
if (gdwPhrStatus & gMaskRestart[i])
gdwPhrStatus &= ~gMaskRestart[i];
else
gdwPhrStatus |= gMaskPause[i];
}
}
return (MASMW_SUCCESS);
}
/*=============================================================================
// Function Name : SINT32 MaPhr_Convert(void)
//
// Description : Convert SMAF/Phraes to Native format
//
// Argument : N/A
//
// Return : Number of convertion events (0:NoEvent)
//
=============================================================================*/
SINT32 MaPhr_Convert(void)
{
UINT8 i;
UINT8 j;
UINT8 bCh;
UINT8 bContinue;
UINT8 bData0;
UINT8 bData1;
UINT8* pbExMsg;
UINT32 dwMask;
UINT32 dwSize;
UINT32 dwCurrent;
UINT32 dwDuration;
UINT32 dwNoteOffTime;
UINT32 dwPhrStatusB;
SINT32 lCnvData;
PPHRINFO pPi;
dwPhrStatusB = gdwPhrStatus;
gdwPhrStatus = 0;
lCnvData = 0L;
/* set Control parameter */
if (gdwCtrlStatus) {
/* System-On */
if(gdwCtrlStatus & CTRL_SYSTEM_ON) {
MaSndDrv_SetCommand(gdwPhrId, -1L, MASNDDRV_CMD_SYSTEM_ON, 0L, 0L, 0L);
gdwCtrlStatus &= ~CTRL_SYSTEM_ON;
lCnvData++;
}
/* Master Volume */
if(gdwCtrlStatus & CTRL_MASTER_VOLUME) {
MaSndDrv_SetCommand(gdwPhrId, -1L, MASNDDRV_CMD_MASTER_VOLUME,
(UINT32)0x7F, 0L, 0L);
gdwCtrlStatus &= ~CTRL_MASTER_VOLUME;
lCnvData++;
}
}
/* control start/stop/pause/restart */
if (dwPhrStatusB) {
/* Start */
if (dwPhrStatusB & MASK_PHRASE_STATUS_START) {
for (i = 0; i < MAX_PHRASE_CHANNEL; i++) {
if (dwPhrStatusB & gMaskStart[i]) {
gbPlayStatus |= gMaskPlay[i];
lCnvData += PutInitPhraseMessage(i);
}
}
}
/* Restart */
if (dwPhrStatusB & MASK_PHRASE_STATUS_RESTART) {
for (i = 0; i < MAX_PHRASE_CHANNEL; i++) {
if (dwPhrStatusB & gMaskRestart[i]) {
gbPauseStatus &= ~gMaskPlay[i];
gbPlayStatus |= gMaskPlay[i];
}
}
}
/* Pause */
if (dwPhrStatusB & MASK_PHRASE_STATUS_PAUSE) {
for (i = 0; i < MAX_PHRASE_CHANNEL; i++) {
if (dwPhrStatusB & gMaskPause[i]) {
/* Mute */
bCh = (UINT8)(i << 2);
lCnvData += CnvAllSoundOff(bCh);
lCnvData += CnvAllSoundOff((UINT8)(bCh+1));
lCnvData += CnvAllSoundOff((UINT8)(bCh+2));
lCnvData += CnvAllSoundOff((UINT8)(bCh+3));
gbPauseStatus |= gMaskPlay[i];
gbPlayStatus &= ~gMaskPlay[i];
}
}
}
/* Stop */
if (dwPhrStatusB & MASK_PHRASE_STATUS_STOP) {
#if MA_STOPWAIT
for (i = 0; i < MAX_PHRASE_CHANNEL; i++) {
if (dwPhrStatusB & gMaskStop[i]) {
/* Mute */
bCh = (UINT8)(i << 2);
lCnvData += CnvAllSoundOff(bCh);
lCnvData += CnvAllSoundOff((UINT8)(bCh+1));
lCnvData += CnvAllSoundOff((UINT8)(bCh+2));
lCnvData += CnvAllSoundOff((UINT8)(bCh+3));
gbPauseStatus &= ~gMaskPlay[i];
gbPlayStatus &= ~gMaskPlay[i];
gApiInfo[i].status = ID_STATUS_READY;
/* seek to top */
Seek(i, 0L);
}
}
#endif
}
}
/* No played Phrase */
if((gbPlayStatus | gbPauseStatus) == 0x00) {
if (gbSeqStatus & MASK_STATUS_PHRASE) {
gbSeqStatus &= ~ MASK_STATUS_PHRASE;
MaSndDrv_ControlSequencer(gdwPhrId, 0);
}
return lCnvData;
}
bContinue = gbPlayStatus;
/* Convert */
for(i = 0; i < MAX_PHRASE_CHANNEL; i++) {
pPi = &(gApiInfo[i].gPhraseInfo);
if(!(gbPlayStatus & (UINT8)(0x01 << i))) {
continue;
}
if (gdwCtrlStatus) {
#if 0
/* Send initialization message */
dwMask = (UINT32)(CTRL_INIT_PHRASE << (i << 2));
if(gdwCtrlStatus & dwMask) {
lCnvData += PutInitPhraseMessage(i);
gdwCtrlStatus &= ~dwMask;
}
#endif
/* Expression */
dwMask = (UINT32)(CTRL_VOLUME_CHANGE << (i << 2));
if(gdwCtrlStatus & dwMask) {
for(j = 0; j < MAX_PHRASE_SLOT; j++) {
bCh = (UINT8)(j + (i << 2));
lCnvData += CnvExpression(bCh, gApiInfo[i].vol);
}
gdwCtrlStatus &= ~dwMask;
}
/* Panpot */
dwMask = (UINT32)(CTRL_PANPOT_CHANGE << (i << 2));
if(gdwCtrlStatus & dwMask) {
for(j = 0; j < MAX_PHRASE_SLOT; j++) {
bCh = (UINT8)(j + (i << 2));
MaSndDrv_SetCommand(gdwPhrId, -1L, MASNDDRV_CMD_PANPOT, (UINT32)bCh, gChInfo[bCh].bPan, 0L);
lCnvData ++;
}
gdwCtrlStatus &= ~dwMask;
}
}
/* Send Note Off */
for(j = 0; j < MAX_PHRASE_SLOT; j++) {
bCh = (UINT8)(j + (i << 2));
if(gChInfo[bCh].dwKeyOffTime != 0xFFFFFFFF) {
if(gChInfo[bCh].dwKeyOffTime <= pPi->dwTimer) {
lCnvData += CnvNoteOff(bCh);
}
}
}
while(pPi->dwSequenceChunkSize > pPi->dwDataPosition)
{
/* Get Current Time */
dwCurrent = pPi->dwDataPosition;
dwDuration = (UINT32)pPi->pbSequenceChunk[dwCurrent++];
if(dwDuration & 0x80) {
dwDuration = (UINT32)(((dwDuration & 0x7F) << 7) + (UINT32)pPi->pbSequenceChunk[dwCurrent++] + 128L);
}
if((pPi->dwCurrentTime + dwDuration) > pPi->dwTimer) {
break;
}
/* Update position & time */
pPi->dwDataPosition = dwCurrent;
pPi->dwCurrentTime += dwDuration;
/**/
bData0 = pPi->pbSequenceChunk[pPi->dwDataPosition++];
switch(bData0)
{
case 0x00 :
bData1 = pPi->pbSequenceChunk[pPi->dwDataPosition++];
bCh = (UINT8)(((bData1 & 0xC0) >> 6) + (i << 2));
switch(bData1 & 0x30)
{
case 0x00 : /* Short type Volume */
lCnvData += CnvChannelVolume(bCh, gbVolTbl[bData1 & 0x0F]);
break;
case 0x10 : /* */
break;
case 0x20 : /* Short type Modulation */
lCnvData += CnvModulation(bCh, gbModTbl[bData1 & 0x0F]);
break;
case 0x30 :
switch(bData1 & 0x0F)
{
case 0x00 :
ProgramChange(bCh, (UINT8)(pPi->pbSequenceChunk[pPi->dwDataPosition++] & 0x03));
break;
case 0x02 :
OctaveShift(bCh, pPi->pbSequenceChunk[pPi->dwDataPosition++]);
break;
case 0x04 :
lCnvData += CnvPitchBend(bCh, (UINT8)(pPi->pbSequenceChunk[pPi->dwDataPosition++] & 0x7F));
break;
case 0x0A :
lCnvData += CnvPanpot(bCh, (UINT8)(pPi->pbSequenceChunk[pPi->dwDataPosition++] & 0x7F));
break;
case 0x0B :
lCnvData += CnvChannelVolume(bCh, (UINT8)(pPi->pbSequenceChunk[pPi->dwDataPosition++] & 0x7F));
break;
default :
pPi->dwDataPosition++;
break;
}
break;
default :
break;
}
break;
case 0xFF :
bData1 = pPi->pbSequenceChunk[pPi->dwDataPosition++];
if(bData1 == 0xF0) { /* Exclusive Message */
dwSize = (UINT32)(pPi->pbSequenceChunk[pPi->dwDataPosition++]);
pbExMsg = &(pPi->pbSequenceChunk[pPi->dwDataPosition]);
lCnvData += CnvExclusiveMessage(pPi->bPhrNum, pbExMsg, dwSize);
/* skip exclusive message */
pPi->dwDataPosition += dwSize;
}
else if((bData1 & 0xF0) == 0x10) { /* User Event */
if(pPi->CallbackFunc != NULL) {
pPi->CallbackFunc((UINT8)(bData1 & 0x0F));
}
}
break;
default :
bCh = (UINT8)(((bData0 & 0xC0) >> 6) + (i << 2));
/* Send Program Chnage */
if(gChInfo[bCh].bNew) {
PVOCINFO pVi = &(pPi->VocInfo[gChInfo[bCh].bVoiceNo]);
MAPHRCNV_DBGMSG(("ProgramChange[%d %d %d %d] \n", bCh, gChInfo[bCh].bVoiceNo, pVi->bBankNo, pVi->bProgNo));
MaSndDrv_SetCommand(gdwPhrId, -1L, MASNDDRV_CMD_PROGRAM_CHANGE, \
(UINT32)bCh, (UINT32)pVi->bBankNo, (UINT32)pVi->bProgNo);
gChInfo[bCh].bNew = 0x00;
lCnvData++;
}
dwDuration = (UINT32)pPi->pbSequenceChunk[pPi->dwDataPosition++];
if(dwDuration & 0x80) {
dwDuration = (UINT32)(((dwDuration & 0x7F) << 7) + \
(UINT32)pPi->pbSequenceChunk[pPi->dwDataPosition++] + 128L);
}
if (dwDuration != 0) {
dwNoteOffTime = (UINT32)(pPi->dwCurrentTime + dwDuration);
lCnvData += CnvNoteOn( bCh,
(UINT8)((bData0 >> 4) & 0x03),
(UINT8)(bData0 & 0x0F),
dwNoteOffTime);
}
break;
}
}
/* End of Data */
if(pPi->dwSequenceChunkSize <= pPi->dwDataPosition) {
bContinue &= ~(UINT8)(0x01 << i);
}
/* increment timer */
pPi->dwTimer++;
}
/* End of Phrase */
if (bContinue != gbPlayStatus) { /* exist end phrase */
for(i = 0; i < MAX_PHRASE_CHANNEL; i++) {
if(!(gbPlayStatus & gMaskPlay[i])) {
continue;
}
pPi = &(gApiInfo[i].gPhraseInfo);
if(!(bContinue & gMaskPlay[i]))
{
MAPHRCNV_DBGMSG(("Phrase%d data end!! \n", i));
/* Stop ***********/
/* Note Off */
bCh = (UINT8)(i << 2);
lCnvData += CnvNoteOff(bCh);
lCnvData += CnvNoteOff((UINT8)(bCh+1));
lCnvData += CnvNoteOff((UINT8)(bCh+2));
lCnvData += CnvNoteOff((UINT8)(bCh+3));
gbPlayStatus &= ~gMaskPlay[i];
/* Seek to top ****/
Seek(i, 0L);
/* Repeat? */
if(gApiInfo[i].loop != 1) { /* repeat */
if(gApiInfo[i].loop != 0) {
gApiInfo[i].loop--;
}
/* Callback */
if(pPi->CallbackFunc != NULL) {
pPi->CallbackFunc((UINT8)MASMW_REPEAT);
}
/* Start ******/
gbPlayStatus |= gMaskPlay[i];
lCnvData += PutInitPhraseMessage(i);
} else { /* one short */
if ((gbPlayStatus | gbPauseStatus) == 0) {
if (gbSeqStatus & MASK_STATUS_PHRASE) {
gbSeqStatus &= ~MASK_STATUS_PHRASE;
MaSndDrv_ControlSequencer(gdwPhrId, 0);
}
}
gApiInfo[i].status = ID_STATUS_READY;
if(pPi->CallbackFunc != NULL) {
pPi->CallbackFunc((UINT8)MASMW_END_OF_SEQUENCE);
}
}
}
}
}
if ((gbPlayStatus | gbPauseStatus) == 0) {
if (gbSeqStatus & MASK_STATUS_PHRASE) {
gbSeqStatus &= ~MASK_STATUS_PHRASE;
MaSndDrv_ControlSequencer(gdwPhrId, 0);
}
}
return (lCnvData);
}
/*=============================================================================
// Function Name : SINT32 MaPhr_GetLength(UINT8 phr_id)
//
// Description : Get Play back time
//
// Argument : phr_id ... Phrase ID (0..3)
//
// Return : Play back time (ms)
//
=============================================================================*/
static SINT32 MaPhr_GetLength(UINT8 phr_id)
{
MAPHRCNV_DBGMSG(("MaPhr_GetLength[%d] \n",phr_id));
return (gApiInfo[phr_id].gPhraseInfo.dwPlayTime * PHRASE_TIMEBASE);
}
/*=============================================================================
// Function Name : SINT32 MaPhr_GetPos(UINT8 phr_id)
//
// Description : Get playing position
//
// Argument : phr_id ... Phrase ID (0..3)
//
// Return : Playing position [ms]
//
=============================================================================*/
static SINT32 MaPhr_GetPos(UINT8 phr_id)
{
SINT32 lPos;
/*
MAPHRCNV_DBGMSG(("MaPhr_GetPos[%d] \n", phr_id));
*/
lPos = (SINT32)gApiInfo[phr_id].gPhraseInfo.dwTimer;
if(lPos > (SINT32)gApiInfo[phr_id].gPhraseInfo.dwPlayTime) {
lPos = (SINT32)gApiInfo[phr_id].gPhraseInfo.dwPlayTime;
}
return (SINT32)(lPos * PHRASE_TIMEBASE);
}
/*=============================================================================
// Function Name : SINT32 MaPhr_SetBind(UINT8 phr_id, UINT32 dwSlave)
//
// Description : Set
//
// Argument : phr_id ... Phrase ID (0..3)
// : bSlave ... Slave Phrase ID
//
// Return : 0:NoError <0:Error Code
//
=============================================================================*/
static SINT32 MaPhr_SetBind(UINT8 phr_id, UINT8 bSlave)
{
UINT8 i;
PPHRINFO pMaster;
PPHRINFO pSlave;
MAPHRCNV_DBGMSG(("MaPhr_SetBind[%d, %08lX] \n", phr_id, bSlave));
pMaster = &(gApiInfo[phr_id].gPhraseInfo);
if(gApiInfo[phr_id].master_channel != -1) return (MASMW_ERROR);
if(gApiInfo[phr_id].status != ID_STATUS_READY) return (MASMW_ERROR);
/* Register bind */
if(phr_id != bSlave) {
pSlave = &(gApiInfo[bSlave].gPhraseInfo);
if(gApiInfo[bSlave].status != ID_STATUS_READY) return (MASMW_ERROR);
if( (gApiInfo[bSlave].master_channel == -1) && /* Master */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -