Tuple *gsf_get_song_tuple(const gchar *filename, VFSFile *file)
{
  char tag[50001];
  char tmp_str[256];
  const gchar *fn;

  Tuple *ti;

  fn = g_filename_from_uri(filename, NULL, NULL);

  ti = tuple_new_from_filename(fn);

  psftag_readfromfile((void*)tag, fn);

  if (!psftag_getvar(tag, "title", tmp_str, sizeof(tmp_str)-1)) {
      tuple_set_str(ti, FIELD_TITLE, NULL, tmp_str);
  }

  if (!psftag_getvar(tag, "artist", tmp_str, sizeof(tmp_str)-1)) {
      tuple_set_str(ti, FIELD_ARTIST, NULL, tmp_str);
  }

  if (!psftag_getvar(tag, "game", tmp_str, sizeof(tmp_str)-1)) {
      tuple_set_str(ti, FIELD_ALBUM, NULL, tmp_str);
  }

  if (!psftag_getvar(tag, "year", tmp_str, sizeof(tmp_str)-1)) {
      tuple_set_str(ti, FIELD_DATE, NULL, tmp_str);
  }

  if (!psftag_getvar(tag, "copyright", tmp_str, sizeof(tmp_str)-1)) {
      tuple_set_str(ti, FIELD_COPYRIGHT, NULL, tmp_str);
  }

  if (!psftag_getvar(tag, "tagger", tmp_str, sizeof(tmp_str)-1)) {
      tuple_set_str(ti, -1, "tagger", tmp_str);
  }

  if (!psftag_raw_getvar(tag, "length", tmp_str, sizeof(tmp_str)-1)) {
      tuple_set_int(ti, FIELD_LENGTH, NULL, LengthFromString(tmp_str) + FadeLength);
  }

  if (!psftag_getvar(tag, "comment", tmp_str, sizeof(tmp_str)-1)) {
      tuple_set_str(ti, FIELD_COMMENT, NULL, tmp_str);
  }

  tuple_set_str(ti, FIELD_CODEC, NULL, "GameBoy Advanced Audio (GSF)");
  tuple_set_str(ti, FIELD_QUALITY, NULL, "sequenced");

  return ti;
}
Exemple #2
0
void getfileinfo(char *filename, char *title, int *length_in_ms)
{
	DWORD dwRead;
	DWORD FileSize;
	DWORD tagstart;
	DWORD taglen;
	DWORD reservesize;
	HANDLE hFile;
	BYTE buffer[256],length[256],fade[256], volume[256];
	BYTE Test[5];
	//char *psftag;

	if (!filename || !*filename) filename=lastfn;
	//if (title) sprintf(title,"%s",filename);

	if(!strcmp(filename,lastfn))
		IsCurrentFile = TRUE;
	else
		IsCurrentFile = FALSE;



	hFile = CreateFile(filename,GENERIC_READ,FILE_SHARE_READ,NULL,
		OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
		NULL);

	if (hFile == INVALID_HANDLE_VALUE) {
		return;
	}

	ReadFile(hFile,Test,4,&dwRead,NULL);
	if (!IsValidGSF(Test)) {
		CloseHandle(hFile);
		return;
	}
	// Read GSF contents
	ReadFile(hFile,&reservesize,4,&dwRead,NULL); // size of reserved area
	ReadFile(hFile,&FileSize,4,&dwRead,NULL); // size of program
	ReadFile(hFile,Test,4,&dwRead,NULL); // CRC (no check yet)
	
	tagstart=SetFilePointer(hFile,0,0,FILE_CURRENT)+FileSize+reservesize;
	SetFilePointer(hFile,tagstart,0,FILE_BEGIN);

	ReadFile(hFile,Test,5,&dwRead,NULL);
	// read tags if there are any
	if (IsTagPresent(Test)) {
		tagstart+=5;
		taglen=SetFilePointer(hFile,0,0,FILE_END)-tagstart;
		SetFilePointer(hFile,tagstart,0,FILE_BEGIN);
		getfileinfopsftag=malloc(taglen+2);
				
		ReadFile(hFile,getfileinfopsftag,taglen,&dwRead,NULL);
		getfileinfopsftag[taglen]='\0';

		psftag_raw_getvar(getfileinfopsftag,"length",length,sizeof(length)-1);
		psftag_raw_getvar(getfileinfopsftag,"fade",fade,sizeof(fade)-1);
		psftag_raw_getvar(getfileinfopsftag,"volume",volume,sizeof(volume)-1);

		if (length_in_ms) *length_in_ms=LengthFromString(length)+LengthFromString(fade);
		//if (IgnoreTrackLength) *length_in_ms=0;

		// create title from PSF tag
		if (title) {
			DWORD c=0,tagnamestart;
			char tempchar;
			sprintf(title,"");
			while (c < strlen(titlefmt)) {
				if (titlefmt[c]=='%') {
					tagnamestart=++c;
					for (;c<strlen(titlefmt) && titlefmt[c] != '%'; c++);
					if (c == strlen(titlefmt)) {
						DisplayError("Bad title format string (unterminated token)");
						return;
					}
					titlefmt[c]='\0';
					if(!strcmp(titlefmt+tagnamestart,"file"))
						GetFile(filename,buffer);
					else
						psftag_raw_getvar(getfileinfopsftag,titlefmt+tagnamestart,buffer,sizeof(buffer)-1);
					strcat(title,buffer);
					titlefmt[c]='%';
				} else {
					tempchar=titlefmt[c+1];
					titlefmt[c+1]='\0';
					strcat(title,titlefmt+c);
					titlefmt[c+1]=tempchar;
				}
				c++;
			}
		}

		free(getfileinfopsftag);
		getfileinfopsftag=NULL;
	}
	else
	{
		if (title)
		{
			GetFile(filename,buffer);
			sprintf(title,"");
			strcat(title,buffer);
		}
	}
	if (*length_in_ms <= 0) *length_in_ms=(deflen+deffade)*1000;
	CloseHandle(hFile);
	if(IsCurrentFile)
	{
		track_length = *length_in_ms;
//		relvolume=VolumeFromString(volume);
//		if(relvolume==0)
//		{
//			relvolume=defvolume;
//		}
	}

}
Exemple #3
0
BOOL CALLBACK infoDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	char Buffer[1024];
	char *LFpsftag;
	//char LFpsftag[50001];
	DWORD c,d;
	IPicture * pPicture;
	HANDLE surpriseImage;
	int randNum;


	switch (uMsg) {	
	case WM_CLOSE:
		if(decode_pos_ms  >= TrackLength-FadeLength)
				TrackLength=decode_pos_ms+FadeLength;
		EndDialog(hDlg,TRUE);
		return 0;
	case WM_INITDIALOG:
		pimpbot = FALSE;
		randNum = rand();
	    SetWindowLong(hDlg, DWL_USER, (LONG)0);
		if (PepperisaGoodBoy)
		{
			pPicture = NULL;
			if (randNum < RAND_MAX*0.025)	//  1/10th a chance of occurring
			{
				pPicture = LoadPic(MAKEINTRESOURCE(IDB_BIGKITTY), "JPG", mod.hDllInstance);
			}
			else if (randNum >= RAND_MAX*0.025 && randNum < RAND_MAX*0.05)
			{
				pPicture = LoadPic(MAKEINTRESOURCE(IDB_PIMPBOT), "JPG", mod.hDllInstance);
				pimpbot = TRUE;
			}
			else if (randNum >= RAND_MAX*0.05 && randNum < RAND_MAX*0.1)
			{
				pPicture = LoadPic(MAKEINTRESOURCE(IDB_PEPPER), "JPG", mod.hDllInstance);
			}
			if (pPicture)
			{
				if (IPicture_getHandle(pPicture, (OLE_HANDLE *)&surpriseImage) == S_OK)
				{
					SendMessage( GetDlgItem(hDlg, IDC_LOGO), STM_SETIMAGE, IMAGE_BITMAP, (long)surpriseImage); //change the logo graphic
					SetWindowLong(hDlg, DWL_USER, (LONG)pPicture);
				}
				else
				{
					IPicture_Release(pPicture);
				}
			}
		}

		if(infoDlgDisableTimer)
		{
			CheckDlgButton(hDlg,IDC_DTIMER,BST_CHECKED);
			playforever=1;
		}
		SetinfoDlgText(hDlg);

		
		break;

	case WM_LBUTTONDOWN:
		if (pimpbot)
		{
			if (rand() > RAND_MAX/2) PlaySound((LPCSTR)IDR_PIMPBOT1, mod.hDllInstance, SND_RESOURCE|SND_ASYNC);
			else PlaySound((LPCSTR)IDR_PIMPBOT2, mod.hDllInstance, SND_RESOURCE|SND_ASYNC);
		}
		break;
		
	case WM_COMMAND:
		switch (GET_WM_COMMAND_ID(wParam, lParam)) {
		case IDOK:
			GetDlgItemText(hDlg,IDC_TITLE,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"title",Buffer);
			
			GetDlgItemText(hDlg,IDC_ARTIST,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"artist",Buffer);
				
			GetDlgItemText(hDlg,IDC_GAME,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"game",Buffer);

			GetDlgItemText(hDlg,IDC_YEAR,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"year",Buffer);
			
			GetDlgItemText(hDlg,IDC_COPYRIGHT,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"copyright",Buffer);

			GetDlgItemText(hDlg,IDC_GSFBY,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"gsfby",Buffer);

			GetDlgItemText(hDlg,IDC_TAGBY,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"tagger",Buffer);

			GetDlgItemText(hDlg,IDC_VOLUME,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"volume",Buffer);

			if(IsCurrentFile&&!SongChanged)
			{
				relvolume=VolumeFromString(Buffer);
				if(relvolume==0)
					relvolume=defvolume;
			}

			GetDlgItemText(hDlg,IDC_LENGTH,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"length",Buffer);

			if(IsCurrentFile&&!SongChanged)
				TrackLength=LengthFromString(Buffer);
			
			GetDlgItemText(hDlg,IDC_FADE,Buffer,1024);
			psftag_raw_setvar(infoDlgpsftag,50000-1,"fade",Buffer);
			if(IsCurrentFile&&!SongChanged)
			{
				FadeLength=LengthFromString(Buffer);
				TrackLength+=FadeLength;
			

				if(TrackLength == 0)
				{
					TrackLength = (deflen + deffade)*1000;
					FadeLength = deffade*1000;
				}
				track_length=TrackLength;
			}



			//mod.GetLength;

			GetDlgItemText(hDlg,IDC_COMMENT,Buffer,1024);

			// remove 0x0d (in PSF a newline is 0x0a)
			for (c=0,d=0; c < strlen(Buffer); c++) {
				if (Buffer[c] != 0x0d) {
					Buffer[d]=Buffer[c];
					d++;
				}
			}
			Buffer[d]='\0';

			psftag_raw_setvar(infoDlgpsftag,50000,"comment",Buffer);

			infoDlgWriteNewTags=1;

		case IDCANCEL:
			if(decode_pos_ms  >= TrackLength-FadeLength)
				TrackLength=decode_pos_ms+FadeLength;
			EndDialog(hDlg, TRUE);
			break;
		case IDC_NOWBUT:
			if(decode_pos_ms != 0)
			{
				sprintf(Buffer,"%i:%02i.%i",getoutputtime()/60000,(getoutputtime()%60000)/1000,getoutputtime()%1000);
				SetDlgItemText(hDlg,IDC_LENGTH,Buffer);
			}
			break;
		case IDC_DTIMER:
			infoDlgDisableTimer=(IsDlgButtonChecked(hDlg, IDC_DTIMER) == BST_CHECKED) ? TRUE : FALSE;
			playforever=infoDlgDisableTimer;
			if(decode_pos_ms  >= TrackLength-FadeLength)
				TrackLength=decode_pos_ms+FadeLength;
			break;

		//case IDC_SECRETBUTTON:
		//	PlaySound((LPCSTR)IDR_WAVE1, mod.hDllInstance, SND_RESOURCE|SND_ASYNC);
		//	surpriseImage = LoadImage(mod.hDllInstance, MAKEINTRESOURCE(IDB_BIGKITTY), IMAGE_BITMAP, 0, 0, 0);		//change the logo graphic
			//SendMessage( GetDlgItem(hDlg, IDC_SECRETBUTTON), STM_SETIMAGE, IMAGE_BITMAP, (long)surpriseImage); //''
		//	SendMessage(GetDlgItem(hDlg,IDC_SECRETBUTTON),BM_SETIMAGE,IMAGE_BITMAP, (long)surpriseImage);
		//	break;
		case IDC_LAUNCHCONFIG:
			DialogBox(mod.hDllInstance, (const char *)IDD_CONFIG, hDlg, configDlgProc);
			break;
		case IDC_VIEWRAW:
			DialogBox(mod.hDllInstance, (const char *)IDD_RAWTAG, hDlg, rawDlgProc);
			SetinfoDlgText(hDlg);
		}
		break;
	case WM_DESTROY:
		pPicture = (IPicture *) GetWindowLong(hDlg, DWL_USER);
		if (pPicture) IPicture_Release(pPicture);
		break;
	default:
		return 0;
	}

	return 1;
}
Exemple #4
0
int main(int argc, char **argv)
{
	int r, tmp, fi, random=0;
	char Buffer[1024];
	char length_str[256], fade_str[256], volume[256], title_str[256];
	char tmp_str[256];
	char *tag;

	soundLowPass = 0;
	soundEcho = 0;
	soundQuality = 0;

	DetectSilence=1;
	silencelength=5;	
	IgnoreTrackLength=0;
	DefaultLength=150000;
	TrailingSilence=1000;
	playforever=0;
	

	while((r=getopt(argc, argv, "hlsrieWL:t:"))>=0)	
	{
		char *e;
		switch(r)
		{
			case 'h':
				printf("playgsf version %s (based on Highly Advanced version %s)\n\n", 
						VERSION_STR, HA_VERSION_STR);
				printf("Usage: ./playgsf [options] files...\n\n");
				printf("  -l        Enable low pass filer\n");
				printf("  -s        Detect silence\n");
				printf("  -L        Set silence length in seconds (for detection). Default 5\n");
				printf("  -t        Set default track length in milliseconds. Default 150000 ms\n");
				printf("  -i        Ignore track length (use default length)\n");
				printf("  -e        Endless play\n");
				printf("  -r        Play files in random order\n");
				printf("  -W        output to 'output.wav' rather than soundcard\n");
				printf("  -h        Displays what you are reading right now\n");
				return 0;
				break;
			case 'i':
				IgnoreTrackLength = 1;
				break;
			case 'l':
				soundLowPass = 1;
				break;
			case 's':
				DetectSilence = 1;
				break;
			case 'L':
				silencelength = strtol(optarg, &e, 0);
				if (e==optarg) {
					fprintf(stderr, "Bad value\n");
					return 1;
				}				
				break;
			case 'e':
				playforever = 1;
				break;
			case 't':
				DefaultLength = strtol(optarg, &e, 0);
				if (e==optarg) {
					fprintf(stderr, "Bad value\n");
					return 1;
				}				
				break;
			case 'r':
				random = 1;				
				break;
			case 'W':
				fileoutput = 1;
				break;
			case '?':
				fprintf(stderr, "Unknown argument. try -h\n");
				return 1;
				break;
		}
	}
	
	if (argc-optind<=0) {
		printf("No files specified! For help, try -h\n");
		return 1;
	}


	if (random) { shuffle_list(&argv[optind], argc-optind); }

	printf("playgsf version %s (based on Highly Advanced version %s)\n\n", 
				VERSION_STR, HA_VERSION_STR);

	signal(SIGINT, signal_handler);

	tag = (char*)malloc(50001);

	fi = optind;
	while (!g_must_exit && fi < argc)
	{
		decode_pos_ms = 0;
		seek_needed = -1;
		TrailingSilence=1000;
		
		r = GSFRun(argv[fi]);
		if (!r) {
			fi++;
			continue;
		}

		g_playing = 1;

		psftag_readfromfile((void*)tag, argv[fi]);
	
		BOLD(); printf("Filename: "); NORMAL();
		printf("%s\n", basename(argv[fi]));
		BOLD(); printf("Channels: "); NORMAL();
		printf("%d\n", sndNumChannels);
		BOLD(); printf("Sample rate: "); NORMAL();
		printf("%d\n", sndSamplesPerSec);
		
		if (!psftag_getvar(tag, "title", title_str, sizeof(title_str)-1)) {
			BOLD(); printf("Title: "); NORMAL();
			printf("%s\n", title_str);
		}
		
		if (!psftag_getvar(tag, "artist", tmp_str, sizeof(tmp_str)-1)) {
			BOLD(); printf("Artist: "); NORMAL();
			printf("%s\n", tmp_str);
		}
		
		if (!psftag_getvar(tag, "game", tmp_str, sizeof(tmp_str)-1)) {
			BOLD(); printf("Game: "); NORMAL();
			printf("%s\n", tmp_str);
		}
		
		if (!psftag_getvar(tag, "year", tmp_str, sizeof(tmp_str)-1)) {
			BOLD(); printf("Year: "); NORMAL();
			printf("%s\n", tmp_str);
		}
		
		if (!psftag_getvar(tag, "copyright", tmp_str, sizeof(tmp_str)-1)) {
			BOLD(); printf("Copyright: "); NORMAL();
			printf("%s\n", tmp_str);
		}
		
		if (!psftag_getvar(tag, "gsfby", tmp_str, sizeof(tmp_str)-1)) {
			BOLD(); printf("GSF By: "); NORMAL();
			printf("%s\n", tmp_str);
		}
		
		if (!psftag_getvar(tag, "tagger", tmp_str, sizeof(tmp_str)-1)) {
			BOLD(); printf("Tagger: "); NORMAL();
			printf("%s\n", tmp_str);
		}
		
		if (!psftag_getvar(tag, "comment", tmp_str, sizeof(tmp_str)-1)) {
			BOLD(); printf("Comment: "); NORMAL();
			printf("%s\n", tmp_str);
		}
		
		if (!psftag_getvar(tag, "fade", fade_str, sizeof(fade_str)-1)) {
			FadeLength = LengthFromString(fade_str);
			BOLD(); printf("Fade: "); NORMAL();
			printf("%s (%d ms)\n", fade_str, FadeLength);
		}
		
		if (!psftag_raw_getvar(tag, "length", length_str, sizeof(length_str)-1)) {
			TrackLength = LengthFromString(length_str) + FadeLength;
			BOLD(); printf("Length: "); NORMAL();
			printf("%s (%d ms) ", length_str, TrackLength);
			if (IgnoreTrackLength) {
				printf("(ignored)");
				TrackLength = DefaultLength;
			}
			printf("\n");
		}
		else {
			TrackLength = DefaultLength;
		}


		/* Must be done after GSFrun so sndNumchannels and 
		 * sndSamplesPerSec are set to valid values */
		ao_initialize();
		ao_sample_format format_ao = {
		  16, sndSamplesPerSec, sndNumChannels, AO_FMT_LITTLE
		};
		if(fileoutput) {
		  snd_ao = ao_open_file(ao_driver_id("wav"),
					"output.wav", 1,
					&format_ao,
					NULL);
		} else {
		  snd_ao = ao_open_live(ao_default_driver_id(),
					&format_ao,
					NULL);
		}
		
		while(g_playing)
		{
			int remaining = TrackLength - (int)decode_pos_ms;
			if (remaining<0) { 
				// this happens during silence period
				remaining = 0;
			}
			EmulationLoop();
		
			BOLD(); printf("Time: "); NORMAL();
			printf("%02d:%02d.%02d ",
					(int)(decode_pos_ms/1000.0)/60,
					(int)(decode_pos_ms/1000.0)%60,
					(int)(decode_pos_ms/10.0)%100);
			if (!playforever) {
				/*BOLD();*/ printf("["); /*NORMAL();*/
				printf("%02d:%02d.%02d",
					remaining/1000/60, (remaining/1000)%60, (remaining/10%100)
						);
				/*BOLD();*/ printf("] of "); /*NORMAL();*/
				printf("%02d:%02d.%02d ", 
					TrackLength/1000/60, (TrackLength/1000)%60, (TrackLength/10%100)); 
			}
			BOLD(); printf("  GBA Cpu: "); NORMAL();
			printf("%02d%% ", cpupercent);
			printf("     \r");
			
			fflush(stdout);
		}
		printf("\n--\n");
		ao_close(snd_ao);
		fi++;
	}

	ao_shutdown();
	return 0;
}