# V8.10 - HABILLAGES NATIFS CALES AU CUE_IN / CUE_OUT EXACT / MELANGE PERSISTANT # BIEN VIVRE A MAGNY - V8.5 CUE_OUT EXACT NATIF / SOURCES ISOLEES - 2026-10-04 # Liquidsoap 2.4.5. # EXIGENCE PERMANENTE : premier echantillon du suivant au CUE_OUT musical. # Aucune comparaison elapsed() par frame ne declenche une transition musicale. # Le fichier suivant et le tail sortant sont prepares avant la frontiere audio. # Corrections : aucune reutilisation de decodeur entre deux activations, # callbacks lies au slot ET a sa generation, fin physique sans CUE_OUT, # non-musicaux intégraux, mix musique limite aux secondes restantes (max 3 s), # annulation des liners en attente au TOP. Rotate et dossiers du fichier fourni conserves. settings.log.file.path := "/etc/liquidsoap/logs/bienvivreamagny.log" settings.log.stdout := true settings.log.level := 3 settings.init.daemon := false settings.server.telnet := true settings.server.telnet.bind_addr := "127.0.0.1" settings.server.telnet.port := 1240 settings.charset.encodings := ["UTF-8", "ISO-8859-1", "ISO-8859-15"] settings.request.metadata_decoders.recode := true # Surveillance du nombre de sources actives (enfants dynamiques liberes au remplacement). settings.clock.leak_warning := 100 # Musique : fin de requete EXACTEMENT au CUE_OUT, via annotation native. # La fin apres CUE_OUT est une requete tail du MEME fichier, limitee a 3 s. # CUE_IN reste une information pour les liners, jamais un point de debut audio. # Les non-musicaux et tops ignorent tous les points de coupe des tags. def music_cue_metadata(meta) = cue_upper = meta["CUE_OUT"] cue_lower = meta["cue_out"] cue = if cue_upper != "" then cue_upper else cue_lower end if cue != "" then cue_value = float_of_string(default=0.0, cue) if cue_value > 0.0 then [ # IMPORTANT : Cue Studio ecrit aussi LIQ_CUE_OUT dans le MP3. # Ces valeurs sont conservees pour les consommateurs de metadonnees. # La coupe audio au CUE_OUT est appliquee par la requete native. ("liq_cue_out", string(cue_value)), ("LIQ_CUE_OUT", string(cue_value)), ("mix_at_cue", "true"), ("vrs_mix_duration", "3.0"), ("vrs_mix_allowed", "true") ] else [ ("mix_at_cue", "false"), ("vrs_mix_duration", "0.0"), ("vrs_mix_allowed", "true") ] end else [ ("mix_at_cue", "false"), ("vrs_mix_duration", "0.0"), ("vrs_mix_allowed", "true") ] end end def full_end_resolver(~rlog, ~maxtime, filename) = ignore(rlog) ignore(maxtime) "annotate:mix_at_cue=\"false\",vrs_mix_duration=\"0.0\":" ^ filename end protocol.add( "fullend", static=(fun (_) -> true), syntax="fullend:/chemin/fichier.mp3", doc="Lecture jusqu'a la vraie fin du fichier, CUE_OUT ignore.", full_end_resolver ) # Pointeur logique du rotate et identite unique de chaque activation. top_done_hour = ref(-1) program_hold_for_top = ref(false) program_position = ref(0) program_generation = ref(0) music_tails = ref([]) prefetched_requests = ref([]) def set_program_position(pos) = program_generation := program_generation() + 1 program_position := pos end # V8.6 : melange sans remise, historique partage avec la precharge. # Etat conserve dans le cache de l utilisateur ; aucun reset au top horaire. # Python3 standard uniquement, sans module supplementaire. def random_mp3(directory) = cmd = "python3 -c " ^ process.quote("exec(__import__(\"base64\").b64decode(\"aW1wb3J0IHN5cywgb3MsIGpzb24sIHJhbmRvbSwgaGFzaGxpYiwgdGVtcGZpbGUsIGZjbnRsCmZyb20gcGF0aGxpYiBpbXBvcnQgUGF0aAoKZGVmIHNlbGVjdChkaXJlY3RvcnksIHN0YXRlX3Jvb3Q9Tm9uZSk6CiAgICBmb2xkZXIgPSBQYXRoKGRpcmVjdG9yeSkKICAgIGlmIG5vdCBmb2xkZXIuaXNfZGlyKCk6CiAgICAgICAgcmV0dXJuICcnCiAgICBmaWxlcyA9IHNvcnRlZChzdHIocCkgZm9yIHAgaW4gZm9sZGVyLml0ZXJkaXIoKSBpZiBwLmlzX2ZpbGUoKSBhbmQgcC5zdWZmaXgubG93ZXIoKSA9PSAnLm1wMycpCiAgICBpZiBub3QgZmlsZXM6CiAgICAgICAgcmV0dXJuICcnCiAgICByb290ID0gUGF0aChzdGF0ZV9yb290KSBpZiBzdGF0ZV9yb290IGVsc2UgUGF0aC5ob21lKCkgLyAnLmNhY2hlJyAvICdiaWVudml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ToKICAgICAgICAgICAgd2l0aCBvcy5mZG9wZW4oZmQsICd3JykgYXMgb3V0OgogICAgICAgICAgICAgICAganNvbi5kdW1wKGRhdGEsIG91dCwgZW5zdXJlX2FzY2lpPUZhbHNlKQogICAgICAgICAgICAgICAgb3V0LmZsdXNoKCkKICAgICAgICAgICAgICAgIG9zLmZzeW5jKG91dC5maWxlbm8oKSkKICAgICAgICAgICAgb3MucmVwbGFjZSh0bXAsIHRhcmdldCkKICAgICAgICBmaW5hbGx5OgogICAgICAgICAgICBpZiBvcy5wYXRoLmV4aXN0cyh0bXApOgogICAgICAgICAgICAgICAgb3MudW5saW5rKHRtcCkKICAgICAgICByZXR1cm4gY2hvc2VuCgppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOgogICAgdHJ5OgogICAgICAgIHByaW50KHNlbGVjdChzeXMuYXJndlsxXSkpCiAgICBleGNlcHQgRXhjZXB0aW9uIGFzIGV4YzoKICAgICAgICBwcmludCgnVlJTIHNodWZmbGU6ICcgKyBzdHIoZXhjKSwgZmlsZT1zeXMuc3RkZXJyKQogICAgICAgICMgS2VlcCB0aGUgc291cmNlIGF2YWlsYWJsZSBpZiB0aGUgc3RhdGUgZGlyZWN0b3J5IGlzIHRlbXBvcmFyaWx5IHVud3JpdGFibGUuCiAgICAgICAgdHJ5OgogICAgICAgICAgICBmaWxlcyA9IFtzdHIocCkgZm9yIHAgaW4gUGF0aChzeXMuYXJndlsxXSkuaXRlcmRpcigpIGlmIHAuaXNfZmlsZSgpIGFuZCBwLnN1ZmZpeC5sb3dlcigpID09ICcubXAzJ10KICAgICAgICAgICAgcHJpbnQocmFuZG9tLmNob2ljZShmaWxlcykgaWYgZmlsZXMgZWxzZSAnJykKICAgICAgICBleGNlcHQgT1NFcnJvcjoKICAgICAgICAgICAgcHJpbnQoJycpCg==\"))") ^ " " ^ process.quote(directory) list.hd(default="", process.read.lines(cmd)) end def one_shot_request(~target_generation=null, directory, generation_get, generation_set, source_name) = generation = null.get(default=program_generation(), target_generation) ignore(generation_get) ignore(generation_set) if true then filename = random_mp3(directory) if filename != "" then log(label="one_shot_slot", level=3, "ONE-SHOT " ^ source_name ^ " : generation " ^ string(generation) ^ " ; un seul fichier fourni : " ^ filename) begin tags = file.metadata(filename) cue = float_of_string(default=0.0, if tags["CUE_OUT"] != "" then tags["CUE_OUT"] else tags["cue_out"] end) if cue > 0.0 then tail_uri = "annotate:vrs_tail_in=\"" ^ string(cue) ^ "\",vrs_tail_out=\"" ^ string(cue + 3.0) ^ "\":" ^ filename tail_request = request.create(cue_in_metadata="vrs_tail_in", cue_out_metadata="vrs_tail_out", tail_uri) if request.resolve(tail_request) then tail_served = ref(false) def fetch_tail_once() = if tail_served() then null else tail_served := true tail_request end end tail_source = stereo(request.dynamic(synchronous=true, fetch_tail_once)) key = string(generation) music_tails := [(key, (tail_source : source)), ...list.assoc.remove(key, music_tails())] end end physical = null.get(default=0.0, request.duration(filename)) play_length = if cue > 0.0 then min(cue, physical) else physical end uri = if cue > 0.0 then "annotate:vrs_play_length=\"" ^ string(play_length) ^ "\",vrs_request_cue_out=\"" ^ string(cue) ^ "\":" ^ filename else "annotate:vrs_play_length=\"" ^ string(play_length) ^ "\":" ^ filename end request.create(cue_in_metadata=null, cue_out_metadata="vrs_request_cue_out", uri) end else null end else null end end def one_shot_fullend_request(directory, generation_get, generation_set, source_name) = generation = program_generation() ignore(generation_get) ignore(generation_set) if true then filename = random_mp3(directory) if filename != "" then log(label="one_shot_slot", level=3, "ONE-SHOT " ^ source_name ^ " : generation " ^ string(generation) ^ " ; un seul fichier integral fourni : " ^ filename) length = null.get(default=0.0, request.duration(filename)) request.create(cue_in_metadata=null, cue_out_metadata=null, "annotate:vrs_play_length=\"" ^ string(length) ^ "\":fullend:" ^ filename) else null end else null end end # Compatibilite des signatures de selection ; le verrou est dans chaque enfant. last_annees80_generation = ref(-1) last_annees90_generation = ref(-1) last_annees2000_generation = ref(-1) last_annees2010_generation = ref(-1) last_annees2020_generation = ref(-1) last_nouveautes_generation = ref(-1) last_titresjessy_generation = ref(-1) last_grenierjessy_generation = ref(-1) # V8.3.3 : garde de slot. Une source ne peut tirer un fichier que si le pointeur # du rotate demande REELLEMENT cette famille. Les interrogations de prechargement # d'une ancienne branche renvoient null et ne consomment aucun nouveau titre. def next_annees80_request() = if program_position() == 12 or program_position() == 38 then one_shot_request("/home/musique/Annees80", last_annees80_generation, (fun (v) -> last_annees80_generation := v), "ANNEES80") else null end end def next_annees90_request() = if program_position() == 20 or program_position() == 33 then one_shot_request("/home/musique/Annees90", last_annees90_generation, (fun (v) -> last_annees90_generation := v), "ANNEES90") else null end end def next_annees2000_request() = if program_position() == 6 then one_shot_request("/home/musique/Annees2000", last_annees2000_generation, (fun (v) -> last_annees2000_generation := v), "ANNEES2000") else null end end def next_annees2010_request() = if program_position() == 26 then one_shot_request("/home/musique/Annees2010", last_annees2010_generation, (fun (v) -> last_annees2010_generation := v), "ANNEES2010") else null end end def next_annees2020_request() = if program_position() == 40 then one_shot_request("/home/musique/Annees2020", last_annees2020_generation, (fun (v) -> last_annees2020_generation := v), "ANNEES2020") else null end end def next_nouveautes_request() = p = program_position() if p == 4 or p == 17 or p == 22 or p == 23 or p == 29 or p == 35 or p == 42 then one_shot_request("/home/musique/Nouveautes", last_nouveautes_generation, (fun (v) -> last_nouveautes_generation := v), "NOUVEAUTES") else null end end def next_titresjessy_request() = if program_position() == 7 or program_position() == 18 or program_position() == 36 then one_shot_request("/home/bienvivre/Titresjessy", last_titresjessy_generation, (fun (v) -> last_titresjessy_generation := v), "TITRESJESSY") else null end end def next_grenierjessy_request() = if program_position() == 28 then one_shot_request("/home/bienvivre/Grenierjessy", last_grenierjessy_generation, (fun (v) -> last_grenierjessy_generation := v), "GRENIERJESSY") else null end end # CORRECTION ANTI-SILENCE 2026-09-30 # Les callbacks de fin exacte (musique et one-shot non musical) sont synchrones. # Le pointeur passe donc au slot suivant AVANT qu'une source request.dynamic # one-shot puisse etre redemandee dans sa generation deja consommee et renvoyer null. # Cela evite que mksafe() masque cette indisponibilite sous forme de silence. # Le rotate, l'ordre des 43 slots, les CUE_OUT et la logique TOP restent inchanges. # # ROTATION STRICTE REINITIALISABLE APRES CHAQUE TOP HORAIRE # ------------------------------------------------------------ # La version precedente partageait une seule instance de rotate entre toutes # les heures. Cela faisait reprendre la rotation la ou elle se trouvait apres # le top. Ici on utilise un pointeur explicite de 0 a 42. # Chaque top horaire remet ce pointeur a 0 : la reprise est donc TOUJOURS : # JINGLEINFO, INFOSMAGNY, MERCI, JINGLESMIX, NOUVEAUTES, etc. # V8.3.0 : program_position/program_generation/set_program_position/random_mp3 sont definis plus haut. # ------------------------------------------------------------ # SOURCES NON MUSICALES STABLES # ------------------------------------------------------------ last_jingleinfo_generation = ref(-1) last_infosmagny_generation = ref(-1) last_merci_generation = ref(-1) last_jinglesmix_generation = ref(-1) last_lctmeteo_generation = ref(-1) last_meteo_generation = ref(-1) last_jinglehistoire_generation = ref(-1) last_histoire_generation = ref(-1) last_jinglesgrenier_generation = ref(-1) def next_jingleinfo_request() = if program_position() == 0 then one_shot_fullend_request("/home/bienvivre/Jingleinfo", last_jingleinfo_generation, (fun (v) -> last_jingleinfo_generation := v), "JINGLEINFO") else null end end def next_infosmagny_request() = if program_position() == 1 then one_shot_fullend_request("/home/bienvivre/Infosmagny", last_infosmagny_generation, (fun (v) -> last_infosmagny_generation := v), "INFOSMAGNY") else null end end def next_merci_request() = if program_position() == 2 then one_shot_fullend_request("/home/bienvivre/Merciflash", last_merci_generation, (fun (v) -> last_merci_generation := v), "MERCI") else null end end def next_jinglesmix_request() = if program_position() == 3 then one_shot_fullend_request("/home/bienvivre/Jinglesmix", last_jinglesmix_generation, (fun (v) -> last_jinglesmix_generation := v), "JINGLESMIX") else null end end def next_lctmeteo_request() = if program_position() == 8 then one_shot_fullend_request("/home/bienvivre/Lancementmeteo", last_lctmeteo_generation, (fun (v) -> last_lctmeteo_generation := v), "LCTMETEO") else null end end def next_meteo_request() = if program_position() == 9 then one_shot_fullend_request("/home/bienvivre/Meteo", last_meteo_generation, (fun (v) -> last_meteo_generation := v), "METEO") else null end end def next_jinglehistoire_request() = if program_position() == 13 or program_position() == 30 then one_shot_fullend_request("/home/bienvivre/Jinglehistoire", last_jinglehistoire_generation, (fun (v) -> last_jinglehistoire_generation := v), "JINGLEHISTOIRE") else null end end def next_histoire_request() = if program_position() == 14 or program_position() == 31 then one_shot_fullend_request("/home/bienvivre/Histoiremagny", last_histoire_generation, (fun (v) -> last_histoire_generation := v), "HISTOIRE") else null end end def next_jinglesgrenier_request() = if program_position() == 27 then one_shot_fullend_request("/home/bienvivre/Jinglesgrenier", last_jinglesgrenier_generation, (fun (v) -> last_jinglesgrenier_generation := v), "JINGLESGRENIER") else null end end # Verrou utilise pendant la remise a zero horaire. Il empeche les metadonnees # retardees de la branche active avant le top de remettre un ancien slot. program_reset_lock = ref(false) # ------------------------------------------------------------ # V20 - SOURCES ONE-SHOT NATIVES JESSY / JINGLESCHANTES # ------------------------------------------------------------ # request.dynamic est utilise en resolution SYNCHRONE : aucune file asynchrone # et aucun prechargement d'une generation future. # La generation interdit une deuxieme requete logique pour le meme slot. # Les callbacks de chaque enfant font avancer une seule fois sa generation. def is_jessy_slot(slot) = slot == 5 or slot == 11 or slot == 16 or slot == 21 or slot == 25 or slot == 34 or slot == 41 end def is_jingleschantes_slot(slot) = slot == 10 or slot == 15 or slot == 19 or slot == 24 or slot == 32 or slot == 37 or slot == 39 end def jessy_hour_directory() = now = time.local() if now.hour >= 6 and now.hour < 9 then "/home/bienvivre/JESSY06h09h" elsif now.hour >= 9 and now.hour < 12 then "/home/bienvivre/JESSY09h12h" elsif now.hour >= 12 and now.hour < 13 then "/home/bienvivre/JESSY12h13h" elsif now.hour >= 13 and now.hour < 17 then "/home/bienvivre/JESSY13h17h" elsif now.hour >= 17 and now.hour < 20 then "/home/bienvivre/JESSY17h20h" elsif now.hour >= 20 and now.hour < 22 then "/home/bienvivre/JESSY20h22h" else "/home/bienvivre/JESSY22h06h" end end def next_jessy_request() = slot = program_position() generation = program_generation() if is_jessy_slot(slot) then # JESSYete est strictement saisonnier : uniquement du 1er juillet # au 31 aout inclus, chaque annee. Hors de cette periode, ce dossier # n'entre jamais dans le tirage. now = time.local() jessy_directories = if now.month == 7 or now.month == 8 then [ "/home/bienvivre/Jessy", jessy_hour_directory(), "/home/bienvivre/JESSYete" ] else [ "/home/bienvivre/Jessy", jessy_hour_directory() ] end directory = list.hd( default="/home/bienvivre/Jessy", list.shuffle(jessy_directories) ) selected_filename = random_mp3(directory) # Si le dossier choisi est vide, repli sur Jessy toute heure. filename = if selected_filename == "" then random_mp3("/home/bienvivre/Jessy") else selected_filename end if filename != "" then log( label="one_shot_jessy", level=3, "ONE-SHOT JESSY : generation " ^ string(generation) ^ " ; un seul fichier fourni : " ^ filename ) length = null.get(default=0.0, request.duration(filename)) request.create(cue_in_metadata=null, cue_out_metadata=null, "annotate:vrs_play_length=\"" ^ string(length) ^ "\":fullend:" ^ filename) else null end else null end end def next_jingleschantes_request() = slot = program_position() generation = program_generation() if is_jingleschantes_slot(slot) then filename = random_mp3("/home/bienvivre/Jingleschantes") if filename != "" then log( label="one_shot_jingleschantes", level=3, "ONE-SHOT JINGLESCHANTES : generation " ^ string(generation) ^ " ; un seul fichier fourni : " ^ filename ) length = null.get(default=0.0, request.duration(filename)) request.create(cue_in_metadata=null, cue_out_metadata=null, "annotate:vrs_play_length=\"" ^ string(length) ^ "\":fullend:" ^ filename) else null end else null end end transition_mix_requested = ref(false) transition_mix_duration = ref(0.0) transition_tail_duration = ref(0.0) current_program_slot = ref(-1) current_program_generation = ref(-1) current_program_is_music = ref(false) current_program_mix_at_cue = ref(false) current_program_mix_duration = ref(0.0) # IMPORTANT 2026-08-18 : une seule autorite fait avancer la rotation. # program_position est avance uniquement a la fin native de la requete, # sauf remise a zero volontaire au top horaire. Aucun callback on_track ne # modifie le pointeur : cela evite le saut d'un element sur deux. # La meteo est diffusee uniquement entre 00:00 et 14:59:59 (heure locale). # A partir de 15:00, P07 rejoint P10 ; si P08 finit apres 15:00, # P09 est saute lui aussi. Le top horaire conserve son reset sur P00. def next_program_slot(slot) = now = time.local() if now.hour >= 15 and slot == 7 then 10 elsif now.hour >= 15 and slot == 8 then 10 elsif slot + 1 >= 43 then # P42 termine le corps du rotate. Hors top horaire, on repart a P04. # P00-P03 sont reserves au redemarrage impose par le vrai top horaire. 4 else slot + 1 end end # V8.4 : une instance audio neuve pour chaque activation de chaque position. # Le wrapper conserve son ancien enfant uniquement pour terminer la transition. # Lors du retour a cette position, l'enfant est remplace AVANT toute lecture. def top_waiting_at_boundary() = now = time.local() hour = if now.min == 59 then (now.hour + 1) mod 24 else now.hour end top_done_hour() != hour and file.exists("/home/bienvivre/Tophoraire/" ^ string(hour) ^ "h.mp3") end PRELOAD_SLOTS = [ ("0", ("JINGLEINFO", "/home/bienvivre/Jingleinfo", false)), ("1", ("INFOSMAGNY", "/home/bienvivre/Infosmagny", false)), ("2", ("MERCI", "/home/bienvivre/Merciflash", false)), ("3", ("JINGLESMIX", "/home/bienvivre/Jinglesmix", false)), ("4", ("NOUVEAUTES", "/home/musique/Nouveautes", true)), ("5", ("JESSY", "/home/bienvivre/Jessy", false)), ("6", ("ANNEES2000", "/home/musique/Annees2000", true)), ("7", ("TITRESJESSY", "/home/bienvivre/Titresjessy", true)), ("8", ("LCTMETEO", "/home/bienvivre/Lancementmeteo", false)), ("9", ("METEO", "/home/bienvivre/Meteo", false)), ("10", ("JINGLESCHANTES", "/home/bienvivre/Jingleschantes", false)), ("11", ("JESSY", "/home/bienvivre/Jessy", false)), ("12", ("ANNEES80", "/home/musique/Annees80", true)), ("13", ("JINGLEHISTOIRE", "/home/bienvivre/Jinglehistoire", false)), ("14", ("HISTOIRE", "/home/bienvivre/Histoiremagny", false)), ("15", ("JINGLESCHANTES", "/home/bienvivre/Jingleschantes", false)), ("16", ("JESSY", "/home/bienvivre/Jessy", false)), ("17", ("NOUVEAUTES", "/home/musique/Nouveautes", true)), ("18", ("TITRESJESSY", "/home/bienvivre/Titresjessy", true)), ("19", ("JINGLESCHANTES", "/home/bienvivre/Jingleschantes", false)), ("20", ("ANNEES90", "/home/musique/Annees90", true)), ("21", ("JESSY", "/home/bienvivre/Jessy", false)), ("22", ("NOUVEAUTES", "/home/musique/Nouveautes", true)), ("23", ("NOUVEAUTES", "/home/musique/Nouveautes", true)), ("24", ("JINGLESCHANTES", "/home/bienvivre/Jingleschantes", false)), ("25", ("JESSY", "/home/bienvivre/Jessy", false)), ("26", ("ANNEES2010", "/home/musique/Annees2010", true)), ("27", ("JINGLESGRENIER", "/home/bienvivre/Jinglesgrenier", false)), ("28", ("GRENIERJESSY", "/home/bienvivre/Grenierjessy", true)), ("29", ("NOUVEAUTES", "/home/musique/Nouveautes", true)), ("30", ("JINGLEHISTOIRE", "/home/bienvivre/Jinglehistoire", false)), ("31", ("HISTOIRE", "/home/bienvivre/Histoiremagny", false)), ("32", ("JINGLESCHANTES", "/home/bienvivre/Jingleschantes", false)), ("33", ("ANNEES90", "/home/musique/Annees90", true)), ("34", ("JESSY", "/home/bienvivre/Jessy", false)), ("35", ("NOUVEAUTES", "/home/musique/Nouveautes", true)), ("36", ("TITRESJESSY", "/home/bienvivre/Titresjessy", true)), ("37", ("JINGLESCHANTES", "/home/bienvivre/Jingleschantes", false)), ("38", ("ANNEES80", "/home/musique/Annees80", true)), ("39", ("JINGLESCHANTES", "/home/bienvivre/Jingleschantes", false)), ("40", ("ANNEES2020", "/home/musique/Annees2020", true)), ("41", ("JESSY", "/home/bienvivre/Jessy", false)), ("42", ("NOUVEAUTES", "/home/musique/Nouveautes", true)) ] # V8.9 : un seul preparateur hors du thread audio. slot_preparers = ref([]) slot_remaining_getters = ref([]) def prepare_slot_request(slot, generation) = key = string(generation) ^ "/" ^ string(slot) if not list.assoc.mem(key, prefetched_requests()) then let (family, directory, music) = list.assoc(string(slot), PRELOAD_SLOTS) directory = if family == "JESSY" then now = time.local() choices = if now.month == 7 or now.month == 8 then [directory, jessy_hour_directory(), "/home/bienvivre/JESSYete"] else [directory, jessy_hour_directory()] end chosen = list.pick(default=directory, choices) if list.length(file.ls(pattern="*.mp3", chosen)) > 0 then chosen else directory end else directory end candidate = if music then one_shot_request(target_generation=generation, directory, (fun () -> -1), (fun (_) -> ()), family) else one_shot_fullend_request(directory, (fun () -> -1), (fun (_) -> ()), family) end if candidate != null then candidate = null.get(candidate) if request.resolve(candidate) then prefetched_requests := [(key, candidate), ...prefetched_requests()] else request.destroy(candidate) end end end end intro_factory = ref(fun (_,elapsed_get,song) -> begin ignore(elapsed_get()); (song : source) end) def isolated_program_slot(slot, family, is_music, select_request) = built_generation = ref(-1) pending = ref((-1, null)) handed_generation = ref(-1) def build_source(generation) = if built_generation() != generation then served = ref(false) advanced = ref(false) def fetch_once() = if not served() then key = string(generation) ^ "/" ^ string(slot) candidate = if list.assoc.mem(key, prefetched_requests()) then candidate = list.assoc(key, prefetched_requests()) prefetched_requests := list.assoc.remove(key, prefetched_requests()) (candidate : request?) else null end if candidate != null then candidate = null.get(candidate) if request.resolve(candidate) then served := true candidate else log(label="slot_invalid", level=2, "Fichier illisible SLOT " ^ string(slot) ^ " " ^ family ^ " ; nouveau tirage dans le MEME slot, aucune avance du rotate.") request.destroy(candidate) null end else null end else null end end first_request = fetch_once() initial = ref(first_request) def fetch_prepared() = if initial()!=null then r=initial() initial:=null r else fetch_once() end end raw = request.dynamic(synchronous=true, fetch_prepared) def tag_identity(meta) = flags = if is_music then music_cue_metadata(meta) else [("vrs_mix_allowed", "false"), ("mix_at_cue", "false")] end length = float_of_string(default=3.0, meta["vrs_play_length"]) list.append(flags, [("vrs_cross_start", string(min(3.0, max(0.0, length)))), ("vrs_cross_max_start", string(max(0.0, length))), ("vrs_slot", string(slot)), ("vrs_generation", string(generation)), ("vrs_family", family)]) end tagged = metadata.map(strip=false, insert_missing=true, tag_identity, raw) slot_audio = tagged def finish_slot(remaining, meta) = if not advanced() and program_position() == slot and program_generation() == generation then advanced := true ignore(remaining) ignore(meta) log(label="rotation_exact", level=3, "FIN SLOT " ^ string(slot) ^ " " ^ family ^ " generation " ^ string(generation) ^ " ; suivant " ^ string(next_program_slot(slot))) if top_waiting_at_boundary() then program_hold_for_top := true else set_program_position(next_program_slot(slot)) end end end # Requete musicale native : fin au CUE_OUT. Autres : fin physique. slot_audio.on_position(synchronous=true, remaining=true, allow_partial=true, position=0.0, finish_slot) if is_music and first_request!=null then meta=request.metadata(null.get(first_request)) meta=list.append(tag_identity(meta),meta) apply_intro=intro_factory() apply_intro(meta,slot_audio.elapsed,stereo(slot_audio)) else (stereo(slot_audio) : source) end else null end end ignore(select_request) def take_prepared() = generation = program_generation() let (ready_generation, child) = pending() if program_position() == slot and ready_generation == generation and handed_generation() != generation then handed_generation := generation child else null end end dynamic = source.dynamic(id="slot_" ^ string(slot), self_sync=false, track_sensitive=false, take_prepared) def prepare_slot() = current_slot = program_position() current_generation = program_generation() next_slot = next_program_slot(current_slot) remaining_get = list.assoc(default=(fun () -> 0.0), string(current_slot), slot_remaining_getters()) target = if current_slot == slot then current_generation elsif slot == 0 and top_waiting_at_boundary() then current_generation + 1 elsif next_slot == slot and not top_waiting_at_boundary() and remaining_get() <= 5.0 then current_generation + 1 else -1 end if target >= 0 and built_generation() != target then prepare_slot_request(slot, target) key = string(target) ^ "/" ^ string(slot) if list.assoc.mem(key, prefetched_requests()) then child = build_source(target) if child != null then # prepare active les decodeurs avant publication, sans lire de PCM. child = dynamic.prepare(null.get(child)) pending := (target, child) built_generation := target log(label="slot_ready",level=3, "AUDIO PRET SLOT " ^ string(slot) ^ " generation " ^ string(target)) end end end end slot_remaining_getters := [(string(slot), dynamic.remaining), ...slot_remaining_getters()] slot_preparers := [prepare_slot, ...slot_preparers()] dynamic end P00 = isolated_program_slot(0, "JINGLEINFO", false, next_jingleinfo_request) P01 = isolated_program_slot(1, "INFOSMAGNY", false, next_infosmagny_request) P02 = isolated_program_slot(2, "MERCI", false, next_merci_request) P03 = isolated_program_slot(3, "JINGLESMIX", false, next_jinglesmix_request) P04 = isolated_program_slot(4, "NOUVEAUTES", true, next_nouveautes_request) P05 = isolated_program_slot(5, "JESSY", false, next_jessy_request) P06 = isolated_program_slot(6, "ANNEES2000", true, next_annees2000_request) P07 = isolated_program_slot(7, "TITRESJESSY", true, next_titresjessy_request) P08 = isolated_program_slot(8, "LCTMETEO", false, next_lctmeteo_request) P09 = isolated_program_slot(9, "METEO", false, next_meteo_request) P10 = isolated_program_slot(10, "JINGLESCHANTES", false, next_jingleschantes_request) P11 = isolated_program_slot(11, "JESSY", false, next_jessy_request) P12 = isolated_program_slot(12, "ANNEES80", true, next_annees80_request) P13 = isolated_program_slot(13, "JINGLEHISTOIRE", false, next_jinglehistoire_request) P14 = isolated_program_slot(14, "HISTOIRE", false, next_histoire_request) P15 = isolated_program_slot(15, "JINGLESCHANTES", false, next_jingleschantes_request) P16 = isolated_program_slot(16, "JESSY", false, next_jessy_request) P17 = isolated_program_slot(17, "NOUVEAUTES", true, next_nouveautes_request) P18 = isolated_program_slot(18, "TITRESJESSY", true, next_titresjessy_request) P19 = isolated_program_slot(19, "JINGLESCHANTES", false, next_jingleschantes_request) P20 = isolated_program_slot(20, "ANNEES90", true, next_annees90_request) P21 = isolated_program_slot(21, "JESSY", false, next_jessy_request) P22 = isolated_program_slot(22, "NOUVEAUTES", true, next_nouveautes_request) P23 = isolated_program_slot(23, "NOUVEAUTES", true, next_nouveautes_request) P24 = isolated_program_slot(24, "JINGLESCHANTES", false, next_jingleschantes_request) P25 = isolated_program_slot(25, "JESSY", false, next_jessy_request) P26 = isolated_program_slot(26, "ANNEES2010", true, next_annees2010_request) P27 = isolated_program_slot(27, "JINGLESGRENIER", false, next_jinglesgrenier_request) P28 = isolated_program_slot(28, "GRENIERJESSY", true, next_grenierjessy_request) P29 = isolated_program_slot(29, "NOUVEAUTES", true, next_nouveautes_request) P30 = isolated_program_slot(30, "JINGLEHISTOIRE", false, next_jinglehistoire_request) P31 = isolated_program_slot(31, "HISTOIRE", false, next_histoire_request) P32 = isolated_program_slot(32, "JINGLESCHANTES", false, next_jingleschantes_request) P33 = isolated_program_slot(33, "ANNEES90", true, next_annees90_request) P34 = isolated_program_slot(34, "JESSY", false, next_jessy_request) P35 = isolated_program_slot(35, "NOUVEAUTES", true, next_nouveautes_request) P36 = isolated_program_slot(36, "TITRESJESSY", true, next_titresjessy_request) P37 = isolated_program_slot(37, "JINGLESCHANTES", false, next_jingleschantes_request) P38 = isolated_program_slot(38, "ANNEES80", true, next_annees80_request) P39 = isolated_program_slot(39, "JINGLESCHANTES", false, next_jingleschantes_request) P40 = isolated_program_slot(40, "ANNEES2020", true, next_annees2020_request) P41 = isolated_program_slot(41, "JESSY", false, next_jessy_request) P42 = isolated_program_slot(42, "NOUVEAUTES", true, next_nouveautes_request) PROGRAM_RAW = switch(track_sensitive=true, [ ({program_position() == 0}, P00), ({program_position() == 1}, P01), ({program_position() == 2}, P02), ({program_position() == 3}, P03), ({program_position() == 4}, P04), ({program_position() == 5}, P05), ({program_position() == 6}, P06), ({program_position() == 7}, P07), ({program_position() == 8}, P08), ({program_position() == 9}, P09), ({program_position() == 10}, P10), ({program_position() == 11}, P11), ({program_position() == 12}, P12), ({program_position() == 13}, P13), ({program_position() == 14}, P14), ({program_position() == 15}, P15), ({program_position() == 16}, P16), ({program_position() == 17}, P17), ({program_position() == 18}, P18), ({program_position() == 19}, P19), ({program_position() == 20}, P20), ({program_position() == 21}, P21), ({program_position() == 22}, P22), ({program_position() == 23}, P23), ({program_position() == 24}, P24), ({program_position() == 25}, P25), ({program_position() == 26}, P26), ({program_position() == 27}, P27), ({program_position() == 28}, P28), ({program_position() == 29}, P29), ({program_position() == 30}, P30), ({program_position() == 31}, P31), ({program_position() == 32}, P32), ({program_position() == 33}, P33), ({program_position() == 34}, P34), ({program_position() == 35}, P35), ({program_position() == 36}, P36), ({program_position() == 37}, P37), ({program_position() == 38}, P38), ({program_position() == 39}, P39), ({program_position() == 40}, P40), ({program_position() == 41}, P41), ({program_position() == 42}, P42) ] ) # TOP : une requete neuve, une lecture integrale, puis retour a PROGRAM_RAW. # Aucune source horaire suspendue, aucun delai de 23 h conserve en memoire. top_audio_active = ref(false) def choose_hourly_source() = if top_audio_active() then null elsif program_hold_for_top() then now = time.local() h = if now.min == 59 then (now.hour + 1) mod 24 else now.hour end filename = "/home/bienvivre/Tophoraire/" ^ string(h) ^ "h.mp3" top_request = request.create(cue_in_metadata=null, cue_out_metadata=null, filename) top_length = null.get(default=0.0, request.duration(filename)) top_audio = request.once(top_request) def tag_top(meta) = ignore(meta) [("hourly_top_hour", string(h)), ("vrs_mix_allowed", "false"), ("vrs_play_length", string(top_length)), ("vrs_cross_start", string(min(3.0, top_length))), ("vrs_cross_max_start", string(top_length))] end top_audio = metadata.map(strip=false, insert_missing=true, tag_top, top_audio) def finish_top(remaining, meta) = ignore(remaining) ignore(meta) top_audio_active := false end top_audio.on_position(synchronous=true, remaining=true, allow_partial=true, position=0.0, finish_top) if request.resolve(top_request) then top_audio_active := true stereo(top_audio) else program_hold_for_top := false set_program_position(next_program_slot(program_position())) log(label="top_horaire", level=2, "TOP ILLISIBLE : " ^ filename) PROGRAM_RAW end else PROGRAM_RAW end end hourly_radio = source.dynamic(id="hourly_radio", self_sync=false, track_sensitive=false, init=PROGRAM_RAW, choose_hourly_source) # Composition PCM : le suffixe du morceau jusqu'au CUE_OUT est rendu entier. # Le suivant commence seulement APRES ce suffixe. Le tail demarre simultanement. def exact_cue_transition(ending, starting) = before = (ending.source : source) after = (starting.source : source) key = ending.metadata["vrs_generation"] tail = if list.assoc.mem(key, music_tails()) then list.assoc(key, music_tails()) else null end music_tails := list.assoc.remove(key, music_tails()) pair = if ending.metadata["vrs_mix_allowed"] == "true" and ending.metadata["mix_at_cue"] == "true" and tail != null then tail = null.get(tail) # Si l'entrant est court, le tail ne se prolonge pas sur le fichier suivant. d = min(3.0, max(0.0, float_of_string(default=3.0, starting.metadata["vrs_play_length"]))) mixed = add(normalize=false, [after, fade.out(duration=d, max_duration(d, tail))]) log(label="mix_cueout_exact", level=3, "CUE_OUT NATIF : entrant apres le dernier echantillon avant cue ; tail " ^ key ^ " du fichier sortant ; mix max " ^ string(d) ^ " s.") (sequence(single_track=false, [before, mixed]) : source) else (sequence(single_track=false, [before, after]) : source) end # Cross peut rejouer les metadonnees sortantes sur le minuscule # suffixe PCM restant. La paire doit annoncer uniquement son entrant. # update=false remplace les champs ; strip=true seul ne les efface pas. # insert_missing couvre les frontieres sans metadonnees. (metadata.map(update=false, strip=true, insert_missing=true, (fun (_) -> starting.metadata), pair) : source) end # Buffer PCM borne, appartenant exclusivement a la paire de pistes native. # La requete entrante est resolue 5 s avant la frontiere native. # Le prefixe entrant est decode avant de rendre la jonction PCM exacte. # Aucune source de categorie permanente ne peut etre reinjectee. # V8.10 : fournir le prefixe entrant COMPLET au composeur PCM. # Sans ce marqueur, cross reduit starting.source a min(fin sortante, intro). # La fin sortante native vaut zero au CUE_OUT : le vrai prefixe etait alors # rejoue hors du mix, dans cross.after_tail. Aucune analyse autocue n'est lancee. # Ces champs internes sont ajoutes APRES les requetes : ils ne deplacent ni # le CUE_OUT natif, ni les CUE_IN servant au calage des habillages. def exact_pcm_buffers(meta) = [("liq_autocue", "vrs_exact_pcm_buffers"), ("liq_cue_in", "0"), ("liq_cue_out", meta["vrs_play_length"]), ("liq_fade_in", "0"), ("liq_fade_out", "0")] end hourly_exact_buffers = metadata.map(strip=false, exact_pcm_buffers, hourly_radio) PROGRAM = cross(id="program_cue_exact", duration=3.0, start_duration=3.0, end_duration=0.0, assume_autocue=false, override_duration="vrs_unused_cross_duration", override_start_duration="vrs_cross_start", override_end_duration="vrs_unused_cross_end", override_max_start_duration="vrs_cross_max_start", exact_cue_transition, hourly_exact_buffers) def remember_program_track(meta) = slot = int_of_string(default=-1, meta["vrs_slot"]) generation = int_of_string(default=-1, meta["vrs_generation"]) if generation >= current_program_generation() and slot >= 0 and true then current_program_generation := generation # Observation uniquement : ce callback ne fait JAMAIS avancer la rotation. # Ainsi le demarrage reel de P01 apres P00 ne peut plus etre interprete # comme un doublon et provoquer un second saut vers P02. current_program_slot := slot current_program_is_music := meta["vrs_mix_allowed"] == "true" current_program_mix_at_cue := meta["mix_at_cue"] == "true" current_program_mix_duration := float_of_string(default=0.0, meta["vrs_mix_duration"]) if program_reset_lock() and slot == 0 then program_reset_lock := false end log( label="slot_on_air", level=3, "ON AIR SLOT " ^ string(slot) ^ " generation " ^ string(generation) ^ " : " ^ meta["artist"] ^ (if meta["artist"] != "" then " - " else "" end) ^ meta["title"] ) end end # IMPORTANT : on_track sert uniquement au journal et aux proprietes de la # piste courante. Il ne modifie jamais program_position. PROGRAM.on_metadata( synchronous=true, remember_program_track ) # ------------------------------------------------------------ # ANTI-REPETITION ARTISTE DESACTIVEE - ROTATE STRICT 2026-09-29 # ------------------------------------------------------------ # Aucune regle de retry/skip ne doit intervenir dans le moteur du rotate. # Chaque slot musical diffuse le titre choisi par sa famille puis passe # strictement au slot suivant. Cela supprime PROGRAM.skip() du chemin critique. PCM_DURATION_SCRIPT = "exec(__import__(\"base64\").b64decode(\"aW1wb3J0IHN5cyxvcyxqc29uLGhhc2hsaWIsdGVtcGZpbGUsc3VicHJvY2Vzcyx3YXZlCmZyb20gcGF0aGxpYiBpbXBvcnQgUGF0aAp0cnk6CiBwPVBhdGgoc3lzLmFyZ3ZbMV0pO3N0PXAuc3RhdCgpO2tleT1oYXNobGliLnNoYTI1NihzdHIocCkuZW5jb2RlKCkpLmhleGRpZ2VzdCgpCiByb290PVBhdGguaG9tZSgpLycuY2FjaGUnLydiaWVudml2cmVhbWFnbnktbGluZXItcGNtLXY4OCc7cm9vdC5ta2RpcihwYXJlbnRzPVRydWUsZXhpc3Rfb2s9VHJ1ZSkKIHRhcmdldD1yb290LyhrZXkrJy5qc29uJyk7YXVkaW89cm9vdC8oa2V5Kycud2F2Jyk7c2lnbmF0dXJlPVtzdC5zdF9zaXplLHN0LnN0X210aW1lX25zXQogdHJ5OmRhdGE9anNvbi5s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leSsnLScrc3RyKHN0LnN0X210aW1lX25zKSsnLScrc3RyKGN1ZV9zYW1wbGVzKSsnLndhdicpCiAgaWYgbm90IHRpbWVsaW5lLmV4aXN0cygpOgogICBmZCx0bXA9dGVtcGZpbGUubWtzdGVtcChzdWZmaXg9Jy53YXYnLGRpcj1yb290KTtvcy5jbG9zZShmZCkKICAgdHJ5OgogICAgd2l0aCB3YXZlLm9wZW4oc3RyKGF1ZGlvKSwncmInKSBhcyBzcmMsd2F2ZS5vcGVuKHRtcCwnd2InKSBhcyBvdXQ6CiAgICAgb3V0LnNldHBhcmFtcyhzcmMuZ2V0cGFyYW1zKCkpCiAgICAgcHJlZml4PWN1ZV9zYW1wbGVzLXNyYy5nZXRuZnJhbWVzKCkKICAgICB3aGlsZSBwcmVmaXg6CiAgICAgIG49bWluKHByZWZpeCw2NTUzNik7b3V0LndyaXRlZnJhbWVzcmF3KGJ5dGVzKG4qNCkpO3ByZWZpeC09bgogICAgIHdoaWxlIFRydWU6CiAgICAgIGI9c3JjLnJlYWRmcmFtZXMoNjU1MzYpCiAgICAgIGlmIG5vdCBiOmJyZWFrCiAgICAgIG91dC53cml0ZWZyYW1lc3JhdyhiKQogICAgb3MucmVwbGFjZSh0bXAsdGltZWxpbmUpCiAgIGZpbmFsbHk6CiAgICBpZiBvcy5wYXRoLmV4aXN0cyh0bXApOm9zLnVubGluayh0bXApCiAgcHJpbnQoc3RyKHRpbWVsaW5lKSkKIGVsc2U6CiAgcHJpbnQoZGF0YVsnc2FtcGxlcyddLzQ0MTAwKQogIHByaW50KHN0cihhdWRpbykpCmV4Y2VwdCBFeGNlcHRpb24gYXMgZXhjOgogcHJpbnQoJ1ZSUyBsaW5lciBQQ006ICcrc3RyKGV4YyksZmlsZT1zeXMuc3RkZXJyKQogcHJpbnQoMCk7cHJpbnQoJycpCg==\"))" # V8.8 : habillage integre a la chanson AVANT cross. # Les durees sont celles du PCM decode, pas celles estimees de l'en-tete MP3. LINERCAP_FILES = file.ls(absolute=true,pattern="*.mp3","/home/bienvivre/Linercap") LINERART_FILES = file.ls(absolute=true,pattern="*.mp3","/home/musique/Linersartistes") JINGLENOUVEAUTE_FILES = file.ls(absolute=true,pattern="*.mp3","/home/bienvivre/Jinglenouveaute") ALL_LINER_FILES = list.append(list.append(LINERCAP_FILES,LINERART_FILES),JINGLENOUVEAUTE_FILES) def decoded_liner_info(filename) = cmd = "python3 -c " ^ process.quote(PCM_DURATION_SCRIPT) ^ " " ^ process.quote(filename) lines=process.read.lines(cmd) d=float_of_string(default=0.0,list.hd(default="0",lines)) pcm=list.hd(default="",list.tl(lines)) (d,pcm) end LINER_PCM_CACHE=list.map(fun(p)->(p,decoded_liner_info(p)),ALL_LINER_FILES) LINER_DURATION_CACHE=list.map(fun(e)->(fst(e),fst(snd(e))),LINER_PCM_CACHE) LINERART_ARTIST_CACHE = list.map(fun (p) -> (p,string.lowercase(string.trim(metadata.artist(file.metadata(p))))),LINERART_FILES) intro_last_buckets = ref([]) def intro_bucket() = now=time.local() string(now.year) ^ "-" ^ string(now.year_day) ^ "-" ^ string(now.hour) ^ "-" ^ string(if now.min<30 then 0 else 1 end) end def intro_music_slot(slot) = slot==4 or slot==6 or slot==12 or slot==17 or slot==20 or slot==22 or slot==23 or slot==26 or slot==29 or slot==33 or slot==35 or slot==38 or slot==40 or slot==42 end def intro_new_slot(slot) = slot==4 or slot==17 or slot==22 or slot==23 or slot==29 or slot==35 or slot==42 end def build_native_intro(meta, elapsed_get, song) = slot=int_of_string(default=-1,meta["vrs_slot"]) cue=float_of_string(default=0.,if meta["CUE_IN"]!="" then meta["CUE_IN"] else meta["cue_in"] end) length=float_of_string(default=0.,meta["vrs_play_length"]) bucket=intro_bucket() artist=string.lowercase(string.trim(meta["artist"])) def fitting(p) = d=list.assoc(default=0.,p,LINER_DURATION_CACHE) d>0. and d+0.5<=cue end def unused(kind) = list.assoc(default="",kind,intro_last_buckets())!=bucket end newfiles=if intro_new_slot(slot) and unused("JINGLENOUVEAUTE") then list.filter(fitting,JINGLENOUVEAUTE_FILES) else [] end capfiles=if unused("LINERCAP") then list.filter(fitting,LINERCAP_FILES) else [] end artistfiles=if artist!="" and unused("LINERARTISTE") then list.filter(fun(p)->fitting(p) and list.assoc(default="",p,LINERART_ARTIST_CACHE)==artist,LINERART_FILES) else [] end let (kind, files) = if newfiles!=[] then ("JINGLENOUVEAUTE",newfiles) elsif capfiles!=[] then ("LINERCAP",capfiles) else ("LINERARTISTE",artistfiles) end if intro_music_slot(slot) and cue>0. and cue<=length and files!=[] then filename=list.pick(default="",files) voice_length=list.assoc(default=0.,filename,LINER_DURATION_CACHE) # Fixer la grille PCM avant la soustraction : debut + duree = CUE_IN. finish=float(int(cue*44100.))/44100. start=max(0.,finish-voice_length) cmd="python3 -c " ^ process.quote(PCM_DURATION_SCRIPT) ^ " " ^ process.quote(filename) ^ " " ^ process.quote(string(cue)) pcm=list.hd(default="",process.read.lines(cmd)) req=request.create(cue_in_metadata=null,cue_out_metadata=null,pcm) if request.resolve(req) then intro_last_buckets := [(kind,bucket),...list.assoc.remove(kind,intro_last_buckets())] voice_served=ref(false) def voice_request() = if voice_served() then null else voice_served:=true; req end end voice=stereo(request.dynamic(synchronous=true,voice_request)) # Ce WAV contient deja le silence initial et finit au sample CUE_IN. voice=metadata.map(update=false,strip=true,(fun(_)->[]),voice) def gain() = elapsed=elapsed_get() if elapsed>=max(0.,start-0.25) and elapsed prepare(), list.rev(slot_preparers())) end prepare_program_audio() thread.run(fast=false, every=0.1, on_error=(fun (err) -> log(label="slot_prepare_error",level=2,string(err))), prepare_program_audio) def update_hourly_metadata(meta) = announced_hour = meta["hourly_top_hour"] if announced_hour != "" then h = int_of_string(default=-1, announced_hour) program_hold_for_top := false top_done_hour := h # RESET SIMPLE ET UNIQUE AU DEBUT DU TOP : # on rearme P00 sans appeler PROGRAM.skip(). Le dispatcher conserve # son enfant TOP jusqu'a sa fin physique, sans consommer PROGRAM/P00. transition_mix_requested := false transition_mix_duration := 0.0 transition_tail_duration := 0.0 program_reset_lock := true # CORRECTION ROTATE STRICT 2026-09-29 : # le TOP doit ouvrir une NOUVELLE generation de P00. Sans cela, si P00 a # deja ete servi dans la generation courante juste avant le TOP, le one-shot # JINGLEINFO refuse de resservir et PROGRAM peut rester indisponible. # set_program_position(0) rearme donc P00 de facon atomique. list.iter(fun (entry) -> request.destroy(snd(entry)), prefetched_requests()) prefetched_requests := [] music_tails := list.filter(fun (entry) -> int_of_string(default=-1, fst(entry)) <= program_generation(), music_tails()) set_program_position(0) log( label="top_horaire", level=3, "Top horaire " ^ string(h) ^ "h demarre : NOUVELLE generation et pointeur remis sur P00/JINGLEINFO." ) end end hourly_radio.on_metadata( synchronous=true, update_hourly_metadata ) def rendered_top_metadata(meta) = if meta["hourly_top_hour"] != "" then current_program_is_music := false current_program_slot := -1 end end PROGRAM.on_metadata(synchronous=true, rendered_top_metadata) # Le callback de fin physique du TOP libere son enfant ; le dispatcher reprend PROGRAM/P00. # Le top prend la prochaine frontiere CUE_OUT (ou fin physique sans cue). # Il ne peut pas interrompre une chanson a 65% avant son CUE_OUT. # ------------------------------------------------------------ # ANTI-DOUBLE JESSY / JINGLESCHANTES : # gere a la source par program_generation + last_*_generation. # Aucun callback on_track ne fait avancer la rotation ; cela evite les doubles # increments responsables des slots sautes. # ------------------------------------------------------------ radio = PROGRAM # IMPORTANT 2026-08-18 - SUPPRESSION DU PIEGE A BLANC PERMANENT # Ne jamais entourer hourly_radio d'un fallback(track_sensitive=true, [radio, blank()]). # Si PROGRAM devient indisponible quelques millisecondes a une fin de piste, # ce fallback peut selectionner blank(). Comme blank() est continu et que le # fallback est track_sensitive, il peut rester sur le silence jusqu'au restart. # La securisation infaillible est deja faite plus bas avec mksafe(radio), qui # est l'operateur adapte pour garantir une sortie sans emprisonner la radio # dans une branche blank() permanente. # ------------------------------------------------------------ # TRAITEMENT AUDIO APRES LE RENDU CUE_OUT EXACT # ------------------------------------------------------------ # Le chevauchement selectif est deja compose par exact_cue_transition(). # TRAITEMENT AUDIO - VERSION PLUS TRANSPARENTE POUR MP3 128 KB/S # Objectif : homogénéiser les fichiers de niveaux différents sans écraser # les transitoires ni pousser inutilement l'encodeur MP3 dans le limiteur. radio = stereo(radio) # Très léger gain d'entrée. L'ancienne valeur 1.32 poussait déjà le signal # d'environ +2,4 dB avant toute compression. radio = amplify(1.08, radio) # Etage 1 : nivellement lent et doux. # Il remonte légèrement les morceaux faibles et réduit les écarts de niveau # sans créer de pompage audible. radio = compress( attack=120.0, release=1800.0, threshold=-27.0, ratio=1.45, gain=2.4, radio ) # Etage 2 : contrôle des crêtes, plus rapide mais volontairement modéré. # Il évite que certains masters agressifs déclenchent constamment le limiteur. radio = compress( attack=20.0, release=320.0, threshold=-14.0, ratio=1.45, gain=0.6, radio ) # Le limiteur exige une source infaillible. # On securise le flux avant le limiteur. radio = mksafe(radio) # Marge de sécurité légèrement supérieure avant encodage MP3 128 kb/s. # Cela limite les surcharges et les artefacts sur les fichiers déjà très forts. radio = limit( attack=5.0, release=180.0, threshold=-1.2, radio ) # ------------------------------------------------------------ # METADONNEES POUR ICECAST ET L INTERFACE WEB # ------------------------------------------------------------ # Ne pas fabriquer de titre de secours ici : cela risquerait d'ecraser # les vrais tags artist/title au passage des jingles et des transitions. # Les metadata.map des sources conservent deja les tags ID3 avec strip=false. # Journalise chaque titre reellement remis a la sortie Icecast. def log_stream_metadata(meta) = log( label="metadata_icecast", level=3, "Titre envoye : " ^ meta["artist"] ^ (if meta["artist"] != "" then " - " else "" end) ^ meta["title"] ) end radio.on_metadata( synchronous=true, log_stream_metadata ) # SORTIE ICECAST output.icecast( %mp3(bitrate=128, samplerate=44100, stereo=true), encoding="UTF-8", host="stream.votreradiosurlenet.eu", port=8181, user="source", password="jerome", mount="/bienvivreamagny.mp3", send_icy_metadata=true, genre="Bien Vivre A Magny", name="Bien Vivre A Magny", description="Bien Vivre A Magny - toute l'actualite independante de Magny le Hongre Val d'Europe en Seine-et-Marne", url="https://bienvivreamagny.fr", radio )