Hook aus Playlist auslösen

Hallo,

ich bin auf der Suche nach einem Script mit folgender Funktion:
“Spiele eine Hook von einem Song aus der aktuell geladenen Playlist”

Da Mairlist 6 ja jetzt Hooks selbst definieren kann (in der Config definiert) müsste es da doch bestimmt ein Weg geben oder? Ich selbst kenne mich da leider nicht wirklich aus was Scripts angeht. Hat jemand eine Idee? Das ist doch bestimmt auch für andere interessant?! :slight_smile:

Try this script:

var
  i, iItemCount, iMax, iVol, iToth: integer;
  i64Duration: TTimeValue;
  sArtist : string;
  sMessage, sPlaylist, sTitle : string;
  currentItem, ItemHook, ItemHook2: IPlaylistItem;
  ads: IContainerPlaylistItem;
  adsPlaylist, newPlaylist: IPlaylist;
  adsContainerAsPlaylistItem, piNews: IPlaylistItem;
  sFileName, sOpener, sCloser, sMiddle: string;
  i64HookIn, i64HookFade, i64HookOut: TTimeValue;

  const SONG_MIN_LENGTH = 900000000;	

procedure startMarkup;
begin

  for i := 0 to Playlist(0).GetCount -1 do
  begin

  if Playlist(0).GetItem(i).GetTitle = 'Top of the hour' then begin
	iToth := i;
	SystemLog(Playlist(0).GetItem(i).GetTitle);
	break;
  end;
  end;

end;

procedure MarkupCurrentPlaylist;
begin

// Set values (REPLACE THESE WITH YOUR OWN)
  sOpener := 'M:\Jingle\NFM\NFM Selected with Passion Mixdown 1.mp3';
  sMiddle := 'M:\Jingle\Soundeffect\BBC Bleep 2.mp3';
  sCloser := 'M:\Jingle\NFM\NFM 2014 Jingles 4a.mp3';


// Reset counters etc.
  iMax := iItemCount - 1;
  iVol := 0;

// Display our start up message
  SystemLog('Hook: '
    + 'Checking the playlist, looking for songs with Hooks.');

ads.GetPlaylist.InsertFile(0, sOpener, [fitMMD, fitTags, fitNativeTags, fitDuration, fitTilde, fitAutoCue, fitDatabaseLookup]);

// Step through each item in the current (selected) Playlist
  for i := iToth + 2 to Playlist(0).GetCount -1 do
  begin

    
// Create a local reference to the current item
// This makes all subsequent code easier to read and slightly faster to process
    currentItem := Playlist(0).GetItem(i);

// Store the current item's Artist, Title, and Effective Duration
    sArtist := currentItem.GetArtist;
    sTitle := currentItem.GetTitle;
    i64Duration := currentItem.GetDuration;

// Is this a song?
    if currentItem.IsCueable then
    begin
      

// Add the song to the container and set it to a hook.

ItemHook := iPlaylistItem(currentItem.Clone);

i64HookIn := ItemHook.GetCuePosition(ptHookIn);
i64HookFade := ItemHook.GetCuePosition(ptHookFade);
i64HookOut := ItemHook.GetCuePosition(ptHookOut);


if (i64HookIn > 0) then
begin
//	SystemLog('Added');
	ads.GetPlaylist.Add(ItemHook);
	if (iVol < 2) then
	begin
         ads.GetPlaylist.InsertFile(ads.GetPlaylist.GetCount, sMiddle, [fitMMD, fitTags, fitNativeTags, fitDuration, fitTilde, fitAutoCue, fitDatabaseLookup]);
	end;
	ItemHook.SetCuePosition(ptCueIn, i64HookIn);
	ItemHook.SetCuePosition(ptFadeOut, i64HookFade);
	ItemHook.SetCuePosition(ptStartNext, i64HookFade);
	ItemHook.SetCuePosition(ptCueOut, i64HookOut);
	ItemHook.SetArtist('Coming up: '+ currentItem.GetArtist);
	iVol := iVol + 1
end;

if (iVol = 3) then
begin
 break;
end;

SystemLog('Hook: ' + 'Item '
        + IntToStr(i + 1)
        + ' ('
        + Trim(currentItem.GetTitle)
        + ' / '
        + Trim(currentItem.GetArtist)
        + ') '
        + '.');

    end
      

  end;  // of for... loop


// All Playlist items processed, inform user

     if (ivol < 3) then
     begin
     ads.GetPlaylist.Delete(ads.GetPlaylist.GetCount -1);
     end;
   ads.GetPlaylist.InsertFile(ads.GetPlaylist.GetCount, sCloser, [fitMMD, fitTags, fitNativeTags, fitDuration, fitTilde, fitAutoCue, fitDatabaseLookup]);

  SystemLog('Hook: ' + 'Checking done.');

end;



begin

// Create a new Container Item
  ads := Factory.CreateContainerPlaylistItem;

// create a copy of the reference as an IPlaylistItem interface
   
   adsContainerAsPlaylistItem := IPlaylistItem(ads);
   startMarkup;
   MarkupCurrentPlaylist;

   adsContainerAsPlaylistItem.SetTitle('Coming Up Next'); 
 
   Playlist(0).Insert(iToth + 1, adsContainerAsPlaylistItem);

end.

You have to make some minor adjustments concerning the opener, middle and closer jingles.
It picks, when available, up to three hooks from the current playlist and plays them with a jingle before, in the middle and after. If there are no hooks, only the closer jingle is played. Good luck.

It’s actually much easier in v6:

const
  MAX_COUNT = 3;

var
  pl: IPlaylist;
  hook: IPlaylistItem;
  i: integer;

begin
  pl := Factory.CreatePlaylist;

  CurrentPlaylist.BeginUpdate;
  try
    for i := CurrentPlaylist.GetNextIndex to CurrentPlaylist.GetCount - 1 do 
      if CurrentPlaylist.GetItem(i).GetItemType = pitMusic then begin
        pl.Add(CurrentPlaylist.GetItem(i));
        if pl.GetCount = MAX_COUNT then break;
      end;

    hook := Factory.CreateHookContainer(pl);
    CurrentPlaylist.Insert(CurrentPlaylist.GetNextIndex, hook);
  finally
    CurrentPlaylist.EndUpdate;
  end;
end.

This will add the hook for the next three music items (change the number at the top).

The hook container will take care of the cue markers and all jingles.

Hey,

thank you very much! I just tryed it quickly in the event editor. When i try to run the script i get the following error:

13.04.2017 14:14:15 Fehler       Fehler beim Ausführen der Aktion Script ausführen (Z:\mairlist\scripts\playHook.mls): [Fehler] (2:1): Identifier expected

Script works for me, there was only a minor mistake, “GetType” vs. “GetItemType” - corrected my post above.

What kind of editor did you use? Sounds like an issue with the UTF-8 BOM for me. Try Windows Notepad.

Script works fine too Torben in v6, only my closer jingle is not played at the end of the hookcontainer. Opening, middle and closerjingles are defined correctly in the Config App.

It works now, thank you very much!

Another question concerning Torben’s script:
I’d like mairlist to only pick song 5, 12 and 18 from next hour’s playlist. What do I have to change in Torben’s script?

Does somebody know how to change Torben’s Script so that no Hookcontainer will be created?
I will use the script in an another container, so when executing the script, the the hook container is out of the container :confused:

Adding Hook Containers to other containers was not possible until the latest build 3549 which I just uploaded. You were able to add them, but there was an error message when you tried to play the container (“invalid item type”). Same was true for News Containers.

Regarding the script, not sure what your script looks like right now - but if it’s based on my script above, you will probably just have to change the line

CurrentPlaylist.Insert(CurrentPlaylist.GetNextIndex, hook);

so that it operates on the container content playlist, not “CurrentPlaylist” (which is the playout playlist). E.g. something like this:

container.GetPlaylist.Add(hook);

(where “container” is the IContainerPlaylist item variable referencing your newly created container).

Hey Torben,

when i change the line i get the follow error message: “05.05.2017 20:18:17 Fehler Fehler beim Ausführen der Aktion Script ausführen (C:\Program Files (x86)\mAirList-Scripts\generateHook.mls): [Error] (21:5): Unknown identifier ‘container’”

This is my full script:

[code]const
MAX_COUNT = 2;

var
pl: IPlaylist;
hook: IPlaylistItem;
i: integer;

begin
pl := Factory.CreatePlaylist;

CurrentPlaylist.BeginUpdate;
try
for i := CurrentPlaylist.GetNextIndex to CurrentPlaylist.GetCount - 1 do
if CurrentPlaylist.GetItem(i).GetItemType = pitMusic then begin
pl.Add(CurrentPlaylist.GetItem(i));
if pl.GetCount = MAX_COUNT then break;
end;

hook := Factory.CreateHookContainer(pl);
container.GetPlaylist.Add(hook);

finally
CurrentPlaylist.EndUpdate;
end;
end.[/code]

Help :-\

What do you mean by that? How can you “use” a script in a container?

I was under the impression that you had modified by script so that it creates some container, which you want to add the Hook Container to.

Hey Torben,

please find attached a screenshot from my problem. Mairlist is constructing an opener with different elements and start next times so that the opener is totally dynamic. Sounds good! :smiley:
The silence item “Hooks generieren” is exectuing the scribt from you above. This inserts a hook container right after the silence item.

For a better looking i would like to put all the opener items in a container. So far no problem - but the script will insert the hook container after the container with the opener elements, not after the silence item. How do i have to change the script? :confused:


Bildschirmfoto 2017-05-09 um 08.55.53.png

Torben wrote:

This will add the hook for the next three music items (change the number at the top).

The hook container will take care of the cue markers and all jingles.

The script is running but creates a container without jingles Opener, Middel and Closer. How to add this jingles?

Go to the config app -> Miscellaneous -> File Repository

in V6: config app - > miscellaneous - > hooks, I suppose.

Script is working fine now when I place the Hook Container within the hour playlist. I also want the Hook Container to execute before the News (Top of the Hour). In V5 I inserted the Hook Container right before the start of the next hour template, via Event. This does not seem the work in V6 anaymore? Hook Container is skipped…