Example #1
0
// this is the function called by the timer
// it loops through all accounts
static gboolean callUpdateInfo()
{
	GList* cur;
	AcctVar* curAcct;
	gboolean isPlaying;
	char* prevInfo;
	char* title;
	char* artist;

	isPlaying = getSong(&title, &artist);

	cur = g_list_first(accounts);

	while(cur != NULL)
	{
		curAcct = (AcctVar*)cur->data;
		prevInfo = updateInfo(curAcct->c, curAcct->prevInfo,
			       title, artist, isPlaying, FALSE);
		g_free(curAcct->prevInfo);
		curAcct->prevInfo = prevInfo;
		cur = cur->next;
	}
	if(isPlaying)
	{
		g_free(title);
		g_free(artist);
	}
	return TRUE;
}
Example #2
0
int main(int argc, char **argv) {
	unsigned timeout = 1, connected = 0;

	parseArguments(argc, argv);
	daemonize();
	registerSignalHandlers();
	termInit();
	atexit(disconnectFromMPD);
	initCodesets();

	do {
		if (!connected) {
			timeout = timeout <= 30 ? timeout * 2 : 60;
			connected = connectToMPD(timeout > 10 ? 10 : timeout);
		}

		if (connected) {
			timeout = 1;
			connected = getSong();
		}

		display(timeout);
	} while (!done());

	return 0;
}
Example #3
0
void CAudioManager::playSong( const char * path, bool loop ) {
  Mix_Music *music = getSong( path );
  if( music ) {
    Mix_PlayMusic( music, loop ? -1 : 0 );
  } else {
    printf( "CAudioManager:: song '%s' not loaded!\n", path );
  }
}
Example #4
0
Mix_Music* CAudioManager::loadSong( const char * path ) {
  Mix_Music *new_music = getSong( path );
  if( !new_music ) {
    new_music = Mix_LoadMUS( path );
    if( !new_music ) {
      printf( "CAudioManager::Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError( ) );
    } else {
      m_songs[ path ] = new_music;
    }
  }
  return new_music;
}
void MusicData::setSong(const skrillex::Song& song)
{
	m_song = song;

	if (!getSong().empty())
		m_tier = Tier_S;

	if (!getArtist().empty())
		m_tier = static_cast<Tier>(m_tier + Tier_A);

	if (!getGenre().empty())
		m_tier = static_cast<Tier>(m_tier + Tier_G);
}
Example #6
0
static void status_changed(PurpleAccount *account, PurpleStatus *old, PurpleStatus *news) 
{
	char *title, *artist, *prevInfo;
	gboolean isPlaying;
	GList* cur;
	AcctVar* curAcct;
	PurpleConnection* pc;

	if(under_recursion)
	{
		return;
	}
		
	pc = purple_account_get_connection(account);

	isPlaying = getSong(&title, &artist);

	cur = g_list_first(accounts);
	prevInfo = NULL;
	curAcct = NULL;
	//find the correct account so we can get the prevInfo
	while(cur != NULL)
	{
		curAcct = (AcctVar*)cur->data;
		if(curAcct->c == pc)
		{
			break;
		}
		cur = cur->next;
	}
	if(cur != NULL)
	{
		prevInfo = updateInfo(pc, curAcct->prevInfo, title, artist, isPlaying, TRUE);
		g_free(curAcct->prevInfo);
		curAcct->prevInfo = prevInfo;
	}
	if(isPlaying)
	{
		g_free(artist);
		g_free(title);
	}
}
Example #7
0
void LocalSong::saveList(const QString &fName)
{
    QString fileName = QString("%1.xml").arg(fName);
    QFile file(fileName);
    if(false==file.open(QIODevice::ReadWrite|QIODevice::Truncate))
        return;
    QXmlStreamWriter writer(&file);
    writer.setAutoFormatting(true);
    writer.writeStartDocument();// 写文档头
    writer.writeStartElement("Local_Music_List");
    for (int i = 0; i < songlist.length(); i++)
    {
        filePath = getSong(i+1);
        writer.writeStartElement("song");
        writer.writeAttribute("ID", QString::number(i+1, 10));
        writer.writeTextElement("path", filePath);
        writer.writeEndElement();
    }
    writer.writeEndElement();
    writer.writeEndDocument();
    qDebug()<<"本地列表保存完成";
    file.close();
}
Example #8
0
Song MpdLibraryDb::getCoverSong(const QString &artistId, const QString &albumId)
{
    DBUG << artistId << albumId;
    if (0!=currentVersion && db) {
        QSqlQuery *query=nullptr;
        if (albumId.isEmpty()) {
            if (!artistImageQuery) {
                artistImageQuery=new QSqlQuery(*db);
                artistImageQuery->prepare("select * from songs where artistId=:artistId limit 1;");
            }
            query=artistImageQuery;
            query->bindValue(":artistId", artistId);
        } else if (artistId.isEmpty()) {
            if (!albumIdOnlyCoverQuery) {
                albumIdOnlyCoverQuery=new QSqlQuery(*db);
                albumIdOnlyCoverQuery->prepare("select * from songs where albumId=:albumId limit 1;");
            }
            query=albumIdOnlyCoverQuery;
            query->bindValue(":albumId", albumId);
        } else {
            if (!coverQuery) {
                coverQuery=new QSqlQuery(*db);
                coverQuery->prepare("select * from songs where artistId=:artistId and albumId=:albumId limit 1;");
            }
            query=coverQuery;
            query->bindValue(":albumId", albumId);
            query->bindValue(":artistId", artistId);
        }
        query->exec();
        DBUG << "coverquery" << query->executedQuery() << query->size();
        while (query->next()) {
            return getSong(*query);
        }
    }
    return Song();
}
Example #9
0
// prepareSong: Receive a song with network
Music* prepareSong(Socket* Client, u32 idx)
{
	// Init resources
	u16 audiotype;
	u64 size;
	Music* songFile = (Music*)malloc(sizeof(Music));
	Packet* pkg = NULL;
	
	// Sending command to client
	char cmd[10];
	sprintf(cmd, "exec1:%i", (idx - 1));
	cmd[9] = 0;
	socketSend(Client, cmd);
	
	// Getting file info
	while (pkg == NULL) pkg = socketRecv(Client, 64);
	Songlist* song = getSong(idx);
	
	u64 fileSize = atoi((char*)pkg->message);
	socketSend(Client, "OK");
	if (song->format == WAV_PCM16){
		
		// Getting and parsing header file
		linearFree(pkg->message);
		free(pkg);
		pkg = NULL;
		while (pkg == NULL) pkg = socketRecv(Client, 256);
		socketSend(Client, "OK");
		u8* header = pkg->message;
		u32 header_size = pkg->size;
		u32 samplerate,jump,chunk=0x00000000;
		strcpy(songFile->author,"");
		strcpy(songFile->title,"");
		songFile->big_endian = false;
		u32 pos = 16;
		while (chunk != 0x61746164){
			memcpy(&jump, &header[pos], 4);
			pos=pos+4+jump;
			memcpy(&chunk, &header[pos], 4);
			pos=pos+4;
	
			//Chunk LIST detection
			if (chunk == 0x5453494C){
				u32 chunk_size;
				u32 subchunk;
				u32 subchunk_size;
				u32 sub_pos = pos+4;
				memcpy(&subchunk, &header[sub_pos], 4);
				if (subchunk == 0x4F464E49){
					sub_pos = sub_pos+4;
					memcpy(&chunk_size, &header[pos], 4);
					while (sub_pos < (chunk_size + pos + 4)){
						memcpy(&subchunk, &header[sub_pos], 4);
						memcpy(&subchunk_size, &header[sub_pos + 4], 4);
						if (subchunk == 0x54524149){
							strncpy(songFile->author, (char*)&header[sub_pos + 8], subchunk_size);
							songFile->author[subchunk_size] = 0;
						}else if (subchunk == 0x4D414E49){
							strncpy(songFile->title, (char*)&header[sub_pos + 8], subchunk_size);
							songFile->title[subchunk_size] = 0;
						}
						sub_pos = sub_pos + 8 + subchunk_size;
						u8 checksum;
						memcpy(&checksum, &header[sub_pos], 1);
						if (checksum == 0) sub_pos++;
					}
				}
			}
		
		}
		memcpy(&audiotype, &header[22], 2);
		memcpy(&samplerate, &header[24], 4);
		memcpy(&(songFile->bytepersample), &header[32], 2);
		u16 raw_enc;
		memcpy(&raw_enc, &header[20], 2);
		songFile->wavebuf = NULL;
		songFile->wavebuf2 = NULL;
		if (raw_enc == 0x01) songFile->encoding = CSND_ENCODING_PCM16;
		else if (raw_enc == 0x11) songFile->encoding = CSND_ENCODING_ADPCM;
		songFile->mem_size = fileSize - header_size;
		songFile->size = songFile->mem_size;
		u32 REAL_STREAM_MAX_ALLOC;
		if (audiotype == 1) REAL_STREAM_MAX_ALLOC = STREAM_MAX_ALLOC;
		else REAL_STREAM_MAX_ALLOC = STREAM_MAX_ALLOC * 10;
		while (songFile->mem_size > REAL_STREAM_MAX_ALLOC){
			if ((songFile->mem_size % 2) == 1) songFile->mem_size++;
			songFile->mem_size = songFile->mem_size / 2;
		}
		if ((songFile->mem_size % 2) == 1) songFile->mem_size++;
		linearFree(pkg->message);
		free(pkg);
		pkg = NULL;
		if (raw_enc == 0x11){ // TODO: ADPCM support
		}else if (raw_enc == 0x01){
			if (audiotype == 1){
				while (pkg == NULL) pkg = socketRecv(Client, 32768);
				u32 processedBytes = 0;
				songFile->audiobuf = (u8*)linearAlloc(songFile->mem_size);
				while (processedBytes < songFile->mem_size  - 52000){
					if (pkg == NULL){
						pkg = socketRecv(Client, 32768);
						continue;
					}
					memcpy(&songFile->audiobuf[processedBytes], pkg->message, pkg->size);
					processedBytes = processedBytes + pkg->size;
					linearFree(pkg->message);
					free(pkg);
					pkg = socketRecv(Client, 32768);
				}
				//svcSleepThread(1000000000);
				processedBytes = 0;
				socketSend(Client, "exec2:0000");
				bool secondBlock = false;
				pkg = NULL;
				while (pkg == NULL) pkg = socketRecv(Client, 32768);
				streamCache = (u8*)linearAlloc(songFile->mem_size);
				while (processedBytes < songFile->mem_size){
					if (pkg == NULL){
						pkg = socketRecv(Client, 32768);
						continue;
					}
					memcpy(&streamCache[processedBytes], pkg->message, pkg->size);
					processedBytes = processedBytes + pkg->size;
					if ((!secondBlock) && (processedBytes >= (songFile->mem_size / 2))){
						socketSend(Client, "exec2:0000");
						secondBlock = true;
					}
					linearFree(pkg->message);
					free(pkg);
					pkg = socketRecv(Client, 32768);
				}
				songFile->audiobuf2 = NULL;
			}
		}
		songFile->samplerate = samplerate;
		songFile->isPlaying = false;
		songFile->encoding = CSND_ENCODING_PCM16;
		linearFree(header);
	}
	
	return songFile;
		/*}else{
			// I must reordinate my buffer in order to play stereo sound (Thanks CSND/FS libraries .-.)
			u32 size_tbp;
			if (mem_size){
				wav_file->moltiplier = 1;
				//wav_file->sourceFile = fileHandle;
				wav_file->isPlaying = false;
				wav_file->startRead = (pos+4);
				wav_file->size = size;
				wav_file->mem_size = (size-(pos+4));
				while (wav_file->mem_size > STREAM_MAX_ALLOC * 10){
					wav_file->mem_size = wav_file->mem_size / 2;
				}
				tmp_buf = (u8*)linearAlloc(wav_file->mem_size);
				wav_file->audiobuf = (u8*)linearAlloc(wav_file->mem_size/2);
				wav_file->audiobuf2 = (u8*)linearAlloc(wav_file->mem_size/2);
				//FSFILE_Read(fileHandle, &bytesRead, wav_file->startRead, tmp_buf, wav_file->mem_size);
				size_tbp = wav_file->mem_size;
			}else{
				tmp_buf = (u8*)linearAlloc((size-(pos+4)));
				size_tbp = size-(pos+4);
				wav_file->startRead = 0;
				wav_file->size = (size_tbp)/2;
				//FSFILE_Read(fileHandle, &bytesRead, pos+4, tmp_buf, size-(pos+4));
			}
			u32 off=0;
			u32 i=0;
			u16 z;
			if (raw_enc == 0x01){ //PCM16 Decoding
				wav_file->audiobuf = (u8*)linearAlloc((size-(pos+4))/2);
				wav_file->audiobuf2 = (u8*)linearAlloc((size-(pos+4))/2);
				while (i < size_tbp){
					z=0;
					while (z < (wav_file->bytepersample/2)){
						wav_file->audiobuf[off+z] = tmp_buf[i+z];
						wav_file->audiobuf2[off+z] = tmp_buf[i+z+(wav_file->bytepersample/2)];
						z++;
					}
					i=i+wav_file->bytepersample;
					off=off+(wav_file->bytepersample/2);
				}
			}else if (raw_enc == 0x11){ //ADPCM Decoding
				u32 headers_num = (size_tbp) / wav_file->bytepersample;
				wav_file->audiobuf = (u8*)linearAlloc((size_tbp-headers_num*8)/2);
				wav_file->audiobuf2 = (u8*)linearAlloc((size_tbp-headers_num*8)/2);
				int z=0,i=0;
				while (i < size_tbp){
					wav_file->audiobuf[z] = tmp_buf[i++];
					wav_file->audiobuf2[z++] = tmp_buf[i+3];
					wav_file->audiobuf[z] = tmp_buf[i++];
					wav_file->audiobuf2[z++] = tmp_buf[i+3];
					wav_file->audiobuf[z] = tmp_buf[i++];
					wav_file->audiobuf2[z++] = tmp_buf[i+3];
					wav_file->audiobuf[z] = tmp_buf[i++];
					wav_file->audiobuf2[z++] = tmp_buf[i+3];
					i=i+4;
					if ((i % wav_file->bytepersample) == 0) i=i+8;
				}
			}
		}
		wav_file->magic = 0x4C534E44;*/
}