Diff for /np2/win9x/cmmidi.cpp between versions 1.1.1.1 and 1.6

version 1.1.1.1, 2003/10/16 17:58:45 version 1.6, 2005/02/09 20:11:35
Line 2 Line 2
 #include        "np2.h"  #include        "np2.h"
 #include        "mimpidef.h"  #include        "mimpidef.h"
 #include        "commng.h"  #include        "commng.h"
 #include        "keydisp.h"  
 #if defined(VERMOUTH_LIB)  #if defined(VERMOUTH_LIB)
 #include        "sound.h"  #include        "sound.h"
 #include        "vermouth.h"  #include        "vermouth.h"
 #endif  #endif
   #include        "keydisp.h"
   
   
 #if defined(VERMOUTH_LIB)  #if defined(VERMOUTH_LIB)
Line 19  extern MIDIMOD vermouth_module; Line 19  extern MIDIMOD vermouth_module;
 #define MIDIOUTS3(a)            ((*(UINT32 *)(a)) & 0xffffff)  #define MIDIOUTS3(a)            ((*(UINT32 *)(a)) & 0xffffff)
   
   
 const char cmmidi_midimapper[] = "MIDI MAPPER";  const OEMCHAR cmmidi_midimapper[] = OEMTEXT("MIDI MAPPER");
 #if defined(VERMOUTH_LIB)  #if defined(VERMOUTH_LIB)
 const char cmmidi_vermouth[] = "VERMOUTH";  const OEMCHAR cmmidi_vermouth[] = OEMTEXT("VERMOUTH");
 #endif  #endif
 const char *cmmidi_mdlname[12] = {  const OEMCHAR *cmmidi_mdlname[12] = {
                         "MT-32",                "CM-32L",               "CM-64",                  OEMTEXT("MT-32"),       OEMTEXT("CM-32L"),              OEMTEXT("CM-64"),
                         "CM-300",               "CM-500(LA)",   "CM-500(GS)",                  OEMTEXT("CM-300"),      OEMTEXT("CM-500(LA)"),  OEMTEXT("CM-500(GS)"),
                         "SC-55",                "SC-88",                "LA",                  OEMTEXT("SC-55"),       OEMTEXT("SC-88"),               OEMTEXT("LA"),
                         "GM",                   "GS",                   "XG"};                  OEMTEXT("GM"),          OEMTEXT("GS"),                  OEMTEXT("XG")};
   
 enum {          MIDI_MT32 = 0,  MIDI_CM32L,             MIDI_CM64,  enum {          MIDI_MT32 = 0,  MIDI_CM32L,             MIDI_CM64,
                         MIDI_CM300,             MIDI_CM500LA,   MIDI_CM500GS,                          MIDI_CM300,             MIDI_CM500LA,   MIDI_CM500GS,
                         MIDI_SC55,              MIDI_SC88,              MIDI_LA,                          MIDI_SC55,              MIDI_SC88,              MIDI_LA,
                         MIDI_GM,                MIDI_GS,                MIDI_XG,        MIDI_OTHER};                          MIDI_GM,                MIDI_GS,                MIDI_XG,        MIDI_OTHER};
   
 static const BYTE EXCV_MTRESET[] = {  static const UINT8 EXCV_MTRESET[] = {
                         0xfe, 0xfe, 0xfe};                          0xfe, 0xfe, 0xfe};
 static const BYTE EXCV_GMRESET[] = {  static const UINT8 EXCV_GMRESET[] = {
                         0xf0, 0x7e, 0x7f, 0x09, 0x01, 0xf7};                          0xf0, 0x7e, 0x7f, 0x09, 0x01, 0xf7};
 static const BYTE EXCV_GSRESET[] = {  static const UINT8 EXCV_GSRESET[] = {
                         0xf0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7f, 0x00, 0x41, 0xf7};                          0xf0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7f, 0x00, 0x41, 0xf7};
 static const BYTE EXCV_XGRESET[] = {  static const UINT8 EXCV_XGRESET[] = {
                         0xf0, 0x43, 0x10, 0x4C, 0x00, 0x00, 0x7E, 0x00, 0xf7};                          0xf0, 0x43, 0x10, 0x4C, 0x00, 0x00, 0x7E, 0x00, 0xf7};
 static const BYTE EXCV_GMVOLUME[] = {  static const UINT8 EXCV_GMVOLUME[] = {
                         0xf0, 0x7F, 0x7F, 0x04, 0x01, 0x00, 0x00, 0xF7};                          0xf0, 0x7F, 0x7F, 0x04, 0x01, 0x00, 0x00, 0xF7};
   
 enum {  enum {
Line 83  struct _cmmidi; Line 83  struct _cmmidi;
 typedef struct _cmmidi  _CMMIDI;  typedef struct _cmmidi  _CMMIDI;
 typedef struct _cmmidi  *CMMIDI;  typedef struct _cmmidi  *CMMIDI;
   
   typedef struct {
           UINT8   prog;
           UINT8   press;
           UINT16  bend;
           UINT8   ctrl[28];
   } _MIDICH, *MIDICH;
   
 struct _cmmidi {  struct _cmmidi {
         UINT            opened;          UINT            opened;
         void            (*outfn)(CMMIDI self, UINT32 msg);          void            (*outfn)(CMMIDI self, UINT32 msg);
Line 97  struct _cmmidi { Line 104  struct _cmmidi {
         UINT            midisyscnt;          UINT            midisyscnt;
         UINT            mpos;          UINT            mpos;
   
         BYTE            midilast;          UINT8           midilast;
         BYTE            midiexcvwait;          UINT8           midiexcvwait;
         BYTE            midimodule;          UINT8           midimodule;
   
         BYTE            buffer[MIDI_BUFFER];          UINT8           buffer[MIDI_BUFFER];
         _MIDICH         mch[16];          _MIDICH         mch[16];
         BYTE            excvbuf[MIDI_BUFFER];          UINT8           excvbuf[MIDI_BUFFER];
   
         BYTE            def_en;          UINT8           def_en;
         MIMPIDEF        def;          MIMPIDEF        def;
   
         UINT            recvpos;          UINT            recvpos;
         UINT            recvsize;          UINT            recvsize;
         BYTE            recvbuf[MIDI_BUFFER];          UINT8           recvbuf[MIDI_BUFFER];
         BYTE            midiinbuf[MIDI_BUFFER];          UINT8           midiinbuf[MIDI_BUFFER];
 };  };
   
 typedef struct {  typedef struct {
Line 122  typedef struct { Line 129  typedef struct {
 static  UINT            midiinhdls;  static  UINT            midiinhdls;
 static  MIDIINHDL       midiinhdl[MIDIIN_MAX];  static  MIDIINHDL       midiinhdl[MIDIIN_MAX];
   
 static const BYTE midictrltbl[] = {     0, 1, 5, 7, 10, 11, 64,  static const UINT8 midictrltbl[] = { 0, 1, 5, 7, 10, 11, 64,
                                                                         65, 66, 67, 84, 91, 93,                                                                          65, 66, 67, 84, 91, 93,
                                                                         94,                                             // for SC-88                                                                          94,                                             // for SC-88
                                                                         71, 72, 73, 74};                // for XG                                                                          71, 72, 73, 74};                // for XG
   
 static  BYTE    midictrlindex[128];  static  UINT8   midictrlindex[128];
   
   
 // ----  // ----
   
 static BOOL getmidioutid(const char *midiout, UINT *ret) {  static BOOL getmidioutid(const OEMCHAR *midiout, UINT *ret) {
   
         UINT            num;          UINT            num;
         UINT            i;          UINT            i;
Line 153  static BOOL getmidioutid(const char *mid Line 160  static BOOL getmidioutid(const char *mid
         return(FAILURE);          return(FAILURE);
 }  }
   
 static BOOL getmidiinid(const char *midiin, UINT *ret) {  static BOOL getmidiinid(const OEMCHAR *midiin, UINT *ret) {
   
         UINT            num;          UINT            num;
         UINT            i;          UINT            i;
Line 174  static BOOL getmidiinid(const char *midi Line 181  static BOOL getmidiinid(const char *midi
         return(FAILURE);          return(FAILURE);
 }  }
   
 static UINT module2number(const char *module) {  static UINT module2number(const OEMCHAR *module) {
   
         UINT    i;          UINT    i;
   
         for (i=0; i<(sizeof(cmmidi_mdlname)/sizeof(char *)); i++) {          for (i=0; i<NELEMENTS(cmmidi_mdlname); i++) {
                 if (milstr_extendcmp(module, cmmidi_mdlname[i])) {                  if (milstr_extendcmp(module, cmmidi_mdlname[i])) {
                         break;                          break;
                 }                  }
Line 195  static void waitlastexclusiveout(CMMIDI  Line 202  static void waitlastexclusiveout(CMMIDI 
         }          }
 }  }
   
 static void sendexclusive(CMMIDI midi, const BYTE *buf, UINT leng) {  static void sendexclusive(CMMIDI midi, const UINT8 *buf, UINT leng) {
   
         CopyMemory(midi->excvbuf, buf, leng);          CopyMemory(midi->excvbuf, buf, leng);
         midi->hmidiouthdr.lpData = (char *)midi->excvbuf;          midi->hmidiouthdr.lpData = (char *)midi->excvbuf;
Line 249  const SINT32 *ptr; Line 256  const SINT32 *ptr;
   
 static void midireset(CMMIDI midi) {  static void midireset(CMMIDI midi) {
   
 const BYTE      *excv;  const UINT8     *excv;
         UINT    excvsize;          UINT    excvsize;
         BYTE    work[4];          UINT8   work[4];
   
         switch(midi->midimodule) {          switch(midi->midimodule) {
                 case MIDI_GM:                  case MIDI_GM:
Line 309  const BYTE *excv; Line 316  const BYTE *excv;
   
 static void midisetparam(CMMIDI midi) {  static void midisetparam(CMMIDI midi) {
   
         BYTE    i;          UINT8   i;
         UINT    j;          UINT    j;
         MIDICH  mch;          MIDICH  mch;
   
Line 321  static void midisetparam(CMMIDI midi) { Line 328  static void midisetparam(CMMIDI midi) {
                 if (mch->bend != 0xffff) {                  if (mch->bend != 0xffff) {
                         midi->outfn(midi, (mch->bend << 8) + 0xe0+i);                          midi->outfn(midi, (mch->bend << 8) + 0xe0+i);
                 }                  }
                 for (j=0; j<sizeof(midictrltbl)/sizeof(BYTE); j++) {                  for (j=0; j<NELEMENTS(midictrltbl); j++) {
                         if (mch->ctrl[j+1] != 0xff) {                          if (mch->ctrl[j+1] != 0xff) {
                                 midi->outfn(midi,                                  midi->outfn(midi,
                                                         MIDIOUTS(0xb0+i, midictrltbl[j], mch->ctrl[j+1]));                                                          MIDIOUTS(0xb0+i, midictrltbl[j], mch->ctrl[j+1]));
Line 336  static void midisetparam(CMMIDI midi) { Line 343  static void midisetparam(CMMIDI midi) {
   
 // ----  // ----
   
 static UINT     midiread(COMMNG self, BYTE *data) {  static UINT midiread(COMMNG self, UINT8 *data) {
   
         CMMIDI  midi;          CMMIDI  midi;
   
Line 350  static UINT midiread(COMMNG self, BYTE * Line 357  static UINT midiread(COMMNG self, BYTE *
         return(0);          return(0);
 }  }
   
 static UINT     midiwrite(COMMNG self, BYTE data) {  static UINT midiwrite(COMMNG self, UINT8 data) {
   
         CMMIDI  midi;          CMMIDI  midi;
         MIDICH  mch;          MIDICH  mch;
Line 463  static UINT midiwrite(COMMNG self, BYTE  Line 470  static UINT midiwrite(COMMNG self, BYTE 
                                                 if (midi->buffer[1] == 123) {                                                  if (midi->buffer[1] == 123) {
                                                         mch->press = 0;                                                          mch->press = 0;
                                                         mch->bend = 0x4000;                                                          mch->bend = 0x4000;
                                                         mch->ctrl[1] = 0;                       // Modulation                                                          mch->ctrl[1+1] = 0;                     // Modulation
                                                         mch->ctrl[5] = 127;                     // Explession                                                          mch->ctrl[5+1] = 127;           // Explession
                                                         mch->ctrl[6] = 0;                       // Hold                                                          mch->ctrl[6+1] = 0;                     // Hold
                                                         mch->ctrl[7] = 0;                       // Portament                                                          mch->ctrl[7+1] = 0;                     // Portament
                                                         mch->ctrl[8] = 0;                       // Sostenute                                                          mch->ctrl[8+1] = 0;                     // Sostenute
                                                         mch->ctrl[9] = 0;                       // Soft                                                          mch->ctrl[9+1] = 0;                     // Soft
                                                 }                                                  }
                                                 else {                                                  else {
                                                         mch->ctrl[midictrlindex[midi->buffer[1]]]                                                          mch->ctrl[midictrlindex[midi->buffer[1]]]
Line 529  static UINT midiwrite(COMMNG self, BYTE  Line 536  static UINT midiwrite(COMMNG self, BYTE 
         return(0);          return(0);
 }  }
   
 static BYTE     midigetstat(COMMNG self) {  static UINT8 midigetstat(COMMNG self) {
   
         return(0x00);          return(0x00);
 }  }
   
 static UINT     midimsg(COMMNG self, UINT msg, long param) {  static long midimsg(COMMNG self, UINT msg, long param) {
   
         CMMIDI  midi;          CMMIDI  midi;
           COMFLAG flag;
   
         midi = (CMMIDI)(self + 1);          midi = (CMMIDI)(self + 1);
         switch(msg) {          switch(msg) {
Line 544  static UINT midimsg(COMMNG self, UINT ms Line 552  static UINT midimsg(COMMNG self, UINT ms
                         midireset(midi);                          midireset(midi);
                         return(1);                          return(1);
   
                   case COMMSG_SETFLAG:
                           flag = (COMFLAG)param;
                           if ((flag) &&
                                   (flag->size == sizeof(_COMFLAG) + sizeof(midi->mch)) &&
                                   (flag->sig == COMSIG_MIDI)) {
                                   CopyMemory(midi->mch, flag + 1, sizeof(midi->mch));
                                   midisetparam(midi);
                                   return(1);
                           }
                           break;
   
                   case COMMSG_GETFLAG:
                           flag = (COMFLAG)_MALLOC(sizeof(_COMFLAG) + sizeof(midi->mch),
                                                                                                                                   "MIDI FLAG");
                           if (flag) {
                                   flag->size = sizeof(_COMFLAG) + sizeof(midi->mch);
                                   flag->sig = COMSIG_MIDI;
                                   flag->ver = 0;
                                   flag->param = 0;
                                   CopyMemory(flag + 1, midi->mch, sizeof(midi->mch));
                                   return((long)flag);
                           }
                           break;
   
                 case COMMSG_MIMPIDEFFILE:                  case COMMSG_MIMPIDEFFILE:
                         mimpidef_load(&midi->def, (char *)param);                          mimpidef_load(&midi->def, (OEMCHAR *)param);
                         return(1);                          return(1);
   
                 case COMMSG_MIMPIDEFEN:                  case COMMSG_MIMPIDEFEN:
                         midi->def_en = (param)?TRUE:FALSE;                          midi->def_en = (param)?TRUE:FALSE;
                         return(1);                          return(1);
   
                 case COMMSG_MIDISTATSET:  
                         CopyMemory(midi->mch, (void *)param, sizeof(midi->mch));  
                         midisetparam(midi);  
                         return(1);  
   
                 case COMMSG_MIDISTATGET:  
                         CopyMemory((void *)param, midi->mch, sizeof(midi->mch));  
                         return(1);  
         }          }
         return(0);          return(0);
 }  }
Line 643  void cmmidi_initailize(void) { Line 666  void cmmidi_initailize(void) {
         UINT    i;          UINT    i;
   
         ZeroMemory(midictrlindex, sizeof(midictrlindex));          ZeroMemory(midictrlindex, sizeof(midictrlindex));
         for (i=0; i<sizeof(midictrltbl)/sizeof(BYTE); i++) {          for (i=0; i<NELEMENTS(midictrltbl); i++) {
                 midictrlindex[midictrltbl[i]] = (BYTE)(i + 1);                  midictrlindex[midictrltbl[i]] = (UINT8)(i + 1);
         }          }
         midictrlindex[32] = 1;          midictrlindex[32] = 1;
 }  }
   
 COMMNG cmmidi_create(const char *midiout, const char *midiin,  COMMNG cmmidi_create(const OEMCHAR *midiout, const OEMCHAR *midiin,
                                                                                                                 const char *module) {                                                                                                          const OEMCHAR *module) {
   
         UINT            opened;          UINT            opened;
         UINT            id;          UINT            id;
Line 732  COMMNG cmmidi_create(const char *midiout Line 755  COMMNG cmmidi_create(const char *midiout
   
         midi->midilast = 0x80;          midi->midilast = 0x80;
 //      midi->midiexcvwait = 0;  //      midi->midiexcvwait = 0;
         midi->midimodule = (BYTE)module2number(module);          midi->midimodule = (UINT8)module2number(module);
         FillMemory(midi->mch, sizeof(midi->mch), 0xff);          FillMemory(midi->mch, sizeof(midi->mch), 0xff);
         return(ret);          return(ret);
   
Line 754  cmcre_err1: Line 777  cmcre_err1:
   
 // ---- midiin callback  // ---- midiin callback
   
 static void midiinrecv(CMMIDI midi, const BYTE *data, UINT size) {  static void midiinrecv(CMMIDI midi, const UINT8 *data, UINT size) {
   
         UINT    wpos;          UINT    wpos;
         UINT    wsize;          UINT    wsize;
Line 808  void cmmidi_recvdata(HMIDIIN hdr, UINT32 Line 831  void cmmidi_recvdata(HMIDIIN hdr, UINT32
                                 break;                                  break;
 #endif  #endif
                 }                  }
                 midiinrecv(midi, (BYTE *)&data, databytes);                  midiinrecv(midi, (UINT8 *)&data, databytes);
         }          }
 }  }
   
Line 818  void cmmidi_recvexcv(HMIDIIN hdr, MIDIHD Line 841  void cmmidi_recvexcv(HMIDIIN hdr, MIDIHD
   
         midi = midiinhdlget(hdr);          midi = midiinhdlget(hdr);
         if (midi) {          if (midi) {
                 midiinrecv(midi, (BYTE *)data->lpData, data->dwBytesRecorded);                  midiinrecv(midi, (UINT8 *)data->lpData, data->dwBytesRecorded);
                 midiInUnprepareHeader(midi->hmidiin,                  midiInUnprepareHeader(midi->hmidiin,
                                                                                 &midi->hmidiinhdr, sizeof(MIDIHDR));                                                                                  &midi->hmidiinhdr, sizeof(MIDIHDR));
                 midiInPrepareHeader(midi->hmidiin,                  midiInPrepareHeader(midi->hmidiin,

Removed from v.1.1.1.1  
changed lines
  Added in v.1.6


RetroPC.NET-CVS <cvs@retropc.net>