Exemplo n.º 1
0
static void expandFileSongs(HWND playlistWnd, int index, ASAPInfo *info)
{
	const char *fn = (const char *) SendMessage(mod.hMainWindow, WM_WA_IPC, index, IPC_GETPLAYLISTFILE);
	fileinfo fi;
	int song = extractSongNumber(fn, fi.file);
	if (song >= 0)
		return;
	if (ASAPInfo_IsOurFile(fi.file)) {
		if (loadModule(fi.file, module, &module_len)
		 && ASAPInfo_Load(info, fi.file, module, module_len)) {
			SendMessage(playlistWnd, WM_WA_IPC, IPC_PE_DELETEINDEX, index);
			addFileSongs(playlistWnd, &fi, info, &index);
		}
	}
	else if (isATR(fi.file)) {
		FILE *fp = fopen(fi.file, "rb");
		if (fp != NULL) {
			AATR *aatr = AATRStdio_New(fp);
			if (aatr != NULL) {
				size_t atr_fn_len = strlen(fi.file);
				BOOL found = FALSE;
				fi.file[atr_fn_len++] = '#';
				for (;;) {
					const char *inside_fn = AATR_NextFile(aatr);
					if (inside_fn == NULL)
						break;
					if (ASAPInfo_IsOurFile(inside_fn)) {
						module_len = AATR_ReadCurrentFile(aatr, module, sizeof(module));
						if (ASAPInfo_Load(info, inside_fn, module, module_len)) {
							size_t inside_fn_len = strlen(inside_fn);
							if (atr_fn_len + inside_fn_len + 4 <= sizeof(fi.file)) {
								memcpy(fi.file + atr_fn_len, inside_fn, inside_fn_len + 1);
								if (!found) {
									found = TRUE;
									SendMessage(playlistWnd, WM_WA_IPC, IPC_PE_DELETEINDEX, index);
								}
								addFileSongs(playlistWnd, &fi, info, &index);
							}
						}
					}
				}
				AATR_Delete(aatr);
				/* Prevent Winamp crash:
				   1. Play anything.
				   2. Open an ATR with no songs.
				   3. If the ATR deletes itself, Winamp crashes (tested with 5.581).
				   Solution: leave the ATR on playlist. */
				if (!found && SendMessage(mod.hMainWindow, WM_WA_IPC, 0, IPC_GETLISTLENGTH) > 1)
					SendMessage(playlistWnd, WM_WA_IPC, IPC_PE_DELETEINDEX, index);
			}
			fclose(fp);
		}
	}
}
Exemplo n.º 2
0
static void getFileInfo(char *file, char *title, int *length_in_ms)
{
	char filename[MAX_PATH];
	const char *hash;
	if (file == NULL || file[0] == '\0')
		file = playing_filename_with_song;
	title_song = extractSongNumber(file, filename);
	if (title_song < 0)
		expandPlaylistSongs();
	if (!loadModule(filename, module, &module_len))
		return;
	hash = atrFilenameHash(filename);
	if (!ASAPInfo_Load(title_info, hash != NULL ? hash + 1 : filename, module, module_len))
		return;
	if (title_song < 0)
		title_song = ASAPInfo_GetDefaultSong(title_info);
	if (title != NULL) {
		waFormatTitle fmt_title = {
			NULL, NULL, title, 512, tagFunc, tagFreeFunc
		};
		getTitle(title); // in case IPC_FORMAT_TITLE doesn't work...
		SendMessage(mod.hMainWindow, WM_WA_IPC, (WPARAM) &fmt_title, IPC_FORMAT_TITLE);
	}
	if (length_in_ms != NULL)
		*length_in_ms = getSongDuration(title_info, title_song);
}
Exemplo n.º 3
0
	BOOL __cdecl GetInfo(char *filename, int audioDataOffset, TrackInfo *trackInfo)
	{
		BYTE module[ASAPInfo_MAX_MODULE_LENGTH];
		int module_len;
		if (!loadModule(filename, module, &module_len))
			return FALSE;
		ASAPInfo *info = ASAPInfo_New();
		if (info == NULL)
			return FALSE;
		if (!ASAPInfo_Load(info, filename, module, module_len)) {
			ASAPInfo_Delete(info);
			return FALSE;
		}
		strcpy(trackInfo->suggestedTitle, ASAPInfo_GetTitle(info));
		trackInfo->fileSize = module_len;
		trackInfo->seekable = TRUE;
		trackInfo->hasEqualizer = FALSE;
		int duration = getSongDuration(info, ASAPInfo_GetDefaultSong(info));
		trackInfo->playingTime = duration >= 0 ? duration : -1;
		trackInfo->bitRate = 0;
		trackInfo->sampleRate = ASAP_SAMPLE_RATE;
		trackInfo->numChannels = ASAPInfo_GetChannels(info);
		trackInfo->bitResolution = BITS_PER_SAMPLE;
		strcpy(trackInfo->fileTypeDescription, "8-bit Atari music");
		ASAPInfo_Delete(info);
		return TRUE;
	}
Exemplo n.º 4
0
static Tuple *probe_for_tuple(const char *filename, VFSFile *file)
{
	int song = -1;
	unsigned char module[ASAPInfo_MAX_MODULE_LENGTH];
	int module_len;
	ASAPInfo *info = NULL;
	Tuple *tuple = NULL;
	int songs;
	int duration;
	int year;

#if _AUD_PLUGIN_VERSION >= 10
	char *real_filename = filename_split_subtune(filename, &song);
	if (real_filename != NULL)
		filename = real_filename;
#endif
	module_len = load_module(filename, file, module);
	if (module_len > 0) {
		info = ASAPInfo_New();
		if (info != NULL && ASAPInfo_Load(info, filename, module, module_len))
			tuple = tuple_new_from_filename(filename);
	}
#if _AUD_PLUGIN_VERSION >= 10
	g_free(real_filename);
#endif
	if (tuple == NULL) {
		ASAPInfo_Delete(info);
		return NULL;
	}

	tuple_set_nonblank(tuple, FIELD_ARTIST, ASAPInfo_GetAuthor(info));
	tuple_set_nonblank(tuple, FIELD_TITLE, ASAPInfo_GetTitleOrFilename(info));
	tuple_set_nonblank(tuple, FIELD_DATE, ASAPInfo_GetDate(info));
	tuple_set_str(tuple, FIELD_CODEC, NULL, "ASAP");
	songs = ASAPInfo_GetSongs(info);
	if (song > 0) {
		tuple_set_int(tuple, FIELD_SUBSONG_ID, NULL, song);
		tuple_set_int(tuple, FIELD_SUBSONG_NUM, NULL, songs);
		song--;
	}
	else {
		if (songs > 1) {
#if _AUD_PLUGIN_VERSION >= 37
			tuple_set_subtunes(tuple, songs, NULL);
#else
			tuple->nsubtunes = songs;
#endif
		}
		song = ASAPInfo_GetDefaultSong(info);
	}
	duration = ASAPInfo_GetDuration(info, song);
	if (duration > 0)
		tuple_set_int(tuple, FIELD_LENGTH, NULL, duration);
	year = ASAPInfo_GetYear(info);
	if (year > 0)
		tuple_set_int(tuple, FIELD_YEAR, NULL, year);
	ASAPInfo_Delete(info);
	return tuple;
}
Exemplo n.º 5
0
static ASAPInfo *asap_get_info(const char *filename)
{
	ASAPInfo *info;
	if (!asap_load_file(filename))
		return NULL;
	info = ASAPInfo_New();
	if (info == NULL)
		return NULL;
	if (!ASAPInfo_Load(info, filename, module, module_len)) {
		ASAPInfo_Delete(info);
		return NULL;
	}
	return info;
}
Exemplo n.º 6
0
void updateInfoDialog(LPCTSTR filename, int song)
{
	int songs;
	int i;
	if (infoDialog == NULL)
		return;
	if (edited_info == NULL) {
		edited_info = ASAPInfo_New();
		if (astil == NULL)
			astil = ASTIL_New();
		if (edited_info == NULL || astil == NULL) {
			closeInfoDialog();
			return;
		}
	}
	else if (infoChanged())
		return;
	if (!loadModule(filename, saved_module, &saved_module_len)
	 || !ASAPInfo_Load(edited_info, filename, saved_module, saved_module_len)) {
		closeInfoDialog();
		return;
	}
	setSaved();
	can_save = isExt(filename, _T(".sap"));
	invalid_fields = 0;
	SendDlgItemMessage(infoDialog, IDC_FILENAME, WM_SETTEXT, 0, (LPARAM) filename);
	SendDlgItemMessage(infoDialog, IDC_AUTHOR, WM_SETTEXT, 0, (LPARAM) saved_author);
	SendDlgItemMessage(infoDialog, IDC_NAME, WM_SETTEXT, 0, (LPARAM) saved_title);
	SendDlgItemMessage(infoDialog, IDC_DATE, WM_SETTEXT, 0, (LPARAM) saved_date);
	SendDlgItemMessage(infoDialog, IDC_SONGNO, CB_RESETCONTENT, 0, 0);
	songs = ASAPInfo_GetSongs(edited_info);
	EnableWindow(GetDlgItem(infoDialog, IDC_SONGNO), songs > 1);
	for (i = 1; i <= songs; i++) {
		_TCHAR str[16];
		_stprintf(str, _T("%d"), i);
		SendDlgItemMessage(infoDialog, IDC_SONGNO, CB_ADDSTRING, 0, (LPARAM) str);
	}
	if (song < 0)
		song = ASAPInfo_GetDefaultSong(edited_info);
	SendDlgItemMessage(infoDialog, IDC_SONGNO, CB_SETCURSEL, song, 0);
	setEditedSong(song);
	EnableWindow(GetDlgItem(infoDialog, IDC_SAVE), FALSE);
	updateTech();
}
Exemplo n.º 7
0
static gboolean update_song_tuple(const Tuple * tuple, VFSFile *file)
{
#if _AUD_PLUGIN_VERSION < 38
#define vfs_get_filename(file)  g_filename_from_uri(file->uri, NULL, NULL)
#define tuple_get_str  tuple_get_string
#define str_unref(s)
	const char *s;
#else
	char *s;
#endif
	/* read file */
	const char *filename = vfs_get_filename(file);
	unsigned char module[ASAPInfo_MAX_MODULE_LENGTH];
	int module_len = load_module(filename, file, module);
	ASAPInfo *info;
	int year;
	ByteWriter bw;
	gboolean ok;
	if (module_len <= 0)
		return FALSE;
	info = ASAPInfo_New();
	if (info == NULL)
		return FALSE;
	if (!ASAPInfo_Load(info, filename, module, module_len)) {
		ASAPInfo_Delete(info);
		return FALSE;
	}

	/* apply new tags */
	s = tuple_get_str(tuple, FIELD_ARTIST, NULL);
	if (s != NULL) {
		if (!ASAPInfo_SetAuthor(info, s)) {
			str_unref(s);
			ASAPInfo_Delete(info);
			return FALSE;
		}
		str_unref(s);
	}
	else
		ASAPInfo_SetAuthor(info, "");
	s = tuple_get_str(tuple, FIELD_TITLE, NULL);
	if (s != NULL) {
		if (!ASAPInfo_SetTitle(info, s)) {
			str_unref(s);
			ASAPInfo_Delete(info);
			return FALSE;
		}
		str_unref(s);
	}
	else
		ASAPInfo_SetTitle(info, "");
	year = tuple_get_int(tuple, FIELD_YEAR, NULL);
	if (year == 0)
		year = -1;
	/* check if year changed so that we don't lose other date parts */
	if (year != ASAPInfo_GetYear(info)) {
		if (year <= 0)
			ASAPInfo_SetDate(info, "");
		else {
			char d[16];
			sprintf(d, "%d", year);
			ASAPInfo_SetDate(info, d);
		}
	}

	/* write file */
	vfs_rewind(file);
	bw.obj = file;
	bw.func = write_byte;
	ok = ASAPWriter_Write(filename, bw, info, module, module_len, TRUE) && vfs_ftruncate(file, vfs_ftell(file)) == 0;
	ASAPInfo_Delete(info);
	return ok;
}