Follow

PAL Scripting - Lesson 3 (Working with Classes)

PAL Scripting - Lesson 3 Working with Classes

In Lesson 2 we worked with three basic variable types.  A Class could be considered as a collection of variables or attributes either pre-existing or which we create.  In this lesson we will be working with the TSongInfo Class which is a container for all of the information associated with each track, for example, the artist name, the track title etc. are all string variables within the TSongInfo Class.

We will begin by defining our own variable which will be a container for the information related to the track currently playing in Deck A within SAM Broadcaster:

var Song : TSongInfo;

This defines the variable 'Song' as an instance of the Class TSongInfo, an empty collection of places to store the associated Class Attributes.  Remember, this does not currently refer to any specific track, we have simply prepared a place to store the information.

 

Next we will copy the track information for the track currently playing on Deck A into this new information store:

Song := DeckA.GetSongInfo;

This simply says copy the track information from the track playing on Deck A, into our new information store.

 

At this point it would be useful to introduce some error checking.  By incorporating basic error checking into your scripts you can prevent hours of frustrating troubleshooting when your script fails to perform as expected:

if Song = nil then
    WriteLn('No song loaded into DeckA!')

This simply checks for a track playing in Deck A and if none is found, the message 'No song loaded into DeckA!' is displayed.

 

The operator 'Else' can be used with the 'If' to determine what happens if there is a track playing in Deck A which in this instance will write some of the available Class attributes for this currently playing track:

begin
    WriteLn('Artist: '+Song['artist']);
    WriteLn('Title: '+Song['title']);
    WriteLn('Album: '+Song['album']);
    WriteLn('Label: '+Song['Label']);
    WriteLn('Duration: '+Song['Duration']);
    WriteLn('Composer: '+Song['Composer']);
    WriteLn('Genre: '+Song['Genre']);
    WriteLn('Album Year : '+Song['Albumyear ']);
    WriteLn('genre: '+Song['Genre']);
    WriteLn('Track No: '+Song['Trackno']);
    WriteLn('Weighting: '+Song['Weight']);
end;

 

The output is contained between the 'Begin' and 'End' which relate to the 'Else' operator.  This displays a selection of the Class attributes:

By using the now familiar WriteLn command we can first output the name of the attribute and then the attribute itself.


Classes

Any PAL script Keyword starting with a capital letter T is a class and will have further attributes associated with it.

The TPlayer Class relates to the decks.

The TEncoder Class relates the encoders.

The TQueue Class refers to the Queue.

There are many more Classes available and awaiting your investigation.

 

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

Comments