home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / audio / midimon / filter.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  3KB  |  121 lines

  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. /*
  13.  * filter.c - Routines to filter MIDI events.
  14.  */
  15.  
  16. #include <windows.h>
  17. #include "midimon.h"
  18. #include "display.h"
  19. #include "filter.h"
  20.  
  21. /* CheckEventFilter - Checks the given EVENT against the given FILTER.
  22.  *      
  23.  * Params:  lpEvent - Points to an EVENT.
  24.  *          lpFilter - Points to a FILTER structure.
  25.  *
  26.  * Return:  Returns 1 if the event is filtered, 0 if it is not filtered.
  27.  */
  28. BOOL CheckEventFilter(LPEVENT lpEvent, LPFILTER lpFilter)
  29. {
  30.     BYTE bStatus, bStatusRaw, bChannel, bData1, bData2;
  31.  
  32.     /* Get the essential info from the EVENT.
  33.      */
  34.     bStatusRaw = LOBYTE(LOWORD(lpEvent->data));
  35.     bStatus = bStatusRaw & (BYTE) 0xf0;
  36.     bChannel = LOBYTE(LOWORD(lpEvent->data)) & (BYTE) 0x0f;
  37.     bData1 = HIBYTE(LOWORD(lpEvent->data));
  38.     bData2 = LOBYTE(HIWORD(lpEvent->data));
  39.  
  40.     /* Do channel filtering for all but system events.
  41.      */
  42.     if(bStatus != SYSTEMMESSAGE){
  43.         if(lpFilter->channel[bChannel])
  44.             return 1;
  45.     }
  46.  
  47.     /* Do event-type filtering.
  48.      */
  49.     switch(bStatus){
  50.         case NOTEOFF:
  51.             if(lpFilter->event.noteOff)
  52.                 return 1;
  53.             break;
  54.  
  55.         case NOTEON:
  56.             /* A note on with a velocity of 0 is a note off.
  57.              */
  58.             if(bData2 == 0){
  59.                 if(lpFilter->event.noteOff)
  60.                     return 1;
  61.                 break;
  62.             }
  63.             
  64.             if(lpFilter->event.noteOn)
  65.                 return 1;
  66.             break;
  67.  
  68.         case KEYAFTERTOUCH:
  69.             if(lpFilter->event.keyAftertouch)
  70.                 return 1;
  71.             break;
  72.  
  73.         case CONTROLCHANGE:
  74.             if(lpFilter->event.controller)
  75.                 return 1;
  76.             
  77.             /* Channel mode messages can be filtered.
  78.              */
  79.             if((bData1 >= 121) && lpFilter->event.channelMode)
  80.                 return 1;
  81.             break;
  82.  
  83.         case PROGRAMCHANGE:
  84.             if(lpFilter->event.progChange)
  85.                 return 1;
  86.             break;
  87.  
  88.         case CHANAFTERTOUCH:
  89.             if(lpFilter->event.chanAftertouch)
  90.                 return 1;
  91.             break;
  92.  
  93.         case PITCHBEND:
  94.             if(lpFilter->event.pitchBend)
  95.                 return 1;
  96.             break;
  97.  
  98.         case SYSTEMMESSAGE:
  99.             /* System common messages.
  100.              */
  101.             if((bStatusRaw < 0xf8) && (lpFilter->event.sysCommon))
  102.                 return 1;
  103.  
  104.             /* Active sensing messages.
  105.              */
  106.             if((bStatusRaw == 0xfe) && (lpFilter->event.activeSense))
  107.                 return 1;
  108.  
  109.             /* System real time messages.
  110.              */
  111.             if((bStatusRaw >= 0xf8) && lpFilter->event.sysRealTime)
  112.                 return 1;
  113.             break;
  114.  
  115.         default:
  116.             break;
  117.     }
  118.  
  119.     return 0;
  120. }
  121.