FILTER.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:3k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /**************************************************************************
  2.  *
  3.  *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4.  *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5.  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6.  *  PURPOSE.
  7.  *
  8.  *  Copyright (C) 1993 - 1997  Microsoft Corporation.  All Rights Reserved.
  9.  * 
  10.  **************************************************************************/
  11. /*
  12.  * filter.c - Routines to filter MIDI events.
  13.  */
  14. #include <windows.h>
  15. #include "midimon.h"
  16. #include "display.h"
  17. #include "filter.h"
  18. /* CheckEventFilter - Checks the given EVENT against the given FILTER.
  19.  *      
  20.  * Params:  lpEvent - Points to an EVENT.
  21.  *          lpFilter - Points to a FILTER structure.
  22.  *
  23.  * Return:  Returns 1 if the event is filtered, 0 if it is not filtered.
  24.  */
  25. BOOL CheckEventFilter(LPEVENT lpEvent, LPFILTER lpFilter)
  26. {
  27.     BYTE bStatus, bStatusRaw, bChannel, bData1, bData2;
  28.     /* Get the essential info from the EVENT.
  29.      */
  30.     bStatusRaw = LOBYTE(LOWORD(lpEvent->data));
  31.     bStatus = bStatusRaw & (BYTE) 0xf0;
  32.     bChannel = LOBYTE(LOWORD(lpEvent->data)) & (BYTE) 0x0f;
  33.     bData1 = HIBYTE(LOWORD(lpEvent->data));
  34.     bData2 = LOBYTE(HIWORD(lpEvent->data));
  35.     /* Do channel filtering for all but system events.
  36.      */
  37.     if(bStatus != SYSTEMMESSAGE){
  38.         if(lpFilter->channel[bChannel])
  39.             return 1;
  40.     }
  41.     /* Do event-type filtering.
  42.      */
  43.     switch(bStatus){
  44.         case NOTEOFF:
  45.             if(lpFilter->event.noteOff)
  46.                 return 1;
  47.             break;
  48.         case NOTEON:
  49.             /* A note on with a velocity of 0 is a note off.
  50.              */
  51.             if(bData2 == 0){
  52.                 if(lpFilter->event.noteOff)
  53.                     return 1;
  54.                 break;
  55.             }
  56.             
  57.             if(lpFilter->event.noteOn)
  58.                 return 1;
  59.             break;
  60.         case KEYAFTERTOUCH:
  61.             if(lpFilter->event.keyAftertouch)
  62.                 return 1;
  63.             break;
  64.         case CONTROLCHANGE:
  65.             if(lpFilter->event.controller)
  66.                 return 1;
  67.             
  68.             /* Channel mode messages can be filtered.
  69.              */
  70.             if((bData1 >= 121) && lpFilter->event.channelMode)
  71.                 return 1;
  72.             break;
  73.         case PROGRAMCHANGE:
  74.             if(lpFilter->event.progChange)
  75.                 return 1;
  76.             break;
  77.         case CHANAFTERTOUCH:
  78.             if(lpFilter->event.chanAftertouch)
  79.                 return 1;
  80.             break;
  81.         case PITCHBEND:
  82.             if(lpFilter->event.pitchBend)
  83.                 return 1;
  84.             break;
  85.         case SYSTEMMESSAGE:
  86.             /* System common messages.
  87.              */
  88.             if((bStatusRaw < 0xf8) && (lpFilter->event.sysCommon))
  89.                 return 1;
  90.             /* Active sensing messages.
  91.              */
  92.             if((bStatusRaw == 0xfe) && (lpFilter->event.activeSense))
  93.                 return 1;
  94.             /* System real time messages.
  95.              */
  96.             if((bStatusRaw >= 0xf8) && lpFilter->event.sysRealTime)
  97.                 return 1;
  98.             break;
  99.         default:
  100.             break;
  101.     }
  102.     return 0;
  103. }