void TemplateActor::createStringOfSimilarArtists() { if (this->similarArtistsStringCreationInProgress == true) { return; } this->similarArtistsStringCreationInProgress = true; this->similarArtistsStringVector.clear(); this->theTemplateAction->removeImage(); this->similarArtistsCurrentTrackIdentifier = VisualDataStore::getIdentifierOfCurrentTrack(); VisualString* normalizedArtistNameForURLConstruction = VisualNetwork::createNormalizedURLString(VisualDataStore::getArtistOfCurrentTrack()); if (!normalizedArtistNameForURLConstruction) { return; } VisualString similarArtistsURL; similarArtistsURL.initWithUTF8String("http://ws.audioscrobbler.com/1.0/artist/"); similarArtistsURL = (similarArtistsURL + *normalizedArtistNameForURLConstruction); delete normalizedArtistNameForURLConstruction; similarArtistsURL = (similarArtistsURL + "/similar.txt"); if (this->stringOfSimilarArtists != NULL) { delete this->stringOfSimilarArtists; } this->stringOfSimilarArtists = VisualString::createWithContentsOfURL(similarArtistsURL.getUtf8Representation(), this->similarArtistsStringRequestId); this->similarArtistsStringCreationInProgress = false; }
void TemplateActor::handleSimilarArtistsStringCompleted() { if (this->stringOfSimilarArtists == NULL) return; VisualItemIdentifier currTrackIdentifier = VisualDataStore::getIdentifierOfCurrentTrack(); if (currTrackIdentifier != this->similarArtistsCurrentTrackIdentifier) { return; } uint32 numberOfLines = this->stringOfSimilarArtists->getNumberOfLines(); for (uint32 i = 0; i < numberOfLines; i++) { VisualString* visualString = this->stringOfSimilarArtists->createStringWithLine(i); if (visualString) { std::vector<VisualString> stringVector = visualString->splitWithDelimiter(","); if (stringVector.size() > 2) { this->similarArtistsStringVector.push_back(stringVector[2]); } delete visualString; } } VisualString* joinedString = VisualString::createJoinedString(this->similarArtistsStringVector); if (joinedString != NULL) { this->setStringOfSimilarArtists(*joinedString); delete joinedString; } }
void TrackLyricsActor::handleNotification(const VisualNotification& aNotification) { //VisualActor::handleNotification(aNotification); // debug VisualString trackLyricsStr; const VisualString missingValueString("missing value"); // "missing value" is literally sent with streams that do not convey any lyrics VisualNotificationKey notificationKey = aNotification.getKey(); switch (notificationKey) { case kAudioMetadataIsAvailableMsg: VisualDataStore::createLyricsOfCurrentTrack(); break; case kLyricsAreAvailableMsg: trackLyricsStr = VisualDataStore::getLyricsOfCurrentTrack(); if (trackLyricsStr.getNumberOfNonWhitespaceCharacters() > 0 && trackLyricsStr != missingValueString) { OSStatus status = this->trackLyrics->makeTextureOfTrackLyrics(trackLyricsStr); if (status == noErr) { this->trackLyrics->calcPositionOnScreen(); VisualNotification::post(kLyricsTextureIsAvailableMsg); } } break; case kLyricsTextureIsAvailableMsg: this->textureOfCurrentTrackLyricsIsAvailable = true; this->trackLyrics->fadeIn(VisualDataStore::getPreferenceValueInt(VisualConfiguration::kFadeInTimeOnPlayInMS)); break; case kAudioPlayStartedEvt: this->trackLyrics->clear(); this->textureOfCurrentTrackLyricsIsAvailable = false; break; case kAudioPlayStoppedEvt: this->trackLyrics->clear(); this->textureOfCurrentTrackLyricsIsAvailable = false; break; case kAudioPlayPausedEvt: this->trackLyrics->fadeOut(VisualDataStore::getPreferenceValueInt(VisualConfiguration::kFadeOutTimeOnPauseInMS), 0.15f); break; case kAudioPlayResumedEvt: this->trackLyrics->fadeIn(VisualDataStore::getPreferenceValueInt(VisualConfiguration::kFadeInTimeOnResumeInMS)); break; case kAudioPlayReachedFadeOutTimeBeforeEndOfTrackEvt: this->trackLyrics->fadeOut(VisualDataStore::getPreferenceValueInt(VisualConfiguration::kFadeOutTimeBeforeEndOfTrackInMS)); break; case kCanvasReshapeEvt: if (textureOfCurrentTrackLyricsIsAvailable == true) { this->trackLyrics->calcPositionOnScreen(); } break; case kTrackInfoTextureChangedMsg: if (textureOfCurrentTrackLyricsIsAvailable == true) { this->trackLyrics->calcPositionOnScreen(); } break; default: writeLog("unhandled Notification in TrackLyricsActor"); break; } }
void logString(void* aVisualString) { if (!doLogString) { initCocoaBundle(); } VisualString* aString = reinterpret_cast<VisualString*>(aVisualString); CFStringRef aCFStringRef = aString->getCharactersPointer(); doLogString(aCFStringRef); }
void TrackTitleActor::handleNotification(const VisualNotification& aNotification) { //VisualActor::handleNotification(aNotification); // debug VisualNotificationKey notificationKey = aNotification.getKey(); switch (notificationKey) { case kAudioMetadataIsAvailableMsg: { const VisualString trackName = VisualDataStore::getNameOfCurrentTrack(); if (trackName.getNumberOfNonWhitespaceCharacters() > 0) { OSStatus status = this->trackTitle->makeTextureOfTrackTitle(trackName); if (status == noErr) { this->trackTitle->calcPositionOnScreen(); VisualDataStore::setValueInt(VisualConfiguration::kTrackInfoTextureHeight, this->trackTitle->getTrackInfoTextureHeightInPixels()); VisualNotification::post(kTrackInfoTextureIsAvailableMsg); } else { VisualDataStore::setValueInt(VisualConfiguration::kTrackInfoTextureHeight, 0); } VisualNotification::post(kTrackInfoTextureChangedMsg); } } break; case kTrackInfoTextureIsAvailableMsg: this->textureOfCurrentTrackTitleIsAvailable = true; this->trackTitle->fadeIn(VisualDataStore::getPreferenceValueInt(VisualConfiguration::kFadeInTimeOnPlayInMS)); break; case kAudioPlayStartedEvt: this->trackTitle->clear(); this->textureOfCurrentTrackTitleIsAvailable = false; break; case kAudioPlayStoppedEvt: this->trackTitle->clear(); this->textureOfCurrentTrackTitleIsAvailable = false; break; case kAudioPlayPausedEvt: this->trackTitle->pulsate(); break; case kAudioPlayResumedEvt: this->trackTitle->fadeIn(VisualDataStore::getPreferenceValueInt(VisualConfiguration::kFadeInTimeOnResumeInMS)); break; case kAudioPlayReachedFadeOutTimeBeforeEndOfTrackEvt: this->trackTitle->fadeOut(VisualDataStore::getPreferenceValueInt(VisualConfiguration::kFadeOutTimeBeforeEndOfTrackInMS)); break; case kCanvasReshapeEvt: this->trackTitle->calcPositionOnScreen(); VisualDataStore::setValueInt(VisualConfiguration::kTrackInfoTextureHeight, this->trackTitle->getTrackInfoTextureHeightInPixels()); break; default: writeLog("unhandled Notification in TrackTitleActor"); break; } }
OSStatus VisualTextureContainer::initWithURL(VisualString& anURL) { this->releaseTextureData(); if (this->pixelBuffer != NULL) { free(this->pixelBuffer); this->pixelBuffer = NULL; } OSStatus osStatus = noErr; CFURLRef imageURL = CFURLCreateWithString(kCFAllocatorDefault, anURL.getCharactersPointer(), NULL); CGImageSourceRef imageSource = CGImageSourceCreateWithURL(imageURL, NULL); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); this->imageWidth = CGImageGetWidth(imageRef); this->imageHeight = CGImageGetHeight(imageRef); VisualGraphics* theVisualGraphics = VisualGraphics::getInstance(); this->useRectExtension = theVisualGraphics->canUseTextureRectExtension(); if (this->useRectExtension == false) { this->textureWidth = theVisualGraphics->power2Ceiling(this->imageWidth); this->textureHeight = theVisualGraphics->power2Ceiling(this->imageHeight); } else { this->textureWidth = this->imageWidth; this->textureHeight = this->imageHeight; } CGContextRef context = theVisualGraphics->createBitmapContext(this->textureWidth, this->textureHeight); CGContextTranslateCTM(context, 0.0, (float)this->textureHeight + (float)(this->textureHeight - this->imageHeight)); CGContextScaleCTM(context, 1.0, -1.0); CGRect rect = CGRectMake(0, (this->textureHeight - this->imageHeight), this->imageWidth, this->imageHeight); CGContextDrawImage(context, rect, imageRef); this->pixelBuffer = static_cast<UInt32*>(CGBitmapContextGetData(context)); this->textureName = theVisualGraphics->getNextFreeTextureName(); this->textureIsSet = true; VisualTextureContainer::textureRefCountMap[this->textureName] = 1; theVisualGraphics->copyARGBBitmapDataToTexture(this->textureName, this->textureWidth, this->textureHeight, this->useRectExtension, this->pixelFormat, this->dataType, const_cast<const UInt32**>(&(this->pixelBuffer))); CGContextRelease(context); if (this->pixelBuffer) { free(this->pixelBuffer); this->pixelBuffer = NULL; } CGImageRelease(imageRef); if (this->useRectExtension == false) { this->textureLogicalWidth = (double)this->imageWidth / (double)this->textureWidth; this->textureLogicalHeight = (double)this->imageHeight / (double)this->textureHeight; } else { this->textureLogicalWidth = (double)this->textureWidth; this->textureLogicalHeight = (double)this->textureHeight; } return osStatus; }
bool VisualAppleScript::executeScriptFile(VisualFile& scriptFile) { bool success = false; VisualString scriptFilePath; scriptFile.getFilePath(scriptFilePath); const char* const scriptPathCStr = scriptFilePath.getUtf8Representation(); size_t scriptPathCStrLen = strlen(scriptPathCStr); if (scriptPathCStrLen > 0) { char* script = (char*)malloc(scriptPathCStrLen + strlen("osascript ") + 3); sprintf(script, "osascript \"%s\"", scriptPathCStr); system(script); free(script); success = true; } return success; }
bool getDimensionsOfCocoaStringBitmap(void* aVisualString, void* aVisualStringStyle, uint32* imageWidth, uint32* imageHeight, uint16 maxPixelWidth, uint16 maxPixelHeight, char* alignment) { bool success = true; if (!doGetDimensionsOfStringBitmap) { initCocoaBundle(); } VisualString* aString = reinterpret_cast<VisualString*>(aVisualString); VisualStringStyle* aStringStyle = reinterpret_cast<VisualStringStyle*>(aVisualStringStyle); const CFStringRef aCFStringRef = aString->getCharactersPointer(); success = doGetDimensionsOfStringBitmap(aCFStringRef, imageWidth, imageHeight, aStringStyle->fontNameStr, &(aStringStyle->fontSize), aStringStyle->fontColor.red, aStringStyle->fontColor.green, aStringStyle->fontColor.blue, maxPixelWidth, maxPixelHeight, alignment); if (!success) { writeLog("ERR: getDimensionsOfCocoaStringBitmap"); return false; } return success; }
OSStatus getCocoaStringBitmapData(void* aVisualString, UInt32 bitmapWidth, UInt32 bitmapHeight, char* fontNameStr, float fontSize, float red, float green, float blue, char* alignment, UInt32** bitmapData) { OSStatus err = noErr; if (!doGetStringBitmapData) { initCocoaBundle(); } VisualString* aString = reinterpret_cast<VisualString*>(aVisualString); CFStringRef aCFStringRef = aString->getCharactersPointer(); err = doGetStringBitmapData(aCFStringRef, bitmapWidth, bitmapHeight, fontNameStr, fontSize, red, green, blue, alignment, bitmapData); if (err != noErr) { char logStr[64]; sprintf(logStr, "ERR: getCocoaStringBitmapData: %ld", err); writeLog(logStr); return 1001; } return err; }
OSStatus getDimensionsOfCocoaStringBitmap(void* aVisualString, UInt32* imageWidth, UInt32* imageHeight, char* fontNameStr, float* fontSize, float red, float green, float blue, UInt16 maxPixelWidth, UInt16 maxPixelHeight, char* alignment) { OSStatus err = noErr; if (!doGetDimensionsOfStringBitmap) { initCocoaBundle(); } VisualString* aString = reinterpret_cast<VisualString*>(aVisualString); const CFStringRef aCFStringRef = aString->getCharactersPointer(); err = doGetDimensionsOfStringBitmap(aCFStringRef, imageWidth, imageHeight, fontNameStr, fontSize, red, green, blue, maxPixelWidth, maxPixelHeight, alignment); if (err != noErr) { char logStr[64]; sprintf(logStr, "ERR: getDimensionsOfCocoaStringBitmap: %ld", err); writeLog(logStr); return 1; } else { return 0; } return err; }
OSStatus VisualTextureContainer::initWithString(const VisualString& stringValue, VisualStringStyle& stringStyle) { this->releaseTextureData(); if (this->pixelBuffer != NULL) { free(this->pixelBuffer); this->pixelBuffer = NULL; } OSStatus status = noErr; VisualGraphics* theVisualGraphics = VisualGraphics::getInstance(); UInt16 maxPixelWidth = theVisualGraphics->getCanvasPixelWidth(); UInt16 maxPixelHeight = theVisualGraphics->getCanvasPixelHeight(); this->textureName = theVisualGraphics->getNextFreeTextureName(); this->textureIsSet = true; VisualTextureContainer::textureRefCountMap[this->textureName] = 1; this->useRectExtension = theVisualGraphics->canUseTextureRectExtension(); #if TARGET_OS_MAC char alignmentStr[32]; switch (stringStyle.horizontalAlignment) { case (kLeftAligned): strcpy(alignmentStr, "left"); break; case(kCenterAligned): strcpy(alignmentStr, "center"); break; case(kRightAligned): strcpy(alignmentStr, "right"); break; default: break; } status = getDimensionsOfCocoaStringBitmap((void*)&stringValue, &(this->imageWidth), &(this->imageHeight), const_cast<char*>(stringStyle.fontNameStr), &(stringStyle.fontSize), stringStyle.fontColor.r, stringStyle.fontColor.g, stringStyle.fontColor.b, maxPixelWidth, maxPixelHeight, alignmentStr); if (this->useRectExtension == false) { this->textureWidth = theVisualGraphics->power2Ceiling(this->imageWidth); this->textureHeight = theVisualGraphics->power2Ceiling(this->imageHeight); } else { this->textureWidth = this->imageWidth; this->textureHeight = this->imageHeight; } this->pixelBuffer = (UInt32*)calloc(this->textureWidth * this->textureHeight, sizeof(UInt32)); status = getCocoaStringBitmapData((void*)&stringValue, this->textureWidth, this->textureHeight, const_cast<char*>(stringStyle.fontNameStr), stringStyle.fontSize, stringStyle.fontColor.r, stringStyle.fontColor.g, stringStyle.fontColor.b, alignmentStr, &(this->pixelBuffer)); theVisualGraphics->copyARGBBitmapDataToTexture(this->textureName, this->textureWidth, this->textureHeight, this->useRectExtension, this->pixelFormat, this->dataType, const_cast<const UInt32**>(&(this->pixelBuffer))); #endif #if TARGET_OS_WIN wchar_t* stringValueRef = (wchar_t*)stringValue.getCharactersPointer(); UInt8 red = (UInt8)(stringStyle.fontColor.r * 255.0f); UInt8 green = (UInt8)(stringStyle.fontColor.g * 255.0f); UInt8 blue = (UInt8)(stringStyle.fontColor.b * 255.0f); status = theVisualGraphics->makeTextureOfStringWin(stringValueRef, stringValue.getNumberOfCharacters(), this->textureName, this->textureWidth, this->textureHeight, this->imageWidth, this->imageHeight, stringStyle.fontNameStr, (UInt16)stringStyle.fontSize, red, green, blue, stringStyle.horizontalAlignment, maxPixelWidth, maxPixelHeight); #endif if (this->useRectExtension == false) { this->textureLogicalWidth = (double)this->imageWidth / (double)this->textureWidth; this->textureLogicalHeight = (double)this->imageHeight / (double)this->textureHeight; } else { this->textureLogicalWidth = (double)this->textureWidth; this->textureLogicalHeight = (double)this->textureHeight; } return status; }