Help - Search - Members - Calendar
Full Version: Putting a visual mark at exact;y 4 minutes
Hydrogenaudio Forums > Hosted Forums > foobar2000 > 3rd Party Plugins - (fb2k)
leokennis
Hello,

In my Foobar config I have a progress bar the width of the entire config. I want to add a little visual mark at the point where a track will be submitted to Audioscrobbler/Last.fm. The "rules" for this are quite clear:

QUOTE
1-The track must be submitted once it has finished playing. Whether it has finished playing naturally or has been manually stopped by the user is irrelevant.
2-The track must have been played for a duration of at least 240 seconds or half the track's total length, whichever comes first. Skipping or pausing the track is irrelevant as long as the appropriate amount has been played.
3-The total playback time for the track must be more than 30 seconds. Do not submit tracks shorter than this.
4-Unless the client has been specially configured, it should not attempt to interpret filename information to obtain metadata instead of tags (ID3, etc).

No I'm stuck at 2. My code thus far is:

CODE
$ifgreater(
$div(%length_seconds%,2),
240,
$drawrect($mul(240,$div(%_width%,%length_seconds%)),$sub(%_height%,205),1,10,brushColor-255-255-255 penColor-255-255-255),
$drawrect($div(%_width%,2),$sub(%_height%,205),1,10,brushColor-255-255-255 penColor-255-255-255)
)


"Mathematically" this code is correct (I strongly believe):
-First it checks what is greater: 1/2 of the song or 240 seconds.
-If 1/2 song>240 seconds, it's going to draw a line at the 240 seconds (4.00 minutes) point,
-otherwise it'll draw a line at the 1/2 song point.

But if this is executed:
CODE
$drawrect($mul(240,$div(%_width%,%length_seconds%)),$sub(%_height%,205),1,10,brushColor-255-255-255 penColor-255-255-255)

The line is always at more or less the same point, which is 240 or 480 pixels from the left of the screen. I believe this is because $div(%_width%,%length_seconds%) always produces a whole number.

Here lies my problem: is this correct, and if so, can I "fix" (work around) it?

Thanks in advance for your help.
BooooooooB
Try:
$muldiv(240,%_width%,%length_seconds%)
instead. I'm not sure if that rounds at a different time, but ii use $muldiv in progress bars and it seems to go well.
leokennis
QUOTE(BooooooooB @ Jul 12 2007, 22:14) *

Try:
$muldiv(240,%_width%,%length_seconds%)
instead. I'm not sure if that rounds at a different time, but ii use $muldiv in progress bars and it seems to go well.

Wow...this works. Thanks a lot smile.gif

I knew of this function (I saw it in many codes)...but it is nowhere documented so when using it I was just guessing...

Anyhow, works like a charm now:

CODE

//First, no markers when nothing playing
$if(%isplaying%,

//Then, only an audioscrobbler marker when the song is >30 sec.
$ifgreater(%length_seconds%,30,

//Check what's longer: 1/2 of the song or 4 minutes
$ifgreater(
$div(%length_seconds%,2),
240,

//Draw a marker at the correct point accordingly
$drawrect($muldiv(240,%_width%,%length_seconds%),$sub(%_height%,202),1,4,brushColor-null penColor-90-90-90),
$drawrect($div(%_width%,2),$sub(%_height%,202),1,4,brushColor-null penColor-90-90-90)
)
,)

/Draw a line at the 1 minute point to mark when Foobar counts the song as "played"
$drawrect($muldiv(60,%_width%,%length_seconds%),$sub(%_height%,202),1,4,brushColor-null penColor-100-100-100)
,)
plukin
Hi, thanks for the inspiration wink.gif
i will use an modified code, if i'am allowed...
CODE
/// Marker ///
$if(%isplaying%,
// 60 sec
$drawrect($muldiv(60,%_width%,%length_seconds%),$eval(%_height%-4),1,4,brushColor-null penColor-20-80-190 ALPHA-150)
$ifgreater(%length_seconds%,30,
// Audioscrobbler
$drawrect($muldiv($min(240,$eval(%length_seconds%/2),%_width%,%length_seconds%),$eval(%_height%-4),1,4,brushColor-null penColor-200-10-10 ALPHA-150)
,)

bye
leokennis
QUOTE(plukin @ Jul 13 2007, 00:03) *

Hi, thanks for the inspiration wink.gif
i will use an modified code, if i'am allowed...
CODE
/// Marker ///
$if(%isplaying%,
// 60 sec
$drawrect($muldiv(60,%_width%,%length_seconds%),$eval(%_height%-4),1,4,brushColor-null penColor-20-80-190 ALPHA-150)
$ifgreater(%length_seconds%,30,
// Audioscrobbler
$drawrect($muldiv($min(240,$eval(%length_seconds%/2),%_width%,%length_seconds%),$eval(%_height%-4),1,4,brushColor-null penColor-200-10-10 ALPHA-150)
,)

bye

Of course you can use the code tongue.gif It's not like it's secret code or anything wink.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.