• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ BarUiMsg函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中BarUiMsg函数的典型用法代码示例。如果您正苦于以下问题:C++ BarUiMsg函数的具体用法?C++ BarUiMsg怎么用?C++ BarUiMsg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了BarUiMsg函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: BarMainGetInitialStation

/*	get initial station from autostart setting or user input
 */
static void BarMainGetInitialStation (BarApp_t *app) {
	/* try to get autostart station */
	if (app->settings.autostartStation != NULL) {
		app->curStation = PianoFindStationById (app->ph.stations,
				app->settings.autostartStation);
		if (app->curStation == NULL) {
			BarUiMsg (&app->settings, MSG_ERR,
					"Error: Autostart station not found.\n");
		}
	}
	/* no autostart? ask the user */
	if (app->curStation == NULL) {
		app->curStation = BarUiSelectStation (app, "Select station: ", NULL);
	}
	if (app->curStation != NULL) {
		BarUiPrintStation (&app->settings, app->curStation);
	}
}
开发者ID:SilverTab,项目名称:pianobar,代码行数:20,代码来源:main.c


示例2: BarUiPrintSong

/*	Print song infos (artist, title, album, loved)
 *	@param pianobar settings
 *	@param the song
 *	@param alternative station info (show real station for quickmix, e.g.)
 */
void BarUiPrintSong (const BarSettings_t *settings,
		const PianoSong_t *song, const PianoStation_t *station) {
	char outstr[512];
	const char *vals[] = {song->title, song->artist, song->album,
			(song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "",
			station != NULL ? settings->atIcon : "",
			station != NULL ? station->name : "",
			song->detailUrl};

	BarUiCustomFormat (outstr, sizeof (outstr), settings->npSongFormat,
			"[email protected]", vals);
	BarUiAppendNewline (outstr, sizeof (outstr));
	BarUiMsg (settings, MSG_PLAYING, "%s", outstr);

	BarUiCustomFormat(outstr, sizeof(outstr), settings->titleFormat,
		"[email protected]", vals);
	BarConsoleSetTitle(outstr);
}
开发者ID:nriley,项目名称:pianobar-windows,代码行数:23,代码来源:ui.c


示例3: BarMainStartPlayback

/*	start new player thread
 */
static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) {
	assert (app != NULL);
	assert (playerThread != NULL);

	const PianoSong_t * const curSong = app->playlist;
	assert (curSong != NULL);

	BarUiPrintSong (&app->settings, curSong, app->curStation->isQuickMix ?
			PianoFindStationById (app->ph.stations,
			curSong->stationId) : NULL);

	static const char httpPrefix[] = "http://";
	/* avoid playing local files */
	if (curSong->audioUrl == NULL ||
			strncmp (curSong->audioUrl, httpPrefix, strlen (httpPrefix)) != 0) {
		BarUiMsg (&app->settings, MSG_ERR, "Invalid song url.\n");
	} else {
		/* setup player */
		memset (&app->player, 0, sizeof (app->player));

		app->player.url = curSong->audioUrl;
		app->player.gain = curSong->fileGain;
		app->player.settings = &app->settings;
		app->player.songDuration = curSong->length;
		pthread_mutex_init (&app->player.pauseMutex, NULL);
		pthread_cond_init (&app->player.pauseCond, NULL);

		assert (interrupted == &app->doQuit);
		interrupted = &app->player.interrupted;

		/* throw event */
		BarUiStartEventCmd (&app->settings, "songstart",
				app->curStation, curSong, &app->player, app->ph.stations,
				PIANO_RET_OK, CURLE_OK);

		/* prevent race condition, mode must _not_ be DEAD if
		 * thread has been started */
		app->player.mode = PLAYER_WAITING;
		/* start player */
		pthread_create (playerThread, NULL, BarPlayerThread,
				&app->player);
	}
}
开发者ID:gnowxilef,项目名称:pianobar,代码行数:45,代码来源:main.c


示例4: BarMainStartPlayback

/*	start new player thread
 */
static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) {
	BarUiPrintSong (&app->settings, app->playlist, app->curStation->isQuickMix ?
			PianoFindStationById (app->ph.stations,
			app->playlist->stationId) : NULL);

	if (app->playlist->audioUrl == NULL) {
		BarUiMsg (&app->settings, MSG_ERR, "Invalid song url.\n");
	} else {
		/* setup player */
		memset (&app->player, 0, sizeof (app->player));

		WaitressInit (&app->player.waith);
		WaitressSetUrl (&app->player.waith, app->playlist->audioUrl);

		/* set up global proxy, player is NULLed on songfinish */
		if (app->settings.proxy != NULL) {
			WaitressSetProxy (&app->player.waith, app->settings.proxy);
		}

		app->player.gain = app->playlist->fileGain;
		if ( !app->mute ) {
			app->player.scale = BarPlayerCalcScale (app->player.gain + app->settings.volume);
		}
		app->player.audioFormat = app->playlist->audioFormat;
		app->player.settings = &app->settings;
		pthread_mutex_init (&app->player.pauseMutex, NULL);
		pthread_cond_init (&app->player.pauseCond, NULL);

		/* throw event */
		BarUiStartEventCmd (&app->settings, "songstart",
				app->curStation, app->playlist, &app->player, app->ph.stations,
				PIANO_RET_OK, WAITRESS_RET_OK);

        BarDownloadStart(app);

		/* prevent race condition, mode must _not_ be FREED if
		 * thread has been started */
		app->player.mode = PLAYER_STARTING;
		/* start player */
		pthread_create (playerThread, NULL, BarPlayerThread,
				&app->player);
	}
}
开发者ID:robertkrimen,项目名称:pianobar,代码行数:45,代码来源:main.c


示例5: openDevice

/*	setup libao
 */
static bool openDevice (player_t * const player) {
	AVCodecContext * const cctx = player->st->codec;

	ao_sample_format aoFmt;
	memset (&aoFmt, 0, sizeof (aoFmt));
	aoFmt.bits = av_get_bytes_per_sample (avformat) * 8;
	assert (aoFmt.bits > 0);
	aoFmt.channels = cctx->channels;
	aoFmt.rate = cctx->sample_rate;
	aoFmt.byte_format = AO_FMT_NATIVE;

	int driver = ao_default_driver_id ();
	if ((player->aoDev = ao_open_live (driver, &aoFmt, NULL)) == NULL) {
		BarUiMsg (player->settings, MSG_ERR, "Cannot open audio device.\n");
		return false;
	}

	return true;
}
开发者ID:gnowxilef,项目名称:pianobar,代码行数:21,代码来源:player.c


示例6: _BarFlyTagFetchCover

static int _BarFlyTagFetchCover(uint8_t** cover_art, size_t* cover_size,
		char const* url, BarSettings_t const* settings)
{
	int exit_status = 0;
	int status;
	uint8_t* tmp_cover_art = NULL;
	size_t tmp_cover_size;

	assert(cover_art != NULL);
	assert(cover_size != NULL);
	assert(url != NULL);
	assert(settings != NULL);

	/*
	 * Fetch the cover art.
	 */
	status = _BarFlyFetchURL(url, &tmp_cover_art, &tmp_cover_size, settings);
	if (status != 0) {
		BarUiMsg(settings, MSG_ERR, "Could not get the cover art.\n");
		goto error;
	}

	*cover_art = tmp_cover_art;
	tmp_cover_art = NULL;
	*cover_size = tmp_cover_size;

	goto end;

error:
	exit_status = -1;

end:
	if (tmp_cover_art != NULL) {
		free(tmp_cover_art);
	}

	return exit_status;
}
开发者ID:3scorpionm3x,项目名称:pianobarfly,代码行数:38,代码来源:fly.c


示例7: memset

/*	let user pick one song
 *	@param pianobar settings
 *	@param song list
 *	@param input fds
 *	@return pointer to selected item in song list or NULL
 */
PianoSong_t *BarUiSelectSong (const BarSettings_t *settings,
		PianoSong_t *startSong, BarReadlineFds_t *input) {
	PianoSong_t *tmpSong = NULL;
	char buf[100];

	memset (buf, 0, sizeof (buf));

	do {
		BarUiListSongs (settings, startSong, buf);

		BarUiMsg (settings, MSG_QUESTION, "Select song: ");
		if (BarReadlineStr (buf, sizeof (buf), input, BAR_RL_DEFAULT) == 0) {
			return NULL;
		}

		if (isnumeric (buf)) {
			unsigned long i = strtoul (buf, NULL, 0);
			tmpSong = PianoListGetP (startSong, i);
		}
	} while (tmpSong == NULL);

	return tmpSong;
}
开发者ID:KenMacD,项目名称:pianobar,代码行数:29,代码来源:ui.c


示例8: main

int main (int argc, char **argv) {
	static BarApp_t app;
	/* terminal attributes _before_ we started messing around with ~ECHO */
	struct termios termOrig;
	struct sigaction action;

	memset (&app, 0, sizeof (app));
	memset (&action, 0, sizeof(action));

	/* set the signal handler for SIGINT and SIGTERM */
	action.sa_handler = BarSigQuit;
	sigaction(SIGINT, &action, NULL);
	sigaction(SIGTERM, &action, NULL);

	/* save terminal attributes, before disabling echoing */
	BarTermSave (&termOrig);
	BarTermSetEcho (0);
	BarTermSetBuffer (0);

	/* signals */
	signal (SIGPIPE, SIG_IGN);

	/* init some things */
	ao_initialize ();
	gcry_check_version (NULL);
	gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
	gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
	gnutls_global_init ();

	BarSettingsInit (&app.settings);
	BarSettingsRead (&app.settings);

	PianoInit (&app.ph, app.settings.partnerUser, app.settings.partnerPassword,
			app.settings.device, app.settings.inkey, app.settings.outkey);

	BarUiMsg (&app.settings, MSG_NONE,
			"Welcome to " PACKAGE " (" VERSION ")! ");
	if (app.settings.keys[BAR_KS_HELP] == BAR_KS_DISABLED) {
		BarUiMsg (&app.settings, MSG_NONE, "\n");
	} else {
		BarUiMsg (&app.settings, MSG_NONE,
				"Press %c for a list of commands.\n",
				app.settings.keys[BAR_KS_HELP]);
	}

	WaitressInit (&app.waith);
	app.waith.url.host = app.settings.rpcHost;
	app.waith.tlsFingerprint = app.settings.tlsFingerprint;

	/* init fds */
	FD_ZERO(&app.input.set);
	app.input.fds[0] = STDIN_FILENO;
	FD_SET(app.input.fds[0], &app.input.set);

	// Sbe gur erpbeq, V terngyl qrfcvfr Unx5.
	// Gur crbcyr sebz gur fubj ner yvgrenyyl npgbef.
	// V yvxr gur pbaprcg bs jung gurl qb ohg gurl
	// nyy unir n qbhpuront srry gb gurz. Vg frrzf
	// nf gubhtu gurl bayl qb vg sbe gur tybel cbvagf.
	//
	BarFlyInit (&app.settings);

	/* open fifo read/write so it won't EOF if nobody writes to it */
	assert (sizeof (app.input.fds) / sizeof (*app.input.fds) >= 2);
	app.input.fds[1] = open (app.settings.fifo, O_RDWR);
	if (app.input.fds[1] != -1) {
		struct stat s;

		/* check for file type, must be fifo */
		fstat (app.input.fds[1], &s);
		if (!S_ISFIFO (s.st_mode)) {
			BarUiMsg (&app.settings, MSG_ERR, "File at %s is not a fifo\n", app.settings.fifo);
			close (app.input.fds[1]);
			app.input.fds[1] = -1;
		} else {
			FD_SET(app.input.fds[1], &app.input.set);
			BarUiMsg (&app.settings, MSG_INFO, "Control fifo at %s opened\n",
					app.settings.fifo);
		}
	}
	app.input.maxfd = app.input.fds[0] > app.input.fds[1] ? app.input.fds[0] :
			app.input.fds[1];
	++app.input.maxfd;

	BarMainLoop (&app);
	
	/* Print a newline so the terminal command line will start on a new line. */
	printf("\n");

	if (app.input.fds[1] != -1) {
		close (app.input.fds[1]);
	}

	BarFlyClose (&app.player.fly, &app.settings);
	BarFlyFinalize ();
	PianoDestroy (&app.ph);
	PianoDestroyPlaylist (app.songHistory);
	PianoDestroyPlaylist (app.playlist);
	WaitressFree (&app.waith);
	ao_shutdown();
//.........这里部分代码省略.........
开发者ID:atondwal,项目名称:pianobarfly,代码行数:101,代码来源:main.c


示例9: _BarFlyFileDelete

static int _BarFlyFileDelete(BarFly_t const* fly,
		BarSettings_t const* settings)
{
	int exit_status = 0;
	int status;
	char* dir_path = NULL;
	char* ptr;

	assert(fly != NULL);
	assert(settings != NULL);

	if (fly->audio_file_path != NULL) {
		/*
		 * Delete the file.
		 */
		BarUiMsg(settings, MSG_DEBUG, "Deleting partially recorded file (%s).\n",
				fly->audio_file_path);
		status = unlink(fly->audio_file_path);
		if (status != 0) {
			BarUiMsg(settings, MSG_ERR, "Failed to delete the partially "
					"recorded file (%s).\n", fly->audio_file_path);
			goto error;
		}

		/*
		 * Delete any empty parent directories.
		 */
		dir_path = strdup(fly->audio_file_path);
		if (dir_path == NULL) {
			BarUiMsg(settings, MSG_ERR,
					"Error copying the file path (%s) (%d:%s).\n",
					fly->audio_file_path, errno, strerror(errno));
			goto error;
		}

		ptr = strrchr(dir_path, '/');
		while (ptr != NULL) {
			*ptr = '\0';

			status = rmdir(dir_path);
			if ((status != 0) && (errno != ENOTEMPTY) && (errno != EEXIST)) {
				BarUiMsg(settings, MSG_ERR,
						"Failed to delete the empty artist directory "
						"(%s) (%d:%s).\n", dir_path, errno, strerror);
				goto error;

			}

			ptr = strrchr(dir_path, '/');
		}
	}

	goto end;

error:
	exit_status = -1;

end:
	if (dir_path != NULL) {
		free(dir_path);
	}

	return exit_status;
}
开发者ID:3scorpionm3x,项目名称:pianobarfly,代码行数:64,代码来源:fly.c


示例10: BarStationFromGenre

/*	browse genre stations and create shared station
 *	@param app handle
 */
void BarStationFromGenre (BarApp_t *app) {
	PianoReturn_t pRet;
	WaitressReturn_t wRet;
	PianoGenreCategory_t *curCat;
	PianoGenre_t *curGenre;
	int i;

	/* receive genre stations list if not yet available */
	if (app->ph.genreStations == NULL) {
		BarUiMsg (&app->settings, MSG_INFO, "Receiving genre stations... ");
		if (!BarUiPianoCall (app, PIANO_REQUEST_GET_GENRE_STATIONS, NULL,
				&pRet, &wRet)) {
			return;
		}
	}

	/* print all available categories */
	curCat = app->ph.genreStations;
	i = 0;
	while (curCat != NULL) {
		BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curCat->name);
		i++;
		curCat = curCat->next;
	}

	do {
		/* select category or exit */
		BarUiMsg (&app->settings, MSG_QUESTION, "Select category: ");
		if (BarReadlineInt (&i, &app->input) == 0) {
			return;
		}
		curCat = app->ph.genreStations;
		while (curCat != NULL && i > 0) {
			curCat = curCat->next;
			i--;
		}
	} while (curCat == NULL);
	
	/* print all available stations */
	curGenre = curCat->genres;
	i = 0;
	while (curGenre != NULL) {
		BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curGenre->name);
		i++;
		curGenre = curGenre->next;
	}

	do {
		BarUiMsg (&app->settings, MSG_QUESTION, "Select genre: ");
		if (BarReadlineInt (&i, &app->input) == 0) {
			return;
		}
		curGenre = curCat->genres;
		while (curGenre != NULL && i > 0) {
			curGenre = curGenre->next;
			i--;
		}
	} while (curGenre == NULL);

	/* create station */
	PianoRequestDataCreateStation_t reqData;
	reqData.token = curGenre->musicId;
	reqData.type = PIANO_MUSICTYPE_INVALID;
	BarUiMsg (&app->settings, MSG_INFO, "Adding shared station \"%s\"... ", curGenre->name);
	BarUiPianoCall (app, PIANO_REQUEST_CREATE_STATION, &reqData, &pRet, &wRet);
}
开发者ID:CoreDumpling,项目名称:pianobar,代码行数:69,代码来源:ui.c


示例11: BarUiMsg

/*	let user pick one station
 *	@param app handle
 *	@param stations that should be listed
 *	@param prompt string
 *	@param called if input was not a number
 *	@param auto-select if only one station remains after filtering
 *	@return pointer to selected station or NULL
 */
PianoStation_t *BarUiSelectStation (BarApp_t *app, PianoStation_t *stations,
		const char *prompt, BarUiSelectStationCallback_t callback,
		bool autoselect) {
	PianoStation_t **sortedStations = NULL, *retStation = NULL;
	size_t stationCount, i, lastDisplayed, displayCount;
	char buf[100];

	if (stations == NULL) {
		BarUiMsg (&app->settings, MSG_ERR, "No station available.\n");
		return NULL;
	}

	memset (buf, 0, sizeof (buf));

	/* sort and print stations */
	sortedStations = BarSortedStations (stations, &stationCount,
			app->settings.sortOrder);

	do {
		displayCount = 0;
		for (i = 0; i < stationCount; i++) {
			const PianoStation_t *currStation = sortedStations[i];
			/* filter stations */
			if (BarStrCaseStr (currStation->name, buf) != NULL) {
				BarUiMsg (&app->settings, MSG_LIST, "%2i) %c%c%c %s\n", i,
						currStation->useQuickMix ? 'q' : ' ',
						currStation->isQuickMix ? 'Q' : ' ',
						!currStation->isCreator ? 'S' : ' ',
						currStation->name);
				++displayCount;
				lastDisplayed = i;
			}
		}

		BarUiMsg (&app->settings, MSG_QUESTION, prompt);
		if (autoselect && displayCount == 1 && stationCount != 1) {
			/* auto-select last remaining station */
			BarUiMsg (&app->settings, MSG_NONE, "%i\n", lastDisplayed);
			retStation = sortedStations[lastDisplayed];
		} else {
			if (BarReadlineStr (buf, sizeof (buf), &app->input,
					BAR_RL_DEFAULT) == 0) {
				break;
			}

			if (isnumeric (buf)) {
				unsigned long selected = strtoul (buf, NULL, 0);
				if (selected < stationCount) {
					retStation = sortedStations[selected];
				}
			}

			/* hand over buffer to external function if it was not a station number */
			if (retStation == NULL && callback != NULL) {
				callback (app, buf);
			}
		}
	} while (retStation == NULL);

	free (sortedStations);
	return retStation;
}
开发者ID:CoreDumpling,项目名称:pianobar,代码行数:70,代码来源:ui.c


示例12: BarMainGetLoginCredentials

/*	ask for username/password if none were provided in settings
 */
static bool BarMainGetLoginCredentials (BarSettings_t *settings,
		BarReadlineFds_t *input) {
	bool usernameFromConfig = true;

	if (settings->username == NULL) {
		char nameBuf[100];

		BarUiMsg (settings, MSG_QUESTION, "No User name in config? Email: ");
		BarReadlineStr (nameBuf, sizeof (nameBuf), input, BAR_RL_DEFAULT);
		settings->username = strdup (nameBuf);
		usernameFromConfig = false;
	}

	if (settings->password == NULL) {
		char passBuf[100];

		if (usernameFromConfig) {
			BarUiMsg (settings, MSG_QUESTION, "Got username Email: %s\n", settings->username);
		}

		if (settings->passwordCmd == NULL) {
			BarUiMsg (settings, MSG_QUESTION, "Password: ");
			BarReadlineStr (passBuf, sizeof (passBuf), input, BAR_RL_NOECHO);
			/* write missing newline */
			puts ("");
			settings->password = strdup (passBuf);
		} else {
			pid_t chld;
			int pipeFd[2];

			BarUiMsg (settings, MSG_INFO, "Requesting password from external helper... ");

			if (pipe (pipeFd) == -1) {
				BarUiMsg (settings, MSG_NONE, "Error: %s\n", strerror (errno));
				return false;
			}

			chld = fork ();
			if (chld == 0) {
				/* child */
				close (pipeFd[0]);
				dup2 (pipeFd[1], fileno (stdout));
				execl ("/bin/sh", "/bin/sh", "-c", settings->passwordCmd, (char *) NULL);
				BarUiMsg (settings, MSG_NONE, "Error: %s\n", strerror (errno));
				close (pipeFd[1]);
				exit (1);
			} else if (chld == -1) {
				BarUiMsg (settings, MSG_NONE, "Error: %s\n", strerror (errno));
				return false;
			} else {
				/* parent */
				int status;

				close (pipeFd[1]);
				memset (passBuf, 0, sizeof (passBuf));
				read (pipeFd[0], passBuf, sizeof (passBuf)-1);
				close (pipeFd[0]);

				/* drop trailing newlines */
				ssize_t len = strlen (passBuf)-1;
				while (len >= 0 && passBuf[len] == '\n') {
					passBuf[len] = '\0';
					--len;
				}

				waitpid (chld, &status, 0);
				if (WEXITSTATUS (status) == 0) {
					settings->password = strdup (passBuf);
					BarUiMsg (settings, MSG_NONE, "Ok.\n");
				} else {
					BarUiMsg (settings, MSG_NONE, "Error: Exit status %i.\n", WEXITSTATUS (status));
					return false;
				}
			}
		} /* end else passwordCmd */
	}

	return true;
}
开发者ID:gdudek,项目名称:pianobar,代码行数:81,代码来源:main.c


示例13: main

int main (int argc, char **argv) {
	static BarApp_t app;
	/* terminal attributes _before_ we started messing around with ~ECHO */
	struct termios termOrig;

	memset (&app, 0, sizeof (app));

	/* save terminal attributes, before disabling echoing */
	BarTermSave (&termOrig);
	BarTermSetEcho (0);
	BarTermSetBuffer (0);

	/* signals */
	signal (SIGPIPE, SIG_IGN);

	/* init some things */
	ao_initialize ();
	gcry_check_version (NULL);
	gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
	gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
	gnutls_global_init ();

	BarSettingsInit (&app.settings);
	BarSettingsRead (&app.settings);

	PianoInit (&app.ph, app.settings.partnerUser, app.settings.partnerPassword,
			app.settings.device, app.settings.inkey, app.settings.outkey);

	BarUiMsg (&app.settings, MSG_NONE,
			"Welcome to " PACKAGE " (" VERSION ")! ");
	if (app.settings.keys[BAR_KS_HELP] == BAR_KS_DISABLED) {
		BarUiMsg (&app.settings, MSG_NONE, "\n");
	} else {
		BarUiMsg (&app.settings, MSG_NONE,
				"Press %c for a list of commands.\n",
				app.settings.keys[BAR_KS_HELP]);
	}

	WaitressInit (&app.waith);
	app.waith.url.host = app.settings.rpcHost;
	app.waith.tlsFingerprint = app.settings.tlsFingerprint;

	/* init fds */
	FD_ZERO(&app.input.set);
	app.input.fds[0] = STDIN_FILENO;
	FD_SET(app.input.fds[0], &app.input.set);

	/* open fifo read/write so it won't EOF if nobody writes to it */
	assert (sizeof (app.input.fds) / sizeof (*app.input.fds) >= 2);
	app.input.fds[1] = open (app.settings.fifo, O_RDWR);
	if (app.input.fds[1] != -1) {
		struct stat s;

		/* check for file type, must be fifo */
		fstat (app.input.fds[1], &s);
		if (!S_ISFIFO (s.st_mode)) {
			BarUiMsg (&app.settings, MSG_ERR, "File at %s is not a fifo\n", app.settings.fifo);
			close (app.input.fds[1]);
			app.input.fds[1] = -1;
		} else {
			FD_SET(app.input.fds[1], &app.input.set);
			BarUiMsg (&app.settings, MSG_INFO, "Control fifo at %s opened\n",
					app.settings.fifo);
		}
	}
	app.input.maxfd = app.input.fds[0] > app.input.fds[1] ? app.input.fds[0] :
			app.input.fds[1];
	++app.input.maxfd;

	BarMainLoop (&app);

	if (app.input.fds[1] != -1) {
		close (app.input.fds[1]);
	}

	PianoDestroy (&app.ph);
	PianoDestroyPlaylist (app.songHistory);
	PianoDestroyPlaylist (app.playlist);
	WaitressFree (&app.waith);
	ao_shutdown();
	gnutls_global_deinit ();
	BarSettingsDestroy (&app.settings);

	/* restore terminal attributes, zsh doesn't need this, bash does... */
	BarTermRestore (&termOrig);

	return 0;
}
开发者ID:antonywu,项目名称:pianobar,代码行数:88,代码来源:main.c


示例14: BarPlayerMp3Cb

/*	mp3 playback callback
 */
static WaitressCbReturn_t BarPlayerMp3Cb (void *ptr, size_t size,
		void *stream) {
	const char *data = ptr;
	struct audioPlayer *player = stream;
	size_t i;

	QUIT_PAUSE_CHECK;

	if (!BarPlayerBufferFill (player, data, size)) {
		return WAITRESS_CB_RET_ERR;
	}

	/* some "prebuffering" */
	if (player->mode < PLAYER_RECV_DATA &&
			player->bufferFilled < BAR_PLAYER_BUFSIZE / 2) {
		return WAITRESS_CB_RET_OK;
	}

	mad_stream_buffer (&player->mp3Stream, player->buffer,
			player->bufferFilled);
	player->mp3Stream.error = 0;
	do {
		/* channels * max samples, found in mad.h */
		signed short int madDecoded[2*1152], *madPtr = madDecoded;

		if (mad_frame_decode (&player->mp3Frame, &player->mp3Stream) != 0) {
			if (player->mp3Stream.error != MAD_ERROR_BUFLEN) {
				BarUiMsg (player->settings, MSG_ERR,
						"mp3 decoding error: %s\n",
						mad_stream_errorstr (&player->mp3Stream));
				return WAITRESS_CB_RET_ERR;
			} else {
				/* rebuffering required => exit loop */
				break;
			}
		}
		mad_synth_frame (&player->mp3Synth, &player->mp3Frame);
		for (i = 0; i < player->mp3Synth.pcm.length; i++) {
			/* left channel */
			*(madPtr++) = applyReplayGain (BarPlayerMadToShort (
					player->mp3Synth.pcm.samples[0][i]), player->scale);

			/* right channel */
			*(madPtr++) = applyReplayGain (BarPlayerMadToShort (
					player->mp3Synth.pcm.samples[1][i]), player->scale);
		}
		if (player->mode < PLAYER_AUDIO_INITIALIZED) {
			ao_sample_format format;
			int audioOutDriver;

			player->channels = player->mp3Synth.pcm.channels;
			player->samplerate = player->mp3Synth.pcm.samplerate;
			audioOutDriver = ao_default_driver_id();
			memset (&format, 0, sizeof (format));
			format.bits = 16;
			format.channels = player->channels;
			format.rate = player->samplerate;
			format.byte_format = AO_FMT_NATIVE;
			if ((player->audioOutDevice = ao_open_live (audioOutDriver,
					&format, NULL)) == NULL) {
				player->aoError = 1;
				BarUiMsg (player->settings, MSG_ERR,
						"Cannot open audio device\n");
				return WAITRESS_CB_RET_ERR;
			}

			/* calc song length using the framerate of the first decoded frame */
			player->songDuration = (unsigned long long int) player->waith.request.contentLength /
					((unsigned long long int) player->mp3Frame.header.bitrate /
					(unsigned long long int) BAR_PLAYER_MS_TO_S_FACTOR / 8LL);

			/* must be > PLAYER_SAMPLESIZE_INITIALIZED, otherwise time won't
			 * be visible to user (ugly, but mp3 decoding != aac decoding) */
			player->mode = PLAYER_RECV_DATA;
		}
		/* samples * length * channels */
		ao_play (player->audioOutDevice, (char *) madDecoded,
				player->mp3Synth.pcm.length * 2 * 2);

		/* avoid division by 0 */
		if (player->mode == PLAYER_RECV_DATA) {
			/* same calculation as in aac player; don't need to divide by
			 * channels, length is number of samples for _one_ channel */
			player->songPlayed += (unsigned long long int) player->mp3Synth.pcm.length *
					(unsigned long long int) BAR_PLAYER_MS_TO_S_FACTOR /
					(unsigned long long int) player->samplerate;
		}

		QUIT_PAUSE_CHECK;
	} while (player->mp3Stream.error != MAD_ERROR_BUFLEN);

	player->bufferRead += player->mp3Stream.next_frame - player->buffer;

	BarPlayerBufferMove (player);

	return WAITRESS_CB_RET_OK;
}
开发者ID:atondwal,项目名称:pianobarfly,代码行数:99,代码来源:player.c


示例15: _BarFlyParseTrackDisc

static int _BarFlyParseTrackDisc(char const* title, char const* album_xml,
		short unsigned* track_num, short unsigned* disc_num,
		BarSettings_t const* settings)
{
	size_t const MATCH_COUNT = 3;
	size_t const ERROR_MSG_SIZE = 100;

	int exit_status = 0;
	int status;
	char* regex_string = NULL;
	regex_t regex_track;
	regmatch_t match[MATCH_COUNT];
	char error_msg[ERROR_MSG_SIZE];
	char regex_title[BAR_FLY_NAME_LENGTH];
	int index;
	int index2;
	short unsigned track;
	short unsigned disc;

	assert(title != NULL);
	assert(album_xml != NULL);
	assert(track_num != NULL);
	assert(disc_num != NULL);
	assert(settings != NULL);

	memset(&regex_track, 0, sizeof(regex_track));

	/*
	 * Create the regular expression string.
	 * 
	 * The title needs to have all potential regular expresion metacharacters
	 * fixed.  The real correct way to do this would be to escape all of them
	 * with '\'.  But the easy way to it is simply replace them with '.'.
	 *
	 * Additionally Pandora excludes some characters from the titles in the
	 * xml page.  These characters are ignored.
	 */
	index2 = 0;
	for (index = 0; title[index] != '\0'; index++) {
		if (title[index] == '^' ||
			title[index] == '$' ||
			title[index] == '(' ||
			title[index] == ')' ||
			title[index] == '>' ||
			title[index] == '<' ||
			title[index] == '[' ||
			title[index] == '{' ||
			title[index] == '\\' ||
			title[index] == '|' ||
			title[index] == '.' ||
			title[index] == '*' ||
			title[index] == '+' ||
			title[index] == '&') {
			regex_title[index2] = '.';
			index2++;
		} else if (title[index] == '?' ) {
			/*
			 * Skip these characters.
			 */
		} else {
			regex_title[index2] = title[index];
			index2++;
		}
	}
	regex_title[index2] = '\0';

	status = BarFlyasprintf(&regex_string,
			"songTitle *= *\"%s\"[^>]+"
			"discNum *= *\"([0-9]+)\"[^>]+"
			"trackNum *= *\"([0-9]+)\"", regex_title);
	if (status == -1) {
		BarUiMsg(settings, MSG_ERR, "Failed to create the regex string to get "
				"the track and disc numbers (%d:%s).\n", errno,
				strerror(errno));
		goto error;
	}

	/*
	 * Compile and execute the regular expression to get the track and disc
	 * numbers.
	 */
	status = regcomp(&regex_track, regex_string, REG_EXTENDED);
	if (status != 0) {
		regerror(status, &regex_track, error_msg, ERROR_MSG_SIZE);
		BarUiMsg(settings, MSG_ERR, "Failed to compile the regex to get the "
				"track and disc numbers (%d:%s).\n", status, error_msg);
		goto error;
	}

	memset(match, 0, sizeof(match));
	status = regexec(&regex_track, album_xml, MATCH_COUNT, match, 0);
	if (status != 0) {
		regerror(status, &regex_track, error_msg, ERROR_MSG_SIZE);
		BarUiMsg(settings, MSG_DEBUG, "The track and disc numbers were not "
				"included in the album explorer page (%d:%s).\n", status,
				error_msg);
		goto error;
	}

	/*
//.........这里部分代码省略.........
开发者ID:3scorpionm3x,项目名称:pianobarfly,代码行数:101,代码来源:fly.c


示例16: _BarFlyParseCoverArtURL

static char* _BarFlyParseCoverArtURL(char const* html,
		BarSettings_t const* settings)
{
	size_t const MATCH_COUNT = 2;
	size_t const ERROR_MSG_SIZE = 100;

	char* url = NULL;
	int status;
	regex_t regex_cover;
	regmatch_t cover_match[MATCH_COUNT];
	char error_msg[ERROR_MSG_SIZE];

	assert(html != NULL);

	/*
	 * Search the html page to find the cover art URL.
	 */
	memset(&regex_cover, 0, sizeof(regex_cover));
	status = regcomp(&regex_cover,
			"src *= *\"([^\"]+)\"[^>]*class *= *\"img_cvr\"", REG_EXTENDED);
	if (status != 0) {
		regerror(status, &regex_cover, error_msg, ERROR_MSG_SIZE);
		BarUiMsg(settings, MSG_ERR, "Failed to compile the cover at regex "
				"(%d:%s).\n", status, error_msg);
		goto error;
	}

	memset(cover_match, 0, sizeof(cover_match));
	status = regexec(&regex_cover, html, MATCH_COUNT, cover_match, 0);
	if (status != 0) {
		regerror(status, &regex_cover, error_msg, ERROR_MSG_SIZE);
		BarUiMsg(settings, MSG_DEBUG, "The cover art was not included in the "
				"album detail page (%d:%s).\n", status, error_msg);
		goto error;
	}

	/*
	 * Extract the cover art URL.
	 */
	url = strndup(html + cover_match[1].rm_so,
			cover_match[1].rm_eo - cover_match[1].rm_so);
	if (url == NULL) {
		BarUiMsg(settings, MSG_ERR, "Failed to copy the cover art url "
				"(%d:%s).\n", errno, strerror(errno));
		goto error;
	}

	/*
	 * Make sure this isn't the no_album_art.jpg image.  This check must be
	 * done to only the URL itself and not the whole HTML page since the similar
	 * albums list could also use this image.
	 */
	if (strstr(url, "no_album_art.jpg") != NULL) {
		BarUiMsg(settings, MSG_DEBUG, "This album does not have cover art.\n");
		goto error;
	}

	goto end;

error:
	if (url != NULL) {
		free(url);
		url = NULL;
	}

end:
	regfree(&regex_cover);

	return url;
}
开发者ID:3scorpionm3x,项目名称:pianobarfly,代码行数:70,代码来源:fly.c


示例17: _BarFlyFileOpen

static int _BarFlyFileOpen(FILE** file, char const* path,
		BarSettings_t const* settings)
{
	FILE *tmp_file = NULL;
	int exit_status = 0;
	int status;
	char* dir_path = NULL;
	char* ptr;

	assert(file != NULL);
	assert(path != NULL);
	assert(settings != NULL);

	/*
	 * Create any parent directories.
	 */
	ptr = strchr(path, '/');
	while (ptr != NULL) {
		status = BarFlyasprintf(&dir_path, "%.*s", (int)(ptr - path), path);
		if (status == -1) {
			BarUiMsg(settings, MSG_ERR, "Error copying the directory path of "
					"the audio file (%d:%s).\n", errno, strerror(errno));
			exit_status = -1;
			goto error;
		}

		status = mkdir(dir_path, 0755);
		if ((status == -1) && (errno != EEXIST)) {
			BarUiMsg(settings, MSG_ERR, "Error creating a parent directory of "
					"the audio file (%s) (%d:%s).\n", errno, strerror(errno));
			exit_status = -1;
			goto error;
		}

		free(dir_path);
		dir_path = NULL;
		ptr = strchr(ptr + 1, '/');
	}

	/*
	 * Open the audio file for writing.
	 */
	tmp_file = _BarFlyFileOpenStream(path, "wb");
	if ((tmp_file == NULL) && (errno == EEXIST)) {
		BarUiMsg(settings, MSG_DEBUG, "The audio file already exists. It will "
				"not be recorded (%s).\n", path);
		exit_status = -2;
		goto error;
	} else if (tmp_file == NULL) {
		BarUiMsg(settings, MSG_ERR, "Error opening the audio file for reading "
				"(%s) (%d:%s).\n", path, errno, strerror(errno));
		exit_status = -1;
		goto error;
	}

	*file = tmp_file;
	tmp_file = NULL;

	goto end;

error:
end:
	if (dir_path != NULL) {
		free(dir_path);
	}

	if (tmp_file != NULL) {
		fclose(tmp_file);
	}

	return exit_status;
}
开发者ID:3scorpionm3x,项目名称:pianobarfly,代码行数:72,代码来源:fly.c


示例18: _BarFlyFileGetPath

static char* _BarFlyFileGetPath(char const* artist, char const* album,
		char const* title, short unsigned year, short unsigned track,
		short unsigned disc, PianoAudioFormat_t audio_format,
		BarSettings_t const* settings)
{
	char* path = NULL;
	size_t path_length;
	char path_artist[BAR_FLY_NAME_LENGTH];
	char path_album[BAR_FLY_NAME_LENGTH];
	char path_title[BAR_FLY_NAME_LENGTH];
	char const* extension;
	char const* file_pattern_ptr;
	size_t count;
	char* path_ptr;

	assert(artist != NULL);
	assert(album != NULL);
	assert(title != NULL);
	assert(settings != NULL);

	/*
	 * Get the artist, album, and title.  Translate each of the characters
	 * we don't want to _.
	 */
	_BarFlyNameTranslate(path_artist, artist, BAR_FLY_NAME_LENGTH, settings);
	_BarFlyNameTranslate(path_album, album, BAR_FLY_NAME_LENGTH, settings);
	_BarFlyNameTranslate(path_title, title, BAR_FLY_NAME_LENGTH, settings);

	/*
	 * Get the extension.
	 */
	switch (audio_format) {
		#ifdef ENABLE_FAAD
		case PIANO_AF_AACPLUS:
			extension = ".m4a";
			break;
		#endif

		#ifdef ENABLE_MAD
		case PIANO_AF_MP3:
		case PIANO_AF_MP3_HI:
			extension = ".mp3";
			break;
		#endif

		default:
			BarUiMsg(settings, MSG_ERR, "Unsupported audio format!\n");
			goto error;
			break;
	}

	/*
	 * Calculate the length of the path.
	 */
	path_length = 0;
	file_pattern_ptr = settings->audioFileName;
	while (*file_pattern_ptr != '\0') {
		/*
		 * Get the length of everything up to the next '%'.
		 */
		count = strcspn(file_pattern_ptr, "%");
		path_length += count;
		file_pattern_ptr += count;

		/*
		 * Get the length of each substitution.  The track is always at least
		 * 2 digits.
		 */
		if (*file_pattern_ptr != '\0') {
			if (strncmp("%artist", file_pattern_ptr, 7) == 0) {
				path_length += strlen(path_artist);
				file_pattern_ptr += 7;
			} else if (strncmp("%album", file_pattern_ptr, 6) == 0) {
				path_length += strlen(path_album);
				file_pattern_ptr += 6;
			} else if (strncmp("%title", file_pattern_ptr, 6) == 0) {
				path_length += strlen(path_title);
				file_pattern_ptr += 6;
			} else if (strncmp("%year", file_pattern_ptr, 5) == 0) {
				path_length += snprintf(NULL, 0, "%hu", year);
				file_pattern_ptr += 5;
			} else if (strncmp("%track", file_pattern_ptr, 6) == 0) {
				path_length += snprintf(NULL, 0, "%02hu", track);
				file_pattern_ptr += 6;
			} else if (strncmp("%disc", file_pattern_ptr, 5) == 0) {
				path_length += snprintf(NULL, 0, "%hu", disc);
				file_pattern_ptr += 5;
			} else {
				file_pattern_ptr += 1;
			}
		}
	}
	path_length += strlen(extension);

	/*
	 * Allocate space for the path.
	 */
	path = malloc(path_length + 1);
	if (path == NULL) {
		BarUiMsg(settings, MSG_ERR,
//.........这里部分代码省略.........
开发者ID:3scorpionm3x,项目名称:pianobarfly,代码行数:101,代码来源:fly.c


示例19: BarPlayerAACCb

/*	play aac stream
 *	@param streamed data
 *	@param received bytes
 *	@param extra data (player data)
 *	@return received bytes or less on error
 */
static WaitressCbReturn_t BarPlayerAACCb (void *ptr, size_t size,
		void *stream) {
	const char *data = ptr;
	struct audioPlayer *player = stream;

	QUIT_PAUSE_CHECK;

	if (!BarPlayerBufferFill (player, data, size)) {
		return WAITRESS_CB_RET_ERR;
	}

	if (player->mode == PLAYER_RECV_DATA) {
		short int *aacDecoded;
		NeAACDecFrameInfo frameInfo;
		size_t i;

		while ((player->bufferFilled - player->bufferRead) >
				player->sampleSize[player->sampleSizeCurr]) {
			/* decode frame */
			aacDecoded = NeAACDecDecode(player->aacHandle, &frameInfo,
					player->buffer + player->bufferRead,
					player->sampleSize[player->sampleSizeCurr]);
			if (frameInfo.error != 0) {
				BarUiMsg (player->settings, MSG_ERR, "Decoding error: %s\n",
						NeAACDecGetErrorMessage (frameInfo.error));
				break;
			}
			for (i = 0; i < frameInfo.samples; i++) {
				aacDecoded[i] = applyReplayGain (aacDecoded[i], player->scale);
			}
			/* ao_play needs bytes: 1 sample = 16 bits = 2 bytes */
			ao_play (player->audioOutDevice, (char *) aacDecoded,
					frameInfo.samples * 2);
			/* add played frame length to played time, explained below */
			player->songPlayed += (unsigned long long int) frameInfo.samples *
					(unsigned long long int) BAR_PLAYER_MS_TO_S_FACTOR /
					(unsigned long long int) player->samplerate /
					(unsigned long long int) player->channels;
			player->bufferRead += frameInfo.bytesconsumed;
			player->sampleSizeCurr++;
			/* going through this loop can take up to a few seconds =>
			 * allow earlier thread abort */
			QUIT_PAUSE_CHECK;
		}
	} else {
		if (player->mode == PLAYER_INITIALIZED) {
			while (player->bufferRead+4 < player->bufferFilled) {
				if (memcmp (player->buffer + player->bufferRead, "esds",
						4) == 0) {
					player->mode = PLAYER_FOUND_ESDS;
					player->bufferRead += 4;
					break;
				}
				player->bufferRead++;
			}
		}
		if (player->mode == PLAYER_FOUND_ESDS) {
			/* FIXME: is this the correct way? */
			/* we're gonna read 10 bytes */
			while (player->bufferRead+1+4+5 < player->bufferFilled) {
				if (memcmp (player->buffer + player->bufferRead,
						"\x05\x80\x80\x80", 4) == 0) {
					ao_sample_format format;
					int audioOutDriver;

					/* +1+4 needs to be replaced by <something>! */
					player->bufferRead += 1+4;
					char err = NeAACDecInit2 (player->aacHandle, player->buffer +
							player->bufferRead, 5, &player->samplerate,
							&player->channels);
					player->bufferRead += 5;
					if (err != 0) {
						BarUiMsg (player->settings, MSG_ERR,
								"Error while initializing audio decoder "
								"(%i)\n", err);
						return WAITRESS_CB_RET_ERR;
					}
					audioOutDriver = ao_default_driver_id();
					memset (&format, 0, sizeof (format));
					format.bits = 16;
					format.channels = player->channels;
					format.rate = player->samplerate;
					format.byte_format = AO_FMT_NATIVE;
					if ((player->audioOutDevice = ao_open_live (audioOutDriver,
							&format, NULL)) == NULL) {
						/* we're not interested in the errno */
						player->aoError = 1;
						BarUiMsg (player->settings, MSG_ERR,
								"Cannot open audio device\n");
						return WAITRESS_CB_RET_ERR;
					}
					player->mode = PLAYER_AUDIO_INITIALIZED;
					break;
				}
//.........这里部分代码省略.........
开发者ID:atondwal,项目名称:pianobarfly,代码行数:101,代码来源:player.c


示例20: printError

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Base函数代码示例发布时间:2022-05-30
下一篇:
C++ Bar函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap