From: David B. <dav...@gm...> - 2012-04-25 19:51:26
|
Hi Alexandru, 2012/4/24 Alexandru Matei <ale...@gm...>: > I still get empty source ids if I use the code below. In fact, what happens is that your transition is not called at all, right? At least that's what I observed in my tests: I had forgotten that transitions are not used for track sensitive switches. Indeed, they don't make sense in that case, the track from source a is already finished. Therefore I will propose a simpler solution, which has the disadvantage of requiring more coding skills. So I'll provide you with the code (copying verbatim the script that worked for me, and should be easy to adapt). The idea is to keep in a reference (memory cell) the id of the previous source, update it using on_track, and reload when it changes. small1 = playlist(id="small1","~/media/audio/jazz") small2 = playlist(id="small2","~/media/audio/misc") def reload_transition(a,b) log("a is #{source.id(a)}, b is #{source.id(b)}") b end playlists = switch([({0m-44m},small1), ({36m-50m},small2)]) def reload_on_change(s) last_seen = ref("") def handler(m) id = m["source"] old_id = !last_seen if old_id != id then last_seen := id if old_id != "" then log("Reloading #{old_id}...") list.iter(log,server.execute("#{old_id}.reload")) end end end on_track(handler,s) end playlists = reload_on_change(playlists) output.icecast(%vorbis,mount="test.ogg",fallible=true,playlists) > Anyway, I followed your advice and managed to make the transition function. > I would have never tried to make a function with three parameters for a > transition because in the doc I read: > transitions ([(source('a),source('a))->source('a)] – defaults to []): > Transition functions, padded with fun (x,y) -> y functions. > I think the documentation needs to be improved. Well, we may document more the language and type system, but there's nothing we can do about (source('a),source('a))->source('a): transitions have to take only two arguments and return a source. The fact that you can create a function with two arguments from one with three arguments doesn't change this. To make an analogy, type int contains 0, 1, 2, etc. but also 1+1... Cheers, David PS: > This was my mistake. To be sure that nothing bad happens because one source > is mono and another one stereo I added audio_to_stereo to all my playlists. > small_playlist = audio_to_stereo(id="small_stereo", > playlist("..../small.txt")) -> Wrong. Sounds like a good fix. Why did you write "Wrong"? |