Wednesday, June 17, 2015

Digital Dash Documentation, Part 5: Music Info

One of the functions the digital dash project is to provide an continual display of the currently playing music track and artist.  Since there are two possible sources for music (Pandora and PowerAmp) we need routines to extract that information from either app.

Profile: V3_GetPandoraInfo (281)
Event: AutoNotification Intercept [ Configuration:Event Behaviour: true
Notification Type: Only Created Notifications
Notification Apps: Pandora
Get All Fields : true ]
State: Variable Value [ %V3_DrivingMode Set ]
Enter: V3_PandoraInfo (347)

Whenever Pandora starts playing a new track, it adds a entry to the tablet's notification panel (after first destroying the previous one) that contains the name of the track and the artist.  I use AutoNotification to monitor for the creation of that entry.

A1: Variable Set [ Name:%V3_Track To:%antitle Do Maths:Off Append:Off ]
A2: Variable Set [ Name:%V3_Artist To:%antext Do Maths:Off Append:Off ]

The Pandora information comes into Tasker as the local variables %antitle, and %antext.  I simply copy those values to global variables that are used as the sources for text elements on the V3_TopMain scene.

Getting information from PowerAmp is a little more involved and uses an intent that PowerAmp fires off any time it starts playing a new track.

Profile: V3_GetPowerAmpInfo (345)
Event: Intent Received [ Action:com.maxmpz.audioplayer.TRACK_CHANGED Cat:None Cat:None Scheme:* Mime Type:* ]
State: Variable Value [ %V3_DrivingMode Set ]
Enter: V3_PowerAmpInfo (346)

The profile is configured to listen for this specific intent.

A1: Variable Split [ Name:%track Splitter:, Delete Base:Off ] 

The intent payload from PowerAmp contains 18 pieces of information concatenated into a comma-separated bundle that comes into Tasker as the local variable "%track".  For my application, most of that information isn't needed, but I still need to split the variable in order to get at the information I do want. 

A2: Variable Set [ Name:%artist To:%track1 Do Maths:Off Append:Off ] 
A3: Variable Split [ Name:%artist Splitter:= Delete Base:Off ] 
A4: Variable Set [ Name:%V3_Artist To:%artist2 Do Maths:Off Append:Off ] 

After the initial split, the array variable %track1 contains the bundle start designation as well as the first piece of information I want. For example, it might look like this: Bundle[{artist=Queen.  So, I copy that to a temporary local variable (%artist) and split that, this time using an = as the Splitter. What remains in %artist2 after the split is the artist name, in this case, Queen.  That then gets copied into the global variable %V3_Artist, which is referenced as a source for one of the elements in the V3_TopMain scene (to be described later).

A5: Variable Set [ Name:%song To:%track14 Do Maths:Off Append:Off ]
A6: Variable Split [ Name:%song Splitter:= Delete Base:Off ]
A7: Variable Set [ Name:%V3_Track To:%song2 Do Maths:Off Append:Off ] 

I perform a similar set of splits with the 14th entry in the %track variable array. This contains something like this: title=Bohemian Rhapsody.  I copy that to the local %song variable, split it with an = and copy the resulting %song2 value to %V3_Track, which is, again, linked to a text element on the main screen.

2 comments:

Daniel said...

I have got here after starting a digital dashboard project myself.
I want to add something to error-proof the information gotten from PowerAmp. Comma <,> cannot be used as a separator of the %track variable. If any of the tag fields contain a comma, then the result is not correct anymore. I use and as first and second separators and continue from there. It involves more operations, but the result is safer.

Mike said...

Hi, Daniel, thanks for commenting. You're right; this code doesn't work very well if there are commas in the data itself. I no longer actually use this routine. I do splits on the bundle headers instead. I should probably update this post. Good luck with your project. I'd be interested in knowing what features you're putting in.