PDA

View Full Version : Location in code to change transitionbehavior(crossfade, etc)



mwphoto
2005-07-17, 00:22
Hi,

I think I've already developed what you want :)

The attached plugin hooks into the command interface and monitors commands
to identify whether an album or random collection is playing. If it's an
album it sets no pause interval and no fading. If it's a random collection
then it uses FadeIn FadeOut for 5 secs.

It's not documented so feel free to ask questions as needed.

I'm very interested in your replaygain plugin. Is there any chance you can
post it somewhere accessible.

Malcolm

> -----Original Message-----
> From: developers-bounces (AT) lists (DOT) slimdevices.com
> [mailto:developers-bounces (AT) lists (DOT) slimdevices.com]On Behalf Of jsutula
> Sent: 17 July 2005 02:11
> To: developers (AT) lists (DOT) slimdevices.com
> Subject: [Developers] Location in code to change transition
> behavior(crossfade, etc)
>
>
>
> I've just finished modifying some source code to apply track or album
> gain through replaygain to the current track depending on the context
> of the playlist (if you're in the middle of playing an album use album
> gain, if not use track gain).
>
> Anyway, I'm very happy with how it turned out and am excited to start
> on my next hack--doing the same sort of context checking and this time
> turning on the crossfade if an album is not being played. However, I
> haven't been able to figure out how to change the "TransitionType"
> (I've found that variable in several places--mostly Web/Setup.pm).
> Overall, I'm just pretty confused about how the code is organized. Is
> there any resource for that? My way of figuring out how to do things
> conists of way too much grepping for keywords. I'm a beginner with Perl
> but know enough basics to figure most things out. Can anyone quickly
> give me an idea of where to look for changing TransitionType?
>
> I am also curious if many other people are interested in the behaviors
> I mentioned above. I posted a suggestion about the replaygain related
> one in Bug 1311. Unfortunately, I don't think I've gone about things
> the proper way at all in implementing these things as I've just
> inserted chunks of code inside other functions to make it work. A
> resource for code organization/flow would help a lot.
>
>
> --
> jsutula
>

jsutula
2005-07-17, 10:59
I am viewing the forums through forums.slimdevices.com so I was unable to see your attachment (or I'm not sure how to get at it). I've subscribed to the mailing list so if you could re-send it, that would be great.

Here's the code for the "plugin":
<code>
my $previous_index = streamingSongIndex($client) - 1;
my $previous_fullpath = Slim::Player::Playlist::song($client, $previous_index);
my $previous_track = $ds->objectForUrl($previous_fullpath);
my $previous_album = Slim::Music::Info::info($previous_track, "ALBUM");
my $previous_track_num = Slim::Music::Info::info($previous_track, "TRACKNUM");

my $current_index = streamingSongIndex($client);
my $current_album = Slim::Music::Info::info($track, "ALBUM");
my $current_track_num = Slim::Music::Info::info($track, "TRACKNUM");

my $next_index = streamingSongIndex($client) + 1;
my $next_fullpath = Slim::Player::Playlist::song($client, $next_index);
my $next_track = $ds->objectForUrl($next_fullpath);
my $next_album = Slim::Music::Info::info($next_track, "ALBUM");
my $next_track_num = Slim::Music::Info::info($next_track, "TRACKNUM");

my $playing_album = 0;
#check the previous song for a album/tracknumber match
#if current song is not the first song in playlist
if ($current_index != 0)
{

if (!($current_album cmp $previous_album) && ($current_track_num - 1) == $previous_track_num )
{
$playing_album = 1;
}
}
#check the next song for album/tracknumber match
#if next song exists
if ($next_album cmp "")
{
if (!($current_album cmp $next_album) && ($current_track_num + 1) == $next_track_num )
{
$playing_album = 1;
}
}

if ( !$playing_album )
{
$::d_source && msg("Changing album gain to track gain\n");
$command =~ s/--apply-replaygain-which-is-not-lossless=a/--apply-replaygain-which-is-not-lossless=t/;
}
</code>

I just inserted this code in Player/Source.pm in the function openSong() right before the statements:
<code>
$::d_source && msg("openSong: this is an $type file: $fullpath\n");
$::d_source && msg(" file type: $type format: $format inrate: $rate maxRate: $maxRate\n");
$::d_source && msg(" command: $command\n");
</code>

I'm going from FLAC->FLAC to get the replaygain applied, so this only works for FLAC files, but you can easily change the regexp line to work for any other formats that apply replaygain in the command line.

I do plan to implement this correctly as an actual plugin once I get more comfortable with the code and callbacks. I think looking at your code will help me there.

Thanks.

jsutula
2005-07-17, 15:57
Malcolm, each time you respond to a message, a new thread is being created on forums.slimdevices.com with a title with one space less than the title of the message you responded to. I'm not sure why this is happening but I'm going to continue to post in this thread for consistency.

Thanks for your plugin code. I have a good idea of how the callbacks are working now. Your method of detecting randomness which relies solely on different types of commands being issued would not behave correctly when, for example, you play a playlist consisting of multiple albums, all played sequentially. Correct? Or the case of turning shuffle on, then adding an album...?
My method of checking the songs around the current song would handle this. I realize the criteria for "playing an album" that is defined right now is: same album name, in correct track order, and that does have its limitations and could result in some (coincidental) false positives. That criteria could be broadened however. What are your thoughts on this?

I'm also now attempting to write a proper plugin to perform the replaygain mode switching shown in the previous post. The issue I'm running into is that the callback for the very first command that happens when a track is opened: "open", happens AFTER the command line for audio conversion is retrieved and run. Is there any way to get something to run before the command line for audio decoding/encoding is retrieved?

mwphoto
2005-07-18, 00:55
regarding thread forums - I'm posting via email - I don't know if there's anything I can do about this bug. I've replied using the forum web page to see if it helps this time . . . :(


>Thanks for your plugin code. I have a good idea of how the callbacks
>are working now. Your method of detecting randomness which relies
>solely on different types of commands being issued would not behave
>correctly when, for example, you play a playlist consisting of multiple
>albums, all played sequentially. Correct? Or the case of turning >shuffle
>on, then adding an album...?

Yes, a playlist of multiple albums would fail.

Using transitions when an album is shuffled is deliberate. I wanted the transition except when playing in album order for albums that have no pauses between tracks (eg pink floyd etc).

However I agree - it's all compromises and I'm not happy with the method - I would prefer that this information could be queried directly from the server rather than 'guessed' based on the command sequence.


>My method of checking the songs around the current song would handle
>this. I realize the criteria for "playing an album" that is defined
>right now is: same album name, in correct track order, and that does
>have its limitations and could result in some (coincidental) false
>positives. That criteria could be broadened however. What are your
>thoughts on this?

I think the sensible apprach for this is to amend the server code with a patch and provide the information from the server, so we don't have to guess. However I haven't had the time to understand the server code and work out where the edits need to go.


>I'm also now attempting to write a proper plugin to perform the
>replaygain mode switching shown in the previous post. The issue I'm
>running into is that the callback for the very first command that
>happens when a track is opened: "open", happens AFTER the command line
>for audio conversion is retrieved and run. Is there any way to get
>something to run before the command line for audio decoding/encoding is
>retrieved?

I'm not sure - I'll take a look, however we might be out of luck with this as well.

Malcolm