コード例 #1
0
Tune AimpTuneController::getTune() const
{
	HANDLE aFile=OpenFileMapping(FILE_MAP_READ, TRUE, AIMP_REMOTE_CLASS);
	PAIMPRemoteFileInfo aInfo = (PAIMPRemoteFileInfo)MapViewOfFile(aFile, FILE_MAP_READ, 0, 0, AIMPRemoteAccessMapFileSize);
	if (aInfo != NULL) {
		wchar_t *str = (wchar_t *)((char*)aInfo + sizeof(*aInfo));
		QString album = QString::fromWCharArray(str, aInfo->AlbumLength);
		str += aInfo->AlbumLength;
		QString artist = QString::fromWCharArray(str, aInfo->ArtistLength);
		str += aInfo->ArtistLength + aInfo->DateLength;
		QString url = QString::fromWCharArray(str, aInfo->FileNameLength);
		str += aInfo->FileNameLength + aInfo->GenreLength;
		QString title = QString::fromWCharArray(str, aInfo->TitleLength);
		unsigned long trackNumber = aInfo->TrackNumber;
		unsigned long time = aInfo->Duration;
		Tune tune = Tune();
		if (!url.isEmpty()) {
			if (!title.isEmpty()) {
				tune.setName(title);
			}
			else {
				int index = url.replace("/", "\\").lastIndexOf("\\");
				if (index > 0) {
					QString filename = url.right(url.length()-index-1);
					index = filename.lastIndexOf(".");
					title = (index > 0) ? filename.left(index) : filename;
				}
				else {
					title = url;
				}
				tune.setName(title);
			}
			if (trackNumber > 0) {
				tune.setTrack(QString::number(trackNumber));
			}
			if (time > 0) {
				tune.setTime((uint)time);
			}
			if (!artist.isEmpty()) {
				tune.setArtist(artist);
			}
			if (!album.isEmpty()) {
				tune.setAlbum(album);
			}
			tune.setURL(url);
		}
		return tune;
	}
	UnmapViewOfFile(aInfo);
	CloseHandle(aFile);
	return Tune();
}
コード例 #2
0
ファイル: tunefactory.cpp プロジェクト: AlexeyProkhin/jreen
	Payload::Ptr TuneFactory::createPayload()
	{
		Tune *tune = new Tune();
		bool ok = true;
		tune->setArtist(m_data[TuneArtist]);
		tune->setLength(m_data[TuneLength].toInt(&ok) * ok + ok - 1);
		tune->setRating(m_data[TuneRating].toInt(&ok) * ok + ok - 1);
		tune->setSource(m_data[TuneSource]);
		tune->setTitle(m_data[TuneTitle]);
		tune->setTrack(m_data[TuneTrack]);
		tune->setUri(QUrl::fromUserInput(m_data[TuneUri]));
		return Payload::Ptr(tune);
	}
コード例 #3
0
ファイル: filetunecontroller.cpp プロジェクト: hummbl/psi
Tune FileTuneController::currentTune()
{
    Tune tune;
    QFile file(songFile_);
    if (file.open(QIODevice::ReadOnly)) {
        QTextStream stream( &file );
        stream.setCodec("UTF-8");
        stream.setAutoDetectUnicode(true);
        tune.setName(stream.readLine());
        tune.setArtist(stream.readLine());
        tune.setAlbum(stream.readLine());
        tune.setTrack(stream.readLine());
        tune.setTime(stream.readLine().toUInt());
    }
    return tune;
}
コード例 #4
0
void ITunesController::iTunesCallback(CFNotificationCenterRef,void* observer,CFStringRef,const void*, CFDictionaryRef info)
{
	Tune tune;
	ITunesController* controller = (ITunesController*) observer;
	
	CFStringRef cf_state = (CFStringRef) CFDictionaryGetValue(info, CFSTR("Player State"));
	if (CFStringCompare(cf_state,CFSTR("Paused"),0) == kCFCompareEqualTo) {
		//qDebug() << "itunesplayer.cpp: Paused";
		emit controller->stopped();
	}
	else if (CFStringCompare(cf_state,CFSTR("Stopped"),0) == kCFCompareEqualTo) {
		//qDebug() << "itunesplayer.cpp: Stopped";
		emit controller->stopped();
	}
	else if (CFStringCompare(cf_state,CFSTR("Playing"),0) == kCFCompareEqualTo) {
		//qDebug() << "itunesplayer.cpp: Playing";
		tune.setArtist(CFStringToQString((CFStringRef) CFDictionaryGetValue(info, CFSTR("Artist"))));
		tune.setName(CFStringToQString((CFStringRef) CFDictionaryGetValue(info, CFSTR("Name"))));
		tune.setAlbum(CFStringToQString((CFStringRef) CFDictionaryGetValue(info, CFSTR("Album"))));
		
		CFNumberRef cf_track = (CFNumberRef) CFDictionaryGetValue(info, CFSTR("Track Number"));
		if (cf_track) {
			int tracknr;
			if (!CFNumberGetValue(cf_track,kCFNumberIntType,&tracknr)) {
				qWarning("itunesplayer.cpp: Number value conversion failed.");
			}
			tune.setTrack(QString::number(tracknr));
		}
		
		CFNumberRef cf_time = (CFNumberRef) CFDictionaryGetValue(info, CFSTR("Total Time"));
		int time = 0;
		if (cf_time && !CFNumberGetValue(cf_time,kCFNumberIntType,&time)) {
			qWarning("itunesplayer.cpp: Number value conversion failed.");
		}
		tune.setTime((unsigned int) (time / 1000));
		controller->currentTune_ = tune;
		emit controller->playing(tune);
	}
	else {
		qWarning("itunesplayer.cpp: Unknown state.");
	}
}