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

📄 mac_main.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 2 页
字号:
	if( dialog==0 ) return;	SetDialogDefaultItem(dialog, 1);	#ifdef __POWERPC__ #define TIMID_CPU "PPC"#elif __MC68K__ #if  __MC68881__  #define TIMID_CPU "68k+FPU" #else  #define TIMID_CPU "68k" #endif#endif	ParamText("\p" TIMID_VERSION TIMID_CPU, "\p", "\p", "\p");		ShowWindow(dialog);	for(;;){		WaitNextEvent(everyEvent, &event, 10, 0);		if( ! IsDialogEvent(&event) )	continue;		if( StdFilterProc(dialog, &event, &item) ) /**/;			else DialogSelect(&event, &theDialog, &item);		if( theDialog!=dialog ) continue;		if( item==1 ) break;		YieldToAnyThread();	}	DisposeDialog(dialog);}static void CloseFrontWindow(){	WindowRef window;	MacWindow   *macwin;		window=FrontWindow();	if( ! window ) return;	macwin= (MacWindow*)GetWRefCon(window);	if( ! macwin ) return;	macwin->goaway(macwin);}void mac_HandleMenuSelect(long select, short modifiers){	StandardFileReply	stdReply;	Str255	str;	switch(select)	{	case iAbout:		mac_AboutBox();		return;	case iOpen:		StandardGetFile(0, -1, 0, &stdReply);		if (stdReply.sfGood)		{			mac_add_fsspec(&stdReply.sfFile);		}		return;	case iClose:		CloseFrontWindow();		return;	case iLogWindow:	SHOW_WINDOW(mac_LogWindow);		return;	case iListWindow:	SHOW_WINDOW(mac_ListWindow);	return;	case iWrdWindow:	SHOW_WINDOW(mac_WrdWindow);		return;	case iDocWindow:	SHOW_WINDOW(mac_DocWindow);		return;	case iSpecWindow:#ifdef SUPPORT_SOUNDSPEC		if(!mac_SpecWindow.show)		{			mac_SpecWindow.show=true;		    open_soundspec();  			soundspec_update_wave(NULL, 0);		}		SelectWindow(mac_SpecWindow.ref);#endif /* SUPPORT_SOUNDSPEC */		return;	case iTraceWindow:	SHOW_WINDOW(mac_TraceWindow);	return;	case iSkinWindow: SHOW_WINDOW(mac_SkinWindow); return;	case iSaveAs:		NewThread(kCooperativeThread, ConvertToAiffFile,	         0, 0, kCreateIfNeeded, 0, 0);		return;			case iPref:	mac_SetPlayOption(); return;	case iQuit:	Do_Quit();			 return;		//Play menu	case iPlay:	SKIN_ACTION_PLAY(); break;	case iStop:	SKIN_ACTION_STOP();	break;	case iPause:	SKIN_ACTION_PAUSE(); break;	case iPrev:	SKIN_ACTION_PREV(); break;	case iNext:	SKIN_ACTION_NEXT(); break;			//Synth menu	case iTiMidity:{		MenuHandle menu=GetMenu(mSynth);		CheckItem(menu, iTiMidity & 0x0000FFFF, 1);		CheckItem(menu, iQuickTime & 0x0000FFFF, 0);		CheckItem(menu, iOMS & 0x0000FFFF, 0);		play_mode=&mac_play_mode;		}		return;	case iQuickTime:{		MenuHandle menu=GetMenu(mSynth);				if( mac_quicktime_play_mode.fd==-1 ){ //not opened yet			if( mac_quicktime_play_mode.open_output()!=0 ){				SysBeep(0);				return;	//can't open device			}		}		CheckItem(menu, iTiMidity & 0x0000FFFF, 0);		CheckItem(menu, iQuickTime & 0x0000FFFF, 1);		CheckItem(menu, iOMS & 0x0000FFFF, 0);		play_mode=&mac_quicktime_play_mode;		}		return;#ifdef MAC_USE_OMS	case iOMS:{		MenuHandle menu=GetMenu(mSynth);				if( mac_oms_play_mode.fd==-1 || (modifiers & optionKey) ){			if( mac_oms_play_mode.open_output()!=0 ){				SysBeep(0);				return;	//can't open device			}		}		CheckItem(menu, iTiMidity & 0x0000FFFF, 0);		CheckItem(menu, iQuickTime & 0x0000FFFF, 0);		CheckItem(menu, iOMS & 0x0000FFFF, 1);		play_mode=&mac_oms_play_mode;		}		return;#endif	}		if( (select>>16)==mApple )	{		GetMenuItemText(GetMenu(mApple), select&0x0000FFFF, str);		OpenDeskAcc(str);	}}void Do_Quit(){	if( mac_play_mode.fd!=-1 )		mac_play_mode.close_output();	if( mac_quicktime_play_mode.fd!=-1 )		mac_quicktime_play_mode.close_output();#ifdef MAC_USE_OMS	if( mac_oms_play_mode.fd!=-1 )		mac_oms_play_mode.close_output();#endif	if( ctl )		ctl->close();			mac_SetPreference();	#ifdef MAC_USE_OMS	mac_oms_quit();#endif	ExitToShell();}void mac_ErrorExit(Str255 s){	StopAlertMessage(s);	SndDisposeChannel(gSndCannel, 1); gSndCannel=0;	ExitToShell();}/* ****************************** */#pragma mark -void	ShuffleList(int start, int end){	int 	i, newFile;	MidiFile	tmpItem;		for( i=start; i<end; i++){ /*Shuffle target is start..end-1*/		newFile= i+(end-i-1)*((32767+Random())/65535.0);							/*Random() returns between -32767 to 32767*/		tmpItem=fileList[newFile];	/*Swapping*/		fileList[newFile]=fileList[i];		fileList[i]=tmpItem;			//update list window		change_ListRow( i, &fileList[i]);	}}static int isMidiFilename(const char *fn){	char	*p;		p= strrchr(fn, '.'); if( p==0 ) return 0;	if( strcasecmp(p, ".mid")==0 ||		strcasecmp(p, ".rcp")==0 ||		strcasecmp(p, ".r36")==0 ||		strcasecmp(p, ".g18")==0 ||		strcasecmp(p, ".g36")==0 ||		strcasecmp(p, ".kar")==0 ||		strcasecmp(p, ".mod")==0 ||		strcasecmp(p, ".gz")==0		){		return 1;	}else{		return 0;	}}static int isArchiveFilename(const char *fn){	char	*p;		p= strrchr(fn, '.'); if( p==0 ) return 0;	if(	strcasecmp(p, ".lzh")==0 ||		strcasecmp(p, ".zip")==0 ||		strcasecmp(p, ".tar")==0 ||		strcasecmp(p, ".gz")==0		){		return 1;	}else{		return 0;	}}static int isBMPFilename(const char *fn){	char	*p;		p= strrchr(fn, '.'); if( p==0 ) return 0;	if( strcasecmp(p, ".BMP")==0 ){		return 1;	}else{		return 0;	}}static void AddFolderFSSpec2PlayList(const FSSpec *spec){	CInfoPBRec	cipb;	Str32		theString;	OSErr		err = noErr;			BlockMoveData(spec->name, theString, spec->name[0]+1);		cipb.hFileInfo.ioCompletion 	= nil;	cipb.hFileInfo.ioFDirIndex  	= 0;	/* this mean 'use ioNamePtr' */	cipb.hFileInfo.ioDirID			= spec->parID;	cipb.hFileInfo.ioVRefNum 		= spec->vRefNum;	cipb.hFileInfo.ioNamePtr 		= (StringPtr)theString;		if( noErr==PBGetCatInfoSync(&cipb) )		AddFolder2PlayList(spec->vRefNum, cipb.hFileInfo.ioDirID);}static void mac_add_midi_file(const char *fullpath){	if( mac_n_files<LISTSIZE )	//not full	{		fileList[mac_n_files].filename= (char*)safe_malloc(strlen(fullpath)+1);		strcpy(fileList[mac_n_files].filename, fullpath);		if( skin_state==STOP ){ skin_state=WAITING; nPlaying=mac_n_files; }		add_ListWin(&fileList[mac_n_files]);		mac_n_files++;	}}static void mac_add_bmp_file(const char *fullpath){	mac_SkinWindow.message(MW_SKIN_LOAD_BMP, (long)fullpath);}static void mac_add_nonarchive_file(const char *fullpath){	if(isMidiFilename(fullpath)){		mac_add_midi_file(fullpath);	}else if(isBMPFilename(fullpath)){		mac_add_bmp_file(fullpath);	}else if( strtailcasecmp(fullpath, "viscolor.txt")==0 ){		read_viscolor(fullpath);	}}static void mac_add_archive_file(const char *fullpath){		if( mac_n_files<LISTSIZE )	/*not full*/	{		const char  *arc_files[1];		char		**new_files;		int			nfiles=1,i;				//fileList[mac_n_files].filename= (char*)safe_malloc(fullpath[0]+1);		arc_files[0]= fullpath;				new_files = expand_file_archives((char **)arc_files, &nfiles);				for( i=0; i<nfiles; i++ ){			mac_add_nonarchive_file(new_files[i]);					}		if( arc_files!=new_files ) free(new_files);	}}static void mac_add_file(const char *fullpath){	if( isArchiveFilename(fullpath) ){		mac_add_archive_file(fullpath);	}else{		mac_add_nonarchive_file(fullpath);	}}void mac_add_fsspec( FSSpec *spec ){	OSErr	err;	FInfo	fndrInfo;	Boolean	targetIsFolder,wasAliased;		ResolveAliasFile(spec, true, &targetIsFolder, &wasAliased);		err= FSpGetFInfo(spec, &fndrInfo);		if( err ){		if( err==fnfErr ){			AddFolderFSSpec2PlayList(spec); // spec may be directory			return;		}else return;	}		//no error	{ //spec is file, not folder or disk		Str255	fullpath;				GetFullPath(spec, fullpath);		p2cstr(fullpath);				if( fndrInfo.fdType=='Midi' ){			mac_add_midi_file((char*)fullpath);		}else{			mac_add_file((char*)fullpath);		}	}}void	AddHFS2PlayList(HFSFlavor* item){	if( item->fileType=='fold' || item->fileType=='disk')		AddFolderFSSpec2PlayList(&item->fileSpec);	//else if(item->fileType=='Midi'){}	else mac_add_fsspec(&item->fileSpec);}#define kDirFlag (1<<4)OSErr AddFolder2PlayList( short vRefNum, long dirID){	CInfoPBRec	cipb;	Str32		theString;	StringPtr	saveString;	short		saveIndex;	OSErr		err = noErr;			// initialize ourselves	cipb.hFileInfo.ioCompletion 	= nil;	cipb.hFileInfo.ioFDirIndex  	= 1;	cipb.hFileInfo.ioVRefNum 		= vRefNum;	cipb.hFileInfo.ioNamePtr 		= (StringPtr)theString;		while (err == noErr) {				// always reset directory id		cipb.hFileInfo.ioDirID = dirID;		// get the info for the next catalog item		err = PBGetCatInfoSync(&cipb);		if (err) goto exit;				// increment the count		cipb.hFileInfo.ioFDirIndex++;				// if we are a directory, recurse		if (cipb.hFileInfo.ioFlAttrib & kDirFlag) {						// save before recursing			saveIndex = cipb.hFileInfo.ioFDirIndex;			saveString = cipb.hFileInfo.ioNamePtr;			// recurse within the directory			err = AddFolder2PlayList( vRefNum, cipb.hFileInfo.ioDirID );			// restore after recursion			cipb.hFileInfo.ioFDirIndex = saveIndex;			cipb.hFileInfo.ioNamePtr = saveString;					} else {	// we are a file					// call our scanProc if there is one specified			/*if (sp != nil)				err = (*sp)(cipbp, refCon);*/			FSSpec	spec;			if(noErr==FSMakeFSSpec(vRefNum, dirID,						cipb.hFileInfo.ioNamePtr, &spec))				mac_add_fsspec(&spec);						}	}	exit:		// ignore fnfErr and afpAccessDenied errors since fnfErr is what we	// get when there are no more files left to scan, and afpAccessDenied	// can just 幰happen幱 depending on what we are scanning (ie: network	// volumes)	if ((err == fnfErr) || (err == afpAccessDenied)) return noErr;	else return err;}/*******************************************/#pragma mark -

⌨️ 快捷键说明

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