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

📄 player_g36.c

📁 一个很好的c++ midi解码算法,不依赖于任何平台.
💻 C
字号:
/* *  player_g36.cc *  Copyright (C) 1998,1999 SAKAI Katsuya * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <stdio.h> // #include <iostream.h>#include <unistd.h>#include <fcntl.h>#include <sys/ioctl.h>#include <string.h>#include <stdio.h>#include "config.h"#include "sequencer.h"#include "player.h"#include "defines.h"#include "extern.h"int G36_Player::load(char *filename){  int songfd;  u_char g36Version;  char buffer[192];  u_long n;  clear();  if (filename==NULL)	songfd = fileno (stdin);  else	songfd = open(filename, O_RDONLY);  if(songfd<0)	{	  return -1;	}  // Windowns version かどうかのチェック  lseek(songfd, -34L, SEEK_END);  read(songfd, buffer, 4);  if(buffer[0]=='R' && buffer[1]=='C' && buffer[2]=='F' && buffer[3]=='W')	g36Version=V_G36_WIN;  else	g36Version=V_G36_DOS;    lseek(songfd, 0L, SEEK_SET);  // ヘッダの矢机误チェック  read(songfd, Header.Text, 32);#ifdef SHOW_HEADER  for(n=0;n<31;n++)	{	  cout << Header.Text[n] << flush;	}#endif  if(strncmp(Header.Text, "COME ON MUSIC RECOMPOSER RCP3.0", 31)!=0)	{	  if (filename==NULL)		close (songfd);	  return -2;	}  // ヘッダデ〖タ粕み哈み  read(songfd, Header.Title, 64);  read(songfd, buffer, 64 );  read(songfd, Header.Memo, 360);  read(songfd, buffer, 2 );  Header.NumOfTrack = (buffer[1]<<8) | (buffer[0]&0xff);  read(songfd, buffer, 2 );  aSequencer->set_timebase ((buffer[1]<<8) | (buffer[0]&0xff));  read(songfd, buffer, 2);  Header.Tempo = (buffer[1]<<8) | (buffer[0]&0xff);  aSequencer->set_tempo (60*1000000/Header.Tempo);  read(songfd, Header.TimeSignature, 2);  read(songfd, &Header.Key, 1);  read(songfd, &Header.PlayBIAS, 1);  read(songfd, buffer, 6);  read(songfd, buffer, 144);  read(songfd, Header.GSDfile, 16);  read(songfd, Header.GSD2file,16);  read(songfd, Header.CM6file, 16);  read(songfd, buffer, 96);#ifdef SHOW_HEADER  cout << endl 	   << "version("<<V_G36_DOS<<":dos, "<<V_G36_WIN<<":win):"     	   << (int)g36Version << endl	   << "Title   :" << (u_int)Header.Title << endl	   << "Timebase:" << (u_int)aSequencer->show_timebase << endl	   << "Tempo   :" << (u_int)Header.Tempo << endl	   << "BIAS    :" << (int)Header.PlayBIAS << endl	   << "TimeSignature:" << (int) Header.TimeSignature[0]	   << "/" << (int) Header.TimeSignature[1] << endl	   << "Track   :" << (u_int)Header.NumOfTrack << endl;#endif#if defined(SHOW_RYTHM) || defined(SHOW_USEREX) || defined(SHOW_THEADER)  int name;#endif  // リズム不富年盗の粕み哈み  for(n=0;n<126;n++)	{	  read(songfd, Rythm.Name[n], 14);	  read(songfd, &Rythm.Key[n], 1);	  read(songfd, &Rythm.GateTime[n], 1);#ifdef SHOW_RYTHM	  cout << "RythmDefine read:";	  for(name=0;name<13;name++) cout << Rythm.Name[n][name];	  cout << " key:" << (int)Rythm.Key[n]		   << " GT:" << (int)Rythm.GateTime[n] << endl;  #endif	}    // ユ〖ザエクスクル〖シブ年盗の粕み哈み  for(n=0;n<8;n++)	{	  read(songfd, Exclusive.Memo[n], 23);	  if (read(songfd, Exclusive.Data[n], 25)<25)		{		  if (filename==NULL)			close (songfd);		  return -3;		}#ifdef SHOW_USEREX	  cout << "UserExclusiveDefine read :";	  for(name=0;name<23;name++) cout << Exclusive.Memo[n][name];	  cout << endl; #endif	}    Track = new G36_Track [Header.NumOfTrack];  if(!Track)	{	  if (filename==NULL)		close (songfd);	  return -4;	}    // トラックデ〖タの粕み哈み  for(n=0;n<Header.NumOfTrack;n++)	{	  read(songfd, buffer, 4);	  Track[n].DataLength = (u_long)((buffer[3]&0xff)<<24) 		+ ((buffer[2]&0xff)<<16)		+ ((buffer[1]&0xff)<<8) 		+ (buffer[0]&0xff);	  read(songfd, &Track[n].Number, 1);	  read(songfd, &Track[n].RythmFlag, 1);	  read(songfd, &Track[n].Channel, 1);	  read(songfd, &Track[n].Key_Bias, 1);	  read(songfd, &Track[n].ST_Bias, 1);	  read(songfd, &Track[n].Mode, 1);	  if (read(songfd, Track[n].Comment, 36)<36)		{		  Header.NumOfTrack = n;		  continue;		}	  if(Track[n].Number!=n+1)		{#ifdef SHOW_THEADER		  cout << endl << "warning: broken file? ";#endif		  Track[n].Number=n+1;		}#ifdef SHOW_THEADER	  cout << endl		   << "Ch+Dev(0xff:off):" << hex << (int)Track[n].Channel << dec;#endif	  if(Track[n].Channel==0xff) Track[n].Mute=TRUE;	  Track[n].Port = (Track[n].Channel&0xf0)>>4;	  Track[n].Channel = Track[n].Channel & 0x0f;	  Track[n].Version = g36Version;#ifdef SHOW_THEADER	  cout << endl		   <<"Track :" << (int)Track[n].Number << endl		   << "RythmFlag:" << (int)Track[n].RythmFlag << endl;	  if(Track[n].Mute==FALSE)		{		  cout << "Port:" << (int)Track[n].Port << endl			   << "Channel:" << (int)Track[n].Channel+1 << endl;		}	  else		{		  cout << "Port: OFF" << endl << "Channel: OFF" << endl;		}	  cout << "DataLength:" << Track[n].DataLength << endl		   << "Key+:" << (int)Track[n].Key_Bias << endl 		   << "ST:" << (int)Track[n].ST_Bias << endl 		   << "Mode:" << (int)Track[n].Mode << endl 		   << endl << "Comment:";	  for(name=0;name<36;name++) cout << Track[n].Comment[name];	  cout << endl;#endif	  Track[n].Data = new u_char [ Track[n].DataLength-46 ];	  if(!(Track[n].Data))		{		  delete [] Track;		  Track = NULL;		  if (filename==NULL)			close (songfd);		  return -4;		}	  if(read(songfd, Track[n].Data, Track[n].DataLength-46)<Track[n].DataLength-46)		{		  if (filename==NULL)			close (songfd);		  return -3;		}	}  if (filename==NULL)	close (songfd);  return 0;}

⌨️ 快捷键说明

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