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

📄 mac_main.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 2 页
字号:
/*     TiMidity++ -- MIDI to WAVE converter and player    Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>    Copyright (C) 1995 Tuukka Toivonen <tt@cgs.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	Macintosh interface for TiMidity	by T.Nogami	<t-nogami@happy.email.ne.jp>	    mac_main.c*/#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include	<Sound.h>#include	<stdio.h>#include	<stdlib.h>#include	<string.h>#include	<Threads.h>#include	"timidity.h"#include	"common.h"#include	"instrum.h"#include	"playmidi.h"#include	"readmidi.h"#include	"output.h"#include	"controls.h"#include	"tables.h"#include	"wrd.h"#ifdef SUPPORT_SOUNDSPEC#include "soundspec.h"#endif /* SUPPORT_SOUNDSPEC */#include "recache.h"#include "miditrace.h"#include "aq.h"#include	"mac_main.h"#include	"mac_c.h"#include	"mac_util.h"#ifdef MAC_USE_OMS#include	"OMS.h"#include	"mac_oms.h"#endif#define MAIN_INTERFACE  /* non-static */MAIN_INTERFACE void	timidity_start_initialize(void);MAIN_INTERFACE int	timidity_pre_load_configuration(void);MAIN_INTERFACE int	timidity_post_load_configuration(void);MAIN_INTERFACE void	timidity_init_player(void);MAIN_INTERFACE int	timidity_play_main(int nfiles, char **files);MAIN_INTERFACE int	read_config_file(char *name, int self);MAIN_INTERFACE void	timidity_init_aq_buff(void);extern char *wrdt_open_opts;Boolean	skin_f_repeat, gQuit, gBusy, gShuffle;int		mac_rc, skin_state=WAITING, mac_n_files, nPlaying;long	gStartTick;double	gSilentSec;MidiFile	fileList[LISTSIZE];int		evil_level;int		do_initial_filling;#ifdef __MRC__QDGlobals	qd;#endif/*****************************************//* ************************************************** */static pascal OSErr myHandleOAPP(AppleEvent* /*theAppleEvent*/, AppleEvent* /*reply*/, long /*handlerRefCon*/){	return noErr;}static pascal OSErr myHandleODOC(AppleEvent *theAppleEvent, AppleEvent* /*reply*/, long /*handlerRefCon*/){	int				oldListEnd;	AEDescList		docList;	AEKeyword		keyword;	DescType		returnedType;	FSSpec			theFSSpec;	Size			actualSize;	long			itemsInList;	short			index;	OSErr			err;	KeyMap			keys;	GetKeys(keys);	if( keys[1] & 0x00000004 )		if( mac_SetPlayOption()!=noErr ) return noErr; /* user cancel*/			if ( (err=AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList))!=0 )		return(err);	if ( (err=AECountItems(&docList, &itemsInList))!=0 )		return(err);	oldListEnd=mac_n_files;	for (index = 1; index <= itemsInList; index++) {		if ( (err=AEGetNthPtr(&docList, index, typeFSS, &keyword,								 &returnedType, (Ptr) &theFSSpec, sizeof(FSSpec), &actualSize))!=0 )			return(err);		mac_add_fsspec(&theFSSpec);		//if( isArchiveFile(&theFSSpec) ){		//	mac_add_archive_file(&theFSSpec);		//}else  {		//	mac_add_midi_file(&theFSSpec);		//}	}		if( gShuffle ) ShuffleList( oldListEnd, mac_n_files);	return noErr;}static pascal OSErr myHandleQUIT(AppleEvent* /*theEvent*/, AppleEvent* /*reply*/, long /*refCon*/){	gQuit=true;	return noErr;	/* don't ExitToShell() here, must return noErr */}/*******************************************************/static void InitMenuBar(){	MenuHandle	synth;	SetMenuBar(GetNewMBar(128));	AppendResMenu(GetMenu(128),'DRVR');	synth= GetMenu(mSynth);	InsertMenu(synth, -1); //setup submenu	CheckItem(synth, iTiMidity & 0x0000FFFF, 1);	DrawMenuBar();}static void mac_init(){	long	gestaltResponse;	InitGraf( &qd.thePort );	InitFonts();	FlushEvents( everyEvent,0 );	InitWindows();	InitMenus();	TEInit();	InitDialogs( 0 );	InitCursor();	MaxApplZone();	ReadDateTime( (unsigned long*)&qd.randSeed );		if( !((Gestalt(gestaltSystemVersion, &gestaltResponse)==noErr )			&& gestaltResponse>=0x0750))				mac_ErrorExit("\pThis program can run on System 7.5 or later!");		if ((Gestalt(gestaltDragMgrAttr, &gestaltResponse) == noErr)		&& (gestaltResponse & (1 << gestaltDragMgrPresent)))			gHasDragMgr=true;	else gHasDragMgr=false;	#if (__MC68K__ && __MC68881__)	if (!((Gestalt(gestaltFPUType, &gestaltResponse) == noErr)		&& (gestaltResponse!=gestaltNoFPU )))			mac_ErrorExit("\pSorry, No FPU.");#endif		AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,					NewAEEventHandlerProc(myHandleOAPP), 0, false);	AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,					NewAEEventHandlerProc(myHandleODOC), 0, false);	AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,					NewAEEventHandlerProc(myHandleQUIT), 0, false);		InitMenuBar();}extern char *opt_aq_max_buff,*opt_aq_fill_buff;int  main(){	int32	output_rate=DEFAULT_RATE;	int		err;		mac_init();			nPlaying=mac_n_files=0; skin_state=WAITING;		mac_DefaultOption();	mac_GetPreference();#ifdef MAC_INITIAL_FILLING	if(!opt_aq_max_buff)		opt_aq_max_buff = safe_strdup("0.0");	if(!opt_aq_fill_buff)		opt_aq_fill_buff = safe_strdup("100%");#endif		timidity_start_initialize();	if((err = timidity_pre_load_configuration()) != 0)		return err;	err += timidity_post_load_configuration();	if( err )	{		//ctl->cmsg(CMSG_ERROR, VERB_NORMAL,		//	  "Try %s -h for help", program_name);		return 1; /* problems with command line */	}		timidity_init_player();	wrdt=wrdt_list[0];  //dirty!!	wrdt_open_opts= "m";	timidity_play_main(0, NULL);	 	//CPU won't return from timidity_play_main	return 0;}static pascal void *StartPlay(void *threadParam){	int		rc;			//for( i=0; i<nfiles; i++)	{		skin_state=PLAYING; gBusy=true; DrawButton();		gCursorIsWatch=true; SetCursor(*GetCursor(watchCursor));		DisableItem(GetMenu(mFile), iSaveAs & 0x0000FFFF);		DisableItem(GetMenu(mFile), iPref & 0x0000FFFF);			rc=play_midi_file( fileList[nPlaying].filename );			gStartTick=0;			gBusy=true;			//theCmd.cmd=waitCmd;			//theCmd.param1=2000*gSilentSec;			//SndDoCommand(gSndCannel, &theCmd, 1);		EnableItem(GetMenu(mFile), iSaveAs & 0x0000FFFF);		EnableItem(GetMenu(mFile), iPref & 0x0000FFFF);		skin_state=(rc==RC_QUIT? STOP:WAITING);				if( rc==RC_REALLY_PREVIOUS && nPlaying>0)				nPlaying--;		else if(rc==RC_RESTART)	/*noting*/;		else if(rc==RC_QUIT) /*noting*/;		else if(rc==RC_LOAD_FILE) /*noting*/;		else if(rc==RC_NEXT) nPlaying++;		else if(!skin_f_repeat) nPlaying++;	}	DrawButton();	if( gCursorIsWatch ){		InitCursor();	gCursorIsWatch=false;	}	return 0;}static void HandleNullEvent(){		YieldToAnyThread();		if( Button() ){DoVolume();}	if( skin_state==WAITING && mac_rc==RC_PREVIOUS && nPlaying>0)		{nPlaying--; mac_rc=0; }	if( skin_state==WAITING && nPlaying<mac_n_files )	{		NewThread(kCooperativeThread, StartPlay,		         0, 0, kCreateIfNeeded, 0, 0);	}	#ifdef MAC_USE_OMS	mac_oms_doevent();#endif}void mac_HandleEvent(EventRecord *event){		switch(event->what)	{	case nullEvent:		HandleNullEvent();		break;	case mouseDown:		HandleMouseDown(event);		break;	case keyDown:		if( event->modifiers&cmdKey )		{			mac_HandleMenuSelect(MenuKey(event->message&charCodeMask), event->modifiers);			HiliteMenu(0);			break;		}else{ //no command key			HandleSpecKeydownEvent( event->message, event->modifiers);		}		break;	case updateEvt:		BeginUpdate((WindowRef)event->message);		DoUpdate((WindowRef)event->message);		EndUpdate((WindowRef)event->message);		break;	case kHighLevelEvent:		AEProcessAppleEvent(event);		break;	default:		break;	}	}void mac_HandleControl(){	SndCommand		theCmd;	switch(mac_rc)	{	case RC_QUIT:			if( skin_state==PAUSE )			{				play_mode->acntl(PM_REQ_DISCARD,0);				theCmd.cmd=resumeCmd; SndDoImmediate(gSndCannel, &theCmd);				skin_state=PLAYING;			}		break;/*and wait ctl_read*/	case RC_NEXT:		if( skin_state==STOP )			{ skin_state=WAITING; mac_rc=0; if( nPlaying<mac_n_files ) nPlaying++; }		else if( skin_state==WAITING )			{ skin_state=WAITING; mac_rc=0; if( nPlaying<mac_n_files ) nPlaying++; }		else if( skin_state==PAUSE )			{ mac_rc=RC_CONTINUE; mac_HandleControl(); mac_rc=RC_NEXT;}		break;	case RC_PREVIOUS:		if( skin_state==PAUSE ){ mac_rc=RC_CONTINUE; mac_HandleControl(); mac_rc=RC_PREVIOUS;}		else if( skin_state==STOP ) {skin_state=WAITING; if( nPlaying>0 ) nPlaying--; mac_rc=0; }		else if( skin_state==WAITING  && nPlaying>0)			{nPlaying--; mac_rc=0; }		break;			/*and wait ctl_read*/	case RC_FORWARD:		if( skin_state==STOP ){ skin_state=WAITING; mac_rc=0; }		else if( skin_state==PAUSE ){ mac_rc=RC_CONTINUE; mac_HandleControl(); }		break;			/*and wait ctl_read*/	case RC_TOGGLE_PAUSE:		if( skin_state==PAUSE ){ theCmd.cmd=resumeCmd; SndDoImmediate(gSndCannel, &theCmd); skin_state=PLAYING;}		else if( skin_state==PLAYING ){theCmd.cmd=pauseCmd; SndDoImmediate(gSndCannel, &theCmd); skin_state=PAUSE;}		break;	case RC_RESTART:		break;			/*and wait ctl_read*/	case RC_LOAD_FILE:		if( skin_state==PAUSE )			{ mac_rc=RC_CONTINUE; mac_HandleControl(); mac_rc=RC_LOAD_FILE;}		skin_state=WAITING;		break;	/*case RC_PAUSE:		if( skin_state==PLAYING ){theCmd.cmd=pauseCmd; SndDoImmediate(gSndCannel, &theCmd); skin_state=PAUSE;}		break;*/	/*case RC_CONTINUE:		if( skin_state==PAUSE ){ theCmd.cmd=resumeCmd; SndDoImmediate(gSndCannel, &theCmd); skin_state=PLAYING;}		else if( skin_state==STOP ){ skin_state=WAITING; mac_rc=0; }		break;*/	case RC_REALLY_PREVIOUS:		break;			/*and wait ctl_read*/	}	DrawButton();}/*******************************************/#pragma mark -extern PlayMode wave_play_mode;extern PlayMode aiff_play_mode;extern PlayMode mac_play_mode;extern PlayMode mac_quicktime_play_mode;extern PlayMode mac_oms_play_mode;static pascal void *ConvertToAiffFile(void *threadParam){	OSErr	err;	int		tmp;	char	newfile[256];	StandardFileReply	stdReply;	Str255	fullPath;#ifdef __MWERKS__	_fcreator='TVOD';     //Movie Player	_ftype='AIFF';#endif	StandardGetFile(0, 0, 0, &stdReply);	if (stdReply.sfGood)	{		play_mode=&aiff_play_mode;			if( play_mode->open_output()==-1 ) return 0;			aq_setup();			tmp=skin_state;			skin_state=PLAYING;			err=GetFullPath( &stdReply.sfFile, fullPath);			if( err==noErr )				play_midi_file( p2cstr(fullPath) );			skin_state=tmp;			play_mode->close_output();		play_mode=&mac_play_mode;		aq_setup();		timidity_init_aq_buff();		p2cstrcpy(newfile, stdReply.sfFile.name); strcat(newfile,".aiff");		rename("output.aiff", newfile);	}	DrawButton();	return 0;}static void mac_AboutBox(){	short		item;	DialogRef	dialog, theDialog;	EventRecord	event;		dialog=GetNewDialog(200,0,(WindowRef)-1);

⌨️ 快捷键说明

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