Play All 3 - scripted, but only 3!

By Hal MacLean


The files used in this tutorial are available here

In the earlier tutorials we used a mixture of scripting and stories. Both work very well and will accomplish what you want, but there is the small matter of making lots of very similar scripts if you have a lot of tracks to include in your ‘play all’. This tutorial shows you how to accomplish a play all with just three scripts, no matter how many tracks you have got.

The secret lies in the fact that in DVD Studio Pro the tracks are like any other item and can be referenced with a simple number. For example, ‘Track 1′ will always have the value of ‘49,280′. This means that if you want to jump to the first track from wherever you are you can simply do so by using this number. You don’t have to use the track name at all.

The same is true for menus, too. The first menu in your project will have the value ‘32′ and subsequent menus increment the value by 32 each time, so menu 2 will have a value of ‘64′ and menu 3 will be ‘96′ and so on. Tracks, however, increment by 128 each time from that starting value.

But it isn’t just tracks - if you have got a story it too will add to the values by adding a further 128 to the total. So if you have got a track with four stories on it, the fourth story will have a value of (128*4)+49,280… which equals 49,792. Track two will then add a further 128 to this and so on. You must remember that Track 1 is not necessarily the first track you created - it is the one that is at the top of the list when you are looking at the outline view for your project. If you drag the tracks to a different order, then whichever you have got at the top will become ‘track 1′. This simple piece of information is enough for us to start referencing tracks without worrying about their names, and we can use very basic maths to do the work of lots of scripts.

The system in the download files has only three tracks, but you can add as many as you like. You need only to change a single line in each of the three scripts for the project. The project also has only one menu, with buttons for each track and a final button to operate the ‘play all’ scenario. When you select a button you go to a short script:

Script 1

mov GPRM1, 0
mov GPRM2, 0
mov GPRM0, SPRM8
div GPRM0, 1024
mov GPRM1, 1 if (GPRM0 = 4)
Goto 8 if (GPRM 1 = 0)
Jump Track 1
mul GPRM0, 128
add GPRM0, 49152
Jump Indirect GPRM0

Working through this script, the first two lines clear two registers which we use later on and cover us in case the viewer is watching a ‘play all’ but then decides to watch a single clip. If we don’t clear the register in this case, when they play the single clip the system will think they are in a play all and instead of jumping back to the menu at the end of the clip, it will continue through the remaining tracks in sequence.

Line 3 is where the real work begins. We first of all get the button number from the menu so we know what the user selected, then divide it by 1024 to get a simple integer we can work with. In my example, the ‘Play All’ button is button 4, so in line 5 we set a flag in GPRM1 if the viewer selected button 4. This is how we will know that we are in a ‘Play All’ situation.

In line 6 we jump ahead in the script if we are NOT in a ‘Play All’… i.e. the user chose to play a single track. By jumping ahead we skip over the start of the play all scenario, which is the jump in Line 7. If we are doing the ‘Play All’ then we need to start at track 1, but if not we need to work out which track to get to. Here’s where the maths starts.

We already have the button value (let’s assume the viewer pressed button 3, and that GPRM0 now has a value of ‘3′ in it). We know that a track increments by 128, so we need to multiply the button value by 128 to be sure of getting to the right track value. However, we also know that track 1 has the value of 49,280, so no matter what, we have to get to that value as a start point for the first track, and then increment by 128 each time for each subsequent track. Therefore, we add on a value that is exactly 128 less than the track 1 value. This way, if the user chose the track 1 button from the menu, the maths would be ‘(128*1)+49152 which equals 49280, and we would be on track 1. We are assuming they selected track 3, so the maths is now (128*3)*49152 = 49536. This is exactly the value for track 3.

The last line is a jump statement that looks for a value in GPRM0 to do it’s work. We are in effect jumping indirectly to the track we want, since we are not naming it but referring only to its value. You should find that track 3 plays. We now need to get back to the menu, and preferably to the last selected button, so we need a script to handle all of the end jumps

Script 2

Goto 7 if (GPRM1 = 0)
mov GPRM0, Last Track
add GPRM0, 128
Goto 6 if (GPRM 0 = 49664)
Jump Indirect GPRM0
mov GPRM1, 0
sub GPRM0, 49152
div GPRM0, 128
Jump Menu 1 [GPRM0]

This script is handling two possibilities. In line 1 we are looking to see if we are in a play all - if we are not we want to skip ahead to line 7. If not, and we are in a play all, we want to work out the correct value for the next track. Fortunately, DVD Studio Pro has a script setting that gets the value of the last track played (if you are using the ‘Set GPRM’ command you can set the source type to ‘Special’ then the Source Value can be set to three things, one of which is ‘Last Track’). We simply add on 128 to get to the next logical track value.

In line 4 you have got a value beyond that of the maximum possible - in fact this value would equate to a ‘track 4′ if we had one. However, this is not present so given the maths we have done, if we get to this value then we would have played the last track of our three in the ‘Play All’. If this is the case we know we have finished and must go back to a menu. This is the line to change if you add more tracks. For example, if you add three more tracks to the system, then change the value in this line to be ‘50048′. This is arrived at by the following equation:

(128*7)+49152

Note that you have got 6 tracks, but the equation allows for 7, because of the way the script is sequenced.

If you are not at the end of the sequence for ‘Play All’ then you should Jump Indirect to the item with the value in GPRM0 - the next track. If you have reached the end of the play all we need to remove the play all flag, which is what line 6 does.

From line 7 we are simply reversing the maths doen in the first script, subtracting the value that got us to the tracks and then dividing by 128 to find the button number we came from. The last line is then a simple GPRM based button jump.

The system is almost complete. All that remains is to manage the menu call that your viewer might make. You could simply send them back to the menu and that would be alright, since we have got every button pointing to the script which clears the values and removes the ‘play all’ flag. However, not every situation will work this way. It is possible, for example, that your project has got a lot of tracks and your menu is rather busy. You want to get them back to the right button and to do so we need to reverse the maths we did to get them to their track, but at the same time we don’t want to delete the value in GPRM0 because that would disrupt the end jump script - you would end up at the default button every time instead of the last selected button. For this reason we are going to use a third GPRM to do the calculation in just to preserve the work done earlier. If this isn’t an issue for you, then simply remove the menu call script from the project and set the end jumps to go to the menu. However, if you do want to keep the system intact, here’s the script to do the job:

Script 3

mov GPRM2, GPRM0
sub GPRM2, 49152
div GPRM2, 128
Jump Menu1 [GPRM2] if (GPRM1 = 0)
Jump Menu1::Button 4

This should look very familiar - we have used the sequence of commands before. In line 1 we simply copy the value from GPRM0 into GPRM2. From there on we reverse the maths to get back to the button number and in line 4 we jump back to the menu (and correct button) if we are not in the play all. In line 5 we hard code in the jump back to the ‘Play All’ button. In this case, button 4. You may find you need to change this value, depending on your exact project.

And that’s it.

Conclusion

In script 1 (the set up which every menu button must point to) you may need to amend line 5, to ensure it is referring to your play all button number. In script 2 (the end jumps) you may need to amend line 4, the value for one more track than you have actually got so that we know if you have finished the play all sequence. In script 3 you have only to set the last line to go to your play all button.

This system will work for tracks and stories and you can include as many tracks and stories as you wish (up to the maximum 99 allowed in a DVD Studio Pro project) and it will still work. You might do away with the menu call script and it will still work almost as well, however I recommend that you keep it in. It’s a short script, after all!

Remember, the order of your tracks in the outline view is crucial - the numbers refer to these items in that order. Move track 3 to the top and suddenly, according to this system, it becomes the target for the button that should play track 1.

The files to accompany this project are available from here. Good luck!