yea im using on_track and add_timeout because calling the increment function directly can causing some blank audio delay
and i have new problem: sometimes the metadata is missing

here is the full script:

    count_jingle  = interactive.float("count_jingle",0.)
    jingle_period = interactive.float("jingle_period",3.)

    def jingle_count(m)
        value = count_jingle() + 1.0
        ignore(server.execute("var.set count_jingle = "^string_of(value)))
        log(label="increment",string_of(value))
        if value >= jingle_period() then ignore(server.execute("var.set count_jingle = 0.")) end
    end

    def smart_crossfade (jingles, ~start_next=30.,~fade_in=3.,
    ~fade_out=3., ~width=2.,
    ~conservative=false,s)
   
      high   = -20.
      medium = -32.
      margin = 4.

      log = log(label="smart_crossfade")
      log("activate smart crossfade")

      def transition(jingles,a,b,ma,mb,sa,sb)
            if count_jingle() == 0. then
                log("jingle transition")
                add(normalize=false,[
                    fade.final(type="sin",duration=13.,sa),
                    sequence(merge=false,[blank(duration=14.),fade.in(type="sin",duration=16.,sb)]),
                    sequence(merge=false,[blank(duration=7.5),once(jingles)])
                ])               
            else
                log("normal transition")
               
                if
                  a <= medium and
                  b <= medium and
                  abs(a - b) <= margin
                then
                  log("Transition: crossed, fade-in, fade-out.")
                  add(normalize=false,[fade.out(type="sin", duration=3.,sa),sequence([blank(duration=25.),fade.in(type="sin", duration=3.,sb)])])
                elsif
                  b >= a + margin and a >= medium and b <= high
                then
                  log("Transition: crossed, fade-out.")
                  add(normalize=false,[fade.out(type="sin", duration=3.,sa),sequence([blank(duration=25.),sb])])
                elsif
                  b >= a + margin and a <= medium and b <= high
                then
                  log("Transition: crossed, no fade-out.")
                  add(normalize=false,[sa,sequence([blank(duration=25.),sb])])
                elsif
                  a >= b + margin and b >= medium and a <= high
                then
                  log("Transition: crossed, fade-in.")
                  add(normalize=false,[sa,sequence([blank(duration=25.),fade.in(type="sin", duration=3.,sb)])])
                else
                  log("No transition: just sequencing.")
                  sequence([sa, sb])
                end
           
            end
      end

      smart_cross(width=width, duration=start_next,
                  conservative=conservative,
                  transition(jingles),s)
    end

   
    jingles = playlist.safe(mode = "random", "~/deadmediafm_playlist/liq-dmfm_jingle.m3u")
   
    songs  = playlist(mode = "randomize", "~/deadmediafm_playlist/liq-songs.m3u")
   
    songs  = on_track(jingle_count, songs)
   
    songs  = fallback(track_sensitive = false, [songs, jingles])

    radio = smart_crossfade(jingles,conservative=true, songs)


On Wed, May 26, 2010 at 3:28 PM, David Baelde <david.baelde@gmail.com> wrote:
Sounds good to me, I'm impressed! You forgot to show us how you
increment count_jingle. I expected to see it within the transition
itself. Do you use on_track or similar instead?