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

📄 w32g_utl.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 3 页
字号:
/*    TiMidity++ -- MIDI to WAVE converter and player    Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>    Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>    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    w32g_utl.c: written by Daisuke Aoki <dai@y7.net>                           Masanao Izumo <mo@goice.co.jp>*/#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include "interface.h"#include <stdlib.h>#include <stdio.h>#ifndef NO_STRING_H#include <string.h>#else#include <strings.h>#endif#include <ctype.h>#include "timidity.h"#include "common.h"#include "instrum.h"#include "playmidi.h"#include "readmidi.h"#include "reverb.h"#include "output.h"#include "controls.h"#include "recache.h"#include "tables.h"#ifdef SUPPORT_SOUNDSPEC#include "soundspec.h"#endif /* SUPPORT_SOUNDSPEC */#include "wrd.h"#include "w32g.h"#include "w32g_utl.h"#include <sys/stat.h>#include "strtab.h"#include "url.h"extern int opt_default_mid;extern int effect_lr_mode;extern int effect_lr_delay_msec;extern char def_instr_name[];extern int opt_control_ratio;extern char *opt_aq_max_buff;extern char *opt_aq_fill_buff;extern int opt_evil_mode;extern int opt_buffer_fragments;extern int32 opt_output_rate;extern int PlayerLanguage;extern volatile int data_block_bits;extern volatile int data_block_num;extern int DocWndIndependent;extern int DocWndAutoPopup;extern int SeachDirRecursive;extern int IniFileAutoSave;extern int SecondMode;extern int AutoloadPlaylist;extern int AutosavePlaylist;char DefaultPlaylistName[] = "default.pls";char DefaultPlaylistPath[1024];extern int PosSizeSave;//*****************************************************************************/// ini// INI fileCHAR *INI_INVALID = "INVALID PARAMETER";CHAR *INI_SEC_PLAYER = "PLAYER";CHAR *INI_SEC_TIMIDITY = "TIMIDITY";#define INI_MAXLEN 1024intIniGetKeyInt32(char *section, char *key,int32 *n){  CHAR buffer[INI_MAXLEN];  GetPrivateProfileString    (section,key,INI_INVALID,buffer,INI_MAXLEN-1,IniFile);  if(strcasecmp(buffer,INI_INVALID)){    *n =atol(buffer);    return 0;  } else    return 1;}intIniGetKeyInt(char *section, char *key,int *n){  CHAR buffer[INI_MAXLEN];  GetPrivateProfileString    (section,key,INI_INVALID,buffer,INI_MAXLEN-1,IniFile);  if(strcasecmp(buffer,INI_INVALID)){    *n =atoi(buffer);    return 0;  } else    return 1;}intIniGetKeyInt8(char *section, char *key,int8 *n){  CHAR buffer[INI_MAXLEN];  GetPrivateProfileString    (section,key,INI_INVALID,buffer,INI_MAXLEN-1,IniFile);  if(strcasecmp(buffer,INI_INVALID)){    *n = (int8)atoi(buffer);    return 0;  } else    return 1;}intIniGetKeyInt32Array(char *section, char *key, int32 *n, int arraysize){  int i;  int ret = 0;  CHAR buffer[INI_MAXLEN];  char keybuffer[INI_MAXLEN];  for(i=0;i<arraysize;i++){    sprintf(keybuffer,"%s%d",key,i);    GetPrivateProfileString      (section,keybuffer,INI_INVALID,buffer,INI_MAXLEN-1,IniFile);    if(strcasecmp(buffer,INI_INVALID))      n[i] =atol(buffer);    else      ret++;  }  return ret;}intIniGetKeyIntArray(char *section, char *key, int *n, int arraysize){  int i;  int ret = 0;  CHAR buffer[INI_MAXLEN];  char keybuffer[INI_MAXLEN];  for(i=0;i<arraysize;i++){    sprintf(keybuffer,"%s%d",key,i);    GetPrivateProfileString      (section,keybuffer,INI_INVALID,buffer,INI_MAXLEN-1,IniFile);    if(strcasecmp(buffer,INI_INVALID))      n[i] =atol(buffer);    else      ret++;  }  return ret;}intIniGetKeyFloat(char *section, char *key, FLOAT_T *n){    CHAR buffer[INI_MAXLEN];    GetPrivateProfileString(section, key, INI_INVALID, buffer,			    INI_MAXLEN-1, IniFile);    if(strcasecmp(buffer, INI_INVALID))    {	*n = (FLOAT_T)atof(buffer);	return 0;    }    else	return 1;}intIniGetKeyChar(char *section, char *key, char *c){  char buffer[64];  if(IniGetKeyStringN(section,key,buffer,60))    return 1;  else {    *c = buffer[0];    return 0;  }}intIniGetKeyString(char *section, char *key,char *str){  CHAR buffer[INI_MAXLEN];  GetPrivateProfileString    (section,key,INI_INVALID,buffer,INI_MAXLEN-1,IniFile);  if(strcasecmp(buffer,INI_INVALID)){    strcpy(str,buffer);    return 0;  } else    return 1;}intIniGetKeyStringN(char *section, char *key,char *str, int size){  CHAR buffer[INI_MAXLEN];  GetPrivateProfileString    (section,key,INI_INVALID,buffer,INI_MAXLEN-1,IniFile);  if(strcasecmp(buffer,INI_INVALID)){    strncpy(str,buffer,size);    return 0;  }	else    return 1;}intIniPutKeyInt32(char *section, char *key,int32 *n){  CHAR buffer[INI_MAXLEN];  sprintf(buffer,"%ld",*n);  WritePrivateProfileString    (section,key,buffer,IniFile);  return 0;}intIniPutKeyInt(char *section, char *key,int *n){  CHAR buffer[INI_MAXLEN];  sprintf(buffer,"%ld",*n);  WritePrivateProfileString    (section,key,buffer,IniFile);  return 0;}intIniPutKeyInt8(char *section, char *key,int8 *n){  CHAR buffer[INI_MAXLEN];  sprintf(buffer,"%ld",(int)(*n));  WritePrivateProfileString    (section,key,buffer,IniFile);  return 0;}intIniPutKeyInt32Array(char *section, char *key, int32 *n, int arraysize){  int i;  CHAR buffer[INI_MAXLEN];  CHAR keybuffer[INI_MAXLEN];  for(i=0;i<arraysize;i++){    sprintf(buffer,"%ld",n[i]);    sprintf(keybuffer,"%s%d",key,i);    WritePrivateProfileString(section,keybuffer,buffer,IniFile);  }  return 0;}intIniPutKeyIntArray(char *section, char *key, int *n, int arraysize){  int i;  CHAR buffer[INI_MAXLEN];  CHAR keybuffer[INI_MAXLEN];  for(i=0;i<arraysize;i++){    sprintf(buffer,"%ld",n[i]);    sprintf(keybuffer,"%s%d",key,i);    WritePrivateProfileString(section,keybuffer,buffer,IniFile);  }  return 0;}intIniPutKeyChar(char *section, char *key, char *c){  char buffer[64];  sprintf(buffer,"%c",*c);  return IniPutKeyStringN(section,key,buffer,60);}intIniPutKeyString(char *section, char *key, char *str){  WritePrivateProfileString(section,key,str,IniFile);  return 0;}intIniPutKeyStringN(char *section, char *key, char *str, int size){  WritePrivateProfileString(section,key,str,IniFile);  return 0;}intIniPutKeyFloat(char *section, char *key,FLOAT_T n){    CHAR buffer[INI_MAXLEN];    sprintf(buffer,"%f", (double)n);    WritePrivateProfileString(section, key, buffer, IniFile);    return 0;}void IniFlush(void){	WritePrivateProfileString(NULL,NULL,NULL,IniFile);}// LoadIniFile() , SaveIniFile()// ***************************************************************************// Setting#define SetFlag(flag) (!!(flag))static long SetValue(int32 value, int32 min, int32 max){  int32 v = value;  if(v < min) v = min;  else if( v > max) v = max;  return v;}voidApplySettingPlayer(SETTING_PLAYER *sp){  InitMinimizeFlag = SetFlag(sp->InitMinimizeFlag);  DebugWndStartFlag = SetFlag(sp->DebugWndStartFlag);  ConsoleWndStartFlag = SetFlag(sp->ConsoleWndStartFlag);  ListWndStartFlag = SetFlag(sp->ListWndStartFlag);  TracerWndStartFlag = SetFlag(sp->TracerWndStartFlag);  DocWndStartFlag = SetFlag(sp->DocWndStartFlag);  WrdWndStartFlag = SetFlag(sp->WrdWndStartFlag);  DebugWndFlag = SetFlag(sp->DebugWndFlag);  ConsoleWndFlag = SetFlag(sp->ConsoleWndFlag);  ListWndFlag = SetFlag(sp->ListWndFlag);  TracerWndFlag = SetFlag(sp->TracerWndFlag);  DocWndFlag = SetFlag(sp->DocWndFlag);  WrdWndFlag = SetFlag(sp->WrdWndFlag);  SoundSpecWndFlag = SetFlag(sp->SoundSpecWndFlag);  SubWindowMax = SetValue(sp->SubWindowMax,1,10);  strncpy(ConfigFile,sp->ConfigFile,MAXPATH + 31);  ConfigFile[MAXPATH + 31] = '\0';  strncpy(PlaylistFile,sp->PlaylistFile,MAXPATH + 31);  PlaylistFile[MAXPATH + 31] = '\0';  strncpy(PlaylistHistoryFile,sp->PlaylistHistoryFile,MAXPATH + 31);  PlaylistHistoryFile[MAXPATH + 31] = '\0';  strncpy(MidiFileOpenDir,sp->MidiFileOpenDir,MAXPATH + 31);  MidiFileOpenDir[MAXPATH + 31] = '\0';  strncpy(ConfigFileOpenDir,sp->ConfigFileOpenDir,MAXPATH + 31);  ConfigFileOpenDir[MAXPATH + 31] = '\0';  strncpy(PlaylistFileOpenDir,sp->PlaylistFileOpenDir,MAXPATH + 31);  PlaylistFileOpenDir[MAXPATH + 31] = '\0';  PlayerThreadPriority = sp->PlayerThreadPriority;  GUIThreadPriority = sp->GUIThreadPriority;  TraceGraphicFlag = SetFlag(sp->TraceGraphicFlag);  // fonts ...  SystemFontSize = sp->SystemFontSize;  PlayerFontSize = sp->PlayerFontSize;  WrdFontSize = sp->WrdFontSize;  DocFontSize = sp->DocFontSize;  ListFontSize = sp->ListFontSize;  TracerFontSize = sp->TracerFontSize;  strncpy(SystemFont,sp->SystemFont,255);  SystemFont[255] = '\0';  strncpy(PlayerFont,sp->PlayerFont,255);  PlayerFont[255] = '\0';  strncpy(WrdFont,sp->WrdFont,255);  WrdFont[255] = '\0';  strncpy(DocFont,sp->DocFont,255);  DocFont[255] = '\0';  strncpy(ListFont,sp->ListFont,255);  ListFont[255] = '\0';  strncpy(TracerFont,sp->TracerFont,255);  TracerFont[255] = '\0';  // Apply font functions ...  DocMaxSize = sp->DocMaxSize;  strncpy(DocFileExt,sp->DocFileExt,255);  DocFileExt[255] = '\0';  PlayerLanguage = sp->PlayerLanguage;  DocWndIndependent = sp->DocWndIndependent;   DocWndAutoPopup = sp->DocWndAutoPopup;   SeachDirRecursive = sp->SeachDirRecursive;  IniFileAutoSave = sp->IniFileAutoSave;  SecondMode = sp->SecondMode;  AutoloadPlaylist = sp->AutoloadPlaylist;  AutosavePlaylist = sp->AutosavePlaylist;  PosSizeSave = sp->PosSizeSave;}voidSaveSettingPlayer(SETTING_PLAYER *sp){  sp->InitMinimizeFlag = SetFlag(InitMinimizeFlag);  sp->DebugWndStartFlag = SetFlag(DebugWndStartFlag);  sp->ConsoleWndStartFlag = SetFlag(ConsoleWndStartFlag);  sp->ListWndStartFlag = SetFlag(ListWndStartFlag);  sp->TracerWndStartFlag = SetFlag(TracerWndStartFlag);  sp->DocWndStartFlag = SetFlag(DocWndStartFlag);  sp->WrdWndStartFlag = SetFlag(WrdWndStartFlag);  sp->DebugWndFlag = SetFlag(DebugWndFlag);  sp->ConsoleWndFlag = SetFlag(ConsoleWndFlag);  sp->ListWndFlag = SetFlag(ListWndFlag);  sp->TracerWndFlag = SetFlag(TracerWndFlag);  sp->DocWndFlag = SetFlag(DocWndFlag);  sp->WrdWndFlag = SetFlag(WrdWndFlag);  sp->SoundSpecWndFlag = SetFlag(SoundSpecWndFlag);  sp->SubWindowMax = SetValue(SubWindowMax,1,10);  strncpy(sp->ConfigFile,ConfigFile,MAXPATH + 31);  (sp->ConfigFile)[MAXPATH + 31] = '\0';  strncpy(sp->PlaylistFile,PlaylistFile,MAXPATH + 31);  (sp->PlaylistFile)[MAXPATH + 31] = '\0';  strncpy(sp->PlaylistHistoryFile,PlaylistHistoryFile,MAXPATH + 31);  (sp->PlaylistHistoryFile)[MAXPATH + 31] = '\0';  strncpy(sp->MidiFileOpenDir,MidiFileOpenDir,MAXPATH + 31);  (sp->MidiFileOpenDir)[MAXPATH + 31] = '\0';  strncpy(sp->ConfigFileOpenDir,ConfigFileOpenDir,MAXPATH + 31);  (sp->ConfigFileOpenDir)[MAXPATH + 31] = '\0';  strncpy(sp->PlaylistFileOpenDir,PlaylistFileOpenDir,MAXPATH + 31);  (sp->PlaylistFileOpenDir)[MAXPATH + 31] = '\0';  sp->PlayerThreadPriority = PlayerThreadPriority;  sp->GUIThreadPriority = GUIThreadPriority;  sp->WrdGraphicFlag = SetFlag(WrdGraphicFlag);  sp->TraceGraphicFlag = SetFlag(TraceGraphicFlag);  // fonts ...  sp->SystemFontSize = SystemFontSize;  sp->PlayerFontSize = PlayerFontSize;  sp->WrdFontSize = WrdFontSize;  sp->DocFontSize = DocFontSize;  sp->ListFontSize = ListFontSize;  sp->TracerFontSize = TracerFontSize;  strncpy(sp->SystemFont,SystemFont,255);  sp->SystemFont[255] = '\0';  strncpy(sp->PlayerFont,PlayerFont,255);  sp->PlayerFont[255] = '\0';  strncpy(sp->WrdFont,WrdFont,255);  sp->WrdFont[255] = '\0';  strncpy(sp->DocFont,DocFont,255);  DocFont[255] = '\0';  strncpy(sp->ListFont,ListFont,255);  sp->ListFont[255] = '\0';  strncpy(sp->TracerFont,TracerFont,255);  sp->TracerFont[255] = '\0';  sp->DocMaxSize = DocMaxSize;  strncpy(sp->DocFileExt,DocFileExt,255);  sp->DocFileExt[255] = '\0';  sp->PlayerLanguage = PlayerLanguage;  sp->DocWndIndependent = DocWndIndependent;   sp->DocWndAutoPopup = DocWndAutoPopup;   sp->SeachDirRecursive = SeachDirRecursive;  sp->IniFileAutoSave = IniFileAutoSave;  sp->SecondMode = SecondMode;  sp->AutoloadPlaylist = AutoloadPlaylist;  sp->AutosavePlaylist = AutosavePlaylist;  sp->PosSizeSave = PosSizeSave;}

⌨️ 快捷键说明

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